From b3ac62c1ddae4c6fd38b2d4ba4ccffddcc384015 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 17:43:06 +0000 Subject: [PATCH 01/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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/35] 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 76ef34b0ecdc6942afa9550f42c4a86602b12c4f Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 19:12:11 +0000 Subject: [PATCH 10/35] Update tests --- .../out/refcount/defaulted_move_cross_tu.rs | 5 +- .../out/unsafe/defaulted_move_cross_tu.rs | 5 +- .../refcount/out_of_line_methods_cross_tu.rs | 10 +- .../unsafe/out_of_line_methods_cross_tu.rs | 10 +- .../template_method_late_instantiation.rs | 5 +- .../template_method_late_instantiation.rs | 5 +- .../out/refcount/p14-class-in-two-files.rs | 14 +- .../out/unsafe/p14-class-in-two-files.rs | 14 +- .../p15-class-template-static-member.rs | 14 +- .../p15-class-template-static-member.rs | 14 +- .../out/refcount/p15-function-template.rs | 18 +-- .../out/unsafe/p15-function-template.rs | 18 +-- .../out/refcount/p15-inline-function.rs | 12 +- .../out/unsafe/p15-inline-function.rs | 12 +- .../out/refcount/p15-inline-variable.rs | 12 +- .../out/unsafe/p15-inline-variable.rs | 12 +- .../p16-default-argument-lambda-in-class.rs | 12 +- .../p16-default-argument-lambda-in-class.rs | 12 +- .../refcount/p16-lambda-in-inline-function.rs | 12 +- .../unsafe/p16-lambda-in-inline-function.rs | 12 +- .../basic.link/out/refcount/basic.link.rs | 25 ++-- .../basic/basic.link/out/unsafe/basic.link.rs | 25 ++-- .../out/refcount/basic.scope.block.rs | 71 ++++++---- .../out/refcount/basic.scope.class.rs | 10 +- .../out/refcount/basic.scope.pdecl.rs | 7 +- .../out/refcount/basic.scope.scope.rs | 23 +++- .../out/unsafe/basic.scope.block.rs | 42 ++++-- .../out/unsafe/basic.scope.class.rs | 10 +- .../out/unsafe/basic.scope.pdecl.rs | 7 +- .../out/unsafe/basic.scope.scope.rs | 23 +++- tests/std/basic/out/refcount/basic.def.odr.rs | 107 ++++++++------- tests/std/basic/out/unsafe/basic.def.odr.rs | 105 +++++++++------ .../class.conv/out/refcount/class.conv.fct.rs | 35 +++-- .../class.conv/out/unsafe/class.conv.fct.rs | 31 ++++- .../out/refcount/class.copy.ctor.rs | 7 +- .../class.ctor/out/unsafe/class.copy.ctor.rs | 4 +- .../out/refcount/class.mem.general.rs | 10 +- .../class.mem/out/unsafe/class.mem.general.rs | 10 +- .../dcl.init/out/refcount/dcl.init.general.rs | 23 ++-- .../dcl.init/out/unsafe/dcl.init.general.rs | 25 ++-- .../out/refcount/dcl.fct.default.rs | 15 ++- .../dcl.meaning/out/unsafe/dcl.fct.default.rs | 15 ++- .../out/refcount/expr.mptr.oper.rs | 18 ++- .../out/unsafe/expr.mptr.oper.rs | 18 ++- .../allocator.requirements.general.rs | 5 +- .../unsafe/allocator.requirements.general.rs | 5 +- .../stmt.iter/out/refcount/stmt.while.rs | 58 +++++++-- .../stmt.iter/out/unsafe/stmt.while.rs | 53 ++++++-- .../stmt.select/out/refcount/stmt.if.rs | 10 +- .../stmt.select/out/refcount/stmt.switch.rs | 53 +++++--- .../stmt.select/out/unsafe/stmt.if.rs | 10 +- .../stmt.select/out/unsafe/stmt.switch.rs | 45 +++++-- .../temp/temp.spec/out/refcount/temp.inst.rs | 15 ++- .../temp/temp.spec/out/unsafe/temp.inst.rs | 15 ++- .../utility/out/refcount/forward-helpers.rs | 64 +++++---- .../utilities/utility/out/refcount/forward.rs | 5 +- .../utility/out/unsafe/forward-helpers.rs | 83 +++++++----- .../utilities/utility/out/unsafe/forward.rs | 5 +- tests/unit/out/refcount/10_struct.rs | 5 +- .../out/refcount/array_of_noncopy_struct.rs | 7 +- .../out/refcount/assignment_single_eval.rs | 5 +- tests/unit/out/refcount/cast.rs | 5 +- tests/unit/out/refcount/class_templates.rs | 15 ++- tests/unit/out/refcount/constexpr_function.rs | 24 ++-- tests/unit/out/refcount/constructor.rs | 7 +- .../unit/out/refcount/container_field_addr.rs | 7 +- .../conversion_operator_same_translation.rs | 88 +++++++++---- tests/unit/out/refcount/copy_assign.rs | 53 +++++--- tests/unit/out/refcount/copy_ctor.rs | 73 +++++++---- .../unit/out/refcount/copy_move_defaulted.rs | 109 +++++++++------- tests/unit/out/refcount/copy_move_deleted.rs | 34 +++-- .../refcount/default_function_arguments.rs | 5 +- .../unit/out/refcount/enum_underlying_type.rs | 5 +- .../out/refcount/field_method_receiver.rs | 5 +- tests/unit/out/refcount/field_pointers.rs | 5 +- tests/unit/out/refcount/fn_ptr_struct.rs | 10 +- .../unit/out/refcount/for_body_destructor.rs | 24 ++-- .../refcount/foreach_disjoint_field_borrow.rs | 5 +- tests/unit/out/refcount/forward_basic.rs | 20 ++- tests/unit/out/refcount/forward_decltype.rs | 10 +- tests/unit/out/refcount/forward_explicit.rs | 25 +++- tests/unit/out/refcount/forward_pack.rs | 20 ++- .../out/refcount/global_non_const_init.rs | 18 +-- tests/unit/out/refcount/huffman.rs | 5 +- tests/unit/out/refcount/implicit_autoref.rs | 5 +- .../refcount/in_class_field_initializer.rs | 12 +- tests/unit/out/refcount/init_list.rs | 10 +- .../out/refcount/inline_container_fields.rs | 35 +++-- tests/unit/out/refcount/kruskal.rs | 10 +- tests/unit/out/refcount/lambda_as_field.rs | 7 +- .../out/refcount/lambda_capture_copy_ctor.rs | 77 +++++------ .../unit/out/refcount/lambda_decltype_type.rs | 10 +- .../out/refcount/lambda_immediate_init.rs | 5 +- .../out/refcount/lambda_move_only_capture.rs | 13 +- .../refcount/libc_struct_without_default.rs | 5 +- tests/unit/out/refcount/map.rs | 7 +- tests/unit/out/refcount/map_key_copy_ctor.rs | 10 +- tests/unit/out/refcount/map_key_identity.rs | 7 +- tests/unit/out/refcount/map_try_emplace.rs | 48 +++---- .../out/refcount/map_try_emplace_lvalues.rs | 122 +++++++++--------- tests/unit/out/refcount/max.rs | 5 +- tests/unit/out/refcount/move_assign.rs | 17 ++- tests/unit/out/refcount/move_ctor.rs | 42 +++--- tests/unit/out/refcount/move_this.rs | 24 ++-- .../refcount/operator_comparison_nonbool.rs | 90 +++++++++---- .../out/refcount/operator_other_member.rs | 101 ++++++++++++--- .../refcount/pair_converting_construction.rs | 40 ++++-- tests/unit/out/refcount/push_emplace_back.rs | 21 +-- tests/unit/out/refcount/rule_of_five.rs | 15 ++- tests/unit/out/refcount/rule_of_three.rs | 5 +- .../unit/out/refcount/rvalue_rule_arg_move.rs | 15 ++- .../refcount/self_referencing_initializer.rs | 5 +- tests/unit/out/refcount/size_t_ssize_t.rs | 4 +- tests/unit/out/refcount/sort_no_copy.rs | 24 ++-- tests/unit/out/refcount/struct_ctor.rs | 7 +- .../unit/out/refcount/struct_default_ctor.rs | 24 ++-- .../refcount/structured_binding_copy_ctor.rs | 10 +- .../structured_binding_element_ctor.rs | 28 ++-- .../refcount/structured_binding_move_ctor.rs | 20 ++- tests/unit/out/refcount/swap_map_no_copy.rs | 55 ++++---- .../unit/out/refcount/template_default_arg.rs | 18 +-- .../unit/out/refcount/temporary_field_addr.rs | 12 +- .../out/refcount/temporary_field_ctor_arg.rs | 5 +- .../out/refcount/temporary_field_two_args.rs | 12 +- .../unit/out/refcount/typedef-anon-struct.rs | 5 +- tests/unit/out/refcount/unboxed_records.rs | 5 +- tests/unit/out/refcount/unique_ptr.rs | 5 +- .../out/refcount/unique_ptr_const_deref.rs | 5 +- .../out/refcount/unique_ptr_field_reset.rs | 5 +- tests/unit/out/refcount/unique_ptr_nested.rs | 5 +- tests/unit/out/refcount/vector.rs | 5 +- .../out/refcount/vector_iter_range_ctor.rs | 17 ++- .../out/refcount/vector_subscript_direct.rs | 5 +- tests/unit/out/refcount/void_cast.rs | 10 +- tests/unit/out/unsafe/10_struct.rs | 5 +- .../out/unsafe/array_of_noncopy_struct.rs | 7 +- .../unit/out/unsafe/assignment_single_eval.rs | 5 +- tests/unit/out/unsafe/cast.rs | 5 +- tests/unit/out/unsafe/class_templates.rs | 15 ++- tests/unit/out/unsafe/constexpr_function.rs | 17 ++- tests/unit/out/unsafe/constructor.rs | 7 +- tests/unit/out/unsafe/container_field_addr.rs | 7 +- .../conversion_operator_same_translation.rs | 70 +++++++--- tests/unit/out/unsafe/copy_assign.rs | 53 +++++--- tests/unit/out/unsafe/copy_ctor.rs | 73 +++++++---- tests/unit/out/unsafe/copy_move_defaulted.rs | 107 ++++++++------- tests/unit/out/unsafe/copy_move_deleted.rs | 34 +++-- .../out/unsafe/default_function_arguments.rs | 5 +- tests/unit/out/unsafe/enum_underlying_type.rs | 5 +- .../unit/out/unsafe/field_method_receiver.rs | 5 +- tests/unit/out/unsafe/field_pointers.rs | 5 +- tests/unit/out/unsafe/fn_ptr_struct.rs | 10 +- tests/unit/out/unsafe/for_body_destructor.rs | 18 ++- .../unsafe/foreach_disjoint_field_borrow.rs | 5 +- tests/unit/out/unsafe/forward_basic.rs | 20 ++- tests/unit/out/unsafe/forward_decltype.rs | 10 +- tests/unit/out/unsafe/forward_explicit.rs | 25 +++- tests/unit/out/unsafe/forward_pack.rs | 20 ++- .../unit/out/unsafe/global_non_const_init.rs | 18 +-- tests/unit/out/unsafe/huffman.rs | 5 +- tests/unit/out/unsafe/implicit_autoref.rs | 5 +- .../out/unsafe/in_class_field_initializer.rs | 12 +- tests/unit/out/unsafe/init_list.rs | 10 +- .../out/unsafe/inline_container_fields.rs | 25 ++-- tests/unit/out/unsafe/kruskal.rs | 10 +- tests/unit/out/unsafe/lambda_as_field.rs | 9 +- .../out/unsafe/lambda_capture_copy_ctor.rs | 79 +++++------- tests/unit/out/unsafe/lambda_decltype_type.rs | 10 +- .../unit/out/unsafe/lambda_immediate_init.rs | 5 +- .../out/unsafe/lambda_move_only_capture.rs | 14 +- .../out/unsafe/libc_struct_without_default.rs | 5 +- tests/unit/out/unsafe/map.rs | 7 +- tests/unit/out/unsafe/map_key_copy_ctor.rs | 10 +- tests/unit/out/unsafe/map_key_identity.rs | 7 +- tests/unit/out/unsafe/map_try_emplace.rs | 52 +++++--- .../out/unsafe/map_try_emplace_lvalues.rs | 103 ++++++--------- tests/unit/out/unsafe/max.rs | 5 +- tests/unit/out/unsafe/move_assign.rs | 17 ++- tests/unit/out/unsafe/move_ctor.rs | 42 +++--- tests/unit/out/unsafe/move_this.rs | 22 ++-- .../out/unsafe/operator_comparison_nonbool.rs | 68 ++++++---- .../unit/out/unsafe/operator_other_member.rs | 95 ++++++++++++-- .../unsafe/pair_converting_construction.rs | 27 ++-- tests/unit/out/unsafe/push_emplace_back.rs | 21 +-- tests/unit/out/unsafe/rule_of_five.rs | 15 ++- tests/unit/out/unsafe/rule_of_three.rs | 5 +- tests/unit/out/unsafe/rvalue_rule_arg_move.rs | 10 +- .../unsafe/self_referencing_initializer.rs | 5 +- tests/unit/out/unsafe/sort_no_copy.rs | 24 ++-- tests/unit/out/unsafe/struct_ctor.rs | 7 +- tests/unit/out/unsafe/struct_default_ctor.rs | 24 ++-- .../unsafe/structured_binding_copy_ctor.rs | 10 +- .../unsafe/structured_binding_element_ctor.rs | 28 ++-- .../unsafe/structured_binding_move_ctor.rs | 20 ++- tests/unit/out/unsafe/swap_map_no_copy.rs | 55 ++++---- tests/unit/out/unsafe/template_default_arg.rs | 18 +-- tests/unit/out/unsafe/temporary_field_addr.rs | 12 +- .../out/unsafe/temporary_field_ctor_arg.rs | 5 +- .../out/unsafe/temporary_field_two_args.rs | 12 +- tests/unit/out/unsafe/typedef-anon-struct.rs | 5 +- tests/unit/out/unsafe/unboxed_records.rs | 5 +- tests/unit/out/unsafe/unique_ptr.rs | 5 +- .../unit/out/unsafe/unique_ptr_const_deref.rs | 5 +- .../unit/out/unsafe/unique_ptr_field_reset.rs | 5 +- tests/unit/out/unsafe/unique_ptr_nested.rs | 5 +- tests/unit/out/unsafe/vector.rs | 5 +- .../unit/out/unsafe/vector_iter_range_ctor.rs | 10 +- .../out/unsafe/vector_subscript_direct.rs | 5 +- tests/unit/out/unsafe/void_cast.rs | 10 +- 209 files changed, 2779 insertions(+), 1705 deletions(-) diff --git a/tests/multi-file/defaulted_move_cross_tu/out/refcount/defaulted_move_cross_tu.rs b/tests/multi-file/defaulted_move_cross_tu/out/refcount/defaulted_move_cross_tu.rs index d294eb6dd2..8e6f148fac 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 @@ -53,11 +53,12 @@ pub struct T { #[byte_size(24)] pub v: Vec, } -impl DefaultConstructible for T { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for T { + fn constructor(this: &Ptr, (): ()) { field!((*this), v).write(Vec::new()); } } +impl DefaultConstructible for T {} pub fn sum_0(s: Ptr) -> i32 { return ({ ({ (((*s.upgrade().deref()).v.len()) as i32) } + { (array_elem!(s, n, 0).read()) }) 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 58f7a326b7..984102319b 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 @@ -51,11 +51,12 @@ impl T { return ((self.v.len()) as i32); } } -impl DefaultConstructibleUnsafe for T { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for T { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.v).write(Vec::new()); } } +impl DefaultConstructibleUnsafe for T {} pub unsafe fn sum_0(s: *const S) -> i32 { return (((((*s).v.len()) as i32) + ((*s).n[(0) as usize])) + ((*s).n[(1) as usize])); } 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..615a895bf8 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 @@ -99,18 +99,20 @@ fn main_0() -> i32 { assert!((({ pair_diff_0((pair.as_pointer()),) }) == 4)); return 0; } -impl MoveConstructible for M { - fn move_constructor(this: &Ptr, _a0: RvalueRef) { +impl ConstructibleFrom<(RvalueRef,)> for M { + fn 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: LvalueRef>) { +impl MoveConstructible for M {} +impl ConstructibleFrom<(LvalueRef>,)> for M { + fn constructor(this: &Ptr, (o,): (LvalueRef>,)) { let o = o.as_pointer(); field!((*this), v).write((o.with(|__s| __s.v) + 1)); } } +impl CopyConstructible for M {} impl S {} impl Destructible for S { fn destroy(this: &Ptr) {} 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..2c07def7f3 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 @@ -107,18 +107,20 @@ impl M { (&raw mut self.v).write(x); } } -impl MoveConstructibleUnsafe for M { - unsafe fn move_constructor(&mut self, _a0: RvalueRefUnsafe) { +impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for M { + unsafe fn 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: LvalueRefUnsafe>) { +impl MoveConstructibleUnsafe for M {} +impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for M { + unsafe fn constructor(&mut self, (o,): (LvalueRefUnsafe>,)) { let o = (o.as_ptr() as *const M); (&raw mut self.v).write((((*o).v) + (1))); } } +impl CopyConstructibleUnsafe for M {} impl Derived { pub unsafe fn construct(&mut self, mut factor: i32) { (&raw mut self.factor).write(factor); diff --git a/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs b/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs index 8db93d594b..ab68cbb367 100644 --- a/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs +++ b/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs @@ -12,11 +12,12 @@ pub struct S_int_ { #[offset(0)] pub x: i32, } -impl DefaultConstructible for S_int_ { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for S_int_ { + fn constructor(this: &Ptr, (): ()) { field!((*this), x).write(0); } } +impl DefaultConstructible for S_int_ {} impl Default for S_int_ { fn default() -> Self { { S_int_ { x: 0 } } diff --git a/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs b/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs index 8e77fce3de..b3dfd51f7e 100644 --- a/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs +++ b/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs @@ -16,11 +16,12 @@ impl S_int_ { self.x = v; } } -impl DefaultConstructibleUnsafe for S_int_ { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for S_int_ { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.x).write(0); } } +impl DefaultConstructibleUnsafe for S_int_ {} impl Default for S_int_ { fn default() -> Self { unsafe { S_int_ { x: 0 } } 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..7f4aa04e82 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 @@ -54,19 +54,21 @@ impl LifetimeTracked { }); } } -impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for LifetimeTracked { + fn 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>) { +impl DefaultConstructible for LifetimeTracked {} +impl ConstructibleFrom<(LvalueRef>,)> for LifetimeTracked { + fn constructor(this: &Ptr, (_a0,): (LvalueRef>,)) { let _a0 = _a0.as_pointer(); field!((*this), uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl CopyConstructible for LifetimeTracked {} impl Destructible for LifetimeTracked { fn destroy(this: &Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); @@ -108,7 +110,7 @@ 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()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -140,7 +142,7 @@ 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()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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..6cb93e0260 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 @@ -41,19 +41,21 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } -impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for LifetimeTracked { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.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>) { +impl DefaultConstructibleUnsafe for LifetimeTracked {} +impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for LifetimeTracked { + unsafe fn 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(); } } +impl CopyConstructibleUnsafe for LifetimeTracked {} impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -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); + >::constructor(&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); + >::constructor(&mut __v, ()); __v }; libcc2rs::register_static_destructor(|| { 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..d2b3ef685a 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 @@ -54,19 +54,21 @@ impl LifetimeTracked { }); } } -impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for LifetimeTracked { + fn 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>) { +impl DefaultConstructible for LifetimeTracked {} +impl ConstructibleFrom<(LvalueRef>,)> for LifetimeTracked { + fn constructor(this: &Ptr, (_a0,): (LvalueRef>,)) { let _a0 = _a0.as_pointer(); field!((*this), uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl CopyConstructible for LifetimeTracked {} impl Destructible for LifetimeTracked { fn destroy(this: &Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); @@ -76,7 +78,7 @@ 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()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -103,7 +105,7 @@ 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()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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..72e708b2ee 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 @@ -41,19 +41,21 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } -impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for LifetimeTracked { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.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>) { +impl DefaultConstructibleUnsafe for LifetimeTracked {} +impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for LifetimeTracked { + unsafe fn 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(); } } +impl CopyConstructibleUnsafe for LifetimeTracked {} impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -64,7 +66,7 @@ pub static mut member_4: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + >::constructor(&mut __v, ()); __v }; libcc2rs::register_static_destructor(|| { @@ -90,7 +92,7 @@ pub static mut member_5: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + >::constructor(&mut __v, ()); __v }; libcc2rs::register_static_destructor(|| { 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..1cd8d3ee42 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 @@ -54,19 +54,21 @@ impl LifetimeTracked { }); } } -impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for LifetimeTracked { + fn 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>) { +impl DefaultConstructible for LifetimeTracked {} +impl ConstructibleFrom<(LvalueRef>,)> for LifetimeTracked { + fn constructor(this: &Ptr, (_a0,): (LvalueRef>,)) { let _a0 = _a0.as_pointer(); field!((*this), uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl CopyConstructible for LifetimeTracked {} impl Destructible for LifetimeTracked { fn destroy(this: &Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); @@ -108,7 +110,7 @@ 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()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -124,7 +126,7 @@ 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()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -140,7 +142,7 @@ 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()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -200,7 +202,7 @@ 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()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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..b1e0b823c3 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 @@ -41,19 +41,21 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } -impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for LifetimeTracked { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.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>) { +impl DefaultConstructibleUnsafe for LifetimeTracked {} +impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for LifetimeTracked { + unsafe fn 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(); } } +impl CopyConstructibleUnsafe for LifetimeTracked {} impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -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); + >::constructor(&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); + >::constructor(&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); + >::constructor(&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); + >::constructor(&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..92dc226b24 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 @@ -54,19 +54,21 @@ impl LifetimeTracked { }); } } -impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for LifetimeTracked { + fn 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>) { +impl DefaultConstructible for LifetimeTracked {} +impl ConstructibleFrom<(LvalueRef>,)> for LifetimeTracked { + fn constructor(this: &Ptr, (_a0,): (LvalueRef>,)) { let _a0 = _a0.as_pointer(); field!((*this), uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl CopyConstructible for LifetimeTracked {} impl Destructible for LifetimeTracked { fn destroy(this: &Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); @@ -102,7 +104,7 @@ 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()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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..27e3b61c67 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 @@ -41,19 +41,21 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } -impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for LifetimeTracked { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.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>) { +impl DefaultConstructibleUnsafe for LifetimeTracked {} +impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for LifetimeTracked { + unsafe fn 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(); } } +impl CopyConstructibleUnsafe for LifetimeTracked {} impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -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); + >::constructor(&mut __v, ()); __v }; libcc2rs::register_static_destructor(|| { 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..3a68d37d82 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 @@ -54,19 +54,21 @@ impl LifetimeTracked { }); } } -impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for LifetimeTracked { + fn 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>) { +impl DefaultConstructible for LifetimeTracked {} +impl ConstructibleFrom<(LvalueRef>,)> for LifetimeTracked { + fn constructor(this: &Ptr, (_a0,): (LvalueRef>,)) { let _a0 = _a0.as_pointer(); field!((*this), uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl CopyConstructible for LifetimeTracked {} impl Destructible for LifetimeTracked { fn destroy(this: &Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); @@ -108,7 +110,7 @@ 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()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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..0e15654f89 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 @@ -41,19 +41,21 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } -impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for LifetimeTracked { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.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>) { +impl DefaultConstructibleUnsafe for LifetimeTracked {} +impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for LifetimeTracked { + unsafe fn 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(); } } +impl CopyConstructibleUnsafe for LifetimeTracked {} impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -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); + >::constructor(&mut __v, ()); __v }; libcc2rs::register_static_destructor(|| { 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..569ff50e0f 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 @@ -54,19 +54,21 @@ impl LifetimeTracked { }); } } -impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for LifetimeTracked { + fn 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>) { +impl DefaultConstructible for LifetimeTracked {} +impl ConstructibleFrom<(LvalueRef>,)> for LifetimeTracked { + fn constructor(this: &Ptr, (_a0,): (LvalueRef>,)) { let _a0 = _a0.as_pointer(); field!((*this), uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl CopyConstructible for LifetimeTracked {} impl Destructible for LifetimeTracked { fn destroy(this: &Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); @@ -113,7 +115,7 @@ 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()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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..d7abd3b956 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 @@ -41,19 +41,21 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } -impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for LifetimeTracked { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.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>) { +impl DefaultConstructibleUnsafe for LifetimeTracked {} +impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for LifetimeTracked { + unsafe fn 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(); } } +impl CopyConstructibleUnsafe for LifetimeTracked {} impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -116,7 +118,7 @@ static mut local_4: std::cell::LazyCell = std::cell::LazyCell:: { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + >::constructor(&mut __v, ()); __v }; libcc2rs::register_static_destructor(|| { 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..8abb4a4aae 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 @@ -54,19 +54,21 @@ impl LifetimeTracked { }); } } -impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for LifetimeTracked { + fn 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>) { +impl DefaultConstructible for LifetimeTracked {} +impl ConstructibleFrom<(LvalueRef>,)> for LifetimeTracked { + fn constructor(this: &Ptr, (_a0,): (LvalueRef>,)) { let _a0 = _a0.as_pointer(); field!((*this), uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl CopyConstructible for LifetimeTracked {} impl Destructible for LifetimeTracked { fn destroy(this: &Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); @@ -113,7 +115,7 @@ 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()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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..fa4f727082 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 @@ -41,19 +41,21 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } -impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for LifetimeTracked { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.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>) { +impl DefaultConstructibleUnsafe for LifetimeTracked {} +impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for LifetimeTracked { + unsafe fn 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(); } } +impl CopyConstructibleUnsafe for LifetimeTracked {} impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -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); + >::constructor(&mut __v, ()); __v }; libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/basic.link/out/refcount/basic.link.rs b/tests/std/basic/basic.link/out/refcount/basic.link.rs index ccf5fccdfa..b20139d39d 100644 --- a/tests/std/basic/basic.link/out/refcount/basic.link.rs +++ b/tests/std/basic/basic.link/out/refcount/basic.link.rs @@ -81,11 +81,12 @@ pub struct Record_19 { #[offset(0)] pub id: i32, } -impl DefaultConstructible for Record_19 { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Record_19 { + fn constructor(this: &Ptr, (): ()) { field!((*this), id).write(100); } } +impl DefaultConstructible for Record_19 {} impl Default for Record_19 { fn default() -> Self { { Record_19 { id: 100 } } @@ -224,11 +225,12 @@ pub struct Entry_52 { #[offset(0)] pub key: i32, } -impl DefaultConstructible for Entry_52 { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Entry_52 { + fn constructor(this: &Ptr, (): ()) { field!((*this), key).write(1); } } +impl DefaultConstructible for Entry_52 {} impl Default for Entry_52 { fn default() -> Self { { Entry_52 { key: 1 } } @@ -242,12 +244,13 @@ pub struct Entry_54 { #[offset(4)] pub value: i32, } -impl DefaultConstructible for Entry_54 { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Entry_54 { + fn constructor(this: &Ptr, (): ()) { field!((*this), key).write(2); field!((*this), value).write(30); } } +impl DefaultConstructible for Entry_54 {} impl Default for Entry_54 { fn default() -> Self { { Entry_54 { key: 2, value: 30 } } @@ -366,12 +369,13 @@ pub struct Record_65 { #[offset(8)] pub extra: i32, } -impl DefaultConstructible for Record_65 { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Record_65 { + fn constructor(this: &Ptr, (): ()) { field!((*this), id).write(200_i64); field!((*this), extra).write(1); } } +impl DefaultConstructible for Record_65 {} impl Default for Record_65 { fn default() -> Self { { @@ -467,11 +471,12 @@ pub struct Entry_71 { #[offset(0)] pub key: i64, } -impl DefaultConstructible for Entry_71 { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Entry_71 { + fn constructor(this: &Ptr, (): ()) { field!((*this), key).write(400_i64); } } +impl DefaultConstructible for Entry_71 {} impl Default for Entry_71 { fn default() -> Self { { Entry_71 { key: 400_i64 } } diff --git a/tests/std/basic/basic.link/out/unsafe/basic.link.rs b/tests/std/basic/basic.link/out/unsafe/basic.link.rs index 81795fc7bc..3b7d8b1363 100644 --- a/tests/std/basic/basic.link/out/unsafe/basic.link.rs +++ b/tests/std/basic/basic.link/out/unsafe/basic.link.rs @@ -72,11 +72,12 @@ pub unsafe fn bump_18() -> i32 { pub struct Record_19 { pub id: i32, } -impl DefaultConstructibleUnsafe for Record_19 { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for Record_19 { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.id).write(100); } } +impl DefaultConstructibleUnsafe for Record_19 {} impl Default for Record_19 { fn default() -> Self { unsafe { Record_19 { id: 100 } } @@ -206,11 +207,12 @@ pub unsafe fn test_55() { pub struct Entry_52 { pub key: i32, } -impl DefaultConstructibleUnsafe for Entry_52 { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for Entry_52 { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.key).write(1); } } +impl DefaultConstructibleUnsafe for Entry_52 {} impl Default for Entry_52 { fn default() -> Self { unsafe { Entry_52 { key: 1 } } @@ -222,12 +224,13 @@ pub struct Entry_54 { pub key: i32, pub value: i32, } -impl DefaultConstructibleUnsafe for Entry_54 { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for Entry_54 { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.key).write(2); (&raw mut self.value).write(30); } } +impl DefaultConstructibleUnsafe for Entry_54 {} impl Default for Entry_54 { fn default() -> Self { unsafe { Entry_54 { key: 2, value: 30 } } @@ -321,12 +324,13 @@ pub struct Record_65 { pub id: i64, pub extra: i32, } -impl DefaultConstructibleUnsafe for Record_65 { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for Record_65 { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.id).write(200_i64); (&raw mut self.extra).write(1); } } +impl DefaultConstructibleUnsafe for Record_65 {} impl Default for Record_65 { fn default() -> Self { unsafe { @@ -410,11 +414,12 @@ pub unsafe fn key_in_b_56() -> i32 { pub struct Entry_71 { pub key: i64, } -impl DefaultConstructibleUnsafe for Entry_71 { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for Entry_71 { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.key).write(400_i64); } } +impl DefaultConstructibleUnsafe for Entry_71 {} impl Default for Entry_71 { fn default() -> Self { unsafe { Entry_71 { key: 400_i64 } } 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..efd6d0f029 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 @@ -54,19 +54,21 @@ impl LifetimeTracked { }); } } -impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for LifetimeTracked { + fn 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>) { +impl DefaultConstructible for LifetimeTracked {} +impl ConstructibleFrom<(LvalueRef>,)> for LifetimeTracked { + fn constructor(this: &Ptr, (_a0,): (LvalueRef>,)) { let _a0 = _a0.as_pointer(); field!((*this), uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl CopyConstructible for LifetimeTracked {} impl Destructible for LifetimeTracked { fn destroy(this: &Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); @@ -99,6 +101,21 @@ pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { #[offset(0)] pub value: i32, } +impl + ConversionFunction< + bool, + LvalueRef>, + > for p1_1_condition_variable_visible_in_else_ConvertsToBool +{ + fn conversion_function( + this: LvalueRef>, + to: Ptr, + ) { + let this = &this.as_pointer(); + to.write(((*this).with(|__s| __s.value) != 0)); + return; + } +} impl Destructible for p1_1_condition_variable_visible_in_else_ConvertsToBool { fn destroy(this: &Ptr) { (*dtorCount_6.with(Value::clone).borrow_mut()).prefix_inc(); @@ -112,11 +129,19 @@ pub fn test_7() { let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| { Destructible::destroy(&__p.as_pointer()) }); - if ({ - p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl::to_bool( - &condition.as_pointer(), - ) - }) { + if { + let __v: Value = Rc::new(RefCell::new(false)); + >, + >>::conversion_function( + >>::bind( + condition.as_pointer(), + ), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } { (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); } else { (*else_runs_5.with(Value::clone).borrow_mut()).prefix_inc(); @@ -134,11 +159,19 @@ pub fn test_7() { let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| { Destructible::destroy(&__p.as_pointer()) }); - if ({ - p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl::to_bool( - &condition.as_pointer(), - ) - }) { + if { + let __v: Value = Rc::new(RefCell::new(false)); + >, + >>::conversion_function( + >>::bind( + condition.as_pointer(), + ), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } { (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); assert!(({ (*condition.borrow()).value } == 6)); assert!((dtorCount_6.with(|rc| *rc.borrow()) == 1)); @@ -318,16 +351,6 @@ impl LifetimeTrackedImpl for Ptr { (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } } -pub trait p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl { - fn to_bool(&self) -> bool; -} -impl p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl - for Ptr -{ - fn to_bool(&self) -> bool { - return ((*self).with(|__s| __s.value) != 0); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs index 9e43302a64..4be548207e 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs @@ -15,11 +15,12 @@ pub struct p1_member_hides_namespace_variable_HasBalance { #[offset(0)] pub balance: i32, } -impl DefaultConstructible for p1_member_hides_namespace_variable_HasBalance { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for p1_member_hides_namespace_variable_HasBalance { + fn constructor(this: &Ptr, (): ()) { field!((*this), balance).write(7); } } +impl DefaultConstructible for p1_member_hides_namespace_variable_HasBalance {} impl Default for p1_member_hides_namespace_variable_HasBalance { fn default() -> Self { { p1_member_hides_namespace_variable_HasBalance { balance: 7 } } @@ -54,11 +55,12 @@ pub struct p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { #[offset(0)] pub held: i32, } -impl DefaultConstructible for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { + fn constructor(this: &Ptr, (): ()) { field!((*this), held).write(1); } } +impl DefaultConstructible for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal {} impl Default for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { fn default() -> Self { { p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { held: 1 } } diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs index 7d4bc28b97..4f2bd88f93 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs @@ -90,8 +90,8 @@ pub struct p9_func_declared_before_function_body_RecordsConstructorName { #[byte_size(8)] pub name: Ptr, } -impl DefaultConstructible for p9_func_declared_before_function_body_RecordsConstructorName { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for p9_func_declared_before_function_body_RecordsConstructorName { + fn constructor(this: &Ptr, (): ()) { field!((*this), name).write(Ptr::::from_string_literal(b"RecordsConstructorName")); assert!( ((*this).with(|__s| __s.name.clone()) @@ -99,6 +99,7 @@ impl DefaultConstructible for p9_func_declared_before_function_body_RecordsConst ); } } +impl DefaultConstructible for p9_func_declared_before_function_body_RecordsConstructorName {} impl Default for p9_func_declared_before_function_body_RecordsConstructorName { fn default() -> Self { { @@ -107,7 +108,7 @@ impl Default for p9_func_declared_before_function_body_RecordsConstructorName { Rc::new(RefCell::new( ::zero_init(), )); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()) ; Rc::try_unwrap(__v).ok().unwrap().into_inner() } } diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs index 61044feeba..5cfbc12472 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs @@ -260,12 +260,13 @@ pub struct p3_2_const_qualified_member_is_distinct_HasConstOverload { #[offset(4)] pub const_calls: i32, } -impl DefaultConstructible for p3_2_const_qualified_member_is_distinct_HasConstOverload { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for p3_2_const_qualified_member_is_distinct_HasConstOverload { + fn constructor(this: &Ptr, (): ()) { field!((*this), plain_calls).write(0); field!((*this), const_calls).write(0); } } +impl DefaultConstructible for p3_2_const_qualified_member_is_distinct_HasConstOverload {} impl Default for p3_2_const_qualified_member_is_distinct_HasConstOverload { fn default() -> Self { { @@ -309,13 +310,17 @@ pub struct p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjec #[offset(0)] pub base: i32, } -impl DefaultConstructible +impl ConstructibleFrom<()> for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { - fn default_constructor(this: &Ptr) { + fn constructor(this: &Ptr, (): ()) { field!((*this), base).write(10); } } +impl DefaultConstructible + for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload +{ +} impl Default for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { fn default() -> Self { { @@ -341,7 +346,7 @@ pub fn test_15() { let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); assert!( (({ - p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverloadImpl :: pick_2 ( &{ DefaultConstructible::default_constructor(&__tmp_0.as_pointer()) ; __tmp_0.as_pointer() } , 2 , ) + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverloadImpl :: pick_2 ( &{ >::constructor(&__tmp_0.as_pointer(), ()) ; __tmp_0.as_pointer() } , 2 , ) }) == 112) ) }; @@ -411,14 +416,18 @@ pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOv #[offset(4)] pub const_calls: i32, } -impl DefaultConstructible +impl ConstructibleFrom<()> for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { - fn default_constructor(this: &Ptr) { + fn constructor(this: &Ptr, (): ()) { field!((*this), plain_calls).write(0); field!((*this), const_calls).write(0); } } +impl DefaultConstructible + for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload +{ +} impl Default for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { fn default() -> Self { { 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..7169702957 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 @@ -41,19 +41,21 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } -impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for LifetimeTracked { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.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>) { +impl DefaultConstructibleUnsafe for LifetimeTracked {} +impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for LifetimeTracked { + unsafe fn 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(); } } +impl CopyConstructibleUnsafe for LifetimeTracked {} impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -79,9 +81,21 @@ pub static mut dtorCount_6: std::cell::LazyCell = std::cell::LazyCell::new( 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)); +impl + ConversionFunctionUnsafe< + bool, + LvalueRefUnsafe>, + > for p1_1_condition_variable_visible_in_else_ConvertsToBool +{ + unsafe fn conversion_function( + this: LvalueRefUnsafe>, + to: *mut bool, + ) { + let this = unsafe { + &*(this.as_ptr() as *const p1_1_condition_variable_visible_in_else_ConvertsToBool) + }; + to.write(((this.value) != (0))); + return; } } impl DestructibleUnsafe for p1_1_condition_variable_visible_in_else_ConvertsToBool { @@ -96,8 +110,11 @@ pub unsafe fn test_7() { let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { DestructibleUnsafe::destroy(&mut *__p) }); - if (unsafe { p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(&condition) }) - { + if { + let mut __v: bool = false; + >>>::conversion_function(>>::bind(& mut condition ), &mut __v); + __v + } { (*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(); @@ -114,8 +131,11 @@ pub unsafe fn test_7() { let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { DestructibleUnsafe::destroy(&mut *__p) }); - if (unsafe { p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(&condition) }) - { + if { + let mut __v: bool = false; + >>>::conversion_function(>>::bind(& mut condition ), &mut __v); + __v + } { (*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))); diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs index f6bfd2af94..fdae91b4fa 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs @@ -22,11 +22,12 @@ impl p1_member_hides_namespace_variable_HasBalance { return (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_0)); } } -impl DefaultConstructibleUnsafe for p1_member_hides_namespace_variable_HasBalance { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for p1_member_hides_namespace_variable_HasBalance { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.balance).write(7); } } +impl DefaultConstructibleUnsafe for p1_member_hides_namespace_variable_HasBalance {} impl Default for p1_member_hides_namespace_variable_HasBalance { fn default() -> Self { unsafe { p1_member_hides_namespace_variable_HasBalance { balance: 7 } } @@ -54,11 +55,12 @@ pub static mut initial_2: std::cell::LazyCell = std::cell::LazyCell::new(|| pub struct p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { pub held: i32, } -impl DefaultConstructibleUnsafe for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.held).write(1); } } +impl DefaultConstructibleUnsafe for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal {} impl Default for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { fn default() -> Self { unsafe { p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { held: 1 } } diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs index 39cdf52ee8..04deb84ad2 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs @@ -85,19 +85,20 @@ pub const anon_4_above: anon_4 = 14; pub struct p9_func_declared_before_function_body_RecordsConstructorName { pub name: *const libc::c_char, } -impl DefaultConstructibleUnsafe for p9_func_declared_before_function_body_RecordsConstructorName { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for p9_func_declared_before_function_body_RecordsConstructorName { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.name).write(c"RecordsConstructorName".as_ptr()); assert!(((self.name) == (c"RecordsConstructorName".as_ptr()))); } } +impl DefaultConstructibleUnsafe for p9_func_declared_before_function_body_RecordsConstructorName {} impl Default for p9_func_declared_before_function_body_RecordsConstructorName { fn default() -> Self { unsafe { { let mut __v: p9_func_declared_before_function_body_RecordsConstructorName = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + >::constructor(&mut __v, ()) ; __v } } diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs index ee2c27079b..cdc28dc433 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs @@ -223,12 +223,13 @@ impl p3_2_const_qualified_member_is_distinct_HasConstOverload { return 2; } } -impl DefaultConstructibleUnsafe for p3_2_const_qualified_member_is_distinct_HasConstOverload { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for p3_2_const_qualified_member_is_distinct_HasConstOverload { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.plain_calls).write(0); (&raw mut self.const_calls).write(0); } } +impl DefaultConstructibleUnsafe for p3_2_const_qualified_member_is_distinct_HasConstOverload {} impl Default for p3_2_const_qualified_member_is_distinct_HasConstOverload { fn default() -> Self { unsafe { @@ -281,13 +282,17 @@ impl p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverl return (((self.base) + (amount)) + (100)); } } -impl DefaultConstructibleUnsafe +impl ConstructibleFromUnsafe<()> for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { - unsafe fn default_constructor(&mut self) { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.base).write(10); } } +impl DefaultConstructibleUnsafe + for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload +{ +} impl Default for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { fn default() -> Self { unsafe { @@ -316,7 +321,7 @@ pub unsafe fn test_15() { let mut __tmp_0: p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload = ::zero_init(); assert!( ((unsafe { - p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( &mut (*{ DefaultConstructibleUnsafe::default_constructor(&mut __tmp_0) ; & mut __tmp_0 } ) , 2 , ) + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( &mut (*{ >::constructor(&mut __tmp_0, ()) ; & mut __tmp_0 } ) , 2 , ) }) == (112)) ) }; @@ -392,14 +397,18 @@ impl p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload return ((value) + (2)); } } -impl DefaultConstructibleUnsafe +impl ConstructibleFromUnsafe<()> for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { - unsafe fn default_constructor(&mut self) { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.plain_calls).write(0); (&raw mut self.const_calls).write(0); } } +impl DefaultConstructibleUnsafe + for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload +{ +} impl Default for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { fn default() -> Self { unsafe { diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index 737101c440..bc2baca445 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -34,13 +34,14 @@ impl HasConstexprCtor { copyCount_0.with(|rc| *rc.borrow_mut() = 0); } } -impl CopyConstructible for HasConstexprCtor { - fn copy_constructor(this: &Ptr, o: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> for HasConstexprCtor { + fn 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(); } } +impl CopyConstructible for HasConstexprCtor {} thread_local!( pub static ctorCount_1: Value = Rc::new(RefCell::new(0)); ); @@ -89,19 +90,21 @@ impl LifetimeTracked { }); } } -impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for LifetimeTracked { + fn 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>) { +impl DefaultConstructible for LifetimeTracked {} +impl ConstructibleFrom<(LvalueRef>,)> for LifetimeTracked { + fn constructor(this: &Ptr, (_a0,): (LvalueRef>,)) { let _a0 = _a0.as_pointer(); field!((*this), uses).write(0); (*copyCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl CopyConstructible for LifetimeTracked {} impl Destructible for LifetimeTracked { fn destroy(this: &Ptr) { (*dtorCount_3.with(Value::clone).borrow_mut()).prefix_inc(); @@ -263,7 +266,7 @@ 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()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -293,10 +296,7 @@ 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()), - ); + >,)>>::constructor(&__v.as_pointer(), (LvalueRef::bind((r ).clone() ),)) ; Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -333,10 +333,7 @@ pub fn test_16() { let k: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor( - &__v.as_pointer(), - LvalueRef::bind(k.as_pointer()), - ); + >,)>>::constructor(&__v.as_pointer(), (LvalueRef::bind(k .as_pointer() ),)) ; Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -384,10 +381,12 @@ pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { #[offset(4)] pub scratch: i32, } -impl CopyConstructible for p5_2_mutable_subobject_is_odr_used_HasMutableMember { - fn copy_constructor( +impl ConstructibleFrom<(LvalueRef>,)> + for p5_2_mutable_subobject_is_odr_used_HasMutableMember +{ + fn constructor( this: &Ptr, - o: LvalueRef>, + (o,): (LvalueRef>,), ) { let o = o.as_pointer(); field!((*this), value).write(o.with(|__s| __s.value)); @@ -395,6 +394,7 @@ impl CopyConstructible for p5_2_mutable_subobject_is_odr_used_HasMutableMember { (*copies_18.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl CopyConstructible for p5_2_mutable_subobject_is_odr_used_HasMutableMember {} pub fn test_19() { object!(k, p5_2_mutable_subobject_is_odr_used_HasMutableMember(5)); let f: Value i32>> = Rc::new(RefCell::new(lambda!( @@ -405,9 +405,10 @@ pub fn test_19() { Rc::new(RefCell::new( ::zero_init(), )); - CopyConstructible::copy_constructor( - &__v.as_pointer(), - LvalueRef::bind(k.as_pointer()), + >, + )>>::constructor( + &__v.as_pointer(), (LvalueRef::bind(k.as_pointer()),) ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); @@ -433,12 +434,13 @@ pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { #[destroy] 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)); +impl ConstructibleFrom<()> for p6_unevaluated_binding_needs_no_capture_HasTwoMembers { + fn constructor(this: &Ptr, (): ()) { + >::constructor(&field_ptr!(this, a), ()); + >::constructor(&field_ptr!(this, b), ()); } } +impl DefaultConstructible for p6_unevaluated_binding_needs_no_capture_HasTwoMembers {} pub fn test_20() { ({ LifetimeTracked::reset() }); let p: Value = Rc::new(RefCell::new( @@ -446,13 +448,13 @@ pub fn test_20() { a: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::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()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, }, @@ -482,12 +484,13 @@ pub struct p7_member_access_captures_this_HasMemberUsedInLambda { #[offset(4)] pub n: i32, } -impl DefaultConstructible for p7_member_access_captures_this_HasMemberUsedInLambda { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, x)); +impl ConstructibleFrom<()> for p7_member_access_captures_this_HasMemberUsedInLambda { + fn constructor(this: &Ptr, (): ()) { + >::constructor(&field_ptr!(this, x), ()); field!((*this), n).write(1); } } +impl DefaultConstructible for p7_member_access_captures_this_HasMemberUsedInLambda {} pub fn test_22() { ({ LifetimeTracked::reset() }); object!(c, p7_member_access_captures_this_HasMemberUsedInLambda); @@ -511,11 +514,12 @@ pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { #[destroy] pub x: LifetimeTracked, } -impl DefaultConstructible for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, x)); +impl ConstructibleFrom<()> for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { + fn constructor(this: &Ptr, (): ()) { + >::constructor(&field_ptr!(this, x), ()); } } +impl DefaultConstructible for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda {} pub fn test_23() { ({ LifetimeTracked::reset() }); object!( @@ -568,16 +572,17 @@ thread_local!( #[memberwise(copy_assign)] #[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) { +impl ConstructibleFrom<()> for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { + fn constructor(this: &Ptr, (): ()) { (*t_ctors_27.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl DefaultConstructible for p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} pub fn test_28() { let mut p: Ptr = { let __p = Ptr::alloc(::zero_init()); - DefaultConstructible::default_constructor(&__p); + >::constructor(&__p, ()) ; __p }; assert!(!((p).is_null())); @@ -603,12 +608,13 @@ pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { #[offset(0)] pub value: i32, } -impl DefaultConstructible for p9_unused_copy_constructor_HasUndefinedCopyCtor { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for p9_unused_copy_constructor_HasUndefinedCopyCtor { + fn constructor(this: &Ptr, (): ()) { field!((*this), value).write(3); (*ctor_calls_29.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl DefaultConstructible for p9_unused_copy_constructor_HasUndefinedCopyCtor {} impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { fn default() -> Self { { @@ -616,7 +622,7 @@ impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()) ; Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -647,11 +653,12 @@ 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) { +impl ConstructibleFrom<()> for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { + fn constructor(this: &Ptr, (): ()) { (*m_ctors_32.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl DefaultConstructible for p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { fn default() -> Self { { @@ -660,7 +667,9 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { Rc::new(RefCell::new( ::zero_init(), )); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -684,11 +693,12 @@ pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { #[byte_size(1)] 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)); +impl ConstructibleFrom<()> for p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { + fn constructor(this: &Ptr, (): ()) { + >::constructor(&field_ptr!(this, m), ()) ; } } +impl DefaultConstructible for p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment {} pub fn test_33() { object!( a, @@ -838,13 +848,16 @@ impl Destructible for p9_destructor_not_potentially_invoked_HasUndefinedDestruct ) } } -impl CopyConstructible for p9_unused_copy_constructor_HasUndefinedCopyCtor { - fn copy_constructor(this: &Ptr, _: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> + for p9_unused_copy_constructor_HasUndefinedCopyCtor +{ + fn constructor(this: &Ptr, _: (LvalueRef>,)) { unreachable!( "p9_unused_copy_constructor_HasUndefinedCopyCtor::copy_constructor is never defined" ) } } +impl CopyConstructible for p9_unused_copy_constructor_HasUndefinedCopyCtor {} impl CopyAssignable for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { fn copy_assign(this: &Ptr, _: LvalueRef>) -> Ptr { unreachable!( diff --git a/tests/std/basic/out/unsafe/basic.def.odr.rs b/tests/std/basic/out/unsafe/basic.def.odr.rs index bef0dd041c..01064541b3 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -32,13 +32,14 @@ impl HasConstexprCtor { (&raw mut self.m).write(v); } } -impl CopyConstructibleUnsafe for HasConstexprCtor { - unsafe fn copy_constructor(&mut self, o: LvalueRefUnsafe>) { +impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for HasConstexprCtor { + unsafe fn 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(); } } +impl CopyConstructibleUnsafe for HasConstexprCtor {} pub static mut ctorCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut copyCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut dtorCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); @@ -74,19 +75,21 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)).prefix_inc(); } } -impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for LifetimeTracked { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.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>) { +impl DefaultConstructibleUnsafe for LifetimeTracked {} +impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for LifetimeTracked { + unsafe fn 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(); } } +impl CopyConstructibleUnsafe for LifetimeTracked {} impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_3)).prefix_inc(); @@ -224,7 +227,7 @@ pub static mut global_12: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + >::constructor(&mut __v, ()); __v }; libcc2rs::register_static_destructor(|| { @@ -257,7 +260,9 @@ pub unsafe fn test_14() { { let r: LifetimeTracked = { let mut __v: LifetimeTracked = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&mut __v, LvalueRefUnsafe::bind(r)); + >, + )>>::constructor(&mut __v, (LvalueRefUnsafe::bind(r),)); __v }; }, @@ -294,7 +299,9 @@ pub unsafe fn test_16() { { let k: HasConstexprCtor = { let mut __v: HasConstexprCtor = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&mut __v, LvalueRefUnsafe::bind(&k)); + >, + )>>::constructor(&mut __v, (LvalueRefUnsafe::bind(&k),)); __v }; }, @@ -341,10 +348,12 @@ impl p5_2_mutable_subobject_is_odr_used_HasMutableMember { (&raw mut self.scratch).write(0); } } -impl CopyConstructibleUnsafe for p5_2_mutable_subobject_is_odr_used_HasMutableMember { - unsafe fn copy_constructor( +impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> + for p5_2_mutable_subobject_is_odr_used_HasMutableMember +{ + unsafe fn constructor( &mut self, - o: LvalueRefUnsafe>, + (o,): (LvalueRefUnsafe>,), ) { let o = (o.as_ptr() as *const p5_2_mutable_subobject_is_odr_used_HasMutableMember); (&raw mut self.value).write((*o).value); @@ -352,6 +361,7 @@ impl CopyConstructibleUnsafe for p5_2_mutable_subobject_is_odr_used_HasMutableMe (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_18)).prefix_inc(); } } +impl CopyConstructibleUnsafe for p5_2_mutable_subobject_is_odr_used_HasMutableMember {} pub unsafe fn test_19() { object_unsafe!(k, p5_2_mutable_subobject_is_odr_used_HasMutableMember(5)); let mut f: FnPtr i32> = lambda_unsafe!( @@ -359,7 +369,9 @@ 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)); + >,), + >>::constructor(&mut __v, (LvalueRefUnsafe::bind(&k),)); __v }; }, @@ -382,24 +394,25 @@ pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { #[destroy] 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); +impl ConstructibleFromUnsafe<()> for p6_unevaluated_binding_needs_no_capture_HasTwoMembers { + unsafe fn constructor(&mut self, (): ()) { + >::constructor(&mut self.a, ()); + >::constructor(&mut self.b, ()); } } +impl DefaultConstructibleUnsafe for p6_unevaluated_binding_needs_no_capture_HasTwoMembers {} pub unsafe fn test_20() { (unsafe { LifetimeTracked::reset() }); let mut p: p6_unevaluated_binding_needs_no_capture_HasTwoMembers = p6_unevaluated_binding_needs_no_capture_HasTwoMembers { a: { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + >::constructor(&mut __v, ()); __v }, b: { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + >::constructor(&mut __v, ()); __v }, }; @@ -441,12 +454,13 @@ impl p7_member_access_captures_this_HasMemberUsedInLambda { ); } } -impl DefaultConstructibleUnsafe for p7_member_access_captures_this_HasMemberUsedInLambda { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.x); +impl ConstructibleFromUnsafe<()> for p7_member_access_captures_this_HasMemberUsedInLambda { + unsafe fn constructor(&mut self, (): ()) { + >::constructor(&mut self.x, ()); (&raw mut self.n).write(1); } } +impl DefaultConstructibleUnsafe for p7_member_access_captures_this_HasMemberUsedInLambda {} pub unsafe fn test_22() { (unsafe { LifetimeTracked::reset() }); object_unsafe!(c, p7_member_access_captures_this_HasMemberUsedInLambda); @@ -478,11 +492,12 @@ 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); +impl ConstructibleFromUnsafe<()> for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { + unsafe fn constructor(&mut self, (): ()) { + >::constructor(&mut self.x, ()); } } +impl DefaultConstructibleUnsafe for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda {} pub unsafe fn test_23() { (unsafe { LifetimeTracked::reset() }); object_unsafe!( @@ -529,17 +544,20 @@ 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) { +impl ConstructibleFromUnsafe<()> for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { + unsafe fn constructor(&mut self, (): ()) { (*std::cell::LazyCell::force_mut(&mut *&raw mut t_ctors_27)).prefix_inc(); } } +impl DefaultConstructibleUnsafe for p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} pub unsafe fn test_28() { let mut p: *mut p9_destructor_not_potentially_invoked_HasUndefinedDestructor = { let __p: *mut p9_destructor_not_potentially_invoked_HasUndefinedDestructor = Box::leak( Box::new(::zero_init()), ); - DefaultConstructibleUnsafe::default_constructor(&mut *__p); + >::constructor(&mut *__p, ()); __p }; assert!(!((p).is_null())); @@ -561,19 +579,20 @@ pub static mut ctor_calls_29: std::cell::LazyCell = pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { pub value: i32, } -impl DefaultConstructibleUnsafe for p9_unused_copy_constructor_HasUndefinedCopyCtor { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for p9_unused_copy_constructor_HasUndefinedCopyCtor { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.value).write(3); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctor_calls_29)).prefix_inc(); } } +impl DefaultConstructibleUnsafe for p9_unused_copy_constructor_HasUndefinedCopyCtor {} impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { fn default() -> Self { unsafe { { let mut __v: p9_unused_copy_constructor_HasUndefinedCopyCtor = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + >::constructor(&mut __v, ()) ; __v } } @@ -600,18 +619,19 @@ pub static mut m_ctors_32: std::cell::LazyCell = std::cell::LazyCell::new(| MovableUnsafe, )] pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} -impl DefaultConstructibleUnsafe for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { + unsafe fn constructor(&mut self, (): ()) { (*std::cell::LazyCell::force_mut(&mut *&raw mut m_ctors_32)).prefix_inc(); } } +impl DefaultConstructibleUnsafe for p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { fn default() -> Self { unsafe { { let mut __v: p9_unused_implicit_assignment_HasUndefinedCopyAssignment = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + >::constructor(&mut __v, ()) ; __v } } @@ -631,13 +651,17 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { pub m: p9_unused_implicit_assignment_HasUndefinedCopyAssignment, } -impl DefaultConstructibleUnsafe +impl ConstructibleFromUnsafe<()> for p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.m); + unsafe fn constructor(&mut self, (): ()) { + >::constructor(&mut self.m, ()) ; } } +impl DefaultConstructibleUnsafe + for p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment +{ +} pub unsafe fn test_33() { object_unsafe!( a, @@ -774,13 +798,16 @@ impl DestructibleUnsafe for p9_destructor_not_potentially_invoked_HasUndefinedDe ) } } -impl CopyConstructibleUnsafe for p9_unused_copy_constructor_HasUndefinedCopyCtor { - unsafe fn copy_constructor(&mut self, _: LvalueRefUnsafe>) { +impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> + for p9_unused_copy_constructor_HasUndefinedCopyCtor +{ + unsafe fn constructor(&mut self, _: (LvalueRefUnsafe>,)) { unreachable!( "p9_unused_copy_constructor_HasUndefinedCopyCtor::copy_constructor is never defined" ) } } +impl CopyConstructibleUnsafe for p9_unused_copy_constructor_HasUndefinedCopyCtor {} impl CopyAssignableUnsafe for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { unsafe fn copy_assign(&mut self, _: LvalueRefUnsafe>) -> *mut Self { unreachable!( diff --git a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs index 23cb1a23dc..f6fdbf0987 100644 --- a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs +++ b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs @@ -19,19 +19,40 @@ use std::rc::{Rc, Weak}; TriviallyCopyable, Default, )] -#[cpp_into(i64, to_i64, mut_ptr)] #[byte_size(8)] pub struct p2_non_const_conversion_function_Gauge { #[offset(0)] pub value: i64, } +impl ConversionFunction> + for p2_non_const_conversion_function_Gauge +{ + fn conversion_function(this: LvalueRef, to: Ptr) { + let this = &this.as_pointer(); + to.write(field!((*this), value).with_mut(|__v| __v.prefix_inc().clone())); + return; + } +} +impl ImplicitConversionFunction> + for p2_non_const_conversion_function_Gauge +{ +} pub fn test_0() { let gauge: Value = Rc::new(RefCell::new(p2_non_const_conversion_function_Gauge { value: 20_i64, })); - let mut converted: i64 = - ({ p2_non_const_conversion_function_GaugeImpl::to_i64(&gauge.as_pointer()) }); + let mut converted: i64 = { + let __v: Value = Rc::new(RefCell::new(0_i64)); + , + >>::conversion_function( + >::bind(gauge.as_pointer()), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((converted == 21_i64)); assert!(({ (*gauge.borrow()).value } == 21_i64)); } @@ -43,12 +64,4 @@ fn main_0() -> i32 { ({ test_0() }); return 0; } -pub trait p2_non_const_conversion_function_GaugeImpl { - fn to_i64(&self) -> i64; -} -impl p2_non_const_conversion_function_GaugeImpl for Ptr { - fn to_i64(&self) -> i64 { - return field!((*self), value).with_mut(|__v| __v.prefix_inc().clone()); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs index 0688a1be3f..66b80301ae 100644 --- a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs +++ b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs @@ -18,20 +18,39 @@ use std::rc::Rc; TriviallyCopyableUnsafe, Default, )] -#[cpp_into(i64, to_i64, mut_ptr)] pub struct p2_non_const_conversion_function_Gauge { pub value: i64, } -impl p2_non_const_conversion_function_Gauge { - pub unsafe fn to_i64(&mut self) -> i64 { - return (*self.value.prefix_inc()); +impl ConversionFunctionUnsafe> + for p2_non_const_conversion_function_Gauge +{ + unsafe fn conversion_function( + this: LvalueRefUnsafe, + to: *mut i64, + ) { + let this = unsafe { &mut *(this.as_ptr() as *mut p2_non_const_conversion_function_Gauge) }; + to.write((*this.value.prefix_inc())); + return; } } +impl ImplicitConversionFunctionUnsafe> + for p2_non_const_conversion_function_Gauge +{ +} pub unsafe fn test_0() { let mut gauge: p2_non_const_conversion_function_Gauge = p2_non_const_conversion_function_Gauge { value: 20_i64 }; - let mut converted: i64 = - (unsafe { p2_non_const_conversion_function_Gauge::to_i64(&mut gauge) }); + let mut converted: i64 = { + let mut __v: i64 = 0_i64; + , + >>::conversion_function( + >::bind(&mut gauge), + &mut __v, + ); + __v + }; assert!(((converted) == (21_i64))); assert!(((gauge.value) == (21_i64))); } diff --git a/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs b/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs index 359828e042..d2c8826acf 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,10 +32,9 @@ pub fn pass_0( let __v: Value = Rc::new(RefCell::new( ::zero_init(), )); - MoveConstructible::move_constructor( - &__v.as_pointer(), - RvalueRef::bind(object.as_pointer()), - ); + , + )>>::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 e989542b7b..7410bdb985 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,9 @@ 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)); + , + )>>::constructor(&mut __v, (RvalueRefUnsafe::bind(&mut object),)); __v }; } diff --git a/tests/std/class/class.mem/out/refcount/class.mem.general.rs b/tests/std/class/class.mem/out/refcount/class.mem.general.rs index c0d307643a..5c008753ef 100644 --- a/tests/std/class/class.mem/out/refcount/class.mem.general.rs +++ b/tests/std/class/class.mem/out/refcount/class.mem.general.rs @@ -20,11 +20,12 @@ pub struct p7_1_function_body_names_later_member_HasLaterMembers { #[offset(0)] pub stock: i32, } -impl DefaultConstructible for p7_1_function_body_names_later_member_HasLaterMembers { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for p7_1_function_body_names_later_member_HasLaterMembers { + fn constructor(this: &Ptr, (): ()) { field!((*this), stock).write(9); } } +impl DefaultConstructible for p7_1_function_body_names_later_member_HasLaterMembers {} impl Default for p7_1_function_body_names_later_member_HasLaterMembers { fn default() -> Self { { p7_1_function_body_names_later_member_HasLaterMembers { stock: 9 } } @@ -55,11 +56,12 @@ pub struct p7_2_default_argument_names_later_member_HasLaterStaticStep { #[offset(0)] pub total: i32, } -impl DefaultConstructible for p7_2_default_argument_names_later_member_HasLaterStaticStep { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for p7_2_default_argument_names_later_member_HasLaterStaticStep { + fn constructor(this: &Ptr, (): ()) { field!((*this), total).write(1); } } +impl DefaultConstructible for p7_2_default_argument_names_later_member_HasLaterStaticStep {} impl Default for p7_2_default_argument_names_later_member_HasLaterStaticStep { fn default() -> Self { { p7_2_default_argument_names_later_member_HasLaterStaticStep { total: 1 } } diff --git a/tests/std/class/class.mem/out/unsafe/class.mem.general.rs b/tests/std/class/class.mem/out/unsafe/class.mem.general.rs index dd49b62cf0..edc203e366 100644 --- a/tests/std/class/class.mem/out/unsafe/class.mem.general.rs +++ b/tests/std/class/class.mem/out/unsafe/class.mem.general.rs @@ -28,11 +28,12 @@ impl p7_1_function_body_names_later_member_HasLaterMembers { return 2; } } -impl DefaultConstructibleUnsafe for p7_1_function_body_names_later_member_HasLaterMembers { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for p7_1_function_body_names_later_member_HasLaterMembers { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.stock).write(9); } } +impl DefaultConstructibleUnsafe for p7_1_function_body_names_later_member_HasLaterMembers {} impl Default for p7_1_function_body_names_later_member_HasLaterMembers { fn default() -> Self { unsafe { p7_1_function_body_names_later_member_HasLaterMembers { stock: 9 } } @@ -63,11 +64,12 @@ impl p7_2_default_argument_names_later_member_HasLaterStaticStep { return self.total; } } -impl DefaultConstructibleUnsafe for p7_2_default_argument_names_later_member_HasLaterStaticStep { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for p7_2_default_argument_names_later_member_HasLaterStaticStep { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.total).write(1); } } +impl DefaultConstructibleUnsafe for p7_2_default_argument_names_later_member_HasLaterStaticStep {} impl Default for p7_2_default_argument_names_later_member_HasLaterStaticStep { fn default() -> Self { unsafe { p7_2_default_argument_names_later_member_HasLaterStaticStep { total: 1 } } diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs index f61413b802..599e804a65 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs @@ -401,12 +401,13 @@ pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { #[offset(4)] pub five: i32, } -impl DefaultConstructible for p9_1_2_zero_then_default_initialized_WithDefaultMember { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for p9_1_2_zero_then_default_initialized_WithDefaultMember { + fn constructor(this: &Ptr, (): ()) { field!((*this), zeroed).write(0_i32); field!((*this), five).write(5); } } +impl DefaultConstructible for p9_1_2_zero_then_default_initialized_WithDefaultMember {} impl Default for p9_1_2_zero_then_default_initialized_WithDefaultMember { fn default() -> Self { { @@ -423,11 +424,12 @@ pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { #[offset(0)] pub untouched: i32, } -impl DefaultConstructible for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { + fn constructor(this: &Ptr, (): ()) { field!((*this), untouched).write(0_i32); } } +impl DefaultConstructible for p9_1_2_zero_then_default_initialized_LeavesMemberAlone {} impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { fn default() -> Self { { @@ -436,7 +438,7 @@ impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { Rc::new(RefCell::new( ::zero_init(), )); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()) ; Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -453,12 +455,13 @@ pub struct p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { #[byte_size(4)] pub member: p9_1_2_zero_then_default_initialized_LeavesMemberAlone, } -impl DefaultConstructible for p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { + fn constructor(this: &Ptr, (): ()) { field!((*this), number).write(0_i32); - DefaultConstructible::default_constructor(&field_ptr!(this, member)); + >::constructor(&field_ptr!(this, member), ()) ; } } +impl DefaultConstructible for p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone {} pub fn test_22() { object!( value, @@ -468,7 +471,7 @@ pub fn test_22() { assert!(({ (*value.borrow()).five } == 5)); let mut heap: Ptr = { let __p = Ptr::alloc(::zero_init()); - DefaultConstructible::default_constructor(&__p); + >::constructor(&__p, ()) ; __p }; assert!((heap.with(|__s| __s.zeroed) == 0)); @@ -483,7 +486,7 @@ pub fn test_22() { let mut heap_holder: Ptr = { let __p = Ptr::alloc(::zero_init()); - DefaultConstructible::default_constructor(&__p); + >::constructor(&__p, ()) ; __p }; assert!((heap_holder.with(|__s| __s.number) == 0)); diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs index cef1096ddd..580029d401 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs @@ -332,12 +332,13 @@ pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { pub zeroed: i32, pub five: i32, } -impl DefaultConstructibleUnsafe for p9_1_2_zero_then_default_initialized_WithDefaultMember { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for p9_1_2_zero_then_default_initialized_WithDefaultMember { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.zeroed).write(0_i32); (&raw mut self.five).write(5); } } +impl DefaultConstructibleUnsafe for p9_1_2_zero_then_default_initialized_WithDefaultMember {} impl Default for p9_1_2_zero_then_default_initialized_WithDefaultMember { fn default() -> Self { unsafe { @@ -353,18 +354,19 @@ impl Default for p9_1_2_zero_then_default_initialized_WithDefaultMember { pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { pub untouched: i32, } -impl DefaultConstructibleUnsafe for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.untouched).write(0_i32); } } +impl DefaultConstructibleUnsafe for p9_1_2_zero_then_default_initialized_LeavesMemberAlone {} impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { fn default() -> Self { unsafe { { let mut __v: p9_1_2_zero_then_default_initialized_LeavesMemberAlone = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + >::constructor(&mut __v, ()) ; __v } } @@ -378,12 +380,13 @@ pub struct p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { pub number: i32, pub member: p9_1_2_zero_then_default_initialized_LeavesMemberAlone, } -impl DefaultConstructibleUnsafe for p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.number).write(0_i32); - DefaultConstructibleUnsafe::default_constructor(&mut self.member); + >::constructor(&mut self.member, ()) ; } } +impl DefaultConstructibleUnsafe for p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone {} pub unsafe fn test_22() { object_unsafe!( value, @@ -395,7 +398,7 @@ pub unsafe fn test_22() { let __p: *mut p9_1_2_zero_then_default_initialized_WithDefaultMember = Box::leak(Box::new( ::zero_init(), )); - DefaultConstructibleUnsafe::default_constructor(&mut *__p); + >::constructor(&mut *__p, ()) ; __p }; assert!((((*heap).zeroed) == (0))); @@ -416,7 +419,9 @@ pub unsafe fn test_22() { let __p: *mut p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone = Box::leak( Box::new(::zero_init()), ); - DefaultConstructibleUnsafe::default_constructor(&mut *__p); + >::constructor(&mut *__p, ()); __p }; assert!((((*heap_holder).number) == (0))); diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs index 16cf0ed793..69bac67b1f 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs @@ -60,11 +60,12 @@ pub struct p9_static_member_hides_namespace_variable_HasStaticStep { #[offset(0)] pub total: i32, } -impl DefaultConstructible for p9_static_member_hides_namespace_variable_HasStaticStep { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for p9_static_member_hides_namespace_variable_HasStaticStep { + fn constructor(this: &Ptr, (): ()) { field!((*this), total).write(1); } } +impl DefaultConstructible for p9_static_member_hides_namespace_variable_HasStaticStep {} impl Default for p9_static_member_hides_namespace_variable_HasStaticStep { fn default() -> Self { { p9_static_member_hides_namespace_variable_HasStaticStep { total: 1 } } @@ -120,13 +121,14 @@ pub struct p9_evaluated_each_time_called_Widget { #[offset(0)] pub id: i32, } -impl DefaultConstructible for p9_evaluated_each_time_called_Widget { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for p9_evaluated_each_time_called_Widget { + fn constructor(this: &Ptr, (): ()) { { p9_evaluated_each_time_called_WidgetImpl::construct(this, ({ count_default_13() })); } } } +impl DefaultConstructible for p9_evaluated_each_time_called_Widget {} impl Default for p9_evaluated_each_time_called_Widget { fn default() -> Self { { @@ -162,11 +164,12 @@ impl p9_evaluated_each_time_called_Account { base_15.with(|rc| *rc.borrow_mut() = value); } } -impl DefaultConstructible for p9_evaluated_each_time_called_Account { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for p9_evaluated_each_time_called_Account { + fn constructor(this: &Ptr, (): ()) { field!((*this), balance).write(0); } } +impl DefaultConstructible for p9_evaluated_each_time_called_Account {} impl Default for p9_evaluated_each_time_called_Account { fn default() -> Self { { p9_evaluated_each_time_called_Account { balance: 0 } } diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs index eae9df980c..27c5b8620c 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs @@ -64,11 +64,12 @@ impl p9_static_member_hides_namespace_variable_HasStaticStep { return self.total; } } -impl DefaultConstructibleUnsafe for p9_static_member_hides_namespace_variable_HasStaticStep { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for p9_static_member_hides_namespace_variable_HasStaticStep { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.total).write(1); } } +impl DefaultConstructibleUnsafe for p9_static_member_hides_namespace_variable_HasStaticStep {} impl Default for p9_static_member_hides_namespace_variable_HasStaticStep { fn default() -> Self { unsafe { p9_static_member_hides_namespace_variable_HasStaticStep { total: 1 } } @@ -124,8 +125,8 @@ impl p9_evaluated_each_time_called_Widget { (&raw mut self.id).write(id); } } -impl DefaultConstructibleUnsafe for p9_evaluated_each_time_called_Widget { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for p9_evaluated_each_time_called_Widget { + unsafe fn constructor(&mut self, (): ()) { unsafe { p9_evaluated_each_time_called_Widget::construct( &mut *self, @@ -134,6 +135,7 @@ impl DefaultConstructibleUnsafe for p9_evaluated_each_time_called_Widget { } } } +impl DefaultConstructibleUnsafe for p9_evaluated_each_time_called_Widget {} impl Default for p9_evaluated_each_time_called_Widget { fn default() -> Self { unsafe { @@ -169,11 +171,12 @@ impl p9_evaluated_each_time_called_Account { (*std::cell::LazyCell::force_mut(&mut *&raw mut base_15)) = value; } } -impl DefaultConstructibleUnsafe for p9_evaluated_each_time_called_Account { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for p9_evaluated_each_time_called_Account { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.balance).write(0); } } +impl DefaultConstructibleUnsafe for p9_evaluated_each_time_called_Account {} impl Default for p9_evaluated_each_time_called_Account { fn default() -> Self { unsafe { p9_evaluated_each_time_called_Account { balance: 0 } } 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..37080b11bf 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 @@ -142,24 +142,30 @@ thread_local!( )] #[byte_size(1)] pub struct p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} -impl CopyConstructible for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { - fn copy_constructor( +impl ConstructibleFrom<(LvalueRef>,)> + for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves +{ + fn constructor( this: &Ptr, - _a0: LvalueRef>, + (_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( +impl CopyConstructible for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} +impl ConstructibleFrom<(RvalueRef,)> + for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves +{ + fn constructor( this: &Ptr, - _a0: RvalueRef, + (_a0,): (RvalueRef,), ) { let _a0 = _a0.as_pointer(); (*moveCount_10.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl MoveConstructible for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} #[derive( Record, ByteRepr, 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..ea614eec9c 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 @@ -129,24 +129,30 @@ pub static mut moveCount_10: std::cell::LazyCell = std::cell::LazyCell::new Default, )] 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( +impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> + for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves +{ + unsafe fn constructor( &mut self, - _a0: LvalueRefUnsafe>, + (_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( +impl CopyConstructibleUnsafe for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} +impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> + for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves +{ + unsafe fn constructor( &mut self, - _a0: RvalueRefUnsafe, + (_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(); } } +impl MoveConstructibleUnsafe for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} #[repr(C)] #[derive( FnPtrArg, diff --git a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs index 31cf739d9f..c1ee4b13b2 100644 --- a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs +++ b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs @@ -26,11 +26,12 @@ pub struct p16_rebind_member_Alloc_std_pair_const_int__int__ { #[offset(0)] pub id: i32, } -impl DefaultConstructible for p16_rebind_member_Alloc_std_pair_const_int__int__ { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for p16_rebind_member_Alloc_std_pair_const_int__int__ { + fn constructor(this: &Ptr, (): ()) { field!((*this), id).write(0); } } +impl DefaultConstructible for p16_rebind_member_Alloc_std_pair_const_int__int__ {} impl Default for p16_rebind_member_Alloc_std_pair_const_int__int__ { fn default() -> Self { { p16_rebind_member_Alloc_std_pair_const_int__int__ { id: 0 } } diff --git a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs index 24bd0567b2..db39d698b2 100644 --- a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs +++ b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs @@ -23,11 +23,12 @@ pub struct p16_rebind_member_Alloc_std_pair_const_int__int___rebind_std_pair_con pub struct p16_rebind_member_Alloc_std_pair_const_int__int__ { pub id: i32, } -impl DefaultConstructibleUnsafe for p16_rebind_member_Alloc_std_pair_const_int__int__ { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for p16_rebind_member_Alloc_std_pair_const_int__int__ { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.id).write(0); } } +impl DefaultConstructibleUnsafe for p16_rebind_member_Alloc_std_pair_const_int__int__ {} impl Default for p16_rebind_member_Alloc_std_pair_const_int__int__ { fn default() -> Self { unsafe { p16_rebind_member_Alloc_std_pair_const_int__int__ { id: 0 } } diff --git a/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs b/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs index 08befc644a..fe4e45f481 100644 --- a/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs +++ b/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs @@ -37,6 +37,21 @@ impl Destructible for p2_condition_variable_created_each_iteration_ConvertsToBoo (*dtorCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl + ConversionFunction< + bool, + LvalueRef>, + > for p2_condition_variable_created_each_iteration_ConvertsToBool +{ + fn conversion_function( + this: LvalueRef>, + to: Ptr, + ) { + let this = &this.as_pointer(); + to.write(((*this).with(|__s| __s.value) != 0)); + return; + } +} pub fn test_2() { let mut remaining: i32 = 2; let mut iterations: i32 = 0; @@ -46,9 +61,9 @@ pub fn test_2() { p2_condition_variable_created_each_iteration_ConvertsToBool(remaining) ); if !({ - p2_condition_variable_created_each_iteration_ConvertsToBoolImpl::to_bool( - &condition.as_pointer(), - ) + let __v: Value = Rc::new(RefCell::new(false)); + >>>::conversion_function(>>::bind(condition .as_pointer() ), Ptr::clone(&__v.as_pointer())); + Rc::try_unwrap(__v).ok().unwrap().into_inner() }) { break; } @@ -93,6 +108,21 @@ impl Destructible for p2_continue_destroys_condition_variable_ConvertsToBool { (*dtorCount_4.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl + ConversionFunction< + bool, + LvalueRef>, + > for p2_continue_destroys_condition_variable_ConvertsToBool +{ + fn conversion_function( + this: LvalueRef>, + to: Ptr, + ) { + let this = &this.as_pointer(); + to.write(((*this).with(|__s| __s.value) != 0)); + return; + } +} pub fn test_5() { let mut remaining: i32 = 3; let mut continued: i32 = 0; @@ -103,9 +133,17 @@ pub fn test_5() { p2_continue_destroys_condition_variable_ConvertsToBool(remaining) ); if !({ - p2_continue_destroys_condition_variable_ConvertsToBoolImpl::to_bool( - &condition.as_pointer(), - ) + let __v: Value = Rc::new(RefCell::new(false)); + >, + >>::conversion_function( + >>::bind( + condition.as_pointer(), + ), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() }) { break; } @@ -136,7 +174,6 @@ fn main_0() -> i32 { } pub trait p2_condition_variable_created_each_iteration_ConvertsToBoolImpl { fn construct(&self, value: i32); - fn to_bool(&self) -> bool; } impl p2_condition_variable_created_each_iteration_ConvertsToBoolImpl for Ptr @@ -145,13 +182,9 @@ impl p2_condition_variable_created_each_iteration_ConvertsToBoolImpl field!((*self), value).write(value); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } - fn to_bool(&self) -> bool { - return ((*self).with(|__s| __s.value) != 0); - } } pub trait p2_continue_destroys_condition_variable_ConvertsToBoolImpl { fn construct(&self, value: i32); - fn to_bool(&self) -> bool; } impl p2_continue_destroys_condition_variable_ConvertsToBoolImpl for Ptr @@ -160,9 +193,6 @@ impl p2_continue_destroys_condition_variable_ConvertsToBoolImpl field!((*self), value).write(value); (*ctorCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } - fn to_bool(&self) -> bool { - return ((*self).with(|__s| __s.value) != 0); - } } pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); diff --git a/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs b/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs index 68d9d72333..2385ec6aeb 100644 --- a/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs +++ b/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs @@ -30,15 +30,29 @@ impl p2_condition_variable_created_each_iteration_ConvertsToBool { (&raw mut self.value).write(value); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } - pub unsafe fn to_bool(&self) -> bool { - return ((self.value) != (0)); - } } impl DestructibleUnsafe for p2_condition_variable_created_each_iteration_ConvertsToBool { unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_1)).prefix_inc(); } } +impl + ConversionFunctionUnsafe< + bool, + LvalueRefUnsafe>, + > for p2_condition_variable_created_each_iteration_ConvertsToBool +{ + unsafe fn conversion_function( + this: LvalueRefUnsafe>, + to: *mut bool, + ) { + let this = unsafe { + &*(this.as_ptr() as *const p2_condition_variable_created_each_iteration_ConvertsToBool) + }; + to.write(((this.value) != (0))); + return; + } +} pub unsafe fn test_2() { let mut remaining: i32 = 2; let mut iterations: i32 = 0; @@ -47,8 +61,10 @@ pub unsafe fn test_2() { condition, p2_condition_variable_created_each_iteration_ConvertsToBool(remaining) ); - if !(unsafe { - p2_condition_variable_created_each_iteration_ConvertsToBool::to_bool(&condition) + if !({ + let mut __v: bool = false; + >>>::conversion_function(>>::bind(& mut condition ), &mut __v); + __v }) { break; } @@ -88,15 +104,29 @@ impl p2_continue_destroys_condition_variable_ConvertsToBool { (&raw mut self.value).write(value); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_3)).prefix_inc(); } - pub unsafe fn to_bool(&self) -> bool { - return ((self.value) != (0)); - } } impl DestructibleUnsafe for p2_continue_destroys_condition_variable_ConvertsToBool { unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_4)).prefix_inc(); } } +impl + ConversionFunctionUnsafe< + bool, + LvalueRefUnsafe>, + > for p2_continue_destroys_condition_variable_ConvertsToBool +{ + unsafe fn conversion_function( + this: LvalueRefUnsafe>, + to: *mut bool, + ) { + let this = unsafe { + &*(this.as_ptr() as *const p2_continue_destroys_condition_variable_ConvertsToBool) + }; + to.write(((this.value) != (0))); + return; + } +} pub unsafe fn test_5() { let mut remaining: i32 = 3; let mut continued: i32 = 0; @@ -106,8 +136,11 @@ pub unsafe fn test_5() { condition, p2_continue_destroys_condition_variable_ConvertsToBool(remaining) ); - if !(unsafe { p2_continue_destroys_condition_variable_ConvertsToBool::to_bool(&condition) }) - { + if !({ + let mut __v: bool = false; + >>>::conversion_function(>>::bind(& mut condition ), &mut __v); + __v + }) { break; } remaining.prefix_dec(); diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs index 4f3a4b286f..192adf125d 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 @@ -54,19 +54,21 @@ impl LifetimeTracked { }); } } -impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for LifetimeTracked { + fn 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>) { +impl DefaultConstructible for LifetimeTracked {} +impl ConstructibleFrom<(LvalueRef>,)> for LifetimeTracked { + fn constructor(this: &Ptr, (_a0,): (LvalueRef>,)) { let _a0 = _a0.as_pointer(); field!((*this), uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl CopyConstructible for LifetimeTracked {} impl Destructible for LifetimeTracked { fn destroy(this: &Ptr) { (*dtorCount_2.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 33d1a938e8..2d6147a965 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 @@ -54,19 +54,21 @@ impl LifetimeTracked { }); } } -impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for LifetimeTracked { + fn 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>) { +impl DefaultConstructible for LifetimeTracked {} +impl ConstructibleFrom<(LvalueRef>,)> for LifetimeTracked { + fn constructor(this: &Ptr, (_a0,): (LvalueRef>,)) { let _a0 = _a0.as_pointer(); field!((*this), uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl CopyConstructible for LifetimeTracked {} impl Destructible for LifetimeTracked { fn destroy(this: &Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); @@ -95,12 +97,33 @@ thread_local!( Movable, )] #[memberwise(copy_assign)] -#[cpp_into(i32, to_i32)] #[byte_size(4)] pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { #[offset(0)] pub value: i32, } +impl + ConversionFunction< + i32, + LvalueRef>, + > for p2_condition_variable_lives_for_whole_statement_ConvertsToInt +{ + fn conversion_function( + this: LvalueRef>, + to: Ptr, + ) { + let this = &this.as_pointer(); + to.write((*this).with(|__s| __s.value)); + return; + } +} +impl + ImplicitConversionFunction< + i32, + LvalueRef>, + > for p2_condition_variable_lives_for_whole_statement_ConvertsToInt +{ +} impl Destructible for p2_condition_variable_lives_for_whole_statement_ConvertsToInt { fn destroy(this: &Ptr) { (*dtorCount_6.with(Value::clone).borrow_mut()).prefix_inc(); @@ -117,11 +140,11 @@ pub fn test_7() { }); 'switch: { match { - ({ - p2_condition_variable_lives_for_whole_statement_ConvertsToIntImpl::to_i32( - &selector.as_pointer(), - ) - }) + { + let __v: Value = Rc::new(RefCell::new(0_i32)); + >>>::conversion_function(>>::bind(selector .as_pointer() ), Ptr::clone(&__v.as_pointer())); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } } { __v if __v == 2 => { (*matching_case_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); @@ -232,16 +255,6 @@ impl LifetimeTrackedImpl for Ptr { (*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..c5506f242c 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 @@ -41,19 +41,21 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } -impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for LifetimeTracked { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.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>) { +impl DefaultConstructibleUnsafe for LifetimeTracked {} +impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for LifetimeTracked { + unsafe fn 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(); } } +impl CopyConstructibleUnsafe for LifetimeTracked {} impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).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 e26693b527..448605b9e3 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 @@ -41,19 +41,21 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } -impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for LifetimeTracked { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.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>) { +impl DefaultConstructibleUnsafe for LifetimeTracked {} +impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for LifetimeTracked { + unsafe fn 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(); } } +impl CopyConstructibleUnsafe for LifetimeTracked {} impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -77,15 +79,34 @@ pub static mut dtorCount_6: std::cell::LazyCell = std::cell::LazyCell::new( MovableUnsafe, )] #[memberwise(copy_assign)] -#[cpp_into(i32, to_i32)] 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; +impl + ConversionFunctionUnsafe< + i32, + LvalueRefUnsafe>, + > for p2_condition_variable_lives_for_whole_statement_ConvertsToInt +{ + unsafe fn conversion_function( + this: LvalueRefUnsafe>, + to: *mut i32, + ) { + let this = unsafe { + &*(this.as_ptr() + as *const p2_condition_variable_lives_for_whole_statement_ConvertsToInt) + }; + to.write(this.value); + return; } } +impl + ImplicitConversionFunctionUnsafe< + i32, + LvalueRefUnsafe>, + > for p2_condition_variable_lives_for_whole_statement_ConvertsToInt +{ +} impl DestructibleUnsafe for p2_condition_variable_lives_for_whole_statement_ConvertsToInt { unsafe fn destroy(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_6)).prefix_inc(); @@ -100,9 +121,11 @@ pub unsafe fn test_7() { }); 'switch: { match { - (unsafe { - p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32(&selector) - }) + { + let mut __v: i32 = 0_i32; + >>>::conversion_function(>>::bind(& mut selector ), &mut __v); + __v + } } { __v if __v == 2 => { (*std::cell::LazyCell::force_mut(&mut *&raw mut matching_case_runs_4)) diff --git a/tests/std/temp/temp.spec/out/refcount/temp.inst.rs b/tests/std/temp/temp.spec/out/refcount/temp.inst.rs index 2e58366380..6ffbfd8df7 100644 --- a/tests/std/temp/temp.spec/out/refcount/temp.inst.rs +++ b/tests/std/temp/temp.spec/out/refcount/temp.inst.rs @@ -12,11 +12,12 @@ pub struct p2_reference_does_not_instantiate_Member { #[offset(0)] pub value: i32, } -impl DefaultConstructible for p2_reference_does_not_instantiate_Member { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for p2_reference_does_not_instantiate_Member { + fn constructor(this: &Ptr, (): ()) { field!((*this), value).write(1); } } +impl DefaultConstructible for p2_reference_does_not_instantiate_Member {} impl Default for p2_reference_does_not_instantiate_Member { fn default() -> Self { { p2_reference_does_not_instantiate_Member { value: 1 } } @@ -30,11 +31,15 @@ pub struct p2_reference_does_not_instantiate_Holder { #[byte_size(4)] pub member: p2_reference_does_not_instantiate_Member, } -impl DefaultConstructible for p2_reference_does_not_instantiate_Holder { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, member)); +impl ConstructibleFrom<()> for p2_reference_does_not_instantiate_Holder { + fn constructor(this: &Ptr, (): ()) { + >::constructor( + &field_ptr!(this, member), + (), + ); } } +impl DefaultConstructible for p2_reference_does_not_instantiate_Holder {} pub fn test_0() { object!(holder, p2_reference_does_not_instantiate_Holder); assert!(({ (*holder.borrow()).member.value } == 1)); diff --git a/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs b/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs index 03363dd36a..5215519172 100644 --- a/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs +++ b/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs @@ -19,11 +19,12 @@ impl p2_reference_does_not_instantiate_Member { (&raw mut self.value).write(2); } } -impl DefaultConstructibleUnsafe for p2_reference_does_not_instantiate_Member { - unsafe fn default_constructor(&mut self) { +impl ConstructibleFromUnsafe<()> for p2_reference_does_not_instantiate_Member { + unsafe fn constructor(&mut self, (): ()) { (&raw mut self.value).write(1); } } +impl DefaultConstructibleUnsafe for p2_reference_does_not_instantiate_Member {} impl Default for p2_reference_does_not_instantiate_Member { fn default() -> Self { unsafe { p2_reference_does_not_instantiate_Member { value: 1 } } @@ -35,11 +36,15 @@ impl Default for p2_reference_does_not_instantiate_Member { pub struct p2_reference_does_not_instantiate_Holder { pub member: p2_reference_does_not_instantiate_Member, } -impl DefaultConstructibleUnsafe for p2_reference_does_not_instantiate_Holder { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.member); +impl ConstructibleFromUnsafe<()> for p2_reference_does_not_instantiate_Holder { + unsafe fn constructor(&mut self, (): ()) { + >::constructor( + &mut self.member, + (), + ); } } +impl DefaultConstructibleUnsafe for p2_reference_does_not_instantiate_Holder {} pub unsafe fn test_0() { object_unsafe!(holder, p2_reference_does_not_instantiate_Holder); assert!(((holder.member.value) == (1))); diff --git a/tests/std/utilities/utility/out/refcount/forward-helpers.rs b/tests/std/utilities/utility/out/refcount/forward-helpers.rs index 74a10081d1..2e85e1b2aa 100644 --- a/tests/std/utilities/utility/out/refcount/forward-helpers.rs +++ b/tests/std/utilities/utility/out/refcount/forward-helpers.rs @@ -23,19 +23,21 @@ pub struct p6_forward_like_Movable { #[offset(0)] pub value: i32, } -impl CopyConstructible for p6_forward_like_Movable { - fn copy_constructor(this: &Ptr, other: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> for p6_forward_like_Movable { + fn 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: RvalueRef) { +impl CopyConstructible for p6_forward_like_Movable {} +impl ConstructibleFrom<(RvalueRef,)> for p6_forward_like_Movable { + fn constructor(this: &Ptr, (other,): (RvalueRef,)) { let other = other.as_pointer(); field!((*this), value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } +impl MoveConstructible for p6_forward_like_Movable {} #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise)] #[memberwise(copy_constructor, move_constructor)] #[byte_size(4)] @@ -44,11 +46,12 @@ pub struct p6_forward_like_Holder { #[byte_size(4)] pub member: p6_forward_like_Movable, } -impl DefaultConstructible for p6_forward_like_Holder { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for p6_forward_like_Holder { + fn constructor(this: &Ptr, (): ()) { p6_forward_like_MovableImpl::construct(&field_ptr!(this, member), 1); } } +impl DefaultConstructible for p6_forward_like_Holder {} impl Default for p6_forward_like_Holder { fn default() -> Self { { @@ -64,11 +67,11 @@ impl Default for p6_forward_like_Holder { } } pub fn take_1(this: Ptr, self_: Ptr) { - CopyConstructible::copy_constructor(&this, LvalueRef::bind(field_ptr!(self_, member))); + >,)>>::constructor(&this, (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))); + ,)>>::constructor(&this, (RvalueRef::bind(field_ptr!(self_ , member) ),)) ; return; } pub fn test_3() { @@ -91,13 +94,14 @@ pub struct p9_move_Movable { #[offset(0)] pub value: i32, } -impl MoveConstructible for p9_move_Movable { - fn move_constructor(this: &Ptr, other: RvalueRef) { +impl ConstructibleFrom<(RvalueRef,)> for p9_move_Movable { + fn constructor(this: &Ptr, (other,): (RvalueRef,)) { let other = other.as_pointer(); field!((*this), value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } +impl MoveConstructible for p9_move_Movable {} pub fn test_4() { let mut number: i32 = 1; let mut moved: i32 = number; @@ -146,16 +150,17 @@ pub struct p10_forward_in_template_A { #[offset(8)] pub moves: i32, } -impl CopyConstructible for p10_forward_in_template_A { - fn copy_constructor(this: &Ptr, other: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> for p10_forward_in_template_A { + fn 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: RvalueRef) { +impl CopyConstructible for p10_forward_in_template_A {} +impl ConstructibleFrom<(RvalueRef,)> for p10_forward_in_template_A { + fn constructor(this: &Ptr, (other,): (RvalueRef,)) { let other = other.as_pointer(); field!((*this), value).write(other.with(|__s| __s.value)); field!((*this), copies).write(0); @@ -163,17 +168,20 @@ impl MoveConstructible for p10_forward_in_template_A { field!(other, value).write(0); } } +impl MoveConstructible for p10_forward_in_template_A {} impl Default for p10_forward_in_template_A { fn default() -> Self { { ::zero_init() } } } pub fn make_5(this: Ptr, source: Ptr) { - CopyConstructible::copy_constructor(&this, LvalueRef::bind((source).clone())); + >, + )>>::constructor(&this, (LvalueRef::bind((source).clone()),)); return; } pub fn make_6(this: Ptr, source: Ptr) { - MoveConstructible::move_constructor(&this, RvalueRef::bind((source).clone())); + ,)>>::constructor(&this, (RvalueRef::bind((source ).clone() ),)) ; return; } pub fn test_7() { @@ -204,22 +212,24 @@ pub struct p11_move_if_noexcept_NoexceptMove { #[offset(0)] pub value: i32, } -impl CopyConstructible for p11_move_if_noexcept_NoexceptMove { - fn copy_constructor( +impl ConstructibleFrom<(LvalueRef>,)> for p11_move_if_noexcept_NoexceptMove { + fn constructor( this: &Ptr, - other: LvalueRef>, + (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: RvalueRef) { +impl CopyConstructible for p11_move_if_noexcept_NoexceptMove {} +impl ConstructibleFrom<(RvalueRef,)> for p11_move_if_noexcept_NoexceptMove { + fn constructor(this: &Ptr, (other,): (RvalueRef,)) { let other = other.as_pointer(); field!((*this), value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } +impl MoveConstructible for p11_move_if_noexcept_NoexceptMove {} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, )] @@ -229,22 +239,24 @@ pub struct p11_move_if_noexcept_ThrowingMove { #[offset(0)] pub value: i32, } -impl CopyConstructible for p11_move_if_noexcept_ThrowingMove { - fn copy_constructor( +impl ConstructibleFrom<(LvalueRef>,)> for p11_move_if_noexcept_ThrowingMove { + fn constructor( this: &Ptr, - other: LvalueRef>, + (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: RvalueRef) { +impl CopyConstructible for p11_move_if_noexcept_ThrowingMove {} +impl ConstructibleFrom<(RvalueRef,)> for p11_move_if_noexcept_ThrowingMove { + fn constructor(this: &Ptr, (other,): (RvalueRef,)) { let other = other.as_pointer(); field!((*this), value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } +impl MoveConstructible for p11_move_if_noexcept_ThrowingMove {} pub fn test_8() { object!(moved_from, p11_move_if_noexcept_NoexceptMove(1)); object!( diff --git a/tests/std/utilities/utility/out/refcount/forward.rs b/tests/std/utilities/utility/out/refcount/forward.rs index ef7d280d26..b5c1e957db 100644 --- a/tests/std/utilities/utility/out/refcount/forward.rs +++ b/tests/std/utilities/utility/out/refcount/forward.rs @@ -66,13 +66,14 @@ pub struct p10_move_constructor_A { #[offset(0)] pub value: i32, } -impl MoveConstructible for p10_move_constructor_A { - fn move_constructor(this: &Ptr, other: RvalueRef) { +impl ConstructibleFrom<(RvalueRef,)> for p10_move_constructor_A { + fn constructor(this: &Ptr, (other,): (RvalueRef,)) { let other = other.as_pointer(); field!((*this), value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } +impl MoveConstructible for p10_move_constructor_A {} pub fn test_2() { object!(source, p10_move_constructor_A(1)); object!( diff --git a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs index 1417fb9766..995b3259f0 100644 --- a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs +++ b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs @@ -27,30 +27,33 @@ impl p6_forward_like_Movable { (&raw mut self.value).write(value); } } -impl CopyConstructibleUnsafe for p6_forward_like_Movable { - unsafe fn copy_constructor(&mut self, other: LvalueRefUnsafe>) { +impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for p6_forward_like_Movable { + unsafe fn 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: RvalueRefUnsafe) { +impl CopyConstructibleUnsafe for p6_forward_like_Movable {} +impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for p6_forward_like_Movable { + unsafe fn 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; } } +impl MoveConstructibleUnsafe for p6_forward_like_Movable {} #[repr(C)] #[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe)] #[memberwise(copy_constructor, move_constructor)] 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) { +impl ConstructibleFromUnsafe<()> for p6_forward_like_Holder { + unsafe fn constructor(&mut self, (): ()) { p6_forward_like_Movable::construct(&mut self.member, 1); } } +impl DefaultConstructibleUnsafe for p6_forward_like_Holder {} impl Default for p6_forward_like_Holder { fn default() -> Self { unsafe { @@ -65,14 +68,15 @@ impl Default for p6_forward_like_Holder { } } 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)); + >, + )>>::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) { - MoveConstructibleUnsafe::move_constructor( - &mut *this, - RvalueRefUnsafe::bind(&mut (*self_).member), - ); + , + )>>::constructor(&mut *this, (RvalueRefUnsafe::bind(&mut (*self_).member),)); return; } pub unsafe fn test_3() { @@ -99,13 +103,14 @@ impl p9_move_Movable { (&raw mut self.value).write(value); } } -impl MoveConstructibleUnsafe for p9_move_Movable { - unsafe fn move_constructor(&mut self, other: RvalueRefUnsafe) { +impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for p9_move_Movable { + unsafe fn 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; } } +impl MoveConstructibleUnsafe for p9_move_Movable {} pub unsafe fn test_4() { let mut number: i32 = 1; let mut moved: i32 = number; @@ -155,10 +160,10 @@ impl p10_forward_in_template_A { (&raw mut self.moves).write(0); } } -impl CopyConstructibleUnsafe for p10_forward_in_template_A { - unsafe fn copy_constructor( +impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for p10_forward_in_template_A { + unsafe fn constructor( &mut self, - other: LvalueRefUnsafe>, + (other,): (LvalueRefUnsafe>,), ) { let other = (other.as_ptr() as *const p10_forward_in_template_A); (&raw mut self.value).write((*other).value); @@ -166,8 +171,9 @@ impl CopyConstructibleUnsafe for p10_forward_in_template_A { (&raw mut self.moves).write(0); } } -impl MoveConstructibleUnsafe for p10_forward_in_template_A { - unsafe fn move_constructor(&mut self, other: RvalueRefUnsafe) { +impl CopyConstructibleUnsafe for p10_forward_in_template_A {} +impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for p10_forward_in_template_A { + unsafe fn 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); @@ -175,17 +181,22 @@ impl MoveConstructibleUnsafe for p10_forward_in_template_A { (*other).value = 0; } } +impl MoveConstructibleUnsafe for p10_forward_in_template_A {} impl Default for p10_forward_in_template_A { fn default() -> Self { 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)); + >, + )>>::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) { - MoveConstructibleUnsafe::move_constructor(&mut *this, RvalueRefUnsafe::bind(source)); + , + )>>::constructor(&mut *this, (RvalueRefUnsafe::bind(source),)); return; } pub unsafe fn test_7() { @@ -214,25 +225,29 @@ impl p11_move_if_noexcept_NoexceptMove { (&raw mut self.value).write(value); } } -impl CopyConstructibleUnsafe for p11_move_if_noexcept_NoexceptMove { - unsafe fn copy_constructor( +impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> + for p11_move_if_noexcept_NoexceptMove +{ + unsafe fn constructor( &mut self, - other: LvalueRefUnsafe>, + (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( +impl CopyConstructibleUnsafe for p11_move_if_noexcept_NoexceptMove {} +impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for p11_move_if_noexcept_NoexceptMove { + unsafe fn constructor( &mut self, - other: RvalueRefUnsafe, + (other,): (RvalueRefUnsafe,), ) { let other = (other.as_ptr() as *mut p11_move_if_noexcept_NoexceptMove); (&raw mut self.value).write((*other).value); (*other).value = 0; } } +impl MoveConstructibleUnsafe for p11_move_if_noexcept_NoexceptMove {} #[repr(C)] #[derive( FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, @@ -246,25 +261,29 @@ impl p11_move_if_noexcept_ThrowingMove { (&raw mut self.value).write(value); } } -impl CopyConstructibleUnsafe for p11_move_if_noexcept_ThrowingMove { - unsafe fn copy_constructor( +impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> + for p11_move_if_noexcept_ThrowingMove +{ + unsafe fn constructor( &mut self, - other: LvalueRefUnsafe>, + (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( +impl CopyConstructibleUnsafe for p11_move_if_noexcept_ThrowingMove {} +impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for p11_move_if_noexcept_ThrowingMove { + unsafe fn constructor( &mut self, - other: RvalueRefUnsafe, + (other,): (RvalueRefUnsafe,), ) { let other = (other.as_ptr() as *mut p11_move_if_noexcept_ThrowingMove); (&raw mut self.value).write((*other).value); (*other).value = 0; } } +impl MoveConstructibleUnsafe for p11_move_if_noexcept_ThrowingMove {} pub unsafe fn test_8() { object_unsafe!(moved_from, p11_move_if_noexcept_NoexceptMove(1)); object_unsafe!( diff --git a/tests/std/utilities/utility/out/unsafe/forward.rs b/tests/std/utilities/utility/out/unsafe/forward.rs index e777c2b07f..00098125f1 100644 --- a/tests/std/utilities/utility/out/unsafe/forward.rs +++ b/tests/std/utilities/utility/out/unsafe/forward.rs @@ -60,13 +60,14 @@ impl p10_move_constructor_A { (&raw mut self.value).write(value); } } -impl MoveConstructibleUnsafe for p10_move_constructor_A { - unsafe fn move_constructor(&mut self, other: RvalueRefUnsafe) { +impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for p10_move_constructor_A { + unsafe fn 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; } } +impl MoveConstructibleUnsafe for p10_move_constructor_A {} pub unsafe fn test_2() { object_unsafe!(source, p10_move_constructor_A(1)); object_unsafe!( diff --git a/tests/unit/out/refcount/10_struct.rs b/tests/unit/out/refcount/10_struct.rs index d46dea05b5..ed6327c415 100644 --- a/tests/unit/out/refcount/10_struct.rs +++ b/tests/unit/out/refcount/10_struct.rs @@ -51,11 +51,12 @@ pub struct Partial { #[byte_size(8)] pub p: Ptr, } -impl DefaultConstructible for Partial { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Partial { + fn constructor(this: &Ptr, (): ()) { field!((*this), p).write(Ptr::::null()); } } +impl DefaultConstructible for Partial {} impl Default for Partial { fn default() -> Self { { diff --git a/tests/unit/out/refcount/array_of_noncopy_struct.rs b/tests/unit/out/refcount/array_of_noncopy_struct.rs index 00a96f3d1d..30cbe0f860 100644 --- a/tests/unit/out/refcount/array_of_noncopy_struct.rs +++ b/tests/unit/out/refcount/array_of_noncopy_struct.rs @@ -27,12 +27,13 @@ pub struct NonCopy { #[offset(24)] pub tag: i32, } -impl DefaultConstructible for NonCopy { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for NonCopy { + fn constructor(this: &Ptr, (): ()) { field!((*this), data).write(Vec::new()); field!((*this), tag).write(0); } } +impl DefaultConstructible for NonCopy {} impl Default for NonCopy { fn default() -> Self { { @@ -51,7 +52,7 @@ fn main_0() -> i32 { let arr: Value> = Rc::new(RefCell::new(Box::new( std::array::from_fn::<_, 3, _>(|_| { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }), ))); diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index e5b2bcdcc9..a88a373e50 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -2361,11 +2361,12 @@ pub struct Counts_59 { #[byte_size(24)] pub counts: Vec, } -impl DefaultConstructible for Counts_59 { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Counts_59 { + fn constructor(this: &Ptr, (): ()) { field!((*this), counts).write(Vec::new()); } } +impl DefaultConstructible for Counts_59 {} #[derive( Copy, Clone, diff --git a/tests/unit/out/refcount/cast.rs b/tests/unit/out/refcount/cast.rs index 8d9c103416..8883ea37cd 100644 --- a/tests/unit/out/refcount/cast.rs +++ b/tests/unit/out/refcount/cast.rs @@ -105,12 +105,13 @@ pub struct Bag { #[byte_size(24)] pub items: Vec, } -impl DefaultConstructible for Bag { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Bag { + fn constructor(this: &Ptr, (): ()) { field!((*this), n).write(0_i32); field!((*this), items).write(Vec::new()); } } +impl DefaultConstructible for Bag {} pub fn adjacent_arrays_0() { let a: Value> = Rc::new(RefCell::new(Box::new([1, 2, 3, 4]))); let b: Value> = Rc::new(RefCell::new(Box::new([5, 6, 7, 8]))); diff --git a/tests/unit/out/refcount/class_templates.rs b/tests/unit/out/refcount/class_templates.rs index f106590fc7..6df18ba8ea 100644 --- a/tests/unit/out/refcount/class_templates.rs +++ b/tests/unit/out/refcount/class_templates.rs @@ -26,11 +26,12 @@ pub struct MyContainer_int_ { #[byte_size(24)] vec_: Vec, } -impl DefaultConstructible for MyContainer_int_ { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for MyContainer_int_ { + fn constructor(this: &Ptr, (): ()) { field!((*this), vec_).write(Vec::new()); } } +impl DefaultConstructible for MyContainer_int_ {} #[derive( Clone, Record, @@ -51,11 +52,12 @@ pub struct MyContainer_char_ { #[byte_size(24)] vec_: Vec, } -impl DefaultConstructible for MyContainer_char_ { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for MyContainer_char_ { + fn constructor(this: &Ptr, (): ()) { field!((*this), vec_).write(Vec::new()); } } +impl DefaultConstructible for MyContainer_char_ {} #[derive( Clone, Record, @@ -76,11 +78,12 @@ pub struct MyContainer_float_ { #[byte_size(24)] vec_: Vec, } -impl DefaultConstructible for MyContainer_float_ { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for MyContainer_float_ { + fn constructor(this: &Ptr, (): ()) { field!((*this), vec_).write(Vec::new()); } } +impl DefaultConstructible for MyContainer_float_ {} #[derive( Copy, Clone, diff --git a/tests/unit/out/refcount/constexpr_function.rs b/tests/unit/out/refcount/constexpr_function.rs index 7d52dfa2b2..a4a5459817 100644 --- a/tests/unit/out/refcount/constexpr_function.rs +++ b/tests/unit/out/refcount/constexpr_function.rs @@ -38,9 +38,23 @@ pub struct Flag { #[offset(0)] pub v: i32, } +impl ConversionFunction>> for Flag { + fn conversion_function(this: LvalueRef>, to: Ptr) { + let this = &this.as_pointer(); + to.write(((*this).with(|__s| __s.v) != 0)); + return; + } +} pub fn use_4(f: Flag) -> i32 { let f: Value = Rc::new(RefCell::new(f)); - assert!(({ FlagImpl::to_bool(&f.as_pointer(),) })); + assert!({ + let __v: Value = Rc::new(RefCell::new(false)); + >>>::conversion_function( + >>::bind(f.as_pointer()), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); return { (*f.borrow()).v }; } pub fn checked_5(mut x: i32) -> i32 { @@ -111,14 +125,6 @@ fn main_0() -> i32 { thread_local!( static s_8: Value = Rc::new(RefCell::new(true)); ); -pub trait FlagImpl { - fn to_bool(&self) -> bool; -} -impl FlagImpl for Ptr { - fn to_bool(&self) -> bool { - return ((*self).with(|__s| __s.v) != 0); - } -} pub trait PImpl { fn get(&self) -> i32; } diff --git a/tests/unit/out/refcount/constructor.rs b/tests/unit/out/refcount/constructor.rs index 8cd6db1f97..b641167fa0 100644 --- a/tests/unit/out/refcount/constructor.rs +++ b/tests/unit/out/refcount/constructor.rs @@ -47,20 +47,21 @@ pub struct Point { #[offset(4)] pub y: i32, } -impl DefaultConstructible for Point { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Point { + fn constructor(this: &Ptr, (): ()) { PointImpl::construct_1(this, 4); { field!((*this), x).with_mut(|__v| *__v = *__v + 100) }; } } +impl DefaultConstructible for Point {} impl Default for Point { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } diff --git a/tests/unit/out/refcount/container_field_addr.rs b/tests/unit/out/refcount/container_field_addr.rs index 683a2c6a03..472cb3aa23 100644 --- a/tests/unit/out/refcount/container_field_addr.rs +++ b/tests/unit/out/refcount/container_field_addr.rs @@ -28,12 +28,13 @@ pub struct S { #[byte_size(24)] pub v: Vec, } -impl DefaultConstructible for S { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for S { + fn constructor(this: &Ptr, (): ()) { field!((*this), tag).write(0_i32); field!((*this), v).write(Vec::new()); } } +impl DefaultConstructible for S {} pub fn add_0(mut v: Ptr>, k: i32) { let k: Value = Rc::new(RefCell::new(k)); CopyConstructible::push_copied(&v, k.as_pointer()); @@ -63,7 +64,7 @@ fn main_0() -> i32 { ({ run_1((local.as_pointer())) }); let mut heap: Ptr = { let __p = Ptr::alloc(::zero_init()); - DefaultConstructible::default_constructor(&__p); + >::constructor(&__p, ()); __p }; field!(heap, tag).write(7); diff --git a/tests/unit/out/refcount/conversion_operator_same_translation.rs b/tests/unit/out/refcount/conversion_operator_same_translation.rs index 45c44fe60d..158e54a112 100644 --- a/tests/unit/out/refcount/conversion_operator_same_translation.rs +++ b/tests/unit/out/refcount/conversion_operator_same_translation.rs @@ -19,13 +19,27 @@ use std::rc::{Rc, Weak}; TriviallyCopyable, Default, )] -#[cpp_into(i8, to_i8)] -#[cpp_into(u8, to_u8)] #[byte_size(4)] pub struct S { #[offset(0)] pub v: i32, } +impl ConversionFunction>> for S { + fn conversion_function(this: LvalueRef>, to: Ptr) { + let this = &this.as_pointer(); + to.write(((*this).with(|__s| __s.v) as i8)); + return; + } +} +impl ImplicitConversionFunction>> for S {} +impl ConversionFunction>> for S { + fn conversion_function(this: LvalueRef>, to: Ptr) { + let this = &this.as_pointer(); + to.write((((*this).with(|__s| __s.v) + 1) as u8)); + return; + } +} +impl ImplicitConversionFunction>> for S {} #[derive( Copy, Clone, @@ -39,54 +53,80 @@ pub struct S { TriviallyCopyable, Default, )] -#[cpp_into(i64, to_i64_1)] #[byte_size(4)] pub struct T { #[offset(0)] pub v: i32, } +impl ConversionFunction>> for T { + fn conversion_function(this: LvalueRef>, to: Ptr) { + let this = &this.as_pointer(); + to.write(((*this).with(|__s| __s.v) as i64)); + return; + } +} +impl ImplicitConversionFunction>> for T {} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { let s: Value = Rc::new(RefCell::new(S { v: 65 })); - let mut a: i8 = ({ SImpl::to_i8(&s.as_pointer()) }); - let mut b: u8 = ({ SImpl::to_u8(&s.as_pointer()) }); + let mut a: i8 = { + let __v: Value = Rc::new(RefCell::new(0_i8)); + >>>::conversion_function( + >>::bind(s.as_pointer()), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; + let mut b: u8 = { + let __v: Value = Rc::new(RefCell::new(0_u8)); + >>>::conversion_function( + >>::bind(s.as_pointer()), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!(((a as i32) == (('A' as i8) as i32))); assert!(((b as i32) == ((66 as u8) as i32))); assert!( - (((({ SImpl::to_i8(&s.as_pointer(),) }) as i32) - + (({ SImpl::to_u8(&s.as_pointer(),) }) as i32)) + ((({ + let __v: Value = Rc::new(RefCell::new(0_i8)); + >>>::conversion_function( + >>::bind(s.as_pointer()), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } as i32) + + ({ + let __v: Value = Rc::new(RefCell::new(0_u8)); + >>>::conversion_function( + >>::bind(s.as_pointer()), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } as i32)) == 131) ); let t: Value = Rc::new(RefCell::new(T { v: 3 })); - let mut c: i64 = ({ TImpl::to_i64_1(&t.as_pointer()) }); + let mut c: i64 = { + let __v: Value = Rc::new(RefCell::new(0_i64)); + >>>::conversion_function( + >>::bind(t.as_pointer()), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; let mut d: i64 = ({ TImpl::to_i64_2(&t.as_pointer()) }); assert!((c == 3_i64)); assert!((d == 4_i64)); return 0; } -pub trait SImpl { - fn to_i8(&self) -> i8; - fn to_u8(&self) -> u8; -} -impl SImpl for Ptr { - fn to_i8(&self) -> i8 { - return ((*self).with(|__s| __s.v) as i8); - } - fn to_u8(&self) -> u8 { - return (((*self).with(|__s| __s.v) + 1) as u8); - } -} pub trait TImpl { - fn to_i64_1(&self) -> i64; fn to_i64_2(&self) -> i64; } impl TImpl for Ptr { - fn to_i64_1(&self) -> i64 { - return ((*self).with(|__s| __s.v) as i64); - } fn to_i64_2(&self) -> i64 { return (((*self).with(|__s| __s.v) + 1) as i64); } diff --git a/tests/unit/out/refcount/copy_assign.rs b/tests/unit/out/refcount/copy_assign.rs index d4aa6c5a6c..e92f95648f 100644 --- a/tests/unit/out/refcount/copy_assign.rs +++ b/tests/unit/out/refcount/copy_assign.rs @@ -27,13 +27,14 @@ pub struct Partial { #[offset(4)] pub keep: i32, } -impl CopyConstructible for Partial { - fn copy_constructor(this: &Ptr, o: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> for Partial { + fn 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 CopyConstructible for Partial {} impl CopyAssignable for Partial { fn copy_assign(this: &Ptr, o: LvalueRef>) -> Ptr { let o = o.as_pointer(); @@ -53,18 +54,19 @@ pub struct NonConstAssign { #[offset(0)] pub mark: i32, } -impl DefaultConstructible for NonConstAssign { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for NonConstAssign { + fn constructor(this: &Ptr, (): ()) { field!((*this), mark).write(0); } } +impl DefaultConstructible for NonConstAssign {} impl Default for NonConstAssign { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -87,11 +89,12 @@ pub struct RefQualified { #[offset(0)] pub mark: i32, } -impl DefaultConstructible for RefQualified { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for RefQualified { + fn constructor(this: &Ptr, (): ()) { field!((*this), mark).write(0); } } +impl DefaultConstructible for RefQualified {} impl CopyAssignable for RefQualified { fn copy_assign(this: &Ptr, o: LvalueRef>) -> Ptr { let o = o.as_pointer(); @@ -104,7 +107,7 @@ impl Default for RefQualified { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -159,13 +162,14 @@ pub struct CopyCounted { #[offset(0)] pub v: i32, } -impl CopyConstructible for CopyCounted { - fn copy_constructor(this: &Ptr, o: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> for CopyCounted { + fn 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(); } } +impl CopyConstructible for CopyCounted {} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] @@ -224,11 +228,12 @@ impl CopyAssignable for ExplicitOperatorCall { return (*this).clone(); } } -impl DefaultConstructible for ExplicitOperatorCall { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for ExplicitOperatorCall { + fn constructor(this: &Ptr, (): ()) { field!((*this), w).write(Vec::new()); } } +impl DefaultConstructible for ExplicitOperatorCall {} thread_local!( pub static swap_copies_2: Value = Rc::new(RefCell::new(0)); ); @@ -249,13 +254,14 @@ pub struct Swapped { #[offset(0)] pub v: i32, } -impl CopyConstructible for Swapped { - fn copy_constructor(this: &Ptr, o: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> for Swapped { + fn 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 CopyConstructible for Swapped {} impl CopyAssignable for Swapped { fn copy_assign(this: &Ptr, src: LvalueRef>) -> Ptr { object!(__o, Swapped, LvalueRef::bind(src.as_pointer())); @@ -305,11 +311,12 @@ pub struct VoidAssign { #[offset(0)] pub x: i32, } -impl DefaultConstructible for VoidAssign { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for VoidAssign { + fn constructor(this: &Ptr, (): ()) { field!((*this), x).write(0); } } +impl DefaultConstructible for VoidAssign {} impl CopyAssignable for VoidAssign { fn copy_assign(this: &Ptr, src: LvalueRef>) -> Ptr { VoidAssignImpl::copy_assign(this, src.as_pointer()); @@ -327,7 +334,7 @@ impl Default for VoidAssign { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -354,11 +361,12 @@ pub struct HoldsVoidAssign { #[byte_size(4)] pub v: VoidAssign, } -impl DefaultConstructible for HoldsVoidAssign { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, v)); +impl ConstructibleFrom<()> for HoldsVoidAssign { + fn constructor(this: &Ptr, (): ()) { + >::constructor(&field_ptr!(this, v), ()); } } +impl DefaultConstructible for HoldsVoidAssign {} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -524,7 +532,10 @@ fn main_0() -> i32 { object!(sw2, Swapped(2)); ({ let _o: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor(&_o.as_pointer(), LvalueRef::bind(sw2.as_pointer())); + >,)>>::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 117ba477c5..281a849696 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -29,13 +29,14 @@ pub struct Counted { #[offset(0)] pub v: i32, } -impl CopyConstructible for Counted { - fn copy_constructor(this: &Ptr, o: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> for Counted { + fn 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 CopyConstructible for Counted {} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, MoveAssignable, )] @@ -45,17 +46,18 @@ pub struct NonConst { #[offset(0)] pub mark: i32, } -impl DefaultConstructible for NonConst { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for NonConst { + fn constructor(this: &Ptr, (): ()) { field!((*this), mark).write(0); } } +impl DefaultConstructible for NonConst {} impl Default for NonConst { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -81,13 +83,14 @@ pub struct Ignored { #[offset(0)] pub v: i32, } -impl CopyConstructible for Ignored { - fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> for Ignored { + fn 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(); } } +impl CopyConstructible for Ignored {} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] @@ -131,12 +134,13 @@ pub struct Box_int_ { #[offset(0)] pub val: i32, } -impl CopyConstructible for Box_int_ { - fn copy_constructor(this: &Ptr, o: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> for Box_int_ { + fn constructor(this: &Ptr, (o,): (LvalueRef>,)) { let o = o.as_pointer(); field!((*this), val).write(o.with(|__s| __s.val)); } } +impl CopyConstructible for Box_int_ {} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, )] @@ -167,13 +171,14 @@ pub struct OutOfLine { #[offset(0)] pub v: i32, } -impl CopyConstructible for OutOfLine { - fn copy_constructor(this: &Ptr, o: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> for OutOfLine { + fn 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(); } } +impl CopyConstructible for OutOfLine {} #[derive( Record, ByteRepr, @@ -189,13 +194,14 @@ pub struct Tracked { #[offset(0)] pub copied_from: i32, } -impl DefaultConstructible for Tracked { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Tracked { + fn constructor(this: &Ptr, (): ()) { field!((*this), copied_from).write(0); } } -impl CopyConstructible for Tracked { - fn copy_constructor(this: &Ptr, o: LvalueRef>) { +impl DefaultConstructible for Tracked {} +impl ConstructibleFrom<(LvalueRef>,)> for Tracked { + fn constructor(this: &Ptr, (o,): (LvalueRef>,)) { let o = o.as_pointer(); field!((*this), copied_from).write(0); field!(o, copied_from).with_mut(|__v| { @@ -203,6 +209,7 @@ impl CopyConstructible for Tracked { }); } } +impl CopyConstructible for Tracked {} impl CopyAssignable for Tracked { fn copy_assign(this: &Ptr, o: LvalueRef>) -> Ptr { let o = o.as_pointer(); @@ -227,7 +234,10 @@ pub fn by_value_2(c: Ptr) -> i32 { } pub fn make_3(this: Ptr, mut v: i32) { object!(c, Counted(v)); - CopyConstructible::copy_constructor(&this, LvalueRef::bind(c.as_pointer())); + >,)>>::constructor( + &this, + (LvalueRef::bind(c.as_pointer()),), + ); return; } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] @@ -237,29 +247,32 @@ pub struct SelfPtr { #[byte_size(8)] pub self_: Ptr, } -impl DefaultConstructible for SelfPtr { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for SelfPtr { + fn constructor(this: &Ptr, (): ()) { field!((*this), self_).write((*this).clone()); } } -impl CopyConstructible for SelfPtr { - fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { +impl DefaultConstructible for SelfPtr {} +impl ConstructibleFrom<(LvalueRef>,)> for SelfPtr { + fn 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: RvalueRef) { +impl CopyConstructible for SelfPtr {} +impl ConstructibleFrom<(RvalueRef,)> for SelfPtr { + fn constructor(this: &Ptr, (_a0,): (RvalueRef,)) { let _a0 = _a0.as_pointer(); field!((*this), self_).write((*this).clone()); } } +impl MoveConstructible for SelfPtr {} impl Default for SelfPtr { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -287,17 +300,18 @@ pub struct Derived { #[byte_size(4)] pub c: Counted, } -impl DefaultConstructible for Derived { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Derived { + fn constructor(this: &Ptr, (): ()) { CountedImpl::construct(&field_ptr!(this, c), 20); } } +impl DefaultConstructible for Derived {} impl Default for Derived { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -319,7 +333,10 @@ fn main_0() -> i32 { assert!( (({ let _c: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor(&_c.as_pointer(), LvalueRef::bind(a.as_pointer())); + >,)>>::constructor( + &_c.as_pointer(), + (LvalueRef::bind(a.as_pointer()),), + ); by_value_2(_c.as_pointer()) }) == 1) ); @@ -421,7 +438,7 @@ fn main_0() -> i32 { { let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); match ({ - DefaultConstructible::default_constructor(&__tmp_3.as_pointer()); + >::constructor(&__tmp_3.as_pointer(), ()); __tmp_3.as_pointer() },) { diff --git a/tests/unit/out/refcount/copy_move_defaulted.rs b/tests/unit/out/refcount/copy_move_defaulted.rs index 27a85e01f5..17bed03339 100644 --- a/tests/unit/out/refcount/copy_move_defaulted.rs +++ b/tests/unit/out/refcount/copy_move_defaulted.rs @@ -109,13 +109,14 @@ pub struct DefaultCopyUserMove { #[offset(0)] pub v: i32, } -impl MoveConstructible for DefaultCopyUserMove { - fn move_constructor(this: &Ptr, o: RvalueRef) { +impl ConstructibleFrom<(RvalueRef,)> for DefaultCopyUserMove { + fn 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 MoveConstructible for DefaultCopyUserMove {} impl MoveAssignable for DefaultCopyUserMove { fn move_assign( this: &Ptr, @@ -145,12 +146,13 @@ pub struct UserCopyDefaultMove { #[offset(0)] pub v: i32, } -impl CopyConstructible for UserCopyDefaultMove { - fn copy_constructor(this: &Ptr, o: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> for UserCopyDefaultMove { + fn constructor(this: &Ptr, (o,): (LvalueRef>,)) { let o = o.as_pointer(); field!((*this), v).write((o.with(|__s| __s.v) + 100)); } } +impl CopyConstructible for UserCopyDefaultMove {} impl CopyAssignable for UserCopyDefaultMove { fn copy_assign( this: &Ptr, @@ -210,14 +212,15 @@ pub struct Owner { #[byte_size(8)] pub p: Option>, } -impl DefaultConstructible for Owner { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Owner { + fn constructor(this: &Ptr, (): ()) { field!((*this), data).write(Vec::new()); field!((*this), n).write(0_i32); field!((*this), arr).write((0..2).map(|_| 0_i32).collect::>()); field!((*this), p).write(None); } } +impl DefaultConstructible for Owner {} impl Default for Owner { fn default() -> Self { { @@ -250,11 +253,12 @@ pub struct Copyable { #[byte_size(24)] pub data: Vec, } -impl DefaultConstructible for Copyable { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Copyable { + fn constructor(this: &Ptr, (): ()) { field!((*this), data).write(Vec::new()); } } +impl DefaultConstructible for Copyable {} #[derive( Record, ByteRepr, @@ -307,11 +311,12 @@ impl MoveAssignable for SeesThis { return (*this).clone(); } } -impl DefaultConstructible for SeesThis { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for SeesThis { + fn constructor(this: &Ptr, (): ()) { field!((*this), self_).write(Ptr::::null()); } } +impl DefaultConstructible for SeesThis {} impl Default for SeesThis { fn default() -> Self { { @@ -332,12 +337,13 @@ pub struct HasSeesThis { #[byte_size(24)] pub v: Vec, } -impl DefaultConstructible for HasSeesThis { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, s)); +impl ConstructibleFrom<()> for HasSeesThis { + fn constructor(this: &Ptr, (): ()) { + >::constructor(&field_ptr!(this, s), ()); field!((*this), v).write(Vec::new()); } } +impl DefaultConstructible for HasSeesThis {} #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable)] #[byte_size(8)] pub struct Counted_int_ { @@ -346,19 +352,21 @@ pub struct Counted_int_ { #[offset(4)] pub moves: i32, } -impl DefaultConstructible for Counted_int_ { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Counted_int_ { + fn constructor(this: &Ptr, (): ()) { field!((*this), v).write(0_i32); field!((*this), moves).write(0); } } -impl MoveConstructible for Counted_int_ { - fn move_constructor(this: &Ptr, o: RvalueRef) { +impl DefaultConstructible for Counted_int_ {} +impl ConstructibleFrom<(RvalueRef,)> for Counted_int_ { + fn 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 MoveConstructible for Counted_int_ {} impl MoveAssignable for Counted_int_ { fn move_assign(this: &Ptr, o: RvalueRef) -> Ptr { let o = o.as_pointer(); @@ -385,12 +393,13 @@ pub struct HasCounted { #[byte_size(24)] pub w: Vec, } -impl DefaultConstructible for HasCounted { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, c)); +impl ConstructibleFrom<()> for HasCounted { + fn constructor(this: &Ptr, (): ()) { + >::constructor(&field_ptr!(this, c), ()); field!((*this), w).write(Vec::new()); } } +impl DefaultConstructible for HasCounted {} #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Swappable)] #[cpp_from(i32, construct_1, value)] #[byte_size(16)] @@ -401,26 +410,29 @@ pub struct CtorSeesThis { #[offset(8)] pub id: i32, } -impl DefaultConstructible for CtorSeesThis { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for CtorSeesThis { + fn constructor(this: &Ptr, (): ()) { field!((*this), self_).write((*this).clone()); field!((*this), id).write(0); } } -impl CopyConstructible for CtorSeesThis { - fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { +impl DefaultConstructible for CtorSeesThis {} +impl ConstructibleFrom<(LvalueRef>,)> for CtorSeesThis { + fn 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: RvalueRef) { +impl CopyConstructible for CtorSeesThis {} +impl ConstructibleFrom<(RvalueRef,)> for CtorSeesThis { + fn constructor(this: &Ptr, (_a0,): (RvalueRef,)) { let _a0 = _a0.as_pointer(); field!((*this), self_).write((*this).clone()); field!((*this), id).write(0); } } +impl MoveConstructible for CtorSeesThis {} impl CopyAssignable for CtorSeesThis { fn copy_assign(this: &Ptr, _a0: LvalueRef>) -> Ptr { let _a0 = _a0.as_pointer(); @@ -438,7 +450,7 @@ impl Default for CtorSeesThis { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -457,12 +469,13 @@ pub struct HasCtorSeesThis { #[byte_size(24)] pub v: Vec, } -impl DefaultConstructible for HasCtorSeesThis { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, x)); +impl ConstructibleFrom<()> for HasCtorSeesThis { + fn constructor(this: &Ptr, (): ()) { + >::constructor(&field_ptr!(this, x), ()); field!((*this), v).write(Vec::new()); } } +impl DefaultConstructible for HasCtorSeesThis {} #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] #[byte_size(32)] @@ -474,19 +487,20 @@ pub struct InitsCtorSeesThis { #[byte_size(16)] pub y: CtorSeesThis, } -impl DefaultConstructible for InitsCtorSeesThis { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for InitsCtorSeesThis { + fn constructor(this: &Ptr, (): ()) { CtorSeesThisImpl::construct_1(&field_ptr!(this, x), 1); CtorSeesThisImpl::construct_1(&field_ptr!(this, y), 2); } } +impl DefaultConstructible for InitsCtorSeesThis {} impl Default for InitsCtorSeesThis { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -512,23 +526,25 @@ pub struct OutOfLineDefaulted { #[offset(16)] pub v: i32, } -impl CopyConstructible for OutOfLineDefaulted { - fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> for OutOfLineDefaulted { + fn constructor(this: &Ptr, (_a0,): (LvalueRef>,)) { let _a0 = _a0.as_pointer(); - CopyConstructible::copy_constructor( + >,)>>::constructor( &field_ptr!(this, x), - LvalueRef::bind(field_ptr!(_a0, x)), + (LvalueRef::bind(field_ptr!(_a0, x)),), ); field!((*this), v).write(_a0.with(|__s| __s.v)); } } -impl DefaultConstructible for OutOfLineDefaulted { - fn default_constructor(this: &Ptr) { +impl CopyConstructible for OutOfLineDefaulted {} +impl ConstructibleFrom<()> for OutOfLineDefaulted { + fn constructor(this: &Ptr, (): ()) { { OutOfLineDefaultedImpl::construct(this); } } } +impl DefaultConstructible for OutOfLineDefaulted {} impl Default for OutOfLineDefaulted { fn default() -> Self { { @@ -554,13 +570,14 @@ pub struct OutOfLineAssign { #[byte_size(24)] pub w: Vec, } -impl DefaultConstructible for OutOfLineAssign { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, s)); +impl ConstructibleFrom<()> for OutOfLineAssign { + fn constructor(this: &Ptr, (): ()) { + >::constructor(&field_ptr!(this, s), ()); field!((*this), v).write(1); field!((*this), w).write(Vec::new()); } } +impl DefaultConstructible for OutOfLineAssign {} impl Default for OutOfLineAssign { fn default() -> Self { { @@ -723,9 +740,9 @@ fn main_0() -> i32 { let mut __tmp_2 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor( + ,)>>::constructor( &__v.as_pointer(), - RvalueRef::bind(bufs.decay().offset(0_usize)), + (RvalueRef::bind(bufs.decay().offset(0_usize)),), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() } @@ -936,7 +953,7 @@ pub trait CtorSeesThisImpl { } impl CtorSeesThisImpl for Ptr { fn construct_1(&self, mut id: i32) { - DefaultConstructible::default_constructor(self); + >::constructor(self, ()); field!((*self), id).write(id); } } @@ -973,7 +990,7 @@ pub trait OutOfLineDefaultedImpl { } impl OutOfLineDefaultedImpl for Ptr { fn construct(&self) { - DefaultConstructible::default_constructor(&field_ptr!(self, x)); + >::constructor(&field_ptr!(self, x), ()); field!((*self), v).write(1); } } diff --git a/tests/unit/out/refcount/copy_move_deleted.rs b/tests/unit/out/refcount/copy_move_deleted.rs index dd679703a7..1508e7b97f 100644 --- a/tests/unit/out/refcount/copy_move_deleted.rs +++ b/tests/unit/out/refcount/copy_move_deleted.rs @@ -22,13 +22,14 @@ pub struct NoCopy { #[offset(0)] pub v: i32, } -impl MoveConstructible for NoCopy { - fn move_constructor(this: &Ptr, o: RvalueRef) { +impl ConstructibleFrom<(RvalueRef,)> for NoCopy { + fn 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 MoveConstructible for NoCopy {} impl MoveAssignable for NoCopy { fn move_assign(this: &Ptr, o: RvalueRef) -> Ptr { let o = o.as_pointer(); @@ -43,18 +44,20 @@ pub struct PrivateCopy { #[offset(0)] pub v: i32, } -impl DefaultConstructible for PrivateCopy { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for PrivateCopy { + fn constructor(this: &Ptr, (): ()) { field!((*this), v).write(0); } } -impl MoveConstructible for PrivateCopy { - fn move_constructor(this: &Ptr, o: RvalueRef) { +impl DefaultConstructible for PrivateCopy {} +impl ConstructibleFrom<(RvalueRef,)> for PrivateCopy { + fn 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 MoveConstructible for PrivateCopy {} impl MoveAssignable for PrivateCopy { fn move_assign(this: &Ptr, o: RvalueRef) -> Ptr { let o = o.as_pointer(); @@ -68,7 +71,7 @@ impl Default for PrivateCopy { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -80,17 +83,18 @@ pub struct Immovable { #[offset(0)] pub v: i32, } -impl DefaultConstructible for Immovable { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Immovable { + fn constructor(this: &Ptr, (): ()) { field!((*this), v).write(0); } } +impl DefaultConstructible for Immovable {} impl Default for Immovable { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -125,11 +129,12 @@ pub struct VecHolder { #[byte_size(24)] pub items: Vec, } -impl DefaultConstructible for VecHolder { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for VecHolder { + fn constructor(this: &Ptr, (): ()) { field!((*this), items).write(Vec::new()); } } +impl DefaultConstructible for VecHolder {} pub fn bump_0(mut p: Ptr) { field!(p, v).with_mut(|__v| __v.postfix_inc()); } @@ -182,11 +187,12 @@ impl CopyAssignable for PrivateCopy { unreachable!("PrivateCopy::copy_assign is never defined") } } -impl CopyConstructible for PrivateCopy { - fn copy_constructor(this: &Ptr, _: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> for PrivateCopy { + fn constructor(this: &Ptr, _: (LvalueRef>,)) { unreachable!("PrivateCopy::copy_constructor is never defined") } } +impl CopyConstructible for PrivateCopy {} pub trait NoCopyImpl { fn construct(&self, v: i32); } diff --git a/tests/unit/out/refcount/default_function_arguments.rs b/tests/unit/out/refcount/default_function_arguments.rs index 07ffcd91a5..e7c8b1c86c 100644 --- a/tests/unit/out/refcount/default_function_arguments.rs +++ b/tests/unit/out/refcount/default_function_arguments.rs @@ -21,13 +21,14 @@ pub struct Bar { #[offset(0)] pub v: i32, } -impl DefaultConstructible for Bar { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Bar { + fn constructor(this: &Ptr, (): ()) { { BarImpl::construct(this, 1); } } } +impl DefaultConstructible for Bar {} impl Default for Bar { fn default() -> Self { { diff --git a/tests/unit/out/refcount/enum_underlying_type.rs b/tests/unit/out/refcount/enum_underlying_type.rs index 916f8cc14f..874bb2a568 100644 --- a/tests/unit/out/refcount/enum_underlying_type.rs +++ b/tests/unit/out/refcount/enum_underlying_type.rs @@ -31,11 +31,12 @@ pub struct HoldsEmpty { #[offset(0)] pub e: Empty, } -impl DefaultConstructible for HoldsEmpty { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for HoldsEmpty { + fn constructor(this: &Ptr, (): ()) { field!((*this), e).write(::default()); } } +impl DefaultConstructible for HoldsEmpty {} impl Default for HoldsEmpty { fn default() -> Self { { diff --git a/tests/unit/out/refcount/field_method_receiver.rs b/tests/unit/out/refcount/field_method_receiver.rs index 976a9a5f6b..ab9abc1424 100644 --- a/tests/unit/out/refcount/field_method_receiver.rs +++ b/tests/unit/out/refcount/field_method_receiver.rs @@ -51,8 +51,8 @@ pub struct S { #[byte_size(24)] pub v: Vec, } -impl DefaultConstructible for S { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for S { + fn constructor(this: &Ptr, (): ()) { field!((*this), tag).write(0_i32); field!((*this), c).write(::default()); field!((*this), arr).write( @@ -63,6 +63,7 @@ impl DefaultConstructible for S { field!((*this), v).write(Vec::new()); } } +impl DefaultConstructible for S {} impl Default for S { fn default() -> Self { { diff --git a/tests/unit/out/refcount/field_pointers.rs b/tests/unit/out/refcount/field_pointers.rs index 2941553e5a..01ea743189 100644 --- a/tests/unit/out/refcount/field_pointers.rs +++ b/tests/unit/out/refcount/field_pointers.rs @@ -89,8 +89,8 @@ pub struct Outer { #[array_len(4)] pub buf: Box<[i32]>, } -impl DefaultConstructible for Outer { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Outer { + fn constructor(this: &Ptr, (): ()) { field!((*this), x).write(0_i32); field!((*this), inner).write(::default()); field!((*this), items).write((0..3).map(|_| ::default()).collect::>()); @@ -99,6 +99,7 @@ impl DefaultConstructible for Outer { field!((*this), buf).write((0..4).map(|_| 0_i32).collect::>()); } } +impl DefaultConstructible for Outer {} impl Default for Outer { fn default() -> Self { { diff --git a/tests/unit/out/refcount/fn_ptr_struct.rs b/tests/unit/out/refcount/fn_ptr_struct.rs index 76e2abf598..60f1285d46 100644 --- a/tests/unit/out/refcount/fn_ptr_struct.rs +++ b/tests/unit/out/refcount/fn_ptr_struct.rs @@ -65,13 +65,14 @@ pub struct MoveOnly { #[offset(0)] pub data_: i32, } -impl MoveConstructible for MoveOnly { - fn move_constructor(this: &Ptr, x: RvalueRef) { +impl ConstructibleFrom<(RvalueRef,)> for MoveOnly { + fn constructor(this: &Ptr, (x,): (RvalueRef,)) { let x = x.as_pointer(); field!((*this), data_).write(x.with(|__s| __s.data_)); field!(x, data_).write(0); } } +impl MoveConstructible for MoveOnly {} pub fn make_move_only_2(this: Ptr) { MoveOnlyImpl::construct(&this, 4); return; @@ -116,7 +117,10 @@ fn main_0() -> i32 { FnPtr::, Ptr)>::new(scale_move_only_3); object!(n, MoveOnly, |n| ({ let _arg0: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor(&_arg0.as_pointer(), RvalueRef::bind(m.as_pointer())); + ,)>>::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/for_body_destructor.rs b/tests/unit/out/refcount/for_body_destructor.rs index 282cb65648..831d33b269 100644 --- a/tests/unit/out/refcount/for_body_destructor.rs +++ b/tests/unit/out/refcount/for_body_destructor.rs @@ -29,6 +29,13 @@ impl Destructible for Guard { printf!(b"%d ", (*this).with(|__s| __s.digit)); } } +impl ConversionFunction>> for Guard { + fn conversion_function(this: LvalueRef>, to: Ptr) { + let this = &this.as_pointer(); + to.write(((*this).with(|__s| __s.digit) != 0)); + return; + } +} pub fn step_0(i: Ptr) { printf!(b"9 "); i.with_mut(|__v| { @@ -160,7 +167,14 @@ fn main_0() -> i32 { let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| { Destructible::destroy(&__p.as_pointer()) }); - if !({ GuardImpl::to_bool(&condition.as_pointer()) }) { + if !({ + let __v: Value = Rc::new(RefCell::new(false)); + >>>::conversion_function( + >>::bind(condition.as_pointer()), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }) { break; } 'for_body: { @@ -209,12 +223,4 @@ fn main_0() -> i32 { printf!(b"\n"); return 0; } -pub trait GuardImpl { - fn to_bool(&self) -> bool; -} -impl GuardImpl for Ptr { - fn to_bool(&self) -> bool { - return ((*self).with(|__s| __s.digit) != 0); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs index 51e5a772ea..e9e53fe5b3 100644 --- a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs @@ -28,12 +28,13 @@ pub struct S { #[offset(24)] pub a: i32, } -impl DefaultConstructible for S { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for S { + fn constructor(this: &Ptr, (): ()) { field!((*this), v).write(Vec::new()); field!((*this), a).write(0_i32); } } +impl DefaultConstructible for S {} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); diff --git a/tests/unit/out/refcount/forward_basic.rs b/tests/unit/out/refcount/forward_basic.rs index 87b85ec058..afbb2e3044 100644 --- a/tests/unit/out/refcount/forward_basic.rs +++ b/tests/unit/out/refcount/forward_basic.rs @@ -22,16 +22,17 @@ pub struct Tracked { #[offset(8)] pub moves: i32, } -impl CopyConstructible for Tracked { - fn copy_constructor(this: &Ptr, o: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> for Tracked { + fn 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: RvalueRef) { +impl CopyConstructible for Tracked {} +impl ConstructibleFrom<(RvalueRef,)> for Tracked { + fn 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)); @@ -39,6 +40,7 @@ impl MoveConstructible for Tracked { field!(o, v).write(0); } } +impl MoveConstructible for Tracked {} pub fn chosen_overload_0(_a0: Ptr) -> Overload { return Overload_kLvalueOverload; } @@ -140,10 +142,16 @@ pub trait HolderImpl { } impl HolderImpl for Ptr { fn construct_1(&self, x: Ptr) { - CopyConstructible::copy_constructor(&field_ptr!(self, t), LvalueRef::bind((x).clone())); + >,)>>::constructor( + &field_ptr!(self, t), + (LvalueRef::bind((x).clone()),), + ); } fn construct_2(&self, x: Ptr) { - MoveConstructible::move_constructor(&field_ptr!(self, t), RvalueRef::bind((x).clone())); + ,)>>::constructor( + &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 59247ce5cb..a268ad68a0 100644 --- a/tests/unit/out/refcount/forward_decltype.rs +++ b/tests/unit/out/refcount/forward_decltype.rs @@ -22,16 +22,17 @@ pub struct Tracked { #[offset(8)] pub moves: i32, } -impl CopyConstructible for Tracked { - fn copy_constructor(this: &Ptr, o: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> for Tracked { + fn 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: RvalueRef) { +impl CopyConstructible for Tracked {} +impl ConstructibleFrom<(RvalueRef,)> for Tracked { + fn 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)); @@ -39,6 +40,7 @@ impl MoveConstructible for Tracked { field!(o, v).write(0); } } +impl MoveConstructible for Tracked {} pub fn chosen_overload_0(_a0: Ptr) -> Overload { return Overload_kLvalueOverload; } diff --git a/tests/unit/out/refcount/forward_explicit.rs b/tests/unit/out/refcount/forward_explicit.rs index c9b44df499..df175ae1d2 100644 --- a/tests/unit/out/refcount/forward_explicit.rs +++ b/tests/unit/out/refcount/forward_explicit.rs @@ -24,16 +24,17 @@ pub struct Tracked { #[offset(8)] pub moves: i32, } -impl CopyConstructible for Tracked { - fn copy_constructor(this: &Ptr, o: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> for Tracked { + fn 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: RvalueRef) { +impl CopyConstructible for Tracked {} +impl ConstructibleFrom<(RvalueRef,)> for Tracked { + fn 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)); @@ -41,6 +42,7 @@ impl MoveConstructible for Tracked { field!(o, v).write(0); } } +impl MoveConstructible for Tracked {} pub fn chosen_overload_0(_a0: Ptr) -> Overload { return Overload_kLvalueOverload; } @@ -54,7 +56,10 @@ pub fn chosen_overload_3(_a0: Ptr) -> Overload { return Overload_kIntRvalueOverload; } pub fn copy_or_move_into_param_4(this: Ptr, t: Ptr) { - MoveConstructible::move_constructor(&this, RvalueRef::bind((t).clone())); + ,)>>::constructor( + &this, + (RvalueRef::bind((t).clone()),), + ); return; } pub fn main() { @@ -74,7 +79,10 @@ fn main_0() -> i32 { object!(b, Tracked(6)); object!(moved, Tracked, |moved| ({ let _t: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor(&_t.as_pointer(), RvalueRef::bind(b.as_pointer())); + ,)>>::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 +92,10 @@ fn main_0() -> i32 { object!(c, Tracked(7)); object!(copied, Tracked, |copied| ({ let _t: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor(&_t.as_pointer(), LvalueRef::bind(c.as_pointer())); + >,)>>::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 2e8357a76d..fbf262f6e0 100644 --- a/tests/unit/out/refcount/forward_pack.rs +++ b/tests/unit/out/refcount/forward_pack.rs @@ -24,16 +24,17 @@ pub struct Tracked { #[offset(8)] pub moves: i32, } -impl CopyConstructible for Tracked { - fn copy_constructor(this: &Ptr, o: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> for Tracked { + fn 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: RvalueRef) { +impl CopyConstructible for Tracked {} +impl ConstructibleFrom<(RvalueRef,)> for Tracked { + fn 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)); @@ -41,6 +42,7 @@ impl MoveConstructible for Tracked { field!(o, v).write(0); } } +impl MoveConstructible for Tracked {} pub fn chosen_overload_0(_a0: Ptr) -> Overload { return Overload_kLvalueOverload; } @@ -157,8 +159,14 @@ pub trait PairImpl { } impl PairImpl for Ptr { fn construct(&self, x: Ptr, y: Ptr) { - CopyConstructible::copy_constructor(&field_ptr!(self, a), LvalueRef::bind((x).clone())); - MoveConstructible::move_constructor(&field_ptr!(self, b), RvalueRef::bind((y).clone())); + >,)>>::constructor( + &field_ptr!(self, a), + (LvalueRef::bind((x).clone()),), + ); + ,)>>::constructor( + &field_ptr!(self, b), + (RvalueRef::bind((y).clone()),), + ); } } pub trait TrackedImpl { diff --git a/tests/unit/out/refcount/global_non_const_init.rs b/tests/unit/out/refcount/global_non_const_init.rs index af064c9639..555aa21027 100644 --- a/tests/unit/out/refcount/global_non_const_init.rs +++ b/tests/unit/out/refcount/global_non_const_init.rs @@ -38,17 +38,18 @@ pub struct Ctor { #[offset(0)] pub v: i32, } -impl DefaultConstructible for Ctor { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Ctor { + fn constructor(this: &Ptr, (): ()) { field!((*this), v).write(({ next_0() })); } } +impl DefaultConstructible for Ctor {} impl Default for Ctor { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -57,7 +58,7 @@ impl Default for Ctor { thread_local!( pub static default_ctor_7: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -123,17 +124,18 @@ impl Singleton { return s_15.with(|v| v.as_pointer()); } } -impl DefaultConstructible for Singleton { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Singleton { + fn constructor(this: &Ptr, (): ()) { field!((*this), hits).write(0); } } +impl DefaultConstructible for Singleton {} impl Default for Singleton { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -142,7 +144,7 @@ impl Default for Singleton { thread_local!( static s_15: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); diff --git a/tests/unit/out/refcount/huffman.rs b/tests/unit/out/refcount/huffman.rs index 48c9782dee..13f8611abe 100644 --- a/tests/unit/out/refcount/huffman.rs +++ b/tests/unit/out/refcount/huffman.rs @@ -69,8 +69,8 @@ pub struct MinHeap { #[byte_size(8)] pub alloc: Option>>, } -impl DefaultConstructible for MinHeap { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for MinHeap { + fn constructor(this: &Ptr, (): ()) { field!((*this), size).write(0_i32); field!((*this), capacity).write(0_i32); field!((*this), arr).write(None); @@ -78,6 +78,7 @@ impl DefaultConstructible for MinHeap { field!((*this), alloc).write(None); } } +impl DefaultConstructible for MinHeap {} pub fn AllocMinHeap_1(mut capacity: i32) -> Option> { let mut minHeap: Option> = Some(Rc::new(RefCell::new(MinHeap { size: 0, diff --git a/tests/unit/out/refcount/implicit_autoref.rs b/tests/unit/out/refcount/implicit_autoref.rs index a16f158f64..63c12ab3a4 100644 --- a/tests/unit/out/refcount/implicit_autoref.rs +++ b/tests/unit/out/refcount/implicit_autoref.rs @@ -26,11 +26,12 @@ pub struct Holder { #[byte_size(24)] pub v: Vec, } -impl DefaultConstructible for Holder { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Holder { + fn constructor(this: &Ptr, (): ()) { field!((*this), v).write(Vec::new()); } } +impl DefaultConstructible for Holder {} pub fn write_through_0(mut p: Ptr) { p.write(42); } diff --git a/tests/unit/out/refcount/in_class_field_initializer.rs b/tests/unit/out/refcount/in_class_field_initializer.rs index 017aa4a510..dcc3e7f9ff 100644 --- a/tests/unit/out/refcount/in_class_field_initializer.rs +++ b/tests/unit/out/refcount/in_class_field_initializer.rs @@ -14,12 +14,13 @@ pub struct Inner { #[offset(4)] pub y: i32, } -impl DefaultConstructible for Inner { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Inner { + fn constructor(this: &Ptr, (): ()) { field!((*this), x).write(3); field!((*this), y).write(4); } } +impl DefaultConstructible for Inner {} impl Default for Inner { fn default() -> Self { { Inner { x: 3, y: 4 } } @@ -39,14 +40,15 @@ pub struct S { #[byte_size(8)] pub d: Inner, } -impl DefaultConstructible for S { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for S { + fn constructor(this: &Ptr, (): ()) { field!((*this), a).write(1); field!((*this), b).write(2_i8); field!((*this), c).write(::default()); - DefaultConstructible::default_constructor(&field_ptr!(this, d)); + >::constructor(&field_ptr!(this, d), ()); } } +impl DefaultConstructible for S {} impl Default for S { fn default() -> Self { { diff --git a/tests/unit/out/refcount/init_list.rs b/tests/unit/out/refcount/init_list.rs index a4e5bc0ee3..68e3ac11cd 100644 --- a/tests/unit/out/refcount/init_list.rs +++ b/tests/unit/out/refcount/init_list.rs @@ -35,11 +35,12 @@ pub struct Holder { #[byte_size(8)] pub p: Pair, } -impl DefaultConstructible for Holder { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Holder { + fn constructor(this: &Ptr, (): ()) { field!((*this), p).write(Pair { a: 0, b: 0 }); } } +impl DefaultConstructible for Holder {} impl Default for Holder { fn default() -> Self { { @@ -58,11 +59,12 @@ pub struct Seven { #[offset(0)] pub v: i32, } -impl DefaultConstructible for Seven { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Seven { + fn constructor(this: &Ptr, (): ()) { field!((*this), v).write(7); } } +impl DefaultConstructible for Seven {} impl Default for Seven { fn default() -> Self { { Seven { v: 7 } } diff --git a/tests/unit/out/refcount/inline_container_fields.rs b/tests/unit/out/refcount/inline_container_fields.rs index 54b17067dd..c044a82aa3 100644 --- a/tests/unit/out/refcount/inline_container_fields.rs +++ b/tests/unit/out/refcount/inline_container_fields.rs @@ -31,13 +31,14 @@ pub struct Elem { #[byte_size(24)] pub coeffs: Vec, } -impl DefaultConstructible for Elem { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Elem { + fn constructor(this: &Ptr, (): ()) { field!((*this), id).write(0_i32); field!((*this), hist).write((0..4).map(|_| 0_i32).collect::>()); field!((*this), coeffs).write(Vec::new()); } } +impl DefaultConstructible for Elem {} impl Default for Elem { fn default() -> Self { { @@ -81,8 +82,8 @@ pub struct State { #[byte_size(24)] pub rows: Vec>, } -impl DefaultConstructible for State { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for State { + fn constructor(this: &Ptr, (): ()) { field!((*this), count).write(0_i32); field!((*this), grid).write( (0..2) @@ -96,6 +97,7 @@ impl DefaultConstructible for State { field!((*this), rows).write(Vec::new()); } } +impl DefaultConstructible for State {} impl Default for State { fn default() -> Self { { @@ -188,26 +190,29 @@ pub struct Counted { #[offset(0)] pub v: i32, } -impl DefaultConstructible for Counted { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Counted { + fn constructor(this: &Ptr, (): ()) { field!((*this), v).write(0); } } -impl CopyConstructible for Counted { - fn copy_constructor(this: &Ptr, o: LvalueRef>) { +impl DefaultConstructible for Counted {} +impl ConstructibleFrom<(LvalueRef>,)> for Counted { + fn 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: RvalueRef) { +impl CopyConstructible for Counted {} +impl ConstructibleFrom<(RvalueRef,)> for Counted { + fn 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 MoveConstructible for Counted {} impl CopyAssignable for Counted { fn copy_assign(this: &Ptr, o: LvalueRef>) -> Ptr { let o = o.as_pointer(); @@ -403,10 +408,7 @@ fn main_0() -> i32 { )); let __p: Ptr = __v.decay(); for __i in 0..3 { - MoveConstructible::move_constructor( - &__p.offset(__i), - RvalueRef::bind(ca.decay().offset(__i)), - ); + ::constructor(&__p.offset(__i), (RvalueRef::bind(ca.decay().offset(__i)),)); } Rc::try_unwrap(__v).ok().unwrap().into_inner() })); @@ -464,10 +466,7 @@ fn main_0() -> i32 { )); let __p: Ptr> = __v.decay(); for __i in 0..2 { - MoveConstructible::move_constructor( - &__p.offset(__i), - RvalueRef::bind(va.decay().offset(__i)), - ); + >::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/kruskal.rs b/tests/unit/out/refcount/kruskal.rs index c7bed88aaa..75d7bc0848 100644 --- a/tests/unit/out/refcount/kruskal.rs +++ b/tests/unit/out/refcount/kruskal.rs @@ -125,13 +125,14 @@ pub struct DisjointSet { #[offset(16)] pub n: i32, } -impl DefaultConstructible for DisjointSet { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for DisjointSet { + fn constructor(this: &Ptr, (): ()) { field!((*this), rank).write(None); field!((*this), parent).write(None); field!((*this), n).write(0_i32); } } +impl DefaultConstructible for DisjointSet {} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, )] @@ -146,13 +147,14 @@ pub struct Graph { #[offset(12)] pub E: i32, } -impl DefaultConstructible for Graph { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Graph { + fn constructor(this: &Ptr, (): ()) { field!((*this), edges).write(None); field!((*this), V).write(0_i32); field!((*this), E).write(0_i32); } } +impl DefaultConstructible for Graph {} pub fn MSTKruskal_2(graph: Ptr) -> f64 { ({ quicksort_1(field_ptr!(graph, edges), 0, (graph.with(|__s| __s.E) - 1)) }); let set: Value = Rc::new(RefCell::new(DisjointSet { diff --git a/tests/unit/out/refcount/lambda_as_field.rs b/tests/unit/out/refcount/lambda_as_field.rs index e27f614aa6..84fae79ff6 100644 --- a/tests/unit/out/refcount/lambda_as_field.rs +++ b/tests/unit/out/refcount/lambda_as_field.rs @@ -105,16 +105,17 @@ pub struct Moving__lambda_at_lambda_as_field_cpp_64_12__ { #[offset(4)] pub moves: i32, } -impl MoveConstructible for Moving__lambda_at_lambda_as_field_cpp_64_12__ { - fn move_constructor( +impl ConstructibleFrom<(RvalueRef,)> for Moving__lambda_at_lambda_as_field_cpp_64_12__ { + fn constructor( this: &Ptr, - o: RvalueRef, + (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)); } } +impl MoveConstructible for Moving__lambda_at_lambda_as_field_cpp_64_12__ {} impl Default for Moving__lambda_at_lambda_as_field_cpp_64_12__ { fn default() -> Self { { ::zero_init() } diff --git a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs index 49441c12e7..d837a6c02c 100644 --- a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs @@ -14,32 +14,35 @@ pub struct Counted { #[offset(4)] pub moves: i32, } -impl DefaultConstructible for Counted { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Counted { + fn constructor(this: &Ptr, (): ()) { field!((*this), copies).write(0); field!((*this), moves).write(0); } } -impl CopyConstructible for Counted { - fn copy_constructor(this: &Ptr, o: LvalueRef>) { +impl DefaultConstructible for Counted {} +impl ConstructibleFrom<(LvalueRef>,)> for Counted { + fn 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: RvalueRef) { +impl CopyConstructible for Counted {} +impl ConstructibleFrom<(RvalueRef,)> for Counted { + fn 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)); } } +impl MoveConstructible for Counted {} impl Default for Counted { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -51,19 +54,22 @@ thread_local!( #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg)] #[byte_size(1)] pub struct Dropped {} -impl DefaultConstructible for Dropped { - fn default_constructor(this: &Ptr) {} +impl ConstructibleFrom<()> for Dropped { + fn constructor(this: &Ptr, (): ()) {} } -impl CopyConstructible for Dropped { - fn copy_constructor(this: &Ptr, _a0: LvalueRef>) { +impl DefaultConstructible for Dropped {} +impl ConstructibleFrom<(LvalueRef>,)> for Dropped { + fn constructor(this: &Ptr, (_a0,): (LvalueRef>,)) { let _a0 = _a0.as_pointer(); } } -impl MoveConstructible for Dropped { - fn move_constructor(this: &Ptr, _a0: RvalueRef) { +impl CopyConstructible for Dropped {} +impl ConstructibleFrom<(RvalueRef,)> for Dropped { + fn constructor(this: &Ptr, (_a0,): (RvalueRef,)) { let _a0 = _a0.as_pointer(); } } +impl MoveConstructible for Dropped {} impl Destructible for Dropped { fn destroy(this: &Ptr) { (*drops_0.with(Value::clone).borrow_mut()).postfix_inc(); @@ -79,9 +85,9 @@ fn main_0() -> i32 { { let c: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor( + >,)>>::constructor( &__v.as_pointer(), - LvalueRef::bind(c.as_pointer()), + (LvalueRef::bind(c.as_pointer()),), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); @@ -98,35 +104,18 @@ fn main_0() -> i32 { assert!(({ (({ (*h.borrow()).call() }) == 11) })); let mut returned: i32 = { let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); - { - ({ - lambda!( - { - let c: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor( - &__v.as_pointer(), - LvalueRef::bind(c.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); - }, - |this: Ptr| { - CopyConstructible::copy_constructor(&this, LvalueRef::bind(c.as_pointer())); - return; - } - ) - .call(Ptr::clone(&__tmp_0.as_pointer())) - }); - __tmp_0.as_pointer() - } - .with(|__s| __s.copies) + { ( { lambda! ( { let c : Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); >,)>>::constructor(&__v.as_pointer(), (LvalueRef::bind(c .as_pointer() ),)) ; +Rc::try_unwrap(__v).ok().unwrap().into_inner() } )) ; +} , | this: Ptr< Counted > , | { >,)>>::constructor(&this, (LvalueRef::bind(c .as_pointer() ),)) ; +return ; +; +} ) .call ( Ptr::clone(&__tmp_0.as_pointer()) , ) } ) ; __tmp_0.as_pointer() } .with(|__s| __s . copies ) }; assert!((returned == 2)); let arr: Value> = Rc::new(RefCell::new(Box::new( std::array::from_fn::<_, 2, _>(|_| { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }), ))); @@ -135,9 +124,9 @@ 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())); - CopyConstructible::copy_constructor( + >,)>>::constructor( &__v.as_pointer(), - LvalueRef::bind(arr.decay().offset(__i)), + (LvalueRef::bind(arr.decay().offset(__i)),), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }), @@ -159,7 +148,7 @@ fn main_0() -> i32 { { let d: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -177,7 +166,7 @@ fn main_0() -> i32 { { let d: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -195,7 +184,7 @@ fn main_0() -> i32 { { let d: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, diff --git a/tests/unit/out/refcount/lambda_decltype_type.rs b/tests/unit/out/refcount/lambda_decltype_type.rs index 1add8e940a..2e2a8f4420 100644 --- a/tests/unit/out/refcount/lambda_decltype_type.rs +++ b/tests/unit/out/refcount/lambda_decltype_type.rs @@ -19,8 +19,8 @@ pub struct Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { #[byte_size(1)] pub cmp: FnPtr bool>, } -impl DefaultConstructible for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { + fn constructor(this: &Ptr, (): ()) { field!((*this), items).write((0..4).map(|_| 0_i32).collect::>()); field!((*this), size).write(0); field!((*this), cmp).write(FnPtr:: bool>::new( @@ -32,6 +32,7 @@ impl DefaultConstructible for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ )); } } +impl DefaultConstructible for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ {} impl Default for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { fn default() -> Self { { @@ -60,8 +61,8 @@ pub struct Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { #[byte_size(1)] pub cmp: FnPtr bool>, } -impl DefaultConstructible for Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { + fn constructor(this: &Ptr, (): ()) { field!((*this), items).write((0..4).map(|_| 0_i32).collect::>()); field!((*this), size).write(0); field!((*this), cmp).write(FnPtr:: bool>::new( @@ -73,6 +74,7 @@ impl DefaultConstructible for Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ )); } } +impl DefaultConstructible for Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ {} impl Default for Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { fn default() -> Self { { diff --git a/tests/unit/out/refcount/lambda_immediate_init.rs b/tests/unit/out/refcount/lambda_immediate_init.rs index d5fe2f87bd..b473f54709 100644 --- a/tests/unit/out/refcount/lambda_immediate_init.rs +++ b/tests/unit/out/refcount/lambda_immediate_init.rs @@ -17,8 +17,8 @@ pub struct S { #[offset(4)] pub k: i32, } -impl DefaultConstructible for S { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for S { + fn constructor(this: &Ptr, (): ()) { field!((*this), j).write(10); field!((*this), k).write( (({ @@ -32,6 +32,7 @@ impl DefaultConstructible for S { ); } } +impl DefaultConstructible for S {} impl Default for S { fn default() -> Self { { diff --git a/tests/unit/out/refcount/lambda_move_only_capture.rs b/tests/unit/out/refcount/lambda_move_only_capture.rs index 784bb741ca..3447ccb918 100644 --- a/tests/unit/out/refcount/lambda_move_only_capture.rs +++ b/tests/unit/out/refcount/lambda_move_only_capture.rs @@ -14,13 +14,14 @@ pub struct Owner { #[byte_size(8)] pub p: Ptr, } -impl MoveConstructible for Owner { - fn move_constructor(this: &Ptr, o: RvalueRef) { +impl ConstructibleFrom<(RvalueRef,)> for Owner { + fn 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()); } } +impl MoveConstructible for Owner {} impl Destructible for Owner { fn destroy(this: &Ptr) { (*this).with(|__s| __s.p.clone()).delete(); @@ -36,9 +37,9 @@ fn main_0() -> i32 { { let h: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor( + ,)>>::constructor( &__v.as_pointer(), - RvalueRef::bind(o.as_pointer()), + (RvalueRef::bind(o.as_pointer()),), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); @@ -101,9 +102,9 @@ impl OwnerImpl for Ptr { { let self_: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor( + ,)>>::constructor( &__v.as_pointer(), - RvalueRef::bind((*self).clone()), + (RvalueRef::bind((*self).clone()),), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); diff --git a/tests/unit/out/refcount/libc_struct_without_default.rs b/tests/unit/out/refcount/libc_struct_without_default.rs index d3c2ddbd59..b5724743e6 100644 --- a/tests/unit/out/refcount/libc_struct_without_default.rs +++ b/tests/unit/out/refcount/libc_struct_without_default.rs @@ -29,14 +29,15 @@ pub struct UserDefined { #[byte_size(24)] pub v: Vec, } -impl DefaultConstructible for UserDefined { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for UserDefined { + fn constructor(this: &Ptr, (): ()) { field!((*this), a).write(Box::<[i32]>::from(std::array::from_fn::<_, 1, _>(|_| { 0_i32 }))); field!((*this), v).write(Vec::new()); } } +impl DefaultConstructible for UserDefined {} impl Default for UserDefined { fn default() -> Self { { diff --git a/tests/unit/out/refcount/map.rs b/tests/unit/out/refcount/map.rs index b13f4eaff4..470a8694e9 100644 --- a/tests/unit/out/refcount/map.rs +++ b/tests/unit/out/refcount/map.rs @@ -23,18 +23,19 @@ pub struct Point { #[offset(4)] pub y: i32, } -impl DefaultConstructible for Point { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Point { + fn constructor(this: &Ptr, (): ()) { field!((*this), x).write(0); field!((*this), y).write(0); } } +impl DefaultConstructible for Point {} impl Default for Point { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.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 80f1ee132e..7f0704a6aa 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -24,20 +24,22 @@ pub struct Key { #[offset(0)] pub k: i32, } -impl CopyConstructible for Key { - fn copy_constructor(this: &Ptr, o: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> for Key { + fn 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: RvalueRef) { +impl CopyConstructible for Key {} +impl ConstructibleFrom<(RvalueRef,)> for Key { + fn 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(); } } +impl MoveConstructible for Key {} impl CppLess for Key { fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { KeyImpl::operator_lt(__lhs, __rhs.clone()) diff --git a/tests/unit/out/refcount/map_key_identity.rs b/tests/unit/out/refcount/map_key_identity.rs index eb19207a9c..4a052d97cb 100644 --- a/tests/unit/out/refcount/map_key_identity.rs +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -50,18 +50,19 @@ pub struct Mapped { #[offset(0)] pub value: i32, } -impl DefaultConstructible for Mapped { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Mapped { + fn constructor(this: &Ptr, (): ()) { field!((*this), value).write(0); (*default_constructions_0.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl DefaultConstructible for Mapped {} impl Default for Mapped { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index 51526799e4..e27974cf80 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -25,32 +25,35 @@ pub struct Item { #[offset(0)] pub value: i32, } -impl DefaultConstructible for Item { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Item { + fn constructor(this: &Ptr, (): ()) { field!((*this), value).write(0); } } -impl CopyConstructible for Item { - fn copy_constructor(this: &Ptr, other: LvalueRef>) { +impl DefaultConstructible for Item {} +impl ConstructibleFrom<(LvalueRef>,)> for Item { + fn 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: RvalueRef) { +impl CopyConstructible for Item {} +impl ConstructibleFrom<(RvalueRef,)> for Item { + fn 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); } } +impl MoveConstructible for Item {} impl Default for Item { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -66,17 +69,18 @@ pub struct RefItem { #[offset(0)] pub value: i32, } -impl DefaultConstructible for RefItem { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for RefItem { + fn constructor(this: &Ptr, (): ()) { field!((*this), value).write(0); } } +impl DefaultConstructible for RefItem {} impl Default for RefItem { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -382,9 +386,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())); - CopyConstructible::copy_constructor( + >,)>>::constructor( &__v.as_pointer(), - LvalueRef::bind((__tmp_6).clone()), + (LvalueRef::bind((__tmp_6).clone()),), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -424,9 +428,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())); - MoveConstructible::move_constructor( + ,)>>::constructor( &__v.as_pointer(), - RvalueRef::bind((__tmp_7).clone()), + (RvalueRef::bind((__tmp_7).clone()),), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -465,9 +469,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())); - CopyConstructible::copy_constructor( + >,)>>::constructor( &__v.as_pointer(), - LvalueRef::bind((__tmp_8).clone()), + (LvalueRef::bind((__tmp_8).clone()),), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -508,9 +512,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())); - MoveConstructible::move_constructor( + ,)>>::constructor( &__v.as_pointer(), - RvalueRef::bind((__tmp_9).clone()), + (RvalueRef::bind((__tmp_9).clone()),), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -659,9 +663,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())); - MoveConstructible::move_constructor( + ,)>>::constructor( &__v.as_pointer(), - RvalueRef::bind((__tmp_12).clone()), + (RvalueRef::bind((__tmp_12).clone()),), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -702,9 +706,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())); - MoveConstructible::move_constructor( + ,)>>::constructor( &__v.as_pointer(), - RvalueRef::bind((__tmp_14).clone()), + (RvalueRef::bind((__tmp_14).clone()),), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), diff --git a/tests/unit/out/refcount/map_try_emplace_lvalues.rs b/tests/unit/out/refcount/map_try_emplace_lvalues.rs index b12eb41467..421a8997ad 100644 --- a/tests/unit/out/refcount/map_try_emplace_lvalues.rs +++ b/tests/unit/out/refcount/map_try_emplace_lvalues.rs @@ -18,17 +18,18 @@ pub struct Item { #[offset(0)] pub value: i32, } -impl DefaultConstructible for Item { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Item { + fn constructor(this: &Ptr, (): ()) { field!((*this), value).write(0); } } +impl DefaultConstructible for Item {} impl Default for Item { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -57,19 +58,20 @@ pub struct Temporary { #[array_len(2)] pub data: Box<[i32]>, } -impl DefaultConstructible for Temporary { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Temporary { + fn constructor(this: &Ptr, (): ()) { field!((*this), n).write(5); field!((*this), data).write(Box::new([6, 7])); (*temporary_calls_4.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl DefaultConstructible for Temporary {} impl Default for Temporary { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -84,22 +86,23 @@ pub struct Nested { #[byte_size(12)] pub inner: Temporary, } -impl DefaultConstructible for Nested { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, inner)); +impl ConstructibleFrom<()> for Nested { + fn constructor(this: &Ptr, (): ()) { + >::constructor(&field_ptr!(this, inner), ()); } } +impl DefaultConstructible for Nested {} pub fn make_temporary_5() -> Temporary { return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } pub fn make_nested_6() -> Nested { return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -111,21 +114,22 @@ pub struct Owner { #[byte_size(8)] pub ptr: Option>, } -impl DefaultConstructible for Owner { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Owner { + fn constructor(this: &Ptr, (): ()) { field!((*this), ptr).write(Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })))); } } +impl DefaultConstructible for Owner {} impl Default for Owner { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -137,11 +141,12 @@ pub struct Noncopy { #[offset(0)] pub n: i32, } -impl DefaultConstructible for Noncopy { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Noncopy { + fn constructor(this: &Ptr, (): ()) { field!((*this), n).write(5); } } +impl DefaultConstructible for Noncopy {} impl Default for Noncopy { fn default() -> Self { { Noncopy { n: 5 } } @@ -157,17 +162,18 @@ pub struct Held { #[byte_size(8)] pub ptr: Ptr, } -impl DefaultConstructible for Held { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Held { + fn constructor(this: &Ptr, (): ()) { field!((*this), ptr).write(Ptr::::null()); } } +impl DefaultConstructible for Held {} impl Default for Held { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -283,7 +289,7 @@ thread_local!( (*{ __tmp_7 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_7 @@ -1846,7 +1852,10 @@ fn main_0() -> i32 { __tmp_94 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor( + &__v.as_pointer(), + (), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_94 @@ -1883,7 +1892,10 @@ fn main_0() -> i32 { __tmp_96 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor( + &__v.as_pointer(), + (), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_96 @@ -1921,7 +1933,10 @@ fn main_0() -> i32 { __tmp_98 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor( + &__v.as_pointer(), + (), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_98 @@ -1958,7 +1973,10 @@ fn main_0() -> i32 { __tmp_100 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor( + &__v.as_pointer(), + (), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_100 @@ -1994,7 +2012,10 @@ fn main_0() -> i32 { __tmp_102 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor( + &__v.as_pointer(), + (), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_102 @@ -2030,7 +2051,10 @@ fn main_0() -> i32 { __tmp_104 = Some(Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor( + &__v.as_pointer(), + (), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })))))); &mut __tmp_104 @@ -2129,40 +2153,11 @@ fn main_0() -> i32 { let mut __tmp_107: Option>; { match (if (choose != 0) { - field_ptr!( - (*{ - __tmp_106 = Some(Rc::new(RefCell::new({ - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - DefaultConstructible::default_constructor( - &__v.as_pointer(), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }))); - &mut __tmp_106 - }) - .as_pointer(), - n - ) + field_ptr!(( *{ __tmp_106 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); >::constructor(&__v.as_pointer(), ()) ; +Rc::try_unwrap(__v).ok().unwrap().into_inner() } ))) ; & mut __tmp_106 } ) .as_pointer() , n) } else { - array_field_ptr!( - (*{ - __tmp_107 = Some(Rc::new(RefCell::new({ - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - DefaultConstructible::default_constructor( - &__v.as_pointer(), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }))); - &mut __tmp_107 - }) - .as_pointer(), - data - ) - .offset((index.postfix_inc()) as isize) + array_field_ptr!(( *{ __tmp_107 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); >::constructor(&__v.as_pointer(), ()) ; +Rc::try_unwrap(__v).ok().unwrap().into_inner() } ))) ; & mut __tmp_107 } ) .as_pointer() , data) . offset ( ( index . postfix_inc () ) as isize ) },) { (__tmp_105,) => { @@ -2224,8 +2219,9 @@ fn main_0() -> i32 { { match (({ OwnerImpl::value(&{ - DefaultConstructible::default_constructor( + >::constructor( &__tmp_109.as_pointer(), + (), ); __tmp_109.as_pointer() }) @@ -2301,7 +2297,7 @@ fn main_0() -> i32 { match ({ __tmp_111 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))))); __tmp_111.as_pointer() @@ -2341,7 +2337,7 @@ fn main_0() -> i32 { match ({ __tmp_113 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))))); __tmp_113.as_pointer() diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index d5313f931d..1247e6bc11 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -40,13 +40,14 @@ pub struct Bag { #[offset(0)] pub n: i32, } -impl CopyConstructible for Bag { - fn copy_constructor(this: &Ptr, o: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> for Bag { + fn 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(); } } +impl CopyConstructible for Bag {} impl CppLess for Bag { fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { operator_lt_4(__lhs.clone(), __rhs.clone()) diff --git a/tests/unit/out/refcount/move_assign.rs b/tests/unit/out/refcount/move_assign.rs index 80cc71bc26..7ffca2d1db 100644 --- a/tests/unit/out/refcount/move_assign.rs +++ b/tests/unit/out/refcount/move_assign.rs @@ -22,13 +22,14 @@ pub struct MoveOnly { #[offset(0)] pub v: i32, } -impl MoveConstructible for MoveOnly { - fn move_constructor(this: &Ptr, o: RvalueRef) { +impl ConstructibleFrom<(RvalueRef,)> for MoveOnly { + fn 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 MoveConstructible for MoveOnly {} impl MoveAssignable for MoveOnly { fn move_assign(this: &Ptr, o: RvalueRef) -> Ptr { let o = o.as_pointer(); @@ -46,18 +47,19 @@ pub struct ConstMoveAssign { #[offset(0)] pub mark: i32, } -impl DefaultConstructible for ConstMoveAssign { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for ConstMoveAssign { + fn constructor(this: &Ptr, (): ()) { field!((*this), mark).write(0); } } +impl DefaultConstructible for ConstMoveAssign {} impl Default for ConstMoveAssign { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -65,7 +67,10 @@ impl Default for ConstMoveAssign { } pub fn make_0(this: Ptr, mut v: i32) { object!(m, MoveOnly(v)); - MoveConstructible::move_constructor(&this, RvalueRef::bind(m.as_pointer())); + ,)>>::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 1543ac1a03..f55f54d3f7 100644 --- a/tests/unit/out/refcount/move_ctor.rs +++ b/tests/unit/out/refcount/move_ctor.rs @@ -15,30 +15,32 @@ pub struct MoveOnly { #[offset(0)] pub v: i32, } -impl MoveConstructible for MoveOnly { - fn move_constructor(this: &Ptr, o: RvalueRef) { +impl ConstructibleFrom<(RvalueRef,)> for MoveOnly { + fn 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 MoveConstructible for MoveOnly {} #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] #[byte_size(4)] pub struct ConstMove { #[offset(0)] pub mark: i32, } -impl DefaultConstructible for ConstMove { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for ConstMove { + fn constructor(this: &Ptr, (): ()) { field!((*this), mark).write(0); } } +impl DefaultConstructible for ConstMove {} impl Default for ConstMove { fn default() -> Self { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + >::constructor(&__v.as_pointer(), ()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -57,16 +59,17 @@ pub struct ThrowingMove { #[offset(8)] pub moves: i32, } -impl CopyConstructible for ThrowingMove { - fn copy_constructor(this: &Ptr, o: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> for ThrowingMove { + fn 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: RvalueRef) { +impl CopyConstructible for ThrowingMove {} +impl ConstructibleFrom<(RvalueRef,)> for ThrowingMove { + fn 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)); @@ -74,6 +77,7 @@ impl MoveConstructible for ThrowingMove { field!(o, v).write(0); } } +impl MoveConstructible for ThrowingMove {} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, )] @@ -87,16 +91,17 @@ pub struct NoexceptMove { #[offset(8)] pub moves: i32, } -impl CopyConstructible for NoexceptMove { - fn copy_constructor(this: &Ptr, o: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> for NoexceptMove { + fn 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: RvalueRef) { +impl CopyConstructible for NoexceptMove {} +impl ConstructibleFrom<(RvalueRef,)> for NoexceptMove { + fn 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)); @@ -104,12 +109,16 @@ impl MoveConstructible for NoexceptMove { field!(o, v).write(0); } } +impl MoveConstructible for NoexceptMove {} pub fn by_value_0(m: Ptr) -> i32 { return m.with(|__s| __s.v); } pub fn make_1(this: Ptr, mut v: i32) { object!(m, MoveOnly(v)); - MoveConstructible::move_constructor(&this, RvalueRef::bind(m.as_pointer())); + ,)>>::constructor( + &this, + (RvalueRef::bind(m.as_pointer()),), + ); return; } pub fn main() { @@ -139,7 +148,10 @@ fn main_0() -> i32 { assert!( (({ let _m: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor(&_m.as_pointer(), RvalueRef::bind(e.as_pointer())); + ,)>>::constructor( + &_m.as_pointer(), + (RvalueRef::bind(e.as_pointer()),), + ); by_value_0(_m.as_pointer()) }) == 5) ); diff --git a/tests/unit/out/refcount/move_this.rs b/tests/unit/out/refcount/move_this.rs index 96aa283c64..556b7f7063 100644 --- a/tests/unit/out/refcount/move_this.rs +++ b/tests/unit/out/refcount/move_this.rs @@ -15,19 +15,21 @@ pub struct Chain { #[offset(0)] pub v: i32, } -impl CopyConstructible for Chain { - fn copy_constructor(this: &Ptr, o: LvalueRef>) { +impl ConstructibleFrom<(LvalueRef>,)> for Chain { + fn 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: RvalueRef) { +impl CopyConstructible for Chain {} +impl ConstructibleFrom<(RvalueRef,)> for Chain { + fn 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); } } +impl MoveConstructible for Chain {} pub fn consume_0(c: Ptr) -> i32 { return c.with(|__s| __s.v); } @@ -67,9 +69,9 @@ fn main_0() -> i32 { assert!( (({ let _c: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor( + ,)>>::constructor( &_c.as_pointer(), - RvalueRef::bind(({ ChainImpl::self_(&g.as_pointer()) })), + (RvalueRef::bind(({ ChainImpl::self_(&g.as_pointer()) })),), ); consume_0(_c.as_pointer()) }) == 21) @@ -106,11 +108,17 @@ impl ChainImpl for Ptr { return (*self).clone(); } fn take(&self, this: Ptr) { - MoveConstructible::move_constructor(&this, RvalueRef::bind((*self).clone())); + ,)>>::constructor( + &this, + (RvalueRef::bind((*self).clone()),), + ); return; } fn copy(&self, this: Ptr) { - CopyConstructible::copy_constructor(&this, LvalueRef::bind((*self).clone())); + >,)>>::constructor( + &this, + (LvalueRef::bind((*self).clone()),), + ); return; } fn self_(&self) -> Ptr { diff --git a/tests/unit/out/refcount/operator_comparison_nonbool.rs b/tests/unit/out/refcount/operator_comparison_nonbool.rs index 95c9dae3de..26740b12a0 100644 --- a/tests/unit/out/refcount/operator_comparison_nonbool.rs +++ b/tests/unit/out/refcount/operator_comparison_nonbool.rs @@ -125,12 +125,19 @@ impl CppEq for Mixed { TriviallyCopyable, Default, )] -#[cpp_into(bool, to_bool)] #[byte_size(1)] pub struct MyBool { #[offset(0)] pub value: bool, } +impl ConversionFunction>> for MyBool { + fn conversion_function(this: LvalueRef>, to: Ptr) { + let this = &this.as_pointer(); + to.write((*this).with(|__s| __s.value)); + return; + } +} +impl ImplicitConversionFunction>> for MyBool {} #[derive( Copy, Clone, @@ -152,7 +159,12 @@ impl CppLess for Boolish { fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { { let __cmp = operator_lt_6(__lhs.read(), __rhs.read()); - MyBoolImpl::to_bool(&Rc::new(RefCell::new(__cmp)).as_pointer()) + let __v: Value = Rc::new(RefCell::new(false)); + >>>::conversion_function( + >>::bind(Rc::new(RefCell::new(__cmp)).as_pointer()), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } } @@ -160,7 +172,12 @@ impl CppEq for Boolish { fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { { let __cmp = operator_eq_7(__lhs.read(), __rhs.read()); - MyBoolImpl::to_bool(&Rc::new(RefCell::new(__cmp)).as_pointer()) + let __v: Value = Rc::new(RefCell::new(false)); + >>>::conversion_function( + >>::bind(Rc::new(RefCell::new(__cmp)).as_pointer()), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } } @@ -190,12 +207,19 @@ pub fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { Default, )] #[memberwise(copy_assign)] -#[cpp_into(bool, to_bool)] #[byte_size(1)] pub struct RefBool { #[offset(0)] pub value: bool, } +impl ConversionFunction>> for RefBool { + fn conversion_function(this: LvalueRef>, to: Ptr) { + let this = &this.as_pointer(); + to.write((*this).with(|__s| __s.value)); + return; + } +} +impl ImplicitConversionFunction>> for RefBool {} thread_local!( pub static ref_true_8: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); @@ -224,7 +248,12 @@ impl CppEq for RefInt { fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { { let __cmp = RefIntImpl::operator_eq(__lhs, __rhs.clone()); - RefBoolImpl::to_bool(&__cmp) + let __v: Value = Rc::new(RefCell::new(false)); + >>>::conversion_function( + >>::bind(__cmp.clone()), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } } @@ -282,16 +311,26 @@ fn main_0() -> i32 { assert!((({ MixedImpl::operator_lt(&ms.decay().offset(0), ms.decay().offset(1),) }) == 8)); let mut b1: Boolish = Boolish { v: 1 }; let mut b2: Boolish = Boolish { v: 2 }; - assert!( - ({ - MyBoolImpl::to_bool( - &Rc::new(RefCell::new(({ operator_eq_7(b1, Boolish { v: 1 }) }))).as_pointer(), - ) - }) - ); + assert!({ + let __v: Value = Rc::new(RefCell::new(false)); + >>>::conversion_function( + >>::bind( + Rc::new(RefCell::new(({ operator_eq_7(b1, Boolish { v: 1 }) }))).as_pointer(), + ), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); assert!( !({ - MyBoolImpl::to_bool(&Rc::new(RefCell::new(({ operator_lt_6(b2, b1) }))).as_pointer()) + let __v: Value = Rc::new(RefCell::new(false)); + >>>::conversion_function( + >>::bind( + Rc::new(RefCell::new(({ operator_lt_6(b2, b1) }))).as_pointer(), + ), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() }) ); let mut lt: MyBool = ({ operator_lt_6(b1, b2) }); @@ -314,13 +353,16 @@ fn main_0() -> i32 { ); let ri1: Value = Rc::new(RefCell::new(RefInt { v: 1 })); let ri2: Value = Rc::new(RefCell::new(RefInt { v: 2 })); - assert!( - ({ - RefBoolImpl::to_bool( - &({ RefIntImpl::operator_eq(&ri1.as_pointer(), ri2.as_pointer()) }), - ) - }) - ); + assert!({ + let __v: Value = Rc::new(RefCell::new(false)); + >>>::conversion_function( + >>::bind( + ({ RefIntImpl::operator_eq(&ri1.as_pointer(), ri2.as_pointer()) }), + ), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); let ris: Value> = Rc::new(RefCell::new(Box::new([RefInt { v: 1 }, RefInt { v: 2 }]))); assert!( @@ -373,27 +415,19 @@ impl MixedImpl for Ptr { } pub trait MyBoolImpl { fn construct(&self, v: bool); - fn to_bool(&self) -> bool; } impl MyBoolImpl for Ptr { fn construct(&self, mut v: bool) { field!((*self), value).write(v); } - fn to_bool(&self) -> bool { - return (*self).with(|__s| __s.value); - } } pub trait RefBoolImpl { fn construct(&self, v: bool); - fn to_bool(&self) -> bool; } impl RefBoolImpl for Ptr { fn construct(&self, mut v: bool) { field!((*self), value).write(v); } - fn to_bool(&self) -> bool { - return (*self).with(|__s| __s.value); - } } pub trait RefIntImpl { fn operator_eq(&self, _a0: Ptr) -> Ptr; diff --git a/tests/unit/out/refcount/operator_other_member.rs b/tests/unit/out/refcount/operator_other_member.rs index 14e4b3ba85..1f928d20c4 100644 --- a/tests/unit/out/refcount/operator_other_member.rs +++ b/tests/unit/out/refcount/operator_other_member.rs @@ -38,12 +38,26 @@ impl Static { TriviallyCopyable, Default, )] -#[cpp_into(i32, to_i32)] #[byte_size(4)] pub struct S { #[offset(0)] pub v: i32, } +impl ConversionFunction>> for S { + fn conversion_function(this: LvalueRef>, to: Ptr) { + let this = &this.as_pointer(); + to.write((*this).with(|__s| __s.v)); + return; + } +} +impl ImplicitConversionFunction>> for S {} +impl ConversionFunction>> for S { + fn conversion_function(this: LvalueRef>, to: Ptr) { + let this = &this.as_pointer(); + to.write(((*this).with(|__s| __s.v) != 0)); + return; + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -55,18 +69,81 @@ fn main_0() -> i32 { assert!((({ SImpl::operator_call_2(&s.as_pointer(), 1,) }) == 4)); assert!((({ SImpl::operator_call_3(&s.as_pointer(), 1, 2,) }) == 6)); assert!(({ ({ SImpl::operator_comma(&s.as_pointer(), t.as_pointer(),) }).v } == 34)); - let mut i: i32 = ({ SImpl::to_i32(&s.as_pointer()) }); + let mut i: i32 = { + let __v: Value = Rc::new(RefCell::new(0_i32)); + >>>::conversion_function( + >>::bind(s.as_pointer()), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((i == 3)); - assert!(((({ SImpl::to_i32(&s.as_pointer(),) }) + 1) == 4)); - if ({ SImpl::to_bool(&s.as_pointer()) }) { - assert!(({ SImpl::to_bool(&s.as_pointer(),) })); + assert!( + (({ + let __v: Value = Rc::new(RefCell::new(0_i32)); + >>>::conversion_function( + >>::bind(s.as_pointer()), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + 1) + == 4) + ); + if { + let __v: Value = Rc::new(RefCell::new(false)); + >>>::conversion_function( + >>::bind(s.as_pointer()), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } { + assert!({ + let __v: Value = Rc::new(RefCell::new(false)); + >>>::conversion_function( + >>::bind(s.as_pointer()), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); } else { assert!(false); } let z: Value = Rc::new(RefCell::new(S { v: 0 })); - assert!(({ SImpl::to_bool(&s.as_pointer(),) })); - assert!(!({ SImpl::to_bool(&z.as_pointer(),) })); - assert!(({ SImpl::to_bool(&s.as_pointer(),) }) && (!({ SImpl::to_bool(&z.as_pointer(),) }))); + assert!({ + let __v: Value = Rc::new(RefCell::new(false)); + >>>::conversion_function( + >>::bind(s.as_pointer()), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); + assert!( + !({ + let __v: Value = Rc::new(RefCell::new(false)); + >>>::conversion_function( + >>::bind(z.as_pointer()), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }) + ); + assert!( + ({ + let __v: Value = Rc::new(RefCell::new(false)); + >>>::conversion_function( + >>::bind(s.as_pointer()), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }) && (!({ + let __v: Value = Rc::new(RefCell::new(false)); + >>>::conversion_function( + >>::bind(z.as_pointer()), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })) + ); let st: Value = Rc::new(RefCell::new(::default())); assert!((({ Static::operator_call(6, 7,) }) == 42)); assert!((({ SImpl::operator_call_1(&Rc::new(RefCell::new(S { v: 5 })).as_pointer(),) }) == 5)); @@ -80,8 +157,6 @@ pub trait SImpl { fn operator_call_2(&self, a: i32) -> i32; fn operator_call_3(&self, a: i32, b: i32) -> i32; fn operator_comma(&self, o: Ptr) -> S; - fn to_i32(&self) -> i32; - fn to_bool(&self) -> bool; } impl SImpl for Ptr { fn operator_call_1(&self) -> i32 { @@ -98,11 +173,5 @@ impl SImpl for Ptr { v: ({ ((*self).with(|__s| __s.v) * 10) } + { o.with(|__s| __s.v) }), }; } - fn to_i32(&self) -> i32 { - return (*self).with(|__s| __s.v); - } - fn to_bool(&self) -> bool { - return ((*self).with(|__s| __s.v) != 0); - } } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/pair_converting_construction.rs b/tests/unit/out/refcount/pair_converting_construction.rs index ba1b6498b7..f38121a790 100644 --- a/tests/unit/out/refcount/pair_converting_construction.rs +++ b/tests/unit/out/refcount/pair_converting_construction.rs @@ -38,12 +38,19 @@ pub struct Celsius { TriviallyCopyable, Default, )] -#[cpp_into(i32, to_i32)] #[byte_size(4)] pub struct Meters { #[offset(0)] pub value: i32, } +impl ConversionFunction>> for Meters { + fn conversion_function(this: LvalueRef>, to: Ptr) { + let this = &this.as_pointer(); + to.write((*this).with(|__s| __s.value)); + return; + } +} +impl ImplicitConversionFunction>> for Meters {} #[derive( Copy, Clone, @@ -113,13 +120,14 @@ pub struct Fallback { #[offset(0)] pub value: i32, } -impl DefaultConstructible for Fallback { - fn default_constructor(this: &Ptr) { +impl ConstructibleFrom<()> for Fallback { + fn constructor(this: &Ptr, (): ()) { { FallbackImpl::construct(this, -1_i32); } } } +impl DefaultConstructible for Fallback {} impl Default for Fallback { fn default() -> Self { { @@ -232,9 +240,23 @@ fn main_0() -> i32 { assert!(({ (*(*from_ints.borrow()).1.borrow()).degrees } == 2)); let m: Value = Rc::new(RefCell::new(Meters { value: 7 })); let from_operators: Value<(Value, Value)> = Rc::new(RefCell::new(( - Rc::new(RefCell::new(({ MetersImpl::to_i32(&m.as_pointer()) }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(0_i32)); + >>>::conversion_function( + >>::bind(m.as_pointer()), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), Rc::new(RefCell::new( - (({ MetersImpl::to_i32(&m.as_pointer()) }) as i64), + ({ + let __v: Value = Rc::new(RefCell::new(0_i32)); + >>>::conversion_function( + >>::bind(m.as_pointer()), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } as i64), )), ))); assert!(({ ((*(*from_operators.borrow()).0.borrow()) == 7) })); @@ -472,14 +494,6 @@ impl LabelImpl for Ptr

{ + pub table: fn() -> Table

, + pub passing: Passing, +} + +// A constructor, whose params are its parameters, or a conversion function, +// whose only param is the object it converts and whose result is the type it +// converts to. +pub struct Candidate

{ + pub params: Vec>, + pub is_explicit: bool, + pub result: Option Table

>, + // Constructs the object that `to` points to from the objects that args + // point to, one per parameter. + pub call: fn(to: P, args: &[P]), +} + +pub struct Table

{ + pub id: TypeId, + pub name: &'static str, + pub arithmetic: Option, + // Allocates zero-initialized storage for an object of the type. + pub storage: fn() -> P, + // Destroys the object that a pointer from storage points to and frees it. + pub release: fn(P), + // Constructs the object that dst points to from the one that src points + // to, by the copy constructor or, for move, the move constructor. + pub copy: fn(dst: P, src: P), + pub move_from: fn(dst: P, src: P), + pub constructors: Vec>, + pub conversion_functions: Vec>, +} + +pub trait Conversions: ByteRepr + Sized + 'static { + fn table() -> Table; + + // Direct-initialization of the object at this from args. + fn construct(this: Ptr, args: &[Arg]) { + initialize(&Self::table(), this.to_any(), args, true); + } + + // Copy-initialization of the object at this from arg. + fn convert(this: Ptr, arg: Arg) { + initialize(&Self::table(), this.to_any(), &[arg], false); + } +} + +pub trait ConversionsUnsafe: Sized + 'static { + fn table() -> Table<*mut c_void>; + + unsafe fn construct(this: *mut Self, args: &[Arg<*mut c_void>]) { + initialize(&Self::table(), this.cast(), args, true); + } + + unsafe fn convert(this: *mut Self, arg: Arg<*mut c_void>) { + initialize(&Self::table(), this.cast(), &[arg], false); + } +} + +pub struct Arg

{ + pub table: fn() -> Table

, + pub category: Category, + pub ptr: P, +} + +impl Arg<*mut c_void> { + pub fn lvalue_unsafe(ptr: *mut T) -> Self { + Self::new_unsafe(ptr, Category::Lvalue) + } + + pub fn const_lvalue_unsafe(ptr: *const T) -> Self { + Self::new_unsafe(ptr.cast_mut(), Category::ConstLvalue) + } + + pub fn rvalue_unsafe(ptr: *mut T) -> Self { + Self::new_unsafe(ptr, Category::Rvalue) + } + + fn new_unsafe(ptr: *mut T, category: Category) -> Self { + Arg { + table: T::table, + category, + ptr: ptr.cast(), + } + } +} + +impl Arg { + pub fn lvalue(ptr: Ptr) -> Self { + Self::new(ptr, Category::Lvalue) + } + + pub fn const_lvalue(ptr: Ptr) -> Self { + Self::new(ptr, Category::ConstLvalue) + } + + pub fn rvalue(ptr: Ptr) -> Self { + Self::new(ptr, Category::Rvalue) + } + + fn new(ptr: Ptr, category: Category) -> Self { + Arg { + table: T::table, + category, + ptr: ptr.to_any(), + } + } +} + +// The rank of a standard conversion sequence ([over.ics.scs]/3). +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)] +enum Rank { + Exact, + Promotion, + Conversion, +} + +#[derive(Clone, Copy, Debug)] +struct Standard { + rank: Rank, + converts: bool, + binds_rvalue_ref: bool, + binds_to_const: bool, +} + +impl Standard { + fn identity() -> Self { + Standard { + rank: Rank::Exact, + converts: false, + binds_rvalue_ref: false, + binds_to_const: false, + } + } +} + +// The function of a user-defined conversion: a constructor of the target or a +// conversion function of the source, at index in its table. +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +enum UserFunction { + Constructor(usize), + ConversionFunction(usize), +} + +// An implicit conversion sequence ([over.best.ics]). +#[derive(Clone, Copy, Debug)] +enum Sequence { + Standard(Standard), + User { + function: UserFunction, + after: Standard, + }, +} + +fn promotes(from: Arithmetic, to: Arithmetic) -> bool { + use Arithmetic::*; + match (from, to) { + (Bool, Signed(32)) => true, + (Signed(bits), Signed(32)) | (Unsigned(bits), Signed(32)) => bits < 32, + (Float(32), Float(64)) => true, + _ => false, + } +} + +// The standard conversion from an object of type from to one of type to, if +// there is one ([conv]). +fn standard(from: &Table

, to: &Table

) -> Option { + if from.id == to.id { + return Some(Standard::identity()); + } + let (from_kind, to_kind) = (from.arithmetic?, to.arithmetic?); + Some(Standard { + rank: if promotes(from_kind, to_kind) { + Rank::Promotion + } else { + Rank::Conversion + }, + converts: true, + binds_rvalue_ref: false, + binds_to_const: false, + }) +} + +// The binding of a parameter to the result of a standard conversion of an +// argument of the given category ([dcl.init.ref]/5). +fn bind(mut standard: Standard, category: Category, passing: Passing) -> Option { + match passing { + Passing::Value => {} + Passing::LvalueRef => { + if standard.converts || category != Category::Lvalue { + return None; + } + } + Passing::ConstLvalueRef => standard.binds_to_const = category != Category::ConstLvalue, + Passing::RvalueRef => { + if !standard.converts && category != Category::Rvalue { + return None; + } + standard.binds_rvalue_ref = true; + } + } + Some(standard) +} + +// The conversion sequence that initializes a parameter from an argument +// ([over.best.ics]); only standard conversions if standard_only +// ([over.best.ics]/4). +fn parameter_sequence( + arg: &Table

, + category: Category, + param: &Param

, + standard_only: bool, +) -> Option { + let target = (param.table)(); + if let Some(standard) = standard(arg, &target).and_then(|s| bind(s, category, param.passing)) { + return Some(Sequence::Standard(standard)); + } + if standard_only || param.passing == Passing::LvalueRef { + return None; + } + user_sequence(arg, category, &target, false) +} + +// The best user-defined conversion from an object of type arg to one of type +// target ([over.match.copy], [over.match.conv]). +fn user_sequence( + arg: &Table

, + category: Category, + target: &Table

, + allow_explicit: bool, +) -> Option { + let mut viable: Vec<(Sequence, Vec)> = Vec::new(); + for (index, ctor) in target.constructors.iter().enumerate() { + if ctor.params.len() != 1 || (ctor.is_explicit && !allow_explicit) { + continue; + } + if let Some(first) = parameter_sequence(arg, category, &ctor.params[0], true) { + let sequence = Sequence::User { + function: UserFunction::Constructor(index), + after: Standard::identity(), + }; + viable.push((sequence, vec![first])); + } + } + for (index, function) in arg.conversion_functions.iter().enumerate() { + if function.is_explicit && !allow_explicit { + continue; + } + let Some(first) = parameter_sequence(arg, category, &function.params[0], true) else { + continue; + }; + let result = (function.result.expect("a conversion function has a result"))(); + if let Some(after) = standard(&result, target) { + let sequence = Sequence::User { + function: UserFunction::ConversionFunction(index), + after, + }; + viable.push((sequence, vec![first])); + } + } + // [over.match.best]/2.2: in a user-defined conversion, the better second + // standard conversion to the target. + let tiebreak = |a: &Sequence, b: &Sequence| match (a, b) { + (Sequence::User { after: a, .. }, Sequence::User { after: b, .. }) => { + compare_standard(a, b) + } + _ => Ordering::Equal, + }; + best(&viable, tiebreak).map(|index| viable[index].0) +} + +fn compare_standard(a: &Standard, b: &Standard) -> Ordering { + a.rank + .cmp(&b.rank) + // [over.ics.rank]/3.2.3: an rvalue binds better to an rvalue reference. + .then(b.binds_rvalue_ref.cmp(&a.binds_rvalue_ref)) + // [over.ics.rank]/3.2.6: to a reference to the less cv-qualified type. + .then(a.binds_to_const.cmp(&b.binds_to_const)) +} + +// The order of two implicit conversion sequences, Less when a is better +// ([over.ics.rank]); None when they are indistinguishable. +fn compare(a: &Sequence, b: &Sequence) -> Option { + match (a, b) { + (Sequence::Standard(a), Sequence::Standard(b)) => Some(compare_standard(a, b)), + (Sequence::Standard(_), Sequence::User { .. }) => Some(Ordering::Less), + (Sequence::User { .. }, Sequence::Standard(_)) => Some(Ordering::Greater), + ( + Sequence::User { + function: fa, + after: aa, + }, + Sequence::User { + function: fb, + after: ab, + }, + ) => (fa == fb).then(|| compare_standard(aa, ab)), + } +} + +// The best viable candidate ([over.match.best]/2): at least as good for every +// argument and better for one, or, when every argument is as good, better by +// tiebreak. +fn best(viable: &[(T, Vec)], tiebreak: impl Fn(&T, &T) -> Ordering) -> Option { + let better = |i: usize, j: usize| { + let mut strictly = false; + for (a, b) in viable[i].1.iter().zip(&viable[j].1) { + match compare(a, b) { + Some(Ordering::Less) => strictly = true, + Some(Ordering::Equal) => {} + _ => return false, + } + } + strictly || tiebreak(&viable[i].0, &viable[j].0) == Ordering::Less + }; + (0..viable.len()).find(|&i| (0..viable.len()).all(|j| i == j || better(i, j))) +} + +fn initialize(target: &Table

, to: P, args: &[Arg

], is_direct: bool) { + let sources: Vec> = args.iter().map(|arg| (arg.table)()).collect(); + let is_class = target.arithmetic.is_none(); + // A class object from arguments, or from an object of its class, is + // constructed by the best constructor ([over.match.ctor]). + if is_class && (is_direct || sources[0].id == target.id) { + // The copy and move constructors, which the table holds apart, and the + // other constructors. + #[derive(Clone, Copy)] + enum Constructor { + Copy, + Move, + Listed(usize), + } + let mut viable: Vec<(Constructor, Vec)> = Vec::new(); + if args.len() == 1 && sources[0].id == target.id { + let identity = Standard::identity(); + viable.push(( + Constructor::Copy, + vec![Sequence::Standard(Standard { + binds_to_const: args[0].category != Category::ConstLvalue, + ..identity + })], + )); + if args[0].category == Category::Rvalue { + viable.push(( + Constructor::Move, + vec![Sequence::Standard(Standard { + binds_rvalue_ref: true, + ..identity + })], + )); + } + } + for (index, ctor) in target.constructors.iter().enumerate() { + if ctor.params.len() != args.len() || (ctor.is_explicit && !is_direct) { + continue; + } + let sequences: Option> = args + .iter() + .zip(&sources) + .zip(&ctor.params) + .map(|((arg, source), param)| { + parameter_sequence(source, arg.category, param, false) + }) + .collect(); + if let Some(sequences) = sequences { + viable.push((Constructor::Listed(index), sequences)); + } + } + let chosen = best(&viable, |_, _| Ordering::Equal).unwrap_or_else(|| { + panic!("no unique constructor of {} for the arguments", target.name) + }); + let (constructor, sequences) = &viable[chosen]; + match constructor { + Constructor::Copy => (target.copy)(to, args[0].ptr.clone()), + Constructor::Move => (target.move_from)(to, args[0].ptr.clone()), + Constructor::Listed(index) => { + call_with(&target.constructors[*index], to, args, sequences) + } + } + return; + } + assert!( + args.len() == 1, + "{} is initialized from one value", + target.name + ); + let (arg, source) = (&args[0], &sources[0]); + // A standard conversion, else a user-defined conversion by a converting + // constructor or a conversion function ([over.match.copy], + // [over.match.conv]). + if let Some(standard) = standard(source, target) { + if standard.converts { + convert_arithmetic(source, arg.ptr.clone(), target, to); + } else { + (target.copy)(to, arg.ptr.clone()); + } + return; + } + let sequence = user_sequence(source, arg.category, target, is_direct) + .unwrap_or_else(|| panic!("no conversion from {} to {}", source.name, target.name)); + run_user(source, arg, target, to, &sequence); +} + +// Calls a constructor with the arguments converted by their sequences, then +// destroys the temporaries the conversions made. +fn call_with(ctor: &Candidate

, to: P, args: &[Arg

], sequences: &[Sequence]) { + let mut temporaries: Vec<(Table

, P)> = Vec::new(); + let pointers: Vec

= args + .iter() + .zip(&ctor.params) + .zip(sequences) + .map(|((arg, param), sequence)| { + let target = (param.table)(); + let source = (arg.table)(); + let converts = match sequence { + Sequence::Standard(standard) => standard.converts, + Sequence::User { .. } => true, + }; + // A reference binds to the argument itself. + if !converts && param.passing != Passing::Value { + return arg.ptr.clone(); + } + let temporary = (target.storage)(); + match sequence { + Sequence::Standard(standard) if standard.converts => { + convert_arithmetic(&source, arg.ptr.clone(), &target, temporary.clone()) + } + Sequence::Standard(_) if arg.category == Category::Rvalue => { + (target.move_from)(temporary.clone(), arg.ptr.clone()) + } + Sequence::Standard(_) => (target.copy)(temporary.clone(), arg.ptr.clone()), + Sequence::User { .. } => { + run_user(&source, arg, &target, temporary.clone(), sequence) + } + } + temporaries.push((target, temporary.clone())); + temporary + }) + .collect(); + (ctor.call)(to, &pointers); + for (table, temporary) in temporaries { + (table.release)(temporary); + } +} + +fn run_user( + source: &Table

, + arg: &Arg

, + target: &Table

, + to: P, + sequence: &Sequence, +) { + let Sequence::User { function, after } = sequence else { + unreachable!("not a user-defined conversion") + }; + match function { + UserFunction::Constructor(index) => { + let ctor = &target.constructors[*index]; + let first = parameter_sequence(source, arg.category, &ctor.params[0], true) + .expect("the constructor was viable"); + call_with(ctor, to, std::slice::from_ref(arg), &[first]); + } + UserFunction::ConversionFunction(index) => { + let function = &source.conversion_functions[*index]; + if !after.converts { + (function.call)(to, std::slice::from_ref(&arg.ptr)); + return; + } + let result = (function.result.expect("a conversion function has a result"))(); + let value = (result.storage)(); + (function.call)(value.clone(), std::slice::from_ref(&arg.ptr)); + convert_arithmetic(&result, value.clone(), target, to); + (result.release)(value); + } + } +} + +// The value that src points to, as a float and as an integer. +fn read_arithmetic(from: &Table

, src: &P) -> (f64, i128) { + macro_rules! read { + ($($ty:ty),*) => { + $( + if from.id == TypeId::of::<$ty>() { + let value: $ty = Erased::read(src); + return (value as f64, value as i128); + } + )* + }; + } + if from.id == TypeId::of::() { + let value: bool = Erased::read(src); + return (value as u8 as f64, value as i128); + } + read!( + i8, u8, i16, u16, i32, u32, i64, u64, i128, u128, isize, usize, f32, f64 + ); + unreachable!("{} is not an arithmetic type", from.name) +} + +// The arithmetic conversion of the value that src points to, written to dst +// ([conv.integral], [conv.fpint], [conv.double], [conv.bool]). +fn convert_arithmetic(from: &Table

, src: P, to: &Table

, dst: P) { + let (float, integer) = read_arithmetic(from, &src); + let is_float = matches!(from.arithmetic, Some(Arithmetic::Float(_))); + macro_rules! write { + ($($ty:ty),*) => { + $( + if to.id == TypeId::of::<$ty>() { + let value = if is_float { float as $ty } else { integer as $ty }; + Erased::write::<$ty>(&dst, value); + return; + } + )* + }; + } + if to.id == TypeId::of::() { + let value = if is_float { float != 0.0 } else { integer != 0 }; + Erased::write::(&dst, value); + return; + } + write!( + i8, + u8, + i16, u16, i32, u32, i64, u64, i128, u128, isize, usize, f32, f64 + ); + unreachable!("{} is not an arithmetic type", to.name) +} + +macro_rules! arithmetic_conversions { + ($($ty:ty => $kind:expr),* $(,)?) => {$( + impl Arithmetical for $ty {} + + impl Conversions for $ty { + fn table() -> Table { + Table { + id: TypeId::of::<$ty>(), + name: stringify!($ty), + arithmetic: Some($kind), + storage: || Ptr::alloc(<$ty>::default()).to_any(), + release: |ptr| ptr.downcast::<$ty>().delete(), + copy: |dst, src| Erased::write(&dst, Erased::read::<$ty>(&src)), + move_from: |dst, src| Erased::write(&dst, Erased::read::<$ty>(&src)), + constructors: Vec::new(), + conversion_functions: Vec::new(), + } + } + } + + impl ConversionsUnsafe for $ty { + fn table() -> Table<*mut c_void> { + Table { + id: TypeId::of::<$ty>(), + name: stringify!($ty), + arithmetic: Some($kind), + storage: || Box::into_raw(Box::<$ty>::default()).cast(), + release: |ptr| drop(unsafe { Box::from_raw(ptr.cast::<$ty>()) }), + copy: |dst, src| Erased::write(&dst, Erased::read::<$ty>(&src)), + move_from: |dst, src| Erased::write(&dst, Erased::read::<$ty>(&src)), + constructors: Vec::new(), + conversion_functions: Vec::new(), + } + } + } + )*}; +} + +arithmetic_conversions!( + bool => Arithmetic::Bool, + i8 => Arithmetic::Signed(8), + u8 => Arithmetic::Unsigned(8), + i16 => Arithmetic::Signed(16), + u16 => Arithmetic::Unsigned(16), + i32 => Arithmetic::Signed(32), + u32 => Arithmetic::Unsigned(32), + i64 => Arithmetic::Signed(64), + u64 => Arithmetic::Unsigned(64), + i128 => Arithmetic::Signed(128), + u128 => Arithmetic::Unsigned(128), + isize => Arithmetic::Signed(64), + usize => Arithmetic::Unsigned(64), + f32 => Arithmetic::Float(32), + f64 => Arithmetic::Float(64), +); + +impl Conversions for Ptr +where + Ptr: ByteRepr + crate::TriviallyCopyable, +{ + fn table() -> Table { + Table { + id: TypeId::of::>(), + name: "Ptr", + arithmetic: None, + storage: || Ptr::alloc(Ptr::::null()).to_any(), + release: |ptr| ptr.downcast::>().delete(), + copy: |dst, src| { + dst.downcast::>() + .write(src.downcast::>().read()) + }, + move_from: |dst, src| { + dst.downcast::>() + .write(src.downcast::>().read()) + }, + constructors: Vec::new(), + conversion_functions: Vec::new(), + } + } +} + +// A vector is copied element by element, each by the copy constructor its +// table names. +impl Conversions for Vec +where + Vec: ByteRepr, +{ + fn table() -> Table { + Table { + id: TypeId::of::>(), + name: "Vec", + arithmetic: None, + storage: || Ptr::alloc(Vec::::new()).to_any(), + release: |ptr| ptr.downcast::>().delete(), + copy: |dst, src| { + let (dst, src) = (dst.downcast::>(), src.downcast::>()); + let len = src.with(|elems| elems.len()); + dst.with_mut(|elems| *elems = (0..len).map(|_| T::zero_init()).collect()); + let element = T::table(); + for i in 0..len { + (element.copy)( + dst.decay().offset(i).to_any(), + src.decay().offset(i).to_any(), + ); + } + }, + move_from: |dst, src| { + let value = src.downcast::>().with_mut(std::mem::take); + dst.downcast::>().with_mut(|elems| *elems = value); + }, + constructors: Vec::new(), + conversion_functions: Vec::new(), + } + } +} + +// A pair is copied member by member. +impl Conversions for (crate::rc::Value, crate::rc::Value) +where + A: Conversions + crate::ZeroInitialization, + B: Conversions + crate::ZeroInitialization, + (crate::rc::Value, crate::rc::Value): ByteRepr, +{ + fn table() -> Table { + type Pair = (crate::rc::Value, crate::rc::Value); + fn members(ptr: &AnyPtr) -> (AnyPtr, AnyPtr) { + use crate::rc::AsPointer; + ptr.downcast::>() + .with(|pair| (pair.0.as_pointer().to_any(), pair.1.as_pointer().to_any())) + } + Table { + id: TypeId::of::>(), + name: "pair", + arithmetic: None, + storage: || { + Ptr::alloc(( + std::rc::Rc::new(std::cell::RefCell::new(A::zero_init())), + std::rc::Rc::new(std::cell::RefCell::new(B::zero_init())), + )) + .to_any() + }, + release: |ptr| ptr.downcast::>().delete(), + copy: |dst, src| { + let ((d0, d1), (s0, s1)) = (members::(&dst), members::(&src)); + (A::table().copy)(d0, s0); + (B::table().copy)(d1, s1); + }, + move_from: |dst, src| { + let ((d0, d1), (s0, s1)) = (members::(&dst), members::(&src)); + (A::table().move_from)(d0, s0); + (B::table().move_from)(d1, s1); + }, + constructors: Vec::new(), + conversion_functions: Vec::new(), + } + } +} + +// A unique_ptr moves its object and is not copied. +impl Conversions for Option> +where + Option>: ByteRepr, +{ + fn table() -> Table { + type Owner = Option>; + Table { + id: TypeId::of::>(), + name: "unique_ptr", + arithmetic: None, + storage: || Ptr::alloc(Owner::::None).to_any(), + release: |ptr| ptr.downcast::>().delete(), + copy: |_, _| panic!("unique_ptr is not copy constructible"), + move_from: |dst, src| { + let value = src.downcast::>().with_mut(Option::take); + dst.downcast::>().with_mut(|owner| *owner = value); + }, + constructors: Vec::new(), + conversion_functions: Vec::new(), + } + } +} + +impl ConversionsUnsafe for Option> { + fn table() -> Table<*mut c_void> { + Table { + id: TypeId::of::>>(), + name: "unique_ptr", + arithmetic: None, + storage: || Box::into_raw(Box::new(Option::>::None)).cast(), + release: |ptr| drop(unsafe { Box::from_raw(ptr.cast::>>()) }), + copy: |_, _| panic!("unique_ptr is not copy constructible"), + move_from: |dst, src| unsafe { + dst.cast::>>() + .write((*src.cast::>>()).take()) + }, + constructors: Vec::new(), + conversion_functions: Vec::new(), + } + } +} + +impl ConversionsUnsafe for *mut T { + fn table() -> Table<*mut c_void> { + raw_pointer_table::<*mut T>("*mut") + } +} + +impl ConversionsUnsafe for *const T { + fn table() -> Table<*mut c_void> { + raw_pointer_table::<*const T>("*const") + } +} + +fn raw_pointer_table(name: &'static str) -> Table<*mut c_void> { + Table { + id: TypeId::of::(), + name, + arithmetic: None, + storage: || Box::into_raw(Box::::default()).cast(), + release: |ptr| drop(unsafe { Box::from_raw(ptr.cast::()) }), + copy: |dst, src| unsafe { dst.cast::().write(src.cast::().read()) }, + move_from: |dst, src| unsafe { dst.cast::().write(src.cast::().read()) }, + constructors: Vec::new(), + conversion_functions: Vec::new(), + } +} + +impl ConversionsUnsafe for Vec { + fn table() -> Table<*mut c_void> { + Table { + id: TypeId::of::>(), + name: "Vec", + arithmetic: None, + storage: || Box::into_raw(Box::>::default()).cast(), + release: |ptr| drop(unsafe { Box::from_raw(ptr.cast::>()) }), + copy: |dst, src| unsafe { + let (dst, src) = (dst.cast::>(), src.cast::>()); + let len = (*src).len(); + dst.write((0..len).map(|_| T::zero_init()).collect()); + let element = T::table(); + for i in 0..len { + (element.copy)( + (*dst).as_mut_ptr().add(i).cast(), + (*src).as_mut_ptr().add(i).cast(), + ); + } + }, + move_from: |dst, src| unsafe { + dst.cast::>() + .write(std::mem::take(&mut *src.cast::>())) + }, + constructors: Vec::new(), + conversion_functions: Vec::new(), + } + } +} + +impl ConversionsUnsafe for (A, B) +where + A: ConversionsUnsafe + crate::ZeroInitializationUnsafe, + B: ConversionsUnsafe + crate::ZeroInitializationUnsafe, +{ + fn table() -> Table<*mut c_void> { + Table { + id: TypeId::of::<(A, B)>(), + name: "pair", + arithmetic: None, + storage: || Box::into_raw(Box::new(unsafe { <(A, B)>::zero_init() })).cast(), + release: |ptr| drop(unsafe { Box::from_raw(ptr.cast::<(A, B)>()) }), + copy: |dst, src| unsafe { + let (dst, src) = (dst.cast::<(A, B)>(), src.cast::<(A, B)>()); + (A::table().copy)((&raw mut (*dst).0).cast(), (&raw mut (*src).0).cast()); + (B::table().copy)((&raw mut (*dst).1).cast(), (&raw mut (*src).1).cast()); + }, + move_from: |dst, src| unsafe { + let (dst, src) = (dst.cast::<(A, B)>(), src.cast::<(A, B)>()); + (A::table().move_from)((&raw mut (*dst).0).cast(), (&raw mut (*src).0).cast()); + (B::table().move_from)((&raw mut (*dst).1).cast(), (&raw mut (*src).1).cast()); + }, + constructors: Vec::new(), + conversion_functions: Vec::new(), + } + } +} + +#[cfg(test)] +mod tests { + use std::cell::RefCell; + use std::rc::Rc; + + use super::*; + use crate::rc::{AsPointer, Value}; + + fn object(value: T) -> Value { + Rc::new(RefCell::new(value)) + } + + #[test] + fn arithmetic_copy_initialization() { + let from = object(7_i32); + let to = object(0_i64); + Conversions::convert(to.as_pointer(), Arg::const_lvalue(from.as_pointer())); + assert_eq!(*to.borrow(), 7); + let flag = object(false); + Conversions::convert(flag.as_pointer(), Arg::rvalue(object(2.5_f64).as_pointer())); + assert!(*flag.borrow()); + } + + #[derive(Clone, Default)] + struct Ratio(i32, i32); + + impl ByteRepr for Ratio {} + + // struct Ratio { operator int() const; operator double() const; } + impl Conversions for Ratio { + fn table() -> Table { + Table { + id: TypeId::of::(), + name: "Ratio", + arithmetic: None, + storage: || Ptr::alloc(Ratio::default()).to_any(), + release: |ptr| ptr.downcast::().delete(), + copy: |dst, src| { + dst.downcast::() + .write(src.downcast::().with(Ratio::clone)) + }, + move_from: |dst, src| { + dst.downcast::() + .write(src.downcast::().with(Ratio::clone)) + }, + constructors: Vec::new(), + conversion_functions: vec![ + Candidate { + params: vec![Param { + table: ::table, + passing: Passing::ConstLvalueRef, + }], + is_explicit: false, + result: Some(::table), + call: |to, args| { + let ratio = args[0].downcast::().with(Ratio::clone); + to.downcast::().write(ratio.0 / ratio.1) + }, + }, + Candidate { + params: vec![Param { + table: ::table, + passing: Passing::ConstLvalueRef, + }], + is_explicit: false, + result: Some(::table), + call: |to, args| { + let ratio = args[0].downcast::().with(Ratio::clone); + to.downcast::() + .write(ratio.0 as f64 / ratio.1 as f64 + 0.5) + }, + }, + ], + } + } + } + + #[derive(Clone, Default)] + struct Meters(i64); + + impl ByteRepr for Meters {} + + // struct Meters { Meters(long); explicit Meters(double); } + impl Conversions for Meters { + fn table() -> Table { + Table { + id: TypeId::of::(), + name: "Meters", + arithmetic: None, + storage: || Ptr::alloc(Meters::default()).to_any(), + release: |ptr| ptr.downcast::().delete(), + copy: |dst, src| { + dst.downcast::() + .write(src.downcast::().with(Meters::clone)) + }, + move_from: |dst, src| { + dst.downcast::() + .write(src.downcast::().with(Meters::clone)) + }, + constructors: vec![ + Candidate { + params: vec![Param { + table: ::table, + passing: Passing::Value, + }], + is_explicit: false, + result: None, + call: |to, args| { + let value = args[0].downcast::().read(); + to.downcast::().write(Meters(value)) + }, + }, + Candidate { + params: vec![Param { + table: ::table, + passing: Passing::Value, + }], + is_explicit: true, + result: None, + call: |to, args| { + let value = args[0].downcast::().read(); + to.downcast::().write(Meters(value as i64 * 1000)) + }, + }, + ], + conversion_functions: Vec::new(), + } + } + } + + #[test] + fn exact_conversion_function_is_chosen() { + // int i = ratio; picks operator int, whose result needs no conversion. + let ratio = object(Ratio(9, 2)); + let to = object(0_i32); + Conversions::convert(to.as_pointer(), Arg::const_lvalue(ratio.as_pointer())); + assert_eq!(*to.borrow(), 4); + // double d = ratio; picks operator double. + let to = object(0.0_f64); + Conversions::convert(to.as_pointer(), Arg::const_lvalue(ratio.as_pointer())); + assert_eq!(*to.borrow(), 5.0); + } + + #[test] + #[should_panic(expected = "no conversion from Ratio to i64")] + fn conversions_of_equal_rank_are_ambiguous() { + // long l = ratio; int -> long and double -> long rank the same. + let ratio = object(Ratio(9, 2)); + Conversions::convert( + object(0_i64).as_pointer(), + Arg::const_lvalue(ratio.as_pointer()), + ); + } + + #[test] + fn copy_initialization_skips_explicit_constructors() { + // Meters m = 2.0; the explicit Meters(double) is not a candidate, so + // 2.0 converts to long for Meters(long). + let meters = object(Meters(0)); + Conversions::convert( + meters.as_pointer(), + Arg::rvalue(object(2.0_f64).as_pointer()), + ); + assert_eq!(meters.borrow().0, 2); + // Meters m(2.0); direct-initialization picks the exact match. + Conversions::construct( + meters.as_pointer(), + &[Arg::rvalue(object(2.0_f64).as_pointer())], + ); + assert_eq!(meters.borrow().0, 2000); + } + + #[test] + fn arithmetic_copy_initialization_unsafe() { + let mut from = 300_i32; + let mut to = 0_u8; + unsafe { + ConversionsUnsafe::convert(&raw mut to, Arg::const_lvalue_unsafe(&raw const from)) + }; + assert_eq!(to, 44); + let mut pair = (0_i64, 0.0_f64); + let mut source = (3_i64, 1.5_f64); + unsafe { ConversionsUnsafe::convert(&raw mut pair, Arg::lvalue_unsafe(&raw mut source)) }; + assert_eq!(pair, (3, 1.5)); + from += 1; + let _ = from; + } + + #[test] + fn promotion_ranks_above_conversion() { + let promote = Standard { + rank: Rank::Promotion, + converts: true, + binds_rvalue_ref: false, + binds_to_const: false, + }; + let conversion = Standard { + rank: Rank::Conversion, + ..promote + }; + assert_eq!(compare_standard(&promote, &conversion), Ordering::Less); + assert!(promotes(Arithmetic::Signed(16), Arithmetic::Signed(32))); + assert!(!promotes(Arithmetic::Signed(32), Arithmetic::Signed(64))); + } +} diff --git a/libcc2rs/src/void.rs b/libcc2rs/src/void.rs index 6a737d9af9..78a69dd4e7 100644 --- a/libcc2rs/src/void.rs +++ b/libcc2rs/src/void.rs @@ -132,6 +132,15 @@ impl AnyPtr { pub fn is_null(&self) -> bool { self.ptr.is_null() } + + // The pointer this was made from, which must be a Ptr. + pub fn downcast(&self) -> Ptr { + self.ptr + .as_any() + .downcast_ref::>() + .unwrap_or_else(|| panic!("not a pointer to {}", std::any::type_name::())) + .clone() + } } impl PartialEq for AnyPtr { From 4d48edb962708fec29829340e2ff58adfaa2750c Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 4 Dec 2026 12:01:40 +0000 Subject: [PATCH 20/35] Update tests --- .../out/refcount/defaulted_move_cross_tu.rs | 33 +- .../out/unsafe/defaulted_move_cross_tu.rs | 33 +- .../out/refcount/opaque_forward_decl.rs | 19 +- .../out/unsafe/opaque_forward_decl.rs | 26 +- .../refcount/out_of_line_methods_cross_tu.rs | 62 +-- .../unsafe/out_of_line_methods_cross_tu.rs | 62 +-- .../template_method_late_instantiation.rs | 8 +- .../template_method_late_instantiation.rs | 8 +- .../out/refcount/p14-class-in-two-files.rs | 36 +- .../out/unsafe/p14-class-in-two-files.rs | 30 +- .../p15-class-template-static-member.rs | 34 +- .../p15-class-template-static-member.rs | 28 +- .../out/refcount/p15-function-template.rs | 46 +- .../out/unsafe/p15-function-template.rs | 38 +- .../out/refcount/p15-inline-function.rs | 31 +- .../out/unsafe/p15-inline-function.rs | 26 +- .../out/refcount/p15-inline-variable.rs | 31 +- .../out/unsafe/p15-inline-variable.rs | 26 +- .../p16-default-argument-lambda-in-class.rs | 31 +- .../p16-default-argument-lambda-in-class.rs | 26 +- .../refcount/p16-lambda-in-inline-function.rs | 31 +- .../unsafe/p16-lambda-in-inline-function.rs | 26 +- .../basic.link/out/refcount/basic.link.rs | 40 +- .../basic/basic.link/out/unsafe/basic.link.rs | 40 +- .../out/refcount/basic.scope.block.rs | 61 ++- .../out/refcount/basic.scope.class.rs | 19 +- .../out/refcount/basic.scope.param.rs | 19 +- .../out/refcount/basic.scope.pdecl.rs | 16 +- .../out/refcount/basic.scope.scope.rs | 44 +- .../out/unsafe/basic.scope.block.rs | 57 +-- .../out/unsafe/basic.scope.class.rs | 19 +- .../out/unsafe/basic.scope.param.rs | 22 +- .../out/unsafe/basic.scope.pdecl.rs | 14 +- .../out/unsafe/basic.scope.scope.rs | 42 +- .../out/refcount/basic.start.term-p1-exit.rs | 18 +- .../out/refcount/basic.start.term.rs | 53 ++- .../out/unsafe/basic.start.term-p1-exit.rs | 18 +- .../out/unsafe/basic.start.term.rs | 55 ++- tests/std/basic/out/refcount/basic.def.odr.rs | 273 +++++------- tests/std/basic/out/unsafe/basic.def.odr.rs | 272 +++++------- .../out/refcount/class.base.init.rs | 12 +- .../class.init/out/unsafe/class.base.init.rs | 12 +- .../out/refcount/class.conv.ctor.rs | 149 +++---- .../class.conv/out/refcount/class.conv.fct.rs | 106 ++--- .../class.conv/out/unsafe/class.conv.ctor.rs | 136 +++--- .../class.conv/out/unsafe/class.conv.fct.rs | 103 ++--- .../out/refcount/class.copy.ctor.rs | 25 +- .../class.ctor/out/unsafe/class.copy.ctor.rs | 22 +- .../out/refcount/class.mem.general.rs | 16 +- .../class.mem/out/unsafe/class.mem.general.rs | 16 +- .../out/refcount/concept.constructible.rs | 56 ++- .../out/refcount/concept.convertible.rs | 73 ++- .../out/unsafe/concept.constructible.rs | 58 ++- .../out/unsafe/concept.convertible.rs | 66 ++- .../dcl.init/out/refcount/dcl.init.general.rs | 38 +- .../dcl.init/out/unsafe/dcl.init.general.rs | 36 +- .../out/refcount/dcl.fct.default.rs | 51 +-- .../dcl.meaning/out/unsafe/dcl.fct.default.rs | 49 +- .../out/refcount/expr.mptr.oper.rs | 47 +- .../out/unsafe/expr.mptr.oper.rs | 46 +- .../expr.prim/out/refcount/expr.prim.this.rs | 23 +- .../expr.prim/out/unsafe/expr.prim.this.rs | 23 +- .../allocator.requirements.general.rs | 6 +- .../unsafe/allocator.requirements.general.rs | 6 +- .../stmt.iter/out/refcount/stmt.while.rs | 84 ++-- .../stmt.iter/out/unsafe/stmt.while.rs | 86 ++-- .../stmt.select/out/refcount/stmt.if.rs | 28 +- .../stmt.select/out/refcount/stmt.switch.rs | 54 +-- .../stmt.select/out/unsafe/stmt.if.rs | 24 +- .../stmt.select/out/unsafe/stmt.switch.rs | 50 +-- .../temp/temp.spec/out/refcount/temp.inst.rs | 53 +-- .../temp/temp.spec/out/unsafe/temp.inst.rs | 65 +-- .../pairs/out/refcount/pairs.pair.rs | 26 +- .../utilities/pairs/out/unsafe/pairs.pair.rs | 20 +- .../utility/out/refcount/forward-helpers.rs | 173 +++----- .../utilities/utility/out/refcount/forward.rs | 21 +- .../utility/out/unsafe/forward-helpers.rs | 193 +++----- .../utilities/utility/out/unsafe/forward.rs | 21 +- tests/ub/out/refcount/ctor_ref_member.rs | 12 +- tests/ub/out/unsafe/ctor_ref_member.rs | 12 +- tests/unit/out/refcount/10_struct.rs | 17 +- tests/unit/out/refcount/any.rs | 14 +- .../out/refcount/array_of_noncopy_struct.rs | 10 +- .../out/refcount/assignment_single_eval.rs | 6 +- tests/unit/out/refcount/cast.rs | 8 +- tests/unit/out/refcount/class_templates.rs | 24 +- tests/unit/out/refcount/constexpr_function.rs | 12 +- tests/unit/out/refcount/constructor.rs | 42 +- .../unit/out/refcount/container_field_addr.rs | 10 +- .../conversion_operator_same_translation.rs | 63 +-- tests/unit/out/refcount/copy_assign.rs | 223 +++++----- tests/unit/out/refcount/copy_ctor.rs | 256 +++++------ .../unit/out/refcount/copy_move_defaulted.rs | 321 +++++++------- tests/unit/out/refcount/copy_move_deleted.rs | 83 ++-- .../refcount/default_function_arguments.rs | 57 ++- tests/unit/out/refcount/delete_array_order.rs | 2 +- tests/unit/out/refcount/destructor.rs | 14 +- tests/unit/out/refcount/destructor_params.rs | 19 +- .../out/refcount/destructor_temporaries.rs | 20 +- .../out/refcount/emplace_receiver_alias.rs | 4 +- .../out/refcount/emplace_receiver_order.rs | 8 +- .../unit/out/refcount/enum_underlying_type.rs | 8 +- .../out/refcount/field_method_receiver.rs | 6 +- tests/unit/out/refcount/field_pointers.rs | 6 +- tests/unit/out/refcount/fn_ptr.rs | 17 +- tests/unit/out/refcount/fn_ptr_struct.rs | 32 +- .../unit/out/refcount/for_body_destructor.rs | 22 +- .../refcount/foreach_disjoint_field_borrow.rs | 8 +- tests/unit/out/refcount/forward_basic.rs | 74 ++-- tests/unit/out/refcount/forward_decltype.rs | 39 +- tests/unit/out/refcount/forward_explicit.rs | 43 +- tests/unit/out/refcount/forward_pack.rs | 62 +-- .../out/refcount/global_init_side_effect.rs | 15 +- .../out/refcount/global_non_const_init.rs | 50 +-- tests/unit/out/refcount/huffman.rs | 6 +- tests/unit/out/refcount/implicit_autoref.rs | 8 +- .../refcount/in_class_field_initializer.rs | 24 +- tests/unit/out/refcount/init_list.rs | 14 +- .../out/refcount/inline_container_fields.rs | 41 +- tests/unit/out/refcount/kruskal.rs | 12 +- tests/unit/out/refcount/lambda_as_field.rs | 39 +- .../out/refcount/lambda_capture_copy_ctor.rs | 107 ++--- .../unit/out/refcount/lambda_decltype_type.rs | 22 +- .../out/refcount/lambda_immediate_init.rs | 8 +- .../out/refcount/lambda_move_only_capture.rs | 46 +- .../refcount/libc_struct_without_default.rs | 8 +- tests/unit/out/refcount/map.rs | 36 +- tests/unit/out/refcount/map_key_copy_ctor.rs | 43 +- tests/unit/out/refcount/map_key_identity.rs | 10 +- tests/unit/out/refcount/map_try_emplace.rs | 125 +++--- .../out/refcount/map_try_emplace_lvalues.rs | 419 +++++++++--------- tests/unit/out/refcount/max.rs | 25 +- tests/unit/out/refcount/move_assign.rs | 65 ++- tests/unit/out/refcount/move_ctor.rs | 144 +++--- tests/unit/out/refcount/move_this.rs | 68 ++- .../unit/out/refcount/opaque_forward_decl.rs | 19 +- .../refcount/operator_comparison_nonbool.rs | 66 ++- .../operator_comparison_noncopyable.rs | 13 +- .../out/refcount/operator_other_member.rs | 49 +- tests/unit/out/refcount/pair.rs | 72 +-- .../refcount/pair_converting_construction.rs | 268 ++++++----- tests/unit/out/refcount/push_emplace_back.rs | 127 +++--- tests/unit/out/refcount/rule_of_five.rs | 41 +- tests/unit/out/refcount/rule_of_three.rs | 33 +- .../unit/out/refcount/rvalue_rule_arg_move.rs | 32 +- tests/unit/out/refcount/rvalue_struct.rs | 8 +- .../refcount/self_referencing_initializer.rs | 6 +- tests/unit/out/refcount/size_t_ssize_t.rs | 56 +-- .../out/refcount/size_t_template_param.rs | 24 +- tests/unit/out/refcount/sort_no_copy.rs | 118 +++-- tests/unit/out/refcount/stdcopy.rs | 35 +- tests/unit/out/refcount/struct_ctor.rs | 43 +- .../unit/out/refcount/struct_default_ctor.rs | 31 +- .../refcount/structured_binding_copy_ctor.rs | 27 +- .../structured_binding_element_ctor.rs | 75 ++-- .../refcount/structured_binding_move_ctor.rs | 34 +- tests/unit/out/refcount/swap_map_no_copy.rs | 219 ++++----- .../unit/out/refcount/template_default_arg.rs | 75 ++-- .../unit/out/refcount/temporary_field_addr.rs | 22 +- .../out/refcount/temporary_field_ctor_arg.rs | 19 +- .../out/refcount/temporary_field_two_args.rs | 18 +- tests/unit/out/refcount/this.rs | 69 ++- .../unit/out/refcount/typedef-anon-struct.rs | 8 +- tests/unit/out/refcount/unboxed_records.rs | 8 +- tests/unit/out/refcount/unique_ptr.rs | 6 +- .../out/refcount/unique_ptr_const_deref.rs | 8 +- .../out/refcount/unique_ptr_field_reset.rs | 8 +- tests/unit/out/refcount/unique_ptr_nested.rs | 6 +- tests/unit/out/refcount/va_list_field.rs | 9 +- tests/unit/out/refcount/vector.rs | 39 +- .../vector_insert_conversion_chain.rs | 35 +- .../out/refcount/vector_iter_range_ctor.rs | 58 +-- .../out/refcount/vector_subscript_direct.rs | 8 +- .../out/refcount/vector_with_allocator.rs | 20 +- tests/unit/out/refcount/void_cast.rs | 14 +- tests/unit/out/unsafe/10_struct.rs | 17 +- tests/unit/out/unsafe/any.rs | 14 +- .../out/unsafe/array_of_noncopy_struct.rs | 10 +- .../unit/out/unsafe/assignment_single_eval.rs | 6 +- tests/unit/out/unsafe/cast.rs | 8 +- tests/unit/out/unsafe/class_templates.rs | 24 +- tests/unit/out/unsafe/constexpr_function.rs | 12 +- tests/unit/out/unsafe/constructor.rs | 42 +- tests/unit/out/unsafe/container_field_addr.rs | 10 +- .../conversion_operator_same_translation.rs | 63 +-- tests/unit/out/unsafe/copy_assign.rs | 230 +++++----- tests/unit/out/unsafe/copy_ctor.rs | 239 ++++------ tests/unit/out/unsafe/copy_move_defaulted.rs | 308 ++++++------- tests/unit/out/unsafe/copy_move_deleted.rs | 73 ++- .../out/unsafe/default_function_arguments.rs | 57 ++- tests/unit/out/unsafe/delete_array_order.rs | 2 +- tests/unit/out/unsafe/destructor.rs | 14 +- tests/unit/out/unsafe/destructor_params.rs | 19 +- .../unit/out/unsafe/destructor_temporaries.rs | 20 +- .../unit/out/unsafe/emplace_receiver_alias.rs | 4 +- .../unit/out/unsafe/emplace_receiver_order.rs | 8 +- tests/unit/out/unsafe/enum_underlying_type.rs | 8 +- .../unit/out/unsafe/field_method_receiver.rs | 6 +- tests/unit/out/unsafe/field_pointers.rs | 6 +- tests/unit/out/unsafe/fn_ptr.rs | 19 +- tests/unit/out/unsafe/fn_ptr_struct.rs | 34 +- tests/unit/out/unsafe/for_body_destructor.rs | 22 +- .../unsafe/foreach_disjoint_field_borrow.rs | 8 +- tests/unit/out/unsafe/forward_basic.rs | 74 ++-- tests/unit/out/unsafe/forward_decltype.rs | 39 +- tests/unit/out/unsafe/forward_explicit.rs | 43 +- tests/unit/out/unsafe/forward_pack.rs | 63 ++- .../out/unsafe/global_init_side_effect.rs | 15 +- .../unit/out/unsafe/global_non_const_init.rs | 50 +-- tests/unit/out/unsafe/huffman.rs | 6 +- tests/unit/out/unsafe/implicit_autoref.rs | 8 +- .../out/unsafe/in_class_field_initializer.rs | 24 +- tests/unit/out/unsafe/init_list.rs | 14 +- .../out/unsafe/inline_container_fields.rs | 34 +- tests/unit/out/unsafe/kruskal.rs | 12 +- tests/unit/out/unsafe/lambda_as_field.rs | 41 +- .../out/unsafe/lambda_capture_copy_ctor.rs | 81 ++-- tests/unit/out/unsafe/lambda_decltype_type.rs | 22 +- .../unit/out/unsafe/lambda_immediate_init.rs | 8 +- .../out/unsafe/lambda_move_only_capture.rs | 46 +- .../out/unsafe/libc_struct_without_default.rs | 8 +- tests/unit/out/unsafe/map.rs | 32 +- tests/unit/out/unsafe/map_key_copy_ctor.rs | 43 +- tests/unit/out/unsafe/map_key_identity.rs | 10 +- tests/unit/out/unsafe/map_try_emplace.rs | 122 ++--- .../out/unsafe/map_try_emplace_lvalues.rs | 349 +++++++-------- tests/unit/out/unsafe/max.rs | 25 +- tests/unit/out/unsafe/move_assign.rs | 62 ++- tests/unit/out/unsafe/move_ctor.rs | 144 +++--- tests/unit/out/unsafe/move_this.rs | 68 ++- tests/unit/out/unsafe/opaque_forward_decl.rs | 26 +- .../out/unsafe/operator_comparison_nonbool.rs | 80 ++-- .../unsafe/operator_comparison_noncopyable.rs | 13 +- .../unit/out/unsafe/operator_other_member.rs | 49 +- tests/unit/out/unsafe/pair.rs | 68 +-- .../unsafe/pair_converting_construction.rs | 301 +++++++------ tests/unit/out/unsafe/push_emplace_back.rs | 114 +++-- tests/unit/out/unsafe/rule_of_five.rs | 41 +- tests/unit/out/unsafe/rule_of_three.rs | 33 +- tests/unit/out/unsafe/rvalue_rule_arg_move.rs | 25 +- tests/unit/out/unsafe/rvalue_struct.rs | 8 +- .../unsafe/self_referencing_initializer.rs | 6 +- tests/unit/out/unsafe/size_t_ssize_t.rs | 50 +-- .../unit/out/unsafe/size_t_template_param.rs | 26 +- tests/unit/out/unsafe/sort_no_copy.rs | 118 +++-- tests/unit/out/unsafe/stdcopy.rs | 35 +- tests/unit/out/unsafe/struct_ctor.rs | 41 +- tests/unit/out/unsafe/struct_default_ctor.rs | 31 +- .../unsafe/structured_binding_copy_ctor.rs | 24 +- .../unsafe/structured_binding_element_ctor.rs | 73 ++- .../unsafe/structured_binding_move_ctor.rs | 34 +- tests/unit/out/unsafe/swap_map_no_copy.rs | 219 ++++----- tests/unit/out/unsafe/template_default_arg.rs | 75 ++-- tests/unit/out/unsafe/temporary_field_addr.rs | 22 +- .../out/unsafe/temporary_field_ctor_arg.rs | 19 +- .../out/unsafe/temporary_field_two_args.rs | 18 +- tests/unit/out/unsafe/this.rs | 84 ++-- tests/unit/out/unsafe/typedef-anon-struct.rs | 8 +- tests/unit/out/unsafe/unboxed_records.rs | 8 +- tests/unit/out/unsafe/unique_ptr.rs | 6 +- .../unit/out/unsafe/unique_ptr_const_deref.rs | 8 +- .../unit/out/unsafe/unique_ptr_field_reset.rs | 8 +- tests/unit/out/unsafe/unique_ptr_nested.rs | 6 +- tests/unit/out/unsafe/va_list_field.rs | 9 +- tests/unit/out/unsafe/vector.rs | 39 +- .../unsafe/vector_insert_conversion_chain.rs | 35 +- .../unit/out/unsafe/vector_iter_range_ctor.rs | 56 +-- .../out/unsafe/vector_subscript_direct.rs | 8 +- .../unit/out/unsafe/vector_with_allocator.rs | 20 +- tests/unit/out/unsafe/void_cast.rs | 14 +- 270 files changed, 5765 insertions(+), 7380 deletions(-) diff --git a/tests/multi-file/defaulted_move_cross_tu/out/refcount/defaulted_move_cross_tu.rs b/tests/multi-file/defaulted_move_cross_tu/out/refcount/defaulted_move_cross_tu.rs index 9f6d09cf1a..81ab57e4e0 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 @@ -12,7 +12,7 @@ use std::rc::{Rc, Weak}; #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] #[conversions(move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] #[byte_size(32)] pub struct S { #[offset(0)] @@ -23,8 +23,8 @@ pub struct S { #[array_len(2)] pub n: Box<[i32]>, } -impl ConstructibleFrom<(i32,)> for S { - fn constructor(this: Ptr, (x,): (i32,)) { +impl S { + pub fn constructor_1(this: Ptr, x: i32) { let x: Value = Rc::new(RefCell::new(x)); field!(this, v).write( (0..({ ((*x.borrow()) as usize) })) @@ -34,7 +34,6 @@ impl ConstructibleFrom<(i32,)> for S { field!(this, n).write(Box::new([(*x.borrow()), ((*x.borrow()) + 1)])); } } -impl ConvertibleTo for i32 {} impl Default for S { fn default() -> Self { { ::zero_init() } @@ -55,7 +54,7 @@ impl Default for S { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(24)] pub struct T { #[offset(0)] @@ -66,9 +65,7 @@ impl T { pub fn size(this: Ptr) -> i32 { return (((*this.upgrade().deref()).v.len()) as i32); } -} -impl ConstructibleFrom<()> for T { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, v).write(Vec::new()); } } @@ -82,7 +79,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(s, S, (i32,), (2,)); + object!(s, S::constructor_1(2)); assert!((({ sum_0(s.as_pointer(),) }) == 7)); assert!((({ shuffle_1(3,) }) == 10)); let t: Value = Rc::new(RefCell::new(T { @@ -91,16 +88,24 @@ fn main_0() -> i32 { assert!((({ T::size(t.as_pointer(),) }) == 2)); return 0; } +impl S {} +impl T {} pub fn shuffle_1(mut x: i32) -> i32 { - object!(a, S, (i32,), (x,)); - object!(b, S, RvalueRef::bind(a.as_pointer())); + object!(a, S::constructor_1(x)); + object!(b, S, |b| ::move_constructor( + b.clone(), + RvalueRef::bind(a.as_pointer()) + )); assert!(({ (*a.borrow()).v.is_empty() })); - object!(c, S, (i32,), (1,)); + object!(c, S::constructor_1(1)); 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, RvalueRef::bind(t.as_pointer())); - object!(w, T); + object!(u, T, |u| ::move_constructor( + u.clone(), + RvalueRef::bind(t.as_pointer()) + )); + object!(w, T::constructor_1()); assign!(w = RvalueRef(u)); assert!( ((({ T::size(t.as_pointer(),) }) == 0) && (({ T::size(u.as_pointer(),) }) == 0)) diff --git a/tests/multi-file/defaulted_move_cross_tu/out/unsafe/defaulted_move_cross_tu.rs b/tests/multi-file/defaulted_move_cross_tu/out/unsafe/defaulted_move_cross_tu.rs index 4d1a625bb4..e1354b2b9e 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 @@ -18,20 +18,19 @@ use std::rc::Rc; #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] #[conversions(move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] pub struct S { pub v: Vec, pub n: [i32; 2], } -impl ConstructibleFromUnsafe<(i32,)> for S { - unsafe fn constructor(this: *mut Self, (mut x,): (i32,)) { +impl S { + pub unsafe fn constructor_1(this: *mut Self, mut x: i32) { (&raw mut (*this).v).write(Vec::from_fn((x as usize), |_| { copy_constructed_unsafe(&mut x) })); (&raw mut (*this).n).write([x, ((x) + (1))]); } } -impl ConvertibleToUnsafe for i32 {} #[repr(C)] #[derive( Clone, @@ -46,7 +45,7 @@ impl ConvertibleToUnsafe for i32 {} )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct T { pub v: Vec, } @@ -54,9 +53,7 @@ impl T { pub unsafe fn size(this: *const Self) -> i32 { return (((*this).v.len()) as i32); } -} -impl ConstructibleFromUnsafe<()> for T { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write(Vec::new()); } } @@ -70,7 +67,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(s, S, (i32,), (2,)); + object_unsafe!(s, S::constructor_1(2)); assert!(((unsafe { sum_0(&s,) }) == (7))); assert!(((unsafe { shuffle_1(3,) }) == (10))); let mut t: T = T { @@ -79,16 +76,24 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { T::size(&raw const t,) }) == (2))); return 0; } +impl S {} +impl T {} pub unsafe fn shuffle_1(mut x: i32) -> i32 { - object_unsafe!(a, S, (i32,), (x,)); - object_unsafe!(b, S, RvalueRefUnsafe::bind(&mut a)); + object_unsafe!(a, S::constructor_1(x)); + object_unsafe!(b, S, |b| ::move_constructor( + b, + RvalueRefUnsafe::bind(&mut a) + )); assert!(a.v.is_empty()); - object_unsafe!(c, S, (i32,), (1,)); + object_unsafe!(c, S::constructor_1(1)); assign_unsafe!(c = RvalueRefUnsafe(b)); assert!(b.v.is_empty()); let mut t: T = T { v: Vec::from([1]) }; - object_unsafe!(u, T, RvalueRefUnsafe::bind(&mut t)); - object_unsafe!(w, T); + object_unsafe!(u, T, |u| ::move_constructor( + u, + RvalueRefUnsafe::bind(&mut t) + )); + object_unsafe!(w, T::constructor_1()); assign_unsafe!(w = RvalueRefUnsafe(u)); assert!( (((unsafe { T::size(&raw const t,) }) == (0)) diff --git a/tests/multi-file/opaque_forward_decl/out/refcount/opaque_forward_decl.rs b/tests/multi-file/opaque_forward_decl/out/refcount/opaque_forward_decl.rs index 3ebcfc35ad..4f7fd71566 100644 --- a/tests/multi-file/opaque_forward_decl/out/refcount/opaque_forward_decl.rs +++ b/tests/multi-file/opaque_forward_decl/out/refcount/opaque_forward_decl.rs @@ -40,22 +40,9 @@ fn main_0() -> i32 { return 0; } pub fn touch_0(mut c: Ptr) {} -#[derive(Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg)] +#[derive( + Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg, ZeroInitialization, Destructible, Conversions, +)] #[byte_size(1)] pub struct opaque; -impl libcc2rs::overload::Conversions for opaque { - fn table() -> libcc2rs::overload::Table { - libcc2rs::overload::Table { - id: ::std::any::TypeId::of::(), - name: "opaque", - arithmetic: None, - storage: || Ptr::alloc(opaque).to_any(), - release: |ptr| ptr.downcast::().delete(), - copy: |_, _| {}, - move_from: |_, _| {}, - constructors: vec![], - conversion_functions: vec![], - } - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/multi-file/opaque_forward_decl/out/unsafe/opaque_forward_decl.rs b/tests/multi-file/opaque_forward_decl/out/unsafe/opaque_forward_decl.rs index f5e124aaaf..b5489afd25 100644 --- a/tests/multi-file/opaque_forward_decl/out/unsafe/opaque_forward_decl.rs +++ b/tests/multi-file/opaque_forward_decl/out/unsafe/opaque_forward_decl.rs @@ -38,21 +38,15 @@ unsafe fn main_0() -> i32 { return 0; } pub unsafe fn touch_0(mut c: *mut container) {} -#[derive(Clone, Copy, Default, VaArg, FnPtrArg)] +#[derive( + Clone, + Copy, + Default, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + ConversionsUnsafe, +)] pub struct opaque; -impl libcc2rs::overload::ConversionsUnsafe for opaque { - fn table() -> libcc2rs::overload::Table<*mut ::std::ffi::c_void> { - libcc2rs::overload::Table { - id: ::std::any::TypeId::of::(), - name: "opaque", - arithmetic: None, - storage: || Box::into_raw(Box::new(opaque)).cast(), - release: |ptr| drop(unsafe { Box::from_raw(ptr.cast::()) }), - copy: |_, _| {}, - move_from: |_, _| {}, - constructors: vec![], - conversion_functions: vec![], - } - } -} pub unsafe fn __cpp2rust_init_globals() {} 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 eedd5c0c1e..7c3c825d03 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 @@ -20,7 +20,7 @@ use std::rc::{Rc, Weak}; )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy, move)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -40,6 +40,7 @@ pub struct M { #[offset(0)] pub v: i32, } +impl M {} pub trait Base { fn apply(&mut self, x: i32) -> i32; } @@ -62,6 +63,7 @@ pub struct Derived { #[offset(8)] pub factor: i32, } +impl Derived {} #[derive( Copy, Clone, @@ -91,18 +93,18 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(s, S, (i32,), (1,)); + object!(s, S::constructor_1(1)); 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, (i32,), (2,)); - object!(n, M, RvalueRef::bind(m.as_pointer())); + object!(m, M::constructor_1(2)); + object!(n, M::constructor_2(RvalueRef::bind(m.as_pointer()))); assert!(({ (*n.borrow()).v } == 2)); - object!(c, M, LvalueRef::bind(n.as_pointer())); + object!(c, M::constructor_3(LvalueRef::bind(n.as_pointer()))); assert!(({ (*c.borrow()).v } == 3)); assert!((({ move_m_1(5,) }) == 5)); - object!(derived, Derived, (i32,), (3,)); + object!(derived, Derived::constructor_1(3)); let mut base: PtrDyn = (derived.as_pointer()).to_dyn::(|w| w); assert!((({ (*base.upgrade().deref_mut()).apply(5,) }) == 15)); let pair: Value = Rc::new(RefCell::new(Pair { @@ -113,40 +115,30 @@ fn main_0() -> i32 { assert!((({ pair_diff_0((pair.as_pointer()),) }) == 4)); return 0; } -impl ConstructibleFrom<(i32,)> for S { - fn constructor(this: Ptr, (mut x,): (i32,)) { +impl S { + pub fn constructor_1(this: Ptr, mut x: i32) { field!(this, v).write(x); } } -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(i32,)> for M { - fn constructor(this: Ptr, (mut x,): (i32,)) { +impl M { + pub fn constructor_1(this: Ptr, mut x: i32) { field!(this, v).write(x); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(RvalueRef,)> for M { - fn constructor(this: Ptr, (_a0,): (RvalueRef,)) { + pub fn constructor_2(this: Ptr, _a0: RvalueRef) { let _a0 = _a0.as_pointer(); field!(this, v).write({ (*_a0.upgrade().deref()).v }); } -} -impl MoveConstructible for M {} -impl ConvertibleTo for RvalueRef {} -impl ConstructibleFrom<(LvalueRef>,)> for M { - fn constructor(this: Ptr, (o,): (LvalueRef>,)) { + pub fn constructor_3(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); field!(this, v).write((o.with(|__s| __s.v) + 1)); } } -impl CopyConstructible for M {} -impl ConvertibleTo for LvalueRef> {} -impl ConstructibleFrom<(i32,)> for Derived { - fn constructor(this: Ptr, (mut factor,): (i32,)) { +impl Derived { + pub fn constructor_1(this: Ptr, mut factor: i32) { field!(this, factor).write(factor); } } -impl ConvertibleTo for i32 {} +impl S {} impl Destructible for S { fn destroy(this: Ptr) {} } @@ -163,14 +155,30 @@ impl S { return this.with(|__s| __s.v); } } +impl M {} +impl M {} +impl M {} pub fn move_m_1(mut x: i32) -> i32 { - object!(m, M, (i32,), (x,)); - object!(n, M, RvalueRef::bind(m.as_pointer())); + object!(m, M::constructor_1(x)); + object!(n, M::constructor_2(RvalueRef::bind(m.as_pointer()))); return { (*n.borrow()).v }; } +impl Derived {} pub fn pair_sum_2(mut p: Ptr) -> i32 { return ({ p.with(|__s| __s.first) } + { p.with(|__s| __s.second) }); } +impl Constructor<(LvalueRef>,)> for M { + fn constructor(this: Ptr, _: (LvalueRef>,)) { + unreachable!("M::copy_constructor is never defined") + } +} +impl CopyConstructible for M {} +impl Constructor<(RvalueRef,)> for M { + fn constructor(this: Ptr, _: (RvalueRef,)) { + unreachable!("M::move_constructor is never defined") + } +} +impl MoveConstructible for M {} impl Base for Derived { fn apply(&mut self, mut x: i32) -> i32 { return ({ self.factor } * x); 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 2ab77a0f19..48b2fe58d8 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 @@ -19,7 +19,7 @@ use std::rc::Rc; )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy, move)] pub struct S { pub v: i32, } @@ -36,6 +36,7 @@ impl S { pub struct M { pub v: i32, } +impl M {} pub unsafe trait Base { unsafe fn apply(&mut self, x: i32) -> i32; } @@ -55,6 +56,7 @@ pub unsafe trait Base { pub struct Derived { pub factor: i32, } +impl Derived {} #[repr(C)] #[derive( Copy, @@ -82,18 +84,18 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(s, S, (i32,), (1,)); + object_unsafe!(s, S::constructor_1(1)); 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, (i32,), (2,)); - object_unsafe!(n, M, RvalueRefUnsafe::bind(&mut m)); + object_unsafe!(m, M::constructor_1(2)); + object_unsafe!(n, M::constructor_2(RvalueRefUnsafe::bind(&mut m))); assert!(((n.v) == (2))); - object_unsafe!(c, M, LvalueRefUnsafe::bind(&n)); + object_unsafe!(c, M::constructor_3(LvalueRefUnsafe::bind(&n))); assert!(((c.v) == (3))); assert!(((unsafe { move_m_1(5,) }) == (5))); - object_unsafe!(derived, Derived, (i32,), (3,)); + object_unsafe!(derived, Derived::constructor_1(3)); let mut base: *mut dyn Base = (&mut derived as *mut Derived); assert!(((unsafe { (*base).apply(5,) }) == (15))); let mut pair: Pair = Pair { @@ -104,40 +106,30 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { pair_diff_0((&mut pair as *mut Pair).cast_const(),) }) == (4))); return 0; } -impl ConstructibleFromUnsafe<(i32,)> for S { - unsafe fn constructor(this: *mut Self, (mut x,): (i32,)) { +impl S { + pub unsafe fn constructor_1(this: *mut Self, mut x: i32) { (&raw mut (*this).v).write(x); } } -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(i32,)> for M { - unsafe fn constructor(this: *mut Self, (mut x,): (i32,)) { +impl M { + pub unsafe fn constructor_1(this: *mut Self, mut x: i32) { (&raw mut (*this).v).write(x); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for M { - unsafe fn constructor(this: *mut Self, (_a0,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_2(this: *mut Self, _a0: RvalueRefUnsafe) { let _a0 = (_a0.as_ptr() as *mut M); (&raw mut (*this).v).write((*_a0).v); } -} -impl MoveConstructibleUnsafe for M {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for M { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_3(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const M); (&raw mut (*this).v).write((((*o).v) + (1))); } } -impl CopyConstructibleUnsafe for M {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} -impl ConstructibleFromUnsafe<(i32,)> for Derived { - unsafe fn constructor(this: *mut Self, (mut factor,): (i32,)) { +impl Derived { + pub unsafe fn constructor_1(this: *mut Self, mut factor: i32) { (&raw mut (*this).factor).write(factor); } } -impl ConvertibleToUnsafe for i32 {} +impl S {} impl DestructibleUnsafe for S { unsafe fn destroy(this: *mut Self) {} } @@ -152,14 +144,30 @@ impl S { return (*this).v; } } +impl M {} +impl M {} +impl M {} pub unsafe fn move_m_1(mut x: i32) -> i32 { - object_unsafe!(m, M, (i32,), (x,)); - object_unsafe!(n, M, RvalueRefUnsafe::bind(&mut m)); + object_unsafe!(m, M::constructor_1(x)); + object_unsafe!(n, M::constructor_2(RvalueRefUnsafe::bind(&mut m))); return n.v; } +impl Derived {} pub unsafe fn pair_sum_2(mut p: *const Pair) -> i32 { return (((*p).first) + ((*p).second)); } +impl ConstructorUnsafe<(LvalueRefUnsafe>,)> for M { + unsafe fn constructor(this: *mut Self, _: (LvalueRefUnsafe>,)) { + unreachable!("M::copy_constructor is never defined") + } +} +impl CopyConstructibleUnsafe for M {} +impl ConstructorUnsafe<(RvalueRefUnsafe,)> for M { + unsafe fn constructor(this: *mut Self, _: (RvalueRefUnsafe,)) { + unreachable!("M::move_constructor is never defined") + } +} +impl MoveConstructibleUnsafe for M {} unsafe impl Base for Derived { unsafe fn apply(&mut self, x: i32) -> i32 { return ((self.factor) * (x)); diff --git a/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs b/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs index 10358c5863..04d361f353 100644 --- a/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs +++ b/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs @@ -17,7 +17,7 @@ use std::rc::{Rc, Weak}; TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct S_int_ { #[offset(0)] @@ -27,9 +27,7 @@ impl S_int_ { pub fn set(this: Ptr, mut v: i32) { field!(this, x).write(v); } -} -impl ConstructibleFrom<()> for S_int_ { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, x).write(0); } } @@ -43,7 +41,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(p, S_int_); + object!(p, S_int_::constructor_1()); ({ S_int_::set(p.as_pointer(), 3) }); assert!((({ f_0((p.as_pointer()),) }) == 3)); return 0; diff --git a/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs b/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs index ae5d216c1b..79890bde99 100644 --- a/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs +++ b/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs @@ -16,7 +16,7 @@ use std::rc::Rc; TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct S_int_ { pub x: i32, } @@ -24,9 +24,7 @@ impl S_int_ { pub unsafe fn set(this: *mut Self, mut v: i32) { (*this).x = v; } -} -impl ConstructibleFromUnsafe<()> for S_int_ { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).x).write(0); } } @@ -42,7 +40,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(p, S_int_); + object_unsafe!(p, S_int_::constructor_1()); (unsafe { S_int_::set(&raw mut p, 3) }); assert!(((unsafe { f_0((&mut p as *mut S_int_),) }) == (3))); return 0; 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 2c906f9f46..3454e11f54 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 @@ -30,7 +30,7 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -55,28 +55,22 @@ 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 ConstructibleFrom<()> for LifetimeTracked { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl ConstructibleFrom<(LvalueRef>,)> for LifetimeTracked { - fn constructor(this: Ptr, (_a0,): (LvalueRef>,)) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } -impl CopyConstructible for LifetimeTracked {} -impl ConvertibleTo for LvalueRef> {} impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); @@ -96,7 +90,7 @@ impl Destructible for LifetimeTracked { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy, move)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -119,8 +113,9 @@ thread_local!( thread_local!( pub static shared_5: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -153,8 +148,9 @@ impl HasInlineMembers { thread_local!( static local_6: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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 e122471e99..20038d31a8 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 @@ -21,7 +21,7 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] pub struct LifetimeTracked { pub uses: i32, } @@ -38,26 +38,20 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - 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 ConstructibleFromUnsafe<()> for LifetimeTracked { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for LifetimeTracked { - unsafe fn constructor(this: *mut Self, (_a0,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + 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 CopyConstructibleUnsafe for LifetimeTracked {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -76,7 +70,7 @@ impl DestructibleUnsafe for LifetimeTracked { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy, move)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -101,8 +95,8 @@ pub static mut shared_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -133,8 +127,8 @@ impl HasInlineMembers { static mut local_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { 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 a57bc3a85b..2dc5586b1a 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 @@ -30,7 +30,7 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -55,28 +55,22 @@ 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 ConstructibleFrom<()> for LifetimeTracked { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl ConstructibleFrom<(LvalueRef>,)> for LifetimeTracked { - fn constructor(this: Ptr, (_a0,): (LvalueRef>,)) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } -impl CopyConstructible for LifetimeTracked {} -impl ConvertibleTo for LvalueRef> {} impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); @@ -85,8 +79,9 @@ impl Destructible for LifetimeTracked { thread_local!( pub static member_4: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -114,8 +109,9 @@ pub struct HasStaticMember_int_ {} thread_local!( pub static member_5: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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 bfb08d9e75..c925f48bcd 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 @@ -21,7 +21,7 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] pub struct LifetimeTracked { pub uses: i32, } @@ -38,26 +38,20 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - 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 ConstructibleFromUnsafe<()> for LifetimeTracked { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for LifetimeTracked { - unsafe fn constructor(this: *mut Self, (_a0,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + 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 CopyConstructibleUnsafe for LifetimeTracked {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -67,8 +61,8 @@ pub static mut member_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -95,8 +89,8 @@ pub static mut member_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { 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 c52ee51e29..b56c509d41 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 @@ -30,7 +30,7 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -55,28 +55,22 @@ 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 ConstructibleFrom<()> for LifetimeTracked { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl ConstructibleFrom<(LvalueRef>,)> for LifetimeTracked { - fn constructor(this: Ptr, (_a0,): (LvalueRef>,)) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } -impl CopyConstructible for LifetimeTracked {} -impl ConvertibleTo for LvalueRef> {} impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); @@ -96,7 +90,7 @@ impl Destructible for LifetimeTracked { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy, move)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -119,8 +113,9 @@ pub fn count_10() -> i32 { thread_local!( static t_5: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -135,8 +130,9 @@ thread_local!( thread_local!( static t_8: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -151,8 +147,9 @@ thread_local!( thread_local!( static t_11: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -213,8 +210,9 @@ pub fn count_18() -> i32 { thread_local!( static t_19: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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 60edcfae1f..c61394add1 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 @@ -21,7 +21,7 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] pub struct LifetimeTracked { pub uses: i32, } @@ -38,26 +38,20 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - 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 ConstructibleFromUnsafe<()> for LifetimeTracked { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for LifetimeTracked { - unsafe fn constructor(this: *mut Self, (_a0,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + 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 CopyConstructibleUnsafe for LifetimeTracked {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -76,7 +70,7 @@ impl DestructibleUnsafe for LifetimeTracked { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy, move)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -99,8 +93,8 @@ pub unsafe fn count_10() -> i32 { static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -113,8 +107,8 @@ static mut n_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { static mut t_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -127,8 +121,8 @@ static mut n_9: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { static mut t_11: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -188,8 +182,8 @@ pub unsafe fn count_18() -> i32 { static mut t_19: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&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 a48791e45c..51a456a061 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 @@ -30,7 +30,7 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -55,28 +55,22 @@ 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 ConstructibleFrom<()> for LifetimeTracked { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl ConstructibleFrom<(LvalueRef>,)> for LifetimeTracked { - fn constructor(this: Ptr, (_a0,): (LvalueRef>,)) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } -impl CopyConstructible for LifetimeTracked {} -impl ConvertibleTo for LvalueRef> {} impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); @@ -96,7 +90,7 @@ impl Destructible for LifetimeTracked { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy, move)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -113,8 +107,9 @@ pub fn instance_4() -> Ptr { thread_local!( static t_5: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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 de3976490c..844ab535bf 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 @@ -21,7 +21,7 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] pub struct LifetimeTracked { pub uses: i32, } @@ -38,26 +38,20 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - 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 ConstructibleFromUnsafe<()> for LifetimeTracked { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for LifetimeTracked { - unsafe fn constructor(this: *mut Self, (_a0,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + 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 CopyConstructibleUnsafe for LifetimeTracked {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -76,7 +70,7 @@ impl DestructibleUnsafe for LifetimeTracked { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy, move)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -93,8 +87,8 @@ pub unsafe fn instance_4() -> *mut LifetimeTracked { static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { 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 d4f4a9241f..4fffe26efa 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 @@ -30,7 +30,7 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -55,28 +55,22 @@ 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 ConstructibleFrom<()> for LifetimeTracked { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl ConstructibleFrom<(LvalueRef>,)> for LifetimeTracked { - fn constructor(this: Ptr, (_a0,): (LvalueRef>,)) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } -impl CopyConstructible for LifetimeTracked {} -impl ConvertibleTo for LvalueRef> {} impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); @@ -96,7 +90,7 @@ impl Destructible for LifetimeTracked { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy, move)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -119,8 +113,9 @@ thread_local!( thread_local!( pub static shared_5: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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 ca5c94afb2..cf86c728cd 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 @@ -21,7 +21,7 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] pub struct LifetimeTracked { pub uses: i32, } @@ -38,26 +38,20 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - 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 ConstructibleFromUnsafe<()> for LifetimeTracked { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for LifetimeTracked { - unsafe fn constructor(this: *mut Self, (_a0,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + 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 CopyConstructibleUnsafe for LifetimeTracked {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -76,7 +70,7 @@ impl DestructibleUnsafe for LifetimeTracked { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy, move)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -101,8 +95,8 @@ pub static mut shared_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { 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 d7ca4a879b..4d03844d70 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 @@ -30,7 +30,7 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -55,28 +55,22 @@ 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 ConstructibleFrom<()> for LifetimeTracked { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl ConstructibleFrom<(LvalueRef>,)> for LifetimeTracked { - fn constructor(this: Ptr, (_a0,): (LvalueRef>,)) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } -impl CopyConstructible for LifetimeTracked {} -impl ConvertibleTo for LvalueRef> {} impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); @@ -96,7 +90,7 @@ impl Destructible for LifetimeTracked { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy, move)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -143,8 +137,9 @@ impl X { thread_local!( static local_4: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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 f15d5e9e7b..0a05a856f4 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 @@ -21,7 +21,7 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] pub struct LifetimeTracked { pub uses: i32, } @@ -38,26 +38,20 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - 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 ConstructibleFromUnsafe<()> for LifetimeTracked { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for LifetimeTracked { - unsafe fn constructor(this: *mut Self, (_a0,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + 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 CopyConstructibleUnsafe for LifetimeTracked {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -76,7 +70,7 @@ impl DestructibleUnsafe for LifetimeTracked { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy, move)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -127,8 +121,8 @@ impl X { static mut local_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { 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 dbfc8b8847..f5a3102da7 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 @@ -30,7 +30,7 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -55,28 +55,22 @@ 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 ConstructibleFrom<()> for LifetimeTracked { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl ConstructibleFrom<(LvalueRef>,)> for LifetimeTracked { - fn constructor(this: Ptr, (_a0,): (LvalueRef>,)) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } -impl CopyConstructible for LifetimeTracked {} -impl ConvertibleTo for LvalueRef> {} impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); @@ -96,7 +90,7 @@ impl Destructible for LifetimeTracked { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy, move)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -124,8 +118,9 @@ pub fn f_4(mut cond: bool, mut p: FnPtr) { thread_local!( static local_5: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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 9d3cf1af1f..5f6fdf29c3 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 @@ -21,7 +21,7 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] pub struct LifetimeTracked { pub uses: i32, } @@ -38,26 +38,20 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - 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 ConstructibleFromUnsafe<()> for LifetimeTracked { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for LifetimeTracked { - unsafe fn constructor(this: *mut Self, (_a0,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + 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 CopyConstructibleUnsafe for LifetimeTracked {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -76,7 +70,7 @@ impl DestructibleUnsafe for LifetimeTracked { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy, move)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -108,8 +102,8 @@ pub unsafe fn f_4(mut cond: bool, mut p: Option) { static mut local_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/basic.link/out/refcount/basic.link.rs b/tests/std/basic/basic.link/out/refcount/basic.link.rs index 5c5af06244..13fa3dbf24 100644 --- a/tests/std/basic/basic.link/out/refcount/basic.link.rs +++ b/tests/std/basic/basic.link/out/refcount/basic.link.rs @@ -86,14 +86,14 @@ pub fn bump_18() -> i32 { TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct Record_19 { #[offset(0)] pub id: i32, } -impl ConstructibleFrom<()> for Record_19 { - fn constructor(this: Ptr, _: ()) { +impl Record_19 { + pub fn constructor_1(this: Ptr) { field!(this, id).write(100); } } @@ -109,7 +109,7 @@ pub fn test_21() { assert!((({ bump_18() }) == 2)); assert!((({ bump_in_b_22() }) == 51)); assert!((counter_17.with(|rc| *rc.borrow()) == 2)); - object!(record, Record_19); + object!(record, Record_19::constructor_1()); assert!(({ (*record.borrow()).id } == 100)); assert!((({ record_id_in_b_23() }) == 200)); assert!((depth_20.with(|rc| *rc.borrow()) == 3)); @@ -227,11 +227,11 @@ thread_local!( static count_48: Value = Rc::new(RefCell::new(1)); ); pub fn first_key_51() -> i32 { - object!(entry, Entry_52); + object!(entry, Entry_52::constructor_1()); return { (*entry.borrow()).key }; } pub fn second_key_plus_value_53() -> i32 { - object!(entry, Entry_54); + object!(entry, Entry_54::constructor_1()); return ({ (*entry.borrow()).key } + { (*entry.borrow()).value }); } pub fn test_55() { @@ -250,14 +250,14 @@ pub fn test_55() { TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct Entry_52 { #[offset(0)] pub key: i32, } -impl ConstructibleFrom<()> for Entry_52 { - fn constructor(this: Ptr, _: ()) { +impl Entry_52 { + pub fn constructor_1(this: Ptr) { field!(this, key).write(1); } } @@ -277,7 +277,7 @@ impl Default for Entry_52 { TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(8)] pub struct Entry_54 { #[offset(0)] @@ -285,8 +285,8 @@ pub struct Entry_54 { #[offset(4)] pub value: i32, } -impl ConstructibleFrom<()> for Entry_54 { - fn constructor(this: Ptr, _: ()) { +impl Entry_54 { + pub fn constructor_1(this: Ptr) { field!(this, key).write(2); field!(this, value).write(30); } @@ -412,7 +412,7 @@ pub fn bump_64() -> i32 { TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(16)] pub struct Record_65 { #[offset(0)] @@ -420,8 +420,8 @@ pub struct Record_65 { #[offset(8)] pub extra: i32, } -impl ConstructibleFrom<()> for Record_65 { - fn constructor(this: Ptr, _: ()) { +impl Record_65 { + pub fn constructor_1(this: Ptr) { field!(this, id).write(200_i64); field!(this, extra).write(1); } @@ -443,7 +443,7 @@ pub fn bump_in_b_22() -> i32 { return ({ bump_64() }); } pub fn record_id_in_b_23() -> i32 { - object!(record, Record_65); + object!(record, Record_65::constructor_1()); return ({ (*record.borrow()).id } as i32); } pub fn depth_in_b_24() -> i32 { @@ -520,7 +520,7 @@ thread_local!( static count_70: Value = Rc::new(RefCell::new(0)); ); pub fn key_in_b_56() -> i32 { - object!(entry, Entry_71); + object!(entry, Entry_71::constructor_1()); return ({ (*entry.borrow()).key } as i32); } #[derive( @@ -534,14 +534,14 @@ pub fn key_in_b_56() -> i32 { TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(8)] pub struct Entry_71 { #[offset(0)] pub key: i64, } -impl ConstructibleFrom<()> for Entry_71 { - fn constructor(this: Ptr, _: ()) { +impl Entry_71 { + pub fn constructor_1(this: Ptr) { field!(this, key).write(400_i64); } } diff --git a/tests/std/basic/basic.link/out/unsafe/basic.link.rs b/tests/std/basic/basic.link/out/unsafe/basic.link.rs index b41717ffb0..fb190851d0 100644 --- a/tests/std/basic/basic.link/out/unsafe/basic.link.rs +++ b/tests/std/basic/basic.link/out/unsafe/basic.link.rs @@ -77,12 +77,12 @@ pub unsafe fn bump_18() -> i32 { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Record_19 { pub id: i32, } -impl ConstructibleFromUnsafe<()> for Record_19 { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Record_19 { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).id).write(100); } } @@ -96,7 +96,7 @@ pub unsafe fn test_21() { assert!(((unsafe { bump_18() }) == (2))); assert!(((unsafe { bump_in_b_22() }) == (51))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut counter_17)) == (2))); - object_unsafe!(record, Record_19); + object_unsafe!(record, Record_19::constructor_1()); assert!(((record.id) == (100))); assert!(((unsafe { record_id_in_b_23() }) == (200))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut depth_20)) == (3))); @@ -202,11 +202,11 @@ pub unsafe fn test_49() { static mut count_46: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); static mut count_48: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 1 }); pub unsafe fn first_key_51() -> i32 { - object_unsafe!(entry, Entry_52); + object_unsafe!(entry, Entry_52::constructor_1()); return entry.key; } pub unsafe fn second_key_plus_value_53() -> i32 { - object_unsafe!(entry, Entry_54); + object_unsafe!(entry, Entry_54::constructor_1()); return ((entry.key) + (entry.value)); } pub unsafe fn test_55() { @@ -224,12 +224,12 @@ pub unsafe fn test_55() { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Entry_52 { pub key: i32, } -impl ConstructibleFromUnsafe<()> for Entry_52 { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Entry_52 { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).key).write(1); } } @@ -248,13 +248,13 @@ impl Default for Entry_52 { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Entry_54 { pub key: i32, pub value: i32, } -impl ConstructibleFromUnsafe<()> for Entry_54 { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Entry_54 { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).key).write(2); (&raw mut (*this).value).write(30); } @@ -356,13 +356,13 @@ pub unsafe fn bump_64() -> i32 { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Record_65 { pub id: i64, pub extra: i32, } -impl ConstructibleFromUnsafe<()> for Record_65 { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Record_65 { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).id).write(200_i64); (&raw mut (*this).extra).write(1); } @@ -382,7 +382,7 @@ pub unsafe fn bump_in_b_22() -> i32 { return (unsafe { bump_64() }); } pub unsafe fn record_id_in_b_23() -> i32 { - object_unsafe!(record, Record_65); + object_unsafe!(record, Record_65::constructor_1()); return (record.id as i32); } pub unsafe fn depth_in_b_24() -> i32 { @@ -444,7 +444,7 @@ pub unsafe fn next_in_b_50() -> i32 { } static mut count_70: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub unsafe fn key_in_b_56() -> i32 { - object_unsafe!(entry, Entry_71); + object_unsafe!(entry, Entry_71::constructor_1()); return (entry.key as i32); } #[repr(C)] @@ -457,12 +457,12 @@ pub unsafe fn key_in_b_56() -> i32 { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Entry_71 { pub key: i64, } -impl ConstructibleFromUnsafe<()> for Entry_71 { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Entry_71 { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).key).write(400_i64); } } 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 2e83086026..38eb2a28b7 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 @@ -30,7 +30,7 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -55,28 +55,22 @@ 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 ConstructibleFrom<()> for LifetimeTracked { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl ConstructibleFrom<(LvalueRef>,)> for LifetimeTracked { - fn constructor(this: Ptr, (_a0,): (LvalueRef>,)) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } -impl CopyConstructible for LifetimeTracked {} -impl ConvertibleTo for LvalueRef> {} impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); @@ -105,25 +99,20 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] -#[conversion_function(bool, const_lvalue_ref, explicit)] +#[conversions(copy, move)] +#[conversion_function(conversion_function_1, bool, const_lvalue_ref, explicit)] #[byte_size(4)] pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { #[offset(0)] pub value: i32, } -impl - ConversionFunction< - bool, - LvalueRef>, - > for p1_1_condition_variable_visible_in_else_ConvertsToBool -{ - fn conversion_function( +impl p1_1_condition_variable_visible_in_else_ConvertsToBool { + pub fn conversion_function_1( this: LvalueRef>, - to: Ptr, + __return: Ptr, ) { let this = this.as_pointer(); - to.write((this.with(|__s| __s.value) != 0)); + __return.write((this.with(|__s| __s.value) != 0)); return; } } @@ -141,8 +130,8 @@ pub fn test_7() { Destructible::destroy(__p.as_pointer()) }); if { - let __v: Value = Rc::new(RefCell::new(false)); - p1_1_condition_variable_visible_in_else_ConvertsToBool::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p1_1_condition_variable_visible_in_else_ConvertsToBool::conversion_function_1( >>::bind( condition.as_pointer(), ), @@ -168,8 +157,8 @@ pub fn test_7() { Destructible::destroy(__p.as_pointer()) }); if { - let __v: Value = Rc::new(RefCell::new(false)); - p1_1_condition_variable_visible_in_else_ConvertsToBool::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p1_1_condition_variable_visible_in_else_ConvertsToBool::conversion_function_1( >>::bind( condition.as_pointer(), ), @@ -208,13 +197,13 @@ pub fn test_8() { } pub fn test_9() { ({ LifetimeTracked::reset() }); - object!(scoped, LifetimeTracked); + object!(scoped, LifetimeTracked::constructor_1()); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); { let mut index: i32 = 0; 'loop_: while (index < 3) { 'for_body: { - object!(scoped, LifetimeTracked); + object!(scoped, LifetimeTracked::constructor_1()); } index.prefix_inc(); } @@ -222,13 +211,13 @@ pub fn test_9() { assert!((ctorCount_0.with(|rc| *rc.borrow()) == 4)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 3)); if (ctorCount_0.with(|rc| *rc.borrow()) == 4) { - object!(scoped, LifetimeTracked); + object!(scoped, LifetimeTracked::constructor_1()); } assert!((ctorCount_0.with(|rc| *rc.borrow()) == 5)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 4)); if (ctorCount_0.with(|rc| *rc.borrow()) == 0) { } else { - object!(scoped, LifetimeTracked); + object!(scoped, LifetimeTracked::constructor_1()); } assert!((ctorCount_0.with(|rc| *rc.borrow()) == 6)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 5)); @@ -257,9 +246,9 @@ pub fn test_10() { } pub fn test_11() { ({ LifetimeTracked::reset() }); - object!(tracked, LifetimeTracked); + object!(tracked, LifetimeTracked::constructor_1()); { - object!(tracked, LifetimeTracked); + object!(tracked, LifetimeTracked::constructor_1()); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2)); ({ LifetimeTracked::use_(tracked.as_pointer()) }); assert!(({ (*tracked.borrow()).uses } == 1)); diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs index 80ff36ac2f..7ea0c42375 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs @@ -20,7 +20,7 @@ thread_local!( TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct p1_member_hides_namespace_variable_HasBalance { #[offset(0)] @@ -37,9 +37,7 @@ impl p1_member_hides_namespace_variable_HasBalance { balance_0.with(|rc| *rc.borrow_mut() += amount); return balance_0.with(|rc| *rc.borrow()); } -} -impl ConstructibleFrom<()> for p1_member_hides_namespace_variable_HasBalance { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, balance).write(7); } } @@ -49,7 +47,10 @@ impl Default for p1_member_hides_namespace_variable_HasBalance { } } pub fn test_1() { - object!(object, p1_member_hides_namespace_variable_HasBalance); + object!( + object, + p1_member_hides_namespace_variable_HasBalance::constructor_1() + ); assert!( (({ p1_member_hides_namespace_variable_HasBalance::deposit(object.as_pointer(), 3,) }) == 10) @@ -78,14 +79,14 @@ thread_local!( TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { #[offset(0)] pub held: i32, } -impl ConstructibleFrom<()> for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { - fn constructor(this: Ptr, _: ()) { +impl p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { + pub fn constructor_1(this: Ptr) { field!(this, held).write(1); } } @@ -113,7 +114,7 @@ pub fn test_5() { assert!((total_4.with(|rc| *rc.borrow()) == 7)); object!( object, - p1_out_of_class_definition_is_in_class_scope_HasStaticTotal + p1_out_of_class_definition_is_in_class_scope_HasStaticTotal::constructor_1() ); assert!( (({ diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs index 5abae02300..a03c662060 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs @@ -20,34 +20,27 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { #[offset(0)] pub amount: i32, } impl p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { - pub fn add(this: Ptr, mut amount: i32) -> i32 { - return (this.with(|__s| __s.amount) + amount); - } -} -impl ConstructibleFrom<(i32,)> - for p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter -{ - fn constructor(this: Ptr, (mut amount,): (i32,)) { + pub fn constructor_1(this: Ptr, mut amount: i32) { field!(this, amount).write((amount + 1)); amount += 10; assert!((amount == 14)); assert!((this.with(|__s| __s.amount) == 5)); } + pub fn add(this: Ptr, mut amount: i32) -> i32 { + return (this.with(|__s| __s.amount) + amount); + } } -impl ConvertibleTo for i32 {} pub fn test_0() { object!( object, - p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter, - (i32,), - (4,) + p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter::constructor_1(4) ); assert!(({ (*object.borrow()).amount } == 5)); assert!( diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs index d7c23708b4..8707ee60d1 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs @@ -88,15 +88,15 @@ pub const anon_4_above: anon_4 = 14; #[derive( Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(8)] pub struct p9_func_declared_before_function_body_RecordsConstructorName { #[offset(0)] #[byte_size(8)] pub name: Ptr, } -impl ConstructibleFrom<()> for p9_func_declared_before_function_body_RecordsConstructorName { - fn constructor(this: Ptr, _: ()) { +impl p9_func_declared_before_function_body_RecordsConstructorName { + pub fn constructor_1(this: Ptr) { field!(this, name).write(Ptr::::from_string_literal(b"RecordsConstructorName")); assert!( (this.with(|__s| __s.name.clone()) @@ -109,10 +109,10 @@ impl Default for p9_func_declared_before_function_body_RecordsConstructorName { { { let __v: Value = - Rc::new(RefCell::new( - ::zero_init(), - )); - >::constructor(__v.as_pointer(), ()) ; + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p9_func_declared_before_function_body_RecordsConstructorName::constructor_1( + __v.as_pointer(), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -142,7 +142,7 @@ pub fn test_6() { assert!((({ plain_function_5() }) == ({ plain_function_5() }))); object!( object, - p9_func_declared_before_function_body_RecordsConstructorName + p9_func_declared_before_function_body_RecordsConstructorName::constructor_1() ); assert!( ({ diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs index b208adf2f4..38d79e1916 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs @@ -277,7 +277,7 @@ impl Default for anon_11 { TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(8)] pub struct p3_2_const_qualified_member_is_distinct_HasConstOverload { #[offset(0)] @@ -298,9 +298,7 @@ impl p3_2_const_qualified_member_is_distinct_HasConstOverload { }); return 2; } -} -impl ConstructibleFrom<()> for p3_2_const_qualified_member_is_distinct_HasConstOverload { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, plain_calls).write(0); field!(this, const_calls).write(0); } @@ -318,7 +316,7 @@ impl Default for p3_2_const_qualified_member_is_distinct_HasConstOverload { pub fn test_12() { object!( object, - p3_2_const_qualified_member_is_distinct_HasConstOverload + p3_2_const_qualified_member_is_distinct_HasConstOverload::constructor_1() ); let view: Ptr = object.as_pointer(); assert!( @@ -352,7 +350,7 @@ thread_local!( TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { #[offset(0)] @@ -370,11 +368,7 @@ impl p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverl (*rvalue_calls_14.with(Value::clone).borrow_mut()).prefix_inc(); return ((this.with(|__s| __s.base) + amount) + 100); } -} -impl ConstructibleFrom<()> - for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload -{ - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, base).write(10); } } @@ -388,10 +382,7 @@ impl Default for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplici } } pub fn test_15() { - object!( - object, - p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload - ); + object!(object, p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload::constructor_1()); assert!( (({ p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload::pick_1( @@ -403,10 +394,12 @@ pub fn test_15() { assert!((explicit_calls_13.with(|rc| *rc.borrow()) == 1)); assert!((rvalue_calls_14.with(|rc| *rc.borrow()) == 0)); { - let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_0: Value< + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload, + > = Rc::new(RefCell::new(ZeroInitialization::zero_init())); assert!( (({ - p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( { >::constructor(__tmp_0.as_pointer(), ()) ; __tmp_0.as_pointer() } , 2 , ) + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( { p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload::constructor_1(__tmp_0.as_pointer()) ; __tmp_0.as_pointer() } , 2 , ) }) == 112) ) }; @@ -491,7 +484,7 @@ pub fn test_18() { TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(8)] pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { #[offset(0)] @@ -500,6 +493,10 @@ pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOv pub const_calls: i32, } impl p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { + pub fn constructor_1(this: Ptr) { + field!(this, plain_calls).write(0); + field!(this, const_calls).write(0); + } pub fn get_1_int(this: Ptr, mut value: i32) -> i32 { field!(this, plain_calls).with_mut(|__v| { __v.prefix_inc(); @@ -513,14 +510,6 @@ impl p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload return (value + 2); } } -impl ConstructibleFrom<()> - for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload -{ - fn constructor(this: Ptr, _: ()) { - field!(this, plain_calls).write(0); - field!(this, const_calls).write(0); - } -} impl Default for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { fn default() -> Self { { @@ -534,7 +523,8 @@ impl Default for p3_4_const_qualified_member_templates_are_distinct_HasConstTemp pub fn test_19() { object!( object, - p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload + p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload::constructor_1( + ) ); let view: Ptr = object.as_pointer(); 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 464db36838..7c0b1d6b29 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 @@ -21,7 +21,7 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] pub struct LifetimeTracked { pub uses: i32, } @@ -38,26 +38,20 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - 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 ConstructibleFromUnsafe<()> for LifetimeTracked { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for LifetimeTracked { - unsafe fn constructor(this: *mut Self, (_a0,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + 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 CopyConstructibleUnsafe for LifetimeTracked {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -81,23 +75,18 @@ pub static mut dtorCount_6: std::cell::LazyCell = std::cell::LazyCell::new( )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] -#[conversion_function(bool, const_lvalue_ref, explicit)] +#[conversions(copy, move)] +#[conversion_function(conversion_function_1, bool, const_lvalue_ref, explicit)] pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { pub value: i32, } -impl - ConversionFunctionUnsafe< - bool, - LvalueRefUnsafe>, - > for p1_1_condition_variable_visible_in_else_ConvertsToBool -{ - unsafe fn conversion_function( +impl p1_1_condition_variable_visible_in_else_ConvertsToBool { + pub unsafe fn conversion_function_1( this: LvalueRefUnsafe>, - to: *mut bool, + __return: *mut bool, ) { let this = this.as_ptr() as *mut p1_1_condition_variable_visible_in_else_ConvertsToBool; - to.write((((*this).value) != (0))); + __return.write((((*this).value) != (0))); return; } } @@ -114,8 +103,8 @@ pub unsafe fn test_7() { DestructibleUnsafe::destroy(__p) }); if { - let mut __v: bool = false; - p1_1_condition_variable_visible_in_else_ConvertsToBool::conversion_function(>>::bind(& mut condition ), &raw mut __v); + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + p1_1_condition_variable_visible_in_else_ConvertsToBool::conversion_function_1(>>::bind(& mut condition ), &raw mut __v); __v } { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); @@ -135,8 +124,8 @@ pub unsafe fn test_7() { DestructibleUnsafe::destroy(__p) }); if { - let mut __v: bool = false; - p1_1_condition_variable_visible_in_else_ConvertsToBool::conversion_function(>>::bind(& mut condition ), &raw mut __v); + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + p1_1_condition_variable_visible_in_else_ConvertsToBool::conversion_function_1(>>::bind(& mut condition ), &raw mut __v); __v } { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); @@ -170,13 +159,13 @@ pub unsafe fn test_8() { } pub unsafe fn test_9() { (unsafe { LifetimeTracked::reset() }); - object_unsafe!(scoped, LifetimeTracked); + object_unsafe!(scoped, LifetimeTracked::constructor_1()); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); { let mut index: i32 = 0; 'loop_: while ((index) < (3)) { 'for_body: { - object_unsafe!(scoped, LifetimeTracked); + object_unsafe!(scoped, LifetimeTracked::constructor_1()); } index.prefix_inc(); } @@ -184,13 +173,13 @@ pub unsafe fn test_9() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (4))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (3))); if ((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (4)) { - object_unsafe!(scoped, LifetimeTracked); + object_unsafe!(scoped, LifetimeTracked::constructor_1()); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (5))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (4))); if ((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0)) { } else { - object_unsafe!(scoped, LifetimeTracked); + object_unsafe!(scoped, LifetimeTracked::constructor_1()); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (6))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (5))); @@ -215,9 +204,9 @@ pub unsafe fn test_10() { } pub unsafe fn test_11() { (unsafe { LifetimeTracked::reset() }); - object_unsafe!(tracked, LifetimeTracked); + object_unsafe!(tracked, LifetimeTracked::constructor_1()); { - object_unsafe!(tracked, LifetimeTracked); + object_unsafe!(tracked, LifetimeTracked::constructor_1()); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2))); (unsafe { LifetimeTracked::use_(&raw const tracked) }); assert!(((tracked.uses) == (1))); diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs index d30922ed12..0a6c1b1f5e 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs @@ -17,7 +17,7 @@ pub static mut balance_0: std::cell::LazyCell = std::cell::LazyCell::new(|| TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct p1_member_hides_namespace_variable_HasBalance { pub balance: i32, } @@ -30,9 +30,7 @@ impl p1_member_hides_namespace_variable_HasBalance { (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_0)) += amount; return (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_0)); } -} -impl ConstructibleFromUnsafe<()> for p1_member_hides_namespace_variable_HasBalance { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).balance).write(7); } } @@ -42,7 +40,10 @@ impl Default for p1_member_hides_namespace_variable_HasBalance { } } pub unsafe fn test_1() { - object_unsafe!(object, p1_member_hides_namespace_variable_HasBalance); + object_unsafe!( + object, + p1_member_hides_namespace_variable_HasBalance::constructor_1() + ); assert!( ((unsafe { p1_member_hides_namespace_variable_HasBalance::deposit(&raw mut object, 3,) }) == (10)) @@ -68,12 +69,12 @@ pub static mut initial_2: std::cell::LazyCell = std::cell::LazyCell::new(|| TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { pub held: i32, } -impl ConstructibleFromUnsafe<()> for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { - unsafe fn constructor(this: *mut Self, _: ()) { +impl p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).held).write(1); } } @@ -98,7 +99,7 @@ pub unsafe fn test_5() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_4)) == (7))); object_unsafe!( object, - p1_out_of_class_definition_is_in_class_scope_HasStaticTotal + p1_out_of_class_definition_is_in_class_scope_HasStaticTotal::constructor_1() ); assert!( ((unsafe { diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs index b5bd173567..be3ead73e1 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs @@ -19,35 +19,25 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] pub struct p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { pub amount: i32, } impl p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { - pub unsafe fn add(this: *const Self, mut amount: i32) -> i32 { - return (((*this).amount) + (amount)); - } -} -impl ConstructibleFromUnsafe<(i32,)> - for p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter -{ - unsafe fn constructor(this: *mut Self, (mut amount,): (i32,)) { + pub unsafe fn constructor_1(this: *mut Self, mut amount: i32) { (&raw mut (*this).amount).write(((amount) + (1))); amount += 10; assert!(((amount) == (14))); assert!((((*this).amount) == (5))); } -} -impl ConvertibleToUnsafe - for i32 -{ + pub unsafe fn add(this: *const Self, mut amount: i32) -> i32 { + return (((*this).amount) + (amount)); + } } pub unsafe fn test_0() { object_unsafe!( object, - p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter, - (i32,), - (4,) + p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter::constructor_1(4) ); assert!(((object.amount) == (5))); assert!( diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs index 0a52f3e76e..66394feebd 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs @@ -92,12 +92,12 @@ pub const anon_4_above: anon_4 = 14; TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct p9_func_declared_before_function_body_RecordsConstructorName { pub name: *const libc::c_char, } -impl ConstructibleFromUnsafe<()> for p9_func_declared_before_function_body_RecordsConstructorName { - unsafe fn constructor(this: *mut Self, _: ()) { +impl p9_func_declared_before_function_body_RecordsConstructorName { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).name).write(c"RecordsConstructorName".as_ptr()); assert!((((*this).name) == (c"RecordsConstructorName".as_ptr()))); } @@ -107,8 +107,10 @@ impl Default for p9_func_declared_before_function_body_RecordsConstructorName { unsafe { { let mut __v: p9_func_declared_before_function_body_RecordsConstructorName = - ::zero_init(); - >::constructor(&raw mut __v, ()) ; + ZeroInitializationUnsafe::zero_init(); + p9_func_declared_before_function_body_RecordsConstructorName::constructor_1( + &raw mut __v, + ); __v } } @@ -122,7 +124,7 @@ pub unsafe fn test_6() { assert!(((unsafe { plain_function_5() }) == (unsafe { plain_function_5() }))); object_unsafe!( object, - p9_func_declared_before_function_body_RecordsConstructorName + p9_func_declared_before_function_body_RecordsConstructorName::constructor_1() ); assert!(((libc::strcmp(object.name, c"RecordsConstructorName".as_ptr())) == (0))); let mut enclosing: *const libc::c_char = c"test".as_ptr(); diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs index cd5b908750..7094982faf 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs @@ -226,7 +226,7 @@ impl Default for anon_11 { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct p3_2_const_qualified_member_is_distinct_HasConstOverload { pub plain_calls: i32, pub const_calls: i32, @@ -240,9 +240,7 @@ impl p3_2_const_qualified_member_is_distinct_HasConstOverload { (*(&raw const (*this).const_calls).cast_mut()).prefix_inc(); return 2; } -} -impl ConstructibleFromUnsafe<()> for p3_2_const_qualified_member_is_distinct_HasConstOverload { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).plain_calls).write(0); (&raw mut (*this).const_calls).write(0); } @@ -260,7 +258,7 @@ impl Default for p3_2_const_qualified_member_is_distinct_HasConstOverload { pub unsafe fn test_12() { object_unsafe!( object, - p3_2_const_qualified_member_is_distinct_HasConstOverload + p3_2_const_qualified_member_is_distinct_HasConstOverload::constructor_1() ); let view: *const p3_2_const_qualified_member_is_distinct_HasConstOverload = &object; assert!( @@ -292,7 +290,7 @@ pub static mut rvalue_calls_14: std::cell::LazyCell = TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { pub base: i32, } @@ -308,11 +306,7 @@ impl p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverl (*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_14)).prefix_inc(); return ((((*this).base) + (amount)) + (100)); } -} -impl ConstructibleFromUnsafe<()> - for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload -{ - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).base).write(10); } } @@ -326,10 +320,7 @@ impl Default for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplici } } pub unsafe fn test_15() { - object_unsafe!( - object, - p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload - ); + object_unsafe!(object, p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload::constructor_1()); assert!( ((unsafe { p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload::pick_1( @@ -341,10 +332,10 @@ pub unsafe fn test_15() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut explicit_calls_13)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_14)) == (0))); { - let mut __tmp_0: p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload = ::zero_init(); + let mut __tmp_0: p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload = ZeroInitializationUnsafe::zero_init(); assert!( ((unsafe { - p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( &mut (*{ >::constructor(&raw mut __tmp_0, ()) ; & mut __tmp_0 } ) , 2 , ) + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( &mut (*{ p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload::constructor_1(&raw mut __tmp_0) ; & mut __tmp_0 } ) , 2 , ) }) == (112)) ) }; @@ -416,12 +407,16 @@ pub unsafe fn test_18() { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { pub plain_calls: i32, pub const_calls: i32, } impl p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).plain_calls).write(0); + (&raw mut (*this).const_calls).write(0); + } pub unsafe fn get_1_int(this: *mut Self, mut value: i32) -> i32 { (*this).plain_calls.prefix_inc(); return ((value) + (1)); @@ -431,14 +426,6 @@ impl p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload return ((value) + (2)); } } -impl ConstructibleFromUnsafe<()> - for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload -{ - unsafe fn constructor(this: *mut Self, _: ()) { - (&raw mut (*this).plain_calls).write(0); - (&raw mut (*this).const_calls).write(0); - } -} impl Default for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { fn default() -> Self { unsafe { @@ -452,7 +439,8 @@ impl Default for p3_4_const_qualified_member_templates_are_distinct_HasConstTemp pub unsafe fn test_19() { object_unsafe!( object, - p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload + p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload::constructor_1( + ) ); let view: *const p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload = &object; diff --git a/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs b/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs index 5a1eb582e9..d098b69ee8 100644 --- a/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs +++ b/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs @@ -20,15 +20,15 @@ use std::rc::{Rc, Weak}; )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] -#[constructor(explicit, value(i32))] +#[conversions(copy, move)] +#[constructor(constructor_1, explicit, value(i32))] #[byte_size(4)] pub struct Tracker { #[offset(0)] pub tag: i32, } -impl ConstructibleFrom<(i32,)> for Tracker { - fn constructor(this: Ptr, (mut tag,): (i32,)) { +impl Tracker { + pub fn constructor_1(this: Ptr, mut tag: i32) { field!(this, tag).write(tag); printf!(b"construct %d\n", tag); } @@ -41,8 +41,8 @@ impl Destructible for Tracker { thread_local!( pub static global_0: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (1,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracker::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -55,14 +55,14 @@ pub fn exit_from_nested_call_1() { printf!(b"local static %d\n", { (*local_static_2.with(Value::clone).borrow()).tag }); - object!(automatic, Tracker, (i32,), (3,)); + object!(automatic, Tracker::constructor_1(3)); libcc2rs::cpp2rust_exit(0); } thread_local!( static local_static_2: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (2,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracker::constructor_1(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/basic.start/out/refcount/basic.start.term.rs b/tests/std/basic/basic.start/out/refcount/basic.start.term.rs index ea1f6821f0..11d460d27e 100644 --- a/tests/std/basic/basic.start/out/refcount/basic.start.term.rs +++ b/tests/std/basic/basic.start/out/refcount/basic.start.term.rs @@ -20,23 +20,21 @@ use std::rc::{Rc, Weak}; )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] -#[constructor(explicit, value(i32))] +#[conversions(copy, move)] +#[constructor(constructor_1, explicit, value(i32))] #[byte_size(4)] pub struct Tracker { #[offset(0)] pub tag: i32, } impl Tracker { - pub fn touch(this: Ptr) { - printf!(b"touch %d\n", this.with(|__s| __s.tag)); - } -} -impl ConstructibleFrom<(i32,)> for Tracker { - fn constructor(this: Ptr, (mut tag,): (i32,)) { + pub fn constructor_1(this: Ptr, mut tag: i32) { field!(this, tag).write(tag); printf!(b"construct %d\n", tag); } + pub fn touch(this: Ptr) { + printf!(b"touch %d\n", this.with(|__s| __s.tag)); + } } impl Destructible for Tracker { fn destroy(this: Ptr) { @@ -88,8 +86,8 @@ pub struct TriviallyDestructible { thread_local!( pub static global_0: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (1,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracker::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -107,8 +105,8 @@ pub fn test_3() { thread_local!( static never_constructed_2: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (100,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracker::constructor_1(__v.as_pointer(), 100); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -123,8 +121,8 @@ pub fn local_static_during_global_init_4() -> Ptr { thread_local!( pub static before_6: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (2,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracker::constructor_1(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -136,10 +134,10 @@ thread_local!( thread_local!( pub static after_7: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracker::constructor_1( __v.as_pointer(), - ((({ local_static_during_global_init_4() }).with(|__s| __s.tag) + 1),), + (({ local_static_during_global_init_4() }).with(|__s| __s.tag) + 1), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); @@ -153,8 +151,8 @@ thread_local!( pub static holder_8: Value = { let __static = Rc::new(RefCell::new(HoldsTracker { member: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (5,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracker::constructor_1(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); @@ -187,8 +185,8 @@ pub struct p3_reverse_completion_order_WithStaticMember {} thread_local!( pub static member_10: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (7,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracker::constructor_1(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -202,8 +200,9 @@ thread_local!( let __static = Rc::new(RefCell::new(lambda!( { let captured: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (8,)); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracker::constructor_1(__v.as_pointer(), 8); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -234,8 +233,8 @@ pub fn test_14() { thread_local!( static during_init_5: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (3,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracker::constructor_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -247,8 +246,8 @@ thread_local!( thread_local!( static during_main_13: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (9,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracker::constructor_1(__v.as_pointer(), 9); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs b/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs index 2ab3f28c96..2df941538d 100644 --- a/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs +++ b/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs @@ -19,13 +19,13 @@ use std::rc::Rc; )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] -#[constructor(explicit, value(i32))] +#[conversions(copy, move)] +#[constructor(constructor_1, explicit, value(i32))] pub struct Tracker { pub tag: i32, } -impl ConstructibleFromUnsafe<(i32,)> for Tracker { - unsafe fn constructor(this: *mut Self, (mut tag,): (i32,)) { +impl Tracker { + pub unsafe fn constructor_1(this: *mut Self, mut tag: i32) { (&raw mut (*this).tag).write(tag); (unsafe { libc::printf(c"construct %d\n".as_ptr() as *const libc::c_char, (tag)) }); } @@ -43,8 +43,8 @@ impl DestructibleUnsafe for Tracker { pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: Tracker = ::zero_init(); - >::constructor(&raw mut __v, (1,)); + let mut __v: Tracker = ZeroInitializationUnsafe::zero_init(); + Tracker::constructor_1(&raw mut __v, 1); __v }; libcc2rs::register_static_destructor(|| { @@ -60,14 +60,14 @@ pub unsafe fn exit_from_nested_call_1() { ((*std::cell::LazyCell::force_mut(&mut *&raw mut local_static_2)).tag), ) }); - object_unsafe!(automatic, Tracker, (i32,), (3,)); + object_unsafe!(automatic, Tracker::constructor_1(3)); libcc2rs::cpp2rust_exit(0); } static mut local_static_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: Tracker = ::zero_init(); - >::constructor(&raw mut __v, (2,)); + let mut __v: Tracker = ZeroInitializationUnsafe::zero_init(); + Tracker::constructor_1(&raw mut __v, 2); __v }; libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs b/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs index 76acce305f..4ffc3e394c 100644 --- a/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs +++ b/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs @@ -19,21 +19,19 @@ use std::rc::Rc; )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] -#[constructor(explicit, value(i32))] +#[conversions(copy, move)] +#[constructor(constructor_1, explicit, value(i32))] pub struct Tracker { pub tag: i32, } impl Tracker { - pub unsafe fn touch(this: *const Self) { - (unsafe { libc::printf(c"touch %d\n".as_ptr() as *const libc::c_char, ((*this).tag)) }); - } -} -impl ConstructibleFromUnsafe<(i32,)> for Tracker { - unsafe fn constructor(this: *mut Self, (mut tag,): (i32,)) { + pub unsafe fn constructor_1(this: *mut Self, mut tag: i32) { (&raw mut (*this).tag).write(tag); (unsafe { libc::printf(c"construct %d\n".as_ptr() as *const libc::c_char, (tag)) }); } + pub unsafe fn touch(this: *const Self) { + (unsafe { libc::printf(c"touch %d\n".as_ptr() as *const libc::c_char, ((*this).tag)) }); + } } impl DestructibleUnsafe for Tracker { unsafe fn destroy(this: *mut Self) { @@ -83,8 +81,8 @@ pub struct TriviallyDestructible { pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: Tracker = ::zero_init(); - >::constructor(&raw mut __v, (1,)); + let mut __v: Tracker = ZeroInitializationUnsafe::zero_init(); + Tracker::constructor_1(&raw mut __v, 1); __v }; libcc2rs::register_static_destructor(|| { @@ -109,8 +107,8 @@ static mut never_constructed_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: Tracker = ::zero_init(); - >::constructor(&raw mut __v, (100,)); + let mut __v: Tracker = ZeroInitializationUnsafe::zero_init(); + Tracker::constructor_1(&raw mut __v, 100); __v }; libcc2rs::register_static_destructor(|| { @@ -127,8 +125,8 @@ pub unsafe fn local_static_during_global_init_4() -> *const Tracker { pub static mut before_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: Tracker = ::zero_init(); - >::constructor(&raw mut __v, (2,)); + let mut __v: Tracker = ZeroInitializationUnsafe::zero_init(); + Tracker::constructor_1(&raw mut __v, 2); __v }; libcc2rs::register_static_destructor(|| { @@ -140,10 +138,10 @@ pub static mut before_6: std::cell::LazyCell = std::cell::LazyCell::new pub static mut after_7: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: Tracker = ::zero_init(); - >::constructor( + let mut __v: Tracker = ZeroInitializationUnsafe::zero_init(); + Tracker::constructor_1( &raw mut __v, - ((((*(unsafe { local_static_during_global_init_4() })).tag) + (1)),), + (((*(unsafe { local_static_during_global_init_4() })).tag) + (1)), ); __v }; @@ -157,8 +155,8 @@ pub static mut holder_8: std::cell::LazyCell = std::cell::LazyCell { let __static = HoldsTracker { member: { - let mut __v: Tracker = ::zero_init(); - >::constructor(&raw mut __v, (5,)); + let mut __v: Tracker = ZeroInitializationUnsafe::zero_init(); + Tracker::constructor_1(&raw mut __v, 5); __v }, }; @@ -187,8 +185,8 @@ pub struct p3_reverse_completion_order_WithStaticMember {} pub static mut member_10: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: Tracker = ::zero_init(); - >::constructor(&raw mut __v, (7,)); + let mut __v: Tracker = ZeroInitializationUnsafe::zero_init(); + Tracker::constructor_1(&raw mut __v, 7); __v }; libcc2rs::register_static_destructor(|| { @@ -203,11 +201,8 @@ pub static mut capturing_11: std::cell::LazyCell i32>> = let __static = lambda_unsafe!( { let captured: Tracker = { - let mut __v: Tracker = ::zero_init(); - >::constructor( - &raw mut __v, - (8,), - ); + let mut __v: Tracker = ZeroInitializationUnsafe::zero_init(); + Tracker::constructor_1(&raw mut __v, 8); __v }; }, @@ -251,8 +246,8 @@ pub unsafe fn test_14() { static mut during_init_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: Tracker = ::zero_init(); - >::constructor(&raw mut __v, (3,)); + let mut __v: Tracker = ZeroInitializationUnsafe::zero_init(); + Tracker::constructor_1(&raw mut __v, 3); __v }; libcc2rs::register_static_destructor(|| { @@ -266,8 +261,8 @@ static mut during_init_5: std::cell::LazyCell = std::cell::LazyCell::ne static mut during_main_13: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: Tracker = ::zero_init(); - >::constructor(&raw mut __v, (9,)); + let mut __v: Tracker = ZeroInitializationUnsafe::zero_init(); + Tracker::constructor_1(&raw mut __v, 9); __v }; libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index 906c1f2b60..827c40ca97 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -23,8 +23,8 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move)] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct HasConstexprCtor { #[offset(0)] @@ -34,22 +34,15 @@ impl HasConstexprCtor { pub fn reset() { copyCount_0.with(|rc| *rc.borrow_mut() = 0); } -} -impl ConstructibleFrom<(i32,)> for HasConstexprCtor { - fn constructor(this: Ptr, (mut v,): (i32,)) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, m).write(v); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for HasConstexprCtor { - fn constructor(this: Ptr, (o,): (LvalueRef>,)) { + pub fn constructor_2(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(); } } -impl CopyConstructible for HasConstexprCtor {} -impl ConvertibleTo for LvalueRef> {} thread_local!( pub static ctorCount_1: Value = Rc::new(RefCell::new(0)); ); @@ -74,7 +67,7 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -99,28 +92,22 @@ 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 ConstructibleFrom<()> for LifetimeTracked { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, uses).write(0); (*ctorCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl ConstructibleFrom<(LvalueRef>,)> for LifetimeTracked { - fn constructor(this: Ptr, (_a0,): (LvalueRef>,)) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + } } -impl CopyConstructible for LifetimeTracked {} -impl ConvertibleTo for LvalueRef> {} impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { (*dtorCount_3.with(Value::clone).borrow_mut()).prefix_inc(); @@ -131,14 +118,14 @@ pub fn test_5() { let mut arr: [HasConstexprCtor; 2] = [ { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (3,)); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (4,)); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]; @@ -148,20 +135,14 @@ pub fn test_5() { return [ { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >::constructor( - __v.as_pointer(), - (3,), - ); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >::constructor( - __v.as_pointer(), - (4,), - ); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ][(1) as usize] @@ -174,18 +155,15 @@ pub fn test_5() { } pub fn test_6() { ({ HasConstexprCtor::reset() }); - object!(k, HasConstexprCtor, (i32,), (5,)); + object!(k, HasConstexprCtor::constructor_1(5)); let f: Value i32>> = Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { { return { { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >::constructor( - __v.as_pointer(), - (5,), - ); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() } .m @@ -198,8 +176,8 @@ pub fn test_6() { } pub fn test_7() { ({ HasConstexprCtor::reset() }); - object!(k1, HasConstexprCtor, (i32,), (7,)); - object!(k2, HasConstexprCtor, (i32,), (9,)); + object!(k1, HasConstexprCtor::constructor_1(7)); + object!(k2, HasConstexprCtor::constructor_1(9)); let f: Value i32>> = Rc::new(RefCell::new(FnPtr:: i32>::new( |mut b: bool| -> i32 { { @@ -207,21 +185,15 @@ pub fn test_7() { (if b { { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >::constructor( - __v.as_pointer(), - (7,), - ); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } else { { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >::constructor( - __v.as_pointer(), - (9,), - ); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 9); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }) @@ -240,7 +212,7 @@ thread_local!( ); pub fn test_9() { ({ HasConstexprCtor::reset() }); - object!(k, HasConstexprCtor, (i32,), (5,)); + object!(k, HasConstexprCtor::constructor_1(5)); let f: Value i32>> = Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { { @@ -249,11 +221,8 @@ pub fn test_9() { (*left_8.with(Value::clone).borrow_mut()).prefix_inc(); { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >::constructor( - __v.as_pointer(), - (5,), - ); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -301,8 +270,9 @@ pub fn test_11() { thread_local!( pub static global_12: Value = { let __static = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -325,14 +295,14 @@ pub fn test_13() { } pub fn test_14() { ({ LifetimeTracked::reset() }); - object!(t, LifetimeTracked); + object!(t, LifetimeTracked::constructor_1()); let r: Ptr = t.as_pointer(); let f: Value> = Rc::new(RefCell::new(lambda!( { let r: Value = Rc::new(RefCell::new({ let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >,)>>::constructor(__v.as_pointer(), (LvalueRef::bind((r ).clone() ),)) ; + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_2(__v.as_pointer(), LvalueRef::bind((r).clone())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -363,20 +333,20 @@ pub fn test_15() { } pub fn test_16() { ({ HasConstexprCtor::reset() }); - object!(k, HasConstexprCtor, (i32,), (5,)); + object!(k, HasConstexprCtor::constructor_1(5)); let f: Value i32>> = Rc::new(RefCell::new(lambda!( { let k: Value = Rc::new(RefCell::new({ let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >,)>>::constructor(__v.as_pointer(), (LvalueRef::bind(k .as_pointer() ),)) ; + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_2(__v.as_pointer(), LvalueRef::bind(k.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, || -> i32 { object!( c, - HasConstexprCtor = >>::bind(k.as_pointer()) + HasConstexprCtor::constructor_2(LvalueRef::bind(k.as_pointer())) ); return { (*c.borrow()).m }; } @@ -412,8 +382,8 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move)] +#[constructor(constructor_1, value(i32))] #[byte_size(8)] pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { #[offset(0)] @@ -421,19 +391,14 @@ pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { #[offset(4)] pub scratch: i32, } -impl ConstructibleFrom<(i32,)> for p5_2_mutable_subobject_is_odr_used_HasMutableMember { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl p5_2_mutable_subobject_is_odr_used_HasMutableMember { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, value).write(v); field!(this, scratch).write(0); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> - for p5_2_mutable_subobject_is_odr_used_HasMutableMember -{ - fn constructor( + pub fn constructor_2( this: Ptr, - (o,): (LvalueRef>,), + o: LvalueRef>, ) { let o = o.as_pointer(); field!(this, value).write(o.with(|__s| __s.value)); @@ -441,30 +406,20 @@ impl ConstructibleFrom<(LvalueRef>,)> (*copies_18.with(Value::clone).borrow_mut()).prefix_inc(); } } -impl CopyConstructible for p5_2_mutable_subobject_is_odr_used_HasMutableMember {} -impl ConvertibleTo - for LvalueRef> -{ -} pub fn test_19() { object!( k, - p5_2_mutable_subobject_is_odr_used_HasMutableMember, - (i32,), - (5,) + p5_2_mutable_subobject_is_odr_used_HasMutableMember::constructor_1(5) ); let f: Value i32>> = Rc::new(RefCell::new(lambda!( { let k: Value = Rc::new(RefCell::new({ let __v: Value = - Rc::new(RefCell::new( - ::zero_init(), - )); - >, - )>>::constructor( - __v.as_pointer(), (LvalueRef::bind(k.as_pointer()),) + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p5_2_mutable_subobject_is_odr_used_HasMutableMember::constructor_2( + __v.as_pointer(), + LvalueRef::bind(k.as_pointer()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); @@ -480,7 +435,7 @@ pub fn test_19() { #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(8)] pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { #[offset(0)] @@ -492,10 +447,10 @@ pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { #[destroy] pub b: LifetimeTracked, } -impl ConstructibleFrom<()> for p6_unevaluated_binding_needs_no_capture_HasTwoMembers { - fn constructor(this: Ptr, _: ()) { - >::constructor(field_ptr!(this, a), ()); - >::constructor(field_ptr!(this, b), ()); +impl p6_unevaluated_binding_needs_no_capture_HasTwoMembers { + pub fn constructor_1(this: Ptr) { + LifetimeTracked::constructor_1(field_ptr!(this, a)); + LifetimeTracked::constructor_1(field_ptr!(this, b)); } } pub fn test_20() { @@ -504,14 +459,14 @@ pub fn test_20() { p6_unevaluated_binding_needs_no_capture_HasTwoMembers { a: { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, b: { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, }, @@ -533,7 +488,7 @@ pub fn test_20() { #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(8)] pub struct p7_member_access_captures_this_HasMemberUsedInLambda { #[offset(0)] @@ -556,16 +511,17 @@ impl p7_member_access_captures_this_HasMemberUsedInLambda { } ); } -} -impl ConstructibleFrom<()> for p7_member_access_captures_this_HasMemberUsedInLambda { - fn constructor(this: Ptr, _: ()) { - >::constructor(field_ptr!(this, x), ()); + pub fn constructor_1(this: Ptr) { + LifetimeTracked::constructor_1(field_ptr!(this, x)); field!(this, n).write(1); } } pub fn test_22() { ({ LifetimeTracked::reset() }); - object!(c, p7_member_access_captures_this_HasMemberUsedInLambda); + object!( + c, + p7_member_access_captures_this_HasMemberUsedInLambda::constructor_1() + ); let f: Value i32>> = Rc::new(RefCell::new( ({ p7_member_access_captures_this_HasMemberUsedInLambda::makeLambda(c.as_pointer()) }), )); @@ -580,7 +536,7 @@ pub fn test_22() { #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { #[offset(0)] @@ -596,17 +552,15 @@ impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { } }); } -} -impl ConstructibleFrom<()> for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { - fn constructor(this: Ptr, _: ()) { - >::constructor(field_ptr!(this, x), ()); + pub fn constructor_1(this: Ptr) { + LifetimeTracked::constructor_1(field_ptr!(this, x)); } } pub fn test_23() { ({ LifetimeTracked::reset() }); object!( c, - p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda + p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::constructor_1() ); let f: Value usize>> = Rc::new(RefCell::new( ({ p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::sizer(c.as_pointer()) }), @@ -651,11 +605,11 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(1)] pub struct p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} -impl ConstructibleFrom<()> for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { - fn constructor(this: Ptr, _: ()) { +impl p9_destructor_not_potentially_invoked_HasUndefinedDestructor { + pub fn constructor_1(this: Ptr) { (*t_ctors_27.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -663,7 +617,7 @@ pub fn test_28() { let mut p: Ptr = { let __p = Ptr::alloc(::zero_init()); - >::constructor(__p.clone(), ()) ; + p9_destructor_not_potentially_invoked_HasUndefinedDestructor::constructor_1(__p.clone()); __p }; assert!(!((p).is_null())); @@ -685,14 +639,14 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { #[offset(0)] pub value: i32, } -impl ConstructibleFrom<()> for p9_unused_copy_constructor_HasUndefinedCopyCtor { - fn constructor(this: Ptr, _: ()) { +impl p9_unused_copy_constructor_HasUndefinedCopyCtor { + pub fn constructor_1(this: Ptr) { field!(this, value).write(3); (*ctor_calls_29.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -701,10 +655,9 @@ impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { fn default() -> Self { { { - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - >::constructor(__v.as_pointer(), ()) ; + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p9_unused_copy_constructor_HasUndefinedCopyCtor::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -714,7 +667,10 @@ pub fn read_30(object: Ptr) -> return object.with(|__s| __s.value); } pub fn test_31() { - object!(a, p9_unused_copy_constructor_HasUndefinedCopyCtor); + object!( + a, + p9_unused_copy_constructor_HasUndefinedCopyCtor::constructor_1() + ); assert!((({ read_30(a.as_pointer(),) }) == 3)); assert!((ctor_calls_29.with(|rc| *rc.borrow()) == 1)); } @@ -734,11 +690,11 @@ thread_local!( Movable, Conversions, )] -#[conversions(copy)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(1)] pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} -impl ConstructibleFrom<()> for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - fn constructor(this: Ptr, _: ()) { +impl p9_unused_implicit_assignment_HasUndefinedCopyAssignment { + pub fn constructor_1(this: Ptr) { (*m_ctors_32.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -747,12 +703,10 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { { { let __v: Value = - Rc::new(RefCell::new( - ::zero_init(), - )); - >::constructor(__v.as_pointer(), ()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p9_unused_implicit_assignment_HasUndefinedCopyAssignment::constructor_1( + __v.as_pointer(), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -771,26 +725,28 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { Default, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(1)] pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { #[offset(0)] #[byte_size(1)] pub m: p9_unused_implicit_assignment_HasUndefinedCopyAssignment, } -impl ConstructibleFrom<()> for p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { - fn constructor(this: Ptr, _: ()) { - >::constructor(field_ptr!(this, m), ()) ; +impl p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { + pub fn constructor_1(this: Ptr) { + p9_unused_implicit_assignment_HasUndefinedCopyAssignment::constructor_1(field_ptr!( + this, m + )); } } pub fn test_33() { object!( a, - p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment + p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment::constructor_1() ); object!( b, - p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment + p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment::constructor_1() ); assert!((m_ctors_32.with(|rc| *rc.borrow()) == 2)); } @@ -915,24 +871,11 @@ fn main_0() -> i32 { ({ test_51() }); return 0; } -#[derive(Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg)] +#[derive( + Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg, ZeroInitialization, Destructible, Conversions, +)] #[byte_size(1)] pub struct p13_pointer_to_incomplete_class_X; -impl libcc2rs::overload::Conversions for p13_pointer_to_incomplete_class_X { - fn table() -> libcc2rs::overload::Table { - libcc2rs::overload::Table { - id: ::std::any::TypeId::of::(), - name: "p13_pointer_to_incomplete_class_X", - arithmetic: None, - storage: || Ptr::alloc(p13_pointer_to_incomplete_class_X).to_any(), - release: |ptr| ptr.downcast::().delete(), - copy: |_, _| {}, - move_from: |_, _| {}, - constructors: vec![], - conversion_functions: vec![], - } - } -} impl Destructible for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { fn destroy(this: Ptr) { unreachable!( @@ -940,9 +883,7 @@ impl Destructible for p9_destructor_not_potentially_invoked_HasUndefinedDestruct ) } } -impl ConstructibleFrom<(LvalueRef>,)> - for p9_unused_copy_constructor_HasUndefinedCopyCtor -{ +impl Constructor<(LvalueRef>,)> for p9_unused_copy_constructor_HasUndefinedCopyCtor { fn constructor(this: Ptr, _: (LvalueRef>,)) { unreachable!( "p9_unused_copy_constructor_HasUndefinedCopyCtor::copy_constructor 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 34a08ec4dd..b8d694b9ae 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -20,8 +20,8 @@ pub static mut copyCount_0: std::cell::LazyCell = std::cell::LazyCell::new( )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move)] +#[constructor(constructor_1, value(i32))] pub struct HasConstexprCtor { pub m: i32, } @@ -29,22 +29,15 @@ impl HasConstexprCtor { pub unsafe fn reset() { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) = 0; } -} -impl ConstructibleFromUnsafe<(i32,)> for HasConstexprCtor { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).m).write(v); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for HasConstexprCtor { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const HasConstexprCtor); (&raw mut (*this).m).write((*o).m); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)).prefix_inc(); } } -impl CopyConstructibleUnsafe for HasConstexprCtor {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} pub static mut ctorCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut copyCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut dtorCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); @@ -60,7 +53,7 @@ pub static mut useCount_4: std::cell::LazyCell = std::cell::LazyCell::new(| )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] pub struct LifetimeTracked { pub uses: i32, } @@ -77,26 +70,20 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) }; } - 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 ConstructibleFromUnsafe<()> for LifetimeTracked { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_1)).prefix_inc(); } -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for LifetimeTracked { - unsafe fn constructor(this: *mut Self, (_a0,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)).prefix_inc(); } + 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 CopyConstructibleUnsafe for LifetimeTracked {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_3)).prefix_inc(); @@ -106,13 +93,13 @@ pub unsafe fn test_5() { (unsafe { HasConstexprCtor::reset() }); let arr: [HasConstexprCtor; 2] = [ { - let mut __v: HasConstexprCtor = ::zero_init(); - >::constructor(&raw mut __v, (3,)); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 3); __v }, { - let mut __v: HasConstexprCtor = ::zero_init(); - >::constructor(&raw mut __v, (4,)); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 4); __v }, ]; @@ -120,19 +107,13 @@ pub unsafe fn test_5() { unsafe { return [ { - let mut __v: HasConstexprCtor = ::zero_init(); - >::constructor( - &raw mut __v, - (3,), - ); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 3); __v }, { - let mut __v: HasConstexprCtor = ::zero_init(); - >::constructor( - &raw mut __v, - (4,), - ); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 4); __v }, ][(1) as usize] @@ -145,15 +126,12 @@ pub unsafe fn test_5() { } pub unsafe fn test_6() { (unsafe { HasConstexprCtor::reset() }); - object_unsafe!(k, HasConstexprCtor, (i32,), (5,)); + object_unsafe!(k, HasConstexprCtor::constructor_1(5)); let mut f: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { unsafe { return { - let mut __v: HasConstexprCtor = ::zero_init(); - >::constructor( - &raw mut __v, - (5,), - ); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 5); __v } .m; @@ -165,26 +143,20 @@ pub unsafe fn test_6() { } pub unsafe fn test_7() { (unsafe { HasConstexprCtor::reset() }); - object_unsafe!(k1, HasConstexprCtor, (i32,), (7,)); - object_unsafe!(k2, HasConstexprCtor, (i32,), (9,)); + object_unsafe!(k1, HasConstexprCtor::constructor_1(7)); + object_unsafe!(k2, HasConstexprCtor::constructor_1(9)); let mut f: FnPtr i32> = FnPtr:: i32>::new(|mut b: bool| -> i32 { unsafe { return (if b { { - let mut __v: HasConstexprCtor = ::zero_init(); - >::constructor( - &raw mut __v, - (7,), - ); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 7); __v } } else { { - let mut __v: HasConstexprCtor = ::zero_init(); - >::constructor( - &raw mut __v, - (9,), - ); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 9); __v } }) @@ -199,17 +171,14 @@ pub unsafe fn test_7() { pub static mut left_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); pub unsafe fn test_9() { (unsafe { HasConstexprCtor::reset() }); - object_unsafe!(k, HasConstexprCtor, (i32,), (5,)); + object_unsafe!(k, HasConstexprCtor::constructor_1(5)); let mut f: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { unsafe { return { (*std::cell::LazyCell::force_mut(&mut *&raw mut left_8)).prefix_inc(); { - let mut __v: HasConstexprCtor = ::zero_init(); - >::constructor( - &raw mut __v, - (5,), - ); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 5); __v } } @@ -253,8 +222,8 @@ pub static mut global_12: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -283,15 +252,13 @@ pub unsafe fn test_13() { } pub unsafe fn test_14() { (unsafe { LifetimeTracked::reset() }); - object_unsafe!(t, LifetimeTracked); + object_unsafe!(t, LifetimeTracked::constructor_1()); let r: *mut LifetimeTracked = &mut t; let mut f: FnPtr = lambda_unsafe!( { let r: LifetimeTracked = { - let mut __v: LifetimeTracked = ::zero_init(); - >, - )>>::constructor(&raw mut __v, (LvalueRefUnsafe::bind(r),)); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(r)); __v }; }, @@ -323,21 +290,19 @@ pub unsafe fn test_15() { } pub unsafe fn test_16() { (unsafe { HasConstexprCtor::reset() }); - object_unsafe!(k, HasConstexprCtor, (i32,), (5,)); + object_unsafe!(k, HasConstexprCtor::constructor_1(5)); let mut f: FnPtr i32> = lambda_unsafe!( { let k: HasConstexprCtor = { - let mut __v: HasConstexprCtor = ::zero_init(); - >, - )>>::constructor(&raw mut __v, (LvalueRefUnsafe::bind(&k),)); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(&k)); __v }; }, || -> i32 { object_unsafe!( c, - HasConstexprCtor = >>::bind(&k) + HasConstexprCtor::constructor_2(LvalueRefUnsafe::bind(&k)) ); return c.m; } @@ -369,25 +334,20 @@ pub static mut copies_18: std::cell::LazyCell = std::cell::LazyCell::new(|| )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move)] +#[constructor(constructor_1, value(i32))] pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { pub value: i32, pub scratch: i32, } -impl ConstructibleFromUnsafe<(i32,)> for p5_2_mutable_subobject_is_odr_used_HasMutableMember { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl p5_2_mutable_subobject_is_odr_used_HasMutableMember { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).value).write(v); (&raw mut (*this).scratch).write(0); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> - for p5_2_mutable_subobject_is_odr_used_HasMutableMember -{ - unsafe fn constructor( + pub unsafe fn constructor_2( this: *mut Self, - (o,): (LvalueRefUnsafe>,), + o: LvalueRefUnsafe>, ) { let o = (o.as_ptr() as *const p5_2_mutable_subobject_is_odr_used_HasMutableMember); (&raw mut (*this).value).write((*o).value); @@ -395,26 +355,20 @@ impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_18)).prefix_inc(); } } -impl CopyConstructibleUnsafe for p5_2_mutable_subobject_is_odr_used_HasMutableMember {} -impl ConvertibleToUnsafe - for LvalueRefUnsafe> -{ -} pub unsafe fn test_19() { object_unsafe!( k, - p5_2_mutable_subobject_is_odr_used_HasMutableMember, - (i32,), - (5,) + p5_2_mutable_subobject_is_odr_used_HasMutableMember::constructor_1(5) ); let mut f: FnPtr i32> = lambda_unsafe!( { let k: p5_2_mutable_subobject_is_odr_used_HasMutableMember = { let mut __v: p5_2_mutable_subobject_is_odr_used_HasMutableMember = - ::zero_init(); - >,), - >>::constructor(&raw mut __v, (LvalueRefUnsafe::bind(&k),)); + ZeroInitializationUnsafe::zero_init(); + p5_2_mutable_subobject_is_odr_used_HasMutableMember::constructor_2( + &raw mut __v, + LvalueRefUnsafe::bind(&k), + ); __v }; }, @@ -432,17 +386,17 @@ pub unsafe fn test_19() { )] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { #[destroy] pub a: LifetimeTracked, #[destroy] pub b: LifetimeTracked, } -impl ConstructibleFromUnsafe<()> for p6_unevaluated_binding_needs_no_capture_HasTwoMembers { - unsafe fn constructor(this: *mut Self, _: ()) { - >::constructor(&raw mut (*this).a, ()); - >::constructor(&raw mut (*this).b, ()); +impl p6_unevaluated_binding_needs_no_capture_HasTwoMembers { + pub unsafe fn constructor_1(this: *mut Self) { + LifetimeTracked::constructor_1(&raw mut (*this).a); + LifetimeTracked::constructor_1(&raw mut (*this).b); } } pub unsafe fn test_20() { @@ -450,13 +404,13 @@ pub unsafe fn test_20() { let mut p: p6_unevaluated_binding_needs_no_capture_HasTwoMembers = p6_unevaluated_binding_needs_no_capture_HasTwoMembers { a: { - let mut __v: LifetimeTracked = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }, b: { - let mut __v: LifetimeTracked = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }, }; @@ -480,7 +434,7 @@ pub unsafe fn test_20() { )] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct p7_member_access_captures_this_HasMemberUsedInLambda { #[destroy] pub x: LifetimeTracked, @@ -498,16 +452,17 @@ impl p7_member_access_captures_this_HasMemberUsedInLambda { } ); } -} -impl ConstructibleFromUnsafe<()> for p7_member_access_captures_this_HasMemberUsedInLambda { - unsafe fn constructor(this: *mut Self, _: ()) { - >::constructor(&raw mut (*this).x, ()); + pub unsafe fn constructor_1(this: *mut Self) { + LifetimeTracked::constructor_1(&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); + object_unsafe!( + c, + p7_member_access_captures_this_HasMemberUsedInLambda::constructor_1() + ); let mut f: FnPtr i32> = (unsafe { p7_member_access_captures_this_HasMemberUsedInLambda::makeLambda(&raw mut c) }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (0))); @@ -524,7 +479,7 @@ pub unsafe fn test_22() { )] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { #[destroy] pub x: LifetimeTracked, @@ -537,17 +492,15 @@ impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { } }); } -} -impl ConstructibleFromUnsafe<()> for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { - unsafe fn constructor(this: *mut Self, _: ()) { - >::constructor(&raw mut (*this).x, ()); + pub unsafe fn constructor_1(this: *mut Self) { + LifetimeTracked::constructor_1(&raw mut (*this).x); } } pub unsafe fn test_23() { (unsafe { LifetimeTracked::reset() }); object_unsafe!( c, - p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda + p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::constructor_1() ); let mut f: FnPtr usize> = (unsafe { p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::sizer(&raw mut c) }); @@ -589,10 +542,10 @@ pub static mut t_ctors_27: std::cell::LazyCell = std::cell::LazyCell::new(| )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy, move, default = constructor_1)] pub struct p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} -impl ConstructibleFromUnsafe<()> for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { - unsafe fn constructor(this: *mut Self, _: ()) { +impl p9_destructor_not_potentially_invoked_HasUndefinedDestructor { + pub unsafe fn constructor_1(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut t_ctors_27)).prefix_inc(); } } @@ -601,9 +554,7 @@ pub unsafe fn test_28() { let __p: *mut p9_destructor_not_potentially_invoked_HasUndefinedDestructor = Box::leak( Box::new(::zero_init()), ); - >::constructor(__p, ()); + p9_destructor_not_potentially_invoked_HasUndefinedDestructor::constructor_1(__p); __p }; assert!(!((p).is_null())); @@ -623,12 +574,12 @@ pub static mut ctor_calls_29: std::cell::LazyCell = )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy, move, default = constructor_1)] pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { pub value: i32, } -impl ConstructibleFromUnsafe<()> for p9_unused_copy_constructor_HasUndefinedCopyCtor { - unsafe fn constructor(this: *mut Self, _: ()) { +impl p9_unused_copy_constructor_HasUndefinedCopyCtor { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).value).write(3); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctor_calls_29)).prefix_inc(); } @@ -638,8 +589,8 @@ impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { unsafe { { let mut __v: p9_unused_copy_constructor_HasUndefinedCopyCtor = - ::zero_init(); - >::constructor(&raw mut __v, ()) ; + ZeroInitializationUnsafe::zero_init(); + p9_unused_copy_constructor_HasUndefinedCopyCtor::constructor_1(&raw mut __v); __v } } @@ -649,7 +600,10 @@ pub unsafe fn read_30(object: *const p9_unused_copy_constructor_HasUndefinedCopy return (*object).value; } pub unsafe fn test_31() { - object_unsafe!(a, p9_unused_copy_constructor_HasUndefinedCopyCtor); + object_unsafe!( + a, + p9_unused_copy_constructor_HasUndefinedCopyCtor::constructor_1() + ); assert!(((unsafe { read_30(&a,) }) == (3))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctor_calls_29)) == (1))); } @@ -666,10 +620,10 @@ pub static mut m_ctors_32: std::cell::LazyCell = std::cell::LazyCell::new(| MovableUnsafe, ConversionsUnsafe, )] -#[conversions(copy)] +#[conversions(copy, move, default = constructor_1)] pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} -impl ConstructibleFromUnsafe<()> for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - unsafe fn constructor(this: *mut Self, _: ()) { +impl p9_unused_implicit_assignment_HasUndefinedCopyAssignment { + pub unsafe fn constructor_1(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut m_ctors_32)).prefix_inc(); } } @@ -678,8 +632,10 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { unsafe { { let mut __v: p9_unused_implicit_assignment_HasUndefinedCopyAssignment = - ::zero_init(); - >::constructor(&raw mut __v, ()) ; + ZeroInitializationUnsafe::zero_init(); + p9_unused_implicit_assignment_HasUndefinedCopyAssignment::constructor_1( + &raw mut __v, + ); __v } } @@ -697,25 +653,23 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { Default, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { pub m: p9_unused_implicit_assignment_HasUndefinedCopyAssignment, } -impl ConstructibleFromUnsafe<()> - for p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment -{ - unsafe fn constructor(this: *mut Self, _: ()) { - >::constructor(&raw mut (*this).m, ()) ; +impl p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { + pub unsafe fn constructor_1(this: *mut Self) { + p9_unused_implicit_assignment_HasUndefinedCopyAssignment::constructor_1(&raw mut (*this).m); } } pub unsafe fn test_33() { object_unsafe!( a, - p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment + p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment::constructor_1() ); object_unsafe!( b, - p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment + p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment::constructor_1() ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut m_ctors_32)) == (2))); } @@ -828,25 +782,17 @@ unsafe fn main_0() -> i32 { (unsafe { test_51() }); return 0; } -#[derive(Clone, Copy, Default, VaArg, FnPtrArg)] +#[derive( + Clone, + Copy, + Default, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + ConversionsUnsafe, +)] pub struct p13_pointer_to_incomplete_class_X; -impl libcc2rs::overload::ConversionsUnsafe for p13_pointer_to_incomplete_class_X { - fn table() -> libcc2rs::overload::Table<*mut ::std::ffi::c_void> { - libcc2rs::overload::Table { - id: ::std::any::TypeId::of::(), - name: "p13_pointer_to_incomplete_class_X", - arithmetic: None, - storage: || Box::into_raw(Box::new(p13_pointer_to_incomplete_class_X)).cast(), - release: |ptr| { - drop(unsafe { Box::from_raw(ptr.cast::()) }) - }, - copy: |_, _| {}, - move_from: |_, _| {}, - constructors: vec![], - conversion_functions: vec![], - } - } -} impl DestructibleUnsafe for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { unsafe fn destroy(this: *mut Self) { unreachable!( @@ -854,7 +800,7 @@ impl DestructibleUnsafe for p9_destructor_not_potentially_invoked_HasUndefinedDe ) } } -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> +impl ConstructorUnsafe<(LvalueRefUnsafe>,)> for p9_unused_copy_constructor_HasUndefinedCopyCtor { unsafe fn constructor(this: *mut Self, _: (LvalueRefUnsafe>,)) { diff --git a/tests/std/class/class.init/out/refcount/class.base.init.rs b/tests/std/class/class.init/out/refcount/class.base.init.rs index ab8cb65d3a..6ed19b9af1 100644 --- a/tests/std/class/class.init/out/refcount/class.base.init.rs +++ b/tests/std/class/class.init/out/refcount/class.base.init.rs @@ -20,7 +20,7 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] #[byte_size(8)] pub struct p13_3_member_reads_earlier_member_Pair { #[offset(0)] @@ -28,15 +28,17 @@ pub struct p13_3_member_reads_earlier_member_Pair { #[offset(4)] pub second: i32, } -impl ConstructibleFrom<(i32,)> for p13_3_member_reads_earlier_member_Pair { - fn constructor(this: Ptr, (mut first,): (i32,)) { +impl p13_3_member_reads_earlier_member_Pair { + pub fn constructor_1(this: Ptr, mut first: i32) { field!(this, first).write(first); field!(this, second).write((this.with(|__s| __s.first) + 1)); } } -impl ConvertibleTo for i32 {} pub fn test_0() { - object!(pair, p13_3_member_reads_earlier_member_Pair, (i32,), (5,)); + object!( + pair, + p13_3_member_reads_earlier_member_Pair::constructor_1(5) + ); assert!(({ (*pair.borrow()).first } == 5)); assert!(({ (*pair.borrow()).second } == 6)); } diff --git a/tests/std/class/class.init/out/unsafe/class.base.init.rs b/tests/std/class/class.init/out/unsafe/class.base.init.rs index 3b3953e4b6..758ac01387 100644 --- a/tests/std/class/class.init/out/unsafe/class.base.init.rs +++ b/tests/std/class/class.init/out/unsafe/class.base.init.rs @@ -19,20 +19,22 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] pub struct p13_3_member_reads_earlier_member_Pair { pub first: i32, pub second: i32, } -impl ConstructibleFromUnsafe<(i32,)> for p13_3_member_reads_earlier_member_Pair { - unsafe fn constructor(this: *mut Self, (mut first,): (i32,)) { +impl p13_3_member_reads_earlier_member_Pair { + pub unsafe fn constructor_1(this: *mut Self, mut first: i32) { (&raw mut (*this).first).write(first); (&raw mut (*this).second).write((((*this).first) + (1))); } } -impl ConvertibleToUnsafe for i32 {} pub unsafe fn test_0() { - object_unsafe!(pair, p13_3_member_reads_earlier_member_Pair, (i32,), (5,)); + object_unsafe!( + pair, + p13_3_member_reads_earlier_member_Pair::constructor_1(5) + ); assert!(((pair.first) == (5))); assert!(((pair.second) == (6))); } diff --git a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs index eabfe04ffd..685f08d2dd 100644 --- a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs +++ b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs @@ -6,21 +6,15 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -impl ConstructibleFrom<(LvalueRef,)> - for p1_template_constructor_from_own_type_Probe -{ - fn constructor( +impl p1_template_constructor_from_own_type_Probe { + pub fn constructor_2_1( this: Ptr, - (u,): (LvalueRef,), + u: LvalueRef, ) { let u = u.as_pointer(); field!(this, value).write((u.with(|__s| __s.value) + 1)); } } -impl ConvertibleTo - for LvalueRef -{ -} #[derive( Copy, Clone, @@ -35,31 +29,31 @@ impl ConvertibleTo Conversions, )] #[conversions(copy, move)] -#[constructor(value(i32))] -#[constructor(lvalue_ref(p1_template_constructor_from_own_type_Probe))] +#[constructor(constructor_1, value(i32))] +#[constructor( + constructor_2_1, + lvalue_ref(p1_template_constructor_from_own_type_Probe) +)] #[byte_size(4)] pub struct p1_template_constructor_from_own_type_Probe { #[offset(0)] pub value: i32, } -impl ConstructibleFrom<(i32,)> for p1_template_constructor_from_own_type_Probe { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl p1_template_constructor_from_own_type_Probe { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, value).write(v); } } -impl ConvertibleTo for i32 {} pub fn test_0() { object!( probe, - p1_template_constructor_from_own_type_Probe, - (i32,), - (22,) + p1_template_constructor_from_own_type_Probe::constructor_1(22) ); object!( converted, - p1_template_constructor_from_own_type_Probe, - (LvalueRef,), - (LvalueRef::bind(probe.as_pointer()),) + p1_template_constructor_from_own_type_Probe::constructor_2_1(LvalueRef::bind( + probe.as_pointer() + )) ); assert!(({ (*converted.borrow()).value } == 23)); } @@ -77,24 +71,22 @@ pub fn test_0() { Conversions, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct p1_implicit_conversion_by_constructor_Meters { #[offset(0)] pub value: i32, } -impl ConstructibleFrom<(i32,)> for p1_implicit_conversion_by_constructor_Meters { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl p1_implicit_conversion_by_constructor_Meters { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, value).write(v); } } -impl ConvertibleTo for i32 {} pub fn test_1() { let mut m: p1_implicit_conversion_by_constructor_Meters = { - let __v: Value = Rc::new(RefCell::new( - ::zero_init(), - )); - ConvertibleTo::convert(5, __v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p1_implicit_conversion_by_constructor_Meters::constructor_1(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((m.value == 5)); @@ -109,18 +101,18 @@ pub fn test_1() { object!( __first, p1_implicit_conversion_by_constructor_Meters, - |__this| Conversions::construct( + |__this| ConstructibleFrom::construct( __this, - &[overload::Arg::const_lvalue( + (LvalueRef::>::bind( (*source.borrow()).0.as_pointer() - )] + ),) ) ); - object!(__second, i64, |__this| Conversions::construct( + object!(__second, i64, |__this| ConstructibleFrom::construct( __this, - &[overload::Arg::const_lvalue( + (LvalueRef::>::bind( (*source.borrow()).1.as_pointer() - )] + ),) )); ( Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), @@ -147,18 +139,18 @@ pub fn test_1() { object!( __first, p1_implicit_conversion_by_constructor_Meters, - |__this| Conversions::construct( + |__this| ConstructibleFrom::construct( __this, - &[overload::Arg::rvalue( + (RvalueRef::::bind( (*__tmp_0.upgrade().deref()).0.as_pointer() - )] + ),) ) ); - object!(__second, i64, |__this| Conversions::construct( + object!(__second, i64, |__this| ConstructibleFrom::construct( __this, - &[overload::Arg::rvalue( + (RvalueRef::::bind( (*__tmp_0.upgrade().deref()).1.as_pointer() - )] + ),) )); ( Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), @@ -188,27 +180,24 @@ pub fn test_1() { Conversions, )] #[conversions(copy, move)] -#[constructor(explicit, value(i32))] +#[constructor(constructor_1, explicit, value(i32))] #[byte_size(4)] pub struct p2_explicit_constructor_Celsius { #[offset(0)] pub degrees: i32, } -impl ConstructibleFrom<(i32,)> for p2_explicit_constructor_Celsius { - fn constructor(this: Ptr, (mut d,): (i32,)) { +impl p2_explicit_constructor_Celsius { + pub fn constructor_1(this: Ptr, mut d: i32) { field!(this, degrees).write(d); } } pub fn test_2() { - object!(direct, p2_explicit_constructor_Celsius, (i32,), (3,)); + object!(direct, p2_explicit_constructor_Celsius::constructor_1(3)); assert!(({ (*direct.borrow()).degrees } == 3)); let mut cast: p2_explicit_constructor_Celsius = { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >::constructor( - __v.as_pointer(), - (4,), - ); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p2_explicit_constructor_Celsius::constructor_1(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((cast.degrees == 4)); @@ -222,18 +211,18 @@ pub fn test_2() { { (__tmp_1,) => { object!(__first, p2_explicit_constructor_Celsius, |__this| { - Conversions::construct( + ConstructibleFrom::construct( __this, - &[overload::Arg::rvalue( + (RvalueRef::::bind( (*__tmp_1.upgrade().deref()).0.as_pointer(), - )], + ),), ) }); - object!(__second, i32, |__this| Conversions::construct( + object!(__second, i32, |__this| ConstructibleFrom::construct( __this, - &[overload::Arg::rvalue( + (RvalueRef::::bind( (*__tmp_1.upgrade().deref()).1.as_pointer() - )] + ),) )); ( Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), @@ -264,6 +253,7 @@ pub fn test_2() { )] #[conversions(copy, move)] #[conversion_function( + conversion_function_1, p2_explicit_constructor_and_conversion_function_Target, const_lvalue_ref )] @@ -287,70 +277,53 @@ pub struct p2_explicit_constructor_and_conversion_function_Source { )] #[conversions(copy, move)] #[constructor( + constructor_1, explicit, const_lvalue_ref(p2_explicit_constructor_and_conversion_function_Source) )] -#[constructor(value(i32))] +#[constructor(constructor_2, value(i32))] #[byte_size(4)] pub struct p2_explicit_constructor_and_conversion_function_Target { #[offset(0)] pub from: i32, } -impl ConstructibleFrom<(LvalueRef>,)> - for p2_explicit_constructor_and_conversion_function_Target -{ - fn constructor( +impl p2_explicit_constructor_and_conversion_function_Target { + pub fn constructor_1( this: Ptr, - (_a0,): (LvalueRef>,), + _a0: LvalueRef>, ) { let _a0 = _a0.as_pointer(); field!(this, from).write(1); } -} -impl ConstructibleFrom<(i32,)> for p2_explicit_constructor_and_conversion_function_Target { - fn constructor(this: Ptr, (mut f,): (i32,)) { + pub fn constructor_2(this: Ptr, mut f: i32) { field!(this, from).write(f); } } -impl ConvertibleTo for i32 {} -impl - ConversionFunction< - p2_explicit_constructor_and_conversion_function_Target, - LvalueRef>, - > for p2_explicit_constructor_and_conversion_function_Source -{ - fn conversion_function( +impl p2_explicit_constructor_and_conversion_function_Source { + pub fn conversion_function_1( this: LvalueRef>, - to: Ptr, + __return: Ptr, ) { let this = this.as_pointer(); - >::constructor(to.clone(), (2 ,)) ; + p2_explicit_constructor_and_conversion_function_Target::constructor_2(__return.clone(), 2); return; } } -impl - ImplicitConversionFunction< - p2_explicit_constructor_and_conversion_function_Target, - LvalueRef>, - > for p2_explicit_constructor_and_conversion_function_Source -{ -} pub fn test_3() { let source: Value = Rc::new( RefCell::new(p2_explicit_constructor_and_conversion_function_Source { value: 0 }), ); object!( direct, - p2_explicit_constructor_and_conversion_function_Target, - (LvalueRef>,), - (LvalueRef::bind(source.as_pointer()),) + p2_explicit_constructor_and_conversion_function_Target::constructor_1(LvalueRef::bind( + source.as_pointer() + )) ); assert!(({ (*direct.borrow()).from } == 1)); let mut copied: p2_explicit_constructor_and_conversion_function_Target = { - let __v: Value = Rc::new( - RefCell::new(::default()), - ); - p2_explicit_constructor_and_conversion_function_Source::conversion_function( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p2_explicit_constructor_and_conversion_function_Source::conversion_function_1( >>::bind( source.as_pointer(), ), diff --git a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs index 89e19a8d64..69ff1eea77 100644 --- a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs +++ b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs @@ -20,33 +20,30 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[conversion_function(i64, lvalue_ref)] +#[conversion_function(conversion_function_1, i64, lvalue_ref)] #[byte_size(8)] pub struct p2_non_const_conversion_function_Gauge { #[offset(0)] pub value: i64, } -impl ConversionFunction> - for p2_non_const_conversion_function_Gauge -{ - fn conversion_function(this: LvalueRef, to: Ptr) { +impl p2_non_const_conversion_function_Gauge { + pub fn conversion_function_1( + this: LvalueRef, + __return: Ptr, + ) { let this = this.as_pointer(); - to.write(field!(this, value).with_mut(|__v| __v.prefix_inc().clone())); + __return.write(field!(this, value).with_mut(|__v| __v.prefix_inc().clone())); return; } } -impl ImplicitConversionFunction> - for p2_non_const_conversion_function_Gauge -{ -} pub fn test_0() { let gauge: Value = Rc::new(RefCell::new(p2_non_const_conversion_function_Gauge { value: 20_i64, })); let mut converted: i64 = { - let __v: Value = Rc::new(RefCell::new(0_i64)); - p2_non_const_conversion_function_Gauge::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p2_non_const_conversion_function_Gauge::conversion_function_1( >::bind(gauge.as_pointer()), Ptr::clone(&__v.as_pointer()), ); @@ -69,7 +66,7 @@ pub fn test_0() { Conversions, )] #[conversions(copy, move)] -#[conversion_function(i32, const_lvalue_ref)] +#[conversion_function(conversion_function_1, i32, const_lvalue_ref)] #[byte_size(8)] pub struct p2_implicit_conversion_function_Ratio { #[offset(0)] @@ -77,22 +74,16 @@ pub struct p2_implicit_conversion_function_Ratio { #[offset(4)] pub denominator: i32, } -impl ConversionFunction>> - for p2_implicit_conversion_function_Ratio -{ - fn conversion_function( +impl p2_implicit_conversion_function_Ratio { + pub fn conversion_function_1( this: LvalueRef>, - to: Ptr, + __return: Ptr, ) { let this = this.as_pointer(); - to.write((this.with(|__s| __s.numerator) / this.with(|__s| __s.denominator))); + __return.write((this.with(|__s| __s.numerator) / this.with(|__s| __s.denominator))); return; } } -impl ImplicitConversionFunction>> - for p2_implicit_conversion_function_Ratio -{ -} pub fn test_1() { let ratio: Value = Rc::new(RefCell::new(p2_implicit_conversion_function_Ratio { @@ -100,8 +91,8 @@ pub fn test_1() { denominator: 3, })); let mut value: i32 = { - let __v: Value = Rc::new(RefCell::new(0_i32)); - p2_implicit_conversion_function_Ratio::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p2_implicit_conversion_function_Ratio::conversion_function_1( >>::bind(ratio.as_pointer()), Ptr::clone(&__v.as_pointer()), ); @@ -126,17 +117,21 @@ pub fn test_1() { )), ))); let converted: Value<(Value, Value)> = Rc::new(RefCell::new({ - object!(__first, i32, |__this| Conversions::construct( + object!(__first, i32, |__this| ConstructibleFrom::construct( __this, - &[overload::Arg::const_lvalue( - (*source.borrow()).0.as_pointer() - )] + ( + LvalueRef::>::bind( + (*source.borrow()).0.as_pointer() + ), + ) )); - object!(__second, i64, |__this| Conversions::construct( + object!(__second, i64, |__this| ConstructibleFrom::construct( __this, - &[overload::Arg::const_lvalue( - (*source.borrow()).1.as_pointer() - )] + ( + LvalueRef::>::bind( + (*source.borrow()).1.as_pointer() + ), + ) )); ( Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), @@ -164,21 +159,19 @@ pub fn test_1() { Conversions, )] #[conversions(copy, move)] -#[conversion_function(bool, const_lvalue_ref, explicit)] +#[conversion_function(conversion_function_1, bool, const_lvalue_ref, explicit)] #[byte_size(4)] pub struct p2_explicit_conversion_function_Flag { #[offset(0)] pub value: i32, } -impl ConversionFunction>> - for p2_explicit_conversion_function_Flag -{ - fn conversion_function( +impl p2_explicit_conversion_function_Flag { + pub fn conversion_function_1( this: LvalueRef>, - to: Ptr, + __return: Ptr, ) { let this = this.as_pointer(); - to.write((this.with(|__s| __s.value) != 0)); + __return.write((this.with(|__s| __s.value) != 0)); return; } } @@ -192,8 +185,8 @@ pub fn test_2() { value: 0, })); assert!({ - let __v: Value = Rc::new(RefCell::new(false)); - p2_explicit_conversion_function_Flag::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p2_explicit_conversion_function_Flag::conversion_function_1( >>::bind(on.as_pointer()), Ptr::clone(&__v.as_pointer()), ); @@ -201,8 +194,8 @@ pub fn test_2() { }); assert!( !({ - let __v: Value = Rc::new(RefCell::new(false)); - p2_explicit_conversion_function_Flag::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p2_explicit_conversion_function_Flag::conversion_function_1( >>::bind(off.as_pointer()), Ptr::clone(&__v.as_pointer()), ); @@ -210,8 +203,8 @@ pub fn test_2() { }) ); let mut cast: bool = { - let __v: Value = Rc::new(RefCell::new(false)); - p2_explicit_conversion_function_Flag::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p2_explicit_conversion_function_Flag::conversion_function_1( >>::bind(on.as_pointer()), Ptr::clone(&__v.as_pointer()), ); @@ -238,33 +231,24 @@ pub struct p1_conversion_function_to_reference_Holder { #[offset(0)] pub value: i32, } -impl ConversionFunction, LvalueRef> - for p1_conversion_function_to_reference_Holder -{ - fn conversion_function( +impl p1_conversion_function_to_reference_Holder { + pub fn conversion_function_1( this: LvalueRef, - to: Ptr>, + __return: Ptr>, ) { let this = this.as_pointer(); - to.write(>::bind(field_ptr!(this, value))); + __return.write(>::bind(field_ptr!(this, value))); return; } } -impl - ImplicitConversionFunction< - LvalueRef, - LvalueRef, - > for p1_conversion_function_to_reference_Holder -{ -} pub fn test_3() { let holder: Value = Rc::new(RefCell::new(p1_conversion_function_to_reference_Holder { value: 1, })); let ref_: Ptr = { - let __v: Value> = Rc::new(RefCell::new(>::zero_init())); - p1_conversion_function_to_reference_Holder::conversion_function( + let __v: Value> = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p1_conversion_function_to_reference_Holder::conversion_function_1( >::bind(holder.as_pointer()), Ptr::clone(&__v.as_pointer()), ); diff --git a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs index 28ace77c0d..7eb340633f 100644 --- a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs +++ b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs @@ -6,21 +6,15 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -impl ConstructibleFromUnsafe<(LvalueRefUnsafe,)> - for p1_template_constructor_from_own_type_Probe -{ - unsafe fn constructor( +impl p1_template_constructor_from_own_type_Probe { + pub unsafe fn constructor_2_1( this: *mut Self, - (u,): (LvalueRefUnsafe,), + u: LvalueRefUnsafe, ) { let u = (u.as_ptr() as *mut p1_template_constructor_from_own_type_Probe); (&raw mut (*this).value).write((((*u).value) + (1))); } } -impl ConvertibleToUnsafe - for LvalueRefUnsafe -{ -} #[repr(C)] #[derive( Copy, @@ -34,29 +28,29 @@ impl ConvertibleToUnsafe ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(value(i32))] -#[constructor(lvalue_ref(p1_template_constructor_from_own_type_Probe))] +#[constructor(constructor_1, value(i32))] +#[constructor( + constructor_2_1, + lvalue_ref(p1_template_constructor_from_own_type_Probe) +)] pub struct p1_template_constructor_from_own_type_Probe { pub value: i32, } -impl ConstructibleFromUnsafe<(i32,)> for p1_template_constructor_from_own_type_Probe { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl p1_template_constructor_from_own_type_Probe { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).value).write(v); } } -impl ConvertibleToUnsafe for i32 {} pub unsafe fn test_0() { object_unsafe!( probe, - p1_template_constructor_from_own_type_Probe, - (i32,), - (22,) + p1_template_constructor_from_own_type_Probe::constructor_1(22) ); object_unsafe!( converted, - p1_template_constructor_from_own_type_Probe, - (LvalueRefUnsafe,), - (LvalueRefUnsafe::bind(&mut probe),) + p1_template_constructor_from_own_type_Probe::constructor_2_1(LvalueRefUnsafe::bind( + &mut probe + )) ); assert!(((converted.value) == (23))); } @@ -73,21 +67,20 @@ pub unsafe fn test_0() { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] pub struct p1_implicit_conversion_by_constructor_Meters { pub value: i32, } -impl ConstructibleFromUnsafe<(i32,)> for p1_implicit_conversion_by_constructor_Meters { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl p1_implicit_conversion_by_constructor_Meters { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).value).write(v); } } -impl ConvertibleToUnsafe for i32 {} pub unsafe fn test_1() { let mut m: p1_implicit_conversion_by_constructor_Meters = { let mut __v: p1_implicit_conversion_by_constructor_Meters = - ::zero_init(); - ConvertibleToUnsafe::convert(5, &raw mut __v); + ZeroInitializationUnsafe::zero_init(); + p1_implicit_conversion_by_constructor_Meters::constructor_1(&raw mut __v, 5); __v }; assert!(((m.value) == (5))); @@ -96,14 +89,14 @@ pub unsafe fn test_1() { object_unsafe!( __first, p1_implicit_conversion_by_constructor_Meters, - |__this| ConversionsUnsafe::construct( + |__this| ConstructibleFromUnsafe::construct( __this, - &[overload::Arg::const_lvalue_unsafe(&raw const source.0)] + (LvalueRefUnsafe::>::bind(&raw const source.0),) ) ); - object_unsafe!(__second, i64, |__this| ConversionsUnsafe::construct( + object_unsafe!(__second, i64, |__this| ConstructibleFromUnsafe::construct( __this, - &[overload::Arg::const_lvalue_unsafe(&raw const source.1)] + (LvalueRefUnsafe::>::bind(&raw const source.1),) )); ( move_constructed_unsafe(&raw mut __first), @@ -117,14 +110,14 @@ pub unsafe fn test_1() { object_unsafe!( __first, p1_implicit_conversion_by_constructor_Meters, - |__this| ConversionsUnsafe::construct( + |__this| ConstructibleFromUnsafe::construct( __this, - &[overload::Arg::rvalue_unsafe(&raw mut (*__tmp_0).0)] + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_0).0),) ) ); - object_unsafe!(__second, i64, |__this| ConversionsUnsafe::construct( + object_unsafe!(__second, i64, |__this| ConstructibleFromUnsafe::construct( __this, - &[overload::Arg::rvalue_unsafe(&raw mut (*__tmp_0).1)] + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_0).1),) )); ( move_constructed_unsafe(&raw mut __first), @@ -147,25 +140,21 @@ pub unsafe fn test_1() { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(explicit, value(i32))] +#[constructor(constructor_1, explicit, value(i32))] pub struct p2_explicit_constructor_Celsius { pub degrees: i32, } -impl ConstructibleFromUnsafe<(i32,)> for p2_explicit_constructor_Celsius { - unsafe fn constructor(this: *mut Self, (mut d,): (i32,)) { +impl p2_explicit_constructor_Celsius { + pub unsafe fn constructor_1(this: *mut Self, mut d: i32) { (&raw mut (*this).degrees).write(d); } } pub unsafe fn test_2() { - object_unsafe!(direct, p2_explicit_constructor_Celsius, (i32,), (3,)); + object_unsafe!(direct, p2_explicit_constructor_Celsius::constructor_1(3)); assert!(((direct.degrees) == (3))); let mut cast: p2_explicit_constructor_Celsius = { - let mut __v: p2_explicit_constructor_Celsius = - ::zero_init(); - >::constructor( - &raw mut __v, - (4,), - ); + let mut __v: p2_explicit_constructor_Celsius = ZeroInitializationUnsafe::zero_init(); + p2_explicit_constructor_Celsius::constructor_1(&raw mut __v, 4); __v }; assert!(((cast.degrees) == (4))); @@ -173,14 +162,14 @@ pub unsafe fn test_2() { match ((&mut (5, 6) as *mut (i32, i32)),) { (__tmp_1,) => { object_unsafe!(__first, p2_explicit_constructor_Celsius, |__this| { - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __this, - &[overload::Arg::rvalue_unsafe(&raw mut (*__tmp_1).0)], + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_1).0),), ) }); - object_unsafe!(__second, i32, |__this| ConversionsUnsafe::construct( + object_unsafe!(__second, i32, |__this| ConstructibleFromUnsafe::construct( __this, - &[overload::Arg::rvalue_unsafe(&raw mut (*__tmp_1).1)] + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_1).1),) )); ( move_constructed_unsafe(&raw mut __first), @@ -204,6 +193,7 @@ pub unsafe fn test_2() { )] #[conversions(copy, move)] #[conversion_function( + conversion_function_1, p2_explicit_constructor_and_conversion_function_Target, const_lvalue_ref )] @@ -224,70 +214,50 @@ pub struct p2_explicit_constructor_and_conversion_function_Source { )] #[conversions(copy, move)] #[constructor( + constructor_1, explicit, const_lvalue_ref(p2_explicit_constructor_and_conversion_function_Source) )] -#[constructor(value(i32))] +#[constructor(constructor_2, value(i32))] pub struct p2_explicit_constructor_and_conversion_function_Target { pub from: i32, } -impl - ConstructibleFromUnsafe<( - LvalueRefUnsafe>, - )> for p2_explicit_constructor_and_conversion_function_Target -{ - unsafe fn constructor( +impl p2_explicit_constructor_and_conversion_function_Target { + pub unsafe fn constructor_1( this: *mut Self, - (_a0,): (LvalueRefUnsafe>,), + _a0: LvalueRefUnsafe>, ) { let _a0 = (_a0.as_ptr() as *const p2_explicit_constructor_and_conversion_function_Source); (&raw mut (*this).from).write(1); } -} -impl ConstructibleFromUnsafe<(i32,)> for p2_explicit_constructor_and_conversion_function_Target { - unsafe fn constructor(this: *mut Self, (mut f,): (i32,)) { + pub unsafe fn constructor_2(this: *mut Self, mut f: i32) { (&raw mut (*this).from).write(f); } } -impl ConvertibleToUnsafe for i32 {} -impl - ConversionFunctionUnsafe< - p2_explicit_constructor_and_conversion_function_Target, - LvalueRefUnsafe>, - > for p2_explicit_constructor_and_conversion_function_Source -{ - unsafe fn conversion_function( +impl p2_explicit_constructor_and_conversion_function_Source { + pub unsafe fn conversion_function_1( this: LvalueRefUnsafe>, - to: *mut p2_explicit_constructor_and_conversion_function_Target, + __return: *mut p2_explicit_constructor_and_conversion_function_Target, ) { let this = this.as_ptr() as *mut p2_explicit_constructor_and_conversion_function_Source; - >::constructor(to, (2,)); + p2_explicit_constructor_and_conversion_function_Target::constructor_2(__return, 2); return; } } -impl - ImplicitConversionFunctionUnsafe< - p2_explicit_constructor_and_conversion_function_Target, - LvalueRefUnsafe>, - > for p2_explicit_constructor_and_conversion_function_Source -{ -} pub unsafe fn test_3() { let mut source: p2_explicit_constructor_and_conversion_function_Source = p2_explicit_constructor_and_conversion_function_Source { value: 0 }; object_unsafe!( direct, - p2_explicit_constructor_and_conversion_function_Target, - (LvalueRefUnsafe>,), - (LvalueRefUnsafe::bind(&source),) + p2_explicit_constructor_and_conversion_function_Target::constructor_1( + LvalueRefUnsafe::bind(&source) + ) ); assert!(((direct.from) == (1))); let mut copied: p2_explicit_constructor_and_conversion_function_Target = { let mut __v: p2_explicit_constructor_and_conversion_function_Target = - ::default(); - p2_explicit_constructor_and_conversion_function_Source::conversion_function( + ZeroInitializationUnsafe::zero_init(); + p2_explicit_constructor_and_conversion_function_Source::conversion_function_1( >>::bind( &mut source, ), diff --git a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs index ce8800c336..f42e0034cf 100644 --- a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs +++ b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs @@ -19,32 +19,26 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(i64, lvalue_ref)] +#[conversion_function(conversion_function_1, i64, lvalue_ref)] pub struct p2_non_const_conversion_function_Gauge { pub value: i64, } -impl ConversionFunctionUnsafe> - for p2_non_const_conversion_function_Gauge -{ - unsafe fn conversion_function( +impl p2_non_const_conversion_function_Gauge { + pub unsafe fn conversion_function_1( this: LvalueRefUnsafe, - to: *mut i64, + __return: *mut i64, ) { let this = this.as_ptr() as *mut p2_non_const_conversion_function_Gauge; - to.write((*(*this).value.prefix_inc())); + __return.write((*(*this).value.prefix_inc())); return; } } -impl ImplicitConversionFunctionUnsafe> - for p2_non_const_conversion_function_Gauge -{ -} pub unsafe fn test_0() { let mut gauge: p2_non_const_conversion_function_Gauge = p2_non_const_conversion_function_Gauge { value: 20_i64 }; let mut converted: i64 = { - let mut __v: i64 = 0_i64; - p2_non_const_conversion_function_Gauge::conversion_function( + let mut __v: i64 = ZeroInitializationUnsafe::zero_init(); + p2_non_const_conversion_function_Gauge::conversion_function_1( >::bind(&mut gauge), &raw mut __v, ); @@ -66,38 +60,29 @@ pub unsafe fn test_0() { ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(i32, const_lvalue_ref)] +#[conversion_function(conversion_function_1, i32, const_lvalue_ref)] pub struct p2_implicit_conversion_function_Ratio { pub numerator: i32, pub denominator: i32, } -impl ConversionFunctionUnsafe>> - for p2_implicit_conversion_function_Ratio -{ - unsafe fn conversion_function( +impl p2_implicit_conversion_function_Ratio { + pub unsafe fn conversion_function_1( this: LvalueRefUnsafe>, - to: *mut i32, + __return: *mut i32, ) { let this = this.as_ptr() as *mut p2_implicit_conversion_function_Ratio; - to.write((((*this).numerator) / ((*this).denominator))); + __return.write((((*this).numerator) / ((*this).denominator))); return; } } -impl - ImplicitConversionFunctionUnsafe< - i32, - LvalueRefUnsafe>, - > for p2_implicit_conversion_function_Ratio -{ -} pub unsafe fn test_1() { let mut ratio: p2_implicit_conversion_function_Ratio = p2_implicit_conversion_function_Ratio { numerator: 9, denominator: 3, }; let mut value: i32 = { - let mut __v: i32 = 0_i32; - p2_implicit_conversion_function_Ratio::conversion_function( + let mut __v: i32 = ZeroInitializationUnsafe::zero_init(); + p2_implicit_conversion_function_Ratio::conversion_function_1( >>::bind(&mut ratio), &raw mut __v, ); @@ -118,13 +103,17 @@ pub unsafe fn test_1() { }), ); let mut converted: (i32, i64) = { - object_unsafe!(__first, i32, |__this| ConversionsUnsafe::construct( + object_unsafe!(__first, i32, |__this| ConstructibleFromUnsafe::construct( __this, - &[overload::Arg::const_lvalue_unsafe(&raw const source.0)] + (LvalueRefUnsafe::< + Const, + >::bind(&raw const source.0),) )); - object_unsafe!(__second, i64, |__this| ConversionsUnsafe::construct( + object_unsafe!(__second, i64, |__this| ConstructibleFromUnsafe::construct( __this, - &[overload::Arg::const_lvalue_unsafe(&raw const source.1)] + (LvalueRefUnsafe::< + Const, + >::bind(&raw const source.1),) )); ( move_constructed_unsafe(&raw mut __first), @@ -146,19 +135,17 @@ pub unsafe fn test_1() { ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(bool, const_lvalue_ref, explicit)] +#[conversion_function(conversion_function_1, bool, const_lvalue_ref, explicit)] pub struct p2_explicit_conversion_function_Flag { pub value: i32, } -impl ConversionFunctionUnsafe>> - for p2_explicit_conversion_function_Flag -{ - unsafe fn conversion_function( +impl p2_explicit_conversion_function_Flag { + pub unsafe fn conversion_function_1( this: LvalueRefUnsafe>, - to: *mut bool, + __return: *mut bool, ) { let this = this.as_ptr() as *mut p2_explicit_conversion_function_Flag; - to.write((((*this).value) != (0))); + __return.write((((*this).value) != (0))); return; } } @@ -168,8 +155,8 @@ pub unsafe fn test_2() { let mut off: p2_explicit_conversion_function_Flag = p2_explicit_conversion_function_Flag { value: 0 }; assert!({ - let mut __v: bool = false; - p2_explicit_conversion_function_Flag::conversion_function( + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + p2_explicit_conversion_function_Flag::conversion_function_1( >>::bind(&mut on), &raw mut __v, ); @@ -177,8 +164,8 @@ pub unsafe fn test_2() { }); assert!( !({ - let mut __v: bool = false; - p2_explicit_conversion_function_Flag::conversion_function( + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + p2_explicit_conversion_function_Flag::conversion_function_1( >>::bind(&mut off), &raw mut __v, ); @@ -186,8 +173,8 @@ pub unsafe fn test_2() { }) ); let mut cast: bool = { - let mut __v: bool = false; - p2_explicit_conversion_function_Flag::conversion_function( + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + p2_explicit_conversion_function_Flag::conversion_function_1( >>::bind(&mut on), &raw mut __v, ); @@ -211,34 +198,22 @@ pub unsafe fn test_2() { pub struct p1_conversion_function_to_reference_Holder { pub value: i32, } -impl - ConversionFunctionUnsafe< - LvalueRefUnsafe, - LvalueRefUnsafe, - > for p1_conversion_function_to_reference_Holder -{ - unsafe fn conversion_function( +impl p1_conversion_function_to_reference_Holder { + pub unsafe fn conversion_function_1( this: LvalueRefUnsafe, - to: *mut LvalueRefUnsafe, + __return: *mut LvalueRefUnsafe, ) { let this = this.as_ptr() as *mut p1_conversion_function_to_reference_Holder; - to.write(>::bind(&mut (*this).value)); + __return.write(>::bind(&mut (*this).value)); return; } } -impl - ImplicitConversionFunctionUnsafe< - LvalueRefUnsafe, - LvalueRefUnsafe, - > for p1_conversion_function_to_reference_Holder -{ -} pub unsafe fn test_3() { let mut holder: p1_conversion_function_to_reference_Holder = p1_conversion_function_to_reference_Holder { value: 1 }; let ref_: *mut i32 = { - let mut __v: LvalueRefUnsafe = >::default(); - p1_conversion_function_to_reference_Holder::conversion_function( + let mut __v: LvalueRefUnsafe = ZeroInitializationUnsafe::zero_init(); + p1_conversion_function_to_reference_Holder::conversion_function_1( >::bind(&mut holder), &raw mut __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 1802d0b47f..a7cef80bb4 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 @@ -12,32 +12,28 @@ use std::rc::{Rc, Weak}; #[memberwise(move_constructor)] #[derive(Conversions)] #[conversions(move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct p11_defaulted_move_constructor_is_trivial_MoveOnly { #[offset(0)] pub value: i32, } -impl ConstructibleFrom<(i32,)> for p11_defaulted_move_constructor_is_trivial_MoveOnly { - fn constructor(this: Ptr, (mut value,): (i32,)) { +impl p11_defaulted_move_constructor_is_trivial_MoveOnly { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); } } -impl ConvertibleTo for i32 {} pub fn pass_0( object: p11_defaulted_move_constructor_is_trivial_MoveOnly, ) -> p11_defaulted_move_constructor_is_trivial_MoveOnly { let object: Value = Rc::new(RefCell::new(object)); return { - let __v: Value = Rc::new(RefCell::new( - ::zero_init(), - )); - ConvertibleTo::convert( - >::bind( - object.as_pointer(), - ), + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + ::move_constructor( __v.as_pointer(), + RvalueRef::bind(object.as_pointer()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; @@ -45,10 +41,9 @@ pub fn pass_0( pub fn test_1() { let mut result: p11_defaulted_move_constructor_is_trivial_MoveOnly = ({ pass_0({ - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - >::constructor(__v.as_pointer(), (7 ,)) ; + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p11_defaulted_move_constructor_is_trivial_MoveOnly::constructor_1(__v.as_pointer(), 7); 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 d77b814c4c..1c46c8a305 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 @@ -13,28 +13,22 @@ use std::rc::Rc; #[memberwise(move_constructor)] #[derive(ConversionsUnsafe)] #[conversions(move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] pub struct p11_defaulted_move_constructor_is_trivial_MoveOnly { pub value: i32, } -impl ConstructibleFromUnsafe<(i32,)> for p11_defaulted_move_constructor_is_trivial_MoveOnly { - unsafe fn constructor(this: *mut Self, (mut value,): (i32,)) { +impl p11_defaulted_move_constructor_is_trivial_MoveOnly { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); } } -impl ConvertibleToUnsafe for i32 {} pub unsafe fn pass_0( mut object: p11_defaulted_move_constructor_is_trivial_MoveOnly, ) -> p11_defaulted_move_constructor_is_trivial_MoveOnly { return { let mut __v: p11_defaulted_move_constructor_is_trivial_MoveOnly = - ::zero_init(); - ConvertibleToUnsafe::convert( - >::bind( - &mut object, - ), - &raw mut __v, - ); + ZeroInitializationUnsafe::zero_init(); + ::move_constructor(&raw mut __v, RvalueRefUnsafe::bind(& mut object )) ; __v }; } @@ -42,10 +36,8 @@ pub unsafe fn test_1() { let mut result: p11_defaulted_move_constructor_is_trivial_MoveOnly = (unsafe { pass_0({ let mut __v: p11_defaulted_move_constructor_is_trivial_MoveOnly = - ::zero_init(); - >::constructor(&raw mut __v, (7,)); + ZeroInitializationUnsafe::zero_init(); + p11_defaulted_move_constructor_is_trivial_MoveOnly::constructor_1(&raw mut __v, 7); __v }) }); diff --git a/tests/std/class/class.mem/out/refcount/class.mem.general.rs b/tests/std/class/class.mem/out/refcount/class.mem.general.rs index a03a721016..3198faf83f 100644 --- a/tests/std/class/class.mem/out/refcount/class.mem.general.rs +++ b/tests/std/class/class.mem/out/refcount/class.mem.general.rs @@ -25,7 +25,7 @@ pub const anon_2_reserve: anon_2 = 30; TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct p7_1_function_body_names_later_member_HasLaterMembers { #[offset(0)] @@ -43,9 +43,7 @@ impl p7_1_function_body_names_later_member_HasLaterMembers { pub fn minimum(this: Ptr) -> i32 { return 2; } -} -impl ConstructibleFrom<()> for p7_1_function_body_names_later_member_HasLaterMembers { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, stock).write(9); } } @@ -57,7 +55,7 @@ impl Default for p7_1_function_body_names_later_member_HasLaterMembers { pub fn test_3() { object!( object, - p7_1_function_body_names_later_member_HasLaterMembers + p7_1_function_body_names_later_member_HasLaterMembers::constructor_1() ); assert!( (({ @@ -84,7 +82,7 @@ thread_local!( TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct p7_2_default_argument_names_later_member_HasLaterStaticStep { #[offset(0)] @@ -97,9 +95,7 @@ impl p7_2_default_argument_names_later_member_HasLaterStaticStep { }; return this.with(|__s| __s.total); } -} -impl ConstructibleFrom<()> for p7_2_default_argument_names_later_member_HasLaterStaticStep { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, total).write(1); } } @@ -111,7 +107,7 @@ impl Default for p7_2_default_argument_names_later_member_HasLaterStaticStep { pub fn test_6() { object!( object, - p7_2_default_argument_names_later_member_HasLaterStaticStep + p7_2_default_argument_names_later_member_HasLaterStaticStep::constructor_1() ); assert!( (({ diff --git a/tests/std/class/class.mem/out/unsafe/class.mem.general.rs b/tests/std/class/class.mem/out/unsafe/class.mem.general.rs index 5915133da5..e23e8fbfd6 100644 --- a/tests/std/class/class.mem/out/unsafe/class.mem.general.rs +++ b/tests/std/class/class.mem/out/unsafe/class.mem.general.rs @@ -22,7 +22,7 @@ pub const anon_2_reserve: anon_2 = 30; TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct p7_1_function_body_names_later_member_HasLaterMembers { pub stock: i32, } @@ -38,9 +38,7 @@ impl p7_1_function_body_names_later_member_HasLaterMembers { pub unsafe fn minimum(this: *const Self) -> i32 { return 2; } -} -impl ConstructibleFromUnsafe<()> for p7_1_function_body_names_later_member_HasLaterMembers { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).stock).write(9); } } @@ -52,7 +50,7 @@ impl Default for p7_1_function_body_names_later_member_HasLaterMembers { pub unsafe fn test_3() { object_unsafe!( object, - p7_1_function_body_names_later_member_HasLaterMembers + p7_1_function_body_names_later_member_HasLaterMembers::constructor_1() ); assert!( ((unsafe { @@ -74,7 +72,7 @@ pub static mut step_5: std::cell::LazyCell = std::cell::LazyCell::new(|| un TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct p7_2_default_argument_names_later_member_HasLaterStaticStep { pub total: i32, } @@ -83,9 +81,7 @@ impl p7_2_default_argument_names_later_member_HasLaterStaticStep { (*this).total += amount; return (*this).total; } -} -impl ConstructibleFromUnsafe<()> for p7_2_default_argument_names_later_member_HasLaterStaticStep { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).total).write(1); } } @@ -97,7 +93,7 @@ impl Default for p7_2_default_argument_names_later_member_HasLaterStaticStep { pub unsafe fn test_6() { object_unsafe!( object, - p7_2_default_argument_names_later_member_HasLaterStaticStep + p7_2_default_argument_names_later_member_HasLaterStaticStep::constructor_1() ); assert!( ((unsafe { diff --git a/tests/std/concepts/concepts.lang/out/refcount/concept.constructible.rs b/tests/std/concepts/concepts.lang/out/refcount/concept.constructible.rs index 26f7f2c802..5707c12803 100644 --- a/tests/std/concepts/concepts.lang/out/refcount/concept.constructible.rs +++ b/tests/std/concepts/concepts.lang/out/refcount/concept.constructible.rs @@ -20,14 +20,14 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(explicit, value(i32))] +#[constructor(constructor_1, explicit, value(i32))] #[byte_size(4)] pub struct p1_constructible_from_Meters { #[offset(0)] pub value: i32, } -impl ConstructibleFrom<(i32,)> for p1_constructible_from_Meters { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl p1_constructible_from_Meters { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, value).write(v); } } @@ -45,7 +45,7 @@ impl ConstructibleFrom<(i32,)> for p1_constructible_from_Meters { Conversions, )] #[conversions(copy, move)] -#[conversion_function(i32, const_lvalue_ref, explicit)] +#[conversion_function(conversion_function_1, i32, const_lvalue_ref, explicit)] #[byte_size(8)] pub struct p1_constructible_from_Ratio { #[offset(0)] @@ -53,12 +53,13 @@ pub struct p1_constructible_from_Ratio { #[offset(4)] pub denominator: i32, } -impl ConversionFunction>> - for p1_constructible_from_Ratio -{ - fn conversion_function(this: LvalueRef>, to: Ptr) { +impl p1_constructible_from_Ratio { + pub fn conversion_function_1( + this: LvalueRef>, + __return: Ptr, + ) { let this = this.as_pointer(); - to.write((this.with(|__s| __s.numerator) / this.with(|__s| __s.denominator))); + __return.write((this.with(|__s| __s.numerator) / this.with(|__s| __s.denominator))); return; } } @@ -78,14 +79,16 @@ pub fn test_0() { let converted: Value<(Value, Value)> = Rc::new(RefCell::new({ object!(__first, p1_constructible_from_Meters, |__this| { - Conversions::construct( + ConstructibleFrom::construct( __this, - &[overload::Arg::lvalue((*source.borrow()).0.as_pointer())], + (LvalueRef::::bind((*source.borrow()).0.as_pointer()),), ) }); - object!(__second, i32, |__this| Conversions::construct( + object!(__second, i32, |__this| ConstructibleFrom::construct( __this, - &[overload::Arg::lvalue((*source.borrow()).1.as_pointer())] + (LvalueRef::::bind( + (*source.borrow()).1.as_pointer() + ),) )); ( Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), @@ -111,30 +114,22 @@ pub fn test_0() { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] +#[constructor(constructor_2, lvalue_ref(p1_copy_constructible_NonConstCopy))] #[byte_size(4)] pub struct p1_copy_constructible_NonConstCopy { #[offset(0)] pub value: i32, } -impl ConstructibleFrom<(i32,)> for p1_copy_constructible_NonConstCopy { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl p1_copy_constructible_NonConstCopy { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, value).write(v); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef,)> - for p1_copy_constructible_NonConstCopy -{ - fn constructor(this: Ptr, (other,): (LvalueRef,)) { + pub fn constructor_2(this: Ptr, other: LvalueRef) { let other = other.as_pointer(); field!(this, value).write((other.with(|__s| __s.value) + 1)); } } -impl ConvertibleTo - for LvalueRef -{ -} const _: () = assert!( true, "std::constructible_from" @@ -145,12 +140,13 @@ const _: () = assert!( ); const _: () = assert!(!(false), "!std::copy_constructible"); pub fn test_1() { - object!(original, p1_copy_constructible_NonConstCopy, (i32,), (1,)); + object!( + original, + p1_copy_constructible_NonConstCopy::constructor_1(1) + ); object!( copy, - p1_copy_constructible_NonConstCopy, - (LvalueRef,), - (LvalueRef::bind(original.as_pointer()),) + p1_copy_constructible_NonConstCopy::constructor_2(LvalueRef::bind(original.as_pointer())) ); assert!(({ (*copy.borrow()).value } == 2)); } diff --git a/tests/std/concepts/concepts.lang/out/refcount/concept.convertible.rs b/tests/std/concepts/concepts.lang/out/refcount/concept.convertible.rs index 7e55b44aa7..ef051c2080 100644 --- a/tests/std/concepts/concepts.lang/out/refcount/concept.convertible.rs +++ b/tests/std/concepts/concepts.lang/out/refcount/concept.convertible.rs @@ -20,18 +20,17 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct p1_convertible_to_Meters { #[offset(0)] pub value: i32, } -impl ConstructibleFrom<(i32,)> for p1_convertible_to_Meters { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl p1_convertible_to_Meters { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, value).write(v); } } -impl ConvertibleTo for i32 {} #[derive( Copy, Clone, @@ -46,14 +45,14 @@ impl ConvertibleTo for i32 {} Conversions, )] #[conversions(copy, move)] -#[constructor(explicit, value(i32))] +#[constructor(constructor_1, explicit, value(i32))] #[byte_size(4)] pub struct p1_convertible_to_Celsius { #[offset(0)] pub degrees: i32, } -impl ConstructibleFrom<(i32,)> for p1_convertible_to_Celsius { - fn constructor(this: Ptr, (mut d,): (i32,)) { +impl p1_convertible_to_Celsius { + pub fn constructor_1(this: Ptr, mut d: i32) { field!(this, degrees).write(d); } } @@ -71,7 +70,7 @@ impl ConstructibleFrom<(i32,)> for p1_convertible_to_Celsius { Conversions, )] #[conversions(copy, move)] -#[conversion_function(i32, const_lvalue_ref)] +#[conversion_function(conversion_function_1, i32, const_lvalue_ref)] #[byte_size(8)] pub struct p1_convertible_to_Ratio { #[offset(0)] @@ -79,19 +78,16 @@ pub struct p1_convertible_to_Ratio { #[offset(4)] pub denominator: i32, } -impl ConversionFunction>> - for p1_convertible_to_Ratio -{ - fn conversion_function(this: LvalueRef>, to: Ptr) { +impl p1_convertible_to_Ratio { + pub fn conversion_function_1( + this: LvalueRef>, + __return: Ptr, + ) { let this = this.as_pointer(); - to.write((this.with(|__s| __s.numerator) / this.with(|__s| __s.denominator))); + __return.write((this.with(|__s| __s.numerator) / this.with(|__s| __s.denominator))); return; } } -impl ImplicitConversionFunction>> - for p1_convertible_to_Ratio -{ -} const _: () = assert!(true, "std::convertible_to"); const _: () = assert!(!(false), "!std::convertible_to"); const _: () = assert!(true, "std::convertible_to"); @@ -102,11 +98,8 @@ pub fn test_1() { let mut meters: p1_convertible_to_Meters = ({ to_meters_0({ let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >::constructor( - __v.as_pointer(), - (7,), - ); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p1_convertible_to_Meters::constructor_1(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }); @@ -116,8 +109,8 @@ pub fn test_1() { denominator: 4, })); let mut value: i32 = { - let __v: Value = Rc::new(RefCell::new(0_i32)); - p1_convertible_to_Ratio::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p1_convertible_to_Ratio::conversion_function_1( >>::bind(ratio.as_pointer()), Ptr::clone(&__v.as_pointer()), ); @@ -138,18 +131,18 @@ pub fn test_1() { { (__tmp_0,) => { object!(__first, p1_convertible_to_Meters, |__this| { - Conversions::construct( + ConstructibleFrom::construct( __this, - &[overload::Arg::rvalue( + (RvalueRef::::bind( (*__tmp_0.upgrade().deref()).0.as_pointer(), - )], + ),), ) }); - object!(__second, i32, |__this| Conversions::construct( + object!(__second, i32, |__this| ConstructibleFrom::construct( __this, - &[overload::Arg::rvalue( + (RvalueRef::::bind( (*__tmp_0.upgrade().deref()).1.as_pointer() - )] + ),) )); ( Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), @@ -171,13 +164,13 @@ pub fn test_2() { Rc::new(RefCell::new((2 as i16))), ))); let converted: Value<(Value, Value)> = Rc::new(RefCell::new({ - object!(__first, i64, |__this| Conversions::construct( + object!(__first, i64, |__this| ConstructibleFrom::construct( __this, - &[overload::Arg::lvalue((*source.borrow()).0.as_pointer())] + (LvalueRef::::bind((*source.borrow()).0.as_pointer()),) )); - object!(__second, i32, |__this| Conversions::construct( + object!(__second, i32, |__this| ConstructibleFrom::construct( __this, - &[overload::Arg::lvalue((*source.borrow()).1.as_pointer())] + (LvalueRef::::bind((*source.borrow()).1.as_pointer()),) )); ( Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), @@ -198,17 +191,17 @@ pub fn test_2() { .as_pointer(),) { (__tmp_1,) => { - object!(__first, bool, |__this| Conversions::construct( + object!(__first, bool, |__this| ConstructibleFrom::construct( __this, - &[overload::Arg::rvalue( + (RvalueRef::::bind( (*__tmp_1.upgrade().deref()).0.as_pointer() - )] + ),) )); - object!(__second, f64, |__this| Conversions::construct( + object!(__second, f64, |__this| ConstructibleFrom::construct( __this, - &[overload::Arg::rvalue( + (RvalueRef::::bind( (*__tmp_1.upgrade().deref()).1.as_pointer() - )] + ),) )); ( Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), diff --git a/tests/std/concepts/concepts.lang/out/unsafe/concept.constructible.rs b/tests/std/concepts/concepts.lang/out/unsafe/concept.constructible.rs index 3138e06044..926eff24b5 100644 --- a/tests/std/concepts/concepts.lang/out/unsafe/concept.constructible.rs +++ b/tests/std/concepts/concepts.lang/out/unsafe/concept.constructible.rs @@ -19,12 +19,12 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(explicit, value(i32))] +#[constructor(constructor_1, explicit, value(i32))] pub struct p1_constructible_from_Meters { pub value: i32, } -impl ConstructibleFromUnsafe<(i32,)> for p1_constructible_from_Meters { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl p1_constructible_from_Meters { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).value).write(v); } } @@ -41,20 +41,18 @@ impl ConstructibleFromUnsafe<(i32,)> for p1_constructible_from_Meters { ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(i32, const_lvalue_ref, explicit)] +#[conversion_function(conversion_function_1, i32, const_lvalue_ref, explicit)] pub struct p1_constructible_from_Ratio { pub numerator: i32, pub denominator: i32, } -impl ConversionFunctionUnsafe>> - for p1_constructible_from_Ratio -{ - unsafe fn conversion_function( +impl p1_constructible_from_Ratio { + pub unsafe fn conversion_function_1( this: LvalueRefUnsafe>, - to: *mut i32, + __return: *mut i32, ) { let this = this.as_ptr() as *mut p1_constructible_from_Ratio; - to.write((((*this).numerator) / ((*this).denominator))); + __return.write((((*this).numerator) / ((*this).denominator))); return; } } @@ -71,11 +69,16 @@ pub unsafe fn test_0() { ); let mut converted: (p1_constructible_from_Meters, i32) = { object_unsafe!(__first, p1_constructible_from_Meters, |__this| { - ConversionsUnsafe::construct(__this, &[overload::Arg::lvalue_unsafe(&raw mut source.0)]) + ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::::bind(&raw mut source.0),), + ) }); - object_unsafe!(__second, i32, |__this| ConversionsUnsafe::construct( + object_unsafe!(__second, i32, |__this| ConstructibleFromUnsafe::construct( __this, - &[overload::Arg::lvalue_unsafe(&raw mut source.1)] + (LvalueRefUnsafe::::bind( + &raw mut source.1 + ),) )); ( move_constructed_unsafe(&raw mut __first), @@ -95,31 +98,23 @@ pub unsafe fn test_0() { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] +#[constructor(constructor_2, lvalue_ref(p1_copy_constructible_NonConstCopy))] pub struct p1_copy_constructible_NonConstCopy { pub value: i32, } -impl ConstructibleFromUnsafe<(i32,)> for p1_copy_constructible_NonConstCopy { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl p1_copy_constructible_NonConstCopy { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).value).write(v); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe,)> - for p1_copy_constructible_NonConstCopy -{ - unsafe fn constructor( + pub unsafe fn constructor_2( this: *mut Self, - (other,): (LvalueRefUnsafe,), + other: LvalueRefUnsafe, ) { let other = (other.as_ptr() as *mut p1_copy_constructible_NonConstCopy); (&raw mut (*this).value).write((((*other).value) + (1))); } } -impl ConvertibleToUnsafe - for LvalueRefUnsafe -{ -} const _: () = assert!( true, "std::constructible_from" @@ -130,12 +125,13 @@ const _: () = assert!( ); const _: () = assert!(!(false), "!std::copy_constructible"); pub unsafe fn test_1() { - object_unsafe!(original, p1_copy_constructible_NonConstCopy, (i32,), (1,)); + object_unsafe!( + original, + p1_copy_constructible_NonConstCopy::constructor_1(1) + ); object_unsafe!( copy, - p1_copy_constructible_NonConstCopy, - (LvalueRefUnsafe,), - (LvalueRefUnsafe::bind(&mut original),) + p1_copy_constructible_NonConstCopy::constructor_2(LvalueRefUnsafe::bind(&mut original)) ); assert!(((copy.value) == (2))); } diff --git a/tests/std/concepts/concepts.lang/out/unsafe/concept.convertible.rs b/tests/std/concepts/concepts.lang/out/unsafe/concept.convertible.rs index 00dc54fd46..67af7563d0 100644 --- a/tests/std/concepts/concepts.lang/out/unsafe/concept.convertible.rs +++ b/tests/std/concepts/concepts.lang/out/unsafe/concept.convertible.rs @@ -19,16 +19,15 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] pub struct p1_convertible_to_Meters { pub value: i32, } -impl ConstructibleFromUnsafe<(i32,)> for p1_convertible_to_Meters { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl p1_convertible_to_Meters { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).value).write(v); } } -impl ConvertibleToUnsafe for i32 {} #[repr(C)] #[derive( Copy, @@ -42,12 +41,12 @@ impl ConvertibleToUnsafe for i32 {} ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(explicit, value(i32))] +#[constructor(constructor_1, explicit, value(i32))] pub struct p1_convertible_to_Celsius { pub degrees: i32, } -impl ConstructibleFromUnsafe<(i32,)> for p1_convertible_to_Celsius { - unsafe fn constructor(this: *mut Self, (mut d,): (i32,)) { +impl p1_convertible_to_Celsius { + pub unsafe fn constructor_1(this: *mut Self, mut d: i32) { (&raw mut (*this).degrees).write(d); } } @@ -64,27 +63,21 @@ impl ConstructibleFromUnsafe<(i32,)> for p1_convertible_to_Celsius { ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(i32, const_lvalue_ref)] +#[conversion_function(conversion_function_1, i32, const_lvalue_ref)] pub struct p1_convertible_to_Ratio { pub numerator: i32, pub denominator: i32, } -impl ConversionFunctionUnsafe>> - for p1_convertible_to_Ratio -{ - unsafe fn conversion_function( +impl p1_convertible_to_Ratio { + pub unsafe fn conversion_function_1( this: LvalueRefUnsafe>, - to: *mut i32, + __return: *mut i32, ) { let this = this.as_ptr() as *mut p1_convertible_to_Ratio; - to.write((((*this).numerator) / ((*this).denominator))); + __return.write((((*this).numerator) / ((*this).denominator))); return; } } -impl ImplicitConversionFunctionUnsafe>> - for p1_convertible_to_Ratio -{ -} const _: () = assert!(true, "std::convertible_to"); const _: () = assert!(!(false), "!std::convertible_to"); const _: () = assert!(true, "std::convertible_to"); @@ -94,11 +87,8 @@ pub unsafe fn to_meters_0(mut meters: p1_convertible_to_Meters) -> p1_convertibl pub unsafe fn test_1() { let mut meters: p1_convertible_to_Meters = (unsafe { to_meters_0({ - let mut __v: p1_convertible_to_Meters = ::zero_init(); - >::constructor( - &raw mut __v, - (7,), - ); + let mut __v: p1_convertible_to_Meters = ZeroInitializationUnsafe::zero_init(); + p1_convertible_to_Meters::constructor_1(&raw mut __v, 7); __v }) }); @@ -108,8 +98,8 @@ pub unsafe fn test_1() { denominator: 4, }; let mut value: i32 = { - let mut __v: i32 = 0_i32; - p1_convertible_to_Ratio::conversion_function( + let mut __v: i32 = ZeroInitializationUnsafe::zero_init(); + p1_convertible_to_Ratio::conversion_function_1( >>::bind(&mut ratio), &raw mut __v, ); @@ -127,14 +117,16 @@ pub unsafe fn test_1() { { (__tmp_0,) => { object_unsafe!(__first, p1_convertible_to_Meters, |__this| { - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __this, - &[overload::Arg::rvalue_unsafe(&raw mut (*__tmp_0).0)], + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_0).0),), ) }); - object_unsafe!(__second, i32, |__this| ConversionsUnsafe::construct( + object_unsafe!(__second, i32, |__this| ConstructibleFromUnsafe::construct( __this, - &[overload::Arg::rvalue_unsafe(&raw mut (*__tmp_0).1)] + (RvalueRefUnsafe::::bind( + &raw mut (*__tmp_0).1 + ),) )); ( move_constructed_unsafe(&raw mut __first), @@ -147,13 +139,13 @@ pub unsafe fn test_1() { pub unsafe fn test_2() { let mut source: (i32, i16) = (1, (2 as i16)); let mut converted: (i64, i32) = { - object_unsafe!(__first, i64, |__this| ConversionsUnsafe::construct( + object_unsafe!(__first, i64, |__this| ConstructibleFromUnsafe::construct( __this, - &[overload::Arg::lvalue_unsafe(&raw mut source.0)] + (LvalueRefUnsafe::::bind(&raw mut source.0),) )); - object_unsafe!(__second, i32, |__this| ConversionsUnsafe::construct( + object_unsafe!(__second, i32, |__this| ConstructibleFromUnsafe::construct( __this, - &[overload::Arg::lvalue_unsafe(&raw mut source.1)] + (LvalueRefUnsafe::::bind(&raw mut source.1),) )); ( move_constructed_unsafe(&raw mut __first), @@ -163,13 +155,13 @@ pub unsafe fn test_2() { assert!(((converted.0) == (1_i64)) && ((converted.1) == (2))); let mut flags: (bool, f64) = match ((&mut (3, 4) as *mut (i32, i32)),) { (__tmp_1,) => { - object_unsafe!(__first, bool, |__this| ConversionsUnsafe::construct( + object_unsafe!(__first, bool, |__this| ConstructibleFromUnsafe::construct( __this, - &[overload::Arg::rvalue_unsafe(&raw mut (*__tmp_1).0)] + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_1).0),) )); - object_unsafe!(__second, f64, |__this| ConversionsUnsafe::construct( + object_unsafe!(__second, f64, |__this| ConstructibleFromUnsafe::construct( __this, - &[overload::Arg::rvalue_unsafe(&raw mut (*__tmp_1).1)] + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_1).1),) )); ( move_constructed_unsafe(&raw mut __first), diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs index c1d9fd256c..52f557abc1 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs @@ -414,7 +414,7 @@ pub fn test_21() { TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(8)] pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { #[offset(0)] @@ -422,8 +422,8 @@ pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { #[offset(4)] pub five: i32, } -impl ConstructibleFrom<()> for p9_1_2_zero_then_default_initialized_WithDefaultMember { - fn constructor(this: Ptr, _: ()) { +impl p9_1_2_zero_then_default_initialized_WithDefaultMember { + pub fn constructor_1(this: Ptr) { field!(this, zeroed).write(0_i32); field!(this, five).write(5); } @@ -449,14 +449,14 @@ impl Default for p9_1_2_zero_then_default_initialized_WithDefaultMember { TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { #[offset(0)] pub untouched: i32, } -impl ConstructibleFrom<()> for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { - fn constructor(this: Ptr, _: ()) { +impl p9_1_2_zero_then_default_initialized_LeavesMemberAlone { + pub fn constructor_1(this: Ptr) { field!(this, untouched).write(0_i32); } } @@ -465,10 +465,10 @@ impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { { { let __v: Value = - Rc::new(RefCell::new( - ::zero_init(), - )); - >::constructor(__v.as_pointer(), ()) ; + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p9_1_2_zero_then_default_initialized_LeavesMemberAlone::constructor_1( + __v.as_pointer(), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -486,7 +486,7 @@ impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { Default, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(8)] pub struct p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { #[offset(0)] @@ -495,22 +495,24 @@ pub struct p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { #[byte_size(4)] pub member: p9_1_2_zero_then_default_initialized_LeavesMemberAlone, } -impl ConstructibleFrom<()> for p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { - fn constructor(this: Ptr, _: ()) { +impl p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { + pub fn constructor_1(this: Ptr) { field!(this, number).write(0_i32); - >::constructor(field_ptr!(this, member), ()) ; + p9_1_2_zero_then_default_initialized_LeavesMemberAlone::constructor_1(field_ptr!( + this, member + )); } } pub fn test_22() { object!( value, - p9_1_2_zero_then_default_initialized_WithDefaultMember + p9_1_2_zero_then_default_initialized_WithDefaultMember::constructor_1() ); assert!(({ (*value.borrow()).zeroed } == 0)); assert!(({ (*value.borrow()).five } == 5)); let mut heap: Ptr = { let __p = Ptr::alloc(::zero_init()); - >::constructor(__p.clone(), ()) ; + p9_1_2_zero_then_default_initialized_WithDefaultMember::constructor_1(__p.clone()); __p }; assert!((heap.with(|__s| __s.zeroed) == 0)); @@ -518,14 +520,14 @@ pub fn test_22() { heap.delete(); object!( holder, - p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone + p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone::constructor_1() ); assert!(({ (*holder.borrow()).number } == 0)); assert!(({ (*holder.borrow()).member.untouched } == 0)); let mut heap_holder: Ptr = { let __p = Ptr::alloc(::zero_init()); - >::constructor(__p.clone(), ()) ; + p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone::constructor_1(__p.clone()); __p }; assert!((heap_holder.with(|__s| __s.number) == 0)); diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs index 3956054c0d..678537335d 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs @@ -346,13 +346,13 @@ pub unsafe fn test_21() { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { pub zeroed: i32, pub five: i32, } -impl ConstructibleFromUnsafe<()> for p9_1_2_zero_then_default_initialized_WithDefaultMember { - unsafe fn constructor(this: *mut Self, _: ()) { +impl p9_1_2_zero_then_default_initialized_WithDefaultMember { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).zeroed).write(0_i32); (&raw mut (*this).five).write(5); } @@ -377,12 +377,12 @@ impl Default for p9_1_2_zero_then_default_initialized_WithDefaultMember { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { pub untouched: i32, } -impl ConstructibleFromUnsafe<()> for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { - unsafe fn constructor(this: *mut Self, _: ()) { +impl p9_1_2_zero_then_default_initialized_LeavesMemberAlone { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).untouched).write(0_i32); } } @@ -391,8 +391,8 @@ impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { unsafe { { let mut __v: p9_1_2_zero_then_default_initialized_LeavesMemberAlone = - ::zero_init(); - >::constructor(&raw mut __v, ()) ; + ZeroInitializationUnsafe::zero_init(); + p9_1_2_zero_then_default_initialized_LeavesMemberAlone::constructor_1(&raw mut __v); __v } } @@ -409,21 +409,23 @@ impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { Default, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { pub number: i32, pub member: p9_1_2_zero_then_default_initialized_LeavesMemberAlone, } -impl ConstructibleFromUnsafe<()> for p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { - unsafe fn constructor(this: *mut Self, _: ()) { +impl p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).number).write(0_i32); - >::constructor(&raw mut (*this).member, ()) ; + p9_1_2_zero_then_default_initialized_LeavesMemberAlone::constructor_1( + &raw mut (*this).member, + ); } } pub unsafe fn test_22() { object_unsafe!( value, - p9_1_2_zero_then_default_initialized_WithDefaultMember + p9_1_2_zero_then_default_initialized_WithDefaultMember::constructor_1() ); assert!(((value.zeroed) == (0))); assert!(((value.five) == (5))); @@ -431,7 +433,7 @@ pub unsafe fn test_22() { let __p: *mut p9_1_2_zero_then_default_initialized_WithDefaultMember = Box::leak(Box::new( ::zero_init(), )); - >::constructor(__p, ()) ; + p9_1_2_zero_then_default_initialized_WithDefaultMember::constructor_1(__p); __p }; assert!((((*heap).zeroed) == (0))); @@ -444,7 +446,7 @@ pub unsafe fn test_22() { }; object_unsafe!( holder, - p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone + p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone::constructor_1() ); assert!(((holder.number) == (0))); assert!(((holder.member.untouched) == (0))); @@ -452,9 +454,7 @@ pub unsafe fn test_22() { let __p: *mut p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone = Box::leak( Box::new(::zero_init()), ); - >::constructor(__p, ()); + p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone::constructor_1(__p); __p }; assert!((((*heap_holder).number) == (0))); diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs index 84c2f523ab..2fa391acab 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs @@ -65,7 +65,7 @@ thread_local!( TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct p9_static_member_hides_namespace_variable_HasStaticStep { #[offset(0)] @@ -78,9 +78,7 @@ impl p9_static_member_hides_namespace_variable_HasStaticStep { }; return this.with(|__s| __s.total); } -} -impl ConstructibleFrom<()> for p9_static_member_hides_namespace_variable_HasStaticStep { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, total).write(1); } } @@ -92,7 +90,7 @@ impl Default for p9_static_member_hides_namespace_variable_HasStaticStep { pub fn test_11() { object!( object, - p9_static_member_hides_namespace_variable_HasStaticStep + p9_static_member_hides_namespace_variable_HasStaticStep::constructor_1() ); assert!( (({ @@ -139,24 +137,23 @@ pub fn combine_14(mut first: i32, mut second: i32) -> i32 { Conversions, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct p9_evaluated_each_time_called_Widget { #[offset(0)] pub id: i32, } -impl ConstructibleFrom<(i32,)> for p9_evaluated_each_time_called_Widget { - fn constructor(this: Ptr, (mut id,): (i32,)) { +impl p9_evaluated_each_time_called_Widget { + pub fn constructor_1(this: Ptr, mut id: i32) { field!(this, id).write(id); } } -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<()> for p9_evaluated_each_time_called_Widget { +impl Constructor<()> for p9_evaluated_each_time_called_Widget { fn constructor(this: Ptr, _: ()) { { - >::constructor( + p9_evaluated_each_time_called_Widget::constructor_1( this.clone(), - (({ count_default_13() }),), + ({ count_default_13() }), ); } } @@ -165,12 +162,11 @@ impl Default for p9_evaluated_each_time_called_Widget { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new( - ::zero_init(), - )); - >::constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p9_evaluated_each_time_called_Widget::constructor_1( __v.as_pointer(), - (({ count_default_13() }),), + ({ count_default_13() }), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() } @@ -193,7 +189,7 @@ pub const anon_16_kBonus: anon_16 = 5; TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct p9_evaluated_each_time_called_Account { #[offset(0)] @@ -212,9 +208,7 @@ impl p9_evaluated_each_time_called_Account { pub fn set_base(mut value: i32) { base_15.with(|rc| *rc.borrow_mut() = value); } -} -impl ConstructibleFrom<()> for p9_evaluated_each_time_called_Account { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, balance).write(0); } } @@ -235,22 +229,21 @@ pub fn test_17() { assert!((defaults_evaluated_12.with(|rc| *rc.borrow()) == 3)); object!( a, - p9_evaluated_each_time_called_Widget, - (i32,), - (({ count_default_13() }),) + p9_evaluated_each_time_called_Widget::constructor_1(({ count_default_13() })) ); - object!(b, p9_evaluated_each_time_called_Widget, (i32,), (40,)); + object!(b, p9_evaluated_each_time_called_Widget::constructor_1(40)); object!( c, - p9_evaluated_each_time_called_Widget, - (i32,), - (({ count_default_13() }),) + p9_evaluated_each_time_called_Widget::constructor_1(({ count_default_13() })) ); assert!(({ (*a.borrow()).id } == 4)); assert!(({ (*b.borrow()).id } == 40)); assert!(({ (*c.borrow()).id } == 5)); assert!((defaults_evaluated_12.with(|rc| *rc.borrow()) == 5)); - object!(account, p9_evaluated_each_time_called_Account); + object!( + account, + p9_evaluated_each_time_called_Account::constructor_1() + ); assert!( (({ p9_evaluated_each_time_called_Account::deposit( diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs index 661ae51482..3e308a9e13 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs @@ -63,7 +63,7 @@ pub static mut step_10: std::cell::LazyCell = std::cell::LazyCell::new(|| u TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct p9_static_member_hides_namespace_variable_HasStaticStep { pub total: i32, } @@ -72,9 +72,7 @@ impl p9_static_member_hides_namespace_variable_HasStaticStep { (*this).total += amount; return (*this).total; } -} -impl ConstructibleFromUnsafe<()> for p9_static_member_hides_namespace_variable_HasStaticStep { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).total).write(1); } } @@ -86,7 +84,7 @@ impl Default for p9_static_member_hides_namespace_variable_HasStaticStep { pub unsafe fn test_11() { object_unsafe!( object, - p9_static_member_hides_namespace_variable_HasStaticStep + p9_static_member_hides_namespace_variable_HasStaticStep::constructor_1() ); assert!( ((unsafe { @@ -131,22 +129,21 @@ pub unsafe fn combine_14(mut first: i32, mut second: i32) -> i32 { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] pub struct p9_evaluated_each_time_called_Widget { pub id: i32, } -impl ConstructibleFromUnsafe<(i32,)> for p9_evaluated_each_time_called_Widget { - unsafe fn constructor(this: *mut Self, (mut id,): (i32,)) { +impl p9_evaluated_each_time_called_Widget { + pub unsafe fn constructor_1(this: *mut Self, mut id: i32) { (&raw mut (*this).id).write(id); } } -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<()> for p9_evaluated_each_time_called_Widget { +impl ConstructorUnsafe<()> for p9_evaluated_each_time_called_Widget { unsafe fn constructor(this: *mut Self, _: ()) { unsafe { - >::constructor( + p9_evaluated_each_time_called_Widget::constructor_1( this, - ((unsafe { count_default_13() }),), + (unsafe { count_default_13() }), ); } } @@ -156,8 +153,11 @@ impl Default for p9_evaluated_each_time_called_Widget { unsafe { { let mut __v: p9_evaluated_each_time_called_Widget = - ::zero_init(); - >::constructor(&raw mut __v, (( unsafe { count_default_13 ( ) } ) ,)) ; + ZeroInitializationUnsafe::zero_init(); + p9_evaluated_each_time_called_Widget::constructor_1( + &raw mut __v, + (unsafe { count_default_13() }), + ); __v } } @@ -176,7 +176,7 @@ pub const anon_16_kBonus: anon_16 = 5; TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct p9_evaluated_each_time_called_Account { pub balance: i32, } @@ -191,9 +191,7 @@ impl p9_evaluated_each_time_called_Account { pub unsafe fn set_base(mut value: i32) { (*std::cell::LazyCell::force_mut(&mut *&raw mut base_15)) = value; } -} -impl ConstructibleFromUnsafe<()> for p9_evaluated_each_time_called_Account { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).balance).write(0); } } @@ -216,22 +214,21 @@ pub unsafe fn test_17() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut defaults_evaluated_12)) == (3))); object_unsafe!( a, - p9_evaluated_each_time_called_Widget, - (i32,), - ((unsafe { count_default_13() }),) + p9_evaluated_each_time_called_Widget::constructor_1((unsafe { count_default_13() })) ); - object_unsafe!(b, p9_evaluated_each_time_called_Widget, (i32,), (40,)); + object_unsafe!(b, p9_evaluated_each_time_called_Widget::constructor_1(40)); object_unsafe!( c, - p9_evaluated_each_time_called_Widget, - (i32,), - ((unsafe { count_default_13() }),) + p9_evaluated_each_time_called_Widget::constructor_1((unsafe { count_default_13() })) ); assert!(((a.id) == (4))); assert!(((b.id) == (40))); assert!(((c.id) == (5))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut defaults_evaluated_12)) == (5))); - object_unsafe!(account, p9_evaluated_each_time_called_Account); + object_unsafe!( + account, + p9_evaluated_each_time_called_Account::constructor_1() + ); assert!( ((unsafe { p9_evaluated_each_time_called_Account::deposit( 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 c60513cbe1..d219b50825 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 @@ -147,41 +147,25 @@ thread_local!( Default, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy = constructor_2, move = constructor_3)] #[byte_size(1)] pub struct p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} -impl ConstructibleFrom<(LvalueRef>,)> - for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves -{ - fn constructor( +impl p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { + pub fn constructor_2( this: Ptr, - (_a0,): (LvalueRef>,), + _a0: LvalueRef>, ) { let _a0 = _a0.as_pointer(); (*copyCount_9.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl CopyConstructible for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} -impl ConvertibleTo - for LvalueRef> -{ -} -impl ConstructibleFrom<(RvalueRef,)> - for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves -{ - fn constructor( + pub fn constructor_3( this: Ptr, - (_a0,): (RvalueRef,), + _a0: RvalueRef, ) { let _a0 = _a0.as_pointer(); (*moveCount_10.with(Value::clone).borrow_mut()).prefix_inc(); } } -impl MoveConstructible for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} -impl ConvertibleTo - for RvalueRef -{ -} #[derive( Record, ByteRepr, @@ -201,6 +185,7 @@ pub struct p6_data_member_of_rvalue_is_xvalue_HoldsCounted { #[byte_size(1)] pub member: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, } +impl p6_data_member_of_rvalue_is_xvalue_HoldsCounted {} pub fn test_11() { let mut pm: isize = (offset_of_field!(p6_data_member_of_rvalue_is_xvalue_HoldsCounted, member) as isize); @@ -209,21 +194,19 @@ pub fn test_11() { )); object!( from_lvalue, - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves = - >>::bind( - (holder.as_pointer()) - .member::(pm) - ) + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::constructor_2(LvalueRef::bind( + (holder.as_pointer()) + .member::(pm) + )) ); assert!((copyCount_9.with(|rc| *rc.borrow()) == 1)); assert!((moveCount_10.with(|rc| *rc.borrow()) == 0)); object!( from_xvalue, - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves = - >::bind( - (holder.as_pointer()) - .member::(pm) - ) + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::constructor_3(RvalueRef::bind( + (holder.as_pointer()) + .member::(pm) + )) ); assert!((copyCount_9.with(|rc| *rc.borrow()) == 1)); assert!((moveCount_10.with(|rc| *rc.borrow()) == 1)); 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 4567b1581c..5871407426 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 @@ -135,40 +135,24 @@ pub static mut moveCount_10: std::cell::LazyCell = std::cell::LazyCell::new Default, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy = constructor_2, move = constructor_3)] pub struct p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> - for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves -{ - unsafe fn constructor( +impl p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { + pub unsafe fn constructor_2( this: *mut Self, - (_a0,): (LvalueRefUnsafe>,), + _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 CopyConstructibleUnsafe for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} -impl ConvertibleToUnsafe - for LvalueRefUnsafe> -{ -} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> - for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves -{ - unsafe fn constructor( + pub unsafe fn constructor_3( this: *mut Self, - (_a0,): (RvalueRefUnsafe,), + _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(); } } -impl MoveConstructibleUnsafe for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} -impl ConvertibleToUnsafe - for RvalueRefUnsafe -{ -} #[repr(C)] #[derive( FnPtrArg, @@ -184,6 +168,7 @@ impl ConvertibleToUnsafe::default(); object_unsafe!( from_lvalue, - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves = , - >>::bind( - &(*(&mut holder as *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted) - .wrapping_byte_offset(pm) - .cast::()) + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::constructor_2( + LvalueRefUnsafe::bind( + &(*(&mut holder as *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted) + .wrapping_byte_offset(pm) + .cast::()) + ) ) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_9)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut moveCount_10)) == (0))); object_unsafe!( from_xvalue, - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves = - >::bind( + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::constructor_3( + RvalueRefUnsafe::bind( &mut (*(&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)) == (1))); diff --git a/tests/std/expr/expr.prim/out/refcount/expr.prim.this.rs b/tests/std/expr/expr.prim/out/refcount/expr.prim.this.rs index 7a58d09606..1701049a73 100644 --- a/tests/std/expr/expr.prim/out/refcount/expr.prim.this.rs +++ b/tests/std/expr/expr.prim/out/refcount/expr.prim.this.rs @@ -18,7 +18,7 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] #[byte_size(16)] pub struct p1_default_member_initializer_names_object_Holder { #[offset(0)] @@ -27,15 +27,14 @@ pub struct p1_default_member_initializer_names_object_Holder { #[offset(8)] pub value: i32, } -impl ConstructibleFrom<(i32,)> for p1_default_member_initializer_names_object_Holder { - fn constructor(this: Ptr, (mut value,): (i32,)) { +impl p1_default_member_initializer_names_object_Holder { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, self_).write((this).clone()); field!(this, value).write(value); assert!((this.with(|__s| __s.self_.clone()) == this)); assert!(({ this.with(|__s| __s.self_.clone()).with(|__s| __s.value) } == { value })); } } -impl ConvertibleTo for i32 {} impl Default for p1_default_member_initializer_names_object_Holder { fn default() -> Self { { ::zero_init() } @@ -44,9 +43,7 @@ impl Default for p1_default_member_initializer_names_object_Holder { pub fn test_0() { object!( holder, - p1_default_member_initializer_names_object_Holder, - (i32,), - (4,) + p1_default_member_initializer_names_object_Holder::constructor_1(4) ); assert!(({ (*holder.borrow()).value } == 4)); } @@ -63,7 +60,7 @@ pub fn test_0() { Conversions, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] #[byte_size(16)] pub struct p1_mem_initializer_names_object_Holder { #[offset(0)] @@ -72,8 +69,8 @@ pub struct p1_mem_initializer_names_object_Holder { #[offset(8)] pub value: i32, } -impl ConstructibleFrom<(i32,)> for p1_mem_initializer_names_object_Holder { - fn constructor(this: Ptr, (mut value,): (i32,)) { +impl p1_mem_initializer_names_object_Holder { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, self_).write((this).clone()); field!(this, value).write(value); assert!((this.with(|__s| __s.self_.clone()) == this)); @@ -83,9 +80,11 @@ impl ConstructibleFrom<(i32,)> for p1_mem_initializer_names_object_Holder { assert!((this.with(|__s| __s.value) == (value + 1))); } } -impl ConvertibleTo for i32 {} pub fn test_1() { - object!(holder, p1_mem_initializer_names_object_Holder, (i32,), (4,)); + object!( + holder, + p1_mem_initializer_names_object_Holder::constructor_1(4) + ); assert!(({ (*holder.borrow()).value } == 5)); } #[derive( diff --git a/tests/std/expr/expr.prim/out/unsafe/expr.prim.this.rs b/tests/std/expr/expr.prim/out/unsafe/expr.prim.this.rs index 0d56cbdbdf..0ffd9cc063 100644 --- a/tests/std/expr/expr.prim/out/unsafe/expr.prim.this.rs +++ b/tests/std/expr/expr.prim/out/unsafe/expr.prim.this.rs @@ -18,20 +18,19 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] pub struct p1_default_member_initializer_names_object_Holder { pub self_: *mut p1_default_member_initializer_names_object_Holder, pub value: i32, } -impl ConstructibleFromUnsafe<(i32,)> for p1_default_member_initializer_names_object_Holder { - unsafe fn constructor(this: *mut Self, (mut value,): (i32,)) { +impl p1_default_member_initializer_names_object_Holder { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).self_).write(this); (&raw mut (*this).value).write(value); assert!((((*this).self_) == (this))); assert!((((*(*this).self_).value) == (value))); } } -impl ConvertibleToUnsafe for i32 {} impl Default for p1_default_member_initializer_names_object_Holder { fn default() -> Self { unsafe { ::zero_init() } @@ -40,9 +39,7 @@ impl Default for p1_default_member_initializer_names_object_Holder { pub unsafe fn test_0() { object_unsafe!( holder, - p1_default_member_initializer_names_object_Holder, - (i32,), - (4,) + p1_default_member_initializer_names_object_Holder::constructor_1(4) ); assert!(((holder.value) == (4))); } @@ -59,13 +56,13 @@ pub unsafe fn test_0() { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] pub struct p1_mem_initializer_names_object_Holder { pub self_: *mut p1_mem_initializer_names_object_Holder, pub value: i32, } -impl ConstructibleFromUnsafe<(i32,)> for p1_mem_initializer_names_object_Holder { - unsafe fn constructor(this: *mut Self, (mut value,): (i32,)) { +impl p1_mem_initializer_names_object_Holder { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).self_).write(this); (&raw mut (*this).value).write(value); assert!((((*this).self_) == (this))); @@ -73,9 +70,11 @@ impl ConstructibleFromUnsafe<(i32,)> for p1_mem_initializer_names_object_Holder assert!((((*this).value) == ((value) + (1)))); } } -impl ConvertibleToUnsafe for i32 {} pub unsafe fn test_1() { - object_unsafe!(holder, p1_mem_initializer_names_object_Holder, (i32,), (4,)); + object_unsafe!( + holder, + p1_mem_initializer_names_object_Holder::constructor_1(4) + ); assert!(((holder.value) == (5))); } #[repr(C)] diff --git a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs index bc9385f38f..fc238679b2 100644 --- a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs +++ b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs @@ -33,14 +33,14 @@ pub struct p16_rebind_member_Alloc_std_pair_const_int__int___rebind_std_pair_con TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct p16_rebind_member_Alloc_std_pair_const_int__int__ { #[offset(0)] pub id: i32, } -impl ConstructibleFrom<()> for p16_rebind_member_Alloc_std_pair_const_int__int__ { - fn constructor(this: Ptr, _: ()) { +impl p16_rebind_member_Alloc_std_pair_const_int__int__ { + pub fn constructor_1(this: Ptr) { field!(this, id).write(0); } } diff --git a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs index ddd2d021a3..978cbdabc8 100644 --- a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs +++ b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs @@ -30,12 +30,12 @@ pub struct p16_rebind_member_Alloc_std_pair_const_int__int___rebind_std_pair_con TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct p16_rebind_member_Alloc_std_pair_const_int__int__ { pub id: i32, } -impl ConstructibleFromUnsafe<()> for p16_rebind_member_Alloc_std_pair_const_int__int__ { - unsafe fn constructor(this: *mut Self, _: ()) { +impl p16_rebind_member_Alloc_std_pair_const_int__int__ { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).id).write(0); } } diff --git a/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs b/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs index aa0bf94ccb..e8e3a288c0 100644 --- a/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs +++ b/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs @@ -26,54 +26,44 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] -#[constructor(value(i32))] -#[conversion_function(bool, const_lvalue_ref, explicit)] +#[conversions(copy, move)] +#[constructor(constructor_1, value(i32))] +#[conversion_function(conversion_function_3, bool, const_lvalue_ref, explicit)] #[byte_size(4)] pub struct p2_condition_variable_created_each_iteration_ConvertsToBool { #[offset(0)] pub value: i32, } -impl ConstructibleFrom<(i32,)> for p2_condition_variable_created_each_iteration_ConvertsToBool { - fn constructor(this: Ptr, (mut value,): (i32,)) { +impl p2_condition_variable_created_each_iteration_ConvertsToBool { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl ConvertibleTo for i32 {} -impl Destructible for p2_condition_variable_created_each_iteration_ConvertsToBool { - fn destroy(this: Ptr) { - (*dtorCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -impl - ConversionFunction< - bool, - LvalueRef>, - > for p2_condition_variable_created_each_iteration_ConvertsToBool -{ - fn conversion_function( + pub fn conversion_function_3( this: LvalueRef>, - to: Ptr, + __return: Ptr, ) { let this = this.as_pointer(); - to.write((this.with(|__s| __s.value) != 0)); + __return.write((this.with(|__s| __s.value) != 0)); return; } } +impl Destructible for p2_condition_variable_created_each_iteration_ConvertsToBool { + fn destroy(this: Ptr) { + (*dtorCount_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} pub fn test_2() { let mut remaining: i32 = 2; let mut iterations: i32 = 0; 'loop_: loop { object!( condition, - p2_condition_variable_created_each_iteration_ConvertsToBool, - (i32,), - (remaining,) + p2_condition_variable_created_each_iteration_ConvertsToBool::constructor_1(remaining) ); if !({ - let __v: Value = Rc::new(RefCell::new(false)); - p2_condition_variable_created_each_iteration_ConvertsToBool::conversion_function(>>::bind(condition .as_pointer() ), Ptr::clone(&__v.as_pointer())); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p2_condition_variable_created_each_iteration_ConvertsToBool::conversion_function_3(>>::bind(condition .as_pointer() ), Ptr::clone(&__v.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) { break; @@ -108,41 +98,33 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] -#[constructor(value(i32))] -#[conversion_function(bool, const_lvalue_ref, explicit)] +#[conversions(copy, move)] +#[constructor(constructor_1, value(i32))] +#[conversion_function(conversion_function_3, bool, const_lvalue_ref, explicit)] #[byte_size(4)] pub struct p2_continue_destroys_condition_variable_ConvertsToBool { #[offset(0)] pub value: i32, } -impl ConstructibleFrom<(i32,)> for p2_continue_destroys_condition_variable_ConvertsToBool { - fn constructor(this: Ptr, (mut value,): (i32,)) { +impl p2_continue_destroys_condition_variable_ConvertsToBool { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); (*ctorCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl ConvertibleTo for i32 {} -impl Destructible for p2_continue_destroys_condition_variable_ConvertsToBool { - fn destroy(this: Ptr) { - (*dtorCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -impl - ConversionFunction< - bool, - LvalueRef>, - > for p2_continue_destroys_condition_variable_ConvertsToBool -{ - fn conversion_function( + pub fn conversion_function_3( this: LvalueRef>, - to: Ptr, + __return: Ptr, ) { let this = this.as_pointer(); - to.write((this.with(|__s| __s.value) != 0)); + __return.write((this.with(|__s| __s.value) != 0)); return; } } +impl Destructible for p2_continue_destroys_condition_variable_ConvertsToBool { + fn destroy(this: Ptr) { + (*dtorCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + } +} pub fn test_5() { let mut remaining: i32 = 3; let mut continued: i32 = 0; @@ -150,13 +132,11 @@ pub fn test_5() { 'loop_: loop { object!( condition, - p2_continue_destroys_condition_variable_ConvertsToBool, - (i32,), - (remaining,) + p2_continue_destroys_condition_variable_ConvertsToBool::constructor_1(remaining) ); if !({ - let __v: Value = Rc::new(RefCell::new(false)); - p2_continue_destroys_condition_variable_ConvertsToBool::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p2_continue_destroys_condition_variable_ConvertsToBool::conversion_function_3( >>::bind( condition.as_pointer(), ), diff --git a/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs b/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs index 1b478dbb63..0c9265505c 100644 --- a/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs +++ b/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs @@ -21,55 +21,43 @@ pub static mut dtorCount_1: std::cell::LazyCell = std::cell::LazyCell::new( )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] -#[constructor(value(i32))] -#[conversion_function(bool, const_lvalue_ref, explicit)] +#[conversions(copy, move)] +#[constructor(constructor_1, value(i32))] +#[conversion_function(conversion_function_3, bool, const_lvalue_ref, explicit)] pub struct p2_condition_variable_created_each_iteration_ConvertsToBool { pub value: i32, } -impl ConstructibleFromUnsafe<(i32,)> - for p2_condition_variable_created_each_iteration_ConvertsToBool -{ - unsafe fn constructor(this: *mut Self, (mut value,): (i32,)) { +impl p2_condition_variable_created_each_iteration_ConvertsToBool { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } -} -impl ConvertibleToUnsafe for i32 {} -impl DestructibleUnsafe for p2_condition_variable_created_each_iteration_ConvertsToBool { - unsafe fn destroy(this: *mut Self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_1)).prefix_inc(); - } -} -impl - ConversionFunctionUnsafe< - bool, - LvalueRefUnsafe>, - > for p2_condition_variable_created_each_iteration_ConvertsToBool -{ - unsafe fn conversion_function( + pub unsafe fn conversion_function_3( this: LvalueRefUnsafe>, - to: *mut bool, + __return: *mut bool, ) { let this = this.as_ptr() as *mut p2_condition_variable_created_each_iteration_ConvertsToBool; - to.write((((*this).value) != (0))); + __return.write((((*this).value) != (0))); return; } } +impl DestructibleUnsafe for p2_condition_variable_created_each_iteration_ConvertsToBool { + unsafe fn destroy(this: *mut Self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_1)).prefix_inc(); + } +} pub unsafe fn test_2() { let mut remaining: i32 = 2; let mut iterations: i32 = 0; 'loop_: loop { object_unsafe!( condition, - p2_condition_variable_created_each_iteration_ConvertsToBool, - (i32,), - (remaining,) + p2_condition_variable_created_each_iteration_ConvertsToBool::constructor_1(remaining) ); if !({ - let mut __v: bool = false; - p2_condition_variable_created_each_iteration_ConvertsToBool::conversion_function(>>::bind(& mut condition ), &raw mut __v); + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + p2_condition_variable_created_each_iteration_ConvertsToBool::conversion_function_3(>>::bind(& mut condition ), &raw mut __v); __v }) { break; @@ -101,39 +89,31 @@ pub static mut dtorCount_4: std::cell::LazyCell = std::cell::LazyCell::new( )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] -#[constructor(value(i32))] -#[conversion_function(bool, const_lvalue_ref, explicit)] +#[conversions(copy, move)] +#[constructor(constructor_1, value(i32))] +#[conversion_function(conversion_function_3, bool, const_lvalue_ref, explicit)] pub struct p2_continue_destroys_condition_variable_ConvertsToBool { pub value: i32, } -impl ConstructibleFromUnsafe<(i32,)> for p2_continue_destroys_condition_variable_ConvertsToBool { - unsafe fn constructor(this: *mut Self, (mut value,): (i32,)) { +impl p2_continue_destroys_condition_variable_ConvertsToBool { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_3)).prefix_inc(); } -} -impl ConvertibleToUnsafe for i32 {} -impl DestructibleUnsafe for p2_continue_destroys_condition_variable_ConvertsToBool { - unsafe fn destroy(this: *mut Self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_4)).prefix_inc(); - } -} -impl - ConversionFunctionUnsafe< - bool, - LvalueRefUnsafe>, - > for p2_continue_destroys_condition_variable_ConvertsToBool -{ - unsafe fn conversion_function( + pub unsafe fn conversion_function_3( this: LvalueRefUnsafe>, - to: *mut bool, + __return: *mut bool, ) { let this = this.as_ptr() as *mut p2_continue_destroys_condition_variable_ConvertsToBool; - to.write((((*this).value) != (0))); + __return.write((((*this).value) != (0))); return; } } +impl DestructibleUnsafe for p2_continue_destroys_condition_variable_ConvertsToBool { + unsafe fn destroy(this: *mut Self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_4)).prefix_inc(); + } +} pub unsafe fn test_5() { let mut remaining: i32 = 3; let mut continued: i32 = 0; @@ -141,13 +121,11 @@ pub unsafe fn test_5() { 'loop_: loop { object_unsafe!( condition, - p2_continue_destroys_condition_variable_ConvertsToBool, - (i32,), - (remaining,) + p2_continue_destroys_condition_variable_ConvertsToBool::constructor_1(remaining) ); if !({ - let mut __v: bool = false; - p2_continue_destroys_condition_variable_ConvertsToBool::conversion_function(>>::bind(& mut condition ), &raw mut __v); + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + p2_continue_destroys_condition_variable_ConvertsToBool::conversion_function_3(>>::bind(& mut condition ), &raw mut __v); __v }) { break; 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 8d2eb4e3ca..595da9d855 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 @@ -30,7 +30,7 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -55,28 +55,22 @@ 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 ConstructibleFrom<()> for LifetimeTracked { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl ConstructibleFrom<(LvalueRef>,)> for LifetimeTracked { - fn constructor(this: Ptr, (_a0,): (LvalueRef>,)) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } -impl CopyConstructible for LifetimeTracked {} -impl ConvertibleTo for LvalueRef> {} impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); @@ -92,7 +86,7 @@ pub fn test_6() { ({ LifetimeTracked::reset() }); let mut choice: i32 = 9; { - object!(guard, LifetimeTracked); + object!(guard, LifetimeTracked::constructor_1()); let mut choice: i32 = 0; if (choice != 0) { (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); @@ -108,7 +102,7 @@ pub fn test_6() { assert!((else_runs_5.with(|rc| *rc.borrow()) == 1)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 1)); { - object!(guard, LifetimeTracked); + object!(guard, LifetimeTracked::constructor_1()); let mut choice: i32 = 4; if (choice != 0) { (*then_runs_4.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 dfffe2b367..73530dc365 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 @@ -30,7 +30,7 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -55,28 +55,22 @@ 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 ConstructibleFrom<()> for LifetimeTracked { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl ConstructibleFrom<(LvalueRef>,)> for LifetimeTracked { - fn constructor(this: Ptr, (_a0,): (LvalueRef>,)) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } -impl CopyConstructible for LifetimeTracked {} -impl ConvertibleTo for LvalueRef> {} impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); @@ -105,35 +99,23 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] -#[conversion_function(i32, const_lvalue_ref)] +#[conversions(copy, move)] +#[conversion_function(conversion_function_1, i32, const_lvalue_ref)] #[byte_size(4)] pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { #[offset(0)] pub value: i32, } -impl - ConversionFunction< - i32, - LvalueRef>, - > for p2_condition_variable_lives_for_whole_statement_ConvertsToInt -{ - fn conversion_function( +impl p2_condition_variable_lives_for_whole_statement_ConvertsToInt { + pub fn conversion_function_1( this: LvalueRef>, - to: Ptr, + __return: Ptr, ) { let this = this.as_pointer(); - to.write(this.with(|__s| __s.value)); + __return.write(this.with(|__s| __s.value)); return; } } -impl - ImplicitConversionFunction< - i32, - LvalueRef>, - > for p2_condition_variable_lives_for_whole_statement_ConvertsToInt -{ -} impl Destructible for p2_condition_variable_lives_for_whole_statement_ConvertsToInt { fn destroy(this: Ptr) { (*dtorCount_6.with(Value::clone).borrow_mut()).prefix_inc(); @@ -151,8 +133,8 @@ pub fn test_7() { 'switch: { match { { - let __v: Value = Rc::new(RefCell::new(0_i32)); - p2_condition_variable_lives_for_whole_statement_ConvertsToInt::conversion_function(>>::bind(selector .as_pointer() ), Ptr::clone(&__v.as_pointer())); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::conversion_function_1(>>::bind(selector .as_pointer() ), Ptr::clone(&__v.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } { @@ -183,7 +165,7 @@ pub fn test_10() { ({ LifetimeTracked::reset() }); let mut selector: i32 = 9; { - object!(guard, LifetimeTracked); + object!(guard, LifetimeTracked::constructor_1()); let mut selector: i32 = 2; 'switch: { match { selector } { 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 626759d5a6..1684990715 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 @@ -21,7 +21,7 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] pub struct LifetimeTracked { pub uses: i32, } @@ -38,26 +38,20 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - 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 ConstructibleFromUnsafe<()> for LifetimeTracked { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for LifetimeTracked { - unsafe fn constructor(this: *mut Self, (_a0,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + 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 CopyConstructibleUnsafe for LifetimeTracked {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -71,7 +65,7 @@ pub unsafe fn test_6() { (unsafe { LifetimeTracked::reset() }); let mut choice: i32 = 9; { - object_unsafe!(guard, LifetimeTracked); + object_unsafe!(guard, LifetimeTracked::constructor_1()); let mut choice: i32 = 0; if (choice != 0) { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); @@ -87,7 +81,7 @@ pub unsafe fn test_6() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (1))); { - object_unsafe!(guard, LifetimeTracked); + object_unsafe!(guard, LifetimeTracked::constructor_1()); let mut choice: i32 = 4; if (choice != 0) { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).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 19f43fc03d..503da79bdc 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 @@ -21,7 +21,7 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] pub struct LifetimeTracked { pub uses: i32, } @@ -38,26 +38,20 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - 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 ConstructibleFromUnsafe<()> for LifetimeTracked { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for LifetimeTracked { - unsafe fn constructor(this: *mut Self, (_a0,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + 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 CopyConstructibleUnsafe for LifetimeTracked {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} impl DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -81,34 +75,22 @@ pub static mut dtorCount_6: std::cell::LazyCell = std::cell::LazyCell::new( )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] -#[conversion_function(i32, const_lvalue_ref)] +#[conversions(copy, move)] +#[conversion_function(conversion_function_1, i32, const_lvalue_ref)] pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { pub value: i32, } -impl - ConversionFunctionUnsafe< - i32, - LvalueRefUnsafe>, - > for p2_condition_variable_lives_for_whole_statement_ConvertsToInt -{ - unsafe fn conversion_function( +impl p2_condition_variable_lives_for_whole_statement_ConvertsToInt { + pub unsafe fn conversion_function_1( this: LvalueRefUnsafe>, - to: *mut i32, + __return: *mut i32, ) { let this = this.as_ptr() as *mut p2_condition_variable_lives_for_whole_statement_ConvertsToInt; - to.write((*this).value); + __return.write((*this).value); return; } } -impl - ImplicitConversionFunctionUnsafe< - i32, - LvalueRefUnsafe>, - > for p2_condition_variable_lives_for_whole_statement_ConvertsToInt -{ -} impl DestructibleUnsafe for p2_condition_variable_lives_for_whole_statement_ConvertsToInt { unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_6)).prefix_inc(); @@ -124,8 +106,8 @@ pub unsafe fn test_7() { 'switch: { match { { - let mut __v: i32 = 0_i32; - p2_condition_variable_lives_for_whole_statement_ConvertsToInt::conversion_function(>>::bind(& mut selector ), &raw mut __v); + let mut __v: i32 = ZeroInitializationUnsafe::zero_init(); + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::conversion_function_1(>>::bind(& mut selector ), &raw mut __v); __v } } { @@ -156,7 +138,7 @@ pub unsafe fn test_10() { (unsafe { LifetimeTracked::reset() }); let mut selector: i32 = 9; { - object_unsafe!(guard, LifetimeTracked); + object_unsafe!(guard, LifetimeTracked::constructor_1()); let mut selector: i32 = 2; 'switch: { match { selector } { diff --git a/tests/std/temp/temp.spec/out/refcount/temp.inst.rs b/tests/std/temp/temp.spec/out/refcount/temp.inst.rs index 384912f0fb..92d37d1efe 100644 --- a/tests/std/temp/temp.spec/out/refcount/temp.inst.rs +++ b/tests/std/temp/temp.spec/out/refcount/temp.inst.rs @@ -17,8 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[constructor( + constructor_2, explicit, const_lvalue_ref(p2_reference_does_not_instantiate_Wrapper_int_) )] @@ -27,17 +28,13 @@ pub struct p2_reference_does_not_instantiate_Member { #[offset(0)] pub value: i32, } -impl ConstructibleFrom<()> for p2_reference_does_not_instantiate_Member { - fn constructor(this: Ptr, _: ()) { +impl p2_reference_does_not_instantiate_Member { + pub fn constructor_1(this: Ptr) { field!(this, value).write(1); } -} -impl ConstructibleFrom<(LvalueRef>,)> - for p2_reference_does_not_instantiate_Member -{ - fn constructor( + pub fn constructor_2( this: Ptr, - (_a0,): (LvalueRef>,), + _a0: LvalueRef>, ) { let _a0 = _a0.as_pointer(); field!(this, value).write(2); @@ -51,23 +48,23 @@ impl Default for p2_reference_does_not_instantiate_Member { #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Default)] #[memberwise(move_constructor)] #[derive(Conversions)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] #[byte_size(4)] pub struct p2_reference_does_not_instantiate_Holder { #[offset(0)] #[byte_size(4)] pub member: p2_reference_does_not_instantiate_Member, } -impl ConstructibleFrom<()> for p2_reference_does_not_instantiate_Holder { - fn constructor(this: Ptr, _: ()) { - >::constructor( - field_ptr!(this, member), - (), - ); +impl p2_reference_does_not_instantiate_Holder { + pub fn constructor_1(this: Ptr) { + p2_reference_does_not_instantiate_Member::constructor_1(field_ptr!(this, member)); } } pub fn test_0() { - object!(holder, p2_reference_does_not_instantiate_Holder); + object!( + holder, + p2_reference_does_not_instantiate_Holder::constructor_1() + ); assert!(({ (*holder.borrow()).member.value } == 1)); (*holder.borrow_mut()).member.value = 3; assert!(({ (*holder.borrow()).member.value } == 3)); @@ -80,25 +77,9 @@ fn main_0() -> i32 { ({ test_0() }); return 0; } -#[derive(Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg)] +#[derive( + Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg, ZeroInitialization, Destructible, Conversions, +)] #[byte_size(1)] pub struct p2_reference_does_not_instantiate_Wrapper_int_; -impl libcc2rs::overload::Conversions for p2_reference_does_not_instantiate_Wrapper_int_ { - fn table() -> libcc2rs::overload::Table { - libcc2rs::overload::Table { - id: ::std::any::TypeId::of::(), - name: "p2_reference_does_not_instantiate_Wrapper_int_", - arithmetic: None, - storage: || Ptr::alloc(p2_reference_does_not_instantiate_Wrapper_int_).to_any(), - release: |ptr| { - ptr.downcast::() - .delete() - }, - copy: |_, _| {}, - move_from: |_, _| {}, - constructors: vec![], - conversion_functions: vec![], - } - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs b/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs index 0d0211beb2..9cf80c318c 100644 --- a/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs +++ b/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs @@ -16,27 +16,22 @@ use std::rc::Rc; TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[constructor( + constructor_2, explicit, const_lvalue_ref(p2_reference_does_not_instantiate_Wrapper_int_) )] pub struct p2_reference_does_not_instantiate_Member { pub value: i32, } -impl ConstructibleFromUnsafe<()> for p2_reference_does_not_instantiate_Member { - unsafe fn constructor(this: *mut Self, _: ()) { +impl p2_reference_does_not_instantiate_Member { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).value).write(1); } -} -impl - ConstructibleFromUnsafe<( - LvalueRefUnsafe>, - )> for p2_reference_does_not_instantiate_Member -{ - unsafe fn constructor( + pub unsafe fn constructor_2( this: *mut Self, - (_a0,): (LvalueRefUnsafe>,), + _a0: LvalueRefUnsafe>, ) { let _a0 = (_a0.as_ptr() as *const p2_reference_does_not_instantiate_Wrapper_int_); (&raw mut (*this).value).write(2); @@ -51,20 +46,20 @@ impl Default for p2_reference_does_not_instantiate_Member { #[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, Default)] #[memberwise(move_constructor)] #[derive(ConversionsUnsafe)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] pub struct p2_reference_does_not_instantiate_Holder { pub member: p2_reference_does_not_instantiate_Member, } -impl ConstructibleFromUnsafe<()> for p2_reference_does_not_instantiate_Holder { - unsafe fn constructor(this: *mut Self, _: ()) { - >::constructor( - &raw mut (*this).member, - (), - ); +impl p2_reference_does_not_instantiate_Holder { + pub unsafe fn constructor_1(this: *mut Self) { + p2_reference_does_not_instantiate_Member::constructor_1(&raw mut (*this).member); } } pub unsafe fn test_0() { - object_unsafe!(holder, p2_reference_does_not_instantiate_Holder); + object_unsafe!( + holder, + p2_reference_does_not_instantiate_Holder::constructor_1() + ); assert!(((holder.member.value) == (1))); holder.member.value = 3; assert!(((holder.member.value) == (3))); @@ -79,27 +74,15 @@ unsafe fn main_0() -> i32 { (unsafe { test_0() }); return 0; } -#[derive(Clone, Copy, Default, VaArg, FnPtrArg)] +#[derive( + Clone, + Copy, + Default, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + ConversionsUnsafe, +)] pub struct p2_reference_does_not_instantiate_Wrapper_int_; -impl libcc2rs::overload::ConversionsUnsafe for p2_reference_does_not_instantiate_Wrapper_int_ { - fn table() -> libcc2rs::overload::Table<*mut ::std::ffi::c_void> { - libcc2rs::overload::Table { - id: ::std::any::TypeId::of::(), - name: "p2_reference_does_not_instantiate_Wrapper_int_", - arithmetic: None, - storage: || { - Box::into_raw(Box::new(p2_reference_does_not_instantiate_Wrapper_int_)).cast() - }, - release: |ptr| { - drop(unsafe { - Box::from_raw(ptr.cast::()) - }) - }, - copy: |_, _| {}, - move_from: |_, _| {}, - constructors: vec![], - conversion_functions: vec![], - } - } -} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/utilities/pairs/out/refcount/pairs.pair.rs b/tests/std/utilities/pairs/out/refcount/pairs.pair.rs index f03762e85a..184b311b16 100644 --- a/tests/std/utilities/pairs/out/refcount/pairs.pair.rs +++ b/tests/std/utilities/pairs/out/refcount/pairs.pair.rs @@ -85,14 +85,16 @@ pub fn test_2() { ))); let mut original: Ptr = ({ (*(*source.borrow()).1.borrow()).as_pointer() }); let converted: Value<(Value, Value>>)> = Rc::new(RefCell::new({ - object!(__first, i64, |__this| Conversions::construct( + object!(__first, i64, |__this| ConstructibleFrom::construct( __this, - &[overload::Arg::rvalue((*source.borrow()).0.as_pointer())] + (RvalueRef::::bind((*source.borrow()).0.as_pointer()),) )); object!(__second, Option>, |__this| { - Conversions::construct( + ConstructibleFrom::construct( __this, - &[overload::Arg::rvalue((*source.borrow()).1.as_pointer())], + (RvalueRef::>>::bind( + (*source.borrow()).1.as_pointer(), + ),), ) }); ( @@ -116,14 +118,16 @@ pub fn test_3() { Rc::new(RefCell::new(None)), ))); { - object!(__first, i64, |__this| Conversions::convert( - __this, - overload::Arg::rvalue((*source.borrow()).0.as_pointer()) - )); - object!(__second, Option>, |__this| Conversions::convert( - __this, - overload::Arg::rvalue((*source.borrow()).1.as_pointer()) + object!(__first, i64, |__this| ConvertibleTo::convert( + RvalueRef::::bind((*source.borrow()).0.as_pointer()), + __this )); + object!(__second, Option>, |__this| { + ConvertibleTo::convert( + RvalueRef::>>::bind((*source.borrow()).1.as_pointer()), + __this, + ) + }); MoveAssignable::move_assign( (*target.borrow()).0.as_pointer(), RvalueRef::::bind(__first.as_pointer()), diff --git a/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs b/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs index 2ea680b170..e6f8a48fc7 100644 --- a/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs +++ b/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs @@ -78,12 +78,15 @@ pub unsafe fn test_2() { .as_deref_mut() .map_or(::std::ptr::null_mut(), |v| v as *mut i32); let mut converted: (i64, Option>) = { - object_unsafe!(__first, i64, |__this| ConversionsUnsafe::construct( + object_unsafe!(__first, i64, |__this| ConstructibleFromUnsafe::construct( __this, - &[overload::Arg::rvalue_unsafe(&raw mut source.0)] + (RvalueRefUnsafe::::bind(&raw mut source.0),) )); object_unsafe!(__second, Option>, |__this| { - ConversionsUnsafe::construct(__this, &[overload::Arg::rvalue_unsafe(&raw mut source.1)]) + ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::>>::bind(&raw mut source.1),), + ) }); ( move_constructed_unsafe(&raw mut __first), @@ -122,12 +125,15 @@ pub unsafe fn test_3() { .map_or(::std::ptr::null_mut(), |v| v as *mut i32); let mut target: (i64, Option>) = (0_i64, None); { - object_unsafe!(__first, i64, |__this| ConversionsUnsafe::convert( - __this, - overload::Arg::rvalue_unsafe(&raw mut source.0) + object_unsafe!(__first, i64, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut source.0), + __this )); object_unsafe!(__second, Option>, |__this| { - ConversionsUnsafe::convert(__this, overload::Arg::rvalue_unsafe(&raw mut source.1)) + ConvertibleToUnsafe::convert( + RvalueRefUnsafe::>>::bind(&raw mut source.1), + __this, + ) }); MoveAssignableUnsafe::move_assign( &raw mut target.0, diff --git a/tests/std/utilities/utility/out/refcount/forward-helpers.rs b/tests/std/utilities/utility/out/refcount/forward-helpers.rs index 983d287cf5..2dce2f0ebe 100644 --- a/tests/std/utilities/utility/out/refcount/forward-helpers.rs +++ b/tests/std/utilities/utility/out/refcount/forward-helpers.rs @@ -17,52 +17,40 @@ pub fn test_0() { #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct p6_forward_like_Movable { #[offset(0)] pub value: i32, } -impl ConstructibleFrom<(i32,)> for p6_forward_like_Movable { - fn constructor(this: Ptr, (mut value,): (i32,)) { +impl p6_forward_like_Movable { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for p6_forward_like_Movable { - fn constructor(this: Ptr, (other,): (LvalueRef>,)) { + pub fn constructor_2(this: Ptr, other: LvalueRef>) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); } -} -impl CopyConstructible for p6_forward_like_Movable {} -impl ConvertibleTo for LvalueRef> {} -impl ConstructibleFrom<(RvalueRef,)> for p6_forward_like_Movable { - fn constructor(this: Ptr, (other,): (RvalueRef,)) { + pub fn constructor_3(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } -impl MoveConstructible for p6_forward_like_Movable {} -impl ConvertibleTo for RvalueRef {} #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise)] #[memberwise(copy_constructor, move_constructor)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct p6_forward_like_Holder { #[offset(0)] #[byte_size(4)] pub member: p6_forward_like_Movable, } -impl ConstructibleFrom<()> for p6_forward_like_Holder { - fn constructor(this: Ptr, _: ()) { - >::constructor( - field_ptr!(this, member), - (1,), - ); +impl p6_forward_like_Holder { + pub fn constructor_1(this: Ptr) { + p6_forward_like_Movable::constructor_1(field_ptr!(this, member), 1); } } impl Default for p6_forward_like_Holder { @@ -71,11 +59,8 @@ impl Default for p6_forward_like_Holder { p6_forward_like_Holder { member: { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >::constructor( - __v.as_pointer(), - (1,), - ); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p6_forward_like_Movable::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, } @@ -83,15 +68,21 @@ impl Default for p6_forward_like_Holder { } } pub fn take_1(__return: Ptr, self_: Ptr) { - >,)>>::constructor(__return.clone(), (LvalueRef::bind(field_ptr!(self_ , member) ),)) ; + p6_forward_like_Movable::constructor_2( + __return.clone(), + LvalueRef::bind(field_ptr!(self_, member)), + ); return; } pub fn take_2(__return: Ptr, self_: Ptr) { - ,)>>::constructor(__return.clone(), (RvalueRef::bind(field_ptr!(self_ , member) ),)) ; + p6_forward_like_Movable::constructor_3( + __return.clone(), + RvalueRef::bind(field_ptr!(self_, member)), + ); return; } pub fn test_3() { - object!(holder, p6_forward_like_Holder); + object!(holder, p6_forward_like_Holder::constructor_1()); object!(copied, p6_forward_like_Movable, |copied| ({ take_1(Ptr::clone(&copied.clone()), holder.as_pointer()) })); @@ -104,28 +95,23 @@ pub fn test_3() { #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[conversions(move)] -#[constructor(value(i32))] +#[conversions(move = constructor_2)] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct p9_move_Movable { #[offset(0)] pub value: i32, } -impl ConstructibleFrom<(i32,)> for p9_move_Movable { - fn constructor(this: Ptr, (mut value,): (i32,)) { +impl p9_move_Movable { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(RvalueRef,)> for p9_move_Movable { - fn constructor(this: Ptr, (other,): (RvalueRef,)) { + pub fn constructor_2(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } -impl MoveConstructible for p9_move_Movable {} -impl ConvertibleTo for RvalueRef {} pub fn test_4() { let mut number: i32 = 1; let mut moved: i32 = number; @@ -137,10 +123,10 @@ pub fn test_4() { ({ (moved_pointer).clone() } == { (target.as_pointer()) }) && ({ (pointer).clone() } == { (target.as_pointer()) }) ); - object!(source, p9_move_Movable, (i32,), (3,)); + object!(source, p9_move_Movable::constructor_1(3)); object!( destination, - p9_move_Movable = >::bind(source.as_pointer()) + p9_move_Movable::constructor_2(RvalueRef::bind(source.as_pointer())) ); assert!(({ (*destination.borrow()).value } == 3) && ({ (*source.borrow()).value } == 0)); let strings: Value>> = Rc::new(RefCell::new(Vec::new())); @@ -163,8 +149,8 @@ pub fn test_4() { ); } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] #[byte_size(12)] pub struct p10_forward_in_template_A { #[offset(0)] @@ -174,26 +160,19 @@ pub struct p10_forward_in_template_A { #[offset(8)] pub moves: i32, } -impl ConstructibleFrom<(i32,)> for p10_forward_in_template_A { - fn constructor(this: Ptr, (mut value,): (i32,)) { +impl p10_forward_in_template_A { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for p10_forward_in_template_A { - fn constructor(this: Ptr, (other,): (LvalueRef>,)) { + pub fn constructor_2(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 CopyConstructible for p10_forward_in_template_A {} -impl ConvertibleTo for LvalueRef> {} -impl ConstructibleFrom<(RvalueRef,)> for p10_forward_in_template_A { - fn constructor(this: Ptr, (other,): (RvalueRef,)) { + pub fn constructor_3(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); field!(this, copies).write(0); @@ -201,25 +180,21 @@ impl ConstructibleFrom<(RvalueRef,)> for p10_forward_in_template_A { field!(other, value).write(0); } } -impl MoveConstructible for p10_forward_in_template_A {} -impl ConvertibleTo for RvalueRef {} impl Default for p10_forward_in_template_A { fn default() -> Self { { ::zero_init() } } } pub fn make_5(__return: Ptr, source: Ptr) { - >, - )>>::constructor(__return.clone(), (LvalueRef::bind((source).clone()),)); + p10_forward_in_template_A::constructor_2(__return.clone(), LvalueRef::bind((source).clone())); return; } pub fn make_6(__return: Ptr, source: Ptr) { - ,)>>::constructor(__return.clone(), (RvalueRef::bind((source ).clone() ),)) ; + p10_forward_in_template_A::constructor_3(__return.clone(), RvalueRef::bind((source).clone())); return; } pub fn test_7() { - object!(a, p10_forward_in_template_A, (i32,), (1,)); + object!(a, p10_forward_in_template_A::constructor_1(1)); object!(copied, p10_forward_in_template_A, |copied| ({ make_5(Ptr::clone(&copied.clone()), a.as_pointer()) })); @@ -240,100 +215,74 @@ pub fn test_7() { #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct p11_move_if_noexcept_NoexceptMove { #[offset(0)] pub value: i32, } -impl ConstructibleFrom<(i32,)> for p11_move_if_noexcept_NoexceptMove { - fn constructor(this: Ptr, (mut value,): (i32,)) { +impl p11_move_if_noexcept_NoexceptMove { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for p11_move_if_noexcept_NoexceptMove { - fn constructor( + pub fn constructor_2( this: Ptr, - (other,): (LvalueRef>,), + other: LvalueRef>, ) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); } -} -impl CopyConstructible for p11_move_if_noexcept_NoexceptMove {} -impl ConvertibleTo - for LvalueRef> -{ -} -impl ConstructibleFrom<(RvalueRef,)> for p11_move_if_noexcept_NoexceptMove { - fn constructor(this: Ptr, (other,): (RvalueRef,)) { + pub fn constructor_3(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } -impl MoveConstructible for p11_move_if_noexcept_NoexceptMove {} -impl ConvertibleTo - for RvalueRef -{ -} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct p11_move_if_noexcept_ThrowingMove { #[offset(0)] pub value: i32, } -impl ConstructibleFrom<(i32,)> for p11_move_if_noexcept_ThrowingMove { - fn constructor(this: Ptr, (mut value,): (i32,)) { +impl p11_move_if_noexcept_ThrowingMove { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for p11_move_if_noexcept_ThrowingMove { - fn constructor( + pub fn constructor_2( this: Ptr, - (other,): (LvalueRef>,), + other: LvalueRef>, ) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); } -} -impl CopyConstructible for p11_move_if_noexcept_ThrowingMove {} -impl ConvertibleTo - for LvalueRef> -{ -} -impl ConstructibleFrom<(RvalueRef,)> for p11_move_if_noexcept_ThrowingMove { - fn constructor(this: Ptr, (other,): (RvalueRef,)) { + pub fn constructor_3(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } -impl MoveConstructible for p11_move_if_noexcept_ThrowingMove {} -impl ConvertibleTo - for RvalueRef -{ -} pub fn test_8() { - object!(moved_from, p11_move_if_noexcept_NoexceptMove, (i32,), (1,)); + object!( + moved_from, + p11_move_if_noexcept_NoexceptMove::constructor_1(1) + ); object!( moved, - p11_move_if_noexcept_NoexceptMove, - RvalueRef::bind(moved_from.as_pointer()) + p11_move_if_noexcept_NoexceptMove::constructor_3(RvalueRef::bind(moved_from.as_pointer())) ); assert!(({ (*moved.borrow()).value } == 1) && ({ (*moved_from.borrow()).value } == 0)); - object!(copied_from, p11_move_if_noexcept_ThrowingMove, (i32,), (2,)); + object!( + copied_from, + p11_move_if_noexcept_ThrowingMove::constructor_1(2) + ); object!( copied, - p11_move_if_noexcept_ThrowingMove, - LvalueRef::bind(copied_from.as_pointer()) + p11_move_if_noexcept_ThrowingMove::constructor_2(LvalueRef::bind(copied_from.as_pointer())) ); assert!(({ (*copied.borrow()).value } == 2) && ({ (*copied_from.borrow()).value } == 2)); } diff --git a/tests/std/utilities/utility/out/refcount/forward.rs b/tests/std/utilities/utility/out/refcount/forward.rs index 432c01ac08..06a743bab8 100644 --- a/tests/std/utilities/utility/out/refcount/forward.rs +++ b/tests/std/utilities/utility/out/refcount/forward.rs @@ -62,38 +62,33 @@ pub fn test_1() { #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[conversions(move)] -#[constructor(value(i32))] +#[conversions(move = constructor_2)] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct p10_move_constructor_A { #[offset(0)] pub value: i32, } -impl ConstructibleFrom<(i32,)> for p10_move_constructor_A { - fn constructor(this: Ptr, (mut value,): (i32,)) { +impl p10_move_constructor_A { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(RvalueRef,)> for p10_move_constructor_A { - fn constructor(this: Ptr, (other,): (RvalueRef,)) { + pub fn constructor_2(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } -impl MoveConstructible for p10_move_constructor_A {} -impl ConvertibleTo for RvalueRef {} pub fn test_2() { - object!(source, p10_move_constructor_A, (i32,), (1,)); + object!(source, p10_move_constructor_A::constructor_1(1)); object!( target, - p10_move_constructor_A = >::bind(source.as_pointer()) + p10_move_constructor_A::constructor_2(RvalueRef::bind(source.as_pointer())) ); assert!(({ (*target.borrow()).value } == 1)); assert!(({ (*source.borrow()).value } == 0)); let values: Value> = Rc::new(RefCell::new(Vec::new())); - object!(element, p10_move_constructor_A, (i32,), (2,)); + object!(element, p10_move_constructor_A::constructor_1(2)); MoveConstructible::push_moved(&values.as_pointer(), element.as_pointer()); assert!(({ (*values.borrow())[0_usize].value } == 2)); assert!(({ (*element.borrow()).value } == 0)); diff --git a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs index 88ffcadaa1..f7289d5e86 100644 --- a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs +++ b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs @@ -18,54 +18,39 @@ pub unsafe fn test_0() { #[derive( FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] pub struct p6_forward_like_Movable { pub value: i32, } -impl ConstructibleFromUnsafe<(i32,)> for p6_forward_like_Movable { - unsafe fn constructor(this: *mut Self, (mut value,): (i32,)) { +impl p6_forward_like_Movable { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for p6_forward_like_Movable { - unsafe fn constructor( + pub unsafe fn constructor_2( this: *mut Self, - (other,): (LvalueRefUnsafe>,), + other: LvalueRefUnsafe>, ) { let other = (other.as_ptr() as *const p6_forward_like_Movable); (&raw mut (*this).value).write((*other).value); } -} -impl CopyConstructibleUnsafe for p6_forward_like_Movable {} -impl ConvertibleToUnsafe - for LvalueRefUnsafe> -{ -} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for p6_forward_like_Movable { - unsafe fn constructor(this: *mut Self, (other,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_3(this: *mut Self, other: RvalueRefUnsafe) { let other = (other.as_ptr() as *mut p6_forward_like_Movable); (&raw mut (*this).value).write((*other).value); (*other).value = 0; } } -impl MoveConstructibleUnsafe for p6_forward_like_Movable {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} #[repr(C)] #[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe)] #[memberwise(copy_constructor, move_constructor)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct p6_forward_like_Holder { pub member: p6_forward_like_Movable, } -impl ConstructibleFromUnsafe<()> for p6_forward_like_Holder { - unsafe fn constructor(this: *mut Self, _: ()) { - >::constructor( - &raw mut (*this).member, - (1,), - ); +impl p6_forward_like_Holder { + pub unsafe fn constructor_1(this: *mut Self) { + p6_forward_like_Movable::constructor_1(&raw mut (*this).member, 1); } } impl Default for p6_forward_like_Holder { @@ -73,11 +58,8 @@ impl Default for p6_forward_like_Holder { unsafe { p6_forward_like_Holder { member: { - let mut __v: p6_forward_like_Movable = ::zero_init(); - >::constructor( - &raw mut __v, - (1,), - ); + let mut __v: p6_forward_like_Movable = ZeroInitializationUnsafe::zero_init(); + p6_forward_like_Movable::constructor_1(&raw mut __v, 1); __v }, } @@ -85,19 +67,15 @@ impl Default for p6_forward_like_Holder { } } pub unsafe fn take_1(__return: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { - >, - )>>::constructor(__return, (LvalueRefUnsafe::bind(&(*self_).member),)); + p6_forward_like_Movable::constructor_2(__return, LvalueRefUnsafe::bind(&(*self_).member)); return; } pub unsafe fn take_2(__return: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { - , - )>>::constructor(__return, (RvalueRefUnsafe::bind(&mut (*self_).member),)); + p6_forward_like_Movable::constructor_3(__return, RvalueRefUnsafe::bind(&mut (*self_).member)); return; } pub unsafe fn test_3() { - object_unsafe!(holder, p6_forward_like_Holder); + object_unsafe!(holder, p6_forward_like_Holder::constructor_1()); object_unsafe!(copied, p6_forward_like_Movable, |copied| (unsafe { take_1(copied, &mut holder) })); @@ -111,26 +89,21 @@ pub unsafe fn test_3() { #[derive( FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[conversions(move)] -#[constructor(value(i32))] +#[conversions(move = constructor_2)] +#[constructor(constructor_1, value(i32))] pub struct p9_move_Movable { pub value: i32, } -impl ConstructibleFromUnsafe<(i32,)> for p9_move_Movable { - unsafe fn constructor(this: *mut Self, (mut value,): (i32,)) { +impl p9_move_Movable { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for p9_move_Movable { - unsafe fn constructor(this: *mut Self, (other,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_2(this: *mut Self, other: RvalueRefUnsafe) { let other = (other.as_ptr() as *mut p9_move_Movable); (&raw mut (*this).value).write((*other).value); (*other).value = 0; } } -impl MoveConstructibleUnsafe for p9_move_Movable {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} pub unsafe fn test_4() { let mut number: i32 = 1; let mut moved: i32 = number; @@ -141,10 +114,10 @@ pub unsafe fn test_4() { assert!( ((moved_pointer) == (&mut target as *mut i32)) && ((pointer) == (&mut target as *mut i32)) ); - object_unsafe!(source, p9_move_Movable, (i32,), (3,)); + object_unsafe!(source, p9_move_Movable::constructor_1(3)); object_unsafe!( destination, - p9_move_Movable = >::bind(&mut source) + p9_move_Movable::constructor_2(RvalueRefUnsafe::bind(&mut source)) ); assert!(((destination.value) == (3)) && ((source.value) == (0))); let mut strings: Vec> = Vec::new(); @@ -166,41 +139,31 @@ pub unsafe fn test_4() { } #[repr(C)] #[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] pub struct p10_forward_in_template_A { pub value: i32, pub copies: i32, pub moves: i32, } -impl ConstructibleFromUnsafe<(i32,)> for p10_forward_in_template_A { - unsafe fn constructor(this: *mut Self, (mut value,): (i32,)) { +impl p10_forward_in_template_A { + pub unsafe fn constructor_1(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 ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for p10_forward_in_template_A { - unsafe fn constructor( + pub unsafe fn constructor_2( this: *mut Self, - (other,): (LvalueRefUnsafe>,), + other: LvalueRefUnsafe>, ) { let other = (other.as_ptr() as *const p10_forward_in_template_A); (&raw mut (*this).value).write((*other).value); (&raw mut (*this).copies).write((((*other).copies) + (1))); (&raw mut (*this).moves).write(0); } -} -impl CopyConstructibleUnsafe for p10_forward_in_template_A {} -impl ConvertibleToUnsafe - for LvalueRefUnsafe> -{ -} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for p10_forward_in_template_A { - unsafe fn constructor( + pub unsafe fn constructor_3( this: *mut Self, - (other,): (RvalueRefUnsafe,), + other: RvalueRefUnsafe, ) { let other = (other.as_ptr() as *mut p10_forward_in_template_A); (&raw mut (*this).value).write((*other).value); @@ -209,8 +172,6 @@ impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for p10_forward_in_templa (*other).value = 0; } } -impl MoveConstructibleUnsafe for p10_forward_in_template_A {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} impl Default for p10_forward_in_template_A { fn default() -> Self { unsafe { ::zero_init() } @@ -220,22 +181,18 @@ pub unsafe fn make_5( __return: *mut p10_forward_in_template_A, source: *mut p10_forward_in_template_A, ) { - >, - )>>::constructor(__return, (LvalueRefUnsafe::bind(source),)); + p10_forward_in_template_A::constructor_2(__return, LvalueRefUnsafe::bind(source)); return; } pub unsafe fn make_6( __return: *mut p10_forward_in_template_A, source: *mut p10_forward_in_template_A, ) { - , - )>>::constructor(__return, (RvalueRefUnsafe::bind(source),)); + p10_forward_in_template_A::constructor_3(__return, RvalueRefUnsafe::bind(source)); return; } pub unsafe fn test_7() { - object_unsafe!(a, p10_forward_in_template_A, (i32,), (1,)); + object_unsafe!(a, p10_forward_in_template_A::constructor_1(1)); object_unsafe!(copied, p10_forward_in_template_A, |copied| (unsafe { make_5(copied, &mut a) })); @@ -251,107 +208,77 @@ pub unsafe fn test_7() { #[derive( FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] pub struct p11_move_if_noexcept_NoexceptMove { pub value: i32, } -impl ConstructibleFromUnsafe<(i32,)> for p11_move_if_noexcept_NoexceptMove { - unsafe fn constructor(this: *mut Self, (mut value,): (i32,)) { +impl p11_move_if_noexcept_NoexceptMove { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> - for p11_move_if_noexcept_NoexceptMove -{ - unsafe fn constructor( + pub unsafe fn constructor_2( this: *mut Self, - (other,): (LvalueRefUnsafe>,), + other: LvalueRefUnsafe>, ) { let other = (other.as_ptr() as *const p11_move_if_noexcept_NoexceptMove); (&raw mut (*this).value).write((*other).value); } -} -impl CopyConstructibleUnsafe for p11_move_if_noexcept_NoexceptMove {} -impl ConvertibleToUnsafe - for LvalueRefUnsafe> -{ -} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for p11_move_if_noexcept_NoexceptMove { - unsafe fn constructor( + pub unsafe fn constructor_3( this: *mut Self, - (other,): (RvalueRefUnsafe,), + other: RvalueRefUnsafe, ) { let other = (other.as_ptr() as *mut p11_move_if_noexcept_NoexceptMove); (&raw mut (*this).value).write((*other).value); (*other).value = 0; } } -impl MoveConstructibleUnsafe for p11_move_if_noexcept_NoexceptMove {} -impl ConvertibleToUnsafe - for RvalueRefUnsafe -{ -} #[repr(C)] #[derive( FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] pub struct p11_move_if_noexcept_ThrowingMove { pub value: i32, } -impl ConstructibleFromUnsafe<(i32,)> for p11_move_if_noexcept_ThrowingMove { - unsafe fn constructor(this: *mut Self, (mut value,): (i32,)) { +impl p11_move_if_noexcept_ThrowingMove { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> - for p11_move_if_noexcept_ThrowingMove -{ - unsafe fn constructor( + pub unsafe fn constructor_2( this: *mut Self, - (other,): (LvalueRefUnsafe>,), + other: LvalueRefUnsafe>, ) { let other = (other.as_ptr() as *const p11_move_if_noexcept_ThrowingMove); (&raw mut (*this).value).write((*other).value); } -} -impl CopyConstructibleUnsafe for p11_move_if_noexcept_ThrowingMove {} -impl ConvertibleToUnsafe - for LvalueRefUnsafe> -{ -} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for p11_move_if_noexcept_ThrowingMove { - unsafe fn constructor( + pub unsafe fn constructor_3( this: *mut Self, - (other,): (RvalueRefUnsafe,), + other: RvalueRefUnsafe, ) { let other = (other.as_ptr() as *mut p11_move_if_noexcept_ThrowingMove); (&raw mut (*this).value).write((*other).value); (*other).value = 0; } } -impl MoveConstructibleUnsafe for p11_move_if_noexcept_ThrowingMove {} -impl ConvertibleToUnsafe - for RvalueRefUnsafe -{ -} pub unsafe fn test_8() { - object_unsafe!(moved_from, p11_move_if_noexcept_NoexceptMove, (i32,), (1,)); + object_unsafe!( + moved_from, + p11_move_if_noexcept_NoexceptMove::constructor_1(1) + ); object_unsafe!( moved, - p11_move_if_noexcept_NoexceptMove, - RvalueRefUnsafe::bind(&mut moved_from) + p11_move_if_noexcept_NoexceptMove::constructor_3(RvalueRefUnsafe::bind(&mut moved_from)) ); assert!(((moved.value) == (1)) && ((moved_from.value) == (0))); - object_unsafe!(copied_from, p11_move_if_noexcept_ThrowingMove, (i32,), (2,)); + object_unsafe!( + copied_from, + p11_move_if_noexcept_ThrowingMove::constructor_1(2) + ); object_unsafe!( copied, - p11_move_if_noexcept_ThrowingMove, - LvalueRefUnsafe::bind(&copied_from) + p11_move_if_noexcept_ThrowingMove::constructor_2(LvalueRefUnsafe::bind(&copied_from)) ); assert!(((copied.value) == (2)) && ((copied_from.value) == (2))); } diff --git a/tests/std/utilities/utility/out/unsafe/forward.rs b/tests/std/utilities/utility/out/unsafe/forward.rs index 4ca7f25bc4..f911a28d73 100644 --- a/tests/std/utilities/utility/out/unsafe/forward.rs +++ b/tests/std/utilities/utility/out/unsafe/forward.rs @@ -53,36 +53,31 @@ pub unsafe fn test_1() { #[derive( FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[conversions(move)] -#[constructor(value(i32))] +#[conversions(move = constructor_2)] +#[constructor(constructor_1, value(i32))] pub struct p10_move_constructor_A { pub value: i32, } -impl ConstructibleFromUnsafe<(i32,)> for p10_move_constructor_A { - unsafe fn constructor(this: *mut Self, (mut value,): (i32,)) { +impl p10_move_constructor_A { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for p10_move_constructor_A { - unsafe fn constructor(this: *mut Self, (other,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_2(this: *mut Self, other: RvalueRefUnsafe) { let other = (other.as_ptr() as *mut p10_move_constructor_A); (&raw mut (*this).value).write((*other).value); (*other).value = 0; } } -impl MoveConstructibleUnsafe for p10_move_constructor_A {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} pub unsafe fn test_2() { - object_unsafe!(source, p10_move_constructor_A, (i32,), (1,)); + object_unsafe!(source, p10_move_constructor_A::constructor_1(1)); object_unsafe!( target, - p10_move_constructor_A = >::bind(&mut source) + p10_move_constructor_A::constructor_2(RvalueRefUnsafe::bind(&mut source)) ); assert!(((target.value) == (1))); assert!(((source.value) == (0))); let mut values: Vec = Vec::new(); - object_unsafe!(element, p10_move_constructor_A, (i32,), (2,)); + object_unsafe!(element, p10_move_constructor_A::constructor_1(2)); values.push_moved(&mut element); assert!(((values[(0_usize)].value) == (2))); assert!(((element.value) == (0))); diff --git a/tests/ub/out/refcount/ctor_ref_member.rs b/tests/ub/out/refcount/ctor_ref_member.rs index 3b40ddf3a1..9ae5b1509a 100644 --- a/tests/ub/out/refcount/ctor_ref_member.rs +++ b/tests/ub/out/refcount/ctor_ref_member.rs @@ -19,20 +19,19 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(const_lvalue_ref(i32))] +#[constructor(constructor_1, const_lvalue_ref(i32))] #[byte_size(8)] pub struct S { #[offset(0)] #[byte_size(8)] pub r: Ptr, } -impl ConstructibleFrom<(LvalueRef>,)> for S { - fn constructor(this: Ptr, (x,): (LvalueRef>,)) { +impl S { + pub fn constructor_1(this: Ptr, x: LvalueRef>) { let x = x.as_pointer(); field!(this, r).write((x).clone()); } } -impl ConvertibleTo for LvalueRef> {} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -40,10 +39,7 @@ pub fn main() { fn main_0() -> i32 { object!(s, S, |s| { let __tmp_0: Value = Rc::new(RefCell::new(5)); - >,)>>::constructor( - s.clone(), - (LvalueRef::bind(__tmp_0.as_pointer()),), - ) + S::constructor_1(s.clone(), LvalueRef::bind(__tmp_0.as_pointer())) }); assert!((({ (*s.borrow()).r.clone() }.read()) == 5)); return 0; diff --git a/tests/ub/out/unsafe/ctor_ref_member.rs b/tests/ub/out/unsafe/ctor_ref_member.rs index b90fcad310..8119c89611 100644 --- a/tests/ub/out/unsafe/ctor_ref_member.rs +++ b/tests/ub/out/unsafe/ctor_ref_member.rs @@ -19,17 +19,16 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(const_lvalue_ref(i32))] +#[constructor(constructor_1, const_lvalue_ref(i32))] pub struct S { pub r: *const i32, } -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for S { - unsafe fn constructor(this: *mut Self, (x,): (LvalueRefUnsafe>,)) { +impl S { + pub unsafe fn constructor_1(this: *mut Self, x: LvalueRefUnsafe>) { let x = (x.as_ptr() as *const i32); (&raw mut (*this).r).write(x); } } -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -39,10 +38,7 @@ pub fn main() { unsafe fn main_0() -> i32 { object_unsafe!(s, S, |s| { let mut __tmp_0: i32 = 5; - >,)>>::constructor( - s, - (LvalueRefUnsafe::bind(&mut __tmp_0),), - ) + S::constructor_1(s, LvalueRefUnsafe::bind(&mut __tmp_0)) }); assert!(((*s.r) == (5))); return 0; diff --git a/tests/unit/out/refcount/10_struct.rs b/tests/unit/out/refcount/10_struct.rs index 8dd3156b71..ab334d1d06 100644 --- a/tests/unit/out/refcount/10_struct.rs +++ b/tests/unit/out/refcount/10_struct.rs @@ -63,21 +63,19 @@ impl Graph { #[derive( Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] -#[constructor(explicit, value(Ptr< i32 > ))] +#[conversions(copy, move, default = constructor_1)] +#[constructor(constructor_2, explicit, value(Ptr< i32 > ))] #[byte_size(8)] pub struct Partial { #[offset(0)] #[byte_size(8)] pub p: Ptr, } -impl ConstructibleFrom<()> for Partial { - fn constructor(this: Ptr, _: ()) { +impl Partial { + pub fn constructor_1(this: Ptr) { field!(this, p).write(Ptr::::null()); } -} -impl ConstructibleFrom<(Ptr,)> for Partial { - fn constructor(this: Ptr, (mut q,): (Ptr,)) { + pub fn constructor_2(this: Ptr, mut q: Ptr) { field!(this, p).write((q).clone()); } } @@ -106,6 +104,7 @@ impl Default for Partial { #[conversions(copy, move)] #[byte_size(1)] pub struct Declared {} +impl Declared {} #[derive( Clone, Record, @@ -137,11 +136,11 @@ fn main_0() -> i32 { adj: Ptr::>::null(), }; let arr: Value> = Rc::new(RefCell::new(Box::new([3, 1, 4]))); - object!(it, Partial, (Ptr,), (arr.decay(),)); + object!(it, Partial::constructor_2(arr.decay())); if ({ { (*it.borrow()).p.clone() } } != { arr.decay() }) { return 1; } - object!(def, Partial); + object!(def, Partial::constructor_1()); if !(({ (*def.borrow()).p.clone() }).is_null()) { return 1; } diff --git a/tests/unit/out/refcount/any.rs b/tests/unit/out/refcount/any.rs index 28d652d13f..5cde8a2da3 100644 --- a/tests/unit/out/refcount/any.rs +++ b/tests/unit/out/refcount/any.rs @@ -20,7 +20,7 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(value(i32), value(i32))] +#[constructor(constructor_1, value(i32), value(i32))] #[byte_size(8)] pub struct Point { #[offset(0)] @@ -28,8 +28,8 @@ pub struct Point { #[offset(4)] pub y: i32, } -impl ConstructibleFrom<(i32, i32)> for Point { - fn constructor(this: Ptr, (mut x, mut y): (i32, i32)) { +impl Point { + pub fn constructor_1(this: Ptr, mut x: i32, mut y: i32) { field!(this, x).write(x); field!(this, y).write(y); } @@ -41,8 +41,8 @@ pub fn main() { fn main_0() -> i32 { let a: Value>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (3, 4)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Point::constructor_1(__v.as_pointer(), 3, 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))))); assert!(({ (*a.borrow()).is_some() })); @@ -81,8 +81,8 @@ fn main_0() -> i32 { let q: Ptr = { let mut __tmp_2 = { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (5, 6)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Point::constructor_1(__v.as_pointer(), 5, 6); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; diff --git a/tests/unit/out/refcount/array_of_noncopy_struct.rs b/tests/unit/out/refcount/array_of_noncopy_struct.rs index 6da7ea0a95..a98ef9ef4a 100644 --- a/tests/unit/out/refcount/array_of_noncopy_struct.rs +++ b/tests/unit/out/refcount/array_of_noncopy_struct.rs @@ -20,7 +20,7 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(32)] pub struct NonCopy { #[offset(0)] @@ -29,8 +29,8 @@ pub struct NonCopy { #[offset(24)] pub tag: i32, } -impl ConstructibleFrom<()> for NonCopy { - fn constructor(this: Ptr, _: ()) { +impl NonCopy { + pub fn constructor_1(this: Ptr) { field!(this, data).write(Vec::new()); field!(this, tag).write(0); } @@ -52,8 +52,8 @@ pub fn main() { fn main_0() -> i32 { let arr: Value> = Rc::new(RefCell::new(Box::new( std::array::from_fn::<_, 3, _>(|_| { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + NonCopy::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }), ))); diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index 85038293f5..fd6f2af5aa 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -2398,15 +2398,15 @@ pub fn test_stable_containers_58() { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(24)] pub struct Counts_59 { #[offset(0)] #[byte_size(24)] pub counts: Vec, } -impl ConstructibleFrom<()> for Counts_59 { - fn constructor(this: Ptr, _: ()) { +impl Counts_59 { + pub fn constructor_1(this: Ptr) { field!(this, counts).write(Vec::new()); } } diff --git a/tests/unit/out/refcount/cast.rs b/tests/unit/out/refcount/cast.rs index 6c1acbc070..28d326ca55 100644 --- a/tests/unit/out/refcount/cast.rs +++ b/tests/unit/out/refcount/cast.rs @@ -104,7 +104,7 @@ impl Default for Grid { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(32)] pub struct Bag { #[offset(0)] @@ -113,8 +113,8 @@ pub struct Bag { #[byte_size(24)] pub items: Vec, } -impl ConstructibleFrom<()> for Bag { - fn constructor(this: Ptr, _: ()) { +impl Bag { + pub fn constructor_1(this: Ptr) { field!(this, n).write(0_i32); field!(this, items).write(Vec::new()); } @@ -388,7 +388,7 @@ pub fn nested_5() { assert!(({ ((*m.borrow())[(1) as usize][(1) as usize] == 42) })); assert!(({ (pm).clone() } == { (m.decay().offset(1).decay().offset(1)) })); assert!(({ (pm).clone() } < { (m.decay().offset(2).decay().offset(0)) })); - object!(b, Bag); + object!(b, Bag::constructor_1()); if 4_usize > (*b.borrow()).items.capacity() as usize { let len_0 = (*b.borrow()).items.len(); (*b.borrow_mut()) diff --git a/tests/unit/out/refcount/class_templates.rs b/tests/unit/out/refcount/class_templates.rs index f3e5252276..9b47f5d1ae 100644 --- a/tests/unit/out/refcount/class_templates.rs +++ b/tests/unit/out/refcount/class_templates.rs @@ -21,7 +21,7 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(24)] pub struct MyContainer_int_ { #[offset(0)] @@ -48,9 +48,7 @@ impl MyContainer_int_ { pub fn push_back(this: Ptr, item: Ptr) { CopyConstructible::push_copied(&field_ref!(this, vec_).as_pointer(), (item).clone()); } -} -impl ConstructibleFrom<()> for MyContainer_int_ { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, vec_).write(Vec::new()); } } @@ -69,7 +67,7 @@ impl ConstructibleFrom<()> for MyContainer_int_ { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(24)] pub struct MyContainer_char_ { #[offset(0)] @@ -96,9 +94,7 @@ impl MyContainer_char_ { pub fn push_back(this: Ptr, item: Ptr) { CopyConstructible::push_copied(&field_ref!(this, vec_).as_pointer(), (item).clone()); } -} -impl ConstructibleFrom<()> for MyContainer_char_ { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, vec_).write(Vec::new()); } } @@ -117,7 +113,7 @@ impl ConstructibleFrom<()> for MyContainer_char_ { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(24)] pub struct MyContainer_float_ { #[offset(0)] @@ -144,9 +140,7 @@ impl MyContainer_float_ { pub fn push_back(this: Ptr, item: Ptr) { CopyConstructible::push_copied(&field_ref!(this, vec_).as_pointer(), (item).clone()); } -} -impl ConstructibleFrom<()> for MyContainer_float_ { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, vec_).write(Vec::new()); } } @@ -421,7 +415,7 @@ fn main_0() -> i32 { assert!((({ Boxed_long_::twice(10_i64,) }) == 20_i64)); let bl: Value = Rc::new(RefCell::new(Boxed_long_ { value: 7_i64 })); assert!((({ Boxed_long_::plus(bl.as_pointer(), 1_i64,) }) == 8_i64)); - object!(imc, MyContainer_int_); + object!(imc, MyContainer_int_::constructor_1()); assert!(({ MyContainer_int_::empty(imc.as_pointer(),) })); ({ let _item: Value = Rc::new(RefCell::new(1)); @@ -433,7 +427,7 @@ fn main_0() -> i32 { ); ({ MyContainer_int_::pop_back(imc.as_pointer()) }); assert!(({ MyContainer_int_::empty(imc.as_pointer(),) })); - object!(cmc, MyContainer_char_); + object!(cmc, MyContainer_char_::constructor_1()); assert!(({ MyContainer_char_::empty(cmc.as_pointer(),) })); ({ let _item: Value = Rc::new(RefCell::new(('a' as i8))); @@ -446,7 +440,7 @@ fn main_0() -> i32 { ); ({ MyContainer_char_::pop_back(cmc.as_pointer()) }); assert!(({ MyContainer_char_::empty(cmc.as_pointer(),) })); - object!(fmc, MyContainer_float_); + object!(fmc, MyContainer_float_::constructor_1()); assert!(({ MyContainer_float_::empty(fmc.as_pointer(),) })); ({ let _item: Value = Rc::new(RefCell::new((1_f64 as f32))); diff --git a/tests/unit/out/refcount/constexpr_function.rs b/tests/unit/out/refcount/constexpr_function.rs index c7978d88e8..d7fe55acbc 100644 --- a/tests/unit/out/refcount/constexpr_function.rs +++ b/tests/unit/out/refcount/constexpr_function.rs @@ -35,24 +35,24 @@ pub fn half_3(mut x: f64) -> f64 { Conversions, )] #[conversions(copy, move)] -#[conversion_function(bool, const_lvalue_ref, explicit)] +#[conversion_function(conversion_function_1, bool, const_lvalue_ref, explicit)] #[byte_size(4)] pub struct Flag { #[offset(0)] pub v: i32, } -impl ConversionFunction>> for Flag { - fn conversion_function(this: LvalueRef>, to: Ptr) { +impl Flag { + pub fn conversion_function_1(this: LvalueRef>, __return: Ptr) { let this = this.as_pointer(); - to.write((this.with(|__s| __s.v) != 0)); + __return.write((this.with(|__s| __s.v) != 0)); return; } } pub fn use_4(f: Flag) -> i32 { let f: Value = Rc::new(RefCell::new(f)); assert!({ - let __v: Value = Rc::new(RefCell::new(false)); - Flag::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Flag::conversion_function_1( >>::bind(f.as_pointer()), Ptr::clone(&__v.as_pointer()), ); diff --git a/tests/unit/out/refcount/constructor.rs b/tests/unit/out/refcount/constructor.rs index 0668104158..5f135feb04 100644 --- a/tests/unit/out/refcount/constructor.rs +++ b/tests/unit/out/refcount/constructor.rs @@ -23,8 +23,8 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] -#[constructor(value(i32))] +#[conversions(copy, move)] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct S { #[offset(0)] @@ -39,16 +39,13 @@ impl S { field!(this, v).with_mut(|__v| *__v = *__v + 1) }; } -} -impl ConstructibleFrom<(i32,)> for S { - fn constructor(this: Ptr, (mut init,): (i32,)) { + pub fn constructor_1(this: Ptr, mut init: i32) { field!(this, v).write(init); ({ S::mut_method(this.clone()) }); let __rhs = ({ S::const_method(this.clone()) }); total_0.with(|rc| *rc.borrow_mut() += __rhs); } } -impl ConvertibleTo for i32 {} impl Destructible for S { fn destroy(this: Ptr) { ({ S::mut_method(this.clone()) }); @@ -67,9 +64,9 @@ impl Destructible for S { TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] -#[constructor(value(i32), value(i32))] -#[constructor(value(i32))] +#[conversions(copy, move, default = constructor_3)] +#[constructor(constructor_1, value(i32), value(i32))] +#[constructor(constructor_2, value(i32))] #[byte_size(8)] pub struct Point { #[offset(0)] @@ -77,24 +74,19 @@ pub struct Point { #[offset(4)] pub y: i32, } -impl ConstructibleFrom<(i32, i32)> for Point { - fn constructor(this: Ptr, (mut x, mut y): (i32, i32)) { +impl Point { + pub fn constructor_1(this: Ptr, mut x: i32, mut y: i32) { field!(this, x).write(x); field!(this, y).write(y); } -} -impl ConstructibleFrom<(i32,)> for Point { - fn constructor(this: Ptr, (mut v,): (i32,)) { - >::constructor(this.clone(), (v, (v + 1))); + pub fn constructor_2(this: Ptr, mut v: i32) { + Point::constructor_1(this.clone(), v, (v + 1)); { field!(this, y).with_mut(|__v| *__v = *__v * 10) }; } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<()> for Point { - fn constructor(this: Ptr, _: ()) { - >::constructor(this.clone(), (4,)); + pub fn constructor_3(this: Ptr) { + Point::constructor_2(this.clone(), 4); { field!(this, x).with_mut(|__v| *__v = *__v + 100) }; @@ -104,8 +96,8 @@ impl Default for Point { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Point::constructor_3(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -117,15 +109,15 @@ pub fn main() { } fn main_0() -> i32 { { - object!(s, S, (i32,), (3,)); + object!(s, S::constructor_1(3)); assert!(({ (*s.borrow()).v } == 4)); assert!((total_0.with(|rc| *rc.borrow()) == 8)); } assert!((total_0.with(|rc| *rc.borrow()) == 18)); - object!(p, Point); + object!(p, Point::constructor_3()); assert!(({ (*p.borrow()).x } == 104)); assert!(({ (*p.borrow()).y } == 50)); - object!(q, Point, (i32,), (7,)); + object!(q, Point::constructor_2(7)); assert!(({ (*q.borrow()).x } == 7)); assert!(({ (*q.borrow()).y } == 80)); return 0; diff --git a/tests/unit/out/refcount/container_field_addr.rs b/tests/unit/out/refcount/container_field_addr.rs index 1506a44c71..b4f60960d9 100644 --- a/tests/unit/out/refcount/container_field_addr.rs +++ b/tests/unit/out/refcount/container_field_addr.rs @@ -21,7 +21,7 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(32)] pub struct S { #[offset(0)] @@ -30,8 +30,8 @@ pub struct S { #[byte_size(24)] pub v: Vec, } -impl ConstructibleFrom<()> for S { - fn constructor(this: Ptr, _: ()) { +impl S { + pub fn constructor_1(this: Ptr) { field!(this, tag).write(0_i32); field!(this, v).write(Vec::new()); } @@ -60,12 +60,12 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(local, S); + object!(local, S::constructor_1()); (*local.borrow_mut()).tag = 7; ({ run_1((local.as_pointer())) }); let mut heap: Ptr = { let __p = Ptr::alloc(::zero_init()); - >::constructor(__p.clone(), ()); + S::constructor_1(__p.clone()); __p }; field!(heap, tag).write(7); diff --git a/tests/unit/out/refcount/conversion_operator_same_translation.rs b/tests/unit/out/refcount/conversion_operator_same_translation.rs index b2217db419..6b04dce8cf 100644 --- a/tests/unit/out/refcount/conversion_operator_same_translation.rs +++ b/tests/unit/out/refcount/conversion_operator_same_translation.rs @@ -20,29 +20,25 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[conversion_function(i8, const_lvalue_ref)] -#[conversion_function(u8, const_lvalue_ref)] +#[conversion_function(conversion_function_1, i8, const_lvalue_ref)] +#[conversion_function(conversion_function_2, u8, const_lvalue_ref)] #[byte_size(4)] pub struct S { #[offset(0)] pub v: i32, } -impl ConversionFunction>> for S { - fn conversion_function(this: LvalueRef>, to: Ptr) { +impl S { + pub fn conversion_function_1(this: LvalueRef>, __return: Ptr) { let this = this.as_pointer(); - to.write((this.with(|__s| __s.v) as i8)); + __return.write((this.with(|__s| __s.v) as i8)); return; } -} -impl ImplicitConversionFunction>> for S {} -impl ConversionFunction>> for S { - fn conversion_function(this: LvalueRef>, to: Ptr) { + pub fn conversion_function_2(this: LvalueRef>, __return: Ptr) { let this = this.as_pointer(); - to.write(((this.with(|__s| __s.v) + 1) as u8)); + __return.write(((this.with(|__s| __s.v) + 1) as u8)); return; } } -impl ImplicitConversionFunction>> for S {} #[derive( Copy, Clone, @@ -57,25 +53,25 @@ impl ImplicitConversionFunction>> for S {} Conversions, )] #[conversions(copy, move)] -#[conversion_function(i64, const_lvalue_ref)] +#[conversion_function(conversion_function_1, i64, const_lvalue_ref)] +#[conversion_function(conversion_function_2, i64, const_lvalue_ref)] #[byte_size(4)] pub struct T { #[offset(0)] pub v: i32, } impl T { - pub fn to_i64_2(this: Ptr) -> i64 { - return ((this.with(|__s| __s.v) + 1) as i64); + pub fn conversion_function_1(this: LvalueRef>, __return: Ptr) { + let this = this.as_pointer(); + __return.write((this.with(|__s| __s.v) as i64)); + return; } -} -impl ConversionFunction>> for T { - fn conversion_function(this: LvalueRef>, to: Ptr) { + pub fn conversion_function_2(this: LvalueRef>, __return: Ptr) { let this = this.as_pointer(); - to.write((this.with(|__s| __s.v) as i64)); + __return.write(((this.with(|__s| __s.v) + 1) as i64)); return; } } -impl ImplicitConversionFunction>> for T {} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -83,16 +79,16 @@ pub fn main() { fn main_0() -> i32 { let s: Value = Rc::new(RefCell::new(S { v: 65 })); let mut a: i8 = { - let __v: Value = Rc::new(RefCell::new(0_i8)); - S::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + S::conversion_function_1( >>::bind(s.as_pointer()), Ptr::clone(&__v.as_pointer()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; let mut b: u8 = { - let __v: Value = Rc::new(RefCell::new(0_u8)); - S::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + S::conversion_function_2( >>::bind(s.as_pointer()), Ptr::clone(&__v.as_pointer()), ); @@ -102,16 +98,16 @@ fn main_0() -> i32 { assert!(((b as i32) == ((66 as u8) as i32))); assert!( ((({ - let __v: Value = Rc::new(RefCell::new(0_i8)); - S::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + S::conversion_function_1( >>::bind(s.as_pointer()), Ptr::clone(&__v.as_pointer()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() } as i32) + ({ - let __v: Value = Rc::new(RefCell::new(0_u8)); - S::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + S::conversion_function_2( >>::bind(s.as_pointer()), Ptr::clone(&__v.as_pointer()), ); @@ -121,14 +117,21 @@ fn main_0() -> i32 { ); let t: Value = Rc::new(RefCell::new(T { v: 3 })); let mut c: i64 = { - let __v: Value = Rc::new(RefCell::new(0_i64)); - T::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + T::conversion_function_1( + >>::bind(t.as_pointer()), + Ptr::clone(&__v.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; + let mut d: i64 = { + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + T::conversion_function_2( >>::bind(t.as_pointer()), Ptr::clone(&__v.as_pointer()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; - let mut d: i64 = ({ T::to_i64_2(t.as_pointer()) }); assert!((c == 3_i64)); assert!((d == 4_i64)); return 0; diff --git a/tests/unit/out/refcount/copy_assign.rs b/tests/unit/out/refcount/copy_assign.rs index eb517cab61..77fbf17579 100644 --- a/tests/unit/out/refcount/copy_assign.rs +++ b/tests/unit/out/refcount/copy_assign.rs @@ -21,8 +21,8 @@ thread_local!( Default, Conversions, )] -#[conversions(copy)] -#[constructor(value(i32), value(i32))] +#[conversions(copy = constructor_2, move)] +#[constructor(constructor_1, value(i32), value(i32))] #[byte_size(8)] pub struct Partial { #[offset(0)] @@ -30,21 +30,17 @@ pub struct Partial { #[offset(4)] pub keep: i32, } -impl ConstructibleFrom<(i32, i32)> for Partial { - fn constructor(this: Ptr, (mut v, mut keep): (i32, i32)) { +impl Partial { + pub fn constructor_1(this: Ptr, mut v: i32, mut keep: i32) { field!(this, v).write(v); field!(this, keep).write(keep); } -} -impl ConstructibleFrom<(LvalueRef>,)> for Partial { - fn constructor(this: Ptr, (o,): (LvalueRef>,)) { + pub fn constructor_2(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 CopyConstructible for Partial {} -impl ConvertibleTo for LvalueRef> {} impl CopyAssignable for Partial { fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { let o = o.as_pointer(); @@ -68,13 +64,16 @@ impl CopyAssignable for Partial { Copyable, Conversions, )] -#[conversions(copy)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct NonConstAssign { #[offset(0)] pub mark: i32, } impl NonConstAssign { + pub fn constructor_1(this: Ptr) { + field!(this, mark).write(0); + } pub fn operator_assign_2(this: Ptr, o: Ptr) -> Ptr { field!(this, mark).write((o.with(|__s| __s.mark) + 1)); return (this).clone(); @@ -84,18 +83,13 @@ impl NonConstAssign { return (this).clone(); } } -impl ConstructibleFrom<()> for NonConstAssign { - fn constructor(this: Ptr, _: ()) { - field!(this, mark).write(0); - } -} impl Default for NonConstAssign { fn default() -> Self { { { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + NonConstAssign::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -114,14 +108,14 @@ impl Default for NonConstAssign { Movable, Conversions, )] -#[conversions(copy)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct RefQualified { #[offset(0)] pub mark: i32, } -impl ConstructibleFrom<()> for RefQualified { - fn constructor(this: Ptr, _: ()) { +impl RefQualified { + pub fn constructor_1(this: Ptr) { field!(this, mark).write(0); } } @@ -136,8 +130,9 @@ impl Default for RefQualified { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + RefQualified::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -159,6 +154,7 @@ pub struct Holder { #[array_len(2)] pub arr: Box<[Partial]>, } +impl Holder {} impl Default for Holder { fn default() -> Self { { @@ -188,28 +184,23 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move)] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct CopyCounted { #[offset(0)] pub v: i32, } -impl ConstructibleFrom<(i32,)> for CopyCounted { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl CopyCounted { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for CopyCounted { - fn constructor(this: Ptr, (o,): (LvalueRef>,)) { + pub fn constructor_2(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(); } } -impl CopyConstructible for CopyCounted {} -impl ConvertibleTo for LvalueRef> {} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] @@ -226,6 +217,7 @@ pub struct HasCopyCounted { #[array_len(2)] pub arr: Box<[CopyCounted]>, } +impl HasCopyCounted {} impl Default for HasCopyCounted { fn default() -> Self { { @@ -251,13 +243,18 @@ impl Default for HasCopyCounted { Default, Conversions, )] -#[conversions(copy)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(24)] pub struct ExplicitOperatorCall { #[offset(0)] #[byte_size(24)] pub w: Vec, } +impl ExplicitOperatorCall { + pub fn constructor_1(this: Ptr) { + field!(this, w).write(Vec::new()); + } +} impl CopyAssignable for ExplicitOperatorCall { fn copy_assign( this: Ptr, @@ -272,11 +269,6 @@ impl CopyAssignable for ExplicitOperatorCall { return (this).clone(); } } -impl ConstructibleFrom<()> for ExplicitOperatorCall { - fn constructor(this: Ptr, _: ()) { - field!(this, w).write(Vec::new()); - } -} thread_local!( pub static swap_copies_2: Value = Rc::new(RefCell::new(0)); ); @@ -291,36 +283,29 @@ thread_local!( Default, Conversions, )] -#[conversions(copy)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move)] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct Swapped { #[offset(0)] pub v: i32, } impl Swapped { - pub fn copy_assign(this: Ptr, o: Ptr) -> Ptr { - let mut t: i32 = this.with(|__s| __s.v); - field!(this, v).write(o.with(|__s| __s.v)); - field!(o, v).write(t); - return (this).clone(); - } -} -impl ConstructibleFrom<(i32,)> for Swapped { - fn constructor(this: Ptr, (mut v,): (i32,)) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for Swapped { - fn constructor(this: Ptr, (o,): (LvalueRef>,)) { + pub fn constructor_2(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(); } + pub fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + let mut t: i32 = this.with(|__s| __s.v); + field!(this, v).write(o.with(|__s| __s.v)); + field!(o, v).write(t); + return (this).clone(); + } } -impl CopyConstructible for Swapped {} -impl ConvertibleTo for LvalueRef> {} impl CopyAssignable for Swapped { fn copy_assign(this: Ptr, src: LvalueRef>) -> Ptr { object!(__o, Swapped, LvalueRef::bind(src.as_pointer())); @@ -354,6 +339,7 @@ pub struct HoldsSwapped { #[byte_size(4)] pub s: Swapped, } +impl HoldsSwapped {} #[derive( Copy, Clone, @@ -368,22 +354,20 @@ pub struct HoldsSwapped { Swappable, Conversions, )] -#[conversions(copy)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct VoidAssign { #[offset(0)] pub x: i32, } impl VoidAssign { + pub fn constructor_1(this: Ptr) { + field!(this, x).write(0); + } pub fn copy_assign(this: Ptr, o: Ptr) { field!(this, x).write((o.with(|__s| __s.x) + 5)); } } -impl ConstructibleFrom<()> for VoidAssign { - fn constructor(this: Ptr, _: ()) { - field!(this, x).write(0); - } -} impl CopyAssignable for VoidAssign { fn copy_assign(this: Ptr, src: LvalueRef>) -> Ptr { VoidAssign::copy_assign(this.clone(), src.as_pointer()); @@ -400,8 +384,8 @@ impl Default for VoidAssign { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + VoidAssign::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -423,16 +407,16 @@ impl Default for VoidAssign { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct HoldsVoidAssign { #[offset(0)] #[byte_size(4)] pub v: VoidAssign, } -impl ConstructibleFrom<()> for HoldsVoidAssign { - fn constructor(this: Ptr, _: ()) { - >::constructor(field_ptr!(this, v), ()); +impl HoldsVoidAssign { + pub fn constructor_1(this: Ptr) { + VoidAssign::constructor_1(field_ptr!(this, v)); } } pub fn main() { @@ -440,9 +424,9 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, Partial, (i32, i32,), (1, 100,)); - object!(b, Partial, (i32, i32,), (2, 200,)); - object!(c, Partial, (i32, i32,), (3, 300,)); + object!(a, Partial::constructor_1(1, 100)); + object!(b, Partial::constructor_1(2, 200)); + object!(c, Partial::constructor_1(3, 300)); assign!(a = b); assert!(({ (*a.borrow()).v } == 2) && ({ (*a.borrow()).keep } == 100)); assert!((assigns_0.with(|rc| *rc.borrow()) == 1)); @@ -452,8 +436,8 @@ fn main_0() -> i32 { assign!(a = a); assert!((assigns_0.with(|rc| *rc.borrow()) == 3)); ({ - let _o: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(_o.as_pointer(), (9, 900)); + let _o: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Partial::constructor_1(_o.as_pointer(), 9, 900); assign!(a = _o) }); assert!(({ (*a.borrow()).v } == 9) && ({ (*a.borrow()).keep } == 100)); @@ -467,19 +451,19 @@ fn main_0() -> i32 { assert!((assigns_0.with(|rc| *rc.borrow()) == 6)); let h: Value = Rc::new(RefCell::new(Holder { p: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (4, 40)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Partial::constructor_1(__v.as_pointer(), 4, 40); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, arr: Box::new([ { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (5, 50)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Partial::constructor_1(__v.as_pointer(), 5, 50); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (6, 60)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Partial::constructor_1(__v.as_pointer(), 6, 60); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]), @@ -492,33 +476,33 @@ fn main_0() -> i32 { && (array_elem!(h.as_pointer(), arr, 1).with(|__s| __s.keep) == 60) ); assert!((assigns_0.with(|rc| *rc.borrow()) == 8)); - object!(n, NonConstAssign); - object!(n1, NonConstAssign); - object!(n2, NonConstAssign); - object!(cn, NonConstAssign); + object!(n, NonConstAssign::constructor_1()); + object!(n1, NonConstAssign::constructor_1()); + object!(n2, NonConstAssign::constructor_1()); + object!(cn, NonConstAssign::constructor_1()); NonConstAssign::operator_assign_2(n1.as_pointer(), n.as_pointer()); NonConstAssign::operator_assign_3(n2.as_pointer(), cn.as_pointer()); assert!(({ (*n1.borrow()).mark } == 1)); assert!(({ (*n2.borrow()).mark } == 10)); - object!(r, RefQualified); - object!(r1, RefQualified); + object!(r, RefQualified::constructor_1()); + object!(r1, RefQualified::constructor_1()); assign!(r1 = r); assert!(({ (*r1.borrow()).mark } == 1)); let h2: Value = Rc::new(RefCell::new(Holder { p: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (7, 70)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Partial::constructor_1(__v.as_pointer(), 7, 70); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, arr: Box::new([ { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (8, 80)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Partial::constructor_1(__v.as_pointer(), 8, 80); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (9, 90)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Partial::constructor_1(__v.as_pointer(), 9, 90); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]), @@ -530,44 +514,48 @@ fn main_0() -> i32 { && (array_elem!(h2.as_pointer(), arr, 1).with(|__s| __s.keep) == 90) ); assert!((assigns_0.with(|rc| *rc.borrow()) == 11)); - object!(cc1, CopyCounted, (i32,), (1,)); - object!(cc2, CopyCounted, (i32,), (2,)); + object!(cc1, CopyCounted::constructor_1(1)); + object!(cc2, CopyCounted::constructor_1(2)); assign!(cc1 = cc2); assert!(({ (*cc1.borrow()).v } == 2)); let hc1: Value = Rc::new(RefCell::new(HasCopyCounted { c: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (1,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CopyCounted::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, arr: Box::new([ { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (2,)); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CopyCounted::constructor_1(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (3,)); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CopyCounted::constructor_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]), })); let hc2: Value = Rc::new(RefCell::new(HasCopyCounted { c: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (4,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CopyCounted::constructor_1(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, arr: Box::new([ { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (5,)); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CopyCounted::constructor_1(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (6,)); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CopyCounted::constructor_1(__v.as_pointer(), 6); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]), @@ -579,8 +567,8 @@ fn main_0() -> i32 { && (array_elem!(hc1.as_pointer(), arr, 1).with(|__s| __s.v) == 6) ); assert!((copies_1.with(|rc| *rc.borrow()) == 0)); - object!(e1, ExplicitOperatorCall); - object!(e2, ExplicitOperatorCall); + object!(e1, ExplicitOperatorCall::constructor_1()); + object!(e2, ExplicitOperatorCall::constructor_1()); ({ let __tmp_1: Value = Rc::new(RefCell::new(5)); MoveConstructible::push_moved( @@ -596,35 +584,32 @@ fn main_0() -> i32 { && ((*e1.borrow()).w.len() == 1_usize) }) ); - object!(sw1, Swapped, (i32,), (1,)); - object!(sw2, Swapped, (i32,), (2,)); + object!(sw1, Swapped::constructor_1(1)); + object!(sw2, Swapped::constructor_1(2)); ({ - let _o: Value = Rc::new(RefCell::new(::zero_init())); - >,)>>::constructor( - _o.as_pointer(), - (LvalueRef::bind(sw2.as_pointer()),), - ); + let _o: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Swapped::constructor_2(_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)); let hs1: Value = Rc::new(RefCell::new(HoldsSwapped { s: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (3,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Swapped::constructor_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); let hs2: Value = Rc::new(RefCell::new(HoldsSwapped { s: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (4,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Swapped::constructor_1(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); assign!(hs1 = hs2); assert!(({ (*hs1.borrow()).s.v } == 4) && (swap_copies_2.with(|rc| *rc.borrow()) == 2)); - object!(hv1, HoldsVoidAssign); - object!(hv2, HoldsVoidAssign); + object!(hv1, HoldsVoidAssign::constructor_1()); + object!(hv2, HoldsVoidAssign::constructor_1()); assign!(hv1 = hv2); assert!(({ (*hv1.borrow()).v.x } == 5)); return 0; diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index 85d560c8fd..71b750d238 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -23,64 +23,54 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move)] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct Counted { #[offset(0)] pub v: i32, } -impl ConstructibleFrom<(i32,)> for Counted { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl Counted { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for Counted { - fn constructor(this: Ptr, (o,): (LvalueRef>,)) { + pub fn constructor_2(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 CopyConstructible for Counted {} -impl ConvertibleTo for LvalueRef> {} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, MoveAssignable, )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy = constructor_3, default = constructor_1)] +#[constructor(constructor_2, lvalue_ref(NonConst))] #[byte_size(4)] pub struct NonConst { #[offset(0)] pub mark: i32, } -impl ConstructibleFrom<()> for NonConst { - fn constructor(this: Ptr, _: ()) { +impl NonConst { + pub fn constructor_1(this: Ptr) { field!(this, mark).write(0); } -} -impl ConstructibleFrom<(LvalueRef,)> for NonConst { - fn constructor(this: Ptr, (o,): (LvalueRef,)) { + pub fn constructor_2(this: Ptr, o: LvalueRef) { let o = o.as_pointer(); field!(this, mark).write((o.with(|__s| __s.mark) + 1)); } -} -impl ConvertibleTo for LvalueRef {} -impl ConstructibleFrom<(LvalueRef>,)> for NonConst { - fn constructor(this: Ptr, (o,): (LvalueRef>,)) { + pub fn constructor_3(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); field!(this, mark).write((o.with(|__s| __s.mark) + 10)); } } -impl ConvertibleTo for LvalueRef> {} impl Default for NonConst { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + NonConst::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -100,28 +90,23 @@ impl Default for NonConst { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move)] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct Ignored { #[offset(0)] pub v: i32, } -impl ConstructibleFrom<(i32,)> for Ignored { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl Ignored { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for Ignored { - fn constructor(this: Ptr, (_a0,): (LvalueRef>,)) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, v).write(-1_i32); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } -impl CopyConstructible for Ignored {} -impl ConvertibleTo for LvalueRef> {} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] @@ -138,6 +123,7 @@ pub struct Holder { #[array_len(2)] pub arr: Box<[Counted]>, } +impl Holder {} impl Default for Holder { fn default() -> Self { { @@ -155,27 +141,22 @@ impl Default for Holder { )] #[memberwise(move_constructor)] #[derive(Conversions)] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move)] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct Box_int_ { #[offset(0)] pub val: i32, } -impl ConstructibleFrom<(i32,)> for Box_int_ { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl Box_int_ { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, val).write(v); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for Box_int_ { - fn constructor(this: Ptr, (o,): (LvalueRef>,)) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); field!(this, val).write(o.with(|__s| __s.val)); } } -impl CopyConstructible for Box_int_ {} -impl ConvertibleTo for LvalueRef> {} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, )] @@ -188,6 +169,7 @@ pub struct Owner { #[byte_size(4)] pub box_: Box_int_, } +impl Owner {} #[derive( Record, ByteRepr, @@ -202,28 +184,24 @@ pub struct Owner { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move)] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct OutOfLine { #[offset(0)] pub v: i32, } -impl ConstructibleFrom<(i32,)> for OutOfLine { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl OutOfLine { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for OutOfLine { - fn constructor(this: Ptr, (o,): (LvalueRef>,)) { + pub fn constructor_2(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(); } } -impl CopyConstructible for OutOfLine {} -impl ConvertibleTo for LvalueRef> {} +impl OutOfLine {} #[derive( Record, ByteRepr, @@ -235,19 +213,17 @@ impl ConvertibleTo for LvalueRef> {} Swappable, Conversions, )] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] #[byte_size(4)] pub struct Tracked { #[offset(0)] pub copied_from: i32, } -impl ConstructibleFrom<()> for Tracked { - fn constructor(this: Ptr, _: ()) { +impl Tracked { + pub fn constructor_1(this: Ptr) { field!(this, copied_from).write(0); } -} -impl ConstructibleFrom<(LvalueRef>,)> for Tracked { - fn constructor(this: Ptr, (o,): (LvalueRef>,)) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); field!(this, copied_from).write(0); field!(o, copied_from).with_mut(|__v| { @@ -255,8 +231,6 @@ impl ConstructibleFrom<(LvalueRef>,)> for Tracked { }); } } -impl CopyConstructible for Tracked {} -impl ConvertibleTo for LvalueRef> {} impl CopyAssignable for Tracked { fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { let o = o.as_pointer(); @@ -280,48 +254,37 @@ pub fn by_value_2(c: Ptr) -> i32 { return c.with(|__s| __s.v); } pub fn make_3(__return: Ptr, mut v: i32) { - object!(c, Counted, (i32,), (v,)); - ConvertibleTo::convert( - >>::bind(c.as_pointer()), - __return.clone(), - ); + object!(c, Counted::constructor_1(v)); + Counted::constructor_2(__return.clone(), LvalueRef::bind(c.as_pointer())); return; } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] -#[conversions(copy, move)] +#[conversions(copy = constructor_2, move = constructor_3, default = constructor_1)] #[byte_size(8)] pub struct SelfPtr { #[offset(0)] #[byte_size(8)] pub self_: Ptr, } -impl ConstructibleFrom<()> for SelfPtr { - fn constructor(this: Ptr, _: ()) { +impl SelfPtr { + pub fn constructor_1(this: Ptr) { field!(this, self_).write((this).clone()); } -} -impl ConstructibleFrom<(LvalueRef>,)> for SelfPtr { - fn constructor(this: Ptr, (_a0,): (LvalueRef>,)) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); } -} -impl CopyConstructible for SelfPtr {} -impl ConvertibleTo for LvalueRef> {} -impl ConstructibleFrom<(RvalueRef,)> for SelfPtr { - fn constructor(this: Ptr, (_a0,): (RvalueRef,)) { + pub fn constructor_3(this: Ptr, _a0: RvalueRef) { let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); } } -impl MoveConstructible for SelfPtr {} -impl ConvertibleTo for RvalueRef {} impl Default for SelfPtr { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + SelfPtr::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -346,24 +309,24 @@ pub struct EmptyBase {} #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct Derived { #[offset(0)] #[byte_size(4)] pub c: Counted, } -impl ConstructibleFrom<()> for Derived { - fn constructor(this: Ptr, _: ()) { - >::constructor(field_ptr!(this, c), (20,)); +impl Derived { + pub fn constructor_1(this: Ptr) { + Counted::constructor_1(field_ptr!(this, c), 20); } } impl Default for Derived { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Derived::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -374,24 +337,18 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, Counted, (i32,), (1,)); - object!(b, Counted, LvalueRef::bind(a.as_pointer())); - object!( - c, - Counted = >>::bind(a.as_pointer()) - ); - object!(d, Counted, LvalueRef::bind(a.as_pointer())); + object!(a, Counted::constructor_1(1)); + object!(b, Counted::constructor_2(LvalueRef::bind(a.as_pointer()))); + object!(c, Counted::constructor_2(LvalueRef::bind(a.as_pointer()))); + object!(d, Counted::constructor_2(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) ); assert!( (({ - let _c: Value = Rc::new(RefCell::new(::zero_init())); - >,)>>::constructor( - _c.as_pointer(), - (LvalueRef::bind(a.as_pointer()),), - ); + let _c: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_2(_c.as_pointer(), LvalueRef::bind(a.as_pointer())); by_value_2(_c.as_pointer()) }) == 1) ); @@ -399,39 +356,38 @@ fn main_0() -> i32 { object!(e, Counted, |e| ({ make_3(Ptr::clone(&e.clone()), 5,) })); assert!(({ (*e.borrow()).v } == 5)); assert!((copies_0.with(|rc| *rc.borrow()) == 5)); - object!(f, Counted, (i32,), (6,)); + object!(f, Counted::constructor_1(6)); assert!(({ (*f.borrow()).v } == 6)); assert!((copies_0.with(|rc| *rc.borrow()) == 5)); - object!(g, Counted, (i32,), (7,)); - object!( - h, - Counted = >>::bind(g.as_pointer()) - ); + object!(g, Counted::constructor_1(7)); + object!(h, Counted::constructor_2(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 { c: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (8,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_1(__v.as_pointer(), 8); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, arr: Box::new([ { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (9,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_1(__v.as_pointer(), 9); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (10,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_1(__v.as_pointer(), 10); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]), })); - object!( - hold2, - Holder = >>::bind(hold.as_pointer()) - ); + object!(hold2, Holder, |hold2| { + ::copy_constructor( + hold2.clone(), + LvalueRef::bind(hold.as_pointer()), + ) + }); assert!( (({ (*hold2.borrow()).c.v } == 8) && (array_elem!(hold2.as_pointer(), arr, 0).with(|__s| __s.v) == 9)) @@ -442,53 +398,53 @@ fn main_0() -> i32 { CopyConstructible::push_copied(&vec_.as_pointer(), a.as_pointer()); assert!(({ (*vec_.borrow())[0_usize].v } == 1)); assert!((copies_0.with(|rc| *rc.borrow()) == 10)); - object!(i1, Ignored, (i32,), (1,)); - object!(i2, Ignored, LvalueRef::bind(i1.as_pointer())); + object!(i1, Ignored::constructor_1(1)); + object!(i2, Ignored::constructor_2(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 { box_: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (3,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Box_int_::constructor_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); - object!(o2, Owner = >::bind(o.as_pointer())); + object!(o2, Owner, |o2| { + ::move_constructor(o2.clone(), RvalueRef::bind(o.as_pointer())) + }); assert!(({ (*o2.borrow()).box_.val } == 3)); - object!(ol1, OutOfLine, (i32,), (5,)); - object!(ol2, OutOfLine, LvalueRef::bind(ol1.as_pointer())); - assert!(({ (*ol2.borrow()).v } == 105)); - assert!((copies_0.with(|rc| *rc.borrow()) == 12)); - object!(n, NonConst); + object!(ol1, OutOfLine::constructor_1(5)); object!( - n1, - NonConst, - (LvalueRef,), - (LvalueRef::bind(n.as_pointer()),) + ol2, + OutOfLine::constructor_2(LvalueRef::bind(ol1.as_pointer())) ); - object!(cn, NonConst); + assert!(({ (*ol2.borrow()).v } == 105)); + assert!((copies_0.with(|rc| *rc.borrow()) == 12)); + object!(n, NonConst::constructor_1()); + object!(n1, NonConst::constructor_2(LvalueRef::bind(n.as_pointer()))); + object!(cn, NonConst::constructor_1()); object!( n2, - NonConst, - (LvalueRef>,), - (LvalueRef::bind(cn.as_pointer()),) + NonConst::constructor_3(LvalueRef::bind(cn.as_pointer())) ); assert!(({ (*n1.borrow()).mark } == 1)); assert!(({ (*n2.borrow()).mark } == 10)); - object!(t1, Tracked); - object!(t2, Tracked, LvalueRef::bind(t1.as_pointer())); + object!(t1, Tracked::constructor_1()); + object!(t2, Tracked::constructor_2(LvalueRef::bind(t1.as_pointer()))); assign!(t2 = t1); assert!(({ (*t1.borrow()).copied_from } == 2)); - object!(ct, Tracked); - object!(t3, Tracked, LvalueRef::bind(ct.as_pointer())); + object!(ct, Tracked::constructor_1()); + object!(t3, Tracked::constructor_2(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 = >>::bind(der.as_pointer()) - ); + object!(der, Derived::constructor_1()); + object!(der2, Derived, |der2| { + ::copy_constructor( + der2.clone(), + LvalueRef::bind(der.as_pointer()), + ) + }); assert!(({ (*der2.borrow()).c.v } == 20) && (copies_0.with(|rc| *rc.borrow()) == (before + 1))); let mut range: Vec = { let __v: Value> = Rc::new(RefCell::new(Vec::new())); @@ -499,9 +455,11 @@ fn main_0() -> i32 { while >::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( __v.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind( + __it.borrow().iter_deref(), + ),), ); __it.borrow_mut().iter_inc(); } @@ -516,16 +474,16 @@ fn main_0() -> i32 { } }); { - let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - >::constructor(__tmp_1.as_pointer(), ()); + SelfPtr::constructor_1(__tmp_1.as_pointer()); __tmp_1.as_pointer() },) { (__tmp_0,) => MoveConstructible::push_moved(&selfs.as_pointer(), (__tmp_0).clone()), } }; - object!(self_src, SelfPtr); + object!(self_src, SelfPtr::constructor_1()); CopyConstructible::push_copied(&selfs.as_pointer(), self_src.as_pointer()); assert!( ({ { (*selfs.borrow())[0_usize].self_.clone() } } == { (selfs.decay().offset(0_usize)) }) @@ -541,9 +499,9 @@ fn main_0() -> i32 { } }); { - let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_3: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - >::constructor(__tmp_3.as_pointer(), (30,)); + Counted::constructor_1(__tmp_3.as_pointer(), 30); __tmp_3.as_pointer() },) { diff --git a/tests/unit/out/refcount/copy_move_defaulted.rs b/tests/unit/out/refcount/copy_move_defaulted.rs index 65fc556df0..79498474d5 100644 --- a/tests/unit/out/refcount/copy_move_defaulted.rs +++ b/tests/unit/out/refcount/copy_move_defaulted.rs @@ -41,7 +41,7 @@ pub struct Inner { #[memberwise(copy_assign, move_assign)] #[derive(Conversions)] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] #[byte_size(16)] pub struct Explicit { #[offset(0)] @@ -54,14 +54,13 @@ pub struct Explicit { #[array_len(2)] pub arr: Box<[i32]>, } -impl ConstructibleFrom<(i32,)> for Explicit { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl Explicit { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); field!(this, inner).write(Inner { x: (v * 10) }); field!(this, arr).write(Box::new([v, (v + 1)])); } } -impl ConvertibleTo for i32 {} impl Destructible for Explicit { fn destroy(this: Ptr) {} } @@ -116,28 +115,23 @@ impl Default for Implicit { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy, move = constructor_3)] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct DefaultCopyUserMove { #[offset(0)] pub v: i32, } -impl ConstructibleFrom<(i32,)> for DefaultCopyUserMove { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl DefaultCopyUserMove { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(RvalueRef,)> for DefaultCopyUserMove { - fn constructor(this: Ptr, (o,): (RvalueRef,)) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } -impl MoveConstructible for DefaultCopyUserMove {} -impl ConvertibleTo for RvalueRef {} impl MoveAssignable for DefaultCopyUserMove { fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { let o = o.as_pointer(); @@ -158,27 +152,22 @@ impl MoveAssignable for DefaultCopyUserMove { )] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move)] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct UserCopyDefaultMove { #[offset(0)] pub v: i32, } -impl ConstructibleFrom<(i32,)> for UserCopyDefaultMove { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl UserCopyDefaultMove { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for UserCopyDefaultMove { - fn constructor(this: Ptr, (o,): (LvalueRef>,)) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); field!(this, v).write((o.with(|__s| __s.v) + 100)); } } -impl CopyConstructible for UserCopyDefaultMove {} -impl ConvertibleTo for LvalueRef> {} impl CopyAssignable for UserCopyDefaultMove { fn copy_assign( this: Ptr, @@ -195,7 +184,7 @@ impl CopyAssignable for UserCopyDefaultMove { #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] #[conversions(move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] #[byte_size(64)] pub struct Buffer { #[offset(0)] @@ -211,8 +200,8 @@ pub struct Buffer { #[array_len(2)] pub arr: Box<[i32]>, } -impl ConstructibleFrom<(i32,)> for Buffer { - fn constructor(this: Ptr, (n,): (i32,)) { +impl Buffer { + pub fn constructor_1(this: Ptr, n: i32) { let n: Value = Rc::new(RefCell::new(n)); field!(this, data).write( (0..({ ((*n.borrow()) as usize) })) @@ -228,7 +217,6 @@ impl ConstructibleFrom<(i32,)> for Buffer { ); } } -impl ConvertibleTo for i32 {} impl Default for Buffer { fn default() -> Self { { ::zero_init() } @@ -237,7 +225,7 @@ impl Default for Buffer { #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] #[byte_size(48)] pub struct Owner { #[offset(0)] @@ -253,8 +241,8 @@ pub struct Owner { #[byte_size(8)] pub p: Option>, } -impl ConstructibleFrom<()> for Owner { - fn constructor(this: Ptr, _: ()) { +impl Owner { + pub fn constructor_1(this: Ptr) { field!(this, data).write(Vec::new()); field!(this, n).write(0_i32); field!(this, arr).write((0..2).map(|_| 0_i32).collect::>()); @@ -288,15 +276,15 @@ impl Default for Owner { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(24)] pub struct Copyable { #[offset(0)] #[byte_size(24)] pub data: Vec, } -impl ConstructibleFrom<()> for Copyable { - fn constructor(this: Ptr, _: ()) { +impl Copyable { + pub fn constructor_1(this: Ptr) { field!(this, data).write(Vec::new()); } } @@ -306,7 +294,7 @@ impl ConstructibleFrom<()> for Copyable { #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] #[conversions(move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] #[byte_size(32)] pub struct Holder { #[offset(0)] @@ -320,14 +308,13 @@ pub struct Holder { #[byte_size(8)] pub p: Option>, } -impl ConstructibleFrom<(i32,)> for Holder { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl Holder { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, inner).write(Inner { x: v }); - >::constructor(field_ptr!(this, e), (v,)); + Explicit::constructor_1(field_ptr!(this, e), v); field!(this, p).write(None); } } -impl ConvertibleTo for i32 {} pub fn same_0(a: Ptr, b: Ptr) -> bool { return ((({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }) && ({ a.with(|__s| __s.inner.x) } == { b.with(|__s| __s.inner.x) })) @@ -335,12 +322,18 @@ pub fn same_0(a: Ptr, b: Ptr) -> bool { && ({ (array_elem!(a, arr, 1).read()) } == { (array_elem!(b, arr, 1).read()) }); } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] +#[conversions(default = constructor_1)] #[byte_size(8)] pub struct SeesThis { #[offset(0)] #[byte_size(8)] pub self_: Ptr, } +impl SeesThis { + pub fn constructor_1(this: Ptr) { + field!(this, self_).write(Ptr::::null()); + } +} impl CopyAssignable for SeesThis { fn copy_assign(this: Ptr, _a0: LvalueRef>) -> Ptr { let _a0 = _a0.as_pointer(); @@ -355,11 +348,6 @@ impl MoveAssignable for SeesThis { return (this).clone(); } } -impl ConstructibleFrom<()> for SeesThis { - fn constructor(this: Ptr, _: ()) { - field!(this, self_).write(Ptr::::null()); - } -} impl Default for SeesThis { fn default() -> Self { { @@ -372,6 +360,7 @@ impl Default for SeesThis { #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Default)] #[memberwise(copy_assign, move_assign)] #[derive(Conversions)] +#[conversions(default = constructor_1)] #[byte_size(32)] pub struct HasSeesThis { #[offset(0)] @@ -381,14 +370,14 @@ pub struct HasSeesThis { #[byte_size(24)] pub v: Vec, } -impl ConstructibleFrom<()> for HasSeesThis { - fn constructor(this: Ptr, _: ()) { - >::constructor(field_ptr!(this, s), ()); +impl HasSeesThis { + pub fn constructor_1(this: Ptr) { + SeesThis::constructor_1(field_ptr!(this, s)); field!(this, v).write(Vec::new()); } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Conversions)] -#[conversions(move)] +#[conversions(move = constructor_2, default = constructor_1)] #[byte_size(8)] pub struct Counted_int_ { #[offset(0)] @@ -396,21 +385,17 @@ pub struct Counted_int_ { #[offset(4)] pub moves: i32, } -impl ConstructibleFrom<()> for Counted_int_ { - fn constructor(this: Ptr, _: ()) { +impl Counted_int_ { + pub fn constructor_1(this: Ptr) { field!(this, v).write(0_i32); field!(this, moves).write(0); } -} -impl ConstructibleFrom<(RvalueRef,)> for Counted_int_ { - fn constructor(this: Ptr, (o,): (RvalueRef,)) { + pub fn constructor_2(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 MoveConstructible for Counted_int_ {} -impl ConvertibleTo for RvalueRef {} impl MoveAssignable for Counted_int_ { fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { let o = o.as_pointer(); @@ -429,7 +414,7 @@ impl Default for Counted_int_ { )] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] #[byte_size(32)] pub struct HasCounted { #[offset(0)] @@ -439,15 +424,15 @@ pub struct HasCounted { #[byte_size(24)] pub w: Vec, } -impl ConstructibleFrom<()> for HasCounted { - fn constructor(this: Ptr, _: ()) { - >::constructor(field_ptr!(this, c), ()); +impl HasCounted { + pub fn constructor_1(this: Ptr) { + Counted_int_::constructor_1(field_ptr!(this, c)); field!(this, w).write(Vec::new()); } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Conversions)] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_3, move = constructor_4, default = constructor_1)] +#[constructor(constructor_2, value(i32))] #[byte_size(16)] pub struct CtorSeesThis { #[offset(0)] @@ -456,37 +441,26 @@ pub struct CtorSeesThis { #[offset(8)] pub id: i32, } -impl ConstructibleFrom<()> for CtorSeesThis { - fn constructor(this: Ptr, _: ()) { +impl CtorSeesThis { + pub fn constructor_1(this: Ptr) { field!(this, self_).write((this).clone()); field!(this, id).write(0); } -} -impl ConstructibleFrom<(i32,)> for CtorSeesThis { - fn constructor(this: Ptr, (mut id,): (i32,)) { - >::constructor(this.clone(), ()); + pub fn constructor_2(this: Ptr, mut id: i32) { + CtorSeesThis::constructor_1(this.clone()); field!(this, id).write(id); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for CtorSeesThis { - fn constructor(this: Ptr, (_a0,): (LvalueRef>,)) { + pub fn constructor_3(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); field!(this, id).write(0); } -} -impl CopyConstructible for CtorSeesThis {} -impl ConvertibleTo for LvalueRef> {} -impl ConstructibleFrom<(RvalueRef,)> for CtorSeesThis { - fn constructor(this: Ptr, (_a0,): (RvalueRef,)) { + pub fn constructor_4(this: Ptr, _a0: RvalueRef) { let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); field!(this, id).write(0); } } -impl MoveConstructible for CtorSeesThis {} -impl ConvertibleTo for RvalueRef {} impl CopyAssignable for CtorSeesThis { fn copy_assign(this: Ptr, _a0: LvalueRef>) -> Ptr { let _a0 = _a0.as_pointer(); @@ -503,8 +477,9 @@ impl Default for CtorSeesThis { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CtorSeesThis::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -515,7 +490,7 @@ impl Default for CtorSeesThis { )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(40)] pub struct HasCtorSeesThis { #[offset(0)] @@ -525,16 +500,16 @@ pub struct HasCtorSeesThis { #[byte_size(24)] pub v: Vec, } -impl ConstructibleFrom<()> for HasCtorSeesThis { - fn constructor(this: Ptr, _: ()) { - >::constructor(field_ptr!(this, x), ()); +impl HasCtorSeesThis { + pub fn constructor_1(this: Ptr) { + CtorSeesThis::constructor_1(field_ptr!(this, x)); field!(this, v).write(Vec::new()); } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(32)] pub struct InitsCtorSeesThis { #[offset(0)] @@ -544,10 +519,10 @@ pub struct InitsCtorSeesThis { #[byte_size(16)] pub y: CtorSeesThis, } -impl ConstructibleFrom<()> for InitsCtorSeesThis { - fn constructor(this: Ptr, _: ()) { - >::constructor(field_ptr!(this, x), (1,)); - >::constructor(field_ptr!(this, y), (2,)); +impl InitsCtorSeesThis { + pub fn constructor_1(this: Ptr) { + CtorSeesThis::constructor_2(field_ptr!(this, x), 1); + CtorSeesThis::constructor_2(field_ptr!(this, y), 2); } } impl Default for InitsCtorSeesThis { @@ -555,8 +530,8 @@ impl Default for InitsCtorSeesThis { { { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + InitsCtorSeesThis::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -575,7 +550,7 @@ impl Default for InitsCtorSeesThis { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move)] #[byte_size(24)] pub struct OutOfLineDefaulted { #[offset(0)] @@ -586,23 +561,16 @@ pub struct OutOfLineDefaulted { } impl OutOfLineDefaulted { pub fn construct(this: Ptr) { - >::constructor(field_ptr!(this, x), ()); + CtorSeesThis::constructor_1(field_ptr!(this, x)); field!(this, v).write(1); } -} -impl ConstructibleFrom<(LvalueRef>,)> for OutOfLineDefaulted { - fn constructor(this: Ptr, (_a0,): (LvalueRef>,)) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); - >,)>>::constructor( - field_ptr!(this, x), - (LvalueRef::bind(field_ptr!(_a0, x)),), - ); + CtorSeesThis::constructor_3(field_ptr!(this, x), LvalueRef::bind(field_ptr!(_a0, x))); field!(this, v).write(_a0.with(|__s| __s.v)); } } -impl CopyConstructible for OutOfLineDefaulted {} -impl ConvertibleTo for LvalueRef> {} -impl ConstructibleFrom<()> for OutOfLineDefaulted { +impl Constructor<()> for OutOfLineDefaulted { fn constructor(this: Ptr, _: ()) { { OutOfLineDefaulted::construct(this.clone()); @@ -614,7 +582,7 @@ impl Default for OutOfLineDefaulted { { { let __v: Value = - Rc::new(RefCell::new(::zero_init())); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); OutOfLineDefaulted::construct(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } @@ -622,7 +590,9 @@ impl Default for OutOfLineDefaulted { } } impl OutOfLineDefaulted {} +impl OutOfLineDefaulted {} #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] +#[conversions(default = constructor_1)] #[byte_size(40)] pub struct OutOfLineAssign { #[offset(0)] @@ -634,9 +604,9 @@ pub struct OutOfLineAssign { #[byte_size(24)] pub w: Vec, } -impl ConstructibleFrom<()> for OutOfLineAssign { - fn constructor(this: Ptr, _: ()) { - >::constructor(field_ptr!(this, s), ()); +impl OutOfLineAssign { + pub fn constructor_1(this: Ptr) { + SeesThis::constructor_1(field_ptr!(this, s)); field!(this, v).write(1); field!(this, w).write(Vec::new()); } @@ -684,7 +654,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, Explicit, (i32,), (1,)); + object!(a, Explicit::constructor_1(1)); let b: Value = Rc::new(RefCell::new((*a.borrow()).clone())); let _dtor_b = std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(__p.as_pointer())); @@ -699,15 +669,15 @@ fn main_0() -> i32 { && ({ same_0(c.as_pointer(), a.as_pointer(),) })) && ({ same_0(d.as_pointer(), a.as_pointer(),) }) ); - object!(e, Explicit, (i32,), (2,)); - object!(f, Explicit, (i32,), (3,)); + object!(e, Explicit::constructor_1(2)); + object!(f, Explicit::constructor_1(3)); assign!(e = b); assign!(f = RvalueRef(c)); assert!( ({ same_0(e.as_pointer(), b.as_pointer(),) }) && ({ same_0(f.as_pointer(), c.as_pointer(),) }) ); - object!(g, Explicit, (i32,), (4,)); + object!(g, Explicit::constructor_1(4)); assign!(g = *assign!(e = f)); assert!( ({ same_0(g.as_pointer(), f.as_pointer(),) }) @@ -732,8 +702,8 @@ fn main_0() -> i32 { let vec_: Value> = Rc::new(RefCell::new(Vec::new())); CopyConstructible::push_copied(&vec_.as_pointer(), b.as_pointer()); match (Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (9,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Explicit::constructor_1(__v.as_pointer(), 9); Rc::try_unwrap(__v).ok().unwrap().into_inner() })) .as_pointer(),) @@ -741,42 +711,46 @@ fn main_0() -> i32 { (__tmp_1,) => MoveConstructible::push_moved(&vec_.as_pointer(), (__tmp_1).clone()), }; assert!(({ (*vec_.borrow())[0_usize].v } == 1) && ({ (*vec_.borrow())[1_usize].v } == 9)); - object!(m, DefaultCopyUserMove, (i32,), (7,)); + object!(m, DefaultCopyUserMove::constructor_1(7)); let m1: Value = Rc::new(RefCell::new((*m.borrow()))); object!( m2, - DefaultCopyUserMove = >::bind(m.as_pointer()) + DefaultCopyUserMove::constructor_3(RvalueRef::bind(m.as_pointer())) ); assert!( (({ (*m1.borrow()).v } == 7) && ({ (*m2.borrow()).v } == 7)) && ({ (*m.borrow()).v } == 0) ); - object!(m3, DefaultCopyUserMove, (i32,), (1,)); - object!(m4, DefaultCopyUserMove, (i32,), (1,)); + object!(m3, DefaultCopyUserMove::constructor_1(1)); + object!(m4, DefaultCopyUserMove::constructor_1(1)); assign!(m3 = m1); assign!(m4 = RvalueRef(m1)); assert!( (({ (*m3.borrow()).v } == 7) && ({ (*m4.borrow()).v } == 7)) && ({ (*m1.borrow()).v } == 0) ); - object!(u, UserCopyDefaultMove, (i32,), (8,)); + object!(u, UserCopyDefaultMove::constructor_1(8)); object!( u1, - UserCopyDefaultMove = >>::bind(u.as_pointer()) - ); - object!( - u2, - UserCopyDefaultMove = >::bind(u.as_pointer()) + UserCopyDefaultMove::constructor_2(LvalueRef::bind(u.as_pointer())) ); + object!(u2, UserCopyDefaultMove, |u2| { + ::move_constructor( + u2.clone(), + RvalueRef::bind(u.as_pointer()), + ) + }); assert!( (({ (*u1.borrow()).v } == 108) && ({ (*u2.borrow()).v } == 8)) && ({ (*u.borrow()).v } == 8) ); - object!(u3, UserCopyDefaultMove, (i32,), (1,)); - object!(u4, UserCopyDefaultMove, (i32,), (1,)); + object!(u3, UserCopyDefaultMove::constructor_1(1)); + object!(u4, UserCopyDefaultMove::constructor_1(1)); assign!(u3 = u2); assign!(u4 = RvalueRef(u2)); assert!(({ (*u3.borrow()).v } == 108) && ({ (*u4.borrow()).v } == 8)); - object!(p, Buffer, (i32,), (3,)); - object!(q, Buffer = >::bind(p.as_pointer())); + object!(p, Buffer::constructor_1(3)); + object!(q, Buffer, |q| { + ::move_constructor(q.clone(), RvalueRef::bind(p.as_pointer())) + }); assert!( ({ ((({ (*q.borrow()).n } == 3) && ((*q.borrow()).data.len() == 3_usize)) @@ -784,7 +758,7 @@ fn main_0() -> i32 { && ((*p.borrow()).data.is_empty()) }) ); - object!(r, Buffer, (i32,), (1,)); + object!(r, Buffer::constructor_1(1)); assign!(r = RvalueRef(q)); assert!( ({ @@ -811,10 +785,10 @@ fn main_0() -> i32 { { let mut __tmp_2 = { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ,)>>::constructor( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + ::move_constructor( __v.as_pointer(), - (RvalueRef::bind(bufs.decay().offset(0_usize)),), + RvalueRef::bind(bufs.decay().offset(0_usize)), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() } @@ -828,7 +802,7 @@ fn main_0() -> i32 { && ((*bufs.borrow())[0_usize].data.is_empty()) }) ); - object!(o1, Owner); + object!(o1, Owner::constructor_1()); ({ let __tmp_3: Value = Rc::new(RefCell::new(5)); MoveConstructible::push_moved( @@ -840,7 +814,9 @@ 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 = >::bind(o1.as_pointer())); + object!(o2, Owner, |o2| { + ::move_constructor(o2.clone(), RvalueRef::bind(o1.as_pointer())) + }); assert!( ({ ((({ (*o2.borrow()).n } == 5) && ((*o2.borrow()).data.len() == 1_usize)) @@ -854,7 +830,7 @@ fn main_0() -> i32 { && (({ (*o1.borrow()).p.clone() }.as_pointer()).is_null()) }) ); - object!(o3, Owner); + object!(o3, Owner::constructor_1()); assign!(o3 = RvalueRef(o2)); assert!( ((({ (*o3.borrow()).n } == 5) @@ -872,10 +848,15 @@ fn main_0() -> i32 { data: Vec::from([1, 2]), })); let mut c2: Copyable = (*c1.borrow()).clone(); - object!(c3, Copyable = >::bind(c1.as_pointer())); + object!(c3, Copyable, |c3| { + ::move_constructor( + c3.clone(), + 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); + object!(c4, Copyable::constructor_1()); assign!(c4 = RvalueRef(c3)); assert!( ({ @@ -883,15 +864,20 @@ fn main_0() -> i32 { && ((*c3.borrow()).data.is_empty()) }) ); - object!(h1, Holder, (i32,), (4,)); + object!(h1, Holder::constructor_1(4)); field_ptr!(h1.as_pointer(), p).write(Ptr::alloc(9).to_owned_opt()); - object!(h2, Holder = >::bind(h1.as_pointer())); + object!(h2, Holder, |h2| { + ::move_constructor( + h2.clone(), + 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, (i32,), (1,)); + object!(h3, Holder::constructor_1(1)); assign!(h3 = RvalueRef(h2)); assert!( ((({ (*h3.borrow()).inner.x } == 4) @@ -899,40 +885,58 @@ fn main_0() -> i32 { && (({ (*h3.borrow()).p.clone() }.as_pointer().read()) == 9)) && (({ (*h2.borrow()).p.clone() }.as_pointer()).is_null()) ); - object!(t1, HasSeesThis); - object!(t2, HasSeesThis); - object!(t3, HasSeesThis); + object!(t1, HasSeesThis::constructor_1()); + object!(t2, HasSeesThis::constructor_1()); + object!(t3, HasSeesThis::constructor_1()); 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, RvalueRef::bind(k1.as_pointer())); + object!(k1, HasCounted::constructor_1()); + object!(k2, HasCounted, |k2| { + ::move_constructor( + k2.clone(), + RvalueRef::bind(k1.as_pointer()), + ) + }); assert!(({ (*k2.borrow()).c.moves } == 1)); - object!(k3, HasCounted); + object!(k3, HasCounted::constructor_1()); assign!(k3 = RvalueRef(k2)); assert!(({ (*k3.borrow()).c.moves } == 2)); { - object!(d, CtorSeesThis); + object!(d, CtorSeesThis::constructor_1()); assert!(({ { (*d.borrow()).self_.clone() } } == { (d.as_pointer()) })); - object!(e, CtorSeesThis, LvalueRef::bind(d.as_pointer())); + object!( + e, + CtorSeesThis::constructor_3(LvalueRef::bind(d.as_pointer())) + ); assert!(({ { (*e.borrow()).self_.clone() } } == { (e.as_pointer()) })); - object!(f, CtorSeesThis, (i32,), (3,)); + object!(f, CtorSeesThis::constructor_2(3)); assert!( ({ { (*f.borrow()).self_.clone() } } == { (f.as_pointer()) }) && ({ (*f.borrow()).id } == 3) ); - object!(h1, HasCtorSeesThis); + object!(h1, HasCtorSeesThis::constructor_1()); assert!(({ { (*h1.borrow()).x.self_.clone() } } == { (field_ptr!(h1.as_pointer(), x)) })); - object!(h2, HasCtorSeesThis, LvalueRef::bind(h1.as_pointer())); + object!(h2, HasCtorSeesThis, |h2| { + ::copy_constructor( + h2.clone(), + 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())); + object!(h3, HasCtorSeesThis, |h3| { + ::move_constructor( + h3.clone(), + RvalueRef::bind(h1.as_pointer()), + ) + }); assert!(({ { (*h3.borrow()).x.self_.clone() } } == { (field_ptr!(h3.as_pointer(), x)) })); 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)) })); - object!(i, InitsCtorSeesThis); + object!(i, InitsCtorSeesThis::constructor_1()); assert!( ({ { (*i.borrow()).x.self_.clone() } } == { (field_ptr!(i.as_pointer(), x)) }) && ({ (*i.borrow()).x.id } == 1) @@ -943,7 +947,7 @@ fn main_0() -> i32 { ); let mut p: Ptr = { let __p = Ptr::alloc(::zero_init()); - >::constructor(__p.clone(), (4,)); + CtorSeesThis::constructor_2(__p.clone(), 4); __p }; assert!( @@ -956,14 +960,17 @@ fn main_0() -> i32 { && ({ { (*o1.borrow()).x.self_.clone() } } == { (field_ptr!(o1.as_pointer(), x)) }) ); (*o1.borrow_mut()).v = 2; - object!(o2, OutOfLineDefaulted, LvalueRef::bind(o1.as_pointer())); + object!( + o2, + OutOfLineDefaulted::constructor_2(LvalueRef::bind(o1.as_pointer())) + ); assert!( ({ (*o2.borrow()).v } == 2) && ({ { (*o2.borrow()).x.self_.clone() } } == { (field_ptr!(o2.as_pointer(), x)) }) ); - object!(a1, OutOfLineAssign); - object!(a2, OutOfLineAssign); - object!(a3, OutOfLineAssign); + object!(a1, OutOfLineAssign::constructor_1()); + object!(a2, OutOfLineAssign::constructor_1()); + object!(a3, OutOfLineAssign::constructor_1()); (*a1.borrow_mut()).v = 3; ({ let __tmp_4: Value = Rc::new(RefCell::new(4)); diff --git a/tests/unit/out/refcount/copy_move_deleted.rs b/tests/unit/out/refcount/copy_move_deleted.rs index ba9074100b..b1942875b8 100644 --- a/tests/unit/out/refcount/copy_move_deleted.rs +++ b/tests/unit/out/refcount/copy_move_deleted.rs @@ -16,28 +16,23 @@ use std::rc::{Rc, Weak}; Default, Conversions, )] -#[conversions(move)] -#[constructor(value(i32))] +#[conversions(move = constructor_3)] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct NoCopy { #[offset(0)] pub v: i32, } -impl ConstructibleFrom<(i32,)> for NoCopy { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl NoCopy { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(RvalueRef,)> for NoCopy { - fn constructor(this: Ptr, (o,): (RvalueRef,)) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } -impl MoveConstructible for NoCopy {} -impl ConvertibleTo for RvalueRef {} impl MoveAssignable for NoCopy { fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { let o = o.as_pointer(); @@ -47,26 +42,22 @@ impl MoveAssignable for NoCopy { } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move = constructor_3, default = constructor_2)] #[byte_size(4)] pub struct PrivateCopy { #[offset(0)] pub v: i32, } -impl ConstructibleFrom<()> for PrivateCopy { - fn constructor(this: Ptr, _: ()) { +impl PrivateCopy { + pub fn constructor_2(this: Ptr) { field!(this, v).write(0); } -} -impl ConstructibleFrom<(RvalueRef,)> for PrivateCopy { - fn constructor(this: Ptr, (o,): (RvalueRef,)) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } -impl MoveConstructible for PrivateCopy {} -impl ConvertibleTo for RvalueRef {} impl MoveAssignable for PrivateCopy { fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { let o = o.as_pointer(); @@ -79,21 +70,23 @@ impl Default for PrivateCopy { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + PrivateCopy::constructor_2(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] +#[conversions(default = constructor_1)] #[byte_size(4)] pub struct Immovable { #[offset(0)] pub v: i32, } -impl ConstructibleFrom<()> for Immovable { - fn constructor(this: Ptr, _: ()) { +impl Immovable { + pub fn constructor_1(this: Ptr) { field!(this, v).write(0); } } @@ -101,8 +94,8 @@ impl Default for Immovable { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Immovable::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -129,20 +122,21 @@ pub struct Container { #[offset(4)] pub tag: i32, } +impl Container {} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, )] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] #[byte_size(24)] pub struct VecHolder { #[offset(0)] #[byte_size(24)] pub items: Vec, } -impl ConstructibleFrom<()> for VecHolder { - fn constructor(this: Ptr, _: ()) { +impl VecHolder { + pub fn constructor_1(this: Ptr) { field!(this, items).write(Vec::new()); } } @@ -157,39 +151,52 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, NoCopy, (i32,), (1,)); - object!(b, NoCopy, RvalueRef::bind(a.as_pointer())); + object!(a, NoCopy::constructor_1(1)); + object!(b, NoCopy::constructor_3(RvalueRef::bind(a.as_pointer()))); assert!(({ (*b.borrow()).v } == 1) && ({ (*a.borrow()).v } == 0)); 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); + object!(p, PrivateCopy::constructor_2()); (*p.borrow_mut()).v = 3; - object!(q, PrivateCopy, RvalueRef::bind(p.as_pointer())); + object!( + q, + PrivateCopy::constructor_3(RvalueRef::bind(p.as_pointer())) + ); assert!(({ (*q.borrow()).v } == 3) && ({ (*p.borrow()).v } == 0)); assign!(p = RvalueRef(q)); assert!(({ (*p.borrow()).v } == 3) && ({ (*q.borrow()).v } == 0)); - object!(im, Immovable); + object!(im, Immovable::constructor_1()); (*im.borrow_mut()).v = 4; ({ bump_ref_1(im.as_pointer()) }); let mut pim: Ptr = (im.as_pointer()); assert!((pim.with(|__s| __s.v) == 5)); let c: Value = Rc::new(RefCell::new(Container { inner: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (6,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + NoCopy::constructor_1(__v.as_pointer(), 6); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, tag: 7, })); - object!(d, Container, RvalueRef::bind(c.as_pointer())); + object!(d, Container, |d| { + ::move_constructor( + d.clone(), + 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, RvalueRef::bind(h.as_pointer())); + object!(h, VecHolder::constructor_1()); + object!(h2, VecHolder, |h2| { + ::move_constructor( + h2.clone(), + RvalueRef::bind(h.as_pointer()), + ) + }); assert!(({ ((*h2.borrow()).items.len() == 0_usize) })); return 0; } @@ -198,7 +205,7 @@ impl CopyAssignable for PrivateCopy { unreachable!("PrivateCopy::copy_assign is never defined") } } -impl ConstructibleFrom<(LvalueRef>,)> for PrivateCopy { +impl Constructor<(LvalueRef>,)> for PrivateCopy { fn constructor(this: Ptr, _: (LvalueRef>,)) { unreachable!("PrivateCopy::copy_constructor is never defined") } diff --git a/tests/unit/out/refcount/default_function_arguments.rs b/tests/unit/out/refcount/default_function_arguments.rs index 76f4176c76..313642dd62 100644 --- a/tests/unit/out/refcount/default_function_arguments.rs +++ b/tests/unit/out/refcount/default_function_arguments.rs @@ -24,22 +24,21 @@ pub fn baz_1(mut a: Ptr, mut b: Ptr) -> bool { Conversions, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct Bar { #[offset(0)] pub v: i32, } -impl ConstructibleFrom<(i32,)> for Bar { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl Bar { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } } -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<()> for Bar { +impl Constructor<()> for Bar { fn constructor(this: Ptr, _: ()) { { - >::constructor(this.clone(), (1,)); + Bar::constructor_1(this.clone(), 1); } } } @@ -47,8 +46,8 @@ impl Default for Bar { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (1,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Bar::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -68,8 +67,8 @@ pub fn by_ref_5(b: Ptr) -> i32 { } thread_local!( pub static global_bar_6: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (9,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Bar::constructor_1(__v.as_pointer(), 9); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -96,14 +95,14 @@ pub fn first_9(r: Ptr) -> i32 { Conversions, )] #[conversions(copy, move)] -#[constructor(explicit, value(i32))] +#[constructor(constructor_1, explicit, value(i32))] #[byte_size(4)] pub struct Holder_int_ { #[offset(0)] pub v: i32, } -impl ConstructibleFrom<(i32,)> for Holder_int_ { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl Holder_int_ { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } } @@ -117,13 +116,13 @@ fn main_0() -> i32 { let a: Value = Rc::new(RefCell::new(0)); assert!(((({ baz_1((a.as_pointer()), Ptr::::null(),) }) as i32) == (false as i32))); assert!(((({ baz_1((a.as_pointer()), (a.as_pointer()),) }) as i32) == (true as i32))); - object!(b, Bar, (i32,), (1,)); + object!(b, Bar::constructor_1(1)); assert!(({ (*b.borrow()).v } == 1)); { - let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_0: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); assert!( ({ - >::constructor(__tmp_0.as_pointer(), (2,)); + Bar::constructor_1(__tmp_0.as_pointer(), 2); __tmp_0.as_pointer() } .with(|__s| __s.v) @@ -132,18 +131,18 @@ fn main_0() -> i32 { }; let mut arr: [Bar; 3] = [ { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (1,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Bar::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (1,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Bar::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (1,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Bar::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]; @@ -155,27 +154,27 @@ fn main_0() -> i32 { assert!((counter_2.with(|rc| *rc.borrow()) == 1)); assert!( (({ - let _b: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(_b.as_pointer(), (7,)); + let _b: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Bar::constructor_1(_b.as_pointer(), 7); by_ref_5(_b.as_pointer()) }) == 7) ); assert!( (({ - let _b: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(_b.as_pointer(), (3,)); + let _b: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Bar::constructor_1(_b.as_pointer(), 3); by_ref_5(_b.as_pointer()) }) == 3) ); assert!((({ by_global_ref_7(global_bar_6.with(|v| v.as_pointer()),) }) == 9)); assert!( (({ - let _b: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(_b.as_pointer(), (4,)); + let _b: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Bar::constructor_1(_b.as_pointer(), 4); by_global_ref_7(_b.as_pointer()) }) == 4) ); - object!(h, Holder_int_, (i32,), (4,)); + object!(h, Holder_int_::constructor_1(4)); assert!(({ (*h.borrow()).v } == 4)); assert!((({ shifted_8(3, -1_i32,) }) == 2)); assert!((({ shifted_8(3, 4,) }) == 7)); diff --git a/tests/unit/out/refcount/delete_array_order.rs b/tests/unit/out/refcount/delete_array_order.rs index 38119de0d4..17621816ec 100644 --- a/tests/unit/out/refcount/delete_array_order.rs +++ b/tests/unit/out/refcount/delete_array_order.rs @@ -20,7 +20,7 @@ use std::rc::{Rc, Weak}; )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy, move)] #[byte_size(16)] pub struct Element { #[offset(0)] diff --git a/tests/unit/out/refcount/destructor.rs b/tests/unit/out/refcount/destructor.rs index bc17b6fa88..21869de643 100644 --- a/tests/unit/out/refcount/destructor.rs +++ b/tests/unit/out/refcount/destructor.rs @@ -23,7 +23,7 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy, move)] #[byte_size(1)] pub struct S {} impl Destructible for S { @@ -46,7 +46,7 @@ impl Destructible for S { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy, move)] #[byte_size(1)] pub struct Defaulted { #[offset(0)] @@ -141,7 +141,7 @@ pub struct ArrayMember { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy, move)] #[byte_size(1)] pub struct EmptyBody { #[offset(0)] @@ -167,7 +167,7 @@ impl Destructible for EmptyBody { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy, move)] #[byte_size(1)] pub struct Templated_char_ { #[offset(0)] @@ -197,7 +197,7 @@ impl Destructible for Templated_char_ { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy, move)] #[byte_size(4)] pub struct Templated_int_ { #[offset(0)] @@ -227,7 +227,7 @@ impl Destructible for Templated_int_ { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy, move)] #[byte_size(4)] pub struct Copied { #[offset(0)] @@ -259,7 +259,7 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy, move)] #[byte_size(4)] pub struct Tagged { #[offset(0)] diff --git a/tests/unit/out/refcount/destructor_params.rs b/tests/unit/out/refcount/destructor_params.rs index 8edf57ae4b..2f4d4af2c7 100644 --- a/tests/unit/out/refcount/destructor_params.rs +++ b/tests/unit/out/refcount/destructor_params.rs @@ -26,7 +26,7 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy, move)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -59,22 +59,20 @@ pub fn with_default_3(s: Ptr) -> i32 { Conversions, )] #[conversions(copy, move)] -#[constructor(explicit, by_value(S))] +#[constructor(constructor_1, explicit, by_value(S))] #[byte_size(4)] pub struct Holder { #[offset(0)] pub v: i32, } impl Holder { - pub fn add(this: Ptr, s: Ptr) -> i32 { - return (this.with(|__s| __s.v) + s.with(|__s| __s.v)); - } -} -impl ConstructibleFrom<(LvalueRef,)> for Holder { - fn constructor(this: Ptr, (s,): (LvalueRef,)) { + pub fn constructor_1(this: Ptr, s: LvalueRef) { let s = s.as_pointer(); field!(this, v).write(s.with(|__s| __s.v)); } + pub fn add(this: Ptr, s: Ptr) -> i32 { + return (this.with(|__s| __s.v) + s.with(|__s| __s.v)); + } } pub fn main() { __cpp2rust_init_globals(); @@ -118,10 +116,7 @@ fn main_0() -> i32 { { object!(h, Holder, |h| { let __tmp_0: Value = Rc::new(RefCell::new(S { v: 3 })); - ,)>>::constructor( - h.clone(), - (LvalueRef::bind(__tmp_0.as_pointer()),), - ) + Holder::constructor_1(h.clone(), LvalueRef::bind(__tmp_0.as_pointer())) }); assert!( (destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 3) diff --git a/tests/unit/out/refcount/destructor_temporaries.rs b/tests/unit/out/refcount/destructor_temporaries.rs index cedae7c049..39d2ed8fb1 100644 --- a/tests/unit/out/refcount/destructor_temporaries.rs +++ b/tests/unit/out/refcount/destructor_temporaries.rs @@ -26,7 +26,7 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy, move)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -93,19 +93,19 @@ pub fn main() { } fn main_0() -> i32 { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ make_2(Ptr::clone(&__v.as_pointer()), 1) }); }; assert!((destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 1)); destroyed_0.with(|rc| *rc.borrow_mut() = 0); &({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ make_2(Ptr::clone(&__v.as_pointer()), 2) }); }); assert!((destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 2)); destroyed_0.with(|rc| *rc.borrow_mut() = 0); let mut x: i32 = { - let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_0: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); { ({ make_2(Ptr::clone(&__tmp_0.as_pointer()), 3) }); __tmp_0.as_pointer() @@ -118,7 +118,7 @@ fn main_0() -> i32 { ); destroyed_0.with(|rc| *rc.borrow_mut() = 0); { - let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); x = ({ S::get({ ({ make_2(Ptr::clone(&__tmp_1.as_pointer()), 4) }); @@ -132,7 +132,7 @@ fn main_0() -> i32 { ); destroyed_0.with(|rc| *rc.borrow_mut() = 0); { - let __tmp_2: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_2: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); x = { ({ make_outer_3(Ptr::clone(&__tmp_2.as_pointer())) }); __tmp_2.as_pointer() @@ -148,7 +148,7 @@ fn main_0() -> i32 { assert!((x == 5) && (destroyed_0.with(|rc| *rc.borrow()) == 1)); destroyed_0.with(|rc| *rc.borrow_mut() = 0); x = ({ - let _s: Value = Rc::new(RefCell::new(::zero_init())); + let _s: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ make_2(Ptr::clone(&_s.as_pointer()), 6) }); use_4(_s.as_pointer()) }); @@ -169,7 +169,7 @@ fn main_0() -> i32 { x = { (if (x == 3) { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ make_2(Ptr::clone(&__v.as_pointer()), 9) }); Rc::try_unwrap(__v).ok().unwrap().into_inner() } @@ -184,7 +184,7 @@ fn main_0() -> i32 { ); destroyed_0.with(|rc| *rc.borrow_mut() = 0); { - let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_3: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ make_2(Ptr::clone(&__tmp_3.as_pointer()), 11) }); let r: Ptr = __tmp_3.as_pointer(); assert!((destroyed_0.with(|rc| *rc.borrow()) == 0) && (r.with(|__s| __s.v) == 11)); @@ -196,7 +196,7 @@ fn main_0() -> i32 { let _dtor_s = std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(__p.as_pointer())); ({ - let _arg0: Value = Rc::new(RefCell::new(::zero_init())); + let _arg0: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ make_2(Ptr::clone(&_arg0.as_pointer()), 13) }); assign!(s = _arg0) }); diff --git a/tests/unit/out/refcount/emplace_receiver_alias.rs b/tests/unit/out/refcount/emplace_receiver_alias.rs index ca6211454f..7fc1217ace 100644 --- a/tests/unit/out/refcount/emplace_receiver_alias.rs +++ b/tests/unit/out/refcount/emplace_receiver_alias.rs @@ -39,9 +39,9 @@ fn main_0() -> i32 { while >::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( __v.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } diff --git a/tests/unit/out/refcount/emplace_receiver_order.rs b/tests/unit/out/refcount/emplace_receiver_order.rs index 94f69a57b7..cb369b1ee9 100644 --- a/tests/unit/out/refcount/emplace_receiver_order.rs +++ b/tests/unit/out/refcount/emplace_receiver_order.rs @@ -47,9 +47,9 @@ fn main_0() -> i32 { { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( __v.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } @@ -74,9 +74,9 @@ fn main_0() -> i32 { { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( __v.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } diff --git a/tests/unit/out/refcount/enum_underlying_type.rs b/tests/unit/out/refcount/enum_underlying_type.rs index 6bd6c69a7d..3e882309bd 100644 --- a/tests/unit/out/refcount/enum_underlying_type.rs +++ b/tests/unit/out/refcount/enum_underlying_type.rs @@ -36,14 +36,14 @@ pub type Empty = bool; TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(1)] pub struct HoldsEmpty { #[offset(0)] pub e: Empty, } -impl ConstructibleFrom<()> for HoldsEmpty { - fn constructor(this: Ptr, _: ()) { +impl HoldsEmpty { + pub fn constructor_1(this: Ptr) { field!(this, e).write(::default()); } } @@ -87,7 +87,7 @@ fn main_0() -> i32 { let mut sc: Scoped = Scoped_NEG; assert!(((sc as i32) == -2_i32)); assert!((((Scoped_POS as i8) as i32) == 2)); - object!(he, HoldsEmpty); + object!(he, HoldsEmpty::constructor_1()); assert!(!({ (*he.borrow()).e })); let mut ev: Empty = ::default(); assert!(((ev as i32) == ({ (*he.borrow()).e } as i32))); diff --git a/tests/unit/out/refcount/field_method_receiver.rs b/tests/unit/out/refcount/field_method_receiver.rs index 4d28a2c6ac..41d3b0ec1a 100644 --- a/tests/unit/out/refcount/field_method_receiver.rs +++ b/tests/unit/out/refcount/field_method_receiver.rs @@ -59,7 +59,7 @@ impl Counter { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(40)] pub struct S { #[offset(0)] @@ -79,9 +79,7 @@ impl S { pub fn bump(this: Ptr) { ({ Counter::add(field_ptr!(this, c), this.with(|__s| __s.tag)) }); } -} -impl ConstructibleFrom<()> for S { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, tag).write(0_i32); field!(this, c).write(::default()); field!(this, arr).write( diff --git a/tests/unit/out/refcount/field_pointers.rs b/tests/unit/out/refcount/field_pointers.rs index 918ef78419..c60a9d9980 100644 --- a/tests/unit/out/refcount/field_pointers.rs +++ b/tests/unit/out/refcount/field_pointers.rs @@ -72,7 +72,7 @@ pub struct Header { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(104)] pub struct Outer { #[offset(0)] @@ -108,9 +108,7 @@ impl Outer { MoveConstructible::push_moved(&field_ref!(this, v).as_pointer(), __tmp_0.as_pointer()) }); } -} -impl ConstructibleFrom<()> for Outer { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, x).write(0_i32); field!(this, inner).write(::default()); field!(this, items).write((0..3).map(|_| ::default()).collect::>()); diff --git a/tests/unit/out/refcount/fn_ptr.rs b/tests/unit/out/refcount/fn_ptr.rs index feda63552b..002a90289a 100644 --- a/tests/unit/out/refcount/fn_ptr.rs +++ b/tests/unit/out/refcount/fn_ptr.rs @@ -47,18 +47,12 @@ pub struct HashHolder_unsigned_long__ptr__bool__ { #[byte_size(8)] pub h: FnPtr u64>, } -impl ConstructibleFrom<(LvalueRef u64>>>,)> - for HashHolder_unsigned_long__ptr__bool__ -{ - fn constructor(this: Ptr, (h,): (LvalueRef u64>>>,)) { +impl HashHolder_unsigned_long__ptr__bool__ { + pub fn constructor_1(this: Ptr, h: LvalueRef u64>>>) { let h = h.as_pointer(); field!(this, h).write((h.read())); } } -impl ConvertibleTo - for LvalueRef u64>>> -{ -} thread_local!( pub static total_7: Value = Rc::new(RefCell::new(0)); ); @@ -107,9 +101,10 @@ fn main_0() -> i32 { let __tmp_0: Value u64>> = Rc::new(RefCell::new( (FnPtr:: usize>::new(identity_hash_6)).cast:: u64>(), )); - u64>>>, - )>>::constructor(hh.clone(), (LvalueRef::bind(__tmp_0.as_pointer()),)) + HashHolder_unsigned_long__ptr__bool__::constructor_1( + hh.clone(), + LvalueRef::bind(__tmp_0.as_pointer()), + ) }); assert!((({ { (*hh.borrow()).h.clone() }.call(true,) }) == 1_u64)); let mut handler: FnPtr = FnPtr::::new(add_to_total_8); diff --git a/tests/unit/out/refcount/fn_ptr_struct.rs b/tests/unit/out/refcount/fn_ptr_struct.rs index c52c41562d..5a86c4e3e5 100644 --- a/tests/unit/out/refcount/fn_ptr_struct.rs +++ b/tests/unit/out/refcount/fn_ptr_struct.rs @@ -63,39 +63,32 @@ impl S { #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[conversions(move)] -#[constructor(value(i32))] +#[conversions(move = constructor_2)] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct MoveOnly { #[offset(0)] pub data_: i32, } impl MoveOnly { - pub fn get(this: Ptr) -> i32 { - return this.with(|__s| __s.data_); - } -} -impl ConstructibleFrom<(i32,)> for MoveOnly { - fn constructor(this: Ptr, (mut data,): (i32,)) { + pub fn constructor_1(this: Ptr, mut data: i32) { field!(this, data_).write(data); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(RvalueRef,)> for MoveOnly { - fn constructor(this: Ptr, (x,): (RvalueRef,)) { + pub fn constructor_2(this: Ptr, x: RvalueRef) { let x = x.as_pointer(); field!(this, data_).write(x.with(|__s| __s.data_)); field!(x, data_).write(0); } + pub fn get(this: Ptr) -> i32 { + return this.with(|__s| __s.data_); + } } -impl MoveConstructible for MoveOnly {} -impl ConvertibleTo for RvalueRef {} pub fn make_move_only_2(__return: Ptr) { - ConvertibleTo::convert(4, __return.clone()); + MoveOnly::constructor_1(__return.clone(), 4); return; } pub fn scale_move_only_3(__return: Ptr, x: Ptr) { - ConvertibleTo::convert((({ MoveOnly::get((x).clone()) }) * 10), __return.clone()); + MoveOnly::constructor_1(__return.clone(), (({ MoveOnly::get((x).clone()) }) * 10)); return; } pub fn main() { @@ -133,11 +126,8 @@ fn main_0() -> i32 { let mut sc: FnPtr, Ptr)> = FnPtr::, Ptr)>::new(scale_move_only_3); object!(n, MoveOnly, |n| ({ - let _arg0: Value = Rc::new(RefCell::new(::zero_init())); - ,)>>::constructor( - _arg0.as_pointer(), - (RvalueRef::bind(m.as_pointer()),), - ); + let _arg0: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MoveOnly::constructor_2(_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/for_body_destructor.rs b/tests/unit/out/refcount/for_body_destructor.rs index 27f81d26b6..0649007c38 100644 --- a/tests/unit/out/refcount/for_body_destructor.rs +++ b/tests/unit/out/refcount/for_body_destructor.rs @@ -20,25 +20,25 @@ use std::rc::{Rc, Weak}; )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] -#[conversion_function(bool, const_lvalue_ref, explicit)] +#[conversions(copy, move)] +#[conversion_function(conversion_function_2, bool, const_lvalue_ref, explicit)] #[byte_size(4)] pub struct Guard { #[offset(0)] pub digit: i32, } +impl Guard { + pub fn conversion_function_2(this: LvalueRef>, __return: Ptr) { + let this = this.as_pointer(); + __return.write((this.with(|__s| __s.digit) != 0)); + return; + } +} impl Destructible for Guard { fn destroy(this: Ptr) { printf!(b"%d ", this.with(|__s| __s.digit)); } } -impl ConversionFunction>> for Guard { - fn conversion_function(this: LvalueRef>, to: Ptr) { - let this = this.as_pointer(); - to.write((this.with(|__s| __s.digit) != 0)); - return; - } -} pub fn step_0(i: Ptr) { printf!(b"9 "); i.with_mut(|__v| { @@ -171,8 +171,8 @@ fn main_0() -> i32 { Destructible::destroy(__p.as_pointer()) }); if !({ - let __v: Value = Rc::new(RefCell::new(false)); - Guard::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Guard::conversion_function_2( >>::bind(condition.as_pointer()), Ptr::clone(&__v.as_pointer()), ); diff --git a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs index 6cea75c067..bf1e858518 100644 --- a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs @@ -21,7 +21,7 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(32)] pub struct S { #[offset(0)] @@ -30,8 +30,8 @@ pub struct S { #[offset(24)] pub a: i32, } -impl ConstructibleFrom<()> for S { - fn constructor(this: Ptr, _: ()) { +impl S { + pub fn constructor_1(this: Ptr) { field!(this, v).write(Vec::new()); field!(this, a).write(0_i32); } @@ -41,7 +41,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(s, S); + object!(s, S::constructor_1()); ({ let __tmp_0: Value = Rc::new(RefCell::new(1)); MoveConstructible::push_moved( diff --git a/tests/unit/out/refcount/forward_basic.rs b/tests/unit/out/refcount/forward_basic.rs index 4807133e7c..1cdf6f6e5e 100644 --- a/tests/unit/out/refcount/forward_basic.rs +++ b/tests/unit/out/refcount/forward_basic.rs @@ -12,8 +12,8 @@ pub const Overload_kRvalueOverload: Overload = 2; #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] #[byte_size(12)] pub struct Tracked { #[offset(0)] @@ -23,26 +23,19 @@ pub struct Tracked { #[offset(8)] pub moves: i32, } -impl ConstructibleFrom<(i32,)> for Tracked { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl Tracked { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for Tracked { - fn constructor(this: Ptr, (o,): (LvalueRef>,)) { + pub fn constructor_2(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 CopyConstructible for Tracked {} -impl ConvertibleTo for LvalueRef> {} -impl ConstructibleFrom<(RvalueRef,)> for Tracked { - fn constructor(this: Ptr, (o,): (RvalueRef,)) { + pub fn constructor_3(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)); @@ -50,48 +43,39 @@ impl ConstructibleFrom<(RvalueRef,)> for Tracked { field!(o, v).write(0); } } -impl MoveConstructible for Tracked {} -impl ConvertibleTo for RvalueRef {} pub fn chosen_overload_0(_a0: Ptr) -> Overload { return Overload_kLvalueOverload; } pub fn chosen_overload_1(_a0: Ptr) -> Overload { return Overload_kRvalueOverload; } -impl ConstructibleFrom<(LvalueRef,)> for Holder { - fn constructor(this: Ptr, (x,): (LvalueRef,)) { +impl Holder { + pub fn constructor_1_1(this: Ptr, x: LvalueRef) { let x = x.as_pointer(); - >,)>>::constructor( - field_ptr!(this, t), - (LvalueRef::bind((x).clone()),), - ); + Tracked::constructor_2(field_ptr!(this, t), LvalueRef::bind((x).clone())); } } -impl ConvertibleTo for LvalueRef {} -impl ConstructibleFrom<(RvalueRef,)> for Holder { - fn constructor(this: Ptr, (x,): (RvalueRef,)) { +impl Holder { + pub fn constructor_1_2(this: Ptr, x: RvalueRef) { let x = x.as_pointer(); - ,)>>::constructor( - field_ptr!(this, t), - (RvalueRef::bind((x).clone()),), - ); + Tracked::constructor_3(field_ptr!(this, t), RvalueRef::bind((x).clone())); } } -impl ConvertibleTo for RvalueRef {} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, )] #[memberwise(copy_constructor, move_constructor)] #[derive(Conversions)] #[conversions(copy, move)] -#[constructor(lvalue_ref(Tracked))] -#[constructor(rvalue_ref(Tracked))] +#[constructor(constructor_1_1, lvalue_ref(Tracked))] +#[constructor(constructor_1_2, rvalue_ref(Tracked))] #[byte_size(12)] pub struct Holder { #[offset(0)] #[byte_size(12)] pub t: Tracked, } +impl Holder {} pub fn forward_once_2(x: Ptr) -> Overload { return ({ chosen_overload_0((x).clone()) }); } @@ -105,17 +89,11 @@ pub fn forward_twice_5(x: Ptr) -> Overload { return ({ forward_once_3((x).clone()) }); } pub fn forward_into_ctor_6(__return: Ptr, x: Ptr) { - ,)>>::constructor( - __return.clone(), - (LvalueRef::bind((x).clone()),), - ); + Holder::constructor_1_1(__return.clone(), LvalueRef::bind((x).clone())); return; } pub fn forward_into_ctor_7(__return: Ptr, x: Ptr) { - ,)>>::constructor( - __return.clone(), - (RvalueRef::bind((x).clone()),), - ); + Holder::constructor_1_2(__return.clone(), RvalueRef::bind((x).clone())); return; } pub fn main() { @@ -123,20 +101,20 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(lvalue, Tracked, (i32,), (7,)); + object!(lvalue, Tracked::constructor_1(7)); assert!( ((({ forward_once_2(lvalue.as_pointer(),) }) as i32) == (Overload_kLvalueOverload as i32)) ); assert!(({ (*lvalue.borrow()).v } == 7)); assert!( ((({ - let _x: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(_x.as_pointer(), (8,)); + let _x: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_x.as_pointer(), 8); forward_once_3(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object!(relayed, Tracked, (i32,), (9,)); + object!(relayed, Tracked::constructor_1(9)); assert!( ((({ forward_twice_4(relayed.as_pointer(),) }) as i32) == (Overload_kLvalueOverload as i32)) @@ -144,13 +122,13 @@ fn main_0() -> i32 { assert!(({ (*relayed.borrow()).v } == 9)); assert!( ((({ - let _x: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(_x.as_pointer(), (10,)); + let _x: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_x.as_pointer(), 10); forward_twice_5(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object!(kept, Tracked, (i32,), (11,)); + object!(kept, Tracked::constructor_1(11)); object!(from_lvalue, Holder, |from_lvalue| ({ forward_into_ctor_6(Ptr::clone(&from_lvalue.clone()), kept.as_pointer()) })); @@ -159,8 +137,8 @@ fn main_0() -> i32 { assert!(({ (*from_lvalue.borrow()).t.moves } == 0)); assert!(({ (*kept.borrow()).v } == 11)); object!(from_rvalue, Holder, |from_rvalue| ({ - let _x: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(_x.as_pointer(), (12,)); + let _x: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_x.as_pointer(), 12); forward_into_ctor_7(Ptr::clone(&from_rvalue.clone()), _x.as_pointer()) })); assert!(({ (*from_rvalue.borrow()).t.v } == 12)); diff --git a/tests/unit/out/refcount/forward_decltype.rs b/tests/unit/out/refcount/forward_decltype.rs index 68d949d180..55a3957039 100644 --- a/tests/unit/out/refcount/forward_decltype.rs +++ b/tests/unit/out/refcount/forward_decltype.rs @@ -12,8 +12,8 @@ pub const Overload_kRvalueOverload: Overload = 2; #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] #[byte_size(12)] pub struct Tracked { #[offset(0)] @@ -23,26 +23,19 @@ pub struct Tracked { #[offset(8)] pub moves: i32, } -impl ConstructibleFrom<(i32,)> for Tracked { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl Tracked { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for Tracked { - fn constructor(this: Ptr, (o,): (LvalueRef>,)) { + pub fn constructor_2(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 CopyConstructible for Tracked {} -impl ConvertibleTo for LvalueRef> {} -impl ConstructibleFrom<(RvalueRef,)> for Tracked { - fn constructor(this: Ptr, (o,): (RvalueRef,)) { + pub fn constructor_3(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)); @@ -50,8 +43,6 @@ impl ConstructibleFrom<(RvalueRef,)> for Tracked { field!(o, v).write(0); } } -impl MoveConstructible for Tracked {} -impl ConvertibleTo for RvalueRef {} pub fn chosen_overload_0(_a0: Ptr) -> Overload { return Overload_kLvalueOverload; } @@ -80,7 +71,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, Tracked, (i32,), (3,)); + object!(a, Tracked::constructor_1(3)); assert!( ((({ forward_by_decltype_2(a.as_pointer(),) }) as i32) == (Overload_kLvalueOverload as i32)) @@ -88,13 +79,13 @@ fn main_0() -> i32 { assert!(({ (*a.borrow()).v } == 3)); assert!( ((({ - let _x: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(_x.as_pointer(), (4,)); + let _x: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_x.as_pointer(), 4); forward_by_decltype_3(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object!(b, Tracked, (i32,), (5,)); + object!(b, Tracked::constructor_1(5)); assert!( ((({ forward_abbreviated_4(b.as_pointer(),) }) as i32) == (Overload_kLvalueOverload as i32)) @@ -102,17 +93,17 @@ fn main_0() -> i32 { assert!(({ (*b.borrow()).v } == 5)); assert!( ((({ - let _x: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(_x.as_pointer(), (6,)); + let _x: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_x.as_pointer(), 6); forward_abbreviated_5(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object!(c, Tracked, (i32,), (7,)); + object!(c, Tracked::constructor_1(7)); assert!( (({ - let _args_1: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(_args_1.as_pointer(), (8,)); + let _args_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_args_1.as_pointer(), 8); forward_abbreviated_pack_6(c.as_pointer(), _args_1.as_pointer()) }) == ((Overload_kLvalueOverload as i32) + (Overload_kRvalueOverload as i32))) ); diff --git a/tests/unit/out/refcount/forward_explicit.rs b/tests/unit/out/refcount/forward_explicit.rs index ef520e5996..0d1516dc77 100644 --- a/tests/unit/out/refcount/forward_explicit.rs +++ b/tests/unit/out/refcount/forward_explicit.rs @@ -14,8 +14,8 @@ pub const Overload_kIntRvalueOverload: Overload = 4; #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] #[byte_size(12)] pub struct Tracked { #[offset(0)] @@ -25,26 +25,19 @@ pub struct Tracked { #[offset(8)] pub moves: i32, } -impl ConstructibleFrom<(i32,)> for Tracked { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl Tracked { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for Tracked { - fn constructor(this: Ptr, (o,): (LvalueRef>,)) { + pub fn constructor_2(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 CopyConstructible for Tracked {} -impl ConvertibleTo for LvalueRef> {} -impl ConstructibleFrom<(RvalueRef,)> for Tracked { - fn constructor(this: Ptr, (o,): (RvalueRef,)) { + pub fn constructor_3(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)); @@ -52,8 +45,6 @@ impl ConstructibleFrom<(RvalueRef,)> for Tracked { field!(o, v).write(0); } } -impl MoveConstructible for Tracked {} -impl ConvertibleTo for RvalueRef {} pub fn chosen_overload_0(_a0: Ptr) -> Overload { return Overload_kLvalueOverload; } @@ -67,7 +58,7 @@ pub fn chosen_overload_3(_a0: Ptr) -> Overload { return Overload_kIntRvalueOverload; } pub fn copy_or_move_into_param_4(__return: Ptr, t: Ptr) { - ConvertibleTo::convert(>::bind((t).clone()), __return.clone()); + Tracked::constructor_3(__return.clone(), RvalueRef::bind((t).clone())); return; } pub fn main() { @@ -75,7 +66,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, Tracked, (i32,), (5,)); + object!(a, Tracked::constructor_1(5)); assert!( ((({ chosen_overload_0(a.as_pointer(),) }) as i32) == (Overload_kLvalueOverload as i32)) ); @@ -84,26 +75,20 @@ fn main_0() -> i32 { ((({ chosen_overload_1(a.as_pointer(),) }) as i32) == (Overload_kRvalueOverload as i32)) ); assert!(({ (*a.borrow()).v } == 5)); - object!(b, Tracked, (i32,), (6,)); + object!(b, Tracked::constructor_1(6)); object!(moved, Tracked, |moved| ({ - let _t: Value = Rc::new(RefCell::new(::zero_init())); - ,)>>::constructor( - _t.as_pointer(), - (RvalueRef::bind(b.as_pointer()),), - ); + let _t: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_3(_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)); assert!(({ (*moved.borrow()).copies } == 0)); assert!(({ (*moved.borrow()).moves } == 2)); assert!(({ (*b.borrow()).v } == 0)); - object!(c, Tracked, (i32,), (7,)); + object!(c, Tracked::constructor_1(7)); object!(copied, Tracked, |copied| ({ - let _t: Value = Rc::new(RefCell::new(::zero_init())); - >,)>>::constructor( - _t.as_pointer(), - (LvalueRef::bind(c.as_pointer()),), - ); + let _t: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(_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 e740ea901f..7d2eba53d4 100644 --- a/tests/unit/out/refcount/forward_pack.rs +++ b/tests/unit/out/refcount/forward_pack.rs @@ -14,8 +14,8 @@ pub const Overload_kIntRvalueOverload: Overload = 4; #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] #[byte_size(12)] pub struct Tracked { #[offset(0)] @@ -25,26 +25,19 @@ pub struct Tracked { #[offset(8)] pub moves: i32, } -impl ConstructibleFrom<(i32,)> for Tracked { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl Tracked { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for Tracked { - fn constructor(this: Ptr, (o,): (LvalueRef>,)) { + pub fn constructor_2(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 CopyConstructible for Tracked {} -impl ConvertibleTo for LvalueRef> {} -impl ConstructibleFrom<(RvalueRef,)> for Tracked { - fn constructor(this: Ptr, (o,): (RvalueRef,)) { + pub fn constructor_3(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)); @@ -52,8 +45,6 @@ impl ConstructibleFrom<(RvalueRef,)> for Tracked { field!(o, v).write(0); } } -impl MoveConstructible for Tracked {} -impl ConvertibleTo for RvalueRef {} pub fn chosen_overload_0(_a0: Ptr) -> Overload { return Overload_kLvalueOverload; } @@ -102,18 +93,12 @@ pub fn forward_pack_7( }; return digits; } -impl ConstructibleFrom<(LvalueRef, RvalueRef)> for Pair { - fn constructor(this: Ptr, (x, y): (LvalueRef, RvalueRef)) { +impl Pair { + pub fn constructor_1_1(this: Ptr, x: LvalueRef, y: RvalueRef) { let x = x.as_pointer(); let y = y.as_pointer(); - >,)>>::constructor( - field_ptr!(this, a), - (LvalueRef::bind((x).clone()),), - ); - ,)>>::constructor( - field_ptr!(this, b), - (RvalueRef::bind((y).clone()),), - ); + Tracked::constructor_2(field_ptr!(this, a), LvalueRef::bind((x).clone())); + Tracked::constructor_3(field_ptr!(this, b), RvalueRef::bind((y).clone())); } } #[derive( @@ -122,7 +107,7 @@ impl ConstructibleFrom<(LvalueRef, RvalueRef)> for Pair { #[memberwise(copy_constructor, move_constructor)] #[derive(Conversions)] #[conversions(copy, move)] -#[constructor(lvalue_ref(Tracked), rvalue_ref(Tracked))] +#[constructor(constructor_1_1, lvalue_ref(Tracked), rvalue_ref(Tracked))] #[byte_size(24)] pub struct Pair { #[offset(0)] @@ -132,13 +117,12 @@ pub struct Pair { #[byte_size(12)] pub b: Tracked, } +impl Pair {} pub fn forward_pack_into_ctor_8(__return: Ptr, args_0: Ptr, args_1: Ptr) { - , RvalueRef)>>::constructor( + Pair::constructor_1_1( __return.clone(), - ( - LvalueRef::bind((args_0).clone()), - RvalueRef::bind((args_1).clone()), - ), + LvalueRef::bind((args_0).clone()), + RvalueRef::bind((args_1).clone()), ); return; } @@ -148,21 +132,21 @@ pub fn main() { } fn main_0() -> i32 { assert!((({ forward_pack_4() }) == 0)); - object!(a, Tracked, (i32,), (1,)); + object!(a, Tracked::constructor_1(1)); assert!((({ forward_pack_5(a.as_pointer(),) }) == (Overload_kLvalueOverload as i32))); assert!(({ (*a.borrow()).v } == 1)); assert!( (({ - let _args: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(_args.as_pointer(), (2,)); + let _args: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_args.as_pointer(), 2); forward_pack_6(_args.as_pointer()) }) == (Overload_kRvalueOverload as i32)) ); let i: Value = Rc::new(RefCell::new(3)); assert!( (({ - let _args_1: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(_args_1.as_pointer(), (4,)); + let _args_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_args_1.as_pointer(), 4); let _args_3: Value = Rc::new(RefCell::new(5)); forward_pack_7( a.as_pointer(), @@ -174,10 +158,10 @@ fn main_0() -> i32 { ); assert!(({ (*a.borrow()).v } == 1)); assert!(({ ((*i.borrow()) == 3) })); - object!(lhs, Tracked, (i32,), (6,)); + object!(lhs, Tracked::constructor_1(6)); object!(p, Pair, |p| ({ - let _args_1: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(_args_1.as_pointer(), (7,)); + let _args_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_args_1.as_pointer(), 7); forward_pack_into_ctor_8( Ptr::clone(&p.clone()), lhs.as_pointer(), diff --git a/tests/unit/out/refcount/global_init_side_effect.rs b/tests/unit/out/refcount/global_init_side_effect.rs index c1ec404b24..a77f9f6268 100644 --- a/tests/unit/out/refcount/global_init_side_effect.rs +++ b/tests/unit/out/refcount/global_init_side_effect.rs @@ -23,26 +23,25 @@ thread_local!( Conversions, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] #[byte_size(1)] pub struct S {} -impl ConstructibleFrom<(i32,)> for S { - fn constructor(this: Ptr, (mut x,): (i32,)) { +impl S { + pub fn constructor_1(this: Ptr, mut x: i32) { total_0.with(|rc| *rc.borrow_mut() += x); } } -impl ConvertibleTo for i32 {} thread_local!( pub static a_1: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (1,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + S::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); thread_local!( pub static b_2: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (10,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + S::constructor_1(__v.as_pointer(), 10); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); diff --git a/tests/unit/out/refcount/global_non_const_init.rs b/tests/unit/out/refcount/global_non_const_init.rs index f0114e8102..8762b49a38 100644 --- a/tests/unit/out/refcount/global_non_const_init.rs +++ b/tests/unit/out/refcount/global_non_const_init.rs @@ -43,20 +43,18 @@ thread_local!( TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] -#[constructor(explicit, value(i32))] +#[conversions(copy, move, default = constructor_1)] +#[constructor(constructor_2, explicit, value(i32))] #[byte_size(4)] pub struct Ctor { #[offset(0)] pub v: i32, } -impl ConstructibleFrom<()> for Ctor { - fn constructor(this: Ptr, _: ()) { +impl Ctor { + pub fn constructor_1(this: Ptr) { field!(this, v).write(({ next_0() })); } -} -impl ConstructibleFrom<(i32,)> for Ctor { - fn constructor(this: Ptr, (mut x,): (i32,)) { + pub fn constructor_2(this: Ptr, mut x: i32) { field!(this, v).write(x); } } @@ -64,8 +62,8 @@ impl Default for Ctor { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Ctor::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -73,15 +71,15 @@ impl Default for Ctor { } thread_local!( pub static default_ctor_7: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Ctor::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); thread_local!( pub static arg_ctor_8: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (7,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Ctor::constructor_2(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -94,8 +92,8 @@ thread_local!( ); thread_local!( pub static inline_member_11: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (5,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Ctor::constructor_2(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -126,8 +124,8 @@ thread_local!( ); thread_local!( static local_ctor_14: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (3,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Ctor::constructor_2(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -142,28 +140,26 @@ thread_local!( TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct Singleton { #[offset(0)] pub hits: i32, } impl Singleton { + pub fn constructor_1(this: Ptr) { + field!(this, hits).write(0); + } pub fn instance() -> Ptr { return s_15.with(|v| v.as_pointer()); } } -impl ConstructibleFrom<()> for Singleton { - fn constructor(this: Ptr, _: ()) { - field!(this, hits).write(0); - } -} impl Default for Singleton { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Singleton::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -171,8 +167,8 @@ impl Default for Singleton { } thread_local!( static s_15: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Singleton::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); diff --git a/tests/unit/out/refcount/huffman.rs b/tests/unit/out/refcount/huffman.rs index b4c610aeb4..521f4bb644 100644 --- a/tests/unit/out/refcount/huffman.rs +++ b/tests/unit/out/refcount/huffman.rs @@ -63,7 +63,7 @@ pub fn Swap_0(a: Ptr, b: Ptr) { )] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] #[byte_size(32)] pub struct MinHeap { #[offset(0)] @@ -238,9 +238,7 @@ impl MinHeap { } } } -} -impl ConstructibleFrom<()> for MinHeap { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, size).write(0_i32); field!(this, capacity).write(0_i32); field!(this, arr).write(None); diff --git a/tests/unit/out/refcount/implicit_autoref.rs b/tests/unit/out/refcount/implicit_autoref.rs index 4cb3e7523f..17d3b07ea6 100644 --- a/tests/unit/out/refcount/implicit_autoref.rs +++ b/tests/unit/out/refcount/implicit_autoref.rs @@ -21,15 +21,15 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(24)] pub struct Holder { #[offset(0)] #[byte_size(24)] pub v: Vec, } -impl ConstructibleFrom<()> for Holder { - fn constructor(this: Ptr, _: ()) { +impl Holder { + pub fn constructor_1(this: Ptr) { field!(this, v).write(Vec::new()); } } @@ -53,7 +53,7 @@ fn main_0() -> i32 { let mut p: Ptr> = (v.as_pointer()); let mut a: i32 = (index!(p, 0_usize).read()); index!(p, 1_usize).write(30); - object!(h, Holder); + object!(h, Holder::constructor_1()); ({ let __tmp_2: Value = Rc::new(RefCell::new(40)); MoveConstructible::push_moved( diff --git a/tests/unit/out/refcount/in_class_field_initializer.rs b/tests/unit/out/refcount/in_class_field_initializer.rs index 20596db2c1..4a7ccc68cd 100644 --- a/tests/unit/out/refcount/in_class_field_initializer.rs +++ b/tests/unit/out/refcount/in_class_field_initializer.rs @@ -17,7 +17,7 @@ use std::rc::{Rc, Weak}; TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(8)] pub struct Inner { #[offset(0)] @@ -25,8 +25,8 @@ pub struct Inner { #[offset(4)] pub y: i32, } -impl ConstructibleFrom<()> for Inner { - fn constructor(this: Ptr, _: ()) { +impl Inner { + pub fn constructor_1(this: Ptr) { field!(this, x).write(3); field!(this, y).write(4); } @@ -47,7 +47,7 @@ impl Default for Inner { TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(24)] pub struct S { #[offset(0)] @@ -61,12 +61,12 @@ pub struct S { #[byte_size(8)] pub d: Inner, } -impl ConstructibleFrom<()> for S { - fn constructor(this: Ptr, _: ()) { +impl S { + pub fn constructor_1(this: Ptr) { field!(this, a).write(1); field!(this, b).write(2_i8); field!(this, c).write(::default()); - >::constructor(field_ptr!(this, d), ()); + Inner::constructor_1(field_ptr!(this, d)); } } impl Default for S { @@ -94,7 +94,7 @@ impl Default for S { Conversions, )] #[conversions(copy, move)] -#[constructor(value(i32), value(i32))] +#[constructor(constructor_1, value(i32), value(i32))] #[byte_size(8)] pub struct Boxed_int_ { #[offset(0)] @@ -102,8 +102,8 @@ pub struct Boxed_int_ { #[offset(4)] pub tag: i32, } -impl ConstructibleFrom<(i32, i32)> for Boxed_int_ { - fn constructor(this: Ptr, (mut x, mut t): (i32, i32)) { +impl Boxed_int_ { + pub fn constructor_1(this: Ptr, mut x: i32, mut t: i32) { field!(this, v).write(x); field!(this, tag).write(t); } @@ -118,14 +118,14 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(s, S); + object!(s, S::constructor_1()); assert!(({ (*s.borrow()).a } == 1)); assert!((({ (*s.borrow()).b } as i32) == 2)); assert!(({ (*s.borrow()).c.x } == 3)); assert!(({ (*s.borrow()).c.y } == 4)); assert!(({ (*s.borrow()).d.x } == 3)); assert!(({ (*s.borrow()).d.y } == 4)); - object!(boxed, Boxed_int_, (i32, i32,), (5, 9,)); + object!(boxed, Boxed_int_::constructor_1(5, 9)); assert!(({ (*boxed.borrow()).v } == 5)); assert!(({ (*boxed.borrow()).tag } == 9)); return 0; diff --git a/tests/unit/out/refcount/init_list.rs b/tests/unit/out/refcount/init_list.rs index 77d1e75fed..99a50c0643 100644 --- a/tests/unit/out/refcount/init_list.rs +++ b/tests/unit/out/refcount/init_list.rs @@ -41,7 +41,7 @@ pub struct Pair { TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(8)] pub struct Holder { #[offset(0)] @@ -53,9 +53,7 @@ impl Holder { field!(this, p).write({ (*o.upgrade().deref()) }); return (this).clone(); } -} -impl ConstructibleFrom<()> for Holder { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, p).write(Pair { a: 0, b: 0 }); } } @@ -82,14 +80,14 @@ pub fn sum_1(p: Ptr) -> i32 { TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct Seven { #[offset(0)] pub v: i32, } -impl ConstructibleFrom<()> for Seven { - fn constructor(this: Ptr, _: ()) { +impl Seven { + pub fn constructor_1(this: Ptr) { field!(this, v).write(7); } } @@ -111,7 +109,7 @@ fn main_0() -> i32 { let mut vec_: Vec = Vec::from([1, 2, 3]); ({ f_0(Vec::from([1, 2, 3, 4])) }); let p: Value = Rc::new(RefCell::new(Pair { a: 1, b: 2 })); - object!(h, Holder); + object!(h, Holder::constructor_1()); Holder::operator_assign_1(h.as_pointer(), p.as_pointer()); assert!(({ (*h.borrow()).p.a } == 1) && ({ (*h.borrow()).p.b } == 2)); assert!((({ sum_1(p.as_pointer(),) }) == 3)); diff --git a/tests/unit/out/refcount/inline_container_fields.rs b/tests/unit/out/refcount/inline_container_fields.rs index eac1c25ccf..7646c7c521 100644 --- a/tests/unit/out/refcount/inline_container_fields.rs +++ b/tests/unit/out/refcount/inline_container_fields.rs @@ -20,7 +20,7 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(48)] pub struct Elem { #[offset(0)] @@ -33,8 +33,8 @@ pub struct Elem { #[byte_size(24)] pub coeffs: Vec, } -impl ConstructibleFrom<()> for Elem { - fn constructor(this: Ptr, _: ()) { +impl Elem { + pub fn constructor_1(this: Ptr) { field!(this, id).write(0_i32); field!(this, hist).write((0..4).map(|_| 0_i32).collect::>()); field!(this, coeffs).write(Vec::new()); @@ -65,7 +65,7 @@ impl Default for Elem { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(88)] pub struct State { #[offset(0)] @@ -85,8 +85,8 @@ pub struct State { #[byte_size(24)] pub rows: Vec>, } -impl ConstructibleFrom<()> for State { - fn constructor(this: Ptr, _: ()) { +impl State { + pub fn constructor_1(this: Ptr) { field!(this, count).write(0_i32); field!(this, grid).write( (0..2) @@ -187,36 +187,28 @@ thread_local!( pub static move_assigns_5: Value = Rc::new(RefCell::new(0)); ); #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Conversions)] -#[conversions(copy, move)] +#[conversions(copy = constructor_2, move = constructor_3, default = constructor_1)] #[byte_size(4)] pub struct Counted { #[offset(0)] pub v: i32, } -impl ConstructibleFrom<()> for Counted { - fn constructor(this: Ptr, _: ()) { +impl Counted { + pub fn constructor_1(this: Ptr) { field!(this, v).write(0); } -} -impl ConstructibleFrom<(LvalueRef>,)> for Counted { - fn constructor(this: Ptr, (o,): (LvalueRef>,)) { + pub fn constructor_2(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 CopyConstructible for Counted {} -impl ConvertibleTo for LvalueRef> {} -impl ConstructibleFrom<(RvalueRef,)> for Counted { - fn constructor(this: Ptr, (o,): (RvalueRef,)) { + pub fn constructor_3(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 MoveConstructible for Counted {} -impl ConvertibleTo for RvalueRef {} impl CopyAssignable for Counted { fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { let o = o.as_pointer(); @@ -357,7 +349,12 @@ 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, RvalueRef::bind(t.as_pointer())); + object!(moved, State, |moved| { + ::move_constructor( + moved.clone(), + RvalueRef::bind(t.as_pointer()), + ) + }); assert!( ({ ((*moved.borrow()).grid[(0) as usize][(0) as usize] == 100) @@ -412,7 +409,7 @@ fn main_0() -> i32 { )); let __p: Ptr = __v.decay(); for __i in 0..3 { - ConstructibleFrom::constructor( + Constructor::constructor( __p.offset(__i), (RvalueRef::::bind(ca.decay().offset(__i)),), ); @@ -473,7 +470,7 @@ fn main_0() -> i32 { )); let __p: Ptr> = __v.decay(); for __i in 0..2 { - ConstructibleFrom::constructor( + Constructor::constructor( __p.offset(__i), (RvalueRef::>::bind(va.decay().offset(__i)),), ); diff --git a/tests/unit/out/refcount/kruskal.rs b/tests/unit/out/refcount/kruskal.rs index 005612ca7e..5c4aec095c 100644 --- a/tests/unit/out/refcount/kruskal.rs +++ b/tests/unit/out/refcount/kruskal.rs @@ -117,7 +117,7 @@ pub fn quicksort_1(arr: Ptr>>>, mut start: i32, mut end )] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] #[byte_size(24)] pub struct DisjointSet { #[offset(0)] @@ -231,9 +231,7 @@ impl DisjointSet { ); } } -} -impl ConstructibleFrom<()> for DisjointSet { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, rank).write(None); field!(this, parent).write(None); field!(this, n).write(0_i32); @@ -244,7 +242,7 @@ impl ConstructibleFrom<()> for DisjointSet { )] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] #[byte_size(16)] pub struct Graph { #[offset(0)] @@ -255,8 +253,8 @@ pub struct Graph { #[offset(12)] pub E: i32, } -impl ConstructibleFrom<()> for Graph { - fn constructor(this: Ptr, _: ()) { +impl Graph { + pub fn constructor_1(this: Ptr) { field!(this, edges).write(None); field!(this, V).write(0_i32); field!(this, E).write(0_i32); diff --git a/tests/unit/out/refcount/lambda_as_field.rs b/tests/unit/out/refcount/lambda_as_field.rs index 59044b56b7..7d156c1aa7 100644 --- a/tests/unit/out/refcount/lambda_as_field.rs +++ b/tests/unit/out/refcount/lambda_as_field.rs @@ -20,7 +20,7 @@ use std::rc::{Rc, Weak}; )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] +#[conversions(copy, move)] #[byte_size(1)] pub struct Guard__lambda_at_lambda_as_field_cpp_34_13__ { #[offset(0)] @@ -43,7 +43,7 @@ impl Destructible for Guard__lambda_at_lambda_as_field_cpp_34_13__ { Copyable, Conversions, )] -#[conversions(copy)] +#[conversions(copy, move)] #[byte_size(8)] pub struct Guard__lambda_at_lambda_as_field_cpp_45_13__ { #[offset(0)] @@ -123,7 +123,7 @@ impl Holder__lambda_at_lambda_as_field_cpp_51_12__ { } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] -#[conversions(move)] +#[conversions(move = constructor_2)] #[byte_size(8)] pub struct Moving__lambda_at_lambda_as_field_cpp_64_12__ { #[offset(0)] @@ -132,29 +132,21 @@ pub struct Moving__lambda_at_lambda_as_field_cpp_64_12__ { #[offset(4)] pub moves: i32, } -impl ConstructibleFrom<(FnPtr i32>,)> for Moving__lambda_at_lambda_as_field_cpp_64_12__ { - fn constructor(this: Ptr, (f,): (FnPtr i32>,)) { +impl Moving__lambda_at_lambda_as_field_cpp_64_12__ { + pub fn constructor_1(this: Ptr, f: FnPtr i32>) { let f: Value i32>> = Rc::new(RefCell::new(f)); field!(this, f).write((*f.borrow()).copy_from()); field!(this, moves).write(0); } -} -impl ConvertibleTo for FnPtr i32> {} -impl ConstructibleFrom<(RvalueRef,)> for Moving__lambda_at_lambda_as_field_cpp_64_12__ { - fn constructor( + pub fn constructor_2( this: Ptr, - (o,): (RvalueRef,), + 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)); } } -impl MoveConstructible for Moving__lambda_at_lambda_as_field_cpp_64_12__ {} -impl ConvertibleTo - for RvalueRef -{ -} impl Default for Moving__lambda_at_lambda_as_field_cpp_64_12__ { fn default() -> Self { { ::zero_init() } @@ -273,18 +265,19 @@ fn main_0() -> i32 { assert!(({ (({ (*ww.borrow()).call(2,) }) == 202) })); object!( m, - Moving__lambda_at_lambda_as_field_cpp_64_12__, - (FnPtr i32>,), - (FnPtr:: i32>::new(|mut x: i32| -> i32 { - { - return (x * 2); + Moving__lambda_at_lambda_as_field_cpp_64_12__::constructor_1(FnPtr:: i32>::new( + |mut x: i32| -> i32 { + { + return (x * 2); + } } - }),) + )) ); object!( m2, - Moving__lambda_at_lambda_as_field_cpp_64_12__, - RvalueRef::bind(m.as_pointer()) + Moving__lambda_at_lambda_as_field_cpp_64_12__::constructor_2(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 266bb5ab00..ed0085aff6 100644 --- a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs @@ -7,7 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] -#[conversions(copy, move)] +#[conversions(copy = constructor_2, move = constructor_3, default = constructor_1)] #[byte_size(8)] pub struct Counted { #[offset(0)] @@ -15,36 +15,28 @@ pub struct Counted { #[offset(4)] pub moves: i32, } -impl ConstructibleFrom<()> for Counted { - fn constructor(this: Ptr, _: ()) { +impl Counted { + pub fn constructor_1(this: Ptr) { field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl ConstructibleFrom<(LvalueRef>,)> for Counted { - fn constructor(this: Ptr, (o,): (LvalueRef>,)) { + pub fn constructor_2(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 CopyConstructible for Counted {} -impl ConvertibleTo for LvalueRef> {} -impl ConstructibleFrom<(RvalueRef,)> for Counted { - fn constructor(this: Ptr, (o,): (RvalueRef,)) { + pub fn constructor_3(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)); } } -impl MoveConstructible for Counted {} -impl ConvertibleTo for RvalueRef {} impl Default for Counted { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -54,26 +46,18 @@ thread_local!( pub static drops_0: Value = Rc::new(RefCell::new(0)); ); #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Conversions)] -#[conversions(copy, move)] +#[conversions(copy = constructor_2, move = constructor_3, default = constructor_1)] #[byte_size(1)] pub struct Dropped {} -impl ConstructibleFrom<()> for Dropped { - fn constructor(this: Ptr, _: ()) {} -} -impl ConstructibleFrom<(LvalueRef>,)> for Dropped { - fn constructor(this: Ptr, (_a0,): (LvalueRef>,)) { +impl Dropped { + pub fn constructor_1(this: Ptr) {} + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); } -} -impl CopyConstructible for Dropped {} -impl ConvertibleTo for LvalueRef> {} -impl ConstructibleFrom<(RvalueRef,)> for Dropped { - fn constructor(this: Ptr, (_a0,): (RvalueRef,)) { + pub fn constructor_3(this: Ptr, _a0: RvalueRef) { let _a0 = _a0.as_pointer(); } } -impl MoveConstructible for Dropped {} -impl ConvertibleTo for RvalueRef {} impl Destructible for Dropped { fn destroy(this: Ptr) { (*drops_0.with(Value::clone).borrow_mut()).postfix_inc(); @@ -84,15 +68,12 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(c, Counted); + object!(c, Counted::constructor_1()); let f: Value i32>> = Rc::new(RefCell::new(lambda!( { let c: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >,)>>::constructor( - __v.as_pointer(), - (LvalueRef::bind(c.as_pointer()),), - ); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_2(__v.as_pointer(), LvalueRef::bind(c.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -107,19 +88,37 @@ fn main_0() -> i32 { let h: Value i32>> = Rc::new(RefCell::new((*f.borrow()).move_from())); assert!(({ (({ (*h.borrow()).call() }) == 11) })); let mut returned: i32 = { - let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); - { ( { lambda! ( { let c : Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); >,)>>::constructor(__v.as_pointer(), (LvalueRef::bind(c .as_pointer() ),)) ; -Rc::try_unwrap(__v).ok().unwrap().into_inner() } )) ; -} , | __return: Ptr< Counted > , | { ConvertibleTo::convert(>>::bind(c .as_pointer() ), __return.clone()) ; -return ; -; -} ) .call ( Ptr::clone(&__tmp_0.as_pointer()) , ) } ) ; __tmp_0.as_pointer() } .with(|__s| __s . copies ) + let __tmp_0: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + { + ({ + lambda!( + { + let c: Value = Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_2( + __v.as_pointer(), + LvalueRef::bind(c.as_pointer()), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + }, + |__return: Ptr| { + Counted::constructor_2(__return.clone(), LvalueRef::bind(c.as_pointer())); + return; + } + ) + .call(Ptr::clone(&__tmp_0.as_pointer())) + }); + __tmp_0.as_pointer() + } + .with(|__s| __s.copies) }; assert!((returned == 2)); let arr: Value> = Rc::new(RefCell::new(Box::new( std::array::from_fn::<_, 2, _>(|_| { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }), ))); @@ -127,10 +126,11 @@ return ; { 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())); - >,)>>::constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_2( __v.as_pointer(), - (LvalueRef::bind(arr.decay().offset(__i)),), + LvalueRef::bind(arr.decay().offset(__i)), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }), @@ -151,8 +151,9 @@ return ; let m: Value> = Rc::new(RefCell::new(lambda!( { let d: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Dropped::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -169,8 +170,9 @@ return ; let k: Value> = Rc::new(RefCell::new(lambda!( { let d: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Dropped::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -187,8 +189,9 @@ return ; let inner: Value> = Rc::new(RefCell::new(lambda!( { let d: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Dropped::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, diff --git a/tests/unit/out/refcount/lambda_decltype_type.rs b/tests/unit/out/refcount/lambda_decltype_type.rs index f1898dcd83..d08d283831 100644 --- a/tests/unit/out/refcount/lambda_decltype_type.rs +++ b/tests/unit/out/refcount/lambda_decltype_type.rs @@ -9,7 +9,7 @@ use std::rc::{Rc, Weak}; #[derive( Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(24)] pub struct Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { #[offset(0)] @@ -38,9 +38,7 @@ impl Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { array_elem!(this, items, i).write(v); field!(this, size).with_mut(|__v| __v.postfix_inc()); } -} -impl ConstructibleFrom<()> for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, items).write((0..4).map(|_| 0_i32).collect::>()); field!(this, size).write(0); field!(this, cmp).write(FnPtr:: bool>::new( @@ -70,7 +68,7 @@ impl Default for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { #[derive( Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(24)] pub struct Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { #[offset(0)] @@ -99,9 +97,7 @@ impl Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { array_elem!(this, items, i).write(v); field!(this, size).with_mut(|__v| __v.postfix_inc()); } -} -impl ConstructibleFrom<()> for Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, items).write((0..4).map(|_| 0_i32).collect::>()); field!(this, size).write(0); field!(this, cmp).write(FnPtr:: bool>::new( @@ -141,14 +137,20 @@ fn main_0() -> i32 { } }, ))); - object!(desc, Sorted__lambda_at_lambda_decltype_type_cpp_22_18__); + object!( + desc, + Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::constructor_1() + ); ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(desc.as_pointer(), 2) }); ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(desc.as_pointer(), 7) }); ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(desc.as_pointer(), 4) }); assert!(((array_elem!(desc.as_pointer(), items, 0).read()) == 7)); assert!(((array_elem!(desc.as_pointer(), items, 1).read()) == 4)); assert!(((array_elem!(desc.as_pointer(), items, 2).read()) == 2)); - object!(asc, Sorted__lambda_at_lambda_decltype_type_cpp_19_23__); + object!( + asc, + Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::constructor_1() + ); ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(asc.as_pointer(), 2) }); ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(asc.as_pointer(), 7) }); ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(asc.as_pointer(), 4) }); diff --git a/tests/unit/out/refcount/lambda_immediate_init.rs b/tests/unit/out/refcount/lambda_immediate_init.rs index fa80276744..1f5900ec5d 100644 --- a/tests/unit/out/refcount/lambda_immediate_init.rs +++ b/tests/unit/out/refcount/lambda_immediate_init.rs @@ -20,7 +20,7 @@ pub fn pick_0(mut x: i32) -> i32 { TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(8)] pub struct S { #[offset(0)] @@ -28,8 +28,8 @@ pub struct S { #[offset(4)] pub k: i32, } -impl ConstructibleFrom<()> for S { - fn constructor(this: Ptr, _: ()) { +impl S { + pub fn constructor_1(this: Ptr) { field!(this, j).write(10); field!(this, k).write( (({ @@ -102,7 +102,7 @@ fn main_0() -> i32 { }) == 237) ); assert!((({ pick_0(1,) }) == 1)); - object!(s, S); + object!(s, S::constructor_1()); assert!(({ (*s.borrow()).k } == 4)); assert!((g_1.with(|rc| *rc.borrow()) == 10)); let a: Value = Rc::new(RefCell::new(2)); diff --git a/tests/unit/out/refcount/lambda_move_only_capture.rs b/tests/unit/out/refcount/lambda_move_only_capture.rs index 5108c81b35..3e3c8dc82e 100644 --- a/tests/unit/out/refcount/lambda_move_only_capture.rs +++ b/tests/unit/out/refcount/lambda_move_only_capture.rs @@ -7,8 +7,8 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultConstructible, Conversions)] -#[conversions(move)] -#[constructor(value(i32))] +#[conversions(move = constructor_3)] +#[constructor(constructor_1, value(i32))] #[byte_size(8)] pub struct Owner { #[offset(0)] @@ -16,15 +16,20 @@ pub struct Owner { pub p: Ptr, } impl Owner { + pub fn constructor_1(this: Ptr, mut v: i32) { + field!(this, p).write(Ptr::alloc(v)); + } + pub fn constructor_3(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()); + } pub fn take(this: Ptr) -> FnPtr i32> { return lambda!( { let self_: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConvertibleTo::convert( - >::bind((this).clone()), - __v.as_pointer(), - ); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Owner::constructor_3(__v.as_pointer(), RvalueRef::bind((this).clone())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -34,21 +39,6 @@ impl Owner { ); } } -impl ConstructibleFrom<(i32,)> for Owner { - fn constructor(this: Ptr, (mut v,): (i32,)) { - field!(this, p).write(Ptr::alloc(v)); - } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(RvalueRef,)> for Owner { - fn 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()); - } -} -impl MoveConstructible for Owner {} -impl ConvertibleTo for RvalueRef {} impl Destructible for Owner { fn destroy(this: Ptr) { this.with(|__s| __s.p.clone()).delete(); @@ -59,12 +49,12 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(o, Owner, (i32,), (5,)); + object!(o, Owner::constructor_1(5)); let f: Value i32>> = Rc::new(RefCell::new(lambda!( { let h: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConvertibleTo::convert(>::bind(o.as_pointer()), __v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Owner::constructor_3(__v.as_pointer(), RvalueRef::bind(o.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -84,8 +74,8 @@ fn main_0() -> i32 { let consume: Value> = Rc::new(RefCell::new(lambda!( { let h: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (7,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Owner::constructor_1(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let total: Ptr = total.as_pointer(); @@ -104,7 +94,7 @@ fn main_0() -> i32 { ({ (*consume.borrow()).call() }); ({ (*consume.borrow()).call() }); assert!(({ ((*total.borrow()) == 7) })); - object!(o2, Owner, (i32,), (9,)); + object!(o2, Owner::constructor_1(9)); let t: Value i32>> = Rc::new(RefCell::new(({ Owner::take(o2.as_pointer()) }))); let _dtor_t = std::mem::DropGuard::new(t.clone(), |__p| Destructible::destroy(__p.as_pointer())); diff --git a/tests/unit/out/refcount/libc_struct_without_default.rs b/tests/unit/out/refcount/libc_struct_without_default.rs index eb6e2b08fd..c1e185a851 100644 --- a/tests/unit/out/refcount/libc_struct_without_default.rs +++ b/tests/unit/out/refcount/libc_struct_without_default.rs @@ -20,7 +20,7 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(32)] pub struct UserDefined { #[offset(0)] @@ -31,8 +31,8 @@ pub struct UserDefined { #[byte_size(24)] pub v: Vec, } -impl ConstructibleFrom<()> for UserDefined { - fn constructor(this: Ptr, _: ()) { +impl UserDefined { + pub fn constructor_1(this: Ptr) { field!(this, a).write(Box::<[i32]>::from(std::array::from_fn::<_, 1, _>(|_| { 0_i32 }))); @@ -101,7 +101,7 @@ fn main_0() -> i32 { let st: Value = Rc::new(RefCell::new(Default::default())); (*st.borrow_mut()).st_size = (1024 as ::libc::off_t); assert!(({ (*st.borrow()).st_size } == (1024 as ::libc::off_t))); - object!(ud, UserDefined); + object!(ud, UserDefined::constructor_1()); elem!(field_ref!(ud.as_pointer(), a).decay(), 0_usize).write(3); assert!(((elem!(field_ref!(ud.as_pointer(), a).decay(), 0_usize).read()) == 3)); assert!(({ ((*ud.borrow()).v.len() == 0_usize) })); diff --git a/tests/unit/out/refcount/map.rs b/tests/unit/out/refcount/map.rs index 7486d82291..8a21920d6f 100644 --- a/tests/unit/out/refcount/map.rs +++ b/tests/unit/out/refcount/map.rs @@ -26,8 +26,8 @@ pub fn inc_2(x: Ptr) { TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] -#[constructor(value(i32), value(i32))] +#[conversions(copy, move, default = constructor_1)] +#[constructor(constructor_2, value(i32), value(i32))] #[byte_size(8)] pub struct Point { #[offset(0)] @@ -35,14 +35,12 @@ pub struct Point { #[offset(4)] pub y: i32, } -impl ConstructibleFrom<()> for Point { - fn constructor(this: Ptr, _: ()) { +impl Point { + pub fn constructor_1(this: Ptr) { field!(this, x).write(0); field!(this, y).write(0); } -} -impl ConstructibleFrom<(i32, i32)> for Point { - fn constructor(this: Ptr, (mut x, mut y): (i32, i32)) { + pub fn constructor_2(this: Ptr, mut x: i32, mut y: i32) { field!(this, x).write(x); field!(this, y).write(y); } @@ -51,8 +49,8 @@ impl Default for Point { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Point::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -702,17 +700,17 @@ fn main_0() -> i32 { .as_pointer(),) { (__tmp_58,) => { - object!(__first, i32, |__this| Conversions::construct( + object!(__first, i32, |__this| ConstructibleFrom::construct( __this, - &[overload::Arg::rvalue( + (RvalueRef::::bind( (*__tmp_58.upgrade().deref()).0.as_pointer() - )] + ),) )); - object!(__second, i32, |__this| Conversions::construct( + object!(__second, i32, |__this| ConstructibleFrom::construct( __this, - &[overload::Arg::rvalue( + (RvalueRef::::bind( (*__tmp_58.upgrade().deref()).1.as_pointer() - )] + ),) )); ( Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), @@ -829,8 +827,8 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(copy_constructed(key1.as_pointer().clone()))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (3, 4)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Point::constructor_2(__v.as_pointer(), 3, 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -876,8 +874,8 @@ fn main_0() -> i32 { ( Rc::new(RefCell::new(({ (*key8.borrow()) }))), Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (5, 6)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Point::constructor_2(__v.as_pointer(), 5, 6); 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 f69a5bea93..962de3b81f 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -18,42 +18,31 @@ thread_local!( #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct Key { #[offset(0)] pub k: i32, } impl Key { - pub fn operator_lt(this: Ptr, o: Ptr) -> bool { - return ({ this.with(|__s| __s.k) } < { o.with(|__s| __s.k) }); - } -} -impl ConstructibleFrom<(i32,)> for Key { - fn constructor(this: Ptr, (mut k,): (i32,)) { + pub fn constructor_1(this: Ptr, mut k: i32) { field!(this, k).write(k); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for Key { - fn constructor(this: Ptr, (o,): (LvalueRef>,)) { + pub fn constructor_2(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 CopyConstructible for Key {} -impl ConvertibleTo for LvalueRef> {} -impl ConstructibleFrom<(RvalueRef,)> for Key { - fn constructor(this: Ptr, (o,): (RvalueRef,)) { + pub fn constructor_3(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(); } + pub fn operator_lt(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.k) } < { o.with(|__s| __s.k) }); + } } -impl MoveConstructible for Key {} -impl ConvertibleTo for RvalueRef {} impl CppLess for Key { fn less(this: Ptr, o: Ptr) -> bool { Key::operator_lt(this.clone(), o.clone()) @@ -61,7 +50,7 @@ impl CppLess for Key { } pub fn make_key_3(__return: Ptr, mut k: i32) { (*made_2.with(Value::clone).borrow_mut()).prefix_inc(); - >::constructor(__return.clone(), (k,)); + Key::constructor_1(__return.clone(), k); return; } pub fn main() { @@ -71,9 +60,9 @@ pub fn main() { fn main_0() -> i32 { let mut ok: bool = true; let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); - object!(a, Key, (i32,), (1,)); - object!(b, Key, (i32,), (2,)); - object!(c, Key, (i32,), (3,)); + object!(a, Key::constructor_1(1)); + object!(b, Key::constructor_1(2)); + object!(c, Key::constructor_1(3)); match (a.as_pointer(),) { (__tmp_0,) => ({ (*m.borrow_mut()).subscript(__tmp_0, || 0_i32) }), } @@ -118,7 +107,7 @@ fn main_0() -> i32 { }; ok = { ((ok as i32) & ((copies_0.with(|rc| *rc.borrow()) == 2) as i32)) != 0 }; { - let __tmp_4: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_4: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ ({ make_key_3(Ptr::clone(&__tmp_4.as_pointer()), 4) }); __tmp_4.as_pointer() @@ -137,7 +126,7 @@ fn main_0() -> i32 { .write(40) }; { - let __tmp_6: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_6: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ ({ make_key_3(Ptr::clone(&__tmp_6.as_pointer()), 4) }); __tmp_6.as_pointer() @@ -213,9 +202,9 @@ fn main_0() -> i32 { .0 .as_pointer()); { - let __tmp_12: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_12: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - >::constructor(__tmp_12.as_pointer(), (0,)); + Key::constructor_1(__tmp_12.as_pointer(), 0); __tmp_12.as_pointer() },) { diff --git a/tests/unit/out/refcount/map_key_identity.rs b/tests/unit/out/refcount/map_key_identity.rs index db0c67aece..2bb66adee1 100644 --- a/tests/unit/out/refcount/map_key_identity.rs +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -49,14 +49,14 @@ pub fn operator_lt_1(a: Ptr, b: Ptr) -> bool { TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct Mapped { #[offset(0)] pub value: i32, } -impl ConstructibleFrom<()> for Mapped { - fn constructor(this: Ptr, _: ()) { +impl Mapped { + pub fn constructor_1(this: Ptr) { field!(this, value).write(0); (*default_constructions_0.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -65,8 +65,8 @@ impl Default for Mapped { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Mapped::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index b369694124..b97c83fe26 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -19,50 +19,39 @@ thread_local!( pub static moves_3: Value = Rc::new(RefCell::new(0)); ); #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_3, move = constructor_4, default = constructor_1)] +#[constructor(constructor_2, value(i32))] #[byte_size(4)] pub struct Item { #[offset(0)] pub value: i32, } -impl ConstructibleFrom<()> for Item { - fn constructor(this: Ptr, _: ()) { +impl Item { + pub fn constructor_1(this: Ptr) { field!(this, value).write(0); } -} -impl ConstructibleFrom<(i32,)> for Item { - fn constructor(this: Ptr, (mut value,): (i32,)) { + pub fn constructor_2(this: Ptr, mut value: i32) { field!(this, value).write(value); (*made_1.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for Item { - fn constructor(this: Ptr, (other,): (LvalueRef>,)) { + pub fn constructor_3(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 CopyConstructible for Item {} -impl ConvertibleTo for LvalueRef> {} -impl ConstructibleFrom<(RvalueRef,)> for Item { - fn constructor(this: Ptr, (other,): (RvalueRef,)) { + pub fn constructor_4(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); } } -impl MoveConstructible for Item {} -impl ConvertibleTo for RvalueRef {} impl Default for Item { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -83,20 +72,18 @@ pub fn argument_4(item: Ptr) -> Ptr { TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] -#[constructor(lvalue_ref(i32), value(i32))] +#[conversions(copy, move, default = constructor_1)] +#[constructor(constructor_2, lvalue_ref(i32), value(i32))] #[byte_size(4)] pub struct RefItem { #[offset(0)] pub value: i32, } -impl ConstructibleFrom<()> for RefItem { - fn constructor(this: Ptr, _: ()) { +impl RefItem { + pub fn constructor_1(this: Ptr) { field!(this, value).write(0); } -} -impl ConstructibleFrom<(LvalueRef, i32)> for RefItem { - fn constructor(this: Ptr, (counter, mut amount): (LvalueRef, i32)) { + pub fn constructor_2(this: Ptr, counter: LvalueRef, mut amount: i32) { let counter = counter.as_pointer(); field!(this, value).write({ { @@ -111,8 +98,8 @@ impl Default for RefItem { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + RefItem::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -383,8 +370,8 @@ 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())); - >::constructor(__v.as_pointer(), (10,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2(__v.as_pointer(), 10); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -394,7 +381,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(__inserted)), ) }; - object!(source, Item, (i32,), (20,)); + object!(source, Item::constructor_2(20)); made_1.with(|rc| { *rc.borrow_mut() = { copies_2.with(|rc| { @@ -417,10 +404,11 @@ 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())); - >,)>>::constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_3( __v.as_pointer(), - (LvalueRef::bind((__tmp_7).clone()),), + LvalueRef::bind((__tmp_7).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -459,10 +447,11 @@ 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())); - ,)>>::constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_4( __v.as_pointer(), - (RvalueRef::bind((__tmp_8).clone()),), + RvalueRef::bind((__tmp_8).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -500,10 +489,11 @@ 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())); - >,)>>::constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_3( __v.as_pointer(), - (LvalueRef::bind((__tmp_9).clone()),), + LvalueRef::bind((__tmp_9).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -543,10 +533,11 @@ 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())); - ,)>>::constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_4( __v.as_pointer(), - (RvalueRef::bind((__tmp_10).clone()),), + RvalueRef::bind((__tmp_10).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -583,10 +574,12 @@ 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())); - , i32)>>::constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + RefItem::constructor_2( __v.as_pointer(), - (LvalueRef::bind(counter.as_pointer()), 5), + LvalueRef::bind(counter.as_pointer()), + 5, ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -608,10 +601,12 @@ 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())); - , i32)>>::constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + RefItem::constructor_2( __v.as_pointer(), - (LvalueRef::bind((__tmp_11).clone()), 2), + LvalueRef::bind((__tmp_11).clone()), + 2, ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -642,10 +637,12 @@ 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())); - , i32)>>::constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + RefItem::constructor_2( __v.as_pointer(), - (LvalueRef::bind((__tmp_12).clone()), 2), + LvalueRef::bind((__tmp_12).clone()), + 2, ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -691,9 +688,9 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_14: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_14: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - >::constructor(__tmp_14.as_pointer(), (30,)); + Item::constructor_2(__tmp_14.as_pointer(), 30); __tmp_14.as_pointer() },) { @@ -703,10 +700,11 @@ 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())); - ,)>>::constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_4( __v.as_pointer(), - (RvalueRef::bind((__tmp_13).clone()),), + RvalueRef::bind((__tmp_13).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -734,9 +732,9 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_16: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_16: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - >::constructor(__tmp_16.as_pointer(), (40,)); + Item::constructor_2(__tmp_16.as_pointer(), 40); __tmp_16.as_pointer() },) { @@ -746,10 +744,11 @@ 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())); - ,)>>::constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_4( __v.as_pointer(), - (RvalueRef::bind((__tmp_15).clone()),), + RvalueRef::bind((__tmp_15).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), diff --git a/tests/unit/out/refcount/map_try_emplace_lvalues.rs b/tests/unit/out/refcount/map_try_emplace_lvalues.rs index e1de13b1aa..0b1c51570b 100644 --- a/tests/unit/out/refcount/map_try_emplace_lvalues.rs +++ b/tests/unit/out/refcount/map_try_emplace_lvalues.rs @@ -23,20 +23,18 @@ thread_local!( TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] -#[constructor(lvalue_ref(i32), value(i32))] +#[conversions(copy, move, default = constructor_1)] +#[constructor(constructor_2, lvalue_ref(i32), value(i32))] #[byte_size(4)] pub struct Item { #[offset(0)] pub value: i32, } -impl ConstructibleFrom<()> for Item { - fn constructor(this: Ptr, _: ()) { +impl Item { + pub fn constructor_1(this: Ptr) { field!(this, value).write(0); } -} -impl ConstructibleFrom<(LvalueRef, i32)> for Item { - fn constructor(this: Ptr, (counter, mut amount): (LvalueRef, i32)) { + pub fn constructor_2(this: Ptr, counter: LvalueRef, mut amount: i32) { let counter = counter.as_pointer(); field!(this, value).write({ { @@ -51,8 +49,8 @@ impl Default for Item { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -74,7 +72,7 @@ thread_local!( #[derive( Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(12)] pub struct Temporary { #[offset(0)] @@ -84,8 +82,8 @@ pub struct Temporary { #[array_len(2)] pub data: Box<[i32]>, } -impl ConstructibleFrom<()> for Temporary { - fn constructor(this: Ptr, _: ()) { +impl Temporary { + pub fn constructor_1(this: Ptr) { field!(this, n).write(5); field!(this, data).write(Box::new([6, 7])); (*temporary_calls_4.with(Value::clone).borrow_mut()).prefix_inc(); @@ -95,8 +93,8 @@ impl Default for Temporary { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Temporary::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -113,36 +111,36 @@ impl Default for Temporary { Default, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(12)] pub struct Nested { #[offset(0)] #[byte_size(12)] pub inner: Temporary, } -impl ConstructibleFrom<()> for Nested { - fn constructor(this: Ptr, _: ()) { - >::constructor(field_ptr!(this, inner), ()); +impl Nested { + pub fn constructor_1(this: Ptr) { + Temporary::constructor_1(field_ptr!(this, inner)); } } pub fn make_temporary_5() -> Temporary { return { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Temporary::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } pub fn make_nested_6() -> Nested { return { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Nested::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] #[byte_size(8)] pub struct Owner { #[offset(0)] @@ -150,38 +148,37 @@ pub struct Owner { pub ptr: Option>, } impl Owner { - pub fn value(this: Ptr) -> Ptr { - return field_ptr!(this.with(|__s| __s.ptr.clone()).as_pointer(), n); - } -} -impl ConstructibleFrom<()> for Owner { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, ptr).write(Some(Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Temporary::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })))); } + pub fn value(this: Ptr) -> Ptr { + return field_ptr!(this.with(|__s| __s.ptr.clone()).as_pointer(), n); + } } impl Default for Owner { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Owner::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] +#[conversions(default = constructor_1)] #[byte_size(4)] pub struct Noncopy { #[offset(0)] pub n: i32, } -impl ConstructibleFrom<()> for Noncopy { - fn constructor(this: Ptr, _: ()) { +impl Noncopy { + pub fn constructor_1(this: Ptr) { field!(this, n).write(5); } } @@ -193,28 +190,23 @@ impl Default for Noncopy { #[derive( Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] -#[constructor(const_lvalue_ref(i32))] +#[conversions(copy, move, default = constructor_1)] +#[constructor(constructor_2, const_lvalue_ref(i32))] #[byte_size(8)] pub struct Held { #[offset(0)] #[byte_size(8)] pub ptr: Ptr, } -impl ConstructibleFrom<()> for Held { - fn constructor(this: Ptr, _: ()) { +impl Held { + pub fn constructor_1(this: Ptr) { field!(this, ptr).write(Ptr::::null()); } -} -impl ConstructibleFrom<(LvalueRef>,)> for Held { - fn constructor(this: Ptr, (n,): (LvalueRef>,)) { + pub fn constructor_2(this: Ptr, n: LvalueRef>) { let n = n.as_pointer(); field!(this, ptr).write((n).clone()); } -} -impl ConvertibleTo for LvalueRef> {} -impl ConstructibleFrom<(Ptr, i32)> for Held { - fn constructor(this: Ptr, (n, mut _a1): (Ptr, i32)) { + pub fn constructor_3(this: Ptr, n: Ptr, mut _a1: i32) { field!(this, ptr).write((n).clone()); } } @@ -222,8 +214,8 @@ impl Default for Held { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Held::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -338,8 +330,9 @@ thread_local!( match (field_ptr!( (*{ __tmp_7 = Some(Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Temporary::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_7 @@ -433,11 +426,8 @@ 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())); - , i32)>>::constructor( - __v.as_pointer(), - (LvalueRef::bind(counter.as_pointer()), 3), - ); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2(__v.as_pointer(), LvalueRef::bind(counter.as_pointer()), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -464,10 +454,12 @@ 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())); - , i32)>>::constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2( __v.as_pointer(), - (LvalueRef::bind((__tmp_9).clone()), 2), + LvalueRef::bind((__tmp_9).clone()), + 2, ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -505,10 +497,12 @@ 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())); - , i32)>>::constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2( __v.as_pointer(), - (LvalueRef::bind((__tmp_11).clone()), 2), + LvalueRef::bind((__tmp_11).clone()), + 2, ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -543,10 +537,12 @@ 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())); - , i32)>>::constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2( __v.as_pointer(), - (LvalueRef::bind((__tmp_13).clone()), 2), + LvalueRef::bind((__tmp_13).clone()), + 2, ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -582,10 +578,12 @@ 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())); - , i32)>>::constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2( __v.as_pointer(), - (LvalueRef::bind((__tmp_16).clone()), 2), + LvalueRef::bind((__tmp_16).clone()), + 2, ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -630,10 +628,12 @@ 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())); - , i32)>>::constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2( __v.as_pointer(), - (LvalueRef::bind((__tmp_19).clone()), 3), + LvalueRef::bind((__tmp_19).clone()), + 3, ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -664,10 +664,12 @@ 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())); - , i32)>>::constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2( __v.as_pointer(), - (LvalueRef::bind((__tmp_21).clone()), 3), + LvalueRef::bind((__tmp_21).clone()), + 3, ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -698,10 +700,12 @@ 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())); - , i32)>>::constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2( __v.as_pointer(), - (LvalueRef::bind((__tmp_24).clone()), 3), + LvalueRef::bind((__tmp_24).clone()), + 3, ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -740,10 +744,12 @@ 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())); - , i32)>>::constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2( __v.as_pointer(), - (LvalueRef::bind((__tmp_27).clone()), 3), + LvalueRef::bind((__tmp_27).clone()), + 3, ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -784,10 +790,12 @@ 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())); - , i32)>>::constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2( __v.as_pointer(), - (LvalueRef::bind((__tmp_30).clone()), 3), + LvalueRef::bind((__tmp_30).clone()), + 3, ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -814,10 +822,12 @@ 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())); - , i32)>>::constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2( __v.as_pointer(), - (LvalueRef::bind((__tmp_33).clone()), 3), + LvalueRef::bind((__tmp_33).clone()), + 3, ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -1332,18 +1342,14 @@ fn main_0() -> i32 { keys.decay().offset(0).clone(), ))), Rc::new(RefCell::new({ - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - , - i32, - )>>::constructor( + let __v: Value = + Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Item::constructor_2( __v.as_pointer(), - ( - LvalueRef::bind((__tmp_61).clone()), - 2, - ), + LvalueRef::bind((__tmp_61).clone()), + 2, ); Rc::try_unwrap(__v) .ok() @@ -1390,18 +1396,14 @@ fn main_0() -> i32 { keys.decay().offset(1).clone(), ))), Rc::new(RefCell::new({ - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - , - i32, - )>>::constructor( + let __v: Value = + Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Item::constructor_2( __v.as_pointer(), - ( - LvalueRef::bind((__tmp_64).clone()), - 2, - ), + LvalueRef::bind((__tmp_64).clone()), + 2, ); Rc::try_unwrap(__v) .ok() @@ -1448,18 +1450,14 @@ fn main_0() -> i32 { keys.decay().offset(2).clone(), ))), Rc::new(RefCell::new({ - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - , - i32, - )>>::constructor( + let __v: Value = + Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Item::constructor_2( __v.as_pointer(), - ( - LvalueRef::bind((__tmp_69).clone()), - 2, - ), + LvalueRef::bind((__tmp_69).clone()), + 2, ); Rc::try_unwrap(__v) .ok() @@ -1718,13 +1716,12 @@ fn main_0() -> i32 { key.as_pointer().clone(), ))), Rc::new(RefCell::new({ - let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >, - )>>::constructor( + let __v: Value = Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Held::constructor_2( __v.as_pointer(), - (LvalueRef::bind(ordinary.as_pointer()),), + LvalueRef::bind(ordinary.as_pointer()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -1772,16 +1769,13 @@ fn main_0() -> i32 { key.as_pointer().clone(), ))), Rc::new(RefCell::new({ - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - >, - )>>::constructor( + let __v: Value = + Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Held::constructor_2( __v.as_pointer(), - (LvalueRef::bind( - (__tmp_83).clone(), - ),), + LvalueRef::bind((__tmp_83).clone()), ); Rc::try_unwrap(__v) .ok() @@ -1832,9 +1826,14 @@ fn main_0() -> i32 { key.as_pointer().clone(), ))), Rc::new(RefCell::new({ - let __v: Value = - Rc::new(RefCell::new(::zero_init())); - ,i32 ,)>>::constructor(__v.as_pointer(), (ordinary_array .decay() , 0 ,)) ; + let __v: Value = Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Held::constructor_3( + __v.as_pointer(), + ordinary_array.decay(), + 0, + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -1880,15 +1879,14 @@ fn main_0() -> i32 { key.as_pointer().clone(), ))), Rc::new(RefCell::new({ - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - , - i32, - )>>::constructor( + let __v: Value = + Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Held::constructor_3( __v.as_pointer(), - ((__tmp_88).clone(), 0), + (__tmp_88).clone(), + 0, ); Rc::try_unwrap(__v) .ok() @@ -1953,11 +1951,8 @@ fn main_0() -> i32 { (*{ __tmp_94 = Some(Rc::new(RefCell::new({ let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >::constructor( - __v.as_pointer(), - (), - ); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Temporary::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_94 @@ -1993,11 +1988,8 @@ fn main_0() -> i32 { (*{ __tmp_96 = Some(Rc::new(RefCell::new({ let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >::constructor( - __v.as_pointer(), - (), - ); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Nested::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_96 @@ -2034,11 +2026,8 @@ fn main_0() -> i32 { (*{ __tmp_98 = Some(Rc::new(RefCell::new({ let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >::constructor( - __v.as_pointer(), - (), - ); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Temporary::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_98 @@ -2074,11 +2063,8 @@ fn main_0() -> i32 { (*{ __tmp_100 = Some(Rc::new(RefCell::new({ let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >::constructor( - __v.as_pointer(), - (), - ); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Temporary::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_100 @@ -2113,11 +2099,8 @@ fn main_0() -> i32 { ((*{ __tmp_102 = Some(Rc::new(RefCell::new({ let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >::constructor( - __v.as_pointer(), - (), - ); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Temporary::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_102 @@ -2152,11 +2135,8 @@ fn main_0() -> i32 { ((*(*{ __tmp_104 = Some(Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >::constructor( - __v.as_pointer(), - (), - ); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Temporary::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })))))); &mut __tmp_104 @@ -2230,13 +2210,12 @@ fn main_0() -> i32 { key.as_pointer().clone(), ))), Rc::new(RefCell::new({ - let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >, - )>>::constructor( + let __v: Value = Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Held::constructor_2( __v.as_pointer(), - (LvalueRef::bind(ordinary.as_pointer()),), + LvalueRef::bind(ordinary.as_pointer()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -2257,11 +2236,38 @@ fn main_0() -> i32 { let mut __tmp_107: Option>; { match (if (choose != 0) { - field_ptr!(( *{ __tmp_106 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); >::constructor(__v.as_pointer(), ()) ; -Rc::try_unwrap(__v).ok().unwrap().into_inner() } ))) ; & mut __tmp_106 } ) .as_pointer() , n) + field_ptr!( + (*{ + __tmp_106 = Some(Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Temporary::constructor_1(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }))); + &mut __tmp_106 + }) + .as_pointer(), + n + ) } else { - array_field_ptr!(( *{ __tmp_107 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); >::constructor(__v.as_pointer(), ()) ; -Rc::try_unwrap(__v).ok().unwrap().into_inner() } ))) ; & mut __tmp_107 } ) .as_pointer() , data) . offset ( ( index . postfix_inc () ) as isize ) + array_field_ptr!( + (*{ + __tmp_107 = Some(Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Temporary::constructor_1(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }))); + &mut __tmp_107 + }) + .as_pointer(), + data + ) + .offset((index.postfix_inc()) as isize) },) { (__tmp_105,) => { @@ -2274,16 +2280,15 @@ Rc::try_unwrap(__v).ok().unwrap().into_inner() } ))) ; & mut __tmp_107 } ) .as_p key.as_pointer().clone(), ))), Rc::new(RefCell::new({ - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - >, - )>>::constructor( + let __v: Value = + Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Held::constructor_2( __v.as_pointer(), - (LvalueRef::bind( + LvalueRef::bind( (__tmp_105).clone(), - ),), + ), ); Rc::try_unwrap(__v) .ok() @@ -2323,14 +2328,11 @@ Rc::try_unwrap(__v).ok().unwrap().into_inner() } ))) ; & mut __tmp_107 } ) .as_p Rc::new(RefCell::new(Map::new())); { let __tmp_109: Value = - Rc::new(RefCell::new(::zero_init())); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); { match (({ Owner::value({ - >::constructor( - __tmp_109.as_pointer(), - (), - ); + Owner::constructor_1(__tmp_109.as_pointer()); __tmp_109.as_pointer() }) }),) @@ -2345,16 +2347,15 @@ Rc::try_unwrap(__v).ok().unwrap().into_inner() } ))) ; & mut __tmp_107 } ) .as_p key.as_pointer().clone(), ))), Rc::new(RefCell::new({ - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - >, - )>>::constructor( + let __v: Value = + Rc::new(RefCell::new( + ZeroInitialization::zero_init(), + )); + Held::constructor_2( __v.as_pointer(), - (LvalueRef::bind( + LvalueRef::bind( (__tmp_108).clone(), - ),), + ), ); Rc::try_unwrap(__v) .ok() @@ -2408,8 +2409,8 @@ Rc::try_unwrap(__v).ok().unwrap().into_inner() } ))) ; & mut __tmp_107 } ) .as_p let __tmp_111: Value>>; match ({ __tmp_111 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Noncopy::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))))); __tmp_111.as_pointer() @@ -2448,8 +2449,8 @@ Rc::try_unwrap(__v).ok().unwrap().into_inner() } ))) ; & mut __tmp_107 } ) .as_p let __tmp_113: Value>>; match ({ __tmp_113 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Noncopy::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))))); __tmp_113.as_pointer() diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index d12d7e3439..9a998db869 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -34,28 +34,23 @@ pub fn pick_3(mut i: i32) -> Ptr { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move)] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct Bag { #[offset(0)] pub n: i32, } -impl ConstructibleFrom<(i32,)> for Bag { - fn constructor(this: Ptr, (mut n,): (i32,)) { +impl Bag { + pub fn constructor_1(this: Ptr, mut n: i32) { field!(this, n).write(n); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for Bag { - fn constructor(this: Ptr, (o,): (LvalueRef>,)) { + pub fn constructor_2(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(); } } -impl CopyConstructible for Bag {} -impl ConvertibleTo for LvalueRef> {} impl CppLess for Bag { fn less(a: Ptr, b: Ptr) -> bool { operator_lt_4(a.clone(), b.clone()) @@ -65,7 +60,7 @@ pub fn operator_lt_4(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.n) } < { b.with(|__s| __s.n) }); } pub fn make_5(__return: Ptr, mut n: i32) { - >::constructor(__return.clone(), (n,)); + Bag::constructor_1(__return.clone(), n); return; } pub fn main() { @@ -162,8 +157,8 @@ fn main_0() -> i32 { calls_0.with(|rc| *rc.borrow_mut() = 0); assert!( ({ - let __tmp_7: Value = Rc::new(RefCell::new(::zero_init())); - let __tmp_9: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_7: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + let __tmp_9: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); (match ( { ({ make_5(Ptr::clone(&__tmp_7.as_pointer()), 1) }); @@ -185,8 +180,8 @@ fn main_0() -> i32 { .with(|__s| __s.n) == 2) }) && ({ - let __tmp_11: Value = Rc::new(RefCell::new(::zero_init())); - let __tmp_13: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_11: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + let __tmp_13: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); (match ( { ({ make_5(Ptr::clone(&__tmp_11.as_pointer()), 1) }); diff --git a/tests/unit/out/refcount/move_assign.rs b/tests/unit/out/refcount/move_assign.rs index 866643b983..3a4df73876 100644 --- a/tests/unit/out/refcount/move_assign.rs +++ b/tests/unit/out/refcount/move_assign.rs @@ -16,28 +16,23 @@ use std::rc::{Rc, Weak}; Default, Conversions, )] -#[conversions(move)] -#[constructor(value(i32))] +#[conversions(move = constructor_3)] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct MoveOnly { #[offset(0)] pub v: i32, } -impl ConstructibleFrom<(i32,)> for MoveOnly { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl MoveOnly { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(RvalueRef,)> for MoveOnly { - fn constructor(this: Ptr, (o,): (RvalueRef,)) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } -impl MoveConstructible for MoveOnly {} -impl ConvertibleTo for RvalueRef {} impl MoveAssignable for MoveOnly { fn move_assign(this: Ptr, o: RvalueRef) -> Ptr { let o = o.as_pointer(); @@ -50,12 +45,16 @@ impl MoveAssignable for MoveOnly { } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] +#[conversions(default = constructor_1)] #[byte_size(4)] pub struct ConstMoveAssign { #[offset(0)] pub mark: i32, } impl ConstMoveAssign { + pub fn constructor_1(this: Ptr) { + field!(this, mark).write(0); + } pub fn operator_assign_2(this: Ptr, o: Ptr) -> Ptr { field!(this, mark).write((o.with(|__s| __s.mark) + 1)); return (this).clone(); @@ -65,29 +64,21 @@ impl ConstMoveAssign { return (this).clone(); } } -impl ConstructibleFrom<()> for ConstMoveAssign { - fn constructor(this: Ptr, _: ()) { - field!(this, mark).write(0); - } -} impl Default for ConstMoveAssign { fn default() -> Self { { { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + ConstMoveAssign::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } } } pub fn make_0(__return: Ptr, mut v: i32) { - object!(m, MoveOnly, (i32,), (v,)); - ConvertibleTo::convert( - >::bind(m.as_pointer()), - __return.clone(), - ); + object!(m, MoveOnly::constructor_1(v)); + MoveOnly::constructor_3(__return.clone(), RvalueRef::bind(m.as_pointer())); return; } pub fn main() { @@ -95,15 +86,15 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, MoveOnly, (i32,), (1,)); - object!(b, MoveOnly, (i32,), (2,)); - object!(c, MoveOnly, (i32,), (3,)); + object!(a, MoveOnly::constructor_1(1)); + object!(b, MoveOnly::constructor_1(2)); + object!(c, MoveOnly::constructor_1(3)); assign!(a = RvalueRef(b)); assert!(({ (*a.borrow()).v } == 2)); assert!(({ (*b.borrow()).v } == 0)); ({ - let _o: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(_o.as_pointer(), (3,)); + let _o: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MoveOnly::constructor_1(_o.as_pointer(), 3); assign!(b = RvalueRef(_o)) }); assign!(c = RvalueRef(*assign!(a = RvalueRef(b)))); @@ -111,13 +102,13 @@ fn main_0() -> i32 { (({ (*b.borrow()).v } == 0) && ({ (*a.borrow()).v } == 0)) && ({ (*c.borrow()).v } == 3) ); ({ - let _o: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(_o.as_pointer(), (5,)); + let _o: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MoveOnly::constructor_1(_o.as_pointer(), 5); assign!(a = RvalueRef(_o)) }); assert!(({ (*a.borrow()).v } == 5)); ({ - let _o: Value = Rc::new(RefCell::new(::zero_init())); + let _o: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ make_0(Ptr::clone(&_o.as_pointer()), 6) }); assign!(a = RvalueRef(_o)) }); @@ -126,23 +117,23 @@ fn main_0() -> i32 { assert!(({ (*a.borrow()).v } == 6)); let vec_: Value> = Rc::new(RefCell::new(Vec::new())); { - let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - >::constructor(__tmp_1.as_pointer(), (7,)); + MoveOnly::constructor_1(__tmp_1.as_pointer(), 7); __tmp_1.as_pointer() },) { (__tmp_0,) => MoveConstructible::push_moved(&vec_.as_pointer(), (__tmp_0).clone()), } }; - object!(d, MoveOnly, (i32,), (8,)); + object!(d, MoveOnly::constructor_1(8)); assign!(*vec_.decay().offset(0_usize) = RvalueRef(d)); assert!(({ (*vec_.borrow())[0_usize].v } == 8)); assert!(({ (*d.borrow()).v } == 0)); - object!(m, ConstMoveAssign); - object!(m1, ConstMoveAssign); - object!(m2, ConstMoveAssign); - object!(cm, ConstMoveAssign); + object!(m, ConstMoveAssign::constructor_1()); + object!(m1, ConstMoveAssign::constructor_1()); + object!(m2, ConstMoveAssign::constructor_1()); + object!(cm, ConstMoveAssign::constructor_1()); ConstMoveAssign::operator_assign_2(m1.as_pointer(), m.as_pointer()); ConstMoveAssign::operator_assign_3(m2.as_pointer(), cm.as_pointer()); assert!(({ (*m1.borrow()).mark } == 1)); diff --git a/tests/unit/out/refcount/move_ctor.rs b/tests/unit/out/refcount/move_ctor.rs index f33e8fa424..db7517ca3b 100644 --- a/tests/unit/out/refcount/move_ctor.rs +++ b/tests/unit/out/refcount/move_ctor.rs @@ -9,60 +9,50 @@ use std::rc::{Rc, Weak}; #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[conversions(move)] -#[constructor(value(i32))] +#[conversions(move = constructor_3)] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct MoveOnly { #[offset(0)] pub v: i32, } -impl ConstructibleFrom<(i32,)> for MoveOnly { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl MoveOnly { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(RvalueRef,)> for MoveOnly { - fn constructor(this: Ptr, (o,): (RvalueRef,)) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } -impl MoveConstructible for MoveOnly {} -impl ConvertibleTo for RvalueRef {} #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] -#[conversions(move)] +#[conversions(move = constructor_2, default = constructor_1)] +#[constructor(constructor_3, const_rvalue_ref(ConstMove))] #[byte_size(4)] pub struct ConstMove { #[offset(0)] pub mark: i32, } -impl ConstructibleFrom<()> for ConstMove { - fn constructor(this: Ptr, _: ()) { +impl ConstMove { + pub fn constructor_1(this: Ptr) { field!(this, mark).write(0); } -} -impl ConstructibleFrom<(RvalueRef,)> for ConstMove { - fn constructor(this: Ptr, (o,): (RvalueRef,)) { + pub fn constructor_2(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, mark).write((o.with(|__s| __s.mark) + 1)); } -} -impl ConvertibleTo for RvalueRef {} -impl ConstructibleFrom<(RvalueRef>,)> for ConstMove { - fn constructor(this: Ptr, (o,): (RvalueRef>,)) { + pub fn constructor_3(this: Ptr, o: RvalueRef>) { let o = o.as_pointer(); field!(this, mark).write((o.with(|__s| __s.mark) + 10)); } } -impl ConvertibleTo for RvalueRef> {} impl Default for ConstMove { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + ConstMove::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -71,8 +61,8 @@ impl Default for ConstMove { #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] #[byte_size(12)] pub struct ThrowingMove { #[offset(0)] @@ -82,26 +72,19 @@ pub struct ThrowingMove { #[offset(8)] pub moves: i32, } -impl ConstructibleFrom<(i32,)> for ThrowingMove { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl ThrowingMove { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for ThrowingMove { - fn constructor(this: Ptr, (o,): (LvalueRef>,)) { + pub fn constructor_2(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 CopyConstructible for ThrowingMove {} -impl ConvertibleTo for LvalueRef> {} -impl ConstructibleFrom<(RvalueRef,)> for ThrowingMove { - fn constructor(this: Ptr, (o,): (RvalueRef,)) { + pub fn constructor_3(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)); @@ -109,13 +92,11 @@ impl ConstructibleFrom<(RvalueRef,)> for ThrowingMove { field!(o, v).write(0); } } -impl MoveConstructible for ThrowingMove {} -impl ConvertibleTo for RvalueRef {} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] #[byte_size(12)] pub struct NoexceptMove { #[offset(0)] @@ -125,26 +106,19 @@ pub struct NoexceptMove { #[offset(8)] pub moves: i32, } -impl ConstructibleFrom<(i32,)> for NoexceptMove { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl NoexceptMove { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for NoexceptMove { - fn constructor(this: Ptr, (o,): (LvalueRef>,)) { + pub fn constructor_2(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 CopyConstructible for NoexceptMove {} -impl ConvertibleTo for LvalueRef> {} -impl ConstructibleFrom<(RvalueRef,)> for NoexceptMove { - fn constructor(this: Ptr, (o,): (RvalueRef,)) { + pub fn constructor_3(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)); @@ -152,17 +126,12 @@ impl ConstructibleFrom<(RvalueRef,)> for NoexceptMove { field!(o, v).write(0); } } -impl MoveConstructible for NoexceptMove {} -impl ConvertibleTo for RvalueRef {} pub fn by_value_0(m: Ptr) -> i32 { return m.with(|__s| __s.v); } pub fn make_1(__return: Ptr, mut v: i32) { - object!(m, MoveOnly, (i32,), (v,)); - ConvertibleTo::convert( - >::bind(m.as_pointer()), - __return.clone(), - ); + object!(m, MoveOnly::constructor_1(v)); + MoveOnly::constructor_3(__return.clone(), RvalueRef::bind(m.as_pointer())); return; } pub fn main() { @@ -170,88 +139,87 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, MoveOnly, (i32,), (1,)); - object!(b, MoveOnly, RvalueRef::bind(a.as_pointer())); + object!(a, MoveOnly::constructor_1(1)); + object!(b, MoveOnly::constructor_3(RvalueRef::bind(a.as_pointer()))); assert!(({ (*b.borrow()).v } == 1)); assert!(({ (*a.borrow()).v } == 0)); - object!(c, MoveOnly = >::bind(b.as_pointer())); + object!(c, MoveOnly::constructor_3(RvalueRef::bind(b.as_pointer()))); assert!(({ (*c.borrow()).v } == 1)); assert!(({ (*b.borrow()).v } == 0)); - object!(d, MoveOnly, RvalueRef::bind(c.as_pointer())); + object!(d, MoveOnly::constructor_3(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,) })); assert!(({ (*e.borrow()).v } == 5)); assert!( (({ - let _m: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(_m.as_pointer(), (6,)); + let _m: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MoveOnly::constructor_1(_m.as_pointer(), 6); by_value_0(_m.as_pointer()) }) == 6) ); assert!( (({ - let _m: Value = Rc::new(RefCell::new(::zero_init())); - ,)>>::constructor( - _m.as_pointer(), - (RvalueRef::bind(e.as_pointer()),), - ); + let _m: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MoveOnly::constructor_3(_m.as_pointer(), RvalueRef::bind(e.as_pointer())); by_value_0(_m.as_pointer()) }) == 5) ); assert!(({ (*e.borrow()).v } == 0)); let vec_: Value> = Rc::new(RefCell::new(Vec::new())); { - let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - >::constructor(__tmp_1.as_pointer(), (7,)); + MoveOnly::constructor_1(__tmp_1.as_pointer(), 7); __tmp_1.as_pointer() },) { (__tmp_0,) => MoveConstructible::push_moved(&vec_.as_pointer(), (__tmp_0).clone()), } }; - object!(f, MoveOnly, (i32,), (8,)); + object!(f, MoveOnly::constructor_1(8)); MoveConstructible::push_moved(&vec_.as_pointer(), f.as_pointer()); assert!(({ (*vec_.borrow())[0_usize].v } == 7) && ({ (*vec_.borrow())[1_usize].v } == 8)); assert!(({ (*f.borrow()).v } == 0)); - object!(m, ConstMove); + object!(m, ConstMove::constructor_1()); object!( m1, - ConstMove, - (RvalueRef,), - (RvalueRef::bind(m.as_pointer()),) + ConstMove::constructor_2(RvalueRef::bind(m.as_pointer())) ); - object!(cm, ConstMove); + object!(cm, ConstMove::constructor_1()); object!( m2, - ConstMove, - (RvalueRef>,), - (RvalueRef::bind(cm.as_pointer()),) + ConstMove::constructor_3(RvalueRef::bind(cm.as_pointer())) ); assert!(({ (*m1.borrow()).mark } == 1)); assert!(({ (*m2.borrow()).mark } == 10)); - object!(t, ThrowingMove, (i32,), (1,)); - object!(t1, ThrowingMove, LvalueRef::bind(t.as_pointer())); + object!(t, ThrowingMove::constructor_1(1)); + object!( + t1, + ThrowingMove::constructor_2(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, (i32,), (2,)); - object!(n1, NoexceptMove, RvalueRef::bind(n.as_pointer())); + object!(n, NoexceptMove::constructor_1(2)); + object!( + n1, + NoexceptMove::constructor_3(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, (i32,), (3,)); - object!(g1, MoveOnly, RvalueRef::bind(g.as_pointer())); + object!(g, MoveOnly::constructor_1(3)); + object!(g1, MoveOnly::constructor_3(RvalueRef::bind(g.as_pointer()))); assert!(({ (*g1.borrow()).v } == 3)); assert!(({ (*g.borrow()).v } == 0)); let nv: Value> = Rc::new(RefCell::new(Vec::new())); { - let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_3: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - >::constructor(__tmp_3.as_pointer(), (4,)); + NoexceptMove::constructor_1(__tmp_3.as_pointer(), 4); __tmp_3.as_pointer() },) { diff --git a/tests/unit/out/refcount/move_this.rs b/tests/unit/out/refcount/move_this.rs index 6cd5366c06..dc2ab80f98 100644 --- a/tests/unit/out/refcount/move_this.rs +++ b/tests/unit/out/refcount/move_this.rs @@ -9,14 +9,26 @@ use std::rc::{Rc, Weak}; #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct Chain { #[offset(0)] pub v: i32, } impl Chain { + pub fn constructor_1(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } + pub fn constructor_2(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); + field!(this, v).write((o.with(|__s| __s.v) + 100)); + } + pub fn constructor_3(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); + field!(this, v).write((o.with(|__s| __s.v) + 1)); + field!(o, v).write(0); + } pub fn add_4(this: Ptr, mut n: i32) -> Ptr { { field!(this, v).with_mut(|__v| *__v = *__v + n) @@ -30,43 +42,17 @@ impl Chain { return (this).clone(); } pub fn take(this: Ptr, __return: Ptr) { - ConvertibleTo::convert(>::bind((this).clone()), __return.clone()); + Chain::constructor_3(__return.clone(), RvalueRef::bind((this).clone())); return; } pub fn copy(this: Ptr, __return: Ptr) { - ConvertibleTo::convert( - >>::bind((this).clone()), - __return.clone(), - ); + Chain::constructor_2(__return.clone(), LvalueRef::bind((this).clone())); return; } pub fn self_(this: Ptr) -> Ptr { return (this).clone(); } } -impl ConstructibleFrom<(i32,)> for Chain { - fn constructor(this: Ptr, (mut v,): (i32,)) { - field!(this, v).write(v); - } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(LvalueRef>,)> for Chain { - fn constructor(this: Ptr, (o,): (LvalueRef>,)) { - let o = o.as_pointer(); - field!(this, v).write((o.with(|__s| __s.v) + 100)); - } -} -impl CopyConstructible for Chain {} -impl ConvertibleTo for LvalueRef> {} -impl ConstructibleFrom<(RvalueRef,)> for Chain { - fn 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); - } -} -impl MoveConstructible for Chain {} -impl ConvertibleTo for RvalueRef {} pub fn consume_0(c: Ptr) -> i32 { return c.with(|__s| __s.v); } @@ -75,23 +61,23 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, Chain, (i32,), (1,)); + object!(a, Chain::constructor_1(1)); ({ Chain::add_4(({ Chain::add_4(a.as_pointer(), 1) }), 1) }); assert!(({ (*a.borrow()).v } == 3)); - object!(b0, Chain, (i32,), (5,)); + object!(b0, Chain::constructor_1(5)); object!( b, - Chain = >::bind( + Chain::constructor_3(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| { - let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_0: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ Chain::take( { - >::constructor(__tmp_0.as_pointer(), (10,)); + Chain::constructor_1(__tmp_0.as_pointer(), 10); __tmp_0.as_pointer() }, Ptr::clone(&c.clone()), @@ -103,18 +89,18 @@ fn main_0() -> i32 { Chain::copy(c.as_pointer(), Ptr::clone(&d.clone())) })); assert!(({ (*d.borrow()).v } == 111) && ({ (*c.borrow()).v } == 11)); - object!(g, Chain, (i32,), (20,)); + object!(g, Chain::constructor_1(20)); assert!( (({ - let _c: Value = Rc::new(RefCell::new(::zero_init())); - ,)>>::constructor( + let _c: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Chain::constructor_3( _c.as_pointer(), - (RvalueRef::bind(({ Chain::self_(g.as_pointer()) })),), + RvalueRef::bind(({ Chain::self_(g.as_pointer()) })), ); consume_0(_c.as_pointer()) }) == 21) ); - object!(e, Chain, (i32,), (30,)); + object!(e, Chain::constructor_1(30)); object!(f, Chain, |f| ({ Chain::take(e.as_pointer(), Ptr::clone(&f.clone())) })); diff --git a/tests/unit/out/refcount/opaque_forward_decl.rs b/tests/unit/out/refcount/opaque_forward_decl.rs index 80d6c431fb..c253a00c35 100644 --- a/tests/unit/out/refcount/opaque_forward_decl.rs +++ b/tests/unit/out/refcount/opaque_forward_decl.rs @@ -36,22 +36,9 @@ fn main_0() -> i32 { }; return (c.x - 42); } -#[derive(Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg)] +#[derive( + Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg, ZeroInitialization, Destructible, Conversions, +)] #[byte_size(1)] pub struct opaque; -impl libcc2rs::overload::Conversions for opaque { - fn table() -> libcc2rs::overload::Table { - libcc2rs::overload::Table { - id: ::std::any::TypeId::of::(), - name: "opaque", - arithmetic: None, - storage: || Ptr::alloc(opaque).to_any(), - release: |ptr| ptr.downcast::().delete(), - copy: |_, _| {}, - move_from: |_, _| {}, - constructors: vec![], - conversion_functions: vec![], - } - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_comparison_nonbool.rs b/tests/unit/out/refcount/operator_comparison_nonbool.rs index 1f6296b0d3..c2d5bcdbf8 100644 --- a/tests/unit/out/refcount/operator_comparison_nonbool.rs +++ b/tests/unit/out/refcount/operator_comparison_nonbool.rs @@ -152,26 +152,23 @@ impl CppLess for Mixed { Conversions, )] #[conversions(copy, move)] -#[constructor(explicit, value(bool))] -#[conversion_function(bool, const_lvalue_ref)] +#[constructor(constructor_1, explicit, value(bool))] +#[conversion_function(conversion_function_2, bool, const_lvalue_ref)] #[byte_size(1)] pub struct MyBool { #[offset(0)] pub value: bool, } -impl ConstructibleFrom<(bool,)> for MyBool { - fn constructor(this: Ptr, (mut v,): (bool,)) { +impl MyBool { + pub fn constructor_1(this: Ptr, mut v: bool) { field!(this, value).write(v); } -} -impl ConversionFunction>> for MyBool { - fn conversion_function(this: LvalueRef>, to: Ptr) { + pub fn conversion_function_2(this: LvalueRef>, __return: Ptr) { let this = this.as_pointer(); - to.write(this.with(|__s| __s.value)); + __return.write(this.with(|__s| __s.value)); return; } } -impl ImplicitConversionFunction>> for MyBool {} #[derive( Copy, Clone, @@ -195,8 +192,8 @@ impl CppLess for Boolish { fn less(a: Ptr, b: Ptr) -> bool { { let __cmp = operator_lt_6(a.read(), b.read()); - let __v: Value = Rc::new(RefCell::new(false)); - MyBool::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MyBool::conversion_function_2( >>::bind(Rc::new(RefCell::new(__cmp)).as_pointer()), Ptr::clone(&__v.as_pointer()), ); @@ -206,15 +203,15 @@ impl CppLess for Boolish { } pub fn operator_eq_7(mut a: Boolish, mut b: Boolish) -> MyBool { return { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ((a.v == b.v),)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MyBool::constructor_1(__v.as_pointer(), (a.v == b.v)); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } pub fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { return { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ((a.v < b.v),)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MyBool::constructor_1(__v.as_pointer(), (a.v < b.v)); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -230,30 +227,27 @@ pub fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[constructor(explicit, value(bool))] -#[conversion_function(bool, const_lvalue_ref)] +#[constructor(constructor_1, explicit, value(bool))] +#[conversion_function(conversion_function_3, bool, const_lvalue_ref)] #[byte_size(1)] pub struct RefBool { #[offset(0)] pub value: bool, } -impl ConstructibleFrom<(bool,)> for RefBool { - fn constructor(this: Ptr, (mut v,): (bool,)) { +impl RefBool { + pub fn constructor_1(this: Ptr, mut v: bool) { field!(this, value).write(v); } -} -impl ConversionFunction>> for RefBool { - fn conversion_function(this: LvalueRef>, to: Ptr) { + pub fn conversion_function_3(this: LvalueRef>, __return: Ptr) { let this = this.as_pointer(); - to.write(this.with(|__s| __s.value)); + __return.write(this.with(|__s| __s.value)); return; } } -impl ImplicitConversionFunction>> for RefBool {} thread_local!( pub static ref_true_8: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (true,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + RefBool::constructor_1(__v.as_pointer(), true); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -336,8 +330,8 @@ fn main_0() -> i32 { let mut b1: Boolish = Boolish { v: 1 }; let mut b2: Boolish = Boolish { v: 2 }; assert!({ - let __v: Value = Rc::new(RefCell::new(false)); - MyBool::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MyBool::conversion_function_2( >>::bind( Rc::new(RefCell::new(({ operator_eq_7(b1, Boolish { v: 1 }) }))).as_pointer(), ), @@ -347,8 +341,8 @@ fn main_0() -> i32 { }); assert!( !({ - let __v: Value = Rc::new(RefCell::new(false)); - MyBool::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MyBool::conversion_function_2( >>::bind( Rc::new(RefCell::new(({ operator_lt_6(b2, b1) }))).as_pointer(), ), @@ -378,8 +372,8 @@ fn main_0() -> i32 { let ri1: Value = Rc::new(RefCell::new(RefInt { v: 1 })); let ri2: Value = Rc::new(RefCell::new(RefInt { v: 2 })); assert!({ - let __v: Value = Rc::new(RefCell::new(false)); - RefBool::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + RefBool::conversion_function_3( >>::bind( ({ RefInt::operator_eq(ri1.as_pointer(), ri2.as_pointer()) }), ), @@ -411,8 +405,8 @@ impl WeaklyEqualityComparableWith for Boolish { fn equal(a: Ptr, b: Ptr) -> bool { { let __cmp = operator_eq_7(a.read(), b.read()); - let __v: Value = Rc::new(RefCell::new(false)); - MyBool::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MyBool::conversion_function_2( >>::bind(Rc::new(RefCell::new(__cmp)).as_pointer()), Ptr::clone(&__v.as_pointer()), ); @@ -429,8 +423,8 @@ impl WeaklyEqualityComparableWith for RefInt { fn equal(this: Ptr, _a0: Ptr) -> bool { { let __cmp = RefInt::operator_eq(this.clone(), _a0.clone()); - let __v: Value = Rc::new(RefCell::new(false)); - RefBool::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + RefBool::conversion_function_3( >>::bind(__cmp.clone()), Ptr::clone(&__v.as_pointer()), ); diff --git a/tests/unit/out/refcount/operator_comparison_noncopyable.rs b/tests/unit/out/refcount/operator_comparison_noncopyable.rs index e25b64f095..9ca88df26f 100644 --- a/tests/unit/out/refcount/operator_comparison_noncopyable.rs +++ b/tests/unit/out/refcount/operator_comparison_noncopyable.rs @@ -15,18 +15,17 @@ pub fn operator_lt_0(x: Ptr, y: Ptr) -> bool { #[memberwise(move_constructor)] #[derive(Conversions)] #[conversions(move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct S { #[offset(0)] data_: i32, } -impl ConstructibleFrom<(i32,)> for S { - fn constructor(this: Ptr, (mut data,): (i32,)) { +impl S { + pub fn constructor_1(this: Ptr, mut data: i32) { field!(this, data_).write(data); } } -impl ConvertibleTo for i32 {} impl CppLess for S { fn less(x: Ptr, y: Ptr) -> bool { operator_lt_0(x.clone(), y.clone()) @@ -37,9 +36,9 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, S, (i32,), (1,)); - object!(b, S, (i32,), (2,)); - object!(c, S, (i32,), (1,)); + object!(a, S::constructor_1(1)); + object!(b, S::constructor_1(2)); + object!(c, S::constructor_1(1)); assert!(({ WeaklyEqualityComparableWith::equal(a.as_pointer(), c.as_pointer(),) })); assert!(({ operator_lt_0(a.as_pointer(), b.as_pointer(),) })); assert!(!({ operator_lt_0(b.as_pointer(), a.as_pointer(),) })); diff --git a/tests/unit/out/refcount/operator_other_member.rs b/tests/unit/out/refcount/operator_other_member.rs index fee0715a88..6c34761050 100644 --- a/tests/unit/out/refcount/operator_other_member.rs +++ b/tests/unit/out/refcount/operator_other_member.rs @@ -41,8 +41,8 @@ impl Static { Conversions, )] #[conversions(copy, move)] -#[conversion_function(i32, const_lvalue_ref)] -#[conversion_function(bool, const_lvalue_ref, explicit)] +#[conversion_function(conversion_function_5, i32, const_lvalue_ref)] +#[conversion_function(conversion_function_6, bool, const_lvalue_ref, explicit)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -63,19 +63,14 @@ impl S { v: ({ (this.with(|__s| __s.v) * 10) } + { o.with(|__s| __s.v) }), }; } -} -impl ConversionFunction>> for S { - fn conversion_function(this: LvalueRef>, to: Ptr) { + pub fn conversion_function_5(this: LvalueRef>, __return: Ptr) { let this = this.as_pointer(); - to.write(this.with(|__s| __s.v)); + __return.write(this.with(|__s| __s.v)); return; } -} -impl ImplicitConversionFunction>> for S {} -impl ConversionFunction>> for S { - fn conversion_function(this: LvalueRef>, to: Ptr) { + pub fn conversion_function_6(this: LvalueRef>, __return: Ptr) { let this = this.as_pointer(); - to.write((this.with(|__s| __s.v) != 0)); + __return.write((this.with(|__s| __s.v) != 0)); return; } } @@ -91,8 +86,8 @@ fn main_0() -> i32 { assert!((({ S::operator_call_3(s.as_pointer(), 1, 2,) }) == 6)); assert!(({ ({ S::operator_comma(s.as_pointer(), t.as_pointer(),) }).v } == 34)); let mut i: i32 = { - let __v: Value = Rc::new(RefCell::new(0_i32)); - S::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + S::conversion_function_5( >>::bind(s.as_pointer()), Ptr::clone(&__v.as_pointer()), ); @@ -101,8 +96,8 @@ fn main_0() -> i32 { assert!((i == 3)); assert!( (({ - let __v: Value = Rc::new(RefCell::new(0_i32)); - S::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + S::conversion_function_5( >>::bind(s.as_pointer()), Ptr::clone(&__v.as_pointer()), ); @@ -111,16 +106,16 @@ fn main_0() -> i32 { == 4) ); if { - let __v: Value = Rc::new(RefCell::new(false)); - S::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + S::conversion_function_6( >>::bind(s.as_pointer()), Ptr::clone(&__v.as_pointer()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() } { assert!({ - let __v: Value = Rc::new(RefCell::new(false)); - S::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + S::conversion_function_6( >>::bind(s.as_pointer()), Ptr::clone(&__v.as_pointer()), ); @@ -131,8 +126,8 @@ fn main_0() -> i32 { } let z: Value = Rc::new(RefCell::new(S { v: 0 })); assert!({ - let __v: Value = Rc::new(RefCell::new(false)); - S::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + S::conversion_function_6( >>::bind(s.as_pointer()), Ptr::clone(&__v.as_pointer()), ); @@ -140,8 +135,8 @@ fn main_0() -> i32 { }); assert!( !({ - let __v: Value = Rc::new(RefCell::new(false)); - S::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + S::conversion_function_6( >>::bind(z.as_pointer()), Ptr::clone(&__v.as_pointer()), ); @@ -150,15 +145,15 @@ fn main_0() -> i32 { ); assert!( ({ - let __v: Value = Rc::new(RefCell::new(false)); - S::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + S::conversion_function_6( >>::bind(s.as_pointer()), Ptr::clone(&__v.as_pointer()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) && (!({ - let __v: Value = Rc::new(RefCell::new(false)); - S::conversion_function( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + S::conversion_function_6( >>::bind(z.as_pointer()), Ptr::clone(&__v.as_pointer()), ); diff --git a/tests/unit/out/refcount/pair.rs b/tests/unit/out/refcount/pair.rs index 2d6d2b8095..5140efef8b 100644 --- a/tests/unit/out/refcount/pair.rs +++ b/tests/unit/out/refcount/pair.rs @@ -31,17 +31,17 @@ fn main_0() -> i32 { .as_pointer(),) { (__tmp_0,) => { - object!(__first, f64, |__this| Conversions::construct( + object!(__first, f64, |__this| ConstructibleFrom::construct( __this, - &[overload::Arg::rvalue( + (RvalueRef::::bind( (*__tmp_0.upgrade().deref()).0.as_pointer() - )] + ),) )); - object!(__second, i32, |__this| Conversions::construct( + object!(__second, i32, |__this| ConstructibleFrom::construct( __this, - &[overload::Arg::rvalue( + (RvalueRef::::bind( (*__tmp_0.upgrade().deref()).1.as_pointer() - )] + ),) )); ( Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), @@ -70,13 +70,13 @@ fn main_0() -> i32 { .as_pointer(), ) { (__tmp_1, __tmp_2) => { - object!(__first, Ptr, |__this| Conversions::convert( - __this, - overload::Arg::rvalue((*__tmp_2.upgrade().deref()).0.as_pointer()) + object!(__first, Ptr, |__this| ConvertibleTo::convert( + RvalueRef::>::bind((*__tmp_2.upgrade().deref()).0.as_pointer()), + __this )); - object!(__second, u64, |__this| Conversions::convert( - __this, - overload::Arg::rvalue((*__tmp_2.upgrade().deref()).1.as_pointer()) + object!(__second, u64, |__this| ConvertibleTo::convert( + RvalueRef::::bind((*__tmp_2.upgrade().deref()).1.as_pointer()), + __this )); MoveAssignable::move_assign( (*__tmp_1.upgrade().deref()).0.as_pointer(), @@ -154,13 +154,13 @@ fn main_0() -> i32 { ))); let mut pw: Ptr = ((*w.borrow()).0.as_pointer()); { - object!(__first, i64, |__this| Conversions::convert( - __this, - overload::Arg::const_lvalue((*narrow.borrow()).0.as_pointer()) + object!(__first, i64, |__this| ConvertibleTo::convert( + LvalueRef::>::bind((*narrow.borrow()).0.as_pointer()), + __this )); - object!(__second, i64, |__this| Conversions::convert( - __this, - overload::Arg::const_lvalue((*narrow.borrow()).1.as_pointer()) + object!(__second, i64, |__this| ConvertibleTo::convert( + LvalueRef::>::bind((*narrow.borrow()).1.as_pointer()), + __this )); MoveAssignable::move_assign( (*w.borrow()).0.as_pointer(), @@ -177,13 +177,13 @@ fn main_0() -> i32 { Rc::new(RefCell::new(6)), ))); { - object!(__first, i64, |__this| Conversions::convert( - __this, - overload::Arg::rvalue((*m.borrow()).0.as_pointer()) + object!(__first, i64, |__this| ConvertibleTo::convert( + RvalueRef::::bind((*m.borrow()).0.as_pointer()), + __this )); - object!(__second, i64, |__this| Conversions::convert( - __this, - overload::Arg::rvalue((*m.borrow()).1.as_pointer()) + object!(__second, i64, |__this| ConvertibleTo::convert( + RvalueRef::::bind((*m.borrow()).1.as_pointer()), + __this )); MoveAssignable::move_assign( (*w.borrow()).0.as_pointer(), @@ -216,13 +216,13 @@ fn main_0() -> i32 { .borrow_mut()) = 8; assert!(({ ((*(*d.borrow()).0.borrow()) == 8) && ((*(*d.borrow()).1.borrow()) == 4) })); (*(*{ - object!(__first, i64, |__this| Conversions::convert( - __this, - overload::Arg::const_lvalue((*narrow.borrow()).0.as_pointer()) + object!(__first, i64, |__this| ConvertibleTo::convert( + LvalueRef::>::bind((*narrow.borrow()).0.as_pointer()), + __this )); - object!(__second, i64, |__this| Conversions::convert( - __this, - overload::Arg::const_lvalue((*narrow.borrow()).1.as_pointer()) + object!(__second, i64, |__this| ConvertibleTo::convert( + LvalueRef::>::bind((*narrow.borrow()).1.as_pointer()), + __this )); MoveAssignable::move_assign( (*w.borrow()).0.as_pointer(), @@ -240,13 +240,13 @@ fn main_0() -> i32 { .borrow_mut()) = 9_i64; assert!(({ ((*(*w.borrow()).0.borrow()) == 3_i64) && ((*(*w.borrow()).1.borrow()) == 9_i64) })); (*(*{ - object!(__first, i64, |__this| Conversions::convert( - __this, - overload::Arg::rvalue((*narrow.borrow()).0.as_pointer()) + object!(__first, i64, |__this| ConvertibleTo::convert( + RvalueRef::::bind((*narrow.borrow()).0.as_pointer()), + __this )); - object!(__second, i64, |__this| Conversions::convert( - __this, - overload::Arg::rvalue((*narrow.borrow()).1.as_pointer()) + object!(__second, i64, |__this| ConvertibleTo::convert( + RvalueRef::::bind((*narrow.borrow()).1.as_pointer()), + __this )); MoveAssignable::move_assign( (*w.borrow()).0.as_pointer(), diff --git a/tests/unit/out/refcount/pair_converting_construction.rs b/tests/unit/out/refcount/pair_converting_construction.rs index 8a4d8e70ca..f74fa68341 100644 --- a/tests/unit/out/refcount/pair_converting_construction.rs +++ b/tests/unit/out/refcount/pair_converting_construction.rs @@ -20,18 +20,17 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct Celsius { #[offset(0)] pub degrees: i32, } -impl ConstructibleFrom<(i32,)> for Celsius { - fn constructor(this: Ptr, (mut d,): (i32,)) { +impl Celsius { + pub fn constructor_1(this: Ptr, mut d: i32) { field!(this, degrees).write(d); } } -impl ConvertibleTo for i32 {} #[derive( Copy, Clone, @@ -46,20 +45,19 @@ impl ConvertibleTo for i32 {} Conversions, )] #[conversions(copy, move)] -#[conversion_function(i32, const_lvalue_ref)] +#[conversion_function(conversion_function_1, i32, const_lvalue_ref)] #[byte_size(4)] pub struct Meters { #[offset(0)] pub value: i32, } -impl ConversionFunction>> for Meters { - fn conversion_function(this: LvalueRef>, to: Ptr) { +impl Meters { + pub fn conversion_function_1(this: LvalueRef>, __return: Ptr) { let this = this.as_pointer(); - to.write(this.with(|__s| __s.value)); + __return.write(this.with(|__s| __s.value)); return; } } -impl ImplicitConversionFunction>> for Meters {} #[derive( Copy, Clone, @@ -74,19 +72,18 @@ impl ImplicitConversionFunction>> for Meters {} Conversions, )] #[conversions(copy, move)] -#[constructor(const_lvalue_ref(Celsius))] +#[constructor(constructor_1, const_lvalue_ref(Celsius))] #[byte_size(4)] pub struct Label { #[offset(0)] pub id: i32, } -impl ConstructibleFrom<(LvalueRef>,)> for Label { - fn constructor(this: Ptr, (c,): (LvalueRef>,)) { +impl Label { + pub fn constructor_1(this: Ptr, c: LvalueRef>) { let c = c.as_pointer(); field!(this, id).write(c.with(|__s| __s.degrees)); } } -impl ConvertibleTo for i32 {} impl Default for A { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + A::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -57,14 +54,14 @@ impl Default for A { TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct B { #[offset(0)] pub v: i32, } -impl ConstructibleFrom<()> for B { - fn constructor(this: Ptr, _: ()) { +impl B { + pub fn constructor_1(this: Ptr) { field!(this, v).write(2); } } @@ -72,8 +69,8 @@ impl Default for B { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + B::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -93,18 +90,17 @@ impl Default for B { Conversions, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct NoDefault { #[offset(0)] pub v: i32, } -impl ConstructibleFrom<(i32,)> for NoDefault { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl NoDefault { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } } -impl ConvertibleTo for i32 {} pub fn used_0(mut x: A) -> i32 { return x.v; } @@ -131,23 +127,20 @@ pub fn always_given_3(mut x: NoDefault) -> i32 { Conversions, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct S_NoDefault_ { #[offset(0)] pub v: i32, } impl S_NoDefault_ { + pub fn constructor_1(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } pub fn get(this: Ptr, mut t: NoDefault) -> i32 { return (this.with(|__s| __s.v) + t.v); } } -impl ConstructibleFrom<(i32,)> for S_NoDefault_ { - fn constructor(this: Ptr, (mut v,): (i32,)) { - field!(this, v).write(v); - } -} -impl ConvertibleTo for i32 {} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -156,8 +149,8 @@ fn main_0() -> i32 { assert!( (({ used_0({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + A::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 1) @@ -165,8 +158,8 @@ fn main_0() -> i32 { assert!( (({ used_0({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (5,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + A::constructor_2(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 5) @@ -174,8 +167,8 @@ fn main_0() -> i32 { assert!( (({ used_1({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), ()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + B::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 2) @@ -184,8 +177,8 @@ fn main_0() -> i32 { (({ scaled_2( { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (3,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + A::constructor_2(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, (4usize as i32), @@ -196,8 +189,8 @@ fn main_0() -> i32 { (({ scaled_2( { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (3,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + A::constructor_2(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, 2, @@ -207,18 +200,18 @@ fn main_0() -> i32 { assert!( (({ always_given_3({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (3,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + NoDefault::constructor_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 3) ); - object!(s, S_NoDefault_, (i32,), (1,)); + object!(s, S_NoDefault_::constructor_1(1)); assert!( (({ S_NoDefault_::get(s.as_pointer(), { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (4,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + NoDefault::constructor_1(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 5) diff --git a/tests/unit/out/refcount/temporary_field_addr.rs b/tests/unit/out/refcount/temporary_field_addr.rs index bea75e7cc8..e3df798c3b 100644 --- a/tests/unit/out/refcount/temporary_field_addr.rs +++ b/tests/unit/out/refcount/temporary_field_addr.rs @@ -21,15 +21,15 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(24)] pub struct Inner { #[offset(0)] #[byte_size(24)] pub values: Vec, } -impl ConstructibleFrom<()> for Inner { - fn constructor(this: Ptr, _: ()) { +impl Inner { + pub fn constructor_1(this: Ptr) { field!(this, values).write(Vec::new()); } } @@ -47,7 +47,7 @@ impl ConstructibleFrom<()> for Inner { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(56)] pub struct Outer { #[offset(0)] @@ -61,10 +61,10 @@ pub struct Outer { #[array_len(8)] pub name: Box<[i8]>, } -impl ConstructibleFrom<()> for Outer { - fn constructor(this: Ptr, _: ()) { +impl Outer { + pub fn constructor_1(this: Ptr) { field!(this, values).write(Vec::new()); - >::constructor(field_ptr!(this, inner), ()); + Inner::constructor_1(field_ptr!(this, inner)); field!(this, name).write((0..8).map(|_| 0_i8).collect::>()); } } @@ -107,7 +107,7 @@ pub fn main() { fn main_0() -> i32 { let calls: Value = Rc::new(RefCell::new(0)); let mut member: i32 = { - let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ sum_1( (match { @@ -120,7 +120,7 @@ fn main_0() -> i32 { }) }; let mut nested: i32 = { - let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_3: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ sum_1( (match { @@ -133,7 +133,7 @@ fn main_0() -> i32 { }) }; let mut element: i32 = { - let __tmp_6: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_6: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); (match ( (match { ({ make_0(Ptr::clone(&__tmp_6.as_pointer()), calls.as_pointer()) }); @@ -153,7 +153,7 @@ fn main_0() -> i32 { .read()) }; let mut length: usize = { - let __tmp_9: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_9: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); (match { ({ make_0(Ptr::clone(&__tmp_9.as_pointer()), calls.as_pointer()) }); __tmp_9.as_pointer() diff --git a/tests/unit/out/refcount/temporary_field_ctor_arg.rs b/tests/unit/out/refcount/temporary_field_ctor_arg.rs index 05cd87b16a..9aedfed164 100644 --- a/tests/unit/out/refcount/temporary_field_ctor_arg.rs +++ b/tests/unit/out/refcount/temporary_field_ctor_arg.rs @@ -21,15 +21,15 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(24)] pub struct Outer { #[offset(0)] #[byte_size(24)] pub values: Vec, } -impl ConstructibleFrom<()> for Outer { - fn constructor(this: Ptr, _: ()) { +impl Outer { + pub fn constructor_1(this: Ptr) { field!(this, values).write(Vec::new()); } } @@ -58,30 +58,29 @@ pub struct H { #[offset(0)] pub last: i32, } -impl ConstructibleFrom<(LvalueRef>>,)> for H { - fn constructor(this: Ptr, (values,): (LvalueRef>>,)) { +impl H { + pub fn constructor_1(this: Ptr, values: LvalueRef>>) { let values = values.as_pointer(); field!(this, last).write((index!(values, 3_usize).read())); } } -impl ConvertibleTo for LvalueRef>> {} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { object!(h, H, |h| { - let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); - >>,)>>::constructor( + let __tmp_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + H::constructor_1( h.clone(), - (LvalueRef::bind( + LvalueRef::bind( (match { ({ make_0(Ptr::clone(&__tmp_1.as_pointer())) }); __tmp_1.as_pointer() } { __tmp_0 => field_ref!(__tmp_0, values).as_pointer(), }), - ),), + ), ) }); printf!(b"%d\n", { (*h.borrow()).last }); diff --git a/tests/unit/out/refcount/temporary_field_two_args.rs b/tests/unit/out/refcount/temporary_field_two_args.rs index ab7ef19c10..e06491813d 100644 --- a/tests/unit/out/refcount/temporary_field_two_args.rs +++ b/tests/unit/out/refcount/temporary_field_two_args.rs @@ -21,15 +21,15 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(24)] pub struct Inner { #[offset(0)] #[byte_size(24)] pub values: Vec, } -impl ConstructibleFrom<()> for Inner { - fn constructor(this: Ptr, _: ()) { +impl Inner { + pub fn constructor_1(this: Ptr) { field!(this, values).write(Vec::new()); } } @@ -48,7 +48,7 @@ impl ConstructibleFrom<()> for Inner { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(48)] pub struct Outer { #[offset(0)] @@ -58,10 +58,10 @@ pub struct Outer { #[byte_size(24)] pub inner: Inner, } -impl ConstructibleFrom<()> for Outer { - fn constructor(this: Ptr, _: ()) { +impl Outer { + pub fn constructor_1(this: Ptr) { field!(this, values).write(Vec::new()); - >::constructor(field_ptr!(this, inner), ()); + Inner::constructor_1(field_ptr!(this, inner)); } } pub fn make_0(__return: Ptr) { @@ -82,8 +82,8 @@ pub fn main() { } fn main_0() -> i32 { { - let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); - let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + let __tmp_3: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); printf!( b"%d\n", ({ diff --git a/tests/unit/out/refcount/this.rs b/tests/unit/out/refcount/this.rs index 7ebd69780d..e4f7edde5b 100644 --- a/tests/unit/out/refcount/this.rs +++ b/tests/unit/out/refcount/this.rs @@ -19,8 +19,9 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(value(i32))] -#[constructor(value(i32 ), value(Ptr< S > ))] +#[constructor(constructor_1, value(i32))] +#[constructor(constructor_2, value(i32 ), value(Ptr< S > ))] +#[constructor(constructor_3, value(i32 ), value(Ptr< S > ))] #[byte_size(16)] pub struct S { #[offset(0)] @@ -30,7 +31,20 @@ pub struct S { pub self__: Ptr, } impl S { - pub fn construct_1(this: Ptr, mut a: i32, mut other: Ptr) { + pub fn constructor_1(this: Ptr, mut a: i32) { + field!(this, a_).write(a); + field!(this, self__).write(Ptr::::null()); + } + pub fn constructor_2(this: Ptr, mut a: i32, mut other: Ptr) { + field!(this, a_).write(a); + field!(this, self__).write(Ptr::::null()); + if (this == other) { + field!(this, self__).write(Ptr::::null()); + } else { + field!(this, self__).write((other).clone()); + } + } + pub fn constructor_3(this: Ptr, mut a: i32, mut other: Ptr) { field!(this, a_).write(a); field!(this, self__).write(Ptr::::null()); if (this == other) { @@ -73,8 +87,8 @@ impl S { } pub fn reset(this: Ptr) { let __rhs = { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (0,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + S::constructor_1(__v.as_pointer(), 0); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; this.write(__rhs); @@ -96,24 +110,6 @@ impl S { return true; } } -impl ConstructibleFrom<(i32,)> for S { - fn constructor(this: Ptr, (mut a,): (i32,)) { - field!(this, a_).write(a); - field!(this, self__).write(Ptr::::null()); - } -} -impl ConvertibleTo for i32 {} -impl ConstructibleFrom<(i32, Ptr)> for S { - fn constructor(this: Ptr, (mut a, mut other): (i32, Ptr)) { - field!(this, a_).write(a); - field!(this, self__).write(Ptr::::null()); - if (this == other) { - field!(this, self__).write(Ptr::::null()); - } else { - field!(this, self__).write((other).clone()); - } - } -} pub fn bump_0(mut p: Ptr) { field!(p, a_).with_mut(|__v| __v.postfix_inc()); } @@ -131,27 +127,26 @@ pub fn bump_0(mut p: Ptr) { Conversions, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct D { #[offset(0)] pub a_: i32, } -impl ConstructibleFrom<(i32,)> for D { - fn constructor(this: Ptr, (mut a,): (i32,)) { +impl D { + pub fn constructor_1(this: Ptr, mut a: i32) { field!(this, a_).write(a); { field!(this, a_).with_mut(|__v| *__v = *__v * 2) }; } } -impl ConvertibleTo for i32 {} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(s, S, (i32,), (1,)); + object!(s, S::constructor_1(1)); let ref_: Ptr = ({ S::returns_this_reference(s.as_pointer()) }); field!(ref_, a_).with_mut(|__v| __v.postfix_inc()); assert!(({ (*s.borrow()).a_ } == 2)); @@ -169,16 +164,16 @@ fn main_0() -> i32 { assert!(({ (*s.borrow()).a_ } == 8)); ({ S::bump_me(s.as_pointer()) }); assert!(({ (*s.borrow()).a_ } == 9)); - object!(d, D, (i32,), (3,)); + object!(d, D::constructor_1(3)); assert!(({ (*d.borrow()).a_ } == 6)); let cr: Ptr = ({ S::cref(s.as_pointer()) }); assert!((cr.with(|__s| __s.a_) == 9)); - object!(t, S, (i32,), (0,)); + object!(t, S::constructor_1(0)); assert!(({ S::is(s.as_pointer(), (s.as_pointer()),) })); assert!(!({ S::is(s.as_pointer(), (t.as_pointer()),) })); let mut p: Ptr = { let __p = Ptr::alloc(::zero_init()); - >::constructor(__p.clone(), (1,)); + S::constructor_1(__p.clone(), 1); __p }; let mut q: Ptr = ({ S::returns_this_pointer((p).clone()) }); @@ -187,7 +182,7 @@ fn main_0() -> i32 { p.delete(); let mut h: Ptr = { let __p = Ptr::alloc(::zero_init()); - >::constructor(__p.clone(), (5,)); + S::constructor_1(__p.clone(), 5); __p }; ({ S::destroy((h).clone()) }); @@ -201,21 +196,21 @@ fn main_0() -> i32 { ((({ S::copy_if_different_const(s.as_pointer(), (s.as_pointer()),) }) as i32) == (false as i32)) ); - object!(other, S, (i32,), (22,)); + object!(other, S::constructor_1(22)); assert!( ((({ S::copy_if_different(s.as_pointer(), (other.as_pointer()),) }) as i32) == (true as i32)) ); assert!(({ (*s.borrow()).a_ } == { (*other.borrow()).a_ })); assert!(({ { (*s.borrow()).self__.clone() } } == { { (*other.borrow()).self__.clone() } })); - object!(u, S, (i32, Ptr,), (1, (s.as_pointer()),)); + object!(u, S::constructor_2(1, (s.as_pointer()))); assert!(({ { (*u.borrow()).self__.clone() } } == { (s.as_pointer()) })); let s_const: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - >::constructor(__v.as_pointer(), (100,)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + S::constructor_1(__v.as_pointer(), 100); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - object!(u1, S::construct_1(1, (s_const.as_pointer()))); + object!(u1, S::constructor_3(1, (s_const.as_pointer()))); assert!(({ (*u1.borrow()).self__.clone() }).is_null()); return 0; } diff --git a/tests/unit/out/refcount/typedef-anon-struct.rs b/tests/unit/out/refcount/typedef-anon-struct.rs index 830d71c560..dabd578909 100644 --- a/tests/unit/out/refcount/typedef-anon-struct.rs +++ b/tests/unit/out/refcount/typedef-anon-struct.rs @@ -42,15 +42,15 @@ pub struct Outer_RunInfo { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(24)] pub struct Outer { #[offset(0)] #[byte_size(24)] pub runs: Vec, } -impl ConstructibleFrom<()> for Outer { - fn constructor(this: Ptr, _: ()) { +impl Outer { + pub fn constructor_1(this: Ptr) { field!(this, runs).write(Vec::new()); } } @@ -59,7 +59,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(o, Outer); + object!(o, Outer::constructor_1()); let info: Value = Rc::new(RefCell::new(::default())); (*info.borrow_mut()).block_idx = 1; (*info.borrow_mut()).num_extra_zero_runs = 2; diff --git a/tests/unit/out/refcount/unboxed_records.rs b/tests/unit/out/refcount/unboxed_records.rs index b97162d692..8e2706935c 100644 --- a/tests/unit/out/refcount/unboxed_records.rs +++ b/tests/unit/out/refcount/unboxed_records.rs @@ -81,7 +81,7 @@ impl Default for Cookie { TriviallyCopyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(4)] pub struct Counter { #[offset(0)] @@ -93,9 +93,7 @@ impl Counter { __v.prefix_inc(); }); } -} -impl ConstructibleFrom<()> for Counter { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, n).write(0); } } @@ -163,7 +161,7 @@ fn main_0() -> i32 { let field_addr: Value = Rc::new(RefCell::new(Inner { a: 0, b: 0 })); ({ set_0((field_ptr!(field_addr.as_pointer(), b)), 7) }); assert!(({ (*field_addr.borrow()).b } == 7)); - object!(counter, Counter); + object!(counter, Counter::constructor_1()); ({ Counter::inc(counter.as_pointer()) }); assert!(({ (*counter.borrow()).n } == 1)); return 0; diff --git a/tests/unit/out/refcount/unique_ptr.rs b/tests/unit/out/refcount/unique_ptr.rs index 865f8799e8..68bdac327f 100644 --- a/tests/unit/out/refcount/unique_ptr.rs +++ b/tests/unit/out/refcount/unique_ptr.rs @@ -11,7 +11,7 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] #[byte_size(8)] pub struct SafePointer { #[offset(0)] @@ -26,9 +26,7 @@ impl SafePointer { __v.prefix_inc(); }); } -} -impl ConstructibleFrom<()> for SafePointer { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, ptr).write(None); } } diff --git a/tests/unit/out/refcount/unique_ptr_const_deref.rs b/tests/unit/out/refcount/unique_ptr_const_deref.rs index 1dcbfa5971..066249966a 100644 --- a/tests/unit/out/refcount/unique_ptr_const_deref.rs +++ b/tests/unit/out/refcount/unique_ptr_const_deref.rs @@ -11,15 +11,15 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] #[byte_size(8)] pub struct Holder { #[offset(0)] #[byte_size(8)] pub val: Option>, } -impl ConstructibleFrom<()> for Holder { - fn constructor(this: Ptr, _: ()) { +impl Holder { + pub fn constructor_1(this: Ptr) { field!(this, val).write(None); } } @@ -34,7 +34,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(h, Holder); + object!(h, Holder::constructor_1()); { (*h.borrow_mut()).val = Some(Rc::new(RefCell::new(10))).take(); }; diff --git a/tests/unit/out/refcount/unique_ptr_field_reset.rs b/tests/unit/out/refcount/unique_ptr_field_reset.rs index 9d225c0392..521176b82e 100644 --- a/tests/unit/out/refcount/unique_ptr_field_reset.rs +++ b/tests/unit/out/refcount/unique_ptr_field_reset.rs @@ -30,7 +30,7 @@ pub struct Data { )] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] #[byte_size(16)] pub struct Holder { #[offset(0)] @@ -43,9 +43,7 @@ impl Holder { pub fn set(this: Ptr, mut p: Ptr) { field_ptr!(this, data).write(p.to_owned_opt()); } -} -impl ConstructibleFrom<()> for Holder { - fn constructor(this: Ptr, _: ()) { + pub fn constructor_1(this: Ptr) { field!(this, data).write(None); field!(this, n).write(0_i32); } @@ -66,7 +64,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(h, Holder); + object!(h, Holder::constructor_1()); (*h.borrow_mut()).n = 1; let mut hp: Ptr = (h.as_pointer()); field_ptr!(hp, data).write(Ptr::alloc(Data { v: 3 }).to_owned_opt()); diff --git a/tests/unit/out/refcount/unique_ptr_nested.rs b/tests/unit/out/refcount/unique_ptr_nested.rs index 88abfdec3f..e9b49614d3 100644 --- a/tests/unit/out/refcount/unique_ptr_nested.rs +++ b/tests/unit/out/refcount/unique_ptr_nested.rs @@ -32,15 +32,15 @@ pub struct Inner { )] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] #[byte_size(8)] pub struct Outer { #[offset(0)] #[byte_size(8)] pub inner: Option>, } -impl ConstructibleFrom<()> for Outer { - fn constructor(this: Ptr, _: ()) { +impl Outer { + pub fn constructor_1(this: Ptr) { field!(this, inner).write(None); } } diff --git a/tests/unit/out/refcount/va_list_field.rs b/tests/unit/out/refcount/va_list_field.rs index c118c9359e..d13473d766 100644 --- a/tests/unit/out/refcount/va_list_field.rs +++ b/tests/unit/out/refcount/va_list_field.rs @@ -11,7 +11,7 @@ pub fn sum_0(n: i32, __args: Box<[VaArg]>) -> i32 { let n: Value = Rc::new(RefCell::new(n)); let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); (*ap.borrow_mut()) = __args.decay(); - object!(guard, Guard_1, (Ptr>,), (ap.as_pointer(),)); + object!(guard, Guard_1::constructor_1(ap.as_pointer())); let mut total: i32 = 0; { let mut i: i32 = 0; @@ -35,7 +35,7 @@ pub fn sum_0(n: i32, __args: Box<[VaArg]>) -> i32 { Copyable, Conversions, )] -#[conversions(copy)] +#[conversions(copy, move)] #[byte_size(16)] pub struct Guard_1 { #[offset(0)] @@ -44,13 +44,12 @@ pub struct Guard_1 { #[offset(8)] pub active: bool, } -impl ConstructibleFrom<(Ptr>,)> for Guard_1 { - fn constructor(this: Ptr, (val,): (Ptr>,)) { +impl Guard_1 { + pub fn constructor_1(this: Ptr, val: Ptr>) { field!(this, ap).write((val).clone()); field!(this, active).write(true); } } -impl ConvertibleTo for Ptr> {} impl Destructible for Guard_1 { fn destroy(this: Ptr) { if this.with(|__s| __s.active) {} diff --git a/tests/unit/out/refcount/vector.rs b/tests/unit/out/refcount/vector.rs index 0b9872e5f4..ea59b7709f 100644 --- a/tests/unit/out/refcount/vector.rs +++ b/tests/unit/out/refcount/vector.rs @@ -41,7 +41,7 @@ pub fn copy_0(mut copy_vector: Vec) {} )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(48)] pub struct Foo { #[offset(0)] @@ -51,8 +51,8 @@ pub struct Foo { #[byte_size(24)] pub b: Vec, } -impl ConstructibleFrom<()> for Foo { - fn constructor(this: Ptr, _: ()) { +impl Foo { + pub fn constructor_1(this: Ptr) { field!(this, a).write(Vec::new()); field!(this, b).write(Vec::new()); } @@ -71,18 +71,17 @@ impl ConstructibleFrom<()> for Foo { Conversions, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct Wrapped { #[offset(0)] pub v: i32, } -impl ConstructibleFrom<(i32,)> for Wrapped { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl Wrapped { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } } -impl ConvertibleTo for i32 {} pub fn exchange_1(x: Ptr>, y: Ptr>) { x.swap_with(&(y).clone(), |__v| __v.with_mut(std::mem::take)); } @@ -195,9 +194,9 @@ fn main_0() -> i32 { while >::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = temp_vec.borrow().len(); temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( temp_vec.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } @@ -558,7 +557,7 @@ fn main_0() -> i32 { && ({ (*v11.borrow())[2_usize] } == 3) }) ); - object!(foo, Foo); + object!(foo, Foo::constructor_1()); ({ let __tmp_22: Value = Rc::new(RefCell::new(5)); MoveConstructible::push_moved( @@ -709,9 +708,9 @@ fn main_0() -> i32 { while >::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = temp_vec.borrow().len(); temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( temp_vec.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } @@ -743,9 +742,9 @@ fn main_0() -> i32 { while >::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = temp_vec.borrow().len(); temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( temp_vec.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } @@ -770,9 +769,9 @@ fn main_0() -> i32 { while >::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = temp_vec.borrow().len(); temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( temp_vec.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } @@ -800,9 +799,9 @@ fn main_0() -> i32 { while >::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = temp_vec.borrow().len(); temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( temp_vec.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } @@ -832,9 +831,9 @@ fn main_0() -> i32 { while >::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = temp_vec.borrow().len(); temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( temp_vec.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } diff --git a/tests/unit/out/refcount/vector_insert_conversion_chain.rs b/tests/unit/out/refcount/vector_insert_conversion_chain.rs index e72776ea32..6555612412 100644 --- a/tests/unit/out/refcount/vector_insert_conversion_chain.rs +++ b/tests/unit/out/refcount/vector_insert_conversion_chain.rs @@ -20,20 +20,19 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[conversion_function(i32, const_lvalue_ref)] +#[conversion_function(conversion_function_1, i32, const_lvalue_ref)] #[byte_size(4)] pub struct Ratio { #[offset(0)] pub num: i32, } -impl ConversionFunction>> for Ratio { - fn conversion_function(this: LvalueRef>, to: Ptr) { +impl Ratio { + pub fn conversion_function_1(this: LvalueRef>, __return: Ptr) { let this = this.as_pointer(); - to.write(this.with(|__s| __s.num)); + __return.write(this.with(|__s| __s.num)); return; } } -impl ImplicitConversionFunction>> for Ratio {} #[derive( Copy, Clone, @@ -48,29 +47,25 @@ impl ImplicitConversionFunction>> for Ratio {} Conversions, )] #[conversions(copy, move)] -#[conversion_function(i16, const_lvalue_ref)] -#[conversion_function(i64, const_lvalue_ref)] +#[conversion_function(conversion_function_1, i16, const_lvalue_ref)] +#[conversion_function(conversion_function_2, i64, const_lvalue_ref)] #[byte_size(4)] pub struct Level { #[offset(0)] pub raw_: i32, } -impl ConversionFunction>> for Level { - fn conversion_function(this: LvalueRef>, to: Ptr) { +impl Level { + pub fn conversion_function_1(this: LvalueRef>, __return: Ptr) { let this = this.as_pointer(); - to.write((this.with(|__s| __s.raw_) as i16)); + __return.write((this.with(|__s| __s.raw_) as i16)); return; } -} -impl ImplicitConversionFunction>> for Level {} -impl ConversionFunction>> for Level { - fn conversion_function(this: LvalueRef>, to: Ptr) { + pub fn conversion_function_2(this: LvalueRef>, __return: Ptr) { let this = this.as_pointer(); - to.write(((this.with(|__s| __s.raw_) as i64) * 100_i64)); + __return.write(((this.with(|__s| __s.raw_) as i64) * 100_i64)); return; } } -impl ImplicitConversionFunction>> for Level {} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -88,9 +83,9 @@ fn main_0() -> i32 { while >::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = temp_vec.borrow().len(); temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( temp_vec.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } @@ -117,9 +112,9 @@ fn main_0() -> i32 { while >::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = temp_vec.borrow().len(); temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( temp_vec.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } diff --git a/tests/unit/out/refcount/vector_iter_range_ctor.rs b/tests/unit/out/refcount/vector_iter_range_ctor.rs index ca36cb5553..fd85fab4c4 100644 --- a/tests/unit/out/refcount/vector_iter_range_ctor.rs +++ b/tests/unit/out/refcount/vector_iter_range_ctor.rs @@ -20,18 +20,17 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] #[byte_size(4)] pub struct Degrees { #[offset(0)] pub value: i32, } -impl ConstructibleFrom<(i32,)> for Degrees { - fn constructor(this: Ptr, (mut v,): (i32,)) { +impl Degrees { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, value).write(v); } } -impl ConvertibleTo for i32 {} #[derive( Copy, Clone, @@ -46,20 +45,19 @@ impl ConvertibleTo for i32 {} Conversions, )] #[conversions(copy, move)] -#[conversion_function(i64, const_lvalue_ref)] +#[conversion_function(conversion_function_1, i64, const_lvalue_ref)] #[byte_size(4)] pub struct Reading { #[offset(0)] pub raw_: i32, } -impl ConversionFunction>> for Reading { - fn conversion_function(this: LvalueRef>, to: Ptr) { +impl Reading { + pub fn conversion_function_1(this: LvalueRef>, __return: Ptr) { let this = this.as_pointer(); - to.write(((this.with(|__s| __s.raw_) as i64) * 10_i64)); + __return.write(((this.with(|__s| __s.raw_) as i64) * 10_i64)); return; } } -impl ImplicitConversionFunction>> for Reading {} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -73,9 +71,9 @@ fn main_0() -> i32 { while >::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( __v.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } @@ -90,9 +88,9 @@ fn main_0() -> i32 { while >::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( __v.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } @@ -107,9 +105,9 @@ fn main_0() -> i32 { while >::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( __v.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } @@ -125,9 +123,9 @@ fn main_0() -> i32 { while >::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( __v.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } @@ -149,9 +147,9 @@ fn main_0() -> i32 { while >::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( __v.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } @@ -194,9 +192,11 @@ fn main_0() -> i32 { ) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( __v.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::, Value)>>::bind( + __it.borrow().iter_deref(), + ),), ); __it.borrow_mut().iter_inc(); } @@ -237,9 +237,11 @@ fn main_0() -> i32 { ) { let __i = temp_vec.borrow().len(); temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( temp_vec.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::, Value)>>::bind( + __it.borrow().iter_deref(), + ),), ); __it.borrow_mut().iter_inc(); } @@ -268,9 +270,9 @@ fn main_0() -> i32 { while >::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( __v.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } @@ -289,9 +291,11 @@ fn main_0() -> i32 { while >::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( __v.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind( + __it.borrow().iter_deref(), + ),), ); __it.borrow_mut().iter_inc(); } diff --git a/tests/unit/out/refcount/vector_subscript_direct.rs b/tests/unit/out/refcount/vector_subscript_direct.rs index 3911966b74..8315f3319e 100644 --- a/tests/unit/out/refcount/vector_subscript_direct.rs +++ b/tests/unit/out/refcount/vector_subscript_direct.rs @@ -47,7 +47,7 @@ impl Point { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(48)] pub struct Holder { #[offset(0)] @@ -57,8 +57,8 @@ pub struct Holder { #[byte_size(24)] pub points: Vec, } -impl ConstructibleFrom<()> for Holder { - fn constructor(this: Ptr, _: ()) { +impl Holder { + pub fn constructor_1(this: Ptr) { field!(this, values).write(Vec::new()); field!(this, points).write(Vec::new()); } @@ -119,7 +119,7 @@ fn main_0() -> i32 { p.write(9); assert!(({ (*v.borrow())[2_usize] } == 9)); assert!((({ sum_ref_1(v.as_pointer(),) }) == ((((3 + 0) + 9) + 42) + 5))); - object!(h, Holder); + object!(h, Holder::constructor_1()); (*h.borrow_mut()).values.resize_with(2_usize, || 0_i32); vec_elem!(h.as_pointer(), values, 1_usize).write(6); ({ diff --git a/tests/unit/out/refcount/vector_with_allocator.rs b/tests/unit/out/refcount/vector_with_allocator.rs index e700d8eb50..a3c027a626 100644 --- a/tests/unit/out/refcount/vector_with_allocator.rs +++ b/tests/unit/out/refcount/vector_with_allocator.rs @@ -408,9 +408,9 @@ fn main_0() -> i32 { while >::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( __v.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } @@ -425,9 +425,9 @@ fn main_0() -> i32 { while >::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( __v.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } @@ -442,9 +442,9 @@ fn main_0() -> i32 { while >::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( __v.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } @@ -460,9 +460,9 @@ fn main_0() -> i32 { while >::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( __v.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } @@ -481,9 +481,9 @@ fn main_0() -> i32 { while >::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct( + ConstructibleFrom::construct( __v.as_pointer().decay().offset(__i), - &[overload::Arg::const_lvalue(__it.borrow().iter_deref())], + (LvalueRef::>::bind(__it.borrow().iter_deref()),), ); __it.borrow_mut().iter_inc(); } diff --git a/tests/unit/out/refcount/void_cast.rs b/tests/unit/out/refcount/void_cast.rs index 17a13b6e37..853f4871d1 100644 --- a/tests/unit/out/refcount/void_cast.rs +++ b/tests/unit/out/refcount/void_cast.rs @@ -22,15 +22,15 @@ pub fn unused_param_0(mut x: i32) {} )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] #[byte_size(24)] pub struct NonTrivial { #[offset(0)] #[byte_size(24)] pub data: Vec, } -impl ConstructibleFrom<()> for NonTrivial { - fn constructor(this: Ptr, _: ()) { +impl NonTrivial { + pub fn constructor_1(this: Ptr) { field!(this, data).write(Vec::new()); } } @@ -67,15 +67,15 @@ pub struct Holder { )] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] #[byte_size(8)] pub struct NonCopyable { #[offset(0)] #[byte_size(8)] pub value: Option>, } -impl ConstructibleFrom<()> for NonCopyable { - fn constructor(this: Ptr, _: ()) { +impl NonCopyable { + pub fn constructor_1(this: Ptr) { field!(this, value).write(None); } } @@ -127,7 +127,7 @@ fn main_0() -> i32 { let mut arr: [i32; 3] = [1, 2, 3]; let h: Value = Rc::new(RefCell::new(Holder { field: 17 })); let mut hp: Ptr = (h.as_pointer()); - object!(nt, NonTrivial); + object!(nt, NonTrivial::constructor_1()); ({ unused_ref_param_1(nt.as_pointer()) }); ({ unused_ptr_param_2((nt.as_pointer())) }); let g: Value = Rc::new(RefCell::new(NonCopyable { diff --git a/tests/unit/out/unsafe/10_struct.rs b/tests/unit/out/unsafe/10_struct.rs index 66c1af076c..9bb92fad99 100644 --- a/tests/unit/out/unsafe/10_struct.rs +++ b/tests/unit/out/unsafe/10_struct.rs @@ -62,18 +62,16 @@ impl Graph { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] -#[constructor(explicit, value(*mut i32 ))] +#[conversions(copy, move, default = constructor_1)] +#[constructor(constructor_2, explicit, value(*mut i32 ))] pub struct Partial { pub p: *mut i32, } -impl ConstructibleFromUnsafe<()> for Partial { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Partial { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).p).write(std::ptr::null_mut()); } -} -impl ConstructibleFromUnsafe<(*mut i32,)> for Partial { - unsafe fn constructor(this: *mut Self, (mut q,): (*mut i32,)) { + pub unsafe fn constructor_2(this: *mut Self, mut q: *mut i32) { (&raw mut (*this).p).write(q); } } @@ -100,6 +98,7 @@ impl Default for Partial { )] #[conversions(copy, move)] pub struct Declared {} +impl Declared {} #[repr(C)] #[derive( Copy, @@ -129,11 +128,11 @@ unsafe fn main_0() -> i32 { adj: std::ptr::null_mut(), }; let mut arr: [i32; 3] = [3, 1, 4]; - object_unsafe!(it, Partial, (*mut i32,), (arr.as_mut_ptr(),)); + object_unsafe!(it, Partial::constructor_2(arr.as_mut_ptr())); if ((it.p) != (arr.as_mut_ptr())) { return 1; } - object_unsafe!(def, Partial); + object_unsafe!(def, Partial::constructor_1()); if !((def.p).is_null()) { return 1; } diff --git a/tests/unit/out/unsafe/any.rs b/tests/unit/out/unsafe/any.rs index ec4582334d..9e1fd3a219 100644 --- a/tests/unit/out/unsafe/any.rs +++ b/tests/unit/out/unsafe/any.rs @@ -19,13 +19,13 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(value(i32), value(i32))] +#[constructor(constructor_1, value(i32), value(i32))] pub struct Point { pub x: i32, pub y: i32, } -impl ConstructibleFromUnsafe<(i32, i32)> for Point { - unsafe fn constructor(this: *mut Self, (mut x, mut y): (i32, i32)) { +impl Point { + pub unsafe fn constructor_1(this: *mut Self, mut x: i32, mut y: i32) { (&raw mut (*this).x).write(x); (&raw mut (*this).y).write(y); } @@ -38,8 +38,8 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut a: Option> = Some(Box::new({ - let mut __v: Point = ::zero_init(); - >::constructor(&raw mut __v, (3, 4)); + let mut __v: Point = ZeroInitializationUnsafe::zero_init(); + Point::constructor_1(&raw mut __v, 3, 4); __v })); assert!(a.is_some()); @@ -67,8 +67,8 @@ unsafe fn main_0() -> i32 { ); let q: *mut Point = { a = Some(Box::new({ - let mut __v: Point = ::zero_init(); - >::constructor(&raw mut __v, (5, 6)); + let mut __v: Point = ZeroInitializationUnsafe::zero_init(); + Point::constructor_1(&raw mut __v, 5, 6); __v })); a.as_mut().unwrap().downcast_mut::().unwrap() diff --git a/tests/unit/out/unsafe/array_of_noncopy_struct.rs b/tests/unit/out/unsafe/array_of_noncopy_struct.rs index e8a6e1e800..3ed0fe86b0 100644 --- a/tests/unit/out/unsafe/array_of_noncopy_struct.rs +++ b/tests/unit/out/unsafe/array_of_noncopy_struct.rs @@ -19,13 +19,13 @@ use std::rc::Rc; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct NonCopy { pub data: Vec, pub tag: i32, } -impl ConstructibleFromUnsafe<()> for NonCopy { - unsafe fn constructor(this: *mut Self, _: ()) { +impl NonCopy { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).data).write(Vec::new()); (&raw mut (*this).tag).write(0); } @@ -48,8 +48,8 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut arr: [NonCopy; 3] = std::array::from_fn::<_, 3, _>(|_| { - let mut __v: NonCopy = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: NonCopy = ZeroInitializationUnsafe::zero_init(); + NonCopy::constructor_1(&raw mut __v); __v }); arr[(0) as usize].tag = 7; diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index c2e1cd2dda..86c5e2fd3a 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -2163,12 +2163,12 @@ pub unsafe fn test_stable_containers_58() { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Counts_59 { pub counts: Vec, } -impl ConstructibleFromUnsafe<()> for Counts_59 { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Counts_59 { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).counts).write(Vec::new()); } } diff --git a/tests/unit/out/unsafe/cast.rs b/tests/unit/out/unsafe/cast.rs index ca80b09715..5773b18117 100644 --- a/tests/unit/out/unsafe/cast.rs +++ b/tests/unit/out/unsafe/cast.rs @@ -75,13 +75,13 @@ pub struct Grid { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Bag { pub n: i32, pub items: Vec, } -impl ConstructibleFromUnsafe<()> for Bag { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Bag { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).n).write(0_i32); (&raw mut (*this).items).write(Vec::new()); } @@ -318,7 +318,7 @@ pub unsafe fn nested_5() { assert!(((m[(1) as usize][(1) as usize]) == (42))); assert!(((pm) == (&mut m[(1) as usize][(1) as usize] as *mut i32))); assert!(((pm) < (&mut m[(2) as usize][(0) as usize] as *mut i32))); - object_unsafe!(b, Bag); + object_unsafe!(b, Bag::constructor_1()); if 4_usize > b.items.capacity() as usize { let len_0 = b.items.len(); b.items.reserve_exact(4_usize - len_0 as usize); diff --git a/tests/unit/out/unsafe/class_templates.rs b/tests/unit/out/unsafe/class_templates.rs index 22a6bad8d1..3df9db857c 100644 --- a/tests/unit/out/unsafe/class_templates.rs +++ b/tests/unit/out/unsafe/class_templates.rs @@ -20,7 +20,7 @@ use std::rc::Rc; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct MyContainer_int_ { vec_: Vec, } @@ -44,9 +44,7 @@ impl MyContainer_int_ { pub unsafe fn push_back(this: *mut Self, item: *const i32) { (*this).vec_.push_copied(item); } -} -impl ConstructibleFromUnsafe<()> for MyContainer_int_ { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).vec_).write(Vec::new()); } } @@ -64,7 +62,7 @@ impl ConstructibleFromUnsafe<()> for MyContainer_int_ { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct MyContainer_char_ { vec_: Vec, } @@ -88,9 +86,7 @@ impl MyContainer_char_ { pub unsafe fn push_back(this: *mut Self, item: *const libc::c_char) { (*this).vec_.push_copied(item); } -} -impl ConstructibleFromUnsafe<()> for MyContainer_char_ { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).vec_).write(Vec::new()); } } @@ -108,7 +104,7 @@ impl ConstructibleFromUnsafe<()> for MyContainer_char_ { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct MyContainer_float_ { vec_: Vec, } @@ -132,9 +128,7 @@ impl MyContainer_float_ { pub unsafe fn push_back(this: *mut Self, item: *const f32) { (*this).vec_.push_copied(item); } -} -impl ConstructibleFromUnsafe<()> for MyContainer_float_ { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).vec_).write(Vec::new()); } } @@ -374,7 +368,7 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { Boxed_long_::twice(10_i64,) }) == (20_i64))); let mut bl: Boxed_long_ = Boxed_long_ { value: 7_i64 }; assert!(((unsafe { Boxed_long_::plus(&raw const bl, 1_i64,) }) == (8_i64))); - object_unsafe!(imc, MyContainer_int_); + object_unsafe!(imc, MyContainer_int_::constructor_1()); assert!((unsafe { MyContainer_int_::empty(&raw const imc,) })); (unsafe { let mut _item: i32 = 1; @@ -386,7 +380,7 @@ unsafe fn main_0() -> i32 { ); (unsafe { MyContainer_int_::pop_back(&raw mut imc) }); assert!((unsafe { MyContainer_int_::empty(&raw const imc,) })); - object_unsafe!(cmc, MyContainer_char_); + object_unsafe!(cmc, MyContainer_char_::constructor_1()); assert!((unsafe { MyContainer_char_::empty(&raw const cmc,) })); (unsafe { let mut _item: libc::c_char = ('a' as libc::c_char); @@ -399,7 +393,7 @@ unsafe fn main_0() -> i32 { ); (unsafe { MyContainer_char_::pop_back(&raw mut cmc) }); assert!((unsafe { MyContainer_char_::empty(&raw const cmc,) })); - object_unsafe!(fmc, MyContainer_float_); + object_unsafe!(fmc, MyContainer_float_::constructor_1()); assert!((unsafe { MyContainer_float_::empty(&raw const fmc,) })); (unsafe { let mut _item: f32 = (1_f64 as f32); diff --git a/tests/unit/out/unsafe/constexpr_function.rs b/tests/unit/out/unsafe/constexpr_function.rs index 0757973a3a..cb95bb5f41 100644 --- a/tests/unit/out/unsafe/constexpr_function.rs +++ b/tests/unit/out/unsafe/constexpr_function.rs @@ -34,21 +34,21 @@ pub unsafe fn half_3(mut x: f64) -> f64 { ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(bool, const_lvalue_ref, explicit)] +#[conversion_function(conversion_function_1, bool, const_lvalue_ref, explicit)] pub struct Flag { pub v: i32, } -impl ConversionFunctionUnsafe>> for Flag { - unsafe fn conversion_function(this: LvalueRefUnsafe>, to: *mut bool) { +impl Flag { + pub unsafe fn conversion_function_1(this: LvalueRefUnsafe>, __return: *mut bool) { let this = this.as_ptr() as *mut Flag; - to.write((((*this).v) != (0))); + __return.write((((*this).v) != (0))); return; } } pub unsafe fn use_4(mut f: Flag) -> i32 { assert!({ - let mut __v: bool = false; - Flag::conversion_function(>>::bind(&mut f), &raw mut __v); + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + Flag::conversion_function_1(>>::bind(&mut f), &raw mut __v); __v }); return f.v; diff --git a/tests/unit/out/unsafe/constructor.rs b/tests/unit/out/unsafe/constructor.rs index d821919759..4aa4d270a6 100644 --- a/tests/unit/out/unsafe/constructor.rs +++ b/tests/unit/out/unsafe/constructor.rs @@ -20,8 +20,8 @@ pub static mut total_0: std::cell::LazyCell = std::cell::LazyCell::new(|| u )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] -#[constructor(value(i32))] +#[conversions(copy, move)] +#[constructor(constructor_1, value(i32))] pub struct S { pub v: i32, } @@ -32,16 +32,13 @@ impl S { pub unsafe fn mut_method(this: *mut Self) { (*this).v += 1; } -} -impl ConstructibleFromUnsafe<(i32,)> for S { - unsafe fn constructor(this: *mut Self, (mut init,): (i32,)) { + pub unsafe fn constructor_1(this: *mut Self, mut init: i32) { (&raw mut (*this).v).write(init); (unsafe { S::mut_method(this) }); (*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) += (unsafe { S::const_method((this).cast_const()) }); } } -impl ConvertibleToUnsafe for i32 {} impl DestructibleUnsafe for S { unsafe fn destroy(this: *mut Self) { (unsafe { S::mut_method(this) }); @@ -59,29 +56,24 @@ impl DestructibleUnsafe for S { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] -#[constructor(value(i32), value(i32))] -#[constructor(value(i32))] +#[conversions(copy, move, default = constructor_3)] +#[constructor(constructor_1, value(i32), value(i32))] +#[constructor(constructor_2, value(i32))] pub struct Point { pub x: i32, pub y: i32, } -impl ConstructibleFromUnsafe<(i32, i32)> for Point { - unsafe fn constructor(this: *mut Self, (mut x, mut y): (i32, i32)) { +impl Point { + pub unsafe fn constructor_1(this: *mut Self, mut x: i32, mut y: i32) { (&raw mut (*this).x).write(x); (&raw mut (*this).y).write(y); } -} -impl ConstructibleFromUnsafe<(i32,)> for Point { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { - >::constructor(this, (v, ((v) + (1)))); + pub unsafe fn constructor_2(this: *mut Self, mut v: i32) { + Point::constructor_1(this, v, ((v) + (1))); (*this).y *= 10; } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<()> for Point { - unsafe fn constructor(this: *mut Self, _: ()) { - >::constructor(this, (4,)); + pub unsafe fn constructor_3(this: *mut Self) { + Point::constructor_2(this, 4); (*this).x += 100; } } @@ -89,8 +81,8 @@ impl Default for Point { fn default() -> Self { unsafe { { - let mut __v: Point = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Point = ZeroInitializationUnsafe::zero_init(); + Point::constructor_3(&raw mut __v); __v } } @@ -104,15 +96,15 @@ pub fn main() { } unsafe fn main_0() -> i32 { { - object_unsafe!(s, S, (i32,), (3,)); + object_unsafe!(s, S::constructor_1(3)); assert!(((s.v) == (4))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) == (8))); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) == (18))); - object_unsafe!(p, Point); + object_unsafe!(p, Point::constructor_3()); assert!(((p.x) == (104))); assert!(((p.y) == (50))); - object_unsafe!(q, Point, (i32,), (7,)); + object_unsafe!(q, Point::constructor_2(7)); assert!(((q.x) == (7))); assert!(((q.y) == (80))); return 0; diff --git a/tests/unit/out/unsafe/container_field_addr.rs b/tests/unit/out/unsafe/container_field_addr.rs index 98f5f77d87..a0e925f87a 100644 --- a/tests/unit/out/unsafe/container_field_addr.rs +++ b/tests/unit/out/unsafe/container_field_addr.rs @@ -20,13 +20,13 @@ use std::rc::Rc; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct S { pub tag: i32, pub v: Vec, } -impl ConstructibleFromUnsafe<()> for S { - unsafe fn constructor(this: *mut Self, _: ()) { +impl S { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).tag).write(0_i32); (&raw mut (*this).v).write(Vec::new()); } @@ -57,12 +57,12 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(local, S); + object_unsafe!(local, S::constructor_1()); local.tag = 7; (unsafe { run_1((&mut local as *mut S)) }); let mut heap: *mut S = { let __p: *mut S = Box::leak(Box::new(::zero_init())); - >::constructor(__p, ()); + S::constructor_1(__p); __p }; (*heap).tag = 7; diff --git a/tests/unit/out/unsafe/conversion_operator_same_translation.rs b/tests/unit/out/unsafe/conversion_operator_same_translation.rs index 0ad1c00807..7b849f4005 100644 --- a/tests/unit/out/unsafe/conversion_operator_same_translation.rs +++ b/tests/unit/out/unsafe/conversion_operator_same_translation.rs @@ -19,27 +19,26 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(libc::c_char, const_lvalue_ref)] -#[conversion_function(u8, const_lvalue_ref)] +#[conversion_function(conversion_function_1, libc::c_char, const_lvalue_ref)] +#[conversion_function(conversion_function_2, u8, const_lvalue_ref)] pub struct S { pub v: i32, } -impl ConversionFunctionUnsafe>> for S { - unsafe fn conversion_function(this: LvalueRefUnsafe>, to: *mut libc::c_char) { +impl S { + pub unsafe fn conversion_function_1( + this: LvalueRefUnsafe>, + __return: *mut libc::c_char, + ) { let this = this.as_ptr() as *mut S; - to.write(((*this).v as libc::c_char)); + __return.write(((*this).v as libc::c_char)); return; } -} -impl ImplicitConversionFunctionUnsafe>> for S {} -impl ConversionFunctionUnsafe>> for S { - unsafe fn conversion_function(this: LvalueRefUnsafe>, to: *mut u8) { + pub unsafe fn conversion_function_2(this: LvalueRefUnsafe>, __return: *mut u8) { let this = this.as_ptr() as *mut S; - to.write(((((*this).v) + (1)) as u8)); + __return.write(((((*this).v) + (1)) as u8)); return; } } -impl ImplicitConversionFunctionUnsafe>> for S {} #[repr(C)] #[derive( Copy, @@ -53,23 +52,23 @@ impl ImplicitConversionFunctionUnsafe>> for S {} ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(i64, const_lvalue_ref)] +#[conversion_function(conversion_function_1, i64, const_lvalue_ref)] +#[conversion_function(conversion_function_2, i64, const_lvalue_ref)] pub struct T { pub v: i32, } impl T { - pub unsafe fn to_i64_2(this: *const Self) -> i64 { - return ((((*this).v) + (1)) as i64); + pub unsafe fn conversion_function_1(this: LvalueRefUnsafe>, __return: *mut i64) { + let this = this.as_ptr() as *mut T; + __return.write(((*this).v as i64)); + return; } -} -impl ConversionFunctionUnsafe>> for T { - unsafe fn conversion_function(this: LvalueRefUnsafe>, to: *mut i64) { + pub unsafe fn conversion_function_2(this: LvalueRefUnsafe>, __return: *mut i64) { let this = this.as_ptr() as *mut T; - to.write(((*this).v as i64)); + __return.write(((((*this).v) + (1)) as i64)); return; } } -impl ImplicitConversionFunctionUnsafe>> for T {} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -79,37 +78,41 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut s: S = S { v: 65 }; let mut a: libc::c_char = { - let mut __v: libc::c_char = (0 as libc::c_char); - S::conversion_function(>>::bind(&mut s), &raw mut __v); + let mut __v: libc::c_char = ZeroInitializationUnsafe::zero_init(); + S::conversion_function_1(>>::bind(&mut s), &raw mut __v); __v }; let mut b: u8 = { - let mut __v: u8 = 0_u8; - S::conversion_function(>>::bind(&mut s), &raw mut __v); + let mut __v: u8 = ZeroInitializationUnsafe::zero_init(); + S::conversion_function_2(>>::bind(&mut s), &raw mut __v); __v }; assert!(((a as i32) == (('A' as libc::c_char) as i32))); assert!(((b as i32) == ((66 as u8) as i32))); assert!( ((({ - let mut __v: libc::c_char = (0 as libc::c_char); - S::conversion_function(>>::bind(&mut s), &raw mut __v); + let mut __v: libc::c_char = ZeroInitializationUnsafe::zero_init(); + S::conversion_function_1(>>::bind(&mut s), &raw mut __v); __v } as i32) + ({ - let mut __v: u8 = 0_u8; - S::conversion_function(>>::bind(&mut s), &raw mut __v); + let mut __v: u8 = ZeroInitializationUnsafe::zero_init(); + S::conversion_function_2(>>::bind(&mut s), &raw mut __v); __v } as i32)) == (131)) ); let mut t: T = T { v: 3 }; let mut c: i64 = { - let mut __v: i64 = 0_i64; - T::conversion_function(>>::bind(&mut t), &raw mut __v); + let mut __v: i64 = ZeroInitializationUnsafe::zero_init(); + T::conversion_function_1(>>::bind(&mut t), &raw mut __v); + __v + }; + let mut d: i64 = { + let mut __v: i64 = ZeroInitializationUnsafe::zero_init(); + T::conversion_function_2(>>::bind(&mut t), &raw mut __v); __v }; - let mut d: i64 = (unsafe { T::to_i64_2(&raw const t) }); assert!(((c) == (3_i64))); assert!(((d) == (4_i64))); return 0; diff --git a/tests/unit/out/unsafe/copy_assign.rs b/tests/unit/out/unsafe/copy_assign.rs index 95039f6f9c..701f7f0a5e 100644 --- a/tests/unit/out/unsafe/copy_assign.rs +++ b/tests/unit/out/unsafe/copy_assign.rs @@ -18,27 +18,23 @@ pub static mut assigns_0: std::cell::LazyCell = std::cell::LazyCell::new(|| Default, ConversionsUnsafe, )] -#[conversions(copy)] -#[constructor(value(i32), value(i32))] +#[conversions(copy = constructor_2, move)] +#[constructor(constructor_1, value(i32), value(i32))] pub struct Partial { pub v: i32, pub keep: i32, } -impl ConstructibleFromUnsafe<(i32, i32)> for Partial { - unsafe fn constructor(this: *mut Self, (mut v, mut keep): (i32, i32)) { +impl Partial { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32, mut keep: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).keep).write(keep); } -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for Partial { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(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 CopyConstructibleUnsafe for Partial {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} impl CopyAssignableUnsafe for Partial { unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut Partial { let o = (o.as_ptr() as *const Partial); @@ -61,11 +57,14 @@ impl CopyAssignableUnsafe for Partial { CopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy)] +#[conversions(copy, move, default = constructor_1)] pub struct NonConstAssign { pub mark: i32, } impl NonConstAssign { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).mark).write(0); + } pub unsafe fn operator_assign_2( this: *mut Self, o: *mut NonConstAssign, @@ -81,17 +80,12 @@ impl NonConstAssign { return &mut (*this); } } -impl ConstructibleFromUnsafe<()> for NonConstAssign { - unsafe fn constructor(this: *mut Self, _: ()) { - (&raw mut (*this).mark).write(0); - } -} impl Default for NonConstAssign { fn default() -> Self { unsafe { { - let mut __v: NonConstAssign = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: NonConstAssign = ZeroInitializationUnsafe::zero_init(); + NonConstAssign::constructor_1(&raw mut __v); __v } } @@ -109,12 +103,12 @@ impl Default for NonConstAssign { MovableUnsafe, ConversionsUnsafe, )] -#[conversions(copy)] +#[conversions(copy, move, default = constructor_1)] pub struct RefQualified { pub mark: i32, } -impl ConstructibleFromUnsafe<()> for RefQualified { - unsafe fn constructor(this: *mut Self, _: ()) { +impl RefQualified { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).mark).write(0); } } @@ -132,8 +126,8 @@ impl Default for RefQualified { fn default() -> Self { unsafe { { - let mut __v: RefQualified = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: RefQualified = ZeroInitializationUnsafe::zero_init(); + RefQualified::constructor_1(&raw mut __v); __v } } @@ -155,6 +149,7 @@ pub struct Holder { pub p: Partial, pub arr: [Partial; 2], } +impl Holder {} pub static mut copies_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( @@ -169,26 +164,21 @@ pub static mut copies_1: std::cell::LazyCell = std::cell::LazyCell::new(|| )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move)] +#[constructor(constructor_1, value(i32))] pub struct CopyCounted { pub v: i32, } -impl ConstructibleFromUnsafe<(i32,)> for CopyCounted { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl CopyCounted { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for CopyCounted { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(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(); } } -impl CopyConstructibleUnsafe for CopyCounted {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} #[repr(C)] #[derive( FnPtrArg, @@ -205,6 +195,7 @@ pub struct HasCopyCounted { pub c: CopyCounted, pub arr: [CopyCounted; 2], } +impl HasCopyCounted {} #[repr(C)] #[derive( Clone, @@ -217,10 +208,15 @@ pub struct HasCopyCounted { Default, ConversionsUnsafe, )] -#[conversions(copy)] +#[conversions(copy, move, default = constructor_1)] pub struct ExplicitOperatorCall { pub w: Vec, } +impl ExplicitOperatorCall { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).w).write(Vec::new()); + } +} impl CopyAssignableUnsafe for ExplicitOperatorCall { unsafe fn copy_assign( this: *mut Self, @@ -233,11 +229,6 @@ impl CopyAssignableUnsafe for ExplicitOperatorCall { return &mut (*this); } } -impl ConstructibleFromUnsafe<()> for ExplicitOperatorCall { - unsafe fn constructor(this: *mut Self, _: ()) { - (&raw mut (*this).w).write(Vec::new()); - } -} pub static mut swap_copies_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( @@ -249,34 +240,27 @@ pub static mut swap_copies_2: std::cell::LazyCell = std::cell::LazyCell::ne Default, ConversionsUnsafe, )] -#[conversions(copy)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move)] +#[constructor(constructor_1, value(i32))] pub struct Swapped { pub v: i32, } impl Swapped { - pub unsafe fn copy_assign(this: *mut Self, o: *mut Swapped) -> *mut Swapped { - let mut t: i32 = (*this).v; - (*this).v = (*o).v; - (*o).v = t; - return &mut (*this); - } -} -impl ConstructibleFromUnsafe<(i32,)> for Swapped { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for Swapped { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(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(); } + pub unsafe fn copy_assign(this: *mut Self, o: *mut Swapped) -> *mut Swapped { + let mut t: i32 = (*this).v; + (*this).v = (*o).v; + (*o).v = t; + return &mut (*this); + } } -impl CopyConstructibleUnsafe for Swapped {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} impl CopyAssignableUnsafe for Swapped { unsafe fn copy_assign(this: *mut Self, src: LvalueRefUnsafe>) -> *mut Self { object_unsafe!( @@ -314,6 +298,7 @@ impl MoveAssignableUnsafe for Swapped { pub struct HoldsSwapped { pub s: Swapped, } +impl HoldsSwapped {} #[repr(C)] #[derive( Copy, @@ -327,20 +312,18 @@ pub struct HoldsSwapped { SwappableUnsafe, ConversionsUnsafe, )] -#[conversions(copy)] +#[conversions(copy, move, default = constructor_1)] pub struct VoidAssign { pub x: i32, } impl VoidAssign { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).x).write(0); + } pub unsafe fn copy_assign(this: *mut Self, o: *const VoidAssign) { (*this).x = (((*o).x) + (5)); } } -impl ConstructibleFromUnsafe<()> for VoidAssign { - unsafe fn constructor(this: *mut Self, _: ()) { - (&raw mut (*this).x).write(0); - } -} impl CopyAssignableUnsafe for VoidAssign { unsafe fn copy_assign(this: *mut Self, src: LvalueRefUnsafe>) -> *mut Self { VoidAssign::copy_assign(this, (src.as_ptr() as *const VoidAssign)); @@ -357,8 +340,8 @@ impl Default for VoidAssign { fn default() -> Self { unsafe { { - let mut __v: VoidAssign = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: VoidAssign = ZeroInitializationUnsafe::zero_init(); + VoidAssign::constructor_1(&raw mut __v); __v } } @@ -379,13 +362,13 @@ impl Default for VoidAssign { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct HoldsVoidAssign { pub v: VoidAssign, } -impl ConstructibleFromUnsafe<()> for HoldsVoidAssign { - unsafe fn constructor(this: *mut Self, _: ()) { - >::constructor(&raw mut (*this).v, ()); +impl HoldsVoidAssign { + pub unsafe fn constructor_1(this: *mut Self) { + VoidAssign::constructor_1(&raw mut (*this).v); } } pub fn main() { @@ -395,9 +378,9 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, Partial, (i32, i32,), (1, 100,)); - object_unsafe!(b, Partial, (i32, i32,), (2, 200,)); - object_unsafe!(c, Partial, (i32, i32,), (3, 300,)); + object_unsafe!(a, Partial::constructor_1(1, 100)); + object_unsafe!(b, Partial::constructor_1(2, 200)); + object_unsafe!(c, Partial::constructor_1(3, 300)); assign_unsafe!(a = b); assert!(((a.v) == (2)) && ((a.keep) == (100))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (1))); @@ -410,8 +393,8 @@ unsafe fn main_0() -> i32 { }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (3))); (unsafe { - let mut _o: Partial = ::zero_init(); - >::constructor(&raw mut _o, (9, 900)); + let mut _o: Partial = ZeroInitializationUnsafe::zero_init(); + Partial::constructor_1(&raw mut _o, 9, 900); assign_unsafe!(a = _o) }); assert!(((a.v) == (9)) && ((a.keep) == (100))); @@ -425,25 +408,19 @@ unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (6))); let mut h: Holder = Holder { p: { - let mut __v: Partial = ::zero_init(); - >::constructor(&raw mut __v, (4, 40)); + let mut __v: Partial = ZeroInitializationUnsafe::zero_init(); + Partial::constructor_1(&raw mut __v, 4, 40); __v }, arr: [ { - let mut __v: Partial = ::zero_init(); - >::constructor( - &raw mut __v, - (5, 50), - ); + let mut __v: Partial = ZeroInitializationUnsafe::zero_init(); + Partial::constructor_1(&raw mut __v, 5, 50); __v }, { - let mut __v: Partial = ::zero_init(); - >::constructor( - &raw mut __v, - (6, 60), - ); + let mut __v: Partial = ZeroInitializationUnsafe::zero_init(); + Partial::constructor_1(&raw mut __v, 6, 60); __v }, ], @@ -453,39 +430,33 @@ unsafe fn main_0() -> i32 { assert!(((h.p.v) == (2)) && ((h.p.keep) == (40))); assert!(((h.arr[(1) as usize].v) == (2)) && ((h.arr[(1) as usize].keep) == (60))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (8))); - object_unsafe!(n, NonConstAssign); - object_unsafe!(n1, NonConstAssign); - object_unsafe!(n2, NonConstAssign); - object_unsafe!(cn, NonConstAssign); + object_unsafe!(n, NonConstAssign::constructor_1()); + object_unsafe!(n1, NonConstAssign::constructor_1()); + object_unsafe!(n2, NonConstAssign::constructor_1()); + object_unsafe!(cn, NonConstAssign::constructor_1()); (unsafe { NonConstAssign::operator_assign_2(&raw mut n1, &mut n) }); (unsafe { NonConstAssign::operator_assign_3(&raw mut n2, &cn) }); assert!(((n1.mark) == (1))); assert!(((n2.mark) == (10))); - object_unsafe!(r, RefQualified); - object_unsafe!(r1, RefQualified); + object_unsafe!(r, RefQualified::constructor_1()); + object_unsafe!(r1, RefQualified::constructor_1()); assign_unsafe!(r1 = r); assert!(((r1.mark) == (1))); let mut h2: Holder = Holder { p: { - let mut __v: Partial = ::zero_init(); - >::constructor(&raw mut __v, (7, 70)); + let mut __v: Partial = ZeroInitializationUnsafe::zero_init(); + Partial::constructor_1(&raw mut __v, 7, 70); __v }, arr: [ { - let mut __v: Partial = ::zero_init(); - >::constructor( - &raw mut __v, - (8, 80), - ); + let mut __v: Partial = ZeroInitializationUnsafe::zero_init(); + Partial::constructor_1(&raw mut __v, 8, 80); __v }, { - let mut __v: Partial = ::zero_init(); - >::constructor( - &raw mut __v, - (9, 90), - ); + let mut __v: Partial = ZeroInitializationUnsafe::zero_init(); + Partial::constructor_1(&raw mut __v, 9, 90); __v }, ], @@ -494,44 +465,44 @@ unsafe fn main_0() -> i32 { assert!(((h2.p.v) == (2)) && ((h2.p.keep) == (70))); assert!(((h2.arr[(1) as usize].v) == (2)) && ((h2.arr[(1) as usize].keep) == (90))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (11))); - object_unsafe!(cc1, CopyCounted, (i32,), (1,)); - object_unsafe!(cc2, CopyCounted, (i32,), (2,)); + object_unsafe!(cc1, CopyCounted::constructor_1(1)); + object_unsafe!(cc2, CopyCounted::constructor_1(2)); assign_unsafe!(cc1 = cc2); assert!(((cc1.v) == (2))); let mut hc1: HasCopyCounted = HasCopyCounted { c: { - let mut __v: CopyCounted = ::zero_init(); - >::constructor(&raw mut __v, (1,)); + let mut __v: CopyCounted = ZeroInitializationUnsafe::zero_init(); + CopyCounted::constructor_1(&raw mut __v, 1); __v }, arr: [ { - let mut __v: CopyCounted = ::zero_init(); - >::constructor(&raw mut __v, (2,)); + let mut __v: CopyCounted = ZeroInitializationUnsafe::zero_init(); + CopyCounted::constructor_1(&raw mut __v, 2); __v }, { - let mut __v: CopyCounted = ::zero_init(); - >::constructor(&raw mut __v, (3,)); + let mut __v: CopyCounted = ZeroInitializationUnsafe::zero_init(); + CopyCounted::constructor_1(&raw mut __v, 3); __v }, ], }; let mut hc2: HasCopyCounted = HasCopyCounted { c: { - let mut __v: CopyCounted = ::zero_init(); - >::constructor(&raw mut __v, (4,)); + let mut __v: CopyCounted = ZeroInitializationUnsafe::zero_init(); + CopyCounted::constructor_1(&raw mut __v, 4); __v }, arr: [ { - let mut __v: CopyCounted = ::zero_init(); - >::constructor(&raw mut __v, (5,)); + let mut __v: CopyCounted = ZeroInitializationUnsafe::zero_init(); + CopyCounted::constructor_1(&raw mut __v, 5); __v }, { - let mut __v: CopyCounted = ::zero_init(); - >::constructor(&raw mut __v, (6,)); + let mut __v: CopyCounted = ZeroInitializationUnsafe::zero_init(); + CopyCounted::constructor_1(&raw mut __v, 6); __v }, ], @@ -542,8 +513,8 @@ unsafe fn main_0() -> i32 { && ((hc1.arr[(1) as usize].v) == (6)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (0))); - object_unsafe!(e1, ExplicitOperatorCall); - object_unsafe!(e2, ExplicitOperatorCall); + object_unsafe!(e1, ExplicitOperatorCall::constructor_1()); + object_unsafe!(e2, ExplicitOperatorCall::constructor_1()); { let mut __tmp_0: i32 = 5; e1.w.push_moved(&mut __tmp_0) @@ -552,14 +523,11 @@ unsafe fn main_0() -> i32 { assert!( (((e2.w.len()) == (1_usize)) && ((e2.w[(0_usize)]) == (5))) && ((e1.w.len()) == (1_usize)) ); - object_unsafe!(sw1, Swapped, (i32,), (1,)); - object_unsafe!(sw2, Swapped, (i32,), (2,)); + object_unsafe!(sw1, Swapped::constructor_1(1)); + object_unsafe!(sw2, Swapped::constructor_1(2)); (unsafe { - let mut _o: Swapped = ::zero_init(); - >,)>>::constructor( - &raw mut _o, - (LvalueRefUnsafe::bind(&sw2),), - ); + let mut _o: Swapped = ZeroInitializationUnsafe::zero_init(); + Swapped::constructor_2(&raw mut _o, LvalueRefUnsafe::bind(&sw2)); Swapped::copy_assign(&raw mut sw1, &mut _o) }); assert!( @@ -568,15 +536,15 @@ unsafe fn main_0() -> i32 { ); let mut hs1: HoldsSwapped = HoldsSwapped { s: { - let mut __v: Swapped = ::zero_init(); - >::constructor(&raw mut __v, (3,)); + let mut __v: Swapped = ZeroInitializationUnsafe::zero_init(); + Swapped::constructor_1(&raw mut __v, 3); __v }, }; let mut hs2: HoldsSwapped = HoldsSwapped { s: { - let mut __v: Swapped = ::zero_init(); - >::constructor(&raw mut __v, (4,)); + let mut __v: Swapped = ZeroInitializationUnsafe::zero_init(); + Swapped::constructor_1(&raw mut __v, 4); __v }, }; @@ -585,8 +553,8 @@ unsafe fn main_0() -> i32 { ((hs1.s.v) == (4)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut swap_copies_2)) == (2)) ); - object_unsafe!(hv1, HoldsVoidAssign); - object_unsafe!(hv2, HoldsVoidAssign); + object_unsafe!(hv1, HoldsVoidAssign::constructor_1()); + object_unsafe!(hv2, HoldsVoidAssign::constructor_1()); assign_unsafe!(hv1 = hv2); assert!(((hv1.v.x) == (5))); return 0; diff --git a/tests/unit/out/unsafe/copy_ctor.rs b/tests/unit/out/unsafe/copy_ctor.rs index 90343a0a2e..ab5d5ee6ee 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -20,61 +20,51 @@ pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move)] +#[constructor(constructor_1, value(i32))] pub struct Counted { pub v: i32, } -impl ConstructibleFromUnsafe<(i32,)> for Counted { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl Counted { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for Counted { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(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(); } } -impl CopyConstructibleUnsafe for Counted {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} #[repr(C)] #[derive( FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, MoveAssignableUnsafe, )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy = constructor_3, default = constructor_1)] +#[constructor(constructor_2, lvalue_ref(NonConst))] pub struct NonConst { pub mark: i32, } -impl ConstructibleFromUnsafe<()> for NonConst { - unsafe fn constructor(this: *mut Self, _: ()) { +impl NonConst { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).mark).write(0); } -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe,)> for NonConst { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe,)) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe) { let o = (o.as_ptr() as *mut NonConst); (&raw mut (*this).mark).write((((*o).mark) + (1))); } -} -impl ConvertibleToUnsafe for LvalueRefUnsafe {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for NonConst { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_3(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const NonConst); (&raw mut (*this).mark).write((((*o).mark) + (10))); } } -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} impl Default for NonConst { fn default() -> Self { unsafe { { - let mut __v: NonConst = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: NonConst = ZeroInitializationUnsafe::zero_init(); + NonConst::constructor_1(&raw mut __v); __v } } @@ -93,26 +83,21 @@ impl Default for NonConst { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move)] +#[constructor(constructor_1, value(i32))] pub struct Ignored { pub v: i32, } -impl ConstructibleFromUnsafe<(i32,)> for Ignored { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl Ignored { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for Ignored { - unsafe fn constructor(this: *mut Self, (_a0,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(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(); } } -impl CopyConstructibleUnsafe for Ignored {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} #[repr(C)] #[derive( FnPtrArg, @@ -129,31 +114,27 @@ pub struct Holder { pub c: Counted, pub arr: [Counted; 2], } +impl Holder {} #[repr(C)] #[derive( FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, )] #[memberwise(move_constructor)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move)] +#[constructor(constructor_1, value(i32))] pub struct Box_int_ { pub val: i32, } -impl ConstructibleFromUnsafe<(i32,)> for Box_int_ { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl Box_int_ { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).val).write(v); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for Box_int_ { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const Box_int_); (&raw mut (*this).val).write((*o).val); } } -impl CopyConstructibleUnsafe for Box_int_ {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} #[repr(C)] #[derive( FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, @@ -164,6 +145,7 @@ impl ConvertibleToUnsafe for LvalueRefUnsafe> {} pub struct Owner { pub box_: Box_int_, } +impl Owner {} #[repr(C)] #[derive( FnPtrArg, @@ -177,26 +159,22 @@ pub struct Owner { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move)] +#[constructor(constructor_1, value(i32))] pub struct OutOfLine { pub v: i32, } -impl ConstructibleFromUnsafe<(i32,)> for OutOfLine { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl OutOfLine { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for OutOfLine { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(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(); } } -impl CopyConstructibleUnsafe for OutOfLine {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} +impl OutOfLine {} #[repr(C)] #[derive( FnPtrArg, @@ -207,24 +185,20 @@ impl ConvertibleToUnsafe for LvalueRefUnsafe> {} SwappableUnsafe, ConversionsUnsafe, )] -#[conversions(copy)] +#[conversions(copy = constructor_2, move, default = constructor_1)] pub struct Tracked { pub copied_from: i32, } -impl ConstructibleFromUnsafe<()> for Tracked { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Tracked { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).copied_from).write(0); } -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for Tracked { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(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 CopyConstructibleUnsafe for Tracked {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} impl CopyAssignableUnsafe for Tracked { unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut Tracked { let o = (o.as_ptr() as *const Tracked); @@ -244,43 +218,35 @@ pub unsafe fn by_value_2(c: *mut Counted) -> i32 { return (*c).v; } pub unsafe fn make_3(__return: *mut Counted, mut v: i32) { - object_unsafe!(c, Counted, (i32,), (v,)); - ConvertibleToUnsafe::convert(>>::bind(&c), __return); + object_unsafe!(c, Counted::constructor_1(v)); + Counted::constructor_2(__return, LvalueRefUnsafe::bind(&c)); return; } #[repr(C)] #[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy = constructor_2, move = constructor_3, default = constructor_1)] pub struct SelfPtr { pub self_: *mut SelfPtr, } -impl ConstructibleFromUnsafe<()> for SelfPtr { - unsafe fn constructor(this: *mut Self, _: ()) { +impl SelfPtr { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).self_).write(this); } -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for SelfPtr { - unsafe fn constructor(this: *mut Self, (_a0,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const SelfPtr); (&raw mut (*this).self_).write(this); } -} -impl CopyConstructibleUnsafe for SelfPtr {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for SelfPtr { - unsafe fn constructor(this: *mut Self, (_a0,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_3(this: *mut Self, _a0: RvalueRefUnsafe) { let _a0 = (_a0.as_ptr() as *mut SelfPtr); (&raw mut (*this).self_).write(this); } } -impl MoveConstructibleUnsafe for SelfPtr {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} impl Default for SelfPtr { fn default() -> Self { unsafe { { - let mut __v: SelfPtr = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: SelfPtr = ZeroInitializationUnsafe::zero_init(); + SelfPtr::constructor_1(&raw mut __v); __v } } @@ -306,21 +272,21 @@ pub struct EmptyBase {} )] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Derived { pub c: Counted, } -impl ConstructibleFromUnsafe<()> for Derived { - unsafe fn constructor(this: *mut Self, _: ()) { - >::constructor(&raw mut (*this).c, (20,)); +impl Derived { + pub unsafe fn constructor_1(this: *mut Self) { + Counted::constructor_1(&raw mut (*this).c, 20); } } impl Default for Derived { fn default() -> Self { unsafe { { - let mut __v: Derived = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Derived = ZeroInitializationUnsafe::zero_init(); + Derived::constructor_1(&raw mut __v); __v } } @@ -333,19 +299,16 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, Counted, (i32,), (1,)); - object_unsafe!(b, Counted, LvalueRefUnsafe::bind(&a)); - object_unsafe!(c, Counted = >>::bind(&a)); - object_unsafe!(d, Counted, LvalueRefUnsafe::bind(&a)); + object_unsafe!(a, Counted::constructor_1(1)); + object_unsafe!(b, Counted::constructor_2(LvalueRefUnsafe::bind(&a))); + object_unsafe!(c, Counted::constructor_2(LvalueRefUnsafe::bind(&a))); + object_unsafe!(d, Counted::constructor_2(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(); - >,)>>::constructor( - &raw mut _c, - (LvalueRefUnsafe::bind(&a),), - ); + let mut _c: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_2(&raw mut _c, LvalueRefUnsafe::bind(&a)); by_value_2(&mut _c) }) == (1)) ); @@ -353,36 +316,35 @@ unsafe fn main_0() -> i32 { object_unsafe!(e, Counted, |e| (unsafe { make_3(e, 5,) })); assert!(((e.v) == (5))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (5))); - object_unsafe!(f, Counted, (i32,), (6,)); + object_unsafe!(f, Counted::constructor_1(6)); assert!(((f.v) == (6))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (5))); - object_unsafe!(g, Counted, (i32,), (7,)); - object_unsafe!(h, Counted = >>::bind(&g)); + object_unsafe!(g, Counted::constructor_1(7)); + object_unsafe!(h, Counted::constructor_2(LvalueRefUnsafe::bind(&g))); assert!(((h.v) == (7))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (6))); let mut hold: Holder = Holder { c: { - let mut __v: Counted = ::zero_init(); - >::constructor(&raw mut __v, (8,)); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_1(&raw mut __v, 8); __v }, arr: [ { - let mut __v: Counted = ::zero_init(); - >::constructor(&raw mut __v, (9,)); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_1(&raw mut __v, 9); __v }, { - let mut __v: Counted = ::zero_init(); - >::constructor(&raw mut __v, (10,)); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_1(&raw mut __v, 10); __v }, ], }; - object_unsafe!( - hold2, - Holder = >>::bind(&hold) - ); + object_unsafe!(hold2, Holder, |hold2| { + ::copy_constructor(hold2, LvalueRefUnsafe::bind(&hold)) + }); assert!( (((hold2.c.v) == (8)) && ((hold2.arr[(0) as usize].v) == (9))) && ((hold2.arr[(1) as usize].v) == (10)) @@ -392,53 +354,44 @@ unsafe fn main_0() -> i32 { vec_.push_copied(&mut a); assert!(((vec_[(0_usize)].v) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (10))); - object_unsafe!(i1, Ignored, (i32,), (1,)); - object_unsafe!(i2, Ignored, LvalueRefUnsafe::bind(&i1)); + object_unsafe!(i1, Ignored::constructor_1(1)); + object_unsafe!(i2, Ignored::constructor_2(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 { box_: { - let mut __v: Box_int_ = ::zero_init(); - >::constructor(&raw mut __v, (3,)); + let mut __v: Box_int_ = ZeroInitializationUnsafe::zero_init(); + Box_int_::constructor_1(&raw mut __v, 3); __v }, }; - object_unsafe!(o2, Owner = >::bind(&mut o)); + object_unsafe!(o2, Owner, |o2| { + ::move_constructor(o2, RvalueRefUnsafe::bind(&mut o)) + }); assert!(((o2.box_.val) == (3))); - object_unsafe!(ol1, OutOfLine, (i32,), (5,)); - object_unsafe!(ol2, OutOfLine, LvalueRefUnsafe::bind(&ol1)); + object_unsafe!(ol1, OutOfLine::constructor_1(5)); + object_unsafe!(ol2, OutOfLine::constructor_2(LvalueRefUnsafe::bind(&ol1))); assert!(((ol2.v) == (105))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (12))); - object_unsafe!(n, NonConst); - object_unsafe!( - n1, - NonConst, - (LvalueRefUnsafe,), - (LvalueRefUnsafe::bind(&mut n),) - ); - object_unsafe!(cn, NonConst); - object_unsafe!( - n2, - NonConst, - (LvalueRefUnsafe>,), - (LvalueRefUnsafe::bind(&cn),) - ); + object_unsafe!(n, NonConst::constructor_1()); + object_unsafe!(n1, NonConst::constructor_2(LvalueRefUnsafe::bind(&mut n))); + object_unsafe!(cn, NonConst::constructor_1()); + object_unsafe!(n2, NonConst::constructor_3(LvalueRefUnsafe::bind(&cn))); assert!(((n1.mark) == (1))); assert!(((n2.mark) == (10))); - object_unsafe!(t1, Tracked); - object_unsafe!(t2, Tracked, LvalueRefUnsafe::bind(&t1)); + object_unsafe!(t1, Tracked::constructor_1()); + object_unsafe!(t2, Tracked::constructor_2(LvalueRefUnsafe::bind(&t1))); assign_unsafe!(t2 = t1); assert!(((t1.copied_from) == (2))); - object_unsafe!(ct, Tracked); - object_unsafe!(t3, Tracked, LvalueRefUnsafe::bind(&ct)); + object_unsafe!(ct, Tracked::constructor_1()); + object_unsafe!(t3, Tracked::constructor_2(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 = >>::bind(&der) - ); + object_unsafe!(der, Derived::constructor_1()); + object_unsafe!(der2, Derived, |der2| { + ::copy_constructor(der2, LvalueRefUnsafe::bind(&der)) + }); assert!( ((der2.c.v) == (20)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == ((before) + (1))) @@ -450,9 +403,9 @@ unsafe fn main_0() -> i32 { let mut __it = (__tmp_0).clone(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { __v.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } @@ -468,16 +421,16 @@ unsafe fn main_0() -> i32 { selfs.reserve_exact(2_usize - len_0 as usize); }; { - let mut __tmp_3: SelfPtr = ::zero_init(); + let mut __tmp_3: SelfPtr = ZeroInitializationUnsafe::zero_init(); match (({ - >::constructor(&raw mut __tmp_3, ()); + SelfPtr::constructor_1(&raw mut __tmp_3); &mut __tmp_3 } as *mut SelfPtr),) { (__tmp_2,) => selfs.push_moved(__tmp_2), } }; - object_unsafe!(self_src, SelfPtr); + object_unsafe!(self_src, SelfPtr::constructor_1()); selfs.push_copied(&mut self_src); assert!( ((selfs[(0_usize)].self_) == (&mut selfs[(0_usize)] as *mut SelfPtr)) @@ -489,9 +442,9 @@ unsafe fn main_0() -> i32 { temps.reserve_exact(1_usize - len_0 as usize); }; { - let mut __tmp_5: Counted = ::zero_init(); + let mut __tmp_5: Counted = ZeroInitializationUnsafe::zero_init(); match (({ - >::constructor(&raw mut __tmp_5, (30,)); + Counted::constructor_1(&raw mut __tmp_5, 30); &mut __tmp_5 } as *mut Counted),) { diff --git a/tests/unit/out/unsafe/copy_move_defaulted.rs b/tests/unit/out/unsafe/copy_move_defaulted.rs index 8f6bcc26de..e72e684ba3 100644 --- a/tests/unit/out/unsafe/copy_move_defaulted.rs +++ b/tests/unit/out/unsafe/copy_move_defaulted.rs @@ -37,20 +37,19 @@ pub struct Inner { #[memberwise(copy_assign, move_assign)] #[derive(ConversionsUnsafe)] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] pub struct Explicit { pub v: i32, pub inner: Inner, pub arr: [i32; 2], } -impl ConstructibleFromUnsafe<(i32,)> for Explicit { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl Explicit { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).inner).write(Inner { x: ((v) * (10)) }); (&raw mut (*this).arr).write([v, ((v) + (1))]); } } -impl ConvertibleToUnsafe for i32 {} impl DestructibleUnsafe for Explicit { unsafe fn destroy(this: *mut Self) {} } @@ -87,26 +86,21 @@ pub struct Implicit { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy, move = constructor_3)] +#[constructor(constructor_1, value(i32))] pub struct DefaultCopyUserMove { pub v: i32, } -impl ConstructibleFromUnsafe<(i32,)> for DefaultCopyUserMove { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl DefaultCopyUserMove { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for DefaultCopyUserMove { - unsafe fn constructor(this: *mut Self, (o,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut DefaultCopyUserMove); (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } -impl MoveConstructibleUnsafe for DefaultCopyUserMove {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} impl MoveAssignableUnsafe for DefaultCopyUserMove { unsafe fn move_assign( this: *mut Self, @@ -129,25 +123,20 @@ impl MoveAssignableUnsafe for DefaultCopyUserMove { )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move)] +#[constructor(constructor_1, value(i32))] pub struct UserCopyDefaultMove { pub v: i32, } -impl ConstructibleFromUnsafe<(i32,)> for UserCopyDefaultMove { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl UserCopyDefaultMove { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for UserCopyDefaultMove { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const UserCopyDefaultMove); (&raw mut (*this).v).write((((*o).v) + (100))); } } -impl CopyConstructibleUnsafe for UserCopyDefaultMove {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} impl CopyAssignableUnsafe for UserCopyDefaultMove { unsafe fn copy_assign( this: *mut Self, @@ -170,15 +159,15 @@ impl CopyAssignableUnsafe for UserCopyDefaultMove { #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] #[conversions(move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] pub struct Buffer { pub data: Vec, pub rows: Vec>, pub n: i32, pub arr: [i32; 2], } -impl ConstructibleFromUnsafe<(i32,)> for Buffer { - unsafe fn constructor(this: *mut Self, (mut n,): (i32,)) { +impl Buffer { + pub unsafe fn constructor_1(this: *mut Self, mut n: i32) { (&raw mut (*this).data).write(Vec::from_fn((n as usize), |_| { copy_constructed_unsafe(&mut n) })); @@ -188,7 +177,6 @@ impl ConstructibleFromUnsafe<(i32,)> for Buffer { (*this).rows.push_copied(&mut (*this).data); } } -impl ConvertibleToUnsafe for i32 {} #[repr(C)] #[derive( FnPtrArg, @@ -200,15 +188,15 @@ impl ConvertibleToUnsafe for i32 {} )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] pub struct Owner { pub data: Vec, pub n: i32, pub arr: [i32; 2], pub p: Option>, } -impl ConstructibleFromUnsafe<()> for Owner { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Owner { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).data).write(Vec::new()); (&raw mut (*this).n).write(0_i32); (&raw mut (*this).arr).write([0_i32; 2]); @@ -229,12 +217,12 @@ impl ConstructibleFromUnsafe<()> for Owner { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Copyable { pub data: Vec, } -impl ConstructibleFromUnsafe<()> for Copyable { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Copyable { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).data).write(Vec::new()); } } @@ -249,21 +237,20 @@ impl ConstructibleFromUnsafe<()> for Copyable { #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] #[conversions(move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] pub struct Holder { pub inner: Inner, #[destroy] pub e: Explicit, pub p: Option>, } -impl ConstructibleFromUnsafe<(i32,)> for Holder { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl Holder { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).inner).write(Inner { x: v }); - >::constructor(&raw mut (*this).e, (v,)); + Explicit::constructor_1(&raw mut (*this).e, v); (&raw mut (*this).p).write(None); } } -impl ConvertibleToUnsafe for i32 {} pub unsafe fn same_0(a: *const Explicit, b: *const Explicit) -> bool { return (((((*a).v) == ((*b).v)) && (((*a).inner.x) == ((*b).inner.x))) && (((*a).arr[(0) as usize]) == ((*b).arr[(0) as usize]))) @@ -271,9 +258,15 @@ pub unsafe fn same_0(a: *const Explicit, b: *const Explicit) -> bool { } #[repr(C)] #[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] +#[conversions(default = constructor_1)] pub struct SeesThis { pub self_: *mut SeesThis, } +impl SeesThis { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).self_).write(std::ptr::null_mut()); + } +} impl CopyAssignableUnsafe for SeesThis { unsafe fn copy_assign(this: *mut Self, _a0: LvalueRefUnsafe>) -> *mut SeesThis { let _a0 = (_a0.as_ptr() as *const SeesThis); @@ -288,11 +281,6 @@ impl MoveAssignableUnsafe for SeesThis { return &mut (*this); } } -impl ConstructibleFromUnsafe<()> for SeesThis { - unsafe fn constructor(this: *mut Self, _: ()) { - (&raw mut (*this).self_).write(std::ptr::null_mut()); - } -} impl Default for SeesThis { fn default() -> Self { unsafe { @@ -306,13 +294,14 @@ impl Default for SeesThis { #[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, Default)] #[memberwise(copy_assign, move_assign)] #[derive(ConversionsUnsafe)] +#[conversions(default = constructor_1)] pub struct HasSeesThis { pub s: SeesThis, pub v: Vec, } -impl ConstructibleFromUnsafe<()> for HasSeesThis { - unsafe fn constructor(this: *mut Self, _: ()) { - >::constructor(&raw mut (*this).s, ()); +impl HasSeesThis { + pub unsafe fn constructor_1(this: *mut Self) { + SeesThis::constructor_1(&raw mut (*this).s); (&raw mut (*this).v).write(Vec::new()); } } @@ -320,26 +309,22 @@ impl ConstructibleFromUnsafe<()> for HasSeesThis { #[derive( FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, ConversionsUnsafe, )] -#[conversions(move)] +#[conversions(move = constructor_2, default = constructor_1)] pub struct Counted_int_ { pub v: i32, pub moves: i32, } -impl ConstructibleFromUnsafe<()> for Counted_int_ { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Counted_int_ { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write(0_i32); (&raw mut (*this).moves).write(0); } -} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for Counted_int_ { - unsafe fn constructor(this: *mut Self, (o,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_2(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 MoveConstructibleUnsafe for Counted_int_ {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} impl MoveAssignableUnsafe for Counted_int_ { unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut Counted_int_ { let o = (o.as_ptr() as *mut Counted_int_); @@ -364,14 +349,14 @@ impl Default for Counted_int_ { )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] pub struct HasCounted { pub c: Counted_int_, pub w: Vec, } -impl ConstructibleFromUnsafe<()> for HasCounted { - unsafe fn constructor(this: *mut Self, _: ()) { - >::constructor(&raw mut (*this).c, ()); +impl HasCounted { + pub unsafe fn constructor_1(this: *mut Self) { + Counted_int_::constructor_1(&raw mut (*this).c); (&raw mut (*this).w).write(Vec::new()); } } @@ -379,43 +364,32 @@ impl ConstructibleFromUnsafe<()> for HasCounted { #[derive( FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_3, move = constructor_4, default = constructor_1)] +#[constructor(constructor_2, value(i32))] pub struct CtorSeesThis { pub self_: *mut CtorSeesThis, pub id: i32, } -impl ConstructibleFromUnsafe<()> for CtorSeesThis { - unsafe fn constructor(this: *mut Self, _: ()) { +impl CtorSeesThis { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).self_).write(this); (&raw mut (*this).id).write(0); } -} -impl ConstructibleFromUnsafe<(i32,)> for CtorSeesThis { - unsafe fn constructor(this: *mut Self, (mut id,): (i32,)) { - >::constructor(this, ()); + pub unsafe fn constructor_2(this: *mut Self, mut id: i32) { + CtorSeesThis::constructor_1(this); (*this).id = id; } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for CtorSeesThis { - unsafe fn constructor(this: *mut Self, (_a0,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_3(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 CopyConstructibleUnsafe for CtorSeesThis {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for CtorSeesThis { - unsafe fn constructor(this: *mut Self, (_a0,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_4(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 MoveConstructibleUnsafe for CtorSeesThis {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} impl CopyAssignableUnsafe for CtorSeesThis { unsafe fn copy_assign( this: *mut Self, @@ -438,8 +412,8 @@ impl Default for CtorSeesThis { fn default() -> Self { unsafe { { - let mut __v: CtorSeesThis = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: CtorSeesThis = ZeroInitializationUnsafe::zero_init(); + CtorSeesThis::constructor_1(&raw mut __v); __v } } @@ -456,14 +430,14 @@ impl Default for CtorSeesThis { )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct HasCtorSeesThis { pub x: CtorSeesThis, pub v: Vec, } -impl ConstructibleFromUnsafe<()> for HasCtorSeesThis { - unsafe fn constructor(this: *mut Self, _: ()) { - >::constructor(&raw mut (*this).x, ()); +impl HasCtorSeesThis { + pub unsafe fn constructor_1(this: *mut Self) { + CtorSeesThis::constructor_1(&raw mut (*this).x); (&raw mut (*this).v).write(Vec::new()); } } @@ -473,23 +447,23 @@ impl ConstructibleFromUnsafe<()> for HasCtorSeesThis { )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct InitsCtorSeesThis { pub x: CtorSeesThis, pub y: CtorSeesThis, } -impl ConstructibleFromUnsafe<()> for InitsCtorSeesThis { - unsafe fn constructor(this: *mut Self, _: ()) { - >::constructor(&raw mut (*this).x, (1,)); - >::constructor(&raw mut (*this).y, (2,)); +impl InitsCtorSeesThis { + pub unsafe fn constructor_1(this: *mut Self) { + CtorSeesThis::constructor_2(&raw mut (*this).x, 1); + CtorSeesThis::constructor_2(&raw mut (*this).y, 2); } } impl Default for InitsCtorSeesThis { fn default() -> Self { unsafe { { - let mut __v: InitsCtorSeesThis = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: InitsCtorSeesThis = ZeroInitializationUnsafe::zero_init(); + InitsCtorSeesThis::constructor_1(&raw mut __v); __v } } @@ -507,27 +481,23 @@ impl Default for InitsCtorSeesThis { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy = constructor_2, move)] pub struct OutOfLineDefaulted { pub x: CtorSeesThis, pub v: i32, } impl OutOfLineDefaulted { pub unsafe fn construct(this: *mut Self) { - >::constructor(&raw mut (*this).x, ()); + CtorSeesThis::constructor_1(&raw mut (*this).x); (&raw mut (*this).v).write(1); } -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for OutOfLineDefaulted { - unsafe fn constructor(this: *mut Self, (_a0,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const OutOfLineDefaulted); - >,)>>::constructor(&raw mut (*this).x, (LvalueRefUnsafe::bind(& ( * _a0 ) . x ),)) ; + CtorSeesThis::constructor_3(&raw mut (*this).x, LvalueRefUnsafe::bind(&(*_a0).x)); (&raw mut (*this).v).write((*_a0).v); } } -impl CopyConstructibleUnsafe for OutOfLineDefaulted {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} -impl ConstructibleFromUnsafe<()> for OutOfLineDefaulted { +impl ConstructorUnsafe<()> for OutOfLineDefaulted { unsafe fn constructor(this: *mut Self, _: ()) { unsafe { OutOfLineDefaulted::construct(this); @@ -538,7 +508,7 @@ impl Default for OutOfLineDefaulted { fn default() -> Self { unsafe { { - let mut __v: OutOfLineDefaulted = ::zero_init(); + let mut __v: OutOfLineDefaulted = ZeroInitializationUnsafe::zero_init(); OutOfLineDefaulted::construct(&raw mut __v); __v } @@ -546,16 +516,18 @@ impl Default for OutOfLineDefaulted { } } impl OutOfLineDefaulted {} +impl OutOfLineDefaulted {} #[repr(C)] #[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] +#[conversions(default = constructor_1)] pub struct OutOfLineAssign { pub s: SeesThis, pub v: i32, pub w: Vec, } -impl ConstructibleFromUnsafe<()> for OutOfLineAssign { - unsafe fn constructor(this: *mut Self, _: ()) { - >::constructor(&raw mut (*this).s, ()); +impl OutOfLineAssign { + pub unsafe fn constructor_1(this: *mut Self) { + SeesThis::constructor_1(&raw mut (*this).s); (&raw mut (*this).v).write(1); (&raw mut (*this).w).write(Vec::new()); } @@ -612,7 +584,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, Explicit, (i32,), (1,)); + object_unsafe!(a, Explicit::constructor_1(1)); let mut b: Explicit = a.clone(); let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { DestructibleUnsafe::destroy(__p) @@ -629,12 +601,12 @@ unsafe fn main_0() -> i32 { ((unsafe { same_0(&b, &a,) }) && (unsafe { same_0(&c, &a,) })) && (unsafe { same_0(&d, &a,) }) ); - object_unsafe!(e, Explicit, (i32,), (2,)); - object_unsafe!(f, Explicit, (i32,), (3,)); + object_unsafe!(e, Explicit::constructor_1(2)); + object_unsafe!(f, Explicit::constructor_1(3)); assign_unsafe!(e = b); assign_unsafe!(f = RvalueRefUnsafe(c)); assert!((unsafe { same_0(&e, &b,) }) && (unsafe { same_0(&f, &c,) })); - object_unsafe!(g, Explicit, (i32,), (4,)); + object_unsafe!(g, Explicit::constructor_1(4)); assign_unsafe!(g = (*assign_unsafe!(e = f))); assert!((unsafe { same_0(&g, &f,) }) && (unsafe { same_0(&e, &f,) })); let mut i: Implicit = Implicit { @@ -656,48 +628,52 @@ unsafe fn main_0() -> i32 { let mut vec_: Vec = Vec::new(); vec_.push_copied(&mut b); match ((&mut { - let mut __v: Explicit = ::zero_init(); - >::constructor(&raw mut __v, (9,)); + let mut __v: Explicit = ZeroInitializationUnsafe::zero_init(); + Explicit::constructor_1(&raw mut __v, 9); __v } as *mut Explicit),) { (__tmp_0,) => vec_.push_moved(__tmp_0), }; assert!(((vec_[(0_usize)].v) == (1)) && ((vec_[(1_usize)].v) == (9))); - object_unsafe!(m, DefaultCopyUserMove, (i32,), (7,)); + object_unsafe!(m, DefaultCopyUserMove::constructor_1(7)); let mut m1: DefaultCopyUserMove = m; object_unsafe!( m2, - DefaultCopyUserMove = >::bind(&mut m) + DefaultCopyUserMove::constructor_3(RvalueRefUnsafe::bind(&mut m)) ); assert!((((m1.v) == (7)) && ((m2.v) == (7))) && ((m.v) == (0))); - object_unsafe!(m3, DefaultCopyUserMove, (i32,), (1,)); - object_unsafe!(m4, DefaultCopyUserMove, (i32,), (1,)); + object_unsafe!(m3, DefaultCopyUserMove::constructor_1(1)); + object_unsafe!(m4, DefaultCopyUserMove::constructor_1(1)); assign_unsafe!(m3 = m1); assign_unsafe!(m4 = RvalueRefUnsafe(m1)); assert!((((m3.v) == (7)) && ((m4.v) == (7))) && ((m1.v) == (0))); - object_unsafe!(u, UserCopyDefaultMove, (i32,), (8,)); + object_unsafe!(u, UserCopyDefaultMove::constructor_1(8)); object_unsafe!( u1, - UserCopyDefaultMove = >>::bind(&u) - ); - object_unsafe!( - u2, - UserCopyDefaultMove = >::bind(&mut u) + UserCopyDefaultMove::constructor_2(LvalueRefUnsafe::bind(&u)) ); + object_unsafe!(u2, UserCopyDefaultMove, |u2| { + ::move_constructor( + u2, + RvalueRefUnsafe::bind(&mut u), + ) + }); assert!((((u1.v) == (108)) && ((u2.v) == (8))) && ((u.v) == (8))); - object_unsafe!(u3, UserCopyDefaultMove, (i32,), (1,)); - object_unsafe!(u4, UserCopyDefaultMove, (i32,), (1,)); + object_unsafe!(u3, UserCopyDefaultMove::constructor_1(1)); + object_unsafe!(u4, UserCopyDefaultMove::constructor_1(1)); assign_unsafe!(u3 = u2); assign_unsafe!(u4 = RvalueRefUnsafe(u2)); assert!(((u3.v) == (108)) && ((u4.v) == (8))); - object_unsafe!(p, Buffer, (i32,), (3,)); - object_unsafe!(q, Buffer = >::bind(&mut p)); + object_unsafe!(p, Buffer::constructor_1(3)); + object_unsafe!(q, Buffer, |q| { + ::move_constructor(q, 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, (i32,), (1,)); + object_unsafe!(r, Buffer::constructor_1(1)); assign_unsafe!(r = RvalueRefUnsafe(q)); assert!( ((((r.n) == (3)) && ((r.data.len()) == (3_usize))) && ((r.arr[(1) as usize]) == (4))) @@ -712,10 +688,10 @@ unsafe fn main_0() -> i32 { { let mut __tmp_1 = { { - let mut __v: Buffer = ::zero_init(); - ,)>>::constructor( + let mut __v: Buffer = ZeroInitializationUnsafe::zero_init(); + ::move_constructor( &raw mut __v, - (RvalueRefUnsafe::bind(&mut bufs[(0_usize)]),), + RvalueRefUnsafe::bind(&mut bufs[(0_usize)]), ); __v } @@ -726,7 +702,7 @@ unsafe fn main_0() -> i32 { (((bufs[(1_usize)].n) == (3)) && ((bufs[(1_usize)].data.len()) == (3_usize))) && (bufs[(0_usize)].data.is_empty()) ); - object_unsafe!(o1, Owner); + object_unsafe!(o1, Owner::constructor_1()); { let mut __tmp_2: i32 = 5; o1.data.push_moved(&mut __tmp_2) @@ -742,7 +718,9 @@ unsafe fn main_0() -> i32 { Some(Box::from_raw(__tmp_3)) } }; - object_unsafe!(o2, Owner = >::bind(&mut o1)); + object_unsafe!(o2, Owner, |o2| { + ::move_constructor(o2, RvalueRefUnsafe::bind(&mut o1)) + }); assert!( ((((o2.n) == (5)) && ((o2.data.len()) == (1_usize))) && ((o2.arr[(1) as usize]) == (6))) && ((*o2 @@ -759,7 +737,7 @@ unsafe fn main_0() -> i32 { .map_or(::std::ptr::null_mut(), |v| v as *mut i32)) .is_null()) ); - object_unsafe!(o3, Owner); + object_unsafe!(o3, Owner::constructor_1()); assign_unsafe!(o3 = RvalueRefUnsafe(o2)); assert!( ((((o3.n) == (5)) && ((o3.data[(0_usize)]) == (5))) && ((o3.arr[(0) as usize]) == (5))) @@ -781,13 +759,15 @@ unsafe fn main_0() -> i32 { data: Vec::from([1, 2]), }; let mut c2: Copyable = c1.clone(); - object_unsafe!(c3, Copyable = >::bind(&mut c1)); + object_unsafe!(c3, Copyable, |c3| { + ::move_constructor(c3, RvalueRefUnsafe::bind(&mut c1)) + }); assert!(((c2.data.len()) == (2_usize)) && ((c3.data.len()) == (2_usize))); assert!(c1.data.is_empty()); - object_unsafe!(c4, Copyable); + object_unsafe!(c4, Copyable::constructor_1()); assign_unsafe!(c4 = RvalueRefUnsafe(c3)); assert!(((c4.data[(1_usize)]) == (2)) && (c3.data.is_empty())); - object_unsafe!(h1, Holder, (i32,), (4,)); + object_unsafe!(h1, Holder::constructor_1(4)); { let mut __tmp_4 = { (Box::leak(Box::new(9)) as *mut i32) }; h1.p = if __tmp_4.is_null() { @@ -796,7 +776,9 @@ unsafe fn main_0() -> i32 { Some(Box::from_raw(__tmp_4)) } }; - object_unsafe!(h2, Holder = >::bind(&mut h1)); + object_unsafe!(h2, Holder, |h2| { + ::move_constructor(h2, RvalueRefUnsafe::bind(&mut h1)) + }); assert!( ((((h2.inner.x) == (4)) && ((h2.e.v) == (4))) && ((*h2 @@ -810,7 +792,7 @@ unsafe fn main_0() -> i32 { .map_or(::std::ptr::null_mut(), |v| v as *mut i32)) .is_null()) ); - object_unsafe!(h3, Holder, (i32,), (1,)); + object_unsafe!(h3, Holder::constructor_1(1)); assign_unsafe!(h3 = RvalueRefUnsafe(h2)); assert!( ((((h3.inner.x) == (4)) && ((h3.e.arr[(1) as usize]) == (5))) @@ -825,42 +807,57 @@ unsafe fn main_0() -> i32 { .map_or(::std::ptr::null_mut(), |v| v as *mut i32)) .is_null()) ); - object_unsafe!(t1, HasSeesThis); - object_unsafe!(t2, HasSeesThis); - object_unsafe!(t3, HasSeesThis); + object_unsafe!(t1, HasSeesThis::constructor_1()); + object_unsafe!(t2, HasSeesThis::constructor_1()); + object_unsafe!(t3, HasSeesThis::constructor_1()); 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, RvalueRefUnsafe::bind(&mut k1)); + object_unsafe!(k1, HasCounted::constructor_1()); + object_unsafe!(k2, HasCounted, |k2| { + ::move_constructor( + k2, + RvalueRefUnsafe::bind(&mut k1), + ) + }); assert!(((k2.c.moves) == (1))); - object_unsafe!(k3, HasCounted); + object_unsafe!(k3, HasCounted::constructor_1()); assign_unsafe!(k3 = RvalueRefUnsafe(k2)); assert!(((k3.c.moves) == (2))); { - object_unsafe!(d, CtorSeesThis); + object_unsafe!(d, CtorSeesThis::constructor_1()); assert!(((d.self_) == (&mut d as *mut CtorSeesThis))); - object_unsafe!(e, CtorSeesThis, LvalueRefUnsafe::bind(&d)); + object_unsafe!(e, CtorSeesThis::constructor_3(LvalueRefUnsafe::bind(&d))); assert!(((e.self_) == (&mut e as *mut CtorSeesThis))); - object_unsafe!(f, CtorSeesThis, (i32,), (3,)); + object_unsafe!(f, CtorSeesThis::constructor_2(3)); assert!(((f.self_) == (&mut f as *mut CtorSeesThis)) && ((f.id) == (3))); - object_unsafe!(h1, HasCtorSeesThis); + object_unsafe!(h1, HasCtorSeesThis::constructor_1()); assert!(((h1.x.self_) == (&mut h1.x as *mut CtorSeesThis))); - object_unsafe!(h2, HasCtorSeesThis, LvalueRefUnsafe::bind(&h1)); + object_unsafe!(h2, HasCtorSeesThis, |h2| { + ::copy_constructor( + h2, + LvalueRefUnsafe::bind(&h1), + ) + }); assert!(((h2.x.self_) == (&mut h2.x as *mut CtorSeesThis))); - object_unsafe!(h3, HasCtorSeesThis, RvalueRefUnsafe::bind(&mut h1)); + object_unsafe!(h3, HasCtorSeesThis, |h3| { + ::move_constructor( + h3, + RvalueRefUnsafe::bind(&mut h1), + ) + }); assert!(((h3.x.self_) == (&mut h3.x as *mut CtorSeesThis))); 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))); - object_unsafe!(i, InitsCtorSeesThis); + object_unsafe!(i, InitsCtorSeesThis::constructor_1()); assert!(((i.x.self_) == (&mut i.x as *mut CtorSeesThis)) && ((i.x.id) == (1))); assert!(((i.y.self_) == (&mut i.y as *mut CtorSeesThis)) && ((i.y.id) == (2))); let mut p: *mut CtorSeesThis = { let __p: *mut CtorSeesThis = Box::leak(Box::new(::zero_init())); - >::constructor(__p, (4,)); + CtorSeesThis::constructor_2(__p, 4); __p }; assert!((((*p).self_) == (p)) && (((*p).id) == (4))); @@ -873,11 +870,14 @@ 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, LvalueRefUnsafe::bind(&o1)); + object_unsafe!( + o2, + OutOfLineDefaulted::constructor_2(LvalueRefUnsafe::bind(&o1)) + ); assert!(((o2.v) == (2)) && ((o2.x.self_) == (&mut o2.x as *mut CtorSeesThis))); - object_unsafe!(a1, OutOfLineAssign); - object_unsafe!(a2, OutOfLineAssign); - object_unsafe!(a3, OutOfLineAssign); + object_unsafe!(a1, OutOfLineAssign::constructor_1()); + object_unsafe!(a2, OutOfLineAssign::constructor_1()); + object_unsafe!(a3, OutOfLineAssign::constructor_1()); a1.v = 3; { let mut __tmp_5: i32 = 4; diff --git a/tests/unit/out/unsafe/copy_move_deleted.rs b/tests/unit/out/unsafe/copy_move_deleted.rs index b9f0d71f5d..16b949fe3a 100644 --- a/tests/unit/out/unsafe/copy_move_deleted.rs +++ b/tests/unit/out/unsafe/copy_move_deleted.rs @@ -15,26 +15,21 @@ use std::rc::Rc; Default, ConversionsUnsafe, )] -#[conversions(move)] -#[constructor(value(i32))] +#[conversions(move = constructor_3)] +#[constructor(constructor_1, value(i32))] pub struct NoCopy { pub v: i32, } -impl ConstructibleFromUnsafe<(i32,)> for NoCopy { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl NoCopy { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for NoCopy { - unsafe fn constructor(this: *mut Self, (o,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut NoCopy); (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } -impl MoveConstructibleUnsafe for NoCopy {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} impl MoveAssignableUnsafe for NoCopy { unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut NoCopy { let o = (o.as_ptr() as *mut NoCopy); @@ -47,24 +42,20 @@ impl MoveAssignableUnsafe for NoCopy { #[derive( FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move = constructor_3, default = constructor_2)] pub struct PrivateCopy { pub v: i32, } -impl ConstructibleFromUnsafe<()> for PrivateCopy { - unsafe fn constructor(this: *mut Self, _: ()) { +impl PrivateCopy { + pub unsafe fn constructor_2(this: *mut Self) { (&raw mut (*this).v).write(0); } -} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for PrivateCopy { - unsafe fn constructor(this: *mut Self, (o,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut PrivateCopy); (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } -impl MoveConstructibleUnsafe for PrivateCopy {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} impl MoveAssignableUnsafe for PrivateCopy { unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut PrivateCopy { let o = (o.as_ptr() as *mut PrivateCopy); @@ -77,8 +68,8 @@ impl Default for PrivateCopy { fn default() -> Self { unsafe { { - let mut __v: PrivateCopy = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: PrivateCopy = ZeroInitializationUnsafe::zero_init(); + PrivateCopy::constructor_2(&raw mut __v); __v } } @@ -86,11 +77,12 @@ impl Default for PrivateCopy { } #[repr(C)] #[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] +#[conversions(default = constructor_1)] pub struct Immovable { pub v: i32, } -impl ConstructibleFromUnsafe<()> for Immovable { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Immovable { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write(0); } } @@ -98,8 +90,8 @@ impl Default for Immovable { fn default() -> Self { unsafe { { - let mut __v: Immovable = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Immovable = ZeroInitializationUnsafe::zero_init(); + Immovable::constructor_1(&raw mut __v); __v } } @@ -121,6 +113,7 @@ pub struct Container { pub inner: NoCopy, pub tag: i32, } +impl Container {} #[repr(C)] #[derive( FnPtrArg, @@ -132,12 +125,12 @@ pub struct Container { )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] pub struct VecHolder { pub items: Vec, } -impl ConstructibleFromUnsafe<()> for VecHolder { - unsafe fn constructor(this: *mut Self, _: ()) { +impl VecHolder { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).items).write(Vec::new()); } } @@ -154,36 +147,40 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, NoCopy, (i32,), (1,)); - object_unsafe!(b, NoCopy, RvalueRefUnsafe::bind(&mut a)); + object_unsafe!(a, NoCopy::constructor_1(1)); + object_unsafe!(b, NoCopy::constructor_3(RvalueRefUnsafe::bind(&mut a))); assert!(((b.v) == (1)) && ((a.v) == (0))); 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); + object_unsafe!(p, PrivateCopy::constructor_2()); p.v = 3; - object_unsafe!(q, PrivateCopy, RvalueRefUnsafe::bind(&mut p)); + object_unsafe!(q, PrivateCopy::constructor_3(RvalueRefUnsafe::bind(&mut p))); assert!(((q.v) == (3)) && ((p.v) == (0))); assign_unsafe!(p = RvalueRefUnsafe(q)); assert!(((p.v) == (3)) && ((q.v) == (0))); - object_unsafe!(im, Immovable); + object_unsafe!(im, Immovable::constructor_1()); im.v = 4; (unsafe { bump_ref_1(&mut im) }); let mut pim: *mut Immovable = (&mut im as *mut Immovable); assert!((((*pim).v) == (5))); let mut c: Container = Container { inner: { - let mut __v: NoCopy = ::zero_init(); - >::constructor(&raw mut __v, (6,)); + let mut __v: NoCopy = ZeroInitializationUnsafe::zero_init(); + NoCopy::constructor_1(&raw mut __v, 6); __v }, tag: 7, }; - object_unsafe!(d, Container, RvalueRefUnsafe::bind(&mut c)); + object_unsafe!(d, Container, |d| { + ::move_constructor(d, RvalueRefUnsafe::bind(&mut c)) + }); assert!((((d.inner.v) == (6)) && ((d.tag) == (7))) && ((c.inner.v) == (0))); - object_unsafe!(h, VecHolder); - object_unsafe!(h2, VecHolder, RvalueRefUnsafe::bind(&mut h)); + object_unsafe!(h, VecHolder::constructor_1()); + object_unsafe!(h2, VecHolder, |h2| { + ::move_constructor(h2, RvalueRefUnsafe::bind(&mut h)) + }); assert!(((h2.items.len()) == (0_usize))); return 0; } @@ -192,7 +189,7 @@ impl CopyAssignableUnsafe for PrivateCopy { unreachable!("PrivateCopy::copy_assign is never defined") } } -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for PrivateCopy { +impl ConstructorUnsafe<(LvalueRefUnsafe>,)> for PrivateCopy { unsafe fn constructor(this: *mut Self, _: (LvalueRefUnsafe>,)) { unreachable!("PrivateCopy::copy_constructor is never defined") } diff --git a/tests/unit/out/unsafe/default_function_arguments.rs b/tests/unit/out/unsafe/default_function_arguments.rs index 4480dd3cd2..cfd9b820e9 100644 --- a/tests/unit/out/unsafe/default_function_arguments.rs +++ b/tests/unit/out/unsafe/default_function_arguments.rs @@ -23,20 +23,19 @@ pub unsafe fn baz_1(mut a: *mut i32, mut b: *mut i32) -> bool { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] pub struct Bar { pub v: i32, } -impl ConstructibleFromUnsafe<(i32,)> for Bar { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl Bar { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } } -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<()> for Bar { +impl ConstructorUnsafe<()> for Bar { unsafe fn constructor(this: *mut Self, _: ()) { unsafe { - >::constructor(this, (1,)); + Bar::constructor_1(this, 1); } } } @@ -44,8 +43,8 @@ impl Default for Bar { fn default() -> Self { unsafe { { - let mut __v: Bar = ::zero_init(); - >::constructor(&raw mut __v, (1,)); + let mut __v: Bar = ZeroInitializationUnsafe::zero_init(); + Bar::constructor_1(&raw mut __v, 1); __v } } @@ -63,8 +62,8 @@ pub unsafe fn by_ref_5(b: *const Bar) -> i32 { } pub static mut global_bar_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __v: Bar = ::zero_init(); - >::constructor(&raw mut __v, (9,)); + let mut __v: Bar = ZeroInitializationUnsafe::zero_init(); + Bar::constructor_1(&raw mut __v, 9); __v } }); @@ -90,12 +89,12 @@ pub unsafe fn first_9(r: *mut [i32; 3]) -> i32 { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(explicit, value(i32))] +#[constructor(constructor_1, explicit, value(i32))] pub struct Holder_int_ { pub v: i32, } -impl ConstructibleFromUnsafe<(i32,)> for Holder_int_ { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl Holder_int_ { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } } @@ -121,13 +120,13 @@ unsafe fn main_0() -> i32 { }) as i32) == (true as i32)) ); - object_unsafe!(b, Bar, (i32,), (1,)); + object_unsafe!(b, Bar::constructor_1(1)); assert!(((b.v) == (1))); { - let mut __tmp_0: Bar = ::zero_init(); + let mut __tmp_0: Bar = ZeroInitializationUnsafe::zero_init(); assert!( (((*{ - >::constructor(&raw mut __tmp_0, (2,)); + Bar::constructor_1(&raw mut __tmp_0, 2); &mut __tmp_0 }) .v) == (2)) @@ -135,18 +134,18 @@ unsafe fn main_0() -> i32 { }; let mut arr: [Bar; 3] = [ { - let mut __v: Bar = ::zero_init(); - >::constructor(&raw mut __v, (1,)); + let mut __v: Bar = ZeroInitializationUnsafe::zero_init(); + Bar::constructor_1(&raw mut __v, 1); __v }, { - let mut __v: Bar = ::zero_init(); - >::constructor(&raw mut __v, (1,)); + let mut __v: Bar = ZeroInitializationUnsafe::zero_init(); + Bar::constructor_1(&raw mut __v, 1); __v }, { - let mut __v: Bar = ::zero_init(); - >::constructor(&raw mut __v, (1,)); + let mut __v: Bar = ZeroInitializationUnsafe::zero_init(); + Bar::constructor_1(&raw mut __v, 1); __v }, ]; @@ -158,15 +157,15 @@ unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut counter_2)) == (1))); assert!( ((unsafe { - let mut _b: Bar = ::zero_init(); - >::constructor(&raw mut _b, (7,)); + let mut _b: Bar = ZeroInitializationUnsafe::zero_init(); + Bar::constructor_1(&raw mut _b, 7); by_ref_5(&mut _b) }) == (7)) ); assert!( ((unsafe { - let mut _b: Bar = ::zero_init(); - >::constructor(&raw mut _b, (3,)); + let mut _b: Bar = ZeroInitializationUnsafe::zero_init(); + Bar::constructor_1(&raw mut _b, 3); by_ref_5(&mut _b) }) == (3)) ); @@ -177,12 +176,12 @@ unsafe fn main_0() -> i32 { ); assert!( ((unsafe { - let mut _b: Bar = ::zero_init(); - >::constructor(&raw mut _b, (4,)); + let mut _b: Bar = ZeroInitializationUnsafe::zero_init(); + Bar::constructor_1(&raw mut _b, 4); by_global_ref_7(&mut _b) }) == (4)) ); - object_unsafe!(h, Holder_int_, (i32,), (4,)); + object_unsafe!(h, Holder_int_::constructor_1(4)); assert!(((h.v) == (4))); assert!(((unsafe { shifted_8(3, -1_i32,) }) == (2))); assert!(((unsafe { shifted_8(3, 4,) }) == (7))); diff --git a/tests/unit/out/unsafe/delete_array_order.rs b/tests/unit/out/unsafe/delete_array_order.rs index 49713f23e3..b8aa1f021b 100644 --- a/tests/unit/out/unsafe/delete_array_order.rs +++ b/tests/unit/out/unsafe/delete_array_order.rs @@ -19,7 +19,7 @@ use std::rc::Rc; )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy, move)] pub struct Element { pub id: i64, pub value: i64, diff --git a/tests/unit/out/unsafe/destructor.rs b/tests/unit/out/unsafe/destructor.rs index c4907e839b..1dcde266d8 100644 --- a/tests/unit/out/unsafe/destructor.rs +++ b/tests/unit/out/unsafe/destructor.rs @@ -20,7 +20,7 @@ pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new(|| )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy, move)] pub struct S {} impl DestructibleUnsafe for S { unsafe fn destroy(this: *mut Self) { @@ -41,7 +41,7 @@ impl DestructibleUnsafe for S { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy, move)] pub struct Defaulted { #[destroy] pub s: S, @@ -119,7 +119,7 @@ pub struct ArrayMember { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy, move)] pub struct EmptyBody { pub s: S, } @@ -141,7 +141,7 @@ impl DestructibleUnsafe for EmptyBody { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy, move)] pub struct Templated_char_ { pub v: libc::c_char, } @@ -165,7 +165,7 @@ impl DestructibleUnsafe for Templated_char_ { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy, move)] pub struct Templated_int_ { pub v: i32, } @@ -189,7 +189,7 @@ impl DestructibleUnsafe for Templated_int_ { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy, move)] pub struct Copied { pub v: i32, } @@ -214,7 +214,7 @@ pub static mut order_count_2: std::cell::LazyCell = std::cell::LazyCell::ne )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy, move)] pub struct Tagged { pub tag: i32, } diff --git a/tests/unit/out/unsafe/destructor_params.rs b/tests/unit/out/unsafe/destructor_params.rs index ef9ce74787..fc207ea492 100644 --- a/tests/unit/out/unsafe/destructor_params.rs +++ b/tests/unit/out/unsafe/destructor_params.rs @@ -21,7 +21,7 @@ pub static mut last_1: std::cell::LazyCell = std::cell::LazyCell::new(|| un )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy, move)] pub struct S { pub v: i32, } @@ -51,20 +51,18 @@ pub unsafe fn with_default_3(s: *mut S) -> i32 { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(explicit, by_value(S))] +#[constructor(constructor_1, explicit, by_value(S))] pub struct Holder { pub v: i32, } impl Holder { - pub unsafe fn add(this: *const Self, s: *mut S) -> i32 { - return (((*this).v) + ((*s).v)); - } -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe,)> for Holder { - unsafe fn constructor(this: *mut Self, (s,): (LvalueRefUnsafe,)) { + pub unsafe fn constructor_1(this: *mut Self, s: LvalueRefUnsafe) { let s = (s.as_ptr() as *mut S); (&raw mut (*this).v).write((*s).v); } + pub unsafe fn add(this: *const Self, s: *mut S) -> i32 { + return (((*this).v) + ((*s).v)); + } } pub fn main() { unsafe { @@ -116,10 +114,7 @@ unsafe fn main_0() -> i32 { { object_unsafe!(h, Holder, |h| { let mut __tmp_0: S = S { v: 3 }; - ,)>>::constructor( - h, - (LvalueRefUnsafe::bind(&mut __tmp_0),), - ) + Holder::constructor_1(h, LvalueRefUnsafe::bind(&mut __tmp_0)) }); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1)) diff --git a/tests/unit/out/unsafe/destructor_temporaries.rs b/tests/unit/out/unsafe/destructor_temporaries.rs index 1acd356afc..0e731484ef 100644 --- a/tests/unit/out/unsafe/destructor_temporaries.rs +++ b/tests/unit/out/unsafe/destructor_temporaries.rs @@ -21,7 +21,7 @@ pub static mut last_1: std::cell::LazyCell = std::cell::LazyCell::new(|| un )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy, move)] pub struct S { pub v: i32, } @@ -83,7 +83,7 @@ pub fn main() { } unsafe fn main_0() -> i32 { { - let mut __v: S = ::zero_init(); + let mut __v: S = ZeroInitializationUnsafe::zero_init(); (unsafe { make_2(&raw mut __v, 1) }); }; assert!( @@ -92,7 +92,7 @@ unsafe fn main_0() -> i32 { ); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; &({ - let mut __v: S = ::zero_init(); + let mut __v: S = ZeroInitializationUnsafe::zero_init(); (unsafe { make_2(&raw mut __v, 2) }); }); assert!( @@ -101,7 +101,7 @@ unsafe fn main_0() -> i32 { ); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; let mut x: i32 = { - let mut __tmp_0: S = ::zero_init(); + let mut __tmp_0: S = ZeroInitializationUnsafe::zero_init(); (*{ (unsafe { make_2(&raw mut __tmp_0, 3) }); &mut __tmp_0 @@ -114,7 +114,7 @@ unsafe fn main_0() -> i32 { ); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; { - let mut __tmp_1: S = ::zero_init(); + let mut __tmp_1: S = ZeroInitializationUnsafe::zero_init(); x = (unsafe { S::get( &(*{ @@ -130,7 +130,7 @@ unsafe fn main_0() -> i32 { ); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; { - let mut __tmp_2: Outer = ::zero_init(); + let mut __tmp_2: Outer = ZeroInitializationUnsafe::zero_init(); x = (*{ (unsafe { make_outer_3(&raw mut __tmp_2) }); &mut __tmp_2 @@ -147,7 +147,7 @@ unsafe fn main_0() -> i32 { assert!(((x) == (5)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1))); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; x = (unsafe { - let mut _s: S = ::zero_init(); + let mut _s: S = ZeroInitializationUnsafe::zero_init(); (unsafe { make_2(&raw mut _s, 6) }); use_4(&mut _s) }); @@ -167,7 +167,7 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; x = (if ((x) == (3)) { { - let mut __v: S = ::zero_init(); + let mut __v: S = ZeroInitializationUnsafe::zero_init(); (unsafe { make_2(&raw mut __v, 9) }); __v } @@ -181,7 +181,7 @@ unsafe fn main_0() -> i32 { ); (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; { - let mut __tmp_3: S = ::zero_init(); + let mut __tmp_3: S = ZeroInitializationUnsafe::zero_init(); (unsafe { make_2(&raw mut __tmp_3, 11) }); let r: *const S = &mut __tmp_3; assert!( @@ -200,7 +200,7 @@ unsafe fn main_0() -> i32 { DestructibleUnsafe::destroy(__p) }); (unsafe { - let mut _arg0: S = ::zero_init(); + let mut _arg0: S = ZeroInitializationUnsafe::zero_init(); (unsafe { make_2(&raw mut _arg0, 13) }); assign_unsafe!(s = _arg0) }); diff --git a/tests/unit/out/unsafe/emplace_receiver_alias.rs b/tests/unit/out/unsafe/emplace_receiver_alias.rs index 01452cf76e..56d855dadc 100644 --- a/tests/unit/out/unsafe/emplace_receiver_alias.rs +++ b/tests/unit/out/unsafe/emplace_receiver_alias.rs @@ -34,9 +34,9 @@ unsafe fn main_0() -> i32 { let mut __it = __tmp_0; while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { __v.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/emplace_receiver_order.rs b/tests/unit/out/unsafe/emplace_receiver_order.rs index cf41e8c7c2..5f7496e063 100644 --- a/tests/unit/out/unsafe/emplace_receiver_order.rs +++ b/tests/unit/out/unsafe/emplace_receiver_order.rs @@ -42,9 +42,9 @@ unsafe fn main_0() -> i32 { let mut __it = __tmp_0; while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { __v.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } @@ -70,9 +70,9 @@ unsafe fn main_0() -> i32 { while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_4) { __v.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/enum_underlying_type.rs b/tests/unit/out/unsafe/enum_underlying_type.rs index 92d5490b99..2f0ca24cb5 100644 --- a/tests/unit/out/unsafe/enum_underlying_type.rs +++ b/tests/unit/out/unsafe/enum_underlying_type.rs @@ -35,12 +35,12 @@ pub type Empty = bool; TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct HoldsEmpty { pub e: Empty, } -impl ConstructibleFromUnsafe<()> for HoldsEmpty { - unsafe fn constructor(this: *mut Self, _: ()) { +impl HoldsEmpty { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).e).write(false); } } @@ -82,7 +82,7 @@ unsafe fn main_0() -> i32 { let mut sc: Scoped = Scoped_NEG; assert!(((sc as i32) == (-2_i32))); assert!((((Scoped_POS as i8) as i32) == (2))); - object_unsafe!(he, HoldsEmpty); + object_unsafe!(he, HoldsEmpty::constructor_1()); assert!(!(he.e)); let mut ev: Empty = false; assert!(((ev as i32) == (he.e as i32))); diff --git a/tests/unit/out/unsafe/field_method_receiver.rs b/tests/unit/out/unsafe/field_method_receiver.rs index b964cf23ae..7ac18d1268 100644 --- a/tests/unit/out/unsafe/field_method_receiver.rs +++ b/tests/unit/out/unsafe/field_method_receiver.rs @@ -51,7 +51,7 @@ impl Counter { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct S { pub tag: i32, pub c: Counter, @@ -65,9 +65,7 @@ impl S { Counter::add(&raw mut (*this).c, _k) }); } -} -impl ConstructibleFromUnsafe<()> for S { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).tag).write(0_i32); (&raw mut (*this).c).write(::default()); (&raw mut (*this).arr).write([::default(); 2]); diff --git a/tests/unit/out/unsafe/field_pointers.rs b/tests/unit/out/unsafe/field_pointers.rs index 40fb93775b..cab26031a4 100644 --- a/tests/unit/out/unsafe/field_pointers.rs +++ b/tests/unit/out/unsafe/field_pointers.rs @@ -54,7 +54,7 @@ pub struct Header { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Outer { pub x: i32, pub inner: Inner, @@ -76,9 +76,7 @@ impl Outer { (*this).v.push_moved(&mut __tmp_0) }; } -} -impl ConstructibleFromUnsafe<()> for Outer { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).x).write(0_i32); (&raw mut (*this).inner).write(::default()); (&raw mut (*this).items).write([::default(); 3]); diff --git a/tests/unit/out/unsafe/fn_ptr.rs b/tests/unit/out/unsafe/fn_ptr.rs index 899b903a3a..6c55379747 100644 --- a/tests/unit/out/unsafe/fn_ptr.rs +++ b/tests/unit/out/unsafe/fn_ptr.rs @@ -47,21 +47,15 @@ pub unsafe fn identity_hash_6(mut v: bool) -> usize { pub struct HashHolder_unsigned_long__ptr__bool__ { pub h: Option u64>, } -impl ConstructibleFromUnsafe<(LvalueRefUnsafe u64>>>,)> - for HashHolder_unsigned_long__ptr__bool__ -{ - unsafe fn constructor( +impl HashHolder_unsigned_long__ptr__bool__ { + pub unsafe fn constructor_1( this: *mut Self, - (h,): (LvalueRefUnsafe u64>>>,), + h: LvalueRefUnsafe u64>>>, ) { let h = (h.as_ptr() as *const Option u64>); (&raw mut (*this).h).write((*h)); } } -impl ConvertibleToUnsafe - for LvalueRefUnsafe u64>>> -{ -} pub static mut total_7: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub unsafe fn add_to_total_8(mut x: i32) { (*std::cell::LazyCell::force_mut(&mut *&raw mut total_7)) += x; @@ -109,9 +103,10 @@ unsafe fn main_0() -> i32 { Option usize>, Option u64>, >(Some(identity_hash_6)); - u64>>>, - )>>::constructor(hh, (LvalueRefUnsafe::bind(&mut __tmp_0),)) + HashHolder_unsigned_long__ptr__bool__::constructor_1( + hh, + LvalueRefUnsafe::bind(&mut __tmp_0), + ) }); assert!(((unsafe { (hh.h).unwrap()(true,) }) == (1_u64))); let mut handler: Option = Some(add_to_total_8); diff --git a/tests/unit/out/unsafe/fn_ptr_struct.rs b/tests/unit/out/unsafe/fn_ptr_struct.rs index 70ff57d1a8..dcc62c8a18 100644 --- a/tests/unit/out/unsafe/fn_ptr_struct.rs +++ b/tests/unit/out/unsafe/fn_ptr_struct.rs @@ -58,39 +58,32 @@ impl S { #[derive( FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[conversions(move)] -#[constructor(value(i32))] +#[conversions(move = constructor_2)] +#[constructor(constructor_1, value(i32))] pub struct MoveOnly { pub data_: i32, } impl MoveOnly { - pub unsafe fn get(this: *const Self) -> i32 { - return (*this).data_; - } -} -impl ConstructibleFromUnsafe<(i32,)> for MoveOnly { - unsafe fn constructor(this: *mut Self, (mut data,): (i32,)) { + pub unsafe fn constructor_1(this: *mut Self, mut data: i32) { (&raw mut (*this).data_).write(data); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for MoveOnly { - unsafe fn constructor(this: *mut Self, (x,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_2(this: *mut Self, x: RvalueRefUnsafe) { let x = (x.as_ptr() as *mut MoveOnly); (&raw mut (*this).data_).write((*x).data_); (*x).data_ = 0; } + pub unsafe fn get(this: *const Self) -> i32 { + return (*this).data_; + } } -impl MoveConstructibleUnsafe for MoveOnly {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} pub unsafe fn make_move_only_2(__return: *mut MoveOnly) { - ConvertibleToUnsafe::convert(4, __return); + MoveOnly::constructor_1(__return, 4); return; } pub unsafe fn scale_move_only_3(__return: *mut MoveOnly, x: *mut MoveOnly) { - ConvertibleToUnsafe::convert( - ((unsafe { MoveOnly::get(&raw const (*x)) }) * (10)), + MoveOnly::constructor_1( __return, + ((unsafe { MoveOnly::get(&raw const (*x)) }) * (10)), ); return; } @@ -130,11 +123,8 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { MoveOnly::get(&raw const m,) }) == (4))); let mut sc: Option = Some(scale_move_only_3); object_unsafe!(n, MoveOnly, |n| (unsafe { - let mut _arg0: MoveOnly = ::zero_init(); - ,)>>::constructor( - &raw mut _arg0, - (RvalueRefUnsafe::bind(&mut m),), - ); + let mut _arg0: MoveOnly = ZeroInitializationUnsafe::zero_init(); + MoveOnly::constructor_2(&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/for_body_destructor.rs b/tests/unit/out/unsafe/for_body_destructor.rs index ab8ff1866b..46185ff8df 100644 --- a/tests/unit/out/unsafe/for_body_destructor.rs +++ b/tests/unit/out/unsafe/for_body_destructor.rs @@ -19,23 +19,23 @@ use std::rc::Rc; )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] -#[conversion_function(bool, const_lvalue_ref, explicit)] +#[conversions(copy, move)] +#[conversion_function(conversion_function_2, bool, const_lvalue_ref, explicit)] pub struct Guard { pub digit: i32, } +impl Guard { + pub unsafe fn conversion_function_2(this: LvalueRefUnsafe>, __return: *mut bool) { + let this = this.as_ptr() as *mut Guard; + __return.write((((*this).digit) != (0))); + return; + } +} impl DestructibleUnsafe for Guard { unsafe fn destroy(this: *mut Self) { (unsafe { libc::printf(c"%d ".as_ptr() as *const libc::c_char, ((*this).digit)) }); } } -impl ConversionFunctionUnsafe>> for Guard { - unsafe fn conversion_function(this: LvalueRefUnsafe>, to: *mut bool) { - let this = this.as_ptr() as *mut Guard; - to.write((((*this).digit) != (0))); - return; - } -} pub unsafe fn step_0(i: *mut i32) { (unsafe { libc::printf(c"9 ".as_ptr() as *const libc::c_char) }); (*i).prefix_inc(); @@ -170,8 +170,8 @@ unsafe fn main_0() -> i32 { DestructibleUnsafe::destroy(__p) }); if !({ - let mut __v: bool = false; - Guard::conversion_function( + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + Guard::conversion_function_2( >>::bind(&mut condition), &raw mut __v, ); diff --git a/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs b/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs index b0fb340b04..ca0e3dba3c 100644 --- a/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs @@ -20,13 +20,13 @@ use std::rc::Rc; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct S { pub v: Vec, pub a: i32, } -impl ConstructibleFromUnsafe<()> for S { - unsafe fn constructor(this: *mut Self, _: ()) { +impl S { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write(Vec::new()); (&raw mut (*this).a).write(0_i32); } @@ -38,7 +38,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(s, S); + object_unsafe!(s, S::constructor_1()); { let mut __tmp_0: i32 = 1; s.v.push_moved(&mut __tmp_0) diff --git a/tests/unit/out/unsafe/forward_basic.rs b/tests/unit/out/unsafe/forward_basic.rs index 62222b6c41..8783419dbe 100644 --- a/tests/unit/out/unsafe/forward_basic.rs +++ b/tests/unit/out/unsafe/forward_basic.rs @@ -13,33 +13,26 @@ pub const Overload_kRvalueOverload: Overload = 2; #[derive( FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] pub struct Tracked { pub v: i32, pub copies: i32, pub moves: i32, } -impl ConstructibleFromUnsafe<(i32,)> for Tracked { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl Tracked { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).copies).write(0); (&raw mut (*this).moves).write(0); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for Tracked { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(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 CopyConstructibleUnsafe for Tracked {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for Tracked { - unsafe fn constructor(this: *mut Self, (o,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_3(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); @@ -47,34 +40,24 @@ impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for Tracked { (*o).v = 0; } } -impl MoveConstructibleUnsafe for Tracked {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} pub unsafe fn chosen_overload_0(_a0: *const Tracked) -> Overload { return Overload_kLvalueOverload; } pub unsafe fn chosen_overload_1(_a0: *mut Tracked) -> Overload { return Overload_kRvalueOverload; } -impl ConstructibleFromUnsafe<(LvalueRefUnsafe,)> for Holder { - unsafe fn constructor(this: *mut Self, (x,): (LvalueRefUnsafe,)) { +impl Holder { + pub unsafe fn constructor_1_1(this: *mut Self, x: LvalueRefUnsafe) { let x = (x.as_ptr() as *mut Tracked); - >,)>>::constructor( - &raw mut (*this).t, - (LvalueRefUnsafe::bind(x),), - ); + Tracked::constructor_2(&raw mut (*this).t, LvalueRefUnsafe::bind(x)); } } -impl ConvertibleToUnsafe for LvalueRefUnsafe {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for Holder { - unsafe fn constructor(this: *mut Self, (x,): (RvalueRefUnsafe,)) { +impl Holder { + pub unsafe fn constructor_1_2(this: *mut Self, x: RvalueRefUnsafe) { let x = (x.as_ptr() as *mut Tracked); - ,)>>::constructor( - &raw mut (*this).t, - (RvalueRefUnsafe::bind(x),), - ); + Tracked::constructor_3(&raw mut (*this).t, RvalueRefUnsafe::bind(x)); } } -impl ConvertibleToUnsafe for RvalueRefUnsafe {} #[repr(C)] #[derive( FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, @@ -82,11 +65,12 @@ impl ConvertibleToUnsafe for RvalueRefUnsafe {} #[memberwise(copy_constructor, move_constructor)] #[derive(ConversionsUnsafe)] #[conversions(copy, move)] -#[constructor(lvalue_ref(Tracked))] -#[constructor(rvalue_ref(Tracked))] +#[constructor(constructor_1_1, lvalue_ref(Tracked))] +#[constructor(constructor_1_2, rvalue_ref(Tracked))] pub struct Holder { pub t: Tracked, } +impl Holder {} pub unsafe fn forward_once_2(x: *mut Tracked) -> Overload { return (unsafe { chosen_overload_0(x) }); } @@ -100,17 +84,11 @@ pub unsafe fn forward_twice_5(x: *mut Tracked) -> Overload { return (unsafe { forward_once_3(x) }); } pub unsafe fn forward_into_ctor_6(__return: *mut Holder, x: *mut Tracked) { - ,)>>::constructor( - __return, - (LvalueRefUnsafe::bind(x),), - ); + Holder::constructor_1_1(__return, LvalueRefUnsafe::bind(x)); return; } pub unsafe fn forward_into_ctor_7(__return: *mut Holder, x: *mut Tracked) { - ,)>>::constructor( - __return, - (RvalueRefUnsafe::bind(x),), - ); + Holder::constructor_1_2(__return, RvalueRefUnsafe::bind(x)); return; } pub fn main() { @@ -120,33 +98,33 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(lvalue, Tracked, (i32,), (7,)); + object_unsafe!(lvalue, Tracked::constructor_1(7)); assert!( (((unsafe { forward_once_2(&mut lvalue,) }) as i32) == (Overload_kLvalueOverload as i32)) ); assert!(((lvalue.v) == (7))); assert!( (((unsafe { - let mut _x: Tracked = ::zero_init(); - >::constructor(&raw mut _x, (8,)); + let mut _x: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _x, 8); forward_once_3(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object_unsafe!(relayed, Tracked, (i32,), (9,)); + object_unsafe!(relayed, Tracked::constructor_1(9)); assert!( (((unsafe { forward_twice_4(&mut relayed,) }) as i32) == (Overload_kLvalueOverload as i32)) ); assert!(((relayed.v) == (9))); assert!( (((unsafe { - let mut _x: Tracked = ::zero_init(); - >::constructor(&raw mut _x, (10,)); + let mut _x: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _x, 10); forward_twice_5(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object_unsafe!(kept, Tracked, (i32,), (11,)); + object_unsafe!(kept, Tracked::constructor_1(11)); object_unsafe!(from_lvalue, Holder, |from_lvalue| (unsafe { forward_into_ctor_6(from_lvalue, &mut kept) })); @@ -155,8 +133,8 @@ unsafe fn main_0() -> i32 { assert!(((from_lvalue.t.moves) == (0))); assert!(((kept.v) == (11))); object_unsafe!(from_rvalue, Holder, |from_rvalue| (unsafe { - let mut _x: Tracked = ::zero_init(); - >::constructor(&raw mut _x, (12,)); + let mut _x: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _x, 12); forward_into_ctor_7(from_rvalue, &mut _x) })); assert!(((from_rvalue.t.v) == (12))); diff --git a/tests/unit/out/unsafe/forward_decltype.rs b/tests/unit/out/unsafe/forward_decltype.rs index 8f1bd6f17d..0839e0ef9a 100644 --- a/tests/unit/out/unsafe/forward_decltype.rs +++ b/tests/unit/out/unsafe/forward_decltype.rs @@ -13,33 +13,26 @@ pub const Overload_kRvalueOverload: Overload = 2; #[derive( FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] pub struct Tracked { pub v: i32, pub copies: i32, pub moves: i32, } -impl ConstructibleFromUnsafe<(i32,)> for Tracked { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl Tracked { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).copies).write(0); (&raw mut (*this).moves).write(0); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for Tracked { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(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 CopyConstructibleUnsafe for Tracked {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for Tracked { - unsafe fn constructor(this: *mut Self, (o,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_3(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); @@ -47,8 +40,6 @@ impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for Tracked { (*o).v = 0; } } -impl MoveConstructibleUnsafe for Tracked {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} pub unsafe fn chosen_overload_0(_a0: *const Tracked) -> Overload { return Overload_kLvalueOverload; } @@ -78,37 +69,37 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, Tracked, (i32,), (3,)); + object_unsafe!(a, Tracked::constructor_1(3)); assert!( (((unsafe { forward_by_decltype_2(&mut a,) }) as i32) == (Overload_kLvalueOverload as i32)) ); assert!(((a.v) == (3))); assert!( (((unsafe { - let mut _x: Tracked = ::zero_init(); - >::constructor(&raw mut _x, (4,)); + let mut _x: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _x, 4); forward_by_decltype_3(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object_unsafe!(b, Tracked, (i32,), (5,)); + object_unsafe!(b, Tracked::constructor_1(5)); assert!( (((unsafe { forward_abbreviated_4(&mut b,) }) as i32) == (Overload_kLvalueOverload as i32)) ); assert!(((b.v) == (5))); assert!( (((unsafe { - let mut _x: Tracked = ::zero_init(); - >::constructor(&raw mut _x, (6,)); + let mut _x: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _x, 6); forward_abbreviated_5(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object_unsafe!(c, Tracked, (i32,), (7,)); + object_unsafe!(c, Tracked::constructor_1(7)); assert!( ((unsafe { - let mut _args_1: Tracked = ::zero_init(); - >::constructor(&raw mut _args_1, (8,)); + let mut _args_1: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _args_1, 8); forward_abbreviated_pack_6(&mut c, &mut _args_1) }) == ((Overload_kLvalueOverload as i32) + (Overload_kRvalueOverload as i32))) ); diff --git a/tests/unit/out/unsafe/forward_explicit.rs b/tests/unit/out/unsafe/forward_explicit.rs index 7fb593c453..6d5bf9e6e4 100644 --- a/tests/unit/out/unsafe/forward_explicit.rs +++ b/tests/unit/out/unsafe/forward_explicit.rs @@ -15,33 +15,26 @@ pub const Overload_kIntRvalueOverload: Overload = 4; #[derive( FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] pub struct Tracked { pub v: i32, pub copies: i32, pub moves: i32, } -impl ConstructibleFromUnsafe<(i32,)> for Tracked { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl Tracked { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).copies).write(0); (&raw mut (*this).moves).write(0); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for Tracked { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(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 CopyConstructibleUnsafe for Tracked {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for Tracked { - unsafe fn constructor(this: *mut Self, (o,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_3(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); @@ -49,8 +42,6 @@ impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for Tracked { (*o).v = 0; } } -impl MoveConstructibleUnsafe for Tracked {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} pub unsafe fn chosen_overload_0(_a0: *const Tracked) -> Overload { return Overload_kLvalueOverload; } @@ -64,7 +55,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) { - ConvertibleToUnsafe::convert(>::bind(t), __return); + Tracked::constructor_3(__return, RvalueRefUnsafe::bind(t)); return; } pub fn main() { @@ -74,33 +65,27 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, Tracked, (i32,), (5,)); + object_unsafe!(a, Tracked::constructor_1(5)); assert!((((unsafe { chosen_overload_0(&a,) }) as i32) == (Overload_kLvalueOverload as i32))); assert!(((a.v) == (5))); assert!( (((unsafe { chosen_overload_1(&mut a,) }) as i32) == (Overload_kRvalueOverload as i32)) ); assert!(((a.v) == (5))); - object_unsafe!(b, Tracked, (i32,), (6,)); + object_unsafe!(b, Tracked::constructor_1(6)); object_unsafe!(moved, Tracked, |moved| (unsafe { - let mut _t: Tracked = ::zero_init(); - ,)>>::constructor( - &raw mut _t, - (RvalueRefUnsafe::bind(&mut b),), - ); + let mut _t: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_3(&raw mut _t, RvalueRefUnsafe::bind(&mut b)); copy_or_move_into_param_4(moved, &mut _t) })); assert!(((moved.v) == (6))); assert!(((moved.copies) == (0))); assert!(((moved.moves) == (2))); assert!(((b.v) == (0))); - object_unsafe!(c, Tracked, (i32,), (7,)); + object_unsafe!(c, Tracked::constructor_1(7)); object_unsafe!(copied, Tracked, |copied| (unsafe { - let mut _t: Tracked = ::zero_init(); - >,)>>::constructor( - &raw mut _t, - (LvalueRefUnsafe::bind(&c),), - ); + let mut _t: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&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 d66aad40ce..88bb315021 100644 --- a/tests/unit/out/unsafe/forward_pack.rs +++ b/tests/unit/out/unsafe/forward_pack.rs @@ -15,33 +15,26 @@ pub const Overload_kIntRvalueOverload: Overload = 4; #[derive( FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] pub struct Tracked { pub v: i32, pub copies: i32, pub moves: i32, } -impl ConstructibleFromUnsafe<(i32,)> for Tracked { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl Tracked { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).copies).write(0); (&raw mut (*this).moves).write(0); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for Tracked { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(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 CopyConstructibleUnsafe for Tracked {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for Tracked { - unsafe fn constructor(this: *mut Self, (o,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_3(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); @@ -49,8 +42,6 @@ impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for Tracked { (*o).v = 0; } } -impl MoveConstructibleUnsafe for Tracked {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} pub unsafe fn chosen_overload_0(_a0: *const Tracked) -> Overload { return Overload_kLvalueOverload; } @@ -97,21 +88,16 @@ pub unsafe fn forward_pack_7( }; return digits; } -impl ConstructibleFromUnsafe<(LvalueRefUnsafe, RvalueRefUnsafe)> for Pair { - unsafe fn constructor( +impl Pair { + pub unsafe fn constructor_1_1( this: *mut Self, - (x, y): (LvalueRefUnsafe, RvalueRefUnsafe), + x: LvalueRefUnsafe, + y: RvalueRefUnsafe, ) { let x = (x.as_ptr() as *mut Tracked); let y = (y.as_ptr() as *mut Tracked); - >,)>>::constructor( - &raw mut (*this).a, - (LvalueRefUnsafe::bind(x),), - ); - ,)>>::constructor( - &raw mut (*this).b, - (RvalueRefUnsafe::bind(y),), - ); + Tracked::constructor_2(&raw mut (*this).a, LvalueRefUnsafe::bind(x)); + Tracked::constructor_3(&raw mut (*this).b, RvalueRefUnsafe::bind(y)); } } #[repr(C)] @@ -121,17 +107,22 @@ impl ConstructibleFromUnsafe<(LvalueRefUnsafe, RvalueRefUnsafe #[memberwise(copy_constructor, move_constructor)] #[derive(ConversionsUnsafe)] #[conversions(copy, move)] -#[constructor(lvalue_ref(Tracked), rvalue_ref(Tracked))] +#[constructor(constructor_1_1, lvalue_ref(Tracked), rvalue_ref(Tracked))] pub struct Pair { pub a: Tracked, pub b: Tracked, } +impl Pair {} pub unsafe fn forward_pack_into_ctor_8( __return: *mut Pair, args_0: *mut Tracked, args_1: *mut Tracked, ) { - ,RvalueRefUnsafe,)>>::constructor(__return, (LvalueRefUnsafe::bind(args_0 ), RvalueRefUnsafe::bind(args_1 ),)) ; + Pair::constructor_1_1( + __return, + LvalueRefUnsafe::bind(args_0), + RvalueRefUnsafe::bind(args_1), + ); return; } pub fn main() { @@ -142,31 +133,31 @@ pub fn main() { } unsafe fn main_0() -> i32 { assert!(((unsafe { forward_pack_4() }) == (0))); - object_unsafe!(a, Tracked, (i32,), (1,)); + object_unsafe!(a, Tracked::constructor_1(1)); assert!(((unsafe { forward_pack_5(&mut a,) }) == (Overload_kLvalueOverload as i32))); assert!(((a.v) == (1))); assert!( ((unsafe { - let mut _args: Tracked = ::zero_init(); - >::constructor(&raw mut _args, (2,)); + let mut _args: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _args, 2); forward_pack_6(&mut _args) }) == (Overload_kRvalueOverload as i32)) ); let mut i: i32 = 3; assert!( ((unsafe { - let mut _args_1: Tracked = ::zero_init(); - >::constructor(&raw mut _args_1, (4,)); + let mut _args_1: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _args_1, 4); let mut _args_3: i32 = 5; forward_pack_7(&mut a, &mut _args_1, &mut i, &mut _args_3) }) == (1234)) ); assert!(((a.v) == (1))); assert!(((i) == (3))); - object_unsafe!(lhs, Tracked, (i32,), (6,)); + object_unsafe!(lhs, Tracked::constructor_1(6)); object_unsafe!(p, Pair, |p| (unsafe { - let mut _args_1: Tracked = ::zero_init(); - >::constructor(&raw mut _args_1, (7,)); + let mut _args_1: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _args_1, 7); forward_pack_into_ctor_8(p, &mut lhs, &mut _args_1) })); assert!(((p.a.v) == (6))); diff --git a/tests/unit/out/unsafe/global_init_side_effect.rs b/tests/unit/out/unsafe/global_init_side_effect.rs index e2e1251650..2cb467b4c1 100644 --- a/tests/unit/out/unsafe/global_init_side_effect.rs +++ b/tests/unit/out/unsafe/global_init_side_effect.rs @@ -20,25 +20,24 @@ pub static mut total_0: std::cell::LazyCell = std::cell::LazyCell::new(|| u ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] pub struct S {} -impl ConstructibleFromUnsafe<(i32,)> for S { - unsafe fn constructor(this: *mut Self, (mut x,): (i32,)) { +impl S { + pub unsafe fn constructor_1(this: *mut Self, mut x: i32) { (*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) += x; } } -impl ConvertibleToUnsafe for i32 {} pub static mut a_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __v: S = ::zero_init(); - >::constructor(&raw mut __v, (1,)); + let mut __v: S = ZeroInitializationUnsafe::zero_init(); + S::constructor_1(&raw mut __v, 1); __v } }); pub static mut b_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __v: S = ::zero_init(); - >::constructor(&raw mut __v, (10,)); + let mut __v: S = ZeroInitializationUnsafe::zero_init(); + S::constructor_1(&raw mut __v, 10); __v } }); diff --git a/tests/unit/out/unsafe/global_non_const_init.rs b/tests/unit/out/unsafe/global_non_const_init.rs index 99e3ddcbc6..ecb1ba3edf 100644 --- a/tests/unit/out/unsafe/global_non_const_init.rs +++ b/tests/unit/out/unsafe/global_non_const_init.rs @@ -37,18 +37,16 @@ pub static mut depends_on_call_6: std::cell::LazyCell = std::cell::LazyCell TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] -#[constructor(explicit, value(i32))] +#[conversions(copy, move, default = constructor_1)] +#[constructor(constructor_2, explicit, value(i32))] pub struct Ctor { pub v: i32, } -impl ConstructibleFromUnsafe<()> for Ctor { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Ctor { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write((unsafe { next_0() })); } -} -impl ConstructibleFromUnsafe<(i32,)> for Ctor { - unsafe fn constructor(this: *mut Self, (mut x,): (i32,)) { + pub unsafe fn constructor_2(this: *mut Self, mut x: i32) { (&raw mut (*this).v).write(x); } } @@ -56,8 +54,8 @@ impl Default for Ctor { fn default() -> Self { unsafe { { - let mut __v: Ctor = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Ctor = ZeroInitializationUnsafe::zero_init(); + Ctor::constructor_1(&raw mut __v); __v } } @@ -65,15 +63,15 @@ impl Default for Ctor { } pub static mut default_ctor_7: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __v: Ctor = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Ctor = ZeroInitializationUnsafe::zero_init(); + Ctor::constructor_1(&raw mut __v); __v } }); pub static mut arg_ctor_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __v: Ctor = ::zero_init(); - >::constructor(&raw mut __v, (7,)); + let mut __v: Ctor = ZeroInitializationUnsafe::zero_init(); + Ctor::constructor_2(&raw mut __v, 7); __v } }); @@ -87,8 +85,8 @@ pub static mut str_9: std::cell::LazyCell> = }); pub static mut inline_member_11: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __v: Ctor = ::zero_init(); - >::constructor(&raw mut __v, (5,)); + let mut __v: Ctor = ZeroInitializationUnsafe::zero_init(); + Ctor::constructor_2(&raw mut __v, 5); __v } }); @@ -116,8 +114,8 @@ static mut once_13: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { (unsafe { next_0() }) }); static mut local_ctor_14: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __v: Ctor = ::zero_init(); - >::constructor(&raw mut __v, (3,)); + let mut __v: Ctor = ZeroInitializationUnsafe::zero_init(); + Ctor::constructor_2(&raw mut __v, 3); __v } }); @@ -131,26 +129,24 @@ static mut local_ctor_14: std::cell::LazyCell = std::cell::LazyCell::new(| TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Singleton { pub hits: i32, } impl Singleton { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).hits).write(0); + } pub unsafe fn instance() -> *mut Singleton { return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut s_15)); } } -impl ConstructibleFromUnsafe<()> for Singleton { - unsafe fn constructor(this: *mut Self, _: ()) { - (&raw mut (*this).hits).write(0); - } -} impl Default for Singleton { fn default() -> Self { unsafe { { - let mut __v: Singleton = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Singleton = ZeroInitializationUnsafe::zero_init(); + Singleton::constructor_1(&raw mut __v); __v } } @@ -158,8 +154,8 @@ impl Default for Singleton { } static mut s_15: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __v: Singleton = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Singleton = ZeroInitializationUnsafe::zero_init(); + Singleton::constructor_1(&raw mut __v); __v } }); diff --git a/tests/unit/out/unsafe/huffman.rs b/tests/unit/out/unsafe/huffman.rs index f24a3ae44d..d7efaacf12 100644 --- a/tests/unit/out/unsafe/huffman.rs +++ b/tests/unit/out/unsafe/huffman.rs @@ -61,7 +61,7 @@ pub unsafe fn Swap_0(a: *mut MinHeapNode, b: *mut MinHeapNode) { )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] pub struct MinHeap { pub size: i32, pub capacity: i32, @@ -259,9 +259,7 @@ impl MinHeap { } } } -} -impl ConstructibleFromUnsafe<()> for MinHeap { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).size).write(0_i32); (&raw mut (*this).capacity).write(0_i32); (&raw mut (*this).arr).write(None); diff --git a/tests/unit/out/unsafe/implicit_autoref.rs b/tests/unit/out/unsafe/implicit_autoref.rs index 8d38706193..23d1f92e2a 100644 --- a/tests/unit/out/unsafe/implicit_autoref.rs +++ b/tests/unit/out/unsafe/implicit_autoref.rs @@ -20,12 +20,12 @@ use std::rc::Rc; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Holder { pub v: Vec, } -impl ConstructibleFromUnsafe<()> for Holder { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Holder { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write(Vec::new()); } } @@ -51,7 +51,7 @@ unsafe fn main_0() -> i32 { let mut p: *mut Vec = (&mut v as *mut Vec); let mut a: i32 = (&mut (*p))[(0_usize)]; (&mut (*p))[(1_usize)] = 30; - object_unsafe!(h, Holder); + object_unsafe!(h, Holder::constructor_1()); { let mut __tmp_2: i32 = 40; h.v.push_moved(&mut __tmp_2) diff --git a/tests/unit/out/unsafe/in_class_field_initializer.rs b/tests/unit/out/unsafe/in_class_field_initializer.rs index 5cf6cff62b..6cc11cb4c9 100644 --- a/tests/unit/out/unsafe/in_class_field_initializer.rs +++ b/tests/unit/out/unsafe/in_class_field_initializer.rs @@ -16,13 +16,13 @@ use std::rc::Rc; TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Inner { pub x: i32, pub y: i32, } -impl ConstructibleFromUnsafe<()> for Inner { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Inner { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).x).write(3); (&raw mut (*this).y).write(4); } @@ -42,19 +42,19 @@ impl Default for Inner { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct S { pub a: i32, pub b: libc::c_char, pub c: Inner, pub d: Inner, } -impl ConstructibleFromUnsafe<()> for S { - unsafe fn constructor(this: *mut Self, _: ()) { +impl S { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).a).write(1); (&raw mut (*this).b).write((2 as libc::c_char)); (&raw mut (*this).c).write(::default()); - >::constructor(&raw mut (*this).d, ()); + Inner::constructor_1(&raw mut (*this).d); } } impl Default for S { @@ -81,13 +81,13 @@ impl Default for S { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(value(i32), value(i32))] +#[constructor(constructor_1, value(i32), value(i32))] pub struct Boxed_int_ { pub v: i32, pub tag: i32, } -impl ConstructibleFromUnsafe<(i32, i32)> for Boxed_int_ { - unsafe fn constructor(this: *mut Self, (mut x, mut t): (i32, i32)) { +impl Boxed_int_ { + pub unsafe fn constructor_1(this: *mut Self, mut x: i32, mut t: i32) { (&raw mut (*this).v).write(x); (&raw mut (*this).tag).write(t); } @@ -104,14 +104,14 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(s, S); + object_unsafe!(s, S::constructor_1()); assert!(((s.a) == (1))); assert!(((s.b as i32) == (2))); assert!(((s.c.x) == (3))); assert!(((s.c.y) == (4))); assert!(((s.d.x) == (3))); assert!(((s.d.y) == (4))); - object_unsafe!(boxed, Boxed_int_, (i32, i32,), (5, 9,)); + object_unsafe!(boxed, Boxed_int_::constructor_1(5, 9)); assert!(((boxed.v) == (5))); assert!(((boxed.tag) == (9))); return 0; diff --git a/tests/unit/out/unsafe/init_list.rs b/tests/unit/out/unsafe/init_list.rs index f6850b4c54..7b83ecc868 100644 --- a/tests/unit/out/unsafe/init_list.rs +++ b/tests/unit/out/unsafe/init_list.rs @@ -34,7 +34,7 @@ pub struct Pair { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Holder { pub p: Pair, } @@ -43,9 +43,7 @@ impl Holder { (*this).p = (*o); return &mut (*this); } -} -impl ConstructibleFromUnsafe<()> for Holder { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).p).write(Pair { a: 0, b: 0 }); } } @@ -71,12 +69,12 @@ pub unsafe fn sum_1(p: *const Pair) -> i32 { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Seven { pub v: i32, } -impl ConstructibleFromUnsafe<()> for Seven { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Seven { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write(7); } } @@ -100,7 +98,7 @@ unsafe fn main_0() -> i32 { let mut vec_: Vec = Vec::from([1, 2, 3]); (unsafe { f_0(Vec::from([1, 2, 3, 4])) }); let mut p: Pair = Pair { a: 1, b: 2 }; - object_unsafe!(h, Holder); + object_unsafe!(h, Holder::constructor_1()); (unsafe { Holder::operator_assign_1(&raw mut h, &mut p) }); assert!(((h.p.a) == (1)) && ((h.p.b) == (2))); assert!(((unsafe { sum_1(&p,) }) == (3))); diff --git a/tests/unit/out/unsafe/inline_container_fields.rs b/tests/unit/out/unsafe/inline_container_fields.rs index e629fd105d..27bc1158cc 100644 --- a/tests/unit/out/unsafe/inline_container_fields.rs +++ b/tests/unit/out/unsafe/inline_container_fields.rs @@ -20,14 +20,14 @@ use std::rc::Rc; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Elem { pub id: i32, pub hist: [i32; 4], pub coeffs: Vec, } -impl ConstructibleFromUnsafe<()> for Elem { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Elem { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).id).write(0_i32); (&raw mut (*this).hist).write([0_i32; 4]); (&raw mut (*this).coeffs).write(Vec::new()); @@ -46,7 +46,7 @@ impl ConstructibleFromUnsafe<()> for Elem { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct State { pub count: i32, pub grid: [[i32; 3]; 2], @@ -54,8 +54,8 @@ pub struct State { pub elems: Vec, pub rows: Vec>, } -impl ConstructibleFromUnsafe<()> for State { - unsafe fn constructor(this: *mut Self, _: ()) { +impl State { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).count).write(0_i32); (&raw mut (*this).grid).write([[0_i32; 3]; 2]); (&raw mut (*this).arr).write(std::array::from_fn::<_, 3, _>(|_| 0_i32)); @@ -145,34 +145,26 @@ pub static mut move_assigns_5: std::cell::LazyCell = std::cell::LazyCell::n #[derive( FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy = constructor_2, move = constructor_3, default = constructor_1)] pub struct Counted { pub v: i32, } -impl ConstructibleFromUnsafe<()> for Counted { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Counted { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write(0); } -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for Counted { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(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 CopyConstructibleUnsafe for Counted {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for Counted { - unsafe fn constructor(this: *mut Self, (o,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_3(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 MoveConstructibleUnsafe for Counted {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} impl CopyAssignableUnsafe for Counted { unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut Counted { let o = (o.as_ptr() as *const Counted); @@ -264,7 +256,9 @@ unsafe fn main_0() -> i32 { assert!( ((elems[(1_usize)].hist[(2) as usize]) == (5)) && (((*first).hist[(2) as usize]) == (0)) ); - object_unsafe!(moved, State, RvalueRefUnsafe::bind(&mut t)); + object_unsafe!(moved, State, |moved| { + ::move_constructor(moved, RvalueRefUnsafe::bind(&mut t)) + }); assert!( ((moved.grid[(0) as usize][(0) as usize]) == (100)) && ((moved.grid[(1) as usize][(2) as usize]) == (5)) diff --git a/tests/unit/out/unsafe/kruskal.rs b/tests/unit/out/unsafe/kruskal.rs index 0ed2d341c0..2af26fa956 100644 --- a/tests/unit/out/unsafe/kruskal.rs +++ b/tests/unit/out/unsafe/kruskal.rs @@ -185,7 +185,7 @@ pub unsafe fn quicksort_1(arr: *mut Option>, mut start: i32, mut end )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] pub struct DisjointSet { pub rank: Option>, pub parent: Option>, @@ -295,9 +295,7 @@ impl DisjointSet { + (1)); } } -} -impl ConstructibleFromUnsafe<()> for DisjointSet { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).rank).write(None); (&raw mut (*this).parent).write(None); (&raw mut (*this).n).write(0_i32); @@ -314,14 +312,14 @@ impl ConstructibleFromUnsafe<()> for DisjointSet { )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] pub struct Graph { pub edges: Option>, pub V: i32, pub E: i32, } -impl ConstructibleFromUnsafe<()> for Graph { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Graph { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).edges).write(None); (&raw mut (*this).V).write(0_i32); (&raw mut (*this).E).write(0_i32); diff --git a/tests/unit/out/unsafe/lambda_as_field.rs b/tests/unit/out/unsafe/lambda_as_field.rs index c1ce38ef6f..75dbd4c47c 100644 --- a/tests/unit/out/unsafe/lambda_as_field.rs +++ b/tests/unit/out/unsafe/lambda_as_field.rs @@ -19,7 +19,7 @@ use std::rc::Rc; )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] +#[conversions(copy, move)] pub struct Guard__lambda_at_lambda_as_field_cpp_34_13__ { pub f: FnPtr, } @@ -38,7 +38,7 @@ impl DestructibleUnsafe for Guard__lambda_at_lambda_as_field_cpp_34_13__ { CopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy)] +#[conversions(copy, move)] pub struct Guard__lambda_at_lambda_as_field_cpp_45_13__ { pub f: FnPtr, } @@ -106,37 +106,25 @@ impl Holder__lambda_at_lambda_as_field_cpp_51_12__ { } #[repr(C)] #[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] -#[conversions(move)] +#[conversions(move = constructor_2)] pub struct Moving__lambda_at_lambda_as_field_cpp_64_12__ { pub f: FnPtr i32>, pub moves: i32, } -impl ConstructibleFromUnsafe<(FnPtr i32>,)> - for Moving__lambda_at_lambda_as_field_cpp_64_12__ -{ - unsafe fn constructor(this: *mut Self, (mut f,): (FnPtr i32>,)) { +impl Moving__lambda_at_lambda_as_field_cpp_64_12__ { + pub unsafe fn constructor_1(this: *mut Self, mut f: FnPtr i32>) { (&raw mut (*this).f).write(f.copy_from()); (&raw mut (*this).moves).write(0); } -} -impl ConvertibleToUnsafe for FnPtr i32> {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> - for Moving__lambda_at_lambda_as_field_cpp_64_12__ -{ - unsafe fn constructor( + pub unsafe fn constructor_2( this: *mut Self, - (o,): (RvalueRefUnsafe,), + 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))); } } -impl MoveConstructibleUnsafe for Moving__lambda_at_lambda_as_field_cpp_64_12__ {} -impl ConvertibleToUnsafe - for RvalueRefUnsafe -{ -} impl Default for Moving__lambda_at_lambda_as_field_cpp_64_12__ { fn default() -> Self { unsafe { ::zero_init() } @@ -252,18 +240,17 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { ww.call(2,) }) == (202))); object_unsafe!( m, - Moving__lambda_at_lambda_as_field_cpp_64_12__, - (FnPtr i32>,), - (FnPtr:: i32>::new(|mut x: i32| -> i32 { - unsafe { - return ((x) * (2)); + Moving__lambda_at_lambda_as_field_cpp_64_12__::constructor_1(FnPtr:: i32>::new( + |mut x: i32| -> i32 { + unsafe { + return ((x) * (2)); + } } - }),) + )) ); object_unsafe!( m2, - Moving__lambda_at_lambda_as_field_cpp_64_12__, - RvalueRefUnsafe::bind(&mut m) + Moving__lambda_at_lambda_as_field_cpp_64_12__::constructor_2(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 fe7cde6b2e..947fbf813d 100644 --- a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs @@ -8,41 +8,33 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy = constructor_2, move = constructor_3, default = constructor_1)] pub struct Counted { pub copies: i32, pub moves: i32, } -impl ConstructibleFromUnsafe<()> for Counted { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Counted { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).copies).write(0); (&raw mut (*this).moves).write(0); } -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for Counted { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(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 CopyConstructibleUnsafe for Counted {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for Counted { - unsafe fn constructor(this: *mut Self, (o,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_3(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))); } } -impl MoveConstructibleUnsafe for Counted {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} impl Default for Counted { fn default() -> Self { unsafe { { - let mut __v: Counted = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_1(&raw mut __v); __v } } @@ -51,25 +43,17 @@ impl Default for Counted { pub static mut drops_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive(FnPtrArg, ZeroInitializationUnsafe, ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy = constructor_2, move = constructor_3, default = constructor_1)] pub struct Dropped {} -impl ConstructibleFromUnsafe<()> for Dropped { - unsafe fn constructor(this: *mut Self, _: ()) {} -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for Dropped { - unsafe fn constructor(this: *mut Self, (_a0,): (LvalueRefUnsafe>,)) { +impl Dropped { + pub unsafe fn constructor_1(this: *mut Self) {} + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const Dropped); } -} -impl CopyConstructibleUnsafe for Dropped {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for Dropped { - unsafe fn constructor(this: *mut Self, (_a0,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_3(this: *mut Self, _a0: RvalueRefUnsafe) { let _a0 = (_a0.as_ptr() as *mut Dropped); } } -impl MoveConstructibleUnsafe for Dropped {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} impl DestructibleUnsafe for Dropped { unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut drops_0)).postfix_inc(); @@ -82,12 +66,12 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(c, Counted); + object_unsafe!(c, Counted::constructor_1()); let mut f: FnPtr i32> = lambda_unsafe!( { let c: Counted = { - let mut __v: Counted = ::zero_init(); - >,)>>::constructor(&raw mut __v, (LvalueRefUnsafe::bind(& c ),)) ; + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(&c)); __v }; }, @@ -102,26 +86,19 @@ unsafe fn main_0() -> i32 { let mut h: FnPtr i32> = f.move_from(); assert!(((unsafe { h.call() }) == (11))); let mut returned: i32 = { - let mut __tmp_0: Counted = ::zero_init(); + let mut __tmp_0: Counted = ZeroInitializationUnsafe::zero_init(); (*{ (unsafe { lambda_unsafe!( { let c: Counted = { - let mut __v: Counted = ::zero_init(); - >, - )>>::constructor( - &raw mut __v, (LvalueRefUnsafe::bind(&c),) - ); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(&c)); __v }; }, |__return: *mut Counted| { - ConvertibleToUnsafe::convert( - >>::bind(&c), - __return, - ); + Counted::constructor_2(__return, LvalueRefUnsafe::bind(&c)); return; } ) @@ -133,15 +110,15 @@ unsafe fn main_0() -> i32 { }; assert!(((returned) == (2))); let mut arr: [Counted; 2] = std::array::from_fn::<_, 2, _>(|_| { - let mut __v: Counted = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_1(&raw mut __v); __v }); let mut a: FnPtr i32> = lambda_unsafe!( { let arr: [Counted; 2] = std::array::from_fn::<_, 2, _>(|__i: usize| { - let mut __v: Counted = ::zero_init(); - >,)>>::constructor(&raw mut __v, (LvalueRefUnsafe::bind(& arr [ ( __i ) ] ),)) ; + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(&arr[(__i)])); __v }); }, @@ -158,8 +135,8 @@ unsafe fn main_0() -> i32 { let mut m: FnPtr = lambda_unsafe!( { let d: Dropped = { - let mut __v: Dropped = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Dropped = ZeroInitializationUnsafe::zero_init(); + Dropped::constructor_1(&raw mut __v); __v }; }, @@ -178,8 +155,8 @@ unsafe fn main_0() -> i32 { let mut k: FnPtr = lambda_unsafe!( { let d: Dropped = { - let mut __v: Dropped = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Dropped = ZeroInitializationUnsafe::zero_init(); + Dropped::constructor_1(&raw mut __v); __v }; }, @@ -198,8 +175,8 @@ unsafe fn main_0() -> i32 { let mut inner: FnPtr = lambda_unsafe!( { let d: Dropped = { - let mut __v: Dropped = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Dropped = ZeroInitializationUnsafe::zero_init(); + Dropped::constructor_1(&raw mut __v); __v }; }, diff --git a/tests/unit/out/unsafe/lambda_decltype_type.rs b/tests/unit/out/unsafe/lambda_decltype_type.rs index 266d0df243..be9e62fc14 100644 --- a/tests/unit/out/unsafe/lambda_decltype_type.rs +++ b/tests/unit/out/unsafe/lambda_decltype_type.rs @@ -10,7 +10,7 @@ use std::rc::Rc; #[derive( Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { pub items: [i32; 4], pub size: i32, @@ -31,9 +31,7 @@ impl Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { (*this).items[(i) as usize] = v; (*this).size.postfix_inc(); } -} -impl ConstructibleFromUnsafe<()> for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).items).write([0_i32; 4]); (&raw mut (*this).size).write(0); (&raw mut (*this).cmp).write(FnPtr:: bool>::new( @@ -64,7 +62,7 @@ impl Default for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { #[derive( Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { pub items: [i32; 4], pub size: i32, @@ -85,9 +83,7 @@ impl Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { (*this).items[(i) as usize] = v; (*this).size.postfix_inc(); } -} -impl ConstructibleFromUnsafe<()> for Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).items).write([0_i32; 4]); (&raw mut (*this).size).write(0); (&raw mut (*this).cmp).write(FnPtr:: bool>::new( @@ -127,14 +123,20 @@ unsafe fn main_0() -> i32 { return ((a) > (b)); } }); - object_unsafe!(desc, Sorted__lambda_at_lambda_decltype_type_cpp_22_18__); + object_unsafe!( + desc, + Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::constructor_1() + ); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&raw mut desc, 2) }); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&raw mut desc, 7) }); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&raw mut desc, 4) }); assert!(((desc.items[(0) as usize]) == (7))); assert!(((desc.items[(1) as usize]) == (4))); assert!(((desc.items[(2) as usize]) == (2))); - object_unsafe!(asc, Sorted__lambda_at_lambda_decltype_type_cpp_19_23__); + object_unsafe!( + asc, + Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::constructor_1() + ); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&raw mut asc, 2) }); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&raw mut asc, 7) }); (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&raw mut asc, 4) }); diff --git a/tests/unit/out/unsafe/lambda_immediate_init.rs b/tests/unit/out/unsafe/lambda_immediate_init.rs index 2906682342..ef646efde6 100644 --- a/tests/unit/out/unsafe/lambda_immediate_init.rs +++ b/tests/unit/out/unsafe/lambda_immediate_init.rs @@ -19,13 +19,13 @@ pub unsafe fn pick_0(mut x: i32) -> i32 { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct S { pub j: i32, pub k: i32, } -impl ConstructibleFromUnsafe<()> for S { - unsafe fn constructor(this: *mut Self, _: ()) { +impl S { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).j).write(10); (&raw mut (*this).k).write( ((unsafe { @@ -98,7 +98,7 @@ unsafe fn main_0() -> i32 { }) == (237)) ); assert!(((unsafe { pick_0(1,) }) == (1))); - object_unsafe!(s, S); + object_unsafe!(s, S::constructor_1()); assert!(((s.k) == (4))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut g_1)) == (10))); let mut a: i32 = 2; diff --git a/tests/unit/out/unsafe/lambda_move_only_capture.rs b/tests/unit/out/unsafe/lambda_move_only_capture.rs index d28f67918a..2c71372aa6 100644 --- a/tests/unit/out/unsafe/lambda_move_only_capture.rs +++ b/tests/unit/out/unsafe/lambda_move_only_capture.rs @@ -8,21 +8,26 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultConstructibleUnsafe, ConversionsUnsafe)] -#[conversions(move)] -#[constructor(value(i32))] +#[conversions(move = constructor_3)] +#[constructor(constructor_1, value(i32))] pub struct Owner { pub p: *mut i32, } impl Owner { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { + (&raw mut (*this).p).write((Box::leak(Box::new(v)) as *mut i32)); + } + pub unsafe fn constructor_3(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(); + } pub unsafe fn take(this: *mut Self) -> FnPtr i32> { return lambda_unsafe!( { let self_: Owner = { - let mut __v: Owner = ::zero_init(); - ConvertibleToUnsafe::convert( - >::bind(&mut (*this)), - &raw mut __v, - ); + let mut __v: Owner = ZeroInitializationUnsafe::zero_init(); + Owner::constructor_3(&raw mut __v, RvalueRefUnsafe::bind(&mut (*this))); __v }; }, @@ -32,21 +37,6 @@ impl Owner { ); } } -impl ConstructibleFromUnsafe<(i32,)> for Owner { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { - (&raw mut (*this).p).write((Box::leak(Box::new(v)) as *mut i32)); - } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for Owner { - unsafe fn 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(); - } -} -impl MoveConstructibleUnsafe for Owner {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} impl DestructibleUnsafe for Owner { unsafe fn destroy(this: *mut Self) { { @@ -64,12 +54,12 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(o, Owner, (i32,), (5,)); + object_unsafe!(o, Owner::constructor_1(5)); let mut f: FnPtr i32> = lambda_unsafe!( { let h: Owner = { - let mut __v: Owner = ::zero_init(); - ConvertibleToUnsafe::convert(>::bind(&mut o), &raw mut __v); + let mut __v: Owner = ZeroInitializationUnsafe::zero_init(); + Owner::constructor_3(&raw mut __v, RvalueRefUnsafe::bind(&mut o)); __v }; }, @@ -91,8 +81,8 @@ unsafe fn main_0() -> i32 { let mut consume: FnPtr = lambda_unsafe!( { let h: Owner = { - let mut __v: Owner = ::zero_init(); - >::constructor(&raw mut __v, (7,)); + let mut __v: Owner = ZeroInitializationUnsafe::zero_init(); + Owner::constructor_1(&raw mut __v, 7); __v }; let total: *mut i32 = &mut total; @@ -108,7 +98,7 @@ unsafe fn main_0() -> i32 { (unsafe { consume.call() }); (unsafe { consume.call() }); assert!(((total) == (7))); - object_unsafe!(o2, Owner, (i32,), (9,)); + object_unsafe!(o2, Owner::constructor_1(9)); let mut t: FnPtr i32> = (unsafe { Owner::take(&raw mut o2) }); let _dtor_t = std::mem::DropGuard::new(&raw mut t, |__p| unsafe { DestructibleUnsafe::destroy(__p) diff --git a/tests/unit/out/unsafe/libc_struct_without_default.rs b/tests/unit/out/unsafe/libc_struct_without_default.rs index fbe1691284..5a47987693 100644 --- a/tests/unit/out/unsafe/libc_struct_without_default.rs +++ b/tests/unit/out/unsafe/libc_struct_without_default.rs @@ -19,13 +19,13 @@ use std::rc::Rc; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct UserDefined { pub a: [i32; 1], pub v: Vec, } -impl ConstructibleFromUnsafe<()> for UserDefined { - unsafe fn constructor(this: *mut Self, _: ()) { +impl UserDefined { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).a).write(std::array::from_fn::<_, 1, _>(|_| 0_i32)); (&raw mut (*this).v).write(Vec::new()); } @@ -91,7 +91,7 @@ unsafe fn main_0() -> i32 { let mut st: ::libc::stat = std::mem::zeroed(); st.st_size = (1024 as ::libc::off_t); assert!(((st.st_size) == (1024 as ::libc::off_t))); - object_unsafe!(ud, UserDefined); + object_unsafe!(ud, UserDefined::constructor_1()); ud.a[(0_usize)] = 3; assert!(((ud.a[(0_usize)]) == (3))); assert!(((ud.v.len()) == (0_usize))); diff --git a/tests/unit/out/unsafe/map.rs b/tests/unit/out/unsafe/map.rs index cf0598f101..d5f4886aa3 100644 --- a/tests/unit/out/unsafe/map.rs +++ b/tests/unit/out/unsafe/map.rs @@ -25,20 +25,18 @@ pub unsafe fn inc_2(x: *mut i32) { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] -#[constructor(value(i32), value(i32))] +#[conversions(copy, move, default = constructor_1)] +#[constructor(constructor_2, value(i32), value(i32))] pub struct Point { pub x: i32, pub y: i32, } -impl ConstructibleFromUnsafe<()> for Point { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Point { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).x).write(0); (&raw mut (*this).y).write(0); } -} -impl ConstructibleFromUnsafe<(i32, i32)> for Point { - unsafe fn constructor(this: *mut Self, (mut x, mut y): (i32, i32)) { + pub unsafe fn constructor_2(this: *mut Self, mut x: i32, mut y: i32) { (&raw mut (*this).x).write(x); (&raw mut (*this).y).write(y); } @@ -47,8 +45,8 @@ impl Default for Point { fn default() -> Self { unsafe { { - let mut __v: Point = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Point = ZeroInitializationUnsafe::zero_init(); + Point::constructor_1(&raw mut __v); __v } } @@ -428,13 +426,13 @@ unsafe fn main_0() -> i32 { assert!((((*not_inserted.0.iter_deref()).1) == (2))); m3.emplace(match ((&mut (4, 5) as *mut (i32, i32)),) { (__tmp_27,) => { - object_unsafe!(__first, i32, |__this| ConversionsUnsafe::construct( + object_unsafe!(__first, i32, |__this| ConstructibleFromUnsafe::construct( __this, - &[overload::Arg::rvalue_unsafe(&raw mut (*__tmp_27).0)] + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_27).0),) )); - object_unsafe!(__second, i32, |__this| ConversionsUnsafe::construct( + object_unsafe!(__second, i32, |__this| ConstructibleFromUnsafe::construct( __this, - &[overload::Arg::rvalue_unsafe(&raw mut (*__tmp_27).1)] + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_27).1),) )); ( move_constructed_unsafe(&raw mut __first), @@ -486,8 +484,8 @@ unsafe fn main_0() -> i32 { let mut points: UnsafeMap = UnsafeMap::new(); let mut point_new: (UnsafeBidirectionalIterator<(i32, Point)>, bool) = points.try_emplace(key1, || { - let mut __v: Point = ::zero_init(); - >::constructor(&raw mut __v, (3, 4)); + let mut __v: Point = ZeroInitializationUnsafe::zero_init(); + Point::constructor_2(&raw mut __v, 3, 4); __v }); assert!(((point_new.1) as bool)); @@ -520,8 +518,8 @@ unsafe fn main_0() -> i32 { ) }; points.emplace((key8, { - let mut __v: Point = ::zero_init(); - >::constructor(&raw mut __v, (5, 6)); + let mut __v: Point = ZeroInitializationUnsafe::zero_init(); + Point::constructor_2(&raw mut __v, 5, 6); __v })); { diff --git a/tests/unit/out/unsafe/map_key_copy_ctor.rs b/tests/unit/out/unsafe/map_key_copy_ctor.rs index 93b878845b..9b5a52f8b8 100644 --- a/tests/unit/out/unsafe/map_key_copy_ctor.rs +++ b/tests/unit/out/unsafe/map_key_copy_ctor.rs @@ -13,40 +13,29 @@ pub static mut made_2: std::cell::LazyCell = std::cell::LazyCell::new(|| un #[derive( FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] pub struct Key { pub k: i32, } impl Key { - pub unsafe fn operator_lt(this: *const Self, o: *const Key) -> bool { - return (((*this).k) < ((*o).k)); - } -} -impl ConstructibleFromUnsafe<(i32,)> for Key { - unsafe fn constructor(this: *mut Self, (mut k,): (i32,)) { + pub unsafe fn constructor_1(this: *mut Self, mut k: i32) { (&raw mut (*this).k).write(k); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for Key { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(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 CopyConstructibleUnsafe for Key {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for Key { - unsafe fn constructor(this: *mut Self, (o,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_3(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(); } + pub unsafe fn operator_lt(this: *const Self, o: *const Key) -> bool { + return (((*this).k) < ((*o).k)); + } } -impl MoveConstructibleUnsafe for Key {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} impl std::cmp::Ord for Key { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { @@ -76,7 +65,7 @@ impl std::cmp::PartialEq for Key { impl std::cmp::Eq for Key {} pub unsafe fn make_key_3(__return: *mut Key, mut k: i32) { (*std::cell::LazyCell::force_mut(&mut *&raw mut made_2)).prefix_inc(); - >::constructor(__return, (k,)); + Key::constructor_1(__return, k); return; } pub fn main() { @@ -88,9 +77,9 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut ok: bool = true; let mut m: UnsafeMap = UnsafeMap::new(); - object_unsafe!(a, Key, (i32,), (1,)); - object_unsafe!(b, Key, (i32,), (2,)); - object_unsafe!(c, Key, (i32,), (3,)); + object_unsafe!(a, Key::constructor_1(1)); + object_unsafe!(b, Key::constructor_1(2)); + object_unsafe!(c, Key::constructor_1(3)); (*m.subscript(&a, || 0_i32)) = 10; ok = ((ok as i32) & (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (1)) as i32)) @@ -109,7 +98,7 @@ unsafe fn main_0() -> i32 { & (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) as i32)) != 0; { - let mut __tmp_1: Key = ::zero_init(); + let mut __tmp_1: Key = ZeroInitializationUnsafe::zero_init(); (*match (({ (unsafe { make_key_3(&raw mut __tmp_1, 4) }); &mut __tmp_1 @@ -119,7 +108,7 @@ unsafe fn main_0() -> i32 { }) = 40 }; { - let mut __tmp_3: Key = ::zero_init(); + let mut __tmp_3: Key = ZeroInitializationUnsafe::zero_init(); (*match (({ (unsafe { make_key_3(&raw mut __tmp_3, 4) }); &mut __tmp_3 @@ -149,9 +138,9 @@ unsafe fn main_0() -> i32 { != 0; let mut first: *const Key = (&(*m.begin().iter_deref()).0 as *const Key); { - let mut __tmp_5: Key = ::zero_init(); + let mut __tmp_5: Key = ZeroInitializationUnsafe::zero_init(); (*match (({ - >::constructor(&raw mut __tmp_5, (0,)); + Key::constructor_1(&raw mut __tmp_5, 0); &mut __tmp_5 } as *mut Key),) { diff --git a/tests/unit/out/unsafe/map_key_identity.rs b/tests/unit/out/unsafe/map_key_identity.rs index de1bc1e54e..fd8e90702a 100644 --- a/tests/unit/out/unsafe/map_key_identity.rs +++ b/tests/unit/out/unsafe/map_key_identity.rs @@ -64,12 +64,12 @@ pub unsafe fn operator_lt_1(a: *const Key, b: *const Key) -> bool { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Mapped { pub value: i32, } -impl ConstructibleFromUnsafe<()> for Mapped { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Mapped { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).value).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)).prefix_inc(); } @@ -78,8 +78,8 @@ impl Default for Mapped { fn default() -> Self { unsafe { { - let mut __v: Mapped = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Mapped = ZeroInitializationUnsafe::zero_init(); + Mapped::constructor_1(&raw mut __v); __v } } diff --git a/tests/unit/out/unsafe/map_try_emplace.rs b/tests/unit/out/unsafe/map_try_emplace.rs index c776089648..4e2dbab9e1 100644 --- a/tests/unit/out/unsafe/map_try_emplace.rs +++ b/tests/unit/out/unsafe/map_try_emplace.rs @@ -12,48 +12,37 @@ pub static mut copies_2: std::cell::LazyCell = std::cell::LazyCell::new(|| pub static mut moves_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_3, move = constructor_4, default = constructor_1)] +#[constructor(constructor_2, value(i32))] pub struct Item { pub value: i32, } -impl ConstructibleFromUnsafe<()> for Item { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Item { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).value).write(0); } -} -impl ConstructibleFromUnsafe<(i32,)> for Item { - unsafe fn constructor(this: *mut Self, (mut value,): (i32,)) { + pub unsafe fn constructor_2(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)).prefix_inc(); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for Item { - unsafe fn constructor(this: *mut Self, (other,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_3(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 CopyConstructibleUnsafe for Item {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for Item { - unsafe fn constructor(this: *mut Self, (other,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_4(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; } } -impl MoveConstructibleUnsafe for Item {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} impl Default for Item { fn default() -> Self { unsafe { { - let mut __v: Item = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_1(&raw mut __v); __v } } @@ -73,18 +62,16 @@ pub unsafe fn argument_4(item: *mut Item) -> *mut Item { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] -#[constructor(lvalue_ref(i32), value(i32))] +#[conversions(copy, move, default = constructor_1)] +#[constructor(constructor_2, lvalue_ref(i32), value(i32))] pub struct RefItem { pub value: i32, } -impl ConstructibleFromUnsafe<()> for RefItem { - unsafe fn constructor(this: *mut Self, _: ()) { +impl RefItem { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).value).write(0); } -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe, i32)> for RefItem { - unsafe fn constructor(this: *mut Self, (counter, mut amount): (LvalueRefUnsafe, i32)) { + pub unsafe fn constructor_2(this: *mut Self, counter: LvalueRefUnsafe, mut amount: i32) { let counter = (counter.as_ptr() as *mut i32); (&raw mut (*this).value).write({ (*counter) += amount; @@ -97,8 +84,8 @@ impl Default for RefItem { fn default() -> Self { unsafe { { - let mut __v: RefItem = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: RefItem = ZeroInitializationUnsafe::zero_init(); + RefItem::constructor_1(&raw mut __v); __v } } @@ -273,11 +260,11 @@ unsafe fn main_0() -> i32 { let mut items: UnsafeMap = UnsafeMap::new(); let mut key: i32 = 0; items.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - >::constructor(&raw mut __v, (10,)); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, 10); __v }); - object_unsafe!(source, Item, (i32,), (20,)); + object_unsafe!(source, Item::constructor_2(20)); (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) = { (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) = { (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) = 0; @@ -288,11 +275,8 @@ unsafe fn main_0() -> i32 { 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(); - >,)>>::constructor( - &raw mut __v, - (LvalueRefUnsafe::bind(__tmp_6),), - ); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_3(&raw mut __v, LvalueRefUnsafe::bind(__tmp_6)); __v }), }; @@ -307,11 +291,8 @@ unsafe fn main_0() -> i32 { 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(); - ,)>>::constructor( - &raw mut __v, - (RvalueRefUnsafe::bind(__tmp_7),), - ); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_4(&raw mut __v, RvalueRefUnsafe::bind(__tmp_7)); __v }), }; @@ -327,11 +308,8 @@ unsafe fn main_0() -> i32 { 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(); - >,)>>::constructor( - &raw mut __v, - (LvalueRefUnsafe::bind(__tmp_8),), - ); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_3(&raw mut __v, LvalueRefUnsafe::bind(__tmp_8)); __v }), }; @@ -347,11 +325,8 @@ unsafe fn main_0() -> i32 { 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(); - ,)>>::constructor( - &raw mut __v, - (RvalueRefUnsafe::bind(__tmp_9),), - ); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_4(&raw mut __v, RvalueRefUnsafe::bind(__tmp_9)); __v }), }; @@ -370,22 +345,16 @@ unsafe fn main_0() -> i32 { key = 0; let mut counter: i32 = 0; refs.try_emplace(key, || { - let mut __v: RefItem = ::zero_init(); - , i32)>>::constructor( - &raw mut __v, - (LvalueRefUnsafe::bind(&mut counter), 5), - ); + let mut __v: RefItem = ZeroInitializationUnsafe::zero_init(); + RefItem::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(&mut counter), 5); __v }); (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) = 0; let mut ref_hit: (UnsafeBidirectionalIterator<(i32, RefItem)>, bool) = match (((unsafe { reference_5(&mut counter) }) as *mut i32),) { (__tmp_10,) => refs.try_emplace(key, || { - let mut __v: RefItem = ::zero_init(); - , i32)>>::constructor( - &raw mut __v, - (LvalueRefUnsafe::bind(__tmp_10), 2), - ); + let mut __v: RefItem = ZeroInitializationUnsafe::zero_init(); + RefItem::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_10), 2); __v }), }; @@ -399,11 +368,8 @@ unsafe fn main_0() -> i32 { let mut ref_new: (UnsafeBidirectionalIterator<(i32, RefItem)>, bool) = match (((unsafe { reference_5(&mut counter) }) as *mut i32),) { (__tmp_11,) => refs.try_emplace(key, || { - let mut __v: RefItem = ::zero_init(); - , i32)>>::constructor( - &raw mut __v, - (LvalueRefUnsafe::bind(__tmp_11), 2), - ); + let mut __v: RefItem = ZeroInitializationUnsafe::zero_init(); + RefItem::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_11), 2); __v }), }; @@ -426,18 +392,15 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) }; let mut temporary_hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = { - let mut __tmp_13: Item = ::zero_init(); + let mut __tmp_13: Item = ZeroInitializationUnsafe::zero_init(); match (({ - >::constructor(&raw mut __tmp_13, (30,)); + Item::constructor_2(&raw mut __tmp_13, 30); &mut __tmp_13 } as *mut Item),) { (__tmp_12,) => items.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - ,)>>::constructor( - &raw mut __v, - (RvalueRefUnsafe::bind(__tmp_12),), - ); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_4(&raw mut __v, RvalueRefUnsafe::bind(__tmp_12)); __v }), } @@ -452,18 +415,15 @@ unsafe fn main_0() -> i32 { key.prefix_inc(); key.prefix_inc(); let mut temporary_new: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = { - let mut __tmp_15: Item = ::zero_init(); + let mut __tmp_15: Item = ZeroInitializationUnsafe::zero_init(); match (({ - >::constructor(&raw mut __tmp_15, (40,)); + Item::constructor_2(&raw mut __tmp_15, 40); &mut __tmp_15 } as *mut Item),) { (__tmp_14,) => items.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - ,)>>::constructor( - &raw mut __v, - (RvalueRefUnsafe::bind(__tmp_14),), - ); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_4(&raw mut __v, RvalueRefUnsafe::bind(__tmp_14)); __v }), } diff --git a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs index aeb485cdea..9bebb01a0e 100644 --- a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs +++ b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs @@ -18,18 +18,16 @@ pub static mut visits_1: std::cell::LazyCell = std::cell::LazyCell::new(|| TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] -#[constructor(lvalue_ref(i32), value(i32))] +#[conversions(copy, move, default = constructor_1)] +#[constructor(constructor_2, lvalue_ref(i32), value(i32))] pub struct Item { pub value: i32, } -impl ConstructibleFromUnsafe<()> for Item { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Item { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).value).write(0); } -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe, i32)> for Item { - unsafe fn constructor(this: *mut Self, (counter, mut amount): (LvalueRefUnsafe, i32)) { + pub unsafe fn constructor_2(this: *mut Self, counter: LvalueRefUnsafe, mut amount: i32) { let counter = (counter.as_ptr() as *mut i32); (&raw mut (*this).value).write({ (*counter) += amount; @@ -42,8 +40,8 @@ impl Default for Item { fn default() -> Self { unsafe { { - let mut __v: Item = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_1(&raw mut __v); __v } } @@ -69,13 +67,13 @@ pub static mut temporary_calls_4: std::cell::LazyCell = TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Temporary { pub n: i32, pub data: [i32; 2], } -impl ConstructibleFromUnsafe<()> for Temporary { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Temporary { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).n).write(5); (&raw mut (*this).data).write([6, 7]); (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)).prefix_inc(); @@ -85,8 +83,8 @@ impl Default for Temporary { fn default() -> Self { unsafe { { - let mut __v: Temporary = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Temporary = ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); __v } } @@ -103,26 +101,26 @@ impl Default for Temporary { Default, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Nested { pub inner: Temporary, } -impl ConstructibleFromUnsafe<()> for Nested { - unsafe fn constructor(this: *mut Self, _: ()) { - >::constructor(&raw mut (*this).inner, ()); +impl Nested { + pub unsafe fn constructor_1(this: *mut Self) { + Temporary::constructor_1(&raw mut (*this).inner); } } pub unsafe fn make_temporary_5() -> Temporary { return { - let mut __v: Temporary = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Temporary = ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); __v }; } pub unsafe fn make_nested_6() -> Nested { return { - let mut __v: Nested = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Nested = ZeroInitializationUnsafe::zero_init(); + Nested::constructor_1(&raw mut __v); __v }; } @@ -132,11 +130,18 @@ pub unsafe fn make_nested_6() -> Nested { )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] pub struct Owner { pub ptr: Option>, } impl Owner { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).ptr).write(Some(Box::new({ + let mut __v: Temporary = ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); + __v + }))); + } pub unsafe fn value(this: *mut Self) -> *const i32 { return &(*(*this).ptr.as_deref().map_or(::std::ptr::null_mut(), |v| { v as *const Temporary as *mut Temporary @@ -144,21 +149,12 @@ impl Owner { .n; } } -impl ConstructibleFromUnsafe<()> for Owner { - unsafe fn constructor(this: *mut Self, _: ()) { - (&raw mut (*this).ptr).write(Some(Box::new({ - let mut __v: Temporary = ::zero_init(); - >::constructor(&raw mut __v, ()); - __v - }))); - } -} impl Default for Owner { fn default() -> Self { unsafe { { - let mut __v: Owner = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Owner = ZeroInitializationUnsafe::zero_init(); + Owner::constructor_1(&raw mut __v); __v } } @@ -166,11 +162,12 @@ impl Default for Owner { } #[repr(C)] #[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] +#[conversions(default = constructor_1)] pub struct Noncopy { pub n: i32, } -impl ConstructibleFromUnsafe<()> for Noncopy { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Noncopy { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).n).write(5); } } @@ -189,25 +186,20 @@ impl Default for Noncopy { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] -#[constructor(const_lvalue_ref(i32))] +#[conversions(copy, move, default = constructor_1)] +#[constructor(constructor_2, const_lvalue_ref(i32))] pub struct Held { pub ptr: *const i32, } -impl ConstructibleFromUnsafe<()> for Held { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Held { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).ptr).write(std::ptr::null()); } -} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for Held { - unsafe fn constructor(this: *mut Self, (n,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(this: *mut Self, n: LvalueRefUnsafe>) { let n = (n.as_ptr() as *const i32); (&raw mut (*this).ptr).write((n)); } -} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} -impl ConstructibleFromUnsafe<(*const [i32; 2], i32)> for Held { - unsafe fn constructor(this: *mut Self, (n, mut _a1): (*const [i32; 2], i32)) { + pub unsafe fn constructor_3(this: *mut Self, n: *const [i32; 2], mut _a1: i32) { (&raw mut (*this).ptr).write((*n).as_ptr()); } } @@ -215,8 +207,8 @@ impl Default for Held { fn default() -> Self { unsafe { { - let mut __v: Held = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Held = ZeroInitializationUnsafe::zero_init(); + Held::constructor_1(&raw mut __v); __v } } @@ -286,8 +278,8 @@ pub static mut global_owned_16: std::cell::LazyCell<( let mut __tmp_6: Option>; match ((&mut (*(*{ __tmp_6 = Some(Box::new({ - let mut __v: Temporary = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Temporary = ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); __v })); &mut __tmp_6 @@ -340,11 +332,8 @@ unsafe fn main_0() -> i32 { let mut key: i32 = 0; let mut counter: i32 = 0; m.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - , i32)>>::constructor( - &raw mut __v, - (LvalueRefUnsafe::bind(&mut counter), 3), - ); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(&mut counter), 3); __v }); (*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)) = 0; @@ -357,11 +346,8 @@ unsafe fn main_0() -> i32 { } as *mut i32), ) { (__tmp_7, __tmp_8) => (*__tmp_7).try_emplace(key, || { - let mut __v: Item = ::zero_init(); - , i32)>>::constructor( - &raw mut __v, - (LvalueRefUnsafe::bind(__tmp_8), 2), - ); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_8), 2); __v }), }; @@ -378,11 +364,8 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_10,) => m.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - , i32)>>::constructor( - &raw mut __v, - (LvalueRefUnsafe::bind(__tmp_10), 2), - ); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_10), 2); __v }), }; @@ -399,11 +382,8 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_12,) => m.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - , i32)>>::constructor( - &raw mut __v, - (LvalueRefUnsafe::bind(__tmp_12), 2), - ); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_12), 2); __v }), }; @@ -421,11 +401,8 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_15,) => m.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - , i32)>>::constructor( - &raw mut __v, - (LvalueRefUnsafe::bind(__tmp_15), 2), - ); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_15), 2); __v }), }; @@ -447,11 +424,8 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_18,) => m.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - , i32)>>::constructor( - &raw mut __v, - (LvalueRefUnsafe::bind(__tmp_18), 3), - ); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_18), 3); __v }), }; @@ -471,11 +445,8 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_20,) => m.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - , i32)>>::constructor( - &raw mut __v, - (LvalueRefUnsafe::bind(__tmp_20), 3), - ); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_20), 3); __v }), }; @@ -491,11 +462,8 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_23,) => m.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - , i32)>>::constructor( - &raw mut __v, - (LvalueRefUnsafe::bind(__tmp_23), 3), - ); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_23), 3); __v }), }; @@ -520,11 +488,8 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_26,) => m.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - , i32)>>::constructor( - &raw mut __v, - (LvalueRefUnsafe::bind(__tmp_26), 3), - ); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_26), 3); __v }), }; @@ -548,11 +513,8 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_29,) => m.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - , i32)>>::constructor( - &raw mut __v, - (LvalueRefUnsafe::bind(__tmp_29), 3), - ); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_29), 3); __v }), }; @@ -566,11 +528,8 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_32,) => m.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - , i32)>>::constructor( - &raw mut __v, - (LvalueRefUnsafe::bind(__tmp_32), 3), - ); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_32), 3); __v }), }; @@ -800,13 +759,11 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_60,) => selected.try_emplace(keys[(0) as usize], || { - let mut __v: Item = ::zero_init(); - , - i32, - )>>::constructor( + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2( &raw mut __v, - (LvalueRefUnsafe::bind(__tmp_60), 2), + LvalueRefUnsafe::bind(__tmp_60), + 2, ); __v }), @@ -829,13 +786,11 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_63,) => selected.try_emplace(keys[(1) as usize], || { - let mut __v: Item = ::zero_init(); - , - i32, - )>>::constructor( + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2( &raw mut __v, - (LvalueRefUnsafe::bind(__tmp_63), 2), + LvalueRefUnsafe::bind(__tmp_63), + 2, ); __v }), @@ -858,13 +813,11 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_68,) => selected.try_emplace(keys[(2) as usize], || { - let mut __v: Item = ::zero_init(); - , - i32, - )>>::constructor( + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2( &raw mut __v, - (LvalueRefUnsafe::bind(__tmp_68), 2), + LvalueRefUnsafe::bind(__tmp_68), + 2, ); __v }), @@ -1004,12 +957,10 @@ unsafe fn main_0() -> i32 { let mut ordinary: i32 = 9; if (hit != 0) { references.try_emplace(key, || { - let mut __v: Held = ::zero_init(); - >, - )>>::constructor( + let mut __v: Held = ZeroInitializationUnsafe::zero_init(); + Held::constructor_2( &raw mut __v, - (LvalueRefUnsafe::bind(&ordinary),), + LvalueRefUnsafe::bind(&ordinary), ); __v }); @@ -1040,12 +991,11 @@ unsafe fn main_0() -> i32 { } as *mut i32),) { (__tmp_79,) => references.try_emplace(key, || { - let mut __v: Held = ::zero_init(); - >, - )>>::constructor( + let mut __v: Held = + ZeroInitializationUnsafe::zero_init(); + Held::constructor_2( &raw mut __v, - (LvalueRefUnsafe::bind(__tmp_79),), + LvalueRefUnsafe::bind(__tmp_79), ); __v }), @@ -1071,8 +1021,11 @@ unsafe fn main_0() -> i32 { let mut arrays: UnsafeMap = UnsafeMap::new(); let ordinary_array: [i32; 2] = [9, 10]; if (hit != 0) { - arrays .try_emplace(key , || { let mut __v: Held = ::zero_init(); >::constructor(&raw mut __v, (& ordinary_array , 0 ,)) ; -__v } ) ; + arrays.try_emplace(key, || { + let mut __v: Held = ZeroInitializationUnsafe::zero_init(); + Held::constructor_3(&raw mut __v, &ordinary_array, 0); + __v + }); } before = (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)); @@ -1098,13 +1051,9 @@ __v } ) ; } as *mut [i32; 2]),) { (__tmp_82,) => arrays.try_emplace(key, || { - let mut __v: Held = ::zero_init(); - >::constructor( - &raw mut __v, (__tmp_82, 0) - ); + let mut __v: Held = + ZeroInitializationUnsafe::zero_init(); + Held::constructor_3(&raw mut __v, __tmp_82, 0); __v }), }; @@ -1148,11 +1097,8 @@ __v } ) ; let mut __tmp_86: Option>; match ((&mut (*(*{ __tmp_86 = Some(Box::new({ - let mut __v: Temporary = ::zero_init(); - >::constructor( - &raw mut __v, - (), - ); + let mut __v: Temporary = ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); __v })); &mut __tmp_86 @@ -1170,8 +1116,8 @@ __v } ) ; let mut __tmp_88: Option>; match ((&mut (*&mut (*(*{ __tmp_88 = Some(Box::new({ - let mut __v: Nested = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Nested = ZeroInitializationUnsafe::zero_init(); + Nested::constructor_1(&raw mut __v); __v })); &mut __tmp_88 @@ -1190,11 +1136,8 @@ __v } ) ; let mut __tmp_90: Option>; match ((&mut (*(*{ __tmp_90 = Some(Box::new({ - let mut __v: Temporary = ::zero_init(); - >::constructor( - &raw mut __v, - (), - ); + let mut __v: Temporary = ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); __v })); &mut __tmp_90 @@ -1212,11 +1155,8 @@ __v } ) ; let mut __tmp_92: Option>; match ((&mut (*(*{ __tmp_92 = Some(Box::new({ - let mut __v: Temporary = ::zero_init(); - >::constructor( - &raw mut __v, - (), - ); + let mut __v: Temporary = ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); __v })); &mut __tmp_92 @@ -1232,11 +1172,8 @@ __v } ) ; let mut __tmp_94: Option>; match ((&mut (*((*{ __tmp_94 = Some(Box::new({ - let mut __v: Temporary = ::zero_init(); - >::constructor( - &raw mut __v, - (), - ); + let mut __v: Temporary = ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); __v })); &mut __tmp_94 @@ -1254,11 +1191,8 @@ __v } ) ; let mut __tmp_96: Option>>>; match ((&mut (*((*(*{ __tmp_96 = Some(Box::new(Some(Box::new({ - let mut __v: Temporary = ::zero_init(); - >::constructor( - &raw mut __v, - (), - ); + let mut __v: Temporary = ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); __v })))); &mut __tmp_96 @@ -1310,12 +1244,10 @@ __v } ) ; let mut ordinary: i32 = 9; if (hit != 0) { references.try_emplace(key, || { - let mut __v: Held = ::zero_init(); - >, - )>>::constructor( + let mut __v: Held = ZeroInitializationUnsafe::zero_init(); + Held::constructor_2( &raw mut __v, - (LvalueRefUnsafe::bind(&ordinary),), + LvalueRefUnsafe::bind(&ordinary), ); __v }); @@ -1329,20 +1261,45 @@ __v } ) ; let mut __tmp_99: Option>; { match ((if (choose != 0) { - (& mut ( * ( *{ __tmp_98 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); >::constructor(&raw mut __v, ()) ; -__v } )) ; & mut __tmp_98 } ) .as_deref().map_or(::std::ptr::null_mut(), |v| v as *const Temporary as *mut Temporary ) ) . n as *mut i32 ) + (&mut (*(*{ + __tmp_98 = Some(Box::new({ + let mut __v: Temporary = + ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); + __v + })); + &mut __tmp_98 + }) + .as_deref() + .map_or(::std::ptr::null_mut(), |v| { + v as *const Temporary as *mut Temporary + })) + .n as *mut i32) } else { - (& mut ( * ( *{ __tmp_99 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); >::constructor(&raw mut __v, ()) ; -__v } )) ; & mut __tmp_99 } ) .as_deref().map_or(::std::ptr::null_mut(), |v| v as *const Temporary as *mut Temporary ) ) . data [ ( index .postfix_inc() ) as usize ] as *mut i32 ) + (&mut (*(*{ + __tmp_99 = Some(Box::new({ + let mut __v: Temporary = + ZeroInitializationUnsafe::zero_init(); + Temporary::constructor_1(&raw mut __v); + __v + })); + &mut __tmp_99 + }) + .as_deref() + .map_or(::std::ptr::null_mut(), |v| { + v as *const Temporary as *mut Temporary + })) + .data + [(index.postfix_inc()) as usize] + as *mut i32) } as *mut i32),) { (__tmp_97,) => references.try_emplace(key, || { - let mut __v: Held = ::zero_init(); - >, - )>>::constructor( + let mut __v: Held = + ZeroInitializationUnsafe::zero_init(); + Held::constructor_2( &raw mut __v, - (LvalueRefUnsafe::bind(__tmp_97),), + LvalueRefUnsafe::bind(__tmp_97), ); __v }), @@ -1367,27 +1324,23 @@ __v } )) ; & mut __tmp_99 } ) .as_deref().map_or(::std::ptr::null_mut(), |v| v a ); let mut owners: UnsafeMap = UnsafeMap::new(); { - let mut __tmp_101: Owner = ::zero_init(); + let mut __tmp_101: Owner = ZeroInitializationUnsafe::zero_init(); { match (((unsafe { Owner::value( &mut (*{ - >::constructor( - &raw mut __tmp_101, - (), - ); + Owner::constructor_1(&raw mut __tmp_101); &mut __tmp_101 }), ) }) as *const i32),) { (__tmp_100,) => owners.try_emplace(key, || { - let mut __v: Held = ::zero_init(); - >, - )>>::constructor( + let mut __v: Held = + ZeroInitializationUnsafe::zero_init(); + Held::constructor_2( &raw mut __v, - (LvalueRefUnsafe::bind(__tmp_100),), + LvalueRefUnsafe::bind(__tmp_100), ); __v }), @@ -1412,8 +1365,8 @@ __v } )) ; & mut __tmp_99 } ) .as_deref().map_or(::std::ptr::null_mut(), |v| v a let mut __tmp_103: Option>; match (({ __tmp_103 = Some(Box::new({ - let mut __v: Noncopy = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Noncopy = ZeroInitializationUnsafe::zero_init(); + Noncopy::constructor_1(&raw mut __v); __v })); &mut __tmp_103 @@ -1429,8 +1382,8 @@ __v } )) ; & mut __tmp_99 } ) .as_deref().map_or(::std::ptr::null_mut(), |v| v a let mut __tmp_105: Option>; match (({ __tmp_105 = Some(Box::new({ - let mut __v: Noncopy = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: Noncopy = ZeroInitializationUnsafe::zero_init(); + Noncopy::constructor_1(&raw mut __v); __v })); &mut __tmp_105 diff --git a/tests/unit/out/unsafe/max.rs b/tests/unit/out/unsafe/max.rs index 0df409a805..8b89bb1c51 100644 --- a/tests/unit/out/unsafe/max.rs +++ b/tests/unit/out/unsafe/max.rs @@ -29,26 +29,21 @@ pub unsafe fn pick_3(mut i: i32) -> *mut i32 { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move)] +#[constructor(constructor_1, value(i32))] pub struct Bag { pub n: i32, } -impl ConstructibleFromUnsafe<(i32,)> for Bag { - unsafe fn constructor(this: *mut Self, (mut n,): (i32,)) { +impl Bag { + pub unsafe fn constructor_1(this: *mut Self, mut n: i32) { (&raw mut (*this).n).write(n); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for Bag { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(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(); } } -impl CopyConstructibleUnsafe for Bag {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} impl std::cmp::Ord for Bag { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { @@ -80,7 +75,7 @@ pub unsafe fn operator_lt_4(a: *const Bag, b: *const Bag) -> bool { return (((*a).n) < ((*b).n)); } pub unsafe fn make_5(__return: *mut Bag, mut n: i32) { - >::constructor(__return, (n,)); + Bag::constructor_1(__return, n); return; } pub fn main() { @@ -163,8 +158,8 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) = 0; assert!( ({ - let mut __tmp_5: Bag = ::zero_init(); - let mut __tmp_7: Bag = ::zero_init(); + let mut __tmp_5: Bag = ZeroInitializationUnsafe::zero_init(); + let mut __tmp_7: Bag = ZeroInitializationUnsafe::zero_init(); (((*match ( ({ (unsafe { make_5(&raw mut __tmp_5, 1) }); @@ -183,8 +178,8 @@ unsafe fn main_0() -> i32 { }) .n) == (2)) }) && ({ - let mut __tmp_9: Bag = ::zero_init(); - let mut __tmp_11: Bag = ::zero_init(); + let mut __tmp_9: Bag = ZeroInitializationUnsafe::zero_init(); + let mut __tmp_11: Bag = ZeroInitializationUnsafe::zero_init(); (((*match ( ({ (unsafe { make_5(&raw mut __tmp_9, 1) }); diff --git a/tests/unit/out/unsafe/move_assign.rs b/tests/unit/out/unsafe/move_assign.rs index 9227596b3c..965308afc6 100644 --- a/tests/unit/out/unsafe/move_assign.rs +++ b/tests/unit/out/unsafe/move_assign.rs @@ -15,26 +15,21 @@ use std::rc::Rc; Default, ConversionsUnsafe, )] -#[conversions(move)] -#[constructor(value(i32))] +#[conversions(move = constructor_3)] +#[constructor(constructor_1, value(i32))] pub struct MoveOnly { pub v: i32, } -impl ConstructibleFromUnsafe<(i32,)> for MoveOnly { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl MoveOnly { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for MoveOnly { - unsafe fn constructor(this: *mut Self, (o,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut MoveOnly); (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } -impl MoveConstructibleUnsafe for MoveOnly {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} impl MoveAssignableUnsafe for MoveOnly { unsafe fn move_assign(this: *mut Self, o: RvalueRefUnsafe) -> *mut MoveOnly { let o = (o.as_ptr() as *mut MoveOnly); @@ -48,10 +43,14 @@ impl MoveAssignableUnsafe for MoveOnly { } #[repr(C)] #[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] +#[conversions(default = constructor_1)] pub struct ConstMoveAssign { pub mark: i32, } impl ConstMoveAssign { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).mark).write(0); + } pub unsafe fn operator_assign_2( this: *mut Self, o: *mut ConstMoveAssign, @@ -67,25 +66,20 @@ impl ConstMoveAssign { return &mut (*this); } } -impl ConstructibleFromUnsafe<()> for ConstMoveAssign { - unsafe fn constructor(this: *mut Self, _: ()) { - (&raw mut (*this).mark).write(0); - } -} impl Default for ConstMoveAssign { fn default() -> Self { unsafe { { - let mut __v: ConstMoveAssign = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: ConstMoveAssign = ZeroInitializationUnsafe::zero_init(); + ConstMoveAssign::constructor_1(&raw mut __v); __v } } } } pub unsafe fn make_0(__return: *mut MoveOnly, mut v: i32) { - object_unsafe!(m, MoveOnly, (i32,), (v,)); - ConvertibleToUnsafe::convert(>::bind(&mut m), __return); + object_unsafe!(m, MoveOnly::constructor_1(v)); + MoveOnly::constructor_3(__return, RvalueRefUnsafe::bind(&mut m)); return; } pub fn main() { @@ -95,27 +89,27 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, MoveOnly, (i32,), (1,)); - object_unsafe!(b, MoveOnly, (i32,), (2,)); - object_unsafe!(c, MoveOnly, (i32,), (3,)); + object_unsafe!(a, MoveOnly::constructor_1(1)); + object_unsafe!(b, MoveOnly::constructor_1(2)); + object_unsafe!(c, MoveOnly::constructor_1(3)); assign_unsafe!(a = RvalueRefUnsafe(b)); assert!(((a.v) == (2))); assert!(((b.v) == (0))); (unsafe { - let mut _o: MoveOnly = ::zero_init(); - >::constructor(&raw mut _o, (3,)); + let mut _o: MoveOnly = ZeroInitializationUnsafe::zero_init(); + MoveOnly::constructor_1(&raw mut _o, 3); assign_unsafe!(b = RvalueRefUnsafe(_o)) }); 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(); - >::constructor(&raw mut _o, (5,)); + let mut _o: MoveOnly = ZeroInitializationUnsafe::zero_init(); + MoveOnly::constructor_1(&raw mut _o, 5); assign_unsafe!(a = RvalueRefUnsafe(_o)) }); assert!(((a.v) == (5))); (unsafe { - let mut _o: MoveOnly = ::zero_init(); + let mut _o: MoveOnly = ZeroInitializationUnsafe::zero_init(); (unsafe { make_0(&raw mut _o, 6) }); assign_unsafe!(a = RvalueRefUnsafe(_o)) }); @@ -127,23 +121,23 @@ unsafe fn main_0() -> i32 { assert!(((a.v) == (6))); let mut vec_: Vec = Vec::new(); { - let mut __tmp_1: MoveOnly = ::zero_init(); + let mut __tmp_1: MoveOnly = ZeroInitializationUnsafe::zero_init(); match (({ - >::constructor(&raw mut __tmp_1, (7,)); + MoveOnly::constructor_1(&raw mut __tmp_1, 7); &mut __tmp_1 } as *mut MoveOnly),) { (__tmp_0,) => vec_.push_moved(__tmp_0), } }; - object_unsafe!(d, MoveOnly, (i32,), (8,)); + object_unsafe!(d, MoveOnly::constructor_1(8)); assign_unsafe!(vec_[(0_usize)] = RvalueRefUnsafe(d)); assert!(((vec_[(0_usize)].v) == (8))); assert!(((d.v) == (0))); - object_unsafe!(m, ConstMoveAssign); - object_unsafe!(m1, ConstMoveAssign); - object_unsafe!(m2, ConstMoveAssign); - object_unsafe!(cm, ConstMoveAssign); + object_unsafe!(m, ConstMoveAssign::constructor_1()); + object_unsafe!(m1, ConstMoveAssign::constructor_1()); + object_unsafe!(m2, ConstMoveAssign::constructor_1()); + object_unsafe!(cm, ConstMoveAssign::constructor_1()); (unsafe { ConstMoveAssign::operator_assign_2(&raw mut m1, &mut m) }); (unsafe { ConstMoveAssign::operator_assign_3(&raw mut m2, &cm) }); assert!(((m1.mark) == (1))); diff --git a/tests/unit/out/unsafe/move_ctor.rs b/tests/unit/out/unsafe/move_ctor.rs index 0e7f9ce6ac..4bb0f044b6 100644 --- a/tests/unit/out/unsafe/move_ctor.rs +++ b/tests/unit/out/unsafe/move_ctor.rs @@ -10,57 +10,47 @@ use std::rc::Rc; #[derive( FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[conversions(move)] -#[constructor(value(i32))] +#[conversions(move = constructor_3)] +#[constructor(constructor_1, value(i32))] pub struct MoveOnly { pub v: i32, } -impl ConstructibleFromUnsafe<(i32,)> for MoveOnly { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl MoveOnly { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for MoveOnly { - unsafe fn constructor(this: *mut Self, (o,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut MoveOnly); (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } -impl MoveConstructibleUnsafe for MoveOnly {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} #[repr(C)] #[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] -#[conversions(move)] +#[conversions(move = constructor_2, default = constructor_1)] +#[constructor(constructor_3, const_rvalue_ref(ConstMove))] pub struct ConstMove { pub mark: i32, } -impl ConstructibleFromUnsafe<()> for ConstMove { - unsafe fn constructor(this: *mut Self, _: ()) { +impl ConstMove { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).mark).write(0); } -} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for ConstMove { - unsafe fn constructor(this: *mut Self, (o,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_2(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut ConstMove); (&raw mut (*this).mark).write((((*o).mark) + (1))); } -} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe>,)> for ConstMove { - unsafe fn constructor(this: *mut Self, (o,): (RvalueRefUnsafe>,)) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe>) { let o = (o.as_ptr() as *const ConstMove); (&raw mut (*this).mark).write((((*o).mark) + (10))); } } -impl ConvertibleToUnsafe for RvalueRefUnsafe> {} impl Default for ConstMove { fn default() -> Self { unsafe { { - let mut __v: ConstMove = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: ConstMove = ZeroInitializationUnsafe::zero_init(); + ConstMove::constructor_1(&raw mut __v); __v } } @@ -70,33 +60,26 @@ impl Default for ConstMove { #[derive( FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] pub struct ThrowingMove { pub v: i32, pub copies: i32, pub moves: i32, } -impl ConstructibleFromUnsafe<(i32,)> for ThrowingMove { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl ThrowingMove { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).copies).write(0); (&raw mut (*this).moves).write(0); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for ThrowingMove { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(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 CopyConstructibleUnsafe for ThrowingMove {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for ThrowingMove { - unsafe fn constructor(this: *mut Self, (o,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_3(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); @@ -104,39 +87,30 @@ impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for ThrowingMove { (*o).v = 0; } } -impl MoveConstructibleUnsafe for ThrowingMove {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} #[repr(C)] #[derive( FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] pub struct NoexceptMove { pub v: i32, pub copies: i32, pub moves: i32, } -impl ConstructibleFromUnsafe<(i32,)> for NoexceptMove { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl NoexceptMove { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).copies).write(0); (&raw mut (*this).moves).write(0); } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for NoexceptMove { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe>,)) { + pub unsafe fn constructor_2(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 CopyConstructibleUnsafe for NoexceptMove {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for NoexceptMove { - unsafe fn constructor(this: *mut Self, (o,): (RvalueRefUnsafe,)) { + pub unsafe fn constructor_3(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); @@ -144,14 +118,12 @@ impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for NoexceptMove { (*o).v = 0; } } -impl MoveConstructibleUnsafe for NoexceptMove {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} pub unsafe fn by_value_0(m: *mut MoveOnly) -> i32 { return (*m).v; } pub unsafe fn make_1(__return: *mut MoveOnly, mut v: i32) { - object_unsafe!(m, MoveOnly, (i32,), (v,)); - ConvertibleToUnsafe::convert(>::bind(&mut m), __return); + object_unsafe!(m, MoveOnly::constructor_1(v)); + MoveOnly::constructor_3(__return, RvalueRefUnsafe::bind(&mut m)); return; } pub fn main() { @@ -161,88 +133,78 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, MoveOnly, (i32,), (1,)); - object_unsafe!(b, MoveOnly, RvalueRefUnsafe::bind(&mut a)); + object_unsafe!(a, MoveOnly::constructor_1(1)); + object_unsafe!(b, MoveOnly::constructor_3(RvalueRefUnsafe::bind(&mut a))); assert!(((b.v) == (1))); assert!(((a.v) == (0))); - object_unsafe!(c, MoveOnly = >::bind(&mut b)); + object_unsafe!(c, MoveOnly::constructor_3(RvalueRefUnsafe::bind(&mut b))); assert!(((c.v) == (1))); assert!(((b.v) == (0))); - object_unsafe!(d, MoveOnly, RvalueRefUnsafe::bind(&mut c)); + object_unsafe!(d, MoveOnly::constructor_3(RvalueRefUnsafe::bind(&mut c))); assert!(((d.v) == (1))); assert!(((c.v) == (0))); object_unsafe!(e, MoveOnly, |e| (unsafe { make_1(e, 5,) })); assert!(((e.v) == (5))); assert!( ((unsafe { - let mut _m: MoveOnly = ::zero_init(); - >::constructor(&raw mut _m, (6,)); + let mut _m: MoveOnly = ZeroInitializationUnsafe::zero_init(); + MoveOnly::constructor_1(&raw mut _m, 6); by_value_0(&mut _m) }) == (6)) ); assert!( ((unsafe { - let mut _m: MoveOnly = ::zero_init(); - ,)>>::constructor( - &raw mut _m, - (RvalueRefUnsafe::bind(&mut e),), - ); + let mut _m: MoveOnly = ZeroInitializationUnsafe::zero_init(); + MoveOnly::constructor_3(&raw mut _m, RvalueRefUnsafe::bind(&mut e)); by_value_0(&mut _m) }) == (5)) ); assert!(((e.v) == (0))); let mut vec_: Vec = Vec::new(); { - let mut __tmp_1: MoveOnly = ::zero_init(); + let mut __tmp_1: MoveOnly = ZeroInitializationUnsafe::zero_init(); match (({ - >::constructor(&raw mut __tmp_1, (7,)); + MoveOnly::constructor_1(&raw mut __tmp_1, 7); &mut __tmp_1 } as *mut MoveOnly),) { (__tmp_0,) => vec_.push_moved(__tmp_0), } }; - object_unsafe!(f, MoveOnly, (i32,), (8,)); + object_unsafe!(f, MoveOnly::constructor_1(8)); vec_.push_moved(&mut f); assert!(((vec_[(0_usize)].v) == (7)) && ((vec_[(1_usize)].v) == (8))); assert!(((f.v) == (0))); - object_unsafe!(m, ConstMove); - object_unsafe!( - m1, - ConstMove, - (RvalueRefUnsafe,), - (RvalueRefUnsafe::bind(&mut m),) - ); - object_unsafe!(cm, ConstMove); - object_unsafe!( - m2, - ConstMove, - (RvalueRefUnsafe>,), - (RvalueRefUnsafe::bind(&cm),) - ); + object_unsafe!(m, ConstMove::constructor_1()); + object_unsafe!(m1, ConstMove::constructor_2(RvalueRefUnsafe::bind(&mut m))); + object_unsafe!(cm, ConstMove::constructor_1()); + object_unsafe!(m2, ConstMove::constructor_3(RvalueRefUnsafe::bind(&cm))); assert!(((m1.mark) == (1))); assert!(((m2.mark) == (10))); - object_unsafe!(t, ThrowingMove, (i32,), (1,)); - object_unsafe!(t1, ThrowingMove, LvalueRefUnsafe::bind(&t)); + object_unsafe!(t, ThrowingMove::constructor_1(1)); + object_unsafe!(t1, ThrowingMove::constructor_2(LvalueRefUnsafe::bind(&t))); assert!(((t1.v) == (1))); assert!(((t1.copies) == (1))); assert!(((t1.moves) == (0))); assert!(((t.v) == (1))); - object_unsafe!(n, NoexceptMove, (i32,), (2,)); - object_unsafe!(n1, NoexceptMove, RvalueRefUnsafe::bind(&mut n)); + object_unsafe!(n, NoexceptMove::constructor_1(2)); + object_unsafe!( + n1, + NoexceptMove::constructor_3(RvalueRefUnsafe::bind(&mut n)) + ); assert!(((n1.v) == (2))); assert!(((n1.copies) == (0))); assert!(((n1.moves) == (1))); assert!(((n.v) == (0))); - object_unsafe!(g, MoveOnly, (i32,), (3,)); - object_unsafe!(g1, MoveOnly, RvalueRefUnsafe::bind(&mut g)); + object_unsafe!(g, MoveOnly::constructor_1(3)); + object_unsafe!(g1, MoveOnly::constructor_3(RvalueRefUnsafe::bind(&mut g))); assert!(((g1.v) == (3))); assert!(((g.v) == (0))); let mut nv: Vec = Vec::new(); { - let mut __tmp_3: NoexceptMove = ::zero_init(); + let mut __tmp_3: NoexceptMove = ZeroInitializationUnsafe::zero_init(); match (({ - >::constructor(&raw mut __tmp_3, (4,)); + NoexceptMove::constructor_1(&raw mut __tmp_3, 4); &mut __tmp_3 } as *mut NoexceptMove),) { diff --git a/tests/unit/out/unsafe/move_this.rs b/tests/unit/out/unsafe/move_this.rs index 79b91a3616..0cbc81a0c4 100644 --- a/tests/unit/out/unsafe/move_this.rs +++ b/tests/unit/out/unsafe/move_this.rs @@ -10,12 +10,24 @@ use std::rc::Rc; #[derive( FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[conversions(copy, move)] -#[constructor(value(i32))] +#[conversions(copy = constructor_2, move = constructor_3)] +#[constructor(constructor_1, value(i32))] pub struct Chain { pub v: i32, } impl Chain { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); + } + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Chain); + (&raw mut (*this).v).write((((*o).v) + (100))); + } + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Chain); + (&raw mut (*this).v).write((((*o).v) + (1))); + (*o).v = 0; + } pub unsafe fn add_4(this: *mut Self, mut n: i32) -> *mut Chain { (*this).v += n; return &mut (*this); @@ -25,40 +37,17 @@ impl Chain { return &mut (*this); } pub unsafe fn take(this: *mut Self, __return: *mut Chain) { - ConvertibleToUnsafe::convert(>::bind(&mut (*this)), __return); + Chain::constructor_3(__return, RvalueRefUnsafe::bind(&mut (*this))); return; } pub unsafe fn copy(this: *const Self, __return: *mut Chain) { - ConvertibleToUnsafe::convert(>>::bind(&(*this)), __return); + Chain::constructor_2(__return, LvalueRefUnsafe::bind(&(*this))); return; } pub unsafe fn self_(this: *mut Self) -> *mut Chain { return &mut (*this); } } -impl ConstructibleFromUnsafe<(i32,)> for Chain { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { - (&raw mut (*this).v).write(v); - } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for Chain { - unsafe fn constructor(this: *mut Self, (o,): (LvalueRefUnsafe>,)) { - let o = (o.as_ptr() as *const Chain); - (&raw mut (*this).v).write((((*o).v) + (100))); - } -} -impl CopyConstructibleUnsafe for Chain {} -impl ConvertibleToUnsafe for LvalueRefUnsafe> {} -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for Chain { - unsafe fn 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; - } -} -impl MoveConstructibleUnsafe for Chain {} -impl ConvertibleToUnsafe for RvalueRefUnsafe {} pub unsafe fn consume_0(c: *mut Chain) -> i32 { return (*c).v; } @@ -69,26 +58,23 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, Chain, (i32,), (1,)); + object_unsafe!(a, Chain::constructor_1(1)); (unsafe { Chain::add_4(&raw mut (*(unsafe { Chain::add_4(&raw mut a, 1) })), 1) }); assert!(((a.v) == (3))); - object_unsafe!(b0, Chain, (i32,), (5,)); + object_unsafe!(b0, Chain::constructor_1(5)); object_unsafe!( b, - Chain = >::bind( + Chain::constructor_3(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| { - let mut __tmp_0: Chain = ::zero_init(); + let mut __tmp_0: Chain = ZeroInitializationUnsafe::zero_init(); (unsafe { Chain::take( &mut (*{ - >::constructor( - &raw mut __tmp_0, - (10,), - ); + Chain::constructor_1(&raw mut __tmp_0, 10); &mut __tmp_0 }), c, @@ -98,18 +84,18 @@ unsafe fn main_0() -> i32 { assert!(((c.v) == (11))); object_unsafe!(d, Chain, |d| (unsafe { Chain::copy(&raw const c, d,) })); assert!(((d.v) == (111)) && ((c.v) == (11))); - object_unsafe!(g, Chain, (i32,), (20,)); + object_unsafe!(g, Chain::constructor_1(20)); assert!( ((unsafe { - let mut _c: Chain = ::zero_init(); - ,)>>::constructor( + let mut _c: Chain = ZeroInitializationUnsafe::zero_init(); + Chain::constructor_3( &raw mut _c, - (RvalueRefUnsafe::bind((unsafe { Chain::self_(&raw mut g) })),), + RvalueRefUnsafe::bind((unsafe { Chain::self_(&raw mut g) })), ); consume_0(&mut _c) }) == (21)) ); - object_unsafe!(e, Chain, (i32,), (30,)); + object_unsafe!(e, Chain::constructor_1(30)); object_unsafe!(f, Chain, |f| (unsafe { Chain::take(&raw mut e, f,) })); assert!(((f.v) == (31)) && ((e.v) == (0))); return 0; diff --git a/tests/unit/out/unsafe/opaque_forward_decl.rs b/tests/unit/out/unsafe/opaque_forward_decl.rs index 6ca925f1a0..54d591d405 100644 --- a/tests/unit/out/unsafe/opaque_forward_decl.rs +++ b/tests/unit/out/unsafe/opaque_forward_decl.rs @@ -34,21 +34,15 @@ unsafe fn main_0() -> i32 { }; return ((c.x) - (42)); } -#[derive(Clone, Copy, Default, VaArg, FnPtrArg)] +#[derive( + Clone, + Copy, + Default, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + ConversionsUnsafe, +)] pub struct opaque; -impl libcc2rs::overload::ConversionsUnsafe for opaque { - fn table() -> libcc2rs::overload::Table<*mut ::std::ffi::c_void> { - libcc2rs::overload::Table { - id: ::std::any::TypeId::of::(), - name: "opaque", - arithmetic: None, - storage: || Box::into_raw(Box::new(opaque)).cast(), - release: |ptr| drop(unsafe { Box::from_raw(ptr.cast::()) }), - copy: |_, _| {}, - move_from: |_, _| {}, - constructors: vec![], - conversion_functions: vec![], - } - } -} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_comparison_nonbool.rs b/tests/unit/out/unsafe/operator_comparison_nonbool.rs index f4edfb4476..2a8d277bf3 100644 --- a/tests/unit/out/unsafe/operator_comparison_nonbool.rs +++ b/tests/unit/out/unsafe/operator_comparison_nonbool.rs @@ -182,24 +182,21 @@ impl std::cmp::Eq for Mixed {} ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(explicit, value(bool))] -#[conversion_function(bool, const_lvalue_ref)] +#[constructor(constructor_1, explicit, value(bool))] +#[conversion_function(conversion_function_2, bool, const_lvalue_ref)] pub struct MyBool { pub value: bool, } -impl ConstructibleFromUnsafe<(bool,)> for MyBool { - unsafe fn constructor(this: *mut Self, (mut v,): (bool,)) { +impl MyBool { + pub unsafe fn constructor_1(this: *mut Self, mut v: bool) { (&raw mut (*this).value).write(v); } -} -impl ConversionFunctionUnsafe>> for MyBool { - unsafe fn conversion_function(this: LvalueRefUnsafe>, to: *mut bool) { + pub unsafe fn conversion_function_2(this: LvalueRefUnsafe>, __return: *mut bool) { let this = this.as_ptr() as *mut MyBool; - to.write((*this).value); + __return.write((*this).value); return; } } -impl ImplicitConversionFunctionUnsafe>> for MyBool {} #[repr(C)] #[derive( Copy, @@ -224,8 +221,8 @@ impl std::cmp::Ord for Boolish { (*(self as *const Self)).clone(), (*(other as *const Self)).clone(), ); - let mut __v: bool = false; - MyBool::conversion_function( + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + MyBool::conversion_function_2( >>::bind(&raw const __cmp), &raw mut __v, ); @@ -237,8 +234,8 @@ impl std::cmp::Ord for Boolish { (*(other as *const Self)).clone(), (*(self as *const Self)).clone(), ); - let mut __v: bool = false; - MyBool::conversion_function( + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + MyBool::conversion_function_2( >>::bind(&raw const __cmp), &raw mut __v, ); @@ -264,8 +261,8 @@ impl std::cmp::PartialEq for Boolish { (*(self as *const Self)).clone(), (*(other as *const Self)).clone(), ); - let mut __v: bool = false; - MyBool::conversion_function( + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + MyBool::conversion_function_2( >>::bind(&raw const __cmp), &raw mut __v, ); @@ -277,18 +274,15 @@ impl std::cmp::PartialEq for Boolish { impl std::cmp::Eq for Boolish {} pub unsafe fn operator_eq_7(mut a: Boolish, mut b: Boolish) -> MyBool { return { - let mut __v: MyBool = ::zero_init(); - >::constructor( - &raw mut __v, - (((a.v) == (b.v)),), - ); + let mut __v: MyBool = ZeroInitializationUnsafe::zero_init(); + MyBool::constructor_1(&raw mut __v, ((a.v) == (b.v))); __v }; } pub unsafe fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { return { - let mut __v: MyBool = ::zero_init(); - >::constructor(&raw mut __v, (((a.v) < (b.v)),)); + let mut __v: MyBool = ZeroInitializationUnsafe::zero_init(); + MyBool::constructor_1(&raw mut __v, ((a.v) < (b.v))); __v }; } @@ -303,28 +297,28 @@ pub unsafe fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[constructor(explicit, value(bool))] -#[conversion_function(bool, const_lvalue_ref)] +#[constructor(constructor_1, explicit, value(bool))] +#[conversion_function(conversion_function_3, bool, const_lvalue_ref)] pub struct RefBool { pub value: bool, } -impl ConstructibleFromUnsafe<(bool,)> for RefBool { - unsafe fn constructor(this: *mut Self, (mut v,): (bool,)) { +impl RefBool { + pub unsafe fn constructor_1(this: *mut Self, mut v: bool) { (&raw mut (*this).value).write(v); } -} -impl ConversionFunctionUnsafe>> for RefBool { - unsafe fn conversion_function(this: LvalueRefUnsafe>, to: *mut bool) { + pub unsafe fn conversion_function_3( + this: LvalueRefUnsafe>, + __return: *mut bool, + ) { let this = this.as_ptr() as *mut RefBool; - to.write((*this).value); + __return.write((*this).value); return; } } -impl ImplicitConversionFunctionUnsafe>> for RefBool {} pub static mut ref_true_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __v: RefBool = ::zero_init(); - >::constructor(&raw mut __v, (true,)); + let mut __v: RefBool = ZeroInitializationUnsafe::zero_init(); + RefBool::constructor_1(&raw mut __v, true); __v } }); @@ -454,8 +448,8 @@ unsafe fn main_0() -> i32 { let mut b1: Boolish = Boolish { v: 1 }; let mut b2: Boolish = Boolish { v: 2 }; assert!({ - let mut __v: bool = false; - MyBool::conversion_function( + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + MyBool::conversion_function_2( >>::bind( &mut (unsafe { let _a: Boolish = b1; @@ -468,8 +462,8 @@ unsafe fn main_0() -> i32 { }); assert!( !({ - let mut __v: bool = false; - MyBool::conversion_function( + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + MyBool::conversion_function_2( >>::bind( &mut (unsafe { let _a: Boolish = b2; @@ -507,8 +501,8 @@ unsafe fn main_0() -> i32 { let mut ri1: RefInt = RefInt { v: 1 }; let mut ri2: RefInt = RefInt { v: 2 }; assert!({ - let mut __v: bool = false; - RefBool::conversion_function( + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + RefBool::conversion_function_3( >>::bind( (unsafe { RefInt::operator_eq(&raw const ri1, &ri2) }), ), @@ -535,8 +529,8 @@ impl WeaklyEqualityComparableWithUnsafe for Boolish { unsafe fn equal(a: *const Self, b: *const Self) -> bool { { let __cmp = operator_eq_7((*a).clone(), (*b).clone()); - let mut __v: bool = false; - MyBool::conversion_function( + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + MyBool::conversion_function_2( >>::bind(&raw const __cmp), &raw mut __v, ); @@ -553,8 +547,8 @@ impl WeaklyEqualityComparableWithUnsafe for RefInt { unsafe fn equal(this: *const Self, _a0: *const Self) -> bool { { let __cmp = RefInt::operator_eq(this, _a0); - let mut __v: bool = false; - RefBool::conversion_function( + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + RefBool::conversion_function_3( >>::bind(&raw const *__cmp), &raw mut __v, ); diff --git a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs index e3245531ea..978c759aed 100644 --- a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs +++ b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs @@ -16,16 +16,15 @@ pub unsafe fn operator_lt_0(x: *const S, y: *const S) -> bool { #[memberwise(move_constructor)] #[derive(ConversionsUnsafe)] #[conversions(move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] pub struct S { data_: i32, } -impl ConstructibleFromUnsafe<(i32,)> for S { - unsafe fn constructor(this: *mut Self, (mut data,): (i32,)) { +impl S { + pub unsafe fn constructor_1(this: *mut Self, mut data: i32) { (&raw mut (*this).data_).write(data); } } -impl ConvertibleToUnsafe for i32 {} impl std::cmp::Ord for S { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { @@ -59,9 +58,9 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, S, (i32,), (1,)); - object_unsafe!(b, S, (i32,), (2,)); - object_unsafe!(c, S, (i32,), (1,)); + object_unsafe!(a, S::constructor_1(1)); + object_unsafe!(b, S::constructor_1(2)); + object_unsafe!(c, S::constructor_1(1)); assert!( (unsafe { let _x: *const S = &a; diff --git a/tests/unit/out/unsafe/operator_other_member.rs b/tests/unit/out/unsafe/operator_other_member.rs index ebd0b36ce6..7ec461d9c1 100644 --- a/tests/unit/out/unsafe/operator_other_member.rs +++ b/tests/unit/out/unsafe/operator_other_member.rs @@ -38,8 +38,8 @@ impl Static { ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(i32, const_lvalue_ref)] -#[conversion_function(bool, const_lvalue_ref, explicit)] +#[conversion_function(conversion_function_5, i32, const_lvalue_ref)] +#[conversion_function(conversion_function_6, bool, const_lvalue_ref, explicit)] pub struct S { pub v: i32, } @@ -58,19 +58,14 @@ impl S { v: ((((*this).v) * (10)) + ((*o).v)), }; } -} -impl ConversionFunctionUnsafe>> for S { - unsafe fn conversion_function(this: LvalueRefUnsafe>, to: *mut i32) { + pub unsafe fn conversion_function_5(this: LvalueRefUnsafe>, __return: *mut i32) { let this = this.as_ptr() as *mut S; - to.write((*this).v); + __return.write((*this).v); return; } -} -impl ImplicitConversionFunctionUnsafe>> for S {} -impl ConversionFunctionUnsafe>> for S { - unsafe fn conversion_function(this: LvalueRefUnsafe>, to: *mut bool) { + pub unsafe fn conversion_function_6(this: LvalueRefUnsafe>, __return: *mut bool) { let this = this.as_ptr() as *mut S; - to.write((((*this).v) != (0))); + __return.write((((*this).v) != (0))); return; } } @@ -88,27 +83,27 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { S::operator_call_3(&raw const s, 1, 2,) }) == (6))); assert!((((unsafe { S::operator_comma(&raw const s, &t,) }).v) == (34))); let mut i: i32 = { - let mut __v: i32 = 0_i32; - S::conversion_function(>>::bind(&mut s), &raw mut __v); + let mut __v: i32 = ZeroInitializationUnsafe::zero_init(); + S::conversion_function_5(>>::bind(&mut s), &raw mut __v); __v }; assert!(((i) == (3))); assert!( ((({ - let mut __v: i32 = 0_i32; - S::conversion_function(>>::bind(&mut s), &raw mut __v); + let mut __v: i32 = ZeroInitializationUnsafe::zero_init(); + S::conversion_function_5(>>::bind(&mut s), &raw mut __v); __v }) + (1)) == (4)) ); if { - let mut __v: bool = false; - S::conversion_function(>>::bind(&mut s), &raw mut __v); + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + S::conversion_function_6(>>::bind(&mut s), &raw mut __v); __v } { assert!({ - let mut __v: bool = false; - S::conversion_function(>>::bind(&mut s), &raw mut __v); + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + S::conversion_function_6(>>::bind(&mut s), &raw mut __v); __v }); } else { @@ -116,25 +111,25 @@ unsafe fn main_0() -> i32 { } let mut z: S = S { v: 0 }; assert!({ - let mut __v: bool = false; - S::conversion_function(>>::bind(&mut s), &raw mut __v); + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + S::conversion_function_6(>>::bind(&mut s), &raw mut __v); __v }); assert!( !({ - let mut __v: bool = false; - S::conversion_function(>>::bind(&mut z), &raw mut __v); + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + S::conversion_function_6(>>::bind(&mut z), &raw mut __v); __v }) ); assert!( ({ - let mut __v: bool = false; - S::conversion_function(>>::bind(&mut s), &raw mut __v); + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + S::conversion_function_6(>>::bind(&mut s), &raw mut __v); __v }) && (!({ - let mut __v: bool = false; - S::conversion_function(>>::bind(&mut z), &raw mut __v); + let mut __v: bool = ZeroInitializationUnsafe::zero_init(); + S::conversion_function_6(>>::bind(&mut z), &raw mut __v); __v })) ); diff --git a/tests/unit/out/unsafe/pair.rs b/tests/unit/out/unsafe/pair.rs index e75dc8c903..bae0c585f0 100644 --- a/tests/unit/out/unsafe/pair.rs +++ b/tests/unit/out/unsafe/pair.rs @@ -21,13 +21,13 @@ unsafe fn main_0() -> i32 { assert!(((p2.1) == (4))); let mut p3: (f64, i32) = match ((&mut (5, 6) as *mut (i32, i32)),) { (__tmp_0,) => { - object_unsafe!(__first, f64, |__this| ConversionsUnsafe::construct( + object_unsafe!(__first, f64, |__this| ConstructibleFromUnsafe::construct( __this, - &[overload::Arg::rvalue_unsafe(&raw mut (*__tmp_0).0)] + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_0).0),) )); - object_unsafe!(__second, i32, |__this| ConversionsUnsafe::construct( + object_unsafe!(__second, i32, |__this| ConstructibleFromUnsafe::construct( __this, - &[overload::Arg::rvalue_unsafe(&raw mut (*__tmp_0).1)] + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_0).1),) )); ( move_constructed_unsafe(&raw mut __first), @@ -46,13 +46,13 @@ unsafe fn main_0() -> i32 { (&mut (arr.as_ptr().offset((1) as isize), n) as *mut (*const i32, u32)), ) { (__tmp_1, __tmp_2) => { - object_unsafe!(__first, *const i32, |__this| ConversionsUnsafe::convert( - __this, - overload::Arg::rvalue_unsafe(&raw mut (*__tmp_2).0) + object_unsafe!(__first, *const i32, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::<*const i32>::bind(&raw mut (*__tmp_2).0), + __this )); - object_unsafe!(__second, u64, |__this| ConversionsUnsafe::convert( - __this, - overload::Arg::rvalue_unsafe(&raw mut (*__tmp_2).1) + object_unsafe!(__second, u64, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut (*__tmp_2).1), + __this )); MoveAssignableUnsafe::move_assign( &raw mut (*__tmp_1).0, @@ -103,13 +103,13 @@ unsafe fn main_0() -> i32 { let mut narrow: (i32, i32) = (3, 4); let mut pw: *mut i64 = (&mut w.0 as *mut i64); { - object_unsafe!(__first, i64, |__this| ConversionsUnsafe::convert( - __this, - overload::Arg::const_lvalue_unsafe(&raw const narrow.0) + object_unsafe!(__first, i64, |__this| ConvertibleToUnsafe::convert( + LvalueRefUnsafe::>::bind(&raw const narrow.0), + __this )); - object_unsafe!(__second, i64, |__this| ConversionsUnsafe::convert( - __this, - overload::Arg::const_lvalue_unsafe(&raw const narrow.1) + object_unsafe!(__second, i64, |__this| ConvertibleToUnsafe::convert( + LvalueRefUnsafe::>::bind(&raw const narrow.1), + __this )); MoveAssignableUnsafe::move_assign( &raw mut w.0, @@ -123,13 +123,13 @@ unsafe fn main_0() -> i32 { assert!(((*pw) == (3_i64))); let mut m: (i32, i32) = (5, 6); { - object_unsafe!(__first, i64, |__this| ConversionsUnsafe::convert( - __this, - overload::Arg::rvalue_unsafe(&raw mut m.0) + object_unsafe!(__first, i64, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut m.0), + __this )); - object_unsafe!(__second, i64, |__this| ConversionsUnsafe::convert( - __this, - overload::Arg::rvalue_unsafe(&raw mut m.1) + object_unsafe!(__second, i64, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut m.1), + __this )); MoveAssignableUnsafe::move_assign( &raw mut w.0, @@ -156,13 +156,13 @@ unsafe fn main_0() -> i32 { .0 = 8; assert!(((d.0) == (8)) && ((d.1) == (4))); (*{ - object_unsafe!(__first, i64, |__this| ConversionsUnsafe::convert( - __this, - overload::Arg::const_lvalue_unsafe(&raw const narrow.0) + object_unsafe!(__first, i64, |__this| ConvertibleToUnsafe::convert( + LvalueRefUnsafe::>::bind(&raw const narrow.0), + __this )); - object_unsafe!(__second, i64, |__this| ConversionsUnsafe::convert( - __this, - overload::Arg::const_lvalue_unsafe(&raw const narrow.1) + object_unsafe!(__second, i64, |__this| ConvertibleToUnsafe::convert( + LvalueRefUnsafe::>::bind(&raw const narrow.1), + __this )); MoveAssignableUnsafe::move_assign( &raw mut w.0, @@ -177,13 +177,13 @@ unsafe fn main_0() -> i32 { .1 = 9_i64; assert!(((w.0) == (3_i64)) && ((w.1) == (9_i64))); (*{ - object_unsafe!(__first, i64, |__this| ConversionsUnsafe::convert( - __this, - overload::Arg::rvalue_unsafe(&raw mut narrow.0) + object_unsafe!(__first, i64, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut narrow.0), + __this )); - object_unsafe!(__second, i64, |__this| ConversionsUnsafe::convert( - __this, - overload::Arg::rvalue_unsafe(&raw mut narrow.1) + object_unsafe!(__second, i64, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut narrow.1), + __this )); MoveAssignableUnsafe::move_assign( &raw mut w.0, diff --git a/tests/unit/out/unsafe/pair_converting_construction.rs b/tests/unit/out/unsafe/pair_converting_construction.rs index 147d4454cc..9ae762d789 100644 --- a/tests/unit/out/unsafe/pair_converting_construction.rs +++ b/tests/unit/out/unsafe/pair_converting_construction.rs @@ -19,16 +19,15 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] pub struct Celsius { pub degrees: i32, } -impl ConstructibleFromUnsafe<(i32,)> for Celsius { - unsafe fn constructor(this: *mut Self, (mut d,): (i32,)) { +impl Celsius { + pub unsafe fn constructor_1(this: *mut Self, mut d: i32) { (&raw mut (*this).degrees).write(d); } } -impl ConvertibleToUnsafe for i32 {} #[repr(C)] #[derive( Copy, @@ -42,18 +41,17 @@ impl ConvertibleToUnsafe for i32 {} ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(i32, const_lvalue_ref)] +#[conversion_function(conversion_function_1, i32, const_lvalue_ref)] pub struct Meters { pub value: i32, } -impl ConversionFunctionUnsafe>> for Meters { - unsafe fn conversion_function(this: LvalueRefUnsafe>, to: *mut i32) { +impl Meters { + pub unsafe fn conversion_function_1(this: LvalueRefUnsafe>, __return: *mut i32) { let this = this.as_ptr() as *mut Meters; - to.write((*this).value); + __return.write((*this).value); return; } } -impl ImplicitConversionFunctionUnsafe>> for Meters {} #[repr(C)] #[derive( Copy, @@ -67,17 +65,16 @@ impl ImplicitConversionFunctionUnsafe>> for M ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(const_lvalue_ref(Celsius))] +#[constructor(constructor_1, const_lvalue_ref(Celsius))] pub struct Label { pub id: i32, } -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for Label { - unsafe fn constructor(this: *mut Self, (c,): (LvalueRefUnsafe>,)) { +impl Label { + pub unsafe fn constructor_1(this: *mut Self, c: LvalueRefUnsafe>) { let c = (c.as_ptr() as *const Celsius); (&raw mut (*this).id).write((*c).degrees); } } -impl ConvertibleToUnsafe for i32 {} impl Default for A { fn default() -> Self { unsafe { { - let mut __v: A = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: A = ZeroInitializationUnsafe::zero_init(); + A::constructor_1(&raw mut __v); __v } } @@ -53,12 +50,12 @@ impl Default for A { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct B { pub v: i32, } -impl ConstructibleFromUnsafe<()> for B { - unsafe fn constructor(this: *mut Self, _: ()) { +impl B { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write(2); } } @@ -66,8 +63,8 @@ impl Default for B { fn default() -> Self { unsafe { { - let mut __v: B = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: B = ZeroInitializationUnsafe::zero_init(); + B::constructor_1(&raw mut __v); __v } } @@ -86,16 +83,15 @@ impl Default for B { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] pub struct NoDefault { pub v: i32, } -impl ConstructibleFromUnsafe<(i32,)> for NoDefault { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl NoDefault { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } } -impl ConvertibleToUnsafe for i32 {} pub unsafe fn used_0(mut x: A) -> i32 { return x.v; } @@ -121,21 +117,18 @@ pub unsafe fn always_given_3(mut x: NoDefault) -> i32 { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] pub struct S_NoDefault_ { pub v: i32, } impl S_NoDefault_ { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); + } pub unsafe fn get(this: *const Self, mut t: NoDefault) -> i32 { return (((*this).v) + (t.v)); } } -impl ConstructibleFromUnsafe<(i32,)> for S_NoDefault_ { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { - (&raw mut (*this).v).write(v); - } -} -impl ConvertibleToUnsafe for i32 {} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -146,8 +139,8 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { used_0({ - let mut __v: A = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: A = ZeroInitializationUnsafe::zero_init(); + A::constructor_1(&raw mut __v); __v }) }) == (1)) @@ -155,8 +148,8 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { used_0({ - let mut __v: A = ::zero_init(); - >::constructor(&raw mut __v, (5,)); + let mut __v: A = ZeroInitializationUnsafe::zero_init(); + A::constructor_2(&raw mut __v, 5); __v }) }) == (5)) @@ -164,8 +157,8 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { used_1({ - let mut __v: B = ::zero_init(); - >::constructor(&raw mut __v, ()); + let mut __v: B = ZeroInitializationUnsafe::zero_init(); + B::constructor_1(&raw mut __v); __v }) }) == (2)) @@ -174,8 +167,8 @@ unsafe fn main_0() -> i32 { ((unsafe { scaled_2( { - let mut __v: A = ::zero_init(); - >::constructor(&raw mut __v, (3,)); + let mut __v: A = ZeroInitializationUnsafe::zero_init(); + A::constructor_2(&raw mut __v, 3); __v }, (::std::mem::size_of::() as i32), @@ -186,8 +179,8 @@ unsafe fn main_0() -> i32 { ((unsafe { scaled_2( { - let mut __v: A = ::zero_init(); - >::constructor(&raw mut __v, (3,)); + let mut __v: A = ZeroInitializationUnsafe::zero_init(); + A::constructor_2(&raw mut __v, 3); __v }, 2, @@ -197,18 +190,18 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { always_given_3({ - let mut __v: NoDefault = ::zero_init(); - >::constructor(&raw mut __v, (3,)); + let mut __v: NoDefault = ZeroInitializationUnsafe::zero_init(); + NoDefault::constructor_1(&raw mut __v, 3); __v }) }) == (3)) ); - object_unsafe!(s, S_NoDefault_, (i32,), (1,)); + object_unsafe!(s, S_NoDefault_::constructor_1(1)); assert!( ((unsafe { S_NoDefault_::get(&raw const s, { - let mut __v: NoDefault = ::zero_init(); - >::constructor(&raw mut __v, (4,)); + let mut __v: NoDefault = ZeroInitializationUnsafe::zero_init(); + NoDefault::constructor_1(&raw mut __v, 4); __v }) }) == (5)) diff --git a/tests/unit/out/unsafe/temporary_field_addr.rs b/tests/unit/out/unsafe/temporary_field_addr.rs index c5a4cde462..9ea03b1968 100644 --- a/tests/unit/out/unsafe/temporary_field_addr.rs +++ b/tests/unit/out/unsafe/temporary_field_addr.rs @@ -20,12 +20,12 @@ use std::rc::Rc; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Inner { pub values: Vec, } -impl ConstructibleFromUnsafe<()> for Inner { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Inner { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).values).write(Vec::new()); } } @@ -43,16 +43,16 @@ impl ConstructibleFromUnsafe<()> for Inner { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Outer { pub values: Vec, pub inner: Inner, pub name: [libc::c_char; 8], } -impl ConstructibleFromUnsafe<()> for Outer { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Outer { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).values).write(Vec::new()); - >::constructor(&raw mut (*this).inner, ()); + Inner::constructor_1(&raw mut (*this).inner); (&raw mut (*this).name).write([(0 as libc::c_char); 8]); } } @@ -84,7 +84,7 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut calls: i32 = 0; let mut member: i32 = { - let mut __tmp_0: Outer = ::zero_init(); + let mut __tmp_0: Outer = ZeroInitializationUnsafe::zero_init(); (unsafe { sum_1( &(*{ @@ -96,7 +96,7 @@ unsafe fn main_0() -> i32 { }) }; let mut nested: i32 = { - let mut __tmp_1: Outer = ::zero_init(); + let mut __tmp_1: Outer = ZeroInitializationUnsafe::zero_init(); (unsafe { sum_1( &(*{ @@ -109,7 +109,7 @@ unsafe fn main_0() -> i32 { }) }; let mut element: i32 = { - let mut __tmp_2: Outer = ::zero_init(); + let mut __tmp_2: Outer = ZeroInitializationUnsafe::zero_init(); (*{ (unsafe { make_0(&raw mut __tmp_2, &mut calls) }); &mut __tmp_2 @@ -117,7 +117,7 @@ unsafe fn main_0() -> i32 { .values[(((calls) - (2)) as usize)] }; let mut length: usize = { - let mut __tmp_3: Outer = ::zero_init(); + let mut __tmp_3: Outer = ZeroInitializationUnsafe::zero_init(); libc::strlen( ((*{ (unsafe { make_0(&raw mut __tmp_3, &mut calls) }); diff --git a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs index e5e348542c..d7bc0d8e45 100644 --- a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs +++ b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs @@ -20,12 +20,12 @@ use std::rc::Rc; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Outer { pub values: Vec, } -impl ConstructibleFromUnsafe<()> for Outer { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Outer { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).values).write(Vec::new()); } } @@ -51,13 +51,12 @@ pub unsafe fn make_0(__return: *mut Outer) { pub struct H { pub last: i32, } -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>>,)> for H { - unsafe fn constructor(this: *mut Self, (values,): (LvalueRefUnsafe>>,)) { +impl H { + pub unsafe fn constructor_1(this: *mut Self, values: LvalueRefUnsafe>>) { let values = (values.as_ptr() as *const Vec); (&raw mut (*this).last).write((&(*values))[(3_usize)]); } } -impl ConvertibleToUnsafe for LvalueRefUnsafe>> {} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -66,16 +65,16 @@ pub fn main() { } unsafe fn main_0() -> i32 { object_unsafe!(h, H, |h| { - let mut __tmp_0: Outer = ::zero_init(); - >>,)>>::constructor( + let mut __tmp_0: Outer = ZeroInitializationUnsafe::zero_init(); + H::constructor_1( h, - (LvalueRefUnsafe::bind( + LvalueRefUnsafe::bind( &(*{ (unsafe { make_0(&raw mut __tmp_0) }); &mut __tmp_0 }) .values, - ),), + ), ) }); (unsafe { libc::printf(c"%d\n".as_ptr() as *const libc::c_char, (h.last)) }); diff --git a/tests/unit/out/unsafe/temporary_field_two_args.rs b/tests/unit/out/unsafe/temporary_field_two_args.rs index 2900780307..2a5875bac5 100644 --- a/tests/unit/out/unsafe/temporary_field_two_args.rs +++ b/tests/unit/out/unsafe/temporary_field_two_args.rs @@ -20,12 +20,12 @@ use std::rc::Rc; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Inner { pub values: Vec, } -impl ConstructibleFromUnsafe<()> for Inner { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Inner { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).values).write(Vec::new()); } } @@ -43,15 +43,15 @@ impl ConstructibleFromUnsafe<()> for Inner { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Outer { pub values: Vec, pub inner: Inner, } -impl ConstructibleFromUnsafe<()> for Outer { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Outer { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).values).write(Vec::new()); - >::constructor(&raw mut (*this).inner, ()); + Inner::constructor_1(&raw mut (*this).inner); } } pub unsafe fn make_0(__return: *mut Outer) { @@ -74,8 +74,8 @@ pub fn main() { } unsafe fn main_0() -> i32 { { - let mut __tmp_0: Outer = ::zero_init(); - let mut __tmp_1: Outer = ::zero_init(); + let mut __tmp_0: Outer = ZeroInitializationUnsafe::zero_init(); + let mut __tmp_1: Outer = ZeroInitializationUnsafe::zero_init(); (unsafe { libc::printf( c"%d\n".as_ptr() as *const libc::c_char, diff --git a/tests/unit/out/unsafe/this.rs b/tests/unit/out/unsafe/this.rs index 3d0c9f7251..c5710b875f 100644 --- a/tests/unit/out/unsafe/this.rs +++ b/tests/unit/out/unsafe/this.rs @@ -19,14 +19,34 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(value(i32))] -#[constructor(value(i32 ), value(*mut S ))] -#[constructor(value(i32 ), value(*const S ))] +#[constructor(constructor_1, value(i32))] +#[constructor(constructor_2, value(i32 ), value(*mut S ))] +#[constructor(constructor_3, value(i32 ), value(*const S ))] pub struct S { pub a_: i32, pub self__: *mut S, } impl S { + pub unsafe fn constructor_1(this: *mut Self, mut a: i32) { + (&raw mut (*this).a_).write(a); + (&raw mut (*this).self__).write(std::ptr::null_mut()); + } + pub unsafe fn constructor_2(this: *mut Self, mut a: i32, mut other: *mut S) { + (&raw mut (*this).a_).write(a); + (&raw mut (*this).self__).write(std::ptr::null_mut()); + if ((this) == (other)) { + (*this).self__ = std::ptr::null_mut(); + } else { + (*this).self__ = other; + } + } + pub unsafe fn constructor_3(this: *mut Self, mut a: i32, mut other: *const S) { + (&raw mut (*this).a_).write(a); + (&raw mut (*this).self__).write(std::ptr::null_mut()); + if (((this).cast_const()) == (other)) { + (*this).self__ = std::ptr::null_mut(); + } + } pub unsafe fn returns_this_reference(this: *mut Self) -> *mut S { return &mut (*this); } @@ -68,8 +88,8 @@ impl S { } pub unsafe fn reset(this: *mut Self) { (*this) = { - let mut __v: S = ::zero_init(); - >::constructor(&raw mut __v, (0,)); + let mut __v: S = ZeroInitializationUnsafe::zero_init(); + S::constructor_1(&raw mut __v, 0); __v }; } @@ -90,33 +110,6 @@ impl S { return true; } } -impl ConstructibleFromUnsafe<(i32,)> for S { - unsafe fn constructor(this: *mut Self, (mut a,): (i32,)) { - (&raw mut (*this).a_).write(a); - (&raw mut (*this).self__).write(std::ptr::null_mut()); - } -} -impl ConvertibleToUnsafe for i32 {} -impl ConstructibleFromUnsafe<(i32, *mut S)> for S { - unsafe fn constructor(this: *mut Self, (mut a, mut other): (i32, *mut S)) { - (&raw mut (*this).a_).write(a); - (&raw mut (*this).self__).write(std::ptr::null_mut()); - if ((this) == (other)) { - (*this).self__ = std::ptr::null_mut(); - } else { - (*this).self__ = other; - } - } -} -impl ConstructibleFromUnsafe<(i32, *const S)> for S { - unsafe fn constructor(this: *mut Self, (mut a, mut other): (i32, *const S)) { - (&raw mut (*this).a_).write(a); - (&raw mut (*this).self__).write(std::ptr::null_mut()); - if (((this).cast_const()) == (other)) { - (*this).self__ = std::ptr::null_mut(); - } - } -} pub unsafe fn bump_0(mut p: *mut S) { (*p).a_.postfix_inc(); } @@ -133,17 +126,16 @@ pub unsafe fn bump_0(mut p: *mut S) { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] pub struct D { pub a_: i32, } -impl ConstructibleFromUnsafe<(i32,)> for D { - unsafe fn constructor(this: *mut Self, (mut a,): (i32,)) { +impl D { + pub unsafe fn constructor_1(this: *mut Self, mut a: i32) { (&raw mut (*this).a_).write(a); (*this).a_ *= 2; } } -impl ConvertibleToUnsafe for i32 {} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -151,7 +143,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(s, S, (i32,), (1,)); + object_unsafe!(s, S::constructor_1(1)); let ref_: *mut S = (unsafe { S::returns_this_reference(&raw mut s) }); (*ref_).a_.postfix_inc(); assert!(((s.a_) == (2))); @@ -171,11 +163,11 @@ unsafe fn main_0() -> i32 { assert!(((s.a_) == (8))); (unsafe { S::bump_me(&raw mut s) }); assert!(((s.a_) == (9))); - object_unsafe!(d, D, (i32,), (3,)); + object_unsafe!(d, D::constructor_1(3)); assert!(((d.a_) == (6))); let cr: *const S = (unsafe { S::cref(&raw const s) }); assert!((((*cr).a_) == (9))); - object_unsafe!(t, S, (i32,), (0,)); + object_unsafe!(t, S::constructor_1(0)); assert!( (unsafe { let _o: *const S = (&mut s as *mut S).cast_const(); @@ -185,7 +177,7 @@ unsafe fn main_0() -> i32 { assert!(!(unsafe { S::is(&raw const s, (&mut t as *mut S).cast_const(),) })); let mut p: *mut S = { let __p: *mut S = Box::leak(Box::new(::zero_init())); - >::constructor(__p, (1,)); + S::constructor_1(__p, 1); __p }; let mut q: *mut S = (unsafe { S::returns_this_pointer(&raw mut (*p)) }); @@ -199,7 +191,7 @@ unsafe fn main_0() -> i32 { }; let mut h: *mut S = { let __p: *mut S = Box::leak(Box::new(::zero_init())); - >::constructor(__p, (5,)); + S::constructor_1(__p, 5); __p }; (unsafe { S::destroy(&raw mut (*h)) }); @@ -220,21 +212,21 @@ unsafe fn main_0() -> i32 { }) as i32) == (false as i32)) ); - object_unsafe!(other, S, (i32,), (22,)); + object_unsafe!(other, S::constructor_1(22)); assert!( (((unsafe { S::copy_if_different(&raw mut s, (&mut other as *mut S),) }) as i32) == (true as i32)) ); assert!(((s.a_) == (other.a_))); assert!(((s.self__) == (other.self__))); - object_unsafe!(u, S, (i32, *mut S,), (1, (&mut s as *mut S),)); + object_unsafe!(u, S::constructor_2(1, (&mut s as *mut S))); assert!(((u.self__) == (&mut s as *mut S))); let s_const: S = { - let mut __v: S = ::zero_init(); - >::constructor(&raw mut __v, (100,)); + let mut __v: S = ZeroInitializationUnsafe::zero_init(); + S::constructor_1(&raw mut __v, 100); __v }; - object_unsafe!(u1, S, (i32, *const S,), (1, (&s_const as *const S),)); + object_unsafe!(u1, S::constructor_3(1, (&s_const as *const S))); assert!((u1.self__).is_null()); return 0; } diff --git a/tests/unit/out/unsafe/typedef-anon-struct.rs b/tests/unit/out/unsafe/typedef-anon-struct.rs index 8b5cab4a85..f4ae0b3e9f 100644 --- a/tests/unit/out/unsafe/typedef-anon-struct.rs +++ b/tests/unit/out/unsafe/typedef-anon-struct.rs @@ -37,12 +37,12 @@ pub struct Outer_RunInfo { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Outer { pub runs: Vec, } -impl ConstructibleFromUnsafe<()> for Outer { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Outer { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).runs).write(Vec::new()); } } @@ -53,7 +53,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(o, Outer); + object_unsafe!(o, Outer::constructor_1()); let mut info: Outer_RunInfo = ::default(); info.block_idx = 1; info.num_extra_zero_runs = 2; diff --git a/tests/unit/out/unsafe/unboxed_records.rs b/tests/unit/out/unsafe/unboxed_records.rs index e413188280..2335611c29 100644 --- a/tests/unit/out/unsafe/unboxed_records.rs +++ b/tests/unit/out/unsafe/unboxed_records.rs @@ -53,7 +53,7 @@ pub struct Cookie { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Counter { pub n: i32, } @@ -61,9 +61,7 @@ impl Counter { pub unsafe fn inc(this: *mut Self) { (*this).n.prefix_inc(); } -} -impl ConstructibleFromUnsafe<()> for Counter { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).n).write(0); } } @@ -134,7 +132,7 @@ unsafe fn main_0() -> i32 { let mut field_addr: Inner = Inner { a: 0, b: 0 }; (unsafe { set_0((&mut field_addr.b as *mut i32), 7) }); assert!(((field_addr.b) == (7))); - object_unsafe!(counter, Counter); + object_unsafe!(counter, Counter::constructor_1()); (unsafe { Counter::inc(&raw mut counter) }); assert!(((counter.n) == (1))); return 0; diff --git a/tests/unit/out/unsafe/unique_ptr.rs b/tests/unit/out/unsafe/unique_ptr.rs index c7e4577b94..b0d2f67695 100644 --- a/tests/unit/out/unsafe/unique_ptr.rs +++ b/tests/unit/out/unsafe/unique_ptr.rs @@ -17,7 +17,7 @@ use std::rc::Rc; )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] pub struct SafePointer { pub ptr: Option>, } @@ -29,9 +29,7 @@ impl SafePointer { .map_or(::std::ptr::null_mut(), |v| v as *const i32 as *mut i32)) .prefix_inc(); } -} -impl ConstructibleFromUnsafe<()> for SafePointer { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).ptr).write(None); } } diff --git a/tests/unit/out/unsafe/unique_ptr_const_deref.rs b/tests/unit/out/unsafe/unique_ptr_const_deref.rs index 70b654e67b..aafb44bece 100644 --- a/tests/unit/out/unsafe/unique_ptr_const_deref.rs +++ b/tests/unit/out/unsafe/unique_ptr_const_deref.rs @@ -17,12 +17,12 @@ use std::rc::Rc; )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] pub struct Holder { pub val: Option>, } -impl ConstructibleFromUnsafe<()> for Holder { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Holder { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).val).write(None); } } @@ -45,7 +45,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(h, Holder); + object_unsafe!(h, Holder::constructor_1()); { h.val = Some(Box::new(10)).take(); }; diff --git a/tests/unit/out/unsafe/unique_ptr_field_reset.rs b/tests/unit/out/unsafe/unique_ptr_field_reset.rs index b97db06591..a8a31965cb 100644 --- a/tests/unit/out/unsafe/unique_ptr_field_reset.rs +++ b/tests/unit/out/unsafe/unique_ptr_field_reset.rs @@ -33,7 +33,7 @@ pub struct Data { )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] pub struct Holder { pub data: Option>, pub n: i32, @@ -46,9 +46,7 @@ impl Holder { Some(Box::from_raw(p)) }; } -} -impl ConstructibleFromUnsafe<()> for Holder { - unsafe fn constructor(this: *mut Self, _: ()) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).data).write(None); (&raw mut (*this).n).write(0_i32); } @@ -71,7 +69,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(h, Holder); + object_unsafe!(h, Holder::constructor_1()); h.n = 1; let mut hp: *mut Holder = (&mut h as *mut Holder); { diff --git a/tests/unit/out/unsafe/unique_ptr_nested.rs b/tests/unit/out/unsafe/unique_ptr_nested.rs index f56bd8d411..3f7f46f0ca 100644 --- a/tests/unit/out/unsafe/unique_ptr_nested.rs +++ b/tests/unit/out/unsafe/unique_ptr_nested.rs @@ -34,12 +34,12 @@ pub struct Inner { )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] pub struct Outer { pub inner: Option>, } -impl ConstructibleFromUnsafe<()> for Outer { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Outer { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).inner).write(None); } } diff --git a/tests/unit/out/unsafe/va_list_field.rs b/tests/unit/out/unsafe/va_list_field.rs index 2f203f36d2..6970149a14 100644 --- a/tests/unit/out/unsafe/va_list_field.rs +++ b/tests/unit/out/unsafe/va_list_field.rs @@ -9,7 +9,7 @@ use std::rc::Rc; pub unsafe fn sum_0(mut n: i32, __args: Box<[VaArg]>) -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); - object_unsafe!(guard, Guard_1, (*mut *const VaArg,), (&mut ap,)); + object_unsafe!(guard, Guard_1::constructor_1(&mut ap)); let mut total: i32 = 0; { let mut i: i32 = 0; @@ -32,18 +32,17 @@ pub unsafe fn sum_0(mut n: i32, __args: Box<[VaArg]>) -> i32 { CopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy)] +#[conversions(copy, move)] pub struct Guard_1 { pub ap: *mut *const VaArg, pub active: bool, } -impl ConstructibleFromUnsafe<(*mut *const VaArg,)> for Guard_1 { - unsafe fn constructor(this: *mut Self, (val,): (*mut *const VaArg,)) { +impl Guard_1 { + pub unsafe fn constructor_1(this: *mut Self, val: *mut *const VaArg) { (&raw mut (*this).ap).write(val); (&raw mut (*this).active).write(true); } } -impl ConvertibleToUnsafe for *mut *const VaArg {} impl DestructibleUnsafe for Guard_1 { unsafe fn destroy(this: *mut Self) { if (*this).active {} diff --git a/tests/unit/out/unsafe/vector.rs b/tests/unit/out/unsafe/vector.rs index a99ebc3a30..35531f8be8 100644 --- a/tests/unit/out/unsafe/vector.rs +++ b/tests/unit/out/unsafe/vector.rs @@ -37,13 +37,13 @@ pub unsafe fn copy_0(mut copy_vector: Vec) {} )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Foo { pub a: Vec, pub b: Vec, } -impl ConstructibleFromUnsafe<()> for Foo { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Foo { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).a).write(Vec::new()); (&raw mut (*this).b).write(Vec::new()); } @@ -61,16 +61,15 @@ impl ConstructibleFromUnsafe<()> for Foo { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] pub struct Wrapped { pub v: i32, } -impl ConstructibleFromUnsafe<(i32,)> for Wrapped { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl Wrapped { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } } -impl ConvertibleToUnsafe for i32 {} pub unsafe fn exchange_1(x: *mut Vec, y: *mut Vec) { std::mem::swap(&mut (*x), &mut (*y)); } @@ -193,9 +192,9 @@ unsafe fn main_0() -> i32 { let mut __it = (__tmp_8).clone(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_9) { __tmp.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __tmp.as_mut_ptr().add(__tmp.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } @@ -428,7 +427,7 @@ unsafe fn main_0() -> i32 { ((((v10.len()) == (1_usize)) && ((v10[(0_usize)]) == (4))) && ((v11.len()) == (3_usize))) && ((v11[(2_usize)]) == (3)) ); - object_unsafe!(foo, Foo); + object_unsafe!(foo, Foo::constructor_1()); { let mut __tmp_15: i32 = 5; foo.a.push_moved(&mut __tmp_15) @@ -521,9 +520,9 @@ unsafe fn main_0() -> i32 { let mut __it = ints.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_20) { __tmp.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __tmp.as_mut_ptr().add(__tmp.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } @@ -546,9 +545,9 @@ unsafe fn main_0() -> i32 { let mut __it = (__tmp_22).clone(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_23) { __tmp.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __tmp.as_mut_ptr().add(__tmp.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } @@ -567,9 +566,9 @@ unsafe fn main_0() -> i32 { let mut __it = ints.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_25) { __tmp.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __tmp.as_mut_ptr().add(__tmp.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } @@ -588,9 +587,9 @@ unsafe fn main_0() -> i32 { let mut __it = ints.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_27) { __tmp.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __tmp.as_mut_ptr().add(__tmp.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } @@ -609,9 +608,9 @@ unsafe fn main_0() -> i32 { let mut __it = (__tmp_29).clone(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_30) { __tmp.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __tmp.as_mut_ptr().add(__tmp.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/vector_insert_conversion_chain.rs b/tests/unit/out/unsafe/vector_insert_conversion_chain.rs index c9b8a75c15..ae7f394c18 100644 --- a/tests/unit/out/unsafe/vector_insert_conversion_chain.rs +++ b/tests/unit/out/unsafe/vector_insert_conversion_chain.rs @@ -19,18 +19,17 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(i32, const_lvalue_ref)] +#[conversion_function(conversion_function_1, i32, const_lvalue_ref)] pub struct Ratio { pub num: i32, } -impl ConversionFunctionUnsafe>> for Ratio { - unsafe fn conversion_function(this: LvalueRefUnsafe>, to: *mut i32) { +impl Ratio { + pub unsafe fn conversion_function_1(this: LvalueRefUnsafe>, __return: *mut i32) { let this = this.as_ptr() as *mut Ratio; - to.write((*this).num); + __return.write((*this).num); return; } } -impl ImplicitConversionFunctionUnsafe>> for Ratio {} #[repr(C)] #[derive( Copy, @@ -44,27 +43,23 @@ impl ImplicitConversionFunctionUnsafe>> for Ra ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(i16, const_lvalue_ref)] -#[conversion_function(i64, const_lvalue_ref)] +#[conversion_function(conversion_function_1, i16, const_lvalue_ref)] +#[conversion_function(conversion_function_2, i64, const_lvalue_ref)] pub struct Level { pub raw_: i32, } -impl ConversionFunctionUnsafe>> for Level { - unsafe fn conversion_function(this: LvalueRefUnsafe>, to: *mut i16) { +impl Level { + pub unsafe fn conversion_function_1(this: LvalueRefUnsafe>, __return: *mut i16) { let this = this.as_ptr() as *mut Level; - to.write(((*this).raw_ as i16)); + __return.write(((*this).raw_ as i16)); return; } -} -impl ImplicitConversionFunctionUnsafe>> for Level {} -impl ConversionFunctionUnsafe>> for Level { - unsafe fn conversion_function(this: LvalueRefUnsafe>, to: *mut i64) { + pub unsafe fn conversion_function_2(this: LvalueRefUnsafe>, __return: *mut i64) { let this = this.as_ptr() as *mut Level; - to.write((((*this).raw_ as i64) * (100_i64))); + __return.write((((*this).raw_ as i64) * (100_i64))); return; } } -impl ImplicitConversionFunctionUnsafe>> for Level {} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -83,9 +78,9 @@ unsafe fn main_0() -> i32 { let mut __it = ratios.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { __tmp.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __tmp.as_mut_ptr().add(__tmp.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } @@ -104,9 +99,9 @@ unsafe fn main_0() -> i32 { let mut __it = levels.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) { __tmp.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __tmp.as_mut_ptr().add(__tmp.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/vector_iter_range_ctor.rs b/tests/unit/out/unsafe/vector_iter_range_ctor.rs index 9676e7a0cf..6dbebfec01 100644 --- a/tests/unit/out/unsafe/vector_iter_range_ctor.rs +++ b/tests/unit/out/unsafe/vector_iter_range_ctor.rs @@ -19,16 +19,15 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(value(i32))] +#[constructor(constructor_1, value(i32))] pub struct Degrees { pub value: i32, } -impl ConstructibleFromUnsafe<(i32,)> for Degrees { - unsafe fn constructor(this: *mut Self, (mut v,): (i32,)) { +impl Degrees { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).value).write(v); } } -impl ConvertibleToUnsafe for i32 {} #[repr(C)] #[derive( Copy, @@ -42,18 +41,17 @@ impl ConvertibleToUnsafe for i32 {} ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(i64, const_lvalue_ref)] +#[conversion_function(conversion_function_1, i64, const_lvalue_ref)] pub struct Reading { pub raw_: i32, } -impl ConversionFunctionUnsafe>> for Reading { - unsafe fn conversion_function(this: LvalueRefUnsafe>, to: *mut i64) { +impl Reading { + pub unsafe fn conversion_function_1(this: LvalueRefUnsafe>, __return: *mut i64) { let this = this.as_ptr() as *mut Reading; - to.write((((*this).raw_ as i64) * (10_i64))); + __return.write((((*this).raw_ as i64) * (10_i64))); return; } } -impl ImplicitConversionFunctionUnsafe>> for Reading {} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -68,9 +66,9 @@ unsafe fn main_0() -> i32 { let mut __it = src.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_0) { __v.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } @@ -87,9 +85,9 @@ unsafe fn main_0() -> i32 { let mut __it = src.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { __v.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } @@ -106,9 +104,9 @@ unsafe fn main_0() -> i32 { let mut __it = src.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_2) { __v.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } @@ -123,9 +121,9 @@ unsafe fn main_0() -> i32 { let mut __it = src1.as_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) { __v.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } @@ -151,9 +149,9 @@ unsafe fn main_0() -> i32 { let mut __it = start; while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_5) { __v.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } @@ -190,9 +188,11 @@ unsafe fn main_0() -> i32 { let mut __it = (__tmp_9).clone(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_10) { __v.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind( + __it.iter_deref(), + ),), ); __it.iter_inc(); } @@ -212,9 +212,11 @@ unsafe fn main_0() -> i32 { let mut __it = (__tmp_12).clone(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_13) { __tmp.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __tmp.as_mut_ptr().add(__tmp.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind( + __it.iter_deref(), + ),), ); __it.iter_inc(); } @@ -232,9 +234,9 @@ unsafe fn main_0() -> i32 { let mut __it = ints.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_14) { __v.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } @@ -248,9 +250,9 @@ unsafe fn main_0() -> i32 { let mut __it = readings.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_15) { __v.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/vector_subscript_direct.rs b/tests/unit/out/unsafe/vector_subscript_direct.rs index 36e638b26c..955c2e8dfb 100644 --- a/tests/unit/out/unsafe/vector_subscript_direct.rs +++ b/tests/unit/out/unsafe/vector_subscript_direct.rs @@ -42,13 +42,13 @@ impl Point { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct Holder { pub values: Vec, pub points: Vec, } -impl ConstructibleFromUnsafe<()> for Holder { - unsafe fn constructor(this: *mut Self, _: ()) { +impl Holder { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).values).write(Vec::new()); (&raw mut (*this).points).write(Vec::new()); } @@ -113,7 +113,7 @@ unsafe fn main_0() -> i32 { (*p) = 9; assert!(((v[(2_usize)]) == (9))); assert!(((unsafe { sum_ref_1(&v,) }) == (((((3) + (0)) + (9)) + (42)) + (5)))); - object_unsafe!(h, Holder); + object_unsafe!(h, Holder::constructor_1()); h.values.resize_with(2_usize, || 0_i32); h.values[(1_usize)] = 6; { diff --git a/tests/unit/out/unsafe/vector_with_allocator.rs b/tests/unit/out/unsafe/vector_with_allocator.rs index 17a9365c22..1ba3b4e042 100644 --- a/tests/unit/out/unsafe/vector_with_allocator.rs +++ b/tests/unit/out/unsafe/vector_with_allocator.rs @@ -323,9 +323,9 @@ unsafe fn main_0() -> i32 { let mut __it = src.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_16) { __v.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } @@ -342,9 +342,9 @@ unsafe fn main_0() -> i32 { let mut __it = src.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_17) { __v.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } @@ -361,9 +361,9 @@ unsafe fn main_0() -> i32 { let mut __it = src.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_18) { __v.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } @@ -378,9 +378,9 @@ unsafe fn main_0() -> i32 { let mut __it = src1.as_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_19) { __v.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } @@ -400,9 +400,9 @@ unsafe fn main_0() -> i32 { let mut __it = start; while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_20) { __v.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct( + ConstructibleFromUnsafe::construct( __v.as_mut_ptr().add(__v.len() - 1), - &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())], + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), ); __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/void_cast.rs b/tests/unit/out/unsafe/void_cast.rs index 2eac657141..fa76775729 100644 --- a/tests/unit/out/unsafe/void_cast.rs +++ b/tests/unit/out/unsafe/void_cast.rs @@ -21,12 +21,12 @@ pub unsafe fn unused_param_0(mut x: i32) {} )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy, move, default = constructor_1)] pub struct NonTrivial { pub data: Vec, } -impl ConstructibleFromUnsafe<()> for NonTrivial { - unsafe fn constructor(this: *mut Self, _: ()) { +impl NonTrivial { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).data).write(Vec::new()); } } @@ -65,12 +65,12 @@ pub struct Holder { )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(move)] +#[conversions(move, default = constructor_1)] pub struct NonCopyable { pub value: Option>, } -impl ConstructibleFromUnsafe<()> for NonCopyable { - unsafe fn constructor(this: *mut Self, _: ()) { +impl NonCopyable { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).value).write(None); } } @@ -124,7 +124,7 @@ unsafe fn main_0() -> i32 { let mut arr: [i32; 3] = [1, 2, 3]; let mut h: Holder = Holder { field: 17 }; let mut hp: *mut Holder = (&mut h as *mut Holder); - object_unsafe!(nt, NonTrivial); + object_unsafe!(nt, NonTrivial::constructor_1()); (unsafe { unused_ref_param_1(&nt) }); (unsafe { unused_ptr_param_2((&mut nt as *mut NonTrivial).cast_const()) }); let mut g: NonCopyable = NonCopyable { From 7585db9f7c78bafd1e3ed4b75c103f9e36b313f3 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 4 Dec 2026 12:02:55 +0000 Subject: [PATCH 21/35] Update rules --- rules/algorithm/tgt_refcount.rs | 11 +++-- rules/algorithm/tgt_unsafe.rs | 9 +++-- rules/array/tgt_refcount.rs | 2 +- rules/iterator_category/shim.rs | 8 ++-- rules/map/shim.rs | 6 +-- rules/pair/tgt_refcount.rs | 72 ++++++++++++++++++--------------- rules/pair/tgt_unsafe.rs | 38 ++++++++++------- rules/unique_ptr/shim.rs | 6 +-- rules/vector/shim.rs | 10 ++--- rules/vector/tgt_refcount.rs | 8 ++-- rules/vector/tgt_unsafe.rs | 8 ++-- 11 files changed, 100 insertions(+), 78 deletions(-) diff --git a/rules/algorithm/tgt_refcount.rs b/rules/algorithm/tgt_refcount.rs index 4b2ead934f..b3189d1a18 100644 --- a/rules/algorithm/tgt_refcount.rs +++ b/rules/algorithm/tgt_refcount.rs @@ -16,18 +16,21 @@ fn f1, T2: CppLess + Clone + ByteRepr>(a0: T1, a fn f2< T1: CppInputIterator, T2: CppIterator, - T3: overload::Conversions, - T4: overload::Conversions + MoveAssignable + ZeroInitialization, + T3: ByteRepr, + T4: MoveAssignable + ZeroInitialization, >( a0: T1, a1: T1, a2: T2, -) -> T2 { +) -> T2 +where + LvalueRef: ConvertibleTo, +{ let __first: Value = Rc::new(RefCell::new(a0)); let __last: Value = Rc::new(RefCell::new(a1)); let mut __out = a2; while ::not_equal(__first.as_pointer(), __last.as_pointer()) { - object!(__value, T4, |__this| Conversions::convert(__this, overload::Arg::lvalue(__first.borrow().iter_deref()))); + object!(__value, T4, |__this| ConvertibleTo::convert(LvalueRef::::bind(__first.borrow().iter_deref()), __this)); MoveAssignable::move_assign(__out.iter_deref(), RvalueRef::::bind(__value.as_pointer())); __first.borrow_mut().iter_inc(); __out.iter_inc(); diff --git a/rules/algorithm/tgt_unsafe.rs b/rules/algorithm/tgt_unsafe.rs index 093c314b2c..70fe833985 100644 --- a/rules/algorithm/tgt_unsafe.rs +++ b/rules/algorithm/tgt_unsafe.rs @@ -17,15 +17,18 @@ unsafe fn f1, T2: Ord>(a0: T1, a1: T1) { } } -unsafe fn f2, T2: UnsafeCppIterator, T3: overload::ConversionsUnsafe, T4: overload::ConversionsUnsafe + ZeroInitializationUnsafe + MoveAssignableUnsafe>( +unsafe fn f2, T2: UnsafeCppIterator, T3, T4: ZeroInitializationUnsafe + MoveAssignableUnsafe>( a0: T1, a1: T1, a2: T2, -) -> T2 { +) -> T2 +where + LvalueRefUnsafe: ConvertibleToUnsafe, +{ let mut __first = a0; let mut __out = a2; while WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &a1) { - object_unsafe!(__value, T4, |__this| ConversionsUnsafe::convert(__this, overload::Arg::lvalue_unsafe(__first.iter_deref()))); + object_unsafe!(__value, T4, |__this| ConvertibleToUnsafe::convert(LvalueRefUnsafe::::bind(__first.iter_deref()), __this)); MoveAssignableUnsafe::move_assign(__out.iter_deref(), RvalueRefUnsafe::::bind(&raw mut __value)); __first.iter_inc(); __out.iter_inc(); diff --git a/rules/array/tgt_refcount.rs b/rules/array/tgt_refcount.rs index 87371e357e..5ee485007d 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(|_| ZeroInitialization::zero_init()).collect())); let __p: Ptr = __v.decay(); for __i in 0..T2 { - ConstructibleFrom::constructor(__p.offset(__i), (RvalueRef::::bind(a0.offset(__i)),)); + Constructor::constructor(__p.offset(__i), (RvalueRef::::bind(a0.offset(__i)),)); } Rc::try_unwrap(__v).ok().unwrap().into_inner() } diff --git a/rules/iterator_category/shim.rs b/rules/iterator_category/shim.rs index 667717b070..d296f558c7 100644 --- a/rules/iterator_category/shim.rs +++ b/rules/iterator_category/shim.rs @@ -176,7 +176,7 @@ macro_rules! uninhabited_iterator { } } - impl crate::ConstructibleFrom<(crate::RvalueRef,)> for $name { + impl crate::Constructor<(crate::RvalueRef,)> for $name { fn constructor(_: Ptr, (src,): (crate::RvalueRef,)) { src.as_pointer().with(|it| it.never()) } @@ -184,7 +184,7 @@ macro_rules! uninhabited_iterator { impl crate::MoveConstructible for $name {} - impl crate::ConstructibleFrom<(crate::LvalueRef>,)> + impl crate::Constructor<(crate::LvalueRef>,)> for $name { fn constructor(_: Ptr, (src,): (crate::LvalueRef>,)) { @@ -194,7 +194,7 @@ macro_rules! uninhabited_iterator { impl crate::CopyConstructible for $name {} - impl crate::ConstructibleFromUnsafe<(crate::RvalueRefUnsafe,)> for $name { + impl crate::ConstructorUnsafe<(crate::RvalueRefUnsafe,)> for $name { unsafe fn constructor(_: *mut Self, (src,): (crate::RvalueRefUnsafe,)) { unsafe { (*src.as_ptr()).never() } } @@ -202,7 +202,7 @@ macro_rules! uninhabited_iterator { impl crate::MoveConstructibleUnsafe for $name {} - impl crate::ConstructibleFromUnsafe<(crate::LvalueRefUnsafe>,)> + impl crate::ConstructorUnsafe<(crate::LvalueRefUnsafe>,)> for $name { unsafe fn constructor( diff --git a/rules/map/shim.rs b/rules/map/shim.rs index bf33f41672..9db9c20a59 100644 --- a/rules/map/shim.rs +++ b/rules/map/shim.rs @@ -8,7 +8,7 @@ use std::ops::Bound; use std::rc::{Rc, Weak}; use crate::{ - AsPointer, BidirectionalIterator, ByteRepr, Const, ConstructibleFrom, ConstructibleFromUnsafe, + AsPointer, BidirectionalIterator, ByteRepr, Const, Constructor, ConstructorUnsafe, CopyAssignable, CopyAssignableUnsafe, CopyConstructible, CopyConstructibleUnsafe, CppIterator, CppLess, LvalueRef, LvalueRefUnsafe, Ptr, UnsafeBidirectionalIterator, UnsafeCppIterator, Value, ZeroInitialization, copy_constructed, copy_constructed_unsafe, cpp_cmp, @@ -110,7 +110,7 @@ impl ByteRepr for Map {} // A map is copied by copying its keys and values, each with its copy // constructor. -impl ConstructibleFrom<(LvalueRef>,)> for Map, Value)> +impl Constructor<(LvalueRef>,)> for Map, Value)> where K: CppLess + CopyConstructible + ZeroInitialization + 'static, V: CopyConstructible + ZeroInitialization + 'static, @@ -472,7 +472,7 @@ impl UnsafeMap - ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for UnsafeMap + ConstructorUnsafe<(LvalueRefUnsafe>,)> for UnsafeMap { unsafe fn constructor(this: *mut Self, (src,): (LvalueRefUnsafe>,)) { let src = src.as_const_ptr(); diff --git a/rules/pair/tgt_refcount.rs b/rules/pair/tgt_refcount.rs index 454ff7fe60..a43ca2e729 100644 --- a/rules/pair/tgt_refcount.rs +++ b/rules/pair/tgt_refcount.rs @@ -88,15 +88,15 @@ where } fn f23< - T1: overload::Conversions + ZeroInitialization + MoveConstructible, - T2: overload::Conversions + ZeroInitialization + MoveConstructible, - T3: overload::Conversions, - T4: overload::Conversions, + T1: ConstructibleFrom<(RvalueRef,)> + ZeroInitialization + MoveConstructible, + T2: ConstructibleFrom<(RvalueRef,)> + ZeroInitialization + MoveConstructible, + T3: ByteRepr, + T4: ByteRepr, >( a0: &mut (Value, Value), ) -> (Value, Value) { - object!(__first, T1, |__this| Conversions::construct(__this, &[overload::Arg::rvalue(a0.0.as_pointer())])); - object!(__second, T2, |__this| Conversions::construct(__this, &[overload::Arg::rvalue(a0.1.as_pointer())])); + object!(__first, T1, |__this| ConstructibleFrom::construct(__this, (RvalueRef::::bind(a0.0.as_pointer()),))); + object!(__second, T2, |__this| ConstructibleFrom::construct(__this, (RvalueRef::::bind(a0.1.as_pointer()),))); ( Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), @@ -104,15 +104,15 @@ fn f23< } fn f24< - T1: overload::Conversions + ZeroInitialization + MoveConstructible, - T2: overload::Conversions + ZeroInitialization + MoveConstructible, - T3: overload::Conversions, - T4: overload::Conversions, + T1: ConstructibleFrom<(LvalueRef>,)> + ZeroInitialization + MoveConstructible, + T2: ConstructibleFrom<(LvalueRef>,)> + ZeroInitialization + MoveConstructible, + T3: ByteRepr, + T4: ByteRepr, >( a0: (Value, Value), ) -> (Value, Value) { - object!(__first, T1, |__this| Conversions::construct(__this, &[overload::Arg::const_lvalue(a0.0.as_pointer())])); - object!(__second, T2, |__this| Conversions::construct(__this, &[overload::Arg::const_lvalue(a0.1.as_pointer())])); + object!(__first, T1, |__this| ConstructibleFrom::construct(__this, (LvalueRef::>::bind(a0.0.as_pointer()),))); + object!(__second, T2, |__this| ConstructibleFrom::construct(__this, (LvalueRef::>::bind(a0.1.as_pointer()),))); ( Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), @@ -120,32 +120,40 @@ fn f24< } fn f25< - T1: overload::Conversions + ZeroInitialization + MoveAssignable, - T2: overload::Conversions + ZeroInitialization + MoveAssignable, - T3: overload::Conversions, - T4: overload::Conversions, + T1: ZeroInitialization + MoveAssignable, + T2: ZeroInitialization + MoveAssignable, + T3: ByteRepr, + T4: ByteRepr, >( a0: &mut (Value, Value), a1: (Value, Value), -) -> &mut (Value, Value) { - object!(__first, T1, |__this| Conversions::convert(__this, overload::Arg::const_lvalue(a1.0.as_pointer()))); - object!(__second, T2, |__this| Conversions::convert(__this, overload::Arg::const_lvalue(a1.1.as_pointer()))); +) -> &mut (Value, Value) +where + LvalueRef>: ConvertibleTo, + LvalueRef>: ConvertibleTo, +{ + object!(__first, T1, |__this| ConvertibleTo::convert(LvalueRef::>::bind(a1.0.as_pointer()), __this)); + object!(__second, T2, |__this| ConvertibleTo::convert(LvalueRef::>::bind(a1.1.as_pointer()), __this)); MoveAssignable::move_assign(a0.0.as_pointer(), RvalueRef::::bind(__first.as_pointer())); MoveAssignable::move_assign(a0.1.as_pointer(), RvalueRef::::bind(__second.as_pointer())); a0 } fn f26< - 'a, T1: overload::Conversions + ZeroInitialization + MoveAssignable, - T2: overload::Conversions + ZeroInitialization + MoveAssignable, - T3: overload::Conversions, - T4: overload::Conversions, + 'a, T1: ZeroInitialization + MoveAssignable, + T2: ZeroInitialization + MoveAssignable, + T3: ByteRepr, + T4: ByteRepr, >( a0: &'a mut (Value, Value), a1: &mut (Value, Value), -) -> &'a mut (Value, Value) { - object!(__first, T1, |__this| Conversions::convert(__this, overload::Arg::rvalue(a1.0.as_pointer()))); - object!(__second, T2, |__this| Conversions::convert(__this, overload::Arg::rvalue(a1.1.as_pointer()))); +) -> &'a mut (Value, Value) +where + RvalueRef: ConvertibleTo, + RvalueRef: ConvertibleTo, +{ + object!(__first, T1, |__this| ConvertibleTo::convert(RvalueRef::::bind(a1.0.as_pointer()), __this)); + object!(__second, T2, |__this| ConvertibleTo::convert(RvalueRef::::bind(a1.1.as_pointer()), __this)); MoveAssignable::move_assign(a0.0.as_pointer(), RvalueRef::::bind(__first.as_pointer())); MoveAssignable::move_assign(a0.1.as_pointer(), RvalueRef::::bind(__second.as_pointer())); a0 @@ -163,15 +171,15 @@ fn f28, T2: WeaklyEqualityComparableWith,)> + ZeroInitialization + MoveConstructible, + T2: ConstructibleFrom<(LvalueRef,)> + ZeroInitialization + MoveConstructible, + T3: ByteRepr, + T4: ByteRepr, >( a0: &mut (Value, Value), ) -> (Value, Value) { - object!(__first, T1, |__this| Conversions::construct(__this, &[overload::Arg::lvalue(a0.0.as_pointer())])); - object!(__second, T2, |__this| Conversions::construct(__this, &[overload::Arg::lvalue(a0.1.as_pointer())])); + object!(__first, T1, |__this| ConstructibleFrom::construct(__this, (LvalueRef::::bind(a0.0.as_pointer()),))); + object!(__second, T2, |__this| ConstructibleFrom::construct(__this, (LvalueRef::::bind(a0.1.as_pointer()),))); ( Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), diff --git a/rules/pair/tgt_unsafe.rs b/rules/pair/tgt_unsafe.rs index 5fcbe08a63..6f421161ab 100644 --- a/rules/pair/tgt_unsafe.rs +++ b/rules/pair/tgt_unsafe.rs @@ -73,29 +73,37 @@ where &mut *a0.get_mut::() } -unsafe fn f23(a0: &mut (T3, T4)) -> (T1, T2) { - object_unsafe!(__first, T1, |__this| ConversionsUnsafe::construct(__this, &[overload::Arg::rvalue_unsafe(&raw mut a0.0)])); - object_unsafe!(__second, T2, |__this| ConversionsUnsafe::construct(__this, &[overload::Arg::rvalue_unsafe(&raw mut a0.1)])); +unsafe fn f23,)> + ZeroInitializationUnsafe + MoveConstructibleUnsafe, T2: ConstructibleFromUnsafe<(RvalueRefUnsafe,)> + ZeroInitializationUnsafe + MoveConstructibleUnsafe, T3, T4>(a0: &mut (T3, T4)) -> (T1, T2) { + object_unsafe!(__first, T1, |__this| ConstructibleFromUnsafe::construct(__this, (RvalueRefUnsafe::::bind(&raw mut a0.0),))); + object_unsafe!(__second, T2, |__this| ConstructibleFromUnsafe::construct(__this, (RvalueRefUnsafe::::bind(&raw mut a0.1),))); (move_constructed_unsafe(&raw mut __first), move_constructed_unsafe(&raw mut __second)) } -unsafe fn f24(a0: &(T3, T4)) -> (T1, T2) { - object_unsafe!(__first, T1, |__this| ConversionsUnsafe::construct(__this, &[overload::Arg::const_lvalue_unsafe(&raw const a0.0)])); - object_unsafe!(__second, T2, |__this| ConversionsUnsafe::construct(__this, &[overload::Arg::const_lvalue_unsafe(&raw const a0.1)])); +unsafe fn f24>,)> + ZeroInitializationUnsafe + MoveConstructibleUnsafe, T2: ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> + ZeroInitializationUnsafe + MoveConstructibleUnsafe, T3, T4>(a0: &(T3, T4)) -> (T1, T2) { + object_unsafe!(__first, T1, |__this| ConstructibleFromUnsafe::construct(__this, (LvalueRefUnsafe::>::bind(&raw const a0.0),))); + object_unsafe!(__second, T2, |__this| ConstructibleFromUnsafe::construct(__this, (LvalueRefUnsafe::>::bind(&raw const a0.1),))); (move_constructed_unsafe(&raw mut __first), move_constructed_unsafe(&raw mut __second)) } -unsafe fn f25<'a, T1: overload::ConversionsUnsafe + ZeroInitializationUnsafe + MoveAssignableUnsafe, T2: overload::ConversionsUnsafe + ZeroInitializationUnsafe + MoveAssignableUnsafe, T3: overload::ConversionsUnsafe, T4: overload::ConversionsUnsafe>(a0: &'a mut (T1, T2), a1: &(T3, T4)) -> &'a mut (T1, T2) { - object_unsafe!(__first, T1, |__this| ConversionsUnsafe::convert(__this, overload::Arg::const_lvalue_unsafe(&raw const a1.0))); - object_unsafe!(__second, T2, |__this| ConversionsUnsafe::convert(__this, overload::Arg::const_lvalue_unsafe(&raw const a1.1))); +unsafe fn f25<'a, T1: ZeroInitializationUnsafe + MoveAssignableUnsafe, T2: ZeroInitializationUnsafe + MoveAssignableUnsafe, T3, T4>(a0: &'a mut (T1, T2), a1: &(T3, T4)) -> &'a mut (T1, T2) +where + LvalueRefUnsafe>: ConvertibleToUnsafe, + LvalueRefUnsafe>: ConvertibleToUnsafe, +{ + object_unsafe!(__first, T1, |__this| ConvertibleToUnsafe::convert(LvalueRefUnsafe::>::bind(&raw const a1.0), __this)); + object_unsafe!(__second, T2, |__this| ConvertibleToUnsafe::convert(LvalueRefUnsafe::>::bind(&raw const a1.1), __this)); MoveAssignableUnsafe::move_assign(&raw mut a0.0, RvalueRefUnsafe::::bind(&raw mut __first)); MoveAssignableUnsafe::move_assign(&raw mut a0.1, RvalueRefUnsafe::::bind(&raw mut __second)); a0 } -unsafe fn f26<'a, T1: overload::ConversionsUnsafe + ZeroInitializationUnsafe + MoveAssignableUnsafe, T2: overload::ConversionsUnsafe + ZeroInitializationUnsafe + MoveAssignableUnsafe, T3: overload::ConversionsUnsafe, T4: overload::ConversionsUnsafe>(a0: &'a mut (T1, T2), a1: &mut (T3, T4)) -> &'a mut (T1, T2) { - object_unsafe!(__first, T1, |__this| ConversionsUnsafe::convert(__this, overload::Arg::rvalue_unsafe(&raw mut a1.0))); - object_unsafe!(__second, T2, |__this| ConversionsUnsafe::convert(__this, overload::Arg::rvalue_unsafe(&raw mut a1.1))); +unsafe fn f26<'a, T1: ZeroInitializationUnsafe + MoveAssignableUnsafe, T2: ZeroInitializationUnsafe + MoveAssignableUnsafe, T3, T4>(a0: &'a mut (T1, T2), a1: &mut (T3, T4)) -> &'a mut (T1, T2) +where + RvalueRefUnsafe: ConvertibleToUnsafe, + RvalueRefUnsafe: ConvertibleToUnsafe, +{ + object_unsafe!(__first, T1, |__this| ConvertibleToUnsafe::convert(RvalueRefUnsafe::::bind(&raw mut a1.0), __this)); + object_unsafe!(__second, T2, |__this| ConvertibleToUnsafe::convert(RvalueRefUnsafe::::bind(&raw mut a1.1), __this)); MoveAssignableUnsafe::move_assign(&raw mut a0.0, RvalueRefUnsafe::::bind(&raw mut __first)); MoveAssignableUnsafe::move_assign(&raw mut a0.1, RvalueRefUnsafe::::bind(&raw mut __second)); a0 @@ -132,8 +140,8 @@ fn f33(a0: (T1, T2), a1: (T1, T2)) -> bool { a0 == a1 } -unsafe fn f34(a0: &mut (T3, T4)) -> (T1, T2) { - object_unsafe!(__first, T1, |__this| ConversionsUnsafe::construct(__this, &[overload::Arg::lvalue_unsafe(&raw mut a0.0)])); - object_unsafe!(__second, T2, |__this| ConversionsUnsafe::construct(__this, &[overload::Arg::lvalue_unsafe(&raw mut a0.1)])); +unsafe fn f34,)> + ZeroInitializationUnsafe + MoveConstructibleUnsafe, T2: ConstructibleFromUnsafe<(LvalueRefUnsafe,)> + ZeroInitializationUnsafe + MoveConstructibleUnsafe, T3, T4>(a0: &mut (T3, T4)) -> (T1, T2) { + object_unsafe!(__first, T1, |__this| ConstructibleFromUnsafe::construct(__this, (LvalueRefUnsafe::::bind(&raw mut a0.0),))); + object_unsafe!(__second, T2, |__this| ConstructibleFromUnsafe::construct(__this, (LvalueRefUnsafe::::bind(&raw mut a0.1),))); (move_constructed_unsafe(&raw mut __first), move_constructed_unsafe(&raw mut __second)) } diff --git a/rules/unique_ptr/shim.rs b/rules/unique_ptr/shim.rs index 23657c933d..5c79f239ab 100644 --- a/rules/unique_ptr/shim.rs +++ b/rules/unique_ptr/shim.rs @@ -2,7 +2,7 @@ // Distributed under the MIT license that can be found in the LICENSE file. use crate::{ - ByteRepr, ConstructibleFrom, ConstructibleFromUnsafe, MoveAssignable, MoveAssignableUnsafe, + ByteRepr, Constructor, ConstructorUnsafe, MoveAssignable, MoveAssignableUnsafe, MoveConstructible, MoveConstructibleUnsafe, Ptr, RvalueRef, RvalueRefUnsafe, Swappable, SwappableUnsafe, Value, }; @@ -19,7 +19,7 @@ impl crate::DestructibleUnsafe for Option> { unsafe fn destroy(_this: *mut Self) {} } -impl ConstructibleFrom<(RvalueRef,)> for Option> +impl Constructor<(RvalueRef,)> for Option> where Self: ByteRepr, { @@ -42,7 +42,7 @@ where } } -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for Option> { +impl ConstructorUnsafe<(RvalueRefUnsafe,)> for Option> { unsafe fn constructor(this: *mut Self, (src,): (RvalueRefUnsafe,)) { let src = src.as_ptr(); unsafe { std::ptr::write(this, (*src).take()) } diff --git a/rules/vector/shim.rs b/rules/vector/shim.rs index 470e437794..3ce481e275 100644 --- a/rules/vector/shim.rs +++ b/rules/vector/shim.rs @@ -2,7 +2,7 @@ // Distributed under the MIT license that can be found in the LICENSE file. use crate::{ - ArgRepr, ByteRepr, Const, ConstructibleFrom, ConstructibleFromUnsafe, CopyAssignable, + ArgRepr, ByteRepr, Const, Constructor, ConstructorUnsafe, CopyAssignable, CopyAssignableUnsafe, CopyConstructible, CopyConstructibleUnsafe, FnPtrArg, LvalueRef, LvalueRefUnsafe, MoveConstructibleUnsafe, Ptr, RvalueRefUnsafe, ZeroInitialization, copy_constructed_unsafe, record_from_repr, @@ -34,7 +34,7 @@ impl crate::DestructibleUnsafe for Vec { // A vector is copied by copying its elements, each with its copy constructor. impl - ConstructibleFrom<(LvalueRef>,)> for Vec + Constructor<(LvalueRef>,)> for Vec { fn constructor(this: Ptr, (src,): (LvalueRef>,)) { this.write(T::copied_elems(&src.as_pointer())); @@ -99,7 +99,7 @@ impl PushConstructedUnsafe for Vec { { unsafe { push_constructed(self, src.cast_mut(), |dst, src| { - >,)>>::constructor( + >,)>>::constructor( dst, (LvalueRefUnsafe::bind(src),), ) @@ -113,7 +113,7 @@ impl PushConstructedUnsafe for Vec { { unsafe { push_constructed(self, src, |dst, src| { - ,)>>::constructor( + ,)>>::constructor( dst, (RvalueRefUnsafe::bind(src),), ) @@ -131,7 +131,7 @@ unsafe fn copied_elems_unsafe(src: *const Vec) -> } } -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> +impl ConstructorUnsafe<(LvalueRefUnsafe>,)> for Vec { unsafe fn constructor(this: *mut Self, (src,): (LvalueRefUnsafe>,)) { diff --git a/rules/vector/tgt_refcount.rs b/rules/vector/tgt_refcount.rs index 9a0fad552a..ce48434032 100644 --- a/rules/vector/tgt_refcount.rs +++ b/rules/vector/tgt_refcount.rs @@ -91,14 +91,14 @@ fn f80(a0: Ptr>, CopyConstructible::push_copied(&a0, a1) } -fn f92, T4: overload::Conversions>(a0: T3, a1: T3) -> Vec { +fn f92>,)> + ZeroInitialization + ByteRepr, T2, T3: CppInputIterator, T4: ByteRepr>(a0: T3, a1: T3) -> Vec { let __v: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value = Rc::new(RefCell::new(a0)); let __last: Value = Rc::new(RefCell::new(a1)); while ::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct(__v.as_pointer().decay().offset(__i), &[overload::Arg::const_lvalue(__it.borrow().iter_deref())]); + ConstructibleFrom::construct(__v.as_pointer().decay().offset(__i), (LvalueRef::>::bind(__it.borrow().iter_deref()),)); __it.borrow_mut().iter_inc(); } Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -132,7 +132,7 @@ fn f99(a0: &Vec) -> &T1 { &a0[__n] } -fn f101, T4: overload::Conversions>( +fn f101>,)> + ZeroInitialization + ByteRepr, T2, T3: CppInputIterator, T4: ByteRepr>( a0: Ptr>, a1: RandomAccessIterator, a2: T3, @@ -145,7 +145,7 @@ fn f101::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = temp_vec.borrow().len(); temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); - Conversions::construct(temp_vec.as_pointer().decay().offset(__i), &[overload::Arg::const_lvalue(__it.borrow().iter_deref())]); + ConstructibleFrom::construct(temp_vec.as_pointer().decay().offset(__i), (LvalueRef::>::bind(__it.borrow().iter_deref()),)); __it.borrow_mut().iter_inc(); } a0.with_mut(|v: &mut Vec| { diff --git a/rules/vector/tgt_unsafe.rs b/rules/vector/tgt_unsafe.rs index 60c93640a2..a347944fd0 100644 --- a/rules/vector/tgt_unsafe.rs +++ b/rules/vector/tgt_unsafe.rs @@ -149,12 +149,12 @@ fn f91(a0: Vec) -> Vec { a0 } -unsafe fn f92, T4: overload::ConversionsUnsafe>(a0: T3, a1: T3) -> Vec { +unsafe fn f92>,)> + ZeroInitializationUnsafe, T2, T3: UnsafeCppInputIterator, T4>(a0: T3, a1: T3) -> Vec { let mut __v: Vec = Vec::new(); let mut __it = a0; while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) { __v.push(ZeroInitializationUnsafe::zero_init()); - ConversionsUnsafe::construct(__v.as_mut_ptr().add(__v.len() - 1), &[overload::Arg::const_lvalue_unsafe(__it.iter_deref())]); + ConstructibleFromUnsafe::construct(__v.as_mut_ptr().add(__v.len() - 1), (LvalueRefUnsafe::>::bind(__it.iter_deref()),)); __it.iter_inc(); } __v @@ -185,7 +185,7 @@ fn f99(a0: &Vec) -> &T1 { &a0[__n] } -unsafe fn f101, T4: overload::ConversionsUnsafe>( +unsafe fn f101>,)> + ZeroInitializationUnsafe, T2, T3: UnsafeCppInputIterator, T4>( a0: &mut Vec, a1: UnsafeRandomAccessIterator, a2: T3, @@ -196,7 +196,7 @@ unsafe fn f101>::bind(__it.iter_deref()),)); __it.iter_inc(); } a0.splice(__off..__off, __tmp); From 4e5f8c0d3bcd1b4ffc8d5afdbeeef4d466cc1453 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 4 Dec 2026 12:07:18 +0000 Subject: [PATCH 22/35] Add ConvertibleTo and ConstructibleFrom as marker traits --- libcc2rs-macros/src/constructor.rs | 44 ++----- libcc2rs-macros/src/conversions.rs | 195 ++++++++++++++++++++--------- libcc2rs/src/capture.rs | 12 +- libcc2rs/src/constructor.rs | 114 ++++++++++------- libcc2rs/src/conversion.rs | 39 +----- libcc2rs/src/lib.rs | 9 +- libcc2rs/src/object.rs | 51 ++------ libcc2rs/src/overload.rs | 176 ++++++++++++++++++++++---- libcc2rs/src/reference.rs | 17 ++- libcc2rs/src/swap.rs | 12 +- 10 files changed, 410 insertions(+), 259 deletions(-) diff --git a/libcc2rs-macros/src/constructor.rs b/libcc2rs-macros/src/constructor.rs index dad2a2d9ae..652a91f0bf 100644 --- a/libcc2rs-macros/src/constructor.rs +++ b/libcc2rs-macros/src/constructor.rs @@ -54,7 +54,7 @@ pub fn expand_default_constructible(input: TokenStream, is_unsafe: bool) -> Toke let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); if is_unsafe { quote! { - impl #impl_generics ::libcc2rs::ConstructibleFromUnsafe<()> for #name #ty_generics #where_clause { + impl #impl_generics ::libcc2rs::ConstructorUnsafe<()> for #name #ty_generics #where_clause { unsafe fn constructor(this: *mut Self, _: ()) { unsafe { ::std::ptr::write( @@ -67,7 +67,7 @@ pub fn expand_default_constructible(input: TokenStream, is_unsafe: bool) -> Toke } } else { quote! { - impl #impl_generics ::libcc2rs::ConstructibleFrom<()> for #name #ty_generics #where_clause { + impl #impl_generics ::libcc2rs::Constructor<()> for #name #ty_generics #where_clause { fn constructor(this: ::libcc2rs::Ptr, _: ()) { this.write(::zero_init()); } @@ -108,14 +108,6 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - let name = &input.ident; let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); let is_move = op == "move"; - let source = match (is_move, is_unsafe) { - (true, true) => quote!(::libcc2rs::RvalueRefUnsafe<#name #ty_generics>), - (false, true) => { - quote!(::libcc2rs::LvalueRefUnsafe<::libcc2rs::Const<#name #ty_generics>>) - } - (true, false) => quote!(::libcc2rs::RvalueRef<#name #ty_generics>), - (false, false) => quote!(::libcc2rs::LvalueRef<::libcc2rs::Const<#name #ty_generics>>), - }; let trait_name = format_ident!( "{}{}{}", if is_move { "Move" } else { "Copy" }, @@ -153,7 +145,7 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - }; let body = if is_move && !is_assign { quote!(unsafe { - >, )>>::constructor( this, (::libcc2rs::LvalueRefUnsafe::bind(src.as_ptr()),) @@ -181,15 +173,13 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - }; if !is_assign { return quote! { - impl #impl_generics ::libcc2rs::ConstructibleFromUnsafe<(#src_ty,)> for #name #ty_generics #where_clause { + impl #impl_generics ::libcc2rs::ConstructorUnsafe<(#src_ty,)> for #name #ty_generics #where_clause { unsafe fn constructor(this: *mut Self, (src,): (#src_ty,)) { #body } } impl #impl_generics ::libcc2rs::#trait_name for #name #ty_generics #where_clause {} - - impl #impl_generics ::libcc2rs::ConvertibleToUnsafe<#name #ty_generics> for #source #where_clause {} }; } quote! { @@ -211,7 +201,7 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - quote!(::libcc2rs::LvalueRef<::libcc2rs::Const>) }; let body = if is_move && !is_assign { - quote!(>, )>>::constructor( this, @@ -258,7 +248,7 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - }; if !is_assign { return quote! { - impl #impl_generics ::libcc2rs::ConstructibleFrom<(#src_ty,)> for #name #ty_generics #where_clause { + impl #impl_generics ::libcc2rs::Constructor<(#src_ty,)> for #name #ty_generics #where_clause { fn constructor(this: ::libcc2rs::Ptr, (src,): (#src_ty,)) { #body } @@ -267,8 +257,6 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - impl #impl_generics ::libcc2rs::#trait_name for #name #ty_generics #where_clause { #copied } - - impl #impl_generics ::libcc2rs::ConvertibleTo<#name #ty_generics> for #source #where_clause {} }; } quote! { @@ -404,14 +392,6 @@ fn impl_memberwise( let name = &input.ident; let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); let is_move = op == "move"; - let source = match (is_move, is_unsafe) { - (true, true) => quote!(::libcc2rs::RvalueRefUnsafe<#name #ty_generics>), - (false, true) => { - quote!(::libcc2rs::LvalueRefUnsafe<::libcc2rs::Const<#name #ty_generics>>) - } - (true, false) => quote!(::libcc2rs::RvalueRef<#name #ty_generics>), - (false, false) => quote!(::libcc2rs::LvalueRef<::libcc2rs::Const<#name #ty_generics>>), - }; let trait_name = format_ident!( "{}{}{}", if is_move { "Move" } else { "Copy" }, @@ -459,11 +439,11 @@ fn impl_memberwise( }; let field_srcs: Vec<_> = field_types.iter().map(|ty| field_src(ty)).collect(); return quote! { - impl #impl_generics ::libcc2rs::ConstructibleFromUnsafe<(#src_ty,)> for #name #ty_generics #where_clause { + impl #impl_generics ::libcc2rs::ConstructorUnsafe<(#src_ty,)> for #name #ty_generics #where_clause { unsafe fn constructor(this: *mut Self, (src,): (#src_ty,)) { let src = src.#object(); #(unsafe { - <#field_types as ::libcc2rs::ConstructibleFromUnsafe<(#field_srcs,)>>::constructor( + <#field_types as ::libcc2rs::ConstructorUnsafe<(#field_srcs,)>>::constructor( &raw mut (*this).#members, (#marker::bind(#src_field (*src).#members),), ) @@ -472,8 +452,6 @@ fn impl_memberwise( } impl #impl_generics #tr for #name #ty_generics #where_clause {} - - impl #impl_generics ::libcc2rs::ConvertibleToUnsafe<#name #ty_generics> for #source #where_clause {} }; } return quote! { @@ -516,10 +494,10 @@ fn impl_memberwise( }) .collect(); return quote! { - impl #impl_generics ::libcc2rs::ConstructibleFrom<(#src_ty,)> for #name #ty_generics #where_clause { + impl #impl_generics ::libcc2rs::Constructor<(#src_ty,)> for #name #ty_generics #where_clause { fn constructor(this: ::libcc2rs::Ptr, (src,): (#src_ty,)) { let src = src.as_pointer(); - #(<#field_types as ::libcc2rs::ConstructibleFrom<(#field_srcs,)>>::constructor( + #(<#field_types as ::libcc2rs::Constructor<(#field_srcs,)>>::constructor( ::libcc2rs::field_ptr!(this, #members), (#marker::bind(::libcc2rs::field_ptr!(src, #members)),), );)* @@ -527,8 +505,6 @@ fn impl_memberwise( } impl #impl_generics #tr for #name #ty_generics #where_clause {} - - impl #impl_generics ::libcc2rs::ConvertibleTo<#name #ty_generics> for #source #where_clause {} }; } quote! { diff --git a/libcc2rs-macros/src/conversions.rs b/libcc2rs-macros/src/conversions.rs index 0c8021f001..7cae6c580d 100644 --- a/libcc2rs-macros/src/conversions.rs +++ b/libcc2rs-macros/src/conversions.rs @@ -9,18 +9,21 @@ use syn::punctuated::Punctuated; use syn::{DeriveInput, Ident, Token, Type, parenthesized, parse_macro_input}; // #[derive(Conversions)] -// #[conversions(copy, move)] -// #[constructor(explicit, const_lvalue_ref(W))] // explicit S(const W &) -// #[constructor(value(i32), lvalue_ref(T))] // S(int, T &) -// #[conversion_function(i32, const_lvalue_ref)] // operator int() const +// #[conversions(copy = copy_from, move = move_from, default = default_constructor)] +// #[constructor(construct_1, explicit, const_lvalue_ref(W))] // explicit S(const W &) +// #[constructor(construct_2, value(i32), lvalue_ref(T))] // S(int, T &) +// #[conversion_function(operator_int, i32, const_lvalue_ref)] // operator int() const // pub struct S { ... } // // Implements libcc2rs::overload::Conversions for S, the table of its -// constructors and conversion functions that libcc2rs resolves -// initializations against at run time. A parameter is value(T), by_value(T) -// for a class passed by value, which the caller constructs, lvalue_ref(T), -// const_lvalue_ref(T), rvalue_ref(T) or const_rvalue_ref(T). ConversionsUnsafe is the -// same for the unsafe model. +// constructors and conversion functions, each naming the inherent method that +// holds its body, which libcc2rs resolves initializations against at run time. +// copy = m, move = m and default = m also implement CopyConstructible, +// MoveConstructible and DefaultConstructible by calling m; a bare copy or move +// says that the trait is implemented elsewhere. A parameter is value(T), +// by_value(T) for a class passed by value, which the caller constructs, +// lvalue_ref(T), const_lvalue_ref(T), rvalue_ref(T) or const_rvalue_ref(T). +// ConversionsUnsafe is the same for the unsafe model. #[derive(Clone, Copy, PartialEq)] enum Kind { @@ -56,7 +59,7 @@ impl Kind { quote!(::libcc2rs::overload::Passing::#passing) } - // The reference a parameter of this kind is in the ConstructibleFrom + // The reference a parameter of this kind is in the Constructor // arguments, or None for a value. fn reference(self, ty: &TokenStream2, is_unsafe: bool) -> Option { let (lvalue, rvalue) = if is_unsafe { @@ -95,21 +98,26 @@ impl Parse for Parameter { } struct Constructor { + method: Ident, is_explicit: bool, params: Vec, } impl Parse for Constructor { fn parse(input: ParseStream) -> syn::Result { - let is_explicit = input.peek(Ident) && input.fork().parse::()? == "explicit"; - if is_explicit { + let method = input.parse()?; + let mut is_explicit = false; + if input.parse::>()?.is_some() + && input.peek(Ident) + && input.fork().parse::()? == "explicit" + { input.parse::()?; - if !input.is_empty() { - input.parse::()?; - } + is_explicit = true; + input.parse::>()?; } let params = Punctuated::::parse_terminated(input)?; Ok(Constructor { + method, is_explicit, params: params.into_iter().collect(), }) @@ -117,6 +125,7 @@ impl Parse for Constructor { } struct ConversionFunction { + method: Ident, to: Type, object: Kind, is_explicit: bool, @@ -124,6 +133,8 @@ struct ConversionFunction { impl Parse for ConversionFunction { fn parse(input: ParseStream) -> syn::Result { + let method = input.parse()?; + input.parse::()?; let to = input.parse()?; input.parse::()?; let object = Kind::parse(&input.parse()?)?; @@ -136,6 +147,7 @@ impl Parse for ConversionFunction { is_explicit = true; } Ok(ConversionFunction { + method, to, object, is_explicit, @@ -143,6 +155,24 @@ impl Parse for ConversionFunction { } } +// A special member: whether S has it, and the inherent method that holds its +// body when this derive implements its trait. +#[derive(Default)] +struct Special { + exists: bool, + method: Option, +} + +impl Special { + fn parse(&mut self, meta: &syn::meta::ParseNestedMeta) -> syn::Result<()> { + self.exists = true; + if meta.input.peek(Token![=]) { + self.method = Some(meta.value()?.parse()?); + } + Ok(()) + } +} + pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); let name = &input.ident; @@ -151,7 +181,8 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { let mut constructors = Vec::new(); let mut functions = Vec::new(); - let (mut copy, mut moves) = (false, false); + let (mut copy, mut moves, mut default) = + (Special::default(), Special::default(), Special::default()); for attr in &input.attrs { let result = if attr.path().is_ident("constructor") { attr.parse_args::() @@ -162,13 +193,14 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { } else if attr.path().is_ident("conversions") { attr.parse_nested_meta(|meta| { if meta.path.is_ident("copy") { - copy = true; + copy.parse(&meta) } else if meta.path.is_ident("move") { - moves = true; + moves.parse(&meta) + } else if meta.path.is_ident("default") { + default.parse(&meta) } else { - return Err(meta.error("expected `copy` or `move`")); + Err(meta.error("expected `copy`, `move` or `default`")) } - Ok(()) }) } else { Ok(()) @@ -178,37 +210,40 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { } } - let (trait_name, table_ty, constructible, cast) = if is_unsafe { + let (trait_name, table_ty, cast, ptr_ty) = if is_unsafe { ( quote!(::libcc2rs::overload::ConversionsUnsafe), quote!(::libcc2rs::overload::Table<*mut ::std::ffi::c_void>), - quote!(::libcc2rs::ConstructibleFromUnsafe), format_ident!("cast"), + quote!(*mut Self), ) } else { ( quote!(::libcc2rs::overload::Conversions), quote!(::libcc2rs::overload::Table<::libcc2rs::AnyPtr>), - quote!(::libcc2rs::ConstructibleFrom), format_ident!("downcast"), + quote!(::libcc2rs::Ptr), ) }; + let suffix = if is_unsafe { "Unsafe" } else { "" }; + let constructor = format_ident!("Constructor{}", suffix); + let copy_trait = format_ident!("CopyConstructible{}", suffix); + let move_trait = format_ident!("MoveConstructible{}", suffix); + let fn_kw = if is_unsafe { + quote!(unsafe fn) + } else { + quote!(fn) + }; let table_of = |ty: &TokenStream2| quote!(<#ty as #trait_name>::table); let candidates = constructors.iter().map(|ctor| { + let method = &ctor.method; let params = ctor.params.iter().map(|param| { let ty = ¶m.ty; let table = table_of("e!(#ty)); let passing = param.kind.passing(); quote!(::libcc2rs::overload::Param { table: #table, passing: #passing }) }); - let arg_types = ctor.params.iter().map(|param| { - let ty = ¶m.ty; - param - .kind - .reference("e!(#ty), is_unsafe) - .unwrap_or_else(|| quote!(#ty)) - }); let values = ctor.params.iter().enumerate().map(|(i, param)| { let ty = ¶m.ty; let pointer = quote!(args[#i].#cast::<#ty>()); @@ -225,18 +260,14 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { result: None, call: |to, args| { #[allow(unused_unsafe)] - unsafe { - <#self_ty as #constructible<(#(#arg_types,)*)>>::constructor( - to.#cast::<#self_ty>(), - (#(#values,)*), - ) - } + unsafe { <#self_ty>::#method(to.#cast::<#self_ty>(), #(#values),*) } }, } } }); let conversions = functions.iter().map(|function| { + let method = &function.method; let to = &function.to; let object = function .object @@ -254,7 +285,7 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { call: |to, args| { #[allow(unused_unsafe)] unsafe { - <#self_ty>::conversion_function( + <#self_ty>::#method( <#object>::bind(args[0].#cast::<#self_ty>()), to.#cast::<#to>(), ) @@ -264,40 +295,90 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { } }); - let special = |is_move: bool, exists: bool| { + let copy_ref = Kind::ConstRef.reference(&self_ty, is_unsafe).unwrap(); + let move_ref = Kind::RvalueRef.reference(&self_ty, is_unsafe).unwrap(); + let lvalue_marker = if is_unsafe { + quote!(::libcc2rs::LvalueRefUnsafe) + } else { + quote!(::libcc2rs::LvalueRef) + }; + let moved_object = if is_unsafe { + quote!(src.as_ptr()) + } else { + quote!(src.as_pointer()) + }; + + let mut impls = TokenStream2::new(); + if let Some(method) = ©.method { + impls.extend(quote! { + impl #impl_generics ::libcc2rs::#constructor<(#copy_ref,)> for #self_ty #where_clause { + #fn_kw constructor(this: #ptr_ty, (src,): (#copy_ref,)) { + #[allow(unused_unsafe)] + unsafe { <#self_ty>::#method(this, src) } + } + } + + impl #impl_generics ::libcc2rs::#copy_trait for #self_ty #where_clause {} + }); + } + if let Some(method) = &moves.method { + impls.extend(quote! { + impl #impl_generics ::libcc2rs::#constructor<(#move_ref,)> for #self_ty #where_clause { + #fn_kw constructor(this: #ptr_ty, (src,): (#move_ref,)) { + #[allow(unused_unsafe)] + unsafe { <#self_ty>::#method(this, src) } + } + } + + impl #impl_generics ::libcc2rs::#move_trait for #self_ty #where_clause {} + }); + } else if let (Some(method), false) = (©.method, moves.exists) { + impls.extend(quote! { + impl #impl_generics ::libcc2rs::#constructor<(#move_ref,)> for #self_ty #where_clause { + #fn_kw constructor(this: #ptr_ty, (src,): (#move_ref,)) { + #[allow(unused_unsafe)] + unsafe { <#self_ty>::#method(this, #lvalue_marker::bind(#moved_object)) } + } + } + + impl #impl_generics ::libcc2rs::#move_trait for #self_ty #where_clause {} + }); + } + if let Some(method) = &default.method { + impls.extend(quote! { + impl #impl_generics ::libcc2rs::#constructor<()> for #self_ty #where_clause { + #fn_kw constructor(this: #ptr_ty, _: ()) { + #[allow(unused_unsafe)] + unsafe { <#self_ty>::#method(this) } + } + } + }); + } + + let special = |trait_: &Ident, method: &str, reference: &TokenStream2, exists: bool| { if !exists { - let message = format!( - "{} is not {} constructible", - name, - if is_move { "move" } else { "copy" } - ); + let message = format!("{} has no {}", name, method); return quote!(|_, _| panic!(#message)); } - let kind = if is_move { - Kind::RvalueRef - } else { - Kind::ConstRef - }; - let reference = kind.reference(&self_ty, is_unsafe).unwrap(); + let method = format_ident!("{}", method); quote! { |dst, src| { #[allow(unused_unsafe)] unsafe { - <#self_ty as #constructible<(#reference,)>>::constructor( + <#self_ty as ::libcc2rs::#trait_>::#method( dst.#cast::<#self_ty>(), - (<#reference>::bind(src.#cast::<#self_ty>()),), + <#reference>::bind(src.#cast::<#self_ty>()), ) } } } }; - let copy_fn = special(false, copy); - let move_fn = if moves { - special(true, true) + let copy_fn = special(©_trait, "copy_constructor", ©_ref, copy.exists); + let move_fn = if moves.exists || copy.method.is_some() { + special(&move_trait, "move_constructor", &move_ref, true) } else { - special(false, copy) + special(©_trait, "copy_constructor", ©_ref, copy.exists) }; - let (storage, release) = if is_unsafe { ( quote!(|| ::std::boxed::Box::into_raw(::std::boxed::Box::new(unsafe { @@ -325,6 +406,8 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { let label = name.to_string(); quote! { + #impls + impl #impl_generics #trait_name for #self_ty #where_clause { fn table() -> #table_ty { ::libcc2rs::overload::Table { diff --git a/libcc2rs/src/capture.rs b/libcc2rs/src/capture.rs index 4b675caa0e..92f03fb7dd 100644 --- a/libcc2rs/src/capture.rs +++ b/libcc2rs/src/capture.rs @@ -94,7 +94,7 @@ pub trait CopyLambda { impl CopyLambda>> for &&&Capture<'_, Value>> { fn copy_capture(&self) -> Value> { let dst: Value> = Rc::new(RefCell::new(FnPtr::zero_init())); - as crate::ConstructibleFrom<(crate::LvalueRef>>,)>>::constructor( + as crate::Constructor<(crate::LvalueRef>>,)>>::constructor( AsPointer::>::as_pointer(&dst), (crate::LvalueRef::bind(AsPointer::>::as_pointer(self.0)),), ); @@ -126,7 +126,7 @@ pub trait CopyCtor { impl CopyCtor> for &Capture<'_, Value> { fn copy_capture(&self) -> Value { let dst: Value = Rc::new(RefCell::new(T::zero_init())); - >,)>>::constructor( + >,)>>::constructor( AsPointer::::as_pointer(&dst), (crate::LvalueRef::bind(AsPointer::::as_pointer(self.0)),), ); @@ -151,7 +151,7 @@ pub trait MoveWithCtor { impl MoveWithCtor> for &&Capture<'_, Value> { fn move_capture(&self) -> Value { let dst: Value = Rc::new(RefCell::new(T::zero_init())); - ,)>>::constructor( + ,)>>::constructor( AsPointer::::as_pointer(&dst), (crate::RvalueRef::bind(AsPointer::::as_pointer(self.0)),), ); @@ -228,7 +228,7 @@ impl CopyLambdaUnsafe> for &&&CaptureUnsafe> { unsafe fn copy_capture(&self) -> FnPtr { let mut dst = std::mem::MaybeUninit::>::uninit(); unsafe { - as crate::ConstructibleFromUnsafe<( + as crate::ConstructorUnsafe<( crate::LvalueRefUnsafe>>, )>>::constructor( &mut *dst.as_mut_ptr(), @@ -257,7 +257,7 @@ impl CopyCtorUnsafe for &CaptureUnsafe { unsafe fn copy_capture(&self) -> T { let mut dst = std::mem::MaybeUninit::::uninit(); unsafe { - >,)>>::constructor(&mut *dst.as_mut_ptr(), (crate::LvalueRefUnsafe::bind(self.0),)); + >,)>>::constructor(&mut *dst.as_mut_ptr(), (crate::LvalueRefUnsafe::bind(self.0),)); dst.assume_init() } } @@ -281,7 +281,7 @@ impl MoveWithCtorUnsafe for &&CaptureUnsafe { unsafe fn move_capture(&self) -> T { let mut dst = std::mem::MaybeUninit::::uninit(); unsafe { - ,)>>::constructor( + ,)>>::constructor( &mut *dst.as_mut_ptr(), (crate::RvalueRefUnsafe::bind(self.0),), ); diff --git a/libcc2rs/src/constructor.rs b/libcc2rs/src/constructor.rs index acb8ac6d08..e41363af67 100644 --- a/libcc2rs/src/constructor.rs +++ b/libcc2rs/src/constructor.rs @@ -4,7 +4,7 @@ use crate::capture::{ Destructible, DestructibleUnsafe, TriviallyDestructible, TriviallyDestructibleUnsafe, }; -use crate::conversion::{ConstructibleFrom, ConstructibleFromUnsafe}; +use crate::conversion::{Constructor, ConstructorUnsafe}; use crate::fn_ptr::{FnPtr, FnSig}; use crate::initialization::ZeroInitialization; use crate::rc::{AsPointer, Ptr, Value}; @@ -12,7 +12,11 @@ use crate::reference::{Const, LvalueRef, LvalueRefUnsafe, RvalueRef, RvalueRefUn use crate::reinterpret::ByteRepr; use crate::void::AnyPtr; -pub trait DefaultConstructible: ConstructibleFrom<()> + Sized { +pub trait DefaultConstructible: Constructor<()> + Sized { + fn default_constructor(this: Ptr) { + >::constructor(this, ()) + } + // TODO: remove default_constructed. fn default_constructed() -> Self where @@ -24,9 +28,13 @@ pub trait DefaultConstructible: ConstructibleFrom<()> + Sized { } } -impl> DefaultConstructible for T {} +impl> DefaultConstructible for T {} + +pub trait MoveConstructible: Constructor<(RvalueRef,)> + ByteRepr + Sized { + fn move_constructor(this: Ptr, src: RvalueRef) { + ,)>>::constructor(this, (src,)) + } -pub trait MoveConstructible: ConstructibleFrom<(RvalueRef,)> + ByteRepr + Sized { // TODO: remove me. // 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 @@ -39,7 +47,7 @@ pub trait MoveConstructible: ConstructibleFrom<(RvalueRef,)> + ByteRepr + elems.push(Self::zero_init()); elems.len() - 1 }); - ,)>>::constructor( + ,)>>::constructor( v.decay().offset(i), (RvalueRef::bind(src),), ); @@ -51,8 +59,12 @@ pub trait TriviallyMoveConstructible: MoveConstructible { } pub trait CopyConstructible: - MoveConstructible + ConstructibleFrom<(LvalueRef>,)> + MoveConstructible + Constructor<(LvalueRef>,)> { + fn copy_constructor(this: Ptr, src: LvalueRef>) { + >,)>>::constructor(this, (src,)) + } + // TODO: remove me. // A copy of the value that src points to, made by the copy constructor, // which a type with Clone clones. @@ -75,7 +87,7 @@ pub trait CopyConstructible: elems.push(Self::zero_init()); elems.len() - 1 }); - >,)>>::constructor( + >,)>>::constructor( v.decay().offset(i), (LvalueRef::bind(src),), ); @@ -147,7 +159,13 @@ impl< { } -pub trait DefaultConstructibleUnsafe: ConstructibleFromUnsafe<()> + Sized { +pub trait DefaultConstructibleUnsafe: ConstructorUnsafe<()> + Sized { + /// # Safety + /// `this` is storage for an object. + unsafe fn default_constructor(this: *mut Self) { + unsafe { >::constructor(this, ()) } + } + // TODO: remove default_constructed. fn default_constructed() -> Self { let mut dst = std::mem::MaybeUninit::::zeroed(); @@ -158,16 +176,28 @@ pub trait DefaultConstructibleUnsafe: ConstructibleFromUnsafe<()> + Sized { } } -impl> DefaultConstructibleUnsafe for T {} +impl> DefaultConstructibleUnsafe for T {} pub trait MoveConstructibleUnsafe: - ConstructibleFromUnsafe<(RvalueRefUnsafe,)> + Sized + ConstructorUnsafe<(RvalueRefUnsafe,)> + Sized { + /// # Safety + /// `this` is storage for an object, and `src` refers to a live object. + unsafe fn move_constructor(this: *mut Self, src: RvalueRefUnsafe) { + unsafe { ,)>>::constructor(this, (src,)) } + } } pub trait CopyConstructibleUnsafe: - MoveConstructibleUnsafe + ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> + MoveConstructibleUnsafe + ConstructorUnsafe<(LvalueRefUnsafe>,)> { + /// # Safety + /// `this` is storage for an object, and `src` refers to a live object. + unsafe fn copy_constructor(this: *mut Self, src: LvalueRefUnsafe>) { + unsafe { + >,)>>::constructor(this, (src,)) + } + } } pub trait TriviallyMoveConstructibleUnsafe: MoveConstructibleUnsafe { @@ -248,7 +278,7 @@ impl< macro_rules! impl_copy_construct_by_clone { ($(<$($param:ident),*> $ty:ty),* $(,)?) => {$( - impl<$($param),*> $crate::ConstructibleFrom<($crate::LvalueRef<$crate::Const>,)> for $ty + impl<$($param),*> $crate::Constructor<($crate::LvalueRef<$crate::Const>,)> for $ty where $ty: Clone + $crate::ByteRepr, { @@ -257,7 +287,7 @@ macro_rules! impl_copy_construct_by_clone { } } - impl<$($param),*> $crate::ConstructibleFromUnsafe<($crate::LvalueRefUnsafe<$crate::Const>,)> for $ty + impl<$($param),*> $crate::ConstructorUnsafe<($crate::LvalueRefUnsafe<$crate::Const>,)> for $ty where $ty: Clone, { @@ -272,7 +302,7 @@ pub(crate) use impl_copy_construct_by_clone; macro_rules! impl_move_construct_by_clone { ($(<$($param:ident),*> $ty:ty),* $(,)?) => {$( - impl<$($param),*> $crate::ConstructibleFrom<($crate::RvalueRef,)> for $ty + impl<$($param),*> $crate::Constructor<($crate::RvalueRef,)> for $ty where $ty: Clone + $crate::ByteRepr, { @@ -281,7 +311,7 @@ macro_rules! impl_move_construct_by_clone { } } - impl<$($param),*> $crate::ConstructibleFromUnsafe<($crate::RvalueRefUnsafe,)> for $ty + impl<$($param),*> $crate::ConstructorUnsafe<($crate::RvalueRefUnsafe,)> for $ty where $ty: Clone, { @@ -505,7 +535,7 @@ pub(crate) use impl_trivial_copy_move; // The library types whose move leaves the source empty. macro_rules! impl_move_by_take { ($(<$($param:ident),*> $ty:ty),* $(,)?) => {$( - impl<$($param),*> $crate::ConstructibleFrom<($crate::RvalueRef,)> for $ty + impl<$($param),*> $crate::Constructor<($crate::RvalueRef,)> for $ty where $ty: Default + $crate::ByteRepr, { @@ -539,7 +569,7 @@ impl<$($param),*> $crate::MoveConstructible for $ty } } - impl<$($param),*> $crate::ConstructibleFromUnsafe<($crate::RvalueRefUnsafe,)> for $ty + impl<$($param),*> $crate::ConstructorUnsafe<($crate::RvalueRefUnsafe,)> for $ty where $ty: Default, { @@ -585,7 +615,7 @@ pub(crate) use impl_move_by_take; macro_rules! impl_default_by_zeroed { ($($ty:ty),* $(,)?) => {$( - impl $crate::ConstructibleFromUnsafe<()> for $ty { + impl $crate::ConstructorUnsafe<()> for $ty { unsafe fn constructor(this: *mut Self, _: ()) { unsafe { std::ptr::write(this, std::mem::zeroed()) } } @@ -599,7 +629,7 @@ pub(crate) use impl_default_by_zeroed; macro_rules! impl_trivially_default_constructible { ($(<$($param:ident),*> $ty:ty),* $(,)?) => {$( - impl<$($param),*> ConstructibleFrom<()> for $ty + impl<$($param),*> Constructor<()> for $ty where $ty: Default + ByteRepr, { @@ -611,7 +641,7 @@ macro_rules! impl_trivially_default_constructible { impl<$($param),*> TriviallyDefaultConstructible for $ty where $ty: Default + ByteRepr {} - impl<$($param),*> ConstructibleFromUnsafe<()> for $ty + impl<$($param),*> ConstructorUnsafe<()> for $ty where $ty: Default, { @@ -661,43 +691,43 @@ impl TriviallyDefaultConstructibleUnsafe for *mut T {} impl TriviallyDefaultConstructibleUnsafe for *const T {} -impl ConstructibleFrom<()> for FnPtr { +impl Constructor<()> for FnPtr { fn constructor(this: Ptr, _: ()) { this.with_mut(|dst| *dst = ::zero_init()); } } -impl ConstructibleFromUnsafe<()> for FnPtr { +impl ConstructorUnsafe<()> for FnPtr { unsafe fn constructor(this: *mut Self, _: ()) { unsafe { std::ptr::write(this, ::zero_init()) } } } -impl ConstructibleFrom<()> for Box<[T]> { +impl Constructor<()> for Box<[T]> { fn constructor(this: Ptr, _: ()) { let len = this.with(|elems| elems.len()); let dst = this.decay(); for i in 0..len { - >::constructor(dst.offset(i), ()); + >::constructor(dst.offset(i), ()); } } } -impl ConstructibleFromUnsafe<()> for [T; N] { +impl ConstructorUnsafe<()> for [T; N] { unsafe fn constructor(this: *mut Self, _: ()) { for elem in unsafe { (*this).iter_mut() } { - unsafe { >::constructor(elem, ()) } + unsafe { >::constructor(elem, ()) } } } } -impl ConstructibleFromUnsafe<()> for *mut T { +impl ConstructorUnsafe<()> for *mut T { unsafe fn constructor(this: *mut Self, _: ()) { unsafe { std::ptr::write(this, std::ptr::null_mut()) } } } -impl ConstructibleFromUnsafe<()> for *const T { +impl ConstructorUnsafe<()> for *const T { unsafe fn constructor(this: *mut Self, _: ()) { unsafe { std::ptr::write(this, std::ptr::null()) } } @@ -826,7 +856,7 @@ impl TriviallyDe { } -impl ConstructibleFrom<(RvalueRef,)> for FnPtr { +impl Constructor<(RvalueRef,)> for FnPtr { fn constructor(this: Ptr, (src,): (RvalueRef,)) { let value = src.as_pointer().with(FnPtr::move_from); this.with_mut(|dst| *dst = value); @@ -841,7 +871,7 @@ impl TriviallyMoveConstructible for FnPtr { } } -impl ConstructibleFrom<(LvalueRef>,)> for FnPtr { +impl Constructor<(LvalueRef>,)> for FnPtr { fn constructor(this: Ptr, (src,): (LvalueRef>,)) { let value = src.as_pointer().with(FnPtr::copy_from); this.with_mut(|dst| *dst = value); @@ -858,7 +888,7 @@ impl TriviallyCopyConstructible for FnPtr { impl MoveAssignable for FnPtr { fn move_assign(this: Ptr, src: RvalueRef) -> Ptr { - ,)>>::constructor(this.clone(), (src,)); + ,)>>::constructor(this.clone(), (src,)); this.clone() } } @@ -867,7 +897,7 @@ impl TriviallyMoveAssignable for FnPtr {} impl CopyAssignable for FnPtr { fn copy_assign(this: Ptr, src: LvalueRef>) -> Ptr { - >,)>>::constructor(this.clone(), (src,)); + >,)>>::constructor(this.clone(), (src,)); this.clone() } } @@ -886,7 +916,7 @@ impl SwappableUnsafe for FnPtr { } } -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for FnPtr { +impl ConstructorUnsafe<(RvalueRefUnsafe,)> for FnPtr { unsafe fn constructor(this: *mut Self, (src,): (crate::RvalueRefUnsafe,)) { let src = src.as_ptr(); unsafe { std::ptr::write(this, (*src).move_from()) } @@ -895,7 +925,7 @@ impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for FnPtr { impl MoveConstructibleUnsafe for FnPtr {} -impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for FnPtr { +impl ConstructorUnsafe<(LvalueRefUnsafe>,)> for FnPtr { unsafe fn constructor(this: *mut Self, (src,): (crate::LvalueRefUnsafe>,)) { let src = src.as_const_ptr(); unsafe { std::ptr::write(this, (*src).copy_from()) } @@ -965,12 +995,12 @@ fn assign_elems( this.clone() } -impl ConstructibleFrom<(RvalueRef,)> +impl Constructor<(RvalueRef,)> for Box<[T]> { fn constructor(this: Ptr, (src,): (RvalueRef,)) { construct_elems(&this, &src.as_pointer(), |dst, src| { - ,)>>::constructor(dst, (RvalueRef::bind(src),)) + ,)>>::constructor(dst, (RvalueRef::bind(src),)) }); } } @@ -986,11 +1016,11 @@ impl TriviallyMov } impl - ConstructibleFrom<(LvalueRef>,)> for Box<[T]> + Constructor<(LvalueRef>,)> for Box<[T]> { fn constructor(this: Ptr, (src,): (LvalueRef>,)) { construct_elems(&this, &src.as_pointer(), |dst, src| { - >,)>>::constructor( + >,)>>::constructor( dst, (LvalueRef::bind(src),), ) @@ -1048,7 +1078,7 @@ impl SwappableUnsafe for [T; N] { } } -impl ConstructibleFromUnsafe<(RvalueRefUnsafe,)> +impl ConstructorUnsafe<(RvalueRefUnsafe,)> for [T; N] { unsafe fn constructor(this: *mut Self, (src,): (crate::RvalueRefUnsafe,)) { @@ -1056,7 +1086,7 @@ impl ConstructibleFromUnsafe<(Rvalue let src = src as *mut T; for (i, elem) in unsafe { (*this).iter_mut() }.enumerate() { unsafe { - ,)>>::constructor( + ,)>>::constructor( elem, (RvalueRefUnsafe::bind(src.add(i)),), ) @@ -1068,14 +1098,14 @@ impl ConstructibleFromUnsafe<(Rvalue impl MoveConstructibleUnsafe for [T; N] {} impl - ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for [T; N] + ConstructorUnsafe<(LvalueRefUnsafe>,)> for [T; N] { unsafe fn constructor(this: *mut Self, (src,): (crate::LvalueRefUnsafe>,)) { let src = src.as_const_ptr(); let src = src as *const T; for (i, elem) in unsafe { (*this).iter_mut() }.enumerate() { unsafe { - >,)>>::constructor( + >,)>>::constructor( elem, (LvalueRefUnsafe::bind(src.add(i)),), ) diff --git a/libcc2rs/src/conversion.rs b/libcc2rs/src/conversion.rs index e795043e37..3fc3fd5640 100644 --- a/libcc2rs/src/conversion.rs +++ b/libcc2rs/src/conversion.rs @@ -3,52 +3,17 @@ use crate::capture::{Destructible, DestructibleUnsafe}; use crate::rc::Ptr; -use crate::reference::{Const, LvalueRef, LvalueRefUnsafe}; -pub trait ConstructibleFrom: Destructible { +pub trait Constructor: Destructible { fn constructor(this: Ptr, args: Args); } -pub trait ConstructibleFromUnsafe: DestructibleUnsafe { +pub trait ConstructorUnsafe: DestructibleUnsafe { /// # Safety /// `self` is storage for an object, and `args` refer to live objects. unsafe fn constructor(this: *mut Self, args: Args); } -pub trait ConvertibleTo>: Sized { - fn convert(self, to: Ptr) { - To::constructor(to, (self,)) - } -} - -pub trait ConvertibleToUnsafe>: Sized { - /// # Safety - /// `to` is storage for an object, and `self` refers to a live object. - unsafe fn convert(self, to: *mut To) { - unsafe { To::constructor(to, (self,)) } - } -} - -pub trait ConversionFunction>>: Sized { - fn conversion_function(this: This, to: Ptr); -} - -pub trait ImplicitConversionFunction>>: - ConversionFunction -{ -} - -pub trait ConversionFunctionUnsafe>>: Sized { - /// # Safety - /// `this` refers to a live object, and `to` is storage for an object. - unsafe fn conversion_function(this: This, to: *mut To); -} - -pub trait ImplicitConversionFunctionUnsafe>>: - ConversionFunctionUnsafe -{ -} - #[macro_export] macro_rules! cpp_type { ($cpp:literal, $rust:ty) => { diff --git a/libcc2rs/src/lib.rs b/libcc2rs/src/lib.rs index bfdeb9c5e8..3531679c1b 100644 --- a/libcc2rs/src/lib.rs +++ b/libcc2rs/src/lib.rs @@ -66,11 +66,10 @@ pub use reference::*; mod conversion; pub mod overload; -pub use overload::{Conversions, ConversionsUnsafe}; -pub use conversion::{ - ConstructibleFrom, ConstructibleFromUnsafe, ConversionFunction, ConversionFunctionUnsafe, - ConvertibleTo, ConvertibleToUnsafe, ImplicitConversionFunction, - ImplicitConversionFunctionUnsafe, +pub use conversion::{Constructor, ConstructorUnsafe}; +pub use overload::{ + ConstructibleFrom, ConstructibleFromUnsafe, Conversions, ConversionsUnsafe, ConvertibleTo, + ConvertibleToUnsafe, }; mod initialization; diff --git a/libcc2rs/src/object.rs b/libcc2rs/src/object.rs index d005212ad6..d1cb464420 100644 --- a/libcc2rs/src/object.rs +++ b/libcc2rs/src/object.rs @@ -7,7 +7,6 @@ // // object!(a, Buffer, (i32,), (4,)); // Buffer a(4); // object!(a, Buffer, (i32, i32), (4, 5)); // Buffer a(4, 5); -// object!(b, Buffer = >>::bind(a.as_pointer())); // Buffer b = a; // 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; @@ -144,11 +143,6 @@ macro_rules! object { ($name:ident, $ty:ident ($($arg:expr),* $(,)?)) => { $crate::object!($name, $ty::construct($($arg),*)); }; - ($name:ident, $ty:ty = $src:expr) => { - let $name: $crate::Value<$ty> = $crate::__object::storage::<$ty>(); - $crate::ConvertibleTo::<$ty>::convert($src, $crate::AsPointer::<$ty>::as_pointer(&$name)); - $crate::object!(@guard $name); - }; ($name:ident, $ty:ty, |$this:ident| $init:expr) => { let $name: $crate::Value<$ty> = $crate::__object::storage::<$ty>(); { @@ -159,33 +153,24 @@ macro_rules! object { }; ($name:ident, $ty:ty, LvalueRef::bind($src:expr)) => { let $name: $crate::Value<$ty> = $crate::__object::storage::<$ty>(); - <$ty as $crate::ConstructibleFrom<($crate::LvalueRef<$crate::Const<$ty>>,)>>::constructor( + <$ty as $crate::CopyConstructible>::copy_constructor( $crate::AsPointer::<$ty>::as_pointer(&$name), - ($crate::LvalueRef::bind($src),), + $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>(); - <$ty as $crate::ConstructibleFrom<($crate::RvalueRef<$ty>,)>>::constructor( - $crate::AsPointer::<$ty>::as_pointer(&$name), - ($crate::RvalueRef::bind($src),), - ); - $crate::object!(@guard $name); - }; - ($name:ident, $ty:ty, $args:ty, $values:expr) => { - let $name: $crate::Value<$ty> = $crate::__object::storage::<$ty>(); - <$ty as $crate::ConstructibleFrom<$args>>::constructor( + <$ty as $crate::MoveConstructible>::move_constructor( $crate::AsPointer::<$ty>::as_pointer(&$name), - $values, + $crate::RvalueRef::bind($src), ); $crate::object!(@guard $name); }; ($name:ident, $ty:ty) => { let $name: $crate::Value<$ty> = $crate::__object::storage::<$ty>(); - <$ty as $crate::ConstructibleFrom<()>>::constructor( + <$ty as $crate::DefaultConstructible>::default_constructor( $crate::AsPointer::<$ty>::as_pointer(&$name), - (), ); $crate::object!(@guard $name); }; @@ -209,14 +194,6 @@ macro_rules! object_unsafe { ($name:ident, $ty:ident ($($arg:expr),* $(,)?)) => { $crate::object_unsafe!($name, $ty::construct($($arg),*)); }; - ($name:ident, $ty:ty = $src:expr) => { - let mut $name: $ty = <$ty as $crate::ZeroInitializationUnsafe>::zero_init(); - #[allow(unused_unsafe)] - unsafe { - $crate::ConvertibleToUnsafe::<$ty>::convert($src, &raw mut $name) - }; - $crate::object_unsafe!(@guard $name); - }; ($name:ident, $ty:ty, |$this:ident| $init:expr) => { let mut $name: $ty = <$ty as $crate::ZeroInitializationUnsafe>::zero_init(); { @@ -229,9 +206,9 @@ macro_rules! object_unsafe { let mut $name: $ty = <$ty as $crate::ZeroInitializationUnsafe>::zero_init(); #[allow(unused_unsafe)] unsafe { - <$ty as $crate::ConstructibleFromUnsafe<($crate::LvalueRefUnsafe<$crate::Const<$ty>>,)>>::constructor( + <$ty as $crate::CopyConstructibleUnsafe>::copy_constructor( &mut $name, - ($crate::LvalueRefUnsafe::bind::<$ty>($src),), + $crate::LvalueRefUnsafe::bind::<$ty>($src), ) }; $crate::object_unsafe!(@guard $name); @@ -240,26 +217,18 @@ macro_rules! object_unsafe { let mut $name: $ty = <$ty as $crate::ZeroInitializationUnsafe>::zero_init(); #[allow(unused_unsafe)] unsafe { - <$ty as $crate::ConstructibleFromUnsafe<($crate::RvalueRefUnsafe<$ty>,)>>::constructor( + <$ty as $crate::MoveConstructibleUnsafe>::move_constructor( &mut $name, - ($crate::RvalueRefUnsafe::bind::<$ty>($src),), + $crate::RvalueRefUnsafe::bind::<$ty>($src), ) }; $crate::object_unsafe!(@guard $name); }; - ($name:ident, $ty:ty, $args:ty, $values:expr) => { - let mut $name: $ty = <$ty as $crate::ZeroInitializationUnsafe>::zero_init(); - #[allow(unused_unsafe)] - unsafe { - <$ty as $crate::ConstructibleFromUnsafe<$args>>::constructor(&raw mut $name, $values) - }; - $crate::object_unsafe!(@guard $name); - }; ($name:ident, $ty:ty) => { let mut $name: $ty = <$ty as $crate::ZeroInitializationUnsafe>::zero_init(); #[allow(unused_unsafe)] unsafe { - <$ty as $crate::ConstructibleFromUnsafe<()>>::constructor(&raw mut $name, ()) + <$ty as $crate::DefaultConstructibleUnsafe>::default_constructor(&raw mut $name) }; $crate::object_unsafe!(@guard $name); }; diff --git a/libcc2rs/src/overload.rs b/libcc2rs/src/overload.rs index 23e27e55bc..33499465e8 100644 --- a/libcc2rs/src/overload.rs +++ b/libcc2rs/src/overload.rs @@ -13,6 +13,7 @@ use std::ffi::c_void; use crate::initialization::ZeroInitializationUnsafe as _; use crate::rc::Ptr; +use crate::reference::{Const, LvalueRef, LvalueRefUnsafe, RvalueRef, RvalueRefUnsafe}; use crate::reinterpret::ByteRepr; use crate::void::AnyPtr; @@ -105,30 +106,140 @@ pub struct Table

{ pub trait Conversions: ByteRepr + Sized + 'static { fn table() -> Table; +} + +pub trait ConversionsUnsafe: Sized + 'static { + fn table() -> Table<*mut c_void>; +} + +// T t(args...); +pub trait ConstructibleFrom: Sized { + fn construct(this: Ptr, args: Args); +} - // Direct-initialization of the object at this from args. - fn construct(this: Ptr, args: &[Arg]) { - initialize(&Self::table(), this.to_any(), args, true); +impl ConstructibleFrom for T { + fn construct(this: Ptr, args: Args) { + initialize(&T::table(), this.to_any(), &args.as_args(), true); } +} - // Copy-initialization of the object at this from arg. - fn convert(this: Ptr, arg: Arg) { - initialize(&Self::table(), this.to_any(), &[arg], false); +// To t = from; +pub trait ConvertibleTo: Sized { + fn convert(self, to: Ptr); +} + +impl ConvertibleTo for From { + fn convert(self, to: Ptr) { + initialize(&To::table(), to.to_any(), &[self.as_arg()], false); } } -pub trait ConversionsUnsafe: Sized + 'static { - fn table() -> Table<*mut c_void>; +pub trait ConstructibleFromUnsafe: Sized { + /// # Safety + /// `this` is storage for an object, and `args` refer to live objects. + unsafe fn construct(this: *mut Self, args: Args); +} + +impl ConstructibleFromUnsafe for T { + unsafe fn construct(this: *mut T, args: Args) { + initialize(&T::table(), this.cast(), &args.as_args(), true); + } +} + +pub trait ConvertibleToUnsafe: Sized { + /// # Safety + /// `to` is storage for an object, and `self` refers to a live object. + unsafe fn convert(self, to: *mut To); +} - unsafe fn construct(this: *mut Self, args: &[Arg<*mut c_void>]) { - initialize(&Self::table(), this.cast(), args, true); +impl ConvertibleToUnsafe for From { + unsafe fn convert(self, to: *mut To) { + initialize(&To::table(), to.cast(), &[self.as_arg()], false); } +} - unsafe fn convert(this: *mut Self, arg: Arg<*mut c_void>) { - initialize(&Self::table(), this.cast(), &[arg], false); +// The argument that a reference is, with its value category. +pub trait AsArg { + fn as_arg(&self) -> Arg; +} + +impl AsArg for LvalueRef { + fn as_arg(&self) -> Arg { + Arg::lvalue(self.as_pointer()) } } +impl AsArg for LvalueRef> { + fn as_arg(&self) -> Arg { + Arg::const_lvalue(self.as_pointer()) + } +} + +impl AsArg for RvalueRef { + fn as_arg(&self) -> Arg { + Arg::rvalue(self.as_pointer()) + } +} + +pub trait AsArgUnsafe { + fn as_arg(&self) -> Arg<*mut c_void>; +} + +impl AsArgUnsafe for LvalueRefUnsafe { + fn as_arg(&self) -> Arg<*mut c_void> { + Arg::lvalue_unsafe(self.as_ptr()) + } +} + +impl AsArgUnsafe for LvalueRefUnsafe> { + fn as_arg(&self) -> Arg<*mut c_void> { + Arg::const_lvalue_unsafe(self.as_const_ptr()) + } +} + +impl AsArgUnsafe for RvalueRefUnsafe { + fn as_arg(&self) -> Arg<*mut c_void> { + Arg::rvalue_unsafe(self.as_ptr()) + } +} + +// The arguments that a tuple of references is. +pub trait ArgList { + fn as_args(&self) -> Vec>; +} + +pub trait ArgListUnsafe { + fn as_args(&self) -> Vec>; +} + +macro_rules! arg_list { + ($($name:ident),*) => { + impl<$($name: AsArg),*> ArgList for ($($name,)*) { + #[allow(non_snake_case, clippy::vec_init_then_push)] + fn as_args(&self) -> Vec> { + let ($($name,)*) = self; + vec![$($name.as_arg()),*] + } + } + + impl<$($name: AsArgUnsafe),*> ArgListUnsafe for ($($name,)*) { + #[allow(non_snake_case, clippy::vec_init_then_push)] + fn as_args(&self) -> Vec> { + let ($($name,)*) = self; + vec![$($name.as_arg()),*] + } + } + }; +} + +arg_list!(); +arg_list!(A); +arg_list!(A, B); +arg_list!(A, B, C); +arg_list!(A, B, C, D); +arg_list!(A, B, C, D, E); +arg_list!(A, B, C, D, E, F); + pub struct Arg

{ pub table: fn() -> Table

, pub category: Category, @@ -891,6 +1002,23 @@ mod tests { use super::*; use crate::rc::{AsPointer, Value}; + fn construct_with(to: Ptr, args: &[Arg]) { + initialize(&T::table(), to.to_any(), args, true); + } + + fn convert_with(to: Ptr, arg: Arg) { + initialize(&T::table(), to.to_any(), &[arg], false); + } + + #[allow(dead_code)] + unsafe fn construct_with_unsafe(to: *mut T, args: &[Arg<*mut c_void>]) { + initialize(&T::table(), to.cast(), args, true); + } + + unsafe fn convert_with_unsafe(to: *mut T, arg: Arg<*mut c_void>) { + initialize(&T::table(), to.cast(), &[arg], false); + } + fn object(value: T) -> Value { Rc::new(RefCell::new(value)) } @@ -899,10 +1027,10 @@ mod tests { fn arithmetic_copy_initialization() { let from = object(7_i32); let to = object(0_i64); - Conversions::convert(to.as_pointer(), Arg::const_lvalue(from.as_pointer())); + convert_with(to.as_pointer(), Arg::const_lvalue(from.as_pointer())); assert_eq!(*to.borrow(), 7); let flag = object(false); - Conversions::convert(flag.as_pointer(), Arg::rvalue(object(2.5_f64).as_pointer())); + convert_with(flag.as_pointer(), Arg::rvalue(object(2.5_f64).as_pointer())); assert!(*flag.borrow()); } @@ -1018,11 +1146,11 @@ mod tests { // int i = ratio; picks operator int, whose result needs no conversion. let ratio = object(Ratio(9, 2)); let to = object(0_i32); - Conversions::convert(to.as_pointer(), Arg::const_lvalue(ratio.as_pointer())); + convert_with(to.as_pointer(), Arg::const_lvalue(ratio.as_pointer())); assert_eq!(*to.borrow(), 4); // double d = ratio; picks operator double. let to = object(0.0_f64); - Conversions::convert(to.as_pointer(), Arg::const_lvalue(ratio.as_pointer())); + convert_with(to.as_pointer(), Arg::const_lvalue(ratio.as_pointer())); assert_eq!(*to.borrow(), 5.0); } @@ -1031,9 +1159,7 @@ mod tests { fn conversions_of_equal_rank_are_ambiguous() { // long l = ratio; int -> long and double -> long rank the same. let ratio = object(Ratio(9, 2)); - Conversions::convert( - object(0_i64).as_pointer(), - Arg::const_lvalue(ratio.as_pointer()), + convert_with(object(0_i64).as_pointer(), Arg::const_lvalue(ratio.as_pointer()), ); } @@ -1042,15 +1168,11 @@ mod tests { // Meters m = 2.0; the explicit Meters(double) is not a candidate, so // 2.0 converts to long for Meters(long). let meters = object(Meters(0)); - Conversions::convert( - meters.as_pointer(), - Arg::rvalue(object(2.0_f64).as_pointer()), + convert_with(meters.as_pointer(), Arg::rvalue(object(2.0_f64).as_pointer()), ); assert_eq!(meters.borrow().0, 2); // Meters m(2.0); direct-initialization picks the exact match. - Conversions::construct( - meters.as_pointer(), - &[Arg::rvalue(object(2.0_f64).as_pointer())], + construct_with(meters.as_pointer(), &[Arg::rvalue(object(2.0_f64).as_pointer())], ); assert_eq!(meters.borrow().0, 2000); } @@ -1060,12 +1182,12 @@ mod tests { let mut from = 300_i32; let mut to = 0_u8; unsafe { - ConversionsUnsafe::convert(&raw mut to, Arg::const_lvalue_unsafe(&raw const from)) + convert_with_unsafe(&raw mut to, Arg::const_lvalue_unsafe(&raw const from)) }; assert_eq!(to, 44); let mut pair = (0_i64, 0.0_f64); let mut source = (3_i64, 1.5_f64); - unsafe { ConversionsUnsafe::convert(&raw mut pair, Arg::lvalue_unsafe(&raw mut source)) }; + unsafe { convert_with_unsafe(&raw mut pair, Arg::lvalue_unsafe(&raw mut source)) }; assert_eq!(pair, (3, 1.5)); from += 1; let _ = from; diff --git a/libcc2rs/src/reference.rs b/libcc2rs/src/reference.rs index 826c81e57e..cbce5ca559 100644 --- a/libcc2rs/src/reference.rs +++ b/libcc2rs/src/reference.rs @@ -13,7 +13,7 @@ use crate::constructor::{ MoveAssignable, MoveAssignableUnsafe, MoveConstructible, MoveConstructibleUnsafe, Swappable, SwappableUnsafe, }; -use crate::conversion::{ConstructibleFrom, ConstructibleFromUnsafe}; +use crate::conversion::{Constructor, ConstructorUnsafe}; use crate::rc::Ptr; use crate::reinterpret::ByteRepr; @@ -90,7 +90,7 @@ macro_rules! reference { } } - impl ConstructibleFrom<(RvalueRef,)> for $name + impl Constructor<(RvalueRef,)> for $name where T::Object: ByteRepr, { @@ -101,7 +101,7 @@ macro_rules! reference { impl MoveConstructible for $name where T::Object: ByteRepr {} - impl ConstructibleFrom<(LvalueRef>,)> for $name + impl Constructor<(LvalueRef>,)> for $name where T::Object: ByteRepr, { @@ -244,13 +244,20 @@ macro_rules! reference_unsafe { } } + impl crate::ZeroInitializationUnsafe for $name { + #[inline] + unsafe fn zero_init() -> 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 ConstructibleFromUnsafe<(RvalueRefUnsafe,)> for $name { + impl ConstructorUnsafe<(RvalueRefUnsafe,)> for $name { unsafe fn constructor(this: *mut Self, (src,): (RvalueRefUnsafe,)) { let src = src.as_ptr(); unsafe { std::ptr::write(this, *src) } @@ -259,7 +266,7 @@ macro_rules! reference_unsafe { impl MoveConstructibleUnsafe for $name {} - impl ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> for $name { + impl ConstructorUnsafe<(LvalueRefUnsafe>,)> for $name { unsafe fn constructor(this: *mut Self, (src,): (LvalueRefUnsafe>,)) { let src = src.as_const_ptr(); unsafe { std::ptr::write(this, *src) } diff --git a/libcc2rs/src/swap.rs b/libcc2rs/src/swap.rs index a331850753..dfae955b9d 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())); - ,)>>::constructor( + ,)>>::constructor( pointer(&dst), (crate::RvalueRef::bind(src.clone()),), ); @@ -67,7 +67,7 @@ pub(crate) fn copy_constructed_in_storage, ) -> T { let dst: Value = Rc::new(RefCell::new(T::zero_init())); - >,)>>::constructor( + >,)>>::constructor( pointer(&dst), (crate::LvalueRef::bind(src),), ); @@ -79,7 +79,7 @@ pub(crate) fn copy_constructed_in_storage(src: *const T) -> T { let mut dst = std::mem::MaybeUninit::::uninit(); unsafe { - >,)>>::constructor(&mut *dst.as_mut_ptr(), (crate::LvalueRefUnsafe::bind(src),)); + >,)>>::constructor(&mut *dst.as_mut_ptr(), (crate::LvalueRefUnsafe::bind(src),)); dst.assume_init() } } @@ -87,7 +87,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 { - ,)>>::constructor( + ,)>>::constructor( &mut *dst.as_mut_ptr(), (crate::RvalueRefUnsafe::bind(src),), ); @@ -165,7 +165,7 @@ where { let storage: Value = Rc::new(RefCell::new(T::zero_init())); let tmp = AsPointer::::as_pointer(&storage); - ,)>>::constructor( + ,)>>::constructor( tmp.clone(), (crate::RvalueRef::bind(this.clone()),), ); @@ -182,7 +182,7 @@ where { let mut tmp = MaybeUninit::::uninit(); unsafe { - ,)>>::constructor( + ,)>>::constructor( &mut *tmp.as_mut_ptr(), (crate::RvalueRefUnsafe::bind(this),), ); From 6867d2f5c766a96a0ee034cfdaeea74b3bb36abc Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 4 Dec 2026 12:21:46 +0000 Subject: [PATCH 23/35] MoveConstructible and CopyConstructible are markers over Converter --- libcc2rs-macros/src/constructor.rs | 37 --------- libcc2rs-macros/src/conversions.rs | 123 +++++++++-------------------- libcc2rs/src/constructor.rs | 79 ++++-------------- libcc2rs/src/reference.rs | 4 - rules/iterator_category/shim.rs | 4 - rules/map/shim.rs | 2 +- rules/unique_ptr/shim.rs | 2 - rules/vector/shim.rs | 8 -- 8 files changed, 52 insertions(+), 207 deletions(-) diff --git a/libcc2rs-macros/src/constructor.rs b/libcc2rs-macros/src/constructor.rs index 652a91f0bf..e48e155885 100644 --- a/libcc2rs-macros/src/constructor.rs +++ b/libcc2rs-macros/src/constructor.rs @@ -178,8 +178,6 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - #body } } - - impl #impl_generics ::libcc2rs::#trait_name for #name #ty_generics #where_clause {} }; } quote! { @@ -220,32 +218,6 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - } else { 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) { - (false, false) => Some(quote! { - fn copied(src: ::libcc2rs::Ptr) -> Self { - src.with(::clone) - } - - fn copied_elems(src: &::libcc2rs::Ptr>) -> Vec { - src.with(|elems| elems.clone()) - } - - fn push_copied(v: &::libcc2rs::Ptr>, src: ::libcc2rs::Ptr) { - let value = src.with(::clone); - v.with_mut(|elems| elems.push(value)); - } - }), - (true, false) => Some(quote! { - fn push_moved(v: &::libcc2rs::Ptr>, src: ::libcc2rs::Ptr) - where - Self: ::libcc2rs::ZeroInitialization + ::libcc2rs::ByteRepr, - { - ::push_copied(v, src) - } - }), - _ => None, - }; if !is_assign { return quote! { impl #impl_generics ::libcc2rs::Constructor<(#src_ty,)> for #name #ty_generics #where_clause { @@ -253,10 +225,6 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - #body } } - - impl #impl_generics ::libcc2rs::#trait_name for #name #ty_generics #where_clause { - #copied - } }; } quote! { @@ -264,7 +232,6 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - fn #method(this: ::libcc2rs::Ptr, src: #src_ty) #ret { #body } - #copied } } } @@ -450,8 +417,6 @@ fn impl_memberwise( };)* } } - - impl #impl_generics #tr for #name #ty_generics #where_clause {} }; } return quote! { @@ -503,8 +468,6 @@ fn impl_memberwise( );)* } } - - impl #impl_generics #tr for #name #ty_generics #where_clause {} }; } quote! { diff --git a/libcc2rs-macros/src/conversions.rs b/libcc2rs-macros/src/conversions.rs index 7cae6c580d..05384a63cd 100644 --- a/libcc2rs-macros/src/conversions.rs +++ b/libcc2rs-macros/src/conversions.rs @@ -9,7 +9,7 @@ use syn::punctuated::Punctuated; use syn::{DeriveInput, Ident, Token, Type, parenthesized, parse_macro_input}; // #[derive(Conversions)] -// #[conversions(copy = copy_from, move = move_from, default = default_constructor)] +// #[conversions(copy, move)] // #[constructor(construct_1, explicit, const_lvalue_ref(W))] // explicit S(const W &) // #[constructor(construct_2, value(i32), lvalue_ref(T))] // S(int, T &) // #[conversion_function(operator_int, i32, const_lvalue_ref)] // operator int() const @@ -18,9 +18,10 @@ use syn::{DeriveInput, Ident, Token, Type, parenthesized, parse_macro_input}; // Implements libcc2rs::overload::Conversions for S, the table of its // constructors and conversion functions, each naming the inherent method that // holds its body, which libcc2rs resolves initializations against at run time. -// copy = m, move = m and default = m also implement CopyConstructible, -// MoveConstructible and DefaultConstructible by calling m; a bare copy or move -// says that the trait is implemented elsewhere. A parameter is value(T), +// Each constructor also implements Constructor for its arguments, by calling +// its method, such that the copy, move and default constructors implement +// CopyConstructible, MoveConstructible and DefaultConstructible. copy and move +// say that S is copy or move constructible. A parameter is value(T), // by_value(T) for a class passed by value, which the caller constructs, // lvalue_ref(T), const_lvalue_ref(T), rvalue_ref(T) or const_rvalue_ref(T). // ConversionsUnsafe is the same for the unsafe model. @@ -157,22 +158,6 @@ impl Parse for ConversionFunction { // A special member: whether S has it, and the inherent method that holds its // body when this derive implements its trait. -#[derive(Default)] -struct Special { - exists: bool, - method: Option, -} - -impl Special { - fn parse(&mut self, meta: &syn::meta::ParseNestedMeta) -> syn::Result<()> { - self.exists = true; - if meta.input.peek(Token![=]) { - self.method = Some(meta.value()?.parse()?); - } - Ok(()) - } -} - pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); let name = &input.ident; @@ -181,8 +166,7 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { let mut constructors = Vec::new(); let mut functions = Vec::new(); - let (mut copy, mut moves, mut default) = - (Special::default(), Special::default(), Special::default()); + let (mut copy, mut moves) = (false, false); for attr in &input.attrs { let result = if attr.path().is_ident("constructor") { attr.parse_args::() @@ -193,14 +177,13 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { } else if attr.path().is_ident("conversions") { attr.parse_nested_meta(|meta| { if meta.path.is_ident("copy") { - copy.parse(&meta) + copy = true; } else if meta.path.is_ident("move") { - moves.parse(&meta) - } else if meta.path.is_ident("default") { - default.parse(&meta) + moves = true; } else { - Err(meta.error("expected `copy`, `move` or `default`")) + return Err(meta.error("expected `copy` or `move`")); } + Ok(()) }) } else { Ok(()) @@ -295,66 +278,32 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { } }); - let copy_ref = Kind::ConstRef.reference(&self_ty, is_unsafe).unwrap(); - let move_ref = Kind::RvalueRef.reference(&self_ty, is_unsafe).unwrap(); - let lvalue_marker = if is_unsafe { - quote!(::libcc2rs::LvalueRefUnsafe) - } else { - quote!(::libcc2rs::LvalueRef) - }; - let moved_object = if is_unsafe { - quote!(src.as_ptr()) - } else { - quote!(src.as_pointer()) - }; - - let mut impls = TokenStream2::new(); - if let Some(method) = ©.method { - impls.extend(quote! { - impl #impl_generics ::libcc2rs::#constructor<(#copy_ref,)> for #self_ty #where_clause { - #fn_kw constructor(this: #ptr_ty, (src,): (#copy_ref,)) { - #[allow(unused_unsafe)] - unsafe { <#self_ty>::#method(this, src) } - } - } - - impl #impl_generics ::libcc2rs::#copy_trait for #self_ty #where_clause {} - }); - } - if let Some(method) = &moves.method { - impls.extend(quote! { - impl #impl_generics ::libcc2rs::#constructor<(#move_ref,)> for #self_ty #where_clause { - #fn_kw constructor(this: #ptr_ty, (src,): (#move_ref,)) { - #[allow(unused_unsafe)] - unsafe { <#self_ty>::#method(this, src) } - } - } - - impl #impl_generics ::libcc2rs::#move_trait for #self_ty #where_clause {} - }); - } else if let (Some(method), false) = (©.method, moves.exists) { - impls.extend(quote! { - impl #impl_generics ::libcc2rs::#constructor<(#move_ref,)> for #self_ty #where_clause { - #fn_kw constructor(this: #ptr_ty, (src,): (#move_ref,)) { - #[allow(unused_unsafe)] - unsafe { <#self_ty>::#method(this, #lvalue_marker::bind(#moved_object)) } - } - } - - impl #impl_generics ::libcc2rs::#move_trait for #self_ty #where_clause {} - }); - } - if let Some(method) = &default.method { - impls.extend(quote! { - impl #impl_generics ::libcc2rs::#constructor<()> for #self_ty #where_clause { - #fn_kw constructor(this: #ptr_ty, _: ()) { + let impls = constructors.iter().map(|ctor| { + let method = &ctor.method; + let arg_types: Vec<_> = ctor + .params + .iter() + .map(|param| { + let ty = ¶m.ty; + param + .kind + .reference("e!(#ty), is_unsafe) + .unwrap_or_else(|| quote!(#ty)) + }) + .collect(); + let names: Vec<_> = (0..arg_types.len()).map(|i| format_ident!("a{}", i)).collect(); + quote! { + impl #impl_generics ::libcc2rs::#constructor<(#(#arg_types,)*)> for #self_ty #where_clause { + #fn_kw constructor(this: #ptr_ty, (#(#names,)*): (#(#arg_types,)*)) { #[allow(unused_unsafe)] - unsafe { <#self_ty>::#method(this) } + unsafe { <#self_ty>::#method(this, #(#names),*) } } } - }); - } + } + }); + let copy_ref = Kind::ConstRef.reference(&self_ty, is_unsafe).unwrap(); + let move_ref = Kind::RvalueRef.reference(&self_ty, is_unsafe).unwrap(); let special = |trait_: &Ident, method: &str, reference: &TokenStream2, exists: bool| { if !exists { let message = format!("{} has no {}", name, method); @@ -373,11 +322,11 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { } } }; - let copy_fn = special(©_trait, "copy_constructor", ©_ref, copy.exists); - let move_fn = if moves.exists || copy.method.is_some() { + let copy_fn = special(©_trait, "copy_constructor", ©_ref, copy); + let move_fn = if moves { special(&move_trait, "move_constructor", &move_ref, true) } else { - special(©_trait, "copy_constructor", ©_ref, copy.exists) + special(©_trait, "copy_constructor", ©_ref, copy) }; let (storage, release) = if is_unsafe { ( @@ -406,7 +355,7 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { let label = name.to_string(); quote! { - #impls + #(#impls)* impl #impl_generics #trait_name for #self_ty #where_clause { fn table() -> #table_ty { diff --git a/libcc2rs/src/constructor.rs b/libcc2rs/src/constructor.rs index e41363af67..0261f9fd16 100644 --- a/libcc2rs/src/constructor.rs +++ b/libcc2rs/src/constructor.rs @@ -54,6 +54,9 @@ pub trait MoveConstructible: Constructor<(RvalueRef,)> + ByteRepr + Sized } } +impl,)> + ByteRepr> MoveConstructible for T {} + + pub trait TriviallyMoveConstructible: MoveConstructible { fn trivial_move(src: &mut Self) -> Self; } @@ -106,6 +109,9 @@ pub trait CopyConstructible: } } +impl>,)>> CopyConstructible for T {} + + pub trait TriviallyCopyConstructible: CopyConstructible { fn trivial_copy(src: &Self) -> Self; } @@ -188,6 +194,9 @@ pub trait MoveConstructibleUnsafe: } } +impl,)>> MoveConstructibleUnsafe for T {} + + pub trait CopyConstructibleUnsafe: MoveConstructibleUnsafe + ConstructorUnsafe<(LvalueRefUnsafe>,)> { @@ -200,6 +209,12 @@ pub trait CopyConstructibleUnsafe: } } +impl>,)>> + CopyConstructibleUnsafe for T +{ +} + + pub trait TriviallyMoveConstructibleUnsafe: MoveConstructibleUnsafe { /// # Safety /// `src` must point to a live value. @@ -328,26 +343,6 @@ macro_rules! impl_copy_by_clone { ($(<$($param:ident),*> $ty:ty),* $(,)?) => {$( -impl<$($param),*> $crate::CopyConstructible for $ty - where - $ty: Clone + $crate::ByteRepr, - { - - - - fn copied(src: $crate::Ptr) -> Self { - src.with(Self::clone) - } - - fn copied_elems(src: &$crate::Ptr>) -> Vec { - src.with(|elems| elems.clone()) - } - - fn push_copied(v: &$crate::Ptr>, src: $crate::Ptr) { - let value = src.with(Self::clone); - v.with_mut(|elems| elems.push(value)); - } -} impl<$($param),*> $crate::CopyAssignable for $ty where @@ -360,10 +355,6 @@ impl<$($param),*> $crate::CopyConstructible for $ty } -impl<$($param),*> $crate::CopyConstructibleUnsafe for $ty - where - $ty: Clone, - {} impl<$($param),*> $crate::CopyAssignableUnsafe for $ty where @@ -383,18 +374,6 @@ macro_rules! impl_move_by_clone { ($(<$($param:ident),*> $ty:ty),* $(,)?) => {$( -impl<$($param),*> $crate::MoveConstructible for $ty - where - $ty: Clone + $crate::ByteRepr, - { - - - - fn push_moved(v: &$crate::Ptr>, src: $crate::Ptr) { - let value = src.with(Self::clone); - v.with_mut(|elems| elems.push(value)); - } -} impl<$($param),*> $crate::MoveAssignable for $ty where @@ -407,10 +386,6 @@ impl<$($param),*> $crate::MoveConstructible for $ty } -impl<$($param),*> $crate::MoveConstructibleUnsafe for $ty - where - $ty: Clone, - {} impl<$($param),*> $crate::MoveAssignableUnsafe for $ty where @@ -545,18 +520,6 @@ macro_rules! impl_move_by_take { } } -impl<$($param),*> $crate::MoveConstructible for $ty - where - $ty: Default + $crate::ByteRepr, - { - - - - fn push_moved(v: &$crate::Ptr>, src: $crate::Ptr) { - let value = src.with_mut(std::mem::take); - v.with_mut(|elems| elems.push(value)); - } -} impl<$($param),*> $crate::MoveAssignable for $ty where @@ -579,10 +542,6 @@ impl<$($param),*> $crate::MoveConstructible for $ty } } -impl<$($param),*> $crate::MoveConstructibleUnsafe for $ty - where - $ty: Default, - {} impl<$($param),*> $crate::MoveAssignableUnsafe for $ty where @@ -863,7 +822,6 @@ impl Constructor<(RvalueRef,)> for FnPtr { } } -impl MoveConstructible for FnPtr {} impl TriviallyMoveConstructible for FnPtr { fn trivial_move(src: &mut Self) -> Self { @@ -878,7 +836,6 @@ impl Constructor<(LvalueRef>,)> for FnPtr { } } -impl CopyConstructible for FnPtr {} impl TriviallyCopyConstructible for FnPtr { fn trivial_copy(src: &Self) -> Self { @@ -923,7 +880,6 @@ impl ConstructorUnsafe<(RvalueRefUnsafe,)> for FnPtr { } } -impl MoveConstructibleUnsafe for FnPtr {} impl ConstructorUnsafe<(LvalueRefUnsafe>,)> for FnPtr { unsafe fn constructor(this: *mut Self, (src,): (crate::LvalueRefUnsafe>,)) { @@ -932,7 +888,6 @@ impl ConstructorUnsafe<(LvalueRefUnsafe>,)> for FnPtr { } } -impl CopyConstructibleUnsafe for FnPtr {} impl TriviallyMoveConstructibleUnsafe for FnPtr { unsafe fn trivial_move(src: *mut Self) -> Self { @@ -1005,7 +960,6 @@ impl Constructor<(RvalueRe } } -impl MoveConstructible for Box<[T]> {} impl TriviallyMoveConstructible for Box<[T]> @@ -1028,7 +982,6 @@ impl } } -impl CopyConstructible for Box<[T]> {} impl TriviallyCopyConstructible for Box<[T]> @@ -1095,7 +1048,6 @@ impl ConstructorUnsafe<(RvalueRefUns } } -impl MoveConstructibleUnsafe for [T; N] {} impl ConstructorUnsafe<(LvalueRefUnsafe>,)> for [T; N] @@ -1114,7 +1066,6 @@ impl } } -impl CopyConstructibleUnsafe for [T; N] {} impl TriviallyMoveConstructibleUnsafe for [T; N] diff --git a/libcc2rs/src/reference.rs b/libcc2rs/src/reference.rs index cbce5ca559..d0a2edeade 100644 --- a/libcc2rs/src/reference.rs +++ b/libcc2rs/src/reference.rs @@ -99,7 +99,6 @@ macro_rules! reference { } } - impl MoveConstructible for $name where T::Object: ByteRepr {} impl Constructor<(LvalueRef>,)> for $name where @@ -110,7 +109,6 @@ macro_rules! reference { } } - impl CopyConstructible for $name where T::Object: ByteRepr {} impl Destructible for $name where @@ -264,7 +262,6 @@ macro_rules! reference_unsafe { } } - impl MoveConstructibleUnsafe for $name {} impl ConstructorUnsafe<(LvalueRefUnsafe>,)> for $name { unsafe fn constructor(this: *mut Self, (src,): (LvalueRefUnsafe>,)) { @@ -273,7 +270,6 @@ macro_rules! reference_unsafe { } } - impl CopyConstructibleUnsafe for $name {} impl DestructibleUnsafe for $name { unsafe fn destroy(_this: *mut Self) {} diff --git a/rules/iterator_category/shim.rs b/rules/iterator_category/shim.rs index d296f558c7..4afdc5e836 100644 --- a/rules/iterator_category/shim.rs +++ b/rules/iterator_category/shim.rs @@ -182,7 +182,6 @@ macro_rules! uninhabited_iterator { } } - impl crate::MoveConstructible for $name {} impl crate::Constructor<(crate::LvalueRef>,)> for $name @@ -192,7 +191,6 @@ macro_rules! uninhabited_iterator { } } - impl crate::CopyConstructible for $name {} impl crate::ConstructorUnsafe<(crate::RvalueRefUnsafe,)> for $name { unsafe fn constructor(_: *mut Self, (src,): (crate::RvalueRefUnsafe,)) { @@ -200,7 +198,6 @@ macro_rules! uninhabited_iterator { } } - impl crate::MoveConstructibleUnsafe for $name {} impl crate::ConstructorUnsafe<(crate::LvalueRefUnsafe>,)> for $name @@ -213,7 +210,6 @@ macro_rules! uninhabited_iterator { } } - impl crate::CopyConstructibleUnsafe for $name {} impl crate::Destructible for $name { fn destroy(_: Ptr) {} diff --git a/rules/map/shim.rs b/rules/map/shim.rs index 9db9c20a59..a3a4f66c4d 100644 --- a/rules/map/shim.rs +++ b/rules/map/shim.rs @@ -120,7 +120,7 @@ where } } -impl CopyConstructible for Map, Value)> +impl Map, Value)> where K: CppLess + CopyConstructible + ZeroInitialization + 'static, V: CopyConstructible + ZeroInitialization + 'static, diff --git a/rules/unique_ptr/shim.rs b/rules/unique_ptr/shim.rs index 5c79f239ab..519d0b60c8 100644 --- a/rules/unique_ptr/shim.rs +++ b/rules/unique_ptr/shim.rs @@ -29,7 +29,6 @@ where } } -impl MoveConstructible for Option> where Self: ByteRepr {} impl MoveAssignable for Option> where @@ -49,7 +48,6 @@ impl ConstructorUnsafe<(RvalueRefUnsafe,)> for Option> { } } -impl MoveConstructibleUnsafe for Option> {} impl MoveAssignableUnsafe for Option> { unsafe fn move_assign(this: *mut Self, src: RvalueRefUnsafe) -> *mut Self { diff --git a/rules/vector/shim.rs b/rules/vector/shim.rs index 3ce481e275..0a0c7811e4 100644 --- a/rules/vector/shim.rs +++ b/rules/vector/shim.rs @@ -41,12 +41,6 @@ impl } } -impl CopyConstructible for Vec { - fn copied(src: Ptr) -> Self { - T::copied_elems(&src) - } -} - impl CopyAssignable for Vec { fn copy_assign(this: Ptr, src: LvalueRef>) -> Ptr { this.write(T::copied_elems(&src.as_pointer())); @@ -140,8 +134,6 @@ impl ConstructorUnsafe<(LvalueRefUnsafe> } } -impl CopyConstructibleUnsafe for Vec {} - impl CopyAssignableUnsafe for Vec { unsafe fn copy_assign(this: *mut Self, src: LvalueRefUnsafe>) -> *mut Self { let src = src.as_const_ptr(); From b7f54bcceeb5ff3034fda7dd1621a458dc5cc175 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 4 Dec 2026 12:45:32 +0000 Subject: [PATCH 24/35] Add converter support for ConvertibleTo and ConstructibleFrom --- cpp2rust/converter/converter.cpp | 387 +++++++++++------- cpp2rust/converter/converter.h | 35 +- cpp2rust/converter/converter_lib.cpp | 127 +++++- cpp2rust/converter/converter_lib.h | 44 +- .../converter/models/converter_refcount.cpp | 46 ++- .../converter/models/converter_refcount.h | 11 +- cpp2rust/converter/rules/registry.cpp | 13 - cpp2rust/converter/rules/registry.h | 3 - libcc2rs-macros/src/conversions.rs | 195 +++------ libcc2rs/src/constructor.rs | 33 +- libcc2rs/src/fn_ptr_arg.rs | 20 + libcc2rs/src/overload.rs | 153 ++++++- libcc2rs/src/reference.rs | 41 +- 13 files changed, 705 insertions(+), 403 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index eae697d31c..5e17813792 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -128,7 +129,8 @@ void Converter::EmitUndefinedRecordTraits(Model model, std::string &out) { out += std::format( "impl {} for {} {{ {} {{ unreachable!(\"{}::{} is never defined\") " "}} }}\n", - spelling.name, record, spelling.signature, record, trait->method); + spelling.constructor ? spelling.constructor : spelling.name, record, + spelling.signature, record, trait->method); } } } @@ -177,10 +179,13 @@ void Converter::EmitGlobalInits(Model model, std::string &out) { void Converter::EmitOpaqueRecords(Model model, std::string &out) { record_decls_.ForEachUndefined([&](const std::string &name) { if (model == Model::kRefCount) { - out += "#[derive(Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg)]"; + out += "#[derive(Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg, " + "ZeroInitialization, Destructible, Conversions)]"; out += "#[byte_size(1)]"; } else { - out += "#[derive(Clone, Copy, Default, VaArg, FnPtrArg)]"; + out += "#[derive(Clone, Copy, Default, VaArg, FnPtrArg, " + "ZeroInitializationUnsafe, DestructibleUnsafe, " + "ConversionsUnsafe)]"; } out += "pub struct "; out += name; @@ -468,7 +473,7 @@ Converter::ConvertFunctionPointerType(const clang::FunctionProtoType *proto) { result += ','; } for (auto p_ty : proto->param_types()) { - result += ToString(GetPassedParamType(ctx_, p_ty)); + result += UsesReturnSlot(p_ty) ? GetParameterObjectType(p_ty) : ToString(p_ty); result += ','; } if (proto->isVariadic()) { @@ -755,6 +760,10 @@ bool Converter::ConvertVarDeclSkipInit(clang::VarDecl *decl) { StrCat(keyword::kMut); } StrCat(name, token::kColon); + if (clang::isa(decl) && UsesReturnSlot(decl->getType())) { + StrCat(GetParameterObjectType(decl->getType())); + return true; + } { PushLazyType lazy(*this, IsGlobalVar(decl) && LazyStaticInit()); Convert(qual_type); @@ -1131,7 +1140,7 @@ void Converter::EmitRustStructOrUnion(clang::RecordDecl *decl) { } EmitDerives(decl); if (auto *cxx = clang::dyn_cast(decl)) { - EmitConversionAttrs(cxx); + EmitConversionsAttrs(cxx); } EmitByteSizeAttr(decl); @@ -1200,20 +1209,22 @@ Converter::GetAssignmentTraitSignature(const RecordTrait &trait) const { trait.method, GetCopyOrMoveSourceType(trait)); } -std::string Converter::GetCopyOrMoveSourceType(const RecordTrait &trait) const { +std::string Converter::GetCopyOrMoveSourceType(const RecordTrait &trait, + std::string_view self) const { if (&trait == &kMoveConstructible || &trait == &kMoveAssignable) { - return std::format("{}", GetReferenceMarker(true)); + return std::format("{}<{}>", GetReferenceMarker(true), self); } - return std::format("{}>", GetReferenceMarker(false)); + return std::format("{}>", GetReferenceMarker(false), self); } void Converter::ConvertTemplateInstantiatedCtors(clang::CXXRecordDecl *decl) { for (auto c : GetTemplateInstantiatedCtors(decl)) { - if (!decl_ids_.contains(GetID(c))) { - StrCat(keyword::kImpl, GetRecordName(decl)); - PushBrace brace(*this); - VisitCXXMethodDecl(c); + if (decl_ids_.contains(GetID(c))) { + continue; } + StrCat(keyword::kImpl, GetRecordName(decl)); + PushBrace brace(*this); + VisitCXXMethodDecl(c); } } @@ -1232,7 +1243,7 @@ void Converter::ConvertCopyOrMoveTraitImpls( const clang::CXXRecordDecl *decl, bool (*predicate)(clang::CXXMethodDecl *)) { ForEachMethod(decl, [&](clang::CXXMethodDecl *method) { - if (predicate(method) && GetRecordTrait(method) && + if (predicate(method) && GetMethodTrait(method) && !IsDerivedCopyOrMove(method)) { VisitCXXMethodDecl(method); } @@ -1313,47 +1324,6 @@ void Converter::EmitDerives(const clang::RecordDecl *decl) { } } -void Converter::EmitConversionAttrs(clang::CXXRecordDecl *decl) { - std::unordered_set from_types; - ForEachConvertingConstructor(decl, [&](clang::CXXConstructorDecl *ctor) { - auto *param = ctor->getParamDecl(0); - auto type = param->getType(); - if (ctx_.hasSameUnqualifiedType(type.getNonReferenceType(), - ctx_.getCanonicalTagType(decl)) && - RecordImplementsClone(decl)) { - return; - } - auto source = - GetUnboxedTypeAsString(type.getNonReferenceType().getUnqualifiedType()); - bool is_move = type->isRValueReferenceType(); - if (!from_types.insert(source + (is_move ? "&&" : "")).second) { - return; - } - const char *kind = - !type->isReferenceType() ? "value" - : is_move || type.getNonReferenceType().isConstQualified() ? "ptr" - : "mut_ptr"; - StrCat(std::format("#[{}({}, {}, {})]", - is_move ? "cpp_from_move" : "cpp_from", source, - GetCtorName(ctor), kind)); - }); - std::unordered_set into_types; - ForEachMethod(decl, [&](clang::CXXMethodDecl *method) { - if (!IsImplicitConversionOperator(method)) { - return; - } - auto *conversion = clang::cast(method); - auto target = GetUnboxedTypeAsString( - conversion->getConversionType().getUnqualifiedType()); - if (!into_types.insert(target).second) { - return; - } - StrCat(std::format("#[cpp_into({}, {}{})]", target, - GetMethodName(conversion), - conversion->isConst() ? "" : ", mut_ptr")); - }); -} - void Converter::EmitReprC(clang::RecordDecl *decl) { if (decl->hasAttr()) { StrCat(std::format("#[repr(C, align({}))]", @@ -1432,7 +1402,7 @@ bool Converter::VisitCXXMethodDecl(clang::CXXMethodDecl *decl) { } ScopedValue push_fn(curr_function_, decl); - if (auto *trait = GetRecordTrait(decl)) { + if (auto *trait = GetMethodTrait(decl)) { ConvertCopyOrMoveTraitImpl(decl, *trait); return false; } @@ -1456,9 +1426,12 @@ bool Converter::ConvertOutOfLineMethod(clang::CXXMethodDecl *decl) { } std::string Converter::GetMethodName(const clang::CXXMethodDecl *decl) { - if (auto *trait = GetRecordTrait(decl)) { + if (auto *trait = GetMethodTrait(decl)) { return trait->method; } + if (auto method = GetInitMethod(decl)) { + return *method; + } if (clang::isa(decl)) { return kDestructorName; } @@ -1498,9 +1471,9 @@ bool Converter::ConvertCXXMethodDecl(clang::CXXMethodDecl *decl) { return VisitCXXConstructorDecl(ctor); } - if (!GetRecordTrait(decl) && - (decl->isStatic() || - (!decl->isVirtual() && !decl->getParent()->isAbstract()))) { + bool is_trait = GetMethodTrait(decl); + if (!is_trait && (decl->isStatic() || + (!decl->isVirtual() && !decl->getParent()->isAbstract()))) { StrCat(AccessSpecifierAsString(decl->getAccess())); } StrCat(keyword_unsafe_, keyword::kFn, GetMethodName(decl)); @@ -1532,8 +1505,8 @@ std::string Converter::GetSelfMaybeWithMut(const clang::CXXMethodDecl *decl) { } std::string Converter::GetCtorName(clang::CXXConstructorDecl *decl) { - if (auto *trait = GetRecordTrait(decl)) { - return trait->method; + if (auto method = GetInitMethod(decl)) { + return *method; } if (decl->isCopyOrMoveConstructor()) { if (const char *name = GetCopyOrMoveName(decl); @@ -1548,14 +1521,12 @@ std::string Converter::GetCtorName(clang::CXXConstructorDecl *decl) { } bool Converter::VisitCXXConstructorDecl(clang::CXXConstructorDecl *decl) { - if (!IsConvertedConstructor(decl)) { + if (!IsConvertedConstructor(decl) || IsDerivedCopyOrMove(decl)) { return false; } ScopedValue push_fn(curr_function_, decl); - if (!GetRecordTrait(decl)) { - StrCat(AccessSpecifierAsString(decl->getAccess())); - } + StrCat(AccessSpecifierAsString(decl->getAccess())); StrCat(keyword_unsafe_, keyword::kFn, GetCtorName(decl)); { PushParen paren(*this); @@ -1787,12 +1758,14 @@ bool Converter::VisitDeclStmt(clang::DeclStmt *stmt) { bool Converter::VisitReturnStmt(clang::ReturnStmt *stmt) { ScopedValue return_value(return_value_, stmt->getRetValue()); auto return_type = curr_function_->getReturnType(); - if (auto *value = stmt->getRetValue(); value && UsesReturnSlot(return_type)) { + if (auto *value = stmt->getRetValue(); + value && UsesReturnSlot(return_type)) { + std::string_view slot = "__return"; if (auto *construct = GetPlacementInitializer(value)) { - ConstructInPlace(value, construct, GetReturnSlotReceiver()); + ConstructInPlace(value, construct, GetReturnSlotReceiver(slot)); } else { HoistMaterializedTempBindings hoist_temps(*this); - StrCat("__return.write"); + StrCat(slot, ".write"); { PushParen paren(*this); ConvertVarInit(return_type, value); @@ -2774,7 +2747,12 @@ void Converter::EmitArgList(const CallInfo &info) { StrCat(ca.param_name); break; case Kind::Materialized: - StrCat(ca.ref_temp_name); + if (UsesReturnSlot(ca.param_type)) { + StrCat(std::format("{}::bind({})", GetParameterObjectMarker(), + ca.ref_temp_name)); + } else { + StrCat(ca.ref_temp_name); + } break; case Kind::Inline: { StrCat(ConvertArg(info.expr, @@ -4934,6 +4912,8 @@ void Converter::ConvertCXXConstructExprArgs(clang::CXXConstructExpr *expr) { block.emplace(*this); StrCat(CreatePlacementStorage(GetRecordName(ctor->getParent()))); } + bool is_derived = IsDerivedCopyOrMove(ctor); + bool is_init = is_derived || GetInitMethod(ctor).has_value(); std::string args; for (unsigned i = 0; i < ctor->getNumParams(); ++i) { assert(i < expr->getNumArgs()); @@ -4944,38 +4924,38 @@ void Converter::ConvertCXXConstructExprArgs(clang::CXXConstructExpr *expr) { auto converted = ConvertArg(expr, [&] { auto type = ctor->getParamDecl(i)->getType(); if (UsesReturnSlot(type)) { - StrCat(EmitMaterializedTempBinding(type, arg)); + StrCat(std::format("{}::bind({})", GetParameterObjectMarker(), + EmitMaterializedTempBinding(type, arg))); } else { ConvertVarInit(type, arg); } }); + if (auto type = ctor->getParamDecl(i)->getType(); + is_init && IsReferenceToObject(type)) { + converted = std::format("{}::bind({})", + GetReferenceMarker(type->isRValueReferenceType()), + converted); + } args += std::format("{}{}", i ? ", " : "", converted); } - // The copy and move constructors are picked by the type of the source. - auto *trait = GetRecordTrait(ctor); - bool from_source = - trait == &kCopyConstructible || trait == &kMoveConstructible; - 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()) { + full_expression_temporaries_->empty() && !is_derived) { auto record_name = GetRecordName(ctor->getParent()); - if (from_source) { - in_place_.object_tail->emplace(std::format("{}, {}", record_name, args)); - } else if (auto name = GetCtorName(ctor); name == kConstructName) { + if (auto name = GetCtorName(ctor); name == kConstructName) { in_place_.object_tail->emplace(std::format("{}({})", record_name, args)); - } else if (trait != &kDefaultConstructible) { + } else { in_place_.object_tail->emplace( std::format("{}::{}({})", record_name, name, args)); - } else { - in_place_.object_tail->emplace(record_name); } return; } auto path = - std::format("{}::{}", GetConstructorPath(ctor), GetCtorName(ctor)); + is_derived + ? std::format("<{} as {}>::{}", GetRecordName(ctor->getParent()), + GetRecordTraitSpelling(*GetRecordTrait(ctor)).name, + GetRecordTrait(ctor)->method) + : std::format("{}::{}", GetRecordName(ctor->getParent()), + GetCtorName(ctor)); StrCat(std::format("{}({}{}{})", path, in_place ? in_place_.receiver : GetPlacementReceiver(), args.empty() ? "" : ", ", args)); @@ -5054,18 +5034,11 @@ const char *Converter::GetConstructorSelf() const { return "this: *mut Self"; } const char *Converter::GetConstructorWrite() const { return "this.write"; } -std::string -Converter::GetConstructorPath(const clang::CXXConstructorDecl *ctor) const { - if (auto *trait = GetRecordTrait(ctor)) { - return GetCopyOrMoveTraitName(*trait); - } - return GetRecordName(ctor->getParent()); -} - std::string Converter::CreatePlacementStorage(const std::string &record_name, std::string_view name) const { - return std::format("let mut {1}: {0} = <{0}>::zero_init();", record_name, - name); + return std::format( + "let mut {1}: {0} = ZeroInitializationUnsafe::zero_init();", record_name, + name); } std::string Converter::GetPlacementReceiver(std::string_view name) const { @@ -5084,7 +5057,9 @@ bool Converter::CanConstructVarInPlace(const clang::VarDecl *decl) const { const char *Converter::TakePlacementValue() const { return "__v"; } -const char *Converter::GetReturnSlotReceiver() const { return "__return"; } +std::string Converter::GetReturnSlotReceiver(std::string_view slot) const { + return std::string(slot); +} std::string Converter::GetReturnSlotArg(std::string_view receiver) const { return std::string(receiver); @@ -5649,10 +5624,6 @@ Converter::GetStructAttributes(const clang::RecordDecl *decl) { struct_attrs.emplace_back("FnPtrArg"); struct_attrs.emplace_back("ZeroInitializationUnsafe"); - if (HasImplicitConversions(decl)) { - struct_attrs.emplace_back("CppFromUnsafe"); - } - AddSpecialMemberDerives(decl, struct_attrs); if (RecordDerivesDefault(decl)) { @@ -5853,20 +5824,51 @@ void Converter::ConvertFunctionParameters(clang::FunctionDecl *decl) { if (UsesReturnSlot(decl->getReturnType())) { StrCat(GetReturnSlotParam(decl->getReturnType())); } + if (clang::isa(decl) && GetInitMethod(decl)) { + ScopedValue in_formals(in_function_formals_, true); + for (auto *param : DefinitionParameters(decl)) { + auto name = GetNamedDeclAsString(param); + auto type = GetConvertedVarType(param); + StrCat(std::format("{}{}: {},", NeedsMut(param, type, name) ? "mut " : "", + name, GetConstructorArgType(param))); + } + return; + } if (auto *source = GetCopyOrMoveSource(decl)) { - StrCat(GetNamedDeclAsString(source), token::kColon, - GetReferenceMarkerAsString(source->getType()), token::kComma); + StrCat(std::format("{}: {},", GetNamedDeclAsString(source), + GetReferenceMarkerAsString(source->getType()))); return; } ConvertParamList(DefinitionParameters(decl), decl->isVariadic()); } void Converter::EmitFunctionPreamble(clang::FunctionDecl *decl) { - if (auto *source = GetCopyOrMoveSource(decl)) { + for (auto *param : DefinitionParameters(decl)) { + if (UsesReturnSlot(param->getType())) { + auto name = GetNamedDeclAsString(param); + StrCat(std::format( + "let {} = {};", name, + GetReferredObjectPointer(name, GetConvertedVarType(param)))); + } + } + if (!GetMethodTrait(decl) && !GetInitMethod(decl)) { + return; + } + if (auto *source = GetCopyOrMoveSource(decl); + source && !clang::isa(decl)) { auto name = GetNamedDeclAsString(source); StrCat(std::format("let {} = {};", name, GetReferredObjectPointer(name, source->getType()))); } + if (clang::isa(decl)) { + for (auto *param : DefinitionParameters(decl)) { + if (auto type = param->getType(); IsReferenceToObject(type)) { + auto name = GetNamedDeclAsString(param); + StrCat(std::format("let {} = {};", name, + GetReferredObjectPointer(name, type))); + } + } + } } std::string Converter::GetReferredObjectPointer(std::string_view reference, @@ -5931,7 +5933,7 @@ void Converter::ConvertCXXMethodDecls( bool (*predicate)(clang::CXXMethodDecl *)) { bool first = true; auto convert_method = [&](clang::CXXMethodDecl *method) { - if (predicate(method) && !GetRecordTrait(method)) { + if (predicate(method) && !GetMethodTrait(method)) { if (first) { StrCat(signature, token::kOpenCurlyBracket); first = false; @@ -6355,14 +6357,17 @@ Converter::MakeDefaultConstructExpr(const clang::CXXRecordDecl *decl, void Converter::AddDefaultConstructibleTrait(const clang::CXXRecordDecl *decl, clang::CXXConstructorDecl *ctor) { const auto &spelling = GetRecordTraitSpelling(kDefaultConstructible); - StrCat(keyword::kImpl, spelling.name, "for", GetRecordName(decl)); - PushBrace impl_brace(*this); - StrCat(spelling.signature); - PushBrace fn_brace(*this); - StrCat(keyword_unsafe_); - PushBrace unsafe_brace(*this); - auto *construct = MakeDefaultConstructExpr(decl, ctor); - ConstructInPlace(construct, construct, spelling.receiver); + auto record = GetRecordName(decl); + StrCat(keyword::kImpl, spelling.constructor, "for", record); + { + PushBrace impl_brace(*this); + StrCat(spelling.signature); + PushBrace fn_brace(*this); + StrCat(keyword_unsafe_); + PushBrace unsafe_brace(*this); + auto *construct = MakeDefaultConstructExpr(decl, ctor); + ConstructInPlace(construct, construct, spelling.receiver); + } } void Converter::EmitDefaultImpl(const clang::RecordDecl *decl, @@ -7268,16 +7273,6 @@ 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()); @@ -7295,6 +7290,108 @@ const char *Converter::GetReferenceMarker(bool is_rvalue) const { return is_rvalue ? "RvalueRefUnsafe" : "LvalueRefUnsafe"; } +const char *Converter::GetParameterObjectMarker() const { + return "ParameterObjectUnsafe"; +} + +std::string Converter::GetParameterObjectType(clang::QualType type) { + return std::format("{}<{}>", GetParameterObjectMarker(), + GetUnboxedTypeAsString(type.getUnqualifiedType())); +} + +void Converter::EmitConversionsAttrs(const clang::CXXRecordDecl *decl) { + if (!HasConversionsTable(ctx_.getCanonicalTagType(decl))) { + return; + } + StrCat(std::format("#[derive({})]", GetConversionsTrait())); + std::vector ctors(decl->ctors().begin(), + decl->ctors().end()); + for (auto *ctor : + GetTemplateInstantiatedCtors(const_cast(decl))) { + ctors.push_back(ctor); + } + std::vector specials; + if (HasConstructor(decl, false)) { + specials.push_back("copy"); + } + if (HasConstructor(decl, true)) { + specials.push_back("move"); + } + if (!specials.empty()) { + StrCat(std::format("#[conversions({})]", llvm::join(specials, ", "))); + } + auto record = GetRecordName(decl); + std::unordered_set arg_types; + for (auto *ctor : ctors) { + auto method = GetInitMethod(ctor); + if (!method || !IsEmittedConstructor(ctor)) { + continue; + } + if (!llvm::all_of(ctor->parameters(), [](auto *param) { + auto type = param->getType(); + return HasConversionsTable(type) && + !type.getNonReferenceType().isVolatileQualified(); + })) { + continue; + } + std::vector types; + for (auto *param : ctor->parameters()) { + types.push_back(GetConstructorArgType(param)); + } + [[maybe_unused]] bool is_unique = + arg_types.insert(llvm::join(types, ",")).second; + assert(is_unique && "two constructors take the same Rust arguments"); + std::vector params{*method}; + if (ctor->isExplicit()) { + params.push_back("explicit"); + } + params.insert(params.end(), types.begin(), types.end()); + if (auto *trait = GetRecordTrait(ctor)) { + converted_record_traits_.emplace(record, trait->refcount.name); + } + StrCat(std::format("#[constructor({})]", llvm::join(params, ", "))); + } + for (auto *candidate : decl->methods()) { + auto *conversion = clang::dyn_cast(candidate); + if (!conversion || !IsTableConversionFunction(conversion) || + !IsEmittableMethod(conversion) || !conversion->isDefined()) { + continue; + } + auto to = conversion->getConversionType(); + auto object = ctx_.getQualifiedType(ctx_.getCanonicalTagType(decl), + conversion->getMethodQualifiers()); + StrCat(std::format( + "#[conversion_function({}, {}, {}{}{})]", GetMethodName(conversion), + GetReferenceMarkerAsString( + conversion->getRefQualifier() == clang::RQ_RValue + ? ctx_.getRValueReferenceType(object) + : ctx_.getLValueReferenceType(object)), + GetUnboxedTypeAsString(to.getUnqualifiedType()), + conversion->isExplicit() ? ", explicit" : "", + UsesReturnSlot(to) ? ", return_slot" : "")); + } +} + +const char *Converter::GetConversionsTrait() const { + return "ConversionsUnsafe"; +} + +std::string Converter::GetConstructorArgType(const clang::ParmVarDecl *param) { + ScopedValue in_formals(in_function_formals_, true); + auto type = param->getType(); + if (UsesReturnSlot(type)) { + return GetParameterObjectType(type); + } + if (IsReferenceToObject(type)) { + return GetReferenceMarkerAsString(type); + } + return GetParamTypeAsString(param); +} + +std::string Converter::GetParamTypeAsString(const clang::ParmVarDecl *param) { + return ToString(GetConvertedVarType(param)); +} + bool Converter::ReturnsPointerToArg(clang::Expr *) { return false; } std::string Converter::ConvertPointerToArg(clang::Expr *, std::string_view) { @@ -7312,7 +7409,13 @@ std::string Converter::ConvertIRFragment( if (auto *t = std::get_if(&frag)) { result += t->text; } else if (auto *g = std::get_if(&frag)) { - result += GetTemplateArgumentAsString(bindings[g->n - 1]); + if (g->n <= bindings.size()) { + result += GetTemplateArgumentAsString(bindings[g->n - 1]); + } else { + assert(expr && "unbound generic outside an expression rule"); + result += GetTemplateArgumentAsString(clang::TemplateArgument( + RuleRegistry::GetGenericType(ctx_, expr, g->n))); + } } else if (auto *ph = std::get_if(&frag)) { assert(expr && "placeholder outside an expression rule"); auto arg_idx = ph->n; @@ -7409,45 +7512,11 @@ std::string Converter::ConvertGenericCall( assert(call_args.empty() && "default_constructed takes no arguments"); return GetUnboxedDefaultAsString(type); } - if (call.method == "cpp_from" || call.method == "cpp_from_move") { - assert(call_args.size() == 1 && "cpp_from takes one argument"); - return ConvertConversion( - type, RuleRegistry::GetConversionSourceType(ctx_, expr, call.generic), - call.method == "cpp_from_move", call_args[0]); - } + return std::format("<{}>::{}({})", GetUnboxedTypeAsString(type), call.method, llvm::join(call_args, ", ")); } -std::string Converter::ConvertConversion(clang::QualType to, - clang::QualType from, bool is_move, - const std::string &ptr) { - if (to->isArithmeticType() && from->isArithmeticType()) { - auto value = DerefPtrExpr(ptr, from); - if (ctx_.hasSameUnqualifiedType(to, from)) { - return value; - } - if (to->isBooleanType()) { - return std::format("({} != {})", value, - from->isFloatingType() ? "0.0" : "0"); - } - if (from->isBooleanType() && to->isFloatingType()) { - return std::format("({} as u8 as {})", value, GetUnsafeTypeAsString(to)); - } - return std::format("({} as {})", value, GetUnsafeTypeAsString(to)); - } - if (is_move && ctx_.hasSameUnqualifiedType(to, from)) { - return ConvertMoveThroughPointer(to, ptr); - } - return std::format("<{} as {}<{}>>::{}({})", GetUnboxedTypeAsString(to), - GetConversionTraitName(), GetUnboxedTypeAsString(from), - is_move ? "cpp_from_move" : "cpp_from", ptr); -} - -const char *Converter::GetConversionTraitName() const { - return "CppFromUnsafe"; -} - std::string Converter::DerefPtrExpr(std::string_view ptr_expr, clang::QualType pointee_type) { return std::format("({}{})", GetPointerDerefPrefix(pointee_type), ptr_expr); diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index 0f54173255..5709bc3f8c 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -101,12 +101,26 @@ 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 const char *GetParameterObjectMarker() const; + + std::string GetParameterObjectType(clang::QualType type); + + void EmitConversionsAttrs(const clang::CXXRecordDecl *decl); + + virtual const char *GetConversionsTrait() const; + + std::string GetConstructorArgType(const clang::ParmVarDecl *param); + + virtual std::string GetParamTypeAsString(const clang::ParmVarDecl *param); + + + + + virtual std::string CollapseReference(std::string_view result, clang::QualType referred, bool is_place); @@ -197,8 +211,6 @@ class Converter : public clang::RecursiveASTVisitor { void EmitReprC(clang::RecordDecl *decl); void EmitDerives(const clang::RecordDecl *decl); - void EmitConversionAttrs(clang::CXXRecordDecl *decl); - virtual void EmitRustUnion(clang::RecordDecl *decl); virtual bool EmitsReprCForRecords() const { return true; } @@ -273,9 +285,6 @@ class Converter : public clang::RecursiveASTVisitor { virtual const char *GetConstructorWrite() const; - virtual std::string - GetConstructorPath(const clang::CXXConstructorDecl *ctor) const; - // A variable named name that holds zero-initialized storage for a record, // in which a constructor constructs the record. virtual std::string @@ -298,7 +307,7 @@ class Converter : public clang::RecursiveASTVisitor { virtual const char *TakePlacementValue() const; - virtual const char *GetReturnSlotReceiver() const; + virtual std::string GetReturnSlotReceiver(std::string_view slot) const; virtual std::string GetReturnSlotArg(std::string_view receiver) const; @@ -396,11 +405,6 @@ class Converter : public clang::RecursiveASTVisitor { clang::Expr *expr, llvm::ArrayRef args, TempMaterializationCtx *ctx); - std::string ConvertConversion(clang::QualType to, clang::QualType from, - bool is_move, const std::string &ptr); - - virtual const char *GetConversionTraitName() const; - virtual const RecordTraitSpelling & GetRecordTraitSpelling(const RecordTrait &trait) const; @@ -1004,6 +1008,7 @@ class Converter : public clang::RecursiveASTVisitor { const clang::CXXRecordDecl *decl, std::string_view value); + virtual std::string GetComparisonResultReceiver(const clang::CXXMethodDecl *method, bool returns_ref, std::string_view result); @@ -1024,7 +1029,8 @@ class Converter : public clang::RecursiveASTVisitor { virtual std::string GetAssignmentTraitSignature(const RecordTrait &trait) const; - std::string GetCopyOrMoveSourceType(const RecordTrait &trait) const; + std::string GetCopyOrMoveSourceType(const RecordTrait &trait, + std::string_view self = "Self") const; virtual void AddDefaultTraitForUnion(const clang::RecordDecl *decl); @@ -1236,6 +1242,7 @@ class Converter : public clang::RecursiveASTVisitor { bool in_function_formals_ = false; std::string ufcs_receiver_; + bool in_const_initializer_ = false; bool constant_evaluated_ = false; std::optional autoref_mut_; diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 444884f2d5..0601fab771 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -896,6 +896,18 @@ const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method) { return is_copy ? &kCopyAssignable : &kMoveAssignable; } +bool IsConstructibleFromConstructor(const clang::FunctionDecl *decl) { + auto *ctor = clang::dyn_cast_or_null(decl); + if (!ctor || ctor->isDeleted() || ctor->isVariadic() || + ctor->getNumParams() == 0 || GetRecordTrait(ctor)) { + return false; + } + auto *record = ctor->getParent(); + return IsUserDefinedDecl(record) && !record->isLambda() && + !record->isAbstract() && !record->isDependentContext() && + !record->isUnion(); +} + const clang::ParmVarDecl *GetCopyOrMoveSource(const clang::FunctionDecl *decl) { auto *method = clang::dyn_cast(decl); auto *trait = method ? GetRecordTrait(method) : nullptr; @@ -1029,23 +1041,22 @@ bool MovesRuleArg(clang::Expr *expr, unsigned arg_idx, clang::Expr *arg, return moved && !clang::isa(arg); } -static bool -IsImplicitConvertingConstructor(const clang::CXXConstructorDecl *ctor) { +static bool IsOneArgumentConstructor(const clang::CXXConstructorDecl *ctor) { return !ctor->isCopyOrMoveConstructor() && !ctor->isImplicit() && !ctor->isDeleted() && ctor->hasBody() && ctor->getNumParams() == 1 && - ctor->isConvertingConstructor(/*AllowExplicit=*/false); + ctor->isConvertingConstructor(/*AllowExplicit=*/true); } void ForEachConvertingConstructor( clang::CXXRecordDecl *decl, llvm::function_ref fn) { for (auto *ctor : decl->ctors()) { - if (IsImplicitConvertingConstructor(ctor)) { + if (IsOneArgumentConstructor(ctor)) { fn(ctor); } } for (auto *ctor : GetTemplateInstantiatedCtors(decl)) { - if (IsImplicitConvertingConstructor(ctor)) { + if (IsOneArgumentConstructor(ctor)) { fn(ctor); } } @@ -1487,6 +1498,95 @@ unsigned GetCtorIndex(clang::CXXConstructorDecl *ctor) { return static_cast(std::distance(vec.begin(), it) + 1); } +const RecordTrait *GetMethodTrait(const clang::FunctionDecl *decl) { + auto *method = clang::dyn_cast_or_null(decl); + return method && !clang::isa(method) + ? GetRecordTrait(method) + : nullptr; +} + +bool IsReferenceToObject(clang::QualType type) { + if (!type->isReferenceType()) { + return false; + } + auto pointee = type->getPointeeType(); + auto *record = pointee->getAsCXXRecordDecl(); + return !pointee->isFunctionType() && !pointee->isArrayType() && + !(record && IsAbstractUserClass(record)); +} + +bool HasConversionsTable(clang::QualType type) { + type = type.getNonReferenceType().getCanonicalType(); + if (type->isArithmeticType() && !type->isEnumeralType()) { + return true; + } + if (type->isPointerType()) { + return !type->getPointeeType()->isFunctionType(); + } + auto *record = type->getAsCXXRecordDecl(); + return record && record->isCompleteDefinition() && + IsUserDefinedDecl(record) && !record->isLambda() && + !record->isAbstract() && !record->isUnion() && + !record->isDependentContext(); +} + +bool IsTableConversionFunction(const clang::CXXConversionDecl *conversion) { + auto *record = conversion->getParent(); + auto type = conversion->getConversionType(); + return IsUserDefinedDecl(record) && !record->isLambda() && + !record->isDependentContext() && !IsAbstractUserClass(record) && + !conversion->isDeleted() && !conversion->isVirtual() && + !type->isReferenceType() && HasConversionsTable(type) && + !conversion->getMethodQualifiers().hasVolatile(); +} + +std::optional GetInitMethod(const clang::FunctionDecl *decl) { + auto *ctor = clang::dyn_cast_or_null(decl); + if (!ctor || IsDerivedCopyOrMove(ctor) || + (!GetRecordTrait(ctor) && !IsConstructibleFromConstructor(ctor))) { + return std::nullopt; + } + if (ctor->getPrimaryTemplate()) { + return std::format( + "constructor_{}_{}", GetDeclaredCtorIndex(ctor), + GetCtorIndex(const_cast(ctor))); + } + return std::format("constructor_{}", GetDeclaredCtorIndex(ctor)); +} + +bool IsEmittedConstructor(clang::CXXConstructorDecl *ctor) { + return IsEmittableMethod(ctor) && IsConvertedConstructor(ctor) && + !IsDerivedCopyOrMove(ctor) && ctor->isDefined(); +} + +unsigned GetDeclaredCtorIndex(const clang::CXXConstructorDecl *ctor) { + const clang::Decl *target = ctor->getCanonicalDecl(); + if (auto *tmpl = ctor->getPrimaryTemplate()) { + target = tmpl->getCanonicalDecl(); + } + unsigned declared = 0; + for (auto *decl : ctor->getParent()->decls()) { + if (decl->isImplicit()) { + continue; + } + auto *templated = decl; + if (auto *tmpl = clang::dyn_cast(decl)) { + templated = tmpl->getTemplatedDecl(); + } + if (!clang::isa(templated)) { + continue; + } + ++declared; + if (decl->getCanonicalDecl() == target) { + return declared; + } + } + if (ctor->isDefaultConstructor()) { + return declared + 1; + } + return declared + (ctor->isCopyConstructor() ? 2 : 3); +} + clang::CXXConstructorDecl * GetUserDefinedDefaultConstructor(const clang::CXXRecordDecl *decl) { for (auto c : decl->ctors()) { @@ -3222,4 +3322,21 @@ const char *GetConstCastSuffix(clang::QualType to, clang::QualType from) { return to.isConstQualified() ? ".cast_const()" : ".cast_mut()"; } +bool HasConstructor(const clang::CXXRecordDecl *decl, bool is_move) { + if (is_move ? decl->needsImplicitMoveConstructor() + : decl->needsImplicitCopyConstructor()) { + return is_move ? !decl->defaultedMoveConstructorIsDeleted() + : !decl->defaultedCopyConstructorIsDeleted(); + } + return llvm::any_of(decl->ctors(), [&](auto *ctor) { + if (ctor->isDeleted()) { + return false; + } + unsigned quals = 0; + return is_move ? ctor->isMoveConstructor() + : ctor->isCopyConstructor(quals) && + (quals & clang::Qualifiers::Const); + }); +} + } // namespace cpp2rust diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index f1e1851fbb..3c46289766 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -109,6 +109,7 @@ struct RecordTraitSpelling { const char *name; const char *signature = nullptr; const char *receiver = nullptr; + const char *constructor = nullptr; }; struct RecordTrait { @@ -119,27 +120,28 @@ struct RecordTrait { inline constexpr RecordTrait kDefaultConstructible{ "default_constructor", - {"DefaultConstructible", "fn default_constructor(this: Ptr)", - "this.clone()"}, + {"DefaultConstructible", "fn constructor(this: Ptr, _: ())", + "this.clone()", "Constructor<()>"}, {"DefaultConstructibleUnsafe", - "unsafe fn default_constructor(this: *mut Self)", "this"}}; + "unsafe fn constructor(this: *mut Self, _: ())", "this", + "ConstructorUnsafe<()>"}}; inline constexpr RecordTrait kCopyConstructible{ "copy_constructor", {"CopyConstructible", - "fn copy_constructor(this: Ptr, _: LvalueRef>)", - "this.clone()"}, + "fn constructor(this: Ptr, _: (LvalueRef>,))", + "this.clone()", "Constructor<(LvalueRef>,)>"}, {"CopyConstructibleUnsafe", - "unsafe fn copy_constructor(this: *mut Self, _: " - "LvalueRefUnsafe>)", - "this"}}; + "unsafe fn constructor(this: *mut Self, _: " + "(LvalueRefUnsafe>,))", + "this", "ConstructorUnsafe<(LvalueRefUnsafe>,)>"}}; inline constexpr RecordTrait kMoveConstructible{ "move_constructor", {"MoveConstructible", - "fn move_constructor(this: Ptr, _: RvalueRef)", - "this.clone()"}, + "fn constructor(this: Ptr, _: (RvalueRef,))", "this.clone()", + "Constructor<(RvalueRef,)>"}, {"MoveConstructibleUnsafe", - "unsafe fn move_constructor(this: *mut Self, _: RvalueRefUnsafe)", - "this"}}; + "unsafe fn constructor(this: *mut Self, _: (RvalueRefUnsafe,))", + "this", "ConstructorUnsafe<(RvalueRefUnsafe,)>"}}; inline constexpr RecordTrait kCopyAssignable{ "copy_assign", {"CopyAssignable", @@ -236,6 +238,10 @@ inline constexpr RecordTrait kMemberwise{ const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method); +const RecordTrait *GetMethodTrait(const clang::FunctionDecl *decl); + +bool IsConstructibleFromConstructor(const clang::FunctionDecl *decl); + const clang::ParmVarDecl *GetCopyOrMoveSource(const clang::FunctionDecl *decl); const RecordTrait *GetComparisonTrait(const clang::FunctionDecl *fn); @@ -396,6 +402,18 @@ unsigned GetNumberOfConvertingCtors(clang::CXXRecordDecl *decl); unsigned GetCtorIndex(clang::CXXConstructorDecl *ctor); +unsigned GetDeclaredCtorIndex(const clang::CXXConstructorDecl *ctor); + +bool IsReferenceToObject(clang::QualType type); + +bool HasConversionsTable(clang::QualType type); + +std::optional GetInitMethod(const clang::FunctionDecl *decl); + +bool IsTableConversionFunction(const clang::CXXConversionDecl *conversion); + +bool IsEmittedConstructor(clang::CXXConstructorDecl *ctor); + clang::CXXConstructorDecl * GetUserDefinedDefaultConstructor(const clang::CXXRecordDecl *decl); @@ -664,4 +682,6 @@ void ReplaceAll(std::string &str, std::string_view from, std::string_view to); // their constness differs, or nullptr if it doesn't. const char *GetConstCastSuffix(clang::QualType to, clang::QualType from); +bool HasConstructor(const clang::CXXRecordDecl *decl, bool is_move); + } // namespace cpp2rust diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index d11751a3e4..6c79d0cbcf 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -318,6 +318,10 @@ const char *ConverterRefCount::GetReferenceMarker(bool is_rvalue) const { return is_rvalue ? "RvalueRef" : "LvalueRef"; } +const char *ConverterRefCount::GetParameterObjectMarker() const { + return "ParameterObject"; +} + std::string ConverterRefCount::CollapseReference(std::string_view result, clang::QualType, bool) { return std::format("{}.with(|__r| __r.as_pointer())", result); @@ -651,11 +655,12 @@ ConverterRefCount::GetComparisonArg(const clang::ParmVarDecl *param, if (IsTriviallyCopyable(decl)) { return std::format("{}.read()", value); } - return std::format("{{ {} {}::{}({}, LvalueRef::bind({}.clone())); {} }}", - CreatePlacementStorage(GetRecordName(decl)), - GetCopyOrMoveTraitName(kCopyConstructible), - kCopyConstructible.method, GetPlacementReceiver(), value, - TakePlacementValue()); + auto record = GetRecordName(decl); + return std::format( + "{{ {} <{} as CopyConstructible>::copy_constructor({}, " + "LvalueRef::bind({}.clone())); {} }}", + CreatePlacementStorage(record), record, GetPlacementReceiver(), value, + TakePlacementValue()); } std::string ConverterRefCount::GetComparisonResultReceiver( @@ -857,6 +862,10 @@ bool ConverterRefCount::VisitFieldDecl(clang::FieldDecl *decl) { return Converter::VisitFieldDecl(decl); } +const char *ConverterRefCount::GetConversionsTrait() const { + return "Conversions"; +} + std::string ConverterRefCount::GetReferredObjectPointer(std::string_view reference, clang::QualType) { @@ -2334,10 +2343,6 @@ ConverterRefCount::GetStructAttributes(const clang::RecordDecl *decl) { } attrs.emplace_back("FnPtrArg"); - if (HasImplicitConversions(decl)) { - attrs.emplace_back("CppFrom"); - } - AddSpecialMemberDerives(decl, attrs); if (RecordDerivesDefault(decl)) { @@ -2346,10 +2351,6 @@ ConverterRefCount::GetStructAttributes(const clang::RecordDecl *decl) { return attrs; } -const char *ConverterRefCount::GetConversionTraitName() const { - return "CppFrom"; -} - const RecordTraitSpelling & ConverterRefCount::GetRecordTraitSpelling(const RecordTrait &trait) const { return trait.refcount; @@ -3561,7 +3562,7 @@ bool ConverterRefCount::ShouldConvertMethod(const clang::CXXMethodDecl *decl) { bool ConverterRefCount::ReceivesThis() const { auto *method = clang::dyn_cast_or_null(curr_function_); - return method && GetRecordTrait(method); + return method && (GetMethodTrait(method) || GetInitMethod(method)); } const char *ConverterRefCount::SelfName() const { @@ -3663,9 +3664,9 @@ const char *ConverterRefCount::GetConstructorWrite() const { std::string ConverterRefCount::CreatePlacementStorage(const std::string &record_name, std::string_view name) const { - return std::format( - "let {1}: Value<{0}> = Rc::new(RefCell::new(<{0}>::zero_init()));", - record_name, name); + return std::format("let {1}: Value<{0}> = " + "Rc::new(RefCell::new(ZeroInitialization::zero_init()));", + record_name, name); } std::string @@ -3692,8 +3693,9 @@ const char *ConverterRefCount::TakePlacementValue() const { return "Rc::try_unwrap(__v).ok().unwrap().into_inner()"; } -const char *ConverterRefCount::GetReturnSlotReceiver() const { - return "__return.clone()"; +std::string +ConverterRefCount::GetReturnSlotReceiver(std::string_view slot) const { + return std::format("{}.clone()", slot); } std::string @@ -3701,6 +3703,12 @@ ConverterRefCount::GetReturnSlotArg(std::string_view receiver) const { return std::format("Ptr::clone(&{})", receiver); } +std::string +ConverterRefCount::GetParamTypeAsString(const clang::ParmVarDecl *param) { + PushConversionKind push(*this, VarConversionKind(param)); + return ToString(GetConvertedVarType(param)); +} + bool ConverterRefCount::VisitCXXThisExpr( [[maybe_unused]] clang::CXXThisExpr *expr) { if (auto field = AsLambdaCaptureThis(curr_function_)) { diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index 2777cf53b2..54f72eda48 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -31,6 +31,8 @@ class ConverterRefCount final : public Converter { const char *GetReferenceMarker(bool is_rvalue) const override; + const char *GetParameterObjectMarker() const override; + std::string CollapseReference(std::string_view result, clang::QualType referred, bool is_place) override; @@ -116,7 +118,12 @@ class ConverterRefCount final : public Converter { const char *TakePlacementValue() const override; - const char *GetReturnSlotReceiver() const override; + std::string GetReturnSlotReceiver(std::string_view slot) const override; + + const char *GetConversionsTrait() const override; + + std::string GetParamTypeAsString(const clang::ParmVarDecl *param) override; + std::string GetReturnSlotArg(std::string_view receiver) const override; @@ -527,8 +534,6 @@ class ConverterRefCount final : public Converter { std::string DerefPtrExpr(std::string_view ptr_expr, clang::QualType pointee_type) override; - const char *GetConversionTraitName() const override; - const RecordTraitSpelling & GetRecordTraitSpelling(const RecordTrait &trait) const override; diff --git a/cpp2rust/converter/rules/registry.cpp b/cpp2rust/converter/rules/registry.cpp index 583961c19c..59007006ee 100644 --- a/cpp2rust/converter/rules/registry.cpp +++ b/cpp2rust/converter/rules/registry.cpp @@ -464,19 +464,6 @@ clang::QualType GetGenericType(clang::ASTContext &ctx, const clang::Expr *expr, return iteratorElementType(ctx, GetGenericType(ctx, expr, iterator)); } -clang::QualType GetConversionSourceType(clang::ASTContext &ctx, - const clang::Expr *expr, unsigned to) { - auto rule = Search(ctx, expr).first; - assert(rule && "expression must have a translation rule"); - for (const auto &bound : rule->generics.at(to - 1)) { - if (bound.trait_name == "CppFrom" || bound.trait_name == "CppFromUnsafe") { - assert(bound.args.size() == 1 && "CppFrom takes one generic"); - return GetGenericType(ctx, expr, bound.args[0]); - } - } - llvm::report_fatal_error("converted generic has no CppFrom bound"); -} - clang::QualType GetInitType(clang::ASTContext &ctx, const clang::Expr *expr) { auto match = findExpr(expr); assert(match.rule_decl && "expression must have a translation rule"); diff --git a/cpp2rust/converter/rules/registry.h b/cpp2rust/converter/rules/registry.h index c035aa8da7..293ec7fa4f 100644 --- a/cpp2rust/converter/rules/registry.h +++ b/cpp2rust/converter/rules/registry.h @@ -47,9 +47,6 @@ std::string InitAliasName(Model model, const std::string &name); clang::QualType GetGenericType(clang::ASTContext &ctx, const clang::Expr *expr, unsigned n); -clang::QualType GetConversionSourceType(clang::ASTContext &ctx, - const clang::Expr *expr, unsigned to); - bool HasExprRule(const clang::FunctionDecl *decl); bool IsLibcPassthrough(clang::ASTContext &ctx, const clang::Expr *expr); bool ReturnsPointer(clang::ASTContext &ctx, const clang::Expr *expr); diff --git a/libcc2rs-macros/src/conversions.rs b/libcc2rs-macros/src/conversions.rs index 05384a63cd..4f99a2769c 100644 --- a/libcc2rs-macros/src/conversions.rs +++ b/libcc2rs-macros/src/conversions.rs @@ -6,13 +6,14 @@ use proc_macro2::TokenStream as TokenStream2; use quote::{format_ident, quote}; use syn::parse::{Parse, ParseStream}; use syn::punctuated::Punctuated; -use syn::{DeriveInput, Ident, Token, Type, parenthesized, parse_macro_input}; +use syn::{DeriveInput, Ident, Token, Type, parse_macro_input}; // #[derive(Conversions)] // #[conversions(copy, move)] -// #[constructor(construct_1, explicit, const_lvalue_ref(W))] // explicit S(const W &) -// #[constructor(construct_2, value(i32), lvalue_ref(T))] // S(int, T &) -// #[conversion_function(operator_int, i32, const_lvalue_ref)] // operator int() const +// #[constructor(constructor_1, explicit, LvalueRef>)] // explicit S(const W &) +// #[constructor(constructor_2, i32, LvalueRef, ParameterObject)] // S(int, T &, U) +// #[conversion_function(to_i32, LvalueRef>, i32)] // operator int() const +// #[conversion_function(to_t, LvalueRef, T, return_slot)] // operator T() // pub struct S { ... } // // Implements libcc2rs::overload::Conversions for S, the table of its @@ -21,87 +22,16 @@ use syn::{DeriveInput, Ident, Token, Type, parenthesized, parse_macro_input}; // Each constructor also implements Constructor for its arguments, by calling // its method, such that the copy, move and default constructors implement // CopyConstructible, MoveConstructible and DefaultConstructible. copy and move -// say that S is copy or move constructible. A parameter is value(T), -// by_value(T) for a class passed by value, which the caller constructs, -// lvalue_ref(T), const_lvalue_ref(T), rvalue_ref(T) or const_rvalue_ref(T). -// ConversionsUnsafe is the same for the unsafe model. - -#[derive(Clone, Copy, PartialEq)] -enum Kind { - Value, - ByValue, - Ref, - ConstRef, - RvalueRef, - ConstRvalueRef, -} - -impl Kind { - fn parse(ident: &Ident) -> syn::Result { - Ok(match ident.to_string().as_str() { - "value" => Kind::Value, - "by_value" => Kind::ByValue, - "lvalue_ref" => Kind::Ref, - "const_lvalue_ref" => Kind::ConstRef, - "rvalue_ref" => Kind::RvalueRef, - "const_rvalue_ref" => Kind::ConstRvalueRef, - _ => return Err(syn::Error::new(ident.span(), "unknown parameter kind")), - }) - } - - fn passing(self) -> TokenStream2 { - let passing = match self { - Kind::Value | Kind::ByValue => "Value", - Kind::Ref => "LvalueRef", - Kind::ConstRef => "ConstLvalueRef", - Kind::RvalueRef | Kind::ConstRvalueRef => "RvalueRef", - }; - let passing = format_ident!("{}", passing); - quote!(::libcc2rs::overload::Passing::#passing) - } - - // The reference a parameter of this kind is in the Constructor - // arguments, or None for a value. - fn reference(self, ty: &TokenStream2, is_unsafe: bool) -> Option { - let (lvalue, rvalue) = if is_unsafe { - ( - quote!(::libcc2rs::LvalueRefUnsafe), - quote!(::libcc2rs::RvalueRefUnsafe), - ) - } else { - (quote!(::libcc2rs::LvalueRef), quote!(::libcc2rs::RvalueRef)) - }; - match self { - Kind::Value => None, - Kind::ByValue | Kind::Ref => Some(quote!(#lvalue<#ty>)), - Kind::ConstRef => Some(quote!(#lvalue<::libcc2rs::Const<#ty>>)), - Kind::RvalueRef => Some(quote!(#rvalue<#ty>)), - Kind::ConstRvalueRef => Some(quote!(#rvalue<::libcc2rs::Const<#ty>>)), - } - } -} - -struct Parameter { - kind: Kind, - ty: Type, -} - -impl Parse for Parameter { - fn parse(input: ParseStream) -> syn::Result { - let kind: Ident = input.parse()?; - let content; - parenthesized!(content in input); - Ok(Parameter { - kind: Kind::parse(&kind)?, - ty: content.parse()?, - }) - } -} +// say that S is copy or move constructible. Parameters, and the object +// parameter of a conversion function, are their Rust types, whose Parameter +// impls say how they are passed. A conversion function is an ordinary method, +// which returns its result, or writes it through its return slot with +// return_slot. ConversionsUnsafe is the same for the unsafe model. struct Constructor { method: Ident, is_explicit: bool, - params: Vec, + params: Vec, } impl Parse for Constructor { @@ -116,7 +46,7 @@ impl Parse for Constructor { is_explicit = true; input.parse::>()?; } - let params = Punctuated::::parse_terminated(input)?; + let params = Punctuated::::parse_terminated(input)?; Ok(Constructor { method, is_explicit, @@ -127,37 +57,43 @@ impl Parse for Constructor { struct ConversionFunction { method: Ident, + object: Type, to: Type, - object: Kind, is_explicit: bool, + return_slot: bool, } impl Parse for ConversionFunction { fn parse(input: ParseStream) -> syn::Result { let method = input.parse()?; input.parse::()?; - let to = input.parse()?; + let object = input.parse()?; input.parse::()?; - let object = Kind::parse(&input.parse()?)?; - let mut is_explicit = false; - if input.parse::>()?.is_some() { - let spelled: Ident = input.parse()?; - if spelled != "explicit" { - return Err(syn::Error::new(spelled.span(), "expected `explicit`")); + let to = input.parse()?; + let (mut is_explicit, mut return_slot) = (false, false); + while input.parse::>()?.is_some() { + let flag: Ident = input.parse()?; + if flag == "explicit" { + is_explicit = true; + } else if flag == "return_slot" { + return_slot = true; + } else { + return Err(syn::Error::new( + flag.span(), + "expected `explicit` or `return_slot`", + )); } - is_explicit = true; } Ok(ConversionFunction { method, - to, object, + to, is_explicit, + return_slot, }) } } -// A special member: whether S has it, and the inherent method that holds its -// body when this derive implements its trait. pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { let input = parse_macro_input!(input as DeriveInput); let name = &input.ident; @@ -193,19 +129,23 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { } } - let (trait_name, table_ty, cast, ptr_ty) = if is_unsafe { + let (trait_name, parameter, table_ty, cast, ptr_ty, arg) = if is_unsafe { ( quote!(::libcc2rs::overload::ConversionsUnsafe), + quote!(::libcc2rs::overload::ParameterUnsafe), quote!(::libcc2rs::overload::Table<*mut ::std::ffi::c_void>), format_ident!("cast"), quote!(*mut Self), + quote!(args), ) } else { ( quote!(::libcc2rs::overload::Conversions), + quote!(::libcc2rs::overload::Parameter), quote!(::libcc2rs::overload::Table<::libcc2rs::AnyPtr>), format_ident!("downcast"), quote!(::libcc2rs::Ptr), + quote!(&args), ) }; let suffix = if is_unsafe { "Unsafe" } else { "" }; @@ -218,23 +158,13 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { quote!(fn) }; let table_of = |ty: &TokenStream2| quote!(<#ty as #trait_name>::table); + let param_of = |ty: &Type| quote!(<#ty as #parameter>::param()); + let bind = |ty: &Type, i: usize| quote!(<#ty as #parameter>::bind(#arg[#i])); let candidates = constructors.iter().map(|ctor| { let method = &ctor.method; - let params = ctor.params.iter().map(|param| { - let ty = ¶m.ty; - let table = table_of("e!(#ty)); - let passing = param.kind.passing(); - quote!(::libcc2rs::overload::Param { table: #table, passing: #passing }) - }); - let values = ctor.params.iter().enumerate().map(|(i, param)| { - let ty = ¶m.ty; - let pointer = quote!(args[#i].#cast::<#ty>()); - match param.kind.reference("e!(#ty), is_unsafe) { - Some(reference) => quote!(<#reference>::bind(#pointer)), - None => quote!(#pointer.read()), - } - }); + let params = ctor.params.iter().map(param_of); + let values = ctor.params.iter().enumerate().map(|(i, ty)| bind(ty, i)); let is_explicit = ctor.is_explicit; quote! { ::libcc2rs::overload::Candidate { @@ -252,27 +182,24 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { let conversions = functions.iter().map(|function| { let method = &function.method; let to = &function.to; - let object = function - .object - .reference(&self_ty, is_unsafe) - .expect("a conversion function takes its object by reference"); - let passing = function.object.passing(); - let self_table = table_of(&self_ty); + let param = param_of(&function.object); let result = table_of("e!(#to)); let is_explicit = function.is_explicit; + let this = quote!(args[0].#cast::<#self_ty>()); + let to_ptr = quote!(to.#cast::<#to>()); + let body = if function.return_slot { + quote!(<#self_ty>::#method(#this, #to_ptr)) + } else { + quote!(#to_ptr.write(<#self_ty>::#method(#this))) + }; quote! { ::libcc2rs::overload::Candidate { - params: vec![::libcc2rs::overload::Param { table: #self_table, passing: #passing }], + params: vec![#param], is_explicit: #is_explicit, result: Some(#result), call: |to, args| { #[allow(unused_unsafe)] - unsafe { - <#self_ty>::#method( - <#object>::bind(args[0].#cast::<#self_ty>()), - to.#cast::<#to>(), - ) - } + unsafe { #body } }, } } @@ -280,21 +207,11 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { let impls = constructors.iter().map(|ctor| { let method = &ctor.method; - let arg_types: Vec<_> = ctor - .params - .iter() - .map(|param| { - let ty = ¶m.ty; - param - .kind - .reference("e!(#ty), is_unsafe) - .unwrap_or_else(|| quote!(#ty)) - }) - .collect(); - let names: Vec<_> = (0..arg_types.len()).map(|i| format_ident!("a{}", i)).collect(); + let types = &ctor.params; + let names: Vec<_> = (0..types.len()).map(|i| format_ident!("a{}", i)).collect(); quote! { - impl #impl_generics ::libcc2rs::#constructor<(#(#arg_types,)*)> for #self_ty #where_clause { - #fn_kw constructor(this: #ptr_ty, (#(#names,)*): (#(#arg_types,)*)) { + impl #impl_generics ::libcc2rs::#constructor<(#(#types,)*)> for #self_ty #where_clause { + #fn_kw constructor(this: #ptr_ty, (#(#names,)*): (#(#types,)*)) { #[allow(unused_unsafe)] unsafe { <#self_ty>::#method(this, #(#names),*) } } @@ -302,8 +219,10 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { } }); - let copy_ref = Kind::ConstRef.reference(&self_ty, is_unsafe).unwrap(); - let move_ref = Kind::RvalueRef.reference(&self_ty, is_unsafe).unwrap(); + let lvalue_ref = format_ident!("LvalueRef{}", suffix); + let rvalue_ref = format_ident!("RvalueRef{}", suffix); + let copy_ref = quote!(::libcc2rs::#lvalue_ref<::libcc2rs::Const<#self_ty>>); + let move_ref = quote!(::libcc2rs::#rvalue_ref<#self_ty>); let special = |trait_: &Ident, method: &str, reference: &TokenStream2, exists: bool| { if !exists { let message = format!("{} has no {}", name, method); diff --git a/libcc2rs/src/constructor.rs b/libcc2rs/src/constructor.rs index 5fed163772..2fcbe074f7 100644 --- a/libcc2rs/src/constructor.rs +++ b/libcc2rs/src/constructor.rs @@ -56,14 +56,11 @@ pub trait MoveConstructible: Constructor<(RvalueRef,)> + ByteRepr + Sized impl,)> + ByteRepr> MoveConstructible for T {} - pub trait TriviallyMoveConstructible: MoveConstructible { fn trivial_move(src: &mut Self) -> Self; } -pub trait CopyConstructible: - MoveConstructible + Constructor<(LvalueRef>,)> -{ +pub trait CopyConstructible: MoveConstructible + Constructor<(LvalueRef>,)> { fn copy_constructor(this: Ptr, src: LvalueRef>) { >,)>>::constructor(this, (src,)) } @@ -111,7 +108,6 @@ pub trait CopyConstructible: impl>,)>> CopyConstructible for T {} - pub trait TriviallyCopyConstructible: CopyConstructible { fn trivial_copy(src: &Self) -> Self; } @@ -184,9 +180,7 @@ pub trait DefaultConstructibleUnsafe: ConstructorUnsafe<()> + Sized { impl> DefaultConstructibleUnsafe for T {} -pub trait MoveConstructibleUnsafe: - ConstructorUnsafe<(RvalueRefUnsafe,)> + Sized -{ +pub trait MoveConstructibleUnsafe: ConstructorUnsafe<(RvalueRefUnsafe,)> + Sized { /// # Safety /// `this` is storage for an object, and `src` refers to a live object. unsafe fn move_constructor(this: *mut Self, src: RvalueRefUnsafe) { @@ -196,7 +190,6 @@ pub trait MoveConstructibleUnsafe: impl,)>> MoveConstructibleUnsafe for T {} - pub trait CopyConstructibleUnsafe: MoveConstructibleUnsafe + ConstructorUnsafe<(LvalueRefUnsafe>,)> { @@ -214,7 +207,6 @@ impl>,) { } - pub trait TriviallyMoveConstructibleUnsafe: MoveConstructibleUnsafe { /// # Safety /// `src` must point to a live value. @@ -821,7 +813,6 @@ impl Constructor<(RvalueRef,)> for FnPtr { } } - impl TriviallyMoveConstructible for FnPtr { fn trivial_move(src: &mut Self) -> Self { src.move_from() @@ -835,7 +826,6 @@ impl Constructor<(LvalueRef>,)> for FnPtr { } } - impl TriviallyCopyConstructible for FnPtr { fn trivial_copy(src: &Self) -> Self { src.copy_from() @@ -879,7 +869,6 @@ impl ConstructorUnsafe<(RvalueRefUnsafe,)> for FnPtr { } } - impl ConstructorUnsafe<(LvalueRefUnsafe>,)> for FnPtr { unsafe fn constructor(this: *mut Self, (src,): (crate::LvalueRefUnsafe>,)) { let src = src.as_const_ptr(); @@ -887,7 +876,6 @@ impl ConstructorUnsafe<(LvalueRefUnsafe>,)> for FnPtr { } } - impl TriviallyMoveConstructibleUnsafe for FnPtr { unsafe fn trivial_move(src: *mut Self) -> Self { unsafe { (*src).move_from() } @@ -959,7 +947,6 @@ impl Constructor<(RvalueRe } } - impl TriviallyMoveConstructible for Box<[T]> { @@ -968,20 +955,16 @@ impl TriviallyMov } } -impl - Constructor<(LvalueRef>,)> for Box<[T]> +impl Constructor<(LvalueRef>,)> + for Box<[T]> { fn constructor(this: Ptr, (src,): (LvalueRef>,)) { construct_elems(&this, &src.as_pointer(), |dst, src| { - >,)>>::constructor( - dst, - (LvalueRef::bind(src),), - ) + >,)>>::constructor(dst, (LvalueRef::bind(src),)) }); } } - impl TriviallyCopyConstructible for Box<[T]> { @@ -1047,9 +1030,8 @@ impl ConstructorUnsafe<(RvalueRefUns } } - -impl - ConstructorUnsafe<(LvalueRefUnsafe>,)> for [T; N] +impl ConstructorUnsafe<(LvalueRefUnsafe>,)> + for [T; N] { unsafe fn constructor(this: *mut Self, (src,): (crate::LvalueRefUnsafe>,)) { let src = src.as_const_ptr(); @@ -1065,7 +1047,6 @@ impl } } - impl TriviallyMoveConstructibleUnsafe for [T; N] { diff --git a/libcc2rs/src/fn_ptr_arg.rs b/libcc2rs/src/fn_ptr_arg.rs index 7295e67798..98dd6d47a1 100644 --- a/libcc2rs/src/fn_ptr_arg.rs +++ b/libcc2rs/src/fn_ptr_arg.rs @@ -104,6 +104,16 @@ impl FnPtrArg for Ptr { } } +impl FnPtrArg for crate::ParameterObject { + #[inline] + fn to_repr(self) -> ArgRepr { + self.as_pointer().to_repr() + } + fn from_repr(r: ArgRepr) -> Self { + Self::bind(Ptr::from_repr(r)) + } +} + impl FnPtrArg for AnyPtr { #[inline] fn to_repr(self) -> ArgRepr { @@ -129,6 +139,16 @@ impl FnPtrArg for Box<[VaArg]> { } } +impl FnPtrArg for crate::ParameterObjectUnsafe { + #[inline] + fn to_repr(self) -> ArgRepr { + self.as_ptr().to_repr() + } + fn from_repr(r: ArgRepr) -> Self { + Self::bind(<*mut T>::from_repr(r)) + } +} + impl FnPtrArg for *mut T { #[inline] fn to_repr(self) -> ArgRepr { diff --git a/libcc2rs/src/overload.rs b/libcc2rs/src/overload.rs index 33499465e8..972e48f1fb 100644 --- a/libcc2rs/src/overload.rs +++ b/libcc2rs/src/overload.rs @@ -13,7 +13,10 @@ use std::ffi::c_void; use crate::initialization::ZeroInitializationUnsafe as _; use crate::rc::Ptr; -use crate::reference::{Const, LvalueRef, LvalueRefUnsafe, RvalueRef, RvalueRefUnsafe}; +use crate::reference::{ + Const, LvalueRef, LvalueRefUnsafe, ParameterObject, ParameterObjectUnsafe, RvalueRef, + RvalueRefUnsafe, +}; use crate::reinterpret::ByteRepr; use crate::void::AnyPtr; @@ -203,6 +206,138 @@ impl AsArgUnsafe for RvalueRefUnsafe { } } +pub trait Parameter: Sized { + fn param() -> Param; + + fn bind(object: &AnyPtr) -> Self; +} + +impl Parameter for T { + fn param() -> Param { + Param { table: T::table, passing: Passing::Value } + } + + fn bind(object: &AnyPtr) -> Self { + object.downcast::().read() + } +} + +impl Parameter for ParameterObject { + fn param() -> Param { + Param { table: T::table, passing: Passing::Value } + } + + fn bind(object: &AnyPtr) -> Self { + ParameterObject::bind(object.downcast::()) + } +} + +impl Parameter for LvalueRef { + fn param() -> Param { + Param { table: T::table, passing: Passing::LvalueRef } + } + + fn bind(object: &AnyPtr) -> Self { + LvalueRef::bind(object.downcast::()) + } +} + +impl Parameter for LvalueRef> { + fn param() -> Param { + Param { table: T::table, passing: Passing::ConstLvalueRef } + } + + fn bind(object: &AnyPtr) -> Self { + LvalueRef::bind(object.downcast::()) + } +} + +impl Parameter for RvalueRef { + fn param() -> Param { + Param { table: T::table, passing: Passing::RvalueRef } + } + + fn bind(object: &AnyPtr) -> Self { + RvalueRef::bind(object.downcast::()) + } +} + +impl Parameter for RvalueRef> { + fn param() -> Param { + Param { table: T::table, passing: Passing::RvalueRef } + } + + fn bind(object: &AnyPtr) -> Self { + RvalueRef::bind(object.downcast::()) + } +} + +pub trait ParameterUnsafe: Sized { + fn param() -> Param<*mut c_void>; + + unsafe fn bind(object: *mut c_void) -> Self; +} + +impl ParameterUnsafe for T { + fn param() -> Param<*mut c_void> { + Param { table: T::table, passing: Passing::Value } + } + + unsafe fn bind(object: *mut c_void) -> Self { + unsafe { object.cast::().read() } + } +} + +impl ParameterUnsafe for ParameterObjectUnsafe { + fn param() -> Param<*mut c_void> { + Param { table: T::table, passing: Passing::Value } + } + + unsafe fn bind(object: *mut c_void) -> Self { + ParameterObjectUnsafe::bind(object.cast::()) + } +} + +impl ParameterUnsafe for LvalueRefUnsafe { + fn param() -> Param<*mut c_void> { + Param { table: T::table, passing: Passing::LvalueRef } + } + + unsafe fn bind(object: *mut c_void) -> Self { + LvalueRefUnsafe::bind(object.cast::()) + } +} + +impl ParameterUnsafe for LvalueRefUnsafe> { + fn param() -> Param<*mut c_void> { + Param { table: T::table, passing: Passing::ConstLvalueRef } + } + + unsafe fn bind(object: *mut c_void) -> Self { + LvalueRefUnsafe::bind(object.cast::()) + } +} + +impl ParameterUnsafe for RvalueRefUnsafe { + fn param() -> Param<*mut c_void> { + Param { table: T::table, passing: Passing::RvalueRef } + } + + unsafe fn bind(object: *mut c_void) -> Self { + RvalueRefUnsafe::bind(object.cast::()) + } +} + +impl ParameterUnsafe for RvalueRefUnsafe> { + fn param() -> Param<*mut c_void> { + Param { table: T::table, passing: Passing::RvalueRef } + } + + unsafe fn bind(object: *mut c_void) -> Self { + RvalueRefUnsafe::bind(object.cast::()) + } +} + // The arguments that a tuple of references is. pub trait ArgList { fn as_args(&self) -> Vec>; @@ -1159,7 +1294,9 @@ mod tests { fn conversions_of_equal_rank_are_ambiguous() { // long l = ratio; int -> long and double -> long rank the same. let ratio = object(Ratio(9, 2)); - convert_with(object(0_i64).as_pointer(), Arg::const_lvalue(ratio.as_pointer()), + convert_with( + object(0_i64).as_pointer(), + Arg::const_lvalue(ratio.as_pointer()), ); } @@ -1168,11 +1305,15 @@ mod tests { // Meters m = 2.0; the explicit Meters(double) is not a candidate, so // 2.0 converts to long for Meters(long). let meters = object(Meters(0)); - convert_with(meters.as_pointer(), Arg::rvalue(object(2.0_f64).as_pointer()), + convert_with( + meters.as_pointer(), + Arg::rvalue(object(2.0_f64).as_pointer()), ); assert_eq!(meters.borrow().0, 2); // Meters m(2.0); direct-initialization picks the exact match. - construct_with(meters.as_pointer(), &[Arg::rvalue(object(2.0_f64).as_pointer())], + construct_with( + meters.as_pointer(), + &[Arg::rvalue(object(2.0_f64).as_pointer())], ); assert_eq!(meters.borrow().0, 2000); } @@ -1181,9 +1322,7 @@ mod tests { fn arithmetic_copy_initialization_unsafe() { let mut from = 300_i32; let mut to = 0_u8; - unsafe { - convert_with_unsafe(&raw mut to, Arg::const_lvalue_unsafe(&raw const from)) - }; + unsafe { convert_with_unsafe(&raw mut to, Arg::const_lvalue_unsafe(&raw const from)) }; assert_eq!(to, 44); let mut pair = (0_i64, 0.0_f64); let mut source = (3_i64, 1.5_f64); diff --git a/libcc2rs/src/reference.rs b/libcc2rs/src/reference.rs index b79a041718..23a512293b 100644 --- a/libcc2rs/src/reference.rs +++ b/libcc2rs/src/reference.rs @@ -98,7 +98,6 @@ macro_rules! reference { } } - impl Constructor<(LvalueRef>,)> for $name where T::Object: ByteRepr, @@ -108,7 +107,6 @@ macro_rules! reference { } } - impl Destructible for $name where T::Object: ByteRepr, @@ -252,7 +250,6 @@ macro_rules! reference_unsafe { } } - impl ConstructorUnsafe<(LvalueRefUnsafe>,)> for $name { unsafe fn constructor(this: *mut Self, (src,): (LvalueRefUnsafe>,)) { let src = src.as_const_ptr(); @@ -260,7 +257,6 @@ macro_rules! reference_unsafe { } } - impl DestructibleUnsafe for $name { unsafe fn destroy(_this: *mut Self) {} } @@ -308,6 +304,43 @@ macro_rules! reference_unsafe { reference_unsafe!(LvalueRefUnsafe); reference_unsafe!(RvalueRefUnsafe); +pub struct ParameterObject(Ptr); + +impl ParameterObject { + #[inline] + pub fn bind(ptr: Ptr) -> Self { + Self(ptr) + } + + #[inline] + pub fn as_pointer(&self) -> Ptr { + self.0.clone() + } +} + +pub struct ParameterObjectUnsafe(*mut T); + +impl ParameterObjectUnsafe { + #[inline] + pub fn bind(ptr: *mut T) -> Self { + Self(ptr) + } + + #[inline] + pub fn as_ptr(&self) -> *mut T { + self.0 + } +} + +impl Clone for ParameterObjectUnsafe { + #[inline] + fn clone(&self) -> Self { + *self + } +} + +impl Copy for ParameterObjectUnsafe {} + impl CopyAssignableUnsafe for LvalueRefUnsafe { unsafe fn copy_assign(this: *mut Self, src: LvalueRefUnsafe>) -> *mut Self { let src = src.as_const_ptr(); From 856d3975f161cc38e9fb914dda3726c73505fb5d Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 4 Dec 2026 12:47:25 +0000 Subject: [PATCH 25/35] Remove leftover impl --- libcc2rs/src/reference.rs | 3 +-- rules/map/shim.rs | 5 ----- rules/pair/tgt_refcount.rs | 2 ++ rules/pair/tgt_unsafe.rs | 4 ---- rules/unique_ptr/shim.rs | 5 ++--- 5 files changed, 5 insertions(+), 14 deletions(-) diff --git a/libcc2rs/src/reference.rs b/libcc2rs/src/reference.rs index 23a512293b..bee5518c94 100644 --- a/libcc2rs/src/reference.rs +++ b/libcc2rs/src/reference.rs @@ -8,8 +8,7 @@ use crate::capture::{ Destructible, DestructibleUnsafe, TriviallyDestructible, TriviallyDestructibleUnsafe, }; use crate::constructor::{ - CopyAssignable, CopyAssignableUnsafe, CopyConstructible, CopyConstructibleUnsafe, - MoveAssignable, MoveAssignableUnsafe, MoveConstructible, MoveConstructibleUnsafe, Swappable, + CopyAssignable, CopyAssignableUnsafe, MoveAssignable, MoveAssignableUnsafe, Swappable, SwappableUnsafe, }; use crate::conversion::{Constructor, ConstructorUnsafe}; diff --git a/rules/map/shim.rs b/rules/map/shim.rs index ac8a51196d..e77027f1dc 100644 --- a/rules/map/shim.rs +++ b/rules/map/shim.rs @@ -472,11 +472,6 @@ impl CopyConstructibleUnsafe - for UnsafeMap -{ -} - impl CopyAssignableUnsafe for UnsafeMap { diff --git a/rules/pair/tgt_refcount.rs b/rules/pair/tgt_refcount.rs index 2c67a48900..6cb4847b9c 100644 --- a/rules/pair/tgt_refcount.rs +++ b/rules/pair/tgt_refcount.rs @@ -184,6 +184,8 @@ fn f34< Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), ) +} + fn f29(a0: Ptr<(Value, Value)>, a1: Ptr<(Value, Value)>) -> bool { LessThanComparable::less(a0, a1) } diff --git a/rules/pair/tgt_unsafe.rs b/rules/pair/tgt_unsafe.rs index 1e012d7eb6..89fe8de6c2 100644 --- a/rules/pair/tgt_unsafe.rs +++ b/rules/pair/tgt_unsafe.rs @@ -140,10 +140,6 @@ unsafe fn f33, T2: WeaklyEqualityComp WeaklyEqualityComparableWithUnsafe::equal(&a0.0, &a1.0) && WeaklyEqualityComparableWithUnsafe::equal(&a0.1, &a1.1) } -fn f33(a0: (T1, T2), a1: (T1, T2)) -> bool { - a0 == a1 -} - unsafe fn f34,)> + ZeroInitializationUnsafe + MoveConstructibleUnsafe, T2: ConstructibleFromUnsafe<(LvalueRefUnsafe,)> + ZeroInitializationUnsafe + MoveConstructibleUnsafe, T3, T4>(a0: &mut (T3, T4)) -> (T1, T2) { object_unsafe!(__first, T1, |__this| ConstructibleFromUnsafe::construct(__this, (LvalueRefUnsafe::::bind(&raw mut a0.0),))); object_unsafe!(__second, T2, |__this| ConstructibleFromUnsafe::construct(__this, (LvalueRefUnsafe::::bind(&raw mut a0.1),))); diff --git a/rules/unique_ptr/shim.rs b/rules/unique_ptr/shim.rs index 519d0b60c8..d6303b16d9 100644 --- a/rules/unique_ptr/shim.rs +++ b/rules/unique_ptr/shim.rs @@ -2,9 +2,8 @@ // Distributed under the MIT license that can be found in the LICENSE file. use crate::{ - ByteRepr, Constructor, ConstructorUnsafe, MoveAssignable, MoveAssignableUnsafe, - MoveConstructible, MoveConstructibleUnsafe, Ptr, RvalueRef, RvalueRefUnsafe, Swappable, - SwappableUnsafe, Value, + ByteRepr, Constructor, ConstructorUnsafe, MoveAssignable, MoveAssignableUnsafe, Ptr, + RvalueRef, RvalueRefUnsafe, Swappable, SwappableUnsafe, Value, }; pub trait CppArray {} From 46c532d0446dfbb495ecef933dbc3e3fd2aa2e7c Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 4 Dec 2026 12:51:26 +0000 Subject: [PATCH 26/35] Update expected output --- .../tests/ui/reference_binding.stderr | 132 +++++++++--------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/libcc2rs-macros/tests/ui/reference_binding.stderr b/libcc2rs-macros/tests/ui/reference_binding.stderr index 2199d97ce9..d01738ce64 100644 --- a/libcc2rs-macros/tests/ui/reference_binding.stderr +++ b/libcc2rs-macros/tests/ui/reference_binding.stderr @@ -1,110 +1,110 @@ -error[E0277]: the trait bound `LvalueRef: From>>` is not satisfied +error[E0277]: the trait bound `libcc2rs::LvalueRef: From>>` is not satisfied --> tests/ui/reference_binding.rs:7:7 | 7 | r.into() - | ^^^^ the trait `From>>` is not implemented for `LvalueRef` + | ^^^^ the trait `From>>` is not implemented for `libcc2rs::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>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>>` + `libcc2rs::LvalueRef>>` implements `From>` + `libcc2rs::LvalueRef>>` implements `From>>` + `libcc2rs::LvalueRef>>` implements `From>>` + = note: required for `libcc2rs::LvalueRef>` to implement `Into>` -error[E0277]: the trait bound `LvalueRef: From>>` is not satisfied +error[E0277]: the trait bound `libcc2rs::LvalueRef: From>>` is not satisfied --> tests/ui/reference_binding.rs:11:7 | 11 | r.into() - | ^^^^ the trait `From>>` is not implemented for `LvalueRef` + | ^^^^ the trait `From>>` is not implemented for `libcc2rs::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>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>>` + `libcc2rs::LvalueRef>>` implements `From>` + `libcc2rs::LvalueRef>>` implements `From>>` + `libcc2rs::LvalueRef>>` implements `From>>` + = note: required for `libcc2rs::LvalueRef>` to implement `Into>` -error[E0277]: the trait bound `LvalueRef>: From>>>` is not satisfied +error[E0277]: the trait bound `libcc2rs::LvalueRef>: From>>>` is not satisfied --> tests/ui/reference_binding.rs:15:7 | 15 | r.into() - | ^^^^ the trait `From>>>` is not implemented for `LvalueRef>` + | ^^^^ the trait `From>>>` is not implemented for `libcc2rs::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>>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>>` + `libcc2rs::LvalueRef>>` implements `From>` + `libcc2rs::LvalueRef>>` implements `From>>` + `libcc2rs::LvalueRef>>` implements `From>>` + = note: required for `libcc2rs::LvalueRef>>` to implement `Into>>` -error[E0277]: the trait bound `RvalueRef: From>>` is not satisfied +error[E0277]: the trait bound `libcc2rs::RvalueRef: From>>` is not satisfied --> tests/ui/reference_binding.rs:19:7 | 19 | r.into() - | ^^^^ the trait `From>>` is not implemented for `RvalueRef` + | ^^^^ the trait `From>>` is not implemented for `libcc2rs::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>` + `libcc2rs::RvalueRef>` implements `From>` + `libcc2rs::RvalueRef>` implements `From>` + `libcc2rs::RvalueRef>>` implements `From>` + `libcc2rs::RvalueRef>>` implements `From>>` + `libcc2rs::RvalueRef>>` implements `From>>` + = note: required for `libcc2rs::RvalueRef>` to implement `Into>` -error[E0277]: the trait bound `RvalueRef: From>` is not satisfied +error[E0277]: the trait bound `libcc2rs::RvalueRef: From>` is not satisfied --> tests/ui/reference_binding.rs:23:7 | 23 | r.into() - | ^^^^ the trait `From>` is not implemented for `RvalueRef` + | ^^^^ the trait `From>` is not implemented for `libcc2rs::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>` + `libcc2rs::RvalueRef>` implements `From>` + `libcc2rs::RvalueRef>` implements `From>` + `libcc2rs::RvalueRef>>` implements `From>` + `libcc2rs::RvalueRef>>` implements `From>>` + `libcc2rs::RvalueRef>>` implements `From>>` + = note: required for `libcc2rs::LvalueRef` to implement `Into>` -error[E0277]: the trait bound `LvalueRef: From>` is not satisfied +error[E0277]: the trait bound `libcc2rs::LvalueRef: From>` is not satisfied --> tests/ui/reference_binding.rs:27:7 | 27 | r.into() - | ^^^^ the trait `From>` is not implemented for `LvalueRef` + | ^^^^ the trait `From>` is not implemented for `libcc2rs::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>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>>` + `libcc2rs::LvalueRef>>` implements `From>` + `libcc2rs::LvalueRef>>` implements `From>>` + `libcc2rs::LvalueRef>>` implements `From>>` + = note: required for `libcc2rs::RvalueRef` to implement `Into>` -error[E0277]: the trait bound `LvalueRef>>: From>` is not satisfied +error[E0277]: the trait bound `libcc2rs::LvalueRef>>: From>` is not satisfied --> tests/ui/reference_binding.rs:33:7 | 33 | r.into() - | ^^^^ the trait `From>` is not implemented for `LvalueRef>>` + | ^^^^ the trait `From>` is not implemented for `libcc2rs::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>>>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>` + `libcc2rs::LvalueRef>` implements `From>>` + `libcc2rs::LvalueRef>>` implements `From>` + `libcc2rs::LvalueRef>>` implements `From>>` + `libcc2rs::LvalueRef>>` implements `From>>` + = note: required for `libcc2rs::RvalueRef` to implement `Into>>>` error[E0277]: the trait bound `LvalueRefUnsafe: From>>` is not satisfied --> tests/ui/reference_binding.rs:37:7 From 60437859aa9e25140f19f8892b87a3ba03bdc594 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 4 Dec 2026 12:52:32 +0000 Subject: [PATCH 27/35] Update tests --- .../out/refcount/defaulted_move_cross_tu.rs | 42 ++- .../out/unsafe/defaulted_move_cross_tu.rs | 34 +- .../refcount/out_of_line_methods_cross_tu.rs | 51 ++- .../unsafe/out_of_line_methods_cross_tu.rs | 51 ++- .../template_method_late_instantiation.rs | 3 +- .../template_method_late_instantiation.rs | 3 +- .../out/refcount/p14-class-in-two-files.rs | 38 +- .../out/unsafe/p14-class-in-two-files.rs | 32 +- .../p15-class-template-static-member.rs | 38 +- .../p15-class-template-static-member.rs | 32 +- .../out/refcount/p15-function-template.rs | 50 ++- .../out/unsafe/p15-function-template.rs | 42 ++- .../out/refcount/p15-inline-function.rs | 31 +- .../out/unsafe/p15-inline-function.rs | 26 +- .../out/refcount/p15-inline-variable.rs | 31 +- .../out/unsafe/p15-inline-variable.rs | 26 +- .../p16-default-argument-lambda-in-class.rs | 33 +- .../p16-default-argument-lambda-in-class.rs | 28 +- .../refcount/p16-lambda-in-inline-function.rs | 31 +- .../unsafe/p16-lambda-in-inline-function.rs | 26 +- .../basic.link/out/refcount/basic.link.rs | 15 +- .../basic/basic.link/out/unsafe/basic.link.rs | 15 +- .../out/refcount/basic.scope.block.rs | 39 +- .../out/refcount/basic.scope.class.rs | 6 +- .../out/refcount/basic.scope.param.rs | 2 +- .../out/refcount/basic.scope.pdecl.rs | 3 +- .../out/refcount/basic.scope.scope.rs | 9 +- .../out/unsafe/basic.scope.block.rs | 35 +- .../out/unsafe/basic.scope.class.rs | 6 +- .../out/unsafe/basic.scope.param.rs | 2 +- .../out/unsafe/basic.scope.pdecl.rs | 3 +- .../out/unsafe/basic.scope.scope.rs | 9 +- .../out/refcount/basic.start.term-p1-exit.rs | 4 +- .../out/refcount/basic.start.term.rs | 4 +- .../out/unsafe/basic.start.term-p1-exit.rs | 4 +- .../out/unsafe/basic.start.term.rs | 4 +- tests/std/basic/out/refcount/basic.def.odr.rs | 236 ++++++------ tests/std/basic/out/unsafe/basic.def.odr.rs | 233 +++++++----- .../out/refcount/class.spaceship.rs | 8 + .../out/unsafe/class.spaceship.rs | 8 + .../out/refcount/class.base.init.rs | 2 +- .../class.init/out/unsafe/class.base.init.rs | 2 +- .../out/refcount/class.conv.ctor.rs | 57 ++- .../class.conv/out/refcount/class.conv.fct.rs | 100 +---- .../class.conv/out/unsafe/class.conv.ctor.rs | 54 +-- .../class.conv/out/unsafe/class.conv.fct.rs | 101 +---- .../out/refcount/class.copy.ctor.rs | 32 +- .../class.ctor/out/unsafe/class.copy.ctor.rs | 21 +- .../out/refcount/class.mem.general.rs | 6 +- .../class.mem/out/unsafe/class.mem.general.rs | 6 +- .../out/refcount/concept.totallyordered.rs | 6 + .../out/unsafe/concept.totallyordered.rs | 6 + .../out/refcount/concept.constructible.rs | 17 +- .../out/refcount/concept.convertible.rs | 24 +- .../out/unsafe/concept.constructible.rs | 17 +- .../out/unsafe/concept.convertible.rs | 24 +- .../dcl.init/out/refcount/dcl.init.general.rs | 9 +- .../dcl.init/out/refcount/dcl.init.ref.rs | 2 + .../dcl.init/out/unsafe/dcl.init.general.rs | 9 +- .../dcl.init/out/unsafe/dcl.init.ref.rs | 2 + .../out/refcount/dcl.fct.default.rs | 8 +- .../dcl.meaning/out/unsafe/dcl.fct.default.rs | 8 +- .../out/refcount/expr.mptr.oper.rs | 31 +- .../out/unsafe/expr.mptr.oper.rs | 43 ++- .../expr.prim/out/refcount/expr.prim.this.rs | 4 +- .../expr.prim/out/unsafe/expr.prim.this.rs | 4 +- .../allocator.requirements.general.rs | 3 +- .../unsafe/allocator.requirements.general.rs | 3 +- .../out/refcount/utility.arg.requirements.rs | 10 + .../out/unsafe/utility.arg.requirements.rs | 10 + .../stmt.iter/out/refcount/stmt.while.rs | 45 +-- .../stmt.iter/out/unsafe/stmt.while.rs | 45 +-- .../stmt.select/out/refcount/stmt.if.rs | 28 +- .../stmt.select/out/refcount/stmt.switch.rs | 31 +- .../stmt.select/out/unsafe/stmt.if.rs | 24 +- .../stmt.select/out/unsafe/stmt.switch.rs | 27 +- .../support/cmp/out/refcount/cmp.concept.rs | 8 + .../std/support/cmp/out/unsafe/cmp.concept.rs | 8 + .../temp/temp.spec/out/refcount/temp.inst.rs | 12 +- .../temp/temp.spec/out/unsafe/temp.inst.rs | 12 +- .../pairs/out/refcount/pairs.pair.rs | 46 ++- .../utilities/pairs/out/unsafe/pairs.pair.rs | 37 +- .../utility/out/refcount/forward-helpers.rs | 126 +++---- .../utilities/utility/out/refcount/forward.rs | 21 +- .../utility/out/unsafe/forward-helpers.rs | 132 +++---- .../utilities/utility/out/unsafe/forward.rs | 21 +- tests/ub/out/refcount/ctor_ref_member.rs | 2 +- tests/ub/out/unsafe/ctor_ref_member.rs | 2 +- tests/unit/out/refcount/10_struct.rs | 5 +- tests/unit/out/refcount/any.rs | 2 +- .../out/refcount/array_of_noncopy_struct.rs | 3 +- .../out/refcount/assignment_single_eval.rs | 3 +- tests/unit/out/refcount/cast.rs | 3 +- tests/unit/out/refcount/class_templates.rs | 9 +- tests/unit/out/refcount/constexpr_function.rs | 17 +- tests/unit/out/refcount/constructor.rs | 11 +- .../unit/out/refcount/container_field_addr.rs | 3 +- .../conversion_operator_same_translation.rs | 85 +---- tests/unit/out/refcount/copy_assign.rs | 232 +++++++----- tests/unit/out/refcount/copy_ctor.rs | 253 +++++++------ .../unit/out/refcount/copy_move_defaulted.rs | 349 ++++++++++-------- tests/unit/out/refcount/copy_move_deleted.rs | 88 +++-- .../refcount/default_function_arguments.rs | 4 +- tests/unit/out/refcount/delete_array_order.rs | 2 +- tests/unit/out/refcount/destructor.rs | 14 +- tests/unit/out/refcount/destructor_params.rs | 25 +- .../out/refcount/destructor_temporaries.rs | 2 +- .../unit/out/refcount/enum_underlying_type.rs | 3 +- .../out/refcount/field_method_receiver.rs | 3 +- tests/unit/out/refcount/field_pointers.rs | 3 +- tests/unit/out/refcount/fn_ptr.rs | 12 +- tests/unit/out/refcount/fn_ptr_struct.rs | 42 ++- .../unit/out/refcount/for_body_destructor.rs | 19 +- .../refcount/foreach_disjoint_field_borrow.rs | 3 +- tests/unit/out/refcount/forward_basic.rs | 65 ++-- tests/unit/out/refcount/forward_decltype.rs | 35 +- tests/unit/out/refcount/forward_explicit.rs | 46 ++- tests/unit/out/refcount/forward_pack.rs | 51 +-- .../out/refcount/global_call_temporaries.rs | 2 + .../out/refcount/global_init_side_effect.rs | 2 +- .../out/refcount/global_non_const_init.rs | 8 +- tests/unit/out/refcount/huffman.rs | 3 +- tests/unit/out/refcount/implicit_autoref.rs | 3 +- .../refcount/in_class_field_initializer.rs | 8 +- tests/unit/out/refcount/init_list.rs | 6 +- .../out/refcount/inline_container_fields.rs | 51 ++- tests/unit/out/refcount/kruskal.rs | 6 +- tests/unit/out/refcount/lambda_as_field.rs | 35 +- .../out/refcount/lambda_capture_copy_ctor.rs | 85 +++-- .../unit/out/refcount/lambda_decltype_type.rs | 6 +- .../out/refcount/lambda_immediate_init.rs | 3 +- .../out/refcount/lambda_move_only_capture.rs | 42 +-- .../refcount/libc_struct_without_default.rs | 3 +- tests/unit/out/refcount/map.rs | 5 +- tests/unit/out/refcount/map_key_copy_ctor.rs | 33 +- tests/unit/out/refcount/map_key_identity.rs | 24 +- tests/unit/out/refcount/map_try_emplace.rs | 131 ++++--- .../out/refcount/map_try_emplace_lvalues.rs | 21 +- tests/unit/out/refcount/max.rs | 22 +- tests/unit/out/refcount/move_assign.rs | 61 ++- tests/unit/out/refcount/move_ctor.rs | 139 +++---- tests/unit/out/refcount/move_this.rs | 61 +-- .../refcount/operator_comparison_defaulted.rs | 16 + .../out/refcount/operator_comparison_free.rs | 4 + .../refcount/operator_comparison_member.rs | 2 + .../refcount/operator_comparison_nonbool.rs | 39 +- .../operator_comparison_noncopyable.rs | 21 +- tests/unit/out/refcount/operator_friend.rs | 14 + tests/unit/out/refcount/operator_less_than.rs | 2 + .../out/refcount/operator_other_member.rs | 93 +---- tests/unit/out/refcount/operator_three_way.rs | 2 + tests/unit/out/refcount/operator_traits.rs | 10 + tests/unit/out/refcount/pair.rs | 126 +++++-- .../refcount/pair_converting_construction.rs | 46 +-- tests/unit/out/refcount/push_emplace_back.rs | 15 +- tests/unit/out/refcount/rule_of_five.rs | 37 +- tests/unit/out/refcount/rule_of_three.rs | 30 +- .../unit/out/refcount/rvalue_rule_arg_move.rs | 25 +- tests/unit/out/refcount/rvalue_struct.rs | 2 +- .../refcount/self_referencing_initializer.rs | 3 +- tests/unit/out/refcount/size_t_ssize_t.rs | 119 ++++-- .../out/refcount/size_t_template_param.rs | 4 +- tests/unit/out/refcount/sort_no_copy.rs | 120 +++--- tests/unit/out/refcount/stdcopy.rs | 2 +- tests/unit/out/refcount/struct_ctor.rs | 7 +- .../unit/out/refcount/struct_default_ctor.rs | 9 +- .../refcount/structured_binding_copy_ctor.rs | 20 +- .../structured_binding_element_ctor.rs | 74 ++-- .../refcount/structured_binding_move_ctor.rs | 33 +- tests/unit/out/refcount/swap_map_no_copy.rs | 220 +++++------ .../unit/out/refcount/template_default_arg.rs | 12 +- .../unit/out/refcount/temporary_field_addr.rs | 6 +- .../out/refcount/temporary_field_ctor_arg.rs | 3 +- .../out/refcount/temporary_field_two_args.rs | 6 +- .../unit/out/refcount/typedef-anon-struct.rs | 3 +- tests/unit/out/refcount/unboxed_locals.rs | 4 + tests/unit/out/refcount/unboxed_records.rs | 3 +- tests/unit/out/refcount/unique_ptr.rs | 3 +- .../out/refcount/unique_ptr_const_deref.rs | 3 +- .../out/refcount/unique_ptr_field_reset.rs | 3 +- tests/unit/out/refcount/unique_ptr_nested.rs | 3 +- tests/unit/out/refcount/va_list_field.rs | 2 +- tests/unit/out/refcount/vector.rs | 5 +- .../vector_insert_conversion_chain.rs | 24 +- .../out/refcount/vector_iter_range_ctor.rs | 10 +- .../out/refcount/vector_subscript_direct.rs | 3 +- tests/unit/out/refcount/void_cast.rs | 6 +- tests/unit/out/unsafe/10_struct.rs | 5 +- tests/unit/out/unsafe/any.rs | 2 +- .../out/unsafe/array_of_noncopy_struct.rs | 3 +- .../unit/out/unsafe/assignment_single_eval.rs | 3 +- tests/unit/out/unsafe/cast.rs | 15 +- tests/unit/out/unsafe/class_templates.rs | 9 +- tests/unit/out/unsafe/clone_vs_move.rs | 6 + tests/unit/out/unsafe/constexpr_function.rs | 14 +- tests/unit/out/unsafe/constructor.rs | 11 +- tests/unit/out/unsafe/container_field_addr.rs | 3 +- .../conversion_operator_same_translation.rs | 71 +--- tests/unit/out/unsafe/copy_assign.rs | 225 ++++++----- tests/unit/out/unsafe/copy_ctor.rs | 234 ++++++------ tests/unit/out/unsafe/copy_move_defaulted.rs | 325 +++++++++------- tests/unit/out/unsafe/copy_move_deleted.rs | 80 ++-- .../out/unsafe/default_function_arguments.rs | 4 +- tests/unit/out/unsafe/delete_array_order.rs | 2 +- tests/unit/out/unsafe/destructor.rs | 14 +- tests/unit/out/unsafe/destructor_params.rs | 25 +- .../unit/out/unsafe/destructor_temporaries.rs | 2 +- tests/unit/out/unsafe/enum_underlying_type.rs | 3 +- .../unit/out/unsafe/field_method_receiver.rs | 3 +- tests/unit/out/unsafe/field_pointers.rs | 3 +- tests/unit/out/unsafe/fn_ptr.rs | 15 +- tests/unit/out/unsafe/fn_ptr_struct.rs | 38 +- tests/unit/out/unsafe/for_body_destructor.rs | 19 +- .../unsafe/foreach_disjoint_field_borrow.rs | 3 +- tests/unit/out/unsafe/forward_basic.rs | 63 ++-- tests/unit/out/unsafe/forward_decltype.rs | 35 +- tests/unit/out/unsafe/forward_explicit.rs | 40 +- tests/unit/out/unsafe/forward_pack.rs | 55 +-- .../out/unsafe/global_call_temporaries.rs | 2 + .../out/unsafe/global_init_side_effect.rs | 2 +- .../unit/out/unsafe/global_non_const_init.rs | 8 +- tests/unit/out/unsafe/huffman.rs | 3 +- tests/unit/out/unsafe/implicit_autoref.rs | 3 +- .../out/unsafe/in_class_field_initializer.rs | 8 +- tests/unit/out/unsafe/init_list.rs | 6 +- .../out/unsafe/inline_container_fields.rs | 38 +- tests/unit/out/unsafe/kruskal.rs | 6 +- tests/unit/out/unsafe/lambda_as_field.rs | 31 +- .../out/unsafe/lambda_capture_copy_ctor.rs | 83 ++--- tests/unit/out/unsafe/lambda_decltype_type.rs | 6 +- .../unit/out/unsafe/lambda_immediate_init.rs | 3 +- .../out/unsafe/lambda_move_only_capture.rs | 42 +-- .../out/unsafe/libc_struct_without_default.rs | 3 +- tests/unit/out/unsafe/map.rs | 5 +- tests/unit/out/unsafe/map_key_copy_ctor.rs | 33 +- tests/unit/out/unsafe/map_key_identity.rs | 22 +- tests/unit/out/unsafe/map_try_emplace.rs | 171 ++++----- .../out/unsafe/map_try_emplace_lvalues.rs | 21 +- tests/unit/out/unsafe/max.rs | 22 +- tests/unit/out/unsafe/move_assign.rs | 61 ++- tests/unit/out/unsafe/move_ctor.rs | 130 +++---- tests/unit/out/unsafe/move_this.rs | 61 ++- .../unsafe/operator_comparison_defaulted.rs | 16 + .../out/unsafe/operator_comparison_free.rs | 4 + .../out/unsafe/operator_comparison_member.rs | 2 + .../out/unsafe/operator_comparison_nonbool.rs | 39 +- .../unsafe/operator_comparison_noncopyable.rs | 19 +- tests/unit/out/unsafe/operator_friend.rs | 14 + tests/unit/out/unsafe/operator_less_than.rs | 2 + .../unit/out/unsafe/operator_other_member.rs | 69 +--- tests/unit/out/unsafe/operator_three_way.rs | 2 + tests/unit/out/unsafe/operator_traits.rs | 10 + tests/unit/out/unsafe/pair.rs | 101 ++++- .../unsafe/pair_converting_construction.rs | 44 +-- tests/unit/out/unsafe/push_emplace_back.rs | 15 +- tests/unit/out/unsafe/rule_of_five.rs | 41 +- tests/unit/out/unsafe/rule_of_three.rs | 30 +- tests/unit/out/unsafe/rvalue_rule_arg_move.rs | 21 +- tests/unit/out/unsafe/rvalue_struct.rs | 2 +- .../unsafe/self_referencing_initializer.rs | 3 +- tests/unit/out/unsafe/size_t_ssize_t.rs | 81 +++- .../unit/out/unsafe/size_t_template_param.rs | 4 +- tests/unit/out/unsafe/sort_no_copy.rs | 120 +++--- tests/unit/out/unsafe/stdcopy.rs | 2 +- tests/unit/out/unsafe/struct_ctor.rs | 7 +- tests/unit/out/unsafe/struct_default_ctor.rs | 9 +- .../unsafe/structured_binding_copy_ctor.rs | 20 +- .../unsafe/structured_binding_element_ctor.rs | 71 ++-- .../unsafe/structured_binding_move_ctor.rs | 33 +- tests/unit/out/unsafe/swap_map_no_copy.rs | 224 +++++------ tests/unit/out/unsafe/template_default_arg.rs | 12 +- tests/unit/out/unsafe/temporary_field_addr.rs | 6 +- .../out/unsafe/temporary_field_ctor_arg.rs | 3 +- .../out/unsafe/temporary_field_two_args.rs | 6 +- tests/unit/out/unsafe/this.rs | 8 +- tests/unit/out/unsafe/typedef-anon-struct.rs | 3 +- tests/unit/out/unsafe/unboxed_locals.rs | 4 + tests/unit/out/unsafe/unboxed_records.rs | 3 +- tests/unit/out/unsafe/unique_ptr.rs | 3 +- .../unit/out/unsafe/unique_ptr_const_deref.rs | 3 +- .../unit/out/unsafe/unique_ptr_field_reset.rs | 3 +- tests/unit/out/unsafe/unique_ptr_nested.rs | 3 +- tests/unit/out/unsafe/va_list_field.rs | 2 +- tests/unit/out/unsafe/vector.rs | 5 +- .../unsafe/vector_insert_conversion_chain.rs | 24 +- .../unit/out/unsafe/vector_iter_range_ctor.rs | 10 +- .../out/unsafe/vector_subscript_direct.rs | 3 +- tests/unit/out/unsafe/void_cast.rs | 6 +- 288 files changed, 4991 insertions(+), 4108 deletions(-) diff --git a/tests/multi-file/defaulted_move_cross_tu/out/refcount/defaulted_move_cross_tu.rs b/tests/multi-file/defaulted_move_cross_tu/out/refcount/defaulted_move_cross_tu.rs index 5211876784..bc4ba39164 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 @@ -7,17 +7,12 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - CppFrom, - DefaultInitializable, - Memberwise, - Swappable, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] #[memberwise(move_constructor, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1, i32)] #[byte_size(32)] pub struct S { #[offset(0)] @@ -29,7 +24,7 @@ pub struct S { pub n: Box<[i32]>, } impl S { - pub fn construct(this: Ptr, x: i32) { + pub fn constructor_1(this: Ptr, x: i32) { let x: Value = Rc::new(RefCell::new(x)); field!(this, v).write( (0..({ ((*x.borrow()) as usize) })) @@ -58,6 +53,9 @@ impl Default for S { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct T { #[offset(0)] @@ -68,9 +66,7 @@ impl T { pub fn size(this: Ptr) -> i32 { return (((*this.upgrade().deref()).v.len()) as i32); } -} -impl DefaultConstructible for T { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, v).write(Vec::new()); } } @@ -84,7 +80,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(s, S(2)); + object!(s, S::constructor_1(2)); assert!((({ sum_0(s.as_pointer(),) }) == 7)); assert!((({ shuffle_1(3,) }) == 10)); let t: Value = Rc::new(RefCell::new(T { @@ -93,16 +89,24 @@ fn main_0() -> i32 { assert!((({ T::size(t.as_pointer(),) }) == 2)); return 0; } +impl S {} +impl T {} pub fn shuffle_1(mut x: i32) -> i32 { - object!(a, S(x)); - object!(b, S, RvalueRef::bind(a.as_pointer())); + object!(a, S::constructor_1(x)); + object!(b, S, |b| ::move_constructor( + b.clone(), + RvalueRef::bind(a.as_pointer()) + )); assert!(({ (*a.borrow()).v.is_empty() })); - object!(c, S(1)); + object!(c, S::constructor_1(1)); 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, RvalueRef::bind(t.as_pointer())); - object!(w, T); + object!(u, T, |u| ::move_constructor( + u.clone(), + RvalueRef::bind(t.as_pointer()) + )); + object!(w, T::constructor_1()); assign!(w = RvalueRef(u)); assert!( ((({ T::size(t.as_pointer(),) }) == 0) && (({ T::size(u.as_pointer(),) }) == 0)) diff --git a/tests/multi-file/defaulted_move_cross_tu/out/unsafe/defaulted_move_cross_tu.rs b/tests/multi-file/defaulted_move_cross_tu/out/unsafe/defaulted_move_cross_tu.rs index 6c424bfeca..736e2c672a 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 @@ -10,20 +10,21 @@ use std::rc::Rc; #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, Default, )] #[memberwise(move_constructor, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1, i32)] pub struct S { pub v: Vec, pub n: [i32; 2], } impl S { - pub unsafe fn construct(this: *mut Self, mut x: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut x: i32) { (&raw mut (*this).v).write(Vec::from_fn((x as usize), |_| { copy_constructed_unsafe(&mut x) })); @@ -43,6 +44,9 @@ impl S { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct T { pub v: Vec, } @@ -50,9 +54,7 @@ impl T { pub unsafe fn size(this: *const Self) -> i32 { return (((*this).v.len()) as i32); } -} -impl DefaultConstructibleUnsafe for T { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write(Vec::new()); } } @@ -66,7 +68,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(s, S(2)); + object_unsafe!(s, S::constructor_1(2)); assert!(((unsafe { sum_0(&s,) }) == (7))); assert!(((unsafe { shuffle_1(3,) }) == (10))); let mut t: T = T { @@ -75,16 +77,24 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { T::size(&raw const t,) }) == (2))); return 0; } +impl S {} +impl T {} pub unsafe fn shuffle_1(mut x: i32) -> i32 { - object_unsafe!(a, S(x)); - object_unsafe!(b, S, RvalueRefUnsafe::bind(&mut a)); + object_unsafe!(a, S::constructor_1(x)); + object_unsafe!(b, S, |b| ::move_constructor( + b, + RvalueRefUnsafe::bind(&mut a) + )); assert!(a.v.is_empty()); - object_unsafe!(c, S(1)); + object_unsafe!(c, S::constructor_1(1)); assign_unsafe!(c = RvalueRefUnsafe(b)); assert!(b.v.is_empty()); let mut t: T = T { v: Vec::from([1]) }; - object_unsafe!(u, T, RvalueRefUnsafe::bind(&mut t)); - object_unsafe!(w, T); + object_unsafe!(u, T, |u| ::move_constructor( + u, + RvalueRefUnsafe::bind(&mut t) + )); + object_unsafe!(w, T::constructor_1()); assign_unsafe!(w = RvalueRefUnsafe(u)); assert!( (((unsafe { T::size(&raw const t,) }) == (0)) diff --git a/tests/multi-file/out_of_line_methods_cross_tu/out/refcount/out_of_line_methods_cross_tu.rs b/tests/multi-file/out_of_line_methods_cross_tu/out/refcount/out_of_line_methods_cross_tu.rs index 00e752b7cf..10e90ff48d 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 @@ -19,6 +19,8 @@ use std::rc::{Rc, Weak}; Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -29,7 +31,10 @@ impl S { return this.with(|__s| __s.v); } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default)] +#[derive( + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, +)] +#[conversions(copy, move)] #[byte_size(4)] pub struct M { #[offset(0)] @@ -50,7 +55,9 @@ pub trait Base { DefaultInitializable, Copyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct Derived { #[offset(8)] @@ -68,7 +75,9 @@ impl Derived {} TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -84,18 +93,18 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(s, S(1)); + object!(s, S::constructor_1(1)); 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())); + object!(m, M::constructor_1(2)); + object!(n, M::constructor_2(RvalueRef::bind(m.as_pointer()))); assert!(({ (*n.borrow()).v } == 2)); - object!(c, M, LvalueRef::bind(n.as_pointer())); + object!(c, M::constructor_3(LvalueRef::bind(n.as_pointer()))); assert!(({ (*c.borrow()).v } == 3)); assert!((({ move_m_1(5,) }) == 5)); - object!(derived, Derived(3)); + object!(derived, Derived::constructor_1(3)); let mut base: PtrDyn = (derived.as_pointer()).to_dyn::(|w| w); assert!((({ (*base.upgrade().deref_mut()).apply(5,) }) == 15)); let pair: Value = Rc::new(RefCell::new(Pair { @@ -107,29 +116,25 @@ fn main_0() -> i32 { return 0; } impl S { - pub fn construct(this: Ptr, mut x: i32) { + pub fn constructor_1(this: Ptr, mut x: i32) { field!(this, v).write(x); } } impl M { - pub fn construct(this: Ptr, mut x: i32) { + pub fn constructor_1(this: Ptr, mut x: i32) { field!(this, v).write(x); } -} -impl MoveConstructible for M { - fn move_constructor(this: Ptr, _a0: RvalueRef) { + pub fn constructor_2(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: LvalueRef>) { + pub fn constructor_3(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); field!(this, v).write((o.with(|__s| __s.v) + 1)); } } impl Derived { - pub fn construct(this: Ptr, mut factor: i32) { + pub fn constructor_1(this: Ptr, mut factor: i32) { field!(this, factor).write(factor); } } @@ -151,15 +156,27 @@ impl S { } } impl M {} +impl M {} +impl M {} pub fn move_m_1(mut x: i32) -> i32 { - object!(m, M(x)); - object!(n, M, RvalueRef::bind(m.as_pointer())); + object!(m, M::constructor_1(x)); + object!(n, M::constructor_2(RvalueRef::bind(m.as_pointer()))); return { (*n.borrow()).v }; } impl Derived {} pub fn pair_sum_2(mut p: Ptr) -> i32 { return ({ p.with(|__s| __s.first) } + { p.with(|__s| __s.second) }); } +impl Constructor<(LvalueRef>,)> for M { + fn constructor(this: Ptr, _: (LvalueRef>,)) { + unreachable!("M::copy_constructor is never defined") + } +} +impl Constructor<(RvalueRef,)> for M { + fn constructor(this: Ptr, _: (RvalueRef,)) { + unreachable!("M::move_constructor is never defined") + } +} impl Base for Derived { fn apply(&mut self, mut x: i32) -> i32 { return ({ self.factor } * x); 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 059056900a..51e50e971e 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 @@ -18,6 +18,8 @@ use std::rc::Rc; MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct S { pub v: i32, } @@ -27,7 +29,10 @@ impl S { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default)] +#[derive( + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, +)] +#[conversions(copy, move)] pub struct M { pub v: i32, } @@ -45,7 +50,9 @@ pub unsafe trait Base { DefaultInitializableUnsafe, CopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Derived { pub factor: i32, } @@ -60,7 +67,9 @@ impl Derived {} TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Pair { pub first: i32, pub second: i32, @@ -75,18 +84,18 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(s, S(1)); + object_unsafe!(s, S::constructor_1(1)); 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)); + object_unsafe!(m, M::constructor_1(2)); + object_unsafe!(n, M::constructor_2(RvalueRefUnsafe::bind(&mut m))); assert!(((n.v) == (2))); - object_unsafe!(c, M, LvalueRefUnsafe::bind(&n)); + object_unsafe!(c, M::constructor_3(LvalueRefUnsafe::bind(&n))); assert!(((c.v) == (3))); assert!(((unsafe { move_m_1(5,) }) == (5))); - object_unsafe!(derived, Derived(3)); + object_unsafe!(derived, Derived::constructor_1(3)); let mut base: *mut dyn Base = (&mut derived as *mut Derived); assert!(((unsafe { (*base).apply(5,) }) == (15))); let mut pair: Pair = Pair { @@ -98,29 +107,25 @@ unsafe fn main_0() -> i32 { return 0; } impl S { - pub unsafe fn construct(this: *mut Self, mut x: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut x: i32) { (&raw mut (*this).v).write(x); } } impl M { - pub unsafe fn construct(this: *mut Self, mut x: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut x: i32) { (&raw mut (*this).v).write(x); } -} -impl MoveConstructibleUnsafe for M { - unsafe fn move_constructor(this: *mut Self, _a0: RvalueRefUnsafe) { + pub unsafe fn constructor_2(this: *mut Self, _a0: RvalueRefUnsafe) { let _a0 = (_a0.as_ptr() as *mut M); (&raw mut (*this).v).write((*_a0).v); } -} -impl CopyConstructibleUnsafe for M { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_3(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const M); (&raw mut (*this).v).write((((*o).v) + (1))); } } impl Derived { - pub unsafe fn construct(this: *mut Self, mut factor: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut factor: i32) { (&raw mut (*this).factor).write(factor); } } @@ -140,15 +145,27 @@ impl S { } } impl M {} +impl M {} +impl M {} pub unsafe fn move_m_1(mut x: i32) -> i32 { - object_unsafe!(m, M(x)); - object_unsafe!(n, M, RvalueRefUnsafe::bind(&mut m)); + object_unsafe!(m, M::constructor_1(x)); + object_unsafe!(n, M::constructor_2(RvalueRefUnsafe::bind(&mut m))); return n.v; } impl Derived {} pub unsafe fn pair_sum_2(mut p: *const Pair) -> i32 { return (((*p).first) + ((*p).second)); } +impl ConstructorUnsafe<(LvalueRefUnsafe>,)> for M { + unsafe fn constructor(this: *mut Self, _: (LvalueRefUnsafe>,)) { + unreachable!("M::copy_constructor is never defined") + } +} +impl ConstructorUnsafe<(RvalueRefUnsafe,)> for M { + unsafe fn constructor(this: *mut Self, _: (RvalueRefUnsafe,)) { + unreachable!("M::move_constructor is never defined") + } +} unsafe impl Base for Derived { unsafe fn apply(&mut self, x: i32) -> i32 { return ((self.factor) * (x)); diff --git a/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs b/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs index 04d361f353..f23fc96578 100644 --- a/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs +++ b/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs @@ -17,7 +17,8 @@ use std::rc::{Rc, Weak}; TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct S_int_ { #[offset(0)] diff --git a/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs b/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs index 79890bde99..4623ba404f 100644 --- a/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs +++ b/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs @@ -16,7 +16,8 @@ use std::rc::Rc; TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct S_int_ { pub x: i32, } diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs index efa08bb605..66076fe075 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 @@ -29,6 +29,10 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -53,25 +57,21 @@ 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) { + pub fn constructor_1(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>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { @@ -91,6 +91,8 @@ impl Destructible for LifetimeTracked { Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -113,8 +115,9 @@ thread_local!( 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()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -134,7 +137,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct HasInlineMembers {} impl HasInlineMembers { @@ -145,8 +150,9 @@ impl HasInlineMembers { 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()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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 9d5edbf4fc..5949c7cd1a 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 @@ -20,6 +20,10 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct LifetimeTracked { pub uses: i32, } @@ -36,23 +40,19 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - 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(this: *mut Self) { + pub unsafe fn constructor_1(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(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + 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 DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { @@ -71,6 +71,8 @@ impl DestructibleUnsafe for LifetimeTracked { MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -95,8 +97,8 @@ pub static mut shared_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -115,7 +117,9 @@ pub static mut shared_5: std::cell::LazyCell = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct HasInlineMembers {} impl HasInlineMembers { pub unsafe fn instance() -> *mut LifetimeTracked { @@ -125,8 +129,8 @@ impl HasInlineMembers { static mut local_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { 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 f5e3f4f2bc..dc756f1f38 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 @@ -29,6 +29,10 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -53,25 +57,21 @@ 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) { + pub fn constructor_1(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>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { @@ -81,8 +81,9 @@ impl Destructible for LifetimeTracked { 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()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -102,14 +103,17 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct HasStaticMember_int_ {} 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()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -129,7 +133,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct HasStaticMember_long_ {} pub fn main() { 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 71eb9129c1..8752bcaa6e 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 @@ -20,6 +20,10 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct LifetimeTracked { pub uses: i32, } @@ -36,23 +40,19 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - 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(this: *mut Self) { + pub unsafe fn constructor_1(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(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + 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 DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { @@ -63,8 +63,8 @@ pub static mut member_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -83,14 +83,16 @@ pub static mut member_4: std::cell::LazyCell = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct HasStaticMember_int_ {} pub static mut member_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -109,7 +111,9 @@ pub static mut member_5: std::cell::LazyCell = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct HasStaticMember_long_ {} pub fn main() { unsafe { 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 42f9c61e41..fda33c6c38 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 @@ -29,6 +29,10 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -53,25 +57,21 @@ 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) { + pub fn constructor_1(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>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { @@ -91,6 +91,8 @@ impl Destructible for LifetimeTracked { Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -113,8 +115,9 @@ pub fn count_10() -> i32 { 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()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -129,8 +132,9 @@ thread_local!( 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()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -145,8 +149,9 @@ thread_local!( 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()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -196,7 +201,9 @@ fn main_0() -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct S_14 {} pub fn count_18() -> i32 { @@ -205,8 +212,9 @@ pub fn count_18() -> i32 { 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()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -238,7 +246,9 @@ pub fn b_count_local_15() -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct S_21 {} pub fn __cpp2rust_init_globals() { 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 e40f13ae30..fa90a916bb 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 @@ -20,6 +20,10 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct LifetimeTracked { pub uses: i32, } @@ -36,23 +40,19 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - 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(this: *mut Self) { + pub unsafe fn constructor_1(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(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + 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 DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { @@ -71,6 +71,8 @@ impl DestructibleUnsafe for LifetimeTracked { MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -93,8 +95,8 @@ pub unsafe fn count_10() -> i32 { static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -107,8 +109,8 @@ static mut n_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { static mut t_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -121,8 +123,8 @@ static mut n_9: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { static mut t_11: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -172,7 +174,9 @@ unsafe fn main_0() -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct S_14 {} pub unsafe fn count_18() -> i32 { return (*(*std::cell::LazyCell::force_mut(&mut *&raw mut n_20)).prefix_inc()); @@ -180,8 +184,8 @@ pub unsafe fn count_18() -> i32 { static mut t_19: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -210,7 +214,9 @@ pub unsafe fn b_count_local_15() -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct S_21 {} pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const ctorCount_0); 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 318037e78f..43e47bff8e 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 @@ -29,6 +29,10 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -53,25 +57,21 @@ 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) { + pub fn constructor_1(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>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { @@ -91,6 +91,8 @@ impl Destructible for LifetimeTracked { Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -107,8 +109,9 @@ pub fn instance_4() -> Ptr { 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()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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 afc2b03b66..ffd360f654 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 @@ -20,6 +20,10 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct LifetimeTracked { pub uses: i32, } @@ -36,23 +40,19 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - 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(this: *mut Self) { + pub unsafe fn constructor_1(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(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + 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 DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { @@ -71,6 +71,8 @@ impl DestructibleUnsafe for LifetimeTracked { MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -87,8 +89,8 @@ pub unsafe fn instance_4() -> *mut LifetimeTracked { static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { 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 cfbfc17551..3f1b9ff775 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 @@ -29,6 +29,10 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -53,25 +57,21 @@ 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) { + pub fn constructor_1(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>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { @@ -91,6 +91,8 @@ impl Destructible for LifetimeTracked { Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -113,8 +115,9 @@ thread_local!( 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()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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 890dc010a4..1066f6f244 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 @@ -20,6 +20,10 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct LifetimeTracked { pub uses: i32, } @@ -36,23 +40,19 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - 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(this: *mut Self) { + pub unsafe fn constructor_1(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(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + 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 DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { @@ -71,6 +71,8 @@ impl DestructibleUnsafe for LifetimeTracked { MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -95,8 +97,8 @@ pub static mut shared_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { 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 0b2af40577..ff87206292 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 @@ -29,6 +29,10 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -53,25 +57,21 @@ 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) { + pub fn constructor_1(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>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { @@ -91,6 +91,8 @@ impl Destructible for LifetimeTracked { Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -112,7 +114,9 @@ impl Destructible for AssertsDtorCountAtExit { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct X {} impl X { @@ -135,8 +139,9 @@ impl X { 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()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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 f0ccef5c69..347a2005ea 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 @@ -20,6 +20,10 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct LifetimeTracked { pub uses: i32, } @@ -36,23 +40,19 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - 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(this: *mut Self) { + pub unsafe fn constructor_1(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(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + 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 DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { @@ -71,6 +71,8 @@ impl DestructibleUnsafe for LifetimeTracked { MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -91,7 +93,9 @@ impl DestructibleUnsafe for AssertsDtorCountAtExit { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct X {} impl X { pub unsafe fn h(this: *mut Self, mut cond: bool, mut p: Option) { @@ -119,8 +123,8 @@ impl X { static mut local_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { 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 1881620397..877701844f 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 @@ -29,6 +29,10 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -53,25 +57,21 @@ 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) { + pub fn constructor_1(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>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { @@ -91,6 +91,8 @@ impl Destructible for LifetimeTracked { Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -118,8 +120,9 @@ pub fn f_4(mut cond: bool, mut p: FnPtr) { 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()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { 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 93cd43ae0b..b261789ee0 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 @@ -20,6 +20,10 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct LifetimeTracked { pub uses: i32, } @@ -36,23 +40,19 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - 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(this: *mut Self) { + pub unsafe fn constructor_1(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(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + 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 DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { @@ -71,6 +71,8 @@ impl DestructibleUnsafe for LifetimeTracked { MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -102,8 +104,8 @@ pub unsafe fn f_4(mut cond: bool, mut p: Option) { static mut local_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/basic.link/out/refcount/basic.link.rs b/tests/std/basic/basic.link/out/refcount/basic.link.rs index 13fa3dbf24..b8797e781b 100644 --- a/tests/std/basic/basic.link/out/refcount/basic.link.rs +++ b/tests/std/basic/basic.link/out/refcount/basic.link.rs @@ -86,7 +86,8 @@ pub fn bump_18() -> i32 { TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct Record_19 { #[offset(0)] @@ -250,7 +251,8 @@ pub fn test_55() { TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct Entry_52 { #[offset(0)] @@ -277,7 +279,8 @@ impl Default for Entry_52 { TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct Entry_54 { #[offset(0)] @@ -412,7 +415,8 @@ pub fn bump_64() -> i32 { TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(16)] pub struct Record_65 { #[offset(0)] @@ -534,7 +538,8 @@ pub fn key_in_b_56() -> i32 { TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct Entry_71 { #[offset(0)] diff --git a/tests/std/basic/basic.link/out/unsafe/basic.link.rs b/tests/std/basic/basic.link/out/unsafe/basic.link.rs index fb190851d0..ec942e8e60 100644 --- a/tests/std/basic/basic.link/out/unsafe/basic.link.rs +++ b/tests/std/basic/basic.link/out/unsafe/basic.link.rs @@ -77,7 +77,8 @@ pub unsafe fn bump_18() -> i32 { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Record_19 { pub id: i32, } @@ -224,7 +225,8 @@ pub unsafe fn test_55() { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Entry_52 { pub key: i32, } @@ -248,7 +250,8 @@ impl Default for Entry_52 { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Entry_54 { pub key: i32, pub value: i32, @@ -356,7 +359,8 @@ pub unsafe fn bump_64() -> i32 { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Record_65 { pub id: i64, pub extra: i32, @@ -457,7 +461,8 @@ pub unsafe fn key_in_b_56() -> i32 { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Entry_71 { pub key: i64, } 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 302b248269..48e633fe80 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 @@ -29,6 +29,10 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -53,25 +57,21 @@ 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) { + pub fn constructor_1(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>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { @@ -100,6 +100,9 @@ thread_local!( Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[conversion_function(to_bool, LvalueRef>, bool , explicit)] #[byte_size(4)] pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { #[offset(0)] @@ -177,13 +180,13 @@ pub fn test_8() { } pub fn test_9() { ({ LifetimeTracked::reset() }); - object!(scoped, LifetimeTracked); + object!(scoped, LifetimeTracked::constructor_1()); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); { let mut index: i32 = 0; 'loop_: while (index < 3) { 'for_body: { - object!(scoped, LifetimeTracked); + object!(scoped, LifetimeTracked::constructor_1()); } index.prefix_inc(); } @@ -191,13 +194,13 @@ pub fn test_9() { assert!((ctorCount_0.with(|rc| *rc.borrow()) == 4)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 3)); if (ctorCount_0.with(|rc| *rc.borrow()) == 4) { - object!(scoped, LifetimeTracked); + object!(scoped, LifetimeTracked::constructor_1()); } assert!((ctorCount_0.with(|rc| *rc.borrow()) == 5)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 4)); if (ctorCount_0.with(|rc| *rc.borrow()) == 0) { } else { - object!(scoped, LifetimeTracked); + object!(scoped, LifetimeTracked::constructor_1()); } assert!((ctorCount_0.with(|rc| *rc.borrow()) == 6)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 5)); @@ -226,9 +229,9 @@ pub fn test_10() { } pub fn test_11() { ({ LifetimeTracked::reset() }); - object!(tracked, LifetimeTracked); + object!(tracked, LifetimeTracked::constructor_1()); { - object!(tracked, LifetimeTracked); + object!(tracked, LifetimeTracked::constructor_1()); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2)); ({ LifetimeTracked::use_(tracked.as_pointer()) }); assert!(({ (*tracked.borrow()).uses } == 1)); diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs index 7ea0c42375..166826eb34 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs @@ -20,7 +20,8 @@ thread_local!( TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p1_member_hides_namespace_variable_HasBalance { #[offset(0)] @@ -79,7 +80,8 @@ thread_local!( TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { #[offset(0)] diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs index a03c662060..c20a931c54 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs @@ -20,7 +20,7 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { #[offset(0)] diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs index 8707ee60d1..2966ede095 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs @@ -88,7 +88,8 @@ pub const anon_4_above: anon_4 = 14; #[derive( Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct p9_func_declared_before_function_body_RecordsConstructorName { #[offset(0)] diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs index 38d79e1916..af1207012a 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs @@ -277,7 +277,8 @@ impl Default for anon_11 { TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct p3_2_const_qualified_member_is_distinct_HasConstOverload { #[offset(0)] @@ -350,7 +351,8 @@ thread_local!( TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { #[offset(0)] @@ -484,7 +486,8 @@ pub fn test_18() { TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { #[offset(0)] diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs index 5d170897e2..ff10deb2a4 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 @@ -20,6 +20,10 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct LifetimeTracked { pub uses: i32, } @@ -36,23 +40,19 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - 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(this: *mut Self) { + pub unsafe fn constructor_1(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(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + 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 DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { @@ -76,6 +76,9 @@ pub static mut dtorCount_6: std::cell::LazyCell = std::cell::LazyCell::new( MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[conversion_function(to_bool, LvalueRefUnsafe>, bool , explicit)] pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { pub value: i32, } @@ -149,13 +152,13 @@ pub unsafe fn test_8() { } pub unsafe fn test_9() { (unsafe { LifetimeTracked::reset() }); - object_unsafe!(scoped, LifetimeTracked); + object_unsafe!(scoped, LifetimeTracked::constructor_1()); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); { let mut index: i32 = 0; 'loop_: while ((index) < (3)) { 'for_body: { - object_unsafe!(scoped, LifetimeTracked); + object_unsafe!(scoped, LifetimeTracked::constructor_1()); } index.prefix_inc(); } @@ -163,13 +166,13 @@ pub unsafe fn test_9() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (4))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (3))); if ((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (4)) { - object_unsafe!(scoped, LifetimeTracked); + object_unsafe!(scoped, LifetimeTracked::constructor_1()); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (5))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (4))); if ((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0)) { } else { - object_unsafe!(scoped, LifetimeTracked); + object_unsafe!(scoped, LifetimeTracked::constructor_1()); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (6))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (5))); @@ -194,9 +197,9 @@ pub unsafe fn test_10() { } pub unsafe fn test_11() { (unsafe { LifetimeTracked::reset() }); - object_unsafe!(tracked, LifetimeTracked); + object_unsafe!(tracked, LifetimeTracked::constructor_1()); { - object_unsafe!(tracked, LifetimeTracked); + object_unsafe!(tracked, LifetimeTracked::constructor_1()); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2))); (unsafe { LifetimeTracked::use_(&raw const tracked) }); assert!(((tracked.uses) == (1))); diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs index 0a6c1b1f5e..d72be59edc 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs @@ -17,7 +17,8 @@ pub static mut balance_0: std::cell::LazyCell = std::cell::LazyCell::new(|| TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p1_member_hides_namespace_variable_HasBalance { pub balance: i32, } @@ -69,7 +70,8 @@ pub static mut initial_2: std::cell::LazyCell = std::cell::LazyCell::new(|| TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { pub held: i32, } diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs index be3ead73e1..d3424bc960 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs @@ -19,7 +19,7 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] pub struct p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { pub amount: i32, } diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs index 66394feebd..16559374a7 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs @@ -92,7 +92,8 @@ pub const anon_4_above: anon_4 = 14; TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p9_func_declared_before_function_body_RecordsConstructorName { pub name: *const libc::c_char, } diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs index 7094982faf..fd92c6ac36 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs @@ -226,7 +226,8 @@ impl Default for anon_11 { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p3_2_const_qualified_member_is_distinct_HasConstOverload { pub plain_calls: i32, pub const_calls: i32, @@ -290,7 +291,8 @@ pub static mut rvalue_calls_14: std::cell::LazyCell = TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { pub base: i32, } @@ -407,7 +409,8 @@ pub unsafe fn test_18() { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { pub plain_calls: i32, pub const_calls: i32, diff --git a/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs b/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs index d098b69ee8..17e7807749 100644 --- a/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs +++ b/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs @@ -20,8 +20,8 @@ use std::rc::{Rc, Weak}; )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy, move)] -#[constructor(constructor_1, explicit, value(i32))] +#[conversions(copy)] +#[constructor(constructor_1, explicit, i32)] #[byte_size(4)] pub struct Tracker { #[offset(0)] diff --git a/tests/std/basic/basic.start/out/refcount/basic.start.term.rs b/tests/std/basic/basic.start/out/refcount/basic.start.term.rs index 11d460d27e..b55aea53a8 100644 --- a/tests/std/basic/basic.start/out/refcount/basic.start.term.rs +++ b/tests/std/basic/basic.start/out/refcount/basic.start.term.rs @@ -20,8 +20,8 @@ use std::rc::{Rc, Weak}; )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy, move)] -#[constructor(constructor_1, explicit, value(i32))] +#[conversions(copy)] +#[constructor(constructor_1, explicit, i32)] #[byte_size(4)] pub struct Tracker { #[offset(0)] diff --git a/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs b/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs index 2df941538d..fa8939a70e 100644 --- a/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs +++ b/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs @@ -19,8 +19,8 @@ use std::rc::Rc; )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] -#[constructor(constructor_1, explicit, value(i32))] +#[conversions(copy)] +#[constructor(constructor_1, explicit, i32)] pub struct Tracker { pub tag: i32, } diff --git a/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs b/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs index 4ffc3e394c..47926e2396 100644 --- a/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs +++ b/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs @@ -19,8 +19,8 @@ use std::rc::Rc; )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] -#[constructor(constructor_1, explicit, value(i32))] +#[conversions(copy)] +#[constructor(constructor_1, explicit, i32)] pub struct Tracker { pub tag: i32, } diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index 2b4fecaf95..4aa16c4365 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -14,7 +14,6 @@ thread_local!( ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Memberwise, MoveConstructible, @@ -23,7 +22,10 @@ thread_local!( Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct HasConstexprCtor { #[offset(0)] @@ -33,12 +35,10 @@ impl HasConstexprCtor { pub fn reset() { copyCount_0.with(|rc| *rc.borrow_mut() = 0); } - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, m).write(v); } -} -impl CopyConstructible for HasConstexprCtor { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(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(); @@ -67,6 +67,10 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -91,25 +95,21 @@ 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) { + pub fn constructor_1(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>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { @@ -121,14 +121,14 @@ pub fn test_5() { let mut arr: [HasConstexprCtor; 2] = [ { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - HasConstexprCtor::construct(__v.as_pointer(), 3); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - HasConstexprCtor::construct(__v.as_pointer(), 4); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]; @@ -138,14 +138,14 @@ pub fn test_5() { return [ { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - HasConstexprCtor::construct(__v.as_pointer(), 3); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - HasConstexprCtor::construct(__v.as_pointer(), 4); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ][(1) as usize] @@ -158,15 +158,15 @@ pub fn test_5() { } pub fn test_6() { ({ HasConstexprCtor::reset() }); - object!(k, HasConstexprCtor(5)); + object!(k, HasConstexprCtor::constructor_1(5)); let f: Value i32>> = Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { { return { { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - HasConstexprCtor::construct(__v.as_pointer(), 5); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() } .m @@ -179,8 +179,8 @@ pub fn test_6() { } pub fn test_7() { ({ HasConstexprCtor::reset() }); - object!(k1, HasConstexprCtor(7)); - object!(k2, HasConstexprCtor(9)); + object!(k1, HasConstexprCtor::constructor_1(7)); + object!(k2, HasConstexprCtor::constructor_1(9)); let f: Value i32>> = Rc::new(RefCell::new(FnPtr:: i32>::new( |mut b: bool| -> i32 { { @@ -188,15 +188,15 @@ pub fn test_7() { (if b { { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - HasConstexprCtor::construct(__v.as_pointer(), 7); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } else { { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - HasConstexprCtor::construct(__v.as_pointer(), 9); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 9); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }) @@ -215,7 +215,7 @@ thread_local!( ); pub fn test_9() { ({ HasConstexprCtor::reset() }); - object!(k, HasConstexprCtor(5)); + object!(k, HasConstexprCtor::constructor_1(5)); let f: Value i32>> = Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { { @@ -224,8 +224,8 @@ pub fn test_9() { (*left_8.with(Value::clone).borrow_mut()).prefix_inc(); { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - HasConstexprCtor::construct(__v.as_pointer(), 5); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_1(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -256,7 +256,9 @@ pub trait p4_1_pure_virtual_without_definition_HasPureVirtual { DefaultInitializable, Copyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct p4_1_pure_virtual_without_definition_OverridesPureVirtual {} pub fn test_11() { @@ -271,8 +273,9 @@ pub fn test_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()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { @@ -295,14 +298,14 @@ pub fn test_13() { } pub fn test_14() { ({ LifetimeTracked::reset() }); - object!(t, LifetimeTracked); + object!(t, LifetimeTracked::constructor_1()); let r: Ptr = t.as_pointer(); let f: Value> = Rc::new(RefCell::new(lambda!( { 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())); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_2(__v.as_pointer(), LvalueRef::bind((r).clone())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -333,21 +336,21 @@ pub fn test_15() { } pub fn test_16() { ({ HasConstexprCtor::reset() }); - object!(k, HasConstexprCtor(5)); + object!(k, HasConstexprCtor::constructor_1(5)); let f: Value i32>> = Rc::new(RefCell::new(lambda!( { let k: Value = Rc::new(RefCell::new({ let __v: Value = - Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor( - __v.as_pointer(), - LvalueRef::bind(k.as_pointer()), - ); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + HasConstexprCtor::constructor_2(__v.as_pointer(), LvalueRef::bind(k.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, || -> i32 { - object!(c, HasConstexprCtor, LvalueRef::bind(k.as_pointer())); + object!( + c, + HasConstexprCtor::constructor_2(LvalueRef::bind(k.as_pointer())) + ); return { (*c.borrow()).m }; } ))); @@ -373,7 +376,6 @@ thread_local!( ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Memberwise, MoveConstructible, @@ -382,7 +384,10 @@ thread_local!( Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(8)] pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { #[offset(0)] @@ -391,13 +396,11 @@ pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { pub scratch: i32, } impl p5_2_mutable_subobject_is_odr_used_HasMutableMember { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(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( + pub fn constructor_2( this: Ptr, o: LvalueRef>, ) { @@ -408,16 +411,17 @@ impl CopyConstructible for p5_2_mutable_subobject_is_odr_used_HasMutableMember { } } pub fn test_19() { - object!(k, p5_2_mutable_subobject_is_odr_used_HasMutableMember(5)); + object!( + k, + p5_2_mutable_subobject_is_odr_used_HasMutableMember::constructor_1(5) + ); let f: Value i32>> = Rc::new(RefCell::new(lambda!( { let k: Value = Rc::new(RefCell::new({ let __v: Value = - Rc::new(RefCell::new( - ::zero_init(), - )); - CopyConstructible::copy_constructor( + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p5_2_mutable_subobject_is_odr_used_HasMutableMember::constructor_2( __v.as_pointer(), LvalueRef::bind(k.as_pointer()), ); @@ -434,6 +438,9 @@ pub fn test_19() { } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { #[offset(0)] @@ -445,10 +452,10 @@ pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { #[destroy] 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)); +impl p6_unevaluated_binding_needs_no_capture_HasTwoMembers { + pub fn constructor_1(this: Ptr) { + LifetimeTracked::constructor_1(field_ptr!(this, a)); + LifetimeTracked::constructor_1(field_ptr!(this, b)); } } pub fn test_20() { @@ -457,14 +464,14 @@ pub fn test_20() { p6_unevaluated_binding_needs_no_capture_HasTwoMembers { a: { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__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()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + LifetimeTracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, }, @@ -485,6 +492,9 @@ pub fn test_20() { } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct p7_member_access_captures_this_HasMemberUsedInLambda { #[offset(0)] @@ -507,16 +517,17 @@ impl p7_member_access_captures_this_HasMemberUsedInLambda { } ); } -} -impl DefaultConstructible for p7_member_access_captures_this_HasMemberUsedInLambda { - fn default_constructor(this: Ptr) { - DefaultConstructible::default_constructor(field_ptr!(this, x)); + pub fn constructor_1(this: Ptr) { + LifetimeTracked::constructor_1(field_ptr!(this, x)); field!(this, n).write(1); } } pub fn test_22() { ({ LifetimeTracked::reset() }); - object!(c, p7_member_access_captures_this_HasMemberUsedInLambda); + object!( + c, + p7_member_access_captures_this_HasMemberUsedInLambda::constructor_1() + ); let f: Value i32>> = Rc::new(RefCell::new( ({ p7_member_access_captures_this_HasMemberUsedInLambda::makeLambda(c.as_pointer()) }), )); @@ -530,6 +541,9 @@ pub fn test_22() { } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { #[offset(0)] @@ -545,17 +559,15 @@ impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { } }); } -} -impl DefaultConstructible for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { - fn default_constructor(this: Ptr) { - DefaultConstructible::default_constructor(field_ptr!(this, x)); + pub fn constructor_1(this: Ptr) { + LifetimeTracked::constructor_1(field_ptr!(this, x)); } } pub fn test_23() { ({ LifetimeTracked::reset() }); object!( c, - p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda + p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::constructor_1() ); let f: Value usize>> = Rc::new(RefCell::new( ({ p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::sizer(c.as_pointer()) }), @@ -599,10 +611,13 @@ thread_local!( Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] #[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) { +impl p9_destructor_not_potentially_invoked_HasUndefinedDestructor { + pub fn constructor_1(this: Ptr) { (*t_ctors_27.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -610,7 +625,7 @@ pub fn test_28() { let mut p: Ptr = { let __p = Ptr::alloc(::zero_init()); - DefaultConstructible::default_constructor(__p.clone()); + p9_destructor_not_potentially_invoked_HasUndefinedDestructor::constructor_1(__p.clone()); __p }; assert!(!((p).is_null())); @@ -631,13 +646,16 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { #[offset(0)] pub value: i32, } -impl DefaultConstructible for p9_unused_copy_constructor_HasUndefinedCopyCtor { - fn default_constructor(this: Ptr) { +impl p9_unused_copy_constructor_HasUndefinedCopyCtor { + pub fn constructor_1(this: Ptr) { field!(this, value).write(3); (*ctor_calls_29.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -646,10 +664,9 @@ impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { fn default() -> Self { { { - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p9_unused_copy_constructor_HasUndefinedCopyCtor::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -659,7 +676,10 @@ pub fn read_30(object: Ptr) -> return object.with(|__s| __s.value); } pub fn test_31() { - object!(a, p9_unused_copy_constructor_HasUndefinedCopyCtor); + object!( + a, + p9_unused_copy_constructor_HasUndefinedCopyCtor::constructor_1() + ); assert!((({ read_30(a.as_pointer(),) }) == 3)); assert!((ctor_calls_29.with(|rc| *rc.borrow()) == 1)); } @@ -677,11 +697,14 @@ thread_local!( Destructible, CopyConstructible, Movable, + Conversions, )] +#[conversions(copy)] +#[constructor(constructor_1)] #[byte_size(1)] pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} -impl DefaultConstructible for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - fn default_constructor(this: Ptr) { +impl p9_unused_implicit_assignment_HasUndefinedCopyAssignment { + pub fn constructor_1(this: Ptr) { (*m_ctors_32.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -690,10 +713,10 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { { { let __v: Value = - Rc::new(RefCell::new( - ::zero_init(), - )); - DefaultConstructible::default_constructor(__v.as_pointer()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p9_unused_implicit_assignment_HasUndefinedCopyAssignment::constructor_1( + __v.as_pointer(), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -710,26 +733,31 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { Destructible, Copyable, Default, + Conversions, )] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(1)] pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { #[offset(0)] #[byte_size(1)] 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)); +impl p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { + pub fn constructor_1(this: Ptr) { + p9_unused_implicit_assignment_HasUndefinedCopyAssignment::constructor_1(field_ptr!( + this, m + )); } } pub fn test_33() { object!( a, - p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment + p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment::constructor_1() ); object!( b, - p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment + p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment::constructor_1() ); assert!((m_ctors_32.with(|rc| *rc.borrow()) == 2)); } @@ -854,7 +882,9 @@ fn main_0() -> i32 { ({ test_51() }); return 0; } -#[derive(Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg)] +#[derive( + Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg, ZeroInitialization, Destructible, Conversions, +)] #[byte_size(1)] pub struct p13_pointer_to_incomplete_class_X; impl Destructible for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { @@ -864,8 +894,8 @@ impl Destructible for p9_destructor_not_potentially_invoked_HasUndefinedDestruct ) } } -impl CopyConstructible for p9_unused_copy_constructor_HasUndefinedCopyCtor { - fn copy_constructor(this: Ptr, _: LvalueRef>) { +impl Constructor<(LvalueRef>,)> for p9_unused_copy_constructor_HasUndefinedCopyCtor { + fn constructor(this: Ptr, _: (LvalueRef>,)) { unreachable!( "p9_unused_copy_constructor_HasUndefinedCopyCtor::copy_constructor 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 a923657ccf..96d07ff20f 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -11,7 +11,6 @@ pub static mut copyCount_0: std::cell::LazyCell = std::cell::LazyCell::new( #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, MoveConstructibleUnsafe, @@ -20,7 +19,10 @@ pub static mut copyCount_0: std::cell::LazyCell = std::cell::LazyCell::new( Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct HasConstexprCtor { pub m: i32, } @@ -28,12 +30,10 @@ impl HasConstexprCtor { pub unsafe fn reset() { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) = 0; } - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).m).write(v); } -} -impl CopyConstructibleUnsafe for HasConstexprCtor { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const HasConstexprCtor); (&raw mut (*this).m).write((*o).m); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)).prefix_inc(); @@ -53,6 +53,10 @@ pub static mut useCount_4: std::cell::LazyCell = std::cell::LazyCell::new(| SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct LifetimeTracked { pub uses: i32, } @@ -69,23 +73,19 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) }; } - 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(this: *mut Self) { + pub unsafe fn constructor_1(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(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)).prefix_inc(); } + 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 DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { @@ -96,13 +96,13 @@ pub unsafe fn test_5() { (unsafe { HasConstexprCtor::reset() }); let arr: [HasConstexprCtor; 2] = [ { - let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&raw mut __v, 3); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 3); __v }, { - let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&raw mut __v, 4); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 4); __v }, ]; @@ -110,13 +110,13 @@ pub unsafe fn test_5() { unsafe { return [ { - let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&raw mut __v, 3); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 3); __v }, { - let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&raw mut __v, 4); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 4); __v }, ][(1) as usize] @@ -129,12 +129,12 @@ pub unsafe fn test_5() { } pub unsafe fn test_6() { (unsafe { HasConstexprCtor::reset() }); - object_unsafe!(k, HasConstexprCtor(5)); + object_unsafe!(k, HasConstexprCtor::constructor_1(5)); let mut f: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { unsafe { return { - let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&raw mut __v, 5); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 5); __v } .m; @@ -146,20 +146,20 @@ pub unsafe fn test_6() { } pub unsafe fn test_7() { (unsafe { HasConstexprCtor::reset() }); - object_unsafe!(k1, HasConstexprCtor(7)); - object_unsafe!(k2, HasConstexprCtor(9)); + object_unsafe!(k1, HasConstexprCtor::constructor_1(7)); + object_unsafe!(k2, HasConstexprCtor::constructor_1(9)); let mut f: FnPtr i32> = FnPtr:: i32>::new(|mut b: bool| -> i32 { unsafe { return (if b { { - let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&raw mut __v, 7); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 7); __v } } else { { - let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&raw mut __v, 9); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 9); __v } }) @@ -174,14 +174,14 @@ pub unsafe fn test_7() { pub static mut left_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); pub unsafe fn test_9() { (unsafe { HasConstexprCtor::reset() }); - object_unsafe!(k, HasConstexprCtor(5)); + object_unsafe!(k, HasConstexprCtor::constructor_1(5)); let mut f: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { unsafe { return { (*std::cell::LazyCell::force_mut(&mut *&raw mut left_8)).prefix_inc(); { - let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&raw mut __v, 5); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_1(&raw mut __v, 5); __v } } @@ -209,7 +209,9 @@ pub unsafe trait p4_1_pure_virtual_without_definition_HasPureVirtual { DefaultInitializableUnsafe, CopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p4_1_pure_virtual_without_definition_OverridesPureVirtual {} pub unsafe fn test_11() { let mut d: p4_1_pure_virtual_without_definition_OverridesPureVirtual = @@ -223,8 +225,8 @@ pub static mut global_12: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -253,13 +255,13 @@ pub unsafe fn test_13() { } pub unsafe fn test_14() { (unsafe { LifetimeTracked::reset() }); - object_unsafe!(t, LifetimeTracked); + object_unsafe!(t, LifetimeTracked::constructor_1()); let r: *mut LifetimeTracked = &mut t; let mut f: FnPtr = lambda_unsafe!( { let r: LifetimeTracked = { - let mut __v: LifetimeTracked = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(r)); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(r)); __v }; }, @@ -291,17 +293,20 @@ pub unsafe fn test_15() { } pub unsafe fn test_16() { (unsafe { HasConstexprCtor::reset() }); - object_unsafe!(k, HasConstexprCtor(5)); + object_unsafe!(k, HasConstexprCtor::constructor_1(5)); let mut f: FnPtr i32> = lambda_unsafe!( { let k: HasConstexprCtor = { - let mut __v: HasConstexprCtor = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(&k)); + let mut __v: HasConstexprCtor = ZeroInitializationUnsafe::zero_init(); + HasConstexprCtor::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(&k)); __v }; }, || -> i32 { - object_unsafe!(c, HasConstexprCtor, LvalueRefUnsafe::bind(&k)); + object_unsafe!( + c, + HasConstexprCtor::constructor_2(LvalueRefUnsafe::bind(&k)) + ); return c.m; } ); @@ -323,7 +328,6 @@ pub static mut copies_18: std::cell::LazyCell = std::cell::LazyCell::new(|| #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, MoveConstructibleUnsafe, @@ -332,19 +336,20 @@ pub static mut copies_18: std::cell::LazyCell = std::cell::LazyCell::new(|| Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { pub value: i32, pub scratch: i32, } impl p5_2_mutable_subobject_is_odr_used_HasMutableMember { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(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( + pub unsafe fn constructor_2( this: *mut Self, o: LvalueRefUnsafe>, ) { @@ -355,13 +360,19 @@ impl CopyConstructibleUnsafe for p5_2_mutable_subobject_is_odr_used_HasMutableMe } } pub unsafe fn test_19() { - object_unsafe!(k, p5_2_mutable_subobject_is_odr_used_HasMutableMember(5)); + object_unsafe!( + k, + p5_2_mutable_subobject_is_odr_used_HasMutableMember::constructor_1(5) + ); let mut f: FnPtr i32> = lambda_unsafe!( { 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(&raw mut __v, LvalueRefUnsafe::bind(&k)); + ZeroInitializationUnsafe::zero_init(); + p5_2_mutable_subobject_is_odr_used_HasMutableMember::constructor_2( + &raw mut __v, + LvalueRefUnsafe::bind(&k), + ); __v }; }, @@ -378,16 +389,19 @@ pub unsafe fn test_19() { FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { #[destroy] pub a: LifetimeTracked, #[destroy] pub b: LifetimeTracked, } -impl DefaultConstructibleUnsafe for p6_unevaluated_binding_needs_no_capture_HasTwoMembers { - unsafe fn default_constructor(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).a); - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).b); +impl p6_unevaluated_binding_needs_no_capture_HasTwoMembers { + pub unsafe fn constructor_1(this: *mut Self) { + LifetimeTracked::constructor_1(&raw mut (*this).a); + LifetimeTracked::constructor_1(&raw mut (*this).b); } } pub unsafe fn test_20() { @@ -395,13 +409,13 @@ pub unsafe fn test_20() { let mut p: p6_unevaluated_binding_needs_no_capture_HasTwoMembers = p6_unevaluated_binding_needs_no_capture_HasTwoMembers { a: { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }, b: { - let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: LifetimeTracked = ZeroInitializationUnsafe::zero_init(); + LifetimeTracked::constructor_1(&raw mut __v); __v }, }; @@ -424,6 +438,9 @@ pub unsafe fn test_20() { FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p7_member_access_captures_this_HasMemberUsedInLambda { #[destroy] pub x: LifetimeTracked, @@ -441,16 +458,17 @@ impl p7_member_access_captures_this_HasMemberUsedInLambda { } ); } -} -impl DefaultConstructibleUnsafe for p7_member_access_captures_this_HasMemberUsedInLambda { - unsafe fn default_constructor(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).x); + pub unsafe fn constructor_1(this: *mut Self) { + LifetimeTracked::constructor_1(&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); + object_unsafe!( + c, + p7_member_access_captures_this_HasMemberUsedInLambda::constructor_1() + ); let mut f: FnPtr i32> = (unsafe { p7_member_access_captures_this_HasMemberUsedInLambda::makeLambda(&raw mut c) }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (0))); @@ -466,6 +484,9 @@ pub unsafe fn test_22() { FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { #[destroy] pub x: LifetimeTracked, @@ -478,17 +499,15 @@ impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { } }); } -} -impl DefaultConstructibleUnsafe for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { - unsafe fn default_constructor(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).x); + pub unsafe fn constructor_1(this: *mut Self) { + LifetimeTracked::constructor_1(&raw mut (*this).x); } } pub unsafe fn test_23() { (unsafe { LifetimeTracked::reset() }); object_unsafe!( c, - p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda + p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::constructor_1() ); let mut f: FnPtr usize> = (unsafe { p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::sizer(&raw mut c) }); @@ -529,9 +548,12 @@ pub static mut t_ctors_27: std::cell::LazyCell = std::cell::LazyCell::new(| MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] pub struct p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} -impl DefaultConstructibleUnsafe for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { - unsafe fn default_constructor(this: *mut Self) { +impl p9_destructor_not_potentially_invoked_HasUndefinedDestructor { + pub unsafe fn constructor_1(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut t_ctors_27)).prefix_inc(); } } @@ -540,7 +562,7 @@ pub unsafe fn test_28() { let __p: *mut p9_destructor_not_potentially_invoked_HasUndefinedDestructor = Box::leak( Box::new(::zero_init()), ); - DefaultConstructibleUnsafe::default_constructor(__p); + p9_destructor_not_potentially_invoked_HasUndefinedDestructor::constructor_1(__p); __p }; assert!(!((p).is_null())); @@ -559,11 +581,14 @@ pub static mut ctor_calls_29: std::cell::LazyCell = SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { pub value: i32, } -impl DefaultConstructibleUnsafe for p9_unused_copy_constructor_HasUndefinedCopyCtor { - unsafe fn default_constructor(this: *mut Self) { +impl p9_unused_copy_constructor_HasUndefinedCopyCtor { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).value).write(3); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctor_calls_29)).prefix_inc(); } @@ -573,8 +598,8 @@ impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { unsafe { { let mut __v: p9_unused_copy_constructor_HasUndefinedCopyCtor = - ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + ZeroInitializationUnsafe::zero_init(); + p9_unused_copy_constructor_HasUndefinedCopyCtor::constructor_1(&raw mut __v); __v } } @@ -584,7 +609,10 @@ pub unsafe fn read_30(object: *const p9_unused_copy_constructor_HasUndefinedCopy return (*object).value; } pub unsafe fn test_31() { - object_unsafe!(a, p9_unused_copy_constructor_HasUndefinedCopyCtor); + object_unsafe!( + a, + p9_unused_copy_constructor_HasUndefinedCopyCtor::constructor_1() + ); assert!(((unsafe { read_30(&a,) }) == (3))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctor_calls_29)) == (1))); } @@ -599,10 +627,13 @@ pub static mut m_ctors_32: std::cell::LazyCell = std::cell::LazyCell::new(| DestructibleUnsafe, CopyConstructibleUnsafe, MovableUnsafe, + ConversionsUnsafe, )] +#[conversions(copy)] +#[constructor(constructor_1)] pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} -impl DefaultConstructibleUnsafe for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - unsafe fn default_constructor(this: *mut Self) { +impl p9_unused_implicit_assignment_HasUndefinedCopyAssignment { + pub unsafe fn constructor_1(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut m_ctors_32)).prefix_inc(); } } @@ -611,8 +642,10 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { unsafe { { let mut __v: p9_unused_implicit_assignment_HasUndefinedCopyAssignment = - ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + ZeroInitializationUnsafe::zero_init(); + p9_unused_implicit_assignment_HasUndefinedCopyAssignment::constructor_1( + &raw mut __v, + ); __v } } @@ -628,25 +661,26 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { DestructibleUnsafe, CopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { pub m: p9_unused_implicit_assignment_HasUndefinedCopyAssignment, } -impl DefaultConstructibleUnsafe - for p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment -{ - unsafe fn default_constructor(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).m); +impl p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { + pub unsafe fn constructor_1(this: *mut Self) { + p9_unused_implicit_assignment_HasUndefinedCopyAssignment::constructor_1(&raw mut (*this).m); } } pub unsafe fn test_33() { object_unsafe!( a, - p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment + p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment::constructor_1() ); object_unsafe!( b, - p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment + p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment::constructor_1() ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut m_ctors_32)) == (2))); } @@ -759,7 +793,16 @@ unsafe fn main_0() -> i32 { (unsafe { test_51() }); return 0; } -#[derive(Clone, Copy, Default, VaArg, FnPtrArg)] +#[derive( + Clone, + Copy, + Default, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + ConversionsUnsafe, +)] pub struct p13_pointer_to_incomplete_class_X; impl DestructibleUnsafe for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { unsafe fn destroy(this: *mut Self) { @@ -768,8 +811,10 @@ impl DestructibleUnsafe for p9_destructor_not_potentially_invoked_HasUndefinedDe ) } } -impl CopyConstructibleUnsafe for p9_unused_copy_constructor_HasUndefinedCopyCtor { - unsafe fn copy_constructor(this: *mut Self, _: LvalueRefUnsafe>) { +impl ConstructorUnsafe<(LvalueRefUnsafe>,)> + for p9_unused_copy_constructor_HasUndefinedCopyCtor +{ + unsafe fn constructor(this: *mut Self, _: (LvalueRefUnsafe>,)) { unreachable!( "p9_unused_copy_constructor_HasUndefinedCopyCtor::copy_constructor is never defined" ) diff --git a/tests/std/class/class.compare/out/refcount/class.spaceship.rs b/tests/std/class/class.compare/out/refcount/class.spaceship.rs index 22e6dc46f0..222558373f 100644 --- a/tests/std/class/class.compare/out/refcount/class.spaceship.rs +++ b/tests/std/class/class.compare/out/refcount/class.spaceship.rs @@ -20,6 +20,8 @@ use std::rc::{Rc, Weak}; PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(12)] pub struct p1_memberwise_in_declaration_order_Date { #[offset(0)] @@ -129,6 +131,8 @@ pub fn test_0() { PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(16)] pub struct p2_common_comparison_category_Reading { #[offset(0)] @@ -217,6 +221,8 @@ pub fn test_1() { PartiallyOrderedWith, )] #[three_way(weak_ordering_from_user_operator_Fraction::operator_cmp)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(8)] pub struct weak_ordering_from_user_operator_Fraction { #[offset(0)] @@ -340,6 +346,8 @@ pub fn test_2() { PartiallyOrderedWith, )] #[three_way(partial_ordering_from_user_operator_Interval::operator_cmp)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(8)] pub struct partial_ordering_from_user_operator_Interval { #[offset(0)] diff --git a/tests/std/class/class.compare/out/unsafe/class.spaceship.rs b/tests/std/class/class.compare/out/unsafe/class.spaceship.rs index ce52094a51..38362beb7f 100644 --- a/tests/std/class/class.compare/out/unsafe/class.spaceship.rs +++ b/tests/std/class/class.compare/out/unsafe/class.spaceship.rs @@ -19,6 +19,8 @@ use std::rc::Rc; PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct p1_memberwise_in_declaration_order_Date { pub year: i32, pub month: i32, @@ -129,6 +131,8 @@ pub unsafe fn test_0() { PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct p2_common_comparison_category_Reading { pub sensor: i32, pub value: f64, @@ -205,6 +209,8 @@ pub unsafe fn test_1() { PartiallyOrderedWithUnsafe, )] #[three_way(weak_ordering_from_user_operator_Fraction::operator_cmp)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct weak_ordering_from_user_operator_Fraction { pub numerator: i32, pub denominator: i32, @@ -313,6 +319,8 @@ pub unsafe fn test_2() { PartiallyOrderedWithUnsafe, )] #[three_way(partial_ordering_from_user_operator_Interval::operator_cmp)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct partial_ordering_from_user_operator_Interval { pub low: i32, pub high: i32, diff --git a/tests/std/class/class.init/out/refcount/class.base.init.rs b/tests/std/class/class.init/out/refcount/class.base.init.rs index 6ed19b9af1..e684057e0f 100644 --- a/tests/std/class/class.init/out/refcount/class.base.init.rs +++ b/tests/std/class/class.init/out/refcount/class.base.init.rs @@ -20,7 +20,7 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] #[byte_size(8)] pub struct p13_3_member_reads_earlier_member_Pair { #[offset(0)] diff --git a/tests/std/class/class.init/out/unsafe/class.base.init.rs b/tests/std/class/class.init/out/unsafe/class.base.init.rs index 758ac01387..89a481c297 100644 --- a/tests/std/class/class.init/out/unsafe/class.base.init.rs +++ b/tests/std/class/class.init/out/unsafe/class.base.init.rs @@ -19,7 +19,7 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] pub struct p13_3_member_reads_earlier_member_Pair { pub first: i32, pub second: i32, diff --git a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs index 685f08d2dd..fcf9e4da77 100644 --- a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs +++ b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs @@ -29,11 +29,8 @@ impl p1_template_constructor_from_own_type_Probe { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] -#[constructor( - constructor_2_1, - lvalue_ref(p1_template_constructor_from_own_type_Probe) -)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2_1, LvalueRef)] #[byte_size(4)] pub struct p1_template_constructor_from_own_type_Probe { #[offset(0)] @@ -71,7 +68,7 @@ pub fn test_0() { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct p1_implicit_conversion_by_constructor_Meters { #[offset(0)] @@ -180,7 +177,7 @@ pub fn test_1() { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, explicit, value(i32))] +#[constructor(constructor_1, explicit, i32)] #[byte_size(4)] pub struct p2_explicit_constructor_Celsius { #[offset(0)] @@ -252,11 +249,6 @@ pub fn test_2() { Conversions, )] #[conversions(copy, move)] -#[conversion_function( - conversion_function_1, - p2_explicit_constructor_and_conversion_function_Target, - const_lvalue_ref -)] #[byte_size(4)] pub struct p2_explicit_constructor_and_conversion_function_Source { #[offset(0)] @@ -276,12 +268,8 @@ pub struct p2_explicit_constructor_and_conversion_function_Source { Conversions, )] #[conversions(copy, move)] -#[constructor( - constructor_1, - explicit, - const_lvalue_ref(p2_explicit_constructor_and_conversion_function_Source) -)] -#[constructor(constructor_2, value(i32))] +#[constructor(constructor_1, explicit, LvalueRef>)] +#[constructor(constructor_2, i32)] #[byte_size(4)] pub struct p2_explicit_constructor_and_conversion_function_Target { #[offset(0)] @@ -300,13 +288,18 @@ impl p2_explicit_constructor_and_conversion_function_Target { } } impl p2_explicit_constructor_and_conversion_function_Source { - pub fn conversion_function_1( - this: LvalueRef>, - __return: Ptr, - ) { - let this = this.as_pointer(); - p2_explicit_constructor_and_conversion_function_Target::constructor_2(__return.clone(), 2); - return; + pub fn to_p2_explicit_constructor_and_conversion_function_Target_1( + this: Ptr, + ) -> p2_explicit_constructor_and_conversion_function_Target { + return { + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p2_explicit_constructor_and_conversion_function_Target::constructor_2( + __v.as_pointer(), + 2, + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; } } pub fn test_3() { @@ -320,17 +313,9 @@ pub fn test_3() { )) ); assert!(({ (*direct.borrow()).from } == 1)); - let mut copied: p2_explicit_constructor_and_conversion_function_Target = { - let __v: Value = - Rc::new(RefCell::new(ZeroInitialization::zero_init())); - p2_explicit_constructor_and_conversion_function_Source::conversion_function_1( - >>::bind( - source.as_pointer(), - ), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; + let mut copied: p2_explicit_constructor_and_conversion_function_Target = ({ + p2_explicit_constructor_and_conversion_function_Source :: to_p2_explicit_constructor_and_conversion_function_Target ( source .as_pointer() , ) + }); assert!((copied.from == 2)); } pub fn main() { diff --git a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs index 69ff1eea77..4c4224906a 100644 --- a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs +++ b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs @@ -20,20 +20,15 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, i64, lvalue_ref)] +#[conversion_function(to_i64, LvalueRef, i64 )] #[byte_size(8)] pub struct p2_non_const_conversion_function_Gauge { #[offset(0)] pub value: i64, } impl p2_non_const_conversion_function_Gauge { - pub fn conversion_function_1( - this: LvalueRef, - __return: Ptr, - ) { - let this = this.as_pointer(); - __return.write(field!(this, value).with_mut(|__v| __v.prefix_inc().clone())); - return; + pub fn to_i64(this: Ptr) -> i64 { + return field!(this, value).with_mut(|__v| __v.prefix_inc().clone()); } } pub fn test_0() { @@ -41,14 +36,8 @@ pub fn test_0() { Rc::new(RefCell::new(p2_non_const_conversion_function_Gauge { value: 20_i64, })); - let mut converted: i64 = { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - p2_non_const_conversion_function_Gauge::conversion_function_1( - >::bind(gauge.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; + let mut converted: i64 = + ({ p2_non_const_conversion_function_Gauge::to_i64(gauge.as_pointer()) }); assert!((converted == 21_i64)); assert!(({ (*gauge.borrow()).value } == 21_i64)); } @@ -66,7 +55,7 @@ pub fn test_0() { Conversions, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, i32, const_lvalue_ref)] +#[conversion_function(to_i32, LvalueRef>, i32 )] #[byte_size(8)] pub struct p2_implicit_conversion_function_Ratio { #[offset(0)] @@ -75,13 +64,8 @@ pub struct p2_implicit_conversion_function_Ratio { pub denominator: i32, } impl p2_implicit_conversion_function_Ratio { - pub fn conversion_function_1( - this: LvalueRef>, - __return: Ptr, - ) { - let this = this.as_pointer(); - __return.write((this.with(|__s| __s.numerator) / this.with(|__s| __s.denominator))); - return; + pub fn to_i32(this: Ptr) -> i32 { + return (this.with(|__s| __s.numerator) / this.with(|__s| __s.denominator)); } } pub fn test_1() { @@ -90,14 +74,7 @@ pub fn test_1() { numerator: 9, denominator: 3, })); - let mut value: i32 = { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - p2_implicit_conversion_function_Ratio::conversion_function_1( - >>::bind(ratio.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; + let mut value: i32 = ({ p2_implicit_conversion_function_Ratio::to_i32(ratio.as_pointer()) }); assert!((value == 3)); let source: Value<( Value, @@ -159,20 +136,15 @@ pub fn test_1() { Conversions, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, bool, const_lvalue_ref, explicit)] +#[conversion_function(to_bool, LvalueRef>, bool , explicit)] #[byte_size(4)] pub struct p2_explicit_conversion_function_Flag { #[offset(0)] pub value: i32, } impl p2_explicit_conversion_function_Flag { - pub fn conversion_function_1( - this: LvalueRef>, - __return: Ptr, - ) { - let this = this.as_pointer(); - __return.write((this.with(|__s| __s.value) != 0)); - return; + pub fn to_bool(this: Ptr) -> bool { + return (this.with(|__s| __s.value) != 0); } } pub fn test_2() { @@ -184,32 +156,9 @@ pub fn test_2() { Rc::new(RefCell::new(p2_explicit_conversion_function_Flag { value: 0, })); - assert!({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - p2_explicit_conversion_function_Flag::conversion_function_1( - >>::bind(on.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }); - assert!( - !({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - p2_explicit_conversion_function_Flag::conversion_function_1( - >>::bind(off.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }) - ); - let mut cast: bool = { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - p2_explicit_conversion_function_Flag::conversion_function_1( - >>::bind(on.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; + assert!(({ p2_explicit_conversion_function_Flag::to_bool(on.as_pointer(),) })); + assert!(!({ p2_explicit_conversion_function_Flag::to_bool(off.as_pointer(),) })); + let mut cast: bool = ({ p2_explicit_conversion_function_Flag::to_bool(on.as_pointer()) }); assert!(cast); } #[derive( @@ -232,13 +181,8 @@ pub struct p1_conversion_function_to_reference_Holder { pub value: i32, } impl p1_conversion_function_to_reference_Holder { - pub fn conversion_function_1( - this: LvalueRef, - __return: Ptr>, - ) { - let this = this.as_pointer(); - __return.write(>::bind(field_ptr!(this, value))); - return; + pub fn to_pmuti32(this: Ptr) -> Ptr { + return field_ptr!(this, value); } } pub fn test_3() { @@ -246,14 +190,8 @@ pub fn test_3() { Rc::new(RefCell::new(p1_conversion_function_to_reference_Holder { value: 1, })); - let ref_: Ptr = { - let __v: Value> = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - p1_conversion_function_to_reference_Holder::conversion_function_1( - >::bind(holder.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - (Rc::try_unwrap(__v).ok().unwrap().into_inner()).as_pointer() - }; + let ref_: Ptr = + ({ p1_conversion_function_to_reference_Holder::to_pmuti32(holder.as_pointer()) }); ref_.write(5); assert!(({ (*holder.borrow()).value } == 5)); } diff --git a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs index 7eb340633f..28f418e643 100644 --- a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs +++ b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs @@ -28,11 +28,8 @@ impl p1_template_constructor_from_own_type_Probe { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] -#[constructor( - constructor_2_1, - lvalue_ref(p1_template_constructor_from_own_type_Probe) -)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2_1, LvalueRefUnsafe)] pub struct p1_template_constructor_from_own_type_Probe { pub value: i32, } @@ -67,7 +64,7 @@ pub unsafe fn test_0() { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] pub struct p1_implicit_conversion_by_constructor_Meters { pub value: i32, } @@ -140,7 +137,7 @@ pub unsafe fn test_1() { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, explicit, value(i32))] +#[constructor(constructor_1, explicit, i32)] pub struct p2_explicit_constructor_Celsius { pub degrees: i32, } @@ -192,11 +189,6 @@ pub unsafe fn test_2() { ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function( - conversion_function_1, - p2_explicit_constructor_and_conversion_function_Target, - const_lvalue_ref -)] pub struct p2_explicit_constructor_and_conversion_function_Source { pub value: i32, } @@ -213,12 +205,8 @@ pub struct p2_explicit_constructor_and_conversion_function_Source { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor( - constructor_1, - explicit, - const_lvalue_ref(p2_explicit_constructor_and_conversion_function_Source) -)] -#[constructor(constructor_2, value(i32))] +#[constructor(constructor_1, explicit, LvalueRefUnsafe>)] +#[constructor(constructor_2, i32)] pub struct p2_explicit_constructor_and_conversion_function_Target { pub from: i32, } @@ -235,13 +223,15 @@ impl p2_explicit_constructor_and_conversion_function_Target { } } impl p2_explicit_constructor_and_conversion_function_Source { - pub unsafe fn conversion_function_1( - this: LvalueRefUnsafe>, - __return: *mut p2_explicit_constructor_and_conversion_function_Target, - ) { - let this = this.as_ptr() as *mut p2_explicit_constructor_and_conversion_function_Source; - p2_explicit_constructor_and_conversion_function_Target::constructor_2(__return, 2); - return; + pub unsafe fn to_p2_explicit_constructor_and_conversion_function_Target_1( + this: *const Self, + ) -> p2_explicit_constructor_and_conversion_function_Target { + return { + let mut __v: p2_explicit_constructor_and_conversion_function_Target = + ZeroInitializationUnsafe::zero_init(); + p2_explicit_constructor_and_conversion_function_Target::constructor_2(&raw mut __v, 2); + __v + }; } } pub unsafe fn test_3() { @@ -254,17 +244,9 @@ pub unsafe fn test_3() { ) ); assert!(((direct.from) == (1))); - let mut copied: p2_explicit_constructor_and_conversion_function_Target = { - let mut __v: p2_explicit_constructor_and_conversion_function_Target = - ZeroInitializationUnsafe::zero_init(); - p2_explicit_constructor_and_conversion_function_Source::conversion_function_1( - >>::bind( - &mut source, - ), - &raw mut __v, - ); - __v - }; + let mut copied: p2_explicit_constructor_and_conversion_function_Target = (unsafe { + p2_explicit_constructor_and_conversion_function_Source :: to_p2_explicit_constructor_and_conversion_function_Target ( &raw const source , ) + }); assert!(((copied.from) == (2))); } pub fn main() { diff --git a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs index f42e0034cf..9aa229123c 100644 --- a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs +++ b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs @@ -19,31 +19,20 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, i64, lvalue_ref)] +#[conversion_function(to_i64, LvalueRefUnsafe, i64 )] pub struct p2_non_const_conversion_function_Gauge { pub value: i64, } impl p2_non_const_conversion_function_Gauge { - pub unsafe fn conversion_function_1( - this: LvalueRefUnsafe, - __return: *mut i64, - ) { - let this = this.as_ptr() as *mut p2_non_const_conversion_function_Gauge; - __return.write((*(*this).value.prefix_inc())); - return; + pub unsafe fn to_i64(this: *mut Self) -> i64 { + return (*(*this).value.prefix_inc()); } } pub unsafe fn test_0() { let mut gauge: p2_non_const_conversion_function_Gauge = p2_non_const_conversion_function_Gauge { value: 20_i64 }; - let mut converted: i64 = { - let mut __v: i64 = ZeroInitializationUnsafe::zero_init(); - p2_non_const_conversion_function_Gauge::conversion_function_1( - >::bind(&mut gauge), - &raw mut __v, - ); - __v - }; + let mut converted: i64 = + (unsafe { p2_non_const_conversion_function_Gauge::to_i64(&raw mut gauge) }); assert!(((converted) == (21_i64))); assert!(((gauge.value) == (21_i64))); } @@ -60,19 +49,14 @@ pub unsafe fn test_0() { ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, i32, const_lvalue_ref)] +#[conversion_function(to_i32, LvalueRefUnsafe>, i32 )] pub struct p2_implicit_conversion_function_Ratio { pub numerator: i32, pub denominator: i32, } impl p2_implicit_conversion_function_Ratio { - pub unsafe fn conversion_function_1( - this: LvalueRefUnsafe>, - __return: *mut i32, - ) { - let this = this.as_ptr() as *mut p2_implicit_conversion_function_Ratio; - __return.write((((*this).numerator) / ((*this).denominator))); - return; + pub unsafe fn to_i32(this: *const Self) -> i32 { + return (((*this).numerator) / ((*this).denominator)); } } pub unsafe fn test_1() { @@ -80,14 +64,8 @@ pub unsafe fn test_1() { numerator: 9, denominator: 3, }; - let mut value: i32 = { - let mut __v: i32 = ZeroInitializationUnsafe::zero_init(); - p2_implicit_conversion_function_Ratio::conversion_function_1( - >>::bind(&mut ratio), - &raw mut __v, - ); - __v - }; + let mut value: i32 = + (unsafe { p2_implicit_conversion_function_Ratio::to_i32(&raw const ratio) }); assert!(((value) == (3))); let mut source: ( p2_implicit_conversion_function_Ratio, @@ -135,18 +113,13 @@ pub unsafe fn test_1() { ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, bool, const_lvalue_ref, explicit)] +#[conversion_function(to_bool, LvalueRefUnsafe>, bool , explicit)] pub struct p2_explicit_conversion_function_Flag { pub value: i32, } impl p2_explicit_conversion_function_Flag { - pub unsafe fn conversion_function_1( - this: LvalueRefUnsafe>, - __return: *mut bool, - ) { - let this = this.as_ptr() as *mut p2_explicit_conversion_function_Flag; - __return.write((((*this).value) != (0))); - return; + pub unsafe fn to_bool(this: *const Self) -> bool { + return (((*this).value) != (0)); } } pub unsafe fn test_2() { @@ -154,32 +127,9 @@ pub unsafe fn test_2() { p2_explicit_conversion_function_Flag { value: 1 }; let mut off: p2_explicit_conversion_function_Flag = p2_explicit_conversion_function_Flag { value: 0 }; - assert!({ - let mut __v: bool = ZeroInitializationUnsafe::zero_init(); - p2_explicit_conversion_function_Flag::conversion_function_1( - >>::bind(&mut on), - &raw mut __v, - ); - __v - }); - assert!( - !({ - let mut __v: bool = ZeroInitializationUnsafe::zero_init(); - p2_explicit_conversion_function_Flag::conversion_function_1( - >>::bind(&mut off), - &raw mut __v, - ); - __v - }) - ); - let mut cast: bool = { - let mut __v: bool = ZeroInitializationUnsafe::zero_init(); - p2_explicit_conversion_function_Flag::conversion_function_1( - >>::bind(&mut on), - &raw mut __v, - ); - __v - }; + assert!((unsafe { p2_explicit_conversion_function_Flag::to_bool(&raw const on,) })); + assert!(!(unsafe { p2_explicit_conversion_function_Flag::to_bool(&raw const off,) })); + let mut cast: bool = (unsafe { p2_explicit_conversion_function_Flag::to_bool(&raw const on) }); assert!(cast); } #[repr(C)] @@ -199,26 +149,15 @@ pub struct p1_conversion_function_to_reference_Holder { pub value: i32, } impl p1_conversion_function_to_reference_Holder { - pub unsafe fn conversion_function_1( - this: LvalueRefUnsafe, - __return: *mut LvalueRefUnsafe, - ) { - let this = this.as_ptr() as *mut p1_conversion_function_to_reference_Holder; - __return.write(>::bind(&mut (*this).value)); - return; + pub unsafe fn to_pmuti32(this: *mut Self) -> *mut i32 { + return &mut (*this).value; } } pub unsafe fn test_3() { let mut holder: p1_conversion_function_to_reference_Holder = p1_conversion_function_to_reference_Holder { value: 1 }; - let ref_: *mut i32 = { - let mut __v: LvalueRefUnsafe = ZeroInitializationUnsafe::zero_init(); - p1_conversion_function_to_reference_Holder::conversion_function_1( - >::bind(&mut holder), - &raw mut __v, - ); - ((__v).as_ptr() as *mut i32) - }; + let ref_: *mut i32 = + (unsafe { p1_conversion_function_to_reference_Holder::to_pmuti32(&raw mut holder) }); (*ref_) = 5; assert!(((holder.value) == (5))); } 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 206493ac95..6f462ee343 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 @@ -7,24 +7,19 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - CppFrom, - DefaultInitializable, - Memberwise, - Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, )] #[memberwise(move_constructor)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1, i32)] #[byte_size(4)] 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) { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); } } @@ -34,20 +29,21 @@ pub fn pass_0( let object: Value = Rc::new(RefCell::new(object)); return { - let __v: Value = Rc::new(RefCell::new( - ::zero_init(), - )); - MoveConstructible::move_constructor(__v.as_pointer(), RvalueRef::bind(object.as_pointer())); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + ::move_constructor( + __v.as_pointer(), + RvalueRef::bind(object.as_pointer()), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } pub fn test_1() { let mut result: p11_defaulted_move_constructor_is_trivial_MoveOnly = ({ pass_0({ - let __v: Value = Rc::new( - RefCell::new(::zero_init()), - ); - p11_defaulted_move_constructor_is_trivial_MoveOnly::construct(__v.as_pointer(), 7); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p11_defaulted_move_constructor_is_trivial_MoveOnly::constructor_1(__v.as_pointer(), 7); 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 5a52ddae70..d59560429f 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 @@ -8,20 +8,17 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - CppFromUnsafe, - DefaultInitializableUnsafe, - MemberwiseUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, )] #[memberwise(move_constructor)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1, i32)] pub struct p11_defaulted_move_constructor_is_trivial_MoveOnly { pub value: i32, } impl p11_defaulted_move_constructor_is_trivial_MoveOnly { - pub unsafe fn construct(this: *mut Self, mut value: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); } } @@ -30,8 +27,8 @@ pub unsafe fn pass_0( ) -> p11_defaulted_move_constructor_is_trivial_MoveOnly { return { let mut __v: p11_defaulted_move_constructor_is_trivial_MoveOnly = - ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&raw mut __v, RvalueRefUnsafe::bind(&mut object)); + ZeroInitializationUnsafe::zero_init(); + ::move_constructor(&raw mut __v, RvalueRefUnsafe::bind(& mut object )) ; __v }; } @@ -39,8 +36,8 @@ pub unsafe fn test_1() { let mut result: p11_defaulted_move_constructor_is_trivial_MoveOnly = (unsafe { pass_0({ let mut __v: p11_defaulted_move_constructor_is_trivial_MoveOnly = - ::zero_init(); - p11_defaulted_move_constructor_is_trivial_MoveOnly::construct(&raw mut __v, 7); + ZeroInitializationUnsafe::zero_init(); + p11_defaulted_move_constructor_is_trivial_MoveOnly::constructor_1(&raw mut __v, 7); __v }) }); diff --git a/tests/std/class/class.mem/out/refcount/class.mem.general.rs b/tests/std/class/class.mem/out/refcount/class.mem.general.rs index 3198faf83f..977c66d683 100644 --- a/tests/std/class/class.mem/out/refcount/class.mem.general.rs +++ b/tests/std/class/class.mem/out/refcount/class.mem.general.rs @@ -25,7 +25,8 @@ pub const anon_2_reserve: anon_2 = 30; TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p7_1_function_body_names_later_member_HasLaterMembers { #[offset(0)] @@ -82,7 +83,8 @@ thread_local!( TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p7_2_default_argument_names_later_member_HasLaterStaticStep { #[offset(0)] diff --git a/tests/std/class/class.mem/out/unsafe/class.mem.general.rs b/tests/std/class/class.mem/out/unsafe/class.mem.general.rs index e23e8fbfd6..5eace88cf7 100644 --- a/tests/std/class/class.mem/out/unsafe/class.mem.general.rs +++ b/tests/std/class/class.mem/out/unsafe/class.mem.general.rs @@ -22,7 +22,8 @@ pub const anon_2_reserve: anon_2 = 30; TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p7_1_function_body_names_later_member_HasLaterMembers { pub stock: i32, } @@ -72,7 +73,8 @@ pub static mut step_5: std::cell::LazyCell = std::cell::LazyCell::new(|| un TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p7_2_default_argument_names_later_member_HasLaterStaticStep { pub total: i32, } diff --git a/tests/std/concepts/concepts.compare/out/refcount/concept.totallyordered.rs b/tests/std/concepts/concepts.compare/out/refcount/concept.totallyordered.rs index 50ccf0d955..ac877077aa 100644 --- a/tests/std/concepts/concepts.compare/out/refcount/concept.totallyordered.rs +++ b/tests/std/concepts/concepts.compare/out/refcount/concept.totallyordered.rs @@ -26,7 +26,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct p1_each_relation_is_an_operator_Score { #[offset(0)] @@ -70,6 +72,8 @@ pub fn test_3() { PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct p1_relations_from_three_way_Level { #[offset(0)] @@ -132,7 +136,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct p1_operator_preferred_over_three_way_Level { #[offset(0)] diff --git a/tests/std/concepts/concepts.compare/out/unsafe/concept.totallyordered.rs b/tests/std/concepts/concepts.compare/out/unsafe/concept.totallyordered.rs index 7f1cfd2937..4afcb87738 100644 --- a/tests/std/concepts/concepts.compare/out/unsafe/concept.totallyordered.rs +++ b/tests/std/concepts/concepts.compare/out/unsafe/concept.totallyordered.rs @@ -22,7 +22,9 @@ pub static mut greater_equal_calls_2: std::cell::LazyCell = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p1_each_relation_is_an_operator_Score { pub points: i32, } @@ -64,6 +66,8 @@ pub unsafe fn test_3() { PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct p1_relations_from_three_way_Level { pub depth: i32, } @@ -125,7 +129,9 @@ pub static mut greater_calls_5: std::cell::LazyCell = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p1_operator_preferred_over_three_way_Level { pub depth: i32, } diff --git a/tests/std/concepts/concepts.lang/out/refcount/concept.constructible.rs b/tests/std/concepts/concepts.lang/out/refcount/concept.constructible.rs index 5707c12803..3d6901ad4e 100644 --- a/tests/std/concepts/concepts.lang/out/refcount/concept.constructible.rs +++ b/tests/std/concepts/concepts.lang/out/refcount/concept.constructible.rs @@ -20,7 +20,7 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, explicit, value(i32))] +#[constructor(constructor_1, explicit, i32)] #[byte_size(4)] pub struct p1_constructible_from_Meters { #[offset(0)] @@ -45,7 +45,7 @@ impl p1_constructible_from_Meters { Conversions, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, i32, const_lvalue_ref, explicit)] +#[conversion_function(to_i32, LvalueRef>, i32 , explicit)] #[byte_size(8)] pub struct p1_constructible_from_Ratio { #[offset(0)] @@ -54,13 +54,8 @@ pub struct p1_constructible_from_Ratio { pub denominator: i32, } impl p1_constructible_from_Ratio { - pub fn conversion_function_1( - this: LvalueRef>, - __return: Ptr, - ) { - let this = this.as_pointer(); - __return.write((this.with(|__s| __s.numerator) / this.with(|__s| __s.denominator))); - return; + pub fn to_i32(this: Ptr) -> i32 { + return (this.with(|__s| __s.numerator) / this.with(|__s| __s.denominator)); } } const _: () = assert!(true, "std::constructible_from"); @@ -114,8 +109,8 @@ pub fn test_0() { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[constructor(constructor_1, value(i32))] -#[constructor(constructor_2, lvalue_ref(p1_copy_constructible_NonConstCopy))] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef)] #[byte_size(4)] pub struct p1_copy_constructible_NonConstCopy { #[offset(0)] diff --git a/tests/std/concepts/concepts.lang/out/refcount/concept.convertible.rs b/tests/std/concepts/concepts.lang/out/refcount/concept.convertible.rs index ef051c2080..08b66f6b78 100644 --- a/tests/std/concepts/concepts.lang/out/refcount/concept.convertible.rs +++ b/tests/std/concepts/concepts.lang/out/refcount/concept.convertible.rs @@ -20,7 +20,7 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct p1_convertible_to_Meters { #[offset(0)] @@ -45,7 +45,7 @@ impl p1_convertible_to_Meters { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, explicit, value(i32))] +#[constructor(constructor_1, explicit, i32)] #[byte_size(4)] pub struct p1_convertible_to_Celsius { #[offset(0)] @@ -70,7 +70,7 @@ impl p1_convertible_to_Celsius { Conversions, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, i32, const_lvalue_ref)] +#[conversion_function(to_i32, LvalueRef>, i32 )] #[byte_size(8)] pub struct p1_convertible_to_Ratio { #[offset(0)] @@ -79,13 +79,8 @@ pub struct p1_convertible_to_Ratio { pub denominator: i32, } impl p1_convertible_to_Ratio { - pub fn conversion_function_1( - this: LvalueRef>, - __return: Ptr, - ) { - let this = this.as_pointer(); - __return.write((this.with(|__s| __s.numerator) / this.with(|__s| __s.denominator))); - return; + pub fn to_i32(this: Ptr) -> i32 { + return (this.with(|__s| __s.numerator) / this.with(|__s| __s.denominator)); } } const _: () = assert!(true, "std::convertible_to"); @@ -108,14 +103,7 @@ pub fn test_1() { numerator: 8, denominator: 4, })); - let mut value: i32 = { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - p1_convertible_to_Ratio::conversion_function_1( - >>::bind(ratio.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; + let mut value: i32 = ({ p1_convertible_to_Ratio::to_i32(ratio.as_pointer()) }); assert!((value == 2)); let converted: Value<(Value, Value)> = Rc::new(RefCell::new( match (Rc::new(RefCell::new(( diff --git a/tests/std/concepts/concepts.lang/out/unsafe/concept.constructible.rs b/tests/std/concepts/concepts.lang/out/unsafe/concept.constructible.rs index 926eff24b5..8d18ed56ae 100644 --- a/tests/std/concepts/concepts.lang/out/unsafe/concept.constructible.rs +++ b/tests/std/concepts/concepts.lang/out/unsafe/concept.constructible.rs @@ -19,7 +19,7 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, explicit, value(i32))] +#[constructor(constructor_1, explicit, i32)] pub struct p1_constructible_from_Meters { pub value: i32, } @@ -41,19 +41,14 @@ impl p1_constructible_from_Meters { ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, i32, const_lvalue_ref, explicit)] +#[conversion_function(to_i32, LvalueRefUnsafe>, i32 , explicit)] pub struct p1_constructible_from_Ratio { pub numerator: i32, pub denominator: i32, } impl p1_constructible_from_Ratio { - pub unsafe fn conversion_function_1( - this: LvalueRefUnsafe>, - __return: *mut i32, - ) { - let this = this.as_ptr() as *mut p1_constructible_from_Ratio; - __return.write((((*this).numerator) / ((*this).denominator))); - return; + pub unsafe fn to_i32(this: *const Self) -> i32 { + return (((*this).numerator) / ((*this).denominator)); } } const _: () = assert!(true, "std::constructible_from"); @@ -98,8 +93,8 @@ pub unsafe fn test_0() { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[constructor(constructor_1, value(i32))] -#[constructor(constructor_2, lvalue_ref(p1_copy_constructible_NonConstCopy))] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe)] pub struct p1_copy_constructible_NonConstCopy { pub value: i32, } diff --git a/tests/std/concepts/concepts.lang/out/unsafe/concept.convertible.rs b/tests/std/concepts/concepts.lang/out/unsafe/concept.convertible.rs index 67af7563d0..3a19952892 100644 --- a/tests/std/concepts/concepts.lang/out/unsafe/concept.convertible.rs +++ b/tests/std/concepts/concepts.lang/out/unsafe/concept.convertible.rs @@ -19,7 +19,7 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] pub struct p1_convertible_to_Meters { pub value: i32, } @@ -41,7 +41,7 @@ impl p1_convertible_to_Meters { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, explicit, value(i32))] +#[constructor(constructor_1, explicit, i32)] pub struct p1_convertible_to_Celsius { pub degrees: i32, } @@ -63,19 +63,14 @@ impl p1_convertible_to_Celsius { ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, i32, const_lvalue_ref)] +#[conversion_function(to_i32, LvalueRefUnsafe>, i32 )] pub struct p1_convertible_to_Ratio { pub numerator: i32, pub denominator: i32, } impl p1_convertible_to_Ratio { - pub unsafe fn conversion_function_1( - this: LvalueRefUnsafe>, - __return: *mut i32, - ) { - let this = this.as_ptr() as *mut p1_convertible_to_Ratio; - __return.write((((*this).numerator) / ((*this).denominator))); - return; + pub unsafe fn to_i32(this: *const Self) -> i32 { + return (((*this).numerator) / ((*this).denominator)); } } const _: () = assert!(true, "std::convertible_to"); @@ -97,14 +92,7 @@ pub unsafe fn test_1() { numerator: 8, denominator: 4, }; - let mut value: i32 = { - let mut __v: i32 = ZeroInitializationUnsafe::zero_init(); - p1_convertible_to_Ratio::conversion_function_1( - >>::bind(&mut ratio), - &raw mut __v, - ); - __v - }; + let mut value: i32 = (unsafe { p1_convertible_to_Ratio::to_i32(&raw const ratio) }); assert!(((value) == (2))); let mut converted: (p1_convertible_to_Meters, i32) = match ((&mut ( 3, diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs index 52f557abc1..8cf6d61f92 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs @@ -414,7 +414,8 @@ pub fn test_21() { TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { #[offset(0)] @@ -449,7 +450,8 @@ impl Default for p9_1_2_zero_then_default_initialized_WithDefaultMember { TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { #[offset(0)] @@ -486,7 +488,8 @@ impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { Default, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { #[offset(0)] 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 index a1876bad6b..ab9b8c59fa 100644 --- 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 @@ -25,7 +25,9 @@ pub fn test_0() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct p5_3_reference_to_rvalue_Counter { #[offset(0)] diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs index 678537335d..406fec871f 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs @@ -346,7 +346,8 @@ pub unsafe fn test_21() { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { pub zeroed: i32, pub five: i32, @@ -377,7 +378,8 @@ impl Default for p9_1_2_zero_then_default_initialized_WithDefaultMember { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { pub untouched: i32, } @@ -409,7 +411,8 @@ impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { Default, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { pub number: i32, pub member: p9_1_2_zero_then_default_initialized_LeavesMemberAlone, 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 index 6ebabc94ac..fbdd2cce8f 100644 --- 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 @@ -24,7 +24,9 @@ pub unsafe fn test_0() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p5_3_reference_to_rvalue_Counter { pub count: i32, } diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs index 2fa391acab..bb0cbf37f5 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs @@ -65,7 +65,8 @@ thread_local!( TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p9_static_member_hides_namespace_variable_HasStaticStep { #[offset(0)] @@ -137,7 +138,7 @@ pub fn combine_14(mut first: i32, mut second: i32) -> i32 { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct p9_evaluated_each_time_called_Widget { #[offset(0)] @@ -189,7 +190,8 @@ pub const anon_16_kBonus: anon_16 = 5; TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p9_evaluated_each_time_called_Account { #[offset(0)] diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs index 3e308a9e13..dd4664c7a7 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs @@ -63,7 +63,8 @@ pub static mut step_10: std::cell::LazyCell = std::cell::LazyCell::new(|| u TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p9_static_member_hides_namespace_variable_HasStaticStep { pub total: i32, } @@ -129,7 +130,7 @@ pub unsafe fn combine_14(mut first: i32, mut second: i32) -> i32 { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] pub struct p9_evaluated_each_time_called_Widget { pub id: i32, } @@ -176,7 +177,8 @@ pub const anon_16_kBonus: anon_16 = 5; TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p9_evaluated_each_time_called_Account { pub balance: i32, } diff --git a/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs b/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs index a1888f1daf..2856256e52 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 @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct p3_arrow_star_HasTwoInts { #[offset(0)] @@ -49,7 +51,9 @@ pub fn test_0() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct p4_object_expression_sequenced_first_HasValue { #[offset(0)] @@ -102,7 +106,9 @@ pub fn test_7() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct p6_data_member_of_lvalue_is_lvalue_HasTwoInts { #[offset(0)] @@ -139,20 +145,22 @@ thread_local!( TriviallyDefaultConstructible, Destructible, Default, + Conversions, )] +#[conversions(copy, move)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(1)] pub struct p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} -impl CopyConstructible for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { - fn copy_constructor( +impl p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { + pub fn constructor_2( this: 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( + pub fn constructor_3( this: Ptr, _a0: RvalueRef, ) { @@ -171,12 +179,15 @@ impl MoveConstructible for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMov Default, )] #[memberwise(copy_constructor, move_constructor)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(1)] pub struct p6_data_member_of_rvalue_is_xvalue_HoldsCounted { #[offset(0)] #[byte_size(1)] pub member: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, } +impl p6_data_member_of_rvalue_is_xvalue_HoldsCounted {} pub fn test_11() { let mut pm: isize = (offset_of_field!(p6_data_member_of_rvalue_is_xvalue_HoldsCounted, member) as isize); @@ -185,21 +196,19 @@ pub fn test_11() { )); object!( from_lvalue, - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, - LvalueRef::bind( + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::constructor_2(LvalueRef::bind( (holder.as_pointer()) .member::(pm) - ) + )) ); assert!((copyCount_9.with(|rc| *rc.borrow()) == 1)); assert!((moveCount_10.with(|rc| *rc.borrow()) == 0)); object!( from_xvalue, - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, - RvalueRef::bind( + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::constructor_3(RvalueRef::bind( (holder.as_pointer()) .member::(pm) - ) + )) ); assert!((copyCount_9.with(|rc| *rc.borrow()) == 1)); assert!((moveCount_10.with(|rc| *rc.borrow()) == 1)); 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 1811b24dc4..a39ed60c79 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 @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p3_arrow_star_HasTwoInts { pub first: i32, pub second: i32, @@ -49,7 +51,9 @@ pub unsafe fn test_0() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p4_object_expression_sequenced_first_HasValue { pub value: i32, } @@ -92,7 +96,9 @@ pub unsafe fn test_7() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p6_data_member_of_lvalue_is_lvalue_HasTwoInts { pub first: i32, pub second: i32, @@ -127,19 +133,21 @@ pub static mut moveCount_10: std::cell::LazyCell = std::cell::LazyCell::new TriviallyDefaultConstructibleUnsafe, DestructibleUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] 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( +impl p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { + pub unsafe fn constructor_2( this: *mut Self, _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( + pub unsafe fn constructor_3( this: *mut Self, _a0: RvalueRefUnsafe, ) { @@ -157,9 +165,12 @@ impl MoveConstructibleUnsafe for p6_data_member_of_rvalue_is_xvalue_CountsCopies Default, )] #[memberwise(copy_constructor, move_constructor)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct p6_data_member_of_rvalue_is_xvalue_HoldsCounted { pub member: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, } +impl p6_data_member_of_rvalue_is_xvalue_HoldsCounted {} pub unsafe fn test_11() { let mut pm: isize = (::std::mem::offset_of!(p6_data_member_of_rvalue_is_xvalue_HoldsCounted, member) as isize); @@ -167,22 +178,24 @@ pub unsafe fn test_11() { ::default(); object_unsafe!( from_lvalue, - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, - LvalueRefUnsafe::bind( - &(*(&mut holder as *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted) - .wrapping_byte_offset(pm) - .cast::()) + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::constructor_2( + LvalueRefUnsafe::bind( + &(*(&mut holder as *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted) + .wrapping_byte_offset(pm) + .cast::()) + ) ) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_9)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut moveCount_10)) == (0))); object_unsafe!( from_xvalue, - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, - RvalueRefUnsafe::bind( - &mut (*(&mut holder as *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted) - .wrapping_byte_offset(pm) - .cast::()) + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::constructor_3( + RvalueRefUnsafe::bind( + &mut (*(&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))); diff --git a/tests/std/expr/expr.prim/out/refcount/expr.prim.this.rs b/tests/std/expr/expr.prim/out/refcount/expr.prim.this.rs index 1701049a73..aa155229ac 100644 --- a/tests/std/expr/expr.prim/out/refcount/expr.prim.this.rs +++ b/tests/std/expr/expr.prim/out/refcount/expr.prim.this.rs @@ -18,7 +18,7 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] #[byte_size(16)] pub struct p1_default_member_initializer_names_object_Holder { #[offset(0)] @@ -60,7 +60,7 @@ pub fn test_0() { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] #[byte_size(16)] pub struct p1_mem_initializer_names_object_Holder { #[offset(0)] diff --git a/tests/std/expr/expr.prim/out/unsafe/expr.prim.this.rs b/tests/std/expr/expr.prim/out/unsafe/expr.prim.this.rs index 0ffd9cc063..23e5e94649 100644 --- a/tests/std/expr/expr.prim/out/unsafe/expr.prim.this.rs +++ b/tests/std/expr/expr.prim/out/unsafe/expr.prim.this.rs @@ -18,7 +18,7 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] pub struct p1_default_member_initializer_names_object_Holder { pub self_: *mut p1_default_member_initializer_names_object_Holder, pub value: i32, @@ -56,7 +56,7 @@ pub unsafe fn test_0() { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] pub struct p1_mem_initializer_names_object_Holder { pub self_: *mut p1_mem_initializer_names_object_Holder, pub value: i32, diff --git a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs index fc238679b2..76311ce8ab 100644 --- a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs +++ b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs @@ -33,7 +33,8 @@ pub struct p16_rebind_member_Alloc_std_pair_const_int__int___rebind_std_pair_con TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p16_rebind_member_Alloc_std_pair_const_int__int__ { #[offset(0)] diff --git a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs index 978cbdabc8..82820a63f9 100644 --- a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs +++ b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs @@ -30,7 +30,8 @@ pub struct p16_rebind_member_Alloc_std_pair_const_int__int___rebind_std_pair_con TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p16_rebind_member_Alloc_std_pair_const_int__int__ { pub id: i32, } diff --git a/tests/std/library/requirements/utility.requirements/out/refcount/utility.arg.requirements.rs b/tests/std/library/requirements/utility.requirements/out/refcount/utility.arg.requirements.rs index 952225088d..b59ba33b07 100644 --- a/tests/std/library/requirements/utility.requirements/out/refcount/utility.arg.requirements.rs +++ b/tests/std/library/requirements/utility.requirements/out/refcount/utility.arg.requirements.rs @@ -20,7 +20,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct table29_member_operator_Version { #[offset(0)] @@ -179,7 +181,9 @@ pub fn test_1() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct table29_other_operator_shapes_Weight { #[offset(0)] @@ -206,7 +210,9 @@ impl LessThanComparable for table29_other_operator_shapes_Weight { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct table29_other_operator_shapes_Height { #[offset(0)] @@ -234,6 +240,8 @@ impl LessThanComparable for table29_other_operator_shapes_Height { PartiallyOrderedWith, )] #[three_way(table29_other_operator_shapes_Depth::operator_cmp)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct table29_other_operator_shapes_Depth { #[offset(0)] @@ -334,7 +342,9 @@ pub fn test_2() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct pairs_spec_p3_members_order_pairs_Rank { #[offset(0)] diff --git a/tests/std/library/requirements/utility.requirements/out/unsafe/utility.arg.requirements.rs b/tests/std/library/requirements/utility.requirements/out/unsafe/utility.arg.requirements.rs index 801b0f3a1e..e20798e882 100644 --- a/tests/std/library/requirements/utility.requirements/out/unsafe/utility.arg.requirements.rs +++ b/tests/std/library/requirements/utility.requirements/out/unsafe/utility.arg.requirements.rs @@ -17,7 +17,9 @@ pub static mut less_calls_0: std::cell::LazyCell = std::cell::LazyCell::new TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct table29_member_operator_Version { pub major: i32, pub minor: i32, @@ -137,7 +139,9 @@ pub unsafe fn test_1() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct table29_other_operator_shapes_Weight { pub grams: i32, } @@ -164,7 +168,9 @@ impl LessThanComparableUnsafe for table29_other_operator_shapes_Weight { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct table29_other_operator_shapes_Height { pub millimeters: i32, } @@ -189,6 +195,8 @@ impl LessThanComparableUnsafe for table29_other_operator_shapes_Height { PartiallyOrderedWithUnsafe, )] #[three_way(table29_other_operator_shapes_Depth::operator_cmp)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct table29_other_operator_shapes_Depth { pub millimeters: i32, } @@ -276,7 +284,9 @@ pub unsafe fn test_2() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct pairs_spec_p3_members_order_pairs_Rank { pub value: i32, } diff --git a/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs b/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs index e8e3a288c0..0c674441d6 100644 --- a/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs +++ b/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs @@ -26,9 +26,9 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] -#[conversion_function(conversion_function_3, bool, const_lvalue_ref, explicit)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[conversion_function(to_bool, LvalueRef>, bool , explicit)] #[byte_size(4)] pub struct p2_condition_variable_created_each_iteration_ConvertsToBool { #[offset(0)] @@ -39,13 +39,8 @@ impl p2_condition_variable_created_each_iteration_ConvertsToBool { field!(this, value).write(value); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } - pub fn conversion_function_3( - this: LvalueRef>, - __return: Ptr, - ) { - let this = this.as_pointer(); - __return.write((this.with(|__s| __s.value) != 0)); - return; + pub fn to_bool(this: Ptr) -> bool { + return (this.with(|__s| __s.value) != 0); } } impl Destructible for p2_condition_variable_created_each_iteration_ConvertsToBool { @@ -62,9 +57,9 @@ pub fn test_2() { p2_condition_variable_created_each_iteration_ConvertsToBool::constructor_1(remaining) ); if !({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - p2_condition_variable_created_each_iteration_ConvertsToBool::conversion_function_3(>>::bind(condition .as_pointer() ), Ptr::clone(&__v.as_pointer())); - Rc::try_unwrap(__v).ok().unwrap().into_inner() + p2_condition_variable_created_each_iteration_ConvertsToBool::to_bool( + condition.as_pointer(), + ) }) { break; } @@ -98,9 +93,9 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] -#[conversion_function(conversion_function_3, bool, const_lvalue_ref, explicit)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[conversion_function(to_bool, LvalueRef>, bool , explicit)] #[byte_size(4)] pub struct p2_continue_destroys_condition_variable_ConvertsToBool { #[offset(0)] @@ -111,13 +106,8 @@ impl p2_continue_destroys_condition_variable_ConvertsToBool { field!(this, value).write(value); (*ctorCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } - pub fn conversion_function_3( - this: LvalueRef>, - __return: Ptr, - ) { - let this = this.as_pointer(); - __return.write((this.with(|__s| __s.value) != 0)); - return; + pub fn to_bool(this: Ptr) -> bool { + return (this.with(|__s| __s.value) != 0); } } impl Destructible for p2_continue_destroys_condition_variable_ConvertsToBool { @@ -135,14 +125,7 @@ pub fn test_5() { p2_continue_destroys_condition_variable_ConvertsToBool::constructor_1(remaining) ); if !({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - p2_continue_destroys_condition_variable_ConvertsToBool::conversion_function_3( - >>::bind( - condition.as_pointer(), - ), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() + p2_continue_destroys_condition_variable_ConvertsToBool::to_bool(condition.as_pointer()) }) { break; } diff --git a/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs b/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs index 0c9265505c..46f85800f5 100644 --- a/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs +++ b/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs @@ -21,9 +21,9 @@ pub static mut dtorCount_1: std::cell::LazyCell = std::cell::LazyCell::new( )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] -#[conversion_function(conversion_function_3, bool, const_lvalue_ref, explicit)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[conversion_function(to_bool, LvalueRefUnsafe>, bool , explicit)] pub struct p2_condition_variable_created_each_iteration_ConvertsToBool { pub value: i32, } @@ -32,14 +32,8 @@ impl p2_condition_variable_created_each_iteration_ConvertsToBool { (&raw mut (*this).value).write(value); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } - pub unsafe fn conversion_function_3( - this: LvalueRefUnsafe>, - __return: *mut bool, - ) { - let this = - this.as_ptr() as *mut p2_condition_variable_created_each_iteration_ConvertsToBool; - __return.write((((*this).value) != (0))); - return; + pub unsafe fn to_bool(this: *const Self) -> bool { + return (((*this).value) != (0)); } } impl DestructibleUnsafe for p2_condition_variable_created_each_iteration_ConvertsToBool { @@ -55,10 +49,10 @@ pub unsafe fn test_2() { condition, p2_condition_variable_created_each_iteration_ConvertsToBool::constructor_1(remaining) ); - if !({ - let mut __v: bool = ZeroInitializationUnsafe::zero_init(); - p2_condition_variable_created_each_iteration_ConvertsToBool::conversion_function_3(>>::bind(& mut condition ), &raw mut __v); - __v + if !(unsafe { + p2_condition_variable_created_each_iteration_ConvertsToBool::to_bool( + &raw const condition, + ) }) { break; } @@ -89,9 +83,9 @@ pub static mut dtorCount_4: std::cell::LazyCell = std::cell::LazyCell::new( )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] -#[conversion_function(conversion_function_3, bool, const_lvalue_ref, explicit)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[conversion_function(to_bool, LvalueRefUnsafe>, bool , explicit)] pub struct p2_continue_destroys_condition_variable_ConvertsToBool { pub value: i32, } @@ -100,13 +94,8 @@ impl p2_continue_destroys_condition_variable_ConvertsToBool { (&raw mut (*this).value).write(value); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_3)).prefix_inc(); } - pub unsafe fn conversion_function_3( - this: LvalueRefUnsafe>, - __return: *mut bool, - ) { - let this = this.as_ptr() as *mut p2_continue_destroys_condition_variable_ConvertsToBool; - __return.write((((*this).value) != (0))); - return; + pub unsafe fn to_bool(this: *const Self) -> bool { + return (((*this).value) != (0)); } } impl DestructibleUnsafe for p2_continue_destroys_condition_variable_ConvertsToBool { @@ -123,10 +112,8 @@ pub unsafe fn test_5() { condition, p2_continue_destroys_condition_variable_ConvertsToBool::constructor_1(remaining) ); - if !({ - let mut __v: bool = ZeroInitializationUnsafe::zero_init(); - p2_continue_destroys_condition_variable_ConvertsToBool::conversion_function_3(>>::bind(& mut condition ), &raw mut __v); - __v + if !(unsafe { + p2_continue_destroys_condition_variable_ConvertsToBool::to_bool(&raw const condition) }) { break; } 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 f25fdafd12..b08f0c88a1 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 @@ -29,6 +29,10 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -53,25 +57,21 @@ 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) { + pub fn constructor_1(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>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { @@ -88,7 +88,7 @@ pub fn test_6() { ({ LifetimeTracked::reset() }); let mut choice: i32 = 9; { - object!(guard, LifetimeTracked); + object!(guard, LifetimeTracked::constructor_1()); let mut choice: i32 = 0; if (choice != 0) { (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); @@ -104,7 +104,7 @@ pub fn test_6() { assert!((else_runs_5.with(|rc| *rc.borrow()) == 1)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 1)); { - object!(guard, LifetimeTracked); + object!(guard, LifetimeTracked::constructor_1()); let mut choice: i32 = 4; if (choice != 0) { (*then_runs_4.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 44809583da..0afa87e2a5 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 @@ -29,6 +29,10 @@ thread_local!( Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -53,25 +57,21 @@ 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) { + pub fn constructor_1(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>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl Destructible for LifetimeTracked { fn destroy(this: Ptr) { @@ -94,14 +94,15 @@ thread_local!( ZeroInitialization, VaArg, FnPtrArg, - CppFrom, TriviallyDefaultConstructible, Memberwise, CopyConstructible, Movable, )] #[memberwise(copy_assign)] -#[cpp_into(i32, to_i32)] +#[derive(Conversions)] +#[conversions(copy)] +#[conversion_function(to_i32, LvalueRef>, i32 )] #[byte_size(4)] pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { #[offset(0)] @@ -161,7 +162,7 @@ pub fn test_10() { ({ LifetimeTracked::reset() }); let mut selector: i32 = 9; { - object!(guard, LifetimeTracked); + object!(guard, LifetimeTracked::constructor_1()); let mut selector: i32 = 2; 'switch: { match { selector } { 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 d01b906459..304ec5b3d2 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 @@ -20,6 +20,10 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct LifetimeTracked { pub uses: i32, } @@ -36,23 +40,19 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - 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(this: *mut Self) { + pub unsafe fn constructor_1(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(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + 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 DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { @@ -67,7 +67,7 @@ pub unsafe fn test_6() { (unsafe { LifetimeTracked::reset() }); let mut choice: i32 = 9; { - object_unsafe!(guard, LifetimeTracked); + object_unsafe!(guard, LifetimeTracked::constructor_1()); let mut choice: i32 = 0; if (choice != 0) { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); @@ -83,7 +83,7 @@ pub unsafe fn test_6() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (1))); { - object_unsafe!(guard, LifetimeTracked); + object_unsafe!(guard, LifetimeTracked::constructor_1()); let mut choice: i32 = 4; if (choice != 0) { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).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 c1521c990e..ca1db4dfaa 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 @@ -20,6 +20,10 @@ pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(| SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct LifetimeTracked { pub uses: i32, } @@ -36,23 +40,19 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - 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(this: *mut Self) { + pub unsafe fn constructor_1(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(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const LifetimeTracked); (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } + 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 DestructibleUnsafe for LifetimeTracked { unsafe fn destroy(this: *mut Self) { @@ -70,14 +70,15 @@ pub static mut dtorCount_6: std::cell::LazyCell = std::cell::LazyCell::new( VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, TriviallyDefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, MovableUnsafe, )] #[memberwise(copy_assign)] -#[cpp_into(i32, to_i32)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[conversion_function(to_i32, LvalueRefUnsafe>, i32 )] pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { pub value: i32, } @@ -133,7 +134,7 @@ pub unsafe fn test_10() { (unsafe { LifetimeTracked::reset() }); let mut selector: i32 = 9; { - object_unsafe!(guard, LifetimeTracked); + object_unsafe!(guard, LifetimeTracked::constructor_1()); let mut selector: i32 = 2; 'switch: { match { selector } { diff --git a/tests/std/support/cmp/out/refcount/cmp.concept.rs b/tests/std/support/cmp/out/refcount/cmp.concept.rs index 928af2f6a4..c974b14ce7 100644 --- a/tests/std/support/cmp/out/refcount/cmp.concept.rs +++ b/tests/std/support/cmp/out/refcount/cmp.concept.rs @@ -20,6 +20,8 @@ use std::rc::{Rc, Weak}; PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(8)] pub struct p1_defaulted_three_way_Version { #[offset(0)] @@ -114,6 +116,8 @@ thread_local!( PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct p1_user_written_three_way_Money { #[offset(0)] @@ -176,6 +180,8 @@ pub fn test_2() { PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(8)] pub struct p1_weaker_category_Temperature { #[offset(0)] @@ -237,6 +243,8 @@ pub fn test_3() { PartiallyOrderedWith, )] #[three_way(p1_three_way_without_equality_Rank::operator_cmp)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct p1_three_way_without_equality_Rank { #[offset(0)] diff --git a/tests/std/support/cmp/out/unsafe/cmp.concept.rs b/tests/std/support/cmp/out/unsafe/cmp.concept.rs index a199076f39..126c5aa0a9 100644 --- a/tests/std/support/cmp/out/unsafe/cmp.concept.rs +++ b/tests/std/support/cmp/out/unsafe/cmp.concept.rs @@ -19,6 +19,8 @@ use std::rc::Rc; PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct p1_defaulted_three_way_Version { pub major: i32, pub minor: i32, @@ -103,6 +105,8 @@ pub static mut three_way_calls_1: std::cell::LazyCell = PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct p1_user_written_three_way_Money { pub cents: i32, } @@ -168,6 +172,8 @@ pub unsafe fn test_2() { PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct p1_weaker_category_Temperature { pub degrees: f64, } @@ -221,6 +227,8 @@ pub unsafe fn test_3() { PartiallyOrderedWithUnsafe, )] #[three_way(p1_three_way_without_equality_Rank::operator_cmp)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct p1_three_way_without_equality_Rank { pub value: i32, } diff --git a/tests/std/temp/temp.spec/out/refcount/temp.inst.rs b/tests/std/temp/temp.spec/out/refcount/temp.inst.rs index 92d37d1efe..a5ab8c271b 100644 --- a/tests/std/temp/temp.spec/out/refcount/temp.inst.rs +++ b/tests/std/temp/temp.spec/out/refcount/temp.inst.rs @@ -17,12 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] -#[constructor( - constructor_2, - explicit, - const_lvalue_ref(p2_reference_does_not_instantiate_Wrapper_int_) -)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, explicit, LvalueRef>)] #[byte_size(4)] pub struct p2_reference_does_not_instantiate_Member { #[offset(0)] @@ -48,7 +45,8 @@ impl Default for p2_reference_does_not_instantiate_Member { #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Default)] #[memberwise(move_constructor)] #[derive(Conversions)] -#[conversions(move, default = constructor_1)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p2_reference_does_not_instantiate_Holder { #[offset(0)] diff --git a/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs b/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs index 9cf80c318c..2c251655b9 100644 --- a/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs +++ b/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs @@ -16,12 +16,9 @@ use std::rc::Rc; TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] -#[constructor( - constructor_2, - explicit, - const_lvalue_ref(p2_reference_does_not_instantiate_Wrapper_int_) -)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, explicit, LvalueRefUnsafe>)] pub struct p2_reference_does_not_instantiate_Member { pub value: i32, } @@ -46,7 +43,8 @@ impl Default for p2_reference_does_not_instantiate_Member { #[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, Default)] #[memberwise(move_constructor)] #[derive(ConversionsUnsafe)] -#[conversions(move, default = constructor_1)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct p2_reference_does_not_instantiate_Holder { pub member: p2_reference_does_not_instantiate_Member, } diff --git a/tests/std/utilities/pairs/out/refcount/pairs.pair.rs b/tests/std/utilities/pairs/out/refcount/pairs.pair.rs index ccbbd21b47..35d80cdd12 100644 --- a/tests/std/utilities/pairs/out/refcount/pairs.pair.rs +++ b/tests/std/utilities/pairs/out/refcount/pairs.pair.rs @@ -84,12 +84,24 @@ pub fn test_2() { Rc::new(RefCell::new(Ptr::alloc(81).to_owned_opt())), ))); let mut original: Ptr = ({ (*(*source.borrow()).1.borrow()).as_pointer() }); - let converted: Value<(Value, Value>>)> = Rc::new(RefCell::new(( - Rc::new(RefCell::new( - (((*source.borrow()).0.as_pointer().read()) as i64), - )), - Rc::new(RefCell::new(cpp_move!((*source.borrow()).1.as_pointer()))), - ))); + let converted: Value<(Value, Value>>)> = Rc::new(RefCell::new({ + object!(__first, i64, |__this| ConstructibleFrom::construct( + __this, + (RvalueRef::::bind((*source.borrow()).0.as_pointer()),) + )); + object!(__second, Option>, |__this| { + ConstructibleFrom::construct( + __this, + (RvalueRef::>>::bind( + (*source.borrow()).1.as_pointer(), + ),), + ) + }); + ( + Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), + ) + })); assert!(({ ((*(*converted.borrow()).0.borrow()) == 0_i64) })); assert!(({ ({ (*(*converted.borrow()).1.borrow()).as_pointer() }) } == { (original).clone() })); assert!(((({ (*(*converted.borrow()).1.borrow()).as_pointer() }).read()) == 81)); @@ -106,10 +118,24 @@ pub fn test_3() { Rc::new(RefCell::new(None)), ))); { - let __first = (((*source.borrow()).0.as_pointer().read()) as i64); - let __second = cpp_move!((*source.borrow()).1.as_pointer()); - *(*target.borrow()).0.borrow_mut() = __first; - *(*target.borrow()).1.borrow_mut() = __second; + object!(__first, i64, |__this| ConvertibleTo::convert( + RvalueRef::::bind((*source.borrow()).0.as_pointer()), + __this + )); + object!(__second, Option>, |__this| { + ConvertibleTo::convert( + RvalueRef::>>::bind((*source.borrow()).1.as_pointer()), + __this, + ) + }); + MoveAssignable::move_assign( + (*target.borrow()).0.as_pointer(), + RvalueRef::::bind(__first.as_pointer()), + ); + MoveAssignable::move_assign( + (*target.borrow()).1.as_pointer(), + RvalueRef::>>::bind(__second.as_pointer()), + ); }; assert!(({ ((*(*target.borrow()).0.borrow()) == 4_i64) })); assert!(({ ({ (*(*target.borrow()).1.borrow()).as_pointer() }) } == { (original).clone() })); diff --git a/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs b/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs index 05d651e5b5..ca2b64b432 100644 --- a/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs +++ b/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs @@ -77,8 +77,22 @@ pub unsafe fn test_2() { .1 .as_deref_mut() .map_or(::std::ptr::null_mut(), |v| v as *mut i32); - let mut converted: (i64, Option>) = - (((*&mut source.0) as i64), cpp_move_unsafe!(&mut source.1)); + let mut converted: (i64, Option>) = { + object_unsafe!(__first, i64, |__this| ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut source.0),) + )); + object_unsafe!(__second, Option>, |__this| { + ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::>>::bind(&raw mut source.1),), + ) + }); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) + }; assert!(((converted.0) == (0_i64))); assert!( ((converted @@ -111,7 +125,24 @@ pub unsafe fn test_3() { .map_or(::std::ptr::null_mut(), |v| v as *mut i32); let mut target: (i64, Option>) = (0_i64, None); { - target = (((*&mut source.0) as i64), cpp_move_unsafe!(&mut source.1)); + object_unsafe!(__first, i64, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut source.0), + __this + )); + object_unsafe!(__second, Option>, |__this| { + ConvertibleToUnsafe::convert( + RvalueRefUnsafe::>>::bind(&raw mut source.1), + __this, + ) + }); + MoveAssignableUnsafe::move_assign( + &raw mut target.0, + RvalueRefUnsafe::::bind(&raw mut __first), + ); + MoveAssignableUnsafe::move_assign( + &raw mut target.1, + RvalueRefUnsafe::>>::bind(&raw mut __second), + ); }; assert!(((target.0) == (4_i64))); assert!( diff --git a/tests/std/utilities/utility/out/refcount/forward-helpers.rs b/tests/std/utilities/utility/out/refcount/forward-helpers.rs index ddf90123e1..956068cc7e 100644 --- a/tests/std/utilities/utility/out/refcount/forward-helpers.rs +++ b/tests/std/utilities/utility/out/refcount/forward-helpers.rs @@ -15,27 +15,26 @@ pub fn test_0() { assert!(({ ((*value.borrow()) == 2) })); } #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct p6_forward_like_Movable { #[offset(0)] pub value: i32, } impl p6_forward_like_Movable { - pub fn construct(this: Ptr, mut value: i32) { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); } -} -impl CopyConstructible for p6_forward_like_Movable { - fn copy_constructor(this: Ptr, other: LvalueRef>) { + pub fn constructor_2(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: RvalueRef) { + pub fn constructor_3(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); @@ -43,15 +42,18 @@ impl MoveConstructible for p6_forward_like_Movable { } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise)] #[memberwise(copy_constructor, move_constructor)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct p6_forward_like_Holder { #[offset(0)] #[byte_size(4)] pub member: p6_forward_like_Movable, } -impl DefaultConstructible for p6_forward_like_Holder { - fn default_constructor(this: Ptr) { - p6_forward_like_Movable::construct(field_ptr!(this, member), 1); +impl p6_forward_like_Holder { + pub fn constructor_1(this: Ptr) { + p6_forward_like_Movable::constructor_1(field_ptr!(this, member), 1); } } impl Default for p6_forward_like_Holder { @@ -60,8 +62,8 @@ impl Default for p6_forward_like_Holder { p6_forward_like_Holder { member: { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - p6_forward_like_Movable::construct(__v.as_pointer(), 1); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + p6_forward_like_Movable::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, } @@ -69,21 +71,21 @@ impl Default for p6_forward_like_Holder { } } pub fn take_1(__return: Ptr, self_: Ptr) { - CopyConstructible::copy_constructor( + p6_forward_like_Movable::constructor_2( __return.clone(), LvalueRef::bind(field_ptr!(self_, member)), ); return; } pub fn take_2(__return: Ptr, self_: Ptr) { - MoveConstructible::move_constructor( + p6_forward_like_Movable::constructor_3( __return.clone(), RvalueRef::bind(field_ptr!(self_, member)), ); return; } pub fn test_3() { - object!(holder, p6_forward_like_Holder); + object!(holder, p6_forward_like_Holder::constructor_1()); object!(copied, p6_forward_like_Movable, |copied| ({ take_1(Ptr::clone(&copied.clone()), holder.as_pointer()) })); @@ -94,21 +96,21 @@ pub fn test_3() { assert!(({ (*moved.borrow()).value } == 1) && ({ (*holder.borrow()).member.value } == 0)); } #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, RvalueRef)] #[byte_size(4)] pub struct p9_move_Movable { #[offset(0)] pub value: i32, } impl p9_move_Movable { - pub fn construct(this: Ptr, mut value: i32) { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); } -} -impl MoveConstructible for p9_move_Movable { - fn move_constructor(this: Ptr, other: RvalueRef) { + pub fn constructor_2(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); @@ -125,11 +127,10 @@ pub fn test_4() { ({ (moved_pointer).clone() } == { (target.as_pointer()) }) && ({ (pointer).clone() } == { (target.as_pointer()) }) ); - object!(source, p9_move_Movable(3)); + object!(source, p9_move_Movable::constructor_1(3)); object!( destination, - p9_move_Movable, - RvalueRef::bind(source.as_pointer()) + p9_move_Movable::constructor_2(RvalueRef::bind(source.as_pointer())) ); assert!(({ (*destination.borrow()).value } == 3) && ({ (*source.borrow()).value } == 0)); let strings: Value>> = Rc::new(RefCell::new(Vec::new())); @@ -151,8 +152,11 @@ pub fn test_4() { }) ); } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable)] -#[cpp_from(i32, construct, value)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(12)] pub struct p10_forward_in_template_A { #[offset(0)] @@ -163,22 +167,18 @@ pub struct p10_forward_in_template_A { pub moves: i32, } impl p10_forward_in_template_A { - pub fn construct(this: Ptr, mut value: i32) { + pub fn constructor_1(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>) { + pub fn constructor_2(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: RvalueRef) { + pub fn constructor_3(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); field!(this, copies).write(0); @@ -192,15 +192,15 @@ impl Default for p10_forward_in_template_A { } } pub fn make_5(__return: Ptr, source: Ptr) { - CopyConstructible::copy_constructor(__return.clone(), LvalueRef::bind((source).clone())); + p10_forward_in_template_A::constructor_2(__return.clone(), LvalueRef::bind((source).clone())); return; } pub fn make_6(__return: Ptr, source: Ptr) { - MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind((source).clone())); + p10_forward_in_template_A::constructor_3(__return.clone(), RvalueRef::bind((source).clone())); return; } pub fn test_7() { - object!(a, p10_forward_in_template_A(1)); + object!(a, p10_forward_in_template_A::constructor_1(1)); object!(copied, p10_forward_in_template_A, |copied| ({ make_5(Ptr::clone(&copied.clone()), a.as_pointer()) })); @@ -219,78 +219,80 @@ pub fn test_7() { assert!(({ (*a.borrow()).value } == 0)); } #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] 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) { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); } -} -impl CopyConstructible for p11_move_if_noexcept_NoexceptMove { - fn copy_constructor( + pub fn constructor_2( 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: RvalueRef) { + pub fn constructor_3(this: Ptr, other: RvalueRef) { let other = other.as_pointer(); field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] 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) { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); } -} -impl CopyConstructible for p11_move_if_noexcept_ThrowingMove { - fn copy_constructor( + pub fn constructor_2( 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: RvalueRef) { + pub fn constructor_3(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_8() { - object!(moved_from, p11_move_if_noexcept_NoexceptMove(1)); + object!( + moved_from, + p11_move_if_noexcept_NoexceptMove::constructor_1(1) + ); object!( moved, - p11_move_if_noexcept_NoexceptMove, - RvalueRef::bind(moved_from.as_pointer()) + p11_move_if_noexcept_NoexceptMove::constructor_3(RvalueRef::bind(moved_from.as_pointer())) ); assert!(({ (*moved.borrow()).value } == 1) && ({ (*moved_from.borrow()).value } == 0)); - object!(copied_from, p11_move_if_noexcept_ThrowingMove(2)); + object!( + copied_from, + p11_move_if_noexcept_ThrowingMove::constructor_1(2) + ); object!( copied, - p11_move_if_noexcept_ThrowingMove, - LvalueRef::bind(copied_from.as_pointer()) + p11_move_if_noexcept_ThrowingMove::constructor_2(LvalueRef::bind(copied_from.as_pointer())) ); assert!(({ (*copied.borrow()).value } == 2) && ({ (*copied_from.borrow()).value } == 2)); } diff --git a/tests/std/utilities/utility/out/refcount/forward.rs b/tests/std/utilities/utility/out/refcount/forward.rs index 60ce4b7846..b72d0f16fb 100644 --- a/tests/std/utilities/utility/out/refcount/forward.rs +++ b/tests/std/utilities/utility/out/refcount/forward.rs @@ -23,7 +23,9 @@ pub fn test_0() { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct p9_move_trivially_copyable_Point { #[offset(0)] @@ -58,37 +60,36 @@ pub fn test_1() { assert!(({ (*element.borrow()).x } == 5) && ({ (*element.borrow()).y } == 6)); } #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, RvalueRef)] #[byte_size(4)] pub struct p10_move_constructor_A { #[offset(0)] pub value: i32, } impl p10_move_constructor_A { - pub fn construct(this: Ptr, mut value: i32) { + pub fn constructor_1(this: Ptr, mut value: i32) { field!(this, value).write(value); } -} -impl MoveConstructible for p10_move_constructor_A { - fn move_constructor(this: Ptr, other: RvalueRef) { + pub fn constructor_2(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!(source, p10_move_constructor_A::constructor_1(1)); object!( target, - p10_move_constructor_A, - RvalueRef::bind(source.as_pointer()) + p10_move_constructor_A::constructor_2(RvalueRef::bind(source.as_pointer())) ); assert!(({ (*target.borrow()).value } == 1)); assert!(({ (*source.borrow()).value } == 0)); let values: Value> = Rc::new(RefCell::new(Vec::new())); - object!(element, p10_move_constructor_A(2)); + object!(element, p10_move_constructor_A::constructor_1(2)); MoveConstructible::push_moved(&values.as_pointer(), element.as_pointer()); assert!(({ (*values.borrow())[0_usize].value } == 2)); assert!(({ (*element.borrow()).value } == 0)); diff --git a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs index 8b4e364fcf..2a8a93039b 100644 --- a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs +++ b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs @@ -16,28 +16,27 @@ pub unsafe fn test_0() { } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct p6_forward_like_Movable { pub value: i32, } impl p6_forward_like_Movable { - pub unsafe fn construct(this: *mut Self, mut value: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); } -} -impl CopyConstructibleUnsafe for p6_forward_like_Movable { - unsafe fn copy_constructor( + pub unsafe fn constructor_2( this: *mut Self, other: LvalueRefUnsafe>, ) { let other = (other.as_ptr() as *const p6_forward_like_Movable); (&raw mut (*this).value).write((*other).value); } -} -impl MoveConstructibleUnsafe for p6_forward_like_Movable { - unsafe fn move_constructor(this: *mut Self, other: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, other: RvalueRefUnsafe) { let other = (other.as_ptr() as *mut p6_forward_like_Movable); (&raw mut (*this).value).write((*other).value); (*other).value = 0; @@ -46,12 +45,15 @@ impl MoveConstructibleUnsafe for p6_forward_like_Movable { #[repr(C)] #[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe)] #[memberwise(copy_constructor, move_constructor)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct p6_forward_like_Holder { pub member: p6_forward_like_Movable, } -impl DefaultConstructibleUnsafe for p6_forward_like_Holder { - unsafe fn default_constructor(this: *mut Self) { - p6_forward_like_Movable::construct(&raw mut (*this).member, 1); +impl p6_forward_like_Holder { + pub unsafe fn constructor_1(this: *mut Self) { + p6_forward_like_Movable::constructor_1(&raw mut (*this).member, 1); } } impl Default for p6_forward_like_Holder { @@ -59,8 +61,8 @@ impl Default for p6_forward_like_Holder { unsafe { p6_forward_like_Holder { member: { - let mut __v: p6_forward_like_Movable = ::zero_init(); - p6_forward_like_Movable::construct(&raw mut __v, 1); + let mut __v: p6_forward_like_Movable = ZeroInitializationUnsafe::zero_init(); + p6_forward_like_Movable::constructor_1(&raw mut __v, 1); __v }, } @@ -68,18 +70,15 @@ impl Default for p6_forward_like_Holder { } } 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)); + p6_forward_like_Movable::constructor_2(__return, LvalueRefUnsafe::bind(&(*self_).member)); return; } pub unsafe fn take_2(__return: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { - MoveConstructibleUnsafe::move_constructor( - __return, - RvalueRefUnsafe::bind(&mut (*self_).member), - ); + p6_forward_like_Movable::constructor_3(__return, RvalueRefUnsafe::bind(&mut (*self_).member)); return; } pub unsafe fn test_3() { - object_unsafe!(holder, p6_forward_like_Holder); + object_unsafe!(holder, p6_forward_like_Holder::constructor_1()); object_unsafe!(copied, p6_forward_like_Movable, |copied| (unsafe { take_1(copied, &mut holder) })); @@ -91,19 +90,19 @@ pub unsafe fn test_3() { } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, RvalueRefUnsafe)] pub struct p9_move_Movable { pub value: i32, } impl p9_move_Movable { - pub unsafe fn construct(this: *mut Self, mut value: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); } -} -impl MoveConstructibleUnsafe for p9_move_Movable { - unsafe fn move_constructor(this: *mut Self, other: RvalueRefUnsafe) { + pub unsafe fn constructor_2(this: *mut Self, other: RvalueRefUnsafe) { let other = (other.as_ptr() as *mut p9_move_Movable); (&raw mut (*this).value).write((*other).value); (*other).value = 0; @@ -119,11 +118,10 @@ pub unsafe fn test_4() { assert!( ((moved_pointer) == (&mut target as *mut i32)) && ((pointer) == (&mut target as *mut i32)) ); - object_unsafe!(source, p9_move_Movable(3)); + object_unsafe!(source, p9_move_Movable::constructor_1(3)); object_unsafe!( destination, - p9_move_Movable, - RvalueRefUnsafe::bind(&mut source) + p9_move_Movable::constructor_2(RvalueRefUnsafe::bind(&mut source)) ); assert!(((destination.value) == (3)) && ((source.value) == (0))); let mut strings: Vec> = Vec::new(); @@ -144,22 +142,23 @@ pub unsafe fn test_4() { ); } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe)] -#[cpp_from(i32, construct, value)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct p10_forward_in_template_A { pub value: i32, pub copies: i32, pub moves: i32, } impl p10_forward_in_template_A { - pub unsafe fn construct(this: *mut Self, mut value: i32) { + pub unsafe fn constructor_1(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( + pub unsafe fn constructor_2( this: *mut Self, other: LvalueRefUnsafe>, ) { @@ -168,9 +167,10 @@ impl CopyConstructibleUnsafe for p10_forward_in_template_A { (&raw mut (*this).copies).write((((*other).copies) + (1))); (&raw mut (*this).moves).write(0); } -} -impl MoveConstructibleUnsafe for p10_forward_in_template_A { - unsafe fn move_constructor(this: *mut Self, other: RvalueRefUnsafe) { + pub unsafe fn constructor_3( + this: *mut Self, + other: RvalueRefUnsafe, + ) { let other = (other.as_ptr() as *mut p10_forward_in_template_A); (&raw mut (*this).value).write((*other).value); (&raw mut (*this).copies).write(0); @@ -187,18 +187,18 @@ 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)); + p10_forward_in_template_A::constructor_2(__return, LvalueRefUnsafe::bind(source)); return; } 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)); + p10_forward_in_template_A::constructor_3(__return, RvalueRefUnsafe::bind(source)); return; } pub unsafe fn test_7() { - object_unsafe!(a, p10_forward_in_template_A(1)); + object_unsafe!(a, p10_forward_in_template_A::constructor_1(1)); object_unsafe!(copied, p10_forward_in_template_A, |copied| (unsafe { make_5(copied, &mut a) })); @@ -212,28 +212,27 @@ pub unsafe fn test_7() { } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct p11_move_if_noexcept_NoexceptMove { pub value: i32, } impl p11_move_if_noexcept_NoexceptMove { - pub unsafe fn construct(this: *mut Self, mut value: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); } -} -impl CopyConstructibleUnsafe for p11_move_if_noexcept_NoexceptMove { - unsafe fn copy_constructor( + pub unsafe fn constructor_2( this: *mut Self, other: LvalueRefUnsafe>, ) { let other = (other.as_ptr() as *const p11_move_if_noexcept_NoexceptMove); (&raw mut (*this).value).write((*other).value); } -} -impl MoveConstructibleUnsafe for p11_move_if_noexcept_NoexceptMove { - unsafe fn move_constructor( + pub unsafe fn constructor_3( this: *mut Self, other: RvalueRefUnsafe, ) { @@ -244,28 +243,27 @@ impl MoveConstructibleUnsafe for p11_move_if_noexcept_NoexceptMove { } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct p11_move_if_noexcept_ThrowingMove { pub value: i32, } impl p11_move_if_noexcept_ThrowingMove { - pub unsafe fn construct(this: *mut Self, mut value: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); } -} -impl CopyConstructibleUnsafe for p11_move_if_noexcept_ThrowingMove { - unsafe fn copy_constructor( + pub unsafe fn constructor_2( this: *mut Self, other: LvalueRefUnsafe>, ) { let other = (other.as_ptr() as *const p11_move_if_noexcept_ThrowingMove); (&raw mut (*this).value).write((*other).value); } -} -impl MoveConstructibleUnsafe for p11_move_if_noexcept_ThrowingMove { - unsafe fn move_constructor( + pub unsafe fn constructor_3( this: *mut Self, other: RvalueRefUnsafe, ) { @@ -275,18 +273,22 @@ impl MoveConstructibleUnsafe for p11_move_if_noexcept_ThrowingMove { } } pub unsafe fn test_8() { - object_unsafe!(moved_from, p11_move_if_noexcept_NoexceptMove(1)); + object_unsafe!( + moved_from, + p11_move_if_noexcept_NoexceptMove::constructor_1(1) + ); object_unsafe!( moved, - p11_move_if_noexcept_NoexceptMove, - RvalueRefUnsafe::bind(&mut moved_from) + p11_move_if_noexcept_NoexceptMove::constructor_3(RvalueRefUnsafe::bind(&mut moved_from)) ); assert!(((moved.value) == (1)) && ((moved_from.value) == (0))); - object_unsafe!(copied_from, p11_move_if_noexcept_ThrowingMove(2)); + object_unsafe!( + copied_from, + p11_move_if_noexcept_ThrowingMove::constructor_1(2) + ); object_unsafe!( copied, - p11_move_if_noexcept_ThrowingMove, - LvalueRefUnsafe::bind(&copied_from) + p11_move_if_noexcept_ThrowingMove::constructor_2(LvalueRefUnsafe::bind(&copied_from)) ); assert!(((copied.value) == (2)) && ((copied_from.value) == (2))); } diff --git a/tests/std/utilities/utility/out/unsafe/forward.rs b/tests/std/utilities/utility/out/unsafe/forward.rs index 41b6475507..caa94a1e5e 100644 --- a/tests/std/utilities/utility/out/unsafe/forward.rs +++ b/tests/std/utilities/utility/out/unsafe/forward.rs @@ -22,7 +22,9 @@ pub unsafe fn test_0() { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct p9_move_trivially_copyable_Point { pub x: i32, pub y: i32, @@ -49,35 +51,34 @@ pub unsafe fn test_1() { } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, RvalueRefUnsafe)] pub struct p10_move_constructor_A { pub value: i32, } impl p10_move_constructor_A { - pub unsafe fn construct(this: *mut Self, mut value: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); } -} -impl MoveConstructibleUnsafe for p10_move_constructor_A { - unsafe fn move_constructor(this: *mut Self, other: RvalueRefUnsafe) { + pub unsafe fn constructor_2(this: *mut Self, other: RvalueRefUnsafe) { let other = (other.as_ptr() as *mut p10_move_constructor_A); (&raw mut (*this).value).write((*other).value); (*other).value = 0; } } pub unsafe fn test_2() { - object_unsafe!(source, p10_move_constructor_A(1)); + object_unsafe!(source, p10_move_constructor_A::constructor_1(1)); object_unsafe!( target, - p10_move_constructor_A, - RvalueRefUnsafe::bind(&mut source) + p10_move_constructor_A::constructor_2(RvalueRefUnsafe::bind(&mut source)) ); assert!(((target.value) == (1))); assert!(((source.value) == (0))); let mut values: Vec = Vec::new(); - object_unsafe!(element, p10_move_constructor_A(2)); + object_unsafe!(element, p10_move_constructor_A::constructor_1(2)); values.push_moved(&mut element); assert!(((values[(0_usize)].value) == (2))); assert!(((element.value) == (0))); diff --git a/tests/ub/out/refcount/ctor_ref_member.rs b/tests/ub/out/refcount/ctor_ref_member.rs index 9ae5b1509a..576aa62fed 100644 --- a/tests/ub/out/refcount/ctor_ref_member.rs +++ b/tests/ub/out/refcount/ctor_ref_member.rs @@ -19,7 +19,7 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, const_lvalue_ref(i32))] +#[constructor(constructor_1, LvalueRef>)] #[byte_size(8)] pub struct S { #[offset(0)] diff --git a/tests/ub/out/unsafe/ctor_ref_member.rs b/tests/ub/out/unsafe/ctor_ref_member.rs index 8119c89611..f63545f21a 100644 --- a/tests/ub/out/unsafe/ctor_ref_member.rs +++ b/tests/ub/out/unsafe/ctor_ref_member.rs @@ -19,7 +19,7 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, const_lvalue_ref(i32))] +#[constructor(constructor_1, LvalueRefUnsafe>)] pub struct S { pub r: *const i32, } diff --git a/tests/unit/out/refcount/10_struct.rs b/tests/unit/out/refcount/10_struct.rs index ab334d1d06..aa58178b9a 100644 --- a/tests/unit/out/refcount/10_struct.rs +++ b/tests/unit/out/refcount/10_struct.rs @@ -63,8 +63,9 @@ impl Graph { #[derive( Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] -#[constructor(constructor_2, explicit, value(Ptr< i32 > ))] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, explicit, Ptr< i32 > )] #[byte_size(8)] pub struct Partial { #[offset(0)] diff --git a/tests/unit/out/refcount/any.rs b/tests/unit/out/refcount/any.rs index 5cde8a2da3..84ba9fcf17 100644 --- a/tests/unit/out/refcount/any.rs +++ b/tests/unit/out/refcount/any.rs @@ -20,7 +20,7 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32), value(i32))] +#[constructor(constructor_1, i32, i32)] #[byte_size(8)] pub struct Point { #[offset(0)] diff --git a/tests/unit/out/refcount/array_of_noncopy_struct.rs b/tests/unit/out/refcount/array_of_noncopy_struct.rs index a98ef9ef4a..4eae87808a 100644 --- a/tests/unit/out/refcount/array_of_noncopy_struct.rs +++ b/tests/unit/out/refcount/array_of_noncopy_struct.rs @@ -20,7 +20,8 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(32)] pub struct NonCopy { #[offset(0)] diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index fd6f2af5aa..bbd2ca8fbe 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -2398,7 +2398,8 @@ pub fn test_stable_containers_58() { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct Counts_59 { #[offset(0)] diff --git a/tests/unit/out/refcount/cast.rs b/tests/unit/out/refcount/cast.rs index 28d326ca55..831c3621ea 100644 --- a/tests/unit/out/refcount/cast.rs +++ b/tests/unit/out/refcount/cast.rs @@ -104,7 +104,8 @@ impl Default for Grid { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(32)] pub struct Bag { #[offset(0)] diff --git a/tests/unit/out/refcount/class_templates.rs b/tests/unit/out/refcount/class_templates.rs index 9b47f5d1ae..69d4095d39 100644 --- a/tests/unit/out/refcount/class_templates.rs +++ b/tests/unit/out/refcount/class_templates.rs @@ -21,7 +21,8 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct MyContainer_int_ { #[offset(0)] @@ -67,7 +68,8 @@ impl MyContainer_int_ { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct MyContainer_char_ { #[offset(0)] @@ -113,7 +115,8 @@ impl MyContainer_char_ { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct MyContainer_float_ { #[offset(0)] diff --git a/tests/unit/out/refcount/constexpr_function.rs b/tests/unit/out/refcount/constexpr_function.rs index d7fe55acbc..3f53ea24b1 100644 --- a/tests/unit/out/refcount/constexpr_function.rs +++ b/tests/unit/out/refcount/constexpr_function.rs @@ -35,29 +35,20 @@ pub fn half_3(mut x: f64) -> f64 { Conversions, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, bool, const_lvalue_ref, explicit)] +#[conversion_function(to_bool, LvalueRef>, bool , explicit)] #[byte_size(4)] pub struct Flag { #[offset(0)] pub v: i32, } impl Flag { - pub fn conversion_function_1(this: LvalueRef>, __return: Ptr) { - let this = this.as_pointer(); - __return.write((this.with(|__s| __s.v) != 0)); - return; + pub fn to_bool(this: Ptr) -> bool { + return (this.with(|__s| __s.v) != 0); } } pub fn use_4(f: Flag) -> i32 { let f: Value = Rc::new(RefCell::new(f)); - assert!({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Flag::conversion_function_1( - >>::bind(f.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }); + assert!(({ Flag::to_bool(f.as_pointer(),) })); return { (*f.borrow()).v }; } pub fn checked_5(mut x: i32) -> i32 { diff --git a/tests/unit/out/refcount/constructor.rs b/tests/unit/out/refcount/constructor.rs index 5f135feb04..7fbe88c197 100644 --- a/tests/unit/out/refcount/constructor.rs +++ b/tests/unit/out/refcount/constructor.rs @@ -23,8 +23,8 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[conversions(copy)] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -64,9 +64,10 @@ impl Destructible for S { TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_3)] -#[constructor(constructor_1, value(i32), value(i32))] -#[constructor(constructor_2, value(i32))] +#[conversions(copy, move)] +#[constructor(constructor_1, i32, i32)] +#[constructor(constructor_2, i32)] +#[constructor(constructor_3)] #[byte_size(8)] pub struct Point { #[offset(0)] diff --git a/tests/unit/out/refcount/container_field_addr.rs b/tests/unit/out/refcount/container_field_addr.rs index b4f60960d9..c4cac46cc0 100644 --- a/tests/unit/out/refcount/container_field_addr.rs +++ b/tests/unit/out/refcount/container_field_addr.rs @@ -21,7 +21,8 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(32)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/conversion_operator_same_translation.rs b/tests/unit/out/refcount/conversion_operator_same_translation.rs index 6b04dce8cf..95557778f6 100644 --- a/tests/unit/out/refcount/conversion_operator_same_translation.rs +++ b/tests/unit/out/refcount/conversion_operator_same_translation.rs @@ -20,23 +20,19 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, i8, const_lvalue_ref)] -#[conversion_function(conversion_function_2, u8, const_lvalue_ref)] +#[conversion_function(to_i8, LvalueRef>, i8 )] +#[conversion_function(to_u8, LvalueRef>, u8 )] #[byte_size(4)] pub struct S { #[offset(0)] pub v: i32, } impl S { - pub fn conversion_function_1(this: LvalueRef>, __return: Ptr) { - let this = this.as_pointer(); - __return.write((this.with(|__s| __s.v) as i8)); - return; + pub fn to_i8(this: Ptr) -> i8 { + return (this.with(|__s| __s.v) as i8); } - pub fn conversion_function_2(this: LvalueRef>, __return: Ptr) { - let this = this.as_pointer(); - __return.write(((this.with(|__s| __s.v) + 1) as u8)); - return; + pub fn to_u8(this: Ptr) -> u8 { + return ((this.with(|__s| __s.v) + 1) as u8); } } #[derive( @@ -53,23 +49,19 @@ impl S { Conversions, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, i64, const_lvalue_ref)] -#[conversion_function(conversion_function_2, i64, const_lvalue_ref)] +#[conversion_function(to_i64_1, LvalueRef>, i64 )] +#[conversion_function(to_i64_2, LvalueRef>, i64 )] #[byte_size(4)] pub struct T { #[offset(0)] pub v: i32, } impl T { - pub fn conversion_function_1(this: LvalueRef>, __return: Ptr) { - let this = this.as_pointer(); - __return.write((this.with(|__s| __s.v) as i64)); - return; + pub fn to_i64_1(this: Ptr) -> i64 { + return (this.with(|__s| __s.v) as i64); } - pub fn conversion_function_2(this: LvalueRef>, __return: Ptr) { - let this = this.as_pointer(); - __return.write(((this.with(|__s| __s.v) + 1) as i64)); - return; + pub fn to_i64_2(this: Ptr) -> i64 { + return ((this.with(|__s| __s.v) + 1) as i64); } } pub fn main() { @@ -78,60 +70,17 @@ pub fn main() { } fn main_0() -> i32 { let s: Value = Rc::new(RefCell::new(S { v: 65 })); - let mut a: i8 = { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - S::conversion_function_1( - >>::bind(s.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; - let mut b: u8 = { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - S::conversion_function_2( - >>::bind(s.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; + let mut a: i8 = ({ S::to_i8(s.as_pointer()) }); + let mut b: u8 = ({ S::to_u8(s.as_pointer()) }); assert!(((a as i32) == (('A' as i8) as i32))); assert!(((b as i32) == ((66 as u8) as i32))); assert!( - ((({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - S::conversion_function_1( - >>::bind(s.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } as i32) - + ({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - S::conversion_function_2( - >>::bind(s.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } as i32)) + (((({ S::to_i8(s.as_pointer(),) }) as i32) + (({ S::to_u8(s.as_pointer(),) }) as i32)) == 131) ); let t: Value = Rc::new(RefCell::new(T { v: 3 })); - let mut c: i64 = { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - T::conversion_function_1( - >>::bind(t.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; - let mut d: i64 = { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - T::conversion_function_2( - >>::bind(t.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; + let mut c: i64 = ({ T::to_i64_1(t.as_pointer()) }); + let mut d: i64 = ({ T::to_i64_2(t.as_pointer()) }); assert!((c == 3_i64)); assert!((d == 4_i64)); return 0; diff --git a/tests/unit/out/refcount/copy_assign.rs b/tests/unit/out/refcount/copy_assign.rs index dfbec42db3..30df172004 100644 --- a/tests/unit/out/refcount/copy_assign.rs +++ b/tests/unit/out/refcount/copy_assign.rs @@ -19,7 +19,11 @@ thread_local!( MoveAssignable, Swappable, Default, + Conversions, )] +#[conversions(copy)] +#[constructor(constructor_1, i32, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(8)] pub struct Partial { #[offset(0)] @@ -28,13 +32,11 @@ pub struct Partial { pub keep: i32, } impl Partial { - pub fn construct(this: Ptr, mut v: i32, mut keep: i32) { + pub fn constructor_1(this: Ptr, mut v: i32, mut keep: i32) { field!(this, v).write(v); field!(this, keep).write(keep); } -} -impl CopyConstructible for Partial { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(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)); @@ -52,14 +54,28 @@ impl CopyAssignable for Partial { } } #[derive( - Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructible, Copyable, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + Destructible, + Copyable, + Conversions, )] +#[conversions(copy)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct NonConstAssign { #[offset(0)] pub mark: i32, } impl NonConstAssign { + pub fn constructor_1(this: Ptr) { + field!(this, mark).write(0); + } pub fn operator_assign_2(this: Ptr, o: Ptr) -> Ptr { field!(this, mark).write((o.with(|__s| __s.mark) + 1)); return (this).clone(); @@ -69,18 +85,13 @@ impl NonConstAssign { return (this).clone(); } } -impl DefaultConstructible for NonConstAssign { - fn default_constructor(this: Ptr) { - field!(this, mark).write(0); - } -} impl Default for NonConstAssign { fn default() -> Self { { { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + NonConstAssign::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -97,14 +108,17 @@ impl Default for NonConstAssign { Destructible, CopyConstructible, Movable, + Conversions, )] +#[conversions(copy)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct RefQualified { #[offset(0)] pub mark: i32, } -impl DefaultConstructible for RefQualified { - fn default_constructor(this: Ptr) { +impl RefQualified { + pub fn constructor_1(this: Ptr) { field!(this, mark).write(0); } } @@ -119,8 +133,9 @@ impl Default for RefQualified { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + RefQualified::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -130,6 +145,8 @@ impl Default for RefQualified { Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(24)] pub struct Holder { #[offset(0)] @@ -140,6 +157,7 @@ pub struct Holder { #[array_len(2)] pub arr: Box<[Partial]>, } +impl Holder {} impl Default for Holder { fn default() -> Self { { @@ -160,7 +178,6 @@ thread_local!( ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Memberwise, MoveConstructible, @@ -169,19 +186,20 @@ thread_local!( Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct CopyCounted { #[offset(0)] pub v: i32, } impl CopyCounted { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl CopyConstructible for CopyCounted { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(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(); @@ -191,6 +209,8 @@ impl CopyConstructible for CopyCounted { Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(12)] pub struct HasCopyCounted { #[offset(0)] @@ -201,6 +221,7 @@ pub struct HasCopyCounted { #[array_len(2)] pub arr: Box<[CopyCounted]>, } +impl HasCopyCounted {} impl Default for HasCopyCounted { fn default() -> Self { { @@ -224,13 +245,21 @@ impl Default for HasCopyCounted { CopyConstructible, Movable, Default, + Conversions, )] +#[conversions(copy)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct ExplicitOperatorCall { #[offset(0)] #[byte_size(24)] pub w: Vec, } +impl ExplicitOperatorCall { + pub fn constructor_1(this: Ptr) { + field!(this, w).write(Vec::new()); + } +} impl CopyAssignable for ExplicitOperatorCall { fn copy_assign( this: Ptr, @@ -245,11 +274,6 @@ impl CopyAssignable for ExplicitOperatorCall { return (this).clone(); } } -impl DefaultConstructible for ExplicitOperatorCall { - fn default_constructor(this: Ptr) { - field!(this, w).write(Vec::new()); - } -} thread_local!( pub static swap_copies_2: Value = Rc::new(RefCell::new(0)); ); @@ -258,34 +282,35 @@ thread_local!( ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, MoveConstructible, Swappable, Default, + Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct Swapped { #[offset(0)] pub v: i32, } impl Swapped { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } - pub fn copy_assign(this: Ptr, o: Ptr) -> Ptr { - let mut t: i32 = this.with(|__s| __s.v); + pub fn constructor_2(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); - field!(o, v).write(t); - return (this).clone(); + (*swap_copies_2.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl CopyConstructible for Swapped { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn copy_assign(this: Ptr, o: ParameterObject) -> Ptr { let o = o.as_pointer(); + let mut t: i32 = this.with(|__s| __s.v); field!(this, v).write(o.with(|__s| __s.v)); - (*swap_copies_2.with(Value::clone).borrow_mut()).prefix_inc(); + field!(o, v).write(t); + return (this).clone(); } } impl CopyAssignable for Swapped { @@ -313,12 +338,15 @@ impl MoveAssignable for Swapped { Default, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct HoldsSwapped { #[offset(0)] #[byte_size(4)] pub s: Swapped, } +impl HoldsSwapped {} #[derive( Copy, Clone, @@ -331,22 +359,23 @@ pub struct HoldsSwapped { CopyConstructible, MoveConstructible, Swappable, + Conversions, )] +#[conversions(copy)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct VoidAssign { #[offset(0)] pub x: i32, } impl VoidAssign { + pub fn constructor_1(this: Ptr) { + field!(this, x).write(0); + } pub fn copy_assign(this: Ptr, o: Ptr) { field!(this, x).write((o.with(|__s| __s.x) + 5)); } } -impl DefaultConstructible for VoidAssign { - fn default_constructor(this: Ptr) { - field!(this, x).write(0); - } -} impl CopyAssignable for VoidAssign { fn copy_assign(this: Ptr, src: LvalueRef>) -> Ptr { VoidAssign::copy_assign(this.clone(), src.as_pointer()); @@ -363,8 +392,8 @@ impl Default for VoidAssign { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + VoidAssign::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -385,15 +414,18 @@ impl Default for VoidAssign { Default, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct HoldsVoidAssign { #[offset(0)] #[byte_size(4)] pub v: VoidAssign, } -impl DefaultConstructible for HoldsVoidAssign { - fn default_constructor(this: Ptr) { - DefaultConstructible::default_constructor(field_ptr!(this, v)); +impl HoldsVoidAssign { + pub fn constructor_1(this: Ptr) { + VoidAssign::constructor_1(field_ptr!(this, v)); } } pub fn main() { @@ -401,9 +433,9 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, Partial(1, 100)); - object!(b, Partial(2, 200)); - object!(c, Partial(3, 300)); + object!(a, Partial::constructor_1(1, 100)); + object!(b, Partial::constructor_1(2, 200)); + object!(c, Partial::constructor_1(3, 300)); assign!(a = b); assert!(({ (*a.borrow()).v } == 2) && ({ (*a.borrow()).keep } == 100)); assert!((assigns_0.with(|rc| *rc.borrow()) == 1)); @@ -413,8 +445,8 @@ fn main_0() -> i32 { assign!(a = a); assert!((assigns_0.with(|rc| *rc.borrow()) == 3)); ({ - let _o: Value = Rc::new(RefCell::new(::zero_init())); - Partial::construct(_o.as_pointer(), 9, 900); + let _o: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Partial::constructor_1(_o.as_pointer(), 9, 900); assign!(a = _o) }); assert!(({ (*a.borrow()).v } == 9) && ({ (*a.borrow()).keep } == 100)); @@ -428,19 +460,19 @@ fn main_0() -> i32 { assert!((assigns_0.with(|rc| *rc.borrow()) == 6)); let h: Value = Rc::new(RefCell::new(Holder { p: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Partial::construct(__v.as_pointer(), 4, 40); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Partial::constructor_1(__v.as_pointer(), 4, 40); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, arr: Box::new([ { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Partial::construct(__v.as_pointer(), 5, 50); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Partial::constructor_1(__v.as_pointer(), 5, 50); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Partial::construct(__v.as_pointer(), 6, 60); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Partial::constructor_1(__v.as_pointer(), 6, 60); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]), @@ -453,33 +485,33 @@ fn main_0() -> i32 { && (array_elem!(h.as_pointer(), arr, 1).with(|__s| __s.keep) == 60) ); assert!((assigns_0.with(|rc| *rc.borrow()) == 8)); - object!(n, NonConstAssign); - object!(n1, NonConstAssign); - object!(n2, NonConstAssign); - object!(cn, NonConstAssign); + object!(n, NonConstAssign::constructor_1()); + object!(n1, NonConstAssign::constructor_1()); + object!(n2, NonConstAssign::constructor_1()); + object!(cn, NonConstAssign::constructor_1()); NonConstAssign::operator_assign_2(n1.as_pointer(), n.as_pointer()); NonConstAssign::operator_assign_3(n2.as_pointer(), cn.as_pointer()); assert!(({ (*n1.borrow()).mark } == 1)); assert!(({ (*n2.borrow()).mark } == 10)); - object!(r, RefQualified); - object!(r1, RefQualified); + object!(r, RefQualified::constructor_1()); + object!(r1, RefQualified::constructor_1()); assign!(r1 = r); assert!(({ (*r1.borrow()).mark } == 1)); let h2: Value = Rc::new(RefCell::new(Holder { p: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Partial::construct(__v.as_pointer(), 7, 70); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Partial::constructor_1(__v.as_pointer(), 7, 70); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, arr: Box::new([ { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Partial::construct(__v.as_pointer(), 8, 80); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Partial::constructor_1(__v.as_pointer(), 8, 80); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Partial::construct(__v.as_pointer(), 9, 90); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Partial::constructor_1(__v.as_pointer(), 9, 90); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]), @@ -491,44 +523,48 @@ fn main_0() -> i32 { && (array_elem!(h2.as_pointer(), arr, 1).with(|__s| __s.keep) == 90) ); assert!((assigns_0.with(|rc| *rc.borrow()) == 11)); - object!(cc1, CopyCounted(1)); - object!(cc2, CopyCounted(2)); + object!(cc1, CopyCounted::constructor_1(1)); + object!(cc2, CopyCounted::constructor_1(2)); assign!(cc1 = cc2); assert!(({ (*cc1.borrow()).v } == 2)); let hc1: Value = Rc::new(RefCell::new(HasCopyCounted { c: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyCounted::construct(__v.as_pointer(), 1); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CopyCounted::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, arr: Box::new([ { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyCounted::construct(__v.as_pointer(), 2); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CopyCounted::constructor_1(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyCounted::construct(__v.as_pointer(), 3); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CopyCounted::constructor_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]), })); let hc2: Value = Rc::new(RefCell::new(HasCopyCounted { c: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyCounted::construct(__v.as_pointer(), 4); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CopyCounted::constructor_1(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, arr: Box::new([ { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyCounted::construct(__v.as_pointer(), 5); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CopyCounted::constructor_1(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyCounted::construct(__v.as_pointer(), 6); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CopyCounted::constructor_1(__v.as_pointer(), 6); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]), @@ -540,8 +576,8 @@ fn main_0() -> i32 { && (array_elem!(hc1.as_pointer(), arr, 1).with(|__s| __s.v) == 6) ); assert!((copies_1.with(|rc| *rc.borrow()) == 0)); - object!(e1, ExplicitOperatorCall); - object!(e2, ExplicitOperatorCall); + object!(e1, ExplicitOperatorCall::constructor_1()); + object!(e2, ExplicitOperatorCall::constructor_1()); ({ let __tmp_1: Value = Rc::new(RefCell::new(5)); MoveConstructible::push_moved( @@ -557,32 +593,32 @@ fn main_0() -> i32 { && ((*e1.borrow()).w.len() == 1_usize) }) ); - object!(sw1, Swapped(1)); - object!(sw2, Swapped(2)); + object!(sw1, Swapped::constructor_1(1)); + object!(sw2, Swapped::constructor_1(2)); ({ - let _o: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor(_o.as_pointer(), LvalueRef::bind(sw2.as_pointer())); - Swapped::copy_assign(sw1.as_pointer(), _o.as_pointer()) + let _o: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Swapped::constructor_2(_o.as_pointer(), LvalueRef::bind(sw2.as_pointer())); + Swapped::copy_assign(sw1.as_pointer(), ParameterObject::bind(_o.as_pointer())) }); assert!(({ (*sw1.borrow()).v } == 2) && (swap_copies_2.with(|rc| *rc.borrow()) == 1)); let hs1: Value = Rc::new(RefCell::new(HoldsSwapped { s: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Swapped::construct(__v.as_pointer(), 3); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Swapped::constructor_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); let hs2: Value = Rc::new(RefCell::new(HoldsSwapped { s: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Swapped::construct(__v.as_pointer(), 4); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Swapped::constructor_1(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); assign!(hs1 = hs2); assert!(({ (*hs1.borrow()).s.v } == 4) && (swap_copies_2.with(|rc| *rc.borrow()) == 2)); - object!(hv1, HoldsVoidAssign); - object!(hv2, HoldsVoidAssign); + object!(hv1, HoldsVoidAssign::constructor_1()); + object!(hv2, HoldsVoidAssign::constructor_1()); assign!(hv1 = hv2); assert!(({ (*hv1.borrow()).v.x } == 5)); return 0; diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index f1c9d161c8..2d2acedaea 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -14,7 +14,6 @@ thread_local!( ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Memberwise, MoveConstructible, @@ -23,19 +22,20 @@ thread_local!( Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct Counted { #[offset(0)] pub v: i32, } impl Counted { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl CopyConstructible for Counted { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(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(); @@ -45,30 +45,35 @@ impl CopyConstructible for Counted { Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, MoveAssignable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef)] +#[constructor(constructor_3, LvalueRef>)] #[byte_size(4)] pub struct NonConst { #[offset(0)] pub mark: i32, } impl NonConst { - pub fn construct_1(this: Ptr, o: Ptr) { + pub fn constructor_1(this: Ptr) { + field!(this, mark).write(0); + } + pub fn constructor_2(this: Ptr, o: LvalueRef) { + let o = o.as_pointer(); field!(this, mark).write((o.with(|__s| __s.mark) + 1)); } - pub fn construct_2(this: Ptr, o: Ptr) { + pub fn constructor_3(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); field!(this, mark).write((o.with(|__s| __s.mark) + 10)); } } -impl DefaultConstructible for NonConst { - fn default_constructor(this: Ptr) { - field!(this, mark).write(0); - } -} impl Default for NonConst { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + NonConst::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -79,7 +84,6 @@ impl Default for NonConst { ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Memberwise, MoveConstructible, @@ -88,19 +92,20 @@ impl Default for NonConst { Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct Ignored { #[offset(0)] pub v: i32, } impl Ignored { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl CopyConstructible for Ignored { - fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); field!(this, v).write(-1_i32); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); @@ -110,6 +115,8 @@ impl CopyConstructible for Ignored { Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(12)] pub struct Holder { #[offset(0)] @@ -120,6 +127,7 @@ pub struct Holder { #[array_len(2)] pub arr: Box<[Counted]>, } +impl Holder {} impl Default for Holder { fn default() -> Self { { @@ -133,29 +141,23 @@ impl Default for Holder { } } #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - CppFrom, - DefaultInitializable, - Memberwise, - Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, )] #[memberwise(move_constructor)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct Box_int_ { #[offset(0)] pub val: i32, } impl Box_int_ { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, val).write(v); } -} -impl CopyConstructible for Box_int_ { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); field!(this, val).write(o.with(|__s| __s.val)); } @@ -164,18 +166,20 @@ impl CopyConstructible for Box_int_ { Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, )] #[memberwise(copy_constructor, move_constructor)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct Owner { #[offset(0)] #[byte_size(4)] pub box_: Box_int_, } +impl Owner {} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Memberwise, MoveConstructible, @@ -184,24 +188,26 @@ pub struct Owner { Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct OutOfLine { #[offset(0)] pub v: i32, } impl OutOfLine { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl CopyConstructible for OutOfLine { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(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(); } } +impl OutOfLine {} #[derive( Record, ByteRepr, @@ -211,19 +217,21 @@ impl CopyConstructible for OutOfLine { MoveConstructible, MoveAssignable, Swappable, + Conversions, )] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct Tracked { #[offset(0)] pub copied_from: i32, } -impl DefaultConstructible for Tracked { - fn default_constructor(this: Ptr) { +impl Tracked { + pub fn constructor_1(this: Ptr) { field!(this, copied_from).write(0); } -} -impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); field!(this, copied_from).write(0); field!(o, copied_from).with_mut(|__v| { @@ -250,34 +258,35 @@ pub fn touch_1(mut t: Ptr) { __v.prefix_inc(); }); } -pub fn by_value_2(c: Ptr) -> i32 { +pub fn by_value_2(c: ParameterObject) -> i32 { + let c = c.as_pointer(); return c.with(|__s| __s.v); } pub fn make_3(__return: Ptr, mut v: i32) { - object!(c, Counted(v)); - CopyConstructible::copy_constructor(__return.clone(), LvalueRef::bind(c.as_pointer())); + object!(c, Counted::constructor_1(v)); + Counted::constructor_2(__return.clone(), LvalueRef::bind(c.as_pointer())); return; } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(8)] pub struct SelfPtr { #[offset(0)] #[byte_size(8)] pub self_: Ptr, } -impl DefaultConstructible for SelfPtr { - fn default_constructor(this: Ptr) { +impl SelfPtr { + pub fn constructor_1(this: Ptr) { field!(this, self_).write((this).clone()); } -} -impl CopyConstructible for SelfPtr { - fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + pub fn constructor_2(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: RvalueRef) { + pub fn constructor_3(this: Ptr, _a0: RvalueRef) { let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); } @@ -286,8 +295,8 @@ impl Default for SelfPtr { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + SelfPtr::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -304,28 +313,33 @@ impl Default for SelfPtr { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct EmptyBase {} #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct Derived { #[offset(0)] #[byte_size(4)] pub c: Counted, } -impl DefaultConstructible for Derived { - fn default_constructor(this: Ptr) { - Counted::construct(field_ptr!(this, c), 20); +impl Derived { + pub fn constructor_1(this: Ptr) { + Counted::constructor_1(field_ptr!(this, c), 20); } } impl Default for Derived { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Derived::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -336,52 +350,57 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, Counted(1)); - object!(b, Counted, LvalueRef::bind(a.as_pointer())); - object!(c, Counted, LvalueRef::bind(a.as_pointer())); - object!(d, Counted, LvalueRef::bind(a.as_pointer())); + object!(a, Counted::constructor_1(1)); + object!(b, Counted::constructor_2(LvalueRef::bind(a.as_pointer()))); + object!(c, Counted::constructor_2(LvalueRef::bind(a.as_pointer()))); + object!(d, Counted::constructor_2(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) ); assert!( (({ - let _c: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor(_c.as_pointer(), LvalueRef::bind(a.as_pointer())); - by_value_2(_c.as_pointer()) + let _c: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_2(_c.as_pointer(), LvalueRef::bind(a.as_pointer())); + by_value_2(ParameterObject::bind(_c.as_pointer())) }) == 1) ); assert!((copies_0.with(|rc| *rc.borrow()) == 4)); object!(e, Counted, |e| ({ make_3(Ptr::clone(&e.clone()), 5,) })); assert!(({ (*e.borrow()).v } == 5)); assert!((copies_0.with(|rc| *rc.borrow()) == 5)); - object!(f, Counted(6)); + object!(f, Counted::constructor_1(6)); assert!(({ (*f.borrow()).v } == 6)); assert!((copies_0.with(|rc| *rc.borrow()) == 5)); - object!(g, Counted(7)); - object!(h, Counted, LvalueRef::bind(g.as_pointer())); + object!(g, Counted::constructor_1(7)); + object!(h, Counted::constructor_2(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 { c: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Counted::construct(__v.as_pointer(), 8); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_1(__v.as_pointer(), 8); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, arr: Box::new([ { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Counted::construct(__v.as_pointer(), 9); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_1(__v.as_pointer(), 9); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Counted::construct(__v.as_pointer(), 10); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_1(__v.as_pointer(), 10); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]), })); - object!(hold2, Holder, LvalueRef::bind(hold.as_pointer())); + object!(hold2, Holder, |hold2| { + ::copy_constructor( + hold2.clone(), + LvalueRef::bind(hold.as_pointer()), + ) + }); assert!( (({ (*hold2.borrow()).c.v } == 8) && (array_elem!(hold2.as_pointer(), arr, 0).with(|__s| __s.v) == 9)) @@ -392,54 +411,72 @@ fn main_0() -> i32 { CopyConstructible::push_copied(&vec_.as_pointer(), a.as_pointer()); assert!(({ (*vec_.borrow())[0_usize].v } == 1)); assert!((copies_0.with(|rc| *rc.borrow()) == 10)); - object!(i1, Ignored(1)); - object!(i2, Ignored, LvalueRef::bind(i1.as_pointer())); + object!(i1, Ignored::constructor_1(1)); + object!(i2, Ignored::constructor_2(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 { box_: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Box_int_::construct(__v.as_pointer(), 3); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Box_int_::constructor_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); - object!(o2, Owner, RvalueRef::bind(o.as_pointer())); + object!(o2, Owner, |o2| { + ::move_constructor(o2.clone(), RvalueRef::bind(o.as_pointer())) + }); assert!(({ (*o2.borrow()).box_.val } == 3)); - object!(ol1, OutOfLine(5)); - object!(ol2, OutOfLine, LvalueRef::bind(ol1.as_pointer())); + object!(ol1, OutOfLine::constructor_1(5)); + object!( + ol2, + OutOfLine::constructor_2(LvalueRef::bind(ol1.as_pointer())) + ); assert!(({ (*ol2.borrow()).v } == 105)); assert!((copies_0.with(|rc| *rc.borrow()) == 12)); - object!(n, NonConst); - object!(n1, NonConst::construct_1(n.as_pointer())); - object!(cn, NonConst); - object!(n2, NonConst::construct_2(cn.as_pointer())); + object!(n, NonConst::constructor_1()); + object!(n1, NonConst::constructor_2(LvalueRef::bind(n.as_pointer()))); + object!(cn, NonConst::constructor_1()); + object!( + n2, + NonConst::constructor_3(LvalueRef::bind(cn.as_pointer())) + ); assert!(({ (*n1.borrow()).mark } == 1)); assert!(({ (*n2.borrow()).mark } == 10)); - object!(t1, Tracked); - object!(t2, Tracked, LvalueRef::bind(t1.as_pointer())); + object!(t1, Tracked::constructor_1()); + object!(t2, Tracked::constructor_2(LvalueRef::bind(t1.as_pointer()))); assign!(t2 = t1); assert!(({ (*t1.borrow()).copied_from } == 2)); - object!(ct, Tracked); - object!(t3, Tracked, LvalueRef::bind(ct.as_pointer())); + object!(ct, Tracked::constructor_1()); + object!(t3, Tracked::constructor_2(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, LvalueRef::bind(der.as_pointer())); + object!(der, Derived::constructor_1()); + object!(der2, Derived, |der2| { + ::copy_constructor( + der2.clone(), + LvalueRef::bind(der.as_pointer()), + ) + }); assert!(({ (*der2.borrow()).c.v } == 20) && (copies_0.with(|rc| *rc.borrow()) == (before + 1))); let mut range: Vec = { - let mut __v = Vec::new(); + let __v: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new(vec_.decay().begin())); let __last: Value> = Rc::new(RefCell::new(vec_.decay().end())); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - __v.push(>::cpp_from( - __it.borrow().iter_deref(), - )); + let __i = __v.borrow().len(); + __v.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + __v.as_pointer().decay().offset(__i), + (LvalueRef::>::bind( + __it.borrow().iter_deref(), + ),), + ); __it.borrow_mut().iter_inc(); } - __v + Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!((range[0_usize].v == 1) && (copies_0.with(|rc| *rc.borrow()) == (before + 2))); let selfs: Value> = Rc::new(RefCell::new(Vec::new())); @@ -450,16 +487,16 @@ fn main_0() -> i32 { } }); { - let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - DefaultConstructible::default_constructor(__tmp_1.as_pointer()); + SelfPtr::constructor_1(__tmp_1.as_pointer()); __tmp_1.as_pointer() },) { (__tmp_0,) => MoveConstructible::push_moved(&selfs.as_pointer(), (__tmp_0).clone()), } }; - object!(self_src, SelfPtr); + object!(self_src, SelfPtr::constructor_1()); CopyConstructible::push_copied(&selfs.as_pointer(), self_src.as_pointer()); assert!( ({ { (*selfs.borrow())[0_usize].self_.clone() } } == { (selfs.decay().offset(0_usize)) }) @@ -475,9 +512,9 @@ fn main_0() -> i32 { } }); { - let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_3: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - Counted::construct(__tmp_3.as_pointer(), 30); + Counted::constructor_1(__tmp_3.as_pointer(), 30); __tmp_3.as_pointer() },) { diff --git a/tests/unit/out/refcount/copy_move_defaulted.rs b/tests/unit/out/refcount/copy_move_defaulted.rs index 5c66db8525..99e7082ee2 100644 --- a/tests/unit/out/refcount/copy_move_defaulted.rs +++ b/tests/unit/out/refcount/copy_move_defaulted.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Inner { #[offset(0)] @@ -30,7 +32,6 @@ pub struct Inner { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, Memberwise, CopyConstructible, @@ -38,7 +39,9 @@ pub struct Inner { Swappable, )] #[memberwise(copy_assign, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] #[byte_size(16)] pub struct Explicit { #[offset(0)] @@ -52,7 +55,7 @@ pub struct Explicit { pub arr: Box<[i32]>, } impl Explicit { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); field!(this, inner).write(Inner { x: (v * 10) }); field!(this, arr).write(Box::new([v, (v + 1)])); @@ -70,7 +73,9 @@ impl Destructible for Explicit { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct Implicit { #[offset(0)] @@ -102,7 +107,6 @@ impl Default for Implicit { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultInitializable, Memberwise, CopyConstructible, @@ -110,19 +114,20 @@ impl Default for Implicit { Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct DefaultCopyUserMove { #[offset(0)] pub v: i32, } impl DefaultCopyUserMove { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl MoveConstructible for DefaultCopyUserMove { - fn move_constructor(this: Ptr, o: RvalueRef) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); @@ -141,26 +146,26 @@ impl MoveAssignable for DefaultCopyUserMove { ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Memberwise, Swappable, Default, )] #[memberwise(move_constructor, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct UserCopyDefaultMove { #[offset(0)] pub v: i32, } impl UserCopyDefaultMove { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl CopyConstructible for UserCopyDefaultMove { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, o: LvalueRef>) { let o = o.as_pointer(); field!(this, v).write((o.with(|__s| __s.v) + 100)); } @@ -176,17 +181,12 @@ impl CopyAssignable for UserCopyDefaultMove { } } #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - CppFrom, - DefaultInitializable, - Memberwise, - Swappable, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] #[memberwise(move_constructor, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1, i32)] #[byte_size(64)] pub struct Buffer { #[offset(0)] @@ -203,7 +203,7 @@ pub struct Buffer { pub arr: Box<[i32]>, } impl Buffer { - pub fn construct(this: Ptr, n: i32) { + pub fn constructor_1(this: Ptr, n: i32) { let n: Value = Rc::new(RefCell::new(n)); field!(this, data).write( (0..({ ((*n.borrow()) as usize) })) @@ -226,6 +226,9 @@ impl Default for Buffer { } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(move_constructor, move_assign)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(48)] pub struct Owner { #[offset(0)] @@ -241,8 +244,8 @@ pub struct Owner { #[byte_size(8)] pub p: Option>, } -impl DefaultConstructible for Owner { - fn default_constructor(this: Ptr) { +impl Owner { + pub fn constructor_1(this: Ptr) { field!(this, data).write(Vec::new()); field!(this, n).write(0_i32); field!(this, arr).write((0..2).map(|_| 0_i32).collect::>()); @@ -275,29 +278,27 @@ impl Default for Owner { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct Copyable { #[offset(0)] #[byte_size(24)] pub data: Vec, } -impl DefaultConstructible for Copyable { - fn default_constructor(this: Ptr) { +impl Copyable { + pub fn constructor_1(this: Ptr) { field!(this, data).write(Vec::new()); } } #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - CppFrom, - DefaultInitializable, - Memberwise, - Swappable, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] #[memberwise(move_constructor, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1, i32)] #[byte_size(32)] pub struct Holder { #[offset(0)] @@ -312,9 +313,9 @@ pub struct Holder { pub p: Option>, } impl Holder { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, inner).write(Inner { x: v }); - Explicit::construct(field_ptr!(this, e), v); + Explicit::constructor_1(field_ptr!(this, e), v); field!(this, p).write(None); } } @@ -324,13 +325,19 @@ pub fn same_0(a: Ptr, b: Ptr) -> bool { && ({ (array_elem!(a, arr, 0).read()) } == { (array_elem!(b, arr, 0).read()) })) && ({ (array_elem!(a, arr, 1).read()) } == { (array_elem!(b, arr, 1).read()) }); } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct SeesThis { #[offset(0)] #[byte_size(8)] pub self_: Ptr, } +impl SeesThis { + pub fn constructor_1(this: Ptr) { + field!(this, self_).write(Ptr::::null()); + } +} impl CopyAssignable for SeesThis { fn copy_assign(this: Ptr, _a0: LvalueRef>) -> Ptr { let _a0 = _a0.as_pointer(); @@ -345,11 +352,6 @@ impl MoveAssignable for SeesThis { return (this).clone(); } } -impl DefaultConstructible for SeesThis { - fn default_constructor(this: Ptr) { - field!(this, self_).write(Ptr::::null()); - } -} impl Default for SeesThis { fn default() -> Self { { @@ -361,6 +363,8 @@ impl Default for SeesThis { } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Default)] #[memberwise(copy_assign, move_assign)] +#[derive(Conversions)] +#[constructor(constructor_1)] #[byte_size(32)] pub struct HasSeesThis { #[offset(0)] @@ -370,13 +374,16 @@ pub struct HasSeesThis { #[byte_size(24)] pub v: Vec, } -impl DefaultConstructible for HasSeesThis { - fn default_constructor(this: Ptr) { - DefaultConstructible::default_constructor(field_ptr!(this, s)); +impl HasSeesThis { + pub fn constructor_1(this: Ptr) { + SeesThis::constructor_1(field_ptr!(this, s)); field!(this, v).write(Vec::new()); } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Conversions)] +#[conversions(move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, RvalueRef)] #[byte_size(8)] pub struct Counted_int_ { #[offset(0)] @@ -384,14 +391,12 @@ pub struct Counted_int_ { #[offset(4)] pub moves: i32, } -impl DefaultConstructible for Counted_int_ { - fn default_constructor(this: Ptr) { +impl Counted_int_ { + pub fn constructor_1(this: Ptr) { field!(this, v).write(0_i32); field!(this, moves).write(0); } -} -impl MoveConstructible for Counted_int_ { - fn move_constructor(this: Ptr, o: RvalueRef) { + pub fn constructor_2(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)); @@ -414,6 +419,9 @@ impl Default for Counted_int_ { Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(32)] pub struct HasCounted { #[offset(0)] @@ -423,14 +431,18 @@ pub struct HasCounted { #[byte_size(24)] pub w: Vec, } -impl DefaultConstructible for HasCounted { - fn default_constructor(this: Ptr) { - DefaultConstructible::default_constructor(field_ptr!(this, c)); +impl HasCounted { + pub fn constructor_1(this: Ptr) { + Counted_int_::constructor_1(field_ptr!(this, c)); field!(this, w).write(Vec::new()); } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Swappable)] -#[cpp_from(i32, construct_1, value)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, i32)] +#[constructor(constructor_3, LvalueRef>)] +#[constructor(constructor_4, RvalueRef)] #[byte_size(16)] pub struct CtorSeesThis { #[offset(0)] @@ -440,26 +452,20 @@ pub struct CtorSeesThis { pub id: i32, } impl CtorSeesThis { - pub fn construct_1(this: Ptr, mut id: i32) { - DefaultConstructible::default_constructor(this.clone()); - field!(this, id).write(id); - } -} -impl DefaultConstructible for CtorSeesThis { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, self_).write((this).clone()); field!(this, id).write(0); } -} -impl CopyConstructible for CtorSeesThis { - fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + pub fn constructor_2(this: Ptr, mut id: i32) { + CtorSeesThis::constructor_1(this.clone()); + field!(this, id).write(id); + } + pub fn constructor_3(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: RvalueRef) { + pub fn constructor_4(this: Ptr, _a0: RvalueRef) { let _a0 = _a0.as_pointer(); field!(this, self_).write((this).clone()); field!(this, id).write(0); @@ -481,8 +487,9 @@ impl Default for CtorSeesThis { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CtorSeesThis::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -492,6 +499,9 @@ impl Default for CtorSeesThis { Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(40)] pub struct HasCtorSeesThis { #[offset(0)] @@ -501,14 +511,17 @@ pub struct HasCtorSeesThis { #[byte_size(24)] pub v: Vec, } -impl DefaultConstructible for HasCtorSeesThis { - fn default_constructor(this: Ptr) { - DefaultConstructible::default_constructor(field_ptr!(this, x)); +impl HasCtorSeesThis { + pub fn constructor_1(this: Ptr) { + CtorSeesThis::constructor_1(field_ptr!(this, x)); field!(this, v).write(Vec::new()); } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(32)] pub struct InitsCtorSeesThis { #[offset(0)] @@ -518,10 +531,10 @@ pub struct InitsCtorSeesThis { #[byte_size(16)] pub y: CtorSeesThis, } -impl DefaultConstructible for InitsCtorSeesThis { - fn default_constructor(this: Ptr) { - CtorSeesThis::construct_1(field_ptr!(this, x), 1); - CtorSeesThis::construct_1(field_ptr!(this, y), 2); +impl InitsCtorSeesThis { + pub fn constructor_1(this: Ptr) { + CtorSeesThis::constructor_2(field_ptr!(this, x), 1); + CtorSeesThis::constructor_2(field_ptr!(this, y), 2); } } impl Default for InitsCtorSeesThis { @@ -529,8 +542,8 @@ impl Default for InitsCtorSeesThis { { { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + InitsCtorSeesThis::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -548,6 +561,9 @@ impl Default for InitsCtorSeesThis { Swappable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(24)] pub struct OutOfLineDefaulted { #[offset(0)] @@ -558,22 +574,17 @@ pub struct OutOfLineDefaulted { } impl OutOfLineDefaulted { pub fn construct(this: Ptr) { - DefaultConstructible::default_constructor(field_ptr!(this, x)); + CtorSeesThis::constructor_1(field_ptr!(this, x)); field!(this, v).write(1); } -} -impl CopyConstructible for OutOfLineDefaulted { - fn copy_constructor(this: Ptr, _a0: LvalueRef>) { + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); - CopyConstructible::copy_constructor( - field_ptr!(this, x), - LvalueRef::bind(field_ptr!(_a0, x)), - ); + CtorSeesThis::constructor_3(field_ptr!(this, x), LvalueRef::bind(field_ptr!(_a0, x))); field!(this, v).write(_a0.with(|__s| __s.v)); } } -impl DefaultConstructible for OutOfLineDefaulted { - fn default_constructor(this: Ptr) { +impl Constructor<()> for OutOfLineDefaulted { + fn constructor(this: Ptr, _: ()) { { OutOfLineDefaulted::construct(this.clone()); } @@ -584,7 +595,7 @@ impl Default for OutOfLineDefaulted { { { let __v: Value = - Rc::new(RefCell::new(::zero_init())); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); OutOfLineDefaulted::construct(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } @@ -592,7 +603,9 @@ impl Default for OutOfLineDefaulted { } } impl OutOfLineDefaulted {} -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] +impl OutOfLineDefaulted {} +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] +#[constructor(constructor_1)] #[byte_size(40)] pub struct OutOfLineAssign { #[offset(0)] @@ -604,9 +617,9 @@ pub struct OutOfLineAssign { #[byte_size(24)] pub w: Vec, } -impl DefaultConstructible for OutOfLineAssign { - fn default_constructor(this: Ptr) { - DefaultConstructible::default_constructor(field_ptr!(this, s)); +impl OutOfLineAssign { + pub fn constructor_1(this: Ptr) { + SeesThis::constructor_1(field_ptr!(this, s)); field!(this, v).write(1); field!(this, w).write(Vec::new()); } @@ -654,7 +667,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, Explicit(1)); + object!(a, Explicit::constructor_1(1)); let b: Value = Rc::new(RefCell::new((*a.borrow()).clone())); let _dtor_b = std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(__p.as_pointer())); @@ -669,15 +682,15 @@ fn main_0() -> i32 { && ({ same_0(c.as_pointer(), a.as_pointer(),) })) && ({ same_0(d.as_pointer(), a.as_pointer(),) }) ); - object!(e, Explicit(2)); - object!(f, Explicit(3)); + object!(e, Explicit::constructor_1(2)); + object!(f, Explicit::constructor_1(3)); assign!(e = b); assign!(f = RvalueRef(c)); assert!( ({ same_0(e.as_pointer(), b.as_pointer(),) }) && ({ same_0(f.as_pointer(), c.as_pointer(),) }) ); - object!(g, Explicit(4)); + object!(g, Explicit::constructor_1(4)); assign!(g = *assign!(e = f)); assert!( ({ same_0(g.as_pointer(), f.as_pointer(),) }) @@ -702,8 +715,8 @@ fn main_0() -> i32 { let vec_: Value> = Rc::new(RefCell::new(Vec::new())); CopyConstructible::push_copied(&vec_.as_pointer(), b.as_pointer()); match (Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Explicit::construct(__v.as_pointer(), 9); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Explicit::constructor_1(__v.as_pointer(), 9); Rc::try_unwrap(__v).ok().unwrap().into_inner() })) .as_pointer(),) @@ -711,33 +724,46 @@ fn main_0() -> i32 { (__tmp_1,) => MoveConstructible::push_moved(&vec_.as_pointer(), (__tmp_1).clone()), }; assert!(({ (*vec_.borrow())[0_usize].v } == 1) && ({ (*vec_.borrow())[1_usize].v } == 9)); - object!(m, DefaultCopyUserMove(7)); + object!(m, DefaultCopyUserMove::constructor_1(7)); let m1: Value = Rc::new(RefCell::new((*m.borrow()))); - object!(m2, DefaultCopyUserMove, RvalueRef::bind(m.as_pointer())); + object!( + m2, + DefaultCopyUserMove::constructor_3(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)); + object!(m3, DefaultCopyUserMove::constructor_1(1)); + object!(m4, DefaultCopyUserMove::constructor_1(1)); assign!(m3 = 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, LvalueRef::bind(u.as_pointer())); - object!(u2, UserCopyDefaultMove, RvalueRef::bind(u.as_pointer())); + object!(u, UserCopyDefaultMove::constructor_1(8)); + object!( + u1, + UserCopyDefaultMove::constructor_2(LvalueRef::bind(u.as_pointer())) + ); + object!(u2, UserCopyDefaultMove, |u2| { + ::move_constructor( + u2.clone(), + RvalueRef::bind(u.as_pointer()), + ) + }); assert!( (({ (*u1.borrow()).v } == 108) && ({ (*u2.borrow()).v } == 8)) && ({ (*u.borrow()).v } == 8) ); - object!(u3, UserCopyDefaultMove(1)); - object!(u4, UserCopyDefaultMove(1)); + object!(u3, UserCopyDefaultMove::constructor_1(1)); + object!(u4, UserCopyDefaultMove::constructor_1(1)); assign!(u3 = u2); assign!(u4 = RvalueRef(u2)); assert!(({ (*u3.borrow()).v } == 108) && ({ (*u4.borrow()).v } == 8)); - object!(p, Buffer(3)); - object!(q, Buffer, RvalueRef::bind(p.as_pointer())); + object!(p, Buffer::constructor_1(3)); + object!(q, Buffer, |q| { + ::move_constructor(q.clone(), RvalueRef::bind(p.as_pointer())) + }); assert!( ({ ((({ (*q.borrow()).n } == 3) && ((*q.borrow()).data.len() == 3_usize)) @@ -745,7 +771,7 @@ fn main_0() -> i32 { && ((*p.borrow()).data.is_empty()) }) ); - object!(r, Buffer(1)); + object!(r, Buffer::constructor_1(1)); assign!(r = RvalueRef(q)); assert!( ({ @@ -772,8 +798,8 @@ fn main_0() -> i32 { { let mut __tmp_2 = { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor( + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + ::move_constructor( __v.as_pointer(), RvalueRef::bind(bufs.decay().offset(0_usize)), ); @@ -789,7 +815,7 @@ fn main_0() -> i32 { && ((*bufs.borrow())[0_usize].data.is_empty()) }) ); - object!(o1, Owner); + object!(o1, Owner::constructor_1()); ({ let __tmp_3: Value = Rc::new(RefCell::new(5)); MoveConstructible::push_moved( @@ -801,7 +827,9 @@ 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, RvalueRef::bind(o1.as_pointer())); + object!(o2, Owner, |o2| { + ::move_constructor(o2.clone(), RvalueRef::bind(o1.as_pointer())) + }); assert!( ({ ((({ (*o2.borrow()).n } == 5) && ((*o2.borrow()).data.len() == 1_usize)) @@ -815,7 +843,7 @@ fn main_0() -> i32 { && (({ (*o1.borrow()).p.clone() }.as_pointer()).is_null()) }) ); - object!(o3, Owner); + object!(o3, Owner::constructor_1()); assign!(o3 = RvalueRef(o2)); assert!( ((({ (*o3.borrow()).n } == 5) @@ -833,10 +861,15 @@ fn main_0() -> i32 { data: Vec::from([1, 2]), })); let mut c2: Copyable = (*c1.borrow()).clone(); - object!(c3, Copyable, RvalueRef::bind(c1.as_pointer())); + object!(c3, Copyable, |c3| { + ::move_constructor( + c3.clone(), + 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); + object!(c4, Copyable::constructor_1()); assign!(c4 = RvalueRef(c3)); assert!( ({ @@ -844,15 +877,20 @@ fn main_0() -> i32 { && ((*c3.borrow()).data.is_empty()) }) ); - object!(h1, Holder(4)); + object!(h1, Holder::constructor_1(4)); field_ptr!(h1.as_pointer(), p).write(Ptr::alloc(9).to_owned_opt()); - object!(h2, Holder, RvalueRef::bind(h1.as_pointer())); + object!(h2, Holder, |h2| { + ::move_constructor( + h2.clone(), + 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)); + object!(h3, Holder::constructor_1(1)); assign!(h3 = RvalueRef(h2)); assert!( ((({ (*h3.borrow()).inner.x } == 4) @@ -860,40 +898,58 @@ fn main_0() -> i32 { && (({ (*h3.borrow()).p.clone() }.as_pointer().read()) == 9)) && (({ (*h2.borrow()).p.clone() }.as_pointer()).is_null()) ); - object!(t1, HasSeesThis); - object!(t2, HasSeesThis); - object!(t3, HasSeesThis); + object!(t1, HasSeesThis::constructor_1()); + object!(t2, HasSeesThis::constructor_1()); + object!(t3, HasSeesThis::constructor_1()); 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, RvalueRef::bind(k1.as_pointer())); + object!(k1, HasCounted::constructor_1()); + object!(k2, HasCounted, |k2| { + ::move_constructor( + k2.clone(), + RvalueRef::bind(k1.as_pointer()), + ) + }); assert!(({ (*k2.borrow()).c.moves } == 1)); - object!(k3, HasCounted); + object!(k3, HasCounted::constructor_1()); assign!(k3 = RvalueRef(k2)); assert!(({ (*k3.borrow()).c.moves } == 2)); { - object!(d, CtorSeesThis); + object!(d, CtorSeesThis::constructor_1()); assert!(({ { (*d.borrow()).self_.clone() } } == { (d.as_pointer()) })); - object!(e, CtorSeesThis, LvalueRef::bind(d.as_pointer())); + object!( + e, + CtorSeesThis::constructor_3(LvalueRef::bind(d.as_pointer())) + ); assert!(({ { (*e.borrow()).self_.clone() } } == { (e.as_pointer()) })); - object!(f, CtorSeesThis::construct_1(3)); + object!(f, CtorSeesThis::constructor_2(3)); assert!( ({ { (*f.borrow()).self_.clone() } } == { (f.as_pointer()) }) && ({ (*f.borrow()).id } == 3) ); - object!(h1, HasCtorSeesThis); + object!(h1, HasCtorSeesThis::constructor_1()); assert!(({ { (*h1.borrow()).x.self_.clone() } } == { (field_ptr!(h1.as_pointer(), x)) })); - object!(h2, HasCtorSeesThis, LvalueRef::bind(h1.as_pointer())); + object!(h2, HasCtorSeesThis, |h2| { + ::copy_constructor( + h2.clone(), + 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())); + object!(h3, HasCtorSeesThis, |h3| { + ::move_constructor( + h3.clone(), + RvalueRef::bind(h1.as_pointer()), + ) + }); assert!(({ { (*h3.borrow()).x.self_.clone() } } == { (field_ptr!(h3.as_pointer(), x)) })); 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)) })); - object!(i, InitsCtorSeesThis); + object!(i, InitsCtorSeesThis::constructor_1()); assert!( ({ { (*i.borrow()).x.self_.clone() } } == { (field_ptr!(i.as_pointer(), x)) }) && ({ (*i.borrow()).x.id } == 1) @@ -904,7 +960,7 @@ fn main_0() -> i32 { ); let mut p: Ptr = { let __p = Ptr::alloc(::zero_init()); - CtorSeesThis::construct_1(__p.clone(), 4); + CtorSeesThis::constructor_2(__p.clone(), 4); __p }; assert!( @@ -917,14 +973,17 @@ fn main_0() -> i32 { && ({ { (*o1.borrow()).x.self_.clone() } } == { (field_ptr!(o1.as_pointer(), x)) }) ); (*o1.borrow_mut()).v = 2; - object!(o2, OutOfLineDefaulted, LvalueRef::bind(o1.as_pointer())); + object!( + o2, + OutOfLineDefaulted::constructor_2(LvalueRef::bind(o1.as_pointer())) + ); assert!( ({ (*o2.borrow()).v } == 2) && ({ { (*o2.borrow()).x.self_.clone() } } == { (field_ptr!(o2.as_pointer(), x)) }) ); - object!(a1, OutOfLineAssign); - object!(a2, OutOfLineAssign); - object!(a3, OutOfLineAssign); + object!(a1, OutOfLineAssign::constructor_1()); + object!(a2, OutOfLineAssign::constructor_1()); + object!(a3, OutOfLineAssign::constructor_1()); (*a1.borrow_mut()).v = 3; ({ let __tmp_4: Value = Rc::new(RefCell::new(4)); diff --git a/tests/unit/out/refcount/copy_move_deleted.rs b/tests/unit/out/refcount/copy_move_deleted.rs index 81abcb51e9..3779e7dc33 100644 --- a/tests/unit/out/refcount/copy_move_deleted.rs +++ b/tests/unit/out/refcount/copy_move_deleted.rs @@ -11,24 +11,24 @@ use std::rc::{Rc, Weak}; ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Swappable, Default, + Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct NoCopy { #[offset(0)] pub v: i32, } impl NoCopy { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl MoveConstructible for NoCopy { - fn move_constructor(this: Ptr, o: RvalueRef) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); @@ -42,19 +42,20 @@ impl MoveAssignable for NoCopy { return (this).clone(); } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_2)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct PrivateCopy { #[offset(0)] pub v: i32, } -impl DefaultConstructible for PrivateCopy { - fn default_constructor(this: Ptr) { +impl PrivateCopy { + pub fn constructor_2(this: Ptr) { field!(this, v).write(0); } -} -impl MoveConstructible for PrivateCopy { - fn move_constructor(this: Ptr, o: RvalueRef) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); @@ -72,21 +73,23 @@ impl Default for PrivateCopy { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + PrivateCopy::constructor_2(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct Immovable { #[offset(0)] pub v: i32, } -impl DefaultConstructible for Immovable { - fn default_constructor(this: Ptr) { +impl Immovable { + pub fn constructor_1(this: Ptr) { field!(this, v).write(0); } } @@ -94,8 +97,8 @@ impl Default for Immovable { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Immovable::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -112,6 +115,8 @@ impl Default for Immovable { Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(Conversions)] +#[conversions(move)] #[byte_size(8)] pub struct Container { #[offset(0)] @@ -120,18 +125,22 @@ pub struct Container { #[offset(4)] pub tag: i32, } +impl Container {} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct VecHolder { #[offset(0)] #[byte_size(24)] pub items: Vec, } -impl DefaultConstructible for VecHolder { - fn default_constructor(this: Ptr) { +impl VecHolder { + pub fn constructor_1(this: Ptr) { field!(this, items).write(Vec::new()); } } @@ -146,39 +155,52 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, NoCopy(1)); - object!(b, NoCopy, RvalueRef::bind(a.as_pointer())); + object!(a, NoCopy::constructor_1(1)); + object!(b, NoCopy::constructor_3(RvalueRef::bind(a.as_pointer()))); assert!(({ (*b.borrow()).v } == 1) && ({ (*a.borrow()).v } == 0)); 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); + object!(p, PrivateCopy::constructor_2()); (*p.borrow_mut()).v = 3; - object!(q, PrivateCopy, RvalueRef::bind(p.as_pointer())); + object!( + q, + PrivateCopy::constructor_3(RvalueRef::bind(p.as_pointer())) + ); assert!(({ (*q.borrow()).v } == 3) && ({ (*p.borrow()).v } == 0)); assign!(p = RvalueRef(q)); assert!(({ (*p.borrow()).v } == 3) && ({ (*q.borrow()).v } == 0)); - object!(im, Immovable); + object!(im, Immovable::constructor_1()); (*im.borrow_mut()).v = 4; ({ bump_ref_1(im.as_pointer()) }); let mut pim: Ptr = (im.as_pointer()); assert!((pim.with(|__s| __s.v) == 5)); let c: Value = Rc::new(RefCell::new(Container { inner: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - NoCopy::construct(__v.as_pointer(), 6); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + NoCopy::constructor_1(__v.as_pointer(), 6); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, tag: 7, })); - object!(d, Container, RvalueRef::bind(c.as_pointer())); + object!(d, Container, |d| { + ::move_constructor( + d.clone(), + 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, RvalueRef::bind(h.as_pointer())); + object!(h, VecHolder::constructor_1()); + object!(h2, VecHolder, |h2| { + ::move_constructor( + h2.clone(), + RvalueRef::bind(h.as_pointer()), + ) + }); assert!(({ ((*h2.borrow()).items.len() == 0_usize) })); return 0; } @@ -187,8 +209,8 @@ impl CopyAssignable for PrivateCopy { unreachable!("PrivateCopy::copy_assign is never defined") } } -impl CopyConstructible for PrivateCopy { - fn copy_constructor(this: Ptr, _: LvalueRef>) { +impl Constructor<(LvalueRef>,)> for PrivateCopy { + fn constructor(this: Ptr, _: (LvalueRef>,)) { unreachable!("PrivateCopy::copy_constructor is never defined") } } diff --git a/tests/unit/out/refcount/default_function_arguments.rs b/tests/unit/out/refcount/default_function_arguments.rs index 313642dd62..ed9a024b22 100644 --- a/tests/unit/out/refcount/default_function_arguments.rs +++ b/tests/unit/out/refcount/default_function_arguments.rs @@ -24,7 +24,7 @@ pub fn baz_1(mut a: Ptr, mut b: Ptr) -> bool { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct Bar { #[offset(0)] @@ -95,7 +95,7 @@ pub fn first_9(r: Ptr) -> i32 { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, explicit, value(i32))] +#[constructor(constructor_1, explicit, i32)] #[byte_size(4)] pub struct Holder_int_ { #[offset(0)] diff --git a/tests/unit/out/refcount/delete_array_order.rs b/tests/unit/out/refcount/delete_array_order.rs index 17621816ec..38119de0d4 100644 --- a/tests/unit/out/refcount/delete_array_order.rs +++ b/tests/unit/out/refcount/delete_array_order.rs @@ -20,7 +20,7 @@ use std::rc::{Rc, Weak}; )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy)] #[byte_size(16)] pub struct Element { #[offset(0)] diff --git a/tests/unit/out/refcount/destructor.rs b/tests/unit/out/refcount/destructor.rs index 21869de643..bc17b6fa88 100644 --- a/tests/unit/out/refcount/destructor.rs +++ b/tests/unit/out/refcount/destructor.rs @@ -23,7 +23,7 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy)] #[byte_size(1)] pub struct S {} impl Destructible for S { @@ -46,7 +46,7 @@ impl Destructible for S { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy)] #[byte_size(1)] pub struct Defaulted { #[offset(0)] @@ -141,7 +141,7 @@ pub struct ArrayMember { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy)] #[byte_size(1)] pub struct EmptyBody { #[offset(0)] @@ -167,7 +167,7 @@ impl Destructible for EmptyBody { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy)] #[byte_size(1)] pub struct Templated_char_ { #[offset(0)] @@ -197,7 +197,7 @@ impl Destructible for Templated_char_ { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy)] #[byte_size(4)] pub struct Templated_int_ { #[offset(0)] @@ -227,7 +227,7 @@ impl Destructible for Templated_int_ { )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy)] #[byte_size(4)] pub struct Copied { #[offset(0)] @@ -259,7 +259,7 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy)] #[byte_size(4)] pub struct Tagged { #[offset(0)] diff --git a/tests/unit/out/refcount/destructor_params.rs b/tests/unit/out/refcount/destructor_params.rs index 2f4d4af2c7..b791c8fdae 100644 --- a/tests/unit/out/refcount/destructor_params.rs +++ b/tests/unit/out/refcount/destructor_params.rs @@ -26,7 +26,7 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -38,11 +38,13 @@ impl Destructible for S { last_1.with(|rc| *rc.borrow_mut() = this.with(|__s| __s.v)); } } -pub fn by_value_2(s: Ptr) -> i32 { +pub fn by_value_2(s: ParameterObject) -> i32 { + let s = s.as_pointer(); assert!((destroyed_0.with(|rc| *rc.borrow()) == 0)); return s.with(|__s| __s.v); } -pub fn with_default_3(s: Ptr) -> i32 { +pub fn with_default_3(s: ParameterObject) -> i32 { + let s = s.as_pointer(); return s.with(|__s| __s.v); } #[derive( @@ -59,18 +61,19 @@ pub fn with_default_3(s: Ptr) -> i32 { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, explicit, by_value(S))] +#[constructor(constructor_1, explicit, ParameterObject)] #[byte_size(4)] pub struct Holder { #[offset(0)] pub v: i32, } impl Holder { - pub fn constructor_1(this: Ptr, s: LvalueRef) { + pub fn constructor_1(this: Ptr, s: ParameterObject) { let s = s.as_pointer(); field!(this, v).write(s.with(|__s| __s.v)); } - pub fn add(this: Ptr, s: Ptr) -> i32 { + pub fn add(this: Ptr, s: ParameterObject) -> i32 { + let s = s.as_pointer(); return (this.with(|__s| __s.v) + s.with(|__s| __s.v)); } } @@ -87,7 +90,7 @@ fn main_0() -> i32 { ({ (({ let _s: Value = Rc::new(RefCell::new((*s.borrow()).clone())); - by_value_2(_s.as_pointer()) + by_value_2(ParameterObject::bind(_s.as_pointer())) }) == 1) }) ); @@ -100,7 +103,7 @@ fn main_0() -> i32 { assert!( (({ let _s: Value = Rc::new(RefCell::new(S { v: 2 })); - by_value_2(_s.as_pointer()) + by_value_2(ParameterObject::bind(_s.as_pointer())) }) == 2) ); assert!((destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 2)); @@ -108,7 +111,7 @@ fn main_0() -> i32 { assert!( (({ let _s: Value = Rc::new(RefCell::new(S { v: 5 })); - with_default_3(_s.as_pointer()) + with_default_3(ParameterObject::bind(_s.as_pointer())) }) == 5) ); assert!((destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 5)); @@ -116,7 +119,7 @@ fn main_0() -> i32 { { object!(h, Holder, |h| { let __tmp_0: Value = Rc::new(RefCell::new(S { v: 3 })); - Holder::constructor_1(h.clone(), LvalueRef::bind(__tmp_0.as_pointer())) + Holder::constructor_1(h.clone(), ParameterObject::bind(__tmp_0.as_pointer())) }); assert!( (destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 3) @@ -124,7 +127,7 @@ fn main_0() -> i32 { assert!( (({ let _s: Value = Rc::new(RefCell::new(S { v: 4 })); - Holder::add(h.as_pointer(), _s.as_pointer()) + Holder::add(h.as_pointer(), ParameterObject::bind(_s.as_pointer())) }) == 7) ); assert!( diff --git a/tests/unit/out/refcount/destructor_temporaries.rs b/tests/unit/out/refcount/destructor_temporaries.rs index 39d2ed8fb1..191cf428b5 100644 --- a/tests/unit/out/refcount/destructor_temporaries.rs +++ b/tests/unit/out/refcount/destructor_temporaries.rs @@ -26,7 +26,7 @@ thread_local!( )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy, move)] +#[conversions(copy)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/enum_underlying_type.rs b/tests/unit/out/refcount/enum_underlying_type.rs index 3e882309bd..2db50121d3 100644 --- a/tests/unit/out/refcount/enum_underlying_type.rs +++ b/tests/unit/out/refcount/enum_underlying_type.rs @@ -36,7 +36,8 @@ pub type Empty = bool; TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(1)] pub struct HoldsEmpty { #[offset(0)] diff --git a/tests/unit/out/refcount/field_method_receiver.rs b/tests/unit/out/refcount/field_method_receiver.rs index 41d3b0ec1a..b2f2329ea7 100644 --- a/tests/unit/out/refcount/field_method_receiver.rs +++ b/tests/unit/out/refcount/field_method_receiver.rs @@ -59,7 +59,8 @@ impl Counter { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(40)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/field_pointers.rs b/tests/unit/out/refcount/field_pointers.rs index c60a9d9980..b4007c4652 100644 --- a/tests/unit/out/refcount/field_pointers.rs +++ b/tests/unit/out/refcount/field_pointers.rs @@ -72,7 +72,8 @@ pub struct Header { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(104)] pub struct Outer { #[offset(0)] diff --git a/tests/unit/out/refcount/fn_ptr.rs b/tests/unit/out/refcount/fn_ptr.rs index a9a103042f..de9aea0872 100644 --- a/tests/unit/out/refcount/fn_ptr.rs +++ b/tests/unit/out/refcount/fn_ptr.rs @@ -35,12 +35,12 @@ pub fn identity_hash_6(mut v: bool) -> usize { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_from(FnPtr u64 > , construct, ptr)] +#[conversions(copy, move)] #[byte_size(8)] pub struct HashHolder_unsigned_long__ptr__bool__ { #[offset(0)] @@ -48,7 +48,8 @@ pub struct HashHolder_unsigned_long__ptr__bool__ { pub h: FnPtr u64>, } impl HashHolder_unsigned_long__ptr__bool__ { - pub fn construct(this: Ptr, h: Ptr u64>>) { + pub fn constructor_1(this: Ptr, h: LvalueRef u64>>>) { + let h = h.as_pointer(); field!(this, h).write((h.read())); } } @@ -100,7 +101,10 @@ fn main_0() -> i32 { let __tmp_0: Value u64>> = Rc::new(RefCell::new( (FnPtr:: usize>::new(identity_hash_6)).cast:: u64>(), )); - HashHolder_unsigned_long__ptr__bool__::construct(hh.clone(), __tmp_0.as_pointer()) + HashHolder_unsigned_long__ptr__bool__::constructor_1( + hh.clone(), + LvalueRef::bind(__tmp_0.as_pointer()), + ) }); assert!((({ { (*hh.borrow()).h.clone() }.call(true,) }) == 1_u64)); let mut handler: FnPtr = FnPtr::::new(add_to_total_8); diff --git a/tests/unit/out/refcount/fn_ptr_struct.rs b/tests/unit/out/refcount/fn_ptr_struct.rs index 6c6ee7cbbc..22c991bf97 100644 --- a/tests/unit/out/refcount/fn_ptr_struct.rs +++ b/tests/unit/out/refcount/fn_ptr_struct.rs @@ -16,7 +16,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct Handler { #[offset(0)] @@ -42,7 +44,9 @@ pub fn negate_1(mut x: i32) -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(1)] pub struct S {} impl S { @@ -57,35 +61,36 @@ impl S { } } #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, RvalueRef)] #[byte_size(4)] pub struct MoveOnly { #[offset(0)] pub data_: i32, } impl MoveOnly { - pub fn construct(this: Ptr, mut data: i32) { + pub fn constructor_1(this: Ptr, mut data: i32) { field!(this, data_).write(data); } - pub fn get(this: Ptr) -> i32 { - return this.with(|__s| __s.data_); - } -} -impl MoveConstructible for MoveOnly { - fn move_constructor(this: Ptr, x: RvalueRef) { + pub fn constructor_2(this: Ptr, x: RvalueRef) { let x = x.as_pointer(); field!(this, data_).write(x.with(|__s| __s.data_)); field!(x, data_).write(0); } + pub fn get(this: Ptr) -> i32 { + return this.with(|__s| __s.data_); + } } pub fn make_move_only_2(__return: Ptr) { - MoveOnly::construct(__return.clone(), 4); + MoveOnly::constructor_1(__return.clone(), 4); return; } -pub fn scale_move_only_3(__return: Ptr, x: Ptr) { - MoveOnly::construct(__return.clone(), (({ MoveOnly::get((x).clone()) }) * 10)); +pub fn scale_move_only_3(__return: Ptr, x: ParameterObject) { + let x = x.as_pointer(); + MoveOnly::constructor_1(__return.clone(), (({ MoveOnly::get((x).clone()) }) * 10)); return; } pub fn main() { @@ -120,12 +125,15 @@ fn main_0() -> i32 { let mut mk: FnPtr)> = FnPtr::)>::new(make_move_only_2); object!(m, MoveOnly, |m| ({ mk.call(Ptr::clone(&m.clone()),) })); assert!((({ MoveOnly::get(m.as_pointer(),) }) == 4)); - let mut sc: FnPtr, Ptr)> = - FnPtr::, Ptr)>::new(scale_move_only_3); + let mut sc: FnPtr, ParameterObject)> = + FnPtr::, ParameterObject)>::new(scale_move_only_3); object!(n, MoveOnly, |n| ({ - let _arg0: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor(_arg0.as_pointer(), RvalueRef::bind(m.as_pointer())); - sc.call(Ptr::clone(&n.clone()), _arg0.as_pointer()) + let _arg0: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MoveOnly::constructor_2(_arg0.as_pointer(), RvalueRef::bind(m.as_pointer())); + sc.call( + Ptr::clone(&n.clone()), + ParameterObject::bind(_arg0.as_pointer()), + ) })); assert!((({ MoveOnly::get(n.as_pointer(),) }) == 40)); assert!((({ MoveOnly::get(m.as_pointer(),) }) == 0)); diff --git a/tests/unit/out/refcount/for_body_destructor.rs b/tests/unit/out/refcount/for_body_destructor.rs index 0649007c38..a975aa7a93 100644 --- a/tests/unit/out/refcount/for_body_destructor.rs +++ b/tests/unit/out/refcount/for_body_destructor.rs @@ -20,18 +20,16 @@ use std::rc::{Rc, Weak}; )] #[memberwise(copy_assign)] #[derive(Conversions)] -#[conversions(copy, move)] -#[conversion_function(conversion_function_2, bool, const_lvalue_ref, explicit)] +#[conversions(copy)] +#[conversion_function(to_bool, LvalueRef>, bool , explicit)] #[byte_size(4)] pub struct Guard { #[offset(0)] pub digit: i32, } impl Guard { - pub fn conversion_function_2(this: LvalueRef>, __return: Ptr) { - let this = this.as_pointer(); - __return.write((this.with(|__s| __s.digit) != 0)); - return; + pub fn to_bool(this: Ptr) -> bool { + return (this.with(|__s| __s.digit) != 0); } } impl Destructible for Guard { @@ -170,14 +168,7 @@ fn main_0() -> i32 { let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| { Destructible::destroy(__p.as_pointer()) }); - if !({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Guard::conversion_function_2( - >>::bind(condition.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }) { + if !({ Guard::to_bool(condition.as_pointer()) }) { break; } 'for_body: { diff --git a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs index bf1e858518..ab3ac134d4 100644 --- a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs @@ -21,7 +21,8 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(32)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/forward_basic.rs b/tests/unit/out/refcount/forward_basic.rs index c12b3aa9e3..9102d7ef1b 100644 --- a/tests/unit/out/refcount/forward_basic.rs +++ b/tests/unit/out/refcount/forward_basic.rs @@ -10,9 +10,12 @@ pub type Overload = u32; pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(12)] pub struct Tracked { #[offset(0)] @@ -23,22 +26,18 @@ pub struct Tracked { pub moves: i32, } impl Tracked { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(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: RvalueRef) { + pub fn constructor_3(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)); @@ -53,34 +52,32 @@ pub fn chosen_overload_1(_a0: Ptr) -> Overload { return Overload_kRvalueOverload; } impl Holder { - pub fn construct_1(this: Ptr, x: Ptr) { - CopyConstructible::copy_constructor(field_ptr!(this, t), LvalueRef::bind((x).clone())); + pub fn constructor_1_1(this: Ptr, x: LvalueRef) { + let x = x.as_pointer(); + Tracked::constructor_2(field_ptr!(this, t), LvalueRef::bind((x).clone())); } } impl Holder { - pub fn construct_2(this: Ptr, x: Ptr) { - MoveConstructible::move_constructor(field_ptr!(this, t), RvalueRef::bind((x).clone())); + pub fn constructor_1_2(this: Ptr, x: RvalueRef) { + let x = x.as_pointer(); + Tracked::constructor_3(field_ptr!(this, t), RvalueRef::bind((x).clone())); } } #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - CppFrom, - DefaultInitializable, - Memberwise, - Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, )] #[memberwise(copy_constructor, move_constructor)] -#[cpp_from(Tracked, construct_1, mut_ptr)] -#[cpp_from_move(Tracked, construct_2, ptr)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1_1, LvalueRef)] +#[constructor(constructor_1_2, RvalueRef)] #[byte_size(12)] pub struct Holder { #[offset(0)] #[byte_size(12)] pub t: Tracked, } +impl Holder {} pub fn forward_once_2(x: Ptr) -> Overload { return ({ chosen_overload_0((x).clone()) }); } @@ -94,11 +91,11 @@ pub fn forward_twice_5(x: Ptr) -> Overload { return ({ forward_once_3((x).clone()) }); } pub fn forward_into_ctor_6(__return: Ptr, x: Ptr) { - Holder::construct_1(__return.clone(), (x).clone()); + Holder::constructor_1_1(__return.clone(), LvalueRef::bind((x).clone())); return; } pub fn forward_into_ctor_7(__return: Ptr, x: Ptr) { - Holder::construct_2(__return.clone(), (x).clone()); + Holder::constructor_1_2(__return.clone(), RvalueRef::bind((x).clone())); return; } pub fn main() { @@ -106,20 +103,20 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(lvalue, Tracked(7)); + object!(lvalue, Tracked::constructor_1(7)); assert!( ((({ forward_once_2(lvalue.as_pointer(),) }) as i32) == (Overload_kLvalueOverload as i32)) ); assert!(({ (*lvalue.borrow()).v } == 7)); assert!( ((({ - let _x: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct(_x.as_pointer(), 8); + let _x: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_x.as_pointer(), 8); forward_once_3(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object!(relayed, Tracked(9)); + object!(relayed, Tracked::constructor_1(9)); assert!( ((({ forward_twice_4(relayed.as_pointer(),) }) as i32) == (Overload_kLvalueOverload as i32)) @@ -127,13 +124,13 @@ fn main_0() -> i32 { assert!(({ (*relayed.borrow()).v } == 9)); assert!( ((({ - let _x: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct(_x.as_pointer(), 10); + let _x: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_x.as_pointer(), 10); forward_twice_5(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object!(kept, Tracked(11)); + object!(kept, Tracked::constructor_1(11)); object!(from_lvalue, Holder, |from_lvalue| ({ forward_into_ctor_6(Ptr::clone(&from_lvalue.clone()), kept.as_pointer()) })); @@ -142,8 +139,8 @@ fn main_0() -> i32 { assert!(({ (*from_lvalue.borrow()).t.moves } == 0)); assert!(({ (*kept.borrow()).v } == 11)); object!(from_rvalue, Holder, |from_rvalue| ({ - let _x: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct(_x.as_pointer(), 12); + let _x: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_x.as_pointer(), 12); forward_into_ctor_7(Ptr::clone(&from_rvalue.clone()), _x.as_pointer()) })); assert!(({ (*from_rvalue.borrow()).t.v } == 12)); diff --git a/tests/unit/out/refcount/forward_decltype.rs b/tests/unit/out/refcount/forward_decltype.rs index 152965ba21..75903e0673 100644 --- a/tests/unit/out/refcount/forward_decltype.rs +++ b/tests/unit/out/refcount/forward_decltype.rs @@ -10,9 +10,12 @@ pub type Overload = u32; pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(12)] pub struct Tracked { #[offset(0)] @@ -23,22 +26,18 @@ pub struct Tracked { pub moves: i32, } impl Tracked { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(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: RvalueRef) { + pub fn constructor_3(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)); @@ -74,7 +73,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, Tracked(3)); + object!(a, Tracked::constructor_1(3)); assert!( ((({ forward_by_decltype_2(a.as_pointer(),) }) as i32) == (Overload_kLvalueOverload as i32)) @@ -82,13 +81,13 @@ fn main_0() -> i32 { assert!(({ (*a.borrow()).v } == 3)); assert!( ((({ - let _x: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct(_x.as_pointer(), 4); + let _x: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_x.as_pointer(), 4); forward_by_decltype_3(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object!(b, Tracked(5)); + object!(b, Tracked::constructor_1(5)); assert!( ((({ forward_abbreviated_4(b.as_pointer(),) }) as i32) == (Overload_kLvalueOverload as i32)) @@ -96,17 +95,17 @@ fn main_0() -> i32 { assert!(({ (*b.borrow()).v } == 5)); assert!( ((({ - let _x: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct(_x.as_pointer(), 6); + let _x: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_x.as_pointer(), 6); forward_abbreviated_5(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object!(c, Tracked(7)); + object!(c, Tracked::constructor_1(7)); assert!( (({ - let _args_1: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct(_args_1.as_pointer(), 8); + let _args_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_args_1.as_pointer(), 8); forward_abbreviated_pack_6(c.as_pointer(), _args_1.as_pointer()) }) == ((Overload_kLvalueOverload as i32) + (Overload_kRvalueOverload as i32))) ); diff --git a/tests/unit/out/refcount/forward_explicit.rs b/tests/unit/out/refcount/forward_explicit.rs index d448573954..3d55c011d1 100644 --- a/tests/unit/out/refcount/forward_explicit.rs +++ b/tests/unit/out/refcount/forward_explicit.rs @@ -12,9 +12,12 @@ pub const Overload_kRvalueOverload: Overload = 2; pub const Overload_kIntLvalueOverload: Overload = 3; pub const Overload_kIntRvalueOverload: Overload = 4; #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(12)] pub struct Tracked { #[offset(0)] @@ -25,22 +28,18 @@ pub struct Tracked { pub moves: i32, } impl Tracked { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(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: RvalueRef) { + pub fn constructor_3(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)); @@ -60,8 +59,9 @@ pub fn chosen_overload_2(_a0: Ptr) -> Overload { pub fn chosen_overload_3(_a0: Ptr) -> Overload { return Overload_kIntRvalueOverload; } -pub fn copy_or_move_into_param_4(__return: Ptr, t: Ptr) { - MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind((t).clone())); +pub fn copy_or_move_into_param_4(__return: Ptr, t: ParameterObject) { + let t = t.as_pointer(); + Tracked::constructor_3(__return.clone(), RvalueRef::bind((t).clone())); return; } pub fn main() { @@ -69,7 +69,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, Tracked(5)); + object!(a, Tracked::constructor_1(5)); assert!( ((({ chosen_overload_0(a.as_pointer(),) }) as i32) == (Overload_kLvalueOverload as i32)) ); @@ -78,21 +78,27 @@ fn main_0() -> i32 { ((({ chosen_overload_1(a.as_pointer(),) }) as i32) == (Overload_kRvalueOverload as i32)) ); assert!(({ (*a.borrow()).v } == 5)); - object!(b, Tracked(6)); + object!(b, Tracked::constructor_1(6)); object!(moved, Tracked, |moved| ({ - let _t: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor(_t.as_pointer(), RvalueRef::bind(b.as_pointer())); - copy_or_move_into_param_4(Ptr::clone(&moved.clone()), _t.as_pointer()) + let _t: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_3(_t.as_pointer(), RvalueRef::bind(b.as_pointer())); + copy_or_move_into_param_4( + Ptr::clone(&moved.clone()), + ParameterObject::bind(_t.as_pointer()), + ) })); assert!(({ (*moved.borrow()).v } == 6)); assert!(({ (*moved.borrow()).copies } == 0)); assert!(({ (*moved.borrow()).moves } == 2)); assert!(({ (*b.borrow()).v } == 0)); - object!(c, Tracked(7)); + object!(c, Tracked::constructor_1(7)); object!(copied, Tracked, |copied| ({ - let _t: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor(_t.as_pointer(), LvalueRef::bind(c.as_pointer())); - copy_or_move_into_param_4(Ptr::clone(&copied.clone()), _t.as_pointer()) + let _t: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(_t.as_pointer(), LvalueRef::bind(c.as_pointer())); + copy_or_move_into_param_4( + Ptr::clone(&copied.clone()), + ParameterObject::bind(_t.as_pointer()), + ) })); assert!(({ (*copied.borrow()).v } == 7)); assert!(({ (*copied.borrow()).copies } == 1)); diff --git a/tests/unit/out/refcount/forward_pack.rs b/tests/unit/out/refcount/forward_pack.rs index 1322d87ae1..83247cb240 100644 --- a/tests/unit/out/refcount/forward_pack.rs +++ b/tests/unit/out/refcount/forward_pack.rs @@ -12,9 +12,12 @@ pub const Overload_kRvalueOverload: Overload = 2; pub const Overload_kIntLvalueOverload: Overload = 3; pub const Overload_kIntRvalueOverload: Overload = 4; #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(12)] pub struct Tracked { #[offset(0)] @@ -25,22 +28,18 @@ pub struct Tracked { pub moves: i32, } impl Tracked { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(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: RvalueRef) { + pub fn constructor_3(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)); @@ -97,15 +96,20 @@ pub fn forward_pack_7( return digits; } impl Pair { - pub fn construct(this: Ptr, x: Ptr, y: Ptr) { - CopyConstructible::copy_constructor(field_ptr!(this, a), LvalueRef::bind((x).clone())); - MoveConstructible::move_constructor(field_ptr!(this, b), RvalueRef::bind((y).clone())); + pub fn constructor_1_1(this: Ptr, x: LvalueRef, y: RvalueRef) { + let x = x.as_pointer(); + let y = y.as_pointer(); + Tracked::constructor_2(field_ptr!(this, a), LvalueRef::bind((x).clone())); + Tracked::constructor_3(field_ptr!(this, b), RvalueRef::bind((y).clone())); } } #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, )] #[memberwise(copy_constructor, move_constructor)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1_1, LvalueRef, RvalueRef)] #[byte_size(24)] pub struct Pair { #[offset(0)] @@ -115,8 +119,13 @@ pub struct Pair { #[byte_size(12)] pub b: Tracked, } +impl Pair {} pub fn forward_pack_into_ctor_8(__return: Ptr, args_0: Ptr, args_1: Ptr) { - Pair::construct(__return.clone(), (args_0).clone(), (args_1).clone()); + Pair::constructor_1_1( + __return.clone(), + LvalueRef::bind((args_0).clone()), + RvalueRef::bind((args_1).clone()), + ); return; } pub fn main() { @@ -125,21 +134,21 @@ pub fn main() { } fn main_0() -> i32 { assert!((({ forward_pack_4() }) == 0)); - object!(a, Tracked(1)); + object!(a, Tracked::constructor_1(1)); assert!((({ forward_pack_5(a.as_pointer(),) }) == (Overload_kLvalueOverload as i32))); assert!(({ (*a.borrow()).v } == 1)); assert!( (({ - let _args: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct(_args.as_pointer(), 2); + let _args: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_args.as_pointer(), 2); forward_pack_6(_args.as_pointer()) }) == (Overload_kRvalueOverload as i32)) ); let i: Value = Rc::new(RefCell::new(3)); assert!( (({ - let _args_1: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct(_args_1.as_pointer(), 4); + let _args_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_args_1.as_pointer(), 4); let _args_3: Value = Rc::new(RefCell::new(5)); forward_pack_7( a.as_pointer(), @@ -151,10 +160,10 @@ fn main_0() -> i32 { ); assert!(({ (*a.borrow()).v } == 1)); assert!(({ ((*i.borrow()) == 3) })); - object!(lhs, Tracked(6)); + object!(lhs, Tracked::constructor_1(6)); object!(p, Pair, |p| ({ - let _args_1: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct(_args_1.as_pointer(), 7); + let _args_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(_args_1.as_pointer(), 7); forward_pack_into_ctor_8( Ptr::clone(&p.clone()), lhs.as_pointer(), diff --git a/tests/unit/out/refcount/global_call_temporaries.rs b/tests/unit/out/refcount/global_call_temporaries.rs index 34692c03ce..91d788b618 100644 --- a/tests/unit/out/refcount/global_call_temporaries.rs +++ b/tests/unit/out/refcount/global_call_temporaries.rs @@ -114,7 +114,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Item { #[offset(0)] diff --git a/tests/unit/out/refcount/global_init_side_effect.rs b/tests/unit/out/refcount/global_init_side_effect.rs index a77f9f6268..f1f34df9ee 100644 --- a/tests/unit/out/refcount/global_init_side_effect.rs +++ b/tests/unit/out/refcount/global_init_side_effect.rs @@ -23,7 +23,7 @@ thread_local!( Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] #[byte_size(1)] pub struct S {} impl S { diff --git a/tests/unit/out/refcount/global_non_const_init.rs b/tests/unit/out/refcount/global_non_const_init.rs index 8762b49a38..3e989d0e15 100644 --- a/tests/unit/out/refcount/global_non_const_init.rs +++ b/tests/unit/out/refcount/global_non_const_init.rs @@ -43,8 +43,9 @@ thread_local!( TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] -#[constructor(constructor_2, explicit, value(i32))] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, explicit, i32)] #[byte_size(4)] pub struct Ctor { #[offset(0)] @@ -140,7 +141,8 @@ thread_local!( TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct Singleton { #[offset(0)] diff --git a/tests/unit/out/refcount/huffman.rs b/tests/unit/out/refcount/huffman.rs index 521f4bb644..22b3208ef7 100644 --- a/tests/unit/out/refcount/huffman.rs +++ b/tests/unit/out/refcount/huffman.rs @@ -63,7 +63,8 @@ pub fn Swap_0(a: Ptr, b: Ptr) { )] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] -#[conversions(move, default = constructor_1)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(32)] pub struct MinHeap { #[offset(0)] diff --git a/tests/unit/out/refcount/implicit_autoref.rs b/tests/unit/out/refcount/implicit_autoref.rs index 17d3b07ea6..f30d5b13c8 100644 --- a/tests/unit/out/refcount/implicit_autoref.rs +++ b/tests/unit/out/refcount/implicit_autoref.rs @@ -21,7 +21,8 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct Holder { #[offset(0)] diff --git a/tests/unit/out/refcount/in_class_field_initializer.rs b/tests/unit/out/refcount/in_class_field_initializer.rs index 4a7ccc68cd..a4404eedc0 100644 --- a/tests/unit/out/refcount/in_class_field_initializer.rs +++ b/tests/unit/out/refcount/in_class_field_initializer.rs @@ -17,7 +17,8 @@ use std::rc::{Rc, Weak}; TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct Inner { #[offset(0)] @@ -47,7 +48,8 @@ impl Default for Inner { TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct S { #[offset(0)] @@ -94,7 +96,7 @@ impl Default for S { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32), value(i32))] +#[constructor(constructor_1, i32, i32)] #[byte_size(8)] pub struct Boxed_int_ { #[offset(0)] diff --git a/tests/unit/out/refcount/init_list.rs b/tests/unit/out/refcount/init_list.rs index 99a50c0643..0e4e1e348d 100644 --- a/tests/unit/out/refcount/init_list.rs +++ b/tests/unit/out/refcount/init_list.rs @@ -41,7 +41,8 @@ pub struct Pair { TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct Holder { #[offset(0)] @@ -80,7 +81,8 @@ pub fn sum_1(p: Ptr) -> i32 { TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct Seven { #[offset(0)] diff --git a/tests/unit/out/refcount/inline_container_fields.rs b/tests/unit/out/refcount/inline_container_fields.rs index 65956063ca..2fe567d0e7 100644 --- a/tests/unit/out/refcount/inline_container_fields.rs +++ b/tests/unit/out/refcount/inline_container_fields.rs @@ -19,6 +19,9 @@ use std::rc::{Rc, Weak}; Swappable, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(48)] pub struct Elem { #[offset(0)] @@ -31,8 +34,8 @@ pub struct Elem { #[byte_size(24)] pub coeffs: Vec, } -impl DefaultConstructible for Elem { - fn default_constructor(this: Ptr) { +impl Elem { + pub fn constructor_1(this: Ptr) { field!(this, id).write(0_i32); field!(this, hist).write((0..4).map(|_| 0_i32).collect::>()); field!(this, coeffs).write(Vec::new()); @@ -62,6 +65,9 @@ impl Default for Elem { Swappable, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(88)] pub struct State { #[offset(0)] @@ -81,8 +87,8 @@ pub struct State { #[byte_size(24)] pub rows: Vec>, } -impl DefaultConstructible for State { - fn default_constructor(this: Ptr) { +impl State { + pub fn constructor_1(this: Ptr) { field!(this, count).write(0_i32); field!(this, grid).write( (0..2) @@ -182,26 +188,26 @@ thread_local!( thread_local!( pub static move_assigns_5: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct Counted { #[offset(0)] pub v: i32, } -impl DefaultConstructible for Counted { - fn default_constructor(this: Ptr) { +impl Counted { + pub fn constructor_1(this: Ptr) { field!(this, v).write(0); } -} -impl CopyConstructible for Counted { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(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: RvalueRef) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(-1_i32); @@ -348,7 +354,12 @@ 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, RvalueRef::bind(t.as_pointer())); + object!(moved, State, |moved| { + ::move_constructor( + moved.clone(), + RvalueRef::bind(t.as_pointer()), + ) + }); assert!( ({ ((*moved.borrow()).grid[(0) as usize][(0) as usize] == 100) @@ -399,13 +410,13 @@ fn main_0() -> i32 { (*ca.borrow_mut())[1_usize].v = 5; let cb: Value> = Rc::new(RefCell::new({ let __v: Value> = Rc::new(RefCell::new( - (0..3).map(|_| ::zero_init()).collect(), + (0..3).map(|_| ZeroInitialization::zero_init()).collect(), )); let __p: Ptr = __v.decay(); for __i in 0..3 { - MoveConstructible::move_constructor( + Constructor::constructor( __p.offset(__i), - RvalueRef::bind(ca.decay().offset(__i)), + (RvalueRef::::bind(ca.decay().offset(__i)),), ); } Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -460,13 +471,13 @@ fn main_0() -> i32 { }); let vb: Value]>> = Rc::new(RefCell::new({ let __v: Value]>> = Rc::new(RefCell::new( - (0..2).map(|_| >::zero_init()).collect(), + (0..2).map(|_| ZeroInitialization::zero_init()).collect(), )); let __p: Ptr> = __v.decay(); for __i in 0..2 { - MoveConstructible::move_constructor( + Constructor::constructor( __p.offset(__i), - RvalueRef::bind(va.decay().offset(__i)), + (RvalueRef::>::bind(va.decay().offset(__i)),), ); } Rc::try_unwrap(__v).ok().unwrap().into_inner() diff --git a/tests/unit/out/refcount/kruskal.rs b/tests/unit/out/refcount/kruskal.rs index 5c4aec095c..0c2b885a5c 100644 --- a/tests/unit/out/refcount/kruskal.rs +++ b/tests/unit/out/refcount/kruskal.rs @@ -117,7 +117,8 @@ pub fn quicksort_1(arr: Ptr>>>, mut start: i32, mut end )] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] -#[conversions(move, default = constructor_1)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct DisjointSet { #[offset(0)] @@ -242,7 +243,8 @@ impl DisjointSet { )] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] -#[conversions(move, default = constructor_1)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(16)] pub struct Graph { #[offset(0)] diff --git a/tests/unit/out/refcount/lambda_as_field.rs b/tests/unit/out/refcount/lambda_as_field.rs index f4c2bb7b5c..55c942e682 100644 --- a/tests/unit/out/refcount/lambda_as_field.rs +++ b/tests/unit/out/refcount/lambda_as_field.rs @@ -19,6 +19,8 @@ use std::rc::{Rc, Weak}; Movable, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] #[byte_size(1)] pub struct Guard__lambda_at_lambda_as_field_cpp_34_13__ { #[offset(0)] @@ -31,8 +33,17 @@ impl Destructible for Guard__lambda_at_lambda_as_field_cpp_34_13__ { } } #[derive( - Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, DefaultConstructible, Copyable, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + DefaultConstructible, + Copyable, + Conversions, )] +#[conversions(copy)] #[byte_size(8)] pub struct Guard__lambda_at_lambda_as_field_cpp_45_13__ { #[offset(0)] @@ -53,7 +64,9 @@ impl Destructible for Guard__lambda_at_lambda_as_field_cpp_45_13__ { FnPtrArg, TriviallyDefaultConstructible, TriviallyCopyable, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Holder__lambda_at_lambda_as_field_cpp_39_12__ { #[offset(0)] @@ -92,7 +105,9 @@ impl Default for Holder__lambda_at_lambda_as_field_cpp_39_12__ { DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Holder__lambda_at_lambda_as_field_cpp_51_12__ { #[offset(0)] @@ -107,8 +122,9 @@ impl Holder__lambda_at_lambda_as_field_cpp_51_12__ { return ({ (*this.upgrade().deref()).f.call(x) }); } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable)] -#[cpp_from(FnPtr i32 > , construct, value)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Conversions)] +#[conversions(move)] +#[constructor(constructor_2, RvalueRef)] #[byte_size(8)] pub struct Moving__lambda_at_lambda_as_field_cpp_64_12__ { #[offset(0)] @@ -118,14 +134,12 @@ pub struct Moving__lambda_at_lambda_as_field_cpp_64_12__ { pub moves: i32, } impl Moving__lambda_at_lambda_as_field_cpp_64_12__ { - pub fn construct(this: Ptr, f: FnPtr i32>) { + pub fn constructor_1(this: Ptr, f: FnPtr i32>) { let f: Value i32>> = Rc::new(RefCell::new(f)); field!(this, f).write((*f.borrow()).copy_from()); field!(this, moves).write(0); } -} -impl MoveConstructible for Moving__lambda_at_lambda_as_field_cpp_64_12__ { - fn move_constructor( + pub fn constructor_2( this: Ptr, o: RvalueRef, ) { @@ -252,7 +266,7 @@ fn main_0() -> i32 { assert!(({ (({ (*ww.borrow()).call(2,) }) == 202) })); object!( m, - Moving__lambda_at_lambda_as_field_cpp_64_12__(FnPtr:: i32>::new( + Moving__lambda_at_lambda_as_field_cpp_64_12__::constructor_1(FnPtr:: i32>::new( |mut x: i32| -> i32 { { return (x * 2); @@ -262,8 +276,9 @@ fn main_0() -> i32 { ); object!( m2, - Moving__lambda_at_lambda_as_field_cpp_64_12__, - RvalueRef::bind(m.as_pointer()) + Moving__lambda_at_lambda_as_field_cpp_64_12__::constructor_2(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 9afa88dffb..8fc8d569db 100644 --- a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs @@ -6,7 +6,11 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(8)] pub struct Counted { #[offset(0)] @@ -14,21 +18,17 @@ pub struct Counted { #[offset(4)] pub moves: i32, } -impl DefaultConstructible for Counted { - fn default_constructor(this: Ptr) { +impl Counted { + pub fn constructor_1(this: Ptr) { field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl CopyConstructible for Counted { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(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: RvalueRef) { + pub fn constructor_3(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)); @@ -38,8 +38,8 @@ impl Default for Counted { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -48,19 +48,19 @@ impl Default for Counted { thread_local!( pub static drops_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(1)] pub struct Dropped {} -impl DefaultConstructible for Dropped { - fn default_constructor(this: Ptr) {} -} -impl CopyConstructible for Dropped { - fn copy_constructor(this: Ptr, _a0: LvalueRef>) { +impl Dropped { + pub fn constructor_1(this: Ptr) {} + pub fn constructor_2(this: Ptr, _a0: LvalueRef>) { let _a0 = _a0.as_pointer(); } -} -impl MoveConstructible for Dropped { - fn move_constructor(this: Ptr, _a0: RvalueRef) { + pub fn constructor_3(this: Ptr, _a0: RvalueRef) { let _a0 = _a0.as_pointer(); } } @@ -74,15 +74,12 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(c, Counted); + object!(c, Counted::constructor_1()); let f: Value i32>> = Rc::new(RefCell::new(lambda!( { let c: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor( - __v.as_pointer(), - LvalueRef::bind(c.as_pointer()), - ); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_2(__v.as_pointer(), LvalueRef::bind(c.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -97,14 +94,15 @@ fn main_0() -> i32 { let h: Value i32>> = Rc::new(RefCell::new((*f.borrow()).move_from())); assert!(({ (({ (*h.borrow()).call() }) == 11) })); let mut returned: i32 = { - let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_0: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); { ({ lambda!( { let c: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_2( __v.as_pointer(), LvalueRef::bind(c.as_pointer()), ); @@ -112,10 +110,7 @@ fn main_0() -> i32 { })); }, |__return: Ptr| { - CopyConstructible::copy_constructor( - __return.clone(), - LvalueRef::bind(c.as_pointer()), - ); + Counted::constructor_2(__return.clone(), LvalueRef::bind(c.as_pointer())); return; } ) @@ -128,8 +123,8 @@ fn main_0() -> i32 { assert!((returned == 2)); let arr: Value> = Rc::new(RefCell::new(Box::new( std::array::from_fn::<_, 2, _>(|_| { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }), ))); @@ -137,8 +132,9 @@ 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())); - CopyConstructible::copy_constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_2( __v.as_pointer(), LvalueRef::bind(arr.decay().offset(__i)), ); @@ -161,8 +157,9 @@ fn main_0() -> i32 { let m: Value> = Rc::new(RefCell::new(lambda!( { let d: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Dropped::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -179,8 +176,9 @@ fn main_0() -> i32 { let k: Value> = Rc::new(RefCell::new(lambda!( { let d: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Dropped::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -197,8 +195,9 @@ fn main_0() -> i32 { let inner: Value> = Rc::new(RefCell::new(lambda!( { let d: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Dropped::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, diff --git a/tests/unit/out/refcount/lambda_decltype_type.rs b/tests/unit/out/refcount/lambda_decltype_type.rs index d08d283831..8ff9412094 100644 --- a/tests/unit/out/refcount/lambda_decltype_type.rs +++ b/tests/unit/out/refcount/lambda_decltype_type.rs @@ -9,7 +9,8 @@ use std::rc::{Rc, Weak}; #[derive( Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { #[offset(0)] @@ -68,7 +69,8 @@ impl Default for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { #[derive( Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { #[offset(0)] diff --git a/tests/unit/out/refcount/lambda_immediate_init.rs b/tests/unit/out/refcount/lambda_immediate_init.rs index 1f5900ec5d..45d71a6fd0 100644 --- a/tests/unit/out/refcount/lambda_immediate_init.rs +++ b/tests/unit/out/refcount/lambda_immediate_init.rs @@ -20,7 +20,8 @@ pub fn pick_0(mut x: i32) -> i32 { TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/lambda_move_only_capture.rs b/tests/unit/out/refcount/lambda_move_only_capture.rs index 1585f4b343..20b2fb98e5 100644 --- a/tests/unit/out/refcount/lambda_move_only_capture.rs +++ b/tests/unit/out/refcount/lambda_move_only_capture.rs @@ -6,8 +6,10 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultConstructible)] -#[cpp_from(i32, construct, value)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultConstructible, Conversions)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(8)] pub struct Owner { #[offset(0)] @@ -15,18 +17,20 @@ pub struct Owner { pub p: Ptr, } impl Owner { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, p).write(Ptr::alloc(v)); } + pub fn constructor_3(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()); + } pub fn take(this: Ptr) -> FnPtr i32> { return lambda!( { let self_: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor( - __v.as_pointer(), - RvalueRef::bind((this).clone()), - ); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Owner::constructor_3(__v.as_pointer(), RvalueRef::bind((this).clone())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -36,13 +40,6 @@ impl Owner { ); } } -impl MoveConstructible for Owner { - 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()); - } -} impl Destructible for Owner { fn destroy(this: Ptr) { this.with(|__s| __s.p.clone()).delete(); @@ -53,15 +50,12 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(o, Owner(5)); + object!(o, Owner::constructor_1(5)); let f: Value i32>> = Rc::new(RefCell::new(lambda!( { let h: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor( - __v.as_pointer(), - RvalueRef::bind(o.as_pointer()), - ); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Owner::constructor_3(__v.as_pointer(), RvalueRef::bind(o.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -81,8 +75,8 @@ fn main_0() -> i32 { let consume: Value> = Rc::new(RefCell::new(lambda!( { let h: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Owner::construct(__v.as_pointer(), 7); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Owner::constructor_1(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let total: Ptr = total.as_pointer(); @@ -101,7 +95,7 @@ fn main_0() -> i32 { ({ (*consume.borrow()).call() }); ({ (*consume.borrow()).call() }); assert!(({ ((*total.borrow()) == 7) })); - object!(o2, Owner(9)); + object!(o2, Owner::constructor_1(9)); let t: Value i32>> = Rc::new(RefCell::new(({ Owner::take(o2.as_pointer()) }))); let _dtor_t = std::mem::DropGuard::new(t.clone(), |__p| Destructible::destroy(__p.as_pointer())); diff --git a/tests/unit/out/refcount/libc_struct_without_default.rs b/tests/unit/out/refcount/libc_struct_without_default.rs index c1e185a851..cbe1a2dcb5 100644 --- a/tests/unit/out/refcount/libc_struct_without_default.rs +++ b/tests/unit/out/refcount/libc_struct_without_default.rs @@ -20,7 +20,8 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(32)] pub struct UserDefined { #[offset(0)] diff --git a/tests/unit/out/refcount/map.rs b/tests/unit/out/refcount/map.rs index 8a21920d6f..d4c16f8bde 100644 --- a/tests/unit/out/refcount/map.rs +++ b/tests/unit/out/refcount/map.rs @@ -26,8 +26,9 @@ pub fn inc_2(x: Ptr) { TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] -#[constructor(constructor_2, value(i32), value(i32))] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, i32, i32)] #[byte_size(8)] pub struct Point { #[offset(0)] diff --git a/tests/unit/out/refcount/map_key_copy_ctor.rs b/tests/unit/out/refcount/map_key_copy_ctor.rs index b181f563ef..c8c3306cea 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -16,28 +16,27 @@ thread_local!( pub static made_2: Value = Rc::new(RefCell::new(0)); ); #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct Key { #[offset(0)] pub k: i32, } impl Key { - pub fn construct(this: Ptr, mut k: i32) { + pub fn constructor_1(this: Ptr, mut k: i32) { field!(this, k).write(k); } -} -impl CopyConstructible for Key { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(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: RvalueRef) { + pub fn constructor_3(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(); @@ -50,7 +49,7 @@ impl LessThanComparable for Key { } pub fn make_key_3(__return: Ptr, mut k: i32) { (*made_2.with(Value::clone).borrow_mut()).prefix_inc(); - Key::construct(__return.clone(), k); + Key::constructor_1(__return.clone(), k); return; } pub fn main() { @@ -60,9 +59,9 @@ pub fn main() { fn main_0() -> i32 { let mut ok: bool = true; let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); - object!(a, Key(1)); - object!(b, Key(2)); - object!(c, Key(3)); + object!(a, Key::constructor_1(1)); + object!(b, Key::constructor_1(2)); + object!(c, Key::constructor_1(3)); match (a.as_pointer(),) { (__tmp_0,) => ({ (*m.borrow_mut()).subscript(__tmp_0, || 0_i32) }), } @@ -107,7 +106,7 @@ fn main_0() -> i32 { }; ok = { ((ok as i32) & ((copies_0.with(|rc| *rc.borrow()) == 2) as i32)) != 0 }; { - let __tmp_4: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_4: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ ({ make_key_3(Ptr::clone(&__tmp_4.as_pointer()), 4) }); __tmp_4.as_pointer() @@ -126,7 +125,7 @@ fn main_0() -> i32 { .write(40) }; { - let __tmp_6: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_6: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ ({ make_key_3(Ptr::clone(&__tmp_6.as_pointer()), 4) }); __tmp_6.as_pointer() @@ -202,9 +201,9 @@ fn main_0() -> i32 { .0 .as_pointer()); { - let __tmp_12: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_12: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - Key::construct(__tmp_12.as_pointer(), 0); + Key::constructor_1(__tmp_12.as_pointer(), 0); __tmp_12.as_pointer() },) { diff --git a/tests/unit/out/refcount/map_key_identity.rs b/tests/unit/out/refcount/map_key_identity.rs index cee6bfa7de..9140286dc0 100644 --- a/tests/unit/out/refcount/map_key_identity.rs +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -20,7 +20,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Key { #[offset(0)] @@ -33,14 +35,26 @@ impl LessThanComparable for Key { return ({ a.with(|__s| __s.order) } < { b.with(|__s| __s.order) }); } } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct Mapped { #[offset(0)] pub value: i32, } -impl DefaultConstructible for Mapped { - fn default_constructor(this: Ptr) { +impl Mapped { + pub fn constructor_1(this: Ptr) { field!(this, value).write(0); (*default_constructions_0.with(Value::clone).borrow_mut()).prefix_inc(); } @@ -49,8 +63,8 @@ impl Default for Mapped { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Mapped::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index 1ee6e1bce2..e79f634576 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -18,33 +18,31 @@ thread_local!( thread_local!( pub static moves_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible)] -#[cpp_from(i32, construct_1, value)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, i32)] +#[constructor(constructor_3, LvalueRef>)] +#[constructor(constructor_4, RvalueRef)] #[byte_size(4)] pub struct Item { #[offset(0)] pub value: i32, } impl Item { - pub fn construct_1(this: Ptr, mut value: i32) { + pub fn constructor_1(this: Ptr) { + field!(this, value).write(0); + } + pub fn constructor_2(this: Ptr, mut value: i32) { field!(this, value).write(value); (*made_1.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl DefaultConstructible for Item { - fn default_constructor(this: Ptr) { - field!(this, value).write(0); - } -} -impl CopyConstructible for Item { - fn copy_constructor(this: Ptr, other: LvalueRef>) { + pub fn constructor_3(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: RvalueRef) { + pub fn constructor_4(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(); @@ -55,8 +53,8 @@ impl Default for Item { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -66,14 +64,31 @@ pub fn argument_4(item: Ptr) -> Ptr { (*calls_0.with(Value::clone).borrow_mut()).prefix_inc(); return (item).clone(); } -#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyCopyable, + Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef, i32 )] #[byte_size(4)] pub struct RefItem { #[offset(0)] pub value: i32, } impl RefItem { - pub fn construct_1(this: Ptr, counter: Ptr, mut amount: i32) { + pub fn constructor_1(this: Ptr) { + field!(this, value).write(0); + } + pub fn constructor_2(this: Ptr, counter: LvalueRef, mut amount: i32) { + let counter = counter.as_pointer(); field!(this, value).write({ { counter.with_mut(|__v| *__v = *__v + amount) @@ -83,17 +98,12 @@ impl RefItem { (*made_1.with(Value::clone).borrow_mut()).prefix_inc(); } } -impl DefaultConstructible for RefItem { - fn default_constructor(this: Ptr) { - field!(this, value).write(0); - } -} impl Default for RefItem { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + RefItem::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -364,8 +374,8 @@ 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())); - Item::construct_1(__v.as_pointer(), 10); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_2(__v.as_pointer(), 10); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -375,7 +385,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(__inserted)), ) }; - object!(source, Item::construct_1(20)); + object!(source, Item::constructor_2(20)); made_1.with(|rc| { *rc.borrow_mut() = { copies_2.with(|rc| { @@ -398,8 +408,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())); - CopyConstructible::copy_constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_3( __v.as_pointer(), LvalueRef::bind((__tmp_7).clone()), ); @@ -440,8 +451,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())); - MoveConstructible::move_constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_4( __v.as_pointer(), RvalueRef::bind((__tmp_8).clone()), ); @@ -481,8 +493,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())); - CopyConstructible::copy_constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_3( __v.as_pointer(), LvalueRef::bind((__tmp_9).clone()), ); @@ -524,8 +537,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())); - MoveConstructible::move_constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_4( __v.as_pointer(), RvalueRef::bind((__tmp_10).clone()), ); @@ -564,8 +578,13 @@ 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())); - RefItem::construct_1(__v.as_pointer(), counter.as_pointer(), 5); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + RefItem::constructor_2( + __v.as_pointer(), + LvalueRef::bind(counter.as_pointer()), + 5, + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -586,8 +605,13 @@ 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())); - RefItem::construct_1(__v.as_pointer(), (__tmp_11).clone(), 2); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + RefItem::constructor_2( + __v.as_pointer(), + LvalueRef::bind((__tmp_11).clone()), + 2, + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -617,8 +641,13 @@ 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())); - RefItem::construct_1(__v.as_pointer(), (__tmp_12).clone(), 2); + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + RefItem::constructor_2( + __v.as_pointer(), + LvalueRef::bind((__tmp_12).clone()), + 2, + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -663,9 +692,9 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_14: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_14: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - Item::construct_1(__tmp_14.as_pointer(), 30); + Item::constructor_2(__tmp_14.as_pointer(), 30); __tmp_14.as_pointer() },) { @@ -675,8 +704,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())); - MoveConstructible::move_constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_4( __v.as_pointer(), RvalueRef::bind((__tmp_13).clone()), ); @@ -706,9 +736,9 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_16: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_16: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - Item::construct_1(__tmp_16.as_pointer(), 40); + Item::constructor_2(__tmp_16.as_pointer(), 40); __tmp_16.as_pointer() },) { @@ -718,8 +748,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())); - MoveConstructible::move_constructor( + let __v: Value = + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Item::constructor_4( __v.as_pointer(), RvalueRef::bind((__tmp_15).clone()), ); diff --git a/tests/unit/out/refcount/map_try_emplace_lvalues.rs b/tests/unit/out/refcount/map_try_emplace_lvalues.rs index 0b1c51570b..9ee23c4dd4 100644 --- a/tests/unit/out/refcount/map_try_emplace_lvalues.rs +++ b/tests/unit/out/refcount/map_try_emplace_lvalues.rs @@ -23,8 +23,9 @@ thread_local!( TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] -#[constructor(constructor_2, lvalue_ref(i32), value(i32))] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef, i32 )] #[byte_size(4)] pub struct Item { #[offset(0)] @@ -72,7 +73,8 @@ thread_local!( #[derive( Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(12)] pub struct Temporary { #[offset(0)] @@ -111,7 +113,8 @@ impl Default for Temporary { Default, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(12)] pub struct Nested { #[offset(0)] @@ -140,7 +143,8 @@ pub fn make_nested_6() -> Nested { #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] -#[conversions(move, default = constructor_1)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct Owner { #[offset(0)] @@ -171,7 +175,7 @@ impl Default for Owner { } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] -#[conversions(default = constructor_1)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct Noncopy { #[offset(0)] @@ -190,8 +194,9 @@ impl Default for Noncopy { #[derive( Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] -#[constructor(constructor_2, const_lvalue_ref(i32))] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(8)] pub struct Held { #[offset(0)] diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index 8ddeaa17c7..754e499b86 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -25,7 +25,6 @@ pub fn pick_3(mut i: i32) -> Ptr { ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Memberwise, MoveConstructible, @@ -34,19 +33,20 @@ pub fn pick_3(mut i: i32) -> Ptr { Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct Bag { #[offset(0)] pub n: i32, } impl Bag { - pub fn construct(this: Ptr, mut n: i32) { + pub fn constructor_1(this: Ptr, mut n: i32) { field!(this, n).write(n); } -} -impl CopyConstructible for Bag { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(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(); @@ -58,7 +58,7 @@ impl LessThanComparable for Bag { } } pub fn make_4(__return: Ptr, mut n: i32) { - Bag::construct(__return.clone(), n); + Bag::constructor_1(__return.clone(), n); return; } pub fn main() { @@ -159,8 +159,8 @@ fn main_0() -> i32 { calls_0.with(|rc| *rc.borrow_mut() = 0); assert!( ({ - let __tmp_7: Value = Rc::new(RefCell::new(::zero_init())); - let __tmp_9: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_7: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + let __tmp_9: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); (match ( { ({ make_4(Ptr::clone(&__tmp_7.as_pointer()), 1) }); @@ -185,8 +185,8 @@ fn main_0() -> i32 { .with(|__s| __s.n) == 2) }) && ({ - let __tmp_11: Value = Rc::new(RefCell::new(::zero_init())); - let __tmp_13: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_11: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + let __tmp_13: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); (match ( { ({ make_4(Ptr::clone(&__tmp_11.as_pointer()), 1) }); diff --git a/tests/unit/out/refcount/move_assign.rs b/tests/unit/out/refcount/move_assign.rs index 56a09bd1b9..b091e740be 100644 --- a/tests/unit/out/refcount/move_assign.rs +++ b/tests/unit/out/refcount/move_assign.rs @@ -11,24 +11,24 @@ use std::rc::{Rc, Weak}; ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Swappable, Default, + Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct MoveOnly { #[offset(0)] pub v: i32, } impl MoveOnly { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl MoveConstructible for MoveOnly { - fn move_constructor(this: Ptr, o: RvalueRef) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); @@ -45,13 +45,17 @@ impl MoveAssignable for MoveOnly { return (this).clone(); } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct ConstMoveAssign { #[offset(0)] pub mark: i32, } impl ConstMoveAssign { + pub fn constructor_1(this: Ptr) { + field!(this, mark).write(0); + } pub fn operator_assign_2(this: Ptr, o: Ptr) -> Ptr { field!(this, mark).write((o.with(|__s| __s.mark) + 1)); return (this).clone(); @@ -61,26 +65,21 @@ impl ConstMoveAssign { return (this).clone(); } } -impl DefaultConstructible for ConstMoveAssign { - fn default_constructor(this: Ptr) { - field!(this, mark).write(0); - } -} impl Default for ConstMoveAssign { fn default() -> Self { { { let __v: Value = - Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + Rc::new(RefCell::new(ZeroInitialization::zero_init())); + ConstMoveAssign::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } } } pub fn make_0(__return: Ptr, mut v: i32) { - object!(m, MoveOnly(v)); - MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind(m.as_pointer())); + object!(m, MoveOnly::constructor_1(v)); + MoveOnly::constructor_3(__return.clone(), RvalueRef::bind(m.as_pointer())); return; } pub fn main() { @@ -88,15 +87,15 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, MoveOnly(1)); - object!(b, MoveOnly(2)); - object!(c, MoveOnly(3)); + object!(a, MoveOnly::constructor_1(1)); + object!(b, MoveOnly::constructor_1(2)); + object!(c, MoveOnly::constructor_1(3)); 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); + let _o: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MoveOnly::constructor_1(_o.as_pointer(), 3); assign!(b = RvalueRef(_o)) }); assign!(c = RvalueRef(*assign!(a = RvalueRef(b)))); @@ -104,13 +103,13 @@ fn main_0() -> i32 { (({ (*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); + let _o: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MoveOnly::constructor_1(_o.as_pointer(), 5); assign!(a = RvalueRef(_o)) }); assert!(({ (*a.borrow()).v } == 5)); ({ - let _o: Value = Rc::new(RefCell::new(::zero_init())); + let _o: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ make_0(Ptr::clone(&_o.as_pointer()), 6) }); assign!(a = RvalueRef(_o)) }); @@ -119,23 +118,23 @@ fn main_0() -> i32 { assert!(({ (*a.borrow()).v } == 6)); let vec_: Value> = Rc::new(RefCell::new(Vec::new())); { - let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - MoveOnly::construct(__tmp_1.as_pointer(), 7); + MoveOnly::constructor_1(__tmp_1.as_pointer(), 7); __tmp_1.as_pointer() },) { (__tmp_0,) => MoveConstructible::push_moved(&vec_.as_pointer(), (__tmp_0).clone()), } }; - object!(d, MoveOnly(8)); + object!(d, MoveOnly::constructor_1(8)); assign!(*vec_.decay().offset(0_usize) = RvalueRef(d)); assert!(({ (*vec_.borrow())[0_usize].v } == 8)); assert!(({ (*d.borrow()).v } == 0)); - object!(m, ConstMoveAssign); - object!(m1, ConstMoveAssign); - object!(m2, ConstMoveAssign); - object!(cm, ConstMoveAssign); + object!(m, ConstMoveAssign::constructor_1()); + object!(m1, ConstMoveAssign::constructor_1()); + object!(m2, ConstMoveAssign::constructor_1()); + object!(cm, ConstMoveAssign::constructor_1()); ConstMoveAssign::operator_assign_2(m1.as_pointer(), m.as_pointer()); ConstMoveAssign::operator_assign_3(m2.as_pointer(), cm.as_pointer()); assert!(({ (*m1.borrow()).mark } == 1)); diff --git a/tests/unit/out/refcount/move_ctor.rs b/tests/unit/out/refcount/move_ctor.rs index f87768df30..d1b1faf1c4 100644 --- a/tests/unit/out/refcount/move_ctor.rs +++ b/tests/unit/out/refcount/move_ctor.rs @@ -7,60 +7,67 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct MoveOnly { #[offset(0)] pub v: i32, } impl MoveOnly { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl MoveConstructible for MoveOnly { - fn move_constructor(this: Ptr, o: RvalueRef) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Conversions)] +#[conversions(move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, RvalueRef)] +#[constructor(constructor_3, RvalueRef>)] #[byte_size(4)] pub struct ConstMove { #[offset(0)] pub mark: i32, } impl ConstMove { - pub fn construct_1(this: Ptr, o: Ptr) { + pub fn constructor_1(this: Ptr) { + field!(this, mark).write(0); + } + pub fn constructor_2(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); field!(this, mark).write((o.with(|__s| __s.mark) + 1)); } - pub fn construct_2(this: Ptr, o: Ptr) { + pub fn constructor_3(this: Ptr, o: RvalueRef>) { + let o = o.as_pointer(); field!(this, mark).write((o.with(|__s| __s.mark) + 10)); } } -impl DefaultConstructible for ConstMove { - fn default_constructor(this: Ptr) { - field!(this, mark).write(0); - } -} impl Default for ConstMove { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + ConstMove::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } } } #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(12)] pub struct ThrowingMove { #[offset(0)] @@ -71,22 +78,18 @@ pub struct ThrowingMove { pub moves: i32, } impl ThrowingMove { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl CopyConstructible for ThrowingMove { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(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: RvalueRef) { + pub fn constructor_3(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)); @@ -95,9 +98,12 @@ impl MoveConstructible for ThrowingMove { } } #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(12)] pub struct NoexceptMove { #[offset(0)] @@ -108,22 +114,18 @@ pub struct NoexceptMove { pub moves: i32, } impl NoexceptMove { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); field!(this, copies).write(0); field!(this, moves).write(0); } -} -impl CopyConstructible for NoexceptMove { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(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: RvalueRef) { + pub fn constructor_3(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)); @@ -131,12 +133,13 @@ impl MoveConstructible for NoexceptMove { field!(o, v).write(0); } } -pub fn by_value_0(m: Ptr) -> i32 { +pub fn by_value_0(m: ParameterObject) -> i32 { + let m = m.as_pointer(); return m.with(|__s| __s.v); } pub fn make_1(__return: Ptr, mut v: i32) { - object!(m, MoveOnly(v)); - MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind(m.as_pointer())); + object!(m, MoveOnly::constructor_1(v)); + MoveOnly::constructor_3(__return.clone(), RvalueRef::bind(m.as_pointer())); return; } pub fn main() { @@ -144,75 +147,87 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, MoveOnly(1)); - object!(b, MoveOnly, RvalueRef::bind(a.as_pointer())); + object!(a, MoveOnly::constructor_1(1)); + object!(b, MoveOnly::constructor_3(RvalueRef::bind(a.as_pointer()))); assert!(({ (*b.borrow()).v } == 1)); assert!(({ (*a.borrow()).v } == 0)); - object!(c, MoveOnly, RvalueRef::bind(b.as_pointer())); + object!(c, MoveOnly::constructor_3(RvalueRef::bind(b.as_pointer()))); assert!(({ (*c.borrow()).v } == 1)); assert!(({ (*b.borrow()).v } == 0)); - object!(d, MoveOnly, RvalueRef::bind(c.as_pointer())); + object!(d, MoveOnly::constructor_3(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,) })); assert!(({ (*e.borrow()).v } == 5)); assert!( (({ - let _m: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnly::construct(_m.as_pointer(), 6); - by_value_0(_m.as_pointer()) + let _m: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MoveOnly::constructor_1(_m.as_pointer(), 6); + by_value_0(ParameterObject::bind(_m.as_pointer())) }) == 6) ); assert!( (({ - let _m: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor(_m.as_pointer(), RvalueRef::bind(e.as_pointer())); - by_value_0(_m.as_pointer()) + let _m: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MoveOnly::constructor_3(_m.as_pointer(), RvalueRef::bind(e.as_pointer())); + by_value_0(ParameterObject::bind(_m.as_pointer())) }) == 5) ); assert!(({ (*e.borrow()).v } == 0)); let vec_: Value> = Rc::new(RefCell::new(Vec::new())); { - let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - MoveOnly::construct(__tmp_1.as_pointer(), 7); + MoveOnly::constructor_1(__tmp_1.as_pointer(), 7); __tmp_1.as_pointer() },) { (__tmp_0,) => MoveConstructible::push_moved(&vec_.as_pointer(), (__tmp_0).clone()), } }; - object!(f, MoveOnly(8)); + object!(f, MoveOnly::constructor_1(8)); MoveConstructible::push_moved(&vec_.as_pointer(), f.as_pointer()); assert!(({ (*vec_.borrow())[0_usize].v } == 7) && ({ (*vec_.borrow())[1_usize].v } == 8)); assert!(({ (*f.borrow()).v } == 0)); - object!(m, ConstMove); - object!(m1, ConstMove::construct_1(m.as_pointer())); - object!(cm, ConstMove); - object!(m2, ConstMove::construct_2(cm.as_pointer())); + object!(m, ConstMove::constructor_1()); + object!( + m1, + ConstMove::constructor_2(RvalueRef::bind(m.as_pointer())) + ); + object!(cm, ConstMove::constructor_1()); + object!( + m2, + ConstMove::constructor_3(RvalueRef::bind(cm.as_pointer())) + ); assert!(({ (*m1.borrow()).mark } == 1)); assert!(({ (*m2.borrow()).mark } == 10)); - object!(t, ThrowingMove(1)); - object!(t1, ThrowingMove, LvalueRef::bind(t.as_pointer())); + object!(t, ThrowingMove::constructor_1(1)); + object!( + t1, + ThrowingMove::constructor_2(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, RvalueRef::bind(n.as_pointer())); + object!(n, NoexceptMove::constructor_1(2)); + object!( + n1, + NoexceptMove::constructor_3(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, RvalueRef::bind(g.as_pointer())); + object!(g, MoveOnly::constructor_1(3)); + object!(g1, MoveOnly::constructor_3(RvalueRef::bind(g.as_pointer()))); assert!(({ (*g1.borrow()).v } == 3)); assert!(({ (*g.borrow()).v } == 0)); let nv: Value> = Rc::new(RefCell::new(Vec::new())); { - let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_3: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); match ({ - NoexceptMove::construct(__tmp_3.as_pointer(), 4); + NoexceptMove::constructor_1(__tmp_3.as_pointer(), 4); __tmp_3.as_pointer() },) { diff --git a/tests/unit/out/refcount/move_this.rs b/tests/unit/out/refcount/move_this.rs index 8af642151c..a3f1965027 100644 --- a/tests/unit/out/refcount/move_this.rs +++ b/tests/unit/out/refcount/move_this.rs @@ -7,18 +7,30 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct Chain { #[offset(0)] pub v: i32, } impl Chain { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } + pub fn constructor_2(this: Ptr, o: LvalueRef>) { + let o = o.as_pointer(); + field!(this, v).write((o.with(|__s| __s.v) + 100)); + } + pub fn constructor_3(this: Ptr, o: RvalueRef) { + let o = o.as_pointer(); + field!(this, v).write((o.with(|__s| __s.v) + 1)); + field!(o, v).write(0); + } pub fn add_4(this: Ptr, mut n: i32) -> Ptr { { field!(this, v).with_mut(|__v| *__v = *__v + n) @@ -32,31 +44,19 @@ impl Chain { return (this).clone(); } pub fn take(this: Ptr, __return: Ptr) { - MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind((this).clone())); + Chain::constructor_3(__return.clone(), RvalueRef::bind((this).clone())); return; } pub fn copy(this: Ptr, __return: Ptr) { - CopyConstructible::copy_constructor(__return.clone(), LvalueRef::bind((this).clone())); + Chain::constructor_2(__return.clone(), LvalueRef::bind((this).clone())); return; } pub fn self_(this: Ptr) -> Ptr { return (this).clone(); } } -impl CopyConstructible for Chain { - 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: RvalueRef) { - let o = o.as_pointer(); - field!(this, v).write((o.with(|__s| __s.v) + 1)); - field!(o, v).write(0); - } -} -pub fn consume_0(c: Ptr) -> i32 { +pub fn consume_0(c: ParameterObject) -> i32 { + let c = c.as_pointer(); return c.with(|__s| __s.v); } pub fn main() { @@ -64,22 +64,23 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, Chain(1)); + object!(a, Chain::constructor_1(1)); ({ Chain::add_4(({ Chain::add_4(a.as_pointer(), 1) }), 1) }); assert!(({ (*a.borrow()).v } == 3)); - object!(b0, Chain(5)); + object!(b0, Chain::constructor_1(5)); object!( b, - Chain, - RvalueRef::bind(({ Chain::add_5(({ Chain::add_5(b0.as_pointer(), 1,) }), 1,) })) + Chain::constructor_3(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| { - let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_0: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ Chain::take( { - Chain::construct(__tmp_0.as_pointer(), 10); + Chain::constructor_1(__tmp_0.as_pointer(), 10); __tmp_0.as_pointer() }, Ptr::clone(&c.clone()), @@ -91,18 +92,18 @@ fn main_0() -> i32 { Chain::copy(c.as_pointer(), Ptr::clone(&d.clone())) })); assert!(({ (*d.borrow()).v } == 111) && ({ (*c.borrow()).v } == 11)); - object!(g, Chain(20)); + object!(g, Chain::constructor_1(20)); assert!( (({ - let _c: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor( + let _c: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Chain::constructor_3( _c.as_pointer(), RvalueRef::bind(({ Chain::self_(g.as_pointer()) })), ); - consume_0(_c.as_pointer()) + consume_0(ParameterObject::bind(_c.as_pointer())) }) == 21) ); - object!(e, Chain(30)); + object!(e, Chain::constructor_1(30)); object!(f, Chain, |f| ({ Chain::take(e.as_pointer(), Ptr::clone(&f.clone())) })); diff --git a/tests/unit/out/refcount/operator_comparison_defaulted.rs b/tests/unit/out/refcount/operator_comparison_defaulted.rs index a511b9ee95..5a2c77a088 100644 --- a/tests/unit/out/refcount/operator_comparison_defaulted.rs +++ b/tests/unit/out/refcount/operator_comparison_defaulted.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Eq { #[offset(0)] @@ -39,6 +41,8 @@ pub struct Eq { PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(8)] pub struct Cmp { #[offset(0)] @@ -89,6 +93,8 @@ impl LessThanComparable for Cmp { PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct Both { #[offset(0)] @@ -128,6 +134,8 @@ impl LessThanComparable for Both { PartiallyOrderedWith, )] #[three_way(OrdOnly::operator_cmp)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct OrdOnly { #[offset(0)] @@ -166,6 +174,8 @@ impl LessThanComparable for OrdOnly { PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct Inner { #[offset(0)] @@ -205,6 +215,8 @@ impl LessThanComparable for Inner { PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(8)] pub struct Outer { #[offset(0)] @@ -252,7 +264,9 @@ impl LessThanComparable for Outer { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Secondary { #[offset(0)] @@ -291,6 +305,8 @@ impl LessThanComparable for Secondary { PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(8)] pub struct PtrMember { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_comparison_free.rs b/tests/unit/out/refcount/operator_comparison_free.rs index 00fa12bc4e..8601f21645 100644 --- a/tests/unit/out/refcount/operator_comparison_free.rs +++ b/tests/unit/out/refcount/operator_comparison_free.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -45,7 +47,9 @@ pub fn operator_lt_1(mut a: i32, b: Ptr) -> bool { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct V { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_comparison_member.rs b/tests/unit/out/refcount/operator_comparison_member.rs index 95230986c7..acadd8cc62 100644 --- a/tests/unit/out/refcount/operator_comparison_member.rs +++ b/tests/unit/out/refcount/operator_comparison_member.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_comparison_nonbool.rs b/tests/unit/out/refcount/operator_comparison_nonbool.rs index 8c03fcda7f..fe5d82ba36 100644 --- a/tests/unit/out/refcount/operator_comparison_nonbool.rs +++ b/tests/unit/out/refcount/operator_comparison_nonbool.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct X { #[offset(0)] @@ -57,7 +59,9 @@ pub fn operator_ge_3(mut a: X, mut b: X) -> i32 { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Result { #[offset(0)] @@ -74,7 +78,9 @@ pub struct Result { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Custom { #[offset(0)] @@ -98,7 +104,9 @@ impl Custom { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Mixed { #[offset(0)] @@ -138,19 +146,21 @@ impl LessThanComparable for Mixed { ZeroInitialization, VaArg, FnPtrArg, - CppFrom, DefaultConstructible, TriviallyCopyable, Default, + Conversions, )] -#[cpp_into(bool, to_bool)] +#[conversions(copy, move)] +#[constructor(constructor_1, explicit, bool)] +#[conversion_function(to_bool, LvalueRef>, bool )] #[byte_size(1)] pub struct MyBool { #[offset(0)] pub value: bool, } impl MyBool { - pub fn construct(this: Ptr, mut v: bool) { + pub fn constructor_1(this: Ptr, mut v: bool) { field!(this, value).write(v); } pub fn to_bool(this: Ptr) -> bool { @@ -168,7 +178,9 @@ impl MyBool { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Boolish { #[offset(0)] @@ -184,15 +196,15 @@ impl LessThanComparable for Boolish { } pub fn operator_eq_7(mut a: Boolish, mut b: Boolish) -> MyBool { return { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MyBool::construct(__v.as_pointer(), (a.v == b.v)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MyBool::constructor_1(__v.as_pointer(), (a.v == b.v)); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } pub fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { return { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MyBool::construct(__v.as_pointer(), (a.v < b.v)); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MyBool::constructor_1(__v.as_pointer(), (a.v < b.v)); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -201,21 +213,22 @@ pub fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Memberwise, MoveAssignable, Default, )] #[memberwise(copy_assign)] -#[cpp_into(bool, to_bool)] +#[derive(Conversions)] +#[constructor(constructor_1, explicit, bool)] +#[conversion_function(to_bool, LvalueRef>, bool )] #[byte_size(1)] pub struct RefBool { #[offset(0)] pub value: bool, } impl RefBool { - pub fn construct(this: Ptr, mut v: bool) { + pub fn constructor_1(this: Ptr, mut v: bool) { field!(this, value).write(v); } pub fn to_bool(this: Ptr) -> bool { @@ -224,8 +237,8 @@ impl RefBool { } thread_local!( pub static ref_true_8: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - RefBool::construct(__v.as_pointer(), true); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + RefBool::constructor_1(__v.as_pointer(), true); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -240,7 +253,9 @@ thread_local!( TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct RefInt { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_comparison_noncopyable.rs b/tests/unit/out/refcount/operator_comparison_noncopyable.rs index 5428aa4572..100f191845 100644 --- a/tests/unit/out/refcount/operator_comparison_noncopyable.rs +++ b/tests/unit/out/refcount/operator_comparison_noncopyable.rs @@ -12,24 +12,19 @@ impl LessThanComparable for S { } } #[derive( - Record, - ByteRepr, - ZeroInitialization, - FnPtrArg, - CppFrom, - DefaultInitializable, - Memberwise, - Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, )] #[memberwise(move_constructor)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct S { #[offset(0)] data_: i32, } impl S { - pub fn construct(this: Ptr, mut data: i32) { + pub fn constructor_1(this: Ptr, mut data: i32) { field!(this, data_).write(data); } } @@ -38,9 +33,9 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, S(1)); - object!(b, S(2)); - object!(c, S(1)); + object!(a, S::constructor_1(1)); + object!(b, S::constructor_1(2)); + object!(c, S::constructor_1(1)); assert!(({ WeaklyEqualityComparableWith::equal(a.as_pointer(), c.as_pointer(),) })); assert!(({ LessThanComparable::less(a.as_pointer(), b.as_pointer(),) })); assert!(!({ LessThanComparable::less(b.as_pointer(), a.as_pointer(),) })); diff --git a/tests/unit/out/refcount/operator_friend.rs b/tests/unit/out/refcount/operator_friend.rs index e22d7ed68c..73a37d4914 100644 --- a/tests/unit/out/refcount/operator_friend.rs +++ b/tests/unit/out/refcount/operator_friend.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Defaulted { #[offset(0)] @@ -54,6 +56,8 @@ impl ThreeWayComparable for DefaultedOrd { PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct DefaultedOrd { #[offset(0)] @@ -85,7 +89,9 @@ pub fn operator_add_0(x: Ptr, y: Ptr) -> Inline { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Inline { #[offset(0)] @@ -102,7 +108,9 @@ pub struct Inline { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct OutOfLine { #[offset(0)] @@ -124,7 +132,9 @@ impl LessThanComparable for Tmpl_int_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Tmpl_int_ { #[offset(0)] @@ -141,7 +151,9 @@ pub struct Tmpl_int_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Tmpl_long_ { #[offset(0)] @@ -158,7 +170,9 @@ pub struct Tmpl_long_ { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct TmplDefaulted_int_ { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_less_than.rs b/tests/unit/out/refcount/operator_less_than.rs index b62e640d02..92681a1bd6 100644 --- a/tests/unit/out/refcount/operator_less_than.rs +++ b/tests/unit/out/refcount/operator_less_than.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Pair { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_other_member.rs b/tests/unit/out/refcount/operator_other_member.rs index 6c34761050..e933c0b1ef 100644 --- a/tests/unit/out/refcount/operator_other_member.rs +++ b/tests/unit/out/refcount/operator_other_member.rs @@ -41,8 +41,8 @@ impl Static { Conversions, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_5, i32, const_lvalue_ref)] -#[conversion_function(conversion_function_6, bool, const_lvalue_ref, explicit)] +#[conversion_function(to_i32, LvalueRef>, i32 )] +#[conversion_function(to_bool, LvalueRef>, bool , explicit)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -63,15 +63,11 @@ impl S { v: ({ (this.with(|__s| __s.v) * 10) } + { o.with(|__s| __s.v) }), }; } - pub fn conversion_function_5(this: LvalueRef>, __return: Ptr) { - let this = this.as_pointer(); - __return.write(this.with(|__s| __s.v)); - return; + pub fn to_i32(this: Ptr) -> i32 { + return this.with(|__s| __s.v); } - pub fn conversion_function_6(this: LvalueRef>, __return: Ptr) { - let this = this.as_pointer(); - __return.write((this.with(|__s| __s.v) != 0)); - return; + pub fn to_bool(this: Ptr) -> bool { + return (this.with(|__s| __s.v) != 0); } } pub fn main() { @@ -85,81 +81,18 @@ fn main_0() -> i32 { assert!((({ S::operator_call_2(s.as_pointer(), 1,) }) == 4)); assert!((({ S::operator_call_3(s.as_pointer(), 1, 2,) }) == 6)); assert!(({ ({ S::operator_comma(s.as_pointer(), t.as_pointer(),) }).v } == 34)); - let mut i: i32 = { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - S::conversion_function_5( - >>::bind(s.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; + let mut i: i32 = ({ S::to_i32(s.as_pointer()) }); assert!((i == 3)); - assert!( - (({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - S::conversion_function_5( - >>::bind(s.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } + 1) - == 4) - ); - if { - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - S::conversion_function_6( - >>::bind(s.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } { - assert!({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - S::conversion_function_6( - >>::bind(s.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }); + assert!(((({ S::to_i32(s.as_pointer(),) }) + 1) == 4)); + if ({ S::to_bool(s.as_pointer()) }) { + assert!(({ S::to_bool(s.as_pointer(),) })); } else { assert!(false); } let z: Value = Rc::new(RefCell::new(S { v: 0 })); - assert!({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - S::conversion_function_6( - >>::bind(s.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }); - assert!( - !({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - S::conversion_function_6( - >>::bind(z.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }) - ); - assert!( - ({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - S::conversion_function_6( - >>::bind(s.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }) && (!({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - S::conversion_function_6( - >>::bind(z.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })) - ); + assert!(({ S::to_bool(s.as_pointer(),) })); + assert!(!({ S::to_bool(z.as_pointer(),) })); + assert!(({ S::to_bool(s.as_pointer(),) }) && (!({ S::to_bool(z.as_pointer(),) }))); let st: Value = Rc::new(RefCell::new(::default())); assert!((({ Static::operator_call(6, 7,) }) == 42)); assert!((({ S::operator_call_1(Rc::new(RefCell::new(S { v: 5 })).as_pointer(),) }) == 5)); diff --git a/tests/unit/out/refcount/operator_three_way.rs b/tests/unit/out/refcount/operator_three_way.rs index 96e874ef02..3174e5eb07 100644 --- a/tests/unit/out/refcount/operator_three_way.rs +++ b/tests/unit/out/refcount/operator_three_way.rs @@ -20,6 +20,8 @@ use std::rc::{Rc, Weak}; PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_traits.rs b/tests/unit/out/refcount/operator_traits.rs index 3327a1528d..1d662beb1d 100644 --- a/tests/unit/out/refcount/operator_traits.rs +++ b/tests/unit/out/refcount/operator_traits.rs @@ -17,7 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Lt { #[offset(0)] @@ -39,7 +41,9 @@ impl LessThanComparable for Lt { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Eq { #[offset(0)] @@ -59,6 +63,8 @@ pub struct Eq { PartiallyOrderedWith, )] #[three_way(ThreeWayComparable::three_way)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(4)] pub struct Cmp { #[offset(0)] @@ -89,7 +95,9 @@ impl LessThanComparable for Cmp { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Free { #[offset(0)] @@ -111,7 +119,9 @@ impl LessThanComparable for Free { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(4)] pub struct Wrapped_int_ { #[offset(0)] diff --git a/tests/unit/out/refcount/pair.rs b/tests/unit/out/refcount/pair.rs index ae6933b441..5140efef8b 100644 --- a/tests/unit/out/refcount/pair.rs +++ b/tests/unit/out/refcount/pair.rs @@ -30,14 +30,24 @@ fn main_0() -> i32 { ))) .as_pointer(),) { - (__tmp_0,) => ( - Rc::new(RefCell::new( - (((*__tmp_0.upgrade().deref()).0.as_pointer().read()) as f64), - )), - Rc::new(RefCell::new( - ((*__tmp_0.upgrade().deref()).1.as_pointer().read()), - )), - ), + (__tmp_0,) => { + object!(__first, f64, |__this| ConstructibleFrom::construct( + __this, + (RvalueRef::::bind( + (*__tmp_0.upgrade().deref()).0.as_pointer() + ),) + )); + object!(__second, i32, |__this| ConstructibleFrom::construct( + __this, + (RvalueRef::::bind( + (*__tmp_0.upgrade().deref()).1.as_pointer() + ),) + )); + ( + Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), + ) + } }, )); assert!(({ ((*(*p3.borrow()).0.borrow()) == 5_f64) })); @@ -60,10 +70,22 @@ fn main_0() -> i32 { .as_pointer(), ) { (__tmp_1, __tmp_2) => { - let __first = cpp_move!((*__tmp_2.upgrade().deref()).0.as_pointer()); - let __second = (((*__tmp_2.upgrade().deref()).1.as_pointer().read()) as u64); - *(*__tmp_1.upgrade().deref()).0.borrow_mut() = __first; - *(*__tmp_1.upgrade().deref()).1.borrow_mut() = __second; + object!(__first, Ptr, |__this| ConvertibleTo::convert( + RvalueRef::>::bind((*__tmp_2.upgrade().deref()).0.as_pointer()), + __this + )); + object!(__second, u64, |__this| ConvertibleTo::convert( + RvalueRef::::bind((*__tmp_2.upgrade().deref()).1.as_pointer()), + __this + )); + MoveAssignable::move_assign( + (*__tmp_1.upgrade().deref()).0.as_pointer(), + RvalueRef::>::bind(__first.as_pointer()), + ); + MoveAssignable::move_assign( + (*__tmp_1.upgrade().deref()).1.as_pointer(), + RvalueRef::::bind(__second.as_pointer()), + ); } }; assert!( @@ -132,10 +154,22 @@ fn main_0() -> i32 { ))); let mut pw: Ptr = ((*w.borrow()).0.as_pointer()); { - let __first = (((*narrow.borrow()).0.as_pointer().read()) as i64); - let __second = (((*narrow.borrow()).1.as_pointer().read()) as i64); - *(*w.borrow()).0.borrow_mut() = __first; - *(*w.borrow()).1.borrow_mut() = __second; + object!(__first, i64, |__this| ConvertibleTo::convert( + LvalueRef::>::bind((*narrow.borrow()).0.as_pointer()), + __this + )); + object!(__second, i64, |__this| ConvertibleTo::convert( + LvalueRef::>::bind((*narrow.borrow()).1.as_pointer()), + __this + )); + MoveAssignable::move_assign( + (*w.borrow()).0.as_pointer(), + RvalueRef::::bind(__first.as_pointer()), + ); + MoveAssignable::move_assign( + (*w.borrow()).1.as_pointer(), + RvalueRef::::bind(__second.as_pointer()), + ); }; assert!(((pw.read()) == 3_i64)); let m: Value<(Value, Value)> = Rc::new(RefCell::new(( @@ -143,10 +177,22 @@ fn main_0() -> i32 { Rc::new(RefCell::new(6)), ))); { - let __first = (((*m.borrow()).0.as_pointer().read()) as i64); - let __second = (((*m.borrow()).1.as_pointer().read()) as i64); - *(*w.borrow()).0.borrow_mut() = __first; - *(*w.borrow()).1.borrow_mut() = __second; + object!(__first, i64, |__this| ConvertibleTo::convert( + RvalueRef::::bind((*m.borrow()).0.as_pointer()), + __this + )); + object!(__second, i64, |__this| ConvertibleTo::convert( + RvalueRef::::bind((*m.borrow()).1.as_pointer()), + __this + )); + MoveAssignable::move_assign( + (*w.borrow()).0.as_pointer(), + RvalueRef::::bind(__first.as_pointer()), + ); + MoveAssignable::move_assign( + (*w.borrow()).1.as_pointer(), + RvalueRef::::bind(__second.as_pointer()), + ); }; assert!(((pw.read()) == 5_i64)); (*(*{ @@ -170,10 +216,22 @@ fn main_0() -> i32 { .borrow_mut()) = 8; assert!(({ ((*(*d.borrow()).0.borrow()) == 8) && ((*(*d.borrow()).1.borrow()) == 4) })); (*(*{ - let __first = (((*narrow.borrow()).0.as_pointer().read()) as i64); - let __second = (((*narrow.borrow()).1.as_pointer().read()) as i64); - *(*w.borrow()).0.borrow_mut() = __first; - *(*w.borrow()).1.borrow_mut() = __second; + object!(__first, i64, |__this| ConvertibleTo::convert( + LvalueRef::>::bind((*narrow.borrow()).0.as_pointer()), + __this + )); + object!(__second, i64, |__this| ConvertibleTo::convert( + LvalueRef::>::bind((*narrow.borrow()).1.as_pointer()), + __this + )); + MoveAssignable::move_assign( + (*w.borrow()).0.as_pointer(), + RvalueRef::::bind(__first.as_pointer()), + ); + MoveAssignable::move_assign( + (*w.borrow()).1.as_pointer(), + RvalueRef::::bind(__second.as_pointer()), + ); w.as_pointer() } .upgrade() @@ -182,10 +240,22 @@ fn main_0() -> i32 { .borrow_mut()) = 9_i64; assert!(({ ((*(*w.borrow()).0.borrow()) == 3_i64) && ((*(*w.borrow()).1.borrow()) == 9_i64) })); (*(*{ - let __first = (((*narrow.borrow()).0.as_pointer().read()) as i64); - let __second = (((*narrow.borrow()).1.as_pointer().read()) as i64); - *(*w.borrow()).0.borrow_mut() = __first; - *(*w.borrow()).1.borrow_mut() = __second; + object!(__first, i64, |__this| ConvertibleTo::convert( + RvalueRef::::bind((*narrow.borrow()).0.as_pointer()), + __this + )); + object!(__second, i64, |__this| ConvertibleTo::convert( + RvalueRef::::bind((*narrow.borrow()).1.as_pointer()), + __this + )); + MoveAssignable::move_assign( + (*w.borrow()).0.as_pointer(), + RvalueRef::::bind(__first.as_pointer()), + ); + MoveAssignable::move_assign( + (*w.borrow()).1.as_pointer(), + RvalueRef::::bind(__second.as_pointer()), + ); w.as_pointer() } .upgrade() diff --git a/tests/unit/out/refcount/pair_converting_construction.rs b/tests/unit/out/refcount/pair_converting_construction.rs index f74fa68341..c8e9e5de9f 100644 --- a/tests/unit/out/refcount/pair_converting_construction.rs +++ b/tests/unit/out/refcount/pair_converting_construction.rs @@ -20,7 +20,7 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct Celsius { #[offset(0)] @@ -45,17 +45,15 @@ impl Celsius { Conversions, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, i32, const_lvalue_ref)] +#[conversion_function(to_i32, LvalueRef>, i32 )] #[byte_size(4)] pub struct Meters { #[offset(0)] pub value: i32, } impl Meters { - pub fn conversion_function_1(this: LvalueRef>, __return: Ptr) { - let this = this.as_pointer(); - __return.write(this.with(|__s| __s.value)); - return; + pub fn to_i32(this: Ptr) -> i32 { + return this.with(|__s| __s.value); } } #[derive( @@ -72,7 +70,7 @@ impl Meters { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, const_lvalue_ref(Celsius))] +#[constructor(constructor_1, LvalueRef>)] #[byte_size(4)] pub struct Label { #[offset(0)] @@ -98,8 +96,8 @@ impl Label { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, const_lvalue_ref(Celsius))] -#[constructor(constructor_2, rvalue_ref(Celsius))] +#[constructor(constructor_1, LvalueRef>)] +#[constructor(constructor_2, RvalueRef)] #[byte_size(8)] pub struct Owner { #[offset(0)] @@ -133,7 +131,7 @@ impl Owner { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(Celsius))] +#[constructor(constructor_1, Celsius)] #[byte_size(4)] pub struct Holder { #[offset(0)] @@ -156,7 +154,7 @@ impl Holder { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct Fallback { #[offset(0)] @@ -218,7 +216,7 @@ pub struct Counter { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, lvalue_ref(Counter))] +#[constructor(constructor_1, LvalueRef)] #[byte_size(4)] pub struct Observer { #[offset(0)] @@ -251,7 +249,7 @@ impl Tag { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1_1, const_lvalue_ref(Celsius))] +#[constructor(constructor_1_1, LvalueRef>)] #[byte_size(4)] pub struct Tag { #[offset(0)] @@ -271,7 +269,7 @@ pub struct Tag { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(Ptr< i8 > ))] +#[constructor(constructor_1, Ptr< i8 > )] #[byte_size(4)] pub struct Name { #[offset(0)] @@ -314,24 +312,8 @@ fn main_0() -> i32 { assert!(({ (*(*from_ints.borrow()).1.borrow()).degrees } == 2)); let m: Value = Rc::new(RefCell::new(Meters { value: 7 })); let from_operators: Value<(Value, Value)> = Rc::new(RefCell::new(( - Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Meters::conversion_function_1( - >>::bind(m.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })), - Rc::new(RefCell::new( - ({ - let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Meters::conversion_function_1( - >>::bind(m.as_pointer()), - Ptr::clone(&__v.as_pointer()), - ); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - } as i64), - )), + Rc::new(RefCell::new(({ Meters::to_i32(m.as_pointer()) }))), + Rc::new(RefCell::new((({ Meters::to_i32(m.as_pointer()) }) as i64))), ))); assert!(({ ((*(*from_operators.borrow()).0.borrow()) == 7) })); assert!(({ ((*(*from_operators.borrow()).1.borrow()) == 7_i64) })); diff --git a/tests/unit/out/refcount/push_emplace_back.rs b/tests/unit/out/refcount/push_emplace_back.rs index 502f80a4f8..3a5e4706fa 100644 --- a/tests/unit/out/refcount/push_emplace_back.rs +++ b/tests/unit/out/refcount/push_emplace_back.rs @@ -62,7 +62,8 @@ pub struct Writer { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(48)] pub struct JPEGData { #[offset(0)] @@ -167,9 +168,10 @@ pub fn self_ref_push_6(mut comps: Ptr>) { TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] -#[constructor(constructor_2, value(i32))] -#[constructor(constructor_3, value(i32), value(i32))] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, i32)] +#[constructor(constructor_3, i32, i32)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -366,7 +368,8 @@ pub fn emplace_ref_self_read_13(values: Ptr>) -> Ptr { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(32)] pub struct Bytes { #[offset(0)] @@ -475,7 +478,7 @@ thread_local!( Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, explicit, value(i32))] +#[constructor(constructor_1, explicit, i32)] #[byte_size(8)] pub struct Counted { #[offset(0)] diff --git a/tests/unit/out/refcount/rule_of_five.rs b/tests/unit/out/refcount/rule_of_five.rs index 06aa981bdb..5baf8aaa12 100644 --- a/tests/unit/out/refcount/rule_of_five.rs +++ b/tests/unit/out/refcount/rule_of_five.rs @@ -16,9 +16,12 @@ thread_local!( pub static moves_2: Value = Rc::new(RefCell::new(0)); ); #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultConstructible, Swappable, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultConstructible, Swappable, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(20)] pub struct Buffer { #[offset(0)] @@ -29,7 +32,7 @@ pub struct Buffer { pub size: i32, } impl Buffer { - pub fn construct(this: Ptr, mut size: i32) { + pub fn constructor_1(this: Ptr, mut size: i32) { field!(this, data).write((0..4).map(|_| 0_i32).collect::>()); field!(this, size).write(size); { @@ -43,14 +46,7 @@ impl Buffer { } (*alive_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl Destructible for Buffer { - fn destroy(this: Ptr) { - (*alive_0.with(Value::clone).borrow_mut()).prefix_dec(); - } -} -impl CopyConstructible for Buffer { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(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)); @@ -66,9 +62,7 @@ impl CopyConstructible for Buffer { (*alive_0.with(Value::clone).borrow_mut()).prefix_inc(); (*copies_1.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl MoveConstructible for Buffer { - fn move_constructor(this: Ptr, o: RvalueRef) { + pub fn constructor_3(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)); @@ -87,6 +81,11 @@ impl MoveConstructible for Buffer { (*moves_2.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl Destructible for Buffer { + fn destroy(this: Ptr) { + (*alive_0.with(Value::clone).borrow_mut()).prefix_dec(); + } +} impl CopyAssignable for Buffer { fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { let o = o.as_pointer(); @@ -130,8 +129,8 @@ impl MoveAssignable for Buffer { } } pub fn make_3(__return: Ptr, mut size: i32) { - object!(b, Buffer(size)); - MoveConstructible::move_constructor(__return.clone(), RvalueRef::bind(b.as_pointer())); + object!(b, Buffer::constructor_1(size)); + Buffer::constructor_3(__return.clone(), RvalueRef::bind(b.as_pointer())); return; } pub fn main() { @@ -140,15 +139,15 @@ pub fn main() { } fn main_0() -> i32 { { - object!(a, Buffer(4)); - object!(b, Buffer, LvalueRef::bind(a.as_pointer())); + object!(a, Buffer::constructor_1(4)); + object!(b, Buffer::constructor_2(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, RvalueRef::bind(a.as_pointer())); + object!(c, Buffer::constructor_3(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) diff --git a/tests/unit/out/refcount/rule_of_three.rs b/tests/unit/out/refcount/rule_of_three.rs index cefeb4ff1a..cfcad50692 100644 --- a/tests/unit/out/refcount/rule_of_three.rs +++ b/tests/unit/out/refcount/rule_of_three.rs @@ -17,13 +17,15 @@ thread_local!( ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultConstructible, MoveConstructible, MoveAssignable, Swappable, + Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(20)] pub struct Buffer { #[offset(0)] @@ -34,7 +36,7 @@ pub struct Buffer { pub size: i32, } impl Buffer { - pub fn construct(this: Ptr, mut size: i32) { + pub fn constructor_1(this: Ptr, mut size: i32) { field!(this, data).write((0..4).map(|_| 0_i32).collect::>()); field!(this, size).write(size); { @@ -48,14 +50,7 @@ impl Buffer { } (*alive_0.with(Value::clone).borrow_mut()).prefix_inc(); } -} -impl Destructible for Buffer { - fn destroy(this: Ptr) { - (*alive_0.with(Value::clone).borrow_mut()).prefix_dec(); - } -} -impl CopyConstructible for Buffer { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(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,6 +67,11 @@ impl CopyConstructible for Buffer { (*copies_1.with(Value::clone).borrow_mut()).prefix_inc(); } } +impl Destructible for Buffer { + fn destroy(this: Ptr) { + (*alive_0.with(Value::clone).borrow_mut()).prefix_dec(); + } +} impl CopyAssignable for Buffer { fn copy_assign(this: Ptr, o: LvalueRef>) -> Ptr { let o = o.as_pointer(); @@ -111,12 +111,12 @@ pub fn main() { } fn main_0() -> i32 { { - object!(a, Buffer(4)); - object!(b, Buffer, LvalueRef::bind(a.as_pointer())); + object!(a, Buffer::constructor_1(4)); + object!(b, Buffer::constructor_2(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)); - object!(c, Buffer(2)); + object!(c, Buffer::constructor_1(2)); assign!(c = a); assert!( ({ (*c.borrow()).size } == 4) && ((array_elem!(c.as_pointer(), data, 3).read()) == 3) @@ -126,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, LvalueRef::bind(a.as_pointer())); + object!(d, Buffer::constructor_2(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 d4933d171e..f431b93143 100644 --- a/tests/unit/out/refcount/rvalue_rule_arg_move.rs +++ b/tests/unit/out/refcount/rvalue_rule_arg_move.rs @@ -17,33 +17,32 @@ thread_local!( ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Memberwise, Swappable, Default, )] #[memberwise(copy_assign, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct Elem { #[offset(0)] pub v: i32, } impl Elem { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl CopyConstructible for Elem { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(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: RvalueRef) { + pub fn constructor_3(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(); @@ -61,13 +60,13 @@ fn main_0() -> i32 { (*__b0).reserve_exact(4_usize - len_0 as usize); } }); - object!(a, Elem(1)); - object!(b, Elem(2)); + object!(a, Elem::constructor_1(1)); + object!(b, Elem::constructor_1(2)); { let mut __tmp_0 = { >::from(v.decay().end()) }; let __a2 = { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor(__v.as_pointer(), RvalueRef::bind(a.as_pointer())); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Elem::constructor_3(__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/rvalue_struct.rs b/tests/unit/out/refcount/rvalue_struct.rs index c46cfab9aa..4ee92b4ff3 100644 --- a/tests/unit/out/refcount/rvalue_struct.rs +++ b/tests/unit/out/refcount/rvalue_struct.rs @@ -20,7 +20,7 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32), value(i32))] +#[constructor(constructor_1, i32, i32)] #[byte_size(8)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/self_referencing_initializer.rs b/tests/unit/out/refcount/self_referencing_initializer.rs index 57ed9df124..e240f356e6 100644 --- a/tests/unit/out/refcount/self_referencing_initializer.rs +++ b/tests/unit/out/refcount/self_referencing_initializer.rs @@ -49,7 +49,8 @@ pub struct node { #[derive( Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(16)] pub struct node_with_defaults { #[offset(0)] diff --git a/tests/unit/out/refcount/size_t_ssize_t.rs b/tests/unit/out/refcount/size_t_ssize_t.rs index abe31408f9..ec68ef0ef9 100644 --- a/tests/unit/out/refcount/size_t_ssize_t.rs +++ b/tests/unit/out/refcount/size_t_ssize_t.rs @@ -37,9 +37,14 @@ pub fn size_t_in_rules_3() { let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); let mut __out = (dst.decay()).reinterpret_cast::(); while >::not_equal(__first.as_pointer(), __last.as_pointer()) { - __out - .iter_deref() - .write(((__first.borrow().iter_deref().read()) as u64)); + object!(__value, u64, |__this| ConvertibleTo::convert( + LvalueRef::::bind(__first.borrow().iter_deref()), + __this + )); + MoveAssignable::move_assign( + __out.iter_deref(), + RvalueRef::::bind(__value.as_pointer()), + ); __first.borrow_mut().iter_inc(); __out.iter_inc(); } @@ -59,13 +64,14 @@ pub fn size_t_in_rules_3() { ar2.as_pointer() }; let ar3: Value> = Rc::new(RefCell::new({ - let __v: Value> = - Rc::new(RefCell::new((0..3).map(|_| ::zero_init()).collect())); + let __v: Value> = Rc::new(RefCell::new( + (0..3).map(|_| ZeroInitialization::zero_init()).collect(), + )); let __p: Ptr = __v.decay(); for __i in 0..3 { - MoveConstructible::move_constructor( + Constructor::constructor( __p.offset(__i), - RvalueRef::bind(ar2.decay().offset(__i)), + (RvalueRef::::bind(ar2.decay().offset(__i)),), ); } Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -143,33 +149,61 @@ pub fn size_t_in_rules_3() { ))) .as_pointer(),) { - (__tmp_5,) => ( - Rc::new(RefCell::new( - (((*__tmp_5.upgrade().deref()).0.as_pointer().read()) as u64), - )), - Rc::new(RefCell::new( - (((*__tmp_5.upgrade().deref()).1.as_pointer().read()) as u64), - )), - ), + (__tmp_5,) => { + object!(__first, u64, |__this| ConstructibleFrom::construct( + __this, + (RvalueRef::::bind( + (*__tmp_5.upgrade().deref()).0.as_pointer() + ),) + )); + object!(__second, u64, |__this| ConstructibleFrom::construct( + __this, + (RvalueRef::::bind( + (*__tmp_5.upgrade().deref()).1.as_pointer() + ),) + )); + ( + Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), + ) + } }, )); let pi: Value<(Value, Value)> = Rc::new(RefCell::new(( Rc::new(RefCell::new(5)), Rc::new(RefCell::new(6)), ))); - let p3: Value<(Value, Value)> = Rc::new(RefCell::new(( - Rc::new(RefCell::new( - (((*pi.borrow()).0.as_pointer().read()) as u64), - )), - Rc::new(RefCell::new( - (((*pi.borrow()).1.as_pointer().read()) as u64), - )), - ))); + let p3: Value<(Value, Value)> = Rc::new(RefCell::new({ + object!(__first, u64, |__this| ConstructibleFrom::construct( + __this, + (LvalueRef::>::bind((*pi.borrow()).0.as_pointer()),) + )); + object!(__second, u64, |__this| ConstructibleFrom::construct( + __this, + (LvalueRef::>::bind((*pi.borrow()).1.as_pointer()),) + )); + ( + Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), + Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), + ) + })); { - let __first = (((*pi.borrow()).0.as_pointer().read()) as u64); - let __second = (((*pi.borrow()).1.as_pointer().read()) as u64); - *(*p.borrow()).0.borrow_mut() = __first; - *(*p.borrow()).1.borrow_mut() = __second; + object!(__first, u64, |__this| ConvertibleTo::convert( + LvalueRef::>::bind((*pi.borrow()).0.as_pointer()), + __this + )); + object!(__second, u64, |__this| ConvertibleTo::convert( + LvalueRef::>::bind((*pi.borrow()).1.as_pointer()), + __this + )); + MoveAssignable::move_assign( + (*p.borrow()).0.as_pointer(), + RvalueRef::::bind(__first.as_pointer()), + ); + MoveAssignable::move_assign( + (*p.borrow()).1.as_pointer(), + RvalueRef::::bind(__second.as_pointer()), + ); }; match (Rc::new(RefCell::new(( Rc::new(RefCell::new(7)), @@ -178,10 +212,22 @@ pub fn size_t_in_rules_3() { .as_pointer(),) { (__tmp_6,) => { - let __first = (((*__tmp_6.upgrade().deref()).0.as_pointer().read()) as u64); - let __second = (((*__tmp_6.upgrade().deref()).1.as_pointer().read()) as u64); - *(*p.borrow()).0.borrow_mut() = __first; - *(*p.borrow()).1.borrow_mut() = __second; + object!(__first, u64, |__this| ConvertibleTo::convert( + RvalueRef::::bind((*__tmp_6.upgrade().deref()).0.as_pointer()), + __this + )); + object!(__second, u64, |__this| ConvertibleTo::convert( + RvalueRef::::bind((*__tmp_6.upgrade().deref()).1.as_pointer()), + __this + )); + MoveAssignable::move_assign( + (*p.borrow()).0.as_pointer(), + RvalueRef::::bind(__first.as_pointer()), + ); + MoveAssignable::move_assign( + (*p.borrow()).1.as_pointer(), + RvalueRef::::bind(__second.as_pointer()), + ); } }; assert!( @@ -209,14 +255,19 @@ pub fn size_t_in_rules_3() { (__tmp_7).clone() }; let mut v2: Vec = { - let mut __v = Vec::new(); + let __v: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value> = Rc::new(RefCell::new(src.decay())); let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - __v.push(((__it.borrow().iter_deref().read()) as u64)); + let __i = __v.borrow().len(); + __v.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + __v.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } - __v + Rc::try_unwrap(__v).ok().unwrap().into_inner() }; assert!(({ ((*v.borrow()).len() == 4_usize) && (v2[1_usize] == 2_u64) })); let k: Value = Rc::new(RefCell::new(9_usize)); diff --git a/tests/unit/out/refcount/size_t_template_param.rs b/tests/unit/out/refcount/size_t_template_param.rs index ca699f86fe..9326e7703e 100644 --- a/tests/unit/out/refcount/size_t_template_param.rs +++ b/tests/unit/out/refcount/size_t_template_param.rs @@ -24,7 +24,7 @@ pub fn array_ref_0(a: Ptr) -> u64 { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(Ptr< u64 > ))] +#[constructor(constructor_1, Ptr< u64 > )] #[byte_size(8)] pub struct PtrCtor_unsigned_long_ { #[offset(0)] @@ -49,7 +49,7 @@ impl PtrCtor_unsigned_long_ { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, const_lvalue_ref(u64))] +#[constructor(constructor_1, LvalueRef>)] #[byte_size(8)] pub struct RefCtor_unsigned_long_ { #[offset(0)] diff --git a/tests/unit/out/refcount/sort_no_copy.rs b/tests/unit/out/refcount/sort_no_copy.rs index 38e95b18dc..a9e08862ee 100644 --- a/tests/unit/out/refcount/sort_no_copy.rs +++ b/tests/unit/out/refcount/sort_no_copy.rs @@ -9,32 +9,30 @@ use std::rc::{Rc, Weak}; thread_local!( pub static copies_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Swappable)] -#[cpp_from(i32, construct_1, value)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, i32)] +#[constructor(constructor_3, LvalueRef>)] +#[constructor(constructor_4, RvalueRef)] #[byte_size(4)] pub struct Tracked { #[offset(0)] pub v: i32, } impl Tracked { - pub fn construct_1(this: Ptr, mut v: i32) { - field!(this, v).write(v); - } -} -impl DefaultConstructible for Tracked { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, v).write(0); } -} -impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } + pub fn constructor_3(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: RvalueRef) { + pub fn constructor_4(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); } @@ -58,8 +56,8 @@ impl Default for Tracked { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -78,21 +76,22 @@ pub fn greater_1(a: Ptr, b: Ptr) -> bool { ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultInitializable, Memberwise, Swappable, Default, )] #[memberwise(move_constructor, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct MoveOnly { #[offset(0)] pub v: i32, } impl MoveOnly { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } } @@ -105,14 +104,17 @@ impl LessThanComparable for MoveOnly { Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct Bag { #[offset(0)] #[byte_size(24)] pub items: Vec, } -impl DefaultConstructible for Bag { - fn default_constructor(this: Ptr) { +impl Bag { + pub fn constructor_1(this: Ptr) { field!(this, items).write(Vec::new()); } } @@ -128,28 +130,28 @@ pub fn main() { fn main_0() -> i32 { let arr: Value> = Rc::new(RefCell::new(Box::new([ { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 3); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 1); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 4); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 1); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 5); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]))); @@ -178,8 +180,8 @@ fn main_0() -> i32 { { let mut __tmp_1 = { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 2); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; @@ -188,8 +190,8 @@ fn main_0() -> i32 { { let mut __tmp_2 = { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 7); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; @@ -198,8 +200,8 @@ fn main_0() -> i32 { { let mut __tmp_3 = { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 1); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; @@ -208,8 +210,8 @@ fn main_0() -> i32 { { let mut __tmp_4 = { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 8); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 8); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; @@ -306,16 +308,16 @@ fn main_0() -> i32 { assert!((copies_0.with(|rc| *rc.borrow()) == 0)); let bags: Value> = Rc::new(RefCell::new(Box::new(std::array::from_fn::<_, 3, _>( |_| { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Bag::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, )))); { let mut __tmp_9 = { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 1); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; @@ -324,8 +326,8 @@ fn main_0() -> i32 { { let mut __tmp_10 = { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 2); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; @@ -334,8 +336,8 @@ fn main_0() -> i32 { { let mut __tmp_11 = { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 3); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; @@ -362,8 +364,8 @@ fn main_0() -> i32 { field_ref!(bag_vec.decay().offset(1_usize), items).as_pointer(), { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 4); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }, @@ -376,8 +378,8 @@ fn main_0() -> i32 { field_ref!(bag_vec.decay().offset(1_usize), items).as_pointer(), { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 5); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }, @@ -390,8 +392,8 @@ fn main_0() -> i32 { field_ref!(bag_vec.decay().offset(2_usize), items).as_pointer(), { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 6); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 6); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }, @@ -531,8 +533,8 @@ fn main_0() -> i32 { { let mut __tmp_28 = { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnly::construct(__v.as_pointer(), 3); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MoveOnly::constructor_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; @@ -541,8 +543,8 @@ fn main_0() -> i32 { { let mut __tmp_29 = { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnly::construct(__v.as_pointer(), 1); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MoveOnly::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; @@ -551,8 +553,8 @@ fn main_0() -> i32 { { let mut __tmp_30 = { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnly::construct(__v.as_pointer(), 2); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + MoveOnly::constructor_1(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; diff --git a/tests/unit/out/refcount/stdcopy.rs b/tests/unit/out/refcount/stdcopy.rs index aa5559d027..3a312a4201 100644 --- a/tests/unit/out/refcount/stdcopy.rs +++ b/tests/unit/out/refcount/stdcopy.rs @@ -20,7 +20,7 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct Degrees { #[offset(0)] diff --git a/tests/unit/out/refcount/struct_ctor.rs b/tests/unit/out/refcount/struct_ctor.rs index f780d92a85..efeff6d618 100644 --- a/tests/unit/out/refcount/struct_ctor.rs +++ b/tests/unit/out/refcount/struct_ctor.rs @@ -20,7 +20,7 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32), value(i32))] +#[constructor(constructor_1, i32, i32)] #[byte_size(8)] pub struct StructWithCtor { #[offset(0)] @@ -63,7 +63,7 @@ pub fn foo_0(x: Ptr) -> Ptr { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct Value_ { #[offset(0)] @@ -85,7 +85,8 @@ impl Value_ { TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct Ptr_ { #[offset(0)] diff --git a/tests/unit/out/refcount/struct_default_ctor.rs b/tests/unit/out/refcount/struct_default_ctor.rs index 2b00c21afe..cbe377b96f 100644 --- a/tests/unit/out/refcount/struct_default_ctor.rs +++ b/tests/unit/out/refcount/struct_default_ctor.rs @@ -17,7 +17,8 @@ use std::rc::{Rc, Weak}; TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct S { #[offset(0)] @@ -64,7 +65,8 @@ impl Declared {} #[derive( Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(16)] pub struct Holder { #[offset(0)] @@ -104,7 +106,8 @@ thread_local!( TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct FromStatic { #[offset(0)] diff --git a/tests/unit/out/refcount/structured_binding_copy_ctor.rs b/tests/unit/out/refcount/structured_binding_copy_ctor.rs index 1e9c93ba33..b015c29c02 100644 --- a/tests/unit/out/refcount/structured_binding_copy_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_copy_ctor.rs @@ -22,6 +22,10 @@ thread_local!( Default, )] #[memberwise(copy_assign)] +#[derive(Conversions)] +#[conversions(copy)] +#[constructor(constructor_1, i32, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(8)] pub struct Counted { #[offset(0)] @@ -30,13 +34,11 @@ pub struct Counted { pub y: i32, } impl Counted { - pub fn construct(this: Ptr, mut x: i32, mut y: i32) { + pub fn constructor_1(this: Ptr, mut x: i32, mut y: i32) { field!(this, x).write(x); field!(this, y).write(y); } -} -impl CopyConstructible for Counted { - fn copy_constructor(this: Ptr, other: LvalueRef>) { + pub fn constructor_2(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)); @@ -44,7 +46,7 @@ impl CopyConstructible for Counted { } } pub fn make_counted_1(__return: Ptr) { - Counted::construct(__return.clone(), 5, 6); + Counted::constructor_1(__return.clone(), 5, 6); return; } pub fn main() { @@ -52,10 +54,10 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(s, Counted(1, 2)); + object!(s, Counted::constructor_1(1, 2)); let __decomp_2: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyConstructible::copy_constructor(__v.as_pointer(), LvalueRef::bind(s.as_pointer())); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Counted::constructor_2(__v.as_pointer(), LvalueRef::bind(s.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!((copies_0.with(|rc| *rc.borrow()) == 1)); @@ -69,7 +71,7 @@ fn main_0() -> i32 { assert!((copies_0.with(|rc| *rc.borrow()) == 1)); assert!((__decomp_4.with(|__s| __s.x) == 1)); let __decomp_5: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ make_counted_1(Ptr::clone(&__v.as_pointer())) }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); diff --git a/tests/unit/out/refcount/structured_binding_element_ctor.rs b/tests/unit/out/refcount/structured_binding_element_ctor.rs index e73c88804f..2c555331a3 100644 --- a/tests/unit/out/refcount/structured_binding_element_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_element_ctor.rs @@ -13,28 +13,27 @@ thread_local!( pub static moves_1: Value = Rc::new(RefCell::new(0)); ); #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable, Default, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct Elem { #[offset(0)] pub v: i32, } impl Elem { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl CopyConstructible for Elem { - fn copy_constructor(this: Ptr, other: LvalueRef>) { + pub fn constructor_2(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: RvalueRef) { + pub fn constructor_3(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); @@ -45,6 +44,8 @@ impl MoveConstructible for Elem { Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, )] #[memberwise(copy_constructor, move_constructor)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(8)] pub struct Two { #[offset(0)] @@ -54,16 +55,17 @@ pub struct Two { #[byte_size(4)] pub b: Elem, } +impl Two {} pub fn make_two_2(__return: Ptr) { __return.write(Two { a: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Elem::construct(__v.as_pointer(), 1); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Elem::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, b: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Elem::construct(__v.as_pointer(), 2); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Elem::constructor_1(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, }); @@ -76,21 +78,24 @@ pub fn main() { fn main_0() -> i32 { let t: Value = Rc::new(RefCell::new(Two { a: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Elem::construct(__v.as_pointer(), 1); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Elem::constructor_1(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, b: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Elem::construct(__v.as_pointer(), 2); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Elem::constructor_1(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); let mut base_copies: i32 = copies_0.with(|rc| *rc.borrow()); 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())); - CopyConstructible::copy_constructor(__v.as_pointer(), LvalueRef::bind(t.as_pointer())); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + ::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))); @@ -103,8 +108,11 @@ fn main_0() -> i32 { field!(field!(__decomp_4, a), v).write(50); assert!(({ (*t.borrow()).a.v } == 50)); let __decomp_5: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor(__v.as_pointer(), RvalueRef::bind(t.as_pointer())); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + ::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))); @@ -114,7 +122,7 @@ fn main_0() -> i32 { let mut before_copies: i32 = copies_0.with(|rc| *rc.borrow()); let mut before_moves: i32 = moves_1.with(|rc| *rc.borrow()); let __decomp_6: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ make_two_2(Ptr::clone(&__v.as_pointer())) }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); @@ -123,26 +131,20 @@ fn main_0() -> i32 { assert!(({ (*__decomp_6.borrow()).a.v } == 1)); let p: Value<(Value, Value)> = Rc::new(RefCell::new(( Rc::new(RefCell::new({ - let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); - Elem::construct(__tmp_0.as_pointer(), 7); + let __tmp_0: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Elem::constructor_1(__tmp_0.as_pointer(), 7); { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor( - __v.as_pointer(), - RvalueRef::bind(__tmp_0.as_pointer()), - ); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Elem::constructor_3(__v.as_pointer(), RvalueRef::bind(__tmp_0.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() } })), Rc::new(RefCell::new({ - let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); - Elem::construct(__tmp_1.as_pointer(), 8); + let __tmp_1: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Elem::constructor_1(__tmp_1.as_pointer(), 8); { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor( - __v.as_pointer(), - RvalueRef::bind(__tmp_1.as_pointer()), - ); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Elem::constructor_3(__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 5fe6efe7c3..f284322384 100644 --- a/tests/unit/out/refcount/structured_binding_move_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_move_ctor.rs @@ -12,7 +12,13 @@ thread_local!( thread_local!( pub static moves_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default)] +#[derive( + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default, Conversions, +)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(8)] pub struct Movable { #[offset(0)] @@ -21,21 +27,17 @@ pub struct Movable { pub y: i32, } impl Movable { - pub fn construct(this: Ptr, mut x: i32, mut y: i32) { + pub fn constructor_1(this: Ptr, mut x: i32, mut y: i32) { field!(this, x).write(x); field!(this, y).write(y); } -} -impl CopyConstructible for Movable { - fn copy_constructor(this: Ptr, other: LvalueRef>) { + pub fn constructor_2(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: RvalueRef) { + pub fn constructor_3(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)); @@ -58,6 +60,9 @@ impl MoveConstructible for Movable { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(48)] pub struct Holder { #[offset(0)] @@ -75,9 +80,7 @@ impl Holder { }); return; } -} -impl DefaultConstructible for Holder { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, xs).write(Vec::new()); field!(this, ys).write(Vec::new()); } @@ -87,10 +90,10 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(m, Movable(3, 4)); + object!(m, Movable::constructor_1(3, 4)); let __decomp_2: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - MoveConstructible::move_constructor(__v.as_pointer(), RvalueRef::bind(m.as_pointer())); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Movable::constructor_3(__v.as_pointer(), RvalueRef::bind(m.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); assert!((moves_1.with(|rc| *rc.borrow()) == 1)); @@ -104,7 +107,7 @@ fn main_0() -> i32 { ys: Vec::from([4, 5]), })); let __decomp_3: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); ({ Holder::extract(h.as_pointer(), Ptr::clone(&__v.as_pointer())) }); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); diff --git a/tests/unit/out/refcount/swap_map_no_copy.rs b/tests/unit/out/refcount/swap_map_no_copy.rs index e3c2df9ae8..841a656559 100644 --- a/tests/unit/out/refcount/swap_map_no_copy.rs +++ b/tests/unit/out/refcount/swap_map_no_copy.rs @@ -9,32 +9,30 @@ use std::rc::{Rc, Weak}; thread_local!( pub static copies_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Destructible, Swappable)] -#[cpp_from(i32, construct_1, value)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Swappable, Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, i32)] +#[constructor(constructor_3, LvalueRef>)] +#[constructor(constructor_4, RvalueRef)] #[byte_size(4)] pub struct Tracked { #[offset(0)] pub v: i32, } impl Tracked { - pub fn construct_1(this: Ptr, mut v: i32) { - field!(this, v).write(v); - } -} -impl DefaultConstructible for Tracked { - fn default_constructor(this: Ptr) { + pub fn constructor_1(this: Ptr) { field!(this, v).write(0); } -} -impl CopyConstructible for Tracked { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } + pub fn constructor_3(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: RvalueRef) { + pub fn constructor_4(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); } @@ -58,8 +56,8 @@ impl Default for Tracked { fn default() -> Self { { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -69,6 +67,9 @@ impl Default for Tracked { Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -78,14 +79,17 @@ pub struct Pair { #[byte_size(4)] pub y: Tracked, } -impl DefaultConstructible for Pair { - fn default_constructor(this: Ptr) { - DefaultConstructible::default_constructor(field_ptr!(this, x)); - DefaultConstructible::default_constructor(field_ptr!(this, y)); +impl Pair { + pub fn constructor_1(this: Ptr) { + Tracked::constructor_1(field_ptr!(this, x)); + Tracked::constructor_1(field_ptr!(this, y)); } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable)] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(16)] pub struct Arrays { #[offset(0)] @@ -97,16 +101,16 @@ pub struct Arrays { #[array_len(2)] pub b: Box<[Tracked]>, } -impl DefaultConstructible for Arrays { - fn default_constructor(this: Ptr) { +impl Arrays { + pub fn constructor_1(this: Ptr) { field!(this, a).write(Box::new(std::array::from_fn::<_, 2, _>(|_| { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); field!(this, b).write(Box::new(std::array::from_fn::<_, 2, _>(|_| { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(__v.as_pointer()); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_1(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); } @@ -136,25 +140,25 @@ thread_local!( ByteRepr, ZeroInitialization, FnPtrArg, - CppFrom, DefaultConstructible, MoveConstructible, MoveAssignable, Swappable, + Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] #[byte_size(4)] pub struct CopyOnly { #[offset(0)] pub v: i32, } impl CopyOnly { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl CopyConstructible for CopyOnly { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(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(); @@ -177,6 +181,8 @@ impl CopyAssignable for CopyOnly { Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(8)] pub struct CopyOnlyPair { #[offset(0)] @@ -188,6 +194,7 @@ pub struct CopyOnlyPair { #[destroy] pub y: CopyOnly, } +impl CopyOnlyPair {} thread_local!( pub static moves_3: Value = Rc::new(RefCell::new(0)); ); @@ -198,28 +205,27 @@ thread_local!( pub static moved_dtors_5: Value = Rc::new(RefCell::new(0)); ); #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultConstructible, Swappable, + Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultConstructible, Swappable, Conversions, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRef>)] +#[constructor(constructor_3, RvalueRef)] #[byte_size(4)] pub struct Moved { #[offset(0)] pub v: i32, } impl Moved { - pub fn construct(this: Ptr, mut v: i32) { + pub fn constructor_1(this: Ptr, mut v: i32) { field!(this, v).write(v); } -} -impl CopyConstructible for Moved { - fn copy_constructor(this: Ptr, o: LvalueRef>) { + pub fn constructor_2(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: RvalueRef) { + pub fn constructor_3(this: Ptr, o: RvalueRef) { let o = o.as_pointer(); field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(-1_i32); @@ -252,6 +258,8 @@ impl Destructible for Moved { Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Swappable, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(Conversions)] +#[conversions(copy, move)] #[byte_size(8)] pub struct MovedPair { #[offset(0)] @@ -263,6 +271,7 @@ pub struct MovedPair { #[destroy] pub y: Moved, } +impl MovedPair {} pub fn swapped_once_6() -> bool { let mut ok: bool = ((moves_3.with(|rc| *rc.borrow()) == 1) && (move_assigns_4.with(|rc| *rc.borrow()) == 2)) @@ -284,14 +293,17 @@ pub fn swapped_once_6() -> bool { Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, Swappable, Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(Conversions)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct Owner { #[offset(0)] #[byte_size(8)] pub p: Option>, } -impl DefaultConstructible for Owner { - fn default_constructor(this: Ptr) { +impl Owner { + pub fn constructor_1(this: Ptr) { field!(this, p).write(None); } } @@ -300,15 +312,15 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - object!(a, Tracked::construct_1(1)); - object!(b, Tracked::construct_1(2)); + object!(a, Tracked::constructor_2(1)); + object!(b, Tracked::constructor_2(2)); Swappable::swap(a.as_pointer(), b.as_pointer()); assert!(({ (*a.borrow()).v } == 2) && ({ (*b.borrow()).v } == 1)); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); let m1: Value, Value)>> = Rc::new(RefCell::new(Map::new())); ({ - let _o: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(_o.as_pointer(), 10); + let _o: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(_o.as_pointer(), 10); assign!( *match (Rc::new(RefCell::new(1)).as_pointer(),) { (__tmp_0,) => { @@ -324,8 +336,8 @@ fn main_0() -> i32 { ) }); ({ - let _o: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(_o.as_pointer(), 20); + let _o: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(_o.as_pointer(), 20); assign!( *match (Rc::new(RefCell::new(2)).as_pointer(),) { (__tmp_1,) => { @@ -342,8 +354,8 @@ fn main_0() -> i32 { }); let m2: Value, Value)>> = Rc::new(RefCell::new(Map::new())); ({ - let _o: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(_o.as_pointer(), 30); + let _o: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(_o.as_pointer(), 30); assign!( *match (Rc::new(RefCell::new(3)).as_pointer(),) { (__tmp_2,) => { @@ -461,18 +473,18 @@ fn main_0() -> i32 { assert!((copies_0.with(|rc| *rc.borrow()) == 0)); let arr: Value> = Rc::new(RefCell::new(Box::new([ { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 1); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 2); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 3); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]))); @@ -487,8 +499,8 @@ fn main_0() -> i32 { { let mut __tmp_10 = { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 4); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; @@ -497,8 +509,8 @@ fn main_0() -> i32 { { let mut __tmp_11 = { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 5); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; @@ -510,38 +522,38 @@ fn main_0() -> i32 { let pairs: Value> = Rc::new(RefCell::new(Box::new([ Pair { x: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 6); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 6); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, y: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 7); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, }, Pair { x: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 8); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 8); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, y: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 9); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 9); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, }, ]))); let p: Value = Rc::new(RefCell::new(Pair { x: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 10); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 10); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, y: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 11); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 11); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); @@ -567,7 +579,7 @@ fn main_0() -> i32 { && ({ (*pairs.borrow())[(1) as usize].y.v } == 8) ); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); - object!(arrays, Arrays); + object!(arrays, Arrays::constructor_1()); field!(array_elem!(arrays.as_pointer(), a, 0), v).write(1); field!(array_elem!(arrays.as_pointer(), b, 1), v).write(2); Swappable::swap( @@ -591,8 +603,8 @@ fn main_0() -> i32 { Rc::new(RefCell::new(Vec::from_fn(2_usize, |_| Default::default()))); match (grid.decay().offset(0_usize), { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 1); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }) { @@ -602,8 +614,8 @@ fn main_0() -> i32 { }; match (grid.decay().offset(0_usize), { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 2); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }) { @@ -613,8 +625,8 @@ fn main_0() -> i32 { }; match (grid.decay().offset(1_usize), { { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(__v.as_pointer(), 3); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }) { @@ -644,8 +656,8 @@ fn main_0() -> i32 { .collect::, Value)>]>>(), )); ({ - let _o: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(_o.as_pointer(), 1); + let _o: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(_o.as_pointer(), 1); assign!( *match (Rc::new(RefCell::new(1)).as_pointer(),) { (__tmp_18,) => { @@ -661,8 +673,8 @@ fn main_0() -> i32 { ) }); ({ - let _o: Value = Rc::new(RefCell::new(::zero_init())); - Tracked::construct_1(_o.as_pointer(), 2); + let _o: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Tracked::constructor_2(_o.as_pointer(), 2); assign!( *match (Rc::new(RefCell::new(2)).as_pointer(),) { (__tmp_19,) => { @@ -711,8 +723,8 @@ fn main_0() -> i32 { == 1) ); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); - object!(c1, CopyOnly(1)); - object!(c2, CopyOnly(2)); + object!(c1, CopyOnly::constructor_1(1)); + object!(c2, CopyOnly::constructor_1(2)); Swappable::swap(c1.as_pointer(), c2.as_pointer()); assert!(({ (*c1.borrow()).v } == 2) && ({ (*c2.borrow()).v } == 1)); assert!( @@ -721,13 +733,13 @@ fn main_0() -> i32 { ); let cp: Value = Rc::new(RefCell::new(CopyOnlyPair { x: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyOnly::construct(__v.as_pointer(), 3); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CopyOnly::constructor_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, y: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyOnly::construct(__v.as_pointer(), 4); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CopyOnly::constructor_1(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); @@ -744,13 +756,13 @@ fn main_0() -> i32 { ); let carr: Value> = Rc::new(RefCell::new(Box::new([ { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyOnly::construct(__v.as_pointer(), 5); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CopyOnly::constructor_1(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - CopyOnly::construct(__v.as_pointer(), 6); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + CopyOnly::constructor_1(__v.as_pointer(), 6); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]))); @@ -762,20 +774,20 @@ fn main_0() -> i32 { (copy_only_copies_1.with(|rc| *rc.borrow()) == 9) && (copy_only_dtors_2.with(|rc| *rc.borrow()) == 3) ); - object!(mv1, Moved(1)); - object!(mv2, Moved(2)); + object!(mv1, Moved::constructor_1(1)); + object!(mv2, Moved::constructor_1(2)); Swappable::swap(mv1.as_pointer(), mv2.as_pointer()); assert!(({ (*mv1.borrow()).v } == 2) && ({ (*mv2.borrow()).v } == 1)); assert!(({ swapped_once_6() })); let mp: Value = Rc::new(RefCell::new(MovedPair { x: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Moved::construct(__v.as_pointer(), 3); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Moved::constructor_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, y: { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Moved::construct(__v.as_pointer(), 4); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Moved::constructor_1(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); @@ -789,13 +801,13 @@ fn main_0() -> i32 { assert!(({ swapped_once_6() })); let marr: Value> = Rc::new(RefCell::new(Box::new([ { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Moved::construct(__v.as_pointer(), 5); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Moved::constructor_1(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - Moved::construct(__v.as_pointer(), 6); + let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); + Moved::constructor_1(__v.as_pointer(), 6); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]))); diff --git a/tests/unit/out/refcount/template_default_arg.rs b/tests/unit/out/refcount/template_default_arg.rs index 19c2fda4eb..c326db0757 100644 --- a/tests/unit/out/refcount/template_default_arg.rs +++ b/tests/unit/out/refcount/template_default_arg.rs @@ -17,8 +17,9 @@ use std::rc::{Rc, Weak}; TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] -#[constructor(constructor_2, value(i32))] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, i32)] #[byte_size(4)] pub struct A { #[offset(0)] @@ -54,7 +55,8 @@ impl Default for A { TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct B { #[offset(0)] @@ -90,7 +92,7 @@ impl Default for B { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct NoDefault { #[offset(0)] @@ -127,7 +129,7 @@ pub fn always_given_3(mut x: NoDefault) -> i32 { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct S_NoDefault_ { #[offset(0)] diff --git a/tests/unit/out/refcount/temporary_field_addr.rs b/tests/unit/out/refcount/temporary_field_addr.rs index e3df798c3b..ab371a0ab0 100644 --- a/tests/unit/out/refcount/temporary_field_addr.rs +++ b/tests/unit/out/refcount/temporary_field_addr.rs @@ -21,7 +21,8 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct Inner { #[offset(0)] @@ -47,7 +48,8 @@ impl Inner { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(56)] pub struct Outer { #[offset(0)] diff --git a/tests/unit/out/refcount/temporary_field_ctor_arg.rs b/tests/unit/out/refcount/temporary_field_ctor_arg.rs index 9aedfed164..b908d68d41 100644 --- a/tests/unit/out/refcount/temporary_field_ctor_arg.rs +++ b/tests/unit/out/refcount/temporary_field_ctor_arg.rs @@ -21,7 +21,8 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct Outer { #[offset(0)] diff --git a/tests/unit/out/refcount/temporary_field_two_args.rs b/tests/unit/out/refcount/temporary_field_two_args.rs index e06491813d..d528835867 100644 --- a/tests/unit/out/refcount/temporary_field_two_args.rs +++ b/tests/unit/out/refcount/temporary_field_two_args.rs @@ -21,7 +21,8 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct Inner { #[offset(0)] @@ -48,7 +49,8 @@ impl Inner { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(48)] pub struct Outer { #[offset(0)] diff --git a/tests/unit/out/refcount/typedef-anon-struct.rs b/tests/unit/out/refcount/typedef-anon-struct.rs index dabd578909..c9e1dd91e9 100644 --- a/tests/unit/out/refcount/typedef-anon-struct.rs +++ b/tests/unit/out/refcount/typedef-anon-struct.rs @@ -42,7 +42,8 @@ pub struct Outer_RunInfo { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct Outer { #[offset(0)] diff --git a/tests/unit/out/refcount/unboxed_locals.rs b/tests/unit/out/refcount/unboxed_locals.rs index 3793ad37fe..2430ac05fb 100644 --- a/tests/unit/out/refcount/unboxed_locals.rs +++ b/tests/unit/out/refcount/unboxed_locals.rs @@ -25,7 +25,9 @@ pub fn inc_1(r: Ptr) { TriviallyDefaultConstructible, TriviallyCopyable, Default, + Conversions, )] +#[conversions(copy, move)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -75,7 +77,9 @@ pub trait Shape { FnPtrArg, DefaultInitializable, Copyable, + Conversions, )] +#[conversions(copy, move)] #[byte_size(16)] pub struct Square { #[offset(8)] diff --git a/tests/unit/out/refcount/unboxed_records.rs b/tests/unit/out/refcount/unboxed_records.rs index 8e2706935c..9bc761e053 100644 --- a/tests/unit/out/refcount/unboxed_records.rs +++ b/tests/unit/out/refcount/unboxed_records.rs @@ -81,7 +81,8 @@ impl Default for Cookie { TriviallyCopyable, Conversions, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(4)] pub struct Counter { #[offset(0)] diff --git a/tests/unit/out/refcount/unique_ptr.rs b/tests/unit/out/refcount/unique_ptr.rs index 68bdac327f..b8555ff7db 100644 --- a/tests/unit/out/refcount/unique_ptr.rs +++ b/tests/unit/out/refcount/unique_ptr.rs @@ -11,7 +11,8 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] -#[conversions(move, default = constructor_1)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct SafePointer { #[offset(0)] diff --git a/tests/unit/out/refcount/unique_ptr_const_deref.rs b/tests/unit/out/refcount/unique_ptr_const_deref.rs index 066249966a..af51ec923f 100644 --- a/tests/unit/out/refcount/unique_ptr_const_deref.rs +++ b/tests/unit/out/refcount/unique_ptr_const_deref.rs @@ -11,7 +11,8 @@ use std::rc::{Rc, Weak}; )] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] -#[conversions(move, default = constructor_1)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct Holder { #[offset(0)] diff --git a/tests/unit/out/refcount/unique_ptr_field_reset.rs b/tests/unit/out/refcount/unique_ptr_field_reset.rs index 521176b82e..6a752b9461 100644 --- a/tests/unit/out/refcount/unique_ptr_field_reset.rs +++ b/tests/unit/out/refcount/unique_ptr_field_reset.rs @@ -30,7 +30,8 @@ pub struct Data { )] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] -#[conversions(move, default = constructor_1)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(16)] pub struct Holder { #[offset(0)] diff --git a/tests/unit/out/refcount/unique_ptr_nested.rs b/tests/unit/out/refcount/unique_ptr_nested.rs index e9b49614d3..1935680037 100644 --- a/tests/unit/out/refcount/unique_ptr_nested.rs +++ b/tests/unit/out/refcount/unique_ptr_nested.rs @@ -32,7 +32,8 @@ pub struct Inner { )] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] -#[conversions(move, default = constructor_1)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct Outer { #[offset(0)] diff --git a/tests/unit/out/refcount/va_list_field.rs b/tests/unit/out/refcount/va_list_field.rs index d13473d766..fc4a2b93e2 100644 --- a/tests/unit/out/refcount/va_list_field.rs +++ b/tests/unit/out/refcount/va_list_field.rs @@ -35,7 +35,7 @@ pub fn sum_0(n: i32, __args: Box<[VaArg]>) -> i32 { Copyable, Conversions, )] -#[conversions(copy, move)] +#[conversions(copy)] #[byte_size(16)] pub struct Guard_1 { #[offset(0)] diff --git a/tests/unit/out/refcount/vector.rs b/tests/unit/out/refcount/vector.rs index ea59b7709f..7d9809b4eb 100644 --- a/tests/unit/out/refcount/vector.rs +++ b/tests/unit/out/refcount/vector.rs @@ -41,7 +41,8 @@ pub fn copy_0(mut copy_vector: Vec) {} )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(48)] pub struct Foo { #[offset(0)] @@ -71,7 +72,7 @@ impl Foo { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct Wrapped { #[offset(0)] diff --git a/tests/unit/out/refcount/vector_insert_conversion_chain.rs b/tests/unit/out/refcount/vector_insert_conversion_chain.rs index 6555612412..38d4c7fa24 100644 --- a/tests/unit/out/refcount/vector_insert_conversion_chain.rs +++ b/tests/unit/out/refcount/vector_insert_conversion_chain.rs @@ -20,17 +20,15 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, i32, const_lvalue_ref)] +#[conversion_function(to_i32, LvalueRef>, i32 )] #[byte_size(4)] pub struct Ratio { #[offset(0)] pub num: i32, } impl Ratio { - pub fn conversion_function_1(this: LvalueRef>, __return: Ptr) { - let this = this.as_pointer(); - __return.write(this.with(|__s| __s.num)); - return; + pub fn to_i32(this: Ptr) -> i32 { + return this.with(|__s| __s.num); } } #[derive( @@ -47,23 +45,19 @@ impl Ratio { Conversions, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, i16, const_lvalue_ref)] -#[conversion_function(conversion_function_2, i64, const_lvalue_ref)] +#[conversion_function(to_i16, LvalueRef>, i16 )] +#[conversion_function(to_i64, LvalueRef>, i64 )] #[byte_size(4)] pub struct Level { #[offset(0)] pub raw_: i32, } impl Level { - pub fn conversion_function_1(this: LvalueRef>, __return: Ptr) { - let this = this.as_pointer(); - __return.write((this.with(|__s| __s.raw_) as i16)); - return; + pub fn to_i16(this: Ptr) -> i16 { + return (this.with(|__s| __s.raw_) as i16); } - pub fn conversion_function_2(this: LvalueRef>, __return: Ptr) { - let this = this.as_pointer(); - __return.write(((this.with(|__s| __s.raw_) as i64) * 100_i64)); - return; + pub fn to_i64(this: Ptr) -> i64 { + return ((this.with(|__s| __s.raw_) as i64) * 100_i64); } } pub fn main() { diff --git a/tests/unit/out/refcount/vector_iter_range_ctor.rs b/tests/unit/out/refcount/vector_iter_range_ctor.rs index fd85fab4c4..258b666ca4 100644 --- a/tests/unit/out/refcount/vector_iter_range_ctor.rs +++ b/tests/unit/out/refcount/vector_iter_range_ctor.rs @@ -20,7 +20,7 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct Degrees { #[offset(0)] @@ -45,17 +45,15 @@ impl Degrees { Conversions, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, i64, const_lvalue_ref)] +#[conversion_function(to_i64, LvalueRef>, i64 )] #[byte_size(4)] pub struct Reading { #[offset(0)] pub raw_: i32, } impl Reading { - pub fn conversion_function_1(this: LvalueRef>, __return: Ptr) { - let this = this.as_pointer(); - __return.write(((this.with(|__s| __s.raw_) as i64) * 10_i64)); - return; + pub fn to_i64(this: Ptr) -> i64 { + return ((this.with(|__s| __s.raw_) as i64) * 10_i64); } } pub fn main() { diff --git a/tests/unit/out/refcount/vector_subscript_direct.rs b/tests/unit/out/refcount/vector_subscript_direct.rs index 8315f3319e..1b9a9a024e 100644 --- a/tests/unit/out/refcount/vector_subscript_direct.rs +++ b/tests/unit/out/refcount/vector_subscript_direct.rs @@ -47,7 +47,8 @@ impl Point { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(48)] pub struct Holder { #[offset(0)] diff --git a/tests/unit/out/refcount/void_cast.rs b/tests/unit/out/refcount/void_cast.rs index 853f4871d1..65c08c7ed9 100644 --- a/tests/unit/out/refcount/void_cast.rs +++ b/tests/unit/out/refcount/void_cast.rs @@ -22,7 +22,8 @@ pub fn unused_param_0(mut x: i32) {} )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(Conversions)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] #[byte_size(24)] pub struct NonTrivial { #[offset(0)] @@ -67,7 +68,8 @@ pub struct Holder { )] #[memberwise(move_constructor, move_assign)] #[derive(Conversions)] -#[conversions(move, default = constructor_1)] +#[conversions(move)] +#[constructor(constructor_1)] #[byte_size(8)] pub struct NonCopyable { #[offset(0)] diff --git a/tests/unit/out/unsafe/10_struct.rs b/tests/unit/out/unsafe/10_struct.rs index 9bb92fad99..57e044f6e8 100644 --- a/tests/unit/out/unsafe/10_struct.rs +++ b/tests/unit/out/unsafe/10_struct.rs @@ -62,8 +62,9 @@ impl Graph { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] -#[constructor(constructor_2, explicit, value(*mut i32 ))] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, explicit, *mut i32 )] pub struct Partial { pub p: *mut i32, } diff --git a/tests/unit/out/unsafe/any.rs b/tests/unit/out/unsafe/any.rs index 9e1fd3a219..6aa4d696a0 100644 --- a/tests/unit/out/unsafe/any.rs +++ b/tests/unit/out/unsafe/any.rs @@ -19,7 +19,7 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32), value(i32))] +#[constructor(constructor_1, i32, i32)] pub struct Point { pub x: i32, pub y: i32, diff --git a/tests/unit/out/unsafe/array_of_noncopy_struct.rs b/tests/unit/out/unsafe/array_of_noncopy_struct.rs index 3ed0fe86b0..2525d2f09d 100644 --- a/tests/unit/out/unsafe/array_of_noncopy_struct.rs +++ b/tests/unit/out/unsafe/array_of_noncopy_struct.rs @@ -19,7 +19,8 @@ use std::rc::Rc; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct NonCopy { pub data: Vec, pub tag: i32, diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index 86c5e2fd3a..ebf3f25628 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -2163,7 +2163,8 @@ pub unsafe fn test_stable_containers_58() { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Counts_59 { pub counts: Vec, } diff --git a/tests/unit/out/unsafe/cast.rs b/tests/unit/out/unsafe/cast.rs index 0ebeef59cb..49f7e8d1f1 100644 --- a/tests/unit/out/unsafe/cast.rs +++ b/tests/unit/out/unsafe/cast.rs @@ -20,7 +20,9 @@ pub const E_C: E = 2; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Pair { pub x: i32, pub y: i32, @@ -35,7 +37,9 @@ pub struct Pair { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Wide { pub c: libc::c_char, } @@ -49,7 +53,9 @@ pub struct Wide { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Grid { pub h: i32, pub row: [i32; 3], @@ -68,12 +74,15 @@ pub struct Grid { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Bag { pub n: i32, pub items: Vec, } -impl DefaultConstructibleUnsafe for Bag { - unsafe fn default_constructor(this: *mut Self) { +impl Bag { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).n).write(0_i32); (&raw mut (*this).items).write(Vec::new()); } @@ -320,7 +329,7 @@ pub unsafe fn nested_5() { assert!(((m[(1) as usize][(1) as usize]) == (42))); assert!(((pm) == (&mut m[(1) as usize][(1) as usize] as *mut i32))); assert!(((pm) < (&mut m[(2) as usize][(0) as usize] as *mut i32))); - object_unsafe!(b, Bag); + object_unsafe!(b, Bag::constructor_1()); if 4_usize > b.items.capacity() as usize { let len_0 = b.items.len(); b.items.reserve_exact(4_usize - len_0 as usize); diff --git a/tests/unit/out/unsafe/class_templates.rs b/tests/unit/out/unsafe/class_templates.rs index 3df9db857c..f8e23d09af 100644 --- a/tests/unit/out/unsafe/class_templates.rs +++ b/tests/unit/out/unsafe/class_templates.rs @@ -20,7 +20,8 @@ use std::rc::Rc; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct MyContainer_int_ { vec_: Vec, } @@ -62,7 +63,8 @@ impl MyContainer_int_ { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct MyContainer_char_ { vec_: Vec, } @@ -104,7 +106,8 @@ impl MyContainer_char_ { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct MyContainer_float_ { vec_: Vec, } diff --git a/tests/unit/out/unsafe/clone_vs_move.rs b/tests/unit/out/unsafe/clone_vs_move.rs index 919d9683c7..5f4a43f0d3 100644 --- a/tests/unit/out/unsafe/clone_vs_move.rs +++ b/tests/unit/out/unsafe/clone_vs_move.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Bar { pub w: i32, } @@ -30,7 +32,9 @@ pub struct Bar { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Foo { pub x: i32, pub y: *mut i32, @@ -48,7 +52,9 @@ pub struct Foo { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Refs { pub a: *mut i32, pub b: *mut i32, diff --git a/tests/unit/out/unsafe/constexpr_function.rs b/tests/unit/out/unsafe/constexpr_function.rs index cb95bb5f41..e3ad223505 100644 --- a/tests/unit/out/unsafe/constexpr_function.rs +++ b/tests/unit/out/unsafe/constexpr_function.rs @@ -34,23 +34,17 @@ pub unsafe fn half_3(mut x: f64) -> f64 { ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, bool, const_lvalue_ref, explicit)] +#[conversion_function(to_bool, LvalueRefUnsafe>, bool , explicit)] pub struct Flag { pub v: i32, } impl Flag { - pub unsafe fn conversion_function_1(this: LvalueRefUnsafe>, __return: *mut bool) { - let this = this.as_ptr() as *mut Flag; - __return.write((((*this).v) != (0))); - return; + pub unsafe fn to_bool(this: *const Self) -> bool { + return (((*this).v) != (0)); } } pub unsafe fn use_4(mut f: Flag) -> i32 { - assert!({ - let mut __v: bool = ZeroInitializationUnsafe::zero_init(); - Flag::conversion_function_1(>>::bind(&mut f), &raw mut __v); - __v - }); + assert!((unsafe { Flag::to_bool(&raw const f,) })); return f.v; } pub unsafe fn checked_5(mut x: i32) -> i32 { diff --git a/tests/unit/out/unsafe/constructor.rs b/tests/unit/out/unsafe/constructor.rs index 4aa4d270a6..9e158e1fb5 100644 --- a/tests/unit/out/unsafe/constructor.rs +++ b/tests/unit/out/unsafe/constructor.rs @@ -20,8 +20,8 @@ pub static mut total_0: std::cell::LazyCell = std::cell::LazyCell::new(|| u )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[conversions(copy)] +#[constructor(constructor_1, i32)] pub struct S { pub v: i32, } @@ -56,9 +56,10 @@ impl DestructibleUnsafe for S { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_3)] -#[constructor(constructor_1, value(i32), value(i32))] -#[constructor(constructor_2, value(i32))] +#[conversions(copy, move)] +#[constructor(constructor_1, i32, i32)] +#[constructor(constructor_2, i32)] +#[constructor(constructor_3)] pub struct Point { pub x: i32, pub y: i32, diff --git a/tests/unit/out/unsafe/container_field_addr.rs b/tests/unit/out/unsafe/container_field_addr.rs index a0e925f87a..8d7181e194 100644 --- a/tests/unit/out/unsafe/container_field_addr.rs +++ b/tests/unit/out/unsafe/container_field_addr.rs @@ -20,7 +20,8 @@ use std::rc::Rc; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct S { pub tag: i32, pub v: Vec, diff --git a/tests/unit/out/unsafe/conversion_operator_same_translation.rs b/tests/unit/out/unsafe/conversion_operator_same_translation.rs index 7b849f4005..4c1a73b75e 100644 --- a/tests/unit/out/unsafe/conversion_operator_same_translation.rs +++ b/tests/unit/out/unsafe/conversion_operator_same_translation.rs @@ -19,24 +19,17 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, libc::c_char, const_lvalue_ref)] -#[conversion_function(conversion_function_2, u8, const_lvalue_ref)] +#[conversion_function(to_libcc_char, LvalueRefUnsafe>, libc::c_char )] +#[conversion_function(to_u8, LvalueRefUnsafe>, u8 )] pub struct S { pub v: i32, } impl S { - pub unsafe fn conversion_function_1( - this: LvalueRefUnsafe>, - __return: *mut libc::c_char, - ) { - let this = this.as_ptr() as *mut S; - __return.write(((*this).v as libc::c_char)); - return; + pub unsafe fn to_libcc_char(this: *const Self) -> libc::c_char { + return ((*this).v as libc::c_char); } - pub unsafe fn conversion_function_2(this: LvalueRefUnsafe>, __return: *mut u8) { - let this = this.as_ptr() as *mut S; - __return.write(((((*this).v) + (1)) as u8)); - return; + pub unsafe fn to_u8(this: *const Self) -> u8 { + return ((((*this).v) + (1)) as u8); } } #[repr(C)] @@ -52,21 +45,17 @@ impl S { ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, i64, const_lvalue_ref)] -#[conversion_function(conversion_function_2, i64, const_lvalue_ref)] +#[conversion_function(to_i64_1, LvalueRefUnsafe>, i64 )] +#[conversion_function(to_i64_2, LvalueRefUnsafe>, i64 )] pub struct T { pub v: i32, } impl T { - pub unsafe fn conversion_function_1(this: LvalueRefUnsafe>, __return: *mut i64) { - let this = this.as_ptr() as *mut T; - __return.write(((*this).v as i64)); - return; + pub unsafe fn to_i64_1(this: *const Self) -> i64 { + return ((*this).v as i64); } - pub unsafe fn conversion_function_2(this: LvalueRefUnsafe>, __return: *mut i64) { - let this = this.as_ptr() as *mut T; - __return.write(((((*this).v) + (1)) as i64)); - return; + pub unsafe fn to_i64_2(this: *const Self) -> i64 { + return ((((*this).v) + (1)) as i64); } } pub fn main() { @@ -77,42 +66,18 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut s: S = S { v: 65 }; - let mut a: libc::c_char = { - let mut __v: libc::c_char = ZeroInitializationUnsafe::zero_init(); - S::conversion_function_1(>>::bind(&mut s), &raw mut __v); - __v - }; - let mut b: u8 = { - let mut __v: u8 = ZeroInitializationUnsafe::zero_init(); - S::conversion_function_2(>>::bind(&mut s), &raw mut __v); - __v - }; + let mut a: libc::c_char = (unsafe { S::to_libcc_char(&raw const s) }); + let mut b: u8 = (unsafe { S::to_u8(&raw const s) }); assert!(((a as i32) == (('A' as libc::c_char) as i32))); assert!(((b as i32) == ((66 as u8) as i32))); assert!( - ((({ - let mut __v: libc::c_char = ZeroInitializationUnsafe::zero_init(); - S::conversion_function_1(>>::bind(&mut s), &raw mut __v); - __v - } as i32) - + ({ - let mut __v: u8 = ZeroInitializationUnsafe::zero_init(); - S::conversion_function_2(>>::bind(&mut s), &raw mut __v); - __v - } as i32)) + ((((unsafe { S::to_libcc_char(&raw const s,) }) as i32) + + ((unsafe { S::to_u8(&raw const s,) }) as i32)) == (131)) ); let mut t: T = T { v: 3 }; - let mut c: i64 = { - let mut __v: i64 = ZeroInitializationUnsafe::zero_init(); - T::conversion_function_1(>>::bind(&mut t), &raw mut __v); - __v - }; - let mut d: i64 = { - let mut __v: i64 = ZeroInitializationUnsafe::zero_init(); - T::conversion_function_2(>>::bind(&mut t), &raw mut __v); - __v - }; + let mut c: i64 = (unsafe { T::to_i64_1(&raw const t) }); + let mut d: i64 = (unsafe { T::to_i64_2(&raw const t) }); assert!(((c) == (3_i64))); assert!(((d) == (4_i64))); return 0; diff --git a/tests/unit/out/unsafe/copy_assign.rs b/tests/unit/out/unsafe/copy_assign.rs index 9864b73db1..c2baef6f61 100644 --- a/tests/unit/out/unsafe/copy_assign.rs +++ b/tests/unit/out/unsafe/copy_assign.rs @@ -16,19 +16,21 @@ pub static mut assigns_0: std::cell::LazyCell = std::cell::LazyCell::new(|| MoveAssignableUnsafe, SwappableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy)] +#[constructor(constructor_1, i32, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct Partial { pub v: i32, pub keep: i32, } impl Partial { - pub unsafe fn construct(this: *mut Self, mut v: i32, mut keep: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32, mut keep: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).keep).write(keep); } -} -impl CopyConstructibleUnsafe for Partial { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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); @@ -47,12 +49,24 @@ impl CopyAssignableUnsafe for Partial { } #[repr(C)] #[derive( - Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, CopyableUnsafe, + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + CopyableUnsafe, + ConversionsUnsafe, )] +#[conversions(copy)] +#[constructor(constructor_1)] pub struct NonConstAssign { pub mark: i32, } impl NonConstAssign { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).mark).write(0); + } pub unsafe fn operator_assign_2( this: *mut Self, o: *mut NonConstAssign, @@ -68,17 +82,12 @@ impl NonConstAssign { return &mut (*this); } } -impl DefaultConstructibleUnsafe for NonConstAssign { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).mark).write(0); - } -} impl Default for NonConstAssign { fn default() -> Self { unsafe { { - let mut __v: NonConstAssign = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: NonConstAssign = ZeroInitializationUnsafe::zero_init(); + NonConstAssign::constructor_1(&raw mut __v); __v } } @@ -94,12 +103,15 @@ impl Default for NonConstAssign { DestructibleUnsafe, CopyConstructibleUnsafe, MovableUnsafe, + ConversionsUnsafe, )] +#[conversions(copy)] +#[constructor(constructor_1)] pub struct RefQualified { pub mark: i32, } -impl DefaultConstructibleUnsafe for RefQualified { - unsafe fn default_constructor(this: *mut Self) { +impl RefQualified { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).mark).write(0); } } @@ -117,8 +129,8 @@ impl Default for RefQualified { fn default() -> Self { unsafe { { - let mut __v: RefQualified = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: RefQualified = ZeroInitializationUnsafe::zero_init(); + RefQualified::constructor_1(&raw mut __v); __v } } @@ -134,16 +146,18 @@ impl Default for RefQualified { Default, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct Holder { pub p: Partial, pub arr: [Partial; 2], } +impl Holder {} pub static mut copies_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, MoveConstructibleUnsafe, @@ -152,17 +166,18 @@ pub static mut copies_1: std::cell::LazyCell = std::cell::LazyCell::new(|| Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct CopyCounted { pub v: i32, } impl CopyCounted { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl CopyConstructibleUnsafe for CopyCounted { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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(); @@ -178,10 +193,13 @@ impl CopyConstructibleUnsafe for CopyCounted { Default, )] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct HasCopyCounted { pub c: CopyCounted, pub arr: [CopyCounted; 2], } +impl HasCopyCounted {} #[repr(C)] #[derive( Clone, @@ -192,10 +210,18 @@ pub struct HasCopyCounted { CopyConstructibleUnsafe, MovableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy)] +#[constructor(constructor_1)] pub struct ExplicitOperatorCall { pub w: Vec, } +impl ExplicitOperatorCall { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).w).write(Vec::new()); + } +} impl CopyAssignableUnsafe for ExplicitOperatorCall { unsafe fn copy_assign( this: *mut Self, @@ -208,44 +234,40 @@ impl CopyAssignableUnsafe for ExplicitOperatorCall { return &mut (*this); } } -impl DefaultConstructibleUnsafe for ExplicitOperatorCall { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).w).write(Vec::new()); - } -} pub static mut swap_copies_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MoveConstructibleUnsafe, SwappableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct Swapped { pub v: i32, } impl Swapped { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } - pub unsafe fn copy_assign(this: *mut Self, o: *mut Swapped) -> *mut Swapped { + pub unsafe fn constructor_2(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(); + } + pub unsafe fn copy_assign(this: *mut Self, o: ParameterObjectUnsafe) -> *mut Swapped { + let o = (o.as_ptr() as *mut Swapped); let mut t: i32 = (*this).v; (*this).v = (*o).v; (*o).v = t; return &mut (*this); } } -impl CopyConstructibleUnsafe for 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: LvalueRefUnsafe>) -> *mut Self { object_unsafe!( @@ -278,9 +300,12 @@ impl MoveAssignableUnsafe for Swapped { Default, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct HoldsSwapped { pub s: Swapped, } +impl HoldsSwapped {} #[repr(C)] #[derive( Copy, @@ -292,20 +317,21 @@ pub struct HoldsSwapped { CopyConstructibleUnsafe, MoveConstructibleUnsafe, SwappableUnsafe, + ConversionsUnsafe, )] +#[conversions(copy)] +#[constructor(constructor_1)] pub struct VoidAssign { pub x: i32, } impl VoidAssign { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).x).write(0); + } pub unsafe fn copy_assign(this: *mut Self, o: *const VoidAssign) { (*this).x = (((*o).x) + (5)); } } -impl DefaultConstructibleUnsafe for VoidAssign { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).x).write(0); - } -} impl CopyAssignableUnsafe for VoidAssign { unsafe fn copy_assign(this: *mut Self, src: LvalueRefUnsafe>) -> *mut Self { VoidAssign::copy_assign(this, (src.as_ptr() as *const VoidAssign)); @@ -322,8 +348,8 @@ impl Default for VoidAssign { fn default() -> Self { unsafe { { - let mut __v: VoidAssign = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: VoidAssign = ZeroInitializationUnsafe::zero_init(); + VoidAssign::constructor_1(&raw mut __v); __v } } @@ -343,12 +369,15 @@ impl Default for VoidAssign { Default, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct HoldsVoidAssign { pub v: VoidAssign, } -impl DefaultConstructibleUnsafe for HoldsVoidAssign { - unsafe fn default_constructor(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).v); +impl HoldsVoidAssign { + pub unsafe fn constructor_1(this: *mut Self) { + VoidAssign::constructor_1(&raw mut (*this).v); } } pub fn main() { @@ -358,9 +387,9 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, Partial(1, 100)); - object_unsafe!(b, Partial(2, 200)); - object_unsafe!(c, Partial(3, 300)); + object_unsafe!(a, Partial::constructor_1(1, 100)); + object_unsafe!(b, Partial::constructor_1(2, 200)); + object_unsafe!(c, Partial::constructor_1(3, 300)); assign_unsafe!(a = b); assert!(((a.v) == (2)) && ((a.keep) == (100))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (1))); @@ -373,8 +402,8 @@ unsafe fn main_0() -> i32 { }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (3))); (unsafe { - let mut _o: Partial = ::zero_init(); - Partial::construct(&raw mut _o, 9, 900); + let mut _o: Partial = ZeroInitializationUnsafe::zero_init(); + Partial::constructor_1(&raw mut _o, 9, 900); assign_unsafe!(a = _o) }); assert!(((a.v) == (9)) && ((a.keep) == (100))); @@ -388,19 +417,19 @@ unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (6))); let mut h: Holder = Holder { p: { - let mut __v: Partial = ::zero_init(); - Partial::construct(&raw mut __v, 4, 40); + let mut __v: Partial = ZeroInitializationUnsafe::zero_init(); + Partial::constructor_1(&raw mut __v, 4, 40); __v }, arr: [ { - let mut __v: Partial = ::zero_init(); - Partial::construct(&raw mut __v, 5, 50); + let mut __v: Partial = ZeroInitializationUnsafe::zero_init(); + Partial::constructor_1(&raw mut __v, 5, 50); __v }, { - let mut __v: Partial = ::zero_init(); - Partial::construct(&raw mut __v, 6, 60); + let mut __v: Partial = ZeroInitializationUnsafe::zero_init(); + Partial::constructor_1(&raw mut __v, 6, 60); __v }, ], @@ -410,33 +439,33 @@ unsafe fn main_0() -> i32 { assert!(((h.p.v) == (2)) && ((h.p.keep) == (40))); assert!(((h.arr[(1) as usize].v) == (2)) && ((h.arr[(1) as usize].keep) == (60))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (8))); - object_unsafe!(n, NonConstAssign); - object_unsafe!(n1, NonConstAssign); - object_unsafe!(n2, NonConstAssign); - object_unsafe!(cn, NonConstAssign); + object_unsafe!(n, NonConstAssign::constructor_1()); + object_unsafe!(n1, NonConstAssign::constructor_1()); + object_unsafe!(n2, NonConstAssign::constructor_1()); + object_unsafe!(cn, NonConstAssign::constructor_1()); (unsafe { NonConstAssign::operator_assign_2(&raw mut n1, &mut n) }); (unsafe { NonConstAssign::operator_assign_3(&raw mut n2, &cn) }); assert!(((n1.mark) == (1))); assert!(((n2.mark) == (10))); - object_unsafe!(r, RefQualified); - object_unsafe!(r1, RefQualified); + object_unsafe!(r, RefQualified::constructor_1()); + object_unsafe!(r1, RefQualified::constructor_1()); assign_unsafe!(r1 = r); assert!(((r1.mark) == (1))); let mut h2: Holder = Holder { p: { - let mut __v: Partial = ::zero_init(); - Partial::construct(&raw mut __v, 7, 70); + let mut __v: Partial = ZeroInitializationUnsafe::zero_init(); + Partial::constructor_1(&raw mut __v, 7, 70); __v }, arr: [ { - let mut __v: Partial = ::zero_init(); - Partial::construct(&raw mut __v, 8, 80); + let mut __v: Partial = ZeroInitializationUnsafe::zero_init(); + Partial::constructor_1(&raw mut __v, 8, 80); __v }, { - let mut __v: Partial = ::zero_init(); - Partial::construct(&raw mut __v, 9, 90); + let mut __v: Partial = ZeroInitializationUnsafe::zero_init(); + Partial::constructor_1(&raw mut __v, 9, 90); __v }, ], @@ -445,44 +474,44 @@ unsafe fn main_0() -> i32 { assert!(((h2.p.v) == (2)) && ((h2.p.keep) == (70))); assert!(((h2.arr[(1) as usize].v) == (2)) && ((h2.arr[(1) as usize].keep) == (90))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (11))); - object_unsafe!(cc1, CopyCounted(1)); - object_unsafe!(cc2, CopyCounted(2)); + object_unsafe!(cc1, CopyCounted::constructor_1(1)); + object_unsafe!(cc2, CopyCounted::constructor_1(2)); assign_unsafe!(cc1 = cc2); assert!(((cc1.v) == (2))); let mut hc1: HasCopyCounted = HasCopyCounted { c: { - let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&raw mut __v, 1); + let mut __v: CopyCounted = ZeroInitializationUnsafe::zero_init(); + CopyCounted::constructor_1(&raw mut __v, 1); __v }, arr: [ { - let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&raw mut __v, 2); + let mut __v: CopyCounted = ZeroInitializationUnsafe::zero_init(); + CopyCounted::constructor_1(&raw mut __v, 2); __v }, { - let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&raw mut __v, 3); + let mut __v: CopyCounted = ZeroInitializationUnsafe::zero_init(); + CopyCounted::constructor_1(&raw mut __v, 3); __v }, ], }; let mut hc2: HasCopyCounted = HasCopyCounted { c: { - let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&raw mut __v, 4); + let mut __v: CopyCounted = ZeroInitializationUnsafe::zero_init(); + CopyCounted::constructor_1(&raw mut __v, 4); __v }, arr: [ { - let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&raw mut __v, 5); + let mut __v: CopyCounted = ZeroInitializationUnsafe::zero_init(); + CopyCounted::constructor_1(&raw mut __v, 5); __v }, { - let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&raw mut __v, 6); + let mut __v: CopyCounted = ZeroInitializationUnsafe::zero_init(); + CopyCounted::constructor_1(&raw mut __v, 6); __v }, ], @@ -493,8 +522,8 @@ unsafe fn main_0() -> i32 { && ((hc1.arr[(1) as usize].v) == (6)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (0))); - object_unsafe!(e1, ExplicitOperatorCall); - object_unsafe!(e2, ExplicitOperatorCall); + object_unsafe!(e1, ExplicitOperatorCall::constructor_1()); + object_unsafe!(e2, ExplicitOperatorCall::constructor_1()); { let mut __tmp_0: i32 = 5; e1.w.push_moved(&mut __tmp_0) @@ -503,12 +532,12 @@ unsafe fn main_0() -> i32 { assert!( (((e2.w.len()) == (1_usize)) && ((e2.w[(0_usize)]) == (5))) && ((e1.w.len()) == (1_usize)) ); - object_unsafe!(sw1, Swapped(1)); - object_unsafe!(sw2, Swapped(2)); + object_unsafe!(sw1, Swapped::constructor_1(1)); + object_unsafe!(sw2, Swapped::constructor_1(2)); (unsafe { - let mut _o: Swapped = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&raw mut _o, LvalueRefUnsafe::bind(&sw2)); - Swapped::copy_assign(&raw mut sw1, &mut _o) + let mut _o: Swapped = ZeroInitializationUnsafe::zero_init(); + Swapped::constructor_2(&raw mut _o, LvalueRefUnsafe::bind(&sw2)); + Swapped::copy_assign(&raw mut sw1, ParameterObjectUnsafe::bind(&mut _o)) }); assert!( ((sw1.v) == (2)) @@ -516,15 +545,15 @@ unsafe fn main_0() -> i32 { ); let mut hs1: HoldsSwapped = HoldsSwapped { s: { - let mut __v: Swapped = ::zero_init(); - Swapped::construct(&raw mut __v, 3); + let mut __v: Swapped = ZeroInitializationUnsafe::zero_init(); + Swapped::constructor_1(&raw mut __v, 3); __v }, }; let mut hs2: HoldsSwapped = HoldsSwapped { s: { - let mut __v: Swapped = ::zero_init(); - Swapped::construct(&raw mut __v, 4); + let mut __v: Swapped = ZeroInitializationUnsafe::zero_init(); + Swapped::constructor_1(&raw mut __v, 4); __v }, }; @@ -533,8 +562,8 @@ unsafe fn main_0() -> i32 { ((hs1.s.v) == (4)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut swap_copies_2)) == (2)) ); - object_unsafe!(hv1, HoldsVoidAssign); - object_unsafe!(hv2, HoldsVoidAssign); + object_unsafe!(hv1, HoldsVoidAssign::constructor_1()); + object_unsafe!(hv2, HoldsVoidAssign::constructor_1()); assign_unsafe!(hv1 = hv2); assert!(((hv1.v.x) == (5))); return 0; diff --git a/tests/unit/out/unsafe/copy_ctor.rs b/tests/unit/out/unsafe/copy_ctor.rs index eb11c9e37a..176796756e 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -11,7 +11,6 @@ pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, MoveConstructibleUnsafe, @@ -20,17 +19,18 @@ pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct Counted { pub v: i32, } impl Counted { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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(); @@ -41,28 +41,33 @@ impl CopyConstructibleUnsafe for Counted { FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, MoveAssignableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe)] +#[constructor(constructor_3, LvalueRefUnsafe>)] pub struct NonConst { pub mark: i32, } impl NonConst { - pub unsafe fn construct_1(this: *mut Self, o: *mut NonConst) { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).mark).write(0); + } + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe) { + let o = (o.as_ptr() as *mut NonConst); (&raw mut (*this).mark).write((((*o).mark) + (1))); } - pub unsafe fn construct_2(this: *mut Self, o: *const NonConst) { + pub unsafe fn constructor_3(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const NonConst); (&raw mut (*this).mark).write((((*o).mark) + (10))); } } -impl DefaultConstructibleUnsafe for NonConst { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).mark).write(0); - } -} impl Default for NonConst { fn default() -> Self { unsafe { { - let mut __v: NonConst = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: NonConst = ZeroInitializationUnsafe::zero_init(); + NonConst::constructor_1(&raw mut __v); __v } } @@ -72,7 +77,6 @@ impl Default for NonConst { #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, MoveConstructibleUnsafe, @@ -81,17 +85,18 @@ impl Default for NonConst { Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct Ignored { pub v: i32, } impl Ignored { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl CopyConstructibleUnsafe for Ignored { - unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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(); @@ -107,31 +112,30 @@ impl CopyConstructibleUnsafe for Ignored { Default, )] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct Holder { pub c: Counted, pub arr: [Counted; 2], } +impl Holder {} #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - CppFromUnsafe, - DefaultInitializableUnsafe, - MemberwiseUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, )] #[memberwise(move_constructor)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct Box_int_ { pub val: i32, } impl Box_int_ { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).val).write(v); } -} -impl CopyConstructibleUnsafe for Box_int_ { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const Box_int_); (&raw mut (*this).val).write((*o).val); } @@ -141,14 +145,16 @@ impl CopyConstructibleUnsafe for Box_int_ { FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, )] #[memberwise(copy_constructor, move_constructor)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct Owner { pub box_: Box_int_, } +impl Owner {} #[repr(C)] #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, MoveConstructibleUnsafe, @@ -157,22 +163,24 @@ pub struct Owner { Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct OutOfLine { pub v: i32, } impl OutOfLine { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl CopyConstructibleUnsafe for OutOfLine { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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(); } } +impl OutOfLine {} #[repr(C)] #[derive( FnPtrArg, @@ -181,17 +189,19 @@ impl CopyConstructibleUnsafe for OutOfLine { MoveConstructibleUnsafe, MoveAssignableUnsafe, SwappableUnsafe, + ConversionsUnsafe, )] +#[conversions(copy)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct Tracked { pub copied_from: i32, } -impl DefaultConstructibleUnsafe for Tracked { - unsafe fn default_constructor(this: *mut Self) { +impl Tracked { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).copied_from).write(0); } -} -impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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(); @@ -212,32 +222,33 @@ impl Default for Tracked { pub unsafe fn touch_1(mut t: *const Tracked) { (*(&raw const (*t).copied_from).cast_mut()).prefix_inc(); } -pub unsafe fn by_value_2(c: *mut Counted) -> i32 { +pub unsafe fn by_value_2(c: ParameterObjectUnsafe) -> i32 { + let c = (c.as_ptr() as *mut Counted); return (*c).v; } pub unsafe fn make_3(__return: *mut Counted, mut v: i32) { - object_unsafe!(c, Counted(v)); - CopyConstructibleUnsafe::copy_constructor(__return, LvalueRefUnsafe::bind(&c)); + object_unsafe!(c, Counted::constructor_1(v)); + Counted::constructor_2(__return, LvalueRefUnsafe::bind(&c)); return; } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct SelfPtr { pub self_: *mut SelfPtr, } -impl DefaultConstructibleUnsafe for SelfPtr { - unsafe fn default_constructor(this: *mut Self) { +impl SelfPtr { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).self_).write(this); } -} -impl CopyConstructibleUnsafe for SelfPtr { - unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, _a0: RvalueRefUnsafe) { let _a0 = (_a0.as_ptr() as *mut SelfPtr); (&raw mut (*this).self_).write(this); } @@ -246,8 +257,8 @@ impl Default for SelfPtr { fn default() -> Self { unsafe { { - let mut __v: SelfPtr = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: SelfPtr = ZeroInitializationUnsafe::zero_init(); + SelfPtr::constructor_1(&raw mut __v); __v } } @@ -263,27 +274,32 @@ impl Default for SelfPtr { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct EmptyBase {} #[repr(C)] #[derive( FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(copy_constructor, move_constructor, move_assign, copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Derived { pub c: Counted, } -impl DefaultConstructibleUnsafe for Derived { - unsafe fn default_constructor(this: *mut Self) { - Counted::construct(&raw mut (*this).c, 20); +impl Derived { + pub unsafe fn constructor_1(this: *mut Self) { + Counted::constructor_1(&raw mut (*this).c, 20); } } impl Default for Derived { fn default() -> Self { unsafe { { - let mut __v: Derived = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Derived = ZeroInitializationUnsafe::zero_init(); + Derived::constructor_1(&raw mut __v); __v } } @@ -296,50 +312,52 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, Counted(1)); - object_unsafe!(b, Counted, LvalueRefUnsafe::bind(&a)); - object_unsafe!(c, Counted, LvalueRefUnsafe::bind(&a)); - object_unsafe!(d, Counted, LvalueRefUnsafe::bind(&a)); + object_unsafe!(a, Counted::constructor_1(1)); + object_unsafe!(b, Counted::constructor_2(LvalueRefUnsafe::bind(&a))); + object_unsafe!(c, Counted::constructor_2(LvalueRefUnsafe::bind(&a))); + object_unsafe!(d, Counted::constructor_2(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(); - CopyConstructibleUnsafe::copy_constructor(&raw mut _c, LvalueRefUnsafe::bind(&a)); - by_value_2(&mut _c) + let mut _c: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_2(&raw mut _c, LvalueRefUnsafe::bind(&a)); + by_value_2(ParameterObjectUnsafe::bind(&mut _c)) }) == (1)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (4))); object_unsafe!(e, Counted, |e| (unsafe { make_3(e, 5,) })); assert!(((e.v) == (5))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (5))); - object_unsafe!(f, Counted(6)); + object_unsafe!(f, Counted::constructor_1(6)); 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, LvalueRefUnsafe::bind(&g)); + object_unsafe!(g, Counted::constructor_1(7)); + object_unsafe!(h, Counted::constructor_2(LvalueRefUnsafe::bind(&g))); assert!(((h.v) == (7))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (6))); let mut hold: Holder = Holder { c: { - let mut __v: Counted = ::zero_init(); - Counted::construct(&raw mut __v, 8); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_1(&raw mut __v, 8); __v }, arr: [ { - let mut __v: Counted = ::zero_init(); - Counted::construct(&raw mut __v, 9); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_1(&raw mut __v, 9); __v }, { - let mut __v: Counted = ::zero_init(); - Counted::construct(&raw mut __v, 10); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_1(&raw mut __v, 10); __v }, ], }; - object_unsafe!(hold2, Holder, LvalueRefUnsafe::bind(&hold)); + object_unsafe!(hold2, Holder, |hold2| { + ::copy_constructor(hold2, LvalueRefUnsafe::bind(&hold)) + }); assert!( (((hold2.c.v) == (8)) && ((hold2.arr[(0) as usize].v) == (9))) && ((hold2.arr[(1) as usize].v) == (10)) @@ -349,40 +367,44 @@ unsafe fn main_0() -> i32 { vec_.push_copied(&mut a); 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, LvalueRefUnsafe::bind(&i1)); + object_unsafe!(i1, Ignored::constructor_1(1)); + object_unsafe!(i2, Ignored::constructor_2(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 { box_: { - let mut __v: Box_int_ = ::zero_init(); - Box_int_::construct(&raw mut __v, 3); + let mut __v: Box_int_ = ZeroInitializationUnsafe::zero_init(); + Box_int_::constructor_1(&raw mut __v, 3); __v }, }; - object_unsafe!(o2, Owner, RvalueRefUnsafe::bind(&mut o)); + object_unsafe!(o2, Owner, |o2| { + ::move_constructor(o2, RvalueRefUnsafe::bind(&mut o)) + }); assert!(((o2.box_.val) == (3))); - object_unsafe!(ol1, OutOfLine(5)); - object_unsafe!(ol2, OutOfLine, LvalueRefUnsafe::bind(&ol1)); + object_unsafe!(ol1, OutOfLine::constructor_1(5)); + object_unsafe!(ol2, OutOfLine::constructor_2(LvalueRefUnsafe::bind(&ol1))); assert!(((ol2.v) == (105))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (12))); - object_unsafe!(n, NonConst); - object_unsafe!(n1, NonConst::construct_1(&mut n)); - object_unsafe!(cn, NonConst); - object_unsafe!(n2, NonConst::construct_2(&cn)); + object_unsafe!(n, NonConst::constructor_1()); + object_unsafe!(n1, NonConst::constructor_2(LvalueRefUnsafe::bind(&mut n))); + object_unsafe!(cn, NonConst::constructor_1()); + object_unsafe!(n2, NonConst::constructor_3(LvalueRefUnsafe::bind(&cn))); assert!(((n1.mark) == (1))); assert!(((n2.mark) == (10))); - object_unsafe!(t1, Tracked); - object_unsafe!(t2, Tracked, LvalueRefUnsafe::bind(&t1)); + object_unsafe!(t1, Tracked::constructor_1()); + object_unsafe!(t2, Tracked::constructor_2(LvalueRefUnsafe::bind(&t1))); assign_unsafe!(t2 = t1); assert!(((t1.copied_from) == (2))); - object_unsafe!(ct, Tracked); - object_unsafe!(t3, Tracked, LvalueRefUnsafe::bind(&ct)); + object_unsafe!(ct, Tracked::constructor_1()); + object_unsafe!(t3, Tracked::constructor_2(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, LvalueRefUnsafe::bind(&der)); + object_unsafe!(der, Derived::constructor_1()); + object_unsafe!(der2, Derived, |der2| { + ::copy_constructor(der2, LvalueRefUnsafe::bind(&der)) + }); assert!( ((der2.c.v) == (20)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == ((before) + (1))) @@ -390,12 +412,14 @@ unsafe fn main_0() -> i32 { let mut range: Vec = { let mut __tmp_0 = { vec_.begin() }; let mut __tmp_1 = { vec_.end() }; - let mut __v = Vec::new(); + let mut __v: Vec = Vec::new(); let mut __it = (__tmp_0).clone(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { - __v.push(>::cpp_from( - __it.iter_deref(), - )); + __v.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __v.as_mut_ptr().add(__v.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } __v @@ -410,16 +434,16 @@ unsafe fn main_0() -> i32 { selfs.reserve_exact(2_usize - len_0 as usize); }; { - let mut __tmp_3: SelfPtr = ::zero_init(); + let mut __tmp_3: SelfPtr = ZeroInitializationUnsafe::zero_init(); match (({ - DefaultConstructibleUnsafe::default_constructor(&raw mut __tmp_3); + SelfPtr::constructor_1(&raw mut __tmp_3); &mut __tmp_3 } as *mut SelfPtr),) { (__tmp_2,) => selfs.push_moved(__tmp_2), } }; - object_unsafe!(self_src, SelfPtr); + object_unsafe!(self_src, SelfPtr::constructor_1()); selfs.push_copied(&mut self_src); assert!( ((selfs[(0_usize)].self_) == (&mut selfs[(0_usize)] as *mut SelfPtr)) @@ -431,9 +455,9 @@ unsafe fn main_0() -> i32 { temps.reserve_exact(1_usize - len_0 as usize); }; { - let mut __tmp_5: Counted = ::zero_init(); + let mut __tmp_5: Counted = ZeroInitializationUnsafe::zero_init(); match (({ - Counted::construct(&raw mut __tmp_5, 30); + Counted::constructor_1(&raw mut __tmp_5, 30); &mut __tmp_5 } as *mut Counted),) { diff --git a/tests/unit/out/unsafe/copy_move_defaulted.rs b/tests/unit/out/unsafe/copy_move_defaulted.rs index 7dabf54a1b..c7a1b84532 100644 --- a/tests/unit/out/unsafe/copy_move_defaulted.rs +++ b/tests/unit/out/unsafe/copy_move_defaulted.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Inner { pub x: i32, } @@ -26,7 +28,6 @@ pub struct Inner { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, @@ -34,14 +35,16 @@ pub struct Inner { SwappableUnsafe, )] #[memberwise(copy_assign, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] pub struct Explicit { pub v: i32, pub inner: Inner, pub arr: [i32; 2], } impl Explicit { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).inner).write(Inner { x: ((v) * (10)) }); (&raw mut (*this).arr).write([v, ((v) + (1))]); @@ -60,7 +63,9 @@ impl DestructibleUnsafe for Explicit { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Implicit { pub v: i32, pub inner: Inner, @@ -73,7 +78,6 @@ pub struct Implicit { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, CopyConstructibleUnsafe, @@ -81,17 +85,18 @@ pub struct Implicit { Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct DefaultCopyUserMove { pub v: i32, } impl DefaultCopyUserMove { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl MoveConstructibleUnsafe for DefaultCopyUserMove { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut DefaultCopyUserMove); (&raw mut (*this).v).write((*o).v); (*o).v = 0; @@ -112,24 +117,24 @@ impl MoveAssignableUnsafe for DefaultCopyUserMove { #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, Default, )] #[memberwise(move_constructor, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct UserCopyDefaultMove { pub v: i32, } impl UserCopyDefaultMove { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl CopyConstructibleUnsafe for UserCopyDefaultMove { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { let o = (o.as_ptr() as *const UserCopyDefaultMove); (&raw mut (*this).v).write((((*o).v) + (100))); } @@ -148,14 +153,15 @@ impl CopyAssignableUnsafe for UserCopyDefaultMove { #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, Default, )] #[memberwise(move_constructor, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1, i32)] pub struct Buffer { pub data: Vec, pub rows: Vec>, @@ -163,7 +169,7 @@ pub struct Buffer { pub arr: [i32; 2], } impl Buffer { - pub unsafe fn construct(this: *mut Self, mut n: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut n: i32) { (&raw mut (*this).data).write(Vec::from_fn((n as usize), |_| { copy_constructed_unsafe(&mut n) })); @@ -183,14 +189,17 @@ impl Buffer { Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct Owner { pub data: Vec, pub n: i32, pub arr: [i32; 2], pub p: Option>, } -impl DefaultConstructibleUnsafe for Owner { - unsafe fn default_constructor(this: *mut Self) { +impl Owner { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).data).write(Vec::new()); (&raw mut (*this).n).write(0_i32); (&raw mut (*this).arr).write([0_i32; 2]); @@ -210,11 +219,14 @@ impl DefaultConstructibleUnsafe for Owner { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Copyable { pub data: Vec, } -impl DefaultConstructibleUnsafe for Copyable { - unsafe fn default_constructor(this: *mut Self) { +impl Copyable { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).data).write(Vec::new()); } } @@ -222,13 +234,14 @@ impl DefaultConstructibleUnsafe for Copyable { #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(move_constructor, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1, i32)] pub struct Holder { pub inner: Inner, #[destroy] @@ -236,9 +249,9 @@ pub struct Holder { pub p: Option>, } impl Holder { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).inner).write(Inner { x: v }); - Explicit::construct(&raw mut (*this).e, v); + Explicit::constructor_1(&raw mut (*this).e, v); (&raw mut (*this).p).write(None); } } @@ -248,10 +261,16 @@ pub unsafe fn same_0(a: *const Explicit, b: *const Explicit) -> bool { && (((*a).arr[(1) as usize]) == ((*b).arr[(1) as usize])); } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] +#[constructor(constructor_1)] pub struct SeesThis { pub self_: *mut SeesThis, } +impl SeesThis { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).self_).write(std::ptr::null_mut()); + } +} impl CopyAssignableUnsafe for SeesThis { unsafe fn copy_assign(this: *mut Self, _a0: LvalueRefUnsafe>) -> *mut SeesThis { let _a0 = (_a0.as_ptr() as *const SeesThis); @@ -266,11 +285,6 @@ impl MoveAssignableUnsafe for SeesThis { return &mut (*this); } } -impl DefaultConstructibleUnsafe for SeesThis { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).self_).write(std::ptr::null_mut()); - } -} impl Default for SeesThis { fn default() -> Self { unsafe { @@ -283,30 +297,35 @@ impl Default for SeesThis { #[repr(C)] #[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, Default)] #[memberwise(copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[constructor(constructor_1)] pub struct HasSeesThis { pub s: SeesThis, pub v: Vec, } -impl DefaultConstructibleUnsafe for HasSeesThis { - unsafe fn default_constructor(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).s); +impl HasSeesThis { + pub unsafe fn constructor_1(this: *mut Self) { + SeesThis::constructor_1(&raw mut (*this).s); (&raw mut (*this).v).write(Vec::new()); } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe)] +#[derive( + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, ConversionsUnsafe, +)] +#[conversions(move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, RvalueRefUnsafe)] pub struct Counted_int_ { pub v: i32, pub moves: i32, } -impl DefaultConstructibleUnsafe for Counted_int_ { - unsafe fn default_constructor(this: *mut Self) { +impl Counted_int_ { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write(0_i32); (&raw mut (*this).moves).write(0); } -} -impl MoveConstructibleUnsafe for Counted_int_ { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + pub unsafe fn constructor_2(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))); @@ -335,46 +354,47 @@ impl Default for Counted_int_ { Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct HasCounted { pub c: Counted_int_, pub w: Vec, } -impl DefaultConstructibleUnsafe for HasCounted { - unsafe fn default_constructor(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).c); +impl HasCounted { + pub unsafe fn constructor_1(this: *mut Self) { + Counted_int_::constructor_1(&raw mut (*this).c); (&raw mut (*this).w).write(Vec::new()); } } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, SwappableUnsafe, + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, ConversionsUnsafe, )] -#[cpp_from(i32, construct_1, value)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, i32)] +#[constructor(constructor_3, LvalueRefUnsafe>)] +#[constructor(constructor_4, RvalueRefUnsafe)] pub struct CtorSeesThis { pub self_: *mut CtorSeesThis, pub id: i32, } impl CtorSeesThis { - pub unsafe fn construct_1(this: *mut Self, mut id: i32) { - DefaultConstructibleUnsafe::default_constructor(this); - (*this).id = id; - } -} -impl DefaultConstructibleUnsafe for CtorSeesThis { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).self_).write(this); (&raw mut (*this).id).write(0); } -} -impl CopyConstructibleUnsafe for CtorSeesThis { - unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, mut id: i32) { + CtorSeesThis::constructor_1(this); + (*this).id = id; + } + pub unsafe fn constructor_3(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: RvalueRefUnsafe) { + pub unsafe fn constructor_4(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); @@ -402,8 +422,8 @@ impl Default for CtorSeesThis { fn default() -> Self { unsafe { { - let mut __v: CtorSeesThis = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: CtorSeesThis = ZeroInitializationUnsafe::zero_init(); + CtorSeesThis::constructor_1(&raw mut __v); __v } } @@ -419,13 +439,16 @@ impl Default for CtorSeesThis { Default, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct HasCtorSeesThis { pub x: CtorSeesThis, pub v: Vec, } -impl DefaultConstructibleUnsafe for HasCtorSeesThis { - unsafe fn default_constructor(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).x); +impl HasCtorSeesThis { + pub unsafe fn constructor_1(this: *mut Self) { + CtorSeesThis::constructor_1(&raw mut (*this).x); (&raw mut (*this).v).write(Vec::new()); } } @@ -434,22 +457,25 @@ impl DefaultConstructibleUnsafe for HasCtorSeesThis { FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, SwappableUnsafe, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct InitsCtorSeesThis { pub x: CtorSeesThis, pub y: CtorSeesThis, } -impl DefaultConstructibleUnsafe for InitsCtorSeesThis { - unsafe fn default_constructor(this: *mut Self) { - CtorSeesThis::construct_1(&raw mut (*this).x, 1); - CtorSeesThis::construct_1(&raw mut (*this).y, 2); +impl InitsCtorSeesThis { + pub unsafe fn constructor_1(this: *mut Self) { + CtorSeesThis::constructor_2(&raw mut (*this).x, 1); + CtorSeesThis::constructor_2(&raw mut (*this).y, 2); } } impl Default for InitsCtorSeesThis { fn default() -> Self { unsafe { { - let mut __v: InitsCtorSeesThis = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: InitsCtorSeesThis = ZeroInitializationUnsafe::zero_init(); + InitsCtorSeesThis::constructor_1(&raw mut __v); __v } } @@ -466,28 +492,26 @@ impl Default for InitsCtorSeesThis { SwappableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct OutOfLineDefaulted { pub x: CtorSeesThis, pub v: i32, } impl OutOfLineDefaulted { pub unsafe fn construct(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).x); + CtorSeesThis::constructor_1(&raw mut (*this).x); (&raw mut (*this).v).write(1); } -} -impl CopyConstructibleUnsafe for OutOfLineDefaulted { - unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, _a0: LvalueRefUnsafe>) { let _a0 = (_a0.as_ptr() as *const OutOfLineDefaulted); - CopyConstructibleUnsafe::copy_constructor( - &raw mut (*this).x, - LvalueRefUnsafe::bind(&(*_a0).x), - ); + CtorSeesThis::constructor_3(&raw mut (*this).x, LvalueRefUnsafe::bind(&(*_a0).x)); (&raw mut (*this).v).write((*_a0).v); } } -impl DefaultConstructibleUnsafe for OutOfLineDefaulted { - unsafe fn default_constructor(this: *mut Self) { +impl ConstructorUnsafe<()> for OutOfLineDefaulted { + unsafe fn constructor(this: *mut Self, _: ()) { unsafe { OutOfLineDefaulted::construct(this); } @@ -497,7 +521,7 @@ impl Default for OutOfLineDefaulted { fn default() -> Self { unsafe { { - let mut __v: OutOfLineDefaulted = ::zero_init(); + let mut __v: OutOfLineDefaulted = ZeroInitializationUnsafe::zero_init(); OutOfLineDefaulted::construct(&raw mut __v); __v } @@ -505,16 +529,18 @@ impl Default for OutOfLineDefaulted { } } impl OutOfLineDefaulted {} +impl OutOfLineDefaulted {} #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] +#[constructor(constructor_1)] pub struct OutOfLineAssign { pub s: SeesThis, pub v: i32, pub w: Vec, } -impl DefaultConstructibleUnsafe for OutOfLineAssign { - unsafe fn default_constructor(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).s); +impl OutOfLineAssign { + pub unsafe fn constructor_1(this: *mut Self) { + SeesThis::constructor_1(&raw mut (*this).s); (&raw mut (*this).v).write(1); (&raw mut (*this).w).write(Vec::new()); } @@ -571,7 +597,7 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, Explicit(1)); + object_unsafe!(a, Explicit::constructor_1(1)); let mut b: Explicit = a.clone(); let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { DestructibleUnsafe::destroy(__p) @@ -588,12 +614,12 @@ unsafe fn main_0() -> i32 { ((unsafe { same_0(&b, &a,) }) && (unsafe { same_0(&c, &a,) })) && (unsafe { same_0(&d, &a,) }) ); - object_unsafe!(e, Explicit(2)); - object_unsafe!(f, Explicit(3)); + object_unsafe!(e, Explicit::constructor_1(2)); + object_unsafe!(f, Explicit::constructor_1(3)); assign_unsafe!(e = b); assign_unsafe!(f = RvalueRefUnsafe(c)); assert!((unsafe { same_0(&e, &b,) }) && (unsafe { same_0(&f, &c,) })); - object_unsafe!(g, Explicit(4)); + object_unsafe!(g, Explicit::constructor_1(4)); assign_unsafe!(g = (*assign_unsafe!(e = f))); assert!((unsafe { same_0(&g, &f,) }) && (unsafe { same_0(&e, &f,) })); let mut i: Implicit = Implicit { @@ -615,39 +641,52 @@ unsafe fn main_0() -> i32 { let mut vec_: Vec = Vec::new(); vec_.push_copied(&mut b); match ((&mut { - let mut __v: Explicit = ::zero_init(); - Explicit::construct(&raw mut __v, 9); + let mut __v: Explicit = ZeroInitializationUnsafe::zero_init(); + Explicit::constructor_1(&raw mut __v, 9); __v } as *mut Explicit),) { (__tmp_0,) => vec_.push_moved(__tmp_0), }; assert!(((vec_[(0_usize)].v) == (1)) && ((vec_[(1_usize)].v) == (9))); - object_unsafe!(m, DefaultCopyUserMove(7)); + object_unsafe!(m, DefaultCopyUserMove::constructor_1(7)); let mut m1: DefaultCopyUserMove = m; - object_unsafe!(m2, DefaultCopyUserMove, RvalueRefUnsafe::bind(&mut m)); + object_unsafe!( + m2, + DefaultCopyUserMove::constructor_3(RvalueRefUnsafe::bind(&mut m)) + ); assert!((((m1.v) == (7)) && ((m2.v) == (7))) && ((m.v) == (0))); - object_unsafe!(m3, DefaultCopyUserMove(1)); - object_unsafe!(m4, DefaultCopyUserMove(1)); + object_unsafe!(m3, DefaultCopyUserMove::constructor_1(1)); + object_unsafe!(m4, DefaultCopyUserMove::constructor_1(1)); assign_unsafe!(m3 = 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, LvalueRefUnsafe::bind(&u)); - object_unsafe!(u2, UserCopyDefaultMove, RvalueRefUnsafe::bind(&mut u)); + object_unsafe!(u, UserCopyDefaultMove::constructor_1(8)); + object_unsafe!( + u1, + UserCopyDefaultMove::constructor_2(LvalueRefUnsafe::bind(&u)) + ); + object_unsafe!(u2, UserCopyDefaultMove, |u2| { + ::move_constructor( + u2, + RvalueRefUnsafe::bind(&mut u), + ) + }); assert!((((u1.v) == (108)) && ((u2.v) == (8))) && ((u.v) == (8))); - object_unsafe!(u3, UserCopyDefaultMove(1)); - object_unsafe!(u4, UserCopyDefaultMove(1)); + object_unsafe!(u3, UserCopyDefaultMove::constructor_1(1)); + object_unsafe!(u4, UserCopyDefaultMove::constructor_1(1)); assign_unsafe!(u3 = u2); assign_unsafe!(u4 = RvalueRefUnsafe(u2)); assert!(((u3.v) == (108)) && ((u4.v) == (8))); - object_unsafe!(p, Buffer(3)); - object_unsafe!(q, Buffer, RvalueRefUnsafe::bind(&mut p)); + object_unsafe!(p, Buffer::constructor_1(3)); + object_unsafe!(q, Buffer, |q| { + ::move_constructor(q, 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)); + object_unsafe!(r, Buffer::constructor_1(1)); assign_unsafe!(r = RvalueRefUnsafe(q)); assert!( ((((r.n) == (3)) && ((r.data.len()) == (3_usize))) && ((r.arr[(1) as usize]) == (4))) @@ -662,8 +701,8 @@ unsafe fn main_0() -> i32 { { let mut __tmp_1 = { { - let mut __v: Buffer = ::zero_init(); - MoveConstructibleUnsafe::move_constructor( + let mut __v: Buffer = ZeroInitializationUnsafe::zero_init(); + ::move_constructor( &raw mut __v, RvalueRefUnsafe::bind(&mut bufs[(0_usize)]), ); @@ -676,7 +715,7 @@ unsafe fn main_0() -> i32 { (((bufs[(1_usize)].n) == (3)) && ((bufs[(1_usize)].data.len()) == (3_usize))) && (bufs[(0_usize)].data.is_empty()) ); - object_unsafe!(o1, Owner); + object_unsafe!(o1, Owner::constructor_1()); { let mut __tmp_2: i32 = 5; o1.data.push_moved(&mut __tmp_2) @@ -692,7 +731,9 @@ unsafe fn main_0() -> i32 { Some(Box::from_raw(__tmp_3)) } }; - object_unsafe!(o2, Owner, RvalueRefUnsafe::bind(&mut o1)); + object_unsafe!(o2, Owner, |o2| { + ::move_constructor(o2, RvalueRefUnsafe::bind(&mut o1)) + }); assert!( ((((o2.n) == (5)) && ((o2.data.len()) == (1_usize))) && ((o2.arr[(1) as usize]) == (6))) && ((*o2 @@ -709,7 +750,7 @@ unsafe fn main_0() -> i32 { .map_or(::std::ptr::null_mut(), |v| v as *mut i32)) .is_null()) ); - object_unsafe!(o3, Owner); + object_unsafe!(o3, Owner::constructor_1()); assign_unsafe!(o3 = RvalueRefUnsafe(o2)); assert!( ((((o3.n) == (5)) && ((o3.data[(0_usize)]) == (5))) && ((o3.arr[(0) as usize]) == (5))) @@ -731,13 +772,15 @@ unsafe fn main_0() -> i32 { data: Vec::from([1, 2]), }; let mut c2: Copyable = c1.clone(); - object_unsafe!(c3, Copyable, RvalueRefUnsafe::bind(&mut c1)); + object_unsafe!(c3, Copyable, |c3| { + ::move_constructor(c3, RvalueRefUnsafe::bind(&mut c1)) + }); assert!(((c2.data.len()) == (2_usize)) && ((c3.data.len()) == (2_usize))); assert!(c1.data.is_empty()); - object_unsafe!(c4, Copyable); + object_unsafe!(c4, Copyable::constructor_1()); assign_unsafe!(c4 = RvalueRefUnsafe(c3)); assert!(((c4.data[(1_usize)]) == (2)) && (c3.data.is_empty())); - object_unsafe!(h1, Holder(4)); + object_unsafe!(h1, Holder::constructor_1(4)); { let mut __tmp_4 = { (Box::leak(Box::new(9)) as *mut i32) }; h1.p = if __tmp_4.is_null() { @@ -746,7 +789,9 @@ unsafe fn main_0() -> i32 { Some(Box::from_raw(__tmp_4)) } }; - object_unsafe!(h2, Holder, RvalueRefUnsafe::bind(&mut h1)); + object_unsafe!(h2, Holder, |h2| { + ::move_constructor(h2, RvalueRefUnsafe::bind(&mut h1)) + }); assert!( ((((h2.inner.x) == (4)) && ((h2.e.v) == (4))) && ((*h2 @@ -760,7 +805,7 @@ unsafe fn main_0() -> i32 { .map_or(::std::ptr::null_mut(), |v| v as *mut i32)) .is_null()) ); - object_unsafe!(h3, Holder(1)); + object_unsafe!(h3, Holder::constructor_1(1)); assign_unsafe!(h3 = RvalueRefUnsafe(h2)); assert!( ((((h3.inner.x) == (4)) && ((h3.e.arr[(1) as usize]) == (5))) @@ -775,42 +820,57 @@ unsafe fn main_0() -> i32 { .map_or(::std::ptr::null_mut(), |v| v as *mut i32)) .is_null()) ); - object_unsafe!(t1, HasSeesThis); - object_unsafe!(t2, HasSeesThis); - object_unsafe!(t3, HasSeesThis); + object_unsafe!(t1, HasSeesThis::constructor_1()); + object_unsafe!(t2, HasSeesThis::constructor_1()); + object_unsafe!(t3, HasSeesThis::constructor_1()); 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, RvalueRefUnsafe::bind(&mut k1)); + object_unsafe!(k1, HasCounted::constructor_1()); + object_unsafe!(k2, HasCounted, |k2| { + ::move_constructor( + k2, + RvalueRefUnsafe::bind(&mut k1), + ) + }); assert!(((k2.c.moves) == (1))); - object_unsafe!(k3, HasCounted); + object_unsafe!(k3, HasCounted::constructor_1()); assign_unsafe!(k3 = RvalueRefUnsafe(k2)); assert!(((k3.c.moves) == (2))); { - object_unsafe!(d, CtorSeesThis); + object_unsafe!(d, CtorSeesThis::constructor_1()); assert!(((d.self_) == (&mut d as *mut CtorSeesThis))); - object_unsafe!(e, CtorSeesThis, LvalueRefUnsafe::bind(&d)); + object_unsafe!(e, CtorSeesThis::constructor_3(LvalueRefUnsafe::bind(&d))); assert!(((e.self_) == (&mut e as *mut CtorSeesThis))); - object_unsafe!(f, CtorSeesThis::construct_1(3)); + object_unsafe!(f, CtorSeesThis::constructor_2(3)); assert!(((f.self_) == (&mut f as *mut CtorSeesThis)) && ((f.id) == (3))); - object_unsafe!(h1, HasCtorSeesThis); + object_unsafe!(h1, HasCtorSeesThis::constructor_1()); assert!(((h1.x.self_) == (&mut h1.x as *mut CtorSeesThis))); - object_unsafe!(h2, HasCtorSeesThis, LvalueRefUnsafe::bind(&h1)); + object_unsafe!(h2, HasCtorSeesThis, |h2| { + ::copy_constructor( + h2, + LvalueRefUnsafe::bind(&h1), + ) + }); assert!(((h2.x.self_) == (&mut h2.x as *mut CtorSeesThis))); - object_unsafe!(h3, HasCtorSeesThis, RvalueRefUnsafe::bind(&mut h1)); + object_unsafe!(h3, HasCtorSeesThis, |h3| { + ::move_constructor( + h3, + RvalueRefUnsafe::bind(&mut h1), + ) + }); assert!(((h3.x.self_) == (&mut h3.x as *mut CtorSeesThis))); 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))); - object_unsafe!(i, InitsCtorSeesThis); + object_unsafe!(i, InitsCtorSeesThis::constructor_1()); assert!(((i.x.self_) == (&mut i.x as *mut CtorSeesThis)) && ((i.x.id) == (1))); assert!(((i.y.self_) == (&mut i.y as *mut CtorSeesThis)) && ((i.y.id) == (2))); let mut p: *mut CtorSeesThis = { let __p: *mut CtorSeesThis = Box::leak(Box::new(::zero_init())); - CtorSeesThis::construct_1(__p, 4); + CtorSeesThis::constructor_2(__p, 4); __p }; assert!((((*p).self_) == (p)) && (((*p).id) == (4))); @@ -823,11 +883,14 @@ 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, LvalueRefUnsafe::bind(&o1)); + object_unsafe!( + o2, + OutOfLineDefaulted::constructor_2(LvalueRefUnsafe::bind(&o1)) + ); assert!(((o2.v) == (2)) && ((o2.x.self_) == (&mut o2.x as *mut CtorSeesThis))); - object_unsafe!(a1, OutOfLineAssign); - object_unsafe!(a2, OutOfLineAssign); - object_unsafe!(a3, OutOfLineAssign); + object_unsafe!(a1, OutOfLineAssign::constructor_1()); + object_unsafe!(a2, OutOfLineAssign::constructor_1()); + object_unsafe!(a3, OutOfLineAssign::constructor_1()); a1.v = 3; { let mut __tmp_5: i32 = 4; diff --git a/tests/unit/out/unsafe/copy_move_deleted.rs b/tests/unit/out/unsafe/copy_move_deleted.rs index be888a3cd0..3824cb5879 100644 --- a/tests/unit/out/unsafe/copy_move_deleted.rs +++ b/tests/unit/out/unsafe/copy_move_deleted.rs @@ -10,22 +10,22 @@ use std::rc::Rc; #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, SwappableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct NoCopy { pub v: i32, } impl NoCopy { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl MoveConstructibleUnsafe for NoCopy { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut NoCopy); (&raw mut (*this).v).write((*o).v); (*o).v = 0; @@ -40,17 +40,20 @@ impl MoveAssignableUnsafe for NoCopy { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe)] +#[derive( + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_2)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct PrivateCopy { pub v: i32, } -impl DefaultConstructibleUnsafe for PrivateCopy { - unsafe fn default_constructor(this: *mut Self) { +impl PrivateCopy { + pub unsafe fn constructor_2(this: *mut Self) { (&raw mut (*this).v).write(0); } -} -impl MoveConstructibleUnsafe for PrivateCopy { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut PrivateCopy); (&raw mut (*this).v).write((*o).v); (*o).v = 0; @@ -68,20 +71,21 @@ impl Default for PrivateCopy { fn default() -> Self { unsafe { { - let mut __v: PrivateCopy = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: PrivateCopy = ZeroInitializationUnsafe::zero_init(); + PrivateCopy::constructor_2(&raw mut __v); __v } } } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] +#[constructor(constructor_1)] pub struct Immovable { pub v: i32, } -impl DefaultConstructibleUnsafe for Immovable { - unsafe fn default_constructor(this: *mut Self) { +impl Immovable { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write(0); } } @@ -89,8 +93,8 @@ impl Default for Immovable { fn default() -> Self { unsafe { { - let mut __v: Immovable = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Immovable = ZeroInitializationUnsafe::zero_init(); + Immovable::constructor_1(&raw mut __v); __v } } @@ -106,10 +110,13 @@ impl Default for Immovable { Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] pub struct Container { pub inner: NoCopy, pub tag: i32, } +impl Container {} #[repr(C)] #[derive( FnPtrArg, @@ -120,11 +127,14 @@ pub struct Container { Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct VecHolder { pub items: Vec, } -impl DefaultConstructibleUnsafe for VecHolder { - unsafe fn default_constructor(this: *mut Self) { +impl VecHolder { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).items).write(Vec::new()); } } @@ -141,36 +151,40 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, NoCopy(1)); - object_unsafe!(b, NoCopy, RvalueRefUnsafe::bind(&mut a)); + object_unsafe!(a, NoCopy::constructor_1(1)); + object_unsafe!(b, NoCopy::constructor_3(RvalueRefUnsafe::bind(&mut a))); assert!(((b.v) == (1)) && ((a.v) == (0))); 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); + object_unsafe!(p, PrivateCopy::constructor_2()); p.v = 3; - object_unsafe!(q, PrivateCopy, RvalueRefUnsafe::bind(&mut p)); + object_unsafe!(q, PrivateCopy::constructor_3(RvalueRefUnsafe::bind(&mut p))); assert!(((q.v) == (3)) && ((p.v) == (0))); assign_unsafe!(p = RvalueRefUnsafe(q)); assert!(((p.v) == (3)) && ((q.v) == (0))); - object_unsafe!(im, Immovable); + object_unsafe!(im, Immovable::constructor_1()); im.v = 4; (unsafe { bump_ref_1(&mut im) }); let mut pim: *mut Immovable = (&mut im as *mut Immovable); assert!((((*pim).v) == (5))); let mut c: Container = Container { inner: { - let mut __v: NoCopy = ::zero_init(); - NoCopy::construct(&raw mut __v, 6); + let mut __v: NoCopy = ZeroInitializationUnsafe::zero_init(); + NoCopy::constructor_1(&raw mut __v, 6); __v }, tag: 7, }; - object_unsafe!(d, Container, RvalueRefUnsafe::bind(&mut c)); + object_unsafe!(d, Container, |d| { + ::move_constructor(d, RvalueRefUnsafe::bind(&mut c)) + }); assert!((((d.inner.v) == (6)) && ((d.tag) == (7))) && ((c.inner.v) == (0))); - object_unsafe!(h, VecHolder); - object_unsafe!(h2, VecHolder, RvalueRefUnsafe::bind(&mut h)); + object_unsafe!(h, VecHolder::constructor_1()); + object_unsafe!(h2, VecHolder, |h2| { + ::move_constructor(h2, RvalueRefUnsafe::bind(&mut h)) + }); assert!(((h2.items.len()) == (0_usize))); return 0; } @@ -179,8 +193,8 @@ impl CopyAssignableUnsafe for PrivateCopy { unreachable!("PrivateCopy::copy_assign is never defined") } } -impl CopyConstructibleUnsafe for PrivateCopy { - unsafe fn copy_constructor(this: *mut Self, _: LvalueRefUnsafe>) { +impl ConstructorUnsafe<(LvalueRefUnsafe>,)> for PrivateCopy { + unsafe fn constructor(this: *mut Self, _: (LvalueRefUnsafe>,)) { unreachable!("PrivateCopy::copy_constructor is never defined") } } diff --git a/tests/unit/out/unsafe/default_function_arguments.rs b/tests/unit/out/unsafe/default_function_arguments.rs index cfd9b820e9..23bb7e5c10 100644 --- a/tests/unit/out/unsafe/default_function_arguments.rs +++ b/tests/unit/out/unsafe/default_function_arguments.rs @@ -23,7 +23,7 @@ pub unsafe fn baz_1(mut a: *mut i32, mut b: *mut i32) -> bool { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] pub struct Bar { pub v: i32, } @@ -89,7 +89,7 @@ pub unsafe fn first_9(r: *mut [i32; 3]) -> i32 { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, explicit, value(i32))] +#[constructor(constructor_1, explicit, i32)] pub struct Holder_int_ { pub v: i32, } diff --git a/tests/unit/out/unsafe/delete_array_order.rs b/tests/unit/out/unsafe/delete_array_order.rs index b8aa1f021b..49713f23e3 100644 --- a/tests/unit/out/unsafe/delete_array_order.rs +++ b/tests/unit/out/unsafe/delete_array_order.rs @@ -19,7 +19,7 @@ use std::rc::Rc; )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy)] pub struct Element { pub id: i64, pub value: i64, diff --git a/tests/unit/out/unsafe/destructor.rs b/tests/unit/out/unsafe/destructor.rs index 1dcde266d8..c4907e839b 100644 --- a/tests/unit/out/unsafe/destructor.rs +++ b/tests/unit/out/unsafe/destructor.rs @@ -20,7 +20,7 @@ pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new(|| )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy)] pub struct S {} impl DestructibleUnsafe for S { unsafe fn destroy(this: *mut Self) { @@ -41,7 +41,7 @@ impl DestructibleUnsafe for S { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy)] pub struct Defaulted { #[destroy] pub s: S, @@ -119,7 +119,7 @@ pub struct ArrayMember { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy)] pub struct EmptyBody { pub s: S, } @@ -141,7 +141,7 @@ impl DestructibleUnsafe for EmptyBody { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy)] pub struct Templated_char_ { pub v: libc::c_char, } @@ -165,7 +165,7 @@ impl DestructibleUnsafe for Templated_char_ { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy)] pub struct Templated_int_ { pub v: i32, } @@ -189,7 +189,7 @@ impl DestructibleUnsafe for Templated_int_ { )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy)] pub struct Copied { pub v: i32, } @@ -214,7 +214,7 @@ pub static mut order_count_2: std::cell::LazyCell = std::cell::LazyCell::ne )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy)] pub struct Tagged { pub tag: i32, } diff --git a/tests/unit/out/unsafe/destructor_params.rs b/tests/unit/out/unsafe/destructor_params.rs index fc207ea492..b0e4935fc0 100644 --- a/tests/unit/out/unsafe/destructor_params.rs +++ b/tests/unit/out/unsafe/destructor_params.rs @@ -21,7 +21,7 @@ pub static mut last_1: std::cell::LazyCell = std::cell::LazyCell::new(|| un )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy)] pub struct S { pub v: i32, } @@ -31,11 +31,13 @@ impl DestructibleUnsafe for S { (*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) = (*this).v; } } -pub unsafe fn by_value_2(s: *mut S) -> i32 { +pub unsafe fn by_value_2(s: ParameterObjectUnsafe) -> i32 { + let s = (s.as_ptr() as *mut S); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (0))); return (*s).v; } -pub unsafe fn with_default_3(s: *mut S) -> i32 { +pub unsafe fn with_default_3(s: ParameterObjectUnsafe) -> i32 { + let s = (s.as_ptr() as *mut S); return (*s).v; } #[repr(C)] @@ -51,16 +53,17 @@ pub unsafe fn with_default_3(s: *mut S) -> i32 { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, explicit, by_value(S))] +#[constructor(constructor_1, explicit, ParameterObjectUnsafe)] pub struct Holder { pub v: i32, } impl Holder { - pub unsafe fn constructor_1(this: *mut Self, s: LvalueRefUnsafe) { + pub unsafe fn constructor_1(this: *mut Self, s: ParameterObjectUnsafe) { let s = (s.as_ptr() as *mut S); (&raw mut (*this).v).write((*s).v); } - pub unsafe fn add(this: *const Self, s: *mut S) -> i32 { + pub unsafe fn add(this: *const Self, s: ParameterObjectUnsafe) -> i32 { + let s = (s.as_ptr() as *mut S); return (((*this).v) + ((*s).v)); } } @@ -79,7 +82,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _s: S = s.clone(); - by_value_2(&mut _s) + by_value_2(ParameterObjectUnsafe::bind(&mut _s)) }) == (1)) ); assert!( @@ -92,7 +95,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _s: S = S { v: 2 }; - by_value_2(&mut _s) + by_value_2(ParameterObjectUnsafe::bind(&mut _s)) }) == (2)) ); assert!( @@ -103,7 +106,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _s: S = S { v: 5 }; - with_default_3(&mut _s) + with_default_3(ParameterObjectUnsafe::bind(&mut _s)) }) == (5)) ); assert!( @@ -114,7 +117,7 @@ unsafe fn main_0() -> i32 { { object_unsafe!(h, Holder, |h| { let mut __tmp_0: S = S { v: 3 }; - Holder::constructor_1(h, LvalueRefUnsafe::bind(&mut __tmp_0)) + Holder::constructor_1(h, ParameterObjectUnsafe::bind(&mut __tmp_0)) }); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1)) @@ -123,7 +126,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _s: S = S { v: 4 }; - Holder::add(&raw const h, &mut _s) + Holder::add(&raw const h, ParameterObjectUnsafe::bind(&mut _s)) }) == (7)) ); assert!( diff --git a/tests/unit/out/unsafe/destructor_temporaries.rs b/tests/unit/out/unsafe/destructor_temporaries.rs index 0e731484ef..c49a623c5c 100644 --- a/tests/unit/out/unsafe/destructor_temporaries.rs +++ b/tests/unit/out/unsafe/destructor_temporaries.rs @@ -21,7 +21,7 @@ pub static mut last_1: std::cell::LazyCell = std::cell::LazyCell::new(|| un )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] +#[conversions(copy)] pub struct S { pub v: i32, } diff --git a/tests/unit/out/unsafe/enum_underlying_type.rs b/tests/unit/out/unsafe/enum_underlying_type.rs index 2f0ca24cb5..2cb2f2a65f 100644 --- a/tests/unit/out/unsafe/enum_underlying_type.rs +++ b/tests/unit/out/unsafe/enum_underlying_type.rs @@ -35,7 +35,8 @@ pub type Empty = bool; TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct HoldsEmpty { pub e: Empty, } diff --git a/tests/unit/out/unsafe/field_method_receiver.rs b/tests/unit/out/unsafe/field_method_receiver.rs index 7ac18d1268..c3d8cccdc3 100644 --- a/tests/unit/out/unsafe/field_method_receiver.rs +++ b/tests/unit/out/unsafe/field_method_receiver.rs @@ -51,7 +51,8 @@ impl Counter { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct S { pub tag: i32, pub c: Counter, diff --git a/tests/unit/out/unsafe/field_pointers.rs b/tests/unit/out/unsafe/field_pointers.rs index cab26031a4..f501b40dac 100644 --- a/tests/unit/out/unsafe/field_pointers.rs +++ b/tests/unit/out/unsafe/field_pointers.rs @@ -54,7 +54,8 @@ pub struct Header { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Outer { pub x: i32, pub inner: Inner, diff --git a/tests/unit/out/unsafe/fn_ptr.rs b/tests/unit/out/unsafe/fn_ptr.rs index 870d01053d..5e494ad054 100644 --- a/tests/unit/out/unsafe/fn_ptr.rs +++ b/tests/unit/out/unsafe/fn_ptr.rs @@ -38,17 +38,21 @@ pub unsafe fn identity_hash_6(mut v: bool) -> usize { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(Option u64 > , construct, ptr)] +#[conversions(copy, move)] pub struct HashHolder_unsigned_long__ptr__bool__ { pub h: Option u64>, } impl HashHolder_unsigned_long__ptr__bool__ { - pub unsafe fn construct(this: *mut Self, h: *const Option u64>) { + pub unsafe fn constructor_1( + this: *mut Self, + h: LvalueRefUnsafe u64>>>, + ) { + let h = (h.as_ptr() as *const Option u64>); (&raw mut (*this).h).write((*h)); } } @@ -99,7 +103,10 @@ unsafe fn main_0() -> i32 { Option usize>, Option u64>, >(Some(identity_hash_6)); - HashHolder_unsigned_long__ptr__bool__::construct(hh, &mut __tmp_0) + HashHolder_unsigned_long__ptr__bool__::constructor_1( + hh, + LvalueRefUnsafe::bind(&mut __tmp_0), + ) }); assert!(((unsafe { (hh.h).unwrap()(true,) }) == (1_u64))); let mut handler: Option = Some(add_to_total_8); diff --git a/tests/unit/out/unsafe/fn_ptr_struct.rs b/tests/unit/out/unsafe/fn_ptr_struct.rs index dfedc383e9..8ebe5a40f9 100644 --- a/tests/unit/out/unsafe/fn_ptr_struct.rs +++ b/tests/unit/out/unsafe/fn_ptr_struct.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Handler { pub tag: i32, pub cb: Option i32>, @@ -37,7 +39,9 @@ pub unsafe fn negate_1(mut x: i32) -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct S {} impl S { pub unsafe fn pick_1(mut x: i32) -> i32 { @@ -52,33 +56,34 @@ impl S { } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, RvalueRefUnsafe)] pub struct MoveOnly { pub data_: i32, } impl MoveOnly { - pub unsafe fn construct(this: *mut Self, mut data: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut data: i32) { (&raw mut (*this).data_).write(data); } - pub unsafe fn get(this: *const Self) -> i32 { - return (*this).data_; - } -} -impl MoveConstructibleUnsafe for MoveOnly { - unsafe fn move_constructor(this: *mut Self, x: RvalueRefUnsafe) { + pub unsafe fn constructor_2(this: *mut Self, x: RvalueRefUnsafe) { let x = (x.as_ptr() as *mut MoveOnly); (&raw mut (*this).data_).write((*x).data_); (*x).data_ = 0; } + pub unsafe fn get(this: *const Self) -> i32 { + return (*this).data_; + } } pub unsafe fn make_move_only_2(__return: *mut MoveOnly) { - MoveOnly::construct(__return, 4); + MoveOnly::constructor_1(__return, 4); return; } -pub unsafe fn scale_move_only_3(__return: *mut MoveOnly, x: *mut MoveOnly) { - MoveOnly::construct( +pub unsafe fn scale_move_only_3(__return: *mut MoveOnly, x: ParameterObjectUnsafe) { + let x = (x.as_ptr() as *mut MoveOnly); + MoveOnly::constructor_1( __return, ((unsafe { MoveOnly::get(&raw const (*x)) }) * (10)), ); @@ -118,11 +123,12 @@ unsafe fn main_0() -> i32 { let mut mk: Option = Some(make_move_only_2); object_unsafe!(m, MoveOnly, |m| (unsafe { (mk).unwrap()(m,) })); assert!(((unsafe { MoveOnly::get(&raw const m,) }) == (4))); - let mut sc: Option = Some(scale_move_only_3); + let mut sc: Option)> = + Some(scale_move_only_3); object_unsafe!(n, MoveOnly, |n| (unsafe { - let mut _arg0: MoveOnly = ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&raw mut _arg0, RvalueRefUnsafe::bind(&mut m)); - (sc).unwrap()(n, &mut _arg0) + let mut _arg0: MoveOnly = ZeroInitializationUnsafe::zero_init(); + MoveOnly::constructor_2(&raw mut _arg0, RvalueRefUnsafe::bind(&mut m)); + (sc).unwrap()(n, ParameterObjectUnsafe::bind(&mut _arg0)) })); assert!(((unsafe { MoveOnly::get(&raw const n,) }) == (40))); assert!(((unsafe { MoveOnly::get(&raw const m,) }) == (0))); diff --git a/tests/unit/out/unsafe/for_body_destructor.rs b/tests/unit/out/unsafe/for_body_destructor.rs index 46185ff8df..64d9652476 100644 --- a/tests/unit/out/unsafe/for_body_destructor.rs +++ b/tests/unit/out/unsafe/for_body_destructor.rs @@ -19,16 +19,14 @@ use std::rc::Rc; )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move)] -#[conversion_function(conversion_function_2, bool, const_lvalue_ref, explicit)] +#[conversions(copy)] +#[conversion_function(to_bool, LvalueRefUnsafe>, bool , explicit)] pub struct Guard { pub digit: i32, } impl Guard { - pub unsafe fn conversion_function_2(this: LvalueRefUnsafe>, __return: *mut bool) { - let this = this.as_ptr() as *mut Guard; - __return.write((((*this).digit) != (0))); - return; + pub unsafe fn to_bool(this: *const Self) -> bool { + return (((*this).digit) != (0)); } } impl DestructibleUnsafe for Guard { @@ -169,14 +167,7 @@ unsafe fn main_0() -> i32 { let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { DestructibleUnsafe::destroy(__p) }); - if !({ - let mut __v: bool = ZeroInitializationUnsafe::zero_init(); - Guard::conversion_function_2( - >>::bind(&mut condition), - &raw mut __v, - ); - __v - }) { + if !(unsafe { Guard::to_bool(&raw const condition) }) { break; } 'for_body: { diff --git a/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs b/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs index ca0e3dba3c..4a89daab57 100644 --- a/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs @@ -20,7 +20,8 @@ use std::rc::Rc; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct S { pub v: Vec, pub a: i32, diff --git a/tests/unit/out/unsafe/forward_basic.rs b/tests/unit/out/unsafe/forward_basic.rs index a6c2edcaf1..a43ba113a2 100644 --- a/tests/unit/out/unsafe/forward_basic.rs +++ b/tests/unit/out/unsafe/forward_basic.rs @@ -11,31 +11,30 @@ pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Tracked { pub v: i32, pub copies: i32, pub moves: i32, } impl Tracked { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).copies).write(0); (&raw mut (*this).moves).write(0); } -} -impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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: RvalueRefUnsafe) { + pub unsafe fn constructor_3(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); @@ -50,30 +49,30 @@ pub unsafe fn chosen_overload_1(_a0: *mut Tracked) -> Overload { return Overload_kRvalueOverload; } impl Holder { - pub unsafe fn construct_1(this: *mut Self, x: *mut Tracked) { - CopyConstructibleUnsafe::copy_constructor(&raw mut (*this).t, LvalueRefUnsafe::bind(x)); + pub unsafe fn constructor_1_1(this: *mut Self, x: LvalueRefUnsafe) { + let x = (x.as_ptr() as *mut Tracked); + Tracked::constructor_2(&raw mut (*this).t, LvalueRefUnsafe::bind(x)); } } impl Holder { - pub unsafe fn construct_2(this: *mut Self, x: *mut Tracked) { - MoveConstructibleUnsafe::move_constructor(&raw mut (*this).t, RvalueRefUnsafe::bind(x)); + pub unsafe fn constructor_1_2(this: *mut Self, x: RvalueRefUnsafe) { + let x = (x.as_ptr() as *mut Tracked); + Tracked::constructor_3(&raw mut (*this).t, RvalueRefUnsafe::bind(x)); } } #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - CppFromUnsafe, - DefaultInitializableUnsafe, - MemberwiseUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, )] #[memberwise(copy_constructor, move_constructor)] -#[cpp_from(Tracked, construct_1, mut_ptr)] -#[cpp_from_move(Tracked, construct_2, ptr)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1_1, LvalueRefUnsafe)] +#[constructor(constructor_1_2, RvalueRefUnsafe)] pub struct Holder { pub t: Tracked, } +impl Holder {} pub unsafe fn forward_once_2(x: *mut Tracked) -> Overload { return (unsafe { chosen_overload_0(x) }); } @@ -87,11 +86,11 @@ pub unsafe fn forward_twice_5(x: *mut Tracked) -> Overload { return (unsafe { forward_once_3(x) }); } pub unsafe fn forward_into_ctor_6(__return: *mut Holder, x: *mut Tracked) { - Holder::construct_1(__return, x); + Holder::constructor_1_1(__return, LvalueRefUnsafe::bind(x)); return; } pub unsafe fn forward_into_ctor_7(__return: *mut Holder, x: *mut Tracked) { - Holder::construct_2(__return, x); + Holder::constructor_1_2(__return, RvalueRefUnsafe::bind(x)); return; } pub fn main() { @@ -101,33 +100,33 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(lvalue, Tracked(7)); + object_unsafe!(lvalue, Tracked::constructor_1(7)); assert!( (((unsafe { forward_once_2(&mut lvalue,) }) as i32) == (Overload_kLvalueOverload as i32)) ); assert!(((lvalue.v) == (7))); assert!( (((unsafe { - let mut _x: Tracked = ::zero_init(); - Tracked::construct(&raw mut _x, 8); + let mut _x: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _x, 8); forward_once_3(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object_unsafe!(relayed, Tracked(9)); + object_unsafe!(relayed, Tracked::constructor_1(9)); assert!( (((unsafe { forward_twice_4(&mut relayed,) }) as i32) == (Overload_kLvalueOverload as i32)) ); assert!(((relayed.v) == (9))); assert!( (((unsafe { - let mut _x: Tracked = ::zero_init(); - Tracked::construct(&raw mut _x, 10); + let mut _x: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _x, 10); forward_twice_5(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object_unsafe!(kept, Tracked(11)); + object_unsafe!(kept, Tracked::constructor_1(11)); object_unsafe!(from_lvalue, Holder, |from_lvalue| (unsafe { forward_into_ctor_6(from_lvalue, &mut kept) })); @@ -136,8 +135,8 @@ unsafe fn main_0() -> i32 { assert!(((from_lvalue.t.moves) == (0))); assert!(((kept.v) == (11))); object_unsafe!(from_rvalue, Holder, |from_rvalue| (unsafe { - let mut _x: Tracked = ::zero_init(); - Tracked::construct(&raw mut _x, 12); + let mut _x: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _x, 12); forward_into_ctor_7(from_rvalue, &mut _x) })); assert!(((from_rvalue.t.v) == (12))); diff --git a/tests/unit/out/unsafe/forward_decltype.rs b/tests/unit/out/unsafe/forward_decltype.rs index 6c78d55ef1..7111d34853 100644 --- a/tests/unit/out/unsafe/forward_decltype.rs +++ b/tests/unit/out/unsafe/forward_decltype.rs @@ -11,31 +11,30 @@ pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Tracked { pub v: i32, pub copies: i32, pub moves: i32, } impl Tracked { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).copies).write(0); (&raw mut (*this).moves).write(0); } -} -impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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: RvalueRefUnsafe) { + pub unsafe fn constructor_3(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); @@ -72,37 +71,37 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, Tracked(3)); + object_unsafe!(a, Tracked::constructor_1(3)); assert!( (((unsafe { forward_by_decltype_2(&mut a,) }) as i32) == (Overload_kLvalueOverload as i32)) ); assert!(((a.v) == (3))); assert!( (((unsafe { - let mut _x: Tracked = ::zero_init(); - Tracked::construct(&raw mut _x, 4); + let mut _x: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _x, 4); forward_by_decltype_3(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object_unsafe!(b, Tracked(5)); + object_unsafe!(b, Tracked::constructor_1(5)); assert!( (((unsafe { forward_abbreviated_4(&mut b,) }) as i32) == (Overload_kLvalueOverload as i32)) ); assert!(((b.v) == (5))); assert!( (((unsafe { - let mut _x: Tracked = ::zero_init(); - Tracked::construct(&raw mut _x, 6); + let mut _x: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _x, 6); forward_abbreviated_5(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) ); - object_unsafe!(c, Tracked(7)); + object_unsafe!(c, Tracked::constructor_1(7)); assert!( ((unsafe { - let mut _args_1: Tracked = ::zero_init(); - Tracked::construct(&raw mut _args_1, 8); + let mut _args_1: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _args_1, 8); forward_abbreviated_pack_6(&mut c, &mut _args_1) }) == ((Overload_kLvalueOverload as i32) + (Overload_kRvalueOverload as i32))) ); diff --git a/tests/unit/out/unsafe/forward_explicit.rs b/tests/unit/out/unsafe/forward_explicit.rs index e5f675c7ce..a49ede2127 100644 --- a/tests/unit/out/unsafe/forward_explicit.rs +++ b/tests/unit/out/unsafe/forward_explicit.rs @@ -13,31 +13,30 @@ pub const Overload_kIntLvalueOverload: Overload = 3; pub const Overload_kIntRvalueOverload: Overload = 4; #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Tracked { pub v: i32, pub copies: i32, pub moves: i32, } impl Tracked { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).copies).write(0); (&raw mut (*this).moves).write(0); } -} -impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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: RvalueRefUnsafe) { + pub unsafe fn constructor_3(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); @@ -57,8 +56,9 @@ pub unsafe fn chosen_overload_2(_a0: *const i32) -> Overload { pub unsafe fn chosen_overload_3(_a0: *mut i32) -> Overload { return Overload_kIntRvalueOverload; } -pub unsafe fn copy_or_move_into_param_4(__return: *mut Tracked, t: *mut Tracked) { - MoveConstructibleUnsafe::move_constructor(__return, RvalueRefUnsafe::bind(t)); +pub unsafe fn copy_or_move_into_param_4(__return: *mut Tracked, t: ParameterObjectUnsafe) { + let t = (t.as_ptr() as *mut Tracked); + Tracked::constructor_3(__return, RvalueRefUnsafe::bind(t)); return; } pub fn main() { @@ -68,28 +68,28 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, Tracked(5)); + object_unsafe!(a, Tracked::constructor_1(5)); assert!((((unsafe { chosen_overload_0(&a,) }) as i32) == (Overload_kLvalueOverload as i32))); assert!(((a.v) == (5))); assert!( (((unsafe { chosen_overload_1(&mut a,) }) as i32) == (Overload_kRvalueOverload as i32)) ); assert!(((a.v) == (5))); - object_unsafe!(b, Tracked(6)); + object_unsafe!(b, Tracked::constructor_1(6)); object_unsafe!(moved, Tracked, |moved| (unsafe { - let mut _t: Tracked = ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&raw mut _t, RvalueRefUnsafe::bind(&mut b)); - copy_or_move_into_param_4(moved, &mut _t) + let mut _t: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_3(&raw mut _t, RvalueRefUnsafe::bind(&mut b)); + copy_or_move_into_param_4(moved, ParameterObjectUnsafe::bind(&mut _t)) })); assert!(((moved.v) == (6))); assert!(((moved.copies) == (0))); assert!(((moved.moves) == (2))); assert!(((b.v) == (0))); - object_unsafe!(c, Tracked(7)); + object_unsafe!(c, Tracked::constructor_1(7)); object_unsafe!(copied, Tracked, |copied| (unsafe { - let mut _t: Tracked = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&raw mut _t, LvalueRefUnsafe::bind(&c)); - copy_or_move_into_param_4(copied, &mut _t) + let mut _t: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut _t, LvalueRefUnsafe::bind(&c)); + copy_or_move_into_param_4(copied, ParameterObjectUnsafe::bind(&mut _t)) })); assert!(((copied.v) == (7))); assert!(((copied.copies) == (1))); diff --git a/tests/unit/out/unsafe/forward_pack.rs b/tests/unit/out/unsafe/forward_pack.rs index 5b7c949f79..21a28f6080 100644 --- a/tests/unit/out/unsafe/forward_pack.rs +++ b/tests/unit/out/unsafe/forward_pack.rs @@ -13,31 +13,30 @@ pub const Overload_kIntLvalueOverload: Overload = 3; pub const Overload_kIntRvalueOverload: Overload = 4; #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Tracked { pub v: i32, pub copies: i32, pub moves: i32, } impl Tracked { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).copies).write(0); (&raw mut (*this).moves).write(0); } -} -impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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: RvalueRefUnsafe) { + pub unsafe fn constructor_3(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); @@ -92,9 +91,15 @@ pub unsafe fn forward_pack_7( return digits; } impl Pair { - pub unsafe fn construct(this: *mut Self, x: *mut Tracked, y: *mut Tracked) { - CopyConstructibleUnsafe::copy_constructor(&raw mut (*this).a, LvalueRefUnsafe::bind(x)); - MoveConstructibleUnsafe::move_constructor(&raw mut (*this).b, RvalueRefUnsafe::bind(y)); + pub unsafe fn constructor_1_1( + this: *mut Self, + x: LvalueRefUnsafe, + y: RvalueRefUnsafe, + ) { + let x = (x.as_ptr() as *mut Tracked); + let y = (y.as_ptr() as *mut Tracked); + Tracked::constructor_2(&raw mut (*this).a, LvalueRefUnsafe::bind(x)); + Tracked::constructor_3(&raw mut (*this).b, RvalueRefUnsafe::bind(y)); } } #[repr(C)] @@ -102,16 +107,24 @@ impl Pair { FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, )] #[memberwise(copy_constructor, move_constructor)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1_1, LvalueRefUnsafe, RvalueRefUnsafe)] pub struct Pair { pub a: Tracked, pub b: Tracked, } +impl Pair {} pub unsafe fn forward_pack_into_ctor_8( __return: *mut Pair, args_0: *mut Tracked, args_1: *mut Tracked, ) { - Pair::construct(__return, args_0, args_1); + Pair::constructor_1_1( + __return, + LvalueRefUnsafe::bind(args_0), + RvalueRefUnsafe::bind(args_1), + ); return; } pub fn main() { @@ -122,31 +135,31 @@ pub fn main() { } unsafe fn main_0() -> i32 { assert!(((unsafe { forward_pack_4() }) == (0))); - object_unsafe!(a, Tracked(1)); + object_unsafe!(a, Tracked::constructor_1(1)); assert!(((unsafe { forward_pack_5(&mut a,) }) == (Overload_kLvalueOverload as i32))); assert!(((a.v) == (1))); assert!( ((unsafe { - let mut _args: Tracked = ::zero_init(); - Tracked::construct(&raw mut _args, 2); + let mut _args: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _args, 2); forward_pack_6(&mut _args) }) == (Overload_kRvalueOverload as i32)) ); let mut i: i32 = 3; assert!( ((unsafe { - let mut _args_1: Tracked = ::zero_init(); - Tracked::construct(&raw mut _args_1, 4); + let mut _args_1: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _args_1, 4); let mut _args_3: i32 = 5; forward_pack_7(&mut a, &mut _args_1, &mut i, &mut _args_3) }) == (1234)) ); assert!(((a.v) == (1))); assert!(((i) == (3))); - object_unsafe!(lhs, Tracked(6)); + object_unsafe!(lhs, Tracked::constructor_1(6)); object_unsafe!(p, Pair, |p| (unsafe { - let mut _args_1: Tracked = ::zero_init(); - Tracked::construct(&raw mut _args_1, 7); + let mut _args_1: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut _args_1, 7); forward_pack_into_ctor_8(p, &mut lhs, &mut _args_1) })); assert!(((p.a.v) == (6))); diff --git a/tests/unit/out/unsafe/global_call_temporaries.rs b/tests/unit/out/unsafe/global_call_temporaries.rs index 718dcbe31b..901f1d1e13 100644 --- a/tests/unit/out/unsafe/global_call_temporaries.rs +++ b/tests/unit/out/unsafe/global_call_temporaries.rs @@ -98,7 +98,9 @@ pub static mut call_assigned_6: std::cell::LazyCell = std::cell::LazyCell:: TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Item { pub value: i32, } diff --git a/tests/unit/out/unsafe/global_init_side_effect.rs b/tests/unit/out/unsafe/global_init_side_effect.rs index 2cb467b4c1..037d1c716c 100644 --- a/tests/unit/out/unsafe/global_init_side_effect.rs +++ b/tests/unit/out/unsafe/global_init_side_effect.rs @@ -20,7 +20,7 @@ pub static mut total_0: std::cell::LazyCell = std::cell::LazyCell::new(|| u ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] pub struct S {} impl S { pub unsafe fn constructor_1(this: *mut Self, mut x: i32) { diff --git a/tests/unit/out/unsafe/global_non_const_init.rs b/tests/unit/out/unsafe/global_non_const_init.rs index ecb1ba3edf..610423735b 100644 --- a/tests/unit/out/unsafe/global_non_const_init.rs +++ b/tests/unit/out/unsafe/global_non_const_init.rs @@ -37,8 +37,9 @@ pub static mut depends_on_call_6: std::cell::LazyCell = std::cell::LazyCell TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] -#[constructor(constructor_2, explicit, value(i32))] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, explicit, i32)] pub struct Ctor { pub v: i32, } @@ -129,7 +130,8 @@ static mut local_ctor_14: std::cell::LazyCell = std::cell::LazyCell::new(| TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Singleton { pub hits: i32, } diff --git a/tests/unit/out/unsafe/huffman.rs b/tests/unit/out/unsafe/huffman.rs index d7efaacf12..cb7efdb49b 100644 --- a/tests/unit/out/unsafe/huffman.rs +++ b/tests/unit/out/unsafe/huffman.rs @@ -61,7 +61,8 @@ pub unsafe fn Swap_0(a: *mut MinHeapNode, b: *mut MinHeapNode) { )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(move, default = constructor_1)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct MinHeap { pub size: i32, pub capacity: i32, diff --git a/tests/unit/out/unsafe/implicit_autoref.rs b/tests/unit/out/unsafe/implicit_autoref.rs index 23d1f92e2a..f064c49e32 100644 --- a/tests/unit/out/unsafe/implicit_autoref.rs +++ b/tests/unit/out/unsafe/implicit_autoref.rs @@ -20,7 +20,8 @@ use std::rc::Rc; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Holder { pub v: Vec, } diff --git a/tests/unit/out/unsafe/in_class_field_initializer.rs b/tests/unit/out/unsafe/in_class_field_initializer.rs index 6cc11cb4c9..2f0295ed62 100644 --- a/tests/unit/out/unsafe/in_class_field_initializer.rs +++ b/tests/unit/out/unsafe/in_class_field_initializer.rs @@ -16,7 +16,8 @@ use std::rc::Rc; TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Inner { pub x: i32, pub y: i32, @@ -42,7 +43,8 @@ impl Default for Inner { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct S { pub a: i32, pub b: libc::c_char, @@ -81,7 +83,7 @@ impl Default for S { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32), value(i32))] +#[constructor(constructor_1, i32, i32)] pub struct Boxed_int_ { pub v: i32, pub tag: i32, diff --git a/tests/unit/out/unsafe/init_list.rs b/tests/unit/out/unsafe/init_list.rs index 7b83ecc868..1d8f5874e8 100644 --- a/tests/unit/out/unsafe/init_list.rs +++ b/tests/unit/out/unsafe/init_list.rs @@ -34,7 +34,8 @@ pub struct Pair { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Holder { pub p: Pair, } @@ -69,7 +70,8 @@ pub unsafe fn sum_1(p: *const Pair) -> i32 { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Seven { pub v: i32, } diff --git a/tests/unit/out/unsafe/inline_container_fields.rs b/tests/unit/out/unsafe/inline_container_fields.rs index ff19c40209..19128f8439 100644 --- a/tests/unit/out/unsafe/inline_container_fields.rs +++ b/tests/unit/out/unsafe/inline_container_fields.rs @@ -19,13 +19,16 @@ use std::rc::Rc; Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Elem { pub id: i32, pub hist: [i32; 4], pub coeffs: Vec, } -impl DefaultConstructibleUnsafe for Elem { - unsafe fn default_constructor(this: *mut Self) { +impl Elem { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).id).write(0_i32); (&raw mut (*this).hist).write([0_i32; 4]); (&raw mut (*this).coeffs).write(Vec::new()); @@ -43,6 +46,9 @@ impl DefaultConstructibleUnsafe for Elem { SwappableUnsafe, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct State { pub count: i32, pub grid: [[i32; 3]; 2], @@ -50,8 +56,8 @@ pub struct State { pub elems: Vec, pub rows: Vec>, } -impl DefaultConstructibleUnsafe for State { - unsafe fn default_constructor(this: *mut Self) { +impl State { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).count).write(0_i32); (&raw mut (*this).grid).write([[0_i32; 3]; 2]); (&raw mut (*this).arr).write(std::array::from_fn::<_, 3, _>(|_| 0_i32)); @@ -138,24 +144,26 @@ pub static mut moves_3: std::cell::LazyCell = std::cell::LazyCell::new(|| u pub static mut copy_assigns_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut move_assigns_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe)] +#[derive( + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Counted { pub v: i32, } -impl DefaultConstructibleUnsafe for Counted { - unsafe fn default_constructor(this: *mut Self) { +impl Counted { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write(0); } -} -impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut Counted); (&raw mut (*this).v).write((*o).v); (*o).v = -1_i32; @@ -253,7 +261,9 @@ unsafe fn main_0() -> i32 { assert!( ((elems[(1_usize)].hist[(2) as usize]) == (5)) && (((*first).hist[(2) as usize]) == (0)) ); - object_unsafe!(moved, State, RvalueRefUnsafe::bind(&mut t)); + object_unsafe!(moved, State, |moved| { + ::move_constructor(moved, RvalueRefUnsafe::bind(&mut t)) + }); assert!( ((moved.grid[(0) as usize][(0) as usize]) == (100)) && ((moved.grid[(1) as usize][(2) as usize]) == (5)) diff --git a/tests/unit/out/unsafe/kruskal.rs b/tests/unit/out/unsafe/kruskal.rs index 2af26fa956..7028ca1939 100644 --- a/tests/unit/out/unsafe/kruskal.rs +++ b/tests/unit/out/unsafe/kruskal.rs @@ -185,7 +185,8 @@ pub unsafe fn quicksort_1(arr: *mut Option>, mut start: i32, mut end )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(move, default = constructor_1)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct DisjointSet { pub rank: Option>, pub parent: Option>, @@ -312,7 +313,8 @@ impl DisjointSet { )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(move, default = constructor_1)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct Graph { pub edges: Option>, pub V: i32, diff --git a/tests/unit/out/unsafe/lambda_as_field.rs b/tests/unit/out/unsafe/lambda_as_field.rs index 509d44bfd8..cd0356b6f9 100644 --- a/tests/unit/out/unsafe/lambda_as_field.rs +++ b/tests/unit/out/unsafe/lambda_as_field.rs @@ -18,6 +18,8 @@ use std::rc::Rc; MovableUnsafe, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] pub struct Guard__lambda_at_lambda_as_field_cpp_34_13__ { pub f: FnPtr, } @@ -28,8 +30,15 @@ impl DestructibleUnsafe for Guard__lambda_at_lambda_as_field_cpp_34_13__ { } #[repr(C)] #[derive( - Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, DefaultConstructibleUnsafe, CopyableUnsafe, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, + CopyableUnsafe, + ConversionsUnsafe, )] +#[conversions(copy)] pub struct Guard__lambda_at_lambda_as_field_cpp_45_13__ { pub f: FnPtr, } @@ -46,7 +55,9 @@ impl DestructibleUnsafe for Guard__lambda_at_lambda_as_field_cpp_45_13__ { ZeroInitializationUnsafe, TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Holder__lambda_at_lambda_as_field_cpp_39_12__ { pub f: FnPtr i32>, pub calls: i32, @@ -80,7 +91,9 @@ impl Default for Holder__lambda_at_lambda_as_field_cpp_39_12__ { DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Holder__lambda_at_lambda_as_field_cpp_51_12__ { pub f: FnPtr i32>, pub calls: i32, @@ -92,20 +105,19 @@ impl Holder__lambda_at_lambda_as_field_cpp_51_12__ { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe)] -#[cpp_from(FnPtr i32 > , construct, value)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_2, RvalueRefUnsafe)] pub struct Moving__lambda_at_lambda_as_field_cpp_64_12__ { pub f: FnPtr i32>, pub moves: i32, } impl Moving__lambda_at_lambda_as_field_cpp_64_12__ { - pub unsafe fn construct(this: *mut Self, mut f: FnPtr i32>) { + pub unsafe fn constructor_1(this: *mut Self, mut f: FnPtr i32>) { (&raw mut (*this).f).write(f.copy_from()); (&raw mut (*this).moves).write(0); } -} -impl MoveConstructibleUnsafe for Moving__lambda_at_lambda_as_field_cpp_64_12__ { - unsafe fn move_constructor( + pub unsafe fn constructor_2( this: *mut Self, o: RvalueRefUnsafe, ) { @@ -229,7 +241,7 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { ww.call(2,) }) == (202))); object_unsafe!( m, - Moving__lambda_at_lambda_as_field_cpp_64_12__(FnPtr:: i32>::new( + Moving__lambda_at_lambda_as_field_cpp_64_12__::constructor_1(FnPtr:: i32>::new( |mut x: i32| -> i32 { unsafe { return ((x) * (2)); @@ -239,8 +251,7 @@ unsafe fn main_0() -> i32 { ); object_unsafe!( m2, - Moving__lambda_at_lambda_as_field_cpp_64_12__, - RvalueRefUnsafe::bind(&mut m) + Moving__lambda_at_lambda_as_field_cpp_64_12__::constructor_2(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 122501d962..a3d0d20e44 100644 --- a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs @@ -7,26 +7,26 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Counted { pub copies: i32, pub moves: i32, } -impl DefaultConstructibleUnsafe for Counted { - unsafe fn default_constructor(this: *mut Self) { +impl Counted { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).copies).write(0); (&raw mut (*this).moves).write(0); } -} -impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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: RvalueRefUnsafe) { + pub unsafe fn constructor_3(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))); @@ -36,8 +36,8 @@ impl Default for Counted { fn default() -> Self { unsafe { { - let mut __v: Counted = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_1(&raw mut __v); __v } } @@ -45,18 +45,18 @@ impl Default for Counted { } pub static mut drops_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Dropped {} -impl DefaultConstructibleUnsafe for Dropped { - unsafe fn default_constructor(this: *mut Self) {} -} -impl CopyConstructibleUnsafe for Dropped { - unsafe fn copy_constructor(this: *mut Self, _a0: LvalueRefUnsafe>) { +impl Dropped { + pub unsafe fn constructor_1(this: *mut Self) {} + pub unsafe fn constructor_2(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: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, _a0: RvalueRefUnsafe) { let _a0 = (_a0.as_ptr() as *mut Dropped); } } @@ -72,12 +72,12 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(c, Counted); + object_unsafe!(c, Counted::constructor_1()); let mut f: FnPtr i32> = lambda_unsafe!( { let c: Counted = { - let mut __v: Counted = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(&c)); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(&c)); __v }; }, @@ -92,25 +92,19 @@ unsafe fn main_0() -> i32 { let mut h: FnPtr i32> = f.move_from(); assert!(((unsafe { h.call() }) == (11))); let mut returned: i32 = { - let mut __tmp_0: Counted = ::zero_init(); + let mut __tmp_0: Counted = ZeroInitializationUnsafe::zero_init(); (*{ (unsafe { lambda_unsafe!( { let c: Counted = { - let mut __v: Counted = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor( - &raw mut __v, - LvalueRefUnsafe::bind(&c), - ); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(&c)); __v }; }, |__return: *mut Counted| { - CopyConstructibleUnsafe::copy_constructor( - __return, - LvalueRefUnsafe::bind(&c), - ); + Counted::constructor_2(__return, LvalueRefUnsafe::bind(&c)); return; } ) @@ -122,18 +116,15 @@ unsafe fn main_0() -> i32 { }; assert!(((returned) == (2))); let mut arr: [Counted; 2] = std::array::from_fn::<_, 2, _>(|_| { - let mut __v: Counted = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_1(&raw mut __v); __v }); let mut a: FnPtr i32> = lambda_unsafe!( { let arr: [Counted; 2] = std::array::from_fn::<_, 2, _>(|__i: usize| { - let mut __v: Counted = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor( - &raw mut __v, - LvalueRefUnsafe::bind(&arr[(__i)]), - ); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(&arr[(__i)])); __v }); }, @@ -150,8 +141,8 @@ unsafe fn main_0() -> i32 { let mut m: FnPtr = lambda_unsafe!( { let d: Dropped = { - let mut __v: Dropped = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Dropped = ZeroInitializationUnsafe::zero_init(); + Dropped::constructor_1(&raw mut __v); __v }; }, @@ -170,8 +161,8 @@ unsafe fn main_0() -> i32 { let mut k: FnPtr = lambda_unsafe!( { let d: Dropped = { - let mut __v: Dropped = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Dropped = ZeroInitializationUnsafe::zero_init(); + Dropped::constructor_1(&raw mut __v); __v }; }, @@ -190,8 +181,8 @@ unsafe fn main_0() -> i32 { let mut inner: FnPtr = lambda_unsafe!( { let d: Dropped = { - let mut __v: Dropped = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Dropped = ZeroInitializationUnsafe::zero_init(); + Dropped::constructor_1(&raw mut __v); __v }; }, diff --git a/tests/unit/out/unsafe/lambda_decltype_type.rs b/tests/unit/out/unsafe/lambda_decltype_type.rs index be9e62fc14..359658656c 100644 --- a/tests/unit/out/unsafe/lambda_decltype_type.rs +++ b/tests/unit/out/unsafe/lambda_decltype_type.rs @@ -10,7 +10,8 @@ use std::rc::Rc; #[derive( Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { pub items: [i32; 4], pub size: i32, @@ -62,7 +63,8 @@ impl Default for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { #[derive( Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { pub items: [i32; 4], pub size: i32, diff --git a/tests/unit/out/unsafe/lambda_immediate_init.rs b/tests/unit/out/unsafe/lambda_immediate_init.rs index ef646efde6..b938db43ce 100644 --- a/tests/unit/out/unsafe/lambda_immediate_init.rs +++ b/tests/unit/out/unsafe/lambda_immediate_init.rs @@ -19,7 +19,8 @@ pub unsafe fn pick_0(mut x: i32) -> i32 { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct S { pub j: i32, pub k: i32, diff --git a/tests/unit/out/unsafe/lambda_move_only_capture.rs b/tests/unit/out/unsafe/lambda_move_only_capture.rs index 465e9ffbb8..864bf6bade 100644 --- a/tests/unit/out/unsafe/lambda_move_only_capture.rs +++ b/tests/unit/out/unsafe/lambda_move_only_capture.rs @@ -7,24 +7,28 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultConstructibleUnsafe)] -#[cpp_from(i32, construct, value)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultConstructibleUnsafe, ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Owner { pub p: *mut i32, } impl Owner { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).p).write((Box::leak(Box::new(v)) as *mut i32)); } + pub unsafe fn constructor_3(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(); + } pub unsafe fn take(this: *mut Self) -> FnPtr i32> { return lambda_unsafe!( { let self_: Owner = { - let mut __v: Owner = ::zero_init(); - MoveConstructibleUnsafe::move_constructor( - &raw mut __v, - RvalueRefUnsafe::bind(&mut (*this)), - ); + let mut __v: Owner = ZeroInitializationUnsafe::zero_init(); + Owner::constructor_3(&raw mut __v, RvalueRefUnsafe::bind(&mut (*this))); __v }; }, @@ -34,13 +38,6 @@ impl Owner { ); } } -impl MoveConstructibleUnsafe for 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(); - } -} impl DestructibleUnsafe for Owner { unsafe fn destroy(this: *mut Self) { { @@ -58,15 +55,12 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(o, Owner(5)); + object_unsafe!(o, Owner::constructor_1(5)); let mut f: FnPtr i32> = lambda_unsafe!( { let h: Owner = { - let mut __v: Owner = ::zero_init(); - MoveConstructibleUnsafe::move_constructor( - &raw mut __v, - RvalueRefUnsafe::bind(&mut o), - ); + let mut __v: Owner = ZeroInitializationUnsafe::zero_init(); + Owner::constructor_3(&raw mut __v, RvalueRefUnsafe::bind(&mut o)); __v }; }, @@ -88,8 +82,8 @@ unsafe fn main_0() -> i32 { let mut consume: FnPtr = lambda_unsafe!( { let h: Owner = { - let mut __v: Owner = ::zero_init(); - Owner::construct(&raw mut __v, 7); + let mut __v: Owner = ZeroInitializationUnsafe::zero_init(); + Owner::constructor_1(&raw mut __v, 7); __v }; let total: *mut i32 = &mut total; @@ -105,7 +99,7 @@ unsafe fn main_0() -> i32 { (unsafe { consume.call() }); (unsafe { consume.call() }); assert!(((total) == (7))); - object_unsafe!(o2, Owner(9)); + object_unsafe!(o2, Owner::constructor_1(9)); let mut t: FnPtr i32> = (unsafe { Owner::take(&raw mut o2) }); let _dtor_t = std::mem::DropGuard::new(&raw mut t, |__p| unsafe { DestructibleUnsafe::destroy(__p) diff --git a/tests/unit/out/unsafe/libc_struct_without_default.rs b/tests/unit/out/unsafe/libc_struct_without_default.rs index 5a47987693..eee5baa317 100644 --- a/tests/unit/out/unsafe/libc_struct_without_default.rs +++ b/tests/unit/out/unsafe/libc_struct_without_default.rs @@ -19,7 +19,8 @@ use std::rc::Rc; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct UserDefined { pub a: [i32; 1], pub v: Vec, diff --git a/tests/unit/out/unsafe/map.rs b/tests/unit/out/unsafe/map.rs index d5f4886aa3..e7a22f483a 100644 --- a/tests/unit/out/unsafe/map.rs +++ b/tests/unit/out/unsafe/map.rs @@ -25,8 +25,9 @@ pub unsafe fn inc_2(x: *mut i32) { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] -#[constructor(constructor_2, value(i32), value(i32))] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, i32, i32)] pub struct Point { pub x: i32, pub y: i32, diff --git a/tests/unit/out/unsafe/map_key_copy_ctor.rs b/tests/unit/out/unsafe/map_key_copy_ctor.rs index 6079a7fda5..716f383024 100644 --- a/tests/unit/out/unsafe/map_key_copy_ctor.rs +++ b/tests/unit/out/unsafe/map_key_copy_ctor.rs @@ -11,26 +11,25 @@ pub static mut moves_1: std::cell::LazyCell = std::cell::LazyCell::new(|| u pub static mut made_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Key { pub k: i32, } impl Key { - pub unsafe fn construct(this: *mut Self, mut k: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut k: i32) { (&raw mut (*this).k).write(k); } -} -impl CopyConstructibleUnsafe for Key { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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: RvalueRefUnsafe) { + pub unsafe fn constructor_3(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(); @@ -43,7 +42,7 @@ impl LessThanComparableUnsafe for Key { } pub unsafe fn make_key_3(__return: *mut Key, mut k: i32) { (*std::cell::LazyCell::force_mut(&mut *&raw mut made_2)).prefix_inc(); - Key::construct(__return, k); + Key::constructor_1(__return, k); return; } pub fn main() { @@ -55,9 +54,9 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut ok: bool = true; let mut m: UnsafeMap = UnsafeMap::new(); - object_unsafe!(a, Key(1)); - object_unsafe!(b, Key(2)); - object_unsafe!(c, Key(3)); + object_unsafe!(a, Key::constructor_1(1)); + object_unsafe!(b, Key::constructor_1(2)); + object_unsafe!(c, Key::constructor_1(3)); (*m.subscript(&a, || 0_i32)) = 10; ok = ((ok as i32) & (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (1)) as i32)) @@ -76,7 +75,7 @@ unsafe fn main_0() -> i32 { & (((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (2)) as i32)) != 0; { - let mut __tmp_1: Key = ::zero_init(); + let mut __tmp_1: Key = ZeroInitializationUnsafe::zero_init(); (*match (({ (unsafe { make_key_3(&raw mut __tmp_1, 4) }); &mut __tmp_1 @@ -86,7 +85,7 @@ unsafe fn main_0() -> i32 { }) = 40 }; { - let mut __tmp_3: Key = ::zero_init(); + let mut __tmp_3: Key = ZeroInitializationUnsafe::zero_init(); (*match (({ (unsafe { make_key_3(&raw mut __tmp_3, 4) }); &mut __tmp_3 @@ -116,9 +115,9 @@ unsafe fn main_0() -> i32 { != 0; let mut first: *const Key = (&(*m.begin().iter_deref()).0 as *const Key); { - let mut __tmp_5: Key = ::zero_init(); + let mut __tmp_5: Key = ZeroInitializationUnsafe::zero_init(); (*match (({ - Key::construct(&raw mut __tmp_5, 0); + Key::constructor_1(&raw mut __tmp_5, 0); &mut __tmp_5 } as *mut Key),) { diff --git a/tests/unit/out/unsafe/map_key_identity.rs b/tests/unit/out/unsafe/map_key_identity.rs index b311990fe3..fe4f9c4623 100644 --- a/tests/unit/out/unsafe/map_key_identity.rs +++ b/tests/unit/out/unsafe/map_key_identity.rs @@ -18,7 +18,9 @@ pub static mut default_constructions_0: std::cell::LazyCell = TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Key { pub order: i32, pub identity: i32, @@ -29,12 +31,22 @@ impl LessThanComparableUnsafe for Key { } } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Mapped { pub value: i32, } -impl DefaultConstructibleUnsafe for Mapped { - unsafe fn default_constructor(this: *mut Self) { +impl Mapped { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).value).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)).prefix_inc(); } @@ -43,8 +55,8 @@ impl Default for Mapped { fn default() -> Self { unsafe { { - let mut __v: Mapped = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Mapped = ZeroInitializationUnsafe::zero_init(); + Mapped::constructor_1(&raw mut __v); __v } } diff --git a/tests/unit/out/unsafe/map_try_emplace.rs b/tests/unit/out/unsafe/map_try_emplace.rs index 9e806e81cf..8e174ec643 100644 --- a/tests/unit/out/unsafe/map_try_emplace.rs +++ b/tests/unit/out/unsafe/map_try_emplace.rs @@ -11,31 +11,29 @@ pub static mut made_1: std::cell::LazyCell = std::cell::LazyCell::new(|| un pub static mut copies_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut moves_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe)] -#[cpp_from(i32, construct_1, value)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, i32)] +#[constructor(constructor_3, LvalueRefUnsafe>)] +#[constructor(constructor_4, RvalueRefUnsafe)] pub struct Item { pub value: i32, } impl Item { - pub unsafe fn construct_1(this: *mut Self, mut value: i32) { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).value).write(0); + } + pub unsafe fn constructor_2(this: *mut Self, mut value: i32) { (&raw mut (*this).value).write(value); (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)).prefix_inc(); } -} -impl DefaultConstructibleUnsafe for Item { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).value).write(0); - } -} -impl CopyConstructibleUnsafe for Item { - unsafe fn copy_constructor(this: *mut Self, other: LvalueRefUnsafe>) { + pub unsafe fn constructor_3(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: RvalueRefUnsafe) { + pub unsafe fn constructor_4(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(); @@ -46,8 +44,8 @@ impl Default for Item { fn default() -> Self { unsafe { { - let mut __v: Item = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_1(&raw mut __v); __v } } @@ -58,12 +56,27 @@ pub unsafe fn argument_4(item: *mut Item) -> *mut Item { return item; } #[repr(C)] -#[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyCopyableUnsafe, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe, i32 )] pub struct RefItem { pub value: i32, } impl RefItem { - pub unsafe fn construct_1(this: *mut Self, counter: *mut i32, mut amount: i32) { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).value).write(0); + } + pub unsafe fn constructor_2(this: *mut Self, counter: LvalueRefUnsafe, mut amount: i32) { + let counter = (counter.as_ptr() as *mut i32); (&raw mut (*this).value).write({ (*counter) += amount; (*counter) @@ -71,17 +84,12 @@ impl RefItem { (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)).prefix_inc(); } } -impl DefaultConstructibleUnsafe for RefItem { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).value).write(0); - } -} impl Default for RefItem { fn default() -> Self { unsafe { { - let mut __v: RefItem = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: RefItem = ZeroInitializationUnsafe::zero_init(); + RefItem::constructor_1(&raw mut __v); __v } } @@ -256,11 +264,11 @@ unsafe fn main_0() -> i32 { let mut items: UnsafeMap = UnsafeMap::new(); let mut key: i32 = 0; items.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - Item::construct_1(&raw mut __v, 10); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_2(&raw mut __v, 10); __v }); - object_unsafe!(source, Item::construct_1(20)); + object_unsafe!(source, Item::constructor_2(20)); (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) = { (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) = { (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) = 0; @@ -268,16 +276,14 @@ 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(); - CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(__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 = ZeroInitializationUnsafe::zero_init(); + Item::constructor_3(&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))) @@ -286,17 +292,14 @@ 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(); - MoveConstructibleUnsafe::move_constructor(&raw mut __v, RvalueRefUnsafe::bind(__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 = ZeroInitializationUnsafe::zero_init(); + Item::constructor_4(&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))) @@ -306,16 +309,14 @@ 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(); - CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(__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 = ZeroInitializationUnsafe::zero_init(); + Item::constructor_3(&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))) @@ -325,16 +326,14 @@ 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(); - MoveConstructibleUnsafe::move_constructor(&raw mut __v, RvalueRefUnsafe::bind(__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 = ZeroInitializationUnsafe::zero_init(); + Item::constructor_4(&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))) @@ -350,16 +349,16 @@ unsafe fn main_0() -> i32 { key = 0; let mut counter: i32 = 0; refs.try_emplace(key, || { - let mut __v: RefItem = ::zero_init(); - RefItem::construct_1(&raw mut __v, &mut counter, 5); + let mut __v: RefItem = ZeroInitializationUnsafe::zero_init(); + RefItem::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(&mut counter), 5); __v }); (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) = 0; let mut ref_hit: (UnsafeBidirectionalIterator<(i32, RefItem)>, bool) = match (((unsafe { reference_5(&mut counter) }) as *mut i32),) { (__tmp_10,) => refs.try_emplace(key, || { - let mut __v: RefItem = ::zero_init(); - RefItem::construct_1(&raw mut __v, __tmp_10, 2); + let mut __v: RefItem = ZeroInitializationUnsafe::zero_init(); + RefItem::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_10), 2); __v }), }; @@ -373,8 +372,8 @@ unsafe fn main_0() -> i32 { let mut ref_new: (UnsafeBidirectionalIterator<(i32, RefItem)>, bool) = match (((unsafe { reference_5(&mut counter) }) as *mut i32),) { (__tmp_11,) => refs.try_emplace(key, || { - let mut __v: RefItem = ::zero_init(); - RefItem::construct_1(&raw mut __v, __tmp_11, 2); + let mut __v: RefItem = ZeroInitializationUnsafe::zero_init(); + RefItem::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(__tmp_11), 2); __v }), }; @@ -397,18 +396,15 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)) }; let mut temporary_hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = { - let mut __tmp_13: Item = ::zero_init(); + let mut __tmp_13: Item = ZeroInitializationUnsafe::zero_init(); match (({ - Item::construct_1(&raw mut __tmp_13, 30); + Item::constructor_2(&raw mut __tmp_13, 30); &mut __tmp_13 } as *mut Item),) { (__tmp_12,) => items.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - MoveConstructibleUnsafe::move_constructor( - &raw mut __v, - RvalueRefUnsafe::bind(__tmp_12), - ); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_4(&raw mut __v, RvalueRefUnsafe::bind(__tmp_12)); __v }), } @@ -423,18 +419,15 @@ unsafe fn main_0() -> i32 { key.prefix_inc(); key.prefix_inc(); let mut temporary_new: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = { - let mut __tmp_15: Item = ::zero_init(); + let mut __tmp_15: Item = ZeroInitializationUnsafe::zero_init(); match (({ - Item::construct_1(&raw mut __tmp_15, 40); + Item::constructor_2(&raw mut __tmp_15, 40); &mut __tmp_15 } as *mut Item),) { (__tmp_14,) => items.try_emplace(key, || { - let mut __v: Item = ::zero_init(); - MoveConstructibleUnsafe::move_constructor( - &raw mut __v, - RvalueRefUnsafe::bind(__tmp_14), - ); + let mut __v: Item = ZeroInitializationUnsafe::zero_init(); + Item::constructor_4(&raw mut __v, RvalueRefUnsafe::bind(__tmp_14)); __v }), } diff --git a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs index 9bebb01a0e..96e0eacc66 100644 --- a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs +++ b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs @@ -18,8 +18,9 @@ pub static mut visits_1: std::cell::LazyCell = std::cell::LazyCell::new(|| TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] -#[constructor(constructor_2, lvalue_ref(i32), value(i32))] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe, i32 )] pub struct Item { pub value: i32, } @@ -67,7 +68,8 @@ pub static mut temporary_calls_4: std::cell::LazyCell = TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Temporary { pub n: i32, pub data: [i32; 2], @@ -101,7 +103,8 @@ impl Default for Temporary { Default, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Nested { pub inner: Temporary, } @@ -130,7 +133,8 @@ pub unsafe fn make_nested_6() -> Nested { )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(move, default = constructor_1)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct Owner { pub ptr: Option>, } @@ -162,7 +166,7 @@ impl Default for Owner { } #[repr(C)] #[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] -#[conversions(default = constructor_1)] +#[constructor(constructor_1)] pub struct Noncopy { pub n: i32, } @@ -186,8 +190,9 @@ impl Default for Noncopy { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] -#[constructor(constructor_2, const_lvalue_ref(i32))] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct Held { pub ptr: *const i32, } diff --git a/tests/unit/out/unsafe/max.rs b/tests/unit/out/unsafe/max.rs index 927725fa71..52daa3f512 100644 --- a/tests/unit/out/unsafe/max.rs +++ b/tests/unit/out/unsafe/max.rs @@ -20,7 +20,6 @@ pub unsafe fn pick_3(mut i: i32) -> *mut i32 { #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, MoveConstructibleUnsafe, @@ -29,17 +28,18 @@ pub unsafe fn pick_3(mut i: i32) -> *mut i32 { Default, )] #[memberwise(copy_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct Bag { pub n: i32, } impl Bag { - pub unsafe fn construct(this: *mut Self, mut n: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut n: i32) { (&raw mut (*this).n).write(n); } -} -impl CopyConstructibleUnsafe for Bag { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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(); @@ -51,7 +51,7 @@ impl LessThanComparableUnsafe for Bag { } } pub unsafe fn make_4(__return: *mut Bag, mut n: i32) { - Bag::construct(__return, n); + Bag::constructor_1(__return, n); return; } pub fn main() { @@ -165,8 +165,8 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)) = 0; assert!( ({ - let mut __tmp_5: Bag = ::zero_init(); - let mut __tmp_7: Bag = ::zero_init(); + let mut __tmp_5: Bag = ZeroInitializationUnsafe::zero_init(); + let mut __tmp_7: Bag = ZeroInitializationUnsafe::zero_init(); (((*match ( ({ (unsafe { make_4(&raw mut __tmp_5, 1) }); @@ -189,8 +189,8 @@ unsafe fn main_0() -> i32 { }) .n) == (2)) }) && ({ - let mut __tmp_9: Bag = ::zero_init(); - let mut __tmp_11: Bag = ::zero_init(); + let mut __tmp_9: Bag = ZeroInitializationUnsafe::zero_init(); + let mut __tmp_11: Bag = ZeroInitializationUnsafe::zero_init(); (((*match ( ({ (unsafe { make_4(&raw mut __tmp_9, 1) }); diff --git a/tests/unit/out/unsafe/move_assign.rs b/tests/unit/out/unsafe/move_assign.rs index dd069c5785..215170a416 100644 --- a/tests/unit/out/unsafe/move_assign.rs +++ b/tests/unit/out/unsafe/move_assign.rs @@ -10,22 +10,22 @@ use std::rc::Rc; #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, SwappableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct MoveOnly { pub v: i32, } impl MoveOnly { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl MoveConstructibleUnsafe for MoveOnly { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut MoveOnly); (&raw mut (*this).v).write((*o).v); (*o).v = 0; @@ -43,11 +43,15 @@ impl MoveAssignableUnsafe for MoveOnly { } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] +#[constructor(constructor_1)] pub struct ConstMoveAssign { pub mark: i32, } impl ConstMoveAssign { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).mark).write(0); + } pub unsafe fn operator_assign_2( this: *mut Self, o: *mut ConstMoveAssign, @@ -63,25 +67,20 @@ impl ConstMoveAssign { return &mut (*this); } } -impl DefaultConstructibleUnsafe for ConstMoveAssign { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).mark).write(0); - } -} impl Default for ConstMoveAssign { fn default() -> Self { unsafe { { - let mut __v: ConstMoveAssign = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: ConstMoveAssign = ZeroInitializationUnsafe::zero_init(); + ConstMoveAssign::constructor_1(&raw mut __v); __v } } } } pub unsafe fn make_0(__return: *mut MoveOnly, mut v: i32) { - object_unsafe!(m, MoveOnly(v)); - MoveConstructibleUnsafe::move_constructor(__return, RvalueRefUnsafe::bind(&mut m)); + object_unsafe!(m, MoveOnly::constructor_1(v)); + MoveOnly::constructor_3(__return, RvalueRefUnsafe::bind(&mut m)); return; } pub fn main() { @@ -91,27 +90,27 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, MoveOnly(1)); - object_unsafe!(b, MoveOnly(2)); - object_unsafe!(c, MoveOnly(3)); + object_unsafe!(a, MoveOnly::constructor_1(1)); + object_unsafe!(b, MoveOnly::constructor_1(2)); + object_unsafe!(c, MoveOnly::constructor_1(3)); 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); + let mut _o: MoveOnly = ZeroInitializationUnsafe::zero_init(); + MoveOnly::constructor_1(&raw mut _o, 3); assign_unsafe!(b = RvalueRefUnsafe(_o)) }); 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); + let mut _o: MoveOnly = ZeroInitializationUnsafe::zero_init(); + MoveOnly::constructor_1(&raw mut _o, 5); assign_unsafe!(a = RvalueRefUnsafe(_o)) }); assert!(((a.v) == (5))); (unsafe { - let mut _o: MoveOnly = ::zero_init(); + let mut _o: MoveOnly = ZeroInitializationUnsafe::zero_init(); (unsafe { make_0(&raw mut _o, 6) }); assign_unsafe!(a = RvalueRefUnsafe(_o)) }); @@ -123,23 +122,23 @@ unsafe fn main_0() -> i32 { assert!(((a.v) == (6))); let mut vec_: Vec = Vec::new(); { - let mut __tmp_1: MoveOnly = ::zero_init(); + let mut __tmp_1: MoveOnly = ZeroInitializationUnsafe::zero_init(); match (({ - MoveOnly::construct(&raw mut __tmp_1, 7); + MoveOnly::constructor_1(&raw mut __tmp_1, 7); &mut __tmp_1 } as *mut MoveOnly),) { (__tmp_0,) => vec_.push_moved(__tmp_0), } }; - object_unsafe!(d, MoveOnly(8)); + object_unsafe!(d, MoveOnly::constructor_1(8)); assign_unsafe!(vec_[(0_usize)] = RvalueRefUnsafe(d)); assert!(((vec_[(0_usize)].v) == (8))); assert!(((d.v) == (0))); - object_unsafe!(m, ConstMoveAssign); - object_unsafe!(m1, ConstMoveAssign); - object_unsafe!(m2, ConstMoveAssign); - object_unsafe!(cm, ConstMoveAssign); + object_unsafe!(m, ConstMoveAssign::constructor_1()); + object_unsafe!(m1, ConstMoveAssign::constructor_1()); + object_unsafe!(m2, ConstMoveAssign::constructor_1()); + object_unsafe!(cm, ConstMoveAssign::constructor_1()); (unsafe { ConstMoveAssign::operator_assign_2(&raw mut m1, &mut m) }); (unsafe { ConstMoveAssign::operator_assign_3(&raw mut m2, &cm) }); assert!(((m1.mark) == (1))); diff --git a/tests/unit/out/unsafe/move_ctor.rs b/tests/unit/out/unsafe/move_ctor.rs index 19b86d5dfd..560f78c913 100644 --- a/tests/unit/out/unsafe/move_ctor.rs +++ b/tests/unit/out/unsafe/move_ctor.rs @@ -8,48 +8,52 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct MoveOnly { pub v: i32, } impl MoveOnly { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl MoveConstructibleUnsafe for MoveOnly { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut MoveOnly); (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe)] +#[derive(FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, RvalueRefUnsafe)] +#[constructor(constructor_3, RvalueRefUnsafe>)] pub struct ConstMove { pub mark: i32, } impl ConstMove { - pub unsafe fn construct_1(this: *mut Self, o: *mut ConstMove) { + pub unsafe fn constructor_1(this: *mut Self) { + (&raw mut (*this).mark).write(0); + } + pub unsafe fn constructor_2(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut ConstMove); (&raw mut (*this).mark).write((((*o).mark) + (1))); } - pub unsafe fn construct_2(this: *mut Self, o: *const ConstMove) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe>) { + let o = (o.as_ptr() as *const ConstMove); (&raw mut (*this).mark).write((((*o).mark) + (10))); } } -impl DefaultConstructibleUnsafe for ConstMove { - unsafe fn default_constructor(this: *mut Self) { - (&raw mut (*this).mark).write(0); - } -} impl Default for ConstMove { fn default() -> Self { unsafe { { - let mut __v: ConstMove = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: ConstMove = ZeroInitializationUnsafe::zero_init(); + ConstMove::constructor_1(&raw mut __v); __v } } @@ -57,31 +61,30 @@ impl Default for ConstMove { } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct ThrowingMove { pub v: i32, pub copies: i32, pub moves: i32, } impl ThrowingMove { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).copies).write(0); (&raw mut (*this).moves).write(0); } -} -impl CopyConstructibleUnsafe for ThrowingMove { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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: RvalueRefUnsafe) { + pub unsafe fn constructor_3(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); @@ -91,31 +94,30 @@ impl MoveConstructibleUnsafe for ThrowingMove { } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct NoexceptMove { pub v: i32, pub copies: i32, pub moves: i32, } impl NoexceptMove { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); (&raw mut (*this).copies).write(0); (&raw mut (*this).moves).write(0); } -} -impl CopyConstructibleUnsafe for NoexceptMove { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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: RvalueRefUnsafe) { + pub unsafe fn constructor_3(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); @@ -123,12 +125,13 @@ impl MoveConstructibleUnsafe for NoexceptMove { (*o).v = 0; } } -pub unsafe fn by_value_0(m: *mut MoveOnly) -> i32 { +pub unsafe fn by_value_0(m: ParameterObjectUnsafe) -> i32 { + let m = (m.as_ptr() as *mut MoveOnly); return (*m).v; } pub unsafe fn make_1(__return: *mut MoveOnly, mut v: i32) { - object_unsafe!(m, MoveOnly(v)); - MoveConstructibleUnsafe::move_constructor(__return, RvalueRefUnsafe::bind(&mut m)); + object_unsafe!(m, MoveOnly::constructor_1(v)); + MoveOnly::constructor_3(__return, RvalueRefUnsafe::bind(&mut m)); return; } pub fn main() { @@ -138,75 +141,78 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, MoveOnly(1)); - object_unsafe!(b, MoveOnly, RvalueRefUnsafe::bind(&mut a)); + object_unsafe!(a, MoveOnly::constructor_1(1)); + object_unsafe!(b, MoveOnly::constructor_3(RvalueRefUnsafe::bind(&mut a))); assert!(((b.v) == (1))); assert!(((a.v) == (0))); - object_unsafe!(c, MoveOnly, RvalueRefUnsafe::bind(&mut b)); + object_unsafe!(c, MoveOnly::constructor_3(RvalueRefUnsafe::bind(&mut b))); assert!(((c.v) == (1))); assert!(((b.v) == (0))); - object_unsafe!(d, MoveOnly, RvalueRefUnsafe::bind(&mut c)); + object_unsafe!(d, MoveOnly::constructor_3(RvalueRefUnsafe::bind(&mut c))); assert!(((d.v) == (1))); assert!(((c.v) == (0))); object_unsafe!(e, MoveOnly, |e| (unsafe { make_1(e, 5,) })); assert!(((e.v) == (5))); assert!( ((unsafe { - let mut _m: MoveOnly = ::zero_init(); - MoveOnly::construct(&raw mut _m, 6); - by_value_0(&mut _m) + let mut _m: MoveOnly = ZeroInitializationUnsafe::zero_init(); + MoveOnly::constructor_1(&raw mut _m, 6); + by_value_0(ParameterObjectUnsafe::bind(&mut _m)) }) == (6)) ); assert!( ((unsafe { - let mut _m: MoveOnly = ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&raw mut _m, RvalueRefUnsafe::bind(&mut e)); - by_value_0(&mut _m) + let mut _m: MoveOnly = ZeroInitializationUnsafe::zero_init(); + MoveOnly::constructor_3(&raw mut _m, RvalueRefUnsafe::bind(&mut e)); + by_value_0(ParameterObjectUnsafe::bind(&mut _m)) }) == (5)) ); assert!(((e.v) == (0))); let mut vec_: Vec = Vec::new(); { - let mut __tmp_1: MoveOnly = ::zero_init(); + let mut __tmp_1: MoveOnly = ZeroInitializationUnsafe::zero_init(); match (({ - MoveOnly::construct(&raw mut __tmp_1, 7); + MoveOnly::constructor_1(&raw mut __tmp_1, 7); &mut __tmp_1 } as *mut MoveOnly),) { (__tmp_0,) => vec_.push_moved(__tmp_0), } }; - object_unsafe!(f, MoveOnly(8)); + object_unsafe!(f, MoveOnly::constructor_1(8)); vec_.push_moved(&mut f); assert!(((vec_[(0_usize)].v) == (7)) && ((vec_[(1_usize)].v) == (8))); assert!(((f.v) == (0))); - object_unsafe!(m, ConstMove); - object_unsafe!(m1, ConstMove::construct_1(&mut m)); - object_unsafe!(cm, ConstMove); - object_unsafe!(m2, ConstMove::construct_2(&cm)); + object_unsafe!(m, ConstMove::constructor_1()); + object_unsafe!(m1, ConstMove::constructor_2(RvalueRefUnsafe::bind(&mut m))); + object_unsafe!(cm, ConstMove::constructor_1()); + object_unsafe!(m2, ConstMove::constructor_3(RvalueRefUnsafe::bind(&cm))); assert!(((m1.mark) == (1))); assert!(((m2.mark) == (10))); - object_unsafe!(t, ThrowingMove(1)); - object_unsafe!(t1, ThrowingMove, LvalueRefUnsafe::bind(&t)); + object_unsafe!(t, ThrowingMove::constructor_1(1)); + object_unsafe!(t1, ThrowingMove::constructor_2(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, RvalueRefUnsafe::bind(&mut n)); + object_unsafe!(n, NoexceptMove::constructor_1(2)); + object_unsafe!( + n1, + NoexceptMove::constructor_3(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, RvalueRefUnsafe::bind(&mut g)); + object_unsafe!(g, MoveOnly::constructor_1(3)); + object_unsafe!(g1, MoveOnly::constructor_3(RvalueRefUnsafe::bind(&mut g))); assert!(((g1.v) == (3))); assert!(((g.v) == (0))); let mut nv: Vec = Vec::new(); { - let mut __tmp_3: NoexceptMove = ::zero_init(); + let mut __tmp_3: NoexceptMove = ZeroInitializationUnsafe::zero_init(); match (({ - NoexceptMove::construct(&raw mut __tmp_3, 4); + NoexceptMove::constructor_1(&raw mut __tmp_3, 4); &mut __tmp_3 } as *mut NoexceptMove),) { diff --git a/tests/unit/out/unsafe/move_this.rs b/tests/unit/out/unsafe/move_this.rs index ef8486e171..bf79529233 100644 --- a/tests/unit/out/unsafe/move_this.rs +++ b/tests/unit/out/unsafe/move_this.rs @@ -8,16 +8,28 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Chain { pub v: i32, } impl Chain { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } + pub unsafe fn constructor_2(this: *mut Self, o: LvalueRefUnsafe>) { + let o = (o.as_ptr() as *const Chain); + (&raw mut (*this).v).write((((*o).v) + (100))); + } + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { + let o = (o.as_ptr() as *mut Chain); + (&raw mut (*this).v).write((((*o).v) + (1))); + (*o).v = 0; + } pub unsafe fn add_4(this: *mut Self, mut n: i32) -> *mut Chain { (*this).v += n; return &mut (*this); @@ -27,31 +39,19 @@ impl Chain { return &mut (*this); } pub unsafe fn take(this: *mut Self, __return: *mut Chain) { - MoveConstructibleUnsafe::move_constructor(__return, RvalueRefUnsafe::bind(&mut (*this))); + Chain::constructor_3(__return, RvalueRefUnsafe::bind(&mut (*this))); return; } pub unsafe fn copy(this: *const Self, __return: *mut Chain) { - CopyConstructibleUnsafe::copy_constructor(__return, LvalueRefUnsafe::bind(&(*this))); + Chain::constructor_2(__return, LvalueRefUnsafe::bind(&(*this))); return; } pub unsafe fn self_(this: *mut Self) -> *mut Chain { return &mut (*this); } } -impl CopyConstructibleUnsafe for 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: RvalueRefUnsafe) { - let o = (o.as_ptr() as *mut Chain); - (&raw mut (*this).v).write((((*o).v) + (1))); - (*o).v = 0; - } -} -pub unsafe fn consume_0(c: *mut Chain) -> i32 { +pub unsafe fn consume_0(c: ParameterObjectUnsafe) -> i32 { + let c = (c.as_ptr() as *mut Chain); return (*c).v; } pub fn main() { @@ -61,24 +61,23 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, Chain(1)); + object_unsafe!(a, Chain::constructor_1(1)); (unsafe { Chain::add_4(&raw mut (*(unsafe { Chain::add_4(&raw mut a, 1) })), 1) }); assert!(((a.v) == (3))); - object_unsafe!(b0, Chain(5)); + object_unsafe!(b0, Chain::constructor_1(5)); object_unsafe!( b, - Chain, - RvalueRefUnsafe::bind( + Chain::constructor_3(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| { - let mut __tmp_0: Chain = ::zero_init(); + let mut __tmp_0: Chain = ZeroInitializationUnsafe::zero_init(); (unsafe { Chain::take( &mut (*{ - Chain::construct(&raw mut __tmp_0, 10); + Chain::constructor_1(&raw mut __tmp_0, 10); &mut __tmp_0 }), c, @@ -88,18 +87,18 @@ unsafe fn main_0() -> i32 { assert!(((c.v) == (11))); object_unsafe!(d, Chain, |d| (unsafe { Chain::copy(&raw const c, d,) })); assert!(((d.v) == (111)) && ((c.v) == (11))); - object_unsafe!(g, Chain(20)); + object_unsafe!(g, Chain::constructor_1(20)); assert!( ((unsafe { - let mut _c: Chain = ::zero_init(); - MoveConstructibleUnsafe::move_constructor( + let mut _c: Chain = ZeroInitializationUnsafe::zero_init(); + Chain::constructor_3( &raw mut _c, RvalueRefUnsafe::bind((unsafe { Chain::self_(&raw mut g) })), ); - consume_0(&mut _c) + consume_0(ParameterObjectUnsafe::bind(&mut _c)) }) == (21)) ); - object_unsafe!(e, Chain(30)); + object_unsafe!(e, Chain::constructor_1(30)); object_unsafe!(f, Chain, |f| (unsafe { Chain::take(&raw mut e, f,) })); assert!(((f.v) == (31)) && ((e.v) == (0))); return 0; diff --git a/tests/unit/out/unsafe/operator_comparison_defaulted.rs b/tests/unit/out/unsafe/operator_comparison_defaulted.rs index d8bd31e8ea..94ba85e9ea 100644 --- a/tests/unit/out/unsafe/operator_comparison_defaulted.rs +++ b/tests/unit/out/unsafe/operator_comparison_defaulted.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Eq { pub a: i32, pub b: i32, @@ -34,6 +36,8 @@ pub struct Eq { PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct Cmp { pub a: i32, pub b: i32, @@ -76,6 +80,8 @@ impl LessThanComparableUnsafe for Cmp { PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct Both { pub a: i32, } @@ -110,6 +116,8 @@ impl LessThanComparableUnsafe for Both { PartiallyOrderedWithUnsafe, )] #[three_way(OrdOnly::operator_cmp)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct OrdOnly { pub a: i32, } @@ -143,6 +151,8 @@ impl LessThanComparableUnsafe for OrdOnly { PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct Inner { pub x: i32, } @@ -177,6 +187,8 @@ impl LessThanComparableUnsafe for Inner { PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct Outer { pub i: Inner, pub y: i32, @@ -218,7 +230,9 @@ impl LessThanComparableUnsafe for Outer { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Secondary { pub a: i32, } @@ -255,6 +269,8 @@ impl LessThanComparableUnsafe for Secondary { PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct PtrMember { pub p: *mut i32, } diff --git a/tests/unit/out/unsafe/operator_comparison_free.rs b/tests/unit/out/unsafe/operator_comparison_free.rs index 1d3c92e5d4..3f29909619 100644 --- a/tests/unit/out/unsafe/operator_comparison_free.rs +++ b/tests/unit/out/unsafe/operator_comparison_free.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct S { pub v: i32, } @@ -41,7 +43,9 @@ pub unsafe fn operator_lt_1(mut a: i32, b: *const S) -> bool { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct V { pub v: i32, } diff --git a/tests/unit/out/unsafe/operator_comparison_member.rs b/tests/unit/out/unsafe/operator_comparison_member.rs index 0f0c0299c7..4e3b54c8b4 100644 --- a/tests/unit/out/unsafe/operator_comparison_member.rs +++ b/tests/unit/out/unsafe/operator_comparison_member.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct S { pub v: i32, } diff --git a/tests/unit/out/unsafe/operator_comparison_nonbool.rs b/tests/unit/out/unsafe/operator_comparison_nonbool.rs index 197e3a3414..d267606bf5 100644 --- a/tests/unit/out/unsafe/operator_comparison_nonbool.rs +++ b/tests/unit/out/unsafe/operator_comparison_nonbool.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct X { pub v: i32, } @@ -53,7 +55,9 @@ pub unsafe fn operator_ge_3(mut a: X, mut b: X) -> i32 { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Result { pub r: i32, } @@ -67,7 +71,9 @@ pub struct Result { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Custom { pub v: i32, } @@ -88,7 +94,9 @@ impl Custom { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Mixed { pub v: i32, } @@ -117,17 +125,19 @@ impl LessThanComparableUnsafe for Mixed { VaArg, FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] -#[cpp_into(bool, to_bool)] +#[conversions(copy, move)] +#[constructor(constructor_1, explicit, bool)] +#[conversion_function(to_bool, LvalueRefUnsafe>, bool )] pub struct MyBool { pub value: bool, } impl MyBool { - pub unsafe fn construct(this: *mut Self, mut v: bool) { + pub unsafe fn constructor_1(this: *mut Self, mut v: bool) { (&raw mut (*this).value).write(v); } pub unsafe fn to_bool(this: *const Self) -> bool { @@ -144,7 +154,9 @@ impl MyBool { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Boolish { pub v: i32, } @@ -158,15 +170,15 @@ impl LessThanComparableUnsafe for Boolish { } pub unsafe fn operator_eq_7(mut a: Boolish, mut b: Boolish) -> MyBool { return { - let mut __v: MyBool = ::zero_init(); - MyBool::construct(&raw mut __v, ((a.v) == (b.v))); + let mut __v: MyBool = ZeroInitializationUnsafe::zero_init(); + MyBool::constructor_1(&raw mut __v, ((a.v) == (b.v))); __v }; } pub unsafe fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { return { - let mut __v: MyBool = ::zero_init(); - MyBool::construct(&raw mut __v, ((a.v) < (b.v))); + let mut __v: MyBool = ZeroInitializationUnsafe::zero_init(); + MyBool::constructor_1(&raw mut __v, ((a.v) < (b.v))); __v }; } @@ -174,19 +186,20 @@ pub unsafe fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, MoveAssignableUnsafe, Default, )] #[memberwise(copy_assign)] -#[cpp_into(bool, to_bool)] +#[derive(ConversionsUnsafe)] +#[constructor(constructor_1, explicit, bool)] +#[conversion_function(to_bool, LvalueRefUnsafe>, bool )] pub struct RefBool { pub value: bool, } impl RefBool { - pub unsafe fn construct(this: *mut Self, mut v: bool) { + pub unsafe fn constructor_1(this: *mut Self, mut v: bool) { (&raw mut (*this).value).write(v); } pub unsafe fn to_bool(this: *const Self) -> bool { @@ -195,8 +208,8 @@ impl RefBool { } pub static mut ref_true_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let mut __v: RefBool = ::zero_init(); - RefBool::construct(&raw mut __v, true); + let mut __v: RefBool = ZeroInitializationUnsafe::zero_init(); + RefBool::constructor_1(&raw mut __v, true); __v } }); @@ -210,7 +223,9 @@ pub static mut ref_true_8: std::cell::LazyCell = std::cell::LazyCell::n TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct RefInt { pub v: i32, } diff --git a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs index a8079f7e48..d2172b3b03 100644 --- a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs +++ b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs @@ -13,20 +13,17 @@ impl LessThanComparableUnsafe for S { } #[repr(C)] #[derive( - FnPtrArg, - ZeroInitializationUnsafe, - CppFromUnsafe, - DefaultInitializableUnsafe, - MemberwiseUnsafe, - Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, )] #[memberwise(move_constructor)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1, i32)] pub struct S { data_: i32, } impl S { - pub unsafe fn construct(this: *mut Self, mut data: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut data: i32) { (&raw mut (*this).data_).write(data); } } @@ -37,9 +34,9 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, S(1)); - object_unsafe!(b, S(2)); - object_unsafe!(c, S(1)); + object_unsafe!(a, S::constructor_1(1)); + object_unsafe!(b, S::constructor_1(2)); + object_unsafe!(c, S::constructor_1(1)); assert!( (unsafe { let _x: *const S = &a; diff --git a/tests/unit/out/unsafe/operator_friend.rs b/tests/unit/out/unsafe/operator_friend.rs index ca483959cb..1d43aabf16 100644 --- a/tests/unit/out/unsafe/operator_friend.rs +++ b/tests/unit/out/unsafe/operator_friend.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Defaulted { pub a: i32, pub b: i32, @@ -50,6 +52,8 @@ impl ThreeWayComparableUnsafe for DefaultedOrd { PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct DefaultedOrd { pub a: i32, } @@ -78,7 +82,9 @@ pub unsafe fn operator_add_0(x: *const Inline, y: *const Inline) -> Inline { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Inline { pub a: i32, } @@ -92,7 +98,9 @@ pub struct Inline { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct OutOfLine { pub a: i32, } @@ -111,7 +119,9 @@ impl LessThanComparableUnsafe for Tmpl_int_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Tmpl_int_ { pub v: i32, } @@ -125,7 +135,9 @@ pub struct Tmpl_int_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Tmpl_long_ { pub v: i64, } @@ -139,7 +151,9 @@ pub struct Tmpl_long_ { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct TmplDefaulted_int_ { pub v: i32, } diff --git a/tests/unit/out/unsafe/operator_less_than.rs b/tests/unit/out/unsafe/operator_less_than.rs index 557eb3f9aa..a80f6bd106 100644 --- a/tests/unit/out/unsafe/operator_less_than.rs +++ b/tests/unit/out/unsafe/operator_less_than.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Pair { pub x: i32, pub y: i32, diff --git a/tests/unit/out/unsafe/operator_other_member.rs b/tests/unit/out/unsafe/operator_other_member.rs index 7ec461d9c1..d14ee5c86c 100644 --- a/tests/unit/out/unsafe/operator_other_member.rs +++ b/tests/unit/out/unsafe/operator_other_member.rs @@ -38,8 +38,8 @@ impl Static { ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_5, i32, const_lvalue_ref)] -#[conversion_function(conversion_function_6, bool, const_lvalue_ref, explicit)] +#[conversion_function(to_i32, LvalueRefUnsafe>, i32 )] +#[conversion_function(to_bool, LvalueRefUnsafe>, bool , explicit)] pub struct S { pub v: i32, } @@ -58,15 +58,11 @@ impl S { v: ((((*this).v) * (10)) + ((*o).v)), }; } - pub unsafe fn conversion_function_5(this: LvalueRefUnsafe>, __return: *mut i32) { - let this = this.as_ptr() as *mut S; - __return.write((*this).v); - return; + pub unsafe fn to_i32(this: *const Self) -> i32 { + return (*this).v; } - pub unsafe fn conversion_function_6(this: LvalueRefUnsafe>, __return: *mut bool) { - let this = this.as_ptr() as *mut S; - __return.write((((*this).v) != (0))); - return; + pub unsafe fn to_bool(this: *const Self) -> bool { + return (((*this).v) != (0)); } } pub fn main() { @@ -82,57 +78,18 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { S::operator_call_2(&raw const s, 1,) }) == (4))); assert!(((unsafe { S::operator_call_3(&raw const s, 1, 2,) }) == (6))); assert!((((unsafe { S::operator_comma(&raw const s, &t,) }).v) == (34))); - let mut i: i32 = { - let mut __v: i32 = ZeroInitializationUnsafe::zero_init(); - S::conversion_function_5(>>::bind(&mut s), &raw mut __v); - __v - }; + let mut i: i32 = (unsafe { S::to_i32(&raw const s) }); assert!(((i) == (3))); - assert!( - ((({ - let mut __v: i32 = ZeroInitializationUnsafe::zero_init(); - S::conversion_function_5(>>::bind(&mut s), &raw mut __v); - __v - }) + (1)) - == (4)) - ); - if { - let mut __v: bool = ZeroInitializationUnsafe::zero_init(); - S::conversion_function_6(>>::bind(&mut s), &raw mut __v); - __v - } { - assert!({ - let mut __v: bool = ZeroInitializationUnsafe::zero_init(); - S::conversion_function_6(>>::bind(&mut s), &raw mut __v); - __v - }); + assert!((((unsafe { S::to_i32(&raw const s,) }) + (1)) == (4))); + if (unsafe { S::to_bool(&raw const s) }) { + assert!((unsafe { S::to_bool(&raw const s,) })); } else { assert!(false); } let mut z: S = S { v: 0 }; - assert!({ - let mut __v: bool = ZeroInitializationUnsafe::zero_init(); - S::conversion_function_6(>>::bind(&mut s), &raw mut __v); - __v - }); - assert!( - !({ - let mut __v: bool = ZeroInitializationUnsafe::zero_init(); - S::conversion_function_6(>>::bind(&mut z), &raw mut __v); - __v - }) - ); - assert!( - ({ - let mut __v: bool = ZeroInitializationUnsafe::zero_init(); - S::conversion_function_6(>>::bind(&mut s), &raw mut __v); - __v - }) && (!({ - let mut __v: bool = ZeroInitializationUnsafe::zero_init(); - S::conversion_function_6(>>::bind(&mut z), &raw mut __v); - __v - })) - ); + assert!((unsafe { S::to_bool(&raw const s,) })); + assert!(!(unsafe { S::to_bool(&raw const z,) })); + assert!((unsafe { S::to_bool(&raw const s,) }) && (!(unsafe { S::to_bool(&raw const z,) }))); let mut st: Static = ::default(); assert!(((unsafe { Static::operator_call(6, 7,) }) == (42))); assert!(((unsafe { S::operator_call_1(&S { v: 5 },) }) == (5))); diff --git a/tests/unit/out/unsafe/operator_three_way.rs b/tests/unit/out/unsafe/operator_three_way.rs index b66591f0ff..adab99e390 100644 --- a/tests/unit/out/unsafe/operator_three_way.rs +++ b/tests/unit/out/unsafe/operator_three_way.rs @@ -19,6 +19,8 @@ use std::rc::Rc; PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct S { pub v: i32, } diff --git a/tests/unit/out/unsafe/operator_traits.rs b/tests/unit/out/unsafe/operator_traits.rs index 87f7a79611..befbfad472 100644 --- a/tests/unit/out/unsafe/operator_traits.rs +++ b/tests/unit/out/unsafe/operator_traits.rs @@ -16,7 +16,9 @@ use std::rc::Rc; TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Lt { pub v: i32, } @@ -35,7 +37,9 @@ impl LessThanComparableUnsafe for Lt { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Eq { pub v: i32, } @@ -52,6 +56,8 @@ pub struct Eq { PartiallyOrderedWithUnsafe, )] #[three_way(ThreeWayComparableUnsafe::three_way)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct Cmp { pub v: i32, } @@ -76,7 +82,9 @@ impl LessThanComparableUnsafe for Cmp { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Free { pub v: i32, } @@ -95,7 +103,9 @@ impl LessThanComparableUnsafe for Free { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Wrapped_int_ { pub v: i32, } diff --git a/tests/unit/out/unsafe/pair.rs b/tests/unit/out/unsafe/pair.rs index ea56436da7..bae0c585f0 100644 --- a/tests/unit/out/unsafe/pair.rs +++ b/tests/unit/out/unsafe/pair.rs @@ -20,7 +20,20 @@ unsafe fn main_0() -> i32 { assert!(((p2.0) == (3_f64))); assert!(((p2.1) == (4))); let mut p3: (f64, i32) = match ((&mut (5, 6) as *mut (i32, i32)),) { - (__tmp_0,) => (((*&mut (*__tmp_0).0) as f64), (*&mut (*__tmp_0).1)), + (__tmp_0,) => { + object_unsafe!(__first, f64, |__this| ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_0).0),) + )); + object_unsafe!(__second, i32, |__this| ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_0).1),) + )); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) + } }; assert!(((p3.0) == (5_f64))); assert!(((p3.1) == (6))); @@ -33,9 +46,21 @@ unsafe fn main_0() -> i32 { (&mut (arr.as_ptr().offset((1) as isize), n) as *mut (*const i32, u32)), ) { (__tmp_1, __tmp_2) => { - (*__tmp_1) = ( - cpp_move_unsafe!(&mut (*__tmp_2).0), - ((*&mut (*__tmp_2).1) as u64), + object_unsafe!(__first, *const i32, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::<*const i32>::bind(&raw mut (*__tmp_2).0), + __this + )); + object_unsafe!(__second, u64, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut (*__tmp_2).1), + __this + )); + MoveAssignableUnsafe::move_assign( + &raw mut (*__tmp_1).0, + RvalueRefUnsafe::<*const i32>::bind(&raw mut __first), + ); + MoveAssignableUnsafe::move_assign( + &raw mut (*__tmp_1).1, + RvalueRefUnsafe::::bind(&raw mut __second), ); } }; @@ -78,12 +103,42 @@ unsafe fn main_0() -> i32 { let mut narrow: (i32, i32) = (3, 4); let mut pw: *mut i64 = (&mut w.0 as *mut i64); { - w = (((*&narrow.0) as i64), ((*&narrow.1) as i64)); + object_unsafe!(__first, i64, |__this| ConvertibleToUnsafe::convert( + LvalueRefUnsafe::>::bind(&raw const narrow.0), + __this + )); + object_unsafe!(__second, i64, |__this| ConvertibleToUnsafe::convert( + LvalueRefUnsafe::>::bind(&raw const narrow.1), + __this + )); + MoveAssignableUnsafe::move_assign( + &raw mut w.0, + RvalueRefUnsafe::::bind(&raw mut __first), + ); + MoveAssignableUnsafe::move_assign( + &raw mut w.1, + RvalueRefUnsafe::::bind(&raw mut __second), + ); }; assert!(((*pw) == (3_i64))); let mut m: (i32, i32) = (5, 6); { - w = (((*&mut m.0) as i64), ((*&mut m.1) as i64)); + object_unsafe!(__first, i64, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut m.0), + __this + )); + object_unsafe!(__second, i64, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut m.1), + __this + )); + MoveAssignableUnsafe::move_assign( + &raw mut w.0, + RvalueRefUnsafe::::bind(&raw mut __first), + ); + MoveAssignableUnsafe::move_assign( + &raw mut w.1, + RvalueRefUnsafe::::bind(&raw mut __second), + ); }; assert!(((*pw) == (5_i64))); (*{ @@ -101,13 +156,43 @@ unsafe fn main_0() -> i32 { .0 = 8; assert!(((d.0) == (8)) && ((d.1) == (4))); (*{ - w = (((*&narrow.0) as i64), ((*&narrow.1) as i64)); + object_unsafe!(__first, i64, |__this| ConvertibleToUnsafe::convert( + LvalueRefUnsafe::>::bind(&raw const narrow.0), + __this + )); + object_unsafe!(__second, i64, |__this| ConvertibleToUnsafe::convert( + LvalueRefUnsafe::>::bind(&raw const narrow.1), + __this + )); + MoveAssignableUnsafe::move_assign( + &raw mut w.0, + RvalueRefUnsafe::::bind(&raw mut __first), + ); + MoveAssignableUnsafe::move_assign( + &raw mut w.1, + RvalueRefUnsafe::::bind(&raw mut __second), + ); &mut w }) .1 = 9_i64; assert!(((w.0) == (3_i64)) && ((w.1) == (9_i64))); (*{ - w = (((*&mut narrow.0) as i64), ((*&mut narrow.1) as i64)); + object_unsafe!(__first, i64, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut narrow.0), + __this + )); + object_unsafe!(__second, i64, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut narrow.1), + __this + )); + MoveAssignableUnsafe::move_assign( + &raw mut w.0, + RvalueRefUnsafe::::bind(&raw mut __first), + ); + MoveAssignableUnsafe::move_assign( + &raw mut w.1, + RvalueRefUnsafe::::bind(&raw mut __second), + ); &mut w }) .0 = 10_i64; diff --git a/tests/unit/out/unsafe/pair_converting_construction.rs b/tests/unit/out/unsafe/pair_converting_construction.rs index 9ae762d789..23f094176f 100644 --- a/tests/unit/out/unsafe/pair_converting_construction.rs +++ b/tests/unit/out/unsafe/pair_converting_construction.rs @@ -19,7 +19,7 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] pub struct Celsius { pub degrees: i32, } @@ -41,15 +41,13 @@ impl Celsius { ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, i32, const_lvalue_ref)] +#[conversion_function(to_i32, LvalueRefUnsafe>, i32 )] pub struct Meters { pub value: i32, } impl Meters { - pub unsafe fn conversion_function_1(this: LvalueRefUnsafe>, __return: *mut i32) { - let this = this.as_ptr() as *mut Meters; - __return.write((*this).value); - return; + pub unsafe fn to_i32(this: *const Self) -> i32 { + return (*this).value; } } #[repr(C)] @@ -65,7 +63,7 @@ impl Meters { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, const_lvalue_ref(Celsius))] +#[constructor(constructor_1, LvalueRefUnsafe>)] pub struct Label { pub id: i32, } @@ -88,8 +86,8 @@ impl Label { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, const_lvalue_ref(Celsius))] -#[constructor(constructor_2, rvalue_ref(Celsius))] +#[constructor(constructor_1, LvalueRefUnsafe>)] +#[constructor(constructor_2, RvalueRefUnsafe)] pub struct Owner { pub taken: i32, pub copied: i32, @@ -119,7 +117,7 @@ impl Owner { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(Celsius))] +#[constructor(constructor_1, Celsius)] pub struct Holder { pub value: i32, } @@ -139,7 +137,7 @@ impl Holder { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] pub struct Fallback { pub value: i32, } @@ -195,7 +193,7 @@ pub struct Counter { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, lvalue_ref(Counter))] +#[constructor(constructor_1, LvalueRefUnsafe)] pub struct Observer { pub seen: i32, } @@ -225,7 +223,7 @@ impl Tag { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1_1, const_lvalue_ref(Celsius))] +#[constructor(constructor_1_1, LvalueRefUnsafe>)] pub struct Tag { pub code: i32, } @@ -242,7 +240,7 @@ pub struct Tag { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(*const libc::c_char ))] +#[constructor(constructor_1, *const libc::c_char )] pub struct Name { pub len: i32, } @@ -280,22 +278,8 @@ unsafe fn main_0() -> i32 { assert!(((from_ints.1.degrees) == (2))); let mut m: Meters = Meters { value: 7 }; let mut from_operators: (i32, i64) = ( - { - let mut __v: i32 = ZeroInitializationUnsafe::zero_init(); - Meters::conversion_function_1( - >>::bind(&mut m), - &raw mut __v, - ); - __v - }, - ({ - let mut __v: i32 = ZeroInitializationUnsafe::zero_init(); - Meters::conversion_function_1( - >>::bind(&mut m), - &raw mut __v, - ); - __v - } as i64), + (unsafe { Meters::to_i32(&raw const m) }), + ((unsafe { Meters::to_i32(&raw const m) }) as i64), ); assert!(((from_operators.0) == (7))); assert!(((from_operators.1) == (7_i64))); diff --git a/tests/unit/out/unsafe/push_emplace_back.rs b/tests/unit/out/unsafe/push_emplace_back.rs index 896d485ce2..3c4e44ba37 100644 --- a/tests/unit/out/unsafe/push_emplace_back.rs +++ b/tests/unit/out/unsafe/push_emplace_back.rs @@ -53,7 +53,8 @@ pub struct Writer { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct JPEGData { pub com_data: Vec>, pub app_data: Vec>, @@ -140,9 +141,10 @@ pub unsafe fn self_ref_push_6(mut comps: *mut Vec) { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] -#[constructor(constructor_2, value(i32))] -#[constructor(constructor_3, value(i32), value(i32))] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, i32)] +#[constructor(constructor_3, i32, i32)] pub struct Pair { pub first: i32, pub second: i32, @@ -256,7 +258,8 @@ pub unsafe fn emplace_ref_self_read_13(values: *mut Vec) -> *mut i64 { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Bytes { pub v: Vec>, pub b: [u8; 3], @@ -323,7 +326,7 @@ pub static mut all_counted_16: std::cell::LazyCell<*mut Vec> = ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, explicit, value(i32))] +#[constructor(constructor_1, explicit, i32)] pub struct Counted { pub seen: usize, } diff --git a/tests/unit/out/unsafe/rule_of_five.rs b/tests/unit/out/unsafe/rule_of_five.rs index 22858790f7..5bd675699f 100644 --- a/tests/unit/out/unsafe/rule_of_five.rs +++ b/tests/unit/out/unsafe/rule_of_five.rs @@ -11,15 +11,22 @@ pub static mut copies_1: std::cell::LazyCell = std::cell::LazyCell::new(|| pub static mut moves_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultConstructibleUnsafe, SwappableUnsafe, + FnPtrArg, + ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, + SwappableUnsafe, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Buffer { pub data: [i32; 4], pub size: i32, } impl Buffer { - pub unsafe fn construct(this: *mut Self, mut size: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut size: i32) { (&raw mut (*this).data).write([0_i32; 4]); (&raw mut (*this).size).write(size); { @@ -33,14 +40,7 @@ impl Buffer { } (*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)).prefix_inc(); } -} -impl DestructibleUnsafe for Buffer { - unsafe fn destroy(this: *mut Self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)).prefix_dec(); - } -} -impl CopyConstructibleUnsafe for Buffer { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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); @@ -56,9 +56,7 @@ impl CopyConstructibleUnsafe for Buffer { (*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)).prefix_inc(); } -} -impl MoveConstructibleUnsafe for Buffer { - unsafe fn move_constructor(this: *mut Self, o: RvalueRefUnsafe) { + pub unsafe fn constructor_3(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); @@ -77,6 +75,11 @@ impl MoveConstructibleUnsafe for Buffer { (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_2)).prefix_inc(); } } +impl DestructibleUnsafe for Buffer { + unsafe fn destroy(this: *mut Self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)).prefix_dec(); + } +} impl CopyAssignableUnsafe for Buffer { unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut Buffer { let o = (o.as_ptr() as *const Buffer); @@ -120,8 +123,8 @@ impl MoveAssignableUnsafe for Buffer { } } pub unsafe fn make_3(__return: *mut Buffer, mut size: i32) { - object_unsafe!(b, Buffer(size)); - MoveConstructibleUnsafe::move_constructor(__return, RvalueRefUnsafe::bind(&mut b)); + object_unsafe!(b, Buffer::constructor_1(size)); + Buffer::constructor_3(__return, RvalueRefUnsafe::bind(&mut b)); return; } pub fn main() { @@ -132,8 +135,8 @@ pub fn main() { } unsafe fn main_0() -> i32 { { - object_unsafe!(a, Buffer(4)); - object_unsafe!(b, Buffer, LvalueRefUnsafe::bind(&a)); + object_unsafe!(a, Buffer::constructor_1(4)); + object_unsafe!(b, Buffer::constructor_2(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))) @@ -141,7 +144,7 @@ unsafe fn main_0() -> i32 { ); b.data[(0) as usize] = 100; assert!(((a.data[(0) as usize]) == (0))); - object_unsafe!(c, Buffer, RvalueRefUnsafe::bind(&mut a)); + object_unsafe!(c, Buffer::constructor_3(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)) diff --git a/tests/unit/out/unsafe/rule_of_three.rs b/tests/unit/out/unsafe/rule_of_three.rs index 2f80927abb..30e88cec89 100644 --- a/tests/unit/out/unsafe/rule_of_three.rs +++ b/tests/unit/out/unsafe/rule_of_three.rs @@ -12,19 +12,21 @@ pub static mut copies_1: std::cell::LazyCell = std::cell::LazyCell::new(|| #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, MoveConstructibleUnsafe, MoveAssignableUnsafe, SwappableUnsafe, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct Buffer { pub data: [i32; 4], pub size: i32, } impl Buffer { - pub unsafe fn construct(this: *mut Self, mut size: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut size: i32) { (&raw mut (*this).data).write([0_i32; 4]); (&raw mut (*this).size).write(size); { @@ -38,14 +40,7 @@ impl Buffer { } (*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)).prefix_inc(); } -} -impl DestructibleUnsafe for Buffer { - unsafe fn destroy(this: *mut Self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)).prefix_dec(); - } -} -impl CopyConstructibleUnsafe for Buffer { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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,6 +57,11 @@ impl CopyConstructibleUnsafe for Buffer { (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)).prefix_inc(); } } +impl DestructibleUnsafe for Buffer { + unsafe fn destroy(this: *mut Self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)).prefix_dec(); + } +} impl CopyAssignableUnsafe for Buffer { unsafe fn copy_assign(this: *mut Self, o: LvalueRefUnsafe>) -> *mut Buffer { let o = (o.as_ptr() as *const Buffer); @@ -103,15 +103,15 @@ pub fn main() { } unsafe fn main_0() -> i32 { { - object_unsafe!(a, Buffer(4)); - object_unsafe!(b, Buffer, LvalueRefUnsafe::bind(&a)); + object_unsafe!(a, Buffer::constructor_1(4)); + object_unsafe!(b, Buffer::constructor_2(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)) ); b.data[(0) as usize] = 100; assert!(((a.data[(0) as usize]) == (0))); - object_unsafe!(c, Buffer(2)); + object_unsafe!(c, Buffer::constructor_1(2)); assign_unsafe!(c = a); assert!(((c.size) == (4)) && ((c.data[(3) as usize]) == (3))); assert!( @@ -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, LvalueRefUnsafe::bind(&a)); + object_unsafe!(d, Buffer::constructor_2(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 26d09160bc..5432d79c1e 100644 --- a/tests/unit/out/unsafe/rvalue_rule_arg_move.rs +++ b/tests/unit/out/unsafe/rvalue_rule_arg_move.rs @@ -12,31 +12,30 @@ pub static mut moves_1: std::cell::LazyCell = std::cell::LazyCell::new(|| u #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, Default, )] #[memberwise(copy_assign, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Elem { pub v: i32, } impl Elem { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl CopyConstructibleUnsafe for Elem { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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: RvalueRefUnsafe) { + pub unsafe fn constructor_3(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(); @@ -54,8 +53,8 @@ unsafe fn main_0() -> i32 { let len_0 = v.len(); v.reserve_exact(4_usize - len_0 as usize); }; - object_unsafe!(a, Elem(1)); - object_unsafe!(b, Elem(2)); + object_unsafe!(a, Elem::constructor_1(1)); + object_unsafe!(b, Elem::constructor_1(2)); { let pos = >::from(v.end()) .iter_distance(&UnsafeRandomAccessIterator::Vec(v.as_mut_ptr())) diff --git a/tests/unit/out/unsafe/rvalue_struct.rs b/tests/unit/out/unsafe/rvalue_struct.rs index 52a9b282da..c786ba21a5 100644 --- a/tests/unit/out/unsafe/rvalue_struct.rs +++ b/tests/unit/out/unsafe/rvalue_struct.rs @@ -19,7 +19,7 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32), value(i32))] +#[constructor(constructor_1, i32, i32)] pub struct S { pub a: i32, pub b: i32, diff --git a/tests/unit/out/unsafe/self_referencing_initializer.rs b/tests/unit/out/unsafe/self_referencing_initializer.rs index 512a86dcf8..30d5c979ec 100644 --- a/tests/unit/out/unsafe/self_referencing_initializer.rs +++ b/tests/unit/out/unsafe/self_referencing_initializer.rs @@ -49,7 +49,8 @@ pub struct node { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct node_with_defaults { pub next: *mut node_with_defaults, pub value: i32, diff --git a/tests/unit/out/unsafe/size_t_ssize_t.rs b/tests/unit/out/unsafe/size_t_ssize_t.rs index 06ea16e38f..b9541e72a6 100644 --- a/tests/unit/out/unsafe/size_t_ssize_t.rs +++ b/tests/unit/out/unsafe/size_t_ssize_t.rs @@ -37,7 +37,14 @@ pub unsafe fn size_t_in_rules_3() { let mut __first = src.as_mut_ptr(); let mut __out = (dst.as_mut_ptr() as *mut usize).cast::(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &__tmp_0) { - *__out.iter_deref() = ((*__first.iter_deref()) as u64); + object_unsafe!(__value, u64, |__this| ConvertibleToUnsafe::convert( + LvalueRefUnsafe::::bind(__first.iter_deref()), + __this + )); + MoveAssignableUnsafe::move_assign( + __out.iter_deref(), + RvalueRefUnsafe::::bind(&raw mut __value), + ); __first.iter_inc(); __out.iter_inc(); } @@ -85,16 +92,72 @@ pub unsafe fn size_t_in_rules_3() { let mut p: (u64, u64) = ((1 as u64), (2 as u64)); assert!(((*p.get_mut::<0>()) == (1_u64))); let mut p2: (u64, u64) = match ((&mut (3, 4) as *mut (i32, i32)),) { - (__tmp_2,) => (((*&mut (*__tmp_2).0) as u64), ((*&mut (*__tmp_2).1) as u64)), + (__tmp_2,) => { + object_unsafe!(__first, u64, |__this| ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_2).0),) + )); + object_unsafe!(__second, u64, |__this| ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut (*__tmp_2).1),) + )); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) + } }; let mut pi: (i32, i32) = (5, 6); - let mut p3: (u64, u64) = (((*&pi.0) as u64), ((*&pi.1) as u64)); + let mut p3: (u64, u64) = { + object_unsafe!(__first, u64, |__this| ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::>::bind(&raw const pi.0),) + )); + object_unsafe!(__second, u64, |__this| ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::>::bind(&raw const pi.1),) + )); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) + }; { - p = (((*&pi.0) as u64), ((*&pi.1) as u64)); + object_unsafe!(__first, u64, |__this| ConvertibleToUnsafe::convert( + LvalueRefUnsafe::>::bind(&raw const pi.0), + __this + )); + object_unsafe!(__second, u64, |__this| ConvertibleToUnsafe::convert( + LvalueRefUnsafe::>::bind(&raw const pi.1), + __this + )); + MoveAssignableUnsafe::move_assign( + &raw mut p.0, + RvalueRefUnsafe::::bind(&raw mut __first), + ); + MoveAssignableUnsafe::move_assign( + &raw mut p.1, + RvalueRefUnsafe::::bind(&raw mut __second), + ); }; match ((&mut (7, 8) as *mut (i32, i32)),) { (__tmp_3,) => { - p = (((*&mut (*__tmp_3).0) as u64), ((*&mut (*__tmp_3).1) as u64)); + object_unsafe!(__first, u64, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut (*__tmp_3).0), + __this + )); + object_unsafe!(__second, u64, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut (*__tmp_3).1), + __this + )); + MoveAssignableUnsafe::move_assign( + &raw mut p.0, + RvalueRefUnsafe::::bind(&raw mut __first), + ); + MoveAssignableUnsafe::move_assign( + &raw mut p.1, + RvalueRefUnsafe::::bind(&raw mut __second), + ); } }; assert!((((p.0) == (7_u64)) && ((p2.1) == (4_u64))) && ((p3.0) == (5_u64))); @@ -139,10 +202,14 @@ pub unsafe fn size_t_in_rules_3() { }; let mut v2: Vec = { let mut __tmp_6 = { src.as_mut_ptr().offset((3) as isize) }; - let mut __v = Vec::new(); + let mut __v: Vec = Vec::new(); let mut __it = src.as_mut_ptr(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_6) { - __v.push(((*__it.iter_deref()) as u64)); + __v.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __v.as_mut_ptr().add(__v.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } __v diff --git a/tests/unit/out/unsafe/size_t_template_param.rs b/tests/unit/out/unsafe/size_t_template_param.rs index 71730c37e1..1db92808f6 100644 --- a/tests/unit/out/unsafe/size_t_template_param.rs +++ b/tests/unit/out/unsafe/size_t_template_param.rs @@ -23,7 +23,7 @@ pub unsafe fn array_ref_0(a: *mut [u64; 3]) -> u64 { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(*const u64 ))] +#[constructor(constructor_1, *const u64 )] pub struct PtrCtor_unsigned_long_ { pub v: u64, } @@ -45,7 +45,7 @@ impl PtrCtor_unsigned_long_ { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, const_lvalue_ref(u64))] +#[constructor(constructor_1, LvalueRefUnsafe>)] pub struct RefCtor_unsigned_long_ { pub v: u64, } diff --git a/tests/unit/out/unsafe/sort_no_copy.rs b/tests/unit/out/unsafe/sort_no_copy.rs index ceca9eba85..c58ce47980 100644 --- a/tests/unit/out/unsafe/sort_no_copy.rs +++ b/tests/unit/out/unsafe/sort_no_copy.rs @@ -9,31 +9,29 @@ use std::rc::Rc; pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, SwappableUnsafe, + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, ConversionsUnsafe, )] -#[cpp_from(i32, construct_1, value)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, i32)] +#[constructor(constructor_3, LvalueRefUnsafe>)] +#[constructor(constructor_4, RvalueRefUnsafe)] pub struct Tracked { pub v: i32, } impl Tracked { - pub unsafe fn construct_1(this: *mut Self, mut v: i32) { - (&raw mut (*this).v).write(v); - } -} -impl DefaultConstructibleUnsafe for Tracked { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write(0); } -} -impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); + } + pub unsafe fn constructor_3(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: RvalueRefUnsafe) { + pub unsafe fn constructor_4(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut Tracked); (&raw mut (*this).v).write((*o).v); } @@ -57,8 +55,8 @@ impl Default for Tracked { fn default() -> Self { unsafe { { - let mut __v: Tracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut __v); __v } } @@ -76,19 +74,20 @@ pub unsafe fn greater_1(a: *const Tracked, b: *const Tracked) -> bool { #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, SwappableUnsafe, Default, )] #[memberwise(move_constructor, move_assign)] -#[cpp_from(i32, construct, value)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1, i32)] pub struct MoveOnly { pub v: i32, } impl MoveOnly { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } } @@ -107,11 +106,14 @@ impl LessThanComparableUnsafe for MoveOnly { Default, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Bag { pub items: Vec, } -impl DefaultConstructibleUnsafe for Bag { - unsafe fn default_constructor(this: *mut Self) { +impl Bag { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).items).write(Vec::new()); } } @@ -129,28 +131,28 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut arr: [Tracked; 5] = [ { - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 3); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 3); __v }, { - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 1); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 1); __v }, { - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 4); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 4); __v }, { - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 1); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 1); __v }, { - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 5); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 5); __v }, ]; @@ -193,23 +195,23 @@ unsafe fn main_0() -> i32 { vec_.reserve_exact(4_usize - len_0 as usize); }; vec_.push_mut({ - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 2); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 2); __v }); vec_.push_mut({ - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 7); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 7); __v }); vec_.push_mut({ - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 1); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 1); __v }); vec_.push_mut({ - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 8); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 8); __v }); { @@ -340,23 +342,23 @@ unsafe fn main_0() -> i32 { ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); let mut bags: [Bag; 3] = std::array::from_fn::<_, 3, _>(|_| { - let mut __v: Bag = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Bag = ZeroInitializationUnsafe::zero_init(); + Bag::constructor_1(&raw mut __v); __v }); bags[(0) as usize].items.push_mut({ - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 1); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 1); __v }); bags[(0) as usize].items.push_mut({ - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 2); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 2); __v }); bags[(2) as usize].items.push_mut({ - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 3); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 3); __v }); { @@ -392,18 +394,18 @@ unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); let mut bag_vec: Vec = Vec::from_fn(3_usize, |_| ::default()); bag_vec[(1_usize)].items.push_mut({ - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 4); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 4); __v }); bag_vec[(1_usize)].items.push_mut({ - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 5); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 5); __v }); bag_vec[(2_usize)].items.push_mut({ - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 6); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 6); __v }); { @@ -515,18 +517,18 @@ unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); let mut moves: Vec = Vec::new(); moves.push_mut({ - let mut __v: MoveOnly = ::zero_init(); - MoveOnly::construct(&raw mut __v, 3); + let mut __v: MoveOnly = ZeroInitializationUnsafe::zero_init(); + MoveOnly::constructor_1(&raw mut __v, 3); __v }); moves.push_mut({ - let mut __v: MoveOnly = ::zero_init(); - MoveOnly::construct(&raw mut __v, 1); + let mut __v: MoveOnly = ZeroInitializationUnsafe::zero_init(); + MoveOnly::constructor_1(&raw mut __v, 1); __v }); moves.push_mut({ - let mut __v: MoveOnly = ::zero_init(); - MoveOnly::construct(&raw mut __v, 2); + let mut __v: MoveOnly = ZeroInitializationUnsafe::zero_init(); + MoveOnly::constructor_1(&raw mut __v, 2); __v }); { diff --git a/tests/unit/out/unsafe/stdcopy.rs b/tests/unit/out/unsafe/stdcopy.rs index 9723eaa99b..7ca1020bed 100644 --- a/tests/unit/out/unsafe/stdcopy.rs +++ b/tests/unit/out/unsafe/stdcopy.rs @@ -19,7 +19,7 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] pub struct Degrees { pub value: i32, } diff --git a/tests/unit/out/unsafe/struct_ctor.rs b/tests/unit/out/unsafe/struct_ctor.rs index 52c568141c..0cf44f6ffe 100644 --- a/tests/unit/out/unsafe/struct_ctor.rs +++ b/tests/unit/out/unsafe/struct_ctor.rs @@ -19,7 +19,7 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32), value(i32))] +#[constructor(constructor_1, i32, i32)] pub struct StructWithCtor { x1_: i32, x2_: i32, @@ -54,7 +54,7 @@ pub unsafe fn foo_0(x: *mut i32) -> *mut i32 { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] pub struct Value_ { pub v: i32, } @@ -73,7 +73,8 @@ impl Value_ { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Ptr_ { pub v1: Value_, pub v2: Value_, diff --git a/tests/unit/out/unsafe/struct_default_ctor.rs b/tests/unit/out/unsafe/struct_default_ctor.rs index c9a0c093e4..d6b88c62e6 100644 --- a/tests/unit/out/unsafe/struct_default_ctor.rs +++ b/tests/unit/out/unsafe/struct_default_ctor.rs @@ -16,7 +16,8 @@ use std::rc::Rc; TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct S { pub a: i32, pub b: bool, @@ -65,7 +66,8 @@ impl Declared {} Default, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Holder { pub items: [S; 2], } @@ -89,7 +91,8 @@ pub static mut kInit_0: std::cell::LazyCell = std::cell::LazyCell::new(|| u TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct FromStatic { pub v: i32, } diff --git a/tests/unit/out/unsafe/structured_binding_copy_ctor.rs b/tests/unit/out/unsafe/structured_binding_copy_ctor.rs index e56c7afd7e..afb7188eb3 100644 --- a/tests/unit/out/unsafe/structured_binding_copy_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_copy_ctor.rs @@ -19,18 +19,20 @@ pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| Default, )] #[memberwise(copy_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy)] +#[constructor(constructor_1, i32, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct Counted { pub x: i32, pub y: i32, } impl Counted { - pub unsafe fn construct(this: *mut Self, mut x: i32, mut y: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut x: i32, mut y: i32) { (&raw mut (*this).x).write(x); (&raw mut (*this).y).write(y); } -} -impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(this: *mut Self, other: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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))); @@ -38,7 +40,7 @@ impl CopyConstructibleUnsafe for Counted { } } pub unsafe fn make_counted_1(__return: *mut Counted) { - Counted::construct(__return, 5, 6); + Counted::constructor_1(__return, 5, 6); return; } pub fn main() { @@ -48,10 +50,10 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(s, Counted(1, 2)); + object_unsafe!(s, Counted::constructor_1(1, 2)); let mut __decomp_2: Counted = { - let mut __v: Counted = ::zero_init(); - CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(&s)); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); + Counted::constructor_2(&raw mut __v, LvalueRefUnsafe::bind(&s)); __v }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (1))); @@ -65,7 +67,7 @@ unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (1))); assert!((((*__decomp_4).x) == (1))); let mut __decomp_5: Counted = { - let mut __v: Counted = ::zero_init(); + let mut __v: Counted = ZeroInitializationUnsafe::zero_init(); (unsafe { make_counted_1(&raw mut __v) }); __v }; diff --git a/tests/unit/out/unsafe/structured_binding_element_ctor.rs b/tests/unit/out/unsafe/structured_binding_element_ctor.rs index 5a8348d585..9c88a0824e 100644 --- a/tests/unit/out/unsafe/structured_binding_element_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_element_ctor.rs @@ -10,26 +10,25 @@ pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| pub static mut moves_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultInitializableUnsafe, Default, + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Elem { pub v: i32, } impl Elem { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl CopyConstructibleUnsafe for Elem { - unsafe fn copy_constructor(this: *mut Self, other: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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: RvalueRefUnsafe) { + pub unsafe fn constructor_3(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; @@ -41,20 +40,23 @@ impl MoveConstructibleUnsafe for Elem { FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, MemberwiseUnsafe, Default, )] #[memberwise(copy_constructor, move_constructor)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct Two { pub a: Elem, pub b: Elem, } +impl Two {} pub unsafe fn make_two_2(__return: *mut Two) { __return.write(Two { a: { - let mut __v: Elem = ::zero_init(); - Elem::construct(&raw mut __v, 1); + let mut __v: Elem = ZeroInitializationUnsafe::zero_init(); + Elem::constructor_1(&raw mut __v, 1); __v }, b: { - let mut __v: Elem = ::zero_init(); - Elem::construct(&raw mut __v, 2); + let mut __v: Elem = ZeroInitializationUnsafe::zero_init(); + Elem::constructor_1(&raw mut __v, 2); __v }, }); @@ -69,21 +71,21 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut t: Two = Two { a: { - let mut __v: Elem = ::zero_init(); - Elem::construct(&raw mut __v, 1); + let mut __v: Elem = ZeroInitializationUnsafe::zero_init(); + Elem::constructor_1(&raw mut __v, 1); __v }, b: { - let mut __v: Elem = ::zero_init(); - Elem::construct(&raw mut __v, 2); + let mut __v: Elem = ZeroInitializationUnsafe::zero_init(); + Elem::constructor_1(&raw mut __v, 2); __v }, }; let mut base_copies: i32 = (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)); 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(); - CopyConstructibleUnsafe::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(&t)); + let mut __v: Two = ZeroInitializationUnsafe::zero_init(); + ::copy_constructor(&raw mut __v, LvalueRefUnsafe::bind(&t)); __v }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == ((base_copies) + (2)))); @@ -96,8 +98,11 @@ unsafe fn main_0() -> i32 { (*__decomp_4).a.v = 50; assert!(((t.a.v) == (50))); let mut __decomp_5: Two = { - let mut __v: Two = ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&raw mut __v, RvalueRefUnsafe::bind(&mut t)); + let mut __v: Two = ZeroInitializationUnsafe::zero_init(); + ::move_constructor( + &raw mut __v, + RvalueRefUnsafe::bind(&mut t), + ); __v }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == ((base_moves) + (2)))); @@ -107,7 +112,7 @@ unsafe fn main_0() -> i32 { let mut before_copies: i32 = (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)); let mut before_moves: i32 = (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)); let mut __decomp_6: Two = { - let mut __v: Two = ::zero_init(); + let mut __v: Two = ZeroInitializationUnsafe::zero_init(); (unsafe { make_two_2(&raw mut __v) }); __v }; @@ -116,26 +121,20 @@ unsafe fn main_0() -> i32 { assert!(((__decomp_6.a.v) == (1))); let mut p: (Elem, Elem) = ( { - let mut __tmp_0: Elem = ::zero_init(); - Elem::construct(&raw mut __tmp_0, 7); + let mut __tmp_0: Elem = ZeroInitializationUnsafe::zero_init(); + Elem::constructor_1(&raw mut __tmp_0, 7); { - let mut __v: Elem = ::zero_init(); - MoveConstructibleUnsafe::move_constructor( - &raw mut __v, - RvalueRefUnsafe::bind(&mut __tmp_0), - ); + let mut __v: Elem = ZeroInitializationUnsafe::zero_init(); + Elem::constructor_3(&raw mut __v, RvalueRefUnsafe::bind(&mut __tmp_0)); __v } }, { - let mut __tmp_1: Elem = ::zero_init(); - Elem::construct(&raw mut __tmp_1, 8); + let mut __tmp_1: Elem = ZeroInitializationUnsafe::zero_init(); + Elem::constructor_1(&raw mut __tmp_1, 8); { - let mut __v: Elem = ::zero_init(); - MoveConstructibleUnsafe::move_constructor( - &raw mut __v, - RvalueRefUnsafe::bind(&mut __tmp_1), - ); + let mut __v: Elem = ZeroInitializationUnsafe::zero_init(); + Elem::constructor_3(&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 1d18fde0d8..5a2cc0cf9f 100644 --- a/tests/unit/out/unsafe/structured_binding_move_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_move_ctor.rs @@ -9,27 +9,29 @@ use std::rc::Rc; pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut moves_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default)] +#[derive( + FnPtrArg, ZeroInitializationUnsafe, DefaultInitializableUnsafe, Default, ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Movable { pub x: i32, pub y: i32, } impl Movable { - pub unsafe fn construct(this: *mut Self, mut x: i32, mut y: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut x: i32, mut y: i32) { (&raw mut (*this).x).write(x); (&raw mut (*this).y).write(y); } -} -impl CopyConstructibleUnsafe for Movable { - unsafe fn copy_constructor(this: *mut Self, other: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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: RvalueRefUnsafe) { + pub unsafe fn constructor_3(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); @@ -51,6 +53,9 @@ impl MoveConstructibleUnsafe for Movable { Default, )] #[memberwise(move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Holder { pub xs: Vec, pub ys: Vec, @@ -63,9 +68,7 @@ impl Holder { }); return; } -} -impl DefaultConstructibleUnsafe for Holder { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).xs).write(Vec::new()); (&raw mut (*this).ys).write(Vec::new()); } @@ -77,10 +80,10 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(m, Movable(3, 4)); + object_unsafe!(m, Movable::constructor_1(3, 4)); let mut __decomp_2: Movable = { - let mut __v: Movable = ::zero_init(); - MoveConstructibleUnsafe::move_constructor(&raw mut __v, RvalueRefUnsafe::bind(&mut m)); + let mut __v: Movable = ZeroInitializationUnsafe::zero_init(); + Movable::constructor_3(&raw mut __v, RvalueRefUnsafe::bind(&mut m)); __v }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)) == (1))); @@ -94,7 +97,7 @@ unsafe fn main_0() -> i32 { ys: Vec::from([4, 5]), }; let mut __decomp_3: Holder = { - let mut __v: Holder = ::zero_init(); + let mut __v: Holder = ZeroInitializationUnsafe::zero_init(); (unsafe { Holder::extract(&raw mut h, &raw mut __v) }); __v }; diff --git a/tests/unit/out/unsafe/swap_map_no_copy.rs b/tests/unit/out/unsafe/swap_map_no_copy.rs index d802de8c86..37acfaaf99 100644 --- a/tests/unit/out/unsafe/swap_map_no_copy.rs +++ b/tests/unit/out/unsafe/swap_map_no_copy.rs @@ -9,31 +9,29 @@ use std::rc::Rc; pub static mut copies_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DestructibleUnsafe, SwappableUnsafe, + FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, SwappableUnsafe, ConversionsUnsafe, )] -#[cpp_from(i32, construct_1, value)] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, i32)] +#[constructor(constructor_3, LvalueRefUnsafe>)] +#[constructor(constructor_4, RvalueRefUnsafe)] pub struct Tracked { pub v: i32, } impl Tracked { - pub unsafe fn construct_1(this: *mut Self, mut v: i32) { - (&raw mut (*this).v).write(v); - } -} -impl DefaultConstructibleUnsafe for Tracked { - unsafe fn default_constructor(this: *mut Self) { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).v).write(0); } -} -impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); + } + pub unsafe fn constructor_3(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: RvalueRefUnsafe) { + pub unsafe fn constructor_4(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut Tracked); (&raw mut (*this).v).write((*o).v); } @@ -57,8 +55,8 @@ impl Default for Tracked { fn default() -> Self { unsafe { { - let mut __v: Tracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut __v); __v } } @@ -74,14 +72,17 @@ impl Default for Tracked { Default, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Pair { pub x: Tracked, pub y: Tracked, } -impl DefaultConstructibleUnsafe for Pair { - unsafe fn default_constructor(this: *mut Self) { - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).x); - DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).y); +impl Pair { + pub unsafe fn constructor_1(this: *mut Self) { + Tracked::constructor_1(&raw mut (*this).x); + Tracked::constructor_1(&raw mut (*this).y); } } #[repr(C)] @@ -94,20 +95,23 @@ impl DefaultConstructibleUnsafe for Pair { Default, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Arrays { pub a: [Tracked; 2], pub b: [Tracked; 2], } -impl DefaultConstructibleUnsafe for Arrays { - unsafe fn default_constructor(this: *mut Self) { +impl Arrays { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).a).write(std::array::from_fn::<_, 2, _>(|_| { - let mut __v: Tracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut __v); __v })); (&raw mut (*this).b).write(std::array::from_fn::<_, 2, _>(|_| { - let mut __v: Tracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&raw mut __v); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_1(&raw mut __v); __v })); } @@ -120,23 +124,23 @@ pub static mut copy_only_dtors_2: std::cell::LazyCell = #[derive( FnPtrArg, ZeroInitializationUnsafe, - CppFromUnsafe, DefaultConstructibleUnsafe, MoveConstructibleUnsafe, MoveAssignableUnsafe, SwappableUnsafe, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] pub struct CopyOnly { pub v: i32, } impl CopyOnly { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl CopyConstructibleUnsafe for CopyOnly { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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(); @@ -164,37 +168,43 @@ impl CopyAssignableUnsafe for CopyOnly { SwappableUnsafe, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct CopyOnlyPair { #[destroy] pub x: CopyOnly, #[destroy] pub y: CopyOnly, } +impl CopyOnlyPair {} pub static mut moves_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut move_assigns_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut moved_dtors_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, CppFromUnsafe, DefaultConstructibleUnsafe, SwappableUnsafe, + FnPtrArg, + ZeroInitializationUnsafe, + DefaultConstructibleUnsafe, + SwappableUnsafe, + ConversionsUnsafe, )] -#[cpp_from(i32, construct, value)] +#[conversions(copy, move)] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, LvalueRefUnsafe>)] +#[constructor(constructor_3, RvalueRefUnsafe)] pub struct Moved { pub v: i32, } impl Moved { - pub unsafe fn construct(this: *mut Self, mut v: i32) { + pub unsafe fn constructor_1(this: *mut Self, mut v: i32) { (&raw mut (*this).v).write(v); } -} -impl CopyConstructibleUnsafe for Moved { - unsafe fn copy_constructor(this: *mut Self, o: LvalueRefUnsafe>) { + pub unsafe fn constructor_2(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: RvalueRefUnsafe) { + pub unsafe fn constructor_3(this: *mut Self, o: RvalueRefUnsafe) { let o = (o.as_ptr() as *mut Moved); (&raw mut (*this).v).write((*o).v); (*o).v = -1_i32; @@ -232,12 +242,15 @@ impl DestructibleUnsafe for Moved { SwappableUnsafe, )] #[memberwise(copy_constructor, move_constructor, copy_assign, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(copy, move)] pub struct MovedPair { #[destroy] pub x: Moved, #[destroy] pub y: Moved, } +impl MovedPair {} pub unsafe fn swapped_once_6() -> bool { let mut ok: bool = (((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)) == (1)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut move_assigns_4)) == (2))) @@ -261,11 +274,14 @@ pub unsafe fn swapped_once_6() -> bool { Default, )] #[memberwise(move_constructor, move_assign)] +#[derive(ConversionsUnsafe)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct Owner { pub p: Option>, } -impl DefaultConstructibleUnsafe for Owner { - unsafe fn default_constructor(this: *mut Self) { +impl Owner { + pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).p).write(None); } } @@ -276,8 +292,8 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - object_unsafe!(a, Tracked::construct_1(1)); - object_unsafe!(b, Tracked::construct_1(2)); + object_unsafe!(a, Tracked::constructor_2(1)); + object_unsafe!(b, Tracked::constructor_2(2)); { let __a: *mut _ = &mut a; let __b: *mut _ = &mut b; @@ -289,8 +305,8 @@ unsafe fn main_0() -> i32 { { let mut __tmp_0: i32; (unsafe { - let mut _o: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut _o, 10); + let mut _o: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut _o, 10); assign_unsafe!( (*{ __tmp_0 = 1; @@ -306,8 +322,8 @@ unsafe fn main_0() -> i32 { { let mut __tmp_1: i32; (unsafe { - let mut _o: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut _o, 20); + let mut _o: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut _o, 20); assign_unsafe!( (*{ __tmp_1 = 2; @@ -324,8 +340,8 @@ unsafe fn main_0() -> i32 { { let mut __tmp_2: i32; (unsafe { - let mut _o: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut _o, 30); + let mut _o: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut _o, 30); assign_unsafe!( (*{ __tmp_2 = 3; @@ -438,18 +454,18 @@ unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); let mut arr: [Tracked; 3] = [ { - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 1); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 1); __v }, { - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 2); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 2); __v }, { - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 3); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 3); __v }, ]; @@ -468,13 +484,13 @@ unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); let mut vec_: Vec = Vec::new(); vec_.push_mut({ - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 4); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 4); __v }); vec_.push_mut({ - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 5); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 5); __v }); { @@ -487,38 +503,38 @@ unsafe fn main_0() -> i32 { let mut pairs: [Pair; 2] = [ Pair { x: { - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 6); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 6); __v }, y: { - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 7); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 7); __v }, }, Pair { x: { - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 8); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 8); __v }, y: { - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 9); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 9); __v }, }, ]; let mut p: Pair = Pair { x: { - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 10); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 10); __v }, y: { - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 11); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 11); __v }, }; @@ -548,7 +564,7 @@ unsafe fn main_0() -> i32 { }; assert!(((pairs[(0) as usize].x.v) == (7)) && ((pairs[(1) as usize].y.v) == (8))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); - object_unsafe!(arrays, Arrays); + object_unsafe!(arrays, Arrays::constructor_1()); arrays.a[(0) as usize].v = 1; arrays.b[(1) as usize].v = 2; { @@ -566,18 +582,18 @@ unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); let mut grid: Vec> = Vec::from_fn(2_usize, |_| Default::default()); grid[(0_usize)].push_mut({ - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 1); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 1); __v }); grid[(0_usize)].push_mut({ - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 2); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 2); __v }); grid[(1_usize)].push_mut({ - let mut __v: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut __v, 3); + let mut __v: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut __v, 3); __v }); { @@ -598,8 +614,8 @@ unsafe fn main_0() -> i32 { { let mut __tmp_10: i32; (unsafe { - let mut _o: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut _o, 1); + let mut _o: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut _o, 1); assign_unsafe!( (*{ __tmp_10 = 1; @@ -615,8 +631,8 @@ unsafe fn main_0() -> i32 { { let mut __tmp_11: i32; (unsafe { - let mut _o: Tracked = ::zero_init(); - Tracked::construct_1(&raw mut _o, 2); + let mut _o: Tracked = ZeroInitializationUnsafe::zero_init(); + Tracked::constructor_2(&raw mut _o, 2); assign_unsafe!( (*{ __tmp_11 = 2; @@ -665,8 +681,8 @@ unsafe fn main_0() -> i32 { }) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); - object_unsafe!(c1, CopyOnly(1)); - object_unsafe!(c2, CopyOnly(2)); + object_unsafe!(c1, CopyOnly::constructor_1(1)); + object_unsafe!(c2, CopyOnly::constructor_1(2)); { let __a: *mut _ = &mut c1; let __b: *mut _ = &mut c2; @@ -679,13 +695,13 @@ unsafe fn main_0() -> i32 { ); let mut cp: CopyOnlyPair = CopyOnlyPair { x: { - let mut __v: CopyOnly = ::zero_init(); - CopyOnly::construct(&raw mut __v, 3); + let mut __v: CopyOnly = ZeroInitializationUnsafe::zero_init(); + CopyOnly::constructor_1(&raw mut __v, 3); __v }, y: { - let mut __v: CopyOnly = ::zero_init(); - CopyOnly::construct(&raw mut __v, 4); + let mut __v: CopyOnly = ZeroInitializationUnsafe::zero_init(); + CopyOnly::constructor_1(&raw mut __v, 4); __v }, }; @@ -704,13 +720,13 @@ unsafe fn main_0() -> i32 { ); let mut carr: [CopyOnly; 2] = [ { - let mut __v: CopyOnly = ::zero_init(); - CopyOnly::construct(&raw mut __v, 5); + let mut __v: CopyOnly = ZeroInitializationUnsafe::zero_init(); + CopyOnly::constructor_1(&raw mut __v, 5); __v }, { - let mut __v: CopyOnly = ::zero_init(); - CopyOnly::construct(&raw mut __v, 6); + let mut __v: CopyOnly = ZeroInitializationUnsafe::zero_init(); + CopyOnly::constructor_1(&raw mut __v, 6); __v }, ]; @@ -724,8 +740,8 @@ unsafe fn main_0() -> i32 { ((*std::cell::LazyCell::force_mut(&mut *&raw mut copy_only_copies_1)) == (9)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copy_only_dtors_2)) == (3)) ); - object_unsafe!(mv1, Moved(1)); - object_unsafe!(mv2, Moved(2)); + object_unsafe!(mv1, Moved::constructor_1(1)); + object_unsafe!(mv2, Moved::constructor_1(2)); { let __a: *mut _ = &mut mv1; let __b: *mut _ = &mut mv2; @@ -735,13 +751,13 @@ unsafe fn main_0() -> i32 { assert!((unsafe { swapped_once_6() })); let mut mp: MovedPair = MovedPair { x: { - let mut __v: Moved = ::zero_init(); - Moved::construct(&raw mut __v, 3); + let mut __v: Moved = ZeroInitializationUnsafe::zero_init(); + Moved::constructor_1(&raw mut __v, 3); __v }, y: { - let mut __v: Moved = ::zero_init(); - Moved::construct(&raw mut __v, 4); + let mut __v: Moved = ZeroInitializationUnsafe::zero_init(); + Moved::constructor_1(&raw mut __v, 4); __v }, }; @@ -757,13 +773,13 @@ unsafe fn main_0() -> i32 { assert!((unsafe { swapped_once_6() })); let mut marr: [Moved; 2] = [ { - let mut __v: Moved = ::zero_init(); - Moved::construct(&raw mut __v, 5); + let mut __v: Moved = ZeroInitializationUnsafe::zero_init(); + Moved::constructor_1(&raw mut __v, 5); __v }, { - let mut __v: Moved = ::zero_init(); - Moved::construct(&raw mut __v, 6); + let mut __v: Moved = ZeroInitializationUnsafe::zero_init(); + Moved::constructor_1(&raw mut __v, 6); __v }, ]; diff --git a/tests/unit/out/unsafe/template_default_arg.rs b/tests/unit/out/unsafe/template_default_arg.rs index b24efdfa18..592373cf79 100644 --- a/tests/unit/out/unsafe/template_default_arg.rs +++ b/tests/unit/out/unsafe/template_default_arg.rs @@ -16,8 +16,9 @@ use std::rc::Rc; TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] -#[constructor(constructor_2, value(i32))] +#[conversions(copy, move)] +#[constructor(constructor_1)] +#[constructor(constructor_2, i32)] pub struct A { pub v: i32, } @@ -50,7 +51,8 @@ impl Default for A { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct B { pub v: i32, } @@ -83,7 +85,7 @@ impl Default for B { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] pub struct NoDefault { pub v: i32, } @@ -117,7 +119,7 @@ pub unsafe fn always_given_3(mut x: NoDefault) -> i32 { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] pub struct S_NoDefault_ { pub v: i32, } diff --git a/tests/unit/out/unsafe/temporary_field_addr.rs b/tests/unit/out/unsafe/temporary_field_addr.rs index 9ea03b1968..b8206f7d9c 100644 --- a/tests/unit/out/unsafe/temporary_field_addr.rs +++ b/tests/unit/out/unsafe/temporary_field_addr.rs @@ -20,7 +20,8 @@ use std::rc::Rc; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Inner { pub values: Vec, } @@ -43,7 +44,8 @@ impl Inner { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Outer { pub values: Vec, pub inner: Inner, diff --git a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs index d7bc0d8e45..ca5082b431 100644 --- a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs +++ b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs @@ -20,7 +20,8 @@ use std::rc::Rc; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Outer { pub values: Vec, } diff --git a/tests/unit/out/unsafe/temporary_field_two_args.rs b/tests/unit/out/unsafe/temporary_field_two_args.rs index 2a5875bac5..f23edc40f5 100644 --- a/tests/unit/out/unsafe/temporary_field_two_args.rs +++ b/tests/unit/out/unsafe/temporary_field_two_args.rs @@ -20,7 +20,8 @@ use std::rc::Rc; )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Inner { pub values: Vec, } @@ -43,7 +44,8 @@ impl Inner { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Outer { pub values: Vec, pub inner: Inner, diff --git a/tests/unit/out/unsafe/this.rs b/tests/unit/out/unsafe/this.rs index c5710b875f..e97072212c 100644 --- a/tests/unit/out/unsafe/this.rs +++ b/tests/unit/out/unsafe/this.rs @@ -19,9 +19,9 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] -#[constructor(constructor_2, value(i32 ), value(*mut S ))] -#[constructor(constructor_3, value(i32 ), value(*const S ))] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, i32 , *mut S )] +#[constructor(constructor_3, i32 , *const S )] pub struct S { pub a_: i32, pub self__: *mut S, @@ -126,7 +126,7 @@ pub unsafe fn bump_0(mut p: *mut S) { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] pub struct D { pub a_: i32, } diff --git a/tests/unit/out/unsafe/typedef-anon-struct.rs b/tests/unit/out/unsafe/typedef-anon-struct.rs index f4ae0b3e9f..111a77f22b 100644 --- a/tests/unit/out/unsafe/typedef-anon-struct.rs +++ b/tests/unit/out/unsafe/typedef-anon-struct.rs @@ -37,7 +37,8 @@ pub struct Outer_RunInfo { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Outer { pub runs: Vec, } diff --git a/tests/unit/out/unsafe/unboxed_locals.rs b/tests/unit/out/unsafe/unboxed_locals.rs index ec913013c6..748a99e85b 100644 --- a/tests/unit/out/unsafe/unboxed_locals.rs +++ b/tests/unit/out/unsafe/unboxed_locals.rs @@ -22,7 +22,9 @@ pub unsafe fn inc_1(r: *mut i32) { TriviallyDefaultConstructibleUnsafe, TriviallyCopyableUnsafe, Default, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Pair { pub first: i32, pub second: i32, @@ -68,7 +70,9 @@ pub unsafe trait Shape { ZeroInitializationUnsafe, DefaultInitializableUnsafe, CopyableUnsafe, + ConversionsUnsafe, )] +#[conversions(copy, move)] pub struct Square { pub side: i32, } diff --git a/tests/unit/out/unsafe/unboxed_records.rs b/tests/unit/out/unsafe/unboxed_records.rs index 2335611c29..ad4045ab72 100644 --- a/tests/unit/out/unsafe/unboxed_records.rs +++ b/tests/unit/out/unsafe/unboxed_records.rs @@ -53,7 +53,8 @@ pub struct Cookie { TriviallyCopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Counter { pub n: i32, } diff --git a/tests/unit/out/unsafe/unique_ptr.rs b/tests/unit/out/unsafe/unique_ptr.rs index b0d2f67695..45b54ebaa8 100644 --- a/tests/unit/out/unsafe/unique_ptr.rs +++ b/tests/unit/out/unsafe/unique_ptr.rs @@ -17,7 +17,8 @@ use std::rc::Rc; )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(move, default = constructor_1)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct SafePointer { pub ptr: Option>, } diff --git a/tests/unit/out/unsafe/unique_ptr_const_deref.rs b/tests/unit/out/unsafe/unique_ptr_const_deref.rs index aafb44bece..f8dd9749e8 100644 --- a/tests/unit/out/unsafe/unique_ptr_const_deref.rs +++ b/tests/unit/out/unsafe/unique_ptr_const_deref.rs @@ -17,7 +17,8 @@ use std::rc::Rc; )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(move, default = constructor_1)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct Holder { pub val: Option>, } diff --git a/tests/unit/out/unsafe/unique_ptr_field_reset.rs b/tests/unit/out/unsafe/unique_ptr_field_reset.rs index a8a31965cb..794691a49b 100644 --- a/tests/unit/out/unsafe/unique_ptr_field_reset.rs +++ b/tests/unit/out/unsafe/unique_ptr_field_reset.rs @@ -33,7 +33,8 @@ pub struct Data { )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(move, default = constructor_1)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct Holder { pub data: Option>, pub n: i32, diff --git a/tests/unit/out/unsafe/unique_ptr_nested.rs b/tests/unit/out/unsafe/unique_ptr_nested.rs index 3f7f46f0ca..a0dddc0a8d 100644 --- a/tests/unit/out/unsafe/unique_ptr_nested.rs +++ b/tests/unit/out/unsafe/unique_ptr_nested.rs @@ -34,7 +34,8 @@ pub struct Inner { )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(move, default = constructor_1)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct Outer { pub inner: Option>, } diff --git a/tests/unit/out/unsafe/va_list_field.rs b/tests/unit/out/unsafe/va_list_field.rs index 6970149a14..7011b782b9 100644 --- a/tests/unit/out/unsafe/va_list_field.rs +++ b/tests/unit/out/unsafe/va_list_field.rs @@ -32,7 +32,7 @@ pub unsafe fn sum_0(mut n: i32, __args: Box<[VaArg]>) -> i32 { CopyableUnsafe, ConversionsUnsafe, )] -#[conversions(copy, move)] +#[conversions(copy)] pub struct Guard_1 { pub ap: *mut *const VaArg, pub active: bool, diff --git a/tests/unit/out/unsafe/vector.rs b/tests/unit/out/unsafe/vector.rs index 35531f8be8..44560dac26 100644 --- a/tests/unit/out/unsafe/vector.rs +++ b/tests/unit/out/unsafe/vector.rs @@ -37,7 +37,8 @@ pub unsafe fn copy_0(mut copy_vector: Vec) {} )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Foo { pub a: Vec, pub b: Vec, @@ -61,7 +62,7 @@ impl Foo { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] pub struct Wrapped { pub v: i32, } diff --git a/tests/unit/out/unsafe/vector_insert_conversion_chain.rs b/tests/unit/out/unsafe/vector_insert_conversion_chain.rs index ae7f394c18..efd0e3677c 100644 --- a/tests/unit/out/unsafe/vector_insert_conversion_chain.rs +++ b/tests/unit/out/unsafe/vector_insert_conversion_chain.rs @@ -19,15 +19,13 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, i32, const_lvalue_ref)] +#[conversion_function(to_i32, LvalueRefUnsafe>, i32 )] pub struct Ratio { pub num: i32, } impl Ratio { - pub unsafe fn conversion_function_1(this: LvalueRefUnsafe>, __return: *mut i32) { - let this = this.as_ptr() as *mut Ratio; - __return.write((*this).num); - return; + pub unsafe fn to_i32(this: *const Self) -> i32 { + return (*this).num; } } #[repr(C)] @@ -43,21 +41,17 @@ impl Ratio { ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, i16, const_lvalue_ref)] -#[conversion_function(conversion_function_2, i64, const_lvalue_ref)] +#[conversion_function(to_i16, LvalueRefUnsafe>, i16 )] +#[conversion_function(to_i64, LvalueRefUnsafe>, i64 )] pub struct Level { pub raw_: i32, } impl Level { - pub unsafe fn conversion_function_1(this: LvalueRefUnsafe>, __return: *mut i16) { - let this = this.as_ptr() as *mut Level; - __return.write(((*this).raw_ as i16)); - return; + pub unsafe fn to_i16(this: *const Self) -> i16 { + return ((*this).raw_ as i16); } - pub unsafe fn conversion_function_2(this: LvalueRefUnsafe>, __return: *mut i64) { - let this = this.as_ptr() as *mut Level; - __return.write((((*this).raw_ as i64) * (100_i64))); - return; + pub unsafe fn to_i64(this: *const Self) -> i64 { + return (((*this).raw_ as i64) * (100_i64)); } } pub fn main() { diff --git a/tests/unit/out/unsafe/vector_iter_range_ctor.rs b/tests/unit/out/unsafe/vector_iter_range_ctor.rs index 6dbebfec01..202b307dc7 100644 --- a/tests/unit/out/unsafe/vector_iter_range_ctor.rs +++ b/tests/unit/out/unsafe/vector_iter_range_ctor.rs @@ -19,7 +19,7 @@ use std::rc::Rc; ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] pub struct Degrees { pub value: i32, } @@ -41,15 +41,13 @@ impl Degrees { ConversionsUnsafe, )] #[conversions(copy, move)] -#[conversion_function(conversion_function_1, i64, const_lvalue_ref)] +#[conversion_function(to_i64, LvalueRefUnsafe>, i64 )] pub struct Reading { pub raw_: i32, } impl Reading { - pub unsafe fn conversion_function_1(this: LvalueRefUnsafe>, __return: *mut i64) { - let this = this.as_ptr() as *mut Reading; - __return.write((((*this).raw_ as i64) * (10_i64))); - return; + pub unsafe fn to_i64(this: *const Self) -> i64 { + return (((*this).raw_ as i64) * (10_i64)); } } pub fn main() { diff --git a/tests/unit/out/unsafe/vector_subscript_direct.rs b/tests/unit/out/unsafe/vector_subscript_direct.rs index 955c2e8dfb..05d58cc823 100644 --- a/tests/unit/out/unsafe/vector_subscript_direct.rs +++ b/tests/unit/out/unsafe/vector_subscript_direct.rs @@ -42,7 +42,8 @@ impl Point { )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct Holder { pub values: Vec, pub points: Vec, diff --git a/tests/unit/out/unsafe/void_cast.rs b/tests/unit/out/unsafe/void_cast.rs index fa76775729..73b2c93ee8 100644 --- a/tests/unit/out/unsafe/void_cast.rs +++ b/tests/unit/out/unsafe/void_cast.rs @@ -21,7 +21,8 @@ pub unsafe fn unused_param_0(mut x: i32) {} )] #[memberwise(move_constructor, copy_assign, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(copy, move, default = constructor_1)] +#[conversions(copy, move)] +#[constructor(constructor_1)] pub struct NonTrivial { pub data: Vec, } @@ -65,7 +66,8 @@ pub struct Holder { )] #[memberwise(move_constructor, move_assign)] #[derive(ConversionsUnsafe)] -#[conversions(move, default = constructor_1)] +#[conversions(move)] +#[constructor(constructor_1)] pub struct NonCopyable { pub value: Option>, } From fa8ef8280c033cf13fcd5770f3280b465b4efacf Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 4 Dec 2026 12:57:21 +0000 Subject: [PATCH 28/35] Fix --- cpp2rust/converter/converter.cpp | 7 +++++- cpp2rust/converter/converter_lib.cpp | 4 +-- libcc2rs/src/overload.rs | 25 +++++++++++++------ .../out/refcount/class.conv.ctor.rs | 2 +- .../class.conv/out/unsafe/class.conv.ctor.rs | 2 +- tests/unit/out/refcount/copy_assign.rs | 10 ++++++-- tests/unit/out/refcount/copy_ctor.rs | 10 +++++++- tests/unit/out/unsafe/copy_assign.rs | 4 +-- tests/unit/out/unsafe/copy_ctor.rs | 8 +++++- 9 files changed, 53 insertions(+), 19 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 5e17813792..c68d6991fc 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -1196,6 +1196,9 @@ void Converter::AddAssignmentTraits(const clang::CXXRecordDecl *decl) { record_name, GetReferenceMarker(trait == &kMoveAssignable), arg)); arg = GetReturnSlotArg(GetPlacementReceiver("__o")); + if (UsesReturnSlot(param_type)) { + arg = std::format("{}::bind({})", GetParameterObjectMarker(), arg); + } } StrCat(std::format("{}::{}({}, {});", GetUFCSName(method), GetMethodName(method), spelling.receiver, arg), @@ -1449,7 +1452,9 @@ std::string Converter::GetMethodName(const clang::CXXMethodDecl *decl) { [&](const clang::CXXMethodDecl *method) { auto *other = clang::dyn_cast(method); - return other && other != conversion && + return other && + other->getCanonicalDecl() != + conversion->getCanonicalDecl() && GetConversionName(other) == name; }); return shared ? name + std::format("_{}", GetMethodIndex(conversion)) diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 0601fab771..e48b0d33e0 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -871,12 +871,12 @@ const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method) { : nullptr; } const char *name = GetCopyOrMoveName(method); + auto *ctor = clang::dyn_cast(method); if (!name || method->isDeleted() || method->isVirtual() || - !CanUseCopyOrMoveName(method, name) || + (!ctor && !CanUseCopyOrMoveName(method, name)) || (!IsUserWrittenMember(method) && !IsTranslatedSpecialMember(method))) { return nullptr; } - auto *ctor = clang::dyn_cast(method); if (!ctor && !method->getReturnType()->isLValueReferenceType()) { return nullptr; } diff --git a/libcc2rs/src/overload.rs b/libcc2rs/src/overload.rs index 972e48f1fb..aab6467a72 100644 --- a/libcc2rs/src/overload.rs +++ b/libcc2rs/src/overload.rs @@ -649,16 +649,25 @@ fn initialize(target: &Table

, to: P, args: &[Arg

], is_direct: b Listed(usize), } let mut viable: Vec<(Constructor, Vec)> = Vec::new(); + let declares = |passings: &[Passing]| { + target.constructors.iter().any(|ctor| { + ctor.params.len() == 1 + && passings.contains(&ctor.params[0].passing) + && (ctor.params[0].table)().id == target.id + }) + }; if args.len() == 1 && sources[0].id == target.id { let identity = Standard::identity(); - viable.push(( - Constructor::Copy, - vec![Sequence::Standard(Standard { - binds_to_const: args[0].category != Category::ConstLvalue, - ..identity - })], - )); - if args[0].category == Category::Rvalue { + if !declares(&[Passing::LvalueRef, Passing::ConstLvalueRef]) { + viable.push(( + Constructor::Copy, + vec![Sequence::Standard(Standard { + binds_to_const: args[0].category != Category::ConstLvalue, + ..identity + })], + )); + } + if args[0].category == Category::Rvalue && !declares(&[Passing::RvalueRef]) { viable.push(( Constructor::Move, vec![Sequence::Standard(Standard { diff --git a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs index fcf9e4da77..7d5e62eabe 100644 --- a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs +++ b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs @@ -288,7 +288,7 @@ impl p2_explicit_constructor_and_conversion_function_Target { } } impl p2_explicit_constructor_and_conversion_function_Source { - pub fn to_p2_explicit_constructor_and_conversion_function_Target_1( + pub fn to_p2_explicit_constructor_and_conversion_function_Target( this: Ptr, ) -> p2_explicit_constructor_and_conversion_function_Target { return { diff --git a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs index 28f418e643..ec44ca2f4a 100644 --- a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs +++ b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs @@ -223,7 +223,7 @@ impl p2_explicit_constructor_and_conversion_function_Target { } } impl p2_explicit_constructor_and_conversion_function_Source { - pub unsafe fn to_p2_explicit_constructor_and_conversion_function_Target_1( + pub unsafe fn to_p2_explicit_constructor_and_conversion_function_Target( this: *const Self, ) -> p2_explicit_constructor_and_conversion_function_Target { return { diff --git a/tests/unit/out/refcount/copy_assign.rs b/tests/unit/out/refcount/copy_assign.rs index 30df172004..4f00ada430 100644 --- a/tests/unit/out/refcount/copy_assign.rs +++ b/tests/unit/out/refcount/copy_assign.rs @@ -316,14 +316,20 @@ impl Swapped { impl CopyAssignable for Swapped { 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())); + Swapped::copy_assign( + this.clone(), + ParameterObject::bind(Ptr::clone(&__o.as_pointer())), + ); Ptr::clone(&this.clone()) } } impl MoveAssignable for Swapped { 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())); + Swapped::copy_assign( + this.clone(), + ParameterObject::bind(Ptr::clone(&__o.as_pointer())), + ); Ptr::clone(&this.clone()) } } diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index 2d2acedaea..36d2db9828 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -42,7 +42,15 @@ impl Counted { } } #[derive( - Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible, Memberwise, MoveAssignable, + Record, + ByteRepr, + ZeroInitialization, + FnPtrArg, + Destructible, + Memberwise, + MoveConstructible, + MoveAssignable, + Swappable, )] #[memberwise(copy_assign)] #[derive(Conversions)] diff --git a/tests/unit/out/unsafe/copy_assign.rs b/tests/unit/out/unsafe/copy_assign.rs index c2baef6f61..405d122f4c 100644 --- a/tests/unit/out/unsafe/copy_assign.rs +++ b/tests/unit/out/unsafe/copy_assign.rs @@ -275,7 +275,7 @@ impl CopyAssignableUnsafe for Swapped { Swapped, LvalueRefUnsafe::bind((src.as_ptr() as *const Swapped)) ); - Swapped::copy_assign(this, &raw mut __o); + Swapped::copy_assign(this, ParameterObjectUnsafe::bind(&raw mut __o)); this } } @@ -286,7 +286,7 @@ impl MoveAssignableUnsafe for Swapped { Swapped, RvalueRefUnsafe::bind((src.as_ptr() as *mut Swapped)) ); - Swapped::copy_assign(this, &raw mut __o); + Swapped::copy_assign(this, ParameterObjectUnsafe::bind(&raw mut __o)); this } } diff --git a/tests/unit/out/unsafe/copy_ctor.rs b/tests/unit/out/unsafe/copy_ctor.rs index 176796756e..e3052cb205 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -38,7 +38,13 @@ impl Counted { } #[repr(C)] #[derive( - FnPtrArg, ZeroInitializationUnsafe, DestructibleUnsafe, MemberwiseUnsafe, MoveAssignableUnsafe, + FnPtrArg, + ZeroInitializationUnsafe, + DestructibleUnsafe, + MemberwiseUnsafe, + MoveConstructibleUnsafe, + MoveAssignableUnsafe, + SwappableUnsafe, )] #[memberwise(copy_assign)] #[derive(ConversionsUnsafe)] From 57d5d83cf49feca89eb465f57bbbe1fdbdd67613 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 4 Dec 2026 13:10:37 +0000 Subject: [PATCH 29/35] Add Pointer marker --- cpp2rust/converter/converter.cpp | 47 ++++++-- cpp2rust/converter/converter.h | 6 + cpp2rust/converter/converter_lib.cpp | 6 +- cpp2rust/converter/converter_lib.h | 2 + .../converter/models/converter_refcount.cpp | 2 + .../converter/models/converter_refcount.h | 2 + libcc2rs-macros/src/conversions.rs | 1 + libcc2rs/src/overload.rs | 111 +++++++++++++++++- libcc2rs/src/reference.rs | 28 +++++ tests/unit/out/refcount/10_struct.rs | 7 +- .../refcount/pair_converting_construction.rs | 15 ++- .../out/refcount/size_t_template_param.rs | 9 +- tests/unit/out/refcount/this.rs | 21 ++-- tests/unit/out/unsafe/10_struct.rs | 10 +- .../unsafe/pair_converting_construction.rs | 9 +- .../unit/out/unsafe/size_t_template_param.rs | 9 +- tests/unit/out/unsafe/this.rs | 20 +++- 17 files changed, 252 insertions(+), 53 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index c68d6991fc..c90bb09450 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -4940,6 +4940,8 @@ void Converter::ConvertCXXConstructExprArgs(clang::CXXConstructExpr *expr) { converted = std::format("{}::bind({})", GetReferenceMarker(type->isRValueReferenceType()), converted); + } else if (is_init && UsesPointerMarker(type)) { + converted = std::format("{}::bind({})", GetPointerMarker(), converted); } args += std::format("{}{}", i ? ", " : "", converted); } @@ -5834,8 +5836,10 @@ void Converter::ConvertFunctionParameters(clang::FunctionDecl *decl) { for (auto *param : DefinitionParameters(decl)) { auto name = GetNamedDeclAsString(param); auto type = GetConvertedVarType(param); - StrCat(std::format("{}{}: {},", NeedsMut(param, type, name) ? "mut " : "", - name, GetConstructorArgType(param))); + bool is_mut = + NeedsMut(param, type, name) && !UsesPointerMarker(param->getType()); + StrCat(std::format("{}{}: {},", is_mut ? "mut " : "", name, + GetConstructorArgType(param))); } return; } @@ -5867,10 +5871,15 @@ void Converter::EmitFunctionPreamble(clang::FunctionDecl *decl) { } if (clang::isa(decl)) { for (auto *param : DefinitionParameters(decl)) { - if (auto type = param->getType(); IsReferenceToObject(type)) { - auto name = GetNamedDeclAsString(param); + auto type = param->getType(); + auto name = GetNamedDeclAsString(param); + if (IsReferenceToObject(type)) { StrCat(std::format("let {} = {};", name, GetReferredObjectPointer(name, type))); + } else if (UsesPointerMarker(type)) { + bool is_mut = NeedsMut(param, GetConvertedVarType(param), name); + StrCat(std::format("let {}{} = {};", is_mut ? "mut " : "", name, + GetReferredObjectPointer(name, type))); } } } @@ -7278,17 +7287,26 @@ std::vector Converter::ArgsToEvaluateFirst( return first; } -std::string Converter::GetReferenceMarkerAsString(clang::QualType type) { - auto pointee = type->getPointeeType(); - auto object = GetUnboxedTypeAsString(pointee.getUnqualifiedType()); - if (pointee.isVolatileQualified()) { - object = std::format("Volatile<{}>", object); +std::string Converter::GetCvObjectAsString(clang::QualType object) { + auto spelling = GetUnboxedTypeAsString(object.getUnqualifiedType()); + if (object.isVolatileQualified()) { + spelling = std::format("Volatile<{}>", spelling); } - if (pointee.isConstQualified()) { - object = std::format("Const<{}>", object); + if (object.isConstQualified()) { + spelling = std::format("Const<{}>", spelling); } + return spelling; +} + +std::string Converter::GetReferenceMarkerAsString(clang::QualType type) { return std::format("{}<{}>", - GetReferenceMarker(type->isRValueReferenceType()), object); + GetReferenceMarker(type->isRValueReferenceType()), + GetCvObjectAsString(type->getPointeeType())); +} + +std::string Converter::GetPointerMarkerAsString(clang::QualType type) { + return std::format("{}<{}>", GetPointerMarker(), + GetCvObjectAsString(type->getPointeeType())); } const char *Converter::GetReferenceMarker(bool is_rvalue) const { @@ -7299,6 +7317,8 @@ const char *Converter::GetParameterObjectMarker() const { return "ParameterObjectUnsafe"; } +const char *Converter::GetPointerMarker() const { return "PointerUnsafe"; } + std::string Converter::GetParameterObjectType(clang::QualType type) { return std::format("{}<{}>", GetParameterObjectMarker(), GetUnboxedTypeAsString(type.getUnqualifiedType())); @@ -7390,6 +7410,9 @@ std::string Converter::GetConstructorArgType(const clang::ParmVarDecl *param) { if (IsReferenceToObject(type)) { return GetReferenceMarkerAsString(type); } + if (UsesPointerMarker(type)) { + return GetPointerMarkerAsString(type); + } return GetParamTypeAsString(param); } diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index 5709bc3f8c..21f90d7c3e 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -107,6 +107,12 @@ class Converter : public clang::RecursiveASTVisitor { virtual const char *GetParameterObjectMarker() const; + virtual const char *GetPointerMarker() const; + + std::string GetPointerMarkerAsString(clang::QualType type); + + std::string GetCvObjectAsString(clang::QualType object); + std::string GetParameterObjectType(clang::QualType type); void EmitConversionsAttrs(const clang::CXXRecordDecl *decl); diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index e48b0d33e0..05f6396916 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -1521,7 +1521,7 @@ bool HasConversionsTable(clang::QualType type) { return true; } if (type->isPointerType()) { - return !type->getPointeeType()->isFunctionType(); + return HasConversionsTable(type->getPointeeType()); } auto *record = type->getAsCXXRecordDecl(); return record && record->isCompleteDefinition() && @@ -1530,6 +1530,10 @@ bool HasConversionsTable(clang::QualType type) { !record->isDependentContext(); } +bool UsesPointerMarker(clang::QualType type) { + return type->isPointerType() && HasConversionsTable(type); +} + bool IsTableConversionFunction(const clang::CXXConversionDecl *conversion) { auto *record = conversion->getParent(); auto type = conversion->getConversionType(); diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index 3c46289766..51b08bcb1c 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -408,6 +408,8 @@ bool IsReferenceToObject(clang::QualType type); bool HasConversionsTable(clang::QualType type); +bool UsesPointerMarker(clang::QualType type); + std::optional GetInitMethod(const clang::FunctionDecl *decl); bool IsTableConversionFunction(const clang::CXXConversionDecl *conversion); diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 6c79d0cbcf..5097b69b7f 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -322,6 +322,8 @@ const char *ConverterRefCount::GetParameterObjectMarker() const { return "ParameterObject"; } +const char *ConverterRefCount::GetPointerMarker() const { return "Pointer"; } + std::string ConverterRefCount::CollapseReference(std::string_view result, clang::QualType, bool) { return std::format("{}.with(|__r| __r.as_pointer())", result); diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index 54f72eda48..6071f589a7 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -33,6 +33,8 @@ class ConverterRefCount final : public Converter { const char *GetParameterObjectMarker() const override; + const char *GetPointerMarker() const override; + std::string CollapseReference(std::string_view result, clang::QualType referred, bool is_place) override; diff --git a/libcc2rs-macros/src/conversions.rs b/libcc2rs-macros/src/conversions.rs index 4f99a2769c..e4d9a800f8 100644 --- a/libcc2rs-macros/src/conversions.rs +++ b/libcc2rs-macros/src/conversions.rs @@ -288,6 +288,7 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { move_from: #move_fn, constructors: vec![#(#candidates),*], conversion_functions: vec![#(#conversions),*], + qualification_of: None, } } } diff --git a/libcc2rs/src/overload.rs b/libcc2rs/src/overload.rs index aab6467a72..96670e3b02 100644 --- a/libcc2rs/src/overload.rs +++ b/libcc2rs/src/overload.rs @@ -14,8 +14,8 @@ use std::ffi::c_void; use crate::initialization::ZeroInitializationUnsafe as _; use crate::rc::Ptr; use crate::reference::{ - Const, LvalueRef, LvalueRefUnsafe, ParameterObject, ParameterObjectUnsafe, RvalueRef, - RvalueRefUnsafe, + Const, LvalueRef, LvalueRefUnsafe, ParameterObject, ParameterObjectUnsafe, Pointer, + PointerUnsafe, RvalueRef, RvalueRefUnsafe, }; use crate::reinterpret::ByteRepr; use crate::void::AnyPtr; @@ -105,6 +105,9 @@ pub struct Table

{ pub move_from: fn(dst: P, src: P), pub constructors: Vec>, pub conversion_functions: Vec>, + // The type whose objects convert to this type by a qualification + // conversion ([conv.qual]). + pub qualification_of: Option, } pub trait Conversions: ByteRepr + Sized + 'static { @@ -272,6 +275,50 @@ impl Parameter for RvalueRef> { } } +impl Parameter for Pointer +where + Ptr: Conversions, +{ + fn param() -> Param { + Param { + table: as Conversions>::table, + passing: Passing::Value, + } + } + + fn bind(object: &AnyPtr) -> Self { + Pointer::bind(object.downcast::>().read()) + } +} + +fn const_pointer_table() -> Table +where + Ptr: Conversions, +{ + Table { + id: TypeId::of::>>(), + name: "Ptr", + qualification_of: Some(TypeId::of::>()), + .. as Conversions>::table() + } +} + +impl Parameter for Pointer> +where + Ptr: Conversions, +{ + fn param() -> Param { + Param { + table: const_pointer_table::, + passing: Passing::Value, + } + } + + fn bind(object: &AnyPtr) -> Self { + Pointer::bind(object.downcast::>().read()) + } +} + pub trait ParameterUnsafe: Sized { fn param() -> Param<*mut c_void>; @@ -298,6 +345,32 @@ impl ParameterUnsafe for ParameterObjectUnsafe { } } +impl ParameterUnsafe for PointerUnsafe { + fn param() -> Param<*mut c_void> { + Param { + table: <*mut T as ConversionsUnsafe>::table, + passing: Passing::Value, + } + } + + unsafe fn bind(object: *mut c_void) -> Self { + PointerUnsafe::bind(unsafe { object.cast::<*mut T>().read() }) + } +} + +impl ParameterUnsafe for PointerUnsafe> { + fn param() -> Param<*mut c_void> { + Param { + table: <*const T as ConversionsUnsafe>::table, + passing: Passing::Value, + } + } + + unsafe fn bind(object: *mut c_void) -> Self { + PointerUnsafe::bind(unsafe { object.cast::<*const T>().read() }) + } +} + impl ParameterUnsafe for LvalueRefUnsafe { fn param() -> Param<*mut c_void> { Param { table: T::table, passing: Passing::LvalueRef } @@ -437,6 +510,7 @@ enum Rank { struct Standard { rank: Rank, converts: bool, + qualifies: bool, binds_rvalue_ref: bool, binds_to_const: bool, } @@ -446,6 +520,7 @@ impl Standard { Standard { rank: Rank::Exact, converts: false, + qualifies: false, binds_rvalue_ref: false, binds_to_const: false, } @@ -486,6 +561,12 @@ fn standard(from: &Table

, to: &Table

) -> Option { if from.id == to.id { return Some(Standard::identity()); } + if to.qualification_of == Some(from.id) { + return Some(Standard { + qualifies: true, + ..Standard::identity() + }); + } let (from_kind, to_kind) = (from.arithmetic?, to.arithmetic?); Some(Standard { rank: if promotes(from_kind, to_kind) { @@ -494,6 +575,7 @@ fn standard(from: &Table

, to: &Table

) -> Option { Rank::Conversion }, converts: true, + qualifies: false, binds_rvalue_ref: false, binds_to_const: false, }) @@ -590,6 +672,9 @@ fn user_sequence( fn compare_standard(a: &Standard, b: &Standard) -> Ordering { a.rank .cmp(&b.rank) + // [over.ics.rank]/3.2.1: the identity is a proper subsequence of a + // qualification conversion. + .then(a.qualifies.cmp(&b.qualifies)) // [over.ics.rank]/3.2.3: an rvalue binds better to an rvalue reference. .then(b.binds_rvalue_ref.cmp(&a.binds_rvalue_ref)) // [over.ics.rank]/3.2.6: to a reference to the less cv-qualified type. @@ -869,6 +954,7 @@ macro_rules! arithmetic_conversions { move_from: |dst, src| Erased::write(&dst, Erased::read::<$ty>(&src)), constructors: Vec::new(), conversion_functions: Vec::new(), + qualification_of: None, } } } @@ -885,6 +971,7 @@ macro_rules! arithmetic_conversions { move_from: |dst, src| Erased::write(&dst, Erased::read::<$ty>(&src)), constructors: Vec::new(), conversion_functions: Vec::new(), + qualification_of: None, } } } @@ -930,6 +1017,7 @@ where }, constructors: Vec::new(), conversion_functions: Vec::new(), + qualification_of: None, } } } @@ -965,6 +1053,7 @@ where }, constructors: Vec::new(), conversion_functions: Vec::new(), + qualification_of: None, } } } @@ -1007,6 +1096,7 @@ where }, constructors: Vec::new(), conversion_functions: Vec::new(), + qualification_of: None, } } } @@ -1031,6 +1121,7 @@ where }, constructors: Vec::new(), conversion_functions: Vec::new(), + qualification_of: None, } } } @@ -1050,23 +1141,27 @@ impl ConversionsUnsafe for Option> { }, constructors: Vec::new(), conversion_functions: Vec::new(), + qualification_of: None, } } } impl ConversionsUnsafe for *mut T { fn table() -> Table<*mut c_void> { - raw_pointer_table::<*mut T>("*mut") + raw_pointer_table::<*mut T>("*mut", None) } } impl ConversionsUnsafe for *const T { fn table() -> Table<*mut c_void> { - raw_pointer_table::<*const T>("*const") + raw_pointer_table::<*const T>("*const", Some(TypeId::of::<*mut T>())) } } -fn raw_pointer_table(name: &'static str) -> Table<*mut c_void> { +fn raw_pointer_table( + name: &'static str, + qualification_of: Option, +) -> Table<*mut c_void> { Table { id: TypeId::of::(), name, @@ -1077,6 +1172,7 @@ fn raw_pointer_table(name: &'static str) -> Table<* move_from: |dst, src| unsafe { dst.cast::().write(src.cast::().read()) }, constructors: Vec::new(), conversion_functions: Vec::new(), + qualification_of, } } @@ -1106,6 +1202,7 @@ impl ConversionsUnsafe f }, constructors: Vec::new(), conversion_functions: Vec::new(), + qualification_of: None, } } } @@ -1134,6 +1231,7 @@ where }, constructors: Vec::new(), conversion_functions: Vec::new(), + qualification_of: None, } } } @@ -1228,6 +1326,7 @@ mod tests { }, }, ], + qualification_of: None, } } } @@ -1281,6 +1380,7 @@ mod tests { }, ], conversion_functions: Vec::new(), + qualification_of: None, } } } @@ -1346,6 +1446,7 @@ mod tests { let promote = Standard { rank: Rank::Promotion, converts: true, + qualifies: false, binds_rvalue_ref: false, binds_to_const: false, }; diff --git a/libcc2rs/src/reference.rs b/libcc2rs/src/reference.rs index bee5518c94..0d42f81a13 100644 --- a/libcc2rs/src/reference.rs +++ b/libcc2rs/src/reference.rs @@ -303,6 +303,34 @@ macro_rules! reference_unsafe { reference_unsafe!(LvalueRefUnsafe); reference_unsafe!(RvalueRefUnsafe); +pub struct Pointer(Ptr); + +impl Pointer { + #[inline] + pub fn bind(ptr: Ptr) -> Self { + Self(ptr) + } + + #[inline] + pub fn as_pointer(&self) -> Ptr { + self.0.clone() + } +} + +pub struct PointerUnsafe(*mut std::ffi::c_void, PhantomData); + +impl PointerUnsafe { + #[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() + } +} + pub struct ParameterObject(Ptr); impl ParameterObject { diff --git a/tests/unit/out/refcount/10_struct.rs b/tests/unit/out/refcount/10_struct.rs index aa58178b9a..2aab41cbe5 100644 --- a/tests/unit/out/refcount/10_struct.rs +++ b/tests/unit/out/refcount/10_struct.rs @@ -65,7 +65,7 @@ impl Graph { )] #[conversions(copy, move)] #[constructor(constructor_1)] -#[constructor(constructor_2, explicit, Ptr< i32 > )] +#[constructor(constructor_2, explicit, Pointer)] #[byte_size(8)] pub struct Partial { #[offset(0)] @@ -76,7 +76,8 @@ impl Partial { pub fn constructor_1(this: Ptr) { field!(this, p).write(Ptr::::null()); } - pub fn constructor_2(this: Ptr, mut q: Ptr) { + pub fn constructor_2(this: Ptr, q: Pointer) { + let mut q = q.as_pointer(); field!(this, p).write((q).clone()); } } @@ -137,7 +138,7 @@ fn main_0() -> i32 { adj: Ptr::>::null(), }; let arr: Value> = Rc::new(RefCell::new(Box::new([3, 1, 4]))); - object!(it, Partial::constructor_2(arr.decay())); + object!(it, Partial::constructor_2(Pointer::bind(arr.decay()))); if ({ { (*it.borrow()).p.clone() } } != { arr.decay() }) { return 1; } diff --git a/tests/unit/out/refcount/pair_converting_construction.rs b/tests/unit/out/refcount/pair_converting_construction.rs index c8e9e5de9f..bf4a93e669 100644 --- a/tests/unit/out/refcount/pair_converting_construction.rs +++ b/tests/unit/out/refcount/pair_converting_construction.rs @@ -269,14 +269,15 @@ pub struct Tag { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, Ptr< i8 > )] +#[constructor(constructor_1, Pointer>)] #[byte_size(4)] pub struct Name { #[offset(0)] pub len: i32, } impl Name { - pub fn constructor_1(this: Ptr, mut s: Ptr) { + pub fn constructor_1(this: Ptr, s: Pointer>) { + let mut s = s.as_pointer(); field!(this, len).write(0); 'loop_: while ((elem!(s, this.with(|__s| __s.len)).read()) != 0) { field!(this, len).with_mut(|__v| { @@ -598,12 +599,18 @@ fn main_0() -> i32 { let from_string_literals: Value<(Value, Value)> = Rc::new(RefCell::new(( Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Name::constructor_1(__v.as_pointer(), Ptr::::from_string_literal(b"ab")); + Name::constructor_1( + __v.as_pointer(), + Pointer::bind(Ptr::::from_string_literal(b"ab")), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); - Name::constructor_1(__v.as_pointer(), Ptr::::from_string_literal(b"cde")); + Name::constructor_1( + __v.as_pointer(), + Pointer::bind(Ptr::::from_string_literal(b"cde")), + ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ))); diff --git a/tests/unit/out/refcount/size_t_template_param.rs b/tests/unit/out/refcount/size_t_template_param.rs index 9326e7703e..2e2ac9adeb 100644 --- a/tests/unit/out/refcount/size_t_template_param.rs +++ b/tests/unit/out/refcount/size_t_template_param.rs @@ -24,14 +24,15 @@ pub fn array_ref_0(a: Ptr) -> u64 { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, Ptr< u64 > )] +#[constructor(constructor_1, Pointer>)] #[byte_size(8)] pub struct PtrCtor_unsigned_long_ { #[offset(0)] pub v: u64, } impl PtrCtor_unsigned_long_ { - pub fn constructor_1(this: Ptr, mut p: Ptr) { + pub fn constructor_1(this: Ptr, p: Pointer>) { + let mut p = p.as_pointer(); field!(this, v).write((elem!(p, 1).read())); } } @@ -81,7 +82,9 @@ fn main_0() -> i32 { let a2: Value> = Rc::new(RefCell::new(Box::new([4_usize, 5_usize]))); object!( pc, - PtrCtor_unsigned_long_::constructor_1((a2.decay()).reinterpret_cast::()) + PtrCtor_unsigned_long_::constructor_1(Pointer::bind( + (a2.decay()).reinterpret_cast::() + )) ); assert!(({ (*pc.borrow()).v } == 5_u64)); let v1: Value = Rc::new(RefCell::new(6_usize)); diff --git a/tests/unit/out/refcount/this.rs b/tests/unit/out/refcount/this.rs index e4f7edde5b..cf648bb3b7 100644 --- a/tests/unit/out/refcount/this.rs +++ b/tests/unit/out/refcount/this.rs @@ -19,9 +19,9 @@ use std::rc::{Rc, Weak}; Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] -#[constructor(constructor_2, value(i32 ), value(Ptr< S > ))] -#[constructor(constructor_3, value(i32 ), value(Ptr< S > ))] +#[constructor(constructor_1, i32)] +#[constructor(constructor_2, i32 , Pointer)] +#[constructor(constructor_3, i32 , Pointer>)] #[byte_size(16)] pub struct S { #[offset(0)] @@ -35,7 +35,8 @@ impl S { field!(this, a_).write(a); field!(this, self__).write(Ptr::::null()); } - pub fn constructor_2(this: Ptr, mut a: i32, mut other: Ptr) { + pub fn constructor_2(this: Ptr, mut a: i32, other: Pointer) { + let mut other = other.as_pointer(); field!(this, a_).write(a); field!(this, self__).write(Ptr::::null()); if (this == other) { @@ -44,7 +45,8 @@ impl S { field!(this, self__).write((other).clone()); } } - pub fn constructor_3(this: Ptr, mut a: i32, mut other: Ptr) { + pub fn constructor_3(this: Ptr, mut a: i32, other: Pointer>) { + let mut other = other.as_pointer(); field!(this, a_).write(a); field!(this, self__).write(Ptr::::null()); if (this == other) { @@ -127,7 +129,7 @@ pub fn bump_0(mut p: Ptr) { Conversions, )] #[conversions(copy, move)] -#[constructor(constructor_1, value(i32))] +#[constructor(constructor_1, i32)] #[byte_size(4)] pub struct D { #[offset(0)] @@ -203,14 +205,17 @@ fn main_0() -> i32 { ); assert!(({ (*s.borrow()).a_ } == { (*other.borrow()).a_ })); assert!(({ { (*s.borrow()).self__.clone() } } == { { (*other.borrow()).self__.clone() } })); - object!(u, S::constructor_2(1, (s.as_pointer()))); + object!(u, S::constructor_2(1, Pointer::bind((s.as_pointer())))); assert!(({ { (*u.borrow()).self__.clone() } } == { (s.as_pointer()) })); let s_const: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(ZeroInitialization::zero_init())); S::constructor_1(__v.as_pointer(), 100); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); - object!(u1, S::constructor_3(1, (s_const.as_pointer()))); + object!( + u1, + S::constructor_3(1, Pointer::bind((s_const.as_pointer()))) + ); assert!(({ (*u1.borrow()).self__.clone() }).is_null()); return 0; } diff --git a/tests/unit/out/unsafe/10_struct.rs b/tests/unit/out/unsafe/10_struct.rs index 57e044f6e8..3a1746e7b8 100644 --- a/tests/unit/out/unsafe/10_struct.rs +++ b/tests/unit/out/unsafe/10_struct.rs @@ -64,7 +64,7 @@ impl Graph { )] #[conversions(copy, move)] #[constructor(constructor_1)] -#[constructor(constructor_2, explicit, *mut i32 )] +#[constructor(constructor_2, explicit, PointerUnsafe)] pub struct Partial { pub p: *mut i32, } @@ -72,7 +72,8 @@ impl Partial { pub unsafe fn constructor_1(this: *mut Self) { (&raw mut (*this).p).write(std::ptr::null_mut()); } - pub unsafe fn constructor_2(this: *mut Self, mut q: *mut i32) { + pub unsafe fn constructor_2(this: *mut Self, q: PointerUnsafe) { + let mut q = (q.as_ptr() as *mut i32); (&raw mut (*this).p).write(q); } } @@ -129,7 +130,10 @@ unsafe fn main_0() -> i32 { adj: std::ptr::null_mut(), }; let mut arr: [i32; 3] = [3, 1, 4]; - object_unsafe!(it, Partial::constructor_2(arr.as_mut_ptr())); + object_unsafe!( + it, + Partial::constructor_2(PointerUnsafe::bind(arr.as_mut_ptr())) + ); if ((it.p) != (arr.as_mut_ptr())) { return 1; } diff --git a/tests/unit/out/unsafe/pair_converting_construction.rs b/tests/unit/out/unsafe/pair_converting_construction.rs index 23f094176f..2674a4d16b 100644 --- a/tests/unit/out/unsafe/pair_converting_construction.rs +++ b/tests/unit/out/unsafe/pair_converting_construction.rs @@ -240,12 +240,13 @@ pub struct Tag { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, *const libc::c_char )] +#[constructor(constructor_1, PointerUnsafe>)] pub struct Name { pub len: i32, } impl Name { - pub unsafe fn constructor_1(this: *mut Self, mut s: *const libc::c_char) { + pub unsafe fn constructor_1(this: *mut Self, s: PointerUnsafe>) { + let mut s = (s.as_ptr() as *const libc::c_char); (&raw mut (*this).len).write(0); 'loop_: while ((*s.offset(((*this).len) as isize)) != 0) { (*this).len.prefix_inc(); @@ -542,12 +543,12 @@ unsafe fn main_0() -> i32 { let mut from_string_literals: (Name, Name) = ( { let mut __v: Name = ZeroInitializationUnsafe::zero_init(); - Name::constructor_1(&raw mut __v, c"ab".as_ptr()); + Name::constructor_1(&raw mut __v, PointerUnsafe::bind(c"ab".as_ptr())); __v }, { let mut __v: Name = ZeroInitializationUnsafe::zero_init(); - Name::constructor_1(&raw mut __v, c"cde".as_ptr()); + Name::constructor_1(&raw mut __v, PointerUnsafe::bind(c"cde".as_ptr())); __v }, ); diff --git a/tests/unit/out/unsafe/size_t_template_param.rs b/tests/unit/out/unsafe/size_t_template_param.rs index 1db92808f6..07f6e47a40 100644 --- a/tests/unit/out/unsafe/size_t_template_param.rs +++ b/tests/unit/out/unsafe/size_t_template_param.rs @@ -23,12 +23,13 @@ pub unsafe fn array_ref_0(a: *mut [u64; 3]) -> u64 { ConversionsUnsafe, )] #[conversions(copy, move)] -#[constructor(constructor_1, *const u64 )] +#[constructor(constructor_1, PointerUnsafe>)] pub struct PtrCtor_unsigned_long_ { pub v: u64, } impl PtrCtor_unsigned_long_ { - pub unsafe fn constructor_1(this: *mut Self, mut p: *const u64) { + pub unsafe fn constructor_1(this: *mut Self, p: PointerUnsafe>) { + let mut p = (p.as_ptr() as *const u64); (&raw mut (*this).v).write((*p.offset((1) as isize))); } } @@ -77,9 +78,9 @@ unsafe fn main_0() -> i32 { let mut a2: [usize; 2] = [4_usize, 5_usize]; object_unsafe!( pc, - PtrCtor_unsigned_long_::constructor_1( + PtrCtor_unsigned_long_::constructor_1(PointerUnsafe::bind( ((a2.as_mut_ptr()).cast_const() as *const usize).cast::() - ) + )) ); assert!(((pc.v) == (5_u64))); let mut v1: usize = 6_usize; diff --git a/tests/unit/out/unsafe/this.rs b/tests/unit/out/unsafe/this.rs index e97072212c..471e7670b3 100644 --- a/tests/unit/out/unsafe/this.rs +++ b/tests/unit/out/unsafe/this.rs @@ -20,8 +20,8 @@ use std::rc::Rc; )] #[conversions(copy, move)] #[constructor(constructor_1, i32)] -#[constructor(constructor_2, i32 , *mut S )] -#[constructor(constructor_3, i32 , *const S )] +#[constructor(constructor_2, i32 , PointerUnsafe)] +#[constructor(constructor_3, i32 , PointerUnsafe>)] pub struct S { pub a_: i32, pub self__: *mut S, @@ -31,7 +31,8 @@ impl S { (&raw mut (*this).a_).write(a); (&raw mut (*this).self__).write(std::ptr::null_mut()); } - pub unsafe fn constructor_2(this: *mut Self, mut a: i32, mut other: *mut S) { + pub unsafe fn constructor_2(this: *mut Self, mut a: i32, other: PointerUnsafe) { + let mut other = (other.as_ptr() as *mut S); (&raw mut (*this).a_).write(a); (&raw mut (*this).self__).write(std::ptr::null_mut()); if ((this) == (other)) { @@ -40,7 +41,8 @@ impl S { (*this).self__ = other; } } - pub unsafe fn constructor_3(this: *mut Self, mut a: i32, mut other: *const S) { + pub unsafe fn constructor_3(this: *mut Self, mut a: i32, other: PointerUnsafe>) { + let mut other = (other.as_ptr() as *const S); (&raw mut (*this).a_).write(a); (&raw mut (*this).self__).write(std::ptr::null_mut()); if (((this).cast_const()) == (other)) { @@ -219,14 +221,20 @@ unsafe fn main_0() -> i32 { ); assert!(((s.a_) == (other.a_))); assert!(((s.self__) == (other.self__))); - object_unsafe!(u, S::constructor_2(1, (&mut s as *mut S))); + object_unsafe!( + u, + S::constructor_2(1, PointerUnsafe::bind((&mut s as *mut S))) + ); assert!(((u.self__) == (&mut s as *mut S))); let s_const: S = { let mut __v: S = ZeroInitializationUnsafe::zero_init(); S::constructor_1(&raw mut __v, 100); __v }; - object_unsafe!(u1, S::constructor_3(1, (&s_const as *const S))); + object_unsafe!( + u1, + S::constructor_3(1, PointerUnsafe::bind((&s_const as *const S))) + ); assert!((u1.self__).is_null()); return 0; } From 7982a851dabde99580ced0fdb450d3067ea5c765 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 4 Dec 2026 13:21:00 +0000 Subject: [PATCH 30/35] format --- CMakeLists.txt | 3 + cpp2rust/converter/converter.cpp | 42 ++-- cpp2rust/converter/converter.h | 5 - .../converter/models/converter_refcount.cpp | 9 +- .../converter/models/converter_refcount.h | 1 - libcc2rs/src/capture.rs | 4 +- libcc2rs/src/overload.rs | 62 ++++-- libcc2rs/src/swap.rs | 5 +- rules/algorithm/tgt_refcount.rs | 59 +++++- rules/algorithm/tgt_unsafe.rs | 59 +++++- rules/any/tgt_refcount.rs | 13 +- rules/any/tgt_unsafe.rs | 11 +- rules/array/tgt_refcount.rs | 13 +- rules/builtin/tgt_unsafe.rs | 4 +- rules/deque/tgt_unsafe.rs | 5 +- rules/iterator_category/shim.rs | 8 +- rules/iterator_category/tgt_refcount.rs | 9 +- rules/iterator_category/tgt_unsafe.rs | 9 +- rules/map/tgt_refcount.rs | 100 +++++++-- rules/map/tgt_unsafe.rs | 65 +++++- rules/pair/tgt_refcount.rs | 130 +++++++++--- rules/pair/tgt_unsafe.rs | 197 +++++++++++++++--- rules/string/tgt_refcount.rs | 3 +- rules/string/tgt_unsafe.rs | 19 +- rules/unique_ptr/shim.rs | 6 +- rules/unique_ptr/tgt_refcount.rs | 13 +- rules/unique_ptr/tgt_unsafe.rs | 6 +- rules/vector/shim.rs | 16 +- rules/vector/tgt_refcount.rs | 58 +++++- rules/vector/tgt_unsafe.rs | 64 +++++- 30 files changed, 772 insertions(+), 226 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bebc404d8e..e799f20dcb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -100,6 +100,8 @@ find_program(RUFF NAMES ruff) file(GLOB_RECURSE ALL_CXX_SOURCES cpp2rust/*.cpp cpp2rust/*.h rules/*.cpp rules/*.c rules/*.h tests/*.cpp tests/*.c) +file(GLOB_RECURSE RULE_RUST_SOURCES rules/*/*.rs) + set(PYTHON_SOURCES ${PROJECT_SOURCE_DIR}/tests/lit/lit/formats/Cpp2RustTest.py) # `clippy --fix` downgrades -Dwarnings errors back to warnings, and manifest @@ -109,6 +111,7 @@ set(CLIPPY_ENV CARGO_BUILD_WARNINGS=deny) add_custom_target("format" COMMAND ${CLANG_FORMAT} -i ${ALL_CXX_SOURCES} COMMAND cargo +${RUST_STABLE_VERSION} fmt --manifest-path ${PROJECT_SOURCE_DIR}/rules/Cargo.toml + COMMAND rustfmt +${RUST_STABLE_VERSION} --edition 2024 ${RULE_RUST_SOURCES} COMMAND cargo +${RUST_NIGHTLY_VERSION} fmt --manifest-path ${PROJECT_SOURCE_DIR}/rule-preprocessor/Cargo.toml COMMAND cargo +${RUST_STABLE_VERSION} fmt --manifest-path ${PROJECT_SOURCE_DIR}/libcc2rs/Cargo.toml COMMAND cargo +${RUST_STABLE_VERSION} fmt --manifest-path ${PROJECT_SOURCE_DIR}/libcc2rs-macros/Cargo.toml diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index c90bb09450..d1797b57b5 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -473,7 +473,8 @@ Converter::ConvertFunctionPointerType(const clang::FunctionProtoType *proto) { result += ','; } for (auto p_ty : proto->param_types()) { - result += UsesReturnSlot(p_ty) ? GetParameterObjectType(p_ty) : ToString(p_ty); + result += + UsesReturnSlot(p_ty) ? GetParameterObjectType(p_ty) : ToString(p_ty); result += ','; } if (proto->isVariadic()) { @@ -1447,16 +1448,14 @@ std::string Converter::GetMethodName(const clang::CXXMethodDecl *decl) { } if (auto *conversion = clang::dyn_cast(decl)) { auto name = GetConversionName(conversion); - bool shared = - llvm::any_of(conversion->getParent()->methods(), - [&](const clang::CXXMethodDecl *method) { - auto *other = - clang::dyn_cast(method); - return other && - other->getCanonicalDecl() != - conversion->getCanonicalDecl() && - GetConversionName(other) == name; - }); + bool shared = llvm::any_of( + conversion->getParent()->methods(), + [&](const clang::CXXMethodDecl *method) { + auto *other = clang::dyn_cast(method); + return other && + other->getCanonicalDecl() != conversion->getCanonicalDecl() && + GetConversionName(other) == name; + }); return shared ? name + std::format("_{}", GetMethodIndex(conversion)) : name; } @@ -1763,8 +1762,7 @@ bool Converter::VisitDeclStmt(clang::DeclStmt *stmt) { bool Converter::VisitReturnStmt(clang::ReturnStmt *stmt) { ScopedValue return_value(return_value_, stmt->getRetValue()); auto return_type = curr_function_->getReturnType(); - if (auto *value = stmt->getRetValue(); - value && UsesReturnSlot(return_type)) { + if (auto *value = stmt->getRetValue(); value && UsesReturnSlot(return_type)) { std::string_view slot = "__return"; if (auto *construct = GetPlacementInitializer(value)) { ConstructInPlace(value, construct, GetReturnSlotReceiver(slot)); @@ -7385,15 +7383,15 @@ void Converter::EmitConversionsAttrs(const clang::CXXRecordDecl *decl) { auto to = conversion->getConversionType(); auto object = ctx_.getQualifiedType(ctx_.getCanonicalTagType(decl), conversion->getMethodQualifiers()); - StrCat(std::format( - "#[conversion_function({}, {}, {}{}{})]", GetMethodName(conversion), - GetReferenceMarkerAsString( - conversion->getRefQualifier() == clang::RQ_RValue - ? ctx_.getRValueReferenceType(object) - : ctx_.getLValueReferenceType(object)), - GetUnboxedTypeAsString(to.getUnqualifiedType()), - conversion->isExplicit() ? ", explicit" : "", - UsesReturnSlot(to) ? ", return_slot" : "")); + StrCat(std::format("#[conversion_function({}, {}, {}{}{})]", + GetMethodName(conversion), + GetReferenceMarkerAsString( + conversion->getRefQualifier() == clang::RQ_RValue + ? ctx_.getRValueReferenceType(object) + : ctx_.getLValueReferenceType(object)), + GetUnboxedTypeAsString(to.getUnqualifiedType()), + conversion->isExplicit() ? ", explicit" : "", + UsesReturnSlot(to) ? ", return_slot" : "")); } } diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index 21f90d7c3e..44dbc79de1 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -123,10 +123,6 @@ class Converter : public clang::RecursiveASTVisitor { virtual std::string GetParamTypeAsString(const clang::ParmVarDecl *param); - - - - virtual std::string CollapseReference(std::string_view result, clang::QualType referred, bool is_place); @@ -1014,7 +1010,6 @@ class Converter : public clang::RecursiveASTVisitor { const clang::CXXRecordDecl *decl, std::string_view value); - virtual std::string GetComparisonResultReceiver(const clang::CXXMethodDecl *method, bool returns_ref, std::string_view result); diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 5097b69b7f..3435b57a9b 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -658,11 +658,10 @@ ConverterRefCount::GetComparisonArg(const clang::ParmVarDecl *param, return std::format("{}.read()", value); } auto record = GetRecordName(decl); - return std::format( - "{{ {} <{} as CopyConstructible>::copy_constructor({}, " - "LvalueRef::bind({}.clone())); {} }}", - CreatePlacementStorage(record), record, GetPlacementReceiver(), value, - TakePlacementValue()); + return std::format("{{ {} <{} as CopyConstructible>::copy_constructor({}, " + "LvalueRef::bind({}.clone())); {} }}", + CreatePlacementStorage(record), record, + GetPlacementReceiver(), value, TakePlacementValue()); } std::string ConverterRefCount::GetComparisonResultReceiver( diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index 6071f589a7..b65cd7cfbd 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -126,7 +126,6 @@ class ConverterRefCount final : public Converter { std::string GetParamTypeAsString(const clang::ParmVarDecl *param) override; - std::string GetReturnSlotArg(std::string_view receiver) const override; bool VisitCXXThisExpr(clang::CXXThisExpr *expr) override; diff --git a/libcc2rs/src/capture.rs b/libcc2rs/src/capture.rs index 92f03fb7dd..a0cbaea9a4 100644 --- a/libcc2rs/src/capture.rs +++ b/libcc2rs/src/capture.rs @@ -96,7 +96,9 @@ impl CopyLambda>> for &&&Capture<'_, Value>> { let dst: Value> = Rc::new(RefCell::new(FnPtr::zero_init())); as crate::Constructor<(crate::LvalueRef>>,)>>::constructor( AsPointer::>::as_pointer(&dst), - (crate::LvalueRef::bind(AsPointer::>::as_pointer(self.0)),), + (crate::LvalueRef::bind(AsPointer::>::as_pointer( + self.0, + )),), ); dst } diff --git a/libcc2rs/src/overload.rs b/libcc2rs/src/overload.rs index 96670e3b02..e300d2a4c5 100644 --- a/libcc2rs/src/overload.rs +++ b/libcc2rs/src/overload.rs @@ -217,7 +217,10 @@ pub trait Parameter: Sized { impl Parameter for T { fn param() -> Param { - Param { table: T::table, passing: Passing::Value } + Param { + table: T::table, + passing: Passing::Value, + } } fn bind(object: &AnyPtr) -> Self { @@ -227,7 +230,10 @@ impl Parameter for T { impl Parameter for ParameterObject { fn param() -> Param { - Param { table: T::table, passing: Passing::Value } + Param { + table: T::table, + passing: Passing::Value, + } } fn bind(object: &AnyPtr) -> Self { @@ -237,7 +243,10 @@ impl Parameter for ParameterObject { impl Parameter for LvalueRef { fn param() -> Param { - Param { table: T::table, passing: Passing::LvalueRef } + Param { + table: T::table, + passing: Passing::LvalueRef, + } } fn bind(object: &AnyPtr) -> Self { @@ -247,7 +256,10 @@ impl Parameter for LvalueRef { impl Parameter for LvalueRef> { fn param() -> Param { - Param { table: T::table, passing: Passing::ConstLvalueRef } + Param { + table: T::table, + passing: Passing::ConstLvalueRef, + } } fn bind(object: &AnyPtr) -> Self { @@ -257,7 +269,10 @@ impl Parameter for LvalueRef> { impl Parameter for RvalueRef { fn param() -> Param { - Param { table: T::table, passing: Passing::RvalueRef } + Param { + table: T::table, + passing: Passing::RvalueRef, + } } fn bind(object: &AnyPtr) -> Self { @@ -267,7 +282,10 @@ impl Parameter for RvalueRef { impl Parameter for RvalueRef> { fn param() -> Param { - Param { table: T::table, passing: Passing::RvalueRef } + Param { + table: T::table, + passing: Passing::RvalueRef, + } } fn bind(object: &AnyPtr) -> Self { @@ -322,12 +340,17 @@ where pub trait ParameterUnsafe: Sized { fn param() -> Param<*mut c_void>; + /// # Safety + /// `object` points to a live object of the parameter's table type. unsafe fn bind(object: *mut c_void) -> Self; } impl ParameterUnsafe for T { fn param() -> Param<*mut c_void> { - Param { table: T::table, passing: Passing::Value } + Param { + table: T::table, + passing: Passing::Value, + } } unsafe fn bind(object: *mut c_void) -> Self { @@ -337,7 +360,10 @@ impl ParameterUnsafe for T { impl ParameterUnsafe for ParameterObjectUnsafe { fn param() -> Param<*mut c_void> { - Param { table: T::table, passing: Passing::Value } + Param { + table: T::table, + passing: Passing::Value, + } } unsafe fn bind(object: *mut c_void) -> Self { @@ -373,7 +399,10 @@ impl ParameterUnsafe for PointerUnsafe> { impl ParameterUnsafe for LvalueRefUnsafe { fn param() -> Param<*mut c_void> { - Param { table: T::table, passing: Passing::LvalueRef } + Param { + table: T::table, + passing: Passing::LvalueRef, + } } unsafe fn bind(object: *mut c_void) -> Self { @@ -383,7 +412,10 @@ impl ParameterUnsafe for LvalueRefUnsafe { impl ParameterUnsafe for LvalueRefUnsafe> { fn param() -> Param<*mut c_void> { - Param { table: T::table, passing: Passing::ConstLvalueRef } + Param { + table: T::table, + passing: Passing::ConstLvalueRef, + } } unsafe fn bind(object: *mut c_void) -> Self { @@ -393,7 +425,10 @@ impl ParameterUnsafe for LvalueRefUnsafe> { impl ParameterUnsafe for RvalueRefUnsafe { fn param() -> Param<*mut c_void> { - Param { table: T::table, passing: Passing::RvalueRef } + Param { + table: T::table, + passing: Passing::RvalueRef, + } } unsafe fn bind(object: *mut c_void) -> Self { @@ -403,7 +438,10 @@ impl ParameterUnsafe for RvalueRefUnsafe { impl ParameterUnsafe for RvalueRefUnsafe> { fn param() -> Param<*mut c_void> { - Param { table: T::table, passing: Passing::RvalueRef } + Param { + table: T::table, + passing: Passing::RvalueRef, + } } unsafe fn bind(object: *mut c_void) -> Self { diff --git a/libcc2rs/src/swap.rs b/libcc2rs/src/swap.rs index 6710f55b55..860566dcf2 100644 --- a/libcc2rs/src/swap.rs +++ b/libcc2rs/src/swap.rs @@ -79,7 +79,10 @@ pub(crate) fn copy_constructed_in_storage(src: *const T) -> T { let mut dst = std::mem::MaybeUninit::::uninit(); unsafe { - >,)>>::constructor(&mut *dst.as_mut_ptr(), (crate::LvalueRefUnsafe::bind(src),)); + >,)>>::constructor( + &mut *dst.as_mut_ptr(), + (crate::LvalueRefUnsafe::bind(src),), + ); dst.assume_init() } } diff --git a/rules/algorithm/tgt_refcount.rs b/rules/algorithm/tgt_refcount.rs index 6833fa6633..f5fde68c92 100644 --- a/rules/algorithm/tgt_refcount.rs +++ b/rules/algorithm/tgt_refcount.rs @@ -29,16 +29,31 @@ where let __first: Value = Rc::new(RefCell::new(a0)); let __last: Value = Rc::new(RefCell::new(a1)); let mut __out = a2; - while ::not_equal(__first.as_pointer(), __last.as_pointer()) { - object!(__value, T4, |__this| ConvertibleTo::convert(LvalueRef::::bind(__first.borrow().iter_deref()), __this)); - MoveAssignable::move_assign(__out.iter_deref(), RvalueRef::::bind(__value.as_pointer())); + while ::not_equal(__first.as_pointer(), __last.as_pointer()) + { + object!(__value, T4, |__this| ConvertibleTo::convert( + LvalueRef::::bind(__first.borrow().iter_deref()), + __this + )); + MoveAssignable::move_assign( + __out.iter_deref(), + RvalueRef::::bind(__value.as_pointer()), + ); __first.borrow_mut().iter_inc(); __out.iter_inc(); } __out } -fn f3, T2: WeaklyEqualityComparableWith, T3: WeaklyEqualityComparableWith>(a0: T1, a1: T1, a2: Ptr) -> T1 { +fn f3< + T1: CppInputIterator, + T2: WeaklyEqualityComparableWith, + T3: WeaklyEqualityComparableWith, +>( + a0: T1, + a1: T1, + a2: Ptr, +) -> T1 { let __it: Value = Rc::new(RefCell::new(a0)); let __last: Value = Rc::new(RefCell::new(a1)); while ::not_equal(__it.as_pointer(), __last.as_pointer()) @@ -75,7 +90,10 @@ fn f8, T2: LessThanComparable>(a0: T1, a1: T1) -> T1 { let mut __best = __it.borrow().clone(); if ::not_equal(__it.as_pointer(), __last.as_pointer()) { __it.borrow_mut().iter_inc(); - while ::not_equal(__it.as_pointer(), __last.as_pointer()) { + while ::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) { if LessThanComparable::less(__best.iter_deref(), __it.borrow().iter_deref()) { __best = __it.borrow().clone(); } @@ -89,7 +107,10 @@ fn f9(a0: Ptr, a1: Ptr) { Swappable::swap(a0, a1) } -fn f10, T2: WeaklyEqualityComparableWith + TriviallyCopyable + ByteRepr>( +fn f10< + T1: CppInputIterator, + T2: WeaklyEqualityComparableWith + TriviallyCopyable + ByteRepr, +>( a0: T1, a1: T1, ) -> T1 { @@ -100,10 +121,18 @@ fn f10, T2: WeaklyEqualityComparableWith + Triviall } else { let mut __write = __it.borrow().clone(); __it.borrow_mut().iter_inc(); - while ::not_equal(__it.as_pointer(), __last.as_pointer()) { - if !WeaklyEqualityComparableWith::equal(__write.iter_deref(), __it.borrow().iter_deref()) { + while ::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) { + if !WeaklyEqualityComparableWith::equal( + __write.iter_deref(), + __it.borrow().iter_deref(), + ) { __write.iter_inc(); - __write.iter_deref().write(__it.borrow().iter_deref().read()); + __write + .iter_deref() + .write(__it.borrow().iter_deref().read()); } __it.borrow_mut().iter_inc(); } @@ -155,11 +184,19 @@ where } fn f16(a0: Ptr, a1: Ptr) -> Ptr { - if LessThanComparable::less(a1.clone(), a0.clone()) { a1 } else { a0 } + if LessThanComparable::less(a1.clone(), a0.clone()) { + a1 + } else { + a0 + } } fn f17(a0: Ptr, a1: Ptr) -> Ptr { - if LessThanComparable::less(a0.clone(), a1.clone()) { a1 } else { a0 } + if LessThanComparable::less(a0.clone(), a1.clone()) { + a1 + } else { + a0 + } } fn f18, T2: Swappable>(a0: T1, a1: T1) { diff --git a/rules/algorithm/tgt_unsafe.rs b/rules/algorithm/tgt_unsafe.rs index 80e4abb35d..9eee9d415a 100644 --- a/rules/algorithm/tgt_unsafe.rs +++ b/rules/algorithm/tgt_unsafe.rs @@ -27,7 +27,12 @@ unsafe fn f1, T2: LessThanComparableUnsafe } } -unsafe fn f2, T2: UnsafeCppIterator, T3, T4: ZeroInitializationUnsafe + MoveAssignableUnsafe>( +unsafe fn f2< + T1: UnsafeCppInputIterator, + T2: UnsafeCppIterator, + T3, + T4: ZeroInitializationUnsafe + MoveAssignableUnsafe, +>( a0: T1, a1: T1, a2: T2, @@ -38,17 +43,33 @@ where let mut __first = a0; let mut __out = a2; while WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &a1) { - object_unsafe!(__value, T4, |__this| ConvertibleToUnsafe::convert(LvalueRefUnsafe::::bind(__first.iter_deref()), __this)); - MoveAssignableUnsafe::move_assign(__out.iter_deref(), RvalueRefUnsafe::::bind(&raw mut __value)); + object_unsafe!(__value, T4, |__this| ConvertibleToUnsafe::convert( + LvalueRefUnsafe::::bind(__first.iter_deref()), + __this + )); + MoveAssignableUnsafe::move_assign( + __out.iter_deref(), + RvalueRefUnsafe::::bind(&raw mut __value), + ); __first.iter_inc(); __out.iter_inc(); } __out } -unsafe fn f3, T2: WeaklyEqualityComparableWithUnsafe, T3: WeaklyEqualityComparableWithUnsafe>(a0: T1, a1: T1, a2: T2) -> T1 { +unsafe fn f3< + T1: UnsafeCppInputIterator, + T2: WeaklyEqualityComparableWithUnsafe, + T3: WeaklyEqualityComparableWithUnsafe, +>( + a0: T1, + a1: T1, + a2: T2, +) -> T1 { let mut __it = a0; - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &a2) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &a2) + { __it.iter_inc(); } __it @@ -86,7 +107,10 @@ unsafe fn f8, T2: LessThanComparableUnsafe>(a0: T let mut __it = a0; __it.iter_inc(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) { - if LessThanComparableUnsafe::less(__best.iter_deref() as *const _, __it.iter_deref() as *const _) { + if LessThanComparableUnsafe::less( + __best.iter_deref() as *const _, + __it.iter_deref() as *const _, + ) { __best = __it.clone(); } __it.iter_inc(); @@ -101,7 +125,13 @@ unsafe fn f9(a0: *mut T1, a1: *mut T1) { SwappableUnsafe::swap(&mut *__a, __b) } -unsafe fn f10, T2: WeaklyEqualityComparableWithUnsafe + Clone>(a0: T1, a1: T1) -> T1 { +unsafe fn f10< + T1: UnsafeCppInputIterator, + T2: WeaklyEqualityComparableWithUnsafe + Clone, +>( + a0: T1, + a1: T1, +) -> T1 { if WeaklyEqualityComparableWithUnsafe::equal(&a0, &a1) { a1 } else { @@ -109,7 +139,8 @@ unsafe fn f10, T2: WeaklyEqualityComparableWithUn let mut __it = a0; __it.iter_inc(); while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) { - if !WeaklyEqualityComparableWithUnsafe::equal(&*__write.iter_deref(), __it.iter_deref()) { + if !WeaklyEqualityComparableWithUnsafe::equal(&*__write.iter_deref(), __it.iter_deref()) + { __write.iter_inc(); *__write.iter_deref() = (*__it.iter_deref()).clone(); } @@ -163,13 +194,21 @@ where unsafe fn f16(a0: *const T1, a1: *const T1) -> *const T1 { let __a: *const _ = a0; let __b: *const _ = a1; - if LessThanComparableUnsafe::less(__b, __a) { __b } else { __a } + if LessThanComparableUnsafe::less(__b, __a) { + __b + } else { + __a + } } unsafe fn f17(a0: *const T1, a1: *const T1) -> *const T1 { let __a: *const _ = a0; let __b: *const _ = a1; - if LessThanComparableUnsafe::less(__a, __b) { __b } else { __a } + if LessThanComparableUnsafe::less(__a, __b) { + __b + } else { + __a + } } unsafe fn f18, T2: SwappableUnsafe>(a0: T1, a1: T1) { diff --git a/rules/any/tgt_refcount.rs b/rules/any/tgt_refcount.rs index ce69df1430..aa95dfe02f 100644 --- a/rules/any/tgt_refcount.rs +++ b/rules/any/tgt_refcount.rs @@ -21,7 +21,10 @@ fn f8(a0: Option>) -> bool { a0.is_some() } -fn f14(a0: &mut Option>, init: cpp_type!("std::decay_t", T1)) -> Ptr { +fn f14( + a0: &mut Option>, + init: cpp_type!("std::decay_t", T1), +) -> Ptr { let __value: Value = Rc::new(RefCell::new(init)); let __ptr = __value.as_pointer(); *a0 = Some(__value); @@ -32,9 +35,11 @@ fn f19(a0: Ptr>>) -> Ptr { if a0.is_null() { Ptr::null() } else { - a0.with(|__a: &Option>| match __a.clone().map(|__r| __r.downcast::>()) { - Some(Ok(__v)) => __v.as_pointer(), - _ => Ptr::null(), + a0.with(|__a: &Option>| { + match __a.clone().map(|__r| __r.downcast::>()) { + Some(Ok(__v)) => __v.as_pointer(), + _ => Ptr::null(), + } }) } } diff --git a/rules/any/tgt_unsafe.rs b/rules/any/tgt_unsafe.rs index 180180cbdc..93c201aa9f 100644 --- a/rules/any/tgt_unsafe.rs +++ b/rules/any/tgt_unsafe.rs @@ -19,13 +19,20 @@ fn f8(a0: Option>) -> bool { a0.is_some() } -fn f14(a0: &mut Option>, init: cpp_type!("std::decay_t", T1)) -> &mut T1 { +fn f14( + a0: &mut Option>, + init: cpp_type!("std::decay_t", T1), +) -> &mut T1 { *a0 = Some(Box::new(init)); a0.as_mut().unwrap().downcast_mut::().unwrap() } unsafe fn f19(a0: *mut Option>) -> *mut T1 { - match a0.as_mut().and_then(|__a| __a.as_mut()).and_then(|__b| __b.downcast_mut::()) { + match a0 + .as_mut() + .and_then(|__a| __a.as_mut()) + .and_then(|__b| __b.downcast_mut::()) + { Some(__v) => __v as *mut T1, None => std::ptr::null_mut(), } diff --git a/rules/array/tgt_refcount.rs b/rules/array/tgt_refcount.rs index 5ee485007d..1d05b8e527 100644 --- a/rules/array/tgt_refcount.rs +++ b/rules/array/tgt_refcount.rs @@ -6,7 +6,9 @@ use std::cell::RefCell; use std::rc::Rc; fn t1() -> Box<[T1]> { - Box::<[T1]>::from(std::array::from_fn::<_, T2, _>(|_| ::default_constructed())) + Box::<[T1]>::from(std::array::from_fn::<_, T2, _>(|_| { + ::default_constructed() + })) } fn t4() -> Ptr { @@ -32,8 +34,9 @@ fn f3(a0: Ptr) -> Ptr { fn f4( a0: Ptr, ) -> Box<[T1]> { - let __v: Value> = - Rc::new(RefCell::new((0..T2).map(|_| ZeroInitialization::zero_init()).collect())); + let __v: Value> = Rc::new(RefCell::new( + (0..T2).map(|_| ZeroInitialization::zero_init()).collect(), + )); let __p: Ptr = __v.decay(); for __i in 0..T2 { Constructor::constructor(__p.offset(__i), (RvalueRef::::bind(a0.offset(__i)),)); @@ -52,7 +55,9 @@ fn f5( } fn f6(a0: Ptr) -> Box<[T1]> { - (0..T2).map(|__i| copy_constructed(a0.offset(__i))).collect() + (0..T2) + .map(|__i| copy_constructed(a0.offset(__i))) + .collect() } fn f7( diff --git a/rules/builtin/tgt_unsafe.rs b/rules/builtin/tgt_unsafe.rs index 5ea1c5389a..5c3dd1fe18 100644 --- a/rules/builtin/tgt_unsafe.rs +++ b/rules/builtin/tgt_unsafe.rs @@ -58,7 +58,9 @@ unsafe fn f14(a0: *mut u8, a1: *const u8, a2: usize) -> *mut u8 { a0 } -fn f15() { std::process::abort() } +fn f15() { + std::process::abort() +} fn f16(a0: u64) -> i32 { a0.leading_zeros() as i32 diff --git a/rules/deque/tgt_unsafe.rs b/rules/deque/tgt_unsafe.rs index 6cbe7d4254..f912228be0 100644 --- a/rules/deque/tgt_unsafe.rs +++ b/rules/deque/tgt_unsafe.rs @@ -58,7 +58,10 @@ unsafe fn f9(a0: &mut Vec) -> Vec { move_constructed_unsafe(&mut *a0) } -unsafe fn f10<'a, T1: CopyConstructibleUnsafe>(a0: &'a mut Vec, a1: *const Vec) -> &'a mut Vec { +unsafe fn f10<'a, T1: CopyConstructibleUnsafe>( + a0: &'a mut Vec, + a1: *const Vec, +) -> &'a mut Vec { CopyAssignableUnsafe::copy_assign(&raw mut *a0, LvalueRefUnsafe::bind(a1)); a0 } diff --git a/rules/iterator_category/shim.rs b/rules/iterator_category/shim.rs index 9411c63d16..4f15125eb3 100644 --- a/rules/iterator_category/shim.rs +++ b/rules/iterator_category/shim.rs @@ -191,23 +191,18 @@ macro_rules! uninhabited_iterator { } } - - impl crate::Constructor<(crate::LvalueRef>,)> - for $name - { + impl crate::Constructor<(crate::LvalueRef>,)> for $name { fn constructor(_: Ptr, (src,): (crate::LvalueRef>,)) { src.as_pointer().with(|it| it.never()) } } - impl crate::ConstructorUnsafe<(crate::RvalueRefUnsafe,)> for $name { unsafe fn constructor(_: *mut Self, (src,): (crate::RvalueRefUnsafe,)) { unsafe { (*src.as_ptr()).never() } } } - impl crate::ConstructorUnsafe<(crate::LvalueRefUnsafe>,)> for $name { @@ -219,7 +214,6 @@ macro_rules! uninhabited_iterator { } } - impl crate::Destructible for $name { fn destroy(_: Ptr) {} } diff --git a/rules/iterator_category/tgt_refcount.rs b/rules/iterator_category/tgt_refcount.rs index ee6d7bb7ea..71e13deeba 100644 --- a/rules/iterator_category/tgt_refcount.rs +++ b/rules/iterator_category/tgt_refcount.rs @@ -135,6 +135,13 @@ fn f26, T2>(a0: &mut T1) -> &mut T1 { a0 } -fn f27 + WeaklyEqualityComparableWith, T2: CppInputIterator + WeaklyEqualityComparableWith, T3>(a0: Ptr, a1: Ptr) -> bool { +fn f27< + T1: CppInputIterator + WeaklyEqualityComparableWith, + T2: CppInputIterator + WeaklyEqualityComparableWith, + T3, +>( + a0: Ptr, + a1: Ptr, +) -> bool { WeaklyEqualityComparableWith::equal(a0, a1) } diff --git a/rules/iterator_category/tgt_unsafe.rs b/rules/iterator_category/tgt_unsafe.rs index 9e13b027fb..aadacbf262 100644 --- a/rules/iterator_category/tgt_unsafe.rs +++ b/rules/iterator_category/tgt_unsafe.rs @@ -135,6 +135,13 @@ fn f26, T2>(a0: &mut T1) -> &mut T1 { a0 } -unsafe fn f27 + WeaklyEqualityComparableWithUnsafe, T2: UnsafeCppInputIterator + WeaklyEqualityComparableWithUnsafe, T3>(a0: T1, a1: T2) -> bool { +unsafe fn f27< + T1: UnsafeCppInputIterator + WeaklyEqualityComparableWithUnsafe, + T2: UnsafeCppInputIterator + WeaklyEqualityComparableWithUnsafe, + T3, +>( + a0: T1, + a1: T2, +) -> bool { WeaklyEqualityComparableWithUnsafe::equal(&a0, &a1) } diff --git a/rules/map/tgt_refcount.rs b/rules/map/tgt_refcount.rs index e8f419967e..ceafc9f103 100644 --- a/rules/map/tgt_refcount.rs +++ b/rules/map/tgt_refcount.rs @@ -9,7 +9,10 @@ fn t1() -> Map, Value)> { Map::new() } -fn f1( +fn f1< + T1: LessThanComparable + ZeroInitialization + CopyConstructible + 'static, + T2: DefaultConstructible + ZeroInitialization + 'static, +>( a0: &mut Map, Value)>, a1: Ptr, ) -> Ptr { @@ -31,13 +34,19 @@ fn f5() -> Map, Value)> { Map::new() } -fn f6( +fn f6< + T1: LessThanComparable + CopyConstructible + ZeroInitialization + 'static, + T2: CopyConstructible + ZeroInitialization + 'static, +>( a0: Ptr, Value)>>, ) -> Map, Value)> { copy_constructed(a0) } -fn f7(a0: &mut Map, Value)>, a1: Ptr) -> Ptr { +fn f7( + a0: &mut Map, Value)>, + a1: Ptr, +) -> Ptr { a0.get(&a1).expect("out of range!").borrow().1.as_pointer() } @@ -48,35 +57,55 @@ fn f8::default_constructed()) } -fn f9(a0: Ptr, Value)>>) -> BidirectionalIterator<(Value, Value)> { +fn f9( + a0: Ptr, Value)>>, +) -> BidirectionalIterator<(Value, Value)> { a0.with(|__m: &Map, Value)>| __m.end()) } -fn f10(a0: Ptr, Value)>>, a1: Ptr) -> BidirectionalIterator<(Value, Value)> { +fn f10( + a0: Ptr, Value)>>, + a1: Ptr, +) -> BidirectionalIterator<(Value, Value)> { a0.with(|__m: &Map, Value)>| __m.find(&a1)) } -fn f12(a0: Ptr, Value)>>) -> BidirectionalIterator<(Value, Value)> { +fn f12( + a0: Ptr, Value)>>, +) -> BidirectionalIterator<(Value, Value)> { a0.with(|__m: &Map, Value)>| __m.begin()) } -fn f14(a0: Ptr, Value)>>) -> BidirectionalIterator<(Value, Value)> { +fn f14( + a0: Ptr, Value)>>, +) -> BidirectionalIterator<(Value, Value)> { a0.with(|__m: &Map, Value)>| __m.end()) } -fn f15(a0: &mut Map, Value)>, a1: Ptr) -> Ptr { +fn f15( + a0: &mut Map, Value)>, + a1: Ptr, +) -> Ptr { a0.get(&a1).expect("out of range!").borrow().1.as_pointer() } -fn f17(a0: Ptr, Value)>>, a1: Ptr) -> BidirectionalIterator<(Value, Value)> { +fn f17( + a0: Ptr, Value)>>, + a1: Ptr, +) -> BidirectionalIterator<(Value, Value)> { a0.with(|__m: &Map, Value)>| __m.find(&a1)) } -fn f24(a0: Ptr, Value)>>) -> Map, Value)> { +fn f24( + a0: Ptr, Value)>>, +) -> Map, Value)> { a0.with_mut(|__m: &mut Map, Value)>| std::mem::take(__m)) } -fn f25<'a, T1: 'static, T2: 'static>(a0: &'a mut Map, Value)>, a1: Ptr, Value)>>) -> &'a mut Map, Value)> +fn f25<'a, T1: 'static, T2: 'static>( + a0: &'a mut Map, Value)>, + a1: Ptr, Value)>>, +) -> &'a mut Map, Value)> where Map, Value)>: MoveConstructible + ZeroInitialization, { @@ -84,7 +113,10 @@ where a0 } -fn f26( +fn f26< + T1: LessThanComparable + CopyConstructible + ZeroInitialization + 'static, + T2: CopyConstructible + ZeroInitialization + 'static, +>( a0: &mut Map, Value)>, a1: Ptr, Value)>>, ) -> &mut Map, Value)> { @@ -99,26 +131,43 @@ fn f27( Map::erase(a0, &a1) } -fn f28(a0: Ptr, Value)>>, a1: Ptr) -> usize { +fn f28( + a0: Ptr, Value)>>, + a1: Ptr, +) -> usize { Map::erase_key(a0, &a1) } -fn f29(a0: Ptr, Value)>>) -> BidirectionalIterator<(Value, Value)> { +fn f29( + a0: Ptr, Value)>>, +) -> BidirectionalIterator<(Value, Value)> { a0.with(|__m: &Map, Value)>| __m.begin()) } fn f67( a0: Ptr, Value)>>, - init: cpp_type!("typename std::map::value_type", (Value, Value)), -) -> (Value, Value)>>, Value) { + init: cpp_type!( + "typename std::map::value_type", + (Value, Value) + ), +) -> ( + Value, Value)>>, + Value, +) { let (__it, __inserted) = Map::emplace(a0, &init.0.as_pointer(), || init); - (Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted))) + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) } fn f68( a0: Ptr, Value)>>, a1: BidirectionalIterator<(Value, Value)>, - init: cpp_type!("typename std::map::value_type", (Value, Value)), + init: cpp_type!( + "typename std::map::value_type", + (Value, Value) + ), ) -> BidirectionalIterator<(Value, Value)> { let _ = a1; Map::emplace(a0, &init.0.as_pointer(), || init).0 @@ -128,9 +177,18 @@ fn f73, Value)>>, a1: Ptr, init: T2, -) -> (Value, Value)>>, Value) { +) -> ( + Value, Value)>>, + Value, +) { let (__it, __inserted) = Map::emplace(a0, &a1, || { - (Rc::new(RefCell::new(copy_constructed(a1.clone()))), Rc::new(RefCell::new(init))) + ( + Rc::new(RefCell::new(copy_constructed(a1.clone()))), + Rc::new(RefCell::new(init)), + ) }); - (Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted))) + ( + Rc::new(RefCell::new(__it)), + Rc::new(RefCell::new(__inserted)), + ) } diff --git a/rules/map/tgt_unsafe.rs b/rules/map/tgt_unsafe.rs index e3194d1e71..e235a8b549 100644 --- a/rules/map/tgt_unsafe.rs +++ b/rules/map/tgt_unsafe.rs @@ -19,7 +19,13 @@ fn t6() -> T2 { unimplemented!() } -unsafe fn f1(a0: &mut UnsafeMap, a1: T1) -> &mut T2 { +unsafe fn f1< + T1: LessThanComparableUnsafe + CopyConstructibleUnsafe, + T2: DefaultConstructibleUnsafe, +>( + a0: &mut UnsafeMap, + a1: T1, +) -> &mut T2 { &mut (*a0.subscript(&a1, || ::default_constructed())) } @@ -27,7 +33,10 @@ fn f2(a0: UnsafeMap) -> usize { a0.len() } -fn f3(a0: &mut UnsafeMap, a1: UnsafeBidirectionalIterator<(T1, T2)>) -> UnsafeBidirectionalIterator<(T1, T2)> { +fn f3( + a0: &mut UnsafeMap, + a1: UnsafeBidirectionalIterator<(T1, T2)>, +) -> UnsafeBidirectionalIterator<(T1, T2)> { a0.erase(&a1) } @@ -35,23 +44,41 @@ fn f5() -> UnsafeMap { UnsafeMap::new() } -unsafe fn f6(a0: *const UnsafeMap) -> UnsafeMap { +unsafe fn f6< + T1: LessThanComparableUnsafe + CopyConstructibleUnsafe, + T2: CopyConstructibleUnsafe, +>( + a0: *const UnsafeMap, +) -> UnsafeMap { copy_constructed_unsafe(a0) } -unsafe fn f7(a0: &mut UnsafeMap, a1: T1) -> *const T2 { +unsafe fn f7( + a0: &mut UnsafeMap, + a1: T1, +) -> *const T2 { &raw const (*a0.get(&a1).expect("out of range!")).1 } -unsafe fn f8(a0: &mut UnsafeMap, a1: *mut T1) -> &mut T2 { - &mut (*a0.subscript_move(a1, |__k| cpp_move_unsafe!(__k), || ::default_constructed())) +unsafe fn f8( + a0: &mut UnsafeMap, + a1: *mut T1, +) -> &mut T2 { + &mut (*a0.subscript_move( + a1, + |__k| cpp_move_unsafe!(__k), + || ::default_constructed(), + )) } fn f9(a0: UnsafeMap) -> UnsafeBidirectionalIterator<(T1, T2)> { a0.end() } -fn f10(a0: &mut UnsafeMap, a1: T1) -> UnsafeBidirectionalIterator<(T1, T2)> { +fn f10( + a0: &mut UnsafeMap, + a1: T1, +) -> UnsafeBidirectionalIterator<(T1, T2)> { a0.find(&a1) } @@ -63,11 +90,17 @@ fn f14(a0: &mut UnsafeMap) -> UnsafeBidirectionalIterator< a0.end() } -unsafe fn f15(a0: &mut UnsafeMap, a1: T1) -> *const T2 { +unsafe fn f15( + a0: &mut UnsafeMap, + a1: T1, +) -> *const T2 { &raw const (*a0.get(&a1).expect("out of range!")).1 } -fn f17(a0: UnsafeMap, a1: T1) -> UnsafeBidirectionalIterator<(T1, T2)> { +fn f17( + a0: UnsafeMap, + a1: T1, +) -> UnsafeBidirectionalIterator<(T1, T2)> { a0.find(&a1) } @@ -75,12 +108,22 @@ unsafe fn f24(a0: &mut UnsafeMap) -> UnsafeMap(a0: &'a mut UnsafeMap, a1: &mut UnsafeMap) -> &'a mut UnsafeMap { +unsafe fn f25<'a, T1, T2>( + a0: &'a mut UnsafeMap, + a1: &mut UnsafeMap, +) -> &'a mut UnsafeMap { *a0 = move_constructed_unsafe(&mut *a1); a0 } -unsafe fn f26<'a, T1: LessThanComparableUnsafe + CopyConstructibleUnsafe, T2: CopyConstructibleUnsafe>(a0: &'a mut UnsafeMap, a1: *const UnsafeMap) -> &'a mut UnsafeMap { +unsafe fn f26< + 'a, + T1: LessThanComparableUnsafe + CopyConstructibleUnsafe, + T2: CopyConstructibleUnsafe, +>( + a0: &'a mut UnsafeMap, + a1: *const UnsafeMap, +) -> &'a mut UnsafeMap { CopyAssignableUnsafe::copy_assign(&raw mut *a0, LvalueRefUnsafe::bind(a1)); a0 } diff --git a/rules/pair/tgt_refcount.rs b/rules/pair/tgt_refcount.rs index 6cb4847b9c..1cbd23af3e 100644 --- a/rules/pair/tgt_refcount.rs +++ b/rules/pair/tgt_refcount.rs @@ -5,7 +5,10 @@ use libcc2rs::*; use std::cell::RefCell; use std::rc::Rc; -fn t1() -> (Value, Value) { +fn t1< + T1: DefaultConstructible + ZeroInitialization, + T2: DefaultConstructible + ZeroInitialization, +>() -> (Value, Value) { ( Rc::new(RefCell::new(::default_constructed())), Rc::new(RefCell::new(::default_constructed())), @@ -66,21 +69,27 @@ fn f16(a0: (Value, Value)) -> Value { a0.0 } -fn f17(a0: (Value, Value)) -> Ptr<<(T2, T3) as TupleElement>::Type> +fn f17( + a0: (Value, Value), +) -> Ptr<<(T2, T3) as TupleElement>::Type> where (T2, T3): TupleElementValue, Value)>, { a0.get_value::().as_pointer() } -fn f19(a0: (Value, Value)) -> Ptr<<(T2, T3) as TupleElement>::Type> +fn f19( + a0: (Value, Value), +) -> Ptr<<(T2, T3) as TupleElement>::Type> where (T2, T3): TupleElementValue, Value)>, { a0.get_value::().as_pointer() } -fn f21(a0: (Value, Value)) -> Ptr<<(T2, T3) as TupleElement>::Type> +fn f21( + a0: (Value, Value), +) -> Ptr<<(T2, T3) as TupleElement>::Type> where (T2, T3): TupleElementValue, Value)>, { @@ -95,8 +104,14 @@ fn f23< >( a0: &mut (Value, Value), ) -> (Value, Value) { - object!(__first, T1, |__this| ConstructibleFrom::construct(__this, (RvalueRef::::bind(a0.0.as_pointer()),))); - object!(__second, T2, |__this| ConstructibleFrom::construct(__this, (RvalueRef::::bind(a0.1.as_pointer()),))); + object!(__first, T1, |__this| ConstructibleFrom::construct( + __this, + (RvalueRef::::bind(a0.0.as_pointer()),) + )); + object!(__second, T2, |__this| ConstructibleFrom::construct( + __this, + (RvalueRef::::bind(a0.1.as_pointer()),) + )); ( Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), @@ -111,8 +126,14 @@ fn f24< >( a0: (Value, Value), ) -> (Value, Value) { - object!(__first, T1, |__this| ConstructibleFrom::construct(__this, (LvalueRef::>::bind(a0.0.as_pointer()),))); - object!(__second, T2, |__this| ConstructibleFrom::construct(__this, (LvalueRef::>::bind(a0.1.as_pointer()),))); + object!(__first, T1, |__this| ConstructibleFrom::construct( + __this, + (LvalueRef::>::bind(a0.0.as_pointer()),) + )); + object!(__second, T2, |__this| ConstructibleFrom::construct( + __this, + (LvalueRef::>::bind(a0.1.as_pointer()),) + )); ( Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), @@ -132,15 +153,28 @@ where LvalueRef>: ConvertibleTo, LvalueRef>: ConvertibleTo, { - object!(__first, T1, |__this| ConvertibleTo::convert(LvalueRef::>::bind(a1.0.as_pointer()), __this)); - object!(__second, T2, |__this| ConvertibleTo::convert(LvalueRef::>::bind(a1.1.as_pointer()), __this)); - MoveAssignable::move_assign(a0.0.as_pointer(), RvalueRef::::bind(__first.as_pointer())); - MoveAssignable::move_assign(a0.1.as_pointer(), RvalueRef::::bind(__second.as_pointer())); + object!(__first, T1, |__this| ConvertibleTo::convert( + LvalueRef::>::bind(a1.0.as_pointer()), + __this + )); + object!(__second, T2, |__this| ConvertibleTo::convert( + LvalueRef::>::bind(a1.1.as_pointer()), + __this + )); + MoveAssignable::move_assign( + a0.0.as_pointer(), + RvalueRef::::bind(__first.as_pointer()), + ); + MoveAssignable::move_assign( + a0.1.as_pointer(), + RvalueRef::::bind(__second.as_pointer()), + ); a0 } fn f26< - 'a, T1: ZeroInitialization + MoveAssignable, + 'a, + T1: ZeroInitialization + MoveAssignable, T2: ZeroInitialization + MoveAssignable, T3: ByteRepr, T4: ByteRepr, @@ -152,22 +186,40 @@ where RvalueRef: ConvertibleTo, RvalueRef: ConvertibleTo, { - object!(__first, T1, |__this| ConvertibleTo::convert(RvalueRef::::bind(a1.0.as_pointer()), __this)); - object!(__second, T2, |__this| ConvertibleTo::convert(RvalueRef::::bind(a1.1.as_pointer()), __this)); - MoveAssignable::move_assign(a0.0.as_pointer(), RvalueRef::::bind(__first.as_pointer())); - MoveAssignable::move_assign(a0.1.as_pointer(), RvalueRef::::bind(__second.as_pointer())); + object!(__first, T1, |__this| ConvertibleTo::convert( + RvalueRef::::bind(a1.0.as_pointer()), + __this + )); + object!(__second, T2, |__this| ConvertibleTo::convert( + RvalueRef::::bind(a1.1.as_pointer()), + __this + )); + MoveAssignable::move_assign( + a0.0.as_pointer(), + RvalueRef::::bind(__first.as_pointer()), + ); + MoveAssignable::move_assign( + a0.1.as_pointer(), + RvalueRef::::bind(__second.as_pointer()), + ); a0 } -fn f27(a0: (Value, Value)) -> Ptr<<(T2, T3) as TupleElement>::Type> +fn f27( + a0: (Value, Value), +) -> Ptr<<(T2, T3) as TupleElement>::Type> where (T2, T3): TupleElementValue, Value)>, { a0.get_value::().as_pointer() } -fn f28, T2: WeaklyEqualityComparableWith>(a0: (Value, Value), a1: (Value, Value)) -> bool { - !(WeaklyEqualityComparableWith::equal(a0.0.as_pointer(), a1.0.as_pointer()) && WeaklyEqualityComparableWith::equal(a0.1.as_pointer(), a1.1.as_pointer())) +fn f28, T2: WeaklyEqualityComparableWith>( + a0: (Value, Value), + a1: (Value, Value), +) -> bool { + !(WeaklyEqualityComparableWith::equal(a0.0.as_pointer(), a1.0.as_pointer()) + && WeaklyEqualityComparableWith::equal(a0.1.as_pointer(), a1.1.as_pointer())) } fn f34< @@ -178,30 +230,52 @@ fn f34< >( a0: &mut (Value, Value), ) -> (Value, Value) { - object!(__first, T1, |__this| ConstructibleFrom::construct(__this, (LvalueRef::::bind(a0.0.as_pointer()),))); - object!(__second, T2, |__this| ConstructibleFrom::construct(__this, (LvalueRef::::bind(a0.1.as_pointer()),))); + object!(__first, T1, |__this| ConstructibleFrom::construct( + __this, + (LvalueRef::::bind(a0.0.as_pointer()),) + )); + object!(__second, T2, |__this| ConstructibleFrom::construct( + __this, + (LvalueRef::::bind(a0.1.as_pointer()),) + )); ( Rc::new(RefCell::new(move_constructed(&__first.as_pointer()))), Rc::new(RefCell::new(move_constructed(&__second.as_pointer()))), ) } -fn f29(a0: Ptr<(Value, Value)>, a1: Ptr<(Value, Value)>) -> bool { +fn f29( + a0: Ptr<(Value, Value)>, + a1: Ptr<(Value, Value)>, +) -> bool { LessThanComparable::less(a0, a1) } -fn f30(a0: Ptr<(Value, Value)>, a1: Ptr<(Value, Value)>) -> bool { +fn f30( + a0: Ptr<(Value, Value)>, + a1: Ptr<(Value, Value)>, +) -> bool { !LessThanComparable::less(a1, a0) } -fn f31(a0: Ptr<(Value, Value)>, a1: Ptr<(Value, Value)>) -> bool { +fn f31( + a0: Ptr<(Value, Value)>, + a1: Ptr<(Value, Value)>, +) -> bool { LessThanComparable::less(a1, a0) } -fn f32(a0: Ptr<(Value, Value)>, a1: Ptr<(Value, Value)>) -> bool { +fn f32( + a0: Ptr<(Value, Value)>, + a1: Ptr<(Value, Value)>, +) -> bool { !LessThanComparable::less(a0, a1) } -fn f33, T2: WeaklyEqualityComparableWith>(a0: (Value, Value), a1: (Value, Value)) -> bool { - WeaklyEqualityComparableWith::equal(a0.0.as_pointer(), a1.0.as_pointer()) && WeaklyEqualityComparableWith::equal(a0.1.as_pointer(), a1.1.as_pointer()) +fn f33, T2: WeaklyEqualityComparableWith>( + a0: (Value, Value), + a1: (Value, Value), +) -> bool { + WeaklyEqualityComparableWith::equal(a0.0.as_pointer(), a1.0.as_pointer()) + && WeaklyEqualityComparableWith::equal(a0.1.as_pointer(), a1.1.as_pointer()) } diff --git a/rules/pair/tgt_unsafe.rs b/rules/pair/tgt_unsafe.rs index 89fe8de6c2..0a41887c0e 100644 --- a/rules/pair/tgt_unsafe.rs +++ b/rules/pair/tgt_unsafe.rs @@ -15,8 +15,13 @@ fn t3() -> T2 { unimplemented!() } -unsafe fn f2(a0: *const (T1, T2)) -> (T1, T2) { - (copy_constructed_unsafe(&raw const (*a0).0), copy_constructed_unsafe(&raw const (*a0).1)) +unsafe fn f2( + a0: *const (T1, T2), +) -> (T1, T2) { + ( + copy_constructed_unsafe(&raw const (*a0).0), + copy_constructed_unsafe(&raw const (*a0).1), + ) } fn f7(a0: T1, a1: T2) -> (T1, T2) { (a0, a1) @@ -32,13 +37,19 @@ unsafe fn f12(a0: &mut (T1, T2)) -> (T1, T2) { (cpp_move_unsafe!(&mut a0.0), cpp_move_unsafe!(&mut a0.1)) } -unsafe fn f13<'a, T1: CopyAssignableUnsafe, T2: CopyAssignableUnsafe>(a0: &'a mut (T1, T2), a1: *const (T1, T2)) -> &'a mut (T1, T2) { +unsafe fn f13<'a, T1: CopyAssignableUnsafe, T2: CopyAssignableUnsafe>( + a0: &'a mut (T1, T2), + a1: *const (T1, T2), +) -> &'a mut (T1, T2) { assign_unsafe!(a0.0 = (*a1).0); assign_unsafe!(a0.1 = (*a1).1); a0 } -unsafe fn f14<'a, T1: MoveAssignableUnsafe, T2: MoveAssignableUnsafe>(a0: &'a mut (T1, T2), a1: &mut (T1, T2)) -> &'a mut (T1, T2) { +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 = RvalueRefUnsafe(a1.0)); assign_unsafe!(a0.1 = RvalueRefUnsafe(a1.1)); a0 @@ -73,39 +84,115 @@ where &mut *a0.get_mut::() } -unsafe fn f23,)> + ZeroInitializationUnsafe + MoveConstructibleUnsafe, T2: ConstructibleFromUnsafe<(RvalueRefUnsafe,)> + ZeroInitializationUnsafe + MoveConstructibleUnsafe, T3, T4>(a0: &mut (T3, T4)) -> (T1, T2) { - object_unsafe!(__first, T1, |__this| ConstructibleFromUnsafe::construct(__this, (RvalueRefUnsafe::::bind(&raw mut a0.0),))); - object_unsafe!(__second, T2, |__this| ConstructibleFromUnsafe::construct(__this, (RvalueRefUnsafe::::bind(&raw mut a0.1),))); - (move_constructed_unsafe(&raw mut __first), move_constructed_unsafe(&raw mut __second)) +unsafe fn f23< + T1: ConstructibleFromUnsafe<(RvalueRefUnsafe,)> + + ZeroInitializationUnsafe + + MoveConstructibleUnsafe, + T2: ConstructibleFromUnsafe<(RvalueRefUnsafe,)> + + ZeroInitializationUnsafe + + MoveConstructibleUnsafe, + T3, + T4, +>( + a0: &mut (T3, T4), +) -> (T1, T2) { + object_unsafe!(__first, T1, |__this| ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut a0.0),) + )); + object_unsafe!(__second, T2, |__this| ConstructibleFromUnsafe::construct( + __this, + (RvalueRefUnsafe::::bind(&raw mut a0.1),) + )); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) } -unsafe fn f24>,)> + ZeroInitializationUnsafe + MoveConstructibleUnsafe, T2: ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> + ZeroInitializationUnsafe + MoveConstructibleUnsafe, T3, T4>(a0: &(T3, T4)) -> (T1, T2) { - object_unsafe!(__first, T1, |__this| ConstructibleFromUnsafe::construct(__this, (LvalueRefUnsafe::>::bind(&raw const a0.0),))); - object_unsafe!(__second, T2, |__this| ConstructibleFromUnsafe::construct(__this, (LvalueRefUnsafe::>::bind(&raw const a0.1),))); - (move_constructed_unsafe(&raw mut __first), move_constructed_unsafe(&raw mut __second)) +unsafe fn f24< + T1: ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> + + ZeroInitializationUnsafe + + MoveConstructibleUnsafe, + T2: ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> + + ZeroInitializationUnsafe + + MoveConstructibleUnsafe, + T3, + T4, +>( + a0: &(T3, T4), +) -> (T1, T2) { + object_unsafe!(__first, T1, |__this| ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::>::bind(&raw const a0.0),) + )); + object_unsafe!(__second, T2, |__this| ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::>::bind(&raw const a0.1),) + )); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) } -unsafe fn f25<'a, T1: ZeroInitializationUnsafe + MoveAssignableUnsafe, T2: ZeroInitializationUnsafe + MoveAssignableUnsafe, T3, T4>(a0: &'a mut (T1, T2), a1: &(T3, T4)) -> &'a mut (T1, T2) +unsafe fn f25< + 'a, + T1: ZeroInitializationUnsafe + MoveAssignableUnsafe, + T2: ZeroInitializationUnsafe + MoveAssignableUnsafe, + T3, + T4, +>( + a0: &'a mut (T1, T2), + a1: &(T3, T4), +) -> &'a mut (T1, T2) where LvalueRefUnsafe>: ConvertibleToUnsafe, LvalueRefUnsafe>: ConvertibleToUnsafe, { - object_unsafe!(__first, T1, |__this| ConvertibleToUnsafe::convert(LvalueRefUnsafe::>::bind(&raw const a1.0), __this)); - object_unsafe!(__second, T2, |__this| ConvertibleToUnsafe::convert(LvalueRefUnsafe::>::bind(&raw const a1.1), __this)); + object_unsafe!(__first, T1, |__this| ConvertibleToUnsafe::convert( + LvalueRefUnsafe::>::bind(&raw const a1.0), + __this + )); + object_unsafe!(__second, T2, |__this| ConvertibleToUnsafe::convert( + LvalueRefUnsafe::>::bind(&raw const a1.1), + __this + )); MoveAssignableUnsafe::move_assign(&raw mut a0.0, RvalueRefUnsafe::::bind(&raw mut __first)); - MoveAssignableUnsafe::move_assign(&raw mut a0.1, RvalueRefUnsafe::::bind(&raw mut __second)); + MoveAssignableUnsafe::move_assign( + &raw mut a0.1, + RvalueRefUnsafe::::bind(&raw mut __second), + ); a0 } -unsafe fn f26<'a, T1: ZeroInitializationUnsafe + MoveAssignableUnsafe, T2: ZeroInitializationUnsafe + MoveAssignableUnsafe, T3, T4>(a0: &'a mut (T1, T2), a1: &mut (T3, T4)) -> &'a mut (T1, T2) +unsafe fn f26< + 'a, + T1: ZeroInitializationUnsafe + MoveAssignableUnsafe, + T2: ZeroInitializationUnsafe + MoveAssignableUnsafe, + T3, + T4, +>( + a0: &'a mut (T1, T2), + a1: &mut (T3, T4), +) -> &'a mut (T1, T2) where RvalueRefUnsafe: ConvertibleToUnsafe, RvalueRefUnsafe: ConvertibleToUnsafe, { - object_unsafe!(__first, T1, |__this| ConvertibleToUnsafe::convert(RvalueRefUnsafe::::bind(&raw mut a1.0), __this)); - object_unsafe!(__second, T2, |__this| ConvertibleToUnsafe::convert(RvalueRefUnsafe::::bind(&raw mut a1.1), __this)); + object_unsafe!(__first, T1, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut a1.0), + __this + )); + object_unsafe!(__second, T2, |__this| ConvertibleToUnsafe::convert( + RvalueRefUnsafe::::bind(&raw mut a1.1), + __this + )); MoveAssignableUnsafe::move_assign(&raw mut a0.0, RvalueRefUnsafe::::bind(&raw mut __first)); - MoveAssignableUnsafe::move_assign(&raw mut a0.1, RvalueRefUnsafe::::bind(&raw mut __second)); + MoveAssignableUnsafe::move_assign( + &raw mut a0.1, + RvalueRefUnsafe::::bind(&raw mut __second), + ); a0 } @@ -116,32 +203,78 @@ where &*a0.get::() } -unsafe fn f28, T2: WeaklyEqualityComparableWithUnsafe>(a0: (T1, T2), a1: (T1, T2)) -> bool { - !(WeaklyEqualityComparableWithUnsafe::equal(&a0.0, &a1.0) && WeaklyEqualityComparableWithUnsafe::equal(&a0.1, &a1.1)) +unsafe fn f28< + T1: WeaklyEqualityComparableWithUnsafe, + T2: WeaklyEqualityComparableWithUnsafe, +>( + a0: (T1, T2), + a1: (T1, T2), +) -> bool { + !(WeaklyEqualityComparableWithUnsafe::equal(&a0.0, &a1.0) + && WeaklyEqualityComparableWithUnsafe::equal(&a0.1, &a1.1)) } -unsafe fn f29(a0: (T1, T2), a1: (T1, T2)) -> bool { +unsafe fn f29( + a0: (T1, T2), + a1: (T1, T2), +) -> bool { LessThanComparableUnsafe::less(&a0, &a1) } -unsafe fn f30(a0: (T1, T2), a1: (T1, T2)) -> bool { +unsafe fn f30( + a0: (T1, T2), + a1: (T1, T2), +) -> bool { !LessThanComparableUnsafe::less(&a1, &a0) } -unsafe fn f31(a0: (T1, T2), a1: (T1, T2)) -> bool { +unsafe fn f31( + a0: (T1, T2), + a1: (T1, T2), +) -> bool { LessThanComparableUnsafe::less(&a1, &a0) } -unsafe fn f32(a0: (T1, T2), a1: (T1, T2)) -> bool { +unsafe fn f32( + a0: (T1, T2), + a1: (T1, T2), +) -> bool { !LessThanComparableUnsafe::less(&a0, &a1) } -unsafe fn f33, T2: WeaklyEqualityComparableWithUnsafe>(a0: (T1, T2), a1: (T1, T2)) -> bool { - WeaklyEqualityComparableWithUnsafe::equal(&a0.0, &a1.0) && WeaklyEqualityComparableWithUnsafe::equal(&a0.1, &a1.1) +unsafe fn f33< + T1: WeaklyEqualityComparableWithUnsafe, + T2: WeaklyEqualityComparableWithUnsafe, +>( + a0: (T1, T2), + a1: (T1, T2), +) -> bool { + WeaklyEqualityComparableWithUnsafe::equal(&a0.0, &a1.0) + && WeaklyEqualityComparableWithUnsafe::equal(&a0.1, &a1.1) } -unsafe fn f34,)> + ZeroInitializationUnsafe + MoveConstructibleUnsafe, T2: ConstructibleFromUnsafe<(LvalueRefUnsafe,)> + ZeroInitializationUnsafe + MoveConstructibleUnsafe, T3, T4>(a0: &mut (T3, T4)) -> (T1, T2) { - object_unsafe!(__first, T1, |__this| ConstructibleFromUnsafe::construct(__this, (LvalueRefUnsafe::::bind(&raw mut a0.0),))); - object_unsafe!(__second, T2, |__this| ConstructibleFromUnsafe::construct(__this, (LvalueRefUnsafe::::bind(&raw mut a0.1),))); - (move_constructed_unsafe(&raw mut __first), move_constructed_unsafe(&raw mut __second)) +unsafe fn f34< + T1: ConstructibleFromUnsafe<(LvalueRefUnsafe,)> + + ZeroInitializationUnsafe + + MoveConstructibleUnsafe, + T2: ConstructibleFromUnsafe<(LvalueRefUnsafe,)> + + ZeroInitializationUnsafe + + MoveConstructibleUnsafe, + T3, + T4, +>( + a0: &mut (T3, T4), +) -> (T1, T2) { + object_unsafe!(__first, T1, |__this| ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::::bind(&raw mut a0.0),) + )); + object_unsafe!(__second, T2, |__this| ConstructibleFromUnsafe::construct( + __this, + (LvalueRefUnsafe::::bind(&raw mut a0.1),) + )); + ( + move_constructed_unsafe(&raw mut __first), + move_constructed_unsafe(&raw mut __second), + ) } diff --git a/rules/string/tgt_refcount.rs b/rules/string/tgt_refcount.rs index 0bf2871b62..e935317108 100644 --- a/rules/string/tgt_refcount.rs +++ b/rules/string/tgt_refcount.rs @@ -132,7 +132,8 @@ fn f2(a0: Vec) -> usize { fn f8(a0: std::fs::File, a1: std::fs::File) -> Vec { use std::io::Read; let mut __bytes: Vec = Vec::new(); - (&a0).read_to_end(&mut __bytes) + (&a0) + .read_to_end(&mut __bytes) .expect("couldn't read the file"); __bytes.push(0); CChar::from_byte_vec(__bytes) diff --git a/rules/string/tgt_unsafe.rs b/rules/string/tgt_unsafe.rs index 74b4cc5cd5..bae4283701 100644 --- a/rules/string/tgt_unsafe.rs +++ b/rules/string/tgt_unsafe.rs @@ -46,7 +46,11 @@ unsafe fn f3(a0: Vec, a1: *const libc::c_char) -> Vec, a1: *mut libc::c_char, a2: usize) -> &mut Vec { +unsafe fn f4( + a0: &mut Vec, + a1: *mut libc::c_char, + a2: usize, +) -> &mut Vec { a0.splice(a0.len().saturating_sub(1)..a0.len(), { let mut v = ::std::slice::from_raw_parts(a1, a2).to_vec(); v.push(0); @@ -73,7 +77,8 @@ use std::io::Read; fn f8(a0: std::fs::File, a1: std::fs::File) -> Vec { let mut __bytes: Vec = Vec::new(); - (&a0).read_to_end(&mut __bytes) + (&a0) + .read_to_end(&mut __bytes) .expect("couldn't read the file"); let mut __buf: Vec = __bytes.iter().map(|&b| b as libc::c_char).collect(); __buf.push(0); @@ -108,10 +113,7 @@ unsafe fn f14( a3: *const libc::c_char, a4: usize, ) -> &mut Vec { - a0.splice( - a1..a1 + a2, - ::std::slice::from_raw_parts(a3, a4).to_vec(), - ); + a0.splice(a1..a1 + a2, ::std::slice::from_raw_parts(a3, a4).to_vec()); a0 } unsafe fn f15(a0: &mut Vec) -> UnsafeRandomAccessIterator { @@ -190,7 +192,10 @@ fn f29(a0: &mut Vec, a1: Vec) -> &mut Vec(a0: &'a mut Vec, a1: &mut Vec) -> &'a mut Vec { +unsafe fn f30<'a>( + a0: &'a mut Vec, + a1: &mut Vec, +) -> &'a mut Vec { *a0 = move_constructed_unsafe(&mut *a1); a0 } diff --git a/rules/unique_ptr/shim.rs b/rules/unique_ptr/shim.rs index d6303b16d9..d58bd8c070 100644 --- a/rules/unique_ptr/shim.rs +++ b/rules/unique_ptr/shim.rs @@ -2,8 +2,8 @@ // Distributed under the MIT license that can be found in the LICENSE file. use crate::{ - ByteRepr, Constructor, ConstructorUnsafe, MoveAssignable, MoveAssignableUnsafe, Ptr, - RvalueRef, RvalueRefUnsafe, Swappable, SwappableUnsafe, Value, + ByteRepr, Constructor, ConstructorUnsafe, MoveAssignable, MoveAssignableUnsafe, Ptr, RvalueRef, + RvalueRefUnsafe, Swappable, SwappableUnsafe, Value, }; pub trait CppArray {} @@ -28,7 +28,6 @@ where } } - impl MoveAssignable for Option> where Self: ByteRepr, @@ -47,7 +46,6 @@ impl ConstructorUnsafe<(RvalueRefUnsafe,)> for Option> { } } - impl MoveAssignableUnsafe for Option> { unsafe fn move_assign(this: *mut Self, src: RvalueRefUnsafe) -> *mut Self { let src = src.as_ptr(); diff --git a/rules/unique_ptr/tgt_refcount.rs b/rules/unique_ptr/tgt_refcount.rs index 720613af41..77f04a8294 100644 --- a/rules/unique_ptr/tgt_refcount.rs +++ b/rules/unique_ptr/tgt_refcount.rs @@ -21,9 +21,13 @@ fn t4() -> Ptr { Ptr::null() } -fn f1, T2: DefaultConstructible + ZeroInitialization>(a0: usize) -> Option>> { +fn f1, T2: DefaultConstructible + ZeroInitialization>( + a0: usize, +) -> Option>> { Some(Rc::new(RefCell::new( - (0..a0).map(|_| ::default_constructed()).collect::>(), + (0..a0) + .map(|_| ::default_constructed()) + .collect::>(), ))) } @@ -79,7 +83,10 @@ fn f13(a0: &mut Option>>) -> Option>> { a0.take() } -fn f14<'a, T1>(a0: &'a mut Option>, a1: &mut Option>) -> &'a mut Option> { +fn f14<'a, T1>( + a0: &'a mut Option>, + a1: &mut Option>, +) -> &'a mut Option> { *a0 = a1.take(); a0 } diff --git a/rules/unique_ptr/tgt_unsafe.rs b/rules/unique_ptr/tgt_unsafe.rs index 890282930e..589ba13b50 100644 --- a/rules/unique_ptr/tgt_unsafe.rs +++ b/rules/unique_ptr/tgt_unsafe.rs @@ -20,7 +20,11 @@ fn t4() -> *mut T1 { } fn f1, T2: DefaultConstructibleUnsafe>(a0: usize) -> Option> { - Some((0..a0).map(|_| ::default_constructed()).collect::>()) + Some( + (0..a0) + .map(|_| ::default_constructed()) + .collect::>(), + ) } fn f2(a0: &mut Option>) -> *mut T1 { a0.as_deref_mut() diff --git a/rules/vector/shim.rs b/rules/vector/shim.rs index 0a0c7811e4..c0da3b1770 100644 --- a/rules/vector/shim.rs +++ b/rules/vector/shim.rs @@ -2,10 +2,10 @@ // Distributed under the MIT license that can be found in the LICENSE file. use crate::{ - ArgRepr, ByteRepr, Const, Constructor, ConstructorUnsafe, CopyAssignable, - CopyAssignableUnsafe, CopyConstructible, CopyConstructibleUnsafe, FnPtrArg, LvalueRef, - LvalueRefUnsafe, MoveConstructibleUnsafe, Ptr, RvalueRefUnsafe, ZeroInitialization, - copy_constructed_unsafe, record_from_repr, + ArgRepr, ByteRepr, Const, Constructor, ConstructorUnsafe, CopyAssignable, CopyAssignableUnsafe, + CopyConstructible, CopyConstructibleUnsafe, FnPtrArg, LvalueRef, LvalueRefUnsafe, + MoveConstructibleUnsafe, Ptr, RvalueRefUnsafe, ZeroInitialization, copy_constructed_unsafe, + record_from_repr, }; impl ByteRepr for Vec {} @@ -33,8 +33,8 @@ impl crate::DestructibleUnsafe for Vec { } // A vector is copied by copying its elements, each with its copy constructor. -impl - Constructor<(LvalueRef>,)> for Vec +impl Constructor<(LvalueRef>,)> + for Vec { fn constructor(this: Ptr, (src,): (LvalueRef>,)) { this.write(T::copied_elems(&src.as_pointer())); @@ -125,9 +125,7 @@ unsafe fn copied_elems_unsafe(src: *const Vec) -> } } -impl ConstructorUnsafe<(LvalueRefUnsafe>,)> - for Vec -{ +impl ConstructorUnsafe<(LvalueRefUnsafe>,)> for Vec { unsafe fn constructor(this: *mut Self, (src,): (LvalueRefUnsafe>,)) { let src = src.as_const_ptr(); unsafe { std::ptr::write(this, copied_elems_unsafe(src)) } diff --git a/rules/vector/tgt_refcount.rs b/rules/vector/tgt_refcount.rs index ce48434032..57fb717d39 100644 --- a/rules/vector/tgt_refcount.rs +++ b/rules/vector/tgt_refcount.rs @@ -64,14 +64,17 @@ fn f73(a0: Ptr>, MoveConstructible::push_moved(&a0, a1) } - fn f76(a0: Ptr) -> RandomAccessIterator { a0.end() } // The source is read before the vector is borrowed, as it may be in the same // object. -fn f77(a0: &mut Vec, a1: RandomAccessIterator, a2: Ptr) -> RandomAccessIterator { +fn f77( + a0: &mut Vec, + a1: RandomAccessIterator, + a2: Ptr, +) -> RandomAccessIterator { let __a2 = move_constructed(&a2); a0.insert(a1.index(), __a2); a1 @@ -81,7 +84,11 @@ fn f78(a0: usize, a1: Ptr) -> Ve (0..a0).map(|_| copy_constructed(a1.clone())).collect() } -fn f79(a0: &mut Vec, a1: RandomAccessIterator, a2: Ptr) -> RandomAccessIterator { +fn f79( + a0: &mut Vec, + a1: RandomAccessIterator, + a2: Ptr, +) -> RandomAccessIterator { let __a2 = copy_constructed(a2); a0.insert(a1.index(), __a2); a1 @@ -91,14 +98,25 @@ fn f80(a0: Ptr>, CopyConstructible::push_copied(&a0, a1) } -fn f92>,)> + ZeroInitialization + ByteRepr, T2, T3: CppInputIterator, T4: ByteRepr>(a0: T3, a1: T3) -> Vec { +fn f92< + T1: ConstructibleFrom<(LvalueRef>,)> + ZeroInitialization + ByteRepr, + T2, + T3: CppInputIterator, + T4: ByteRepr, +>( + a0: T3, + a1: T3, +) -> Vec { let __v: Value> = Rc::new(RefCell::new(Vec::new())); let __it: Value = Rc::new(RefCell::new(a0)); let __last: Value = Rc::new(RefCell::new(a1)); while ::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = __v.borrow().len(); __v.borrow_mut().push(ZeroInitialization::zero_init()); - ConstructibleFrom::construct(__v.as_pointer().decay().offset(__i), (LvalueRef::>::bind(__it.borrow().iter_deref()),)); + ConstructibleFrom::construct( + __v.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -132,7 +150,12 @@ fn f99(a0: &Vec) -> &T1 { &a0[__n] } -fn f101>,)> + ZeroInitialization + ByteRepr, T2, T3: CppInputIterator, T4: ByteRepr>( +fn f101< + T1: ConstructibleFrom<(LvalueRef>,)> + ZeroInitialization + ByteRepr, + T2, + T3: CppInputIterator, + T4: ByteRepr, +>( a0: Ptr>, a1: RandomAccessIterator, a2: T3, @@ -145,11 +168,17 @@ fn f101>,)> + ZeroInitialization + By while ::not_equal(__it.as_pointer(), __last.as_pointer()) { let __i = temp_vec.borrow().len(); temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); - ConstructibleFrom::construct(temp_vec.as_pointer().decay().offset(__i), (LvalueRef::>::bind(__it.borrow().iter_deref()),)); + ConstructibleFrom::construct( + temp_vec.as_pointer().decay().offset(__i), + (LvalueRef::>::bind(__it.borrow().iter_deref()),), + ); __it.borrow_mut().iter_inc(); } a0.with_mut(|v: &mut Vec| { - v.splice(start_idx..start_idx, Rc::try_unwrap(temp_vec).ok().unwrap().into_inner()); + v.splice( + start_idx..start_idx, + Rc::try_unwrap(temp_vec).ok().unwrap().into_inner(), + ); }); a1 } @@ -185,14 +214,23 @@ where copy_constructed(a0) } -fn f115(a0: &mut Vec, a1: RandomAccessIterator, a2: usize, a3: Ptr) -> RandomAccessIterator { +fn f115( + a0: &mut Vec, + a1: RandomAccessIterator, + a2: usize, + a3: Ptr, +) -> RandomAccessIterator { let __off = a1.index(); let __copies: Vec = (0..a2).map(|_| copy_constructed(a3.clone())).collect(); a0.splice(__off..__off, __copies); a1 } -fn f116(a0: &mut Vec, a1: RandomAccessIterator, a2: Vec) -> RandomAccessIterator { +fn f116( + a0: &mut Vec, + a1: RandomAccessIterator, + a2: Vec, +) -> RandomAccessIterator { let __off = a1.index(); a0.splice(__off..__off, a2); a1 diff --git a/rules/vector/tgt_unsafe.rs b/rules/vector/tgt_unsafe.rs index a347944fd0..505f41b0b7 100644 --- a/rules/vector/tgt_unsafe.rs +++ b/rules/vector/tgt_unsafe.rs @@ -126,7 +126,11 @@ fn f76(a0: &mut Vec) -> UnsafeRandomAccessIterator { } // The insertion may reallocate, so a1 may no longer point into a0. -unsafe fn f77(a0: &mut Vec, a1: UnsafeRandomAccessIterator, a2: *mut T1) -> UnsafeRandomAccessIterator { +unsafe fn f77( + a0: &mut Vec, + a1: UnsafeRandomAccessIterator, + a2: *mut T1, +) -> UnsafeRandomAccessIterator { let pos = a1.iter_distance(&UnsafeRandomAccessIterator::Vec(a0.as_mut_ptr())) as usize; UnsafeRandomAccessIterator::Vec(a0.insert_mut(pos, move_constructed_unsafe(&mut *a2))) } @@ -136,7 +140,11 @@ unsafe fn f78(a0: usize, a1: *const T1) -> Vec } // The insertion may reallocate, so a1 may no longer point into a0. -unsafe fn f79(a0: &mut Vec, a1: UnsafeRandomAccessIterator, a2: *const T1) -> UnsafeRandomAccessIterator { +unsafe fn f79( + a0: &mut Vec, + a1: UnsafeRandomAccessIterator, + a2: *const T1, +) -> UnsafeRandomAccessIterator { let pos = a1.iter_distance(&UnsafeRandomAccessIterator::Vec(a0.as_mut_ptr())) as usize; UnsafeRandomAccessIterator::Vec(a0.insert_mut(pos, copy_constructed_unsafe(a2))) } @@ -149,12 +157,23 @@ fn f91(a0: Vec) -> Vec { a0 } -unsafe fn f92>,)> + ZeroInitializationUnsafe, T2, T3: UnsafeCppInputIterator, T4>(a0: T3, a1: T3) -> Vec { +unsafe fn f92< + T1: ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> + ZeroInitializationUnsafe, + T2, + T3: UnsafeCppInputIterator, + T4, +>( + a0: T3, + a1: T3, +) -> Vec { let mut __v: Vec = Vec::new(); let mut __it = a0; while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) { __v.push(ZeroInitializationUnsafe::zero_init()); - ConstructibleFromUnsafe::construct(__v.as_mut_ptr().add(__v.len() - 1), (LvalueRefUnsafe::>::bind(__it.iter_deref()),)); + ConstructibleFromUnsafe::construct( + __v.as_mut_ptr().add(__v.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } __v @@ -185,7 +204,12 @@ fn f99(a0: &Vec) -> &T1 { &a0[__n] } -unsafe fn f101>,)> + ZeroInitializationUnsafe, T2, T3: UnsafeCppInputIterator, T4>( +unsafe fn f101< + T1: ConstructibleFromUnsafe<(LvalueRefUnsafe>,)> + ZeroInitializationUnsafe, + T2, + T3: UnsafeCppInputIterator, + T4, +>( a0: &mut Vec, a1: UnsafeRandomAccessIterator, a2: T3, @@ -196,7 +220,10 @@ unsafe fn f101>,)> + Zero let mut __it = a2; while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a3) { __tmp.push(ZeroInitializationUnsafe::zero_init()); - ConstructibleFromUnsafe::construct(__tmp.as_mut_ptr().add(__tmp.len() - 1), (LvalueRefUnsafe::>::bind(__it.iter_deref()),)); + ConstructibleFromUnsafe::construct( + __tmp.as_mut_ptr().add(__tmp.len() - 1), + (LvalueRefUnsafe::>::bind(__it.iter_deref()),), + ); __it.iter_inc(); } a0.splice(__off..__off, __tmp); @@ -223,7 +250,10 @@ fn f104(a0: Vec) -> UnsafeRandomAccessIterator { a0.end() } -unsafe fn f105<'a, T1: CopyConstructibleUnsafe>(a0: &'a mut Vec, a1: *const Vec) -> &'a mut Vec { +unsafe fn f105<'a, T1: CopyConstructibleUnsafe>( + a0: &'a mut Vec, + a1: *const Vec, +) -> &'a mut Vec { CopyAssignableUnsafe::copy_assign(&raw mut *a0, LvalueRefUnsafe::bind(a1)); a0 } @@ -248,13 +278,27 @@ fn f122(a0: &mut Vec, init: T1) { a0.push(init) } -unsafe fn f115(a0: &mut Vec, a1: UnsafeRandomAccessIterator, a2: usize, a3: *const T1) -> UnsafeRandomAccessIterator { +unsafe fn f115( + a0: &mut Vec, + a1: UnsafeRandomAccessIterator, + a2: usize, + a3: *const T1, +) -> UnsafeRandomAccessIterator { let __off = a1.iter_distance(&UnsafeRandomAccessIterator::Vec(a0.as_mut_ptr())) as usize; - a0.splice(__off..__off, (0..a2).map(|_| copy_constructed_unsafe(a3)).collect::>()); + a0.splice( + __off..__off, + (0..a2) + .map(|_| copy_constructed_unsafe(a3)) + .collect::>(), + ); UnsafeRandomAccessIterator::Vec(a0.as_mut_ptr().add(__off)) } -unsafe fn f116(a0: &mut Vec, a1: UnsafeRandomAccessIterator, a2: Vec) -> UnsafeRandomAccessIterator { +unsafe fn f116( + a0: &mut Vec, + a1: UnsafeRandomAccessIterator, + a2: Vec, +) -> UnsafeRandomAccessIterator { let __off = a1.iter_distance(&UnsafeRandomAccessIterator::Vec(a0.as_mut_ptr())) as usize; a0.splice(__off..__off, a2); UnsafeRandomAccessIterator::Vec(a0.as_mut_ptr().add(__off)) From 8fa523d95e81a08a1d7eaca9dcac8ba17f6bfff9 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 4 Dec 2026 13:24:13 +0000 Subject: [PATCH 31/35] Fix inference of input --- cpp2rust/converter/converter_lib.cpp | 3 ++- libcc2rs/src/reference.rs | 24 ++++++++++++++++++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 05f6396916..5bfa1625e1 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -1531,7 +1531,8 @@ bool HasConversionsTable(clang::QualType type) { } bool UsesPointerMarker(clang::QualType type) { - return type->isPointerType() && HasConversionsTable(type); + return type->isPointerType() && HasConversionsTable(type) && + !type->getPointeeType().isVolatileQualified(); } bool IsTableConversionFunction(const clang::CXXConversionDecl *conversion) { diff --git a/libcc2rs/src/reference.rs b/libcc2rs/src/reference.rs index 0d42f81a13..182e238984 100644 --- a/libcc2rs/src/reference.rs +++ b/libcc2rs/src/reference.rs @@ -317,17 +317,29 @@ impl Pointer { } } -pub struct PointerUnsafe(*mut std::ffi::c_void, PhantomData); +pub trait CvUnsafe { + type Object; +} + +impl CvUnsafe for T { + type Object = T; +} -impl PointerUnsafe { +impl CvUnsafe for Const { + type Object = T; +} + +pub struct PointerUnsafe(*mut T::Object); + +impl PointerUnsafe { #[inline] - pub fn bind(ptr: *const U) -> Self { - Self(ptr.cast_mut().cast(), PhantomData) + pub fn bind(ptr: *const T::Object) -> Self { + Self(ptr.cast_mut()) } #[inline] - pub fn as_ptr(&self) -> *mut T { - self.0.cast() + pub fn as_ptr(&self) -> *mut T::Object { + self.0 } } From d53a23f6cd2a0bcf7bbf5d96780bd5313e2b59e1 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 4 Dec 2026 13:40:43 +0000 Subject: [PATCH 32/35] Remove comments --- libcc2rs/src/overload.rs | 36 ------------------------------------ libcc2rs/src/void.rs | 1 - 2 files changed, 37 deletions(-) diff --git a/libcc2rs/src/overload.rs b/libcc2rs/src/overload.rs index e300d2a4c5..64ec858b70 100644 --- a/libcc2rs/src/overload.rs +++ b/libcc2rs/src/overload.rs @@ -43,15 +43,12 @@ pub enum Category { Rvalue, } -// A pointer to an object of a type that its table describes: AnyPtr in the -// refcount model, *mut c_void in the unsafe model. pub trait Erased: Clone + 'static { fn read(&self) -> T; fn write(&self, value: T); } -// The arithmetic types, which both models read and write by value. pub trait Arithmetical: ByteRepr + crate::TriviallyCopyable + Copy + 'static {} impl Erased for AnyPtr { @@ -79,15 +76,10 @@ pub struct Param

{ pub passing: Passing, } -// A constructor, whose params are its parameters, or a conversion function, -// whose only param is the object it converts and whose result is the type it -// converts to. pub struct Candidate

{ pub params: Vec>, pub is_explicit: bool, pub result: Option Table

>, - // Constructs the object that `to` points to from the objects that args - // point to, one per parameter. pub call: fn(to: P, args: &[P]), } @@ -95,12 +87,8 @@ pub struct Table

{ pub id: TypeId, pub name: &'static str, pub arithmetic: Option, - // Allocates zero-initialized storage for an object of the type. pub storage: fn() -> P, - // Destroys the object that a pointer from storage points to and frees it. pub release: fn(P), - // Constructs the object that dst points to from the one that src points - // to, by the copy constructor or, for move, the move constructor. pub copy: fn(dst: P, src: P), pub move_from: fn(dst: P, src: P), pub constructors: Vec>, @@ -118,7 +106,6 @@ pub trait ConversionsUnsafe: Sized + 'static { fn table() -> Table<*mut c_void>; } -// T t(args...); pub trait ConstructibleFrom: Sized { fn construct(this: Ptr, args: Args); } @@ -129,7 +116,6 @@ impl ConstructibleFrom for T { } } -// To t = from; pub trait ConvertibleTo: Sized { fn convert(self, to: Ptr); } @@ -164,7 +150,6 @@ impl ConvertibleToUnsafe for From } } -// The argument that a reference is, with its value category. pub trait AsArg { fn as_arg(&self) -> Arg; } @@ -449,7 +434,6 @@ impl ParameterUnsafe for RvalueRefUnsafe> { } } -// The arguments that a tuple of references is. pub trait ArgList { fn as_args(&self) -> Vec>; } @@ -565,8 +549,6 @@ impl Standard { } } -// The function of a user-defined conversion: a constructor of the target or a -// conversion function of the source, at index in its table. #[derive(Clone, Copy, PartialEq, Eq, Debug)] enum UserFunction { Constructor(usize), @@ -763,8 +745,6 @@ fn initialize(target: &Table

, to: P, args: &[Arg

], is_direct: b // A class object from arguments, or from an object of its class, is // constructed by the best constructor ([over.match.ctor]). if is_class && (is_direct || sources[0].id == target.id) { - // The copy and move constructors, which the table holds apart, and the - // other constructors. #[derive(Clone, Copy)] enum Constructor { Copy, @@ -851,8 +831,6 @@ fn initialize(target: &Table

, to: P, args: &[Arg

], is_direct: b run_user(source, arg, target, to, &sequence); } -// Calls a constructor with the arguments converted by their sequences, then -// destroys the temporaries the conversions made. fn call_with(ctor: &Candidate

, to: P, args: &[Arg

], sequences: &[Sequence]) { let mut temporaries: Vec<(Table

, P)> = Vec::new(); let pointers: Vec

= args @@ -866,7 +844,6 @@ fn call_with(ctor: &Candidate

, to: P, args: &[Arg

], sequences: Sequence::Standard(standard) => standard.converts, Sequence::User { .. } => true, }; - // A reference binds to the argument itself. if !converts && param.passing != Passing::Value { return arg.ptr.clone(); } @@ -925,7 +902,6 @@ fn run_user( } } -// The value that src points to, as a float and as an integer. fn read_arithmetic(from: &Table

, src: &P) -> (f64, i128) { macro_rules! read { ($($ty:ty),*) => { @@ -1060,8 +1036,6 @@ where } } -// A vector is copied element by element, each by the copy constructor its -// table names. impl Conversions for Vec where Vec: ByteRepr, @@ -1096,7 +1070,6 @@ where } } -// A pair is copied member by member. impl Conversions for (crate::rc::Value, crate::rc::Value) where A: Conversions + crate::ZeroInitialization, @@ -1139,7 +1112,6 @@ where } } -// A unique_ptr moves its object and is not copied. impl Conversions for Option> where Option>: ByteRepr, @@ -1319,7 +1291,6 @@ mod tests { impl ByteRepr for Ratio {} - // struct Ratio { operator int() const; operator double() const; } impl Conversions for Ratio { fn table() -> Table { Table { @@ -1374,7 +1345,6 @@ mod tests { impl ByteRepr for Meters {} - // struct Meters { Meters(long); explicit Meters(double); } impl Conversions for Meters { fn table() -> Table { Table { @@ -1425,12 +1395,10 @@ mod tests { #[test] fn exact_conversion_function_is_chosen() { - // int i = ratio; picks operator int, whose result needs no conversion. let ratio = object(Ratio(9, 2)); let to = object(0_i32); convert_with(to.as_pointer(), Arg::const_lvalue(ratio.as_pointer())); assert_eq!(*to.borrow(), 4); - // double d = ratio; picks operator double. let to = object(0.0_f64); convert_with(to.as_pointer(), Arg::const_lvalue(ratio.as_pointer())); assert_eq!(*to.borrow(), 5.0); @@ -1439,7 +1407,6 @@ mod tests { #[test] #[should_panic(expected = "no conversion from Ratio to i64")] fn conversions_of_equal_rank_are_ambiguous() { - // long l = ratio; int -> long and double -> long rank the same. let ratio = object(Ratio(9, 2)); convert_with( object(0_i64).as_pointer(), @@ -1449,15 +1416,12 @@ mod tests { #[test] fn copy_initialization_skips_explicit_constructors() { - // Meters m = 2.0; the explicit Meters(double) is not a candidate, so - // 2.0 converts to long for Meters(long). let meters = object(Meters(0)); convert_with( meters.as_pointer(), Arg::rvalue(object(2.0_f64).as_pointer()), ); assert_eq!(meters.borrow().0, 2); - // Meters m(2.0); direct-initialization picks the exact match. construct_with( meters.as_pointer(), &[Arg::rvalue(object(2.0_f64).as_pointer())], diff --git a/libcc2rs/src/void.rs b/libcc2rs/src/void.rs index 78a69dd4e7..e5dba00b77 100644 --- a/libcc2rs/src/void.rs +++ b/libcc2rs/src/void.rs @@ -133,7 +133,6 @@ impl AnyPtr { self.ptr.is_null() } - // The pointer this was made from, which must be a Ptr. pub fn downcast(&self) -> Ptr { self.ptr .as_any() From 4f583d9fb34843dfdfc2ae2076f299b61e140eba Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 4 Dec 2026 14:48:11 +0000 Subject: [PATCH 33/35] Fix macos --- cpp2rust/converter/converter.cpp | 6 +- .../vector_insert_conversion_chain.rs | 126 ------------------ .../unsafe/vector_insert_conversion_chain.rs | 108 --------------- tests/unit/vector_insert_conversion_chain.cpp | 26 ---- 4 files changed, 4 insertions(+), 262 deletions(-) delete mode 100644 tests/unit/out/refcount/vector_insert_conversion_chain.rs delete mode 100644 tests/unit/out/unsafe/vector_insert_conversion_chain.rs delete mode 100644 tests/unit/vector_insert_conversion_chain.cpp diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index d1797b57b5..fa688b9c02 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -7327,8 +7327,10 @@ void Converter::EmitConversionsAttrs(const clang::CXXRecordDecl *decl) { return; } StrCat(std::format("#[derive({})]", GetConversionsTrait())); - std::vector ctors(decl->ctors().begin(), - decl->ctors().end()); + std::vector ctors; + for (auto *ctor : decl->ctors()) { + ctors.push_back(ctor); + } for (auto *ctor : GetTemplateInstantiatedCtors(const_cast(decl))) { ctors.push_back(ctor); diff --git a/tests/unit/out/refcount/vector_insert_conversion_chain.rs b/tests/unit/out/refcount/vector_insert_conversion_chain.rs deleted file mode 100644 index 38d4c7fa24..0000000000 --- a/tests/unit/out/refcount/vector_insert_conversion_chain.rs +++ /dev/null @@ -1,126 +0,0 @@ -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}; -#[derive( - Copy, - Clone, - Record, - ByteRepr, - ZeroInitialization, - VaArg, - FnPtrArg, - TriviallyDefaultConstructible, - TriviallyCopyable, - Default, - Conversions, -)] -#[conversions(copy, move)] -#[conversion_function(to_i32, LvalueRef>, i32 )] -#[byte_size(4)] -pub struct Ratio { - #[offset(0)] - pub num: i32, -} -impl Ratio { - pub fn to_i32(this: Ptr) -> i32 { - return this.with(|__s| __s.num); - } -} -#[derive( - Copy, - Clone, - Record, - ByteRepr, - ZeroInitialization, - VaArg, - FnPtrArg, - TriviallyDefaultConstructible, - TriviallyCopyable, - Default, - Conversions, -)] -#[conversions(copy, move)] -#[conversion_function(to_i16, LvalueRef>, i16 )] -#[conversion_function(to_i64, LvalueRef>, i64 )] -#[byte_size(4)] -pub struct Level { - #[offset(0)] - pub raw_: i32, -} -impl Level { - pub fn to_i16(this: Ptr) -> i16 { - return (this.with(|__s| __s.raw_) as i16); - } - pub fn to_i64(this: Ptr) -> i64 { - return ((this.with(|__s| __s.raw_) as i64) * 100_i64); - } -} -pub fn main() { - __cpp2rust_init_globals(); - libcc2rs::cpp2rust_exit(main_0()); -} -fn main_0() -> i32 { - let ratios: Value> = - Rc::new(RefCell::new(Box::new([Ratio { num: 1 }, Ratio { num: 2 }]))); - let longs: Value> = Rc::new(RefCell::new(Vec::new())); - { - let mut __tmp_0 = { >::from(longs.decay().end()) }; - let start_idx = __tmp_0.index(); - let temp_vec: Value> = Rc::new(RefCell::new(Vec::new())); - let __it: Value> = Rc::new(RefCell::new(ratios.decay())); - let __last: Value> = Rc::new(RefCell::new(ratios.decay().offset((2) as isize))); - while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - let __i = temp_vec.borrow().len(); - temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); - ConstructibleFrom::construct( - temp_vec.as_pointer().decay().offset(__i), - (LvalueRef::>::bind(__it.borrow().iter_deref()),), - ); - __it.borrow_mut().iter_inc(); - } - longs.as_pointer().with_mut(|v: &mut Vec| { - v.splice( - start_idx..start_idx, - Rc::try_unwrap(temp_vec).ok().unwrap().into_inner(), - ); - }); - (__tmp_0).clone() - }; - assert!(({ (*longs.borrow())[0_usize] } == 1_i64) && ({ (*longs.borrow())[1_usize] } == 2_i64)); - let levels: Value> = Rc::new(RefCell::new(Box::new([ - Level { raw_: 3 }, - Level { raw_: 4 }, - ]))); - let ints: Value> = Rc::new(RefCell::new(Vec::new())); - { - let mut __tmp_1 = { >::from(ints.decay().end()) }; - let start_idx = __tmp_1.index(); - let temp_vec: Value> = Rc::new(RefCell::new(Vec::new())); - let __it: Value> = Rc::new(RefCell::new(levels.decay())); - let __last: Value> = Rc::new(RefCell::new(levels.decay().offset((2) as isize))); - while >::not_equal(__it.as_pointer(), __last.as_pointer()) { - let __i = temp_vec.borrow().len(); - temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); - ConstructibleFrom::construct( - temp_vec.as_pointer().decay().offset(__i), - (LvalueRef::>::bind(__it.borrow().iter_deref()),), - ); - __it.borrow_mut().iter_inc(); - } - ints.as_pointer().with_mut(|v: &mut Vec| { - v.splice( - start_idx..start_idx, - Rc::try_unwrap(temp_vec).ok().unwrap().into_inner(), - ); - }); - (__tmp_1).clone() - }; - assert!(({ (*ints.borrow())[0_usize] } == 3) && ({ (*ints.borrow())[1_usize] } == 4)); - return 0; -} -pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/vector_insert_conversion_chain.rs b/tests/unit/out/unsafe/vector_insert_conversion_chain.rs deleted file mode 100644 index efd0e3677c..0000000000 --- a/tests/unit/out/unsafe/vector_insert_conversion_chain.rs +++ /dev/null @@ -1,108 +0,0 @@ -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; -#[repr(C)] -#[derive( - Copy, - Clone, - VaArg, - FnPtrArg, - ZeroInitializationUnsafe, - TriviallyDefaultConstructibleUnsafe, - TriviallyCopyableUnsafe, - Default, - ConversionsUnsafe, -)] -#[conversions(copy, move)] -#[conversion_function(to_i32, LvalueRefUnsafe>, i32 )] -pub struct Ratio { - pub num: i32, -} -impl Ratio { - pub unsafe fn to_i32(this: *const Self) -> i32 { - return (*this).num; - } -} -#[repr(C)] -#[derive( - Copy, - Clone, - VaArg, - FnPtrArg, - ZeroInitializationUnsafe, - TriviallyDefaultConstructibleUnsafe, - TriviallyCopyableUnsafe, - Default, - ConversionsUnsafe, -)] -#[conversions(copy, move)] -#[conversion_function(to_i16, LvalueRefUnsafe>, i16 )] -#[conversion_function(to_i64, LvalueRefUnsafe>, i64 )] -pub struct Level { - pub raw_: i32, -} -impl Level { - pub unsafe fn to_i16(this: *const Self) -> i16 { - return ((*this).raw_ as i16); - } - pub unsafe fn to_i64(this: *const Self) -> i64 { - return (((*this).raw_ as i64) * (100_i64)); - } -} -pub fn main() { - unsafe { - __cpp2rust_init_globals(); - libcc2rs::cpp2rust_exit(main_0() as i32); - } -} -unsafe fn main_0() -> i32 { - let mut ratios: [Ratio; 2] = [Ratio { num: 1 }, Ratio { num: 2 }]; - let mut longs: Vec = Vec::new(); - { - let mut __tmp_0 = { >::from(longs.end()) }; - let mut __tmp_1 = { ratios.as_mut_ptr().offset((2) as isize) }; - let __off = - __tmp_0.iter_distance(&UnsafeRandomAccessIterator::Vec(longs.as_mut_ptr())) as usize; - let mut __tmp: Vec = Vec::new(); - let mut __it = ratios.as_mut_ptr(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { - __tmp.push(ZeroInitializationUnsafe::zero_init()); - ConstructibleFromUnsafe::construct( - __tmp.as_mut_ptr().add(__tmp.len() - 1), - (LvalueRefUnsafe::>::bind(__it.iter_deref()),), - ); - __it.iter_inc(); - } - longs.splice(__off..__off, __tmp); - UnsafeRandomAccessIterator::Vec(longs.as_mut_ptr().add(__off)) - }; - assert!(((longs[(0_usize)]) == (1_i64)) && ((longs[(1_usize)]) == (2_i64))); - let mut levels: [Level; 2] = [Level { raw_: 3 }, Level { raw_: 4 }]; - let mut ints: Vec = Vec::new(); - { - let mut __tmp_2 = { >::from(ints.end()) }; - let mut __tmp_3 = { levels.as_mut_ptr().offset((2) as isize) }; - let __off = - __tmp_2.iter_distance(&UnsafeRandomAccessIterator::Vec(ints.as_mut_ptr())) as usize; - let mut __tmp: Vec = Vec::new(); - let mut __it = levels.as_mut_ptr(); - while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) { - __tmp.push(ZeroInitializationUnsafe::zero_init()); - ConstructibleFromUnsafe::construct( - __tmp.as_mut_ptr().add(__tmp.len() - 1), - (LvalueRefUnsafe::>::bind(__it.iter_deref()),), - ); - __it.iter_inc(); - } - ints.splice(__off..__off, __tmp); - UnsafeRandomAccessIterator::Vec(ints.as_mut_ptr().add(__off)) - }; - assert!(((ints[(0_usize)]) == (3)) && ((ints[(1_usize)]) == (4))); - return 0; -} -pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/vector_insert_conversion_chain.cpp b/tests/unit/vector_insert_conversion_chain.cpp deleted file mode 100644 index 994145f374..0000000000 --- a/tests/unit/vector_insert_conversion_chain.cpp +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include - -struct Ratio { - int num; - operator int() const { return num; } -}; - -struct Level { - int raw; - operator short() const { return static_cast(raw); } - operator long() const { return raw * 100L; } -}; - -int main() { - Ratio ratios[] = {{1}, {2}}; - std::vector longs; - longs.insert(longs.end(), ratios, ratios + 2); - assert(longs[0] == 1 && longs[1] == 2); - - Level levels[] = {{3}, {4}}; - std::vector ints; - ints.insert(ints.end(), levels, levels + 2); - assert(ints[0] == 3 && ints[1] == 4); - return 0; -} From b985af10ca3b10ca05ca96b7c45eb497f8cdbbc4 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 4 Dec 2026 14:58:14 +0000 Subject: [PATCH 34/35] Fix formatting --- rule-preprocessor/src/syntactic.rs | 8 + .../out/refcount/sequence.reqmts.rs | 150 ++++++++++++++++++ .../out/unsafe/sequence.reqmts.rs | 124 +++++++++++++++ .../sequence.reqmts.cpp | 40 +++++ tests/unit/out/refcount/inet_pton_ntop.rs | 5 - tests/unit/out/refcount/map_try_emplace.rs | 4 +- tests/unit/out/refcount/netdb.rs | 6 - tests/unit/out/refcount/sys_time.rs | 12 -- 8 files changed, 324 insertions(+), 25 deletions(-) create mode 100644 tests/std/containers/container.requirements/out/refcount/sequence.reqmts.rs create mode 100644 tests/std/containers/container.requirements/out/unsafe/sequence.reqmts.rs create mode 100644 tests/std/containers/container.requirements/sequence.reqmts.cpp diff --git a/rule-preprocessor/src/syntactic.rs b/rule-preprocessor/src/syntactic.rs index 6eab5b34a9..a3bd5599ab 100644 --- a/rule-preprocessor/src/syntactic.rs +++ b/rule-preprocessor/src/syntactic.rs @@ -286,6 +286,14 @@ impl<'a> FragmentCtx<'a> { self.pending_close_parens -= 1; return; } + match token.kind() { + SyntaxKind::COMMENT => return, + SyntaxKind::WHITESPACE if token.text().contains('\n') => { + self.text_buf.push(' '); + return; + } + _ => {} + } if token.kind() == SyntaxKind::IDENT { if let Some(param) = self.params.iter().find(|p| p.name == token.text()) { if param.is_va_args { diff --git a/tests/std/containers/container.requirements/out/refcount/sequence.reqmts.rs b/tests/std/containers/container.requirements/out/refcount/sequence.reqmts.rs new file mode 100644 index 0000000000..21121f5e06 --- /dev/null +++ b/tests/std/containers/container.requirements/out/refcount/sequence.reqmts.rs @@ -0,0 +1,150 @@ +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}; +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[conversion_function(to_i32, LvalueRef>, i32 )] +#[byte_size(4)] +pub struct p38_insert_range_by_conversion_function_Ratio { + #[offset(0)] + pub num: i32, +} +impl p38_insert_range_by_conversion_function_Ratio { + pub fn to_i32(this: Ptr) -> i32 { + return this.with(|__s| __s.num); + } +} +pub fn test_0() { + let ratios: Value> = + Rc::new(RefCell::new(Box::new([ + p38_insert_range_by_conversion_function_Ratio { num: 1 }, + p38_insert_range_by_conversion_function_Ratio { num: 2 }, + ]))); + let longs: Value> = Rc::new(RefCell::new(Vec::new())); + { + let mut __tmp_0 = { >::from(longs.decay().end()) }; + let start_idx = __tmp_0.index(); + let temp_vec: Value> = Rc::new(RefCell::new(Vec::new())); + let __it: Value> = + Rc::new(RefCell::new(ratios.decay())); + let __last: Value> = + Rc::new(RefCell::new(ratios.decay().offset((2) as isize))); + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) { + let __i = temp_vec.borrow().len(); + temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + temp_vec.as_pointer().decay().offset(__i), + (LvalueRef::< + Const, + >::bind(__it.borrow().iter_deref()),), + ); + __it.borrow_mut().iter_inc(); + } + longs.as_pointer().with_mut(|v: &mut Vec| { + v.splice( + start_idx..start_idx, + Rc::try_unwrap(temp_vec).ok().unwrap().into_inner(), + ); + }); + (__tmp_0).clone() + }; + assert!(({ (*longs.borrow())[0_usize] } == 1_i64) && ({ (*longs.borrow())[1_usize] } == 2_i64)); +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, + Conversions, +)] +#[conversions(copy, move)] +#[conversion_function(to_i16, LvalueRef>, i16 )] +#[conversion_function(to_i64, LvalueRef>, i64 )] +#[byte_size(4)] +pub struct p38_insert_range_best_conversion_function_Level { + #[offset(0)] + pub raw_: i32, +} +impl p38_insert_range_best_conversion_function_Level { + pub fn to_i16(this: Ptr) -> i16 { + return (this.with(|__s| __s.raw_) as i16); + } + pub fn to_i64(this: Ptr) -> i64 { + return ((this.with(|__s| __s.raw_) as i64) * 100_i64); + } +} +pub fn test_1() { + let levels: Value> = + Rc::new(RefCell::new(Box::new([ + p38_insert_range_best_conversion_function_Level { raw_: 3 }, + p38_insert_range_best_conversion_function_Level { raw_: 4 }, + ]))); + let ints: Value> = Rc::new(RefCell::new(Vec::new())); + { + let mut __tmp_1 = { >::from(ints.decay().end()) }; + let start_idx = __tmp_1.index(); + let temp_vec: Value> = Rc::new(RefCell::new(Vec::new())); + let __it: Value> = + Rc::new(RefCell::new(levels.decay())); + let __last: Value> = + Rc::new(RefCell::new(levels.decay().offset((2) as isize))); + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) { + let __i = temp_vec.borrow().len(); + temp_vec.borrow_mut().push(ZeroInitialization::zero_init()); + ConstructibleFrom::construct( + temp_vec.as_pointer().decay().offset(__i), + (LvalueRef::< + Const, + >::bind(__it.borrow().iter_deref()),), + ); + __it.borrow_mut().iter_inc(); + } + ints.as_pointer().with_mut(|v: &mut Vec| { + v.splice( + start_idx..start_idx, + Rc::try_unwrap(temp_vec).ok().unwrap().into_inner(), + ); + }); + (__tmp_1).clone() + }; + assert!(({ (*ints.borrow())[0_usize] } == 3) && ({ (*ints.borrow())[1_usize] } == 4)); +} +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + ({ test_0() }); + ({ test_1() }); + return 0; +} +pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/containers/container.requirements/out/unsafe/sequence.reqmts.rs b/tests/std/containers/container.requirements/out/unsafe/sequence.reqmts.rs new file mode 100644 index 0000000000..17cd966374 --- /dev/null +++ b/tests/std/containers/container.requirements/out/unsafe/sequence.reqmts.rs @@ -0,0 +1,124 @@ +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; +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[conversion_function(to_i32, LvalueRefUnsafe>, i32 )] +pub struct p38_insert_range_by_conversion_function_Ratio { + pub num: i32, +} +impl p38_insert_range_by_conversion_function_Ratio { + pub unsafe fn to_i32(this: *const Self) -> i32 { + return (*this).num; + } +} +pub unsafe fn test_0() { + let mut ratios: [p38_insert_range_by_conversion_function_Ratio; 2] = [ + p38_insert_range_by_conversion_function_Ratio { num: 1 }, + p38_insert_range_by_conversion_function_Ratio { num: 2 }, + ]; + let mut longs: Vec = Vec::new(); + { + let mut __tmp_0 = { >::from(longs.end()) }; + let mut __tmp_1 = { ratios.as_mut_ptr().offset((2) as isize) }; + let __off = + __tmp_0.iter_distance(&UnsafeRandomAccessIterator::Vec(longs.as_mut_ptr())) as usize; + let mut __tmp: Vec = Vec::new(); + let mut __it = ratios.as_mut_ptr(); + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { + __tmp.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __tmp.as_mut_ptr().add(__tmp.len() - 1), + (LvalueRefUnsafe::< + Const, + >::bind(__it.iter_deref()),), + ); + __it.iter_inc(); + } + longs.splice(__off..__off, __tmp); + UnsafeRandomAccessIterator::Vec(longs.as_mut_ptr().add(__off)) + }; + assert!(((longs[(0_usize)]) == (1_i64)) && ((longs[(1_usize)]) == (2_i64))); +} +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, + ConversionsUnsafe, +)] +#[conversions(copy, move)] +#[conversion_function(to_i16, LvalueRefUnsafe>, i16 )] +#[conversion_function(to_i64, LvalueRefUnsafe>, i64 )] +pub struct p38_insert_range_best_conversion_function_Level { + pub raw_: i32, +} +impl p38_insert_range_best_conversion_function_Level { + pub unsafe fn to_i16(this: *const Self) -> i16 { + return ((*this).raw_ as i16); + } + pub unsafe fn to_i64(this: *const Self) -> i64 { + return (((*this).raw_ as i64) * (100_i64)); + } +} +pub unsafe fn test_1() { + let mut levels: [p38_insert_range_best_conversion_function_Level; 2] = [ + p38_insert_range_best_conversion_function_Level { raw_: 3 }, + p38_insert_range_best_conversion_function_Level { raw_: 4 }, + ]; + let mut ints: Vec = Vec::new(); + { + let mut __tmp_2 = { >::from(ints.end()) }; + let mut __tmp_3 = { levels.as_mut_ptr().offset((2) as isize) }; + let __off = + __tmp_2.iter_distance(&UnsafeRandomAccessIterator::Vec(ints.as_mut_ptr())) as usize; + let mut __tmp: Vec = Vec::new(); + let mut __it = levels.as_mut_ptr(); + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) { + __tmp.push(ZeroInitializationUnsafe::zero_init()); + ConstructibleFromUnsafe::construct( + __tmp.as_mut_ptr().add(__tmp.len() - 1), + (LvalueRefUnsafe::< + Const, + >::bind(__it.iter_deref()),), + ); + __it.iter_inc(); + } + ints.splice(__off..__off, __tmp); + UnsafeRandomAccessIterator::Vec(ints.as_mut_ptr().add(__off)) + }; + assert!(((ints[(0_usize)]) == (3)) && ((ints[(1_usize)]) == (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_1() }); + return 0; +} +pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/containers/container.requirements/sequence.reqmts.cpp b/tests/std/containers/container.requirements/sequence.reqmts.cpp new file mode 100644 index 0000000000..1ca4261f33 --- /dev/null +++ b/tests/std/containers/container.requirements/sequence.reqmts.cpp @@ -0,0 +1,40 @@ +#include +#include + +// N4950 [sequence.reqmts]/37-38: a.insert(p, i, j) requires T to be +// Cpp17EmplaceConstructible into X from *i, and inserts copies of the elements +// in [i, j) before p. +namespace p38_insert_range_by_conversion_function { +struct Ratio { + int num; + operator int() const { return num; } +}; + +void test() { + Ratio ratios[] = {{1}, {2}}; + std::vector longs; + longs.insert(longs.end(), ratios, ratios + 2); + assert(longs[0] == 1 && longs[1] == 2); +} +} // namespace p38_insert_range_by_conversion_function + +namespace p38_insert_range_best_conversion_function { +struct Level { + int raw; + operator short() const { return static_cast(raw); } + operator long() const { return raw * 100L; } +}; + +void test() { + Level levels[] = {{3}, {4}}; + std::vector ints; + ints.insert(ints.end(), levels, levels + 2); + assert(ints[0] == 3 && ints[1] == 4); +} +} // namespace p38_insert_range_best_conversion_function + +int main() { + p38_insert_range_by_conversion_function::test(); + p38_insert_range_best_conversion_function::test(); + return 0; +} diff --git a/tests/unit/out/refcount/inet_pton_ntop.rs b/tests/unit/out/refcount/inet_pton_ntop.rs index b855b288c8..ed93375fa8 100644 --- a/tests/unit/out/refcount/inet_pton_ntop.rs +++ b/tests/unit/out/refcount/inet_pton_ntop.rs @@ -63,7 +63,6 @@ fn main_0() -> i32 { ({ let mut __tmp_2 = { (buf.decay()).to_any() }; if libc::AF_INET == libc::AF_INET { - // The address is ASCII, so invalid UTF-8 is not an address. match Ptr::::from_string_literal(b"1.2.3.4").with_c_bytes(|__s| { str::from_utf8(__s).ok()?.parse::().ok() }) { @@ -105,7 +104,6 @@ fn main_0() -> i32 { ({ let mut __tmp_3 = { (buf.decay()).to_any() }; if libc::AF_INET == libc::AF_INET { - // The address is ASCII, so invalid UTF-8 is not an address. match Ptr::::from_string_literal(b"999.1.1.1").with_c_bytes(|__s| { str::from_utf8(__s).ok()?.parse::().ok() }) { @@ -139,7 +137,6 @@ fn main_0() -> i32 { ({ let mut __tmp_4 = { (buf.decay()).to_any() }; if libc::AF_INET == libc::AF_INET { - // The address is ASCII, so invalid UTF-8 is not an address. match Ptr::::from_string_literal(b"not an ip").with_c_bytes(|__s| { str::from_utf8(__s).ok()?.parse::().ok() }) { @@ -173,7 +170,6 @@ fn main_0() -> i32 { ({ let mut __tmp_5 = { (buf.decay()).to_any() }; if libc::AF_INET6 == libc::AF_INET { - // The address is ASCII, so invalid UTF-8 is not an address. match Ptr::::from_string_literal(b"::1").with_c_bytes(|__s| { str::from_utf8(__s).ok()?.parse::().ok() }) { @@ -213,7 +209,6 @@ fn main_0() -> i32 { ({ let mut __tmp_6 = { (buf.decay()).to_any() }; if libc::AF_INET6 == libc::AF_INET { - // The address is ASCII, so invalid UTF-8 is not an address. match Ptr::::from_string_literal(b"2001:db8::5").with_c_bytes(|__s| { str::from_utf8(__s).ok()?.parse::().ok() }) { diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index e79f634576..9d4c95638a 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -251,7 +251,7 @@ fn main_0() -> i32 { m.as_pointer(), &key.as_pointer(), || { - (Rc::new(RefCell::new(copy_constructed(key .as_pointer() .clone()))), Rc::new(RefCell::new((__tmp_2.read()) ))) + ( Rc::new(RefCell::new(copy_constructed(key .as_pointer() .clone()))), Rc::new(RefCell::new((__tmp_2.read()) )), ) }, ); ( @@ -277,7 +277,7 @@ fn main_0() -> i32 { m.as_pointer(), &key.as_pointer(), || { - (Rc::new(RefCell::new(copy_constructed(key .as_pointer() .clone()))), Rc::new(RefCell::new((__tmp_4.read()) ))) + ( Rc::new(RefCell::new(copy_constructed(key .as_pointer() .clone()))), Rc::new(RefCell::new((__tmp_4.read()) )), ) }, ); ( diff --git a/tests/unit/out/refcount/netdb.rs b/tests/unit/out/refcount/netdb.rs index c425dd26cf..0012c957b8 100644 --- a/tests/unit/out/refcount/netdb.rs +++ b/tests/unit/out/refcount/netdb.rs @@ -52,8 +52,6 @@ pub fn test_ipv4_literal_0() { __addrs.push(::std::net::IpAddr::V4(::std::net::Ipv4Addr::UNSPECIFIED)); } } else { - // A host name that is not UTF-8 is not found, as the resolver takes a - // str. match Ptr::::from_string_literal(b"127.0.0.1") .with_c_bytes(|__s| str::from_utf8(__s).map(str::to_owned)) { @@ -199,8 +197,6 @@ pub fn test_ipv6_literal_1() { __addrs.push(::std::net::IpAddr::V4(::std::net::Ipv4Addr::UNSPECIFIED)); } } else { - // A host name that is not UTF-8 is not found, as the resolver takes a - // str. match Ptr::::from_string_literal(b"::1") .with_c_bytes(|__s| str::from_utf8(__s).map(str::to_owned)) { @@ -338,8 +334,6 @@ pub fn test_null_hints_2() { __addrs.push(::std::net::IpAddr::V4(::std::net::Ipv4Addr::UNSPECIFIED)); } } else { - // A host name that is not UTF-8 is not found, as the resolver takes a - // str. match Ptr::::from_string_literal(b"127.0.0.1") .with_c_bytes(|__s| str::from_utf8(__s).map(str::to_owned)) { diff --git a/tests/unit/out/refcount/sys_time.rs b/tests/unit/out/refcount/sys_time.rs index 8fde62a5e5..b787e76840 100644 --- a/tests/unit/out/refcount/sys_time.rs +++ b/tests/unit/out/refcount/sys_time.rs @@ -162,8 +162,6 @@ pub fn test_strftime_5() { ({ let mut __tmp_4 = { buf.decay() }; let __dt = (tm.as_pointer()).with(|__tm| __tm.to_civil()); - // jiff formats UTF-8, so the bytes of the format that are not UTF-8 are - // copied. let __text = match __dt { Ok(__d) => { Ptr::::from_string_literal(b"%Y-%m-%d %H:%M:%S").with_c_bytes(|__fmt| { @@ -193,8 +191,6 @@ pub fn test_strftime_5() { ({ let mut __tmp_5 = { buf.decay() }; let __dt = (tm.as_pointer()).with(|__tm| __tm.to_civil()); - // jiff formats UTF-8, so the bytes of the format that are not UTF-8 are - // copied. let __text = match __dt { Ok(__d) => { Ptr::::from_string_literal(b"%a, %d %b %Y %T").with_c_bytes(|__fmt| { @@ -224,8 +220,6 @@ pub fn test_strftime_5() { ({ let mut __tmp_6 = { buf.decay() }; let __dt = (tm.as_pointer()).with(|__tm| __tm.to_civil()); - // jiff formats UTF-8, so the bytes of the format that are not UTF-8 are - // copied. let __text = match __dt { Ok(__d) => Ptr::::from_string_literal(b"day %j 100%%").with_c_bytes(|__fmt| { __fmt @@ -253,8 +247,6 @@ pub fn test_strftime_5() { ({ let mut __tmp_7 = { buf.decay() }; let __dt = (tm.as_pointer()).with(|__tm| __tm.to_civil()); - // jiff formats UTF-8, so the bytes of the format that are not UTF-8 are - // copied. let __text = match __dt { Ok(__d) => Ptr::::from_string_literal(b"%e").with_c_bytes(|__fmt| { __fmt @@ -282,8 +274,6 @@ pub fn test_strftime_5() { ({ let mut __tmp_8 = { buf.decay() }; let __dt = (tm.as_pointer()).with(|__tm| __tm.to_civil()); - // jiff formats UTF-8, so the bytes of the format that are not UTF-8 are - // copied. let __text = match __dt { Ok(__d) => { Ptr::::from_string_literal(b"\xff%Y\xc3\xa9").with_c_bytes(|__fmt| { @@ -331,8 +321,6 @@ pub fn test_strftime_5() { ({ let mut __tmp_9 = { small.decay() }; let __dt = (tm.as_pointer()).with(|__tm| __tm.to_civil()); - // jiff formats UTF-8, so the bytes of the format that are not UTF-8 are - // copied. let __text = match __dt { Ok(__d) => Ptr::::from_string_literal(b"%Y-%m-%d").with_c_bytes(|__fmt| { __fmt From 9865e61314e099f33bdd49a449ffc239fa66c0b4 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Fri, 4 Dec 2026 15:31:57 +0000 Subject: [PATCH 35/35] Fix macos --- cpp2rust/converter/converter_lib.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 5bfa1625e1..88fc850a5f 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -1512,10 +1512,13 @@ bool IsReferenceToObject(clang::QualType type) { auto pointee = type->getPointeeType(); auto *record = pointee->getAsCXXRecordDecl(); return !pointee->isFunctionType() && !pointee->isArrayType() && - !(record && IsAbstractUserClass(record)); + !IsVaListType(pointee) && !(record && IsAbstractUserClass(record)); } bool HasConversionsTable(clang::QualType type) { + if (IsVaListType(type.getNonReferenceType())) { + return false; + } type = type.getNonReferenceType().getCanonicalType(); if (type->isArithmeticType() && !type->isEnumeralType()) { return true;