From 097a70747ba35c5e46028b793030ccfc5210dddf Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 10:54:21 +0000 Subject: [PATCH 01/18] Update tests --- .../out/refcount/defaulted_move_cross_tu.rs | 48 +- .../refcount/out_of_line_methods_cross_tu.rs | 102 ++-- .../template_method_late_instantiation.rs | 30 +- .../out/refcount/p14-class-in-two-files.rs | 49 +- .../p15-class-template-static-member.rs | 41 +- .../out/refcount/p15-function-template.rs | 49 +- .../out/refcount/p15-inline-function.rs | 41 +- .../out/refcount/p15-inline-variable.rs | 41 +- .../p16-default-argument-lambda-in-class.rs | 86 ++-- .../refcount/p16-lambda-in-inline-function.rs | 39 +- .../basic.link/out/refcount/basic.link.rs | 58 +-- .../out/refcount/basic.scope.block.rs | 62 +-- .../out/refcount/basic.scope.class.rs | 76 ++- .../out/refcount/basic.scope.param.rs | 32 +- .../out/refcount/basic.scope.pdecl.rs | 8 +- .../out/refcount/basic.scope.scope.rs | 254 +++++----- .../out/refcount/basic.start.term-p1-exit.rs | 27 +- .../out/refcount/basic.start.term.rs | 74 ++- tests/std/basic/out/refcount/basic.def.odr.rs | 205 ++++---- .../out/refcount/class.base.init.rs | 15 +- .../out/refcount/class.conv.ctor.rs | 24 +- .../class.conv/out/refcount/class.conv.fct.rs | 15 +- .../out/refcount/class.copy.ctor.rs | 19 +- .../out/refcount/class.mem.general.rs | 71 ++- .../dcl.init/out/refcount/dcl.init.general.rs | 22 +- .../out/refcount/dcl.fct.default.rs | 92 ++-- .../expr.unary/out/refcount/expr.unary.op.rs | 66 ++- .../out/refcount/expr.mptr.oper.rs | 4 +- tests/std/expr/expr.prim/expr.prim.this.cpp | 23 + .../expr.prim/out/refcount/expr.prim.this.rs | 98 ++-- .../expr.prim/out/unsafe/expr.prim.this.rs | 44 ++ .../allocator.requirements.general.rs | 28 +- .../stmt.iter/out/refcount/stmt.while.rs | 60 +-- .../stmt.select/out/refcount/stmt.if.rs | 31 +- .../stmt.select/out/refcount/stmt.switch.rs | 52 +- .../temp/temp.spec/out/refcount/temp.inst.rs | 23 +- .../utility/out/refcount/forward-helpers.rs | 135 +++--- .../utilities/utility/out/refcount/forward.rs | 17 +- .../utility/out/refcount/utility.as.const.rs | 24 +- tests/ub/out/refcount/ctor_ref_member.rs | 15 +- tests/ub/out/refcount/max.rs | 4 +- tests/unit/out/refcount/05_new.rs | 17 +- tests/unit/out/refcount/10_struct.rs | 60 +-- tests/unit/out/refcount/any.rs | 19 +- .../out/refcount/array_of_noncopy_struct.rs | 8 +- tests/unit/out/refcount/as_const.rs | 46 +- .../out/refcount/assignment_single_eval.rs | 31 +- tests/unit/out/refcount/cast.rs | 6 +- tests/unit/out/refcount/class.rs | 173 +++---- .../refcount/class_template_lazy_member.rs | 66 +-- tests/unit/out/refcount/class_templates.rs | 337 ++++++------- tests/unit/out/refcount/complex_function.rs | 91 ++-- tests/unit/out/refcount/concepts.rs | 13 +- tests/unit/out/refcount/constexpr_function.rs | 30 +- tests/unit/out/refcount/constructor.rs | 79 ++-- .../unit/out/refcount/container_field_addr.rs | 8 +- .../conversion_operator_same_translation.rs | 51 +- tests/unit/out/refcount/copy_assign.rs | 215 ++++----- tests/unit/out/refcount/copy_ctor.rs | 144 +++--- .../unit/out/refcount/copy_move_defaulted.rs | 305 ++++++------ tests/unit/out/refcount/copy_move_deleted.rs | 55 +-- .../refcount/default_function_arguments.rs | 48 +- tests/unit/out/refcount/delete_array_order.rs | 8 +- tests/unit/out/refcount/destructor.rs | 40 +- tests/unit/out/refcount/destructor_params.rs | 30 +- .../out/refcount/destructor_temporaries.rs | 21 +- tests/unit/out/refcount/doubly_linked_list.rs | 24 +- .../refcount/elidable_iterator_copy_cxx11.rs | 6 +- .../unit/out/refcount/enum_underlying_type.rs | 4 +- tests/unit/out/refcount/exprs.rs | 26 +- .../out/refcount/field_method_receiver.rs | 101 ++-- tests/unit/out/refcount/field_pointers.rs | 61 +-- tests/unit/out/refcount/find.rs | 34 +- tests/unit/out/refcount/fn_ptr.rs | 15 +- tests/unit/out/refcount/fn_ptr_struct.rs | 40 +- tests/unit/out/refcount/fn_ref.rs | 15 +- .../unit/out/refcount/for_body_destructor.rs | 47 +- .../refcount/foreach_disjoint_field_borrow.rs | 6 +- tests/unit/out/refcount/forward_basic.rs | 69 ++- tests/unit/out/refcount/forward_decltype.rs | 39 +- tests/unit/out/refcount/forward_explicit.rs | 43 +- tests/unit/out/refcount/forward_pack.rs | 62 ++- tests/unit/out/refcount/friend.rs | 2 +- .../unit/out/refcount/function_overloading.rs | 32 +- .../out/refcount/global_call_temporaries.rs | 26 +- .../out/refcount/global_init_side_effect.rs | 17 +- .../out/refcount/global_non_const_init.rs | 35 +- tests/unit/out/refcount/huffman.rs | 387 +++++++-------- .../refcount/immutable-deref-on-func-call.rs | 15 +- tests/unit/out/refcount/implicit_autoref.rs | 4 +- .../refcount/in_class_field_initializer.rs | 31 +- tests/unit/out/refcount/init_list.rs | 25 +- .../out/refcount/inline_container_fields.rs | 44 +- tests/unit/out/refcount/kruskal.rs | 242 +++++----- tests/unit/out/refcount/lambda_as_field.rs | 83 ++-- .../out/refcount/lambda_capture_copy_ctor.rs | 62 ++- .../out/refcount/lambda_capture_star_this.rs | 60 ++- .../unit/out/refcount/lambda_capture_this.rs | 59 +-- .../unit/out/refcount/lambda_decltype_type.rs | 106 ++--- .../out/refcount/lambda_immediate_init.rs | 6 +- .../out/refcount/lambda_move_only_capture.rs | 65 ++- tests/unit/out/refcount/lambda_nested.rs | 51 +- .../refcount/libc_struct_without_default.rs | 6 +- tests/unit/out/refcount/linked_list.rs | 15 +- tests/unit/out/refcount/map.rs | 29 +- tests/unit/out/refcount/map_key_copy_ctor.rs | 42 +- tests/unit/out/refcount/map_key_identity.rs | 10 +- tests/unit/out/refcount/map_try_emplace.rs | 84 ++-- .../out/refcount/map_try_emplace_lvalues.rs | 186 ++++---- tests/unit/out/refcount/max.rs | 48 +- tests/unit/out/refcount/min_max_ptr2ptr.rs | 12 +- tests/unit/out/refcount/move_assign.rs | 69 ++- tests/unit/out/refcount/move_ctor.rs | 121 +++-- tests/unit/out/refcount/move_this.rs | 92 ++-- .../refcount/nttp_distinct_specializations.rs | 45 +- tests/unit/out/refcount/opaque_record_copy.rs | 6 - .../refcount/operator_arithmetic_member.rs | 144 +++--- .../out/refcount/operator_bitwise_member.rs | 64 ++- .../refcount/operator_comparison_defaulted.rs | 443 ++++++++---------- .../out/refcount/operator_comparison_free.rs | 8 +- .../refcount/operator_comparison_member.rs | 79 ++-- .../out/refcount/operator_comparison_mixed.rs | 60 +-- .../refcount/operator_comparison_nonbool.rs | 173 +++---- .../operator_comparison_noncopyable.rs | 17 +- .../operator_compound_assignment_member.rs | 159 +++---- tests/unit/out/refcount/operator_friend.rs | 18 +- tests/unit/out/refcount/operator_less_than.rs | 29 +- .../out/refcount/operator_logical_member.rs | 39 +- .../operator_member_pointer_member.rs | 59 +-- .../out/refcount/operator_other_member.rs | 80 ++-- tests/unit/out/refcount/operator_overloads.rs | 91 ++-- .../unit/out/refcount/operator_qualifiers.rs | 93 ++-- tests/unit/out/refcount/operator_three_way.rs | 60 +-- tests/unit/out/refcount/operator_traits.rs | 79 ++-- tests/unit/out/refcount/overload_mangling.rs | 275 +++++------ .../refcount/pair_converting_construction.rs | 178 +++---- tests/unit/out/refcount/pointers.rs | 40 +- tests/unit/out/refcount/polymorphism.rs | 13 +- tests/unit/out/refcount/push_emplace_back.rs | 89 ++-- tests/unit/out/refcount/random.rs | 54 +-- tests/unit/out/refcount/rule_of_five.rs | 81 ++-- tests/unit/out/refcount/rule_of_three.rs | 57 ++- .../unit/out/refcount/rvalue_rule_arg_move.rs | 23 +- tests/unit/out/refcount/rvalue_struct.rs | 15 +- .../refcount/self_referencing_initializer.rs | 6 +- tests/unit/out/refcount/size_t_ssize_t.rs | 25 +- .../out/refcount/size_t_template_param.rs | 26 +- tests/unit/out/refcount/sort_no_copy.rs | 122 ++--- tests/unit/out/refcount/static_local.rs | 17 +- .../unit/out/refcount/static_var_in_class.rs | 15 +- tests/unit/out/refcount/stdcopy.rs | 15 +- tests/unit/out/refcount/stdmin_fpoint.rs | 2 +- tests/unit/out/refcount/struct_ctor.rs | 66 ++- .../unit/out/refcount/struct_default_ctor.rs | 20 +- .../refcount/structured_binding_copy_ctor.rs | 25 +- .../structured_binding_element_ctor.rs | 41 +- .../refcount/structured_binding_move_ctor.rs | 58 +-- tests/unit/out/refcount/swap_malloc.rs | 16 +- tests/unit/out/refcount/swap_map_no_copy.rs | 226 +++++---- .../unit/out/refcount/template_default_arg.rs | 74 ++- .../unit/out/refcount/temporary_field_addr.rs | 12 +- .../out/refcount/temporary_field_ctor_arg.rs | 21 +- .../out/refcount/temporary_field_two_args.rs | 10 +- tests/unit/out/refcount/this.rs | 237 +++++----- .../unit/out/refcount/typedef-anon-struct.rs | 4 +- .../refcount/unboxed_conditional_iterator.rs | 2 +- tests/unit/out/refcount/unboxed_locals.rs | 2 +- tests/unit/out/refcount/unboxed_records.rs | 23 +- tests/unit/out/refcount/unique_ptr.rs | 59 +-- .../out/refcount/unique_ptr_const_deref.rs | 4 +- .../out/refcount/unique_ptr_field_reset.rs | 27 +- tests/unit/out/refcount/unique_ptr_nested.rs | 4 +- tests/unit/out/refcount/va_list_field.rs | 19 +- tests/unit/out/refcount/vector.rs | 19 +- .../out/refcount/vector_iter_range_ctor.rs | 26 +- .../out/refcount/vector_subscript_direct.rs | 23 +- .../out/refcount/vector_with_allocator.rs | 40 +- tests/unit/out/refcount/void_cast.rs | 8 +- 178 files changed, 4766 insertions(+), 5862 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 d5eb4a1c5f..f9bffd1c6b 100644 --- a/tests/multi-file/defaulted_move_cross_tu/out/refcount/defaulted_move_cross_tu.rs +++ b/tests/multi-file/defaulted_move_cross_tu/out/refcount/defaulted_move_cross_tu.rs @@ -28,6 +28,17 @@ pub struct S { #[array_len(2)] pub n: Box<[i32]>, } +impl S { + pub fn construct(this: Ptr, x: i32) { + let x: Value = Rc::new(RefCell::new(x)); + field!(this, v).write( + (0..({ ((*x.borrow()) as usize) })) + .map(|_| copy_constructed(x.as_pointer().clone())) + .collect(), + ); + field!(this, n).write(Box::new([(*x.borrow()), ((*x.borrow()) + 1)])); + } +} impl Default for S { fn default() -> Self { { ::zero_init() } @@ -53,9 +64,14 @@ pub struct T { #[byte_size(24)] pub v: Vec, } +impl T { + pub fn size(this: Ptr) -> i32 { + return (((*this.upgrade().deref()).v.len()) as i32); + } +} impl DefaultConstructible for T { - fn default_constructor(this: &Ptr) { - field!((*this), v).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, v).write(Vec::new()); } } pub fn sum_0(s: Ptr) -> i32 { @@ -74,7 +90,7 @@ fn main_0() -> i32 { let t: Value = Rc::new(RefCell::new(T { v: Vec::from([1, 2]), })); - assert!((({ TImpl::size(&t.as_pointer(),) }) == 2)); + assert!((({ T::size(t.as_pointer(),) }) == 2)); return 0; } pub fn shuffle_1(mut x: i32) -> i32 { @@ -89,31 +105,9 @@ pub fn shuffle_1(mut x: i32) -> i32 { object!(w, T); assign!(w = Moved(u)); assert!( - ((({ TImpl::size(&t.as_pointer(),) }) == 0) && (({ TImpl::size(&u.as_pointer(),) }) == 0)) - && (({ TImpl::size(&w.as_pointer(),) }) == 1) + ((({ T::size(t.as_pointer(),) }) == 0) && (({ T::size(u.as_pointer(),) }) == 0)) + && (({ T::size(w.as_pointer(),) }) == 1) ); return ({ sum_0(c.as_pointer()) }); } -pub trait SImpl { - fn construct(&self, x: i32); -} -impl SImpl for Ptr { - fn construct(&self, x: i32) { - let x: Value = Rc::new(RefCell::new(x)); - field!((*self), v).write( - (0..({ ((*x.borrow()) as usize) })) - .map(|_| copy_constructed(x.as_pointer().clone())) - .collect(), - ); - field!((*self), n).write(Box::new([(*x.borrow()), ((*x.borrow()) + 1)])); - } -} -pub trait TImpl { - fn size(&self) -> i32; -} -impl TImpl for Ptr { - fn size(&self) -> i32 { - return (((*(*self).upgrade().deref()).v.len()) as i32); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/multi-file/out_of_line_methods_cross_tu/out/refcount/out_of_line_methods_cross_tu.rs b/tests/multi-file/out_of_line_methods_cross_tu/out/refcount/out_of_line_methods_cross_tu.rs index 3648091c45..ce8d8c60c4 100644 --- a/tests/multi-file/out_of_line_methods_cross_tu/out/refcount/out_of_line_methods_cross_tu.rs +++ b/tests/multi-file/out_of_line_methods_cross_tu/out/refcount/out_of_line_methods_cross_tu.rs @@ -24,12 +24,18 @@ pub struct S { #[offset(0)] pub v: i32, } +impl S { + pub fn get(this: Ptr) -> i32 { + return this.with(|__s| __s.v); + } +} #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Default)] #[byte_size(4)] pub struct M { #[offset(0)] pub v: i32, } +impl M {} pub trait Base { fn apply(&mut self, x: i32) -> i32; } @@ -50,6 +56,7 @@ pub struct Derived { #[offset(8)] pub factor: i32, } +impl Derived {} #[derive( Copy, Clone, @@ -78,10 +85,10 @@ pub fn main() { } fn main_0() -> i32 { object!(s, S(1)); - assert!((({ SImpl::get(&s.as_pointer(),) }) == 1)); - ({ SImpl::set(&s.as_pointer(), 4) }); - assert!((({ SImpl::get(&s.as_pointer(),) }) == 4)); - assert!((({ SImpl::add(&s.as_pointer(), 2,) }) == 6)); + assert!((({ S::get(s.as_pointer(),) }) == 1)); + ({ S::set(s.as_pointer(), 4) }); + assert!((({ S::get(s.as_pointer(),) }) == 4)); + assert!((({ S::add(s.as_pointer(), 2,) }) == 6)); object!(m, M(2)); object!(n, M, Moved(m.as_pointer())); assert!(({ (*n.borrow()).v } == 2)); @@ -99,19 +106,47 @@ fn main_0() -> i32 { assert!((({ pair_diff_0((pair.as_pointer()),) }) == 4)); return 0; } +impl S { + pub fn construct(this: Ptr, mut x: i32) { + field!(this, v).write(x); + } +} +impl M { + pub fn construct(this: Ptr, mut x: i32) { + field!(this, v).write(x); + } +} impl MoveConstructible for M { - fn move_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), v).write({ (*_a0.upgrade().deref()).v }); + fn move_constructor(this: Ptr, _a0: Ptr) { + field!(this, v).write({ (*_a0.upgrade().deref()).v }); } } impl CopyConstructible for M { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write((o.with(|__s| __s.v) + 1)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write((o.with(|__s| __s.v) + 1)); + } +} +impl Derived { + pub fn construct(this: Ptr, mut factor: i32) { + field!(this, factor).write(factor); } } impl S {} impl Destructible for S { - fn destroy(this: &Ptr) {} + fn destroy(this: Ptr) {} +} +impl S { + pub fn set(this: Ptr, mut x: i32) { + field!(this, v).write(x); + } +} +impl S { + pub fn add(this: Ptr, mut x: i32) -> i32 { + { + field!(this, v).with_mut(|__v| *__v = *__v + x) + }; + return this.with(|__s| __s.v); + } } impl M {} pub fn move_m_1(mut x: i32) -> i32 { @@ -128,53 +163,4 @@ impl Base for Derived { return ({ self.factor } * x); } } -pub trait DerivedImpl { - fn construct(&self, mut factor: i32) { - unimplemented!() - } -} -impl DerivedImpl for Ptr { - fn construct(&self, mut factor: i32) { - field!((*self), factor).write(factor); - } -} -pub trait MImpl { - fn construct(&self, mut x: i32) { - unimplemented!() - } -} -impl MImpl for Ptr { - fn construct(&self, mut x: i32) { - field!((*self), v).write(x); - } -} -pub trait SImpl { - fn construct(&self, mut x: i32) { - unimplemented!() - } - fn get(&self) -> i32; - fn set(&self, mut x: i32) { - unimplemented!() - } - fn add(&self, mut x: i32) -> i32 { - unimplemented!() - } -} -impl SImpl for Ptr { - fn get(&self) -> i32 { - return (*self).with(|__s| __s.v); - } - fn construct(&self, mut x: i32) { - field!((*self), v).write(x); - } - fn set(&self, mut x: i32) { - field!((*self), v).write(x); - } - fn add(&self, mut x: i32) -> i32 { - { - field!((*self), v).with_mut(|__v| *__v = *__v + x) - }; - return (*self).with(|__s| __s.v); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs b/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs index 8db93d594b..09b91429d0 100644 --- a/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs +++ b/tests/multi-file/template_method_late_instantiation/out/refcount/template_method_late_instantiation.rs @@ -12,9 +12,14 @@ pub struct S_int_ { #[offset(0)] pub x: i32, } +impl S_int_ { + pub fn set(this: Ptr, mut v: i32) { + field!(this, x).write(v); + } +} impl DefaultConstructible for S_int_ { - fn default_constructor(this: &Ptr) { - field!((*this), x).write(0); + fn default_constructor(this: Ptr) { + field!(this, x).write(0); } } impl Default for S_int_ { @@ -28,25 +33,16 @@ pub fn main() { } fn main_0() -> i32 { object!(p, S_int_); - ({ S_int_Impl::set(&p.as_pointer(), 3) }); + ({ S_int_::set(p.as_pointer(), 3) }); assert!((({ f_0((p.as_pointer()),) }) == 3)); return 0; } -pub fn f_0(mut p: Ptr) -> i32 { - return ({ S_int_Impl::get(&p) }); -} -pub trait S_int_Impl { - fn set(&self, v: i32); - fn get(&self) -> i32 { - unimplemented!() +impl S_int_ { + pub fn get(this: Ptr) -> i32 { + return this.with(|__s| __s.x); } } -impl S_int_Impl for Ptr { - fn set(&self, mut v: i32) { - field!((*self), x).write(v); - } - fn get(&self) -> i32 { - return (*self).with(|__s| __s.x); - } +pub fn f_0(mut p: Ptr) -> i32 { + return ({ S_int_::get(p) }); } pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs index ab50e8b772..79458eb9a7 100644 --- a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs @@ -53,21 +53,27 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), uses).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -90,15 +96,15 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl Destructible for AssertsDtorCountAtExit { - fn destroy(this: &Ptr) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + fn destroy(this: Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == this.with(|__s| __s.expected))); } } thread_local!( pub static check_4: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 2 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&check_4.with(Value::clone).as_pointer()) + Destructible::destroy(check_4.with(Value::clone).as_pointer()) }); __static }; @@ -107,11 +113,11 @@ thread_local!( pub static shared_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&shared_5.with(Value::clone).as_pointer()) + Destructible::destroy(shared_5.with(Value::clone).as_pointer()) }); __static }; @@ -139,11 +145,11 @@ thread_local!( static local_6: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&local_6.with(Value::clone).as_pointer()) + Destructible::destroy(local_6.with(Value::clone).as_pointer()) }); __static }; @@ -153,8 +159,8 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - ({ LifetimeTrackedImpl::use_(&shared_5.with(|v| v.as_pointer())) }); - ({ LifetimeTrackedImpl::use_(&({ HasInlineMembers::instance() })) }); + ({ LifetimeTracked::use_(shared_5.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(({ HasInlineMembers::instance() })) }); ({ b_use_7() }); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2)); assert!(({ (*shared_5.with(Value::clone).borrow()).uses } == 2)); @@ -165,8 +171,8 @@ fn main_0() -> i32 { return 0; } pub fn b_use_7() { - ({ LifetimeTrackedImpl::use_(&shared_5.with(|v| v.as_pointer())) }); - ({ LifetimeTrackedImpl::use_(&({ HasInlineMembers::instance() })) }); + ({ LifetimeTracked::use_(shared_5.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(({ HasInlineMembers::instance() })) }); } pub fn b_shared_address_8() -> Ptr { return (shared_5.with(|v| v.as_pointer())); @@ -174,17 +180,6 @@ pub fn b_shared_address_8() -> Ptr { pub fn b_instance_address_9() -> Ptr { return ({ HasInlineMembers::instance() }); } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs index d8b659e11f..4c20fca662 100644 --- a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs @@ -53,21 +53,27 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), uses).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -75,11 +81,11 @@ thread_local!( pub static member_4: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&member_4.with(Value::clone).as_pointer()) + Destructible::destroy(member_4.with(Value::clone).as_pointer()) }); __static }; @@ -102,11 +108,11 @@ thread_local!( pub static member_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&member_5.with(Value::clone).as_pointer()) + Destructible::destroy(member_5.with(Value::clone).as_pointer()) }); __static }; @@ -130,7 +136,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - ({ LifetimeTrackedImpl::use_(&member_4.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(member_4.with(|v| v.as_pointer())) }); ({ b_use_int_6() }); ({ b_use_long_7() }); assert!(({ (*member_4.with(Value::clone).borrow()).uses } == 2)); @@ -141,25 +147,14 @@ fn main_0() -> i32 { return 0; } pub fn b_use_int_6() { - ({ LifetimeTrackedImpl::use_(&member_4.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(member_4.with(|v| v.as_pointer())) }); } pub fn b_use_long_7() { - ({ LifetimeTrackedImpl::use_(&member_5.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(member_5.with(|v| v.as_pointer())) }); } pub fn b_int_address_8() -> Ptr { return (member_4.with(|v| v.as_pointer())); } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs index 074fbc99d8..ff95817e92 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs @@ -53,21 +53,27 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), uses).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -90,8 +96,8 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl Destructible for AssertsDtorCountAtExit { - fn destroy(this: &Ptr) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + fn destroy(this: Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == this.with(|__s| __s.expected))); } } pub fn count_4() -> i32 { @@ -107,11 +113,11 @@ thread_local!( static t_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&t_5.with(Value::clone).as_pointer()) + Destructible::destroy(t_5.with(Value::clone).as_pointer()) }); __static }; @@ -123,11 +129,11 @@ thread_local!( static t_8: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&t_8.with(Value::clone).as_pointer()) + Destructible::destroy(t_8.with(Value::clone).as_pointer()) }); __static }; @@ -139,11 +145,11 @@ thread_local!( static t_11: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&t_11.with(Value::clone).as_pointer()) + Destructible::destroy(t_11.with(Value::clone).as_pointer()) }); __static }; @@ -155,7 +161,7 @@ thread_local!( pub static check_13: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 4 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&check_13.with(Value::clone).as_pointer()) + Destructible::destroy(check_13.with(Value::clone).as_pointer()) }); __static }; @@ -199,11 +205,11 @@ thread_local!( static t_19: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&t_19.with(Value::clone).as_pointer()) + Destructible::destroy(t_19.with(Value::clone).as_pointer()) }); __static }; @@ -234,17 +240,6 @@ pub fn b_count_local_15() -> i32 { )] #[byte_size(1)] pub struct S_21 {} -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs index 1ccf381543..5cfa74c365 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs @@ -53,21 +53,27 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), uses).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -90,8 +96,8 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl Destructible for AssertsDtorCountAtExit { - fn destroy(this: &Ptr) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + fn destroy(this: Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == this.with(|__s| __s.expected))); } } pub fn instance_4() -> Ptr { @@ -101,11 +107,11 @@ thread_local!( static t_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&t_5.with(Value::clone).as_pointer()) + Destructible::destroy(t_5.with(Value::clone).as_pointer()) }); __static }; @@ -114,7 +120,7 @@ thread_local!( pub static check_6: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&check_6.with(Value::clone).as_pointer()) + Destructible::destroy(check_6.with(Value::clone).as_pointer()) }); __static }; @@ -125,7 +131,7 @@ pub fn main() { } fn main_0() -> i32 { assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); - ({ LifetimeTrackedImpl::use_(&({ instance_4() })) }); + ({ LifetimeTracked::use_(({ instance_4() })) }); ({ b_use_7() }); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); assert!((useCount_3.with(|rc| *rc.borrow()) == 2)); @@ -136,22 +142,11 @@ fn main_0() -> i32 { return 0; } pub fn b_use_7() { - ({ LifetimeTrackedImpl::use_(&({ instance_4() })) }); + ({ LifetimeTracked::use_(({ instance_4() })) }); } pub fn b_address_8() -> Ptr { return ({ instance_4() }); } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs index 9985dcd727..cc25f1572b 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs @@ -53,21 +53,27 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), uses).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -90,15 +96,15 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl Destructible for AssertsDtorCountAtExit { - fn destroy(this: &Ptr) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + fn destroy(this: Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == this.with(|__s| __s.expected))); } } thread_local!( pub static check_4: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&check_4.with(Value::clone).as_pointer()) + Destructible::destroy(check_4.with(Value::clone).as_pointer()) }); __static }; @@ -107,11 +113,11 @@ thread_local!( pub static shared_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&shared_5.with(Value::clone).as_pointer()) + Destructible::destroy(shared_5.with(Value::clone).as_pointer()) }); __static }; @@ -121,7 +127,7 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - ({ LifetimeTrackedImpl::use_(&shared_5.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(shared_5.with(|v| v.as_pointer())) }); ({ b_use_6() }); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); assert!((useCount_3.with(|rc| *rc.borrow()) == 2)); @@ -131,22 +137,11 @@ fn main_0() -> i32 { return 0; } pub fn b_use_6() { - ({ LifetimeTrackedImpl::use_(&shared_5.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(shared_5.with(|v| v.as_pointer())) }); } pub fn b_address_7() -> Ptr { return (shared_5.with(|v| v.as_pointer())); } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs index cb38081e40..0e2f2cdacd 100644 --- a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs @@ -53,21 +53,27 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), uses).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -90,8 +96,8 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl Destructible for AssertsDtorCountAtExit { - fn destroy(this: &Ptr) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + fn destroy(this: Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == this.with(|__s| __s.expected))); } } #[derive( @@ -108,15 +114,32 @@ impl Destructible for AssertsDtorCountAtExit { )] #[byte_size(1)] pub struct X {} +impl X { + pub fn h(this: Ptr, mut cond: bool, mut p: FnPtr) { + if cond { + ({ + X::h( + this.clone(), + false, + FnPtr::::new(|| { + ({ LifetimeTracked::use_(local_4.with(|v| v.as_pointer())) }); + }), + ) + }); + } else { + ({ p.call() }); + } + } +} thread_local!( static local_4: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&local_4.with(Value::clone).as_pointer()) + Destructible::destroy(local_4.with(Value::clone).as_pointer()) }); __static }; @@ -125,7 +148,7 @@ thread_local!( pub static check_5: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&check_5.with(Value::clone).as_pointer()) + Destructible::destroy(check_5.with(Value::clone).as_pointer()) }); __static }; @@ -138,11 +161,11 @@ fn main_0() -> i32 { assert!((ctorCount_0.with(|rc| *rc.borrow()) == 0)); let x: Value = Rc::new(RefCell::new(::default())); ({ - XImpl::h( - &x.as_pointer(), + X::h( + x.as_pointer(), true, FnPtr::::new(|| { - ({ LifetimeTrackedImpl::use_(&local_4.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(local_4.with(|v| v.as_pointer())) }); }), ) }); @@ -156,46 +179,15 @@ fn main_0() -> i32 { pub fn b_call_6() { let x: Value = Rc::new(RefCell::new(::default())); ({ - XImpl::h( - &x.as_pointer(), + X::h( + x.as_pointer(), true, FnPtr::::new(|| { - ({ LifetimeTrackedImpl::use_(&local_4.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(local_4.with(|v| v.as_pointer())) }); }), ) }); } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub trait XImpl { - fn h(&self, cond: bool, p: FnPtr); -} -impl XImpl for Ptr { - fn h(&self, mut cond: bool, mut p: FnPtr) { - if cond { - ({ - XImpl::h( - self, - false, - FnPtr::::new(|| { - ({ LifetimeTrackedImpl::use_(&local_4.with(|v| v.as_pointer())) }); - }), - ) - }); - } else { - ({ p.call() }); - } - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs index 51594617c5..38f3a11bae 100644 --- a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs @@ -53,21 +53,27 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), uses).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -90,8 +96,8 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl Destructible for AssertsDtorCountAtExit { - fn destroy(this: &Ptr) { - assert!((dtorCount_2.with(|rc| *rc.borrow()) == (*this).with(|__s| __s.expected))); + fn destroy(this: Ptr) { + assert!((dtorCount_2.with(|rc| *rc.borrow()) == this.with(|__s| __s.expected))); } } pub fn f_4(mut cond: bool, mut p: FnPtr) { @@ -100,7 +106,7 @@ pub fn f_4(mut cond: bool, mut p: FnPtr) { f_4( false, FnPtr::::new(|| { - ({ LifetimeTrackedImpl::use_(&local_5.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(local_5.with(|v| v.as_pointer())) }); }), ) }); @@ -112,11 +118,11 @@ thread_local!( static local_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&local_5.with(Value::clone).as_pointer()) + Destructible::destroy(local_5.with(Value::clone).as_pointer()) }); __static }; @@ -125,7 +131,7 @@ thread_local!( pub static check_6: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&check_6.with(Value::clone).as_pointer()) + Destructible::destroy(check_6.with(Value::clone).as_pointer()) }); __static }; @@ -147,17 +153,6 @@ fn main_0() -> i32 { pub fn b_call_7() { ({ f_4(true, FnPtr::::null()) }); } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.link/out/refcount/basic.link.rs b/tests/std/basic/basic.link/out/refcount/basic.link.rs index ccf5fccdfa..9bcb8c525a 100644 --- a/tests/std/basic/basic.link/out/refcount/basic.link.rs +++ b/tests/std/basic/basic.link/out/refcount/basic.link.rs @@ -82,8 +82,8 @@ pub struct Record_19 { pub id: i32, } impl DefaultConstructible for Record_19 { - fn default_constructor(this: &Ptr) { - field!((*this), id).write(100); + fn default_constructor(this: Ptr) { + field!(this, id).write(100); } } impl Default for Record_19 { @@ -130,12 +130,18 @@ pub fn test_29() { )] #[byte_size(1)] pub struct Tally_31 {} +impl Tally_31 { + pub fn add(this: Ptr, mut amount: i32) -> i32 { + total_32.with(|rc| *rc.borrow_mut() += amount); + return total_32.with(|rc| *rc.borrow()); + } +} thread_local!( pub static total_32: Value = Rc::new(RefCell::new(10)); ); pub fn test_33() { let tally: Value = Rc::new(RefCell::new(::default())); - assert!((({ Tally_31Impl::add(&tally.as_pointer(), 1,) }) == 11)); + assert!((({ Tally_31::add(tally.as_pointer(), 1,) }) == 11)); assert!((({ add_in_b_34(1,) }) == 102)); assert!((total_32.with(|rc| *rc.borrow()) == 11)); } @@ -225,8 +231,8 @@ pub struct Entry_52 { pub key: i32, } impl DefaultConstructible for Entry_52 { - fn default_constructor(this: &Ptr) { - field!((*this), key).write(1); + fn default_constructor(this: Ptr) { + field!(this, key).write(1); } } impl Default for Entry_52 { @@ -243,9 +249,9 @@ pub struct Entry_54 { pub value: i32, } impl DefaultConstructible for Entry_54 { - fn default_constructor(this: &Ptr) { - field!((*this), key).write(2); - field!((*this), value).write(30); + fn default_constructor(this: Ptr) { + field!(this, key).write(2); + field!(this, value).write(30); } } impl Default for Entry_54 { @@ -367,9 +373,9 @@ pub struct Record_65 { pub extra: i32, } impl DefaultConstructible for Record_65 { - fn default_constructor(this: &Ptr) { - field!((*this), id).write(200_i64); - field!((*this), extra).write(1); + fn default_constructor(this: Ptr) { + field!(this, id).write(200_i64); + field!(this, extra).write(1); } } impl Default for Record_65 { @@ -422,12 +428,18 @@ pub fn raise_30(mut by: i32) -> i32 { )] #[byte_size(1)] pub struct Tally_67 {} +impl Tally_67 { + pub fn add(this: Ptr, mut amount: i32) -> i32 { + total_68.with(|rc| *rc.borrow_mut() += (amount * 2)); + return total_68.with(|rc| *rc.borrow()); + } +} thread_local!( pub static total_68: Value = Rc::new(RefCell::new(100)); ); pub fn add_in_b_34(mut amount: i32) -> i32 { let tally: Value = Rc::new(RefCell::new(::default())); - return ({ Tally_67Impl::add(&tally.as_pointer(), amount) }); + return ({ Tally_67::add(tally.as_pointer(), amount) }); } thread_local!( pub static balance_35: Value = Rc::new(RefCell::new(50)); @@ -468,8 +480,8 @@ pub struct Entry_71 { pub key: i64, } impl DefaultConstructible for Entry_71 { - fn default_constructor(this: &Ptr) { - field!((*this), key).write(400_i64); + fn default_constructor(this: Ptr) { + field!(this, key).write(400_i64); } } impl Default for Entry_71 { @@ -492,24 +504,6 @@ pub fn table_sum_in_b_59() -> i32 { table_57.with(|rc| rc.borrow()[__idx0]) })); } -pub trait Tally_31Impl { - fn add(&self, amount: i32) -> i32; -} -impl Tally_31Impl for Ptr { - fn add(&self, mut amount: i32) -> i32 { - total_32.with(|rc| *rc.borrow_mut() += amount); - return total_32.with(|rc| *rc.borrow()); - } -} -pub trait Tally_67Impl { - fn add(&self, amount: i32) -> i32; -} -impl Tally_67Impl for Ptr { - fn add(&self, mut amount: i32) -> i32 { - total_68.with(|rc| *rc.borrow_mut() += (amount * 2)); - return total_68.with(|rc| *rc.borrow()); - } -} pub fn __cpp2rust_init_globals() { let _ = limit_3.with(|_| ()); let _ = anon_13.with(|_| ()); diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs index 105c978f15..1099fd29ae 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs @@ -53,21 +53,27 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), uses).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -98,8 +104,13 @@ pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { #[offset(0)] pub value: i32, } +impl p1_1_condition_variable_visible_in_else_ConvertsToBool { + pub fn to_bool(this: Ptr) -> bool { + return (this.with(|__s| __s.value) != 0); + } +} impl Destructible for p1_1_condition_variable_visible_in_else_ConvertsToBool { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_6.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -109,12 +120,10 @@ pub fn test_7() { RefCell::new(p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 0 }), ); let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); if ({ - p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl::to_bool( - &condition.as_pointer(), - ) + p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(condition.as_pointer()) }) { (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); } else { @@ -131,12 +140,10 @@ pub fn test_7() { RefCell::new(p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 6 }), ); let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); if ({ - p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl::to_bool( - &condition.as_pointer(), - ) + p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(condition.as_pointer()) }) { (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); assert!(({ (*condition.borrow()).value } == 6)); @@ -193,7 +200,7 @@ pub fn test_9() { } assert!((ctorCount_0.with(|rc| *rc.borrow()) == 6)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 5)); - ({ LifetimeTrackedImpl::use_(&scoped.as_pointer()) }); + ({ LifetimeTracked::use_(scoped.as_pointer()) }); assert!(({ (*scoped.borrow()).uses } == 1)); } pub fn test_10() { @@ -222,13 +229,13 @@ pub fn test_11() { { object!(tracked, LifetimeTracked); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2)); - ({ LifetimeTrackedImpl::use_(&tracked.as_pointer()) }); + ({ LifetimeTracked::use_(tracked.as_pointer()) }); assert!(({ (*tracked.borrow()).uses } == 1)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 0)); } assert!((dtorCount_2.with(|rc| *rc.borrow()) == 1)); assert!(({ (*tracked.borrow()).uses } == 0)); - ({ LifetimeTrackedImpl::use_(&tracked.as_pointer()) }); + ({ LifetimeTracked::use_(tracked.as_pointer()) }); assert!(({ (*tracked.borrow()).uses } == 1)); assert!((useCount_3.with(|rc| *rc.borrow()) == 2)); } @@ -306,27 +313,6 @@ fn main_0() -> i32 { ({ test_16() }); return 0; } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub trait p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl { - fn to_bool(&self) -> bool; -} -impl p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl - for Ptr -{ - fn to_bool(&self) -> bool { - return ((*self).with(|__s| __s.value) != 0); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs index 9e43302a64..af9f7a8896 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.class.rs @@ -15,9 +15,21 @@ pub struct p1_member_hides_namespace_variable_HasBalance { #[offset(0)] pub balance: i32, } +impl p1_member_hides_namespace_variable_HasBalance { + pub fn deposit(this: Ptr, mut amount: i32) -> i32 { + { + field!(this, balance).with_mut(|__v| *__v = *__v + amount) + }; + return this.with(|__s| __s.balance); + } + pub fn deposit_globally(this: Ptr, mut amount: i32) -> i32 { + balance_0.with(|rc| *rc.borrow_mut() += amount); + return balance_0.with(|rc| *rc.borrow()); + } +} impl DefaultConstructible for p1_member_hides_namespace_variable_HasBalance { - fn default_constructor(this: &Ptr) { - field!((*this), balance).write(7); + fn default_constructor(this: Ptr) { + field!(this, balance).write(7); } } impl Default for p1_member_hides_namespace_variable_HasBalance { @@ -28,18 +40,14 @@ impl Default for p1_member_hides_namespace_variable_HasBalance { pub fn test_1() { object!(object, p1_member_hides_namespace_variable_HasBalance); assert!( - (({ - p1_member_hides_namespace_variable_HasBalanceImpl::deposit(&object.as_pointer(), 3) - }) == 10) + (({ p1_member_hides_namespace_variable_HasBalance::deposit(object.as_pointer(), 3,) }) + == 10) ); assert!(({ (*object.borrow()).balance } == 10)); assert!((balance_0.with(|rc| *rc.borrow()) == 50)); assert!( (({ - p1_member_hides_namespace_variable_HasBalanceImpl::deposit_globally( - &object.as_pointer(), - 4, - ) + p1_member_hides_namespace_variable_HasBalance::deposit_globally(object.as_pointer(), 4) }) == 54) ); assert!(({ (*object.borrow()).balance } == 10)); @@ -55,8 +63,8 @@ pub struct p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { pub held: i32, } impl DefaultConstructible for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { - fn default_constructor(this: &Ptr) { - field!((*this), held).write(1); + fn default_constructor(this: Ptr) { + field!(this, held).write(1); } } impl Default for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { @@ -70,6 +78,15 @@ thread_local!( thread_local!( pub static total_4: Value = Rc::new(RefCell::new((initial_3.with(|rc| *rc.borrow()) + 1))); ); +impl p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { + pub fn add(this: Ptr, mut amount: i32) -> i32 { + { + field!(this, held).with_mut(|__v| *__v = *__v + amount) + }; + total_4.with(|rc| *rc.borrow_mut() += initial_3.with(|rc| *rc.borrow())); + return this.with(|__s| __s.held); + } +} pub fn test_5() { assert!((total_4.with(|rc| *rc.borrow()) == 7)); object!( @@ -78,10 +95,7 @@ pub fn test_5() { ); assert!( (({ - p1_out_of_class_definition_is_in_class_scope_HasStaticTotalImpl::add( - &object.as_pointer(), - 4, - ) + p1_out_of_class_definition_is_in_class_scope_HasStaticTotal::add(object.as_pointer(), 4) }) == 5) ); assert!((total_4.with(|rc| *rc.borrow()) == 13)); @@ -97,38 +111,6 @@ fn main_0() -> i32 { ({ test_5() }); return 0; } -pub trait p1_member_hides_namespace_variable_HasBalanceImpl { - fn deposit(&self, amount: i32) -> i32; - fn deposit_globally(&self, amount: i32) -> i32; -} -impl p1_member_hides_namespace_variable_HasBalanceImpl - for Ptr -{ - fn deposit(&self, mut amount: i32) -> i32 { - { - field!((*self), balance).with_mut(|__v| *__v = *__v + amount) - }; - return (*self).with(|__s| __s.balance); - } - fn deposit_globally(&self, mut amount: i32) -> i32 { - balance_0.with(|rc| *rc.borrow_mut() += amount); - return balance_0.with(|rc| *rc.borrow()); - } -} -pub trait p1_out_of_class_definition_is_in_class_scope_HasStaticTotalImpl { - fn add(&self, amount: i32) -> i32; -} -impl p1_out_of_class_definition_is_in_class_scope_HasStaticTotalImpl - for Ptr -{ - fn add(&self, mut amount: i32) -> i32 { - { - field!((*self), held).with_mut(|__v| *__v = *__v + amount) - }; - total_4.with(|rc| *rc.borrow_mut() += initial_3.with(|rc| *rc.borrow())); - return (*self).with(|__s| __s.held); - } -} pub fn __cpp2rust_init_globals() { let _ = balance_0.with(|_| ()); let _ = initial_2.with(|_| ()); diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs index 6942fe2142..51f3d0b9df 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs @@ -25,6 +25,17 @@ pub struct p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParamete #[offset(0)] pub amount: i32, } +impl p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { + pub fn construct(this: Ptr, mut amount: i32) { + field!(this, amount).write((amount + 1)); + amount += 10; + assert!((amount == 14)); + assert!((this.with(|__s| __s.amount) == 5)); + } + pub fn add(this: Ptr, mut amount: i32) -> i32 { + return (this.with(|__s| __s.amount) + amount); + } +} pub fn test_0() { object!( object, @@ -33,8 +44,8 @@ pub fn test_0() { assert!(({ (*object.borrow()).amount } == 5)); assert!( (({ - p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameterImpl::add( - &object.as_pointer(), + p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter::add( + object.as_pointer(), 20, ) }) == 25) @@ -85,23 +96,6 @@ fn main_0() -> i32 { ({ test_5() }); return 0; } -pub trait p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameterImpl { - fn construct(&self, amount: i32); - fn add(&self, amount: i32) -> i32; -} -impl p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameterImpl - for Ptr -{ - fn construct(&self, mut amount: i32) { - field!((*self), amount).write((amount + 1)); - amount += 10; - assert!((amount == 14)); - assert!(((*self).with(|__s| __s.amount) == 5)); - } - fn add(&self, mut amount: i32) -> i32 { - return ((*self).with(|__s| __s.amount) + amount); - } -} pub fn __cpp2rust_init_globals() { let _ = rate_1.with(|_| ()); } diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs index 7d4bc28b97..fcfaeefccc 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs @@ -91,10 +91,10 @@ pub struct p9_func_declared_before_function_body_RecordsConstructorName { pub name: Ptr, } impl DefaultConstructible for p9_func_declared_before_function_body_RecordsConstructorName { - fn default_constructor(this: &Ptr) { - field!((*this), name).write(Ptr::::from_string_literal(b"RecordsConstructorName")); + fn default_constructor(this: Ptr) { + field!(this, name).write(Ptr::::from_string_literal(b"RecordsConstructorName")); assert!( - ((*this).with(|__s| __s.name.clone()) + (this.with(|__s| __s.name.clone()) == Ptr::::from_string_literal(b"RecordsConstructorName")) ); } @@ -107,7 +107,7 @@ impl Default for p9_func_declared_before_function_body_RecordsConstructorName { Rc::new(RefCell::new( ::zero_init(), )); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs index 61044feeba..f2e8701287 100644 --- a/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs +++ b/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs @@ -58,6 +58,12 @@ pub const p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large: )] #[byte_size(1)] pub struct p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum {} +impl p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum { + pub fn scale(this: Ptr, mut count: i32) -> i32 { + return (count + * (p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large as i32)); + } +} pub fn test_5() { assert!(((p2_11_unscoped_enumerator_in_both_scopes_Direction_north as i32) == 4)); assert!(((p2_11_unscoped_enumerator_in_both_scopes_Direction_north as i32) == 4)); @@ -72,10 +78,7 @@ pub fn test_5() { ); assert!( (({ - p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnumImpl::scale( - &object.as_pointer(), - 2, - ) + p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum::scale(object.as_pointer(), 2) }) == 16) ); assert!(((p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_small as i32) == 3)); @@ -194,6 +197,11 @@ pub struct p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion { #[byte_size(8)] pub anon_9: anon_9, } +impl p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion { + pub fn read_count(this: Ptr) -> i32 { + return (anon_9::member_count(field_ptr!(this, anon_9)).read()); + } +} pub fn test_10() { anon_8::namespace_count(anon_8.with(|v| v.as_pointer())).write(4); assert!(((anon_8::namespace_count(anon_8.with(|v| v.as_pointer())).read()) == 4)); @@ -207,8 +215,8 @@ pub fn test_10() { assert!(((anon_9::member_count(field_ptr!(object.as_pointer(), anon_9)).read()) == 6)); assert!( (({ - p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnionImpl::read_count( - &object.as_pointer(), + p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion::read_count( + object.as_pointer(), ) }) == 6) ); @@ -260,10 +268,24 @@ pub struct p3_2_const_qualified_member_is_distinct_HasConstOverload { #[offset(4)] pub const_calls: i32, } +impl p3_2_const_qualified_member_is_distinct_HasConstOverload { + pub fn get_1(this: Ptr) -> i32 { + field!(this, plain_calls).with_mut(|__v| { + __v.prefix_inc(); + }); + return 1; + } + pub fn get_2(this: Ptr) -> i32 { + field!(this, const_calls).with_mut(|__v| { + __v.prefix_inc(); + }); + return 2; + } +} impl DefaultConstructible for p3_2_const_qualified_member_is_distinct_HasConstOverload { - fn default_constructor(this: &Ptr) { - field!((*this), plain_calls).write(0); - field!((*this), const_calls).write(0); + fn default_constructor(this: Ptr) { + field!(this, plain_calls).write(0); + field!(this, const_calls).write(0); } } impl Default for p3_2_const_qualified_member_is_distinct_HasConstOverload { @@ -284,15 +306,14 @@ pub fn test_12() { let view: Ptr = object.as_pointer(); assert!( (({ - p3_2_const_qualified_member_is_distinct_HasConstOverloadImpl::get_1( - &object.as_pointer(), - ) + p3_2_const_qualified_member_is_distinct_HasConstOverload::get_1(object.as_pointer()) }) == 1) ); assert!(({ (*object.borrow()).plain_calls } == 1)); assert!(({ (*object.borrow()).const_calls } == 0)); assert!( - (({ p3_2_const_qualified_member_is_distinct_HasConstOverloadImpl::get_2(&view,) }) == 2) + (({ p3_2_const_qualified_member_is_distinct_HasConstOverload::get_2((view).clone(),) }) + == 2) ); assert!(({ (*object.borrow()).plain_calls } == 1)); assert!(({ (*object.borrow()).const_calls } == 1)); @@ -309,11 +330,24 @@ pub struct p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjec #[offset(0)] pub base: i32, } +impl p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { + pub fn pick_1( + self_: Ptr, + mut amount: i32, + ) -> i32 { + (*explicit_calls_13.with(Value::clone).borrow_mut()).prefix_inc(); + return ({ self_.with(|__s| __s.base) } + { amount }); + } + pub fn pick_2(this: Ptr, mut amount: i32) -> i32 { + (*rvalue_calls_14.with(Value::clone).borrow_mut()).prefix_inc(); + return ((this.with(|__s| __s.base) + amount) + 100); + } +} impl DefaultConstructible for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { - fn default_constructor(this: &Ptr) { - field!((*this), base).write(10); + fn default_constructor(this: Ptr) { + field!(this, base).write(10); } } impl Default for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { @@ -332,7 +366,10 @@ pub fn test_15() { ); assert!( (({ - as p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverloadImpl>::pick_1 ( object .as_pointer() , 1 , ) + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload::pick_1( + object.as_pointer(), + 1, + ) }) == 11) ); assert!((explicit_calls_13.with(|rc| *rc.borrow()) == 1)); @@ -341,7 +378,7 @@ pub fn test_15() { let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); assert!( (({ - p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverloadImpl :: pick_2 ( &{ DefaultConstructible::default_constructor(&__tmp_0.as_pointer()) ; __tmp_0.as_pointer() } , 2 , ) + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( { DefaultConstructible::default_constructor(__tmp_0.as_pointer()) ; __tmp_0.as_pointer() } , 2 , ) }) == 112) ) }; @@ -368,14 +405,24 @@ thread_local!( )] #[byte_size(1)] pub struct p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads {} +impl p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads { + pub fn get_1(this: Ptr) -> i32 { + (*lvalue_calls_16.with(Value::clone).borrow_mut()).prefix_inc(); + return 3; + } + pub fn get_2(this: Ptr) -> i32 { + (*rvalue_calls_17.with(Value::clone).borrow_mut()).prefix_inc(); + return 4; + } +} pub fn test_18() { let object: Value = Rc::new( RefCell::new(::default()), ); assert!( (({ - p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloadsImpl::get_1( - &object.as_pointer(), + p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads::get_1( + object.as_pointer(), ) }) == 3) ); @@ -383,8 +430,8 @@ pub fn test_18() { assert!((rvalue_calls_17.with(|rc| *rc.borrow()) == 0)); assert!( (({ - p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloadsImpl::get_2( - &Rc::new(RefCell::new( + p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads::get_2( + Rc::new(RefCell::new( ::default(), )) .as_pointer(), @@ -395,8 +442,8 @@ pub fn test_18() { assert!((rvalue_calls_17.with(|rc| *rc.borrow()) == 1)); assert!( (({ - p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloadsImpl::get_2( - &object.as_pointer(), + p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads::get_2( + object.as_pointer(), ) }) == 4) ); @@ -411,12 +458,26 @@ pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOv #[offset(4)] pub const_calls: i32, } +impl p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { + pub fn get_1_int(this: Ptr, mut value: i32) -> i32 { + field!(this, plain_calls).with_mut(|__v| { + __v.prefix_inc(); + }); + return (value + 1); + } + pub fn get_2_int(this: Ptr, mut value: i32) -> i32 { + field!(this, const_calls).with_mut(|__v| { + __v.prefix_inc(); + }); + return (value + 2); + } +} impl DefaultConstructible for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { - fn default_constructor(this: &Ptr) { - field!((*this), plain_calls).write(0); - field!((*this), const_calls).write(0); + fn default_constructor(this: Ptr) { + field!(this, plain_calls).write(0); + field!(this, const_calls).write(0); } } impl Default for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { @@ -438,14 +499,20 @@ pub fn test_19() { object.as_pointer(); assert!( (({ - p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverloadImpl :: get_1_int ( &object .as_pointer() , 10 , ) + p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload::get_1_int( + object.as_pointer(), + 10, + ) }) == 11) ); assert!(({ (*object.borrow()).plain_calls } == 1)); assert!(({ (*object.borrow()).const_calls } == 0)); assert!( (({ - p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverloadImpl :: get_2_int ( &view , 10 , ) + p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload::get_2_int( + (view).clone(), + 10, + ) }) == 12) ); assert!(({ (*object.borrow()).plain_calls } == 1)); @@ -471,25 +538,35 @@ thread_local!( )] #[byte_size(1)] pub struct p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads {} +impl p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads { + pub fn get_1_int(this: Ptr, mut value: i32) -> i32 { + (*lvalue_calls_20.with(Value::clone).borrow_mut()).prefix_inc(); + return (value + 3); + } + pub fn get_2_int(this: Ptr, mut value: i32) -> i32 { + (*rvalue_calls_21.with(Value::clone).borrow_mut()).prefix_inc(); + return (value + 4); + } +} pub fn test_22() { let object : Value = Rc::new(RefCell::new(::default() )) ; assert!( (({ - p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloadsImpl :: get_1_int ( &object .as_pointer() , 10 , ) + p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads :: get_1_int ( object .as_pointer() , 10 , ) }) == 13) ); assert!((lvalue_calls_20.with(|rc| *rc.borrow()) == 1)); assert!((rvalue_calls_21.with(|rc| *rc.borrow()) == 0)); assert!( (({ - p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloadsImpl :: get_2_int ( &Rc::new(RefCell::new(::default() )).as_pointer() , 10 , ) + p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads :: get_2_int ( Rc::new(RefCell::new(::default() )).as_pointer() , 10 , ) }) == 14) ); assert!((lvalue_calls_20.with(|rc| *rc.borrow()) == 1)); assert!((rvalue_calls_21.with(|rc| *rc.borrow()) == 1)); assert!( (({ - p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloadsImpl :: get_2_int ( &object .as_pointer() , 10 , ) + p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads :: get_2_int ( object .as_pointer() , 10 , ) }) == 14) ); assert!((lvalue_calls_20.with(|rc| *rc.borrow()) == 1)); @@ -775,121 +852,6 @@ fn main_0() -> i32 { ({ test_64() }); return 0; } -pub trait p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnumImpl { - fn scale(&self, count: i32) -> i32; -} -impl p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnumImpl - for Ptr -{ - fn scale(&self, mut count: i32) -> i32 { - return (count - * (p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large as i32)); - } -} -pub trait p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnionImpl { - fn read_count(&self) -> i32; -} -impl p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnionImpl - for Ptr -{ - fn read_count(&self) -> i32 { - return (anon_9::member_count(field_ptr!((*self), anon_9)).read()); - } -} -pub trait p3_2_const_qualified_member_is_distinct_HasConstOverloadImpl { - fn get_1(&self) -> i32; - fn get_2(&self) -> i32; -} -impl p3_2_const_qualified_member_is_distinct_HasConstOverloadImpl - for Ptr -{ - fn get_1(&self) -> i32 { - field!((*self), plain_calls).with_mut(|__v| { - __v.prefix_inc(); - }); - return 1; - } - fn get_2(&self) -> i32 { - field!((*self), const_calls).with_mut(|__v| { - __v.prefix_inc(); - }); - return 2; - } -} -pub trait p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverloadImpl { - fn pick_1( - self_: Ptr, - amount: i32, - ) -> i32; - fn pick_2(&self, amount: i32) -> i32; -} -impl p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverloadImpl - for Ptr -{ - fn pick_1( - self_: Ptr, - mut amount: i32, - ) -> i32 { - (*explicit_calls_13.with(Value::clone).borrow_mut()).prefix_inc(); - return ({ self_.with(|__s| __s.base) } + { amount }); - } - fn pick_2(&self, mut amount: i32) -> i32 { - (*rvalue_calls_14.with(Value::clone).borrow_mut()).prefix_inc(); - return (((*self).with(|__s| __s.base) + amount) + 100); - } -} -pub trait p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloadsImpl { - fn get_1(&self) -> i32; - fn get_2(&self) -> i32; -} -impl p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloadsImpl - for Ptr -{ - fn get_1(&self) -> i32 { - (*lvalue_calls_16.with(Value::clone).borrow_mut()).prefix_inc(); - return 3; - } - fn get_2(&self) -> i32 { - (*rvalue_calls_17.with(Value::clone).borrow_mut()).prefix_inc(); - return 4; - } -} -pub trait p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverloadImpl { - fn get_1_int(&self, value: i32) -> i32; - fn get_2_int(&self, value: i32) -> i32; -} -impl p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverloadImpl - for Ptr -{ - fn get_1_int(&self, mut value: i32) -> i32 { - field!((*self), plain_calls).with_mut(|__v| { - __v.prefix_inc(); - }); - return (value + 1); - } - fn get_2_int(&self, mut value: i32) -> i32 { - field!((*self), const_calls).with_mut(|__v| { - __v.prefix_inc(); - }); - return (value + 2); - } -} -pub trait p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloadsImpl { - fn get_1_int(&self, value: i32) -> i32; - fn get_2_int(&self, value: i32) -> i32; -} -impl p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloadsImpl - for Ptr -{ - fn get_1_int(&self, mut value: i32) -> i32 { - (*lvalue_calls_20.with(Value::clone).borrow_mut()).prefix_inc(); - return (value + 3); - } - fn get_2_int(&self, mut value: i32) -> i32 { - (*rvalue_calls_21.with(Value::clone).borrow_mut()).prefix_inc(); - return (value + 4); - } -} pub fn __cpp2rust_init_globals() { let _ = level_0.with(|_| ()); let _ = function_calls_2.with(|_| ()); diff --git a/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs b/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs index d9091a2f10..348c1b15be 100644 --- a/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs +++ b/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs @@ -24,20 +24,26 @@ pub struct Tracker { #[offset(0)] pub tag: i32, } +impl Tracker { + pub fn construct(this: Ptr, mut tag: i32) { + field!(this, tag).write(tag); + printf!(b"construct %d\n", tag); + } +} impl Destructible for Tracker { - fn destroy(this: &Ptr) { - printf!(b"destroy %d\n", (*this).with(|__s| __s.tag)); + fn destroy(this: Ptr) { + printf!(b"destroy %d\n", this.with(|__s| __s.tag)); } } thread_local!( pub static global_0: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackerImpl::construct(&__v.as_pointer(), 1); + Tracker::construct(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&global_0.with(Value::clone).as_pointer()) + Destructible::destroy(global_0.with(Value::clone).as_pointer()) }); __static }; @@ -53,11 +59,11 @@ thread_local!( static local_static_2: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackerImpl::construct(&__v.as_pointer(), 2); + Tracker::construct(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&local_static_2.with(Value::clone).as_pointer()) + Destructible::destroy(local_static_2.with(Value::clone).as_pointer()) }); __static }; @@ -71,15 +77,6 @@ fn main_0() -> i32 { printf!(b"not reached\n"); return 0; } -pub trait TrackerImpl { - fn construct(&self, tag: i32); -} -impl TrackerImpl for Ptr { - fn construct(&self, mut tag: i32) { - field!((*self), tag).write(tag); - printf!(b"construct %d\n", tag); - } -} pub fn __cpp2rust_init_globals() { let _ = global_0.with(|_| ()); } diff --git a/tests/std/basic/basic.start/out/refcount/basic.start.term.rs b/tests/std/basic/basic.start/out/refcount/basic.start.term.rs index 4aa908f4f4..6b1d94835e 100644 --- a/tests/std/basic/basic.start/out/refcount/basic.start.term.rs +++ b/tests/std/basic/basic.start/out/refcount/basic.start.term.rs @@ -24,9 +24,18 @@ pub struct Tracker { #[offset(0)] pub tag: i32, } +impl Tracker { + pub fn construct(this: Ptr, mut tag: i32) { + field!(this, tag).write(tag); + printf!(b"construct %d\n", tag); + } + pub fn touch(this: Ptr) { + printf!(b"touch %d\n", this.with(|__s| __s.tag)); + } +} impl Destructible for Tracker { - fn destroy(this: &Ptr) { - printf!(b"destroy %d\n", (*this).with(|__s| __s.tag)); + fn destroy(this: Ptr) { + printf!(b"destroy %d\n", this.with(|__s| __s.tag)); } } #[derive( @@ -71,30 +80,30 @@ thread_local!( pub static global_0: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackerImpl::construct(&__v.as_pointer(), 1); + Tracker::construct(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&global_0.with(Value::clone).as_pointer()) + Destructible::destroy(global_0.with(Value::clone).as_pointer()) }); __static }; ); pub fn never_called_1() { - ({ TrackerImpl::touch(&never_constructed_2.with(|v| v.as_pointer())) }); + ({ Tracker::touch(never_constructed_2.with(|v| v.as_pointer())) }); } pub fn test_3() { - ({ TrackerImpl::touch(&global_0.with(|v| v.as_pointer())) }); + ({ Tracker::touch(global_0.with(|v| v.as_pointer())) }); } thread_local!( static never_constructed_2: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackerImpl::construct(&__v.as_pointer(), 100); + Tracker::construct(__v.as_pointer(), 100); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&never_constructed_2.with(Value::clone).as_pointer()) + Destructible::destroy(never_constructed_2.with(Value::clone).as_pointer()) }); __static }; @@ -106,11 +115,11 @@ thread_local!( pub static before_6: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackerImpl::construct(&__v.as_pointer(), 2); + Tracker::construct(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&before_6.with(Value::clone).as_pointer()) + Destructible::destroy(before_6.with(Value::clone).as_pointer()) }); __static }; @@ -119,14 +128,14 @@ thread_local!( pub static after_7: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackerImpl::construct( - &__v.as_pointer(), + Tracker::construct( + __v.as_pointer(), (({ local_static_during_global_init_4() }).with(|__s| __s.tag) + 1), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&after_7.with(Value::clone).as_pointer()) + Destructible::destroy(after_7.with(Value::clone).as_pointer()) }); __static }; @@ -136,12 +145,12 @@ thread_local!( let __static = Rc::new(RefCell::new(HoldsTracker { member: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackerImpl::construct(&__v.as_pointer(), 5); + Tracker::construct(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&holder_8.with(Value::clone).as_pointer()) + Destructible::destroy(holder_8.with(Value::clone).as_pointer()) }); __static }; @@ -168,11 +177,11 @@ thread_local!( pub static member_10: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackerImpl::construct(&__v.as_pointer(), 7); + Tracker::construct(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&member_10.with(Value::clone).as_pointer()) + Destructible::destroy(member_10.with(Value::clone).as_pointer()) }); __static }; @@ -183,7 +192,7 @@ thread_local!( { let captured: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackerImpl::construct(&__v.as_pointer(), 8); + Tracker::construct(__v.as_pointer(), 8); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -192,20 +201,20 @@ thread_local!( } ))); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&capturing_11.with(Value::clone).as_pointer()) + Destructible::destroy(capturing_11.with(Value::clone).as_pointer()) }); __static }; ); pub fn run_local_static_12() { - ({ TrackerImpl::touch(&during_main_13.with(|v| v.as_pointer())) }); + ({ Tracker::touch(during_main_13.with(|v| v.as_pointer())) }); } pub fn test_14() { ({ run_local_static_12() }); ({ run_local_static_12() }); - ({ TrackerImpl::touch(&({ local_static_during_global_init_4() })) }); + ({ Tracker::touch(({ local_static_during_global_init_4() })) }); printf!(b"trivial %d\n", { trivial_9.with(|rc| *rc.borrow()).value }); - ({ TrackerImpl::touch(&member_10.with(|v| v.as_pointer())) }); + ({ Tracker::touch(member_10.with(|v| v.as_pointer())) }); printf!( b"captured %d\n", ({ (*capturing_11.with(Value::clone).borrow()).call() }) @@ -215,11 +224,11 @@ thread_local!( static during_init_5: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackerImpl::construct(&__v.as_pointer(), 3); + Tracker::construct(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&during_init_5.with(Value::clone).as_pointer()) + Destructible::destroy(during_init_5.with(Value::clone).as_pointer()) }); __static }; @@ -228,11 +237,11 @@ thread_local!( static during_main_13: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - TrackerImpl::construct(&__v.as_pointer(), 9); + Tracker::construct(__v.as_pointer(), 9); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&during_main_13.with(Value::clone).as_pointer()) + Destructible::destroy(during_main_13.with(Value::clone).as_pointer()) }); __static }; @@ -247,19 +256,6 @@ fn main_0() -> i32 { printf!(b"return from main\n"); return 0; } -pub trait TrackerImpl { - fn construct(&self, tag: i32); - fn touch(&self); -} -impl TrackerImpl for Ptr { - fn construct(&self, mut tag: i32) { - field!((*self), tag).write(tag); - printf!(b"construct %d\n", tag); - } - fn touch(&self) { - printf!(b"touch %d\n", (*self).with(|__s| __s.tag)); - } -} pub fn __cpp2rust_init_globals() { let _ = global_0.with(|_| ()); let _ = before_6.with(|_| ()); diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index c9407dca3a..80212c0812 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -33,10 +33,13 @@ impl HasConstexprCtor { pub fn reset() { copyCount_0.with(|rc| *rc.borrow_mut() = 0); } + pub fn construct(this: Ptr, mut v: i32) { + field!(this, m).write(v); + } } impl CopyConstructible for HasConstexprCtor { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), m).write(o.with(|__s| __s.m)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, m).write(o.with(|__s| __s.m)); (*copyCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -87,21 +90,27 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_4.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), uses).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, uses).write(0); (*copyCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_3.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -111,13 +120,13 @@ pub fn test_5() { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 3); + HasConstexprCtor::construct(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 4); + HasConstexprCtor::construct(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ]; @@ -128,13 +137,13 @@ pub fn test_5() { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 3); + HasConstexprCtor::construct(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 4); + HasConstexprCtor::construct(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, ][(1) as usize] @@ -155,7 +164,7 @@ pub fn test_6() { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 5); + HasConstexprCtor::construct(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() } .m @@ -178,14 +187,14 @@ pub fn test_7() { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 7); + HasConstexprCtor::construct(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } else { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 9); + HasConstexprCtor::construct(__v.as_pointer(), 9); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }) @@ -214,7 +223,7 @@ pub fn test_9() { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - HasConstexprCtorImpl::construct(&__v.as_pointer(), 5); + HasConstexprCtor::construct(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -261,11 +270,11 @@ thread_local!( pub static global_12: Value = { let __static = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); libcc2rs::register_static_destructor(|| { - Destructible::destroy(&global_12.with(Value::clone).as_pointer()) + Destructible::destroy(global_12.with(Value::clone).as_pointer()) }); __static }; @@ -274,7 +283,7 @@ pub fn test_13() { ({ LifetimeTracked::reset() }); let r: Ptr = global_12.with(|v| v.as_pointer()); let f: Value> = Rc::new(RefCell::new(FnPtr::::new(|| { - ({ LifetimeTrackedImpl::use_(&global_12.with(|v| v.as_pointer())) }); + ({ LifetimeTracked::use_(global_12.with(|v| v.as_pointer())) }); }))); assert!((copyCount_2.with(|rc| *rc.borrow()) == 0)); ({ (*f.borrow()).call() }); @@ -291,16 +300,16 @@ pub fn test_14() { let r: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), (r).clone()); + ConstructFrom::construct_from(__v.as_pointer(), (r).clone()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, || { - ({ LifetimeTrackedImpl::use_(&r.as_pointer()) }); + ({ LifetimeTracked::use_(r.as_pointer()) }); } ))); let _dtor_f = - std::mem::DropGuard::new(f.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(f.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!((copyCount_2.with(|rc| *rc.borrow()) == 1)); ({ (*f.borrow()).call() }); assert!((copyCount_2.with(|rc| *rc.borrow()) == 1)); @@ -328,7 +337,7 @@ pub fn test_16() { let k: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), k.as_pointer()); + ConstructFrom::construct_from(__v.as_pointer(), k.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -376,13 +385,19 @@ pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { #[offset(4)] pub scratch: i32, } +impl p5_2_mutable_subobject_is_odr_used_HasMutableMember { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, value).write(v); + field!(this, scratch).write(0); + } +} impl CopyConstructible for p5_2_mutable_subobject_is_odr_used_HasMutableMember { fn copy_constructor( - this: &Ptr, + this: Ptr, o: Ptr, ) { - field!((*this), value).write(o.with(|__s| __s.value)); - field!((*this), scratch).write(o.with(|__s| __s.scratch)); + field!(this, value).write(o.with(|__s| __s.value)); + field!(this, scratch).write(o.with(|__s| __s.scratch)); (*copies_18.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -396,7 +411,7 @@ pub fn test_19() { Rc::new(RefCell::new( ::zero_init(), )); - ConstructFrom::construct_from(&__v.as_pointer(), k.as_pointer()); + ConstructFrom::construct_from(__v.as_pointer(), k.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -422,9 +437,9 @@ pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { pub b: LifetimeTracked, } impl DefaultConstructible for p6_unevaluated_binding_needs_no_capture_HasTwoMembers { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, a)); - DefaultConstructible::default_constructor(&field_ptr!(this, b)); + fn default_constructor(this: Ptr) { + DefaultConstructible::default_constructor(field_ptr!(this, a)); + DefaultConstructible::default_constructor(field_ptr!(this, b)); } } pub fn test_20() { @@ -434,19 +449,19 @@ pub fn test_20() { a: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, b: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, }, )); let _dtor_p = - std::mem::DropGuard::new(p.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(p.clone(), |__p| Destructible::destroy(__p.as_pointer())); let __decomp_21: Ptr = p.as_pointer(); let f: Value usize>> = Rc::new(RefCell::new(FnPtr:: usize>::new(|| -> usize { @@ -470,17 +485,31 @@ pub struct p7_member_access_captures_this_HasMemberUsedInLambda { #[offset(4)] pub n: i32, } +impl p7_member_access_captures_this_HasMemberUsedInLambda { + pub fn makeLambda(this: Ptr) -> FnPtr i32> { + return lambda!( + { + let this_: Value> = + Rc::new(RefCell::new((this).clone())); + }, + || -> i32 { + ({ LifetimeTracked::use_({ field_ptr!((*this_.borrow()), x) }) }); + return (*this_.borrow()).with(|__s| __s.n); + } + ); + } +} impl DefaultConstructible for p7_member_access_captures_this_HasMemberUsedInLambda { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, x)); - field!((*this), n).write(1); + fn default_constructor(this: Ptr) { + DefaultConstructible::default_constructor(field_ptr!(this, x)); + field!(this, n).write(1); } } pub fn test_22() { ({ LifetimeTracked::reset() }); object!(c, p7_member_access_captures_this_HasMemberUsedInLambda); let f: Value i32>> = Rc::new(RefCell::new( - ({ p7_member_access_captures_this_HasMemberUsedInLambdaImpl::makeLambda(&c.as_pointer()) }), + ({ p7_member_access_captures_this_HasMemberUsedInLambda::makeLambda(c.as_pointer()) }), )); assert!((copyCount_2.with(|rc| *rc.borrow()) == 0)); assert!(({ (({ (*f.borrow()).call() }) == 1) })); @@ -499,9 +528,18 @@ pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { #[destroy] pub x: LifetimeTracked, } +impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { + pub fn sizer(this: Ptr) -> FnPtr usize> { + return FnPtr:: usize>::new(|| -> usize { + { + return 4usize; + } + }); + } +} impl DefaultConstructible for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, x)); + fn default_constructor(this: Ptr) { + DefaultConstructible::default_constructor(field_ptr!(this, x)); } } pub fn test_23() { @@ -511,9 +549,7 @@ pub fn test_23() { p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda ); let f: Value usize>> = Rc::new(RefCell::new( - ({ - p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl::sizer(&c.as_pointer()) - }), + ({ p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::sizer(c.as_pointer()) }), )); assert!(({ (({ (*f.borrow()).call() }) == 4usize) })); assert!((copyCount_2.with(|rc| *rc.borrow()) == 0)); @@ -557,7 +593,7 @@ thread_local!( #[byte_size(1)] pub struct p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} impl DefaultConstructible for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { - fn default_constructor(this: &Ptr) { + fn default_constructor(this: Ptr) { (*t_ctors_27.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -565,7 +601,7 @@ pub fn test_28() { let mut p: Ptr = { let __p = Ptr::alloc(::zero_init()); - DefaultConstructible::default_constructor(&__p); + DefaultConstructible::default_constructor(__p.clone()); __p }; assert!(!((p).is_null())); @@ -592,8 +628,8 @@ pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { pub value: i32, } impl DefaultConstructible for p9_unused_copy_constructor_HasUndefinedCopyCtor { - fn default_constructor(this: &Ptr) { - field!((*this), value).write(3); + fn default_constructor(this: Ptr) { + field!(this, value).write(3); (*ctor_calls_29.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -604,7 +640,7 @@ impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -636,7 +672,7 @@ thread_local!( #[byte_size(1)] pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} impl DefaultConstructible for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - fn default_constructor(this: &Ptr) { + fn default_constructor(this: Ptr) { (*m_ctors_32.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -648,7 +684,7 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { Rc::new(RefCell::new( ::zero_init(), )); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -673,8 +709,8 @@ pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { pub m: p9_unused_implicit_assignment_HasUndefinedCopyAssignment, } impl DefaultConstructible for p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, m)); + fn default_constructor(this: Ptr) { + DefaultConstructible::default_constructor(field_ptr!(this, m)); } } pub fn test_33() { @@ -820,89 +856,26 @@ impl p4_1_pure_virtual_without_definition_HasPureVirtual } } impl Destructible for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { unreachable!( "p9_destructor_not_potentially_invoked_HasUndefinedDestructor::destroy is never defined" ) } } impl CopyConstructible for p9_unused_copy_constructor_HasUndefinedCopyCtor { - fn copy_constructor(this: &Ptr, _: Ptr) { + fn copy_constructor(this: Ptr, _: Ptr) { unreachable!( "p9_unused_copy_constructor_HasUndefinedCopyCtor::copy_constructor is never defined" ) } } impl CopyAssignable for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - fn copy_assign(this: &Ptr, _: Ptr) -> Ptr { + fn copy_assign(this: Ptr, _: Ptr) -> Ptr { unreachable!( "p9_unused_implicit_assignment_HasUndefinedCopyAssignment::copy_assign is never defined" ) } } -pub trait HasConstexprCtorImpl { - fn construct(&self, v: i32); -} -impl HasConstexprCtorImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), m).write(v); - } -} -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_4.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub trait p5_2_mutable_subobject_is_odr_used_HasMutableMemberImpl { - fn construct(&self, v: i32); -} -impl p5_2_mutable_subobject_is_odr_used_HasMutableMemberImpl - for Ptr -{ - fn construct(&self, mut v: i32) { - field!((*self), value).write(v); - field!((*self), scratch).write(0); - } -} -pub trait p7_member_access_captures_this_HasMemberUsedInLambdaImpl { - fn makeLambda(&self) -> FnPtr i32>; -} -impl p7_member_access_captures_this_HasMemberUsedInLambdaImpl - for Ptr -{ - fn makeLambda(&self) -> FnPtr i32> { - return lambda!( - { - let this_: Value> = - Rc::new(RefCell::new((*self).clone())); - }, - || -> i32 { - ({ LifetimeTrackedImpl::use_(&field_ptr!((*this_.borrow()), x)) }); - return (*this_.borrow()).with(|__s| __s.n); - } - ); - } -} -pub trait p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl { - fn sizer(&self) -> FnPtr usize>; -} -impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl - for Ptr -{ - fn sizer(&self) -> FnPtr usize> { - return FnPtr:: usize>::new(|| -> usize { - { - return 4usize; - } - }); - } -} pub fn __cpp2rust_init_globals() { let _ = copyCount_0.with(|_| ()); let _ = ctorCount_1.with(|_| ()); diff --git a/tests/std/class/class.init/out/refcount/class.base.init.rs b/tests/std/class/class.init/out/refcount/class.base.init.rs index 2534e5dade..2acd1ac802 100644 --- a/tests/std/class/class.init/out/refcount/class.base.init.rs +++ b/tests/std/class/class.init/out/refcount/class.base.init.rs @@ -27,6 +27,12 @@ pub struct p13_3_member_reads_earlier_member_Pair { #[offset(4)] pub second: i32, } +impl p13_3_member_reads_earlier_member_Pair { + pub fn construct(this: Ptr, mut first: i32) { + field!(this, first).write(first); + field!(this, second).write((this.with(|__s| __s.first) + 1)); + } +} pub fn test_0() { object!(pair, p13_3_member_reads_earlier_member_Pair(5)); assert!(({ (*pair.borrow()).first } == 5)); @@ -40,13 +46,4 @@ fn main_0() -> i32 { ({ test_0() }); return 0; } -pub trait p13_3_member_reads_earlier_member_PairImpl { - fn construct(&self, first: i32); -} -impl p13_3_member_reads_earlier_member_PairImpl for Ptr { - fn construct(&self, mut first: i32) { - field!((*self), first).write(first); - field!((*self), second).write(((*self).with(|__s| __s.first) + 1)); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs index fa63940b66..039b106303 100644 --- a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs +++ b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.ctor.rs @@ -6,6 +6,11 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; +impl p1_template_constructor_from_own_type_Probe { + pub fn construct_1(this: Ptr, u: Ptr) { + field!(this, value).write((u.with(|__s| __s.value) + 1)); + } +} #[derive( Copy, Clone, @@ -25,6 +30,11 @@ pub struct p1_template_constructor_from_own_type_Probe { #[offset(0)] pub value: i32, } +impl p1_template_constructor_from_own_type_Probe { + pub fn construct_2(this: Ptr, mut v: i32) { + field!(this, value).write(v); + } +} pub fn test_0() { object!( probe, @@ -44,18 +54,4 @@ fn main_0() -> i32 { ({ test_0() }); return 0; } -pub trait p1_template_constructor_from_own_type_ProbeImpl { - fn construct_1(&self, u: Ptr); - fn construct_2(&self, v: i32); -} -impl p1_template_constructor_from_own_type_ProbeImpl - for Ptr -{ - fn construct_1(&self, u: Ptr) { - field!((*self), value).write((u.with(|__s| __s.value) + 1)); - } - fn construct_2(&self, mut v: i32) { - field!((*self), value).write(v); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs index 23cb1a23dc..5a5238fcda 100644 --- a/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs +++ b/tests/std/class/class.mem/class.conv/out/refcount/class.conv.fct.rs @@ -25,13 +25,18 @@ pub struct p2_non_const_conversion_function_Gauge { #[offset(0)] pub value: i64, } +impl p2_non_const_conversion_function_Gauge { + pub fn to_i64(this: Ptr) -> i64 { + return field!(this, value).with_mut(|__v| __v.prefix_inc().clone()); + } +} pub fn test_0() { let gauge: Value = Rc::new(RefCell::new(p2_non_const_conversion_function_Gauge { value: 20_i64, })); let mut converted: i64 = - ({ p2_non_const_conversion_function_GaugeImpl::to_i64(&gauge.as_pointer()) }); + ({ p2_non_const_conversion_function_Gauge::to_i64(gauge.as_pointer()) }); assert!((converted == 21_i64)); assert!(({ (*gauge.borrow()).value } == 21_i64)); } @@ -43,12 +48,4 @@ fn main_0() -> i32 { ({ test_0() }); return 0; } -pub trait p2_non_const_conversion_function_GaugeImpl { - fn to_i64(&self) -> i64; -} -impl p2_non_const_conversion_function_GaugeImpl for Ptr { - fn to_i64(&self) -> i64 { - return field!((*self), value).with_mut(|__v| __v.prefix_inc().clone()); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs b/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs index ca0bfcf7da..0b4938b1d8 100644 --- a/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs +++ b/tests/std/class/class.mem/class.ctor/out/refcount/class.copy.ctor.rs @@ -23,6 +23,11 @@ pub struct p11_defaulted_move_constructor_is_trivial_MoveOnly { #[offset(0)] pub value: i32, } +impl p11_defaulted_move_constructor_is_trivial_MoveOnly { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + } +} pub fn pass_0( object: p11_defaulted_move_constructor_is_trivial_MoveOnly, ) -> p11_defaulted_move_constructor_is_trivial_MoveOnly { @@ -32,7 +37,7 @@ pub fn pass_0( let __v: Value = Rc::new(RefCell::new( ::zero_init(), )); - ConstructFrom::construct_from(&__v.as_pointer(), Moved(object.as_pointer())); + ConstructFrom::construct_from(__v.as_pointer(), Moved(object.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -42,7 +47,7 @@ pub fn test_1() { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - p11_defaulted_move_constructor_is_trivial_MoveOnlyImpl::construct(&__v.as_pointer(), 7); + p11_defaulted_move_constructor_is_trivial_MoveOnly::construct(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }); @@ -74,14 +79,4 @@ fn main_0() -> i32 { ({ test_3() }); return 0; } -pub trait p11_defaulted_move_constructor_is_trivial_MoveOnlyImpl { - fn construct(&self, value: i32); -} -impl p11_defaulted_move_constructor_is_trivial_MoveOnlyImpl - for Ptr -{ - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/class/class.mem/out/refcount/class.mem.general.rs b/tests/std/class/class.mem/out/refcount/class.mem.general.rs index c0d307643a..d33d83e7b8 100644 --- a/tests/std/class/class.mem/out/refcount/class.mem.general.rs +++ b/tests/std/class/class.mem/out/refcount/class.mem.general.rs @@ -20,9 +20,22 @@ pub struct p7_1_function_body_names_later_member_HasLaterMembers { #[offset(0)] pub stock: i32, } +impl p7_1_function_body_names_later_member_HasLaterMembers { + pub fn take(this: Ptr, mut amount: i32) -> i32 { + { + field!(this, stock).with_mut(|__v| *__v = *__v - amount) + }; + return ((this.with(|__s| __s.stock) + + ({ p7_1_function_body_names_later_member_HasLaterMembers::minimum(this.clone()) })) + + (anon_2_reserve as i32)); + } + pub fn minimum(this: Ptr) -> i32 { + return 2; + } +} impl DefaultConstructible for p7_1_function_body_names_later_member_HasLaterMembers { - fn default_constructor(this: &Ptr) { - field!((*this), stock).write(9); + fn default_constructor(this: Ptr) { + field!(this, stock).write(9); } } impl Default for p7_1_function_body_names_later_member_HasLaterMembers { @@ -37,7 +50,7 @@ pub fn test_3() { ); assert!( (({ - p7_1_function_body_names_later_member_HasLaterMembersImpl::take(&object.as_pointer(), 3) + p7_1_function_body_names_later_member_HasLaterMembers::take(object.as_pointer(), 3) }) == 38) ); assert!(({ (*object.borrow()).stock } == 6)); @@ -55,9 +68,17 @@ pub struct p7_2_default_argument_names_later_member_HasLaterStaticStep { #[offset(0)] pub total: i32, } +impl p7_2_default_argument_names_later_member_HasLaterStaticStep { + pub fn advance(this: Ptr, mut amount: i32) -> i32 { + { + field!(this, total).with_mut(|__v| *__v = *__v + amount) + }; + return this.with(|__s| __s.total); + } +} impl DefaultConstructible for p7_2_default_argument_names_later_member_HasLaterStaticStep { - fn default_constructor(this: &Ptr) { - field!((*this), total).write(1); + fn default_constructor(this: Ptr) { + field!(this, total).write(1); } } impl Default for p7_2_default_argument_names_later_member_HasLaterStaticStep { @@ -72,16 +93,16 @@ pub fn test_6() { ); assert!( (({ - p7_2_default_argument_names_later_member_HasLaterStaticStepImpl::advance( - &object.as_pointer(), + p7_2_default_argument_names_later_member_HasLaterStaticStep::advance( + object.as_pointer(), step_5.with(|rc| *rc.borrow()), ) }) == 5) ); assert!( (({ - p7_2_default_argument_names_later_member_HasLaterStaticStepImpl::advance( - &object.as_pointer(), + p7_2_default_argument_names_later_member_HasLaterStaticStep::advance( + object.as_pointer(), 2, ) }) == 7) @@ -97,38 +118,6 @@ fn main_0() -> i32 { ({ test_6() }); return 0; } -pub trait p7_1_function_body_names_later_member_HasLaterMembersImpl { - fn take(&self, amount: i32) -> i32; - fn minimum(&self) -> i32; -} -impl p7_1_function_body_names_later_member_HasLaterMembersImpl - for Ptr -{ - fn take(&self, mut amount: i32) -> i32 { - { - field!((*self), stock).with_mut(|__v| *__v = *__v - amount) - }; - return (((*self).with(|__s| __s.stock) - + ({ p7_1_function_body_names_later_member_HasLaterMembersImpl::minimum(self) })) - + (anon_2_reserve as i32)); - } - fn minimum(&self) -> i32 { - return 2; - } -} -pub trait p7_2_default_argument_names_later_member_HasLaterStaticStepImpl { - fn advance(&self, amount: i32) -> i32; -} -impl p7_2_default_argument_names_later_member_HasLaterStaticStepImpl - for Ptr -{ - fn advance(&self, mut amount: i32) -> i32 { - { - field!((*self), total).with_mut(|__v| *__v = *__v + amount) - }; - return (*self).with(|__s| __s.total); - } -} pub fn __cpp2rust_init_globals() { let _ = stock_0.with(|_| ()); let _ = step_4.with(|_| ()); diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs index f61413b802..f960eaddcf 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/refcount/dcl.init.general.rs @@ -402,9 +402,9 @@ pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { pub five: i32, } impl DefaultConstructible for p9_1_2_zero_then_default_initialized_WithDefaultMember { - fn default_constructor(this: &Ptr) { - field!((*this), zeroed).write(0_i32); - field!((*this), five).write(5); + fn default_constructor(this: Ptr) { + field!(this, zeroed).write(0_i32); + field!(this, five).write(5); } } impl Default for p9_1_2_zero_then_default_initialized_WithDefaultMember { @@ -424,8 +424,8 @@ pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { pub untouched: i32, } impl DefaultConstructible for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { - fn default_constructor(this: &Ptr) { - field!((*this), untouched).write(0_i32); + fn default_constructor(this: Ptr) { + field!(this, untouched).write(0_i32); } } impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { @@ -436,7 +436,7 @@ impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { Rc::new(RefCell::new( ::zero_init(), )); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -454,9 +454,9 @@ pub struct p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { pub member: p9_1_2_zero_then_default_initialized_LeavesMemberAlone, } impl DefaultConstructible for p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { - fn default_constructor(this: &Ptr) { - field!((*this), number).write(0_i32); - DefaultConstructible::default_constructor(&field_ptr!(this, member)); + fn default_constructor(this: Ptr) { + field!(this, number).write(0_i32); + DefaultConstructible::default_constructor(field_ptr!(this, member)); } } pub fn test_22() { @@ -468,7 +468,7 @@ pub fn test_22() { assert!(({ (*value.borrow()).five } == 5)); let mut heap: Ptr = { let __p = Ptr::alloc(::zero_init()); - DefaultConstructible::default_constructor(&__p); + DefaultConstructible::default_constructor(__p.clone()); __p }; assert!((heap.with(|__s| __s.zeroed) == 0)); @@ -483,7 +483,7 @@ pub fn test_22() { let mut heap_holder: Ptr = { let __p = Ptr::alloc(::zero_init()); - DefaultConstructible::default_constructor(&__p); + DefaultConstructible::default_constructor(__p.clone()); __p }; assert!((heap_holder.with(|__s| __s.number) == 0)); diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs index 16cf0ed793..16a6d8f105 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.fct.default.rs @@ -60,9 +60,17 @@ pub struct p9_static_member_hides_namespace_variable_HasStaticStep { #[offset(0)] pub total: i32, } +impl p9_static_member_hides_namespace_variable_HasStaticStep { + pub fn advance(this: Ptr, mut amount: i32) -> i32 { + { + field!(this, total).with_mut(|__v| *__v = *__v + amount) + }; + return this.with(|__s| __s.total); + } +} impl DefaultConstructible for p9_static_member_hides_namespace_variable_HasStaticStep { - fn default_constructor(this: &Ptr) { - field!((*this), total).write(1); + fn default_constructor(this: Ptr) { + field!(this, total).write(1); } } impl Default for p9_static_member_hides_namespace_variable_HasStaticStep { @@ -77,8 +85,8 @@ pub fn test_11() { ); assert!( (({ - p9_static_member_hides_namespace_variable_HasStaticStepImpl::advance( - &object.as_pointer(), + p9_static_member_hides_namespace_variable_HasStaticStep::advance( + object.as_pointer(), step_10.with(|rc| *rc.borrow()), ) }) == 5) @@ -86,18 +94,15 @@ pub fn test_11() { step_10.with(|rc| *rc.borrow_mut() = 6); assert!( (({ - p9_static_member_hides_namespace_variable_HasStaticStepImpl::advance( - &object.as_pointer(), + p9_static_member_hides_namespace_variable_HasStaticStep::advance( + object.as_pointer(), step_10.with(|rc| *rc.borrow()), ) }) == 11) ); assert!( (({ - p9_static_member_hides_namespace_variable_HasStaticStepImpl::advance( - &object.as_pointer(), - 2, - ) + p9_static_member_hides_namespace_variable_HasStaticStep::advance(object.as_pointer(), 2) }) == 13) ); assert!((step_9.with(|rc| *rc.borrow()) == 100)); @@ -120,10 +125,15 @@ pub struct p9_evaluated_each_time_called_Widget { #[offset(0)] pub id: i32, } +impl p9_evaluated_each_time_called_Widget { + pub fn construct(this: Ptr, mut id: i32) { + field!(this, id).write(id); + } +} impl DefaultConstructible for p9_evaluated_each_time_called_Widget { - fn default_constructor(this: &Ptr) { + fn default_constructor(this: Ptr) { { - p9_evaluated_each_time_called_WidgetImpl::construct(this, ({ count_default_13() })); + p9_evaluated_each_time_called_Widget::construct(this.clone(), ({ count_default_13() })); } } } @@ -134,8 +144,8 @@ impl Default for p9_evaluated_each_time_called_Widget { let __v: Value = Rc::new(RefCell::new( ::zero_init(), )); - p9_evaluated_each_time_called_WidgetImpl::construct( - &__v.as_pointer(), + p9_evaluated_each_time_called_Widget::construct( + __v.as_pointer(), ({ count_default_13() }), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -158,13 +168,19 @@ impl p9_evaluated_each_time_called_Account { fn twice(mut value: i32) -> i32 { return (2 * value); } + pub fn deposit(this: Ptr, mut amount: i32) -> i32 { + { + field!(this, balance).with_mut(|__v| *__v = *__v + amount) + }; + return this.with(|__s| __s.balance); + } pub fn set_base(mut value: i32) { base_15.with(|rc| *rc.borrow_mut() = value); } } impl DefaultConstructible for p9_evaluated_each_time_called_Account { - fn default_constructor(this: &Ptr) { - field!((*this), balance).write(0); + fn default_constructor(this: Ptr) { + field!(this, balance).write(0); } } impl Default for p9_evaluated_each_time_called_Account { @@ -198,8 +214,8 @@ pub fn test_17() { object!(account, p9_evaluated_each_time_called_Account); assert!( (({ - p9_evaluated_each_time_called_AccountImpl::deposit( - &account.as_pointer(), + p9_evaluated_each_time_called_Account::deposit( + account.as_pointer(), (({ p9_evaluated_each_time_called_Account::twice(base_15.with(|rc| *rc.borrow())) }) + (anon_16_kBonus as i32)), @@ -209,17 +225,15 @@ pub fn test_17() { ({ p9_evaluated_each_time_called_Account::set_base(1) }); assert!( (({ - p9_evaluated_each_time_called_AccountImpl::deposit( - &account.as_pointer(), + p9_evaluated_each_time_called_Account::deposit( + account.as_pointer(), (({ p9_evaluated_each_time_called_Account::twice(base_15.with(|rc| *rc.borrow())) }) + (anon_16_kBonus as i32)), ) }) == 32) ); - assert!( - (({ p9_evaluated_each_time_called_AccountImpl::deposit(&account.as_pointer(), 3,) }) == 35) - ); + assert!((({ p9_evaluated_each_time_called_Account::deposit(account.as_pointer(), 3,) }) == 35)); } pub fn add_18(mut a: i32, mut b: i32) -> i32 { return (a + b); @@ -307,38 +321,6 @@ fn main_0() -> i32 { ({ test_20() }); return 0; } -pub trait p9_evaluated_each_time_called_AccountImpl { - fn deposit(&self, amount: i32) -> i32; -} -impl p9_evaluated_each_time_called_AccountImpl for Ptr { - fn deposit(&self, mut amount: i32) -> i32 { - { - field!((*self), balance).with_mut(|__v| *__v = *__v + amount) - }; - return (*self).with(|__s| __s.balance); - } -} -pub trait p9_evaluated_each_time_called_WidgetImpl { - fn construct(&self, id: i32); -} -impl p9_evaluated_each_time_called_WidgetImpl for Ptr { - fn construct(&self, mut id: i32) { - field!((*self), id).write(id); - } -} -pub trait p9_static_member_hides_namespace_variable_HasStaticStepImpl { - fn advance(&self, amount: i32) -> i32; -} -impl p9_static_member_hides_namespace_variable_HasStaticStepImpl - for Ptr -{ - fn advance(&self, mut amount: i32) -> i32 { - { - field!((*self), total).with_mut(|__v| *__v = *__v + amount) - }; - return (*self).with(|__s| __s.total); - } -} pub fn __cpp2rust_init_globals() { let _ = scaled_calls_0.with(|_| ()); let _ = rate_1.with(|_| ()); diff --git a/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.unary.op.rs b/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.unary.op.rs index f47f6c147a..c02a9cd9a1 100644 --- a/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.unary.op.rs +++ b/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.unary.op.rs @@ -58,8 +58,26 @@ pub struct p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMemb #[offset(0)] pub base: i32, } +impl p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMember { + pub fn add( + self_: Ptr, + mut amount: i32, + ) -> i32 { + return ({ self_.with(|__s| __s.base) } + { amount }); + } +} pub fn test_3() { - let mut function_pointer : FnPtr ,i32 ,) -> i32 > = ( FnPtr:: ,i32 ,) -> i32 >::new( as p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMemberImpl>::add) ) ; + let mut function_pointer: FnPtr< + fn( + Ptr, + i32, + ) -> i32, + > = (FnPtr::< + fn( + Ptr, + i32, + ) -> i32, + >::new(p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMember::add)); let object: Value = Rc::new(RefCell::new( p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMember { base: 3 }, @@ -85,6 +103,14 @@ pub struct p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMemb #[offset(0)] pub value: i32, } +impl p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMember { + pub fn parenthesized(this: Ptr) -> Ptr { + return (field_ptr!(this, value)); + } + pub fn unqualified(this: Ptr) -> Ptr { + return (field_ptr!(this, value)); + } +} pub fn test_4() { let first: Value = Rc::new(RefCell::new( @@ -95,8 +121,8 @@ pub fn test_4() { p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMember { value: 4 }, )); let mut p: Ptr = ({ - p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMemberImpl::parenthesized( - &first.as_pointer(), + p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMember::parenthesized( + first.as_pointer(), ) }); assert!(({ (p).clone() } == { (field_ptr!(first.as_pointer(), value)) })); @@ -104,8 +130,8 @@ pub fn test_4() { assert!(({ (*first.borrow()).value } == 5)); assert!(({ (*second.borrow()).value } == 4)); let mut q: Ptr = ({ - p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMemberImpl::unqualified( - &second.as_pointer(), + p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMember::unqualified( + second.as_pointer(), ) }); assert!(({ (q).clone() } == { (field_ptr!(second.as_pointer(), value)) })); @@ -123,36 +149,6 @@ fn main_0() -> i32 { ({ test_4() }); return 0; } -pub trait p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMemberImpl { - fn add( - self_: Ptr, - amount: i32, - ) -> i32; -} -impl p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMemberImpl - for Ptr -{ - fn add( - self_: Ptr, - mut amount: i32, - ) -> i32 { - return ({ self_.with(|__s| __s.base) } + { amount }); - } -} -pub trait p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMemberImpl { - fn parenthesized(&self) -> Ptr; - fn unqualified(&self) -> Ptr; -} -impl p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMemberImpl - for Ptr -{ - fn parenthesized(&self) -> Ptr { - return (field_ptr!((*self), value)); - } - fn unqualified(&self) -> Ptr { - return (field_ptr!((*self), value)); - } -} pub fn __cpp2rust_init_globals() { let _ = shared_0.with(|_| ()); let _ = calls_1.with(|_| ()); diff --git a/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs b/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs index b79799d018..623ff80f49 100644 --- a/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs +++ b/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs @@ -144,7 +144,7 @@ thread_local!( pub struct p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} impl CopyConstructible for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { fn copy_constructor( - this: &Ptr, + this: Ptr, _a0: Ptr, ) { (*copyCount_9.with(Value::clone).borrow_mut()).prefix_inc(); @@ -152,7 +152,7 @@ impl CopyConstructible for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMov } impl MoveConstructible for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { fn move_constructor( - this: &Ptr, + this: Ptr, _a0: Ptr, ) { (*moveCount_10.with(Value::clone).borrow_mut()).prefix_inc(); diff --git a/tests/std/expr/expr.prim/expr.prim.this.cpp b/tests/std/expr/expr.prim/expr.prim.this.cpp index 566c58b062..38db1a88b0 100644 --- a/tests/std/expr/expr.prim/expr.prim.this.cpp +++ b/tests/std/expr/expr.prim/expr.prim.this.cpp @@ -38,8 +38,31 @@ void test() { } } // namespace p1_mem_initializer_names_object +// N4950 [expr.prim.this]/1: this is a prvalue. Its value is the pointer the +// function was called with, also after the function changes the pointer +// object that the call was made through. +namespace p1_this_is_a_copy_of_the_pointer { +struct Node { + int value; + Node *next; + int advance(Node *&cursor) { + cursor = next; + return value; + } +}; + +void test() { + Node second{2, nullptr}; + Node first{1, &second}; + Node *cursor = &first; + assert(cursor->advance(cursor) == 1); + assert(cursor == &second); +} +} // namespace p1_this_is_a_copy_of_the_pointer + int main() { p1_default_member_initializer_names_object::test(); p1_mem_initializer_names_object::test(); + p1_this_is_a_copy_of_the_pointer::test(); return 0; } diff --git a/tests/std/expr/expr.prim/out/refcount/expr.prim.this.rs b/tests/std/expr/expr.prim/out/refcount/expr.prim.this.rs index 8e44300e24..5b0d9df9f2 100644 --- a/tests/std/expr/expr.prim/out/refcount/expr.prim.this.rs +++ b/tests/std/expr/expr.prim/out/refcount/expr.prim.this.rs @@ -26,6 +26,14 @@ pub struct p1_default_member_initializer_names_object_Holder { #[offset(8)] pub value: i32, } +impl p1_default_member_initializer_names_object_Holder { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, self_).write((this).clone()); + field!(this, value).write(value); + assert!((this.with(|__s| __s.self_.clone()) == this)); + assert!(({ this.with(|__s| __s.self_.clone()).with(|__s| __s.value) } == { value })); + } +} impl Default for p1_default_member_initializer_names_object_Holder { fn default() -> Self { { ::zero_init() } @@ -56,10 +64,72 @@ pub struct p1_mem_initializer_names_object_Holder { #[offset(8)] pub value: i32, } +impl p1_mem_initializer_names_object_Holder { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, self_).write((this).clone()); + field!(this, value).write(value); + assert!((this.with(|__s| __s.self_.clone()) == this)); + { + field!(this.with(|__s| __s.self_.clone()), value).with_mut(|__v| *__v = *__v + 1) + }; + assert!((this.with(|__s| __s.value) == (value + 1))); + } +} pub fn test_1() { object!(holder, p1_mem_initializer_names_object_Holder(4)); assert!(({ (*holder.borrow()).value } == 5)); } +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, +)] +#[byte_size(16)] +pub struct p1_this_is_a_copy_of_the_pointer_Node { + #[offset(0)] + pub value: i32, + #[offset(8)] + #[byte_size(8)] + pub next: Ptr, +} +impl p1_this_is_a_copy_of_the_pointer_Node { + pub fn advance( + this: Ptr, + cursor: Ptr>, + ) -> i32 { + cursor.write(this.with(|__s| __s.next.clone())); + return this.with(|__s| __s.value); + } +} +pub fn test_2() { + let second: Value = + Rc::new(RefCell::new(p1_this_is_a_copy_of_the_pointer_Node { + value: 2, + next: Ptr::::null(), + })); + let first: Value = + Rc::new(RefCell::new(p1_this_is_a_copy_of_the_pointer_Node { + value: 1, + next: (second.as_pointer()), + })); + let cursor: Value> = + Rc::new(RefCell::new((first.as_pointer()))); + assert!( + (({ + p1_this_is_a_copy_of_the_pointer_Node::advance( + { (*cursor.borrow()).clone() }, + cursor.as_pointer(), + ) + }) == 1) + ); + assert!(({ ({ (*cursor.borrow()).clone() } == { (second.as_pointer()) }) })); +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -67,33 +137,7 @@ pub fn main() { fn main_0() -> i32 { ({ test_0() }); ({ test_1() }); + ({ test_2() }); return 0; } -pub trait p1_default_member_initializer_names_object_HolderImpl { - fn construct(&self, value: i32); -} -impl p1_default_member_initializer_names_object_HolderImpl - for Ptr -{ - fn construct(&self, mut value: i32) { - field!((*self), self_).write((*self).clone()); - field!((*self), value).write(value); - assert!(((*self).with(|__s| __s.self_.clone()) == (*self))); - assert!(({ (*self).with(|__s| __s.self_.clone()).with(|__s| __s.value) } == { value })); - } -} -pub trait p1_mem_initializer_names_object_HolderImpl { - fn construct(&self, value: i32); -} -impl p1_mem_initializer_names_object_HolderImpl for Ptr { - fn construct(&self, mut value: i32) { - field!((*self), self_).write((*self).clone()); - field!((*self), value).write(value); - assert!(((*self).with(|__s| __s.self_.clone()) == (*self))); - { - field!((*self).with(|__s| __s.self_.clone()), value).with_mut(|__v| *__v = *__v + 1) - }; - assert!(((*self).with(|__s| __s.value) == (value + 1))); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/expr/expr.prim/out/unsafe/expr.prim.this.rs b/tests/std/expr/expr.prim/out/unsafe/expr.prim.this.rs index 6e57a8515a..b58309a70c 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 @@ -70,6 +70,49 @@ pub unsafe fn test_1() { object_unsafe!(holder, p1_mem_initializer_names_object_Holder(4)); assert!(((holder.value) == (5))); } +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, +)] +pub struct p1_this_is_a_copy_of_the_pointer_Node { + pub value: i32, + pub next: *mut p1_this_is_a_copy_of_the_pointer_Node, +} +impl p1_this_is_a_copy_of_the_pointer_Node { + pub unsafe fn advance( + &mut self, + cursor: *mut *mut p1_this_is_a_copy_of_the_pointer_Node, + ) -> i32 { + (*cursor) = self.next; + return self.value; + } +} +pub unsafe fn test_2() { + let mut second: p1_this_is_a_copy_of_the_pointer_Node = p1_this_is_a_copy_of_the_pointer_Node { + value: 2, + next: std::ptr::null_mut(), + }; + let mut first: p1_this_is_a_copy_of_the_pointer_Node = p1_this_is_a_copy_of_the_pointer_Node { + value: 1, + next: (&mut second as *mut p1_this_is_a_copy_of_the_pointer_Node), + }; + let mut cursor: *mut p1_this_is_a_copy_of_the_pointer_Node = + (&mut first as *mut p1_this_is_a_copy_of_the_pointer_Node); + assert!( + ((unsafe { + let _cursor: *mut *mut p1_this_is_a_copy_of_the_pointer_Node = &mut cursor; + p1_this_is_a_copy_of_the_pointer_Node::advance(&mut (*cursor), _cursor) + }) == (1)) + ); + assert!(((cursor) == (&mut second as *mut p1_this_is_a_copy_of_the_pointer_Node))); +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -79,6 +122,7 @@ pub fn main() { unsafe fn main_0() -> i32 { (unsafe { test_0() }); (unsafe { test_1() }); + (unsafe { test_2() }); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs index 31cf739d9f..57f81a7b45 100644 --- a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs +++ b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/refcount/allocator.requirements.general.rs @@ -27,8 +27,8 @@ pub struct p16_rebind_member_Alloc_std_pair_const_int__int__ { pub id: i32, } impl DefaultConstructible for p16_rebind_member_Alloc_std_pair_const_int__int__ { - fn default_constructor(this: &Ptr) { - field!((*this), id).write(0); + fn default_constructor(this: Ptr) { + field!(this, id).write(0); } } impl Default for p16_rebind_member_Alloc_std_pair_const_int__int__ { @@ -101,28 +101,4 @@ fn main_0() -> i32 { ({ test_1() }); return 0; } -pub trait p16_rebind_member_Alloc_std_pair_const_int__int__Impl { - fn allocate(&self, mut n: usize) -> Ptr<(Value, Value)> { - unimplemented!() - } - fn deallocate(&self, mut p: Ptr<(Value, Value)>, mut n: usize) { - unimplemented!() - } -} -impl p16_rebind_member_Alloc_std_pair_const_int__int__Impl - for Ptr -{ -} -pub trait p18_rebind_to_container_node_Alloc_std_pair_const_int__int__Impl { - fn allocate(&self, mut n: usize) -> Ptr<(Value, Value)> { - unimplemented!() - } - fn deallocate(&self, mut p: Ptr<(Value, Value)>, mut n: usize) { - unimplemented!() - } -} -impl p18_rebind_to_container_node_Alloc_std_pair_const_int__int__Impl - for Ptr -{ -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs b/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs index 08befc644a..5a09259fc5 100644 --- a/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs +++ b/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs @@ -32,8 +32,17 @@ pub struct p2_condition_variable_created_each_iteration_ConvertsToBool { #[offset(0)] pub value: i32, } +impl p2_condition_variable_created_each_iteration_ConvertsToBool { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); + } + pub fn to_bool(this: Ptr) -> bool { + return (this.with(|__s| __s.value) != 0); + } +} impl Destructible for p2_condition_variable_created_each_iteration_ConvertsToBool { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -46,8 +55,8 @@ pub fn test_2() { p2_condition_variable_created_each_iteration_ConvertsToBool(remaining) ); if !({ - p2_condition_variable_created_each_iteration_ConvertsToBoolImpl::to_bool( - &condition.as_pointer(), + p2_condition_variable_created_each_iteration_ConvertsToBool::to_bool( + condition.as_pointer(), ) }) { break; @@ -88,8 +97,17 @@ pub struct p2_continue_destroys_condition_variable_ConvertsToBool { #[offset(0)] pub value: i32, } +impl p2_continue_destroys_condition_variable_ConvertsToBool { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + (*ctorCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } + pub fn to_bool(this: Ptr) -> bool { + return (this.with(|__s| __s.value) != 0); + } +} impl Destructible for p2_continue_destroys_condition_variable_ConvertsToBool { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_4.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -103,9 +121,7 @@ pub fn test_5() { p2_continue_destroys_condition_variable_ConvertsToBool(remaining) ); if !({ - p2_continue_destroys_condition_variable_ConvertsToBoolImpl::to_bool( - &condition.as_pointer(), - ) + p2_continue_destroys_condition_variable_ConvertsToBool::to_bool(condition.as_pointer()) }) { break; } @@ -134,36 +150,6 @@ fn main_0() -> i32 { ({ test_5() }); return 0; } -pub trait p2_condition_variable_created_each_iteration_ConvertsToBoolImpl { - fn construct(&self, value: i32); - fn to_bool(&self) -> bool; -} -impl p2_condition_variable_created_each_iteration_ConvertsToBoolImpl - for Ptr -{ - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn to_bool(&self) -> bool { - return ((*self).with(|__s| __s.value) != 0); - } -} -pub trait p2_continue_destroys_condition_variable_ConvertsToBoolImpl { - fn construct(&self, value: i32); - fn to_bool(&self) -> bool; -} -impl p2_continue_destroys_condition_variable_ConvertsToBoolImpl - for Ptr -{ - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - (*ctorCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } - fn to_bool(&self) -> bool { - return ((*self).with(|__s| __s.value) != 0); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = dtorCount_1.with(|_| ()); diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs index 1bd4dc7a47..c9707c9790 100644 --- a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs +++ b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs @@ -53,21 +53,27 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), uses).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -87,7 +93,7 @@ pub fn test_6() { (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); } else { (*else_runs_5.with(Value::clone).borrow_mut()).prefix_inc(); - ({ LifetimeTrackedImpl::use_(&guard.as_pointer()) }); + ({ LifetimeTracked::use_(guard.as_pointer()) }); assert!(({ (*guard.borrow()).uses } == 1)); assert!((choice == 0)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 0)); @@ -101,7 +107,7 @@ pub fn test_6() { let mut choice: i32 = 4; if (choice != 0) { (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); - ({ LifetimeTrackedImpl::use_(&guard.as_pointer()) }); + ({ LifetimeTracked::use_(guard.as_pointer()) }); assert!(({ (*guard.borrow()).uses } == 1)); assert!((choice == 4)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 1)); @@ -191,17 +197,6 @@ fn main_0() -> i32 { ({ test_12() }); return 0; } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs index 83a6535236..87f2db939c 100644 --- a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs +++ b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs @@ -53,21 +53,27 @@ impl LifetimeTracked { } }); } + pub fn use_(this: Ptr) { + field!(this, uses).with_mut(|__v| { + __v.prefix_inc(); + }); + (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); + } } impl DefaultConstructible for LifetimeTracked { - fn default_constructor(this: &Ptr) { - field!((*this), uses).write(0); + fn default_constructor(this: Ptr) { + field!(this, uses).write(0); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyConstructible for LifetimeTracked { - fn copy_constructor(this: &Ptr, _a0: Ptr) { - field!((*this), uses).write(0); + fn copy_constructor(this: Ptr, _a0: Ptr) { + field!(this, uses).write(0); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl Destructible for LifetimeTracked { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_2.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -100,8 +106,13 @@ pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { #[offset(0)] pub value: i32, } +impl p2_condition_variable_lives_for_whole_statement_ConvertsToInt { + pub fn to_i32(this: Ptr) -> i32 { + return this.with(|__s| __s.value); + } +} impl Destructible for p2_condition_variable_lives_for_whole_statement_ConvertsToInt { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*dtorCount_6.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -112,13 +123,13 @@ pub fn test_7() { p2_condition_variable_lives_for_whole_statement_ConvertsToInt { value: 2 }, )); let _dtor_selector = std::mem::DropGuard::new(selector.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); 'switch: { match { ({ - p2_condition_variable_lives_for_whole_statement_ConvertsToIntImpl::to_i32( - &selector.as_pointer(), + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + selector.as_pointer(), ) }) } { @@ -155,7 +166,7 @@ pub fn test_10() { match { selector } { __v if __v == 2 => { (*matching_case_runs_8.with(Value::clone).borrow_mut()).prefix_inc(); - ({ LifetimeTrackedImpl::use_(&guard.as_pointer()) }); + ({ LifetimeTracked::use_(guard.as_pointer()) }); assert!(({ (*guard.borrow()).uses } == 1)); assert!((selector == 2)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 0)); @@ -220,27 +231,6 @@ fn main_0() -> i32 { ({ test_10() }); return 0; } -pub trait LifetimeTrackedImpl { - fn use_(&self); -} -impl LifetimeTrackedImpl for Ptr { - fn use_(&self) { - field!((*self), uses).with_mut(|__v| { - __v.prefix_inc(); - }); - (*useCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub trait p2_condition_variable_lives_for_whole_statement_ConvertsToIntImpl { - fn to_i32(&self) -> i32; -} -impl p2_condition_variable_lives_for_whole_statement_ConvertsToIntImpl - for Ptr -{ - fn to_i32(&self) -> i32 { - return (*self).with(|__s| __s.value); - } -} pub fn __cpp2rust_init_globals() { let _ = ctorCount_0.with(|_| ()); let _ = copyCount_1.with(|_| ()); diff --git a/tests/std/temp/temp.spec/out/refcount/temp.inst.rs b/tests/std/temp/temp.spec/out/refcount/temp.inst.rs index 2e58366380..010980f4d9 100644 --- a/tests/std/temp/temp.spec/out/refcount/temp.inst.rs +++ b/tests/std/temp/temp.spec/out/refcount/temp.inst.rs @@ -12,9 +12,14 @@ pub struct p2_reference_does_not_instantiate_Member { #[offset(0)] pub value: i32, } +impl p2_reference_does_not_instantiate_Member { + pub fn construct_1(this: Ptr, _a0: Ptr) { + field!(this, value).write(2); + } +} impl DefaultConstructible for p2_reference_does_not_instantiate_Member { - fn default_constructor(this: &Ptr) { - field!((*this), value).write(1); + fn default_constructor(this: Ptr) { + field!(this, value).write(1); } } impl Default for p2_reference_does_not_instantiate_Member { @@ -31,8 +36,8 @@ pub struct p2_reference_does_not_instantiate_Holder { pub member: p2_reference_does_not_instantiate_Member, } impl DefaultConstructible for p2_reference_does_not_instantiate_Holder { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, member)); + fn default_constructor(this: Ptr) { + DefaultConstructible::default_constructor(field_ptr!(this, member)); } } pub fn test_0() { @@ -52,14 +57,4 @@ fn main_0() -> i32 { #[derive(Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg)] #[byte_size(1)] pub struct p2_reference_does_not_instantiate_Wrapper_int_; -pub trait p2_reference_does_not_instantiate_MemberImpl { - fn construct_1(&self, _a0: Ptr); -} -impl p2_reference_does_not_instantiate_MemberImpl - for Ptr -{ - fn construct_1(&self, _a0: Ptr) { - field!((*self), value).write(2); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/utilities/utility/out/refcount/forward-helpers.rs b/tests/std/utilities/utility/out/refcount/forward-helpers.rs index 725b0a0dd3..1274841391 100644 --- a/tests/std/utilities/utility/out/refcount/forward-helpers.rs +++ b/tests/std/utilities/utility/out/refcount/forward-helpers.rs @@ -23,14 +23,19 @@ pub struct p6_forward_like_Movable { #[offset(0)] pub value: i32, } +impl p6_forward_like_Movable { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + } +} impl CopyConstructible for p6_forward_like_Movable { - fn copy_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); + fn copy_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); } } impl MoveConstructible for p6_forward_like_Movable { - fn move_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); + fn move_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } @@ -43,8 +48,8 @@ pub struct p6_forward_like_Holder { pub member: p6_forward_like_Movable, } impl DefaultConstructible for p6_forward_like_Holder { - fn default_constructor(this: &Ptr) { - p6_forward_like_MovableImpl::construct(&field_ptr!(this, member), 1); + fn default_constructor(this: Ptr) { + p6_forward_like_Movable::construct(field_ptr!(this, member), 1); } } impl Default for p6_forward_like_Holder { @@ -54,7 +59,7 @@ impl Default for p6_forward_like_Holder { member: { let __v: Value = Rc::new(RefCell::new(::zero_init())); - p6_forward_like_MovableImpl::construct(&__v.as_pointer(), 1); + p6_forward_like_Movable::construct(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, } @@ -62,21 +67,21 @@ impl Default for p6_forward_like_Holder { } } pub fn take_1(this: Ptr, self_: Ptr) { - ConstructFrom::construct_from(&this, field_ptr!(self_, member)); + ConstructFrom::construct_from(this.clone(), field_ptr!(self_, member)); return; } pub fn take_2(this: Ptr, self_: Ptr) { - ConstructFrom::construct_from(&this, Moved(field_ptr!(self_, member))); + ConstructFrom::construct_from(this.clone(), Moved(field_ptr!(self_, member))); return; } pub fn test_3() { object!(holder, p6_forward_like_Holder); object!(copied, p6_forward_like_Movable, |copied| ({ - take_1(Ptr::clone(copied), holder.as_pointer()) + take_1(Ptr::clone(&copied.clone()), holder.as_pointer()) })); assert!(({ (*copied.borrow()).value } == 1) && ({ (*holder.borrow()).member.value } == 1)); object!(moved, p6_forward_like_Movable, |moved| ({ - take_2(Ptr::clone(moved), holder.as_pointer()) + take_2(Ptr::clone(&moved.clone()), holder.as_pointer()) })); assert!(({ (*moved.borrow()).value } == 1) && ({ (*holder.borrow()).member.value } == 0)); } @@ -89,9 +94,14 @@ pub struct p9_move_Movable { #[offset(0)] pub value: i32, } +impl p9_move_Movable { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + } +} impl MoveConstructible for p9_move_Movable { - fn move_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); + fn move_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } @@ -139,18 +149,25 @@ pub struct p10_forward_in_template_A { #[offset(8)] pub moves: i32, } +impl p10_forward_in_template_A { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + field!(this, copies).write(0); + field!(this, moves).write(0); + } +} impl CopyConstructible for p10_forward_in_template_A { - fn copy_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); - field!((*this), copies).write((other.with(|__s| __s.copies) + 1)); - field!((*this), moves).write(0); + fn copy_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); + field!(this, copies).write((other.with(|__s| __s.copies) + 1)); + field!(this, moves).write(0); } } impl MoveConstructible for p10_forward_in_template_A { - fn move_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); - field!((*this), copies).write(0); - field!((*this), moves).write((other.with(|__s| __s.moves) + 1)); + fn move_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); + field!(this, copies).write(0); + field!(this, moves).write((other.with(|__s| __s.moves) + 1)); field!(other, value).write(0); } } @@ -160,17 +177,17 @@ impl Default for p10_forward_in_template_A { } } pub fn make_5(this: Ptr, source: Ptr) { - ConstructFrom::construct_from(&this, (source).clone()); + ConstructFrom::construct_from(this.clone(), (source).clone()); return; } pub fn make_6(this: Ptr, source: Ptr) { - ConstructFrom::construct_from(&this, Moved((source).clone())); + ConstructFrom::construct_from(this.clone(), Moved((source).clone())); return; } pub fn test_7() { object!(a, p10_forward_in_template_A(1)); object!(copied, p10_forward_in_template_A, |copied| ({ - make_5(Ptr::clone(copied), a.as_pointer()) + make_5(Ptr::clone(&copied.clone()), a.as_pointer()) })); assert!( (({ (*copied.borrow()).value } == 1) && ({ (*copied.borrow()).copies } == 1)) @@ -178,7 +195,7 @@ pub fn test_7() { ); assert!(({ (*a.borrow()).value } == 1)); object!(moved, p10_forward_in_template_A, |moved| ({ - make_6(Ptr::clone(moved), a.as_pointer()) + make_6(Ptr::clone(&moved.clone()), a.as_pointer()) })); assert!( (({ (*moved.borrow()).value } == 1) && ({ (*moved.borrow()).copies } == 0)) @@ -195,14 +212,19 @@ pub struct p11_move_if_noexcept_NoexceptMove { #[offset(0)] pub value: i32, } +impl p11_move_if_noexcept_NoexceptMove { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + } +} impl CopyConstructible for p11_move_if_noexcept_NoexceptMove { - fn copy_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); + fn copy_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); } } impl MoveConstructible for p11_move_if_noexcept_NoexceptMove { - fn move_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); + fn move_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } @@ -215,14 +237,19 @@ pub struct p11_move_if_noexcept_ThrowingMove { #[offset(0)] pub value: i32, } +impl p11_move_if_noexcept_ThrowingMove { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + } +} impl CopyConstructible for p11_move_if_noexcept_ThrowingMove { - fn copy_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); + fn copy_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); } } impl MoveConstructible for p11_move_if_noexcept_ThrowingMove { - fn move_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); + fn move_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } @@ -254,46 +281,4 @@ fn main_0() -> i32 { ({ test_8() }); return 0; } -pub trait p10_forward_in_template_AImpl { - fn construct(&self, value: i32); -} -impl p10_forward_in_template_AImpl for Ptr { - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - field!((*self), copies).write(0); - field!((*self), moves).write(0); - } -} -pub trait p11_move_if_noexcept_NoexceptMoveImpl { - fn construct(&self, value: i32); -} -impl p11_move_if_noexcept_NoexceptMoveImpl for Ptr { - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - } -} -pub trait p11_move_if_noexcept_ThrowingMoveImpl { - fn construct(&self, value: i32); -} -impl p11_move_if_noexcept_ThrowingMoveImpl for Ptr { - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - } -} -pub trait p6_forward_like_MovableImpl { - fn construct(&self, value: i32); -} -impl p6_forward_like_MovableImpl for Ptr { - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - } -} -pub trait p9_move_MovableImpl { - fn construct(&self, value: i32); -} -impl p9_move_MovableImpl for Ptr { - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/utilities/utility/out/refcount/forward.rs b/tests/std/utilities/utility/out/refcount/forward.rs index 9c74c2ab38..e38d344304 100644 --- a/tests/std/utilities/utility/out/refcount/forward.rs +++ b/tests/std/utilities/utility/out/refcount/forward.rs @@ -66,9 +66,14 @@ pub struct p10_move_constructor_A { #[offset(0)] pub value: i32, } +impl p10_move_constructor_A { + pub fn construct(this: Ptr, mut value: i32) { + field!(this, value).write(value); + } +} impl MoveConstructible for p10_move_constructor_A { - fn move_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); + fn move_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); field!(other, value).write(0); } } @@ -93,12 +98,4 @@ fn main_0() -> i32 { ({ test_2() }); return 0; } -pub trait p10_move_constructor_AImpl { - fn construct(&self, value: i32); -} -impl p10_move_constructor_AImpl for Ptr { - fn construct(&self, mut value: i32) { - field!((*self), value).write(value); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/std/utilities/utility/out/refcount/utility.as.const.rs b/tests/std/utilities/utility/out/refcount/utility.as.const.rs index a5a0bb1817..d2081106fc 100644 --- a/tests/std/utilities/utility/out/refcount/utility.as.const.rs +++ b/tests/std/utilities/utility/out/refcount/utility.as.const.rs @@ -23,6 +23,14 @@ pub struct p1_as_const_Counter { #[offset(0)] pub value: i32, } +impl p1_as_const_Counter { + pub fn get_1(this: Ptr) -> i32 { + return (this.with(|__s| __s.value) + 1); + } + pub fn get_2(this: Ptr) -> i32 { + return this.with(|__s| __s.value); + } +} pub fn test_0() { let number: Value = Rc::new(RefCell::new(3)); let ref_: Ptr = number.as_pointer(); @@ -34,8 +42,8 @@ pub fn test_0() { assert!(({ (pointer).clone() } == { (number.as_pointer()) })); let counter: Value = Rc::new(RefCell::new(p1_as_const_Counter { value: 5 })); - assert!((({ p1_as_const_CounterImpl::get_2(&counter.as_pointer(),) }) == 5)); - assert!((({ p1_as_const_CounterImpl::get_1(&counter.as_pointer(),) }) == 6)); + assert!((({ p1_as_const_Counter::get_2(counter.as_pointer(),) }) == 5)); + assert!((({ p1_as_const_Counter::get_1(counter.as_pointer(),) }) == 6)); } pub fn main() { __cpp2rust_init_globals(); @@ -45,16 +53,4 @@ fn main_0() -> i32 { ({ test_0() }); return 0; } -pub trait p1_as_const_CounterImpl { - fn get_1(&self) -> i32; - fn get_2(&self) -> i32; -} -impl p1_as_const_CounterImpl for Ptr { - fn get_1(&self) -> i32 { - return ((*self).with(|__s| __s.value) + 1); - } - fn get_2(&self) -> i32 { - return (*self).with(|__s| __s.value); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/ub/out/refcount/ctor_ref_member.rs b/tests/ub/out/refcount/ctor_ref_member.rs index 2e50bec5e7..bdf13b0f8f 100644 --- a/tests/ub/out/refcount/ctor_ref_member.rs +++ b/tests/ub/out/refcount/ctor_ref_member.rs @@ -25,6 +25,11 @@ pub struct S { #[byte_size(8)] pub r: Ptr, } +impl S { + pub fn construct(this: Ptr, x: Ptr) { + field!(this, r).write((x).clone()); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -32,17 +37,9 @@ pub fn main() { fn main_0() -> i32 { object!(s, S, |s| { let __tmp_0: Value = Rc::new(RefCell::new(5)); - SImpl::construct(s, __tmp_0.as_pointer()) + S::construct(s.clone(), __tmp_0.as_pointer()) }); assert!((({ (*s.borrow()).r.clone() }.read()) == 5)); return 0; } -pub trait SImpl { - fn construct(&self, x: Ptr); -} -impl SImpl for Ptr { - fn construct(&self, x: Ptr) { - field!((*self), r).write((x).clone()); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/ub/out/refcount/max.rs b/tests/ub/out/refcount/max.rs index eca57caaf2..3cc11db765 100644 --- a/tests/ub/out/refcount/max.rs +++ b/tests/ub/out/refcount/max.rs @@ -14,7 +14,7 @@ fn main_0() -> i32 { let a: Ptr = ({ let __tmp_0: Value = Rc::new(RefCell::new(2)); let __tmp_1: Value = Rc::new(RefCell::new(1)); - if CppLess::less(&__tmp_0.as_pointer(), &__tmp_1.as_pointer()) { + if CppLess::less(__tmp_0.as_pointer().clone(), __tmp_1.as_pointer().clone()) { __tmp_0.as_pointer() } else { __tmp_1.as_pointer() @@ -23,7 +23,7 @@ fn main_0() -> i32 { let b: Ptr = ({ let __tmp_2: Value = Rc::new(RefCell::new(1)); let __tmp_3: Value = Rc::new(RefCell::new(2)); - if CppLess::less(&__tmp_2.as_pointer(), &__tmp_3.as_pointer()) { + if CppLess::less(__tmp_2.as_pointer().clone(), __tmp_3.as_pointer().clone()) { __tmp_3.as_pointer() } else { __tmp_2.as_pointer() diff --git a/tests/unit/out/refcount/05_new.rs b/tests/unit/out/refcount/05_new.rs index e97d3bef1c..9f515fbe1b 100644 --- a/tests/unit/out/refcount/05_new.rs +++ b/tests/unit/out/refcount/05_new.rs @@ -34,6 +34,11 @@ pub struct A {} )] #[byte_size(1)] pub struct D {} +impl D { + pub fn operator_call(this: Ptr, mut ptr: Ptr) { + ptr.delete(); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -44,18 +49,10 @@ fn main_0() -> i32 { d.delete(); let mut c: Ptr = Ptr::alloc(3); c.delete(); - DImpl::operator_call( - &Rc::new(RefCell::new(::default())).as_pointer(), + D::operator_call( + Rc::new(RefCell::new(::default())).as_pointer(), Ptr::alloc(::default()), ); return 0; } -pub trait DImpl { - fn operator_call(&self, ptr: Ptr); -} -impl DImpl for Ptr { - fn operator_call(&self, mut ptr: Ptr) { - ptr.delete(); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/10_struct.rs b/tests/unit/out/refcount/10_struct.rs index d46dea05b5..4970fbf2f9 100644 --- a/tests/unit/out/refcount/10_struct.rs +++ b/tests/unit/out/refcount/10_struct.rs @@ -44,6 +44,18 @@ pub struct Graph { #[byte_size(8)] pub adj: Ptr>, } +impl Graph { + pub fn push(this: Ptr, mut src: u32, mut dst: u32) { + elem!(this.with(|__s| __s.adj.clone()), src).write(Ptr::alloc(GraphNode { + dst: dst, + next: (elem!(this.with(|__s| __s.adj.clone()), src).read()), + })); + elem!(this.with(|__s| __s.adj.clone()), dst).write(Ptr::alloc(GraphNode { + dst: src, + next: (elem!(this.with(|__s| __s.adj.clone()), dst).read()), + })); + } +} #[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] #[byte_size(8)] pub struct Partial { @@ -51,9 +63,14 @@ pub struct Partial { #[byte_size(8)] pub p: Ptr, } +impl Partial { + pub fn construct_1(this: Ptr, mut q: Ptr) { + field!(this, p).write((q).clone()); + } +} impl DefaultConstructible for Partial { - fn default_constructor(this: &Ptr) { - field!((*this), p).write(Ptr::::null()); + fn default_constructor(this: Ptr) { + field!(this, p).write(Ptr::::null()); } } impl Default for Partial { @@ -79,6 +96,7 @@ impl Default for Partial { )] #[byte_size(1)] pub struct Declared {} +impl Declared {} #[derive( Clone, Record, @@ -125,42 +143,4 @@ fn main_0() -> i32 { } return 0; } -pub trait DeclaredImpl { - fn construct(&self, mut _a0: i32) { - unimplemented!() - } -} -impl DeclaredImpl for Ptr {} -pub trait GraphImpl { - fn push(&self, src: u32, dst: u32); -} -impl GraphImpl for Ptr { - fn push(&self, mut src: u32, mut dst: u32) { - elem!((*self).with(|__s| __s.adj.clone()), src).write(Ptr::alloc(GraphNode { - dst: dst, - next: (elem!((*self).with(|__s| __s.adj.clone()), src).read()), - })); - elem!((*self).with(|__s| __s.adj.clone()), dst).write(Ptr::alloc(GraphNode { - dst: src, - next: (elem!((*self).with(|__s| __s.adj.clone()), dst).read()), - })); - } -} -pub trait PartialImpl { - fn construct_1(&self, q: Ptr); - fn get(&self) -> Ptr { - unimplemented!() - } - fn next_4(&self) -> Ptr { - unimplemented!() - } - fn next_5(&self, mut _a0: i32) -> Partial { - unimplemented!() - } -} -impl PartialImpl for Ptr { - fn construct_1(&self, mut q: Ptr) { - field!((*self), p).write((q).clone()); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/any.rs b/tests/unit/out/refcount/any.rs index 466060af08..a7d9a13ee8 100644 --- a/tests/unit/out/refcount/any.rs +++ b/tests/unit/out/refcount/any.rs @@ -25,6 +25,12 @@ pub struct Point { #[offset(4)] pub y: i32, } +impl Point { + pub fn construct(this: Ptr, mut x: i32, mut y: i32) { + field!(this, x).write(x); + field!(this, y).write(y); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -33,7 +39,7 @@ fn main_0() -> i32 { let a: Value>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - PointImpl::construct(&__v.as_pointer(), 3, 4); + Point::construct(__v.as_pointer(), 3, 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))))); assert!(({ (*a.borrow()).is_some() })); @@ -73,7 +79,7 @@ fn main_0() -> i32 { let mut __tmp_2 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - PointImpl::construct(&__v.as_pointer(), 5, 6); + Point::construct(__v.as_pointer(), 5, 6); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; @@ -153,13 +159,4 @@ fn main_0() -> i32 { ); return 0; } -pub trait PointImpl { - fn construct(&self, x: i32, y: i32); -} -impl PointImpl for Ptr { - fn construct(&self, mut x: i32, mut y: i32) { - field!((*self), x).write(x); - field!((*self), y).write(y); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/array_of_noncopy_struct.rs b/tests/unit/out/refcount/array_of_noncopy_struct.rs index 00a96f3d1d..a55ac2883a 100644 --- a/tests/unit/out/refcount/array_of_noncopy_struct.rs +++ b/tests/unit/out/refcount/array_of_noncopy_struct.rs @@ -28,9 +28,9 @@ pub struct NonCopy { pub tag: i32, } impl DefaultConstructible for NonCopy { - fn default_constructor(this: &Ptr) { - field!((*this), data).write(Vec::new()); - field!((*this), tag).write(0); + fn default_constructor(this: Ptr) { + field!(this, data).write(Vec::new()); + field!(this, tag).write(0); } } impl Default for NonCopy { @@ -51,7 +51,7 @@ fn main_0() -> i32 { let arr: Value> = Rc::new(RefCell::new(Box::new( std::array::from_fn::<_, 3, _>(|_| { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }), ))); diff --git a/tests/unit/out/refcount/as_const.rs b/tests/unit/out/refcount/as_const.rs index cdddf6c9c4..d5a2db82e3 100644 --- a/tests/unit/out/refcount/as_const.rs +++ b/tests/unit/out/refcount/as_const.rs @@ -26,6 +26,20 @@ pub struct S { #[offset(0)] pub v: i32, } +impl S { + pub fn f_1(this: Ptr) -> Overload { + return Overload_kMutableOverload; + } + pub fn f_2(this: Ptr) -> Overload { + return Overload_kConstOverload; + } + pub fn value_ref_3(this: Ptr) -> Ptr { + return field_ptr!(this, v); + } + pub fn value_ref_4(this: Ptr) -> Ptr { + return field_ptr!(this, v); + } +} pub fn g_0(_a0: Ptr) -> Overload { return Overload_kMutableOverload; } @@ -38,40 +52,20 @@ pub fn main() { } fn main_0() -> i32 { let s: Value = Rc::new(RefCell::new(S { v: 7 })); - assert!(((({ SImpl::f_1(&s.as_pointer(),) }) as i32) == (Overload_kMutableOverload as i32))); - assert!(((({ SImpl::f_2(&s.as_pointer(),) }) as i32) == (Overload_kConstOverload as i32))); + assert!(((({ S::f_1(s.as_pointer(),) }) as i32) == (Overload_kMutableOverload as i32))); + assert!(((({ S::f_2(s.as_pointer(),) }) as i32) == (Overload_kConstOverload as i32))); assert!(((({ g_0(s.as_pointer(),) }) as i32) == (Overload_kMutableOverload as i32))); assert!(((({ g_1(s.as_pointer(),) }) as i32) == (Overload_kConstOverload as i32))); - ({ SImpl::value_ref_3(&s.as_pointer()) }).write(9); + ({ S::value_ref_3(s.as_pointer()) }).write(9); assert!(({ (*s.borrow()).v } == 9)); - assert!(((({ SImpl::value_ref_4(&s.as_pointer(),) }).read()) == 9)); + assert!(((({ S::value_ref_4(s.as_pointer(),) }).read()) == 9)); let cs: Ptr = s.as_pointer(); - assert!(((({ SImpl::f_2(&cs,) }) as i32) == (Overload_kConstOverload as i32))); + assert!(((({ S::f_2((cs).clone(),) }) as i32) == (Overload_kConstOverload as i32))); assert!((cs.with(|__s| __s.v) == 9)); let mut p: Ptr = (s.as_pointer()); field!(p, v).write(11); assert!(({ (*s.borrow()).v } == 11)); - assert!(((({ SImpl::f_1(&p,) }) as i32) == (Overload_kMutableOverload as i32))); + assert!(((({ S::f_1((p).clone(),) }) as i32) == (Overload_kMutableOverload as i32))); return 0; } -pub trait SImpl { - fn f_1(&self) -> Overload; - fn f_2(&self) -> Overload; - fn value_ref_3(&self) -> Ptr; - fn value_ref_4(&self) -> Ptr; -} -impl SImpl for Ptr { - fn f_1(&self) -> Overload { - return Overload_kMutableOverload; - } - fn f_2(&self) -> Overload { - return Overload_kConstOverload; - } - fn value_ref_3(&self) -> Ptr { - return field_ptr!((*self), v); - } - fn value_ref_4(&self) -> Ptr { - return field_ptr!((*self), v); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/assignment_single_eval.rs b/tests/unit/out/refcount/assignment_single_eval.rs index e5b2bcdcc9..b70578b8ec 100644 --- a/tests/unit/out/refcount/assignment_single_eval.rs +++ b/tests/unit/out/refcount/assignment_single_eval.rs @@ -1498,13 +1498,23 @@ thread_local!( )] #[byte_size(1)] pub struct IndexedBinding {} +impl IndexedBinding { + pub fn get_1_0(this: Ptr) -> Ptr { + return selected_values_34.with(|v| v.decay()).offset( + ({ + let __idx0 = (0) as usize; + selected_values_34.with(|rc| rc.borrow()[__idx0]) + }), + ); + } +} pub fn test_binding_35() { let owner: Value = Rc::new(RefCell::new(::default())); let __decomp_36: Ptr = owner.as_pointer(); - let value: Ptr = ({ IndexedBindingImpl::get_1_0(&__decomp_36) }); + let value: Ptr = ({ IndexedBinding::get_1_0((__decomp_36).clone()) }); let mut result: u32 = ({ match ({ 1_u32 }, { - ({ IndexedBindingImpl::get_1_0(&__decomp_36) }) + ({ IndexedBinding::get_1_0((__decomp_36).clone()) }) }) { (__tmp_97, __tmp_98) => __tmp_98.with_mut(|__tmp_98| { (*__tmp_98) = (*__tmp_98).wrapping_add(__tmp_97); @@ -2362,8 +2372,8 @@ pub struct Counts_59 { pub counts: Vec, } impl DefaultConstructible for Counts_59 { - fn default_constructor(this: &Ptr) { - field!((*this), counts).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, counts).write(Vec::new()); } } #[derive( @@ -2734,19 +2744,6 @@ impl Default for Owner_63 { } } } -pub trait IndexedBindingImpl { - fn get_1_0(&self) -> Ptr; -} -impl IndexedBindingImpl for Ptr { - fn get_1_0(&self) -> Ptr { - return selected_values_34.with(|v| v.decay()).offset( - ({ - let __idx0 = (0) as usize; - selected_values_34.with(|rc| rc.borrow()[__idx0]) - }), - ); - } -} pub fn __cpp2rust_init_globals() { let _ = global_22.with(|_| ()); let _ = global_record_25.with(|_| ()); diff --git a/tests/unit/out/refcount/cast.rs b/tests/unit/out/refcount/cast.rs index 8d9c103416..8749aed227 100644 --- a/tests/unit/out/refcount/cast.rs +++ b/tests/unit/out/refcount/cast.rs @@ -106,9 +106,9 @@ pub struct Bag { pub items: Vec, } impl DefaultConstructible for Bag { - fn default_constructor(this: &Ptr) { - field!((*this), n).write(0_i32); - field!((*this), items).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, n).write(0_i32); + field!(this, items).write(Vec::new()); } } pub fn adjacent_arrays_0() { diff --git a/tests/unit/out/refcount/class.rs b/tests/unit/out/refcount/class.rs index 6f965ac019..b74e57284a 100644 --- a/tests/unit/out/refcount/class.rs +++ b/tests/unit/out/refcount/class.rs @@ -25,6 +25,29 @@ pub struct Pair { #[offset(4)] pub second: i32, } +impl Pair { + pub fn NOP(this: Ptr) {} + pub fn GetFirst(this: Ptr) -> i32 { + return this.with(|__s| __s.first); + } + pub fn GetSecond(this: Ptr) -> i32 { + return this.with(|__s| __s.second); + } + pub fn Set(this: Ptr, field: Ptr, mut new_val: i32) -> i32 { + ({ Pair::NOP(this.clone()) }); + let mut old_val: i32 = (field.read()); + field.write(new_val); + return old_val; + } + pub fn SetFirst(this: Ptr, mut new_first: i32) -> i32 { + return (({ Pair::GetFirst(this.clone()) }) + + ({ Pair::Set(this.clone(), field_ptr!(this, first), new_first) })); + } + pub fn SetSecond(this: Ptr, mut new_second: i32) -> i32 { + return (({ Pair::GetSecond(this.clone()) }) + + ({ Pair::Set(this.clone(), field_ptr!(this, second), new_second) })); + } +} #[derive( Copy, Clone, @@ -45,6 +68,13 @@ pub struct Route { #[offset(8)] pub cost: f64, } +impl Route { + pub fn SetCost(this: Ptr, mut new_cost: f64) -> f64 { + let mut old_cost: f64 = this.with(|__s| __s.cost); + field!(this, cost).write(new_cost); + return old_cost; + } +} #[derive( Copy, Clone, @@ -64,9 +94,23 @@ pub struct Counter { #[offset(4)] pub calls: i32, } +impl Counter { + pub fn Get(this: Ptr) -> i32 { + field!(this, calls).with_mut(|__v| { + __v.prefix_inc(); + }); + return this.with(|__s| __s.v); + } + pub fn operator_eq(this: Ptr, o: Ptr) -> bool { + field!(this, calls).with_mut(|__v| { + __v.prefix_inc(); + }); + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } +} impl CppEq for Counter { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - CounterImpl::operator_eq(__lhs, __rhs.clone()) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + Counter::operator_eq(__lhs.clone(), __rhs.clone()) } } #[derive( @@ -86,19 +130,33 @@ pub struct Tally { #[offset(0)] pub calls: i32, } +impl Tally { + pub fn SameNameBetweenConstAndNonConst_1(this: Ptr) -> i32 { + { + field!(this, calls).with_mut(|__v| *__v = *__v + 1) + }; + return 1; + } + pub fn SameNameBetweenConstAndNonConst_2(this: Ptr) -> i32 { + { + field!(this, calls).with_mut(|__v| *__v = *__v + 10) + }; + return 2; + } +} pub fn RandomRoute_0(route: Ptr) -> i32 { if ((route.with(|__s| __s.path.first) % 2) != 0) { return ({ - PairImpl::SetFirst( - &field_ptr!(route, path), - ({ PairImpl::SetSecond(&field_ptr!(route, path), 10) }), + Pair::SetFirst( + field_ptr!(route, path), + ({ Pair::SetSecond(field_ptr!(route, path), 10) }), ) }); } else { return ({ - PairImpl::SetSecond( - &field_ptr!(route, path), - ({ PairImpl::SetFirst(&field_ptr!(route, path), -10_i32) }), + Pair::SetSecond( + field_ptr!(route, path), + ({ Pair::SetFirst(field_ptr!(route, path), -10_i32) }), ) }); } @@ -124,9 +182,9 @@ fn main_0() -> i32 { cost: 10_f64, })); let mut old_cost: f64 = ({ - RouteImpl::SetCost( - &route1.as_pointer(), - ({ RouteImpl::SetCost(&route2.as_pointer(), 15_f64) }), + Route::SetCost( + route1.as_pointer(), + ({ Route::SetCost(route2.as_pointer(), 15_f64) }), ) }); assert!( @@ -138,98 +196,21 @@ fn main_0() -> i32 { let c1: Value = Rc::new(RefCell::new(Counter { v: 3, calls: 0 })); let c2: Value = Rc::new(RefCell::new(Counter { v: 3, calls: 0 })); let mut pc: Ptr = (c1.as_pointer()); - assert!((({ CounterImpl::Get(&c1.as_pointer(),) }) == 3)); - assert!((({ CounterImpl::Get(&c2.as_pointer(),) }) == 3)); - assert!((({ CounterImpl::Get(&pc,) }) == 3)); - assert!(({ CounterImpl::operator_eq(&c1.as_pointer(), c2.as_pointer(),) })); - assert!(({ CounterImpl::operator_eq(&c2.as_pointer(), c1.as_pointer(),) })); + assert!((({ Counter::Get(c1.as_pointer(),) }) == 3)); + assert!((({ Counter::Get(c2.as_pointer(),) }) == 3)); + assert!((({ Counter::Get((pc).clone(),) }) == 3)); + assert!(({ Counter::operator_eq(c1.as_pointer(), c2.as_pointer(),) })); + assert!(({ Counter::operator_eq(c2.as_pointer(), c1.as_pointer(),) })); assert!(({ (*c1.borrow()).calls } == 3)); assert!(({ (*c2.borrow()).calls } == 2)); let t: Value = Rc::new(RefCell::new(Tally { calls: 0 })); let ct: Value = Rc::new(RefCell::new(Tally { calls: 0 })); let rt: Ptr = t.as_pointer(); - assert!((({ TallyImpl::SameNameBetweenConstAndNonConst_1(&t.as_pointer(),) }) == 1)); - assert!((({ TallyImpl::SameNameBetweenConstAndNonConst_2(&ct.as_pointer(),) }) == 2)); - assert!((({ TallyImpl::SameNameBetweenConstAndNonConst_2(&rt,) }) == 2)); + assert!((({ Tally::SameNameBetweenConstAndNonConst_1(t.as_pointer(),) }) == 1)); + assert!((({ Tally::SameNameBetweenConstAndNonConst_2(ct.as_pointer(),) }) == 2)); + assert!((({ Tally::SameNameBetweenConstAndNonConst_2((rt).clone(),) }) == 2)); assert!(({ (*t.borrow()).calls } == 11)); assert!(({ (*ct.borrow()).calls } == 10)); return 0; } -pub trait CounterImpl { - fn Get(&self) -> i32; - fn operator_eq(&self, o: Ptr) -> bool; -} -impl CounterImpl for Ptr { - fn Get(&self) -> i32 { - field!((*self), calls).with_mut(|__v| { - __v.prefix_inc(); - }); - return (*self).with(|__s| __s.v); - } - fn operator_eq(&self, o: Ptr) -> bool { - field!((*self), calls).with_mut(|__v| { - __v.prefix_inc(); - }); - return ({ (*self).with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } -} -pub trait PairImpl { - fn NOP(&self); - fn GetFirst(&self) -> i32; - fn GetSecond(&self) -> i32; - fn Set(&self, field: Ptr, new_val: i32) -> i32; - fn SetFirst(&self, new_first: i32) -> i32; - fn SetSecond(&self, new_second: i32) -> i32; -} -impl PairImpl for Ptr { - fn NOP(&self) {} - fn GetFirst(&self) -> i32 { - return (*self).with(|__s| __s.first); - } - fn GetSecond(&self) -> i32 { - return (*self).with(|__s| __s.second); - } - fn Set(&self, field: Ptr, mut new_val: i32) -> i32 { - ({ PairImpl::NOP(self) }); - let mut old_val: i32 = (field.read()); - field.write(new_val); - return old_val; - } - fn SetFirst(&self, mut new_first: i32) -> i32 { - return (({ PairImpl::GetFirst(self) }) - + ({ PairImpl::Set(self, field_ptr!((*self), first), new_first) })); - } - fn SetSecond(&self, mut new_second: i32) -> i32 { - return (({ PairImpl::GetSecond(self) }) - + ({ PairImpl::Set(self, field_ptr!((*self), second), new_second) })); - } -} -pub trait RouteImpl { - fn SetCost(&self, new_cost: f64) -> f64; -} -impl RouteImpl for Ptr { - fn SetCost(&self, mut new_cost: f64) -> f64 { - let mut old_cost: f64 = (*self).with(|__s| __s.cost); - field!((*self), cost).write(new_cost); - return old_cost; - } -} -pub trait TallyImpl { - fn SameNameBetweenConstAndNonConst_1(&self) -> i32; - fn SameNameBetweenConstAndNonConst_2(&self) -> i32; -} -impl TallyImpl for Ptr { - fn SameNameBetweenConstAndNonConst_1(&self) -> i32 { - { - field!((*self), calls).with_mut(|__v| *__v = *__v + 1) - }; - return 1; - } - fn SameNameBetweenConstAndNonConst_2(&self) -> i32 { - { - field!((*self), calls).with_mut(|__v| *__v = *__v + 10) - }; - return 2; - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/class_template_lazy_member.rs b/tests/unit/out/refcount/class_template_lazy_member.rs index 59afd97391..ebd24b3d08 100644 --- a/tests/unit/out/refcount/class_template_lazy_member.rs +++ b/tests/unit/out/refcount/class_template_lazy_member.rs @@ -40,6 +40,11 @@ pub struct Box_int_ { #[offset(0)] pub val: i32, } +impl Box_int_ { + pub fn twice(this: Ptr) -> i32 { + return (this.with(|__s| __s.val) + this.with(|__s| __s.val)); + } +} #[derive( Copy, Clone, @@ -58,6 +63,11 @@ pub struct Box_Point_ { #[byte_size(4)] pub val: Point, } +impl Box_Point_ { + pub fn get(this: Ptr) -> Point { + return this.with(|__s| __s.val); + } +} #[derive( Copy, Clone, @@ -75,6 +85,11 @@ pub struct Deduced_int_ { #[offset(0)] pub val: i32, } +impl Deduced_int_ { + pub fn twice(this: Ptr) -> i32 { + return (this.with(|__s| __s.val) + this.with(|__s| __s.val)); + } +} #[derive( Copy, Clone, @@ -93,61 +108,28 @@ pub struct Deduced_Point_ { #[byte_size(4)] pub val: Point, } +impl Deduced_Point_ { + pub fn get(this: Ptr) -> Point { + return this.with(|__s| __s.val); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { let i: Value = Rc::new(RefCell::new(Box_int_ { val: 3 })); - assert!((({ Box_int_Impl::twice(&i.as_pointer(),) }) == 6)); + assert!((({ Box_int_::twice(i.as_pointer(),) }) == 6)); let p: Value = Rc::new(RefCell::new(Box_Point_ { val: Point { x: 4 }, })); - assert!(({ ({ Box_Point_Impl::get(&p.as_pointer(),) }).x } == 4)); + assert!(({ ({ Box_Point_::get(p.as_pointer(),) }).x } == 4)); let d: Value = Rc::new(RefCell::new(Deduced_int_ { val: 5 })); - assert!((({ Deduced_int_Impl::twice(&d.as_pointer(),) }) == 10)); + assert!((({ Deduced_int_::twice(d.as_pointer(),) }) == 10)); let dp: Value = Rc::new(RefCell::new(Deduced_Point_ { val: Point { x: 6 }, })); - assert!(({ ({ Deduced_Point_Impl::get(&dp.as_pointer(),) }).x } == 6)); + assert!(({ ({ Deduced_Point_::get(dp.as_pointer(),) }).x } == 6)); return 0; } -pub trait Box_Point_Impl { - fn get(&self) -> Point; - fn twice(&self) -> Point { - unimplemented!() - } -} -impl Box_Point_Impl for Ptr { - fn get(&self) -> Point { - return (*self).with(|__s| __s.val); - } -} -pub trait Box_int_Impl { - fn get(&self) -> i32 { - unimplemented!() - } - fn twice(&self) -> i32; -} -impl Box_int_Impl for Ptr { - fn twice(&self) -> i32 { - return ((*self).with(|__s| __s.val) + (*self).with(|__s| __s.val)); - } -} -pub trait Deduced_Point_Impl { - fn get(&self) -> Point; -} -impl Deduced_Point_Impl for Ptr { - fn get(&self) -> Point { - return (*self).with(|__s| __s.val); - } -} -pub trait Deduced_int_Impl { - fn twice(&self) -> i32; -} -impl Deduced_int_Impl for Ptr { - fn twice(&self) -> i32 { - return ((*self).with(|__s| __s.val) + (*self).with(|__s| __s.val)); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/class_templates.rs b/tests/unit/out/refcount/class_templates.rs index f106590fc7..8eee2dcecd 100644 --- a/tests/unit/out/refcount/class_templates.rs +++ b/tests/unit/out/refcount/class_templates.rs @@ -26,9 +26,30 @@ pub struct MyContainer_int_ { #[byte_size(24)] vec_: Vec, } +impl MyContainer_int_ { + pub fn empty(this: Ptr) -> bool { + return (*this.upgrade().deref()).vec_.is_empty(); + } + pub fn size(this: Ptr) -> usize { + return (*this.upgrade().deref()).vec_.len(); + } + pub fn back_4(this: Ptr) -> Ptr { + return { + let __n = (*this.upgrade().deref()).vec_.len() - 1; + field_ref!(this, vec_).decay().offset((__n) as isize) + }; + } + pub fn pop_back(this: Ptr) { + field!(this, vec_).with_mut(|__v: &mut Vec| __v.pop()); + return; + } + pub fn push_back(this: Ptr, item: Ptr) { + CopyConstructible::push_copied(&field_ref!(this, vec_).as_pointer(), (item).clone()); + } +} impl DefaultConstructible for MyContainer_int_ { - fn default_constructor(this: &Ptr) { - field!((*this), vec_).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, vec_).write(Vec::new()); } } #[derive( @@ -51,9 +72,30 @@ pub struct MyContainer_char_ { #[byte_size(24)] vec_: Vec, } +impl MyContainer_char_ { + pub fn empty(this: Ptr) -> bool { + return (*this.upgrade().deref()).vec_.is_empty(); + } + pub fn size(this: Ptr) -> usize { + return (*this.upgrade().deref()).vec_.len(); + } + pub fn back_4(this: Ptr) -> Ptr { + return { + let __n = (*this.upgrade().deref()).vec_.len() - 1; + field_ref!(this, vec_).decay().offset((__n) as isize) + }; + } + pub fn pop_back(this: Ptr) { + field!(this, vec_).with_mut(|__v: &mut Vec| __v.pop()); + return; + } + pub fn push_back(this: Ptr, item: Ptr) { + CopyConstructible::push_copied(&field_ref!(this, vec_).as_pointer(), (item).clone()); + } +} impl DefaultConstructible for MyContainer_char_ { - fn default_constructor(this: &Ptr) { - field!((*this), vec_).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, vec_).write(Vec::new()); } } #[derive( @@ -76,9 +118,30 @@ pub struct MyContainer_float_ { #[byte_size(24)] vec_: Vec, } +impl MyContainer_float_ { + pub fn empty(this: Ptr) -> bool { + return (*this.upgrade().deref()).vec_.is_empty(); + } + pub fn size(this: Ptr) -> usize { + return (*this.upgrade().deref()).vec_.len(); + } + pub fn back_4(this: Ptr) -> Ptr { + return { + let __n = (*this.upgrade().deref()).vec_.len() - 1; + field_ref!(this, vec_).decay().offset((__n) as isize) + }; + } + pub fn pop_back(this: Ptr) { + field!(this, vec_).with_mut(|__v: &mut Vec| __v.pop()); + return; + } + pub fn push_back(this: Ptr, item: Ptr) { + CopyConstructible::push_copied(&field_ref!(this, vec_).as_pointer(), (item).clone()); + } +} impl DefaultConstructible for MyContainer_float_ { - fn default_constructor(this: &Ptr) { - field!((*this), vec_).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, vec_).write(Vec::new()); } } #[derive( @@ -102,6 +165,9 @@ impl Boxed_short_ { pub fn twice(mut v: i16) -> i16 { return (((v as i32) + (v as i32)) as i16); } + pub fn plus(this: Ptr, mut other: i16) -> i16 { + return (((this.with(|__s| __s.value) as i32) + (other as i32)) as i16); + } } #[derive( Copy, @@ -124,6 +190,9 @@ impl Boxed_int_ { pub fn twice(mut v: i32) -> i32 { return (v + v); } + pub fn plus(this: Ptr, mut other: i32) -> i32 { + return (this.with(|__s| __s.value) + other); + } } #[derive( Copy, @@ -146,6 +215,9 @@ impl Boxed_long_ { pub fn twice(mut v: i64) -> i64 { return (v + v); } + pub fn plus(this: Ptr, mut other: i64) -> i64 { + return (this.with(|__s| __s.value) + other); + } } #[derive( Copy, @@ -166,6 +238,11 @@ pub struct Outer_int__Inner_int_ { #[offset(4)] pub u: i32, } +impl Outer_int__Inner_int_ { + pub fn sum(this: Ptr) -> i32 { + return ((this.with(|__s| __s.t) as i32) + (this.with(|__s| __s.u) as i32)); + } +} #[derive( Copy, Clone, @@ -183,6 +260,14 @@ pub struct Outer_int_ { #[offset(0)] pub v: i32, } +impl Outer_int_ { + pub fn with(this: Ptr, mut n: i32) -> Outer_int__Inner_int_ { + return Outer_int__Inner_int_ { + t: this.with(|__s| __s.v), + u: n, + }; + } +} #[derive( Copy, Clone, @@ -202,6 +287,11 @@ pub struct Outer_long__Inner_int_ { #[offset(8)] pub u: i32, } +impl Outer_long__Inner_int_ { + pub fn sum(this: Ptr) -> i32 { + return ((this.with(|__s| __s.t) as i32) + (this.with(|__s| __s.u) as i32)); + } +} #[derive( Copy, Clone, @@ -221,6 +311,11 @@ pub struct Outer_long__Inner_char_ { #[offset(8)] pub u: i8, } +impl Outer_long__Inner_char_ { + pub fn sum(this: Ptr) -> i32 { + return ((this.with(|__s| __s.t) as i32) + (this.with(|__s| __s.u) as i32)); + } +} #[derive( Copy, Clone, @@ -238,6 +333,14 @@ pub struct Outer_long_ { #[offset(0)] pub v: i64, } +impl Outer_long_ { + pub fn with(this: Ptr, mut n: i32) -> Outer_long__Inner_int_ { + return Outer_long__Inner_int_ { + t: this.with(|__s| __s.v), + u: n, + }; + } +} #[derive( Copy, Clone, @@ -270,11 +373,8 @@ fn main_0() -> i32 { let oi: Value = Rc::new(RefCell::new(Outer_int_ { v: 3 })); assert!( (({ - Outer_int__Inner_int_Impl::sum( - &Rc::new(RefCell::new( - ({ Outer_int_Impl::with(&oi.as_pointer(), 4) }), - )) - .as_pointer(), + Outer_int__Inner_int_::sum( + Rc::new(RefCell::new(({ Outer_int_::with(oi.as_pointer(), 4) }))).as_pointer(), ) }) == 7) ); @@ -285,224 +385,55 @@ fn main_0() -> i32 { })); assert!( (({ - Outer_long__Inner_int_Impl::sum( - &Rc::new(RefCell::new( - ({ Outer_long_Impl::with(&ol.as_pointer(), 2) }), - )) - .as_pointer(), + Outer_long__Inner_int_::sum( + Rc::new(RefCell::new(({ Outer_long_::with(ol.as_pointer(), 2) }))).as_pointer(), ) }) == 7) ); - assert!( - (({ Outer_long__Inner_char_Impl::sum(&ic.as_pointer(),) }) == (6 + (('a' as i8) as i32))) - ); + assert!((({ Outer_long__Inner_char_::sum(ic.as_pointer(),) }) == (6 + (('a' as i8) as i32)))); assert!((({ Boxed_int_::twice(3,) }) == 6)); let bi: Value = Rc::new(RefCell::new(Boxed_int_ { value: 4 })); - assert!((({ Boxed_int_Impl::plus(&bi.as_pointer(), 5,) }) == 9)); + assert!((({ Boxed_int_::plus(bi.as_pointer(), 5,) }) == 9)); assert!((({ Boxed_long_::twice(10_i64,) }) == 20_i64)); let bl: Value = Rc::new(RefCell::new(Boxed_long_ { value: 7_i64 })); - assert!((({ Boxed_long_Impl::plus(&bl.as_pointer(), 1_i64,) }) == 8_i64)); + assert!((({ Boxed_long_::plus(bl.as_pointer(), 1_i64,) }) == 8_i64)); object!(imc, MyContainer_int_); - assert!(({ MyContainer_int_Impl::empty(&imc.as_pointer(),) })); + assert!(({ MyContainer_int_::empty(imc.as_pointer(),) })); ({ let _item: Value = Rc::new(RefCell::new(1)); - MyContainer_int_Impl::push_back(&imc.as_pointer(), _item.as_pointer()) + MyContainer_int_::push_back(imc.as_pointer(), _item.as_pointer()) }); assert!( - (({ MyContainer_int_Impl::size(&imc.as_pointer(),) }) == 1_usize) - && ((({ MyContainer_int_Impl::back_4(&imc.as_pointer(),) }).read()) == 1) + (({ MyContainer_int_::size(imc.as_pointer(),) }) == 1_usize) + && ((({ MyContainer_int_::back_4(imc.as_pointer(),) }).read()) == 1) ); - ({ MyContainer_int_Impl::pop_back(&imc.as_pointer()) }); - assert!(({ MyContainer_int_Impl::empty(&imc.as_pointer(),) })); + ({ MyContainer_int_::pop_back(imc.as_pointer()) }); + assert!(({ MyContainer_int_::empty(imc.as_pointer(),) })); object!(cmc, MyContainer_char_); - assert!(({ MyContainer_char_Impl::empty(&cmc.as_pointer(),) })); + assert!(({ MyContainer_char_::empty(cmc.as_pointer(),) })); ({ let _item: Value = Rc::new(RefCell::new(('a' as i8))); - MyContainer_char_Impl::push_back(&cmc.as_pointer(), _item.as_pointer()) + MyContainer_char_::push_back(cmc.as_pointer(), _item.as_pointer()) }); assert!( - (({ MyContainer_char_Impl::size(&cmc.as_pointer(),) }) == 1_usize) - && (((({ MyContainer_char_Impl::back_4(&cmc.as_pointer(),) }).read()) as i32) + (({ MyContainer_char_::size(cmc.as_pointer(),) }) == 1_usize) + && (((({ MyContainer_char_::back_4(cmc.as_pointer(),) }).read()) as i32) == (('a' as i8) as i32)) ); - ({ MyContainer_char_Impl::pop_back(&cmc.as_pointer()) }); - assert!(({ MyContainer_char_Impl::empty(&cmc.as_pointer(),) })); + ({ MyContainer_char_::pop_back(cmc.as_pointer()) }); + assert!(({ MyContainer_char_::empty(cmc.as_pointer(),) })); object!(fmc, MyContainer_float_); - assert!(({ MyContainer_float_Impl::empty(&fmc.as_pointer(),) })); + assert!(({ MyContainer_float_::empty(fmc.as_pointer(),) })); ({ let _item: Value = Rc::new(RefCell::new((1_f64 as f32))); - MyContainer_float_Impl::push_back(&fmc.as_pointer(), _item.as_pointer()) + MyContainer_float_::push_back(fmc.as_pointer(), _item.as_pointer()) }); assert!( - (({ MyContainer_float_Impl::size(&fmc.as_pointer(),) }) == 1_usize) - && (((({ MyContainer_float_Impl::back_4(&fmc.as_pointer(),) }).read()) as f64) - == 1_f64) + (({ MyContainer_float_::size(fmc.as_pointer(),) }) == 1_usize) + && (((({ MyContainer_float_::back_4(fmc.as_pointer(),) }).read()) as f64) == 1_f64) ); - ({ MyContainer_float_Impl::pop_back(&fmc.as_pointer()) }); - assert!(({ MyContainer_float_Impl::empty(&fmc.as_pointer(),) })); + ({ MyContainer_float_::pop_back(fmc.as_pointer()) }); + assert!(({ MyContainer_float_::empty(fmc.as_pointer(),) })); return 0; } -pub trait Boxed_int_Impl { - fn plus(&self, other: i32) -> i32; -} -impl Boxed_int_Impl for Ptr { - fn plus(&self, mut other: i32) -> i32 { - return ((*self).with(|__s| __s.value) + other); - } -} -pub trait Boxed_long_Impl { - fn plus(&self, other: i64) -> i64; -} -impl Boxed_long_Impl for Ptr { - fn plus(&self, mut other: i64) -> i64 { - return ((*self).with(|__s| __s.value) + other); - } -} -pub trait Boxed_short_Impl { - fn plus(&self, other: i16) -> i16; -} -impl Boxed_short_Impl for Ptr { - fn plus(&self, mut other: i16) -> i16 { - return ((((*self).with(|__s| __s.value) as i32) + (other as i32)) as i16); - } -} -pub trait MyContainer_char_Impl { - fn empty(&self) -> bool; - fn size(&self) -> usize; - fn back_3(&self) -> Ptr { - unimplemented!() - } - fn back_4(&self) -> Ptr; - fn pop_back(&self); - fn push_back(&self, item: Ptr); -} -impl MyContainer_char_Impl for Ptr { - fn empty(&self) -> bool { - return (*(*self).upgrade().deref()).vec_.is_empty(); - } - fn size(&self) -> usize { - return (*(*self).upgrade().deref()).vec_.len(); - } - fn back_4(&self) -> Ptr { - return { - let __n = (*(*self).upgrade().deref()).vec_.len() - 1; - field_ref!((*self), vec_).decay().offset((__n) as isize) - }; - } - fn pop_back(&self) { - field!((*self), vec_).with_mut(|__v: &mut Vec| __v.pop()); - return; - } - fn push_back(&self, item: Ptr) { - CopyConstructible::push_copied(&field_ref!((*self), vec_).as_pointer(), (item).clone()); - } -} -pub trait MyContainer_float_Impl { - fn empty(&self) -> bool; - fn size(&self) -> usize; - fn back_3(&self) -> Ptr { - unimplemented!() - } - fn back_4(&self) -> Ptr; - fn pop_back(&self); - fn push_back(&self, item: Ptr); -} -impl MyContainer_float_Impl for Ptr { - fn empty(&self) -> bool { - return (*(*self).upgrade().deref()).vec_.is_empty(); - } - fn size(&self) -> usize { - return (*(*self).upgrade().deref()).vec_.len(); - } - fn back_4(&self) -> Ptr { - return { - let __n = (*(*self).upgrade().deref()).vec_.len() - 1; - field_ref!((*self), vec_).decay().offset((__n) as isize) - }; - } - fn pop_back(&self) { - field!((*self), vec_).with_mut(|__v: &mut Vec| __v.pop()); - return; - } - fn push_back(&self, item: Ptr) { - CopyConstructible::push_copied(&field_ref!((*self), vec_).as_pointer(), (item).clone()); - } -} -pub trait MyContainer_int_Impl { - fn empty(&self) -> bool; - fn size(&self) -> usize; - fn back_3(&self) -> Ptr { - unimplemented!() - } - fn back_4(&self) -> Ptr; - fn pop_back(&self); - fn push_back(&self, item: Ptr); -} -impl MyContainer_int_Impl for Ptr { - fn empty(&self) -> bool { - return (*(*self).upgrade().deref()).vec_.is_empty(); - } - fn size(&self) -> usize { - return (*(*self).upgrade().deref()).vec_.len(); - } - fn back_4(&self) -> Ptr { - return { - let __n = (*(*self).upgrade().deref()).vec_.len() - 1; - field_ref!((*self), vec_).decay().offset((__n) as isize) - }; - } - fn pop_back(&self) { - field!((*self), vec_).with_mut(|__v: &mut Vec| __v.pop()); - return; - } - fn push_back(&self, item: Ptr) { - CopyConstructible::push_copied(&field_ref!((*self), vec_).as_pointer(), (item).clone()); - } -} -pub trait Outer_int_Impl { - fn with(&self, n: i32) -> Outer_int__Inner_int_; -} -impl Outer_int_Impl for Ptr { - fn with(&self, mut n: i32) -> Outer_int__Inner_int_ { - return Outer_int__Inner_int_ { - t: (*self).with(|__s| __s.v), - u: n, - }; - } -} -pub trait Outer_int__Inner_int_Impl { - fn sum(&self) -> i32; -} -impl Outer_int__Inner_int_Impl for Ptr { - fn sum(&self) -> i32 { - return (((*self).with(|__s| __s.t) as i32) + ((*self).with(|__s| __s.u) as i32)); - } -} -pub trait Outer_long_Impl { - fn with(&self, n: i32) -> Outer_long__Inner_int_; -} -impl Outer_long_Impl for Ptr { - fn with(&self, mut n: i32) -> Outer_long__Inner_int_ { - return Outer_long__Inner_int_ { - t: (*self).with(|__s| __s.v), - u: n, - }; - } -} -pub trait Outer_long__Inner_char_Impl { - fn sum(&self) -> i32; -} -impl Outer_long__Inner_char_Impl for Ptr { - fn sum(&self) -> i32 { - return (((*self).with(|__s| __s.t) as i32) + ((*self).with(|__s| __s.u) as i32)); - } -} -pub trait Outer_long__Inner_int_Impl { - fn sum(&self) -> i32; -} -impl Outer_long__Inner_int_Impl for Ptr { - fn sum(&self) -> i32 { - return (((*self).with(|__s| __s.t) as i32) + ((*self).with(|__s| __s.u) as i32)); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/complex_function.rs b/tests/unit/out/refcount/complex_function.rs index c6fbbd220c..0ffe5dbb4a 100644 --- a/tests/unit/out/refcount/complex_function.rs +++ b/tests/unit/out/refcount/complex_function.rs @@ -49,6 +49,11 @@ pub struct X2 { #[byte_size(8)] pub v: Ptr, } +impl X2 { + pub fn get(this: Ptr) -> Ptr { + return (this.with(|__s| __s.v.clone())).clone(); + } +} #[derive( Clone, Record, @@ -66,6 +71,11 @@ pub struct X3 { #[byte_size(8)] pub v: Ptr, } +impl X3 { + pub fn get(this: Ptr) -> Ptr { + return this.with(|__s| __s.v.clone()); + } +} #[derive( Clone, Record, @@ -83,6 +93,11 @@ pub struct X4 { #[byte_size(8)] pub v: X3, } +impl X4 { + pub fn get(this: Ptr) -> Ptr { + return field_ptr!(this, v); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -123,32 +138,31 @@ fn main_0() -> i32 { let d: Value = Rc::new(RefCell::new(X4 { v: (c).clone() })); field!({ (*d.borrow()).v.v.clone() }.with(|__s| __s.v.clone()), v).write(0); field!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v ) .write(0); (*d.borrow_mut()).v.v = (b.as_pointer()); let r4: Ptr = field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v ); - let r5: Ptr = ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer()) })) })) }); - let mut p: Ptr = ({ X3Impl::get(&({ X4Impl::get(&d.as_pointer()) })) }); - let r6: Ptr = ({ X4Impl::get(&d.as_pointer()) }); + let r5: Ptr = ({ X2::get(({ X3::get(({ X4::get(d.as_pointer()) })) })) }); + let mut p: Ptr = ({ X3::get(({ X4::get(d.as_pointer()) })) }); + let r6: Ptr = ({ X4::get(d.as_pointer()) }); let r7: Ptr = field_ptr!(d.as_pointer(), v); let r8: Ptr = field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&field_ptr!(d.as_pointer(), v),) }),) }), + ({ X2::get(({ X3::get(field_ptr!(d.as_pointer(), v),) }),) }), v ); - let mut x5: i32 = ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer()) })) })) }) - .with(|__s| __s.v); + let mut x5: i32 = ({ X2::get(({ X3::get(({ X4::get(d.as_pointer()) })) })) }).with(|__s| __s.v); { ({ bar_2(x1.as_pointer()) }).with_mut(|__v| *__v = *__v + 10) }; ({ bar_2(x1.as_pointer()) }).with_mut(|__v| __v.postfix_inc()); let mut bar_out: i32 = (({ bar_2(field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )) }) @@ -159,7 +173,7 @@ fn main_0() -> i32 { { ({ bar_2(field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )) }) @@ -167,21 +181,21 @@ fn main_0() -> i32 { }; ({ bar_2(field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )) }) .with_mut(|__v| __v.postfix_inc()); let mut bar_inc2: i32 = ({ bar_2(field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )) }) .with_mut(|__v| __v.prefix_inc().clone()); bar_inc2 = ({ bar_2(field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )) }) @@ -195,7 +209,7 @@ fn main_0() -> i32 { ({ ptr_1( (field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )), ) @@ -207,7 +221,7 @@ fn main_0() -> i32 { ({ ptr_1( (field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )), ) @@ -218,7 +232,7 @@ fn main_0() -> i32 { ({ ptr_1( (field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )), ) @@ -228,7 +242,7 @@ fn main_0() -> i32 { let mut ptr1: i32 = ({ ptr_1( (field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )), ) @@ -237,7 +251,7 @@ fn main_0() -> i32 { let ptr2: Ptr = ({ ptr_1( (field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )), ) @@ -245,7 +259,7 @@ fn main_0() -> i32 { let mut ptr3: Ptr = ({ ptr_1( (field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )), ) @@ -253,7 +267,7 @@ fn main_0() -> i32 { let mut vptr: i32 = (({ ptr_1( (field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )), ) @@ -261,13 +275,13 @@ fn main_0() -> i32 { .read()); let mut pref: Ptr = ({ bar_2(field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )) }); ({ bar_2(field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )) }) @@ -276,7 +290,7 @@ fn main_0() -> i32 { ((((({ ptr_1( (field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )), ) @@ -284,43 +298,16 @@ fn main_0() -> i32 { .read()) + (({ bar_2(field_ptr!( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer(),) }),) }),) }), + ({ X2::get(({ X3::get(({ X4::get(d.as_pointer(),) }),) }),) }), v )) }) .read())) + ({ - foo_0( - ({ X2Impl::get(&({ X3Impl::get(&({ X4Impl::get(&d.as_pointer()) })) })) }) - .with(|__s| __s.v), - ) + foo_0(({ X2::get(({ X3::get(({ X4::get(d.as_pointer()) })) })) }).with(|__s| __s.v)) })) == 54) ); return 0; } -pub trait X2Impl { - fn get(&self) -> Ptr; -} -impl X2Impl for Ptr { - fn get(&self) -> Ptr { - return ((*self).with(|__s| __s.v.clone())).clone(); - } -} -pub trait X3Impl { - fn get(&self) -> Ptr; -} -impl X3Impl for Ptr { - fn get(&self) -> Ptr { - return (*self).with(|__s| __s.v.clone()); - } -} -pub trait X4Impl { - fn get(&self) -> Ptr; -} -impl X4Impl for Ptr { - fn get(&self) -> Ptr { - return field_ptr!((*self), v); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/concepts.rs b/tests/unit/out/refcount/concepts.rs index 6d8bb7c121..97e6a487cc 100644 --- a/tests/unit/out/refcount/concepts.rs +++ b/tests/unit/out/refcount/concepts.rs @@ -25,6 +25,11 @@ const _: () = assert!( )] #[byte_size(1)] pub struct Sized {} +impl Sized { + pub fn size(this: Ptr) -> i32 { + return 4; + } +} pub fn is_small_0() -> bool { return true; } @@ -68,12 +73,4 @@ fn main_0() -> i32 { assert!((({ pick_6(1_f32,) }) == 2)); return 0; } -pub trait SizedImpl { - fn size(&self) -> i32; -} -impl SizedImpl for Ptr { - fn size(&self) -> i32 { - return 4; - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/constexpr_function.rs b/tests/unit/out/refcount/constexpr_function.rs index 7d52dfa2b2..b93cdd6ebe 100644 --- a/tests/unit/out/refcount/constexpr_function.rs +++ b/tests/unit/out/refcount/constexpr_function.rs @@ -38,9 +38,14 @@ pub struct Flag { #[offset(0)] pub v: i32, } +impl Flag { + pub fn to_bool(this: Ptr) -> bool { + return (this.with(|__s| __s.v) != 0); + } +} pub fn use_4(f: Flag) -> i32 { let f: Value = Rc::new(RefCell::new(f)); - assert!(({ FlagImpl::to_bool(&f.as_pointer(),) })); + assert!(({ Flag::to_bool(f.as_pointer(),) })); return { (*f.borrow()).v }; } pub fn checked_5(mut x: i32) -> i32 { @@ -72,6 +77,11 @@ pub struct P { #[offset(0)] pub v: i32, } +impl P { + pub fn get(this: Ptr) -> i32 { + return this.with(|__s| __s.v); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -94,7 +104,7 @@ fn main_0() -> i32 { let mut ptr: Ptr = arr.decay(); assert!(!(ptr).is_null()); let p: Value

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

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

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

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

{ - fn operator_eq(&self, o: Ptr

) -> bool { - return ({ (*self).with(|__s| __s.x) } == { o.with(|__s| __s.x) }); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/fn_ptr.rs b/tests/unit/out/refcount/fn_ptr.rs index 38db1f7d81..8a188a60a8 100644 --- a/tests/unit/out/refcount/fn_ptr.rs +++ b/tests/unit/out/refcount/fn_ptr.rs @@ -47,6 +47,11 @@ pub struct HashHolder_unsigned_long__ptr__bool__ { #[byte_size(8)] pub h: FnPtr u64>, } +impl HashHolder_unsigned_long__ptr__bool__ { + pub fn construct(this: Ptr, h: Ptr u64>>) { + field!(this, h).write((h.read())); + } +} thread_local!( pub static total_7: Value = Rc::new(RefCell::new(0)); ); @@ -95,7 +100,7 @@ fn main_0() -> i32 { let __tmp_0: Value u64>> = Rc::new(RefCell::new( (FnPtr:: usize>::new(identity_hash_6)).cast:: u64>(), )); - HashHolder_unsigned_long__ptr__bool__Impl::construct(hh, __tmp_0.as_pointer()) + HashHolder_unsigned_long__ptr__bool__::construct(hh.clone(), __tmp_0.as_pointer()) }); assert!((({ { (*hh.borrow()).h.clone() }.call(true,) }) == 1_u64)); let mut handler: FnPtr = FnPtr::::new(add_to_total_8); @@ -129,14 +134,6 @@ fn main_0() -> i32 { ); return 0; } -pub trait HashHolder_unsigned_long__ptr__bool__Impl { - fn construct(&self, h: Ptr u64>>); -} -impl HashHolder_unsigned_long__ptr__bool__Impl for Ptr { - fn construct(&self, h: Ptr u64>>) { - field!((*self), h).write((h.read())); - } -} pub fn __cpp2rust_init_globals() { let _ = total_7.with(|_| ()); } diff --git a/tests/unit/out/refcount/fn_ptr_struct.rs b/tests/unit/out/refcount/fn_ptr_struct.rs index a2dfea5e77..401f586c02 100644 --- a/tests/unit/out/refcount/fn_ptr_struct.rs +++ b/tests/unit/out/refcount/fn_ptr_struct.rs @@ -65,18 +65,26 @@ pub struct MoveOnly { #[offset(0)] pub data_: i32, } +impl MoveOnly { + pub fn construct(this: Ptr, mut data: i32) { + field!(this, data_).write(data); + } + pub fn get(this: Ptr) -> i32 { + return this.with(|__s| __s.data_); + } +} impl MoveConstructible for MoveOnly { - fn move_constructor(this: &Ptr, x: Ptr) { - field!((*this), data_).write(x.with(|__s| __s.data_)); + fn move_constructor(this: Ptr, x: Ptr) { + field!(this, data_).write(x.with(|__s| __s.data_)); field!(x, data_).write(0); } } pub fn make_move_only_2(this: Ptr) { - MoveOnlyImpl::construct(&this, 4); + MoveOnly::construct(this.clone(), 4); return; } pub fn scale_move_only_3(this: Ptr, x: Ptr) { - MoveOnlyImpl::construct(&this, (({ MoveOnlyImpl::get(&x) }) * 10)); + MoveOnly::construct(this.clone(), (({ MoveOnly::get((x).clone()) }) * 10)); return; } pub fn main() { @@ -109,29 +117,17 @@ fn main_0() -> i32 { assert!((({ h1.cb.call(3,) }) == -3_i32)); assert!(({ (h1.cb).clone() } == { (h2.cb).clone() })); let mut mk: FnPtr)> = FnPtr::)>::new(make_move_only_2); - object!(m, MoveOnly, |m| ({ mk.call(Ptr::clone(m),) })); - assert!((({ MoveOnlyImpl::get(&m.as_pointer(),) }) == 4)); + object!(m, MoveOnly, |m| ({ mk.call(Ptr::clone(&m.clone()),) })); + assert!((({ MoveOnly::get(m.as_pointer(),) }) == 4)); let mut sc: FnPtr, Ptr)> = FnPtr::, Ptr)>::new(scale_move_only_3); object!(n, MoveOnly, |n| ({ let _arg0: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&_arg0.as_pointer(), Moved(m.as_pointer())); - sc.call(Ptr::clone(n), _arg0.as_pointer()) + ConstructFrom::construct_from(_arg0.as_pointer(), Moved(m.as_pointer())); + sc.call(Ptr::clone(&n.clone()), _arg0.as_pointer()) })); - assert!((({ MoveOnlyImpl::get(&n.as_pointer(),) }) == 40)); - assert!((({ MoveOnlyImpl::get(&m.as_pointer(),) }) == 0)); + assert!((({ MoveOnly::get(n.as_pointer(),) }) == 40)); + assert!((({ MoveOnly::get(m.as_pointer(),) }) == 0)); return 0; } -pub trait MoveOnlyImpl { - fn construct(&self, data: i32); - fn get(&self) -> i32; -} -impl MoveOnlyImpl for Ptr { - fn construct(&self, mut data: i32) { - field!((*self), data_).write(data); - } - fn get(&self) -> i32 { - return (*self).with(|__s| __s.data_); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/fn_ref.rs b/tests/unit/out/refcount/fn_ref.rs index ed88a34c1b..5abd8b284b 100644 --- a/tests/unit/out/refcount/fn_ref.rs +++ b/tests/unit/out/refcount/fn_ref.rs @@ -38,6 +38,11 @@ pub struct Holder { #[byte_size(8)] pub f: FnPtr i32>, } +impl Holder { + pub fn run(this: Ptr, mut x: i32) -> i32 { + return ({ this.with(|__s| __s.f.clone()).call(x) }); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -53,15 +58,7 @@ fn main_0() -> i32 { let h: Value = Rc::new(RefCell::new(Holder { f: FnPtr:: i32>::new(twice_1), })); - assert!((({ HolderImpl::run(&h.as_pointer(), 8,) }) == 16)); + assert!((({ Holder::run(h.as_pointer(), 8,) }) == 16)); return 0; } -pub trait HolderImpl { - fn run(&self, x: i32) -> i32; -} -impl HolderImpl for Ptr { - fn run(&self, mut x: i32) -> i32 { - return ({ (*self).with(|__s| __s.f.clone()).call(x) }); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/for_body_destructor.rs b/tests/unit/out/refcount/for_body_destructor.rs index 282cb65648..10ab5ac542 100644 --- a/tests/unit/out/refcount/for_body_destructor.rs +++ b/tests/unit/out/refcount/for_body_destructor.rs @@ -24,9 +24,14 @@ pub struct Guard { #[offset(0)] pub digit: i32, } +impl Guard { + pub fn to_bool(this: Ptr) -> bool { + return (this.with(|__s| __s.digit) != 0); + } +} impl Destructible for Guard { - fn destroy(this: &Ptr) { - printf!(b"%d ", (*this).with(|__s| __s.digit)); + fn destroy(this: Ptr) { + printf!(b"%d ", this.with(|__s| __s.digit)); } } pub fn step_0(i: Ptr) { @@ -47,11 +52,11 @@ fn main_0() -> i32 { 'for_body: { let first: Value = Rc::new(RefCell::new(Guard { digit: 1 })); let _dtor_first = std::mem::DropGuard::new(first.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); let second: Value = Rc::new(RefCell::new(Guard { digit: 2 })); let _dtor_second = std::mem::DropGuard::new(second.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); if ((*i.borrow()) == 0) { break 'for_body; @@ -67,7 +72,7 @@ fn main_0() -> i32 { 'for_body: { let g: Value = Rc::new(RefCell::new(Guard { digit: 3 })); let _dtor_g = std::mem::DropGuard::new(g.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); break 'loop_; } @@ -81,7 +86,7 @@ fn main_0() -> i32 { 'for_body: { let outer: Value = Rc::new(RefCell::new(Guard { digit: 4 })); let _dtor_outer = std::mem::DropGuard::new(outer.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); { let j: Value = Rc::new(RefCell::new(0)); @@ -89,7 +94,7 @@ fn main_0() -> i32 { 'for_body: { let inner: Value = Rc::new(RefCell::new(Guard { digit: 5 })); let _dtor_inner = std::mem::DropGuard::new(inner.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); if ((*j.borrow()) == 0) { break 'for_body; @@ -111,13 +116,13 @@ fn main_0() -> i32 { 'for_body: { let outer: Value = Rc::new(RefCell::new(Guard { digit: 4 })); let _dtor_outer = std::mem::DropGuard::new(outer.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); let mut j: i32 = 0; 'loop_: while ((*j.prefix_inc()) < 3) { let inner: Value = Rc::new(RefCell::new(Guard { digit: 5 })); let _dtor_inner = std::mem::DropGuard::new(inner.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); if (j == 1) { continue 'loop_; @@ -129,7 +134,7 @@ fn main_0() -> i32 { __do_while = false; let inner: Value = Rc::new(RefCell::new(Guard { digit: 6 })); let _dtor_inner = std::mem::DropGuard::new(inner.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); continue 'loop_; } @@ -140,7 +145,7 @@ fn main_0() -> i32 { let mut value: i32 = (value.read()); let inner: Value = Rc::new(RefCell::new(Guard { digit: value })); let _dtor_inner = std::mem::DropGuard::new(inner.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); if (value == 1) { continue 'loop_; @@ -158,15 +163,15 @@ fn main_0() -> i32 { 'loop_: loop { let condition: Value = Rc::new(RefCell::new(Guard { digit: i })); let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); - if !({ GuardImpl::to_bool(&condition.as_pointer()) }) { + if !({ Guard::to_bool(condition.as_pointer()) }) { break; } 'for_body: { let body: Value = Rc::new(RefCell::new(Guard { digit: 4 })); let _dtor_body = std::mem::DropGuard::new(body.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); if (i == 2) { break 'for_body; @@ -183,12 +188,12 @@ fn main_0() -> i32 { { let init: Value = Rc::new(RefCell::new(Guard { digit: 5 })); let _dtor_init = - std::mem::DropGuard::new(init.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(init.clone(), |__p| Destructible::destroy(__p.as_pointer())); 'loop_: while ((*i.borrow()) < 2) { 'for_body: { let body: Value = Rc::new(RefCell::new(Guard { digit: 6 })); let _dtor_body = std::mem::DropGuard::new(body.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); } ({ step_0(i.as_pointer()) }); @@ -202,19 +207,11 @@ fn main_0() -> i32 { digit: (*j.prefix_inc()), })); let _dtor_g = - std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(__p.as_pointer())); continue 'loop_; } } printf!(b"\n"); return 0; } -pub trait GuardImpl { - fn to_bool(&self) -> bool; -} -impl GuardImpl for Ptr { - fn to_bool(&self) -> bool { - return ((*self).with(|__s| __s.digit) != 0); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs index 51e5a772ea..e955dbad8d 100644 --- a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs @@ -29,9 +29,9 @@ pub struct S { pub a: i32, } impl DefaultConstructible for S { - fn default_constructor(this: &Ptr) { - field!((*this), v).write(Vec::new()); - field!((*this), a).write(0_i32); + fn default_constructor(this: Ptr) { + field!(this, v).write(Vec::new()); + field!(this, a).write(0_i32); } } pub fn main() { diff --git a/tests/unit/out/refcount/forward_basic.rs b/tests/unit/out/refcount/forward_basic.rs index ddc09a1228..909809f493 100644 --- a/tests/unit/out/refcount/forward_basic.rs +++ b/tests/unit/out/refcount/forward_basic.rs @@ -22,18 +22,25 @@ pub struct Tracked { #[offset(8)] pub moves: i32, } +impl Tracked { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + field!(this, copies).write(0); + field!(this, moves).write(0); + } +} impl CopyConstructible for Tracked { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); - field!((*this), moves).write(o.with(|__s| __s.moves)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write((o.with(|__s| __s.copies) + 1)); + field!(this, moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for Tracked { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write(o.with(|__s| __s.copies)); - field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write(o.with(|__s| __s.copies)); + field!(this, moves).write((o.with(|__s| __s.moves) + 1)); field!(o, v).write(0); } } @@ -43,6 +50,16 @@ pub fn chosen_overload_0(_a0: Ptr) -> Overload { pub fn chosen_overload_1(_a0: Ptr) -> Overload { return Overload_kRvalueOverload; } +impl Holder { + pub fn construct_1(this: Ptr, x: Ptr) { + ConstructFrom::construct_from(field_ptr!(this, t), (x).clone()); + } +} +impl Holder { + pub fn construct_2(this: Ptr, x: Ptr) { + ConstructFrom::construct_from(field_ptr!(this, t), Moved((x).clone())); + } +} #[derive( Record, ByteRepr, @@ -75,11 +92,11 @@ pub fn forward_twice_5(x: Ptr) -> Overload { return ({ forward_once_3((x).clone()) }); } pub fn forward_into_ctor_6(this: Ptr, x: Ptr) { - HolderImpl::construct_1(&this, (x).clone()); + Holder::construct_1(this.clone(), (x).clone()); return; } pub fn forward_into_ctor_7(this: Ptr, x: Ptr) { - HolderImpl::construct_2(&this, (x).clone()); + Holder::construct_2(this.clone(), (x).clone()); return; } pub fn main() { @@ -95,7 +112,7 @@ fn main_0() -> i32 { assert!( ((({ let _x: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&_x.as_pointer(), 8); + Tracked::construct(_x.as_pointer(), 8); forward_once_3(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) @@ -109,14 +126,14 @@ fn main_0() -> i32 { assert!( ((({ let _x: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&_x.as_pointer(), 10); + Tracked::construct(_x.as_pointer(), 10); forward_twice_5(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) ); object!(kept, Tracked(11)); object!(from_lvalue, Holder, |from_lvalue| ({ - forward_into_ctor_6(Ptr::clone(from_lvalue), kept.as_pointer()) + forward_into_ctor_6(Ptr::clone(&from_lvalue.clone()), kept.as_pointer()) })); assert!(({ (*from_lvalue.borrow()).t.v } == 11)); assert!(({ (*from_lvalue.borrow()).t.copies } == 1)); @@ -124,34 +141,12 @@ fn main_0() -> i32 { assert!(({ (*kept.borrow()).v } == 11)); object!(from_rvalue, Holder, |from_rvalue| ({ let _x: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&_x.as_pointer(), 12); - forward_into_ctor_7(Ptr::clone(from_rvalue), _x.as_pointer()) + Tracked::construct(_x.as_pointer(), 12); + forward_into_ctor_7(Ptr::clone(&from_rvalue.clone()), _x.as_pointer()) })); assert!(({ (*from_rvalue.borrow()).t.v } == 12)); assert!(({ (*from_rvalue.borrow()).t.copies } == 0)); assert!(({ (*from_rvalue.borrow()).t.moves } == 1)); return 0; } -pub trait HolderImpl { - fn construct_1(&self, x: Ptr); - fn construct_2(&self, x: Ptr); -} -impl HolderImpl for Ptr { - fn construct_1(&self, x: Ptr) { - ConstructFrom::construct_from(&field_ptr!(self, t), (x).clone()); - } - fn construct_2(&self, x: Ptr) { - ConstructFrom::construct_from(&field_ptr!(self, t), Moved((x).clone())); - } -} -pub trait TrackedImpl { - fn construct(&self, v: i32); -} -impl TrackedImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - field!((*self), copies).write(0); - field!((*self), moves).write(0); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/forward_decltype.rs b/tests/unit/out/refcount/forward_decltype.rs index b3f6eec60d..9b665040ef 100644 --- a/tests/unit/out/refcount/forward_decltype.rs +++ b/tests/unit/out/refcount/forward_decltype.rs @@ -22,18 +22,25 @@ pub struct Tracked { #[offset(8)] pub moves: i32, } +impl Tracked { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + field!(this, copies).write(0); + field!(this, moves).write(0); + } +} impl CopyConstructible for Tracked { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); - field!((*this), moves).write(o.with(|__s| __s.moves)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write((o.with(|__s| __s.copies) + 1)); + field!(this, moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for Tracked { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write(o.with(|__s| __s.copies)); - field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write(o.with(|__s| __s.copies)); + field!(this, moves).write((o.with(|__s| __s.moves) + 1)); field!(o, v).write(0); } } @@ -74,7 +81,7 @@ fn main_0() -> i32 { assert!( ((({ let _x: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&_x.as_pointer(), 4); + Tracked::construct(_x.as_pointer(), 4); forward_by_decltype_3(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) @@ -88,7 +95,7 @@ fn main_0() -> i32 { assert!( ((({ let _x: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&_x.as_pointer(), 6); + Tracked::construct(_x.as_pointer(), 6); forward_abbreviated_5(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) @@ -97,21 +104,11 @@ fn main_0() -> i32 { assert!( (({ let _args_1: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&_args_1.as_pointer(), 8); + Tracked::construct(_args_1.as_pointer(), 8); forward_abbreviated_pack_6(c.as_pointer(), _args_1.as_pointer()) }) == ((Overload_kLvalueOverload as i32) + (Overload_kRvalueOverload as i32))) ); assert!(({ (*c.borrow()).v } == 7)); return 0; } -pub trait TrackedImpl { - fn construct(&self, v: i32); -} -impl TrackedImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - field!((*self), copies).write(0); - field!((*self), moves).write(0); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/forward_explicit.rs b/tests/unit/out/refcount/forward_explicit.rs index dfcbcd792a..a273d6835b 100644 --- a/tests/unit/out/refcount/forward_explicit.rs +++ b/tests/unit/out/refcount/forward_explicit.rs @@ -24,18 +24,25 @@ pub struct Tracked { #[offset(8)] pub moves: i32, } +impl Tracked { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + field!(this, copies).write(0); + field!(this, moves).write(0); + } +} impl CopyConstructible for Tracked { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); - field!((*this), moves).write(o.with(|__s| __s.moves)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write((o.with(|__s| __s.copies) + 1)); + field!(this, moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for Tracked { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write(o.with(|__s| __s.copies)); - field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write(o.with(|__s| __s.copies)); + field!(this, moves).write((o.with(|__s| __s.moves) + 1)); field!(o, v).write(0); } } @@ -52,7 +59,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.clone(), Moved((t).clone())); return; } pub fn main() { @@ -72,8 +79,8 @@ fn main_0() -> i32 { object!(b, Tracked(6)); object!(moved, Tracked, |moved| ({ let _t: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&_t.as_pointer(), Moved(b.as_pointer())); - copy_or_move_into_param_4(Ptr::clone(moved), _t.as_pointer()) + ConstructFrom::construct_from(_t.as_pointer(), Moved(b.as_pointer())); + copy_or_move_into_param_4(Ptr::clone(&moved.clone()), _t.as_pointer()) })); assert!(({ (*moved.borrow()).v } == 6)); assert!(({ (*moved.borrow()).copies } == 0)); @@ -82,8 +89,8 @@ fn main_0() -> i32 { object!(c, Tracked(7)); object!(copied, Tracked, |copied| ({ let _t: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&_t.as_pointer(), c.as_pointer()); - copy_or_move_into_param_4(Ptr::clone(copied), _t.as_pointer()) + ConstructFrom::construct_from(_t.as_pointer(), c.as_pointer()); + copy_or_move_into_param_4(Ptr::clone(&copied.clone()), _t.as_pointer()) })); assert!(({ (*copied.borrow()).v } == 7)); assert!(({ (*copied.borrow()).copies } == 1)); @@ -102,14 +109,4 @@ fn main_0() -> i32 { assert!(({ ((*i.borrow()) == 8) })); return 0; } -pub trait TrackedImpl { - fn construct(&self, v: i32); -} -impl TrackedImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - field!((*self), copies).write(0); - field!((*self), moves).write(0); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/forward_pack.rs b/tests/unit/out/refcount/forward_pack.rs index d89c63fc27..ea73959f0f 100644 --- a/tests/unit/out/refcount/forward_pack.rs +++ b/tests/unit/out/refcount/forward_pack.rs @@ -24,18 +24,25 @@ pub struct Tracked { #[offset(8)] pub moves: i32, } +impl Tracked { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + field!(this, copies).write(0); + field!(this, moves).write(0); + } +} impl CopyConstructible for Tracked { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); - field!((*this), moves).write(o.with(|__s| __s.moves)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write((o.with(|__s| __s.copies) + 1)); + field!(this, moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for Tracked { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write(o.with(|__s| __s.copies)); - field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write(o.with(|__s| __s.copies)); + field!(this, moves).write((o.with(|__s| __s.moves) + 1)); field!(o, v).write(0); } } @@ -87,6 +94,12 @@ pub fn forward_pack_7( }; return digits; } +impl Pair { + pub fn construct(this: Ptr, x: Ptr, y: Ptr) { + ConstructFrom::construct_from(field_ptr!(this, a), (x).clone()); + ConstructFrom::construct_from(field_ptr!(this, b), Moved((y).clone())); + } +} #[derive( Record, ByteRepr, ZeroInitialization, FnPtrArg, DefaultInitializable, Memberwise, Default, )] @@ -101,7 +114,7 @@ pub struct Pair { pub b: Tracked, } pub fn forward_pack_into_ctor_8(this: Ptr, args_0: Ptr, args_1: Ptr) { - PairImpl::construct(&this, (args_0).clone(), (args_1).clone()); + Pair::construct(this.clone(), (args_0).clone(), (args_1).clone()); return; } pub fn main() { @@ -116,7 +129,7 @@ fn main_0() -> i32 { assert!( (({ let _args: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&_args.as_pointer(), 2); + Tracked::construct(_args.as_pointer(), 2); forward_pack_6(_args.as_pointer()) }) == (Overload_kRvalueOverload as i32)) ); @@ -124,7 +137,7 @@ fn main_0() -> i32 { assert!( (({ let _args_1: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&_args_1.as_pointer(), 4); + Tracked::construct(_args_1.as_pointer(), 4); let _args_3: Value = Rc::new(RefCell::new(5)); forward_pack_7( a.as_pointer(), @@ -139,8 +152,12 @@ fn main_0() -> i32 { object!(lhs, Tracked(6)); object!(p, Pair, |p| ({ let _args_1: Value = Rc::new(RefCell::new(::zero_init())); - TrackedImpl::construct(&_args_1.as_pointer(), 7); - forward_pack_into_ctor_8(Ptr::clone(p), lhs.as_pointer(), _args_1.as_pointer()) + Tracked::construct(_args_1.as_pointer(), 7); + forward_pack_into_ctor_8( + Ptr::clone(&p.clone()), + lhs.as_pointer(), + _args_1.as_pointer(), + ) })); assert!(({ (*p.borrow()).a.v } == 6)); assert!(({ (*p.borrow()).a.copies } == 1)); @@ -150,23 +167,4 @@ fn main_0() -> i32 { assert!(({ (*lhs.borrow()).v } == 6)); return 0; } -pub trait PairImpl { - fn construct(&self, x: Ptr, y: Ptr); -} -impl PairImpl for Ptr { - fn construct(&self, x: Ptr, y: Ptr) { - ConstructFrom::construct_from(&field_ptr!(self, a), (x).clone()); - ConstructFrom::construct_from(&field_ptr!(self, b), Moved((y).clone())); - } -} -pub trait TrackedImpl { - fn construct(&self, v: i32); -} -impl TrackedImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - field!((*self), copies).write(0); - field!((*self), moves).write(0); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/friend.rs b/tests/unit/out/refcount/friend.rs index be8d73196f..c9e3cff5e4 100644 --- a/tests/unit/out/refcount/friend.rs +++ b/tests/unit/out/refcount/friend.rs @@ -36,7 +36,7 @@ pub struct V { pub x: i32, } impl CppEq for V { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_1(__lhs.clone(), __rhs.clone()) } } diff --git a/tests/unit/out/refcount/function_overloading.rs b/tests/unit/out/refcount/function_overloading.rs index 36a73a6ce5..34902af520 100644 --- a/tests/unit/out/refcount/function_overloading.rs +++ b/tests/unit/out/refcount/function_overloading.rs @@ -35,6 +35,14 @@ pub fn bar_4(x: Ptr) -> i32 { )] #[byte_size(1)] pub struct Foo {} +impl Foo { + pub fn foo_1(this: Ptr) {} + pub fn foo_2(this: Ptr) {} + pub fn method_3(this: Ptr, mut x: i32) {} + pub fn method_4(this: Ptr, mut x: i32) {} + pub fn method2_5(this: Ptr, mut x: i32, mut y: i32) {} + pub fn method2_6(this: Ptr, mut x: f64, mut y: f64) {} +} pub fn func_5(mut x: i32) -> i32 { return 1; } @@ -57,27 +65,11 @@ fn main_0() -> i32 { out += ((bar + ({ foo_0(0) })) + ({ foo_1((x.as_pointer())) })); let foo1: Value = Rc::new(RefCell::new(::default())); let foo2: Value = Rc::new(RefCell::new(::default())); - ({ FooImpl::foo_2(&foo1.as_pointer()) }); - ({ FooImpl::method_3(&foo1.as_pointer(), 1) }); - ({ FooImpl::foo_1(&foo2.as_pointer()) }); - ({ FooImpl::method_4(&foo2.as_pointer(), 2) }); + ({ Foo::foo_2(foo1.as_pointer()) }); + ({ Foo::method_3(foo1.as_pointer(), 1) }); + ({ Foo::foo_1(foo2.as_pointer()) }); + ({ Foo::method_4(foo2.as_pointer(), 2) }); assert!((out == 13)); return 0; } -pub trait FooImpl { - fn foo_1(&self); - fn foo_2(&self); - fn method_3(&self, x: i32); - fn method_4(&self, x: i32); - fn method2_5(&self, x: i32, y: i32); - fn method2_6(&self, x: f64, y: f64); -} -impl FooImpl for Ptr { - fn foo_1(&self) {} - fn foo_2(&self) {} - fn method_3(&self, mut x: i32) {} - fn method_4(&self, mut x: i32) {} - fn method2_5(&self, mut x: i32, mut y: i32) {} - fn method2_6(&self, mut x: f64, mut y: f64) {} -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/global_call_temporaries.rs b/tests/unit/out/refcount/global_call_temporaries.rs index 730dd447c5..3ffa8ce93b 100644 --- a/tests/unit/out/refcount/global_call_temporaries.rs +++ b/tests/unit/out/refcount/global_call_temporaries.rs @@ -18,7 +18,7 @@ thread_local!( ({ __tmp_0 = Rc::new(RefCell::new(0)); __tmp_1 = Rc::new(RefCell::new(0)); - if CppLess::less(&__tmp_0.as_pointer(), &__tmp_1.as_pointer()) { + if CppLess::less(__tmp_0.as_pointer().clone(), __tmp_1.as_pointer().clone()) { __tmp_0.as_pointer() } else { __tmp_1.as_pointer() @@ -43,7 +43,7 @@ thread_local!( let __rhs = { __tmp_2 = Rc::new(RefCell::new(6)); __tmp_3 = Rc::new(RefCell::new(5)); - (if CppLess::less(&__tmp_2.as_pointer(), &__tmp_3.as_pointer()) { + (if CppLess::less(__tmp_2.as_pointer().clone(), __tmp_3.as_pointer().clone()) { __tmp_2.as_pointer() } else { __tmp_3.as_pointer() @@ -65,7 +65,7 @@ thread_local!( let __rhs = { __tmp_4 = Rc::new(RefCell::new(1)); __tmp_5 = Rc::new(RefCell::new(2)); - (if CppLess::less(&__tmp_4.as_pointer(), &__tmp_5.as_pointer()) { + (if CppLess::less(__tmp_4.as_pointer().clone(), __tmp_5.as_pointer().clone()) { __tmp_5.as_pointer() } else { __tmp_4.as_pointer() @@ -129,7 +129,7 @@ thread_local!( __tmp_7 = Rc::new(RefCell::new(Box::new([{ __tmp_8 = Rc::new(RefCell::new(4)); __tmp_9 = Rc::new(RefCell::new(3)); - (if CppLess::less(&__tmp_8.as_pointer(), &__tmp_9.as_pointer()) { + (if CppLess::less(__tmp_8.as_pointer().clone(), __tmp_9.as_pointer().clone()) { __tmp_8.as_pointer() } else { __tmp_9.as_pointer() @@ -142,7 +142,8 @@ thread_local!( value: { __tmp_11 = Rc::new(RefCell::new(5)); __tmp_12 = Rc::new(RefCell::new(6)); - (if CppLess::less(&__tmp_11.as_pointer(), &__tmp_12.as_pointer()) { + (if CppLess::less(__tmp_11.as_pointer().clone(), __tmp_12.as_pointer().clone()) + { __tmp_12.as_pointer() } else { __tmp_11.as_pointer() @@ -166,7 +167,10 @@ thread_local!( Rc::new(RefCell::new( (({ __tmp_13 = Rc::new(RefCell::new((right_11.with(|rc| *rc.borrow()) as u64))); - (if CppLess::less(&__tmp_13.as_pointer(), &left_10.with(|v| v.as_pointer())) { + (if CppLess::less( + __tmp_13.as_pointer().clone(), + left_10.with(|v| v.as_pointer()).clone(), + ) { __tmp_13.as_pointer() } else { left_10.with(|v| v.as_pointer()) @@ -185,7 +189,10 @@ thread_local!( Rc::new(RefCell::new( (({ __tmp_14 = Rc::new(RefCell::new((right_11.with(|rc| *rc.borrow()) as u64))); - (if CppLess::less(&left_10.with(|v| v.as_pointer()), &__tmp_14.as_pointer()) { + (if CppLess::less( + left_10.with(|v| v.as_pointer()).clone(), + __tmp_14.as_pointer().clone(), + ) { __tmp_14.as_pointer() } else { left_10.with(|v| v.as_pointer()) @@ -222,7 +229,7 @@ thread_local!( __tmp_15 = Rc::new(RefCell::new(Box::new([{ __tmp_16 = Rc::new(RefCell::new(7)); __tmp_17 = Rc::new(RefCell::new(8)); - (if CppLess::less(&__tmp_16.as_pointer(), &__tmp_17.as_pointer()) { + (if CppLess::less(__tmp_16.as_pointer().clone(), __tmp_17.as_pointer().clone()) { __tmp_17.as_pointer() } else { __tmp_16.as_pointer() @@ -235,7 +242,8 @@ thread_local!( value: { __tmp_19 = Rc::new(RefCell::new(10)); __tmp_20 = Rc::new(RefCell::new(9)); - (if CppLess::less(&__tmp_19.as_pointer(), &__tmp_20.as_pointer()) { + (if CppLess::less(__tmp_19.as_pointer().clone(), __tmp_20.as_pointer().clone()) + { __tmp_19.as_pointer() } else { __tmp_20.as_pointer() diff --git a/tests/unit/out/refcount/global_init_side_effect.rs b/tests/unit/out/refcount/global_init_side_effect.rs index 43e141a5d8..45fe592233 100644 --- a/tests/unit/out/refcount/global_init_side_effect.rs +++ b/tests/unit/out/refcount/global_init_side_effect.rs @@ -25,17 +25,22 @@ thread_local!( #[cpp_from(i32, construct, value)] #[byte_size(1)] pub struct S {} +impl S { + pub fn construct(this: Ptr, mut x: i32) { + total_0.with(|rc| *rc.borrow_mut() += x); + } +} thread_local!( pub static a_1: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - SImpl::construct(&__v.as_pointer(), 1); + S::construct(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); thread_local!( pub static b_2: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - SImpl::construct(&__v.as_pointer(), 10); + S::construct(__v.as_pointer(), 10); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -47,14 +52,6 @@ fn main_0() -> i32 { assert!((total_0.with(|rc| *rc.borrow()) == 11)); return 0; } -pub trait SImpl { - fn construct(&self, x: i32); -} -impl SImpl for Ptr { - fn construct(&self, mut x: i32) { - total_0.with(|rc| *rc.borrow_mut() += x); - } -} pub fn __cpp2rust_init_globals() { let _ = total_0.with(|_| ()); let _ = a_1.with(|_| ()); diff --git a/tests/unit/out/refcount/global_non_const_init.rs b/tests/unit/out/refcount/global_non_const_init.rs index af064c9639..46ffacf574 100644 --- a/tests/unit/out/refcount/global_non_const_init.rs +++ b/tests/unit/out/refcount/global_non_const_init.rs @@ -38,9 +38,14 @@ pub struct Ctor { #[offset(0)] pub v: i32, } +impl Ctor { + pub fn construct_1(this: Ptr, mut x: i32) { + field!(this, v).write(x); + } +} impl DefaultConstructible for Ctor { - fn default_constructor(this: &Ptr) { - field!((*this), v).write(({ next_0() })); + fn default_constructor(this: Ptr) { + field!(this, v).write(({ next_0() })); } } impl Default for Ctor { @@ -48,7 +53,7 @@ impl Default for Ctor { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -57,14 +62,14 @@ impl Default for Ctor { thread_local!( pub static default_ctor_7: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); thread_local!( pub static arg_ctor_8: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CtorImpl::construct_1(&__v.as_pointer(), 7); + Ctor::construct_1(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -78,7 +83,7 @@ thread_local!( thread_local!( pub static inline_member_11: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CtorImpl::construct_1(&__v.as_pointer(), 5); + Ctor::construct_1(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -108,7 +113,7 @@ thread_local!( thread_local!( static local_ctor_14: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CtorImpl::construct_1(&__v.as_pointer(), 3); + Ctor::construct_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -124,8 +129,8 @@ impl Singleton { } } impl DefaultConstructible for Singleton { - fn default_constructor(this: &Ptr) { - field!((*this), hits).write(0); + fn default_constructor(this: Ptr) { + field!(this, hits).write(0); } } impl Default for Singleton { @@ -133,7 +138,7 @@ impl Default for Singleton { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -142,7 +147,7 @@ impl Default for Singleton { thread_local!( static s_15: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -189,14 +194,6 @@ fn main_0() -> i32 { assert!((({ Singleton::instance() }) == ({ Singleton::instance() }))); return 0; } -pub trait CtorImpl { - fn construct_1(&self, x: i32); -} -impl CtorImpl for Ptr { - fn construct_1(&self, mut x: i32) { - field!((*self), v).write(x); - } -} pub fn __cpp2rust_init_globals() { let _ = signature_3.with(|_| ()); let _ = single_4.with(|_| ()); diff --git a/tests/unit/out/refcount/huffman.rs b/tests/unit/out/refcount/huffman.rs index 48c9782dee..197ee125ce 100644 --- a/tests/unit/out/refcount/huffman.rs +++ b/tests/unit/out/refcount/huffman.rs @@ -30,6 +30,12 @@ pub struct MinHeapNode { #[byte_size(8)] pub right: Ptr, } +impl MinHeapNode { + pub fn IsLeaf(this: Ptr) -> bool { + return ((this.with(|__s| __s.left.clone())).is_null()) + && ((this.with(|__s| __s.right.clone())).is_null()); + } +} pub fn Swap_0(a: Ptr, b: Ptr) { let mut t: MinHeapNode = MinHeapNode { data: a.with(|__s| __s.data), @@ -69,13 +75,173 @@ pub struct MinHeap { #[byte_size(8)] pub alloc: Option>>, } +impl MinHeap { + pub fn Alloc(this: Ptr, mut data: i8, mut freq: i32) -> Ptr { + this.with(|__s| __s.alloc.clone()) + .decay() + .offset((this.with(|__s| __s.next) as usize)) + .write(MinHeapNode { + data: data, + freq: freq, + left: Ptr::::null(), + right: Ptr::::null(), + }); + return (this + .with(|__s| __s.alloc.clone()) + .decay() + .offset((field!(this, next).with_mut(|__v| __v.postfix_inc()) as usize))); + } + pub fn Heapify(this: Ptr, mut idx: i32) { + let mut smallest: i32 = idx; + let mut left: i32 = ((2 * idx) + 1); + let mut right: i32 = ((2 * idx) + 2); + if (left < this.with(|__s| __s.size)) + && ((this + .with(|__s| __s.arr.clone()) + .decay() + .offset((left as usize)) + .read()) + .with(|__s| __s.freq) + < (this + .with(|__s| __s.arr.clone()) + .decay() + .offset((smallest as usize)) + .read()) + .with(|__s| __s.freq)) + { + smallest = left; + } + if (right < this.with(|__s| __s.size)) + && ((this + .with(|__s| __s.arr.clone()) + .decay() + .offset((right as usize)) + .read()) + .with(|__s| __s.freq) + < (this + .with(|__s| __s.arr.clone()) + .decay() + .offset((smallest as usize)) + .read()) + .with(|__s| __s.freq)) + { + smallest = right; + } + if (smallest != idx) { + ({ + Swap_0( + (this + .with(|__s| __s.arr.clone()) + .decay() + .offset((smallest as usize)) + .read()), + (this + .with(|__s| __s.arr.clone()) + .decay() + .offset((idx as usize)) + .read()), + ) + }); + ({ MinHeap::Heapify(this.clone(), smallest) }); + } + } + pub fn ExtractMin(this: Ptr) -> Ptr { + let mut out: Ptr = (this + .with(|__s| __s.arr.clone()) + .decay() + .offset(0_usize) + .read()); + field!(this, size).with_mut(|__v| { + __v.prefix_dec(); + }); + this.with(|__s| __s.arr.clone()) + .decay() + .offset(0_usize) + .write( + (this + .with(|__s| __s.arr.clone()) + .decay() + .offset((this.with(|__s| __s.size) as usize)) + .read()), + ); + ({ MinHeap::Heapify(this.clone(), 0) }); + return out; + } + pub fn Insert(this: Ptr, mut node: Ptr) { + field!(this, size).with_mut(|__v| { + __v.prefix_inc(); + }); + let mut i: i32 = (this.with(|__s| __s.size) - 1); + 'loop_: while (i != 0) + && ({ node.with(|__s| __s.freq) } < { + (this + .with(|__s| __s.arr.clone()) + .decay() + .offset((((i - 1) / 2) as usize)) + .read()) + .with(|__s| __s.freq) + }) + { + this.with(|__s| __s.arr.clone()) + .decay() + .offset((i as usize)) + .write( + (this + .with(|__s| __s.arr.clone()) + .decay() + .offset((((i - 1) / 2) as usize)) + .read()), + ); + i = ((i - 1) / 2); + } + this.with(|__s| __s.arr.clone()) + .decay() + .offset((i as usize)) + .write((node).clone()); + } + pub fn Build( + this: Ptr, + data: Ptr>>>, + freq: Ptr>>>, + mut n: i32, + ) { + { + let mut i: i32 = 0; + 'loop_: while (i < n) { + 'for_body: { + let __rhs = ({ + MinHeap::Alloc( + this.clone(), + (({ (*data.upgrade().deref()).decay().offset((i as usize)) }).read()), + (({ (*freq.upgrade().deref()).decay().offset((i as usize)) }).read()), + ) + }); + this.with(|__s| __s.arr.clone()) + .decay() + .offset((field!(this, size).with_mut(|__v| __v.postfix_inc()) as usize)) + .write(__rhs); + } + i.prefix_inc(); + } + } + { + let mut i: i32 = ((this.with(|__s| __s.size) - 2) / 2); + 'loop_: while (i >= 0) { + 'for_body: { + ({ MinHeap::Heapify(this.clone(), i) }); + } + i.prefix_dec(); + } + } + } +} impl DefaultConstructible for MinHeap { - fn default_constructor(this: &Ptr) { - field!((*this), size).write(0_i32); - field!((*this), capacity).write(0_i32); - field!((*this), arr).write(None); - field!((*this), next).write(0_i32); - field!((*this), alloc).write(None); + fn default_constructor(this: Ptr) { + field!(this, size).write(0_i32); + field!(this, capacity).write(0_i32); + field!(this, arr).write(None); + field!(this, next).write(0_i32); + field!(this, alloc).write(None); } } pub fn AllocMinHeap_1(mut capacity: i32) -> Option> { @@ -102,27 +268,20 @@ pub fn Huffman_2( mut size: i32, ) -> Option> { let mut minHeap: Option> = ({ AllocMinHeap_1(size) }); - ({ - MinHeapImpl::Build( - &(minHeap.as_pointer()), - (data).clone(), - (freq).clone(), - size, - ) - }); + ({ MinHeap::Build((minHeap.as_pointer()), (data).clone(), (freq).clone(), size) }); 'loop_: while (minHeap.as_pointer().with(|__s| (__s).size) != 1) { - let mut left: Ptr = ({ MinHeapImpl::ExtractMin(&(minHeap.as_pointer())) }); - let mut right: Ptr = ({ MinHeapImpl::ExtractMin(&(minHeap.as_pointer())) }); + let mut left: Ptr = ({ MinHeap::ExtractMin((minHeap.as_pointer())) }); + let mut right: Ptr = ({ MinHeap::ExtractMin((minHeap.as_pointer())) }); let mut top: Ptr = ({ - MinHeapImpl::Alloc( - &(minHeap.as_pointer()), + MinHeap::Alloc( + (minHeap.as_pointer()), ('$' as i8), ({ left.with(|__s| __s.freq) } + { right.with(|__s| __s.freq) }), ) }); field!(top, left).write((left).clone()); field!(top, right).write((right).clone()); - ({ MinHeapImpl::Insert(&(minHeap.as_pointer()), (top).clone()) }); + ({ MinHeap::Insert((minHeap.as_pointer()), (top).clone()) }); } return minHeap.take(); } @@ -210,7 +369,7 @@ pub fn CollectCodes_4( ) }); } - if ({ MinHeapNodeImpl::IsLeaf(&root) }) { + if ({ MinHeapNode::IsLeaf((root).clone()) }) { ({ CollectCode_3((arr).clone(), top, (out).clone(), (next).clone()) }); } } @@ -220,7 +379,7 @@ pub fn HuffmanCodes_5( mut size: i32, ) -> Option>> { let mut minHeap: Option> = ({ Huffman_2((data).clone(), (freq).clone(), size) }); - let mut root: Ptr = ({ MinHeapImpl::ExtractMin(&(minHeap.as_pointer())) }); + let mut root: Ptr = ({ MinHeap::ExtractMin((minHeap.as_pointer())) }); let arr: Value>>> = Rc::new(RefCell::new(Some(Rc::new(RefCell::new( (0..100_usize).map(|_| 0_i32).collect::>(), ))))); @@ -283,190 +442,4 @@ fn main_0() -> i32 { ); return 0; } -pub trait MinHeapImpl { - fn Alloc(&self, data: i8, freq: i32) -> Ptr; - fn Heapify(&self, idx: i32); - fn ExtractMin(&self) -> Ptr; - fn Insert(&self, node: Ptr); - fn Build( - &self, - data: Ptr>>>, - freq: Ptr>>>, - n: i32, - ); -} -impl MinHeapImpl for Ptr { - fn Alloc(&self, mut data: i8, mut freq: i32) -> Ptr { - (*self) - .with(|__s| __s.alloc.clone()) - .decay() - .offset(((*self).with(|__s| __s.next) as usize)) - .write(MinHeapNode { - data: data, - freq: freq, - left: Ptr::::null(), - right: Ptr::::null(), - }); - return ((*self) - .with(|__s| __s.alloc.clone()) - .decay() - .offset((field!((*self), next).with_mut(|__v| __v.postfix_inc()) as usize))); - } - fn Heapify(&self, mut idx: i32) { - let mut smallest: i32 = idx; - let mut left: i32 = ((2 * idx) + 1); - let mut right: i32 = ((2 * idx) + 2); - if (left < (*self).with(|__s| __s.size)) - && (((*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((left as usize)) - .read()) - .with(|__s| __s.freq) - < ((*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((smallest as usize)) - .read()) - .with(|__s| __s.freq)) - { - smallest = left; - } - if (right < (*self).with(|__s| __s.size)) - && (((*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((right as usize)) - .read()) - .with(|__s| __s.freq) - < ((*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((smallest as usize)) - .read()) - .with(|__s| __s.freq)) - { - smallest = right; - } - if (smallest != idx) { - ({ - Swap_0( - ((*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((smallest as usize)) - .read()), - ((*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((idx as usize)) - .read()), - ) - }); - ({ MinHeapImpl::Heapify(self, smallest) }); - } - } - fn ExtractMin(&self) -> Ptr { - let mut out: Ptr = ((*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset(0_usize) - .read()); - field!((*self), size).with_mut(|__v| { - __v.prefix_dec(); - }); - (*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset(0_usize) - .write( - ((*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset(((*self).with(|__s| __s.size) as usize)) - .read()), - ); - ({ MinHeapImpl::Heapify(self, 0) }); - return out; - } - fn Insert(&self, mut node: Ptr) { - field!((*self), size).with_mut(|__v| { - __v.prefix_inc(); - }); - let mut i: i32 = ((*self).with(|__s| __s.size) - 1); - 'loop_: while (i != 0) - && ({ node.with(|__s| __s.freq) } < { - ((*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((((i - 1) / 2) as usize)) - .read()) - .with(|__s| __s.freq) - }) - { - (*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((i as usize)) - .write( - ((*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((((i - 1) / 2) as usize)) - .read()), - ); - i = ((i - 1) / 2); - } - (*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((i as usize)) - .write((node).clone()); - } - fn Build( - &self, - data: Ptr>>>, - freq: Ptr>>>, - mut n: i32, - ) { - { - let mut i: i32 = 0; - 'loop_: while (i < n) { - 'for_body: { - let __rhs = ({ - MinHeapImpl::Alloc( - self, - (({ (*data.upgrade().deref()).decay().offset((i as usize)) }).read()), - (({ (*freq.upgrade().deref()).decay().offset((i as usize)) }).read()), - ) - }); - (*self) - .with(|__s| __s.arr.clone()) - .decay() - .offset((field!((*self), size).with_mut(|__v| __v.postfix_inc()) as usize)) - .write(__rhs); - } - i.prefix_inc(); - } - } - { - let mut i: i32 = (((*self).with(|__s| __s.size) - 2) / 2); - 'loop_: while (i >= 0) { - 'for_body: { - ({ MinHeapImpl::Heapify(self, i) }); - } - i.prefix_dec(); - } - } - } -} -pub trait MinHeapNodeImpl { - fn IsLeaf(&self) -> bool; -} -impl MinHeapNodeImpl for Ptr { - fn IsLeaf(&self) -> bool { - return (((*self).with(|__s| __s.left.clone())).is_null()) - && (((*self).with(|__s| __s.right.clone())).is_null()); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/immutable-deref-on-func-call.rs b/tests/unit/out/refcount/immutable-deref-on-func-call.rs index 32f82f427e..973cb5d533 100644 --- a/tests/unit/out/refcount/immutable-deref-on-func-call.rs +++ b/tests/unit/out/refcount/immutable-deref-on-func-call.rs @@ -23,6 +23,11 @@ pub struct Item { #[offset(0)] pub value: i32, } +impl Item { + pub fn foo(this: Ptr, mut other: Ptr) { + field!(other, value).write(10); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -35,19 +40,11 @@ fn main_0() -> i32 { ); field!(elem!(arr, 0), value).write(1); field!(elem!(arr, 1), value).write(2); - ({ ItemImpl::foo(&arr.offset((0) as isize), (arr.offset((1) as isize))) }); + ({ Item::foo(arr.offset((0) as isize), (arr.offset((1) as isize))) }); let mut result: i32 = (elem!(arr, 0).with(|__s| __s.value) + elem!(arr, 1).with(|__s| __s.value)); arr.delete(); assert!((result == 11)); return 0; } -pub trait ItemImpl { - fn foo(&self, other: Ptr); -} -impl ItemImpl for Ptr { - fn foo(&self, mut other: Ptr) { - field!(other, value).write(10); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/implicit_autoref.rs b/tests/unit/out/refcount/implicit_autoref.rs index a16f158f64..20f3787eb8 100644 --- a/tests/unit/out/refcount/implicit_autoref.rs +++ b/tests/unit/out/refcount/implicit_autoref.rs @@ -27,8 +27,8 @@ pub struct Holder { pub v: Vec, } impl DefaultConstructible for Holder { - fn default_constructor(this: &Ptr) { - field!((*this), v).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, v).write(Vec::new()); } } pub fn write_through_0(mut p: Ptr) { diff --git a/tests/unit/out/refcount/in_class_field_initializer.rs b/tests/unit/out/refcount/in_class_field_initializer.rs index 017aa4a510..e4c30a6732 100644 --- a/tests/unit/out/refcount/in_class_field_initializer.rs +++ b/tests/unit/out/refcount/in_class_field_initializer.rs @@ -15,9 +15,9 @@ pub struct Inner { pub y: i32, } impl DefaultConstructible for Inner { - fn default_constructor(this: &Ptr) { - field!((*this), x).write(3); - field!((*this), y).write(4); + fn default_constructor(this: Ptr) { + field!(this, x).write(3); + field!(this, y).write(4); } } impl Default for Inner { @@ -40,11 +40,11 @@ pub struct S { pub d: Inner, } impl DefaultConstructible for S { - fn default_constructor(this: &Ptr) { - field!((*this), a).write(1); - field!((*this), b).write(2_i8); - field!((*this), c).write(::default()); - DefaultConstructible::default_constructor(&field_ptr!(this, d)); + fn default_constructor(this: Ptr) { + field!(this, a).write(1); + field!(this, b).write(2_i8); + field!(this, c).write(::default()); + DefaultConstructible::default_constructor(field_ptr!(this, d)); } } impl Default for S { @@ -77,6 +77,12 @@ pub struct Boxed_int_ { #[offset(4)] pub tag: i32, } +impl Boxed_int_ { + pub fn construct(this: Ptr, mut x: i32, mut t: i32) { + field!(this, v).write(x); + field!(this, tag).write(t); + } +} impl Default for Boxed_int_ { fn default() -> Self { { ::zero_init() } @@ -99,13 +105,4 @@ fn main_0() -> i32 { assert!(({ (*boxed.borrow()).tag } == 9)); return 0; } -pub trait Boxed_int_Impl { - fn construct(&self, x: i32, t: i32); -} -impl Boxed_int_Impl for Ptr { - fn construct(&self, mut x: i32, mut t: i32) { - field!((*self), v).write(x); - field!((*self), tag).write(t); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/init_list.rs b/tests/unit/out/refcount/init_list.rs index a4e5bc0ee3..a1bf443709 100644 --- a/tests/unit/out/refcount/init_list.rs +++ b/tests/unit/out/refcount/init_list.rs @@ -35,9 +35,15 @@ pub struct Holder { #[byte_size(8)] pub p: Pair, } +impl Holder { + pub fn operator_assign_1(this: Ptr, o: Ptr) -> Ptr { + field!(this, p).write({ (*o.upgrade().deref()) }); + return (this).clone(); + } +} impl DefaultConstructible for Holder { - fn default_constructor(this: &Ptr) { - field!((*this), p).write(Pair { a: 0, b: 0 }); + fn default_constructor(this: Ptr) { + field!(this, p).write(Pair { a: 0, b: 0 }); } } impl Default for Holder { @@ -59,8 +65,8 @@ pub struct Seven { pub v: i32, } impl DefaultConstructible for Seven { - fn default_constructor(this: &Ptr) { - field!((*this), v).write(7); + fn default_constructor(this: Ptr) { + field!(this, v).write(7); } } impl Default for Seven { @@ -82,7 +88,7 @@ fn main_0() -> i32 { ({ f_0(Vec::from([1, 2, 3, 4])) }); let p: Value = Rc::new(RefCell::new(Pair { a: 1, b: 2 })); object!(h, Holder); - HolderImpl::operator_assign_1(&h.as_pointer(), p.as_pointer()); + Holder::operator_assign_1(h.as_pointer(), p.as_pointer()); assert!(({ (*h.borrow()).p.a } == 1) && ({ (*h.borrow()).p.b } == 2)); assert!((({ sum_1(p.as_pointer(),) }) == 3)); let mut sevens: [Seven; 4] = [::default(); 4]; @@ -97,13 +103,4 @@ fn main_0() -> i32 { } return 0; } -pub trait HolderImpl { - fn operator_assign_1(&self, o: Ptr) -> Ptr; -} -impl HolderImpl for Ptr { - fn operator_assign_1(&self, o: Ptr) -> Ptr { - field!((*self), p).write({ (*o.upgrade().deref()) }); - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/inline_container_fields.rs b/tests/unit/out/refcount/inline_container_fields.rs index 84cd94f751..dffd012142 100644 --- a/tests/unit/out/refcount/inline_container_fields.rs +++ b/tests/unit/out/refcount/inline_container_fields.rs @@ -32,10 +32,10 @@ pub struct Elem { pub coeffs: Vec, } impl DefaultConstructible for Elem { - fn default_constructor(this: &Ptr) { - field!((*this), id).write(0_i32); - field!((*this), hist).write((0..4).map(|_| 0_i32).collect::>()); - field!((*this), coeffs).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, id).write(0_i32); + field!(this, hist).write((0..4).map(|_| 0_i32).collect::>()); + field!(this, coeffs).write(Vec::new()); } } impl Default for Elem { @@ -82,18 +82,18 @@ pub struct State { pub rows: Vec>, } impl DefaultConstructible for State { - fn default_constructor(this: &Ptr) { - field!((*this), count).write(0_i32); - field!((*this), grid).write( + fn default_constructor(this: Ptr) { + field!(this, count).write(0_i32); + field!(this, grid).write( (0..2) .map(|_| (0..3).map(|_| 0_i32).collect::>()) .collect::]>>(), ); - field!((*this), arr).write(Box::<[i32]>::from(std::array::from_fn::<_, 3, _>(|_| { + field!(this, arr).write(Box::<[i32]>::from(std::array::from_fn::<_, 3, _>(|_| { 0_i32 }))); - field!((*this), elems).write(Vec::new()); - field!((*this), rows).write(Vec::new()); + field!(this, elems).write(Vec::new()); + field!(this, rows).write(Vec::new()); } } impl Default for State { @@ -189,36 +189,36 @@ pub struct Counted { pub v: i32, } impl DefaultConstructible for Counted { - fn default_constructor(this: &Ptr) { - field!((*this), v).write(0); + fn default_constructor(this: Ptr) { + field!(this, v).write(0); } } impl CopyConstructible for Counted { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); (*copies_2.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Counted { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(-1_i32); (*moves_3.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CopyAssignable for Counted { - fn copy_assign(this: &Ptr, o: Ptr) -> Ptr { - field!((*this), v).write(o.with(|__s| __s.v)); + fn copy_assign(this: Ptr, o: Ptr) -> Ptr { + field!(this, v).write(o.with(|__s| __s.v)); (*copy_assigns_4.with(Value::clone).borrow_mut()).prefix_inc(); - return (*this).clone(); + return (this).clone(); } } impl MoveAssignable for Counted { - fn move_assign(this: &Ptr, o: Ptr) -> Ptr { - field!((*this), v).write(o.with(|__s| __s.v)); + fn move_assign(this: Ptr, o: Ptr) -> Ptr { + field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(-1_i32); (*move_assigns_5.with(Value::clone).borrow_mut()).prefix_inc(); - return (*this).clone(); + return (this).clone(); } } impl Default for Counted { diff --git a/tests/unit/out/refcount/kruskal.rs b/tests/unit/out/refcount/kruskal.rs index c7bed88aaa..fb0bb5334d 100644 --- a/tests/unit/out/refcount/kruskal.rs +++ b/tests/unit/out/refcount/kruskal.rs @@ -125,11 +125,114 @@ pub struct DisjointSet { #[offset(16)] pub n: i32, } +impl DisjointSet { + pub fn makeSet(this: Ptr) { + { + let mut i: i32 = 0; + 'loop_: while (i < this.with(|__s| __s.n)) { + 'for_body: { + this.with(|__s| __s.parent.clone()) + .decay() + .offset((i as usize)) + .write(i); + this.with(|__s| __s.rank.clone()) + .decay() + .offset((i as usize)) + .write(1); + } + i.postfix_inc(); + } + } + } + pub fn find(this: Ptr, mut x: i32) -> i32 { + if ((this + .with(|__s| __s.parent.clone()) + .decay() + .offset((x as usize)) + .read()) + != x) + { + let __rhs = ({ + DisjointSet::find( + this.clone(), + (this + .with(|__s| __s.parent.clone()) + .decay() + .offset((x as usize)) + .read()), + ) + }); + this.with(|__s| __s.parent.clone()) + .decay() + .offset((x as usize)) + .write(__rhs); + } + return (this + .with(|__s| __s.parent.clone()) + .decay() + .offset((x as usize)) + .read()); + } + pub fn merge(this: Ptr, mut x: i32, mut y: i32) { + let mut xset: i32 = ({ DisjointSet::find(this.clone(), x) }); + let mut yset: i32 = ({ DisjointSet::find(this.clone(), y) }); + if (xset == yset) { + return; + } + if ((this + .with(|__s| __s.rank.clone()) + .decay() + .offset((xset as usize)) + .read()) + < (this + .with(|__s| __s.rank.clone()) + .decay() + .offset((yset as usize)) + .read())) + { + this.with(|__s| __s.parent.clone()) + .decay() + .offset((xset as usize)) + .write(yset); + } else if ((this + .with(|__s| __s.rank.clone()) + .decay() + .offset((xset as usize)) + .read()) + > (this + .with(|__s| __s.rank.clone()) + .decay() + .offset((yset as usize)) + .read())) + { + this.with(|__s| __s.parent.clone()) + .decay() + .offset((yset as usize)) + .write(xset); + } else { + this.with(|__s| __s.parent.clone()) + .decay() + .offset((yset as usize)) + .write(xset); + this.with(|__s| __s.rank.clone()) + .decay() + .offset((xset as usize)) + .write( + ((this + .with(|__s| __s.rank.clone()) + .decay() + .offset((xset as usize)) + .read()) + + 1), + ); + } + } +} impl DefaultConstructible for DisjointSet { - fn default_constructor(this: &Ptr) { - field!((*this), rank).write(None); - field!((*this), parent).write(None); - field!((*this), n).write(0_i32); + fn default_constructor(this: Ptr) { + field!(this, rank).write(None); + field!(this, parent).write(None); + field!(this, n).write(0_i32); } } #[derive( @@ -147,10 +250,10 @@ pub struct Graph { pub E: i32, } impl DefaultConstructible for Graph { - fn default_constructor(this: &Ptr) { - field!((*this), edges).write(None); - field!((*this), V).write(0_i32); - field!((*this), E).write(0_i32); + fn default_constructor(this: Ptr) { + field!(this, edges).write(None); + field!(this, V).write(0_i32); + field!(this, E).write(0_i32); } } pub fn MSTKruskal_2(graph: Ptr) -> f64 { @@ -168,7 +271,7 @@ pub fn MSTKruskal_2(graph: Ptr) -> f64 { ))), n: graph.with(|__s| __s.V), })); - ({ DisjointSetImpl::makeSet(&set.as_pointer()) }); + ({ DisjointSet::makeSet(set.as_pointer()) }); let mut total_weight: f64 = 0_f64; { let mut i: i32 = 0; @@ -189,10 +292,10 @@ pub fn MSTKruskal_2(graph: Ptr) -> f64 { .decay() .offset((i as usize)) .with(|__s| __s.weight); - if (({ DisjointSetImpl::find(&set.as_pointer(), x) }) - != ({ DisjointSetImpl::find(&set.as_pointer(), y) })) + if (({ DisjointSet::find(set.as_pointer(), x) }) + != ({ DisjointSet::find(set.as_pointer(), y) })) { - ({ DisjointSetImpl::merge(&set.as_pointer(), x, y) }); + ({ DisjointSet::merge(set.as_pointer(), x, y) }); total_weight += w; } } @@ -261,119 +364,4 @@ fn main_0() -> i32 { assert!((total_weight == 19_f64)); return 0; } -pub trait DisjointSetImpl { - fn makeSet(&self); - fn find(&self, x: i32) -> i32; - fn merge(&self, x: i32, y: i32); -} -impl DisjointSetImpl for Ptr { - fn makeSet(&self) { - { - let mut i: i32 = 0; - 'loop_: while (i < (*self).with(|__s| __s.n)) { - 'for_body: { - (*self) - .with(|__s| __s.parent.clone()) - .decay() - .offset((i as usize)) - .write(i); - (*self) - .with(|__s| __s.rank.clone()) - .decay() - .offset((i as usize)) - .write(1); - } - i.postfix_inc(); - } - } - } - fn find(&self, mut x: i32) -> i32 { - if (((*self) - .with(|__s| __s.parent.clone()) - .decay() - .offset((x as usize)) - .read()) - != x) - { - let __rhs = ({ - DisjointSetImpl::find( - self, - ((*self) - .with(|__s| __s.parent.clone()) - .decay() - .offset((x as usize)) - .read()), - ) - }); - (*self) - .with(|__s| __s.parent.clone()) - .decay() - .offset((x as usize)) - .write(__rhs); - } - return ((*self) - .with(|__s| __s.parent.clone()) - .decay() - .offset((x as usize)) - .read()); - } - fn merge(&self, mut x: i32, mut y: i32) { - let mut xset: i32 = ({ DisjointSetImpl::find(self, x) }); - let mut yset: i32 = ({ DisjointSetImpl::find(self, y) }); - if (xset == yset) { - return; - } - if (((*self) - .with(|__s| __s.rank.clone()) - .decay() - .offset((xset as usize)) - .read()) - < ((*self) - .with(|__s| __s.rank.clone()) - .decay() - .offset((yset as usize)) - .read())) - { - (*self) - .with(|__s| __s.parent.clone()) - .decay() - .offset((xset as usize)) - .write(yset); - } else if (((*self) - .with(|__s| __s.rank.clone()) - .decay() - .offset((xset as usize)) - .read()) - > ((*self) - .with(|__s| __s.rank.clone()) - .decay() - .offset((yset as usize)) - .read())) - { - (*self) - .with(|__s| __s.parent.clone()) - .decay() - .offset((yset as usize)) - .write(xset); - } else { - (*self) - .with(|__s| __s.parent.clone()) - .decay() - .offset((yset as usize)) - .write(xset); - (*self) - .with(|__s| __s.rank.clone()) - .decay() - .offset((xset as usize)) - .write( - (((*self) - .with(|__s| __s.rank.clone()) - .decay() - .offset((xset as usize)) - .read()) - + 1), - ); - } - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/lambda_as_field.rs b/tests/unit/out/refcount/lambda_as_field.rs index b7a28c83e7..faf000ed8c 100644 --- a/tests/unit/out/refcount/lambda_as_field.rs +++ b/tests/unit/out/refcount/lambda_as_field.rs @@ -26,8 +26,8 @@ pub struct Guard__lambda_at_lambda_as_field_cpp_34_13__ { pub f: FnPtr, } impl Destructible for Guard__lambda_at_lambda_as_field_cpp_34_13__ { - fn destroy(this: &Ptr) { - ({ (*(*this).upgrade().deref()).f.call() }); + fn destroy(this: Ptr) { + ({ (*this.upgrade().deref()).f.call() }); } } #[derive( @@ -40,8 +40,8 @@ pub struct Guard__lambda_at_lambda_as_field_cpp_45_13__ { pub f: FnPtr, } impl Destructible for Guard__lambda_at_lambda_as_field_cpp_45_13__ { - fn destroy(this: &Ptr) { - ({ (*(*this).upgrade().deref()).f.call() }); + fn destroy(this: Ptr) { + ({ (*this.upgrade().deref()).f.call() }); } } #[derive( @@ -62,6 +62,12 @@ pub struct Holder__lambda_at_lambda_as_field_cpp_39_12__ { #[offset(4)] pub calls: i32, } +impl Holder__lambda_at_lambda_as_field_cpp_39_12__ { + pub fn call(this: Ptr, mut x: i32) -> i32 { + field!(this, calls).with_mut(|__v| __v.postfix_inc()); + return ({ (*this.upgrade().deref()).f.call(x) }); + } +} impl Default for Holder__lambda_at_lambda_as_field_cpp_39_12__ { fn default() -> Self { { @@ -95,6 +101,12 @@ pub struct Holder__lambda_at_lambda_as_field_cpp_51_12__ { #[offset(4)] pub calls: i32, } +impl Holder__lambda_at_lambda_as_field_cpp_51_12__ { + pub fn call(this: Ptr, mut x: i32) -> i32 { + field!(this, calls).with_mut(|__v| __v.postfix_inc()); + return ({ (*this.upgrade().deref()).f.call(x) }); + } +} #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, DefaultInitializable)] #[cpp_from(FnPtr i32 > , construct, value)] #[byte_size(8)] @@ -105,10 +117,17 @@ pub struct Moving__lambda_at_lambda_as_field_cpp_64_12__ { #[offset(4)] pub moves: i32, } +impl Moving__lambda_at_lambda_as_field_cpp_64_12__ { + pub fn construct(this: Ptr, f: FnPtr i32>) { + let f: Value i32>> = Rc::new(RefCell::new(f)); + field!(this, f).write((*f.borrow()).copy_from()); + field!(this, moves).write(0); + } +} impl MoveConstructible for Moving__lambda_at_lambda_as_field_cpp_64_12__ { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), f).write((*o.upgrade().deref()).f.move_from()); - field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, f).write((*o.upgrade().deref()).f.move_from()); + field!(this, moves).write((o.with(|__s| __s.moves) + 1)); } } impl Default for Moving__lambda_at_lambda_as_field_cpp_64_12__ { @@ -156,7 +175,7 @@ fn main_0() -> i32 { }), })); let _dtor_g = - std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!((count_2.with(|rc| *rc.borrow()) == 0)); } assert!((count_2.with(|rc| *rc.borrow()) == 1)); @@ -170,9 +189,7 @@ fn main_0() -> i32 { calls: 0, }, )); - assert!( - (({ Holder__lambda_at_lambda_as_field_cpp_39_12__Impl::call(&n.as_pointer(), 2,) }) == 3) - ); + assert!((({ Holder__lambda_at_lambda_as_field_cpp_39_12__::call(n.as_pointer(), 2,) }) == 3)); assert!(({ (*n.borrow()).calls } == 1)); let cleaned: Value = Rc::new(RefCell::new(0)); { @@ -188,7 +205,7 @@ fn main_0() -> i32 { ), })); let _dtor_g = - std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!(({ ((*cleaned.borrow()) == 0) })); } assert!(({ ((*cleaned.borrow()) == 1) })); @@ -207,12 +224,8 @@ fn main_0() -> i32 { }, )); (*factor.borrow_mut()) = 100; - assert!( - (({ Holder__lambda_at_lambda_as_field_cpp_51_12__Impl::call(&h.as_pointer(), 2,) }) == 6) - ); - assert!( - (({ Holder__lambda_at_lambda_as_field_cpp_51_12__Impl::call(&h.as_pointer(), 5,) }) == 15) - ); + assert!((({ Holder__lambda_at_lambda_as_field_cpp_51_12__::call(h.as_pointer(), 2,) }) == 6)); + assert!((({ Holder__lambda_at_lambda_as_field_cpp_51_12__::call(h.as_pointer(), 5,) }) == 15)); assert!(({ (*h.borrow()).calls } == 2)); let w: Value i32>> = Rc::new(RefCell::new( ({ @@ -252,40 +265,6 @@ fn main_0() -> i32 { assert!(({ (*m2.borrow()).moves } == 1)); return 0; } -pub trait Holder__lambda_at_lambda_as_field_cpp_39_12__Impl { - fn call(&self, x: i32) -> i32; -} -impl Holder__lambda_at_lambda_as_field_cpp_39_12__Impl - for Ptr -{ - fn call(&self, mut x: i32) -> i32 { - field!((*self), calls).with_mut(|__v| __v.postfix_inc()); - return ({ (*(*self).upgrade().deref()).f.call(x) }); - } -} -pub trait Holder__lambda_at_lambda_as_field_cpp_51_12__Impl { - fn call(&self, x: i32) -> i32; -} -impl Holder__lambda_at_lambda_as_field_cpp_51_12__Impl - for Ptr -{ - fn call(&self, mut x: i32) -> i32 { - field!((*self), calls).with_mut(|__v| __v.postfix_inc()); - return ({ (*(*self).upgrade().deref()).f.call(x) }); - } -} -pub trait Moving__lambda_at_lambda_as_field_cpp_64_12__Impl { - fn construct(&self, f: FnPtr i32>); -} -impl Moving__lambda_at_lambda_as_field_cpp_64_12__Impl - for Ptr -{ - fn construct(&self, f: FnPtr i32>) { - let f: Value i32>> = Rc::new(RefCell::new(f)); - field!((*self), f).write((*f.borrow()).copy_from()); - field!((*self), moves).write(0); - } -} pub fn __cpp2rust_init_globals() { let _ = count_2.with(|_| ()); } diff --git a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs index 2010a3a63b..8712119863 100644 --- a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs @@ -15,21 +15,21 @@ pub struct Counted { pub moves: i32, } impl DefaultConstructible for Counted { - fn default_constructor(this: &Ptr) { - field!((*this), copies).write(0); - field!((*this), moves).write(0); + fn default_constructor(this: Ptr) { + field!(this, copies).write(0); + field!(this, moves).write(0); } } impl CopyConstructible for Counted { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); - field!((*this), moves).write(o.with(|__s| __s.moves)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, copies).write((o.with(|__s| __s.copies) + 1)); + field!(this, moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for Counted { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), copies).write(o.with(|__s| __s.copies)); - field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, copies).write(o.with(|__s| __s.copies)); + field!(this, moves).write((o.with(|__s| __s.moves) + 1)); } } impl Default for Counted { @@ -37,7 +37,7 @@ impl Default for Counted { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -50,16 +50,16 @@ thread_local!( #[byte_size(1)] pub struct Dropped {} impl DefaultConstructible for Dropped { - fn default_constructor(this: &Ptr) {} + fn default_constructor(this: Ptr) {} } impl CopyConstructible for Dropped { - fn copy_constructor(this: &Ptr, _a0: Ptr) {} + fn copy_constructor(this: Ptr, _a0: Ptr) {} } impl MoveConstructible for Dropped { - fn move_constructor(this: &Ptr, _a0: Ptr) {} + fn move_constructor(this: Ptr, _a0: Ptr) {} } impl Destructible for Dropped { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { (*drops_0.with(Value::clone).borrow_mut()).postfix_inc(); } } @@ -73,7 +73,7 @@ fn main_0() -> i32 { { let c: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), c.as_pointer()); + ConstructFrom::construct_from(__v.as_pointer(), c.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -95,12 +95,12 @@ fn main_0() -> i32 { { let c: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), c.as_pointer()); + ConstructFrom::construct_from(__v.as_pointer(), c.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, |this: Ptr| { - ConstructFrom::construct_from(&this, c.as_pointer()); + ConstructFrom::construct_from(this.clone(), c.as_pointer()); return; } ) @@ -114,7 +114,7 @@ fn main_0() -> i32 { let arr: Value> = Rc::new(RefCell::new(Box::new( std::array::from_fn::<_, 2, _>(|_| { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }), ))); @@ -123,7 +123,7 @@ fn main_0() -> i32 { let arr: Value> = Rc::new(RefCell::new(Box::new( std::array::from_fn::<_, 2, _>(|__i: usize| { let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), arr.decay().offset(__i)); + ConstructFrom::construct_from(__v.as_pointer(), arr.decay().offset(__i)); Rc::try_unwrap(__v).ok().unwrap().into_inner() }), ))); @@ -144,17 +144,17 @@ fn main_0() -> i32 { { let d: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, || {} ))); let _dtor_m = - std::mem::DropGuard::new(m.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(m.clone(), |__p| Destructible::destroy(__p.as_pointer())); let m2: Value> = Rc::new(RefCell::new((*m.borrow()).move_from())); let _dtor_m2 = - std::mem::DropGuard::new(m2.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(m2.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((drops_0.with(|rc| *rc.borrow()) == 2)); { @@ -162,17 +162,17 @@ fn main_0() -> i32 { { let d: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, || {} ))); let _dtor_k = - std::mem::DropGuard::new(k.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(k.clone(), |__p| Destructible::destroy(__p.as_pointer())); let k2: Value> = Rc::new(RefCell::new((*k.borrow()).copy_from())); let _dtor_k2 = - std::mem::DropGuard::new(k2.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(k2.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((drops_0.with(|rc| *rc.borrow()) == 4)); { @@ -180,15 +180,14 @@ fn main_0() -> i32 { { let d: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, || {} ))); - let _dtor_inner = std::mem::DropGuard::new(inner.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) - }); + let _dtor_inner = + std::mem::DropGuard::new(inner.clone(), |__p| Destructible::destroy(__p.as_pointer())); let outer: Value> = Rc::new(RefCell::new(lambda!( { let inner: Value> = @@ -196,9 +195,8 @@ fn main_0() -> i32 { }, || {} ))); - let _dtor_outer = std::mem::DropGuard::new(outer.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) - }); + let _dtor_outer = + std::mem::DropGuard::new(outer.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((drops_0.with(|rc| *rc.borrow()) == 6)); return 0; diff --git a/tests/unit/out/refcount/lambda_capture_star_this.rs b/tests/unit/out/refcount/lambda_capture_star_this.rs index 35f4e7de35..638e8b333f 100644 --- a/tests/unit/out/refcount/lambda_capture_star_this.rs +++ b/tests/unit/out/refcount/lambda_capture_star_this.rs @@ -23,34 +23,14 @@ pub struct S { #[offset(0)] pub n: i32, } -pub fn main() { - __cpp2rust_init_globals(); - libcc2rs::cpp2rust_exit(main_0()); -} -fn main_0() -> i32 { - let s: Value = Rc::new(RefCell::new(S { n: 1 })); - assert!((({ SImpl::modify_copy(&s.as_pointer(),) }) == 1101)); - assert!(({ (*s.borrow()).n } == 1)); - assert!((({ SImpl::snapshot(&s.as_pointer(),) }) == 2)); - assert!(({ (*s.borrow()).n } == 99)); - assert!((({ SImpl::mixed(&s.as_pointer(), 1,) }) == 100)); - assert!(({ (*s.borrow()).n } == 0)); - return 0; -} -pub trait SImpl { - fn twice(&self) -> i32; - fn modify_copy(&self) -> i32; - fn snapshot(&self) -> i32; - fn mixed(&self, k: i32) -> i32; -} -impl SImpl for Ptr { - fn twice(&self) -> i32 { - return ((*self).with(|__s| __s.n) * 2); +impl S { + pub fn twice(this: Ptr) -> i32 { + return (this.with(|__s| __s.n) * 2); } - fn modify_copy(&self) -> i32 { + pub fn modify_copy(this: Ptr) -> i32 { let f: Value i32>> = Rc::new(RefCell::new(lambda!( { - let this_: Value = Rc::new(RefCell::new((*(*self).upgrade().deref()))); + let this_: Value = Rc::new(RefCell::new((*this.upgrade().deref()))); }, || -> i32 { { @@ -60,33 +40,47 @@ impl SImpl for Ptr { } ))); let mut r: i32 = ({ (*f.borrow()).call() }).clone(); - return ((r * 100) + (*self).with(|__s| __s.n)); + return ((r * 100) + this.with(|__s| __s.n)); } - fn snapshot(&self) -> i32 { + pub fn snapshot(this: Ptr) -> i32 { let f: Value i32>> = Rc::new(RefCell::new(lambda!( { - let this_: Value = Rc::new(RefCell::new((*(*self).upgrade().deref()))); + let this_: Value = Rc::new(RefCell::new((*this.upgrade().deref()))); }, || -> i32 { - return ({ SImpl::twice(&this_.as_pointer()) }); + return ({ S::twice(this_.as_pointer()) }); } ))); - field!((*self), n).write(99); + field!(this, n).write(99); return ({ (*f.borrow()).call() }).clone(); } - fn mixed(&self, k: i32) -> i32 { + pub fn mixed(this: Ptr, k: i32) -> i32 { let k: Value = Rc::new(RefCell::new(k)); let f: Value i32>> = Rc::new(RefCell::new(lambda!( { - let this_: Value = Rc::new(RefCell::new((*(*self).upgrade().deref()))); + let this_: Value = Rc::new(RefCell::new((*this.upgrade().deref()))); let k: Value = Rc::new(RefCell::new((*k.borrow()))); }, || -> i32 { return (this_.as_pointer().with(|__s| __s.n) + (*k.borrow())); } ))); - field!((*self), n).write(0); + field!(this, n).write(0); return ({ (*f.borrow()).call() }).clone(); } } +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + let s: Value = Rc::new(RefCell::new(S { n: 1 })); + assert!((({ S::modify_copy(s.as_pointer(),) }) == 1101)); + assert!(({ (*s.borrow()).n } == 1)); + assert!((({ S::snapshot(s.as_pointer(),) }) == 2)); + assert!(({ (*s.borrow()).n } == 99)); + assert!((({ S::mixed(s.as_pointer(), 1,) }) == 100)); + assert!(({ (*s.borrow()).n } == 0)); + return 0; +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/lambda_capture_this.rs b/tests/unit/out/refcount/lambda_capture_this.rs index 48cac3a0f0..cb10482d9f 100644 --- a/tests/unit/out/refcount/lambda_capture_this.rs +++ b/tests/unit/out/refcount/lambda_capture_this.rs @@ -25,39 +25,19 @@ pub struct S { #[offset(4)] pub step: i32, } -pub fn main() { - __cpp2rust_init_globals(); - libcc2rs::cpp2rust_exit(main_0()); -} -fn main_0() -> i32 { - let s: Value = Rc::new(RefCell::new(S { n: 0, step: 2 })); - ({ SImpl::bump(&s.as_pointer(), 3) }); - assert!(({ (*s.borrow()).n } == 6)); - ({ SImpl::bump_via_method(&s.as_pointer(), 4) }); - assert!(({ (*s.borrow()).n } == 10)); - assert!((({ SImpl::read_scaled(&s.as_pointer(),) }) == 20)); - return 0; -} -pub trait SImpl { - fn add(&self, k: i32); - fn scaled(&self) -> i32; - fn bump(&self, by: i32); - fn bump_via_method(&self, by: i32); - fn read_scaled(&self) -> i32; -} -impl SImpl for Ptr { - fn add(&self, mut k: i32) { +impl S { + pub fn add(this: Ptr, mut k: i32) { { - field!((*self), n).with_mut(|__v| *__v = *__v + k) + field!(this, n).with_mut(|__v| *__v = *__v + k) }; } - fn scaled(&self) -> i32 { - return ((*self).with(|__s| __s.n) * (*self).with(|__s| __s.step)); + pub fn scaled(this: Ptr) -> i32 { + return (this.with(|__s| __s.n) * this.with(|__s| __s.step)); } - fn bump(&self, mut by: i32) { + pub fn bump(this: Ptr, mut by: i32) { let inc: Value> = Rc::new(RefCell::new(lambda!( { - let this_: Value> = Rc::new(RefCell::new((*self).clone())); + let this_: Value> = Rc::new(RefCell::new((this).clone())); }, |mut k: i32| { { @@ -68,27 +48,40 @@ impl SImpl for Ptr { ({ (*inc.borrow()).call(by) }); ({ (*inc.borrow()).call(by) }); } - fn bump_via_method(&self, mut by: i32) { + pub fn bump_via_method(this: Ptr, mut by: i32) { let inc: Value> = Rc::new(RefCell::new(lambda!( { - let this_: Value> = Rc::new(RefCell::new((*self).clone())); + let this_: Value> = Rc::new(RefCell::new((this).clone())); }, |mut k: i32| { - ({ SImpl::add(&(*this_.borrow()), k) }); + ({ S::add({ (*this_.borrow()).clone() }, k) }); } ))); ({ (*inc.borrow()).call(by) }); } - fn read_scaled(&self) -> i32 { + pub fn read_scaled(this: Ptr) -> i32 { let get: Value i32>> = Rc::new(RefCell::new(lambda!( { - let this_: Value> = Rc::new(RefCell::new((*self).clone())); + let this_: Value> = Rc::new(RefCell::new((this).clone())); }, || -> i32 { - return ({ SImpl::scaled(&(*this_.borrow())) }); + return ({ S::scaled({ (*this_.borrow()).clone() }) }); } ))); return ({ (*get.borrow()).call() }).clone(); } } +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + let s: Value = Rc::new(RefCell::new(S { n: 0, step: 2 })); + ({ S::bump(s.as_pointer(), 3) }); + assert!(({ (*s.borrow()).n } == 6)); + ({ S::bump_via_method(s.as_pointer(), 4) }); + assert!(({ (*s.borrow()).n } == 10)); + assert!((({ S::read_scaled(s.as_pointer(),) }) == 20)); + return 0; +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/lambda_decltype_type.rs b/tests/unit/out/refcount/lambda_decltype_type.rs index 1add8e940a..9a02d69619 100644 --- a/tests/unit/out/refcount/lambda_decltype_type.rs +++ b/tests/unit/out/refcount/lambda_decltype_type.rs @@ -19,11 +19,28 @@ pub struct Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { #[byte_size(1)] pub cmp: FnPtr bool>, } +impl Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { + pub fn insert(this: Ptr, mut v: i32) { + let mut i: i32 = this.with(|__s| __s.size); + 'loop_: while (i > 0) + && ({ + (*this.upgrade().deref()) + .cmp + .call(v, (array_elem!(this, items, (i - 1)).read())) + }) + { + array_elem!(this, items, i).write((array_elem!(this, items, (i - 1)).read())); + i.postfix_dec(); + } + array_elem!(this, items, i).write(v); + field!(this, size).with_mut(|__v| __v.postfix_inc()); + } +} impl DefaultConstructible for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { - fn default_constructor(this: &Ptr) { - field!((*this), items).write((0..4).map(|_| 0_i32).collect::>()); - field!((*this), size).write(0); - field!((*this), cmp).write(FnPtr:: bool>::new( + fn default_constructor(this: Ptr) { + field!(this, items).write((0..4).map(|_| 0_i32).collect::>()); + field!(this, size).write(0); + field!(this, cmp).write(FnPtr:: bool>::new( |mut a: i32, mut b: i32| -> bool { { return (a > b); @@ -60,11 +77,28 @@ pub struct Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { #[byte_size(1)] pub cmp: FnPtr bool>, } +impl Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { + pub fn insert(this: Ptr, mut v: i32) { + let mut i: i32 = this.with(|__s| __s.size); + 'loop_: while (i > 0) + && ({ + (*this.upgrade().deref()) + .cmp + .call(v, (array_elem!(this, items, (i - 1)).read())) + }) + { + array_elem!(this, items, i).write((array_elem!(this, items, (i - 1)).read())); + i.postfix_dec(); + } + array_elem!(this, items, i).write(v); + field!(this, size).with_mut(|__v| __v.postfix_inc()); + } +} impl DefaultConstructible for Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { - fn default_constructor(this: &Ptr) { - field!((*this), items).write((0..4).map(|_| 0_i32).collect::>()); - field!((*this), size).write(0); - field!((*this), cmp).write(FnPtr:: bool>::new( + fn default_constructor(this: Ptr) { + field!(this, items).write((0..4).map(|_| 0_i32).collect::>()); + field!(this, size).write(0); + field!(this, cmp).write(FnPtr:: bool>::new( |mut a: i32, mut b: i32| -> bool { { return (a < b); @@ -102,16 +136,16 @@ fn main_0() -> i32 { }, ))); object!(desc, Sorted__lambda_at_lambda_decltype_type_cpp_22_18__); - ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__Impl::insert(&desc.as_pointer(), 2) }); - ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__Impl::insert(&desc.as_pointer(), 7) }); - ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__Impl::insert(&desc.as_pointer(), 4) }); + ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(desc.as_pointer(), 2) }); + ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(desc.as_pointer(), 7) }); + ({ Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(desc.as_pointer(), 4) }); assert!(((array_elem!(desc.as_pointer(), items, 0).read()) == 7)); assert!(((array_elem!(desc.as_pointer(), items, 1).read()) == 4)); assert!(((array_elem!(desc.as_pointer(), items, 2).read()) == 2)); object!(asc, Sorted__lambda_at_lambda_decltype_type_cpp_19_23__); - ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__Impl::insert(&asc.as_pointer(), 2) }); - ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__Impl::insert(&asc.as_pointer(), 7) }); - ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__Impl::insert(&asc.as_pointer(), 4) }); + ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(asc.as_pointer(), 2) }); + ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(asc.as_pointer(), 7) }); + ({ Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(asc.as_pointer(), 4) }); assert!(((array_elem!(asc.as_pointer(), items, 0).read()) == 2)); assert!(((array_elem!(asc.as_pointer(), items, 1).read()) == 4)); assert!(((array_elem!(asc.as_pointer(), items, 2).read()) == 7)); @@ -146,48 +180,4 @@ fn main_0() -> i32 { assert!(({ (({ (*less.borrow()).call(1, 3,) }) as bool) })); return 0; } -pub trait Sorted__lambda_at_lambda_decltype_type_cpp_19_23__Impl { - fn insert(&self, v: i32); -} -impl Sorted__lambda_at_lambda_decltype_type_cpp_19_23__Impl - for Ptr -{ - fn insert(&self, mut v: i32) { - let mut i: i32 = (*self).with(|__s| __s.size); - 'loop_: while (i > 0) - && ({ - (*(*self).upgrade().deref()) - .cmp - .call(v, (array_elem!((*self), items, (i - 1)).read())) - }) - { - array_elem!((*self), items, i).write((array_elem!((*self), items, (i - 1)).read())); - i.postfix_dec(); - } - array_elem!((*self), items, i).write(v); - field!((*self), size).with_mut(|__v| __v.postfix_inc()); - } -} -pub trait Sorted__lambda_at_lambda_decltype_type_cpp_22_18__Impl { - fn insert(&self, v: i32); -} -impl Sorted__lambda_at_lambda_decltype_type_cpp_22_18__Impl - for Ptr -{ - fn insert(&self, mut v: i32) { - let mut i: i32 = (*self).with(|__s| __s.size); - 'loop_: while (i > 0) - && ({ - (*(*self).upgrade().deref()) - .cmp - .call(v, (array_elem!((*self), items, (i - 1)).read())) - }) - { - array_elem!((*self), items, i).write((array_elem!((*self), items, (i - 1)).read())); - i.postfix_dec(); - } - array_elem!((*self), items, i).write(v); - field!((*self), size).with_mut(|__v| __v.postfix_inc()); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/lambda_immediate_init.rs b/tests/unit/out/refcount/lambda_immediate_init.rs index d5fe2f87bd..2ced1e422c 100644 --- a/tests/unit/out/refcount/lambda_immediate_init.rs +++ b/tests/unit/out/refcount/lambda_immediate_init.rs @@ -18,9 +18,9 @@ pub struct S { pub k: i32, } impl DefaultConstructible for S { - fn default_constructor(this: &Ptr) { - field!((*this), j).write(10); - field!((*this), k).write( + fn default_constructor(this: Ptr) { + field!(this, j).write(10); + field!(this, k).write( (({ FnPtr:: i32>::new(|| -> i32 { { diff --git a/tests/unit/out/refcount/lambda_move_only_capture.rs b/tests/unit/out/refcount/lambda_move_only_capture.rs index ebdd72b00f..12c53fdf5d 100644 --- a/tests/unit/out/refcount/lambda_move_only_capture.rs +++ b/tests/unit/out/refcount/lambda_move_only_capture.rs @@ -14,15 +14,34 @@ pub struct Owner { #[byte_size(8)] pub p: Ptr, } +impl Owner { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, p).write(Ptr::alloc(v)); + } + pub fn take(this: Ptr) -> FnPtr i32> { + return lambda!( + { + let self_: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ConstructFrom::construct_from(__v.as_pointer(), Moved((this).clone())); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + }, + || -> i32 { + return ({ (*self_.borrow()).p.clone() }.read()); + } + ); + } +} impl MoveConstructible for Owner { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), p).write(o.with(|__s| __s.p.clone())); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, p).write(o.with(|__s| __s.p.clone())); field!(o, p).write(Ptr::::null()); } } impl Destructible for Owner { - fn destroy(this: &Ptr) { - (*this).with(|__s| __s.p.clone()).delete(); + fn destroy(this: Ptr) { + this.with(|__s| __s.p.clone()).delete(); } } pub fn main() { @@ -35,7 +54,7 @@ fn main_0() -> i32 { { let h: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), Moved(o.as_pointer())); + ConstructFrom::construct_from(__v.as_pointer(), Moved(o.as_pointer())); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, @@ -44,19 +63,19 @@ fn main_0() -> i32 { } ))); let _dtor_f = - std::mem::DropGuard::new(f.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(f.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!(({ (*o.borrow()).p.clone() }).is_null()); assert!(({ (({ (*f.borrow()).call() }) == 5) })); let g: Value i32>> = Rc::new(RefCell::new((*f.borrow()).move_from())); let _dtor_g = - std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!(({ (({ (*g.borrow()).call() }) == 5) })); let total: Value = Rc::new(RefCell::new(0)); let consume: Value> = Rc::new(RefCell::new(lambda!( { let h: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - OwnerImpl::construct(&__v.as_pointer(), 7); + Owner::construct(__v.as_pointer(), 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); let total: Ptr = total.as_pointer(); @@ -70,41 +89,17 @@ fn main_0() -> i32 { } ))); let _dtor_consume = std::mem::DropGuard::new(consume.clone(), |__p| { - Destructible::destroy(&__p.as_pointer()) + Destructible::destroy(__p.as_pointer()) }); ({ (*consume.borrow()).call() }); ({ (*consume.borrow()).call() }); assert!(({ ((*total.borrow()) == 7) })); object!(o2, Owner(9)); - let t: Value i32>> = - Rc::new(RefCell::new(({ OwnerImpl::take(&o2.as_pointer()) }))); + let t: Value i32>> = Rc::new(RefCell::new(({ Owner::take(o2.as_pointer()) }))); let _dtor_t = - std::mem::DropGuard::new(t.clone(), |__p| Destructible::destroy(&__p.as_pointer())); + std::mem::DropGuard::new(t.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!(({ (*o2.borrow()).p.clone() }).is_null()); assert!(({ (({ (*t.borrow()).call() }) == 9) })); return 0; } -pub trait OwnerImpl { - fn construct(&self, v: i32); - fn take(&self) -> FnPtr i32>; -} -impl OwnerImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), p).write(Ptr::alloc(v)); - } - fn take(&self) -> FnPtr i32> { - return lambda!( - { - let self_: Value = Rc::new(RefCell::new({ - let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), Moved((*self).clone())); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - })); - }, - || -> i32 { - return ({ (*self_.borrow()).p.clone() }.read()); - } - ); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/lambda_nested.rs b/tests/unit/out/refcount/lambda_nested.rs index 19cb26cbdb..2a9fadde0a 100644 --- a/tests/unit/out/refcount/lambda_nested.rs +++ b/tests/unit/out/refcount/lambda_nested.rs @@ -23,6 +23,29 @@ pub struct S { #[offset(0)] pub v: i32, } +impl S { + pub fn nested_this(this: Ptr) -> i32 { + let outer: Value i32>> = Rc::new(RefCell::new(lambda!( + { + let this_: Value> = Rc::new(RefCell::new((this).clone())); + }, + |y: i32| -> i32 { + let y: Value = Rc::new(RefCell::new(y)); + let inner: Value i32>> = Rc::new(RefCell::new(lambda!( + { + let this_: Value> = Rc::new(RefCell::new((*this_.borrow()).clone())); + let y: Value = Rc::new(RefCell::new((*y.borrow()))); + }, + |mut z: i32| -> i32 { + return (((*this_.borrow()).with(|__s| __s.v) + (*y.borrow())) + z); + } + ))); + return ({ (*inner.borrow()).call(1) }); + } + ))); + return ({ (*outer.borrow()).call(20) }); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -51,33 +74,7 @@ fn main_0() -> i32 { (*x.borrow_mut()) = 100; assert!(({ (({ (*outer.borrow()).call(20,) }) == 121) })); let s: Value = Rc::new(RefCell::new(S { v: 5 })); - assert!((({ SImpl::nested_this(&s.as_pointer(),) }) == 26)); + assert!((({ S::nested_this(s.as_pointer(),) }) == 26)); return 0; } -pub trait SImpl { - fn nested_this(&self) -> i32; -} -impl SImpl for Ptr { - fn nested_this(&self) -> i32 { - let outer: Value i32>> = Rc::new(RefCell::new(lambda!( - { - let this_: Value> = Rc::new(RefCell::new((*self).clone())); - }, - |y: i32| -> i32 { - let y: Value = Rc::new(RefCell::new(y)); - let inner: Value i32>> = Rc::new(RefCell::new(lambda!( - { - let this_: Value> = Rc::new(RefCell::new((*this_.borrow()).clone())); - let y: Value = Rc::new(RefCell::new((*y.borrow()))); - }, - |mut z: i32| -> i32 { - return (((*this_.borrow()).with(|__s| __s.v) + (*y.borrow())) + z); - } - ))); - return ({ (*inner.borrow()).call(1) }); - } - ))); - return ({ (*outer.borrow()).call(20) }); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/libc_struct_without_default.rs b/tests/unit/out/refcount/libc_struct_without_default.rs index d3c2ddbd59..ef88225324 100644 --- a/tests/unit/out/refcount/libc_struct_without_default.rs +++ b/tests/unit/out/refcount/libc_struct_without_default.rs @@ -30,11 +30,11 @@ pub struct UserDefined { pub v: Vec, } impl DefaultConstructible for UserDefined { - fn default_constructor(this: &Ptr) { - field!((*this), a).write(Box::<[i32]>::from(std::array::from_fn::<_, 1, _>(|_| { + fn default_constructor(this: Ptr) { + field!(this, a).write(Box::<[i32]>::from(std::array::from_fn::<_, 1, _>(|_| { 0_i32 }))); - field!((*this), v).write(Vec::new()); + field!(this, v).write(Vec::new()); } } impl Default for UserDefined { diff --git a/tests/unit/out/refcount/linked_list.rs b/tests/unit/out/refcount/linked_list.rs index eb9c1d7488..dc1e47b3a3 100644 --- a/tests/unit/out/refcount/linked_list.rs +++ b/tests/unit/out/refcount/linked_list.rs @@ -25,6 +25,11 @@ pub struct Node { #[byte_size(8)] pub next: Ptr, } +impl Node { + pub fn SetNext(this: Ptr, mut next: Ptr) { + field!(this, next).write((next).clone()); + } +} pub fn Find_0(mut head: Ptr, mut idx: i32) -> Ptr { let mut curr: Ptr = (head).clone(); { @@ -43,7 +48,7 @@ pub fn Append_1(head: Ptr, new_node: Ptr) { 'loop_: while !((curr.with(|__s| __s.next.clone())).is_null()) { curr = curr.with(|__s| __s.next.clone()); } - ({ NodeImpl::SetNext(&curr, (new_node).clone()) }); + ({ Node::SetNext((curr).clone(), (new_node).clone()) }); } pub fn Delete_2(mut head: Ptr, mut val: i32) -> Ptr { let mut curr: Ptr = (head).clone(); @@ -120,12 +125,4 @@ fn main_0() -> i32 { ); return 0; } -pub trait NodeImpl { - fn SetNext(&self, next: Ptr); -} -impl NodeImpl for Ptr { - fn SetNext(&self, mut next: Ptr) { - field!((*self), next).write((next).clone()); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/map.rs b/tests/unit/out/refcount/map.rs index b13f4eaff4..2ee95d677a 100644 --- a/tests/unit/out/refcount/map.rs +++ b/tests/unit/out/refcount/map.rs @@ -23,10 +23,16 @@ pub struct Point { #[offset(4)] pub y: i32, } +impl Point { + pub fn construct_1(this: Ptr, mut x: i32, mut y: i32) { + field!(this, x).write(x); + field!(this, y).write(y); + } +} impl DefaultConstructible for Point { - fn default_constructor(this: &Ptr) { - field!((*this), x).write(0); - field!((*this), y).write(0); + fn default_constructor(this: Ptr) { + field!(this, x).write(0); + field!(this, y).write(0); } } impl Default for Point { @@ -34,7 +40,7 @@ impl Default for Point { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -739,7 +745,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key1.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - PointImpl::construct_1(&__v.as_pointer(), 3, 4); + Point::construct_1(__v.as_pointer(), 3, 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -786,7 +792,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(({ (*key8.borrow()) }))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - PointImpl::construct_1(&__v.as_pointer(), 5, 6); + Point::construct_1(__v.as_pointer(), 5, 6); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -972,7 +978,7 @@ fn main_0() -> i32 { }) }); Swappable::swap( - &match (Rc::new(RefCell::new(1_i64)).as_pointer(),) { + match (Rc::new(RefCell::new(1_i64)).as_pointer(),) { (__tmp_68,) => { ({ (*t.borrow_mut()).subscript_move(__tmp_68, |__k| cpp_move!(__k), || 0_i32) }) } @@ -1040,13 +1046,4 @@ fn main_0() -> i32 { } return 0; } -pub trait PointImpl { - fn construct_1(&self, x: i32, y: i32); -} -impl PointImpl for Ptr { - fn construct_1(&self, mut x: i32, mut y: i32) { - field!((*self), x).write(x); - field!((*self), y).write(y); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/map_key_copy_ctor.rs b/tests/unit/out/refcount/map_key_copy_ctor.rs index 58b0144d5b..27ec703703 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -24,32 +24,40 @@ pub struct Key { #[offset(0)] pub k: i32, } +impl Key { + pub fn construct(this: Ptr, mut k: i32) { + field!(this, k).write(k); + } + pub fn operator_lt(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.k) } < { o.with(|__s| __s.k) }); + } +} impl CopyConstructible for Key { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), k).write(o.with(|__s| __s.k)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, k).write(o.with(|__s| __s.k)); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Key { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), k).write(o.with(|__s| __s.k)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, k).write(o.with(|__s| __s.k)); (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CppLess for Key { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - KeyImpl::operator_lt(__lhs, __rhs.clone()) + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + Key::operator_lt(__lhs.clone(), __rhs.clone()) } } impl CppEq for Key { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - !(KeyImpl::operator_lt(__lhs, __rhs.clone())) - && !(KeyImpl::operator_lt(__rhs, __lhs.clone())) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + !(Key::operator_lt(__lhs.clone(), __rhs.clone())) + && !(Key::operator_lt(__rhs.clone(), __lhs.clone())) } } pub fn make_key_3(this: Ptr, mut k: i32) { (*made_2.with(Value::clone).borrow_mut()).prefix_inc(); - KeyImpl::construct(&this, k); + Key::construct(this.clone(), k); return; } pub fn main() { @@ -203,7 +211,7 @@ fn main_0() -> i32 { { let __tmp_12: Value = Rc::new(RefCell::new(::zero_init())); match ({ - KeyImpl::construct(&__tmp_12.as_pointer(), 0); + Key::construct(__tmp_12.as_pointer(), 0); __tmp_12.as_pointer() },) { @@ -309,18 +317,6 @@ fn main_0() -> i32 { ); return if ok { 0 } else { 1 }; } -pub trait KeyImpl { - fn construct(&self, k: i32); - fn operator_lt(&self, o: Ptr) -> bool; -} -impl KeyImpl for Ptr { - fn construct(&self, mut k: i32) { - field!((*self), k).write(k); - } - fn operator_lt(&self, o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.k) } < { o.with(|__s| __s.k) }); - } -} pub fn __cpp2rust_init_globals() { let _ = copies_0.with(|_| ()); let _ = moves_1.with(|_| ()); diff --git a/tests/unit/out/refcount/map_key_identity.rs b/tests/unit/out/refcount/map_key_identity.rs index eb19207a9c..6576af11ae 100644 --- a/tests/unit/out/refcount/map_key_identity.rs +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -29,12 +29,12 @@ pub struct Key { pub identity: i32, } impl CppLess for Key { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { operator_lt_1(__lhs.clone(), __rhs.clone()) } } impl CppEq for Key { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_2(__lhs.clone(), __rhs.clone()) } } @@ -51,8 +51,8 @@ pub struct Mapped { pub value: i32, } impl DefaultConstructible for Mapped { - fn default_constructor(this: &Ptr) { - field!((*this), value).write(0); + fn default_constructor(this: Ptr) { + field!(this, value).write(0); (*default_constructions_0.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -61,7 +61,7 @@ impl Default for Mapped { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index 1cc1ffa71d..bd21add8dd 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -25,20 +25,26 @@ pub struct Item { #[offset(0)] pub value: i32, } +impl Item { + pub fn construct_1(this: Ptr, mut value: i32) { + field!(this, value).write(value); + (*made_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl DefaultConstructible for Item { - fn default_constructor(this: &Ptr) { - field!((*this), value).write(0); + fn default_constructor(this: Ptr) { + field!(this, value).write(0); } } impl CopyConstructible for Item { - fn copy_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); + fn copy_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); (*copies_2.with(Value::clone).borrow_mut()).prefix_inc(); } } impl MoveConstructible for Item { - fn move_constructor(this: &Ptr, other: Ptr) { - field!((*this), value).write(other.with(|__s| __s.value)); + fn move_constructor(this: Ptr, other: Ptr) { + field!(this, value).write(other.with(|__s| __s.value)); (*moves_3.with(Value::clone).borrow_mut()).prefix_inc(); field!(other, value).write(-1_i32); } @@ -48,7 +54,7 @@ impl Default for Item { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -64,9 +70,20 @@ pub struct RefItem { #[offset(0)] pub value: i32, } +impl RefItem { + pub fn construct_1(this: Ptr, counter: Ptr, mut amount: i32) { + field!(this, value).write({ + { + counter.with_mut(|__v| *__v = *__v + amount) + }; + (counter.read()) + }); + (*made_1.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl DefaultConstructible for RefItem { - fn default_constructor(this: &Ptr) { - field!((*this), value).write(0); + fn default_constructor(this: Ptr) { + field!(this, value).write(0); } } impl Default for RefItem { @@ -74,7 +91,7 @@ impl Default for RefItem { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -346,7 +363,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), 10); + Item::construct_1(__v.as_pointer(), 10); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -380,7 +397,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), (__tmp_6).clone()); + ConstructFrom::construct_from(__v.as_pointer(), (__tmp_6).clone()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -420,7 +437,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( - &__v.as_pointer(), + __v.as_pointer(), Moved((__tmp_7).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -460,7 +477,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&__v.as_pointer(), (__tmp_8).clone()); + ConstructFrom::construct_from(__v.as_pointer(), (__tmp_8).clone()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -501,7 +518,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( - &__v.as_pointer(), + __v.as_pointer(), Moved((__tmp_9).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -540,7 +557,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - RefItemImpl::construct_1(&__v.as_pointer(), counter.as_pointer(), 5); + RefItem::construct_1(__v.as_pointer(), counter.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -562,7 +579,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - RefItemImpl::construct_1(&__v.as_pointer(), (__tmp_10).clone(), 2); + RefItem::construct_1(__v.as_pointer(), (__tmp_10).clone(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -593,7 +610,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - RefItemImpl::construct_1(&__v.as_pointer(), (__tmp_11).clone(), 2); + RefItem::construct_1(__v.as_pointer(), (__tmp_11).clone(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -640,7 +657,7 @@ fn main_0() -> i32 { )> = Rc::new(RefCell::new({ let __tmp_13: Value = Rc::new(RefCell::new(::zero_init())); match ({ - ItemImpl::construct_1(&__tmp_13.as_pointer(), 30); + Item::construct_1(__tmp_13.as_pointer(), 30); __tmp_13.as_pointer() },) { @@ -652,7 +669,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( - &__v.as_pointer(), + __v.as_pointer(), Moved((__tmp_12).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -683,7 +700,7 @@ fn main_0() -> i32 { )> = Rc::new(RefCell::new({ let __tmp_15: Value = Rc::new(RefCell::new(::zero_init())); match ({ - ItemImpl::construct_1(&__tmp_15.as_pointer(), 40); + Item::construct_1(__tmp_15.as_pointer(), 40); __tmp_15.as_pointer() },) { @@ -695,7 +712,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( - &__v.as_pointer(), + __v.as_pointer(), Moved((__tmp_14).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -734,29 +751,6 @@ fn main_0() -> i32 { ); return if ok { 0 } else { 1 }; } -pub trait ItemImpl { - fn construct_1(&self, value: i32); -} -impl ItemImpl for Ptr { - fn construct_1(&self, mut value: i32) { - field!((*self), value).write(value); - (*made_1.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub trait RefItemImpl { - fn construct_1(&self, counter: Ptr, amount: i32); -} -impl RefItemImpl for Ptr { - fn construct_1(&self, counter: Ptr, mut amount: i32) { - field!((*self), value).write({ - { - counter.with_mut(|__v| *__v = *__v + amount) - }; - (counter.read()) - }); - (*made_1.with(Value::clone).borrow_mut()).prefix_inc(); - } -} pub fn __cpp2rust_init_globals() { let _ = calls_0.with(|_| ()); let _ = made_1.with(|_| ()); diff --git a/tests/unit/out/refcount/map_try_emplace_lvalues.rs b/tests/unit/out/refcount/map_try_emplace_lvalues.rs index b12eb41467..0b80f5ae8b 100644 --- a/tests/unit/out/refcount/map_try_emplace_lvalues.rs +++ b/tests/unit/out/refcount/map_try_emplace_lvalues.rs @@ -18,9 +18,20 @@ pub struct Item { #[offset(0)] pub value: i32, } +impl Item { + pub fn construct_1(this: Ptr, counter: Ptr, mut amount: i32) { + field!(this, value).write({ + { + counter.with_mut(|__v| *__v = *__v + amount) + }; + (counter.read()) + }); + (*made_0.with(Value::clone).borrow_mut()).prefix_inc(); + } +} impl DefaultConstructible for Item { - fn default_constructor(this: &Ptr) { - field!((*this), value).write(0); + fn default_constructor(this: Ptr) { + field!(this, value).write(0); } } impl Default for Item { @@ -28,7 +39,7 @@ impl Default for Item { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -58,9 +69,9 @@ pub struct Temporary { pub data: Box<[i32]>, } impl DefaultConstructible for Temporary { - fn default_constructor(this: &Ptr) { - field!((*this), n).write(5); - field!((*this), data).write(Box::new([6, 7])); + fn default_constructor(this: Ptr) { + field!(this, n).write(5); + field!(this, data).write(Box::new([6, 7])); (*temporary_calls_4.with(Value::clone).borrow_mut()).prefix_inc(); } } @@ -69,7 +80,7 @@ impl Default for Temporary { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -85,21 +96,21 @@ pub struct Nested { pub inner: Temporary, } impl DefaultConstructible for Nested { - fn default_constructor(this: &Ptr) { - DefaultConstructible::default_constructor(&field_ptr!(this, inner)); + fn default_constructor(this: Ptr) { + DefaultConstructible::default_constructor(field_ptr!(this, inner)); } } pub fn make_temporary_5() -> Temporary { return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } pub fn make_nested_6() -> Nested { return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -111,11 +122,16 @@ pub struct Owner { #[byte_size(8)] pub ptr: Option>, } +impl Owner { + pub fn value(this: Ptr) -> Ptr { + return field_ptr!(this.with(|__s| __s.ptr.clone()).as_pointer(), n); + } +} impl DefaultConstructible for Owner { - fn default_constructor(this: &Ptr) { - field!((*this), ptr).write(Some(Rc::new(RefCell::new({ + fn default_constructor(this: Ptr) { + field!(this, ptr).write(Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })))); } @@ -125,7 +141,7 @@ impl Default for Owner { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -138,8 +154,8 @@ pub struct Noncopy { pub n: i32, } impl DefaultConstructible for Noncopy { - fn default_constructor(this: &Ptr) { - field!((*this), n).write(5); + fn default_constructor(this: Ptr) { + field!(this, n).write(5); } } impl Default for Noncopy { @@ -157,9 +173,17 @@ pub struct Held { #[byte_size(8)] pub ptr: Ptr, } +impl Held { + pub fn construct_1(this: Ptr, n: Ptr) { + field!(this, ptr).write((n).clone()); + } + pub fn construct_2(this: Ptr, n: Ptr, mut _a1: i32) { + field!(this, ptr).write((n).clone()); + } +} impl DefaultConstructible for Held { - fn default_constructor(this: &Ptr) { - field!((*this), ptr).write(Ptr::::null()); + fn default_constructor(this: Ptr) { + field!(this, ptr).write(Ptr::::null()); } } impl Default for Held { @@ -167,7 +191,7 @@ impl Default for Held { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -283,7 +307,7 @@ thread_local!( (*{ __tmp_7 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_7 @@ -378,7 +402,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), counter.as_pointer(), 3); + Item::construct_1(__v.as_pointer(), counter.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -406,7 +430,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), (__tmp_9).clone(), 2); + Item::construct_1(__v.as_pointer(), (__tmp_9).clone(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -444,7 +468,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), (__tmp_11).clone(), 2); + Item::construct_1(__v.as_pointer(), (__tmp_11).clone(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -479,7 +503,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), (__tmp_13).clone(), 2); + Item::construct_1(__v.as_pointer(), (__tmp_13).clone(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -515,7 +539,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), (__tmp_16).clone(), 2); + Item::construct_1(__v.as_pointer(), (__tmp_16).clone(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -560,7 +584,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), (__tmp_19).clone(), 3); + Item::construct_1(__v.as_pointer(), (__tmp_19).clone(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -591,7 +615,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), (__tmp_21).clone(), 3); + Item::construct_1(__v.as_pointer(), (__tmp_21).clone(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -622,7 +646,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), (__tmp_24).clone(), 3); + Item::construct_1(__v.as_pointer(), (__tmp_24).clone(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -661,7 +685,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), (__tmp_27).clone(), 3); + Item::construct_1(__v.as_pointer(), (__tmp_27).clone(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -702,7 +726,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), (__tmp_30).clone(), 3); + Item::construct_1(__v.as_pointer(), (__tmp_30).clone(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -729,7 +753,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ItemImpl::construct_1(&__v.as_pointer(), (__tmp_33).clone(), 3); + Item::construct_1(__v.as_pointer(), (__tmp_33).clone(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -1246,8 +1270,8 @@ fn main_0() -> i32 { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - ItemImpl::construct_1( - &__v.as_pointer(), + Item::construct_1( + __v.as_pointer(), (__tmp_61).clone(), 2, ); @@ -1299,8 +1323,8 @@ fn main_0() -> i32 { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - ItemImpl::construct_1( - &__v.as_pointer(), + Item::construct_1( + __v.as_pointer(), (__tmp_64).clone(), 2, ); @@ -1352,8 +1376,8 @@ fn main_0() -> i32 { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - ItemImpl::construct_1( - &__v.as_pointer(), + Item::construct_1( + __v.as_pointer(), (__tmp_69).clone(), 2, ); @@ -1616,8 +1640,8 @@ fn main_0() -> i32 { Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - HeldImpl::construct_1( - &__v.as_pointer(), + Held::construct_1( + __v.as_pointer(), ordinary.as_pointer(), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -1669,8 +1693,8 @@ fn main_0() -> i32 { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - HeldImpl::construct_1( - &__v.as_pointer(), + Held::construct_1( + __v.as_pointer(), (__tmp_83).clone(), ); Rc::try_unwrap(__v) @@ -1724,8 +1748,8 @@ fn main_0() -> i32 { Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - HeldImpl::construct_2( - &__v.as_pointer(), + Held::construct_2( + __v.as_pointer(), ordinary_array.decay(), 0, ); @@ -1777,8 +1801,8 @@ fn main_0() -> i32 { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - HeldImpl::construct_2( - &__v.as_pointer(), + Held::construct_2( + __v.as_pointer(), (__tmp_88).clone(), 0, ); @@ -1846,7 +1870,7 @@ fn main_0() -> i32 { __tmp_94 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_94 @@ -1883,7 +1907,7 @@ fn main_0() -> i32 { __tmp_96 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_96 @@ -1921,7 +1945,7 @@ fn main_0() -> i32 { __tmp_98 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_98 @@ -1958,7 +1982,7 @@ fn main_0() -> i32 { __tmp_100 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_100 @@ -1994,7 +2018,7 @@ fn main_0() -> i32 { __tmp_102 = Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); &mut __tmp_102 @@ -2030,7 +2054,7 @@ fn main_0() -> i32 { __tmp_104 = Some(Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })))))); &mut __tmp_104 @@ -2106,8 +2130,8 @@ fn main_0() -> i32 { Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - HeldImpl::construct_1( - &__v.as_pointer(), + Held::construct_1( + __v.as_pointer(), ordinary.as_pointer(), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() @@ -2136,7 +2160,7 @@ fn main_0() -> i32 { RefCell::new(::zero_init()), ); DefaultConstructible::default_constructor( - &__v.as_pointer(), + __v.as_pointer(), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); @@ -2153,7 +2177,7 @@ fn main_0() -> i32 { RefCell::new(::zero_init()), ); DefaultConstructible::default_constructor( - &__v.as_pointer(), + __v.as_pointer(), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))); @@ -2178,8 +2202,8 @@ fn main_0() -> i32 { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - HeldImpl::construct_1( - &__v.as_pointer(), + Held::construct_1( + __v.as_pointer(), (__tmp_105).clone(), ); Rc::try_unwrap(__v) @@ -2223,9 +2247,9 @@ fn main_0() -> i32 { Rc::new(RefCell::new(::zero_init())); { match (({ - OwnerImpl::value(&{ + Owner::value({ DefaultConstructible::default_constructor( - &__tmp_109.as_pointer(), + __tmp_109.as_pointer(), ); __tmp_109.as_pointer() }) @@ -2244,8 +2268,8 @@ fn main_0() -> i32 { let __v: Value = Rc::new( RefCell::new(::zero_init()), ); - HeldImpl::construct_1( - &__v.as_pointer(), + Held::construct_1( + __v.as_pointer(), (__tmp_108).clone(), ); Rc::try_unwrap(__v) @@ -2301,7 +2325,7 @@ fn main_0() -> i32 { match ({ __tmp_111 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))))); __tmp_111.as_pointer() @@ -2341,7 +2365,7 @@ fn main_0() -> i32 { match ({ __tmp_113 = Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }))))); __tmp_113.as_pointer() @@ -2495,40 +2519,6 @@ fn main_0() -> i32 { ); return 0; } -pub trait HeldImpl { - fn construct_1(&self, n: Ptr); - fn construct_2(&self, n: Ptr, _a1: i32); -} -impl HeldImpl for Ptr { - fn construct_1(&self, n: Ptr) { - field!((*self), ptr).write((n).clone()); - } - fn construct_2(&self, n: Ptr, mut _a1: i32) { - field!((*self), ptr).write((n).clone()); - } -} -pub trait ItemImpl { - fn construct_1(&self, counter: Ptr, amount: i32); -} -impl ItemImpl for Ptr { - fn construct_1(&self, counter: Ptr, mut amount: i32) { - field!((*self), value).write({ - { - counter.with_mut(|__v| *__v = *__v + amount) - }; - (counter.read()) - }); - (*made_0.with(Value::clone).borrow_mut()).prefix_inc(); - } -} -pub trait OwnerImpl { - fn value(&self) -> Ptr; -} -impl OwnerImpl for Ptr { - fn value(&self) -> Ptr { - return field_ptr!((*self).with(|__s| __s.ptr.clone()).as_pointer(), n); - } -} pub fn __cpp2rust_init_globals() { let _ = made_0.with(|_| ()); let _ = visits_1.with(|_| ()); diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index fcf972442b..ee1944e997 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -40,19 +40,24 @@ pub struct Bag { #[offset(0)] pub n: i32, } +impl Bag { + pub fn construct(this: Ptr, mut n: i32) { + field!(this, n).write(n); + } +} impl CopyConstructible for Bag { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), n).write(o.with(|__s| __s.n)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, n).write(o.with(|__s| __s.n)); (*calls_0.with(Value::clone).borrow_mut()).prefix_inc(); } } impl CppLess for Bag { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { operator_lt_4(__lhs.clone(), __rhs.clone()) } } impl CppEq for Bag { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { !(operator_lt_4(__lhs.clone(), __rhs.clone())) && !(operator_lt_4(__rhs.clone(), __lhs.clone())) } @@ -61,7 +66,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(this: Ptr, mut n: i32) { - BagImpl::construct(&this, n); + Bag::construct(this.clone(), n); return; } pub fn main() { @@ -75,25 +80,25 @@ fn main_0() -> i32 { let x4: Value = Rc::new(RefCell::new(20)); let mut p1: Ptr = (x1.as_pointer()); let mut p2: Ptr = (x2.as_pointer()); - let mut r1: i32 = (if CppLess::less(&x1.as_pointer(), &x2.as_pointer()) { + let mut r1: i32 = (if CppLess::less(x1.as_pointer().clone(), x2.as_pointer().clone()) { x2.as_pointer() } else { x1.as_pointer() } .read()); - let mut r2: i32 = (if CppLess::less(&x4.as_pointer(), &x3.as_pointer()) { + let mut r2: i32 = (if CppLess::less(x4.as_pointer().clone(), x3.as_pointer().clone()) { x4.as_pointer() } else { x3.as_pointer() } .read()); - let mut r3: i32 = (if CppLess::less(&(p1).clone(), &x2.as_pointer()) { + let mut r3: i32 = (if CppLess::less((p1).clone().clone(), x2.as_pointer().clone()) { x2.as_pointer() } else { (p1).clone() } .read()); - let mut r4: i32 = (if CppLess::less(&x3.as_pointer(), &(p2).clone()) { + let mut r4: i32 = (if CppLess::less(x3.as_pointer().clone(), (p2).clone().clone()) { x3.as_pointer() } else { (p2).clone() @@ -102,7 +107,7 @@ fn main_0() -> i32 { let mut r5: i32 = { let __tmp_0: Value = Rc::new(RefCell::new(30)); let __tmp_1: Value = Rc::new(RefCell::new(40)); - (if CppLess::less(&__tmp_0.as_pointer(), &__tmp_1.as_pointer()) { + (if CppLess::less(__tmp_0.as_pointer().clone(), __tmp_1.as_pointer().clone()) { __tmp_1.as_pointer() } else { __tmp_0.as_pointer() @@ -119,7 +124,7 @@ fn main_0() -> i32 { let mut __it = (__tmp_2).clone(); __it.iter_inc(); while __it != __tmp_3 { - if CppLess::less(&__best.iter_deref(), &__it.iter_deref()) { + if CppLess::less(__best.iter_deref(), __it.iter_deref()) { __best = __it.clone(); } __it.iter_inc(); @@ -131,7 +136,7 @@ fn main_0() -> i32 { assert!( ((match (({ pick_3(0,) }), ({ pick_3(1,) }),) { (__tmp_4, __tmp_5) => { - if CppLess::less(&(__tmp_4).clone(), &(__tmp_5).clone()) { + if CppLess::less((__tmp_4).clone().clone(), (__tmp_5).clone().clone()) { (__tmp_5).clone() } else { (__tmp_4).clone() @@ -145,7 +150,7 @@ fn main_0() -> i32 { assert!( ((match (({ pick_3(1,) }), ({ pick_3(0,) }),) { (__tmp_6, __tmp_7) => { - if CppLess::less(&(__tmp_7).clone(), &(__tmp_6).clone()) { + if CppLess::less((__tmp_7).clone().clone(), (__tmp_6).clone().clone()) { (__tmp_7).clone() } else { (__tmp_6).clone() @@ -172,7 +177,7 @@ fn main_0() -> i32 { }, ) { (__tmp_8, __tmp_10) => { - if CppLess::less(&(__tmp_8).clone(), &(__tmp_10).clone()) { + if CppLess::less((__tmp_8).clone().clone(), (__tmp_10).clone().clone()) { (__tmp_10).clone() } else { (__tmp_8).clone() @@ -195,7 +200,7 @@ fn main_0() -> i32 { }, ) { (__tmp_12, __tmp_14) => { - if CppLess::less(&(__tmp_14).clone(), &(__tmp_12).clone()) { + if CppLess::less((__tmp_14).clone().clone(), (__tmp_12).clone().clone()) { (__tmp_14).clone() } else { (__tmp_12).clone() @@ -216,7 +221,10 @@ fn main_0() -> i32 { let __tmp_17: Value = Rc::new(RefCell::new((largest as u64))); (match (Rc::new(RefCell::new((({ size_of_2(i) }) as u64))).as_pointer(),) { (__tmp_16,) => { - if CppLess::less(&__tmp_17.as_pointer(), &(__tmp_16).clone()) { + if CppLess::less( + __tmp_17.as_pointer().clone(), + (__tmp_16).clone().clone(), + ) { (__tmp_16).clone() } else { __tmp_17.as_pointer() @@ -232,14 +240,6 @@ fn main_0() -> i32 { assert!((largest == 6_usize) && (calls_0.with(|rc| *rc.borrow()) == 3)); return 0; } -pub trait BagImpl { - fn construct(&self, n: i32); -} -impl BagImpl for Ptr { - fn construct(&self, mut n: i32) { - field!((*self), n).write(n); - } -} pub fn __cpp2rust_init_globals() { let _ = calls_0.with(|_| ()); let _ = xs_1.with(|_| ()); diff --git a/tests/unit/out/refcount/min_max_ptr2ptr.rs b/tests/unit/out/refcount/min_max_ptr2ptr.rs index 2250c063af..6c2a8acd49 100644 --- a/tests/unit/out/refcount/min_max_ptr2ptr.rs +++ b/tests/unit/out/refcount/min_max_ptr2ptr.rs @@ -17,13 +17,13 @@ fn main_0() -> i32 { let pb: Value> = Rc::new(RefCell::new((b.as_pointer()))); let mut ppa: Ptr> = (pa.as_pointer()); let mut ppb: Ptr> = (pb.as_pointer()); - let mut r1: i32 = (if CppLess::less(&(ppa.read()), &(ppb.read())) { + let mut r1: i32 = (if CppLess::less((ppa.read()).clone(), (ppb.read()).clone()) { (ppb.read()) } else { (ppa.read()) } .read()); - let mut r2: i32 = (if CppLess::less(&(ppb.read()), &(ppa.read())) { + let mut r2: i32 = (if CppLess::less((ppb.read()).clone(), (ppa.read()).clone()) { (ppb.read()) } else { (ppa.read()) @@ -36,7 +36,7 @@ fn main_0() -> i32 { assert!( ({ ({ - (if CppLess::less(&high.as_pointer(), &low.as_pointer()) { + (if CppLess::less(high.as_pointer().clone(), low.as_pointer().clone()) { high.as_pointer() } else { low.as_pointer() @@ -48,7 +48,7 @@ fn main_0() -> i32 { assert!( ({ ({ - (if CppLess::less(&low.as_pointer(), &high.as_pointer()) { + (if CppLess::less(low.as_pointer().clone(), high.as_pointer().clone()) { low.as_pointer() } else { high.as_pointer() @@ -60,7 +60,7 @@ fn main_0() -> i32 { assert!( ({ ({ - (if CppLess::less(&low.as_pointer(), &high.as_pointer()) { + (if CppLess::less(low.as_pointer().clone(), high.as_pointer().clone()) { high.as_pointer() } else { low.as_pointer() @@ -72,7 +72,7 @@ fn main_0() -> i32 { assert!( ({ ({ - (if CppLess::less(&high.as_pointer(), &low.as_pointer()) { + (if CppLess::less(high.as_pointer().clone(), low.as_pointer().clone()) { low.as_pointer() } else { high.as_pointer() diff --git a/tests/unit/out/refcount/move_assign.rs b/tests/unit/out/refcount/move_assign.rs index 949339cca3..3abb448fc9 100644 --- a/tests/unit/out/refcount/move_assign.rs +++ b/tests/unit/out/refcount/move_assign.rs @@ -22,20 +22,25 @@ pub struct MoveOnly { #[offset(0)] pub v: i32, } +impl MoveOnly { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } +} impl MoveConstructible for MoveOnly { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } impl MoveAssignable for MoveOnly { - fn move_assign(this: &Ptr, o: Ptr) -> Ptr { - if ((*this) == (o)) { - return (*this).clone(); + fn move_assign(this: Ptr, o: Ptr) -> Ptr { + if (this == (o)) { + return (this).clone(); } - field!((*this), v).write(o.with(|__s| __s.v)); + field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); - return (*this).clone(); + return (this).clone(); } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] @@ -44,9 +49,19 @@ pub struct ConstMoveAssign { #[offset(0)] pub mark: i32, } +impl ConstMoveAssign { + pub fn operator_assign_2(this: Ptr, o: Ptr) -> Ptr { + field!(this, mark).write((o.with(|__s| __s.mark) + 1)); + return (this).clone(); + } + pub fn operator_assign_3(this: Ptr, o: Ptr) -> Ptr { + field!(this, mark).write((o.with(|__s| __s.mark) + 10)); + return (this).clone(); + } +} impl DefaultConstructible for ConstMoveAssign { - fn default_constructor(this: &Ptr) { - field!((*this), mark).write(0); + fn default_constructor(this: Ptr) { + field!(this, mark).write(0); } } impl Default for ConstMoveAssign { @@ -55,7 +70,7 @@ impl Default for ConstMoveAssign { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -63,7 +78,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.clone(), Moved(m.as_pointer())); return; } pub fn main() { @@ -79,7 +94,7 @@ fn main_0() -> i32 { assert!(({ (*b.borrow()).v } == 0)); ({ let _o: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnlyImpl::construct(&_o.as_pointer(), 3); + MoveOnly::construct(_o.as_pointer(), 3); assign!(b = Moved(_o)) }); assign!(c = Moved(*assign!(a = Moved(b)))); @@ -88,7 +103,7 @@ fn main_0() -> i32 { ); ({ let _o: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnlyImpl::construct(&_o.as_pointer(), 5); + MoveOnly::construct(_o.as_pointer(), 5); assign!(a = Moved(_o)) }); assert!(({ (*a.borrow()).v } == 5)); @@ -104,7 +119,7 @@ fn main_0() -> i32 { { let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); match ({ - MoveOnlyImpl::construct(&__tmp_1.as_pointer(), 7); + MoveOnly::construct(__tmp_1.as_pointer(), 7); __tmp_1.as_pointer() },) { @@ -119,32 +134,10 @@ fn main_0() -> i32 { object!(m1, ConstMoveAssign); object!(m2, ConstMoveAssign); object!(cm, ConstMoveAssign); - ConstMoveAssignImpl::operator_assign_2(&m1.as_pointer(), m.as_pointer()); - ConstMoveAssignImpl::operator_assign_3(&m2.as_pointer(), cm.as_pointer()); + ConstMoveAssign::operator_assign_2(m1.as_pointer(), m.as_pointer()); + ConstMoveAssign::operator_assign_3(m2.as_pointer(), cm.as_pointer()); assert!(({ (*m1.borrow()).mark } == 1)); assert!(({ (*m2.borrow()).mark } == 10)); return 0; } -pub trait ConstMoveAssignImpl { - fn operator_assign_2(&self, o: Ptr) -> Ptr; - fn operator_assign_3(&self, o: Ptr) -> Ptr; -} -impl ConstMoveAssignImpl for Ptr { - fn operator_assign_2(&self, o: Ptr) -> Ptr { - field!((*self), mark).write((o.with(|__s| __s.mark) + 1)); - return (*self).clone(); - } - fn operator_assign_3(&self, o: Ptr) -> Ptr { - field!((*self), mark).write((o.with(|__s| __s.mark) + 10)); - return (*self).clone(); - } -} -pub trait MoveOnlyImpl { - fn construct(&self, v: i32); -} -impl MoveOnlyImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/move_ctor.rs b/tests/unit/out/refcount/move_ctor.rs index a08b6ac284..5d2a0252ef 100644 --- a/tests/unit/out/refcount/move_ctor.rs +++ b/tests/unit/out/refcount/move_ctor.rs @@ -15,9 +15,14 @@ pub struct MoveOnly { #[offset(0)] pub v: i32, } +impl MoveOnly { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } +} impl MoveConstructible for MoveOnly { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); field!(o, v).write(0); } } @@ -27,9 +32,17 @@ pub struct ConstMove { #[offset(0)] pub mark: i32, } +impl ConstMove { + pub fn construct_1(this: Ptr, o: Ptr) { + field!(this, mark).write((o.with(|__s| __s.mark) + 1)); + } + pub fn construct_2(this: Ptr, o: Ptr) { + field!(this, mark).write((o.with(|__s| __s.mark) + 10)); + } +} impl DefaultConstructible for ConstMove { - fn default_constructor(this: &Ptr) { - field!((*this), mark).write(0); + fn default_constructor(this: Ptr) { + field!(this, mark).write(0); } } impl Default for ConstMove { @@ -37,7 +50,7 @@ impl Default for ConstMove { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -56,18 +69,25 @@ pub struct ThrowingMove { #[offset(8)] pub moves: i32, } +impl ThrowingMove { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + field!(this, copies).write(0); + field!(this, moves).write(0); + } +} impl CopyConstructible for ThrowingMove { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); - field!((*this), moves).write(o.with(|__s| __s.moves)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write((o.with(|__s| __s.copies) + 1)); + field!(this, moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for ThrowingMove { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write(o.with(|__s| __s.copies)); - field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write(o.with(|__s| __s.copies)); + field!(this, moves).write((o.with(|__s| __s.moves) + 1)); field!(o, v).write(0); } } @@ -84,18 +104,25 @@ pub struct NoexceptMove { #[offset(8)] pub moves: i32, } +impl NoexceptMove { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + field!(this, copies).write(0); + field!(this, moves).write(0); + } +} impl CopyConstructible for NoexceptMove { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write((o.with(|__s| __s.copies) + 1)); - field!((*this), moves).write(o.with(|__s| __s.moves)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write((o.with(|__s| __s.copies) + 1)); + field!(this, moves).write(o.with(|__s| __s.moves)); } } impl MoveConstructible for NoexceptMove { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write(o.with(|__s| __s.v)); - field!((*this), copies).write(o.with(|__s| __s.copies)); - field!((*this), moves).write((o.with(|__s| __s.moves) + 1)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write(o.with(|__s| __s.v)); + field!(this, copies).write(o.with(|__s| __s.copies)); + field!(this, moves).write((o.with(|__s| __s.moves) + 1)); field!(o, v).write(0); } } @@ -104,7 +131,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.clone(), Moved(m.as_pointer())); return; } pub fn main() { @@ -122,19 +149,19 @@ fn main_0() -> i32 { object!(d, MoveOnly, Moved(c.as_pointer())); assert!(({ (*d.borrow()).v } == 1)); assert!(({ (*c.borrow()).v } == 0)); - object!(e, MoveOnly, |e| ({ make_1(Ptr::clone(e), 5,) })); + object!(e, MoveOnly, |e| ({ make_1(Ptr::clone(&e.clone()), 5,) })); assert!(({ (*e.borrow()).v } == 5)); assert!( (({ let _m: Value = Rc::new(RefCell::new(::zero_init())); - MoveOnlyImpl::construct(&_m.as_pointer(), 6); + MoveOnly::construct(_m.as_pointer(), 6); by_value_0(_m.as_pointer()) }) == 6) ); assert!( (({ let _m: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(&_m.as_pointer(), Moved(e.as_pointer())); + ConstructFrom::construct_from(_m.as_pointer(), Moved(e.as_pointer())); by_value_0(_m.as_pointer()) }) == 5) ); @@ -143,7 +170,7 @@ fn main_0() -> i32 { { let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); match ({ - MoveOnlyImpl::construct(&__tmp_1.as_pointer(), 7); + MoveOnly::construct(__tmp_1.as_pointer(), 7); __tmp_1.as_pointer() },) { @@ -180,7 +207,7 @@ fn main_0() -> i32 { { let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); match ({ - NoexceptMoveImpl::construct(&__tmp_3.as_pointer(), 4); + NoexceptMove::construct(__tmp_3.as_pointer(), 4); __tmp_3.as_pointer() },) { @@ -193,44 +220,4 @@ fn main_0() -> i32 { ); return 0; } -pub trait ConstMoveImpl { - fn construct_1(&self, o: Ptr); - fn construct_2(&self, o: Ptr); -} -impl ConstMoveImpl for Ptr { - fn construct_1(&self, o: Ptr) { - field!((*self), mark).write((o.with(|__s| __s.mark) + 1)); - } - fn construct_2(&self, o: Ptr) { - field!((*self), mark).write((o.with(|__s| __s.mark) + 10)); - } -} -pub trait MoveOnlyImpl { - fn construct(&self, v: i32); -} -impl MoveOnlyImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - } -} -pub trait NoexceptMoveImpl { - fn construct(&self, v: i32); -} -impl NoexceptMoveImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - field!((*self), copies).write(0); - field!((*self), moves).write(0); - } -} -pub trait ThrowingMoveImpl { - fn construct(&self, v: i32); -} -impl ThrowingMoveImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - field!((*self), copies).write(0); - field!((*self), moves).write(0); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/move_this.rs b/tests/unit/out/refcount/move_this.rs index 81c681c21d..4d20d16f2a 100644 --- a/tests/unit/out/refcount/move_this.rs +++ b/tests/unit/out/refcount/move_this.rs @@ -15,14 +15,42 @@ pub struct Chain { #[offset(0)] pub v: i32, } +impl Chain { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } + pub fn add_4(this: Ptr, mut n: i32) -> Ptr { + { + field!(this, v).with_mut(|__v| *__v = *__v + n) + }; + return (this).clone(); + } + pub fn add_5(this: Ptr, mut n: i32) -> Ptr { + { + field!(this, v).with_mut(|__v| *__v = *__v + n) + }; + return (this).clone(); + } + pub fn take(this: Ptr, this: Ptr) { + ConstructFrom::construct_from(this.clone(), Moved((this).clone())); + return; + } + pub fn copy(this: Ptr, this: Ptr) { + ConstructFrom::construct_from(this.clone(), (this).clone()); + return; + } + pub fn self_(this: Ptr) -> Ptr { + return (this).clone(); + } +} impl CopyConstructible for Chain { - fn copy_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write((o.with(|__s| __s.v) + 100)); + fn copy_constructor(this: Ptr, o: Ptr) { + field!(this, v).write((o.with(|__s| __s.v) + 100)); } } impl MoveConstructible for Chain { - fn move_constructor(this: &Ptr, o: Ptr) { - field!((*this), v).write((o.with(|__s| __s.v) + 1)); + fn move_constructor(this: Ptr, o: Ptr) { + field!(this, v).write((o.with(|__s| __s.v) + 1)); field!(o, v).write(0); } } @@ -35,30 +63,30 @@ pub fn main() { } fn main_0() -> i32 { object!(a, Chain(1)); - ({ ChainImpl::add_4(&({ ChainImpl::add_4(&a.as_pointer(), 1) }), 1) }); + ({ Chain::add_4(({ Chain::add_4(a.as_pointer(), 1) }), 1) }); assert!(({ (*a.borrow()).v } == 3)); object!(b0, Chain(5)); object!( b, Chain, - Moved(({ ChainImpl::add_5(&({ ChainImpl::add_5(&b0.as_pointer(), 1,) }), 1,) })) + Moved(({ Chain::add_5(({ Chain::add_5(b0.as_pointer(), 1,) }), 1,) })) ); assert!(({ (*b.borrow()).v } == 8) && ({ (*b0.borrow()).v } == 0)); object!(c, Chain, |c| { let __tmp_0: Value = Rc::new(RefCell::new(::zero_init())); ({ - ChainImpl::take( - &{ - ChainImpl::construct(&__tmp_0.as_pointer(), 10); + Chain::take( + { + Chain::construct(__tmp_0.as_pointer(), 10); __tmp_0.as_pointer() }, - Ptr::clone(c), + Ptr::clone(&c.clone()), ) }) }); assert!(({ (*c.borrow()).v } == 11)); object!(d, Chain, |d| ({ - ChainImpl::copy(&c.as_pointer(), Ptr::clone(d)) + Chain::copy(c.as_pointer(), Ptr::clone(&d.clone())) })); assert!(({ (*d.borrow()).v } == 111) && ({ (*c.borrow()).v } == 11)); object!(g, Chain(20)); @@ -66,53 +94,17 @@ fn main_0() -> i32 { (({ let _c: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( - &_c.as_pointer(), - Moved(({ ChainImpl::self_(&g.as_pointer()) })), + _c.as_pointer(), + Moved(({ Chain::self_(g.as_pointer()) })), ); consume_0(_c.as_pointer()) }) == 21) ); object!(e, Chain(30)); object!(f, Chain, |f| ({ - ChainImpl::take(&e.as_pointer(), Ptr::clone(f)) + Chain::take(e.as_pointer(), Ptr::clone(&f.clone())) })); assert!(({ (*f.borrow()).v } == 31) && ({ (*e.borrow()).v } == 0)); return 0; } -pub trait ChainImpl { - fn construct(&self, v: i32); - fn add_4(&self, n: i32) -> Ptr; - fn add_5(&self, n: i32) -> Ptr; - fn take(&self, this: Ptr); - fn copy(&self, this: Ptr); - fn self_(&self) -> Ptr; -} -impl ChainImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - } - fn add_4(&self, mut n: i32) -> Ptr { - { - field!((*self), v).with_mut(|__v| *__v = *__v + n) - }; - return (*self).clone(); - } - fn add_5(&self, mut n: i32) -> Ptr { - { - field!((*self), v).with_mut(|__v| *__v = *__v + n) - }; - return (*self).clone(); - } - fn take(&self, this: Ptr) { - ConstructFrom::construct_from(&this, Moved((*self).clone())); - return; - } - fn copy(&self, this: Ptr) { - ConstructFrom::construct_from(&this, (*self).clone()); - return; - } - fn self_(&self) -> Ptr { - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/nttp_distinct_specializations.rs b/tests/unit/out/refcount/nttp_distinct_specializations.rs index 50684d62f7..048c716494 100644 --- a/tests/unit/out/refcount/nttp_distinct_specializations.rs +++ b/tests/unit/out/refcount/nttp_distinct_specializations.rs @@ -25,6 +25,11 @@ pub struct S_2_ { #[offset(4)] pub w: i32, } +impl S_2_ { + pub fn get(this: Ptr) -> i32 { + return (this.with(|__s| __s.v) - this.with(|__s| __s.w)); + } +} #[derive( Copy, Clone, @@ -42,6 +47,11 @@ pub struct S_1_ { #[offset(0)] pub v: i32, } +impl S_1_ { + pub fn get(this: Ptr) -> i32 { + return (this.with(|__s| __s.v) * 1); + } +} #[derive( Copy, Clone, @@ -59,6 +69,11 @@ pub struct S_3_ { #[offset(0)] pub v: i32, } +impl S_3_ { + pub fn get(this: Ptr) -> i32 { + return (this.with(|__s| __s.v) * 3); + } +} pub fn scale_0(mut x: i32) -> i32 { return (x * 1); } @@ -94,9 +109,9 @@ fn main_0() -> i32 { let s1: Value = Rc::new(RefCell::new(S_1_ { v: 5 })); let s2: Value = Rc::new(RefCell::new(S_2_ { v: 5, w: 1 })); let s3: Value = Rc::new(RefCell::new(S_3_ { v: 5 })); - assert!((({ S_1_Impl::get(&s1.as_pointer(),) }) == 5)); - assert!((({ S_2_Impl::get(&s2.as_pointer(),) }) == 4)); - assert!((({ S_3_Impl::get(&s3.as_pointer(),) }) == 15)); + assert!((({ S_1_::get(s1.as_pointer(),) }) == 5)); + assert!((({ S_2_::get(s2.as_pointer(),) }) == 4)); + assert!((({ S_3_::get(s3.as_pointer(),) }) == 15)); assert!((({ scale_0(7,) }) == 7)); assert!((({ scale_2(7,) }) == 5)); assert!((({ scale_1(7,) }) == 21)); @@ -114,28 +129,4 @@ fn main_0() -> i32 { assert!((ld_inf < 0_f64)); return 0; } -pub trait S_1_Impl { - fn get(&self) -> i32; -} -impl S_1_Impl for Ptr { - fn get(&self) -> i32 { - return ((*self).with(|__s| __s.v) * 1); - } -} -pub trait S_2_Impl { - fn get(&self) -> i32; -} -impl S_2_Impl for Ptr { - fn get(&self) -> i32 { - return ((*self).with(|__s| __s.v) - (*self).with(|__s| __s.w)); - } -} -pub trait S_3_Impl { - fn get(&self) -> i32; -} -impl S_3_Impl for Ptr { - fn get(&self) -> i32 { - return ((*self).with(|__s| __s.v) * 3); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/opaque_record_copy.rs b/tests/unit/out/refcount/opaque_record_copy.rs index 868fa37299..05c563cafd 100644 --- a/tests/unit/out/refcount/opaque_record_copy.rs +++ b/tests/unit/out/refcount/opaque_record_copy.rs @@ -51,10 +51,4 @@ fn main_0() -> i32 { assert!((b.tag == 3)); return 0; } -pub trait ProbeImpl { - fn operator_inc(&self) -> Ptr { - unimplemented!() - } -} -impl ProbeImpl for Ptr {} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_arithmetic_member.rs b/tests/unit/out/refcount/operator_arithmetic_member.rs index 14fb214da2..37a0b9d95d 100644 --- a/tests/unit/out/refcount/operator_arithmetic_member.rs +++ b/tests/unit/out/refcount/operator_arithmetic_member.rs @@ -23,119 +23,105 @@ pub struct S { #[offset(0)] pub v: i32, } -pub fn main() { - __cpp2rust_init_globals(); - libcc2rs::cpp2rust_exit(main_0()); -} -fn main_0() -> i32 { - let a: Value = Rc::new(RefCell::new(S { v: 7 })); - let b: Value = Rc::new(RefCell::new(S { v: 2 })); - assert!(({ ({ SImpl::operator_add_1(&a.as_pointer(), b.as_pointer(),) }).v } == 9)); - assert!(({ ({ SImpl::operator_sub_2(&a.as_pointer(), b.as_pointer(),) }).v } == 5)); - assert!(({ ({ SImpl::operator_mul(&a.as_pointer(), b.as_pointer(),) }).v } == 14)); - assert!(({ ({ SImpl::operator_div(&a.as_pointer(), b.as_pointer(),) }).v } == 3)); - assert!(({ ({ SImpl::operator_rem(&a.as_pointer(), b.as_pointer(),) }).v } == 1)); - assert!(({ ({ SImpl::operator_pos_6(&a.as_pointer(),) }).v } == 7)); - assert!(({ ({ SImpl::operator_neg_7(&a.as_pointer(),) }).v } == -7_i32)); - assert!((({ SImpl::operator_inc_8(&a.as_pointer(),) }).with(|__s| (__s).v) == 8)); - assert!(({ ({ SImpl::operator_post_inc_9(&a.as_pointer(), 0,) }).v } == 8)); - assert!(({ (*a.borrow()).v } == 9)); - assert!((({ SImpl::operator_dec_10(&a.as_pointer(),) }).with(|__s| (__s).v) == 8)); - assert!(({ ({ SImpl::operator_post_dec_11(&a.as_pointer(), 0,) }).v } == 8)); - assert!(({ (*a.borrow()).v } == 7)); - assert!( - (({ SImpl::operator_inc_8(&({ SImpl::operator_inc_8(&a.as_pointer(),) }),) }) - .with(|__s| (__s).v) - == 9) - ); - assert!( - ({ - ({ - let _o: Value = Rc::new(RefCell::new(S { v: 4 })); - SImpl::operator_add_1( - &Rc::new(RefCell::new(S { v: 3 })).as_pointer(), - _o.as_pointer(), - ) - }) - .v - } == 7) - ); - return 0; -} -pub trait SImpl { - fn operator_add_1(&self, o: Ptr) -> S; - fn operator_sub_2(&self, o: Ptr) -> S; - fn operator_mul(&self, o: Ptr) -> S; - fn operator_div(&self, o: Ptr) -> S; - fn operator_rem(&self, o: Ptr) -> S; - fn operator_pos_6(&self) -> S; - fn operator_neg_7(&self) -> S; - fn operator_inc_8(&self) -> Ptr; - fn operator_post_inc_9(&self, _a0: i32) -> S; - fn operator_dec_10(&self) -> Ptr; - fn operator_post_dec_11(&self, _a0: i32) -> S; -} -impl SImpl for Ptr { - fn operator_add_1(&self, o: Ptr) -> S { +impl S { + pub fn operator_add_1(this: Ptr, o: Ptr) -> S { return S { - v: ({ (*self).with(|__s| __s.v) } + { o.with(|__s| __s.v) }), + v: ({ this.with(|__s| __s.v) } + { o.with(|__s| __s.v) }), }; } - fn operator_sub_2(&self, o: Ptr) -> S { + pub fn operator_sub_2(this: Ptr, o: Ptr) -> S { return S { - v: ({ (*self).with(|__s| __s.v) } - { o.with(|__s| __s.v) }), + v: ({ this.with(|__s| __s.v) } - { o.with(|__s| __s.v) }), }; } - fn operator_mul(&self, o: Ptr) -> S { + pub fn operator_mul(this: Ptr, o: Ptr) -> S { return S { - v: ({ (*self).with(|__s| __s.v) } * { o.with(|__s| __s.v) }), + v: ({ this.with(|__s| __s.v) } * { o.with(|__s| __s.v) }), }; } - fn operator_div(&self, o: Ptr) -> S { + pub fn operator_div(this: Ptr, o: Ptr) -> S { return S { - v: ({ (*self).with(|__s| __s.v) } / { o.with(|__s| __s.v) }), + v: ({ this.with(|__s| __s.v) } / { o.with(|__s| __s.v) }), }; } - fn operator_rem(&self, o: Ptr) -> S { + pub fn operator_rem(this: Ptr, o: Ptr) -> S { return S { - v: ({ (*self).with(|__s| __s.v) } % { o.with(|__s| __s.v) }), + v: ({ this.with(|__s| __s.v) } % { o.with(|__s| __s.v) }), }; } - fn operator_pos_6(&self) -> S { + pub fn operator_pos_6(this: Ptr) -> S { return S { - v: (*self).with(|__s| __s.v), + v: this.with(|__s| __s.v), }; } - fn operator_neg_7(&self) -> S { + pub fn operator_neg_7(this: Ptr) -> S { return S { - v: -(*self).with(|__s| __s.v), + v: -this.with(|__s| __s.v), }; } - fn operator_inc_8(&self) -> Ptr { - field!((*self), v).with_mut(|__v| { + pub fn operator_inc_8(this: Ptr) -> Ptr { + field!(this, v).with_mut(|__v| { __v.prefix_inc(); }); - return (*self).clone(); + return (this).clone(); } - fn operator_post_inc_9(&self, mut _a0: i32) -> S { - let mut old: S = (*(*self).upgrade().deref()); - field!((*self), v).with_mut(|__v| { + pub fn operator_post_inc_9(this: Ptr, mut _a0: i32) -> S { + let mut old: S = (*this.upgrade().deref()); + field!(this, v).with_mut(|__v| { __v.prefix_inc(); }); return old; } - fn operator_dec_10(&self) -> Ptr { - field!((*self), v).with_mut(|__v| { + pub fn operator_dec_10(this: Ptr) -> Ptr { + field!(this, v).with_mut(|__v| { __v.prefix_dec(); }); - return (*self).clone(); + return (this).clone(); } - fn operator_post_dec_11(&self, mut _a0: i32) -> S { - let mut old: S = (*(*self).upgrade().deref()); - field!((*self), v).with_mut(|__v| { + pub fn operator_post_dec_11(this: Ptr, mut _a0: i32) -> S { + let mut old: S = (*this.upgrade().deref()); + field!(this, v).with_mut(|__v| { __v.prefix_dec(); }); return old; } } +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + let a: Value = Rc::new(RefCell::new(S { v: 7 })); + let b: Value = Rc::new(RefCell::new(S { v: 2 })); + assert!(({ ({ S::operator_add_1(a.as_pointer(), b.as_pointer(),) }).v } == 9)); + assert!(({ ({ S::operator_sub_2(a.as_pointer(), b.as_pointer(),) }).v } == 5)); + assert!(({ ({ S::operator_mul(a.as_pointer(), b.as_pointer(),) }).v } == 14)); + assert!(({ ({ S::operator_div(a.as_pointer(), b.as_pointer(),) }).v } == 3)); + assert!(({ ({ S::operator_rem(a.as_pointer(), b.as_pointer(),) }).v } == 1)); + assert!(({ ({ S::operator_pos_6(a.as_pointer(),) }).v } == 7)); + assert!(({ ({ S::operator_neg_7(a.as_pointer(),) }).v } == -7_i32)); + assert!((({ S::operator_inc_8(a.as_pointer(),) }).with(|__s| (__s).v) == 8)); + assert!(({ ({ S::operator_post_inc_9(a.as_pointer(), 0,) }).v } == 8)); + assert!(({ (*a.borrow()).v } == 9)); + assert!((({ S::operator_dec_10(a.as_pointer(),) }).with(|__s| (__s).v) == 8)); + assert!(({ ({ S::operator_post_dec_11(a.as_pointer(), 0,) }).v } == 8)); + assert!(({ (*a.borrow()).v } == 7)); + assert!( + (({ S::operator_inc_8(({ S::operator_inc_8(a.as_pointer(),) }),) }).with(|__s| (__s).v) + == 9) + ); + assert!( + ({ + ({ + let _o: Value = Rc::new(RefCell::new(S { v: 4 })); + S::operator_add_1( + Rc::new(RefCell::new(S { v: 3 })).as_pointer(), + _o.as_pointer(), + ) + }) + .v + } == 7) + ); + return 0; +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_bitwise_member.rs b/tests/unit/out/refcount/operator_bitwise_member.rs index aedd780f74..0599c2fb9c 100644 --- a/tests/unit/out/refcount/operator_bitwise_member.rs +++ b/tests/unit/out/refcount/operator_bitwise_member.rs @@ -23,59 +23,51 @@ pub struct S { #[offset(0)] pub v: u32, } -pub fn main() { - __cpp2rust_init_globals(); - libcc2rs::cpp2rust_exit(main_0()); -} -fn main_0() -> i32 { - let a: Value = Rc::new(RefCell::new(S { v: 12_u32 })); - let b: Value = Rc::new(RefCell::new(S { v: 10_u32 })); - assert!(({ ({ SImpl::operator_bitnot(&a.as_pointer(),) }).v } == !12_u32)); - assert!(({ ({ SImpl::operator_bitand(&a.as_pointer(), b.as_pointer(),) }).v } == 8_u32)); - assert!(({ ({ SImpl::operator_bitor(&a.as_pointer(), b.as_pointer(),) }).v } == 14_u32)); - assert!(({ ({ SImpl::operator_bitxor(&a.as_pointer(), b.as_pointer(),) }).v } == 6_u32)); - assert!(({ ({ SImpl::operator_shl(&a.as_pointer(), 2,) }).v } == 48_u32)); - assert!(({ ({ SImpl::operator_shr(&a.as_pointer(), 2,) }).v } == 3_u32)); - return 0; -} -pub trait SImpl { - fn operator_bitnot(&self) -> S; - fn operator_bitand(&self, o: Ptr) -> S; - fn operator_bitor(&self, o: Ptr) -> S; - fn operator_bitxor(&self, o: Ptr) -> S; - fn operator_shl(&self, n: i32) -> S; - fn operator_shr(&self, n: i32) -> S; -} -impl SImpl for Ptr { - fn operator_bitnot(&self) -> S { +impl S { + pub fn operator_bitnot(this: Ptr) -> S { return S { - v: !(*self).with(|__s| __s.v), + v: !this.with(|__s| __s.v), }; } - fn operator_bitand(&self, o: Ptr) -> S { + pub fn operator_bitand(this: Ptr, o: Ptr) -> S { return S { - v: ({ (*self).with(|__s| __s.v) } & { o.with(|__s| __s.v) }), + v: ({ this.with(|__s| __s.v) } & { o.with(|__s| __s.v) }), }; } - fn operator_bitor(&self, o: Ptr) -> S { + pub fn operator_bitor(this: Ptr, o: Ptr) -> S { return S { - v: ({ (*self).with(|__s| __s.v) } | { o.with(|__s| __s.v) }), + v: ({ this.with(|__s| __s.v) } | { o.with(|__s| __s.v) }), }; } - fn operator_bitxor(&self, o: Ptr) -> S { + pub fn operator_bitxor(this: Ptr, o: Ptr) -> S { return S { - v: ({ (*self).with(|__s| __s.v) } ^ { o.with(|__s| __s.v) }), + v: ({ this.with(|__s| __s.v) } ^ { o.with(|__s| __s.v) }), }; } - fn operator_shl(&self, mut n: i32) -> S { + pub fn operator_shl(this: Ptr, mut n: i32) -> S { return S { - v: ((*self).with(|__s| __s.v) << n), + v: (this.with(|__s| __s.v) << n), }; } - fn operator_shr(&self, mut n: i32) -> S { + pub fn operator_shr(this: Ptr, mut n: i32) -> S { return S { - v: ((*self).with(|__s| __s.v) >> n), + v: (this.with(|__s| __s.v) >> n), }; } } +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + let a: Value = Rc::new(RefCell::new(S { v: 12_u32 })); + let b: Value = Rc::new(RefCell::new(S { v: 10_u32 })); + assert!(({ ({ S::operator_bitnot(a.as_pointer(),) }).v } == !12_u32)); + assert!(({ ({ S::operator_bitand(a.as_pointer(), b.as_pointer(),) }).v } == 8_u32)); + assert!(({ ({ S::operator_bitor(a.as_pointer(), b.as_pointer(),) }).v } == 14_u32)); + assert!(({ ({ S::operator_bitxor(a.as_pointer(), b.as_pointer(),) }).v } == 6_u32)); + assert!(({ ({ S::operator_shl(a.as_pointer(), 2,) }).v } == 48_u32)); + assert!(({ ({ S::operator_shr(a.as_pointer(), 2,) }).v } == 3_u32)); + return 0; +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_comparison_defaulted.rs b/tests/unit/out/refcount/operator_comparison_defaulted.rs index 1e95674b36..35144fd896 100644 --- a/tests/unit/out/refcount/operator_comparison_defaulted.rs +++ b/tests/unit/out/refcount/operator_comparison_defaulted.rs @@ -25,9 +25,15 @@ pub struct Eq { #[offset(4)] pub b: i32, } +impl Eq { + pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }) + && ({ this.with(|__s| __s.b) } == { _a0.with(|__s| __s.b) }); + } +} impl CppEq for Eq { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - EqImpl::operator_eq(__lhs, __rhs.clone()) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + Eq::operator_eq(__lhs.clone(), __rhs.clone()) } } #[derive( @@ -49,14 +55,41 @@ pub struct Cmp { #[offset(4)] pub b: i32, } +impl Cmp { + pub fn operator_cmp(this: Ptr, _a0: Ptr) -> std::cmp::Ordering { + { + let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( + &(this.with(|__s| __s.a)), + &(_a0.with(|__s| __s.a)), + ))); + if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { + return (*cmp.borrow_mut()); + } + } + { + let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( + &(this.with(|__s| __s.b)), + &(_a0.with(|__s| __s.b)), + ))); + if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { + return (*cmp.borrow_mut()); + } + } + return (*libcc2rs::strong_ordering_equal().upgrade().deref()); + } + pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }) + && ({ this.with(|__s| __s.b) } == { _a0.with(|__s| __s.b) }); + } +} impl CppLess for Cmp { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - CmpImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Less + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + Cmp::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } impl CppEq for Cmp { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - CmpImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Equal + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + Cmp::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal } } #[derive( @@ -76,14 +109,31 @@ pub struct Both { #[offset(0)] pub a: i32, } +impl Both { + pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); + } + pub fn operator_cmp(this: Ptr, _a0: Ptr) -> std::cmp::Ordering { + { + let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( + &(this.with(|__s| __s.a)), + &(_a0.with(|__s| __s.a)), + ))); + if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { + return (*cmp.borrow_mut()); + } + } + return (*libcc2rs::strong_ordering_equal().upgrade().deref()); + } +} impl CppLess for Both { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - BothImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Less + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + Both::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } impl CppEq for Both { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - BothImpl::operator_eq(__lhs, __rhs.clone()) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + Both::operator_eq(__lhs.clone(), __rhs.clone()) } } #[derive( @@ -103,14 +153,28 @@ pub struct OrdOnly { #[offset(0)] pub a: i32, } +impl OrdOnly { + pub fn operator_cmp(this: Ptr, _a0: Ptr) -> std::cmp::Ordering { + { + let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( + &(this.with(|__s| __s.a)), + &(_a0.with(|__s| __s.a)), + ))); + if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { + return (*cmp.borrow_mut()); + } + } + return (*libcc2rs::strong_ordering_equal().upgrade().deref()); + } +} impl CppLess for OrdOnly { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - OrdOnlyImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Less + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + OrdOnly::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } impl CppEq for OrdOnly { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - OrdOnlyImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Equal + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + OrdOnly::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal } } #[derive( @@ -130,14 +194,31 @@ pub struct Inner { #[offset(0)] pub x: i32, } +impl Inner { + pub fn operator_cmp(this: Ptr, _a0: Ptr) -> std::cmp::Ordering { + { + let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( + &(this.with(|__s| __s.x)), + &(_a0.with(|__s| __s.x)), + ))); + if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { + return (*cmp.borrow_mut()); + } + } + return (*libcc2rs::strong_ordering_equal().upgrade().deref()); + } + pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.x) } == { _a0.with(|__s| __s.x) }); + } +} impl CppLess for Inner { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - InnerImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Less + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + Inner::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } impl CppEq for Inner { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - InnerImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Equal + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + Inner::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal } } #[derive( @@ -160,14 +241,40 @@ pub struct Outer { #[offset(4)] pub y: i32, } +impl Outer { + pub fn operator_cmp(this: Ptr, _a0: Ptr) -> std::cmp::Ordering { + { + let cmp: Value = Rc::new(RefCell::new( + ({ Inner::operator_cmp(field_ptr!(this, i), field_ptr!(_a0, i)) }), + )); + if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { + return (*cmp.borrow_mut()); + } + } + { + let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( + &(this.with(|__s| __s.y)), + &(_a0.with(|__s| __s.y)), + ))); + if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { + return (*cmp.borrow_mut()); + } + } + return (*libcc2rs::strong_ordering_equal().upgrade().deref()); + } + pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { + return ({ Inner::operator_eq(field_ptr!(this, i), field_ptr!(_a0, i)) }) + && ({ this.with(|__s| __s.y) } == { _a0.with(|__s| __s.y) }); + } +} impl CppLess for Outer { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - OuterImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Less + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + Outer::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } impl CppEq for Outer { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - OuterImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Equal + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + Outer::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal } } #[derive( @@ -187,14 +294,42 @@ pub struct Secondary { #[offset(0)] pub a: i32, } +impl Secondary { + pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); + } + pub fn operator_ne(this: Ptr, _a0: Ptr) -> bool { + return !({ Secondary::operator_eq((this).clone(), (_a0).clone()) }); + } + pub fn operator_cmp(this: Ptr, _a0: Ptr) -> std::cmp::Ordering { + { + let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( + &(this.with(|__s| __s.a)), + &(_a0.with(|__s| __s.a)), + ))); + if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { + return (*cmp.borrow_mut()); + } + } + return (*libcc2rs::strong_ordering_equal().upgrade().deref()); + } + pub fn operator_lt(this: Ptr, _a0: Ptr) -> bool { + return ({ Secondary::operator_cmp((this).clone(), (_a0).clone()) }) + == std::cmp::Ordering::Less; + } + pub fn operator_ge(this: Ptr, _a0: Ptr) -> bool { + return ({ Secondary::operator_cmp((this).clone(), (_a0).clone()) }) + != std::cmp::Ordering::Less; + } +} impl CppLess for Secondary { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - SecondaryImpl::operator_lt(__lhs, __rhs.clone()) + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + Secondary::operator_lt(__lhs.clone(), __rhs.clone()) } } impl CppEq for Secondary { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - SecondaryImpl::operator_eq(__lhs, __rhs.clone()) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + Secondary::operator_eq(__lhs.clone(), __rhs.clone()) } } #[derive( @@ -214,14 +349,31 @@ pub struct PtrMember { #[byte_size(8)] pub p: Ptr, } +impl PtrMember { + pub fn operator_cmp(this: Ptr, _a0: Ptr) -> std::cmp::Ordering { + { + let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( + &(this.with(|__s| __s.p.clone())), + &(_a0.with(|__s| __s.p.clone())), + ))); + if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { + return (*cmp.borrow_mut()); + } + } + return (*libcc2rs::strong_ordering_equal().upgrade().deref()); + } + pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.p.clone()) } == { _a0.with(|__s| __s.p.clone()) }); + } +} impl CppLess for PtrMember { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - PtrMemberImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Less + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + PtrMember::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } impl CppEq for PtrMember { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - PtrMemberImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Equal + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + PtrMember::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal } } pub fn main() { @@ -232,39 +384,34 @@ fn main_0() -> i32 { let e1: Value = Rc::new(RefCell::new(Eq { a: 1, b: 2 })); let e2: Value = Rc::new(RefCell::new(Eq { a: 1, b: 2 })); let e3: Value = Rc::new(RefCell::new(Eq { a: 1, b: 3 })); - assert!(({ EqImpl::operator_eq(&e1.as_pointer(), e2.as_pointer(),) })); - assert!(!({ EqImpl::operator_eq(&e1.as_pointer(), e3.as_pointer(),) })); + assert!(({ Eq::operator_eq(e1.as_pointer(), e2.as_pointer(),) })); + assert!(!({ Eq::operator_eq(e1.as_pointer(), e3.as_pointer(),) })); let c1: Value = Rc::new(RefCell::new(Cmp { a: 1, b: 2 })); let c2: Value = Rc::new(RefCell::new(Cmp { a: 1, b: 3 })); let c3: Value = Rc::new(RefCell::new(Cmp { a: 2, b: 0 })); let c4: Value = Rc::new(RefCell::new(Cmp { a: 1, b: 9 })); + assert!(({ Cmp::operator_cmp(c1.as_pointer(), c2.as_pointer(),) }) == std::cmp::Ordering::Less); assert!( - ({ CmpImpl::operator_cmp(&c1.as_pointer(), c2.as_pointer(),) }) == std::cmp::Ordering::Less + ({ Cmp::operator_cmp(c3.as_pointer(), c4.as_pointer(),) }) == std::cmp::Ordering::Greater ); + assert!(({ Cmp::operator_eq(c1.as_pointer(), c1.as_pointer(),) })); assert!( - ({ CmpImpl::operator_cmp(&c3.as_pointer(), c4.as_pointer(),) }) - == std::cmp::Ordering::Greater - ); - assert!(({ CmpImpl::operator_eq(&c1.as_pointer(), c1.as_pointer(),) })); - assert!( - ({ CmpImpl::operator_cmp(&c1.as_pointer(), c2.as_pointer(),) }) + ({ Cmp::operator_cmp(c1.as_pointer(), c2.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_less().upgrade().deref()) }) ); let b1: Value = Rc::new(RefCell::new(Both { a: 1 })); let b2: Value = Rc::new(RefCell::new(Both { a: 2 })); assert!( - ({ BothImpl::operator_cmp(&b1.as_pointer(), b2.as_pointer(),) }) - == std::cmp::Ordering::Less + ({ Both::operator_cmp(b1.as_pointer(), b2.as_pointer(),) }) == std::cmp::Ordering::Less ); - assert!(({ BothImpl::operator_eq(&b2.as_pointer(), b2.as_pointer(),) })); + assert!(({ Both::operator_eq(b2.as_pointer(), b2.as_pointer(),) })); let o1: Value = Rc::new(RefCell::new(OrdOnly { a: 1 })); let o2: Value = Rc::new(RefCell::new(OrdOnly { a: 2 })); assert!( - ({ OrdOnlyImpl::operator_cmp(&o1.as_pointer(), o2.as_pointer(),) }) - == std::cmp::Ordering::Less + ({ OrdOnly::operator_cmp(o1.as_pointer(), o2.as_pointer(),) }) == std::cmp::Ordering::Less ); assert!( - ({ OrdOnlyImpl::operator_cmp(&o2.as_pointer(), o1.as_pointer(),) }) + ({ OrdOnly::operator_cmp(o2.as_pointer(), o1.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_greater().upgrade().deref()) }) ); let x1: Value = Rc::new(RefCell::new(Outer { @@ -280,20 +427,19 @@ fn main_0() -> i32 { y: 9, })); assert!( - ({ OuterImpl::operator_cmp(&x1.as_pointer(), x2.as_pointer(),) }) - == std::cmp::Ordering::Less + ({ Outer::operator_cmp(x1.as_pointer(), x2.as_pointer(),) }) == std::cmp::Ordering::Less ); - assert!(({ OuterImpl::operator_eq(&x1.as_pointer(), x3.as_pointer(),) })); + assert!(({ Outer::operator_eq(x1.as_pointer(), x3.as_pointer(),) })); assert!( - ({ OuterImpl::operator_cmp(&x2.as_pointer(), x1.as_pointer(),) }) + ({ Outer::operator_cmp(x2.as_pointer(), x1.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_greater().upgrade().deref()) }) ); let s1: Value = Rc::new(RefCell::new(Secondary { a: 1 })); let s2: Value = Rc::new(RefCell::new(Secondary { a: 2 })); - assert!(({ SecondaryImpl::operator_ne(&s1.as_pointer(), s2.as_pointer(),) })); - assert!(({ SecondaryImpl::operator_lt(&s1.as_pointer(), s2.as_pointer(),) })); - assert!(({ SecondaryImpl::operator_ge(&s2.as_pointer(), s1.as_pointer(),) })); - assert!(!({ SecondaryImpl::operator_lt(&s2.as_pointer(), s1.as_pointer(),) })); + assert!(({ Secondary::operator_ne(s1.as_pointer(), s2.as_pointer(),) })); + assert!(({ Secondary::operator_lt(s1.as_pointer(), s2.as_pointer(),) })); + assert!(({ Secondary::operator_ge(s2.as_pointer(), s1.as_pointer(),) })); + assert!(!({ Secondary::operator_lt(s2.as_pointer(), s1.as_pointer(),) })); let arr: Value> = Rc::new(RefCell::new(Box::new([0, 0]))); let p1: Value = Rc::new(RefCell::new(PtrMember { p: arr.decay() })); let p2: Value = Rc::new(RefCell::new(PtrMember { @@ -301,199 +447,14 @@ fn main_0() -> i32 { })); let p3: Value = Rc::new(RefCell::new(PtrMember { p: arr.decay() })); assert!( - ({ PtrMemberImpl::operator_cmp(&p1.as_pointer(), p2.as_pointer(),) }) + ({ PtrMember::operator_cmp(p1.as_pointer(), p2.as_pointer(),) }) == std::cmp::Ordering::Less ); - assert!(({ PtrMemberImpl::operator_eq(&p1.as_pointer(), p3.as_pointer(),) })); + assert!(({ PtrMember::operator_eq(p1.as_pointer(), p3.as_pointer(),) })); assert!( - ({ PtrMemberImpl::operator_cmp(&p2.as_pointer(), p1.as_pointer(),) }) + ({ PtrMember::operator_cmp(p2.as_pointer(), p1.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_greater().upgrade().deref()) }) ); return 0; } -pub trait BothImpl { - fn operator_eq(&self, _a0: Ptr) -> bool; - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering; -} -impl BothImpl for Ptr { - fn operator_eq(&self, _a0: Ptr) -> bool { - return ({ (*self).with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); - } - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering { - { - let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( - &((*self).with(|__s| __s.a)), - &(_a0.with(|__s| __s.a)), - ))); - if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { - return (*cmp.borrow_mut()); - } - } - return (*libcc2rs::strong_ordering_equal().upgrade().deref()); - } -} -pub trait CmpImpl { - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering; - fn operator_eq(&self, _a0: Ptr) -> bool; -} -impl CmpImpl for Ptr { - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering { - { - let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( - &((*self).with(|__s| __s.a)), - &(_a0.with(|__s| __s.a)), - ))); - if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { - return (*cmp.borrow_mut()); - } - } - { - let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( - &((*self).with(|__s| __s.b)), - &(_a0.with(|__s| __s.b)), - ))); - if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { - return (*cmp.borrow_mut()); - } - } - return (*libcc2rs::strong_ordering_equal().upgrade().deref()); - } - fn operator_eq(&self, _a0: Ptr) -> bool { - return ({ (*self).with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }) - && ({ (*self).with(|__s| __s.b) } == { _a0.with(|__s| __s.b) }); - } -} -pub trait EqImpl { - fn operator_eq(&self, _a0: Ptr) -> bool; -} -impl EqImpl for Ptr { - fn operator_eq(&self, _a0: Ptr) -> bool { - return ({ (*self).with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }) - && ({ (*self).with(|__s| __s.b) } == { _a0.with(|__s| __s.b) }); - } -} -pub trait InnerImpl { - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering; - fn operator_eq(&self, _a0: Ptr) -> bool; -} -impl InnerImpl for Ptr { - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering { - { - let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( - &((*self).with(|__s| __s.x)), - &(_a0.with(|__s| __s.x)), - ))); - if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { - return (*cmp.borrow_mut()); - } - } - return (*libcc2rs::strong_ordering_equal().upgrade().deref()); - } - fn operator_eq(&self, _a0: Ptr) -> bool { - return ({ (*self).with(|__s| __s.x) } == { _a0.with(|__s| __s.x) }); - } -} -pub trait OrdOnlyImpl { - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering; -} -impl OrdOnlyImpl for Ptr { - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering { - { - let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( - &((*self).with(|__s| __s.a)), - &(_a0.with(|__s| __s.a)), - ))); - if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { - return (*cmp.borrow_mut()); - } - } - return (*libcc2rs::strong_ordering_equal().upgrade().deref()); - } -} -pub trait OuterImpl { - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering; - fn operator_eq(&self, _a0: Ptr) -> bool; -} -impl OuterImpl for Ptr { - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering { - { - let cmp: Value = Rc::new(RefCell::new( - ({ InnerImpl::operator_cmp(&field_ptr!((*self), i), field_ptr!(_a0, i)) }), - )); - if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { - return (*cmp.borrow_mut()); - } - } - { - let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( - &((*self).with(|__s| __s.y)), - &(_a0.with(|__s| __s.y)), - ))); - if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { - return (*cmp.borrow_mut()); - } - } - return (*libcc2rs::strong_ordering_equal().upgrade().deref()); - } - fn operator_eq(&self, _a0: Ptr) -> bool { - return ({ InnerImpl::operator_eq(&field_ptr!((*self), i), field_ptr!(_a0, i)) }) - && ({ (*self).with(|__s| __s.y) } == { _a0.with(|__s| __s.y) }); - } -} -pub trait PtrMemberImpl { - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering; - fn operator_eq(&self, _a0: Ptr) -> bool; -} -impl PtrMemberImpl for Ptr { - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering { - { - let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( - &((*self).with(|__s| __s.p.clone())), - &(_a0.with(|__s| __s.p.clone())), - ))); - if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { - return (*cmp.borrow_mut()); - } - } - return (*libcc2rs::strong_ordering_equal().upgrade().deref()); - } - fn operator_eq(&self, _a0: Ptr) -> bool { - return ({ (*self).with(|__s| __s.p.clone()) } == { _a0.with(|__s| __s.p.clone()) }); - } -} -pub trait SecondaryImpl { - fn operator_eq(&self, _a0: Ptr) -> bool; - fn operator_ne(&self, _a0: Ptr) -> bool; - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering; - fn operator_lt(&self, _a0: Ptr) -> bool; - fn operator_ge(&self, _a0: Ptr) -> bool; -} -impl SecondaryImpl for Ptr { - fn operator_eq(&self, _a0: Ptr) -> bool { - return ({ (*self).with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); - } - fn operator_ne(&self, _a0: Ptr) -> bool { - return !({ SecondaryImpl::operator_eq(&(*self), (_a0).clone()) }); - } - fn operator_cmp(&self, _a0: Ptr) -> std::cmp::Ordering { - { - let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( - &((*self).with(|__s| __s.a)), - &(_a0.with(|__s| __s.a)), - ))); - if !(({ (*cmp.borrow()) }) == std::cmp::Ordering::Equal) { - return (*cmp.borrow_mut()); - } - } - return (*libcc2rs::strong_ordering_equal().upgrade().deref()); - } - fn operator_lt(&self, _a0: Ptr) -> bool { - return ({ SecondaryImpl::operator_cmp(&(*self), (_a0).clone()) }) - == std::cmp::Ordering::Less; - } - fn operator_ge(&self, _a0: Ptr) -> bool { - return ({ SecondaryImpl::operator_cmp(&(*self), (_a0).clone()) }) - != std::cmp::Ordering::Less; - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_comparison_free.rs b/tests/unit/out/refcount/operator_comparison_free.rs index 1884dc7183..a3cce0c780 100644 --- a/tests/unit/out/refcount/operator_comparison_free.rs +++ b/tests/unit/out/refcount/operator_comparison_free.rs @@ -24,12 +24,12 @@ pub struct S { pub v: i32, } impl CppLess for S { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { operator_lt_0(__lhs.clone(), __rhs.clone()) } } impl CppEq for S { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_1(__lhs.clone(), __rhs.clone()) } } @@ -75,12 +75,12 @@ pub struct V { pub v: i32, } impl CppLess for V { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { operator_lt_8(__lhs.read(), __rhs.read()) } } impl CppEq for V { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_9(__lhs.read(), __rhs.read()) } } diff --git a/tests/unit/out/refcount/operator_comparison_member.rs b/tests/unit/out/refcount/operator_comparison_member.rs index ee3014ac10..a0088dd538 100644 --- a/tests/unit/out/refcount/operator_comparison_member.rs +++ b/tests/unit/out/refcount/operator_comparison_member.rs @@ -23,14 +23,37 @@ pub struct S { #[offset(0)] pub v: i32, } +impl S { + pub fn operator_eq(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } + pub fn operator_ne(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } != { o.with(|__s| __s.v) }); + } + pub fn operator_lt_3(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } < { o.with(|__s| __s.v) }); + } + pub fn operator_gt(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } > { o.with(|__s| __s.v) }); + } + pub fn operator_le(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } <= { o.with(|__s| __s.v) }); + } + pub fn operator_ge(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } >= { o.with(|__s| __s.v) }); + } + pub fn operator_lt_7(this: Ptr, mut o: i32) -> bool { + return (this.with(|__s| __s.v) < o); + } +} impl CppLess for S { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - SImpl::operator_lt_3(__lhs, __rhs.clone()) + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + S::operator_lt_3(__lhs.clone(), __rhs.clone()) } } impl CppEq for S { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - SImpl::operator_eq(__lhs, __rhs.clone()) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + S::operator_eq(__lhs.clone(), __rhs.clone()) } } pub fn main() { @@ -41,46 +64,14 @@ fn main_0() -> i32 { let a: Value = Rc::new(RefCell::new(S { v: 1 })); let b: Value = Rc::new(RefCell::new(S { v: 2 })); let c: Value = Rc::new(RefCell::new(S { v: 1 })); - assert!(({ SImpl::operator_eq(&a.as_pointer(), c.as_pointer(),) })); - assert!(({ SImpl::operator_ne(&a.as_pointer(), b.as_pointer(),) })); - assert!(({ SImpl::operator_lt_3(&a.as_pointer(), b.as_pointer(),) })); - assert!(({ SImpl::operator_gt(&b.as_pointer(), a.as_pointer(),) })); - assert!(({ SImpl::operator_le(&a.as_pointer(), c.as_pointer(),) })); - assert!(({ SImpl::operator_ge(&a.as_pointer(), c.as_pointer(),) })); - assert!(!({ SImpl::operator_lt_3(&b.as_pointer(), a.as_pointer(),) })); - assert!(({ SImpl::operator_lt_7(&a.as_pointer(), 5,) })); + assert!(({ S::operator_eq(a.as_pointer(), c.as_pointer(),) })); + assert!(({ S::operator_ne(a.as_pointer(), b.as_pointer(),) })); + assert!(({ S::operator_lt_3(a.as_pointer(), b.as_pointer(),) })); + assert!(({ S::operator_gt(b.as_pointer(), a.as_pointer(),) })); + assert!(({ S::operator_le(a.as_pointer(), c.as_pointer(),) })); + assert!(({ S::operator_ge(a.as_pointer(), c.as_pointer(),) })); + assert!(!({ S::operator_lt_3(b.as_pointer(), a.as_pointer(),) })); + assert!(({ S::operator_lt_7(a.as_pointer(), 5,) })); return 0; } -pub trait SImpl { - fn operator_eq(&self, o: Ptr) -> bool; - fn operator_ne(&self, o: Ptr) -> bool; - fn operator_lt_3(&self, o: Ptr) -> bool; - fn operator_gt(&self, o: Ptr) -> bool; - fn operator_le(&self, o: Ptr) -> bool; - fn operator_ge(&self, o: Ptr) -> bool; - fn operator_lt_7(&self, o: i32) -> bool; -} -impl SImpl for Ptr { - fn operator_eq(&self, o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } - fn operator_ne(&self, o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.v) } != { o.with(|__s| __s.v) }); - } - fn operator_lt_3(&self, o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.v) } < { o.with(|__s| __s.v) }); - } - fn operator_gt(&self, o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.v) } > { o.with(|__s| __s.v) }); - } - fn operator_le(&self, o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.v) } <= { o.with(|__s| __s.v) }); - } - fn operator_ge(&self, o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.v) } >= { o.with(|__s| __s.v) }); - } - fn operator_lt_7(&self, mut o: i32) -> bool { - return ((*self).with(|__s| __s.v) < o); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_comparison_mixed.rs b/tests/unit/out/refcount/operator_comparison_mixed.rs index d1cd37776b..999d5b316a 100644 --- a/tests/unit/out/refcount/operator_comparison_mixed.rs +++ b/tests/unit/out/refcount/operator_comparison_mixed.rs @@ -23,6 +23,26 @@ pub struct S { #[offset(0)] pub v: i32, } +impl S { + pub fn operator_eq(this: Ptr, mut o: i32) -> bool { + return (this.with(|__s| __s.v) == o); + } + pub fn operator_ne(this: Ptr, mut o: i32) -> bool { + return (this.with(|__s| __s.v) != o); + } + pub fn operator_lt(this: Ptr, mut o: i32) -> bool { + return (this.with(|__s| __s.v) < o); + } + pub fn operator_gt(this: Ptr, mut o: f64) -> bool { + return ((this.with(|__s| __s.v) as f64) > o); + } + pub fn operator_le(this: Ptr, mut o: i64) -> bool { + return ((this.with(|__s| __s.v) as i64) <= o); + } + pub fn operator_ge(this: Ptr, mut o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } >= { (((o.read()) as i32) - (('0' as i8) as i32)) }); + } +} pub fn operator_eq_0(mut a: i32, b: Ptr) -> bool { return ({ a } == { b.with(|__s| __s.v) }); } @@ -51,12 +71,12 @@ pub fn main() { fn main_0() -> i32 { let s: Value = Rc::new(RefCell::new(S { v: 5 })); let cs: Ptr = s.as_pointer(); - assert!(({ SImpl::operator_eq(&cs, 5,) })); - assert!(({ SImpl::operator_ne(&cs, 4,) })); - assert!(({ SImpl::operator_lt(&cs, 6,) })); - assert!(({ SImpl::operator_gt(&cs, 4.5_f64,) })); - assert!(({ SImpl::operator_le(&cs, 5_i64,) })); - assert!(({ SImpl::operator_ge(&cs, Ptr::::from_string_literal(b"3"),) })); + assert!(({ S::operator_eq((cs).clone(), 5,) })); + assert!(({ S::operator_ne((cs).clone(), 4,) })); + assert!(({ S::operator_lt((cs).clone(), 6,) })); + assert!(({ S::operator_gt((cs).clone(), 4.5_f64,) })); + assert!(({ S::operator_le((cs).clone(), 5_i64,) })); + assert!(({ S::operator_ge((cs).clone(), Ptr::::from_string_literal(b"3"),) })); assert!(({ operator_eq_0(5, s.as_pointer(),) })); assert!(({ operator_ne_1(4, s.as_pointer(),) })); assert!(({ operator_lt_2(4, s.as_pointer(),) })); @@ -67,32 +87,4 @@ fn main_0() -> i32 { assert!(!({ operator_lt_6(s.as_pointer(), 6,) })); return 0; } -pub trait SImpl { - fn operator_eq(&self, o: i32) -> bool; - fn operator_ne(&self, o: i32) -> bool; - fn operator_lt(&self, o: i32) -> bool; - fn operator_gt(&self, o: f64) -> bool; - fn operator_le(&self, o: i64) -> bool; - fn operator_ge(&self, o: Ptr) -> bool; -} -impl SImpl for Ptr { - fn operator_eq(&self, mut o: i32) -> bool { - return ((*self).with(|__s| __s.v) == o); - } - fn operator_ne(&self, mut o: i32) -> bool { - return ((*self).with(|__s| __s.v) != o); - } - fn operator_lt(&self, mut o: i32) -> bool { - return ((*self).with(|__s| __s.v) < o); - } - fn operator_gt(&self, mut o: f64) -> bool { - return (((*self).with(|__s| __s.v) as f64) > o); - } - fn operator_le(&self, mut o: i64) -> bool { - return (((*self).with(|__s| __s.v) as i64) <= o); - } - fn operator_ge(&self, mut o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.v) } >= { (((o.read()) as i32) - (('0' as i8) as i32)) }); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_comparison_nonbool.rs b/tests/unit/out/refcount/operator_comparison_nonbool.rs index 95c9dae3de..1229dd8525 100644 --- a/tests/unit/out/refcount/operator_comparison_nonbool.rs +++ b/tests/unit/out/refcount/operator_comparison_nonbool.rs @@ -24,12 +24,12 @@ pub struct X { pub v: i32, } impl CppLess for X { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { ((operator_lt_0(__lhs.read(), __rhs.read())) != 0) } } impl CppEq for X { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { ((operator_eq_1(__lhs.read(), __rhs.read())) != 0) } } @@ -85,6 +85,13 @@ pub struct Custom { #[offset(0)] pub v: i32, } +impl Custom { + pub fn operator_cmp(this: Ptr, o: Ptr) -> Result { + return Result { + r: ({ this.with(|__s| __s.v) } - { o.with(|__s| __s.v) }), + }; + } +} #[derive( Copy, Clone, @@ -102,14 +109,35 @@ pub struct Mixed { #[offset(0)] pub v: i32, } +impl Mixed { + pub fn operator_cmp(this: Ptr, o: Ptr) -> Result { + return Result { + r: ({ this.with(|__s| __s.v) } - { o.with(|__s| __s.v) }), + }; + } + pub fn operator_lt(this: Ptr, o: Ptr) -> i32 { + return if ({ this.with(|__s| __s.v) } < { o.with(|__s| __s.v) }) { + 8 + } else { + 0 + }; + } + pub fn operator_eq(this: Ptr, o: Ptr) -> i32 { + return if ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }) { + 9 + } else { + 0 + }; + } +} impl CppLess for Mixed { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - ((MixedImpl::operator_lt(__lhs, __rhs.clone())) != 0) + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + ((Mixed::operator_lt(__lhs.clone(), __rhs.clone())) != 0) } } impl CppEq for Mixed { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - ((MixedImpl::operator_eq(__lhs, __rhs.clone())) != 0) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + ((Mixed::operator_eq(__lhs.clone(), __rhs.clone())) != 0) } } #[derive( @@ -131,6 +159,14 @@ pub struct MyBool { #[offset(0)] pub value: bool, } +impl MyBool { + pub fn construct(this: Ptr, mut v: bool) { + field!(this, value).write(v); + } + pub fn to_bool(this: Ptr) -> bool { + return this.with(|__s| __s.value); + } +} #[derive( Copy, Clone, @@ -149,32 +185,32 @@ pub struct Boolish { pub v: i32, } impl CppLess for Boolish { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { { let __cmp = operator_lt_6(__lhs.read(), __rhs.read()); - MyBoolImpl::to_bool(&Rc::new(RefCell::new(__cmp)).as_pointer()) + MyBool::to_bool(Rc::new(RefCell::new(__cmp)).as_pointer()) } } } impl CppEq for Boolish { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { { let __cmp = operator_eq_7(__lhs.read(), __rhs.read()); - MyBoolImpl::to_bool(&Rc::new(RefCell::new(__cmp)).as_pointer()) + MyBool::to_bool(Rc::new(RefCell::new(__cmp)).as_pointer()) } } } pub fn operator_eq_7(mut a: Boolish, mut b: Boolish) -> MyBool { return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - MyBoolImpl::construct(&__v.as_pointer(), (a.v == b.v)); + MyBool::construct(__v.as_pointer(), (a.v == b.v)); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } pub fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { return { let __v: Value = Rc::new(RefCell::new(::zero_init())); - MyBoolImpl::construct(&__v.as_pointer(), (a.v < b.v)); + MyBool::construct(__v.as_pointer(), (a.v < b.v)); Rc::try_unwrap(__v).ok().unwrap().into_inner() }; } @@ -196,10 +232,18 @@ pub struct RefBool { #[offset(0)] pub value: bool, } +impl RefBool { + pub fn construct(this: Ptr, mut v: bool) { + field!(this, value).write(v); + } + pub fn to_bool(this: Ptr) -> bool { + return this.with(|__s| __s.value); + } +} thread_local!( pub static ref_true_8: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - RefBoolImpl::construct(&__v.as_pointer(), true); + RefBool::construct(__v.as_pointer(), true); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); ); @@ -220,11 +264,16 @@ pub struct RefInt { #[offset(0)] pub v: i32, } +impl RefInt { + pub fn operator_eq(this: Ptr, _a0: Ptr) -> Ptr { + return ref_true_8.with(|v| v.as_pointer()); + } +} impl CppEq for RefInt { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { { - let __cmp = RefIntImpl::operator_eq(__lhs, __rhs.clone()); - RefBoolImpl::to_bool(&__cmp) + let __cmp = RefInt::operator_eq(__lhs.clone(), __rhs.clone()); + RefBool::to_bool(__cmp.clone()) } } } @@ -257,12 +306,12 @@ fn main_0() -> i32 { ); let p: Value = Rc::new(RefCell::new(Custom { v: 5 })); let q: Value = Rc::new(RefCell::new(Custom { v: 2 })); - let mut r: Result = ({ CustomImpl::operator_cmp(&p.as_pointer(), q.as_pointer()) }); + let mut r: Result = ({ Custom::operator_cmp(p.as_pointer(), q.as_pointer()) }); assert!((r.r == 3)); let m: Value = Rc::new(RefCell::new(Mixed { v: 4 })); let n: Value = Rc::new(RefCell::new(Mixed { v: 4 })); - assert!((({ MixedImpl::operator_eq(&m.as_pointer(), n.as_pointer(),) }) == 9)); - assert!(({ ({ MixedImpl::operator_cmp(&m.as_pointer(), n.as_pointer(),) }).r } == 0)); + assert!((({ Mixed::operator_eq(m.as_pointer(), n.as_pointer(),) }) == 9)); + assert!(({ ({ Mixed::operator_cmp(m.as_pointer(), n.as_pointer(),) }).r } == 0)); let ms: Value> = Rc::new(RefCell::new(Box::new([ Mixed { v: 6 }, Mixed { v: 4 }, @@ -279,20 +328,18 @@ fn main_0() -> i32 { (({ (*ms.borrow())[(0) as usize].v } == 4) && ({ (*ms.borrow())[(1) as usize].v } == 5)) && ({ (*ms.borrow())[(2) as usize].v } == 6) ); - assert!((({ MixedImpl::operator_lt(&ms.decay().offset(0), ms.decay().offset(1),) }) == 8)); + assert!((({ Mixed::operator_lt(ms.decay().offset(0), ms.decay().offset(1),) }) == 8)); let mut b1: Boolish = Boolish { v: 1 }; let mut b2: Boolish = Boolish { v: 2 }; assert!( ({ - MyBoolImpl::to_bool( - &Rc::new(RefCell::new(({ operator_eq_7(b1, Boolish { v: 1 }) }))).as_pointer(), + MyBool::to_bool( + Rc::new(RefCell::new(({ operator_eq_7(b1, Boolish { v: 1 }) }))).as_pointer(), ) }) ); assert!( - !({ - MyBoolImpl::to_bool(&Rc::new(RefCell::new(({ operator_lt_6(b2, b1) }))).as_pointer()) - }) + !({ MyBool::to_bool(Rc::new(RefCell::new(({ operator_lt_6(b2, b1,) }))).as_pointer(),) }) ); let mut lt: MyBool = ({ operator_lt_6(b1, b2) }); assert!(lt.value); @@ -315,11 +362,7 @@ fn main_0() -> i32 { let ri1: Value = Rc::new(RefCell::new(RefInt { v: 1 })); let ri2: Value = Rc::new(RefCell::new(RefInt { v: 2 })); assert!( - ({ - RefBoolImpl::to_bool( - &({ RefIntImpl::operator_eq(&ri1.as_pointer(), ri2.as_pointer()) }), - ) - }) + ({ RefBool::to_bool(({ RefInt::operator_eq(ri1.as_pointer(), ri2.as_pointer(),) }),) }) ); let ris: Value> = Rc::new(RefCell::new(Box::new([RefInt { v: 1 }, RefInt { v: 2 }]))); @@ -327,7 +370,7 @@ fn main_0() -> i32 { ({ let mut __tmp_3 = { ris.decay().offset((2) as isize) }; let mut __it = ris.decay(); - while __it != __tmp_3 && !CppEq::equal(&__it.iter_deref(), &ri2.as_pointer()) { + while __it != __tmp_3 && !CppEq::equal(__it.iter_deref(), ri2.as_pointer().clone()) { __it.iter_inc(); } __it @@ -335,74 +378,6 @@ fn main_0() -> i32 { ); return 0; } -pub trait CustomImpl { - fn operator_cmp(&self, o: Ptr) -> Result; -} -impl CustomImpl for Ptr { - fn operator_cmp(&self, o: Ptr) -> Result { - return Result { - r: ({ (*self).with(|__s| __s.v) } - { o.with(|__s| __s.v) }), - }; - } -} -pub trait MixedImpl { - fn operator_cmp(&self, o: Ptr) -> Result; - fn operator_lt(&self, o: Ptr) -> i32; - fn operator_eq(&self, o: Ptr) -> i32; -} -impl MixedImpl for Ptr { - fn operator_cmp(&self, o: Ptr) -> Result { - return Result { - r: ({ (*self).with(|__s| __s.v) } - { o.with(|__s| __s.v) }), - }; - } - fn operator_lt(&self, o: Ptr) -> i32 { - return if ({ (*self).with(|__s| __s.v) } < { o.with(|__s| __s.v) }) { - 8 - } else { - 0 - }; - } - fn operator_eq(&self, o: Ptr) -> i32 { - return if ({ (*self).with(|__s| __s.v) } == { o.with(|__s| __s.v) }) { - 9 - } else { - 0 - }; - } -} -pub trait MyBoolImpl { - fn construct(&self, v: bool); - fn to_bool(&self) -> bool; -} -impl MyBoolImpl for Ptr { - fn construct(&self, mut v: bool) { - field!((*self), value).write(v); - } - fn to_bool(&self) -> bool { - return (*self).with(|__s| __s.value); - } -} -pub trait RefBoolImpl { - fn construct(&self, v: bool); - fn to_bool(&self) -> bool; -} -impl RefBoolImpl for Ptr { - fn construct(&self, mut v: bool) { - field!((*self), value).write(v); - } - fn to_bool(&self) -> bool { - return (*self).with(|__s| __s.value); - } -} -pub trait RefIntImpl { - fn operator_eq(&self, _a0: Ptr) -> Ptr; -} -impl RefIntImpl for Ptr { - fn operator_eq(&self, _a0: Ptr) -> Ptr { - return ref_true_8.with(|v| v.as_pointer()); - } -} pub fn __cpp2rust_init_globals() { let _ = ref_true_8.with(|_| ()); } diff --git a/tests/unit/out/refcount/operator_comparison_noncopyable.rs b/tests/unit/out/refcount/operator_comparison_noncopyable.rs index 5592587956..7edce8d200 100644 --- a/tests/unit/out/refcount/operator_comparison_noncopyable.rs +++ b/tests/unit/out/refcount/operator_comparison_noncopyable.rs @@ -29,13 +29,18 @@ pub struct S { #[offset(0)] data_: i32, } +impl S { + pub fn construct(this: Ptr, mut data: i32) { + field!(this, data_).write(data); + } +} impl CppLess for S { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { operator_lt_1(__lhs.clone(), __rhs.clone()) } } impl CppEq for S { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_0(__lhs.clone(), __rhs.clone()) } } @@ -52,12 +57,4 @@ fn main_0() -> i32 { assert!(!({ operator_lt_1(b.as_pointer(), a.as_pointer(),) })); return 0; } -pub trait SImpl { - fn construct(&self, data: i32); -} -impl SImpl for Ptr { - fn construct(&self, mut data: i32) { - field!((*self), data_).write(data); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_compound_assignment_member.rs b/tests/unit/out/refcount/operator_compound_assignment_member.rs index faf75dcb59..74ff0168e0 100644 --- a/tests/unit/out/refcount/operator_compound_assignment_member.rs +++ b/tests/unit/out/refcount/operator_compound_assignment_member.rs @@ -23,6 +23,65 @@ pub struct S { #[offset(0)] pub v: u32, } +impl S { + pub fn operator_assign_1(this: Ptr, mut n: u32) -> Ptr { + field!(this, v).write(n); + return (this).clone(); + } + pub fn operator_add_assign(this: Ptr, o: Ptr) -> Ptr { + field!(this, v).write({ (this.with(|__s| __s.v)).wrapping_add(o.with(|__s| __s.v)) }); + return (this).clone(); + } + pub fn operator_sub_assign(this: Ptr, o: Ptr) -> Ptr { + field!(this, v).write({ (this.with(|__s| __s.v)).wrapping_sub(o.with(|__s| __s.v)) }); + return (this).clone(); + } + pub fn operator_mul_assign(this: Ptr, o: Ptr) -> Ptr { + field!(this, v).write({ (this.with(|__s| __s.v)).wrapping_mul(o.with(|__s| __s.v)) }); + return (this).clone(); + } + pub fn operator_div_assign(this: Ptr, o: Ptr) -> Ptr { + field!(this, v).write({ (this.with(|__s| __s.v)).wrapping_div(o.with(|__s| __s.v)) }); + return (this).clone(); + } + pub fn operator_rem_assign(this: Ptr, o: Ptr) -> Ptr { + field!(this, v).write({ (this.with(|__s| __s.v)).wrapping_rem(o.with(|__s| __s.v)) }); + return (this).clone(); + } + pub fn operator_bitand_assign(this: Ptr, o: Ptr) -> Ptr { + { + let __rhs = o.with(|__s| __s.v); + field!(this, v).with_mut(|__v| *__v = *__v & __rhs) + }; + return (this).clone(); + } + pub fn operator_bitor_assign(this: Ptr, o: Ptr) -> Ptr { + { + let __rhs = o.with(|__s| __s.v); + field!(this, v).with_mut(|__v| *__v = *__v | __rhs) + }; + return (this).clone(); + } + pub fn operator_bitxor_assign(this: Ptr, o: Ptr) -> Ptr { + { + let __rhs = o.with(|__s| __s.v); + field!(this, v).with_mut(|__v| *__v = *__v ^ __rhs) + }; + return (this).clone(); + } + pub fn operator_shl_assign(this: Ptr, mut n: i32) -> Ptr { + { + field!(this, v).with_mut(|__v| *__v = *__v << n) + }; + return (this).clone(); + } + pub fn operator_shr_assign(this: Ptr, mut n: i32) -> Ptr { + { + field!(this, v).with_mut(|__v| *__v = *__v >> n) + }; + return (this).clone(); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -30,111 +89,39 @@ pub fn main() { fn main_0() -> i32 { let a: Value = Rc::new(RefCell::new(S { v: 6_u32 })); let b: Value = Rc::new(RefCell::new(S { v: 4_u32 })); - SImpl::operator_add_assign(&a.as_pointer(), b.as_pointer()); + S::operator_add_assign(a.as_pointer(), b.as_pointer()); assert!(({ (*a.borrow()).v } == 10_u32)); - SImpl::operator_sub_assign(&a.as_pointer(), b.as_pointer()); + S::operator_sub_assign(a.as_pointer(), b.as_pointer()); assert!(({ (*a.borrow()).v } == 6_u32)); - SImpl::operator_mul_assign(&a.as_pointer(), b.as_pointer()); + S::operator_mul_assign(a.as_pointer(), b.as_pointer()); assert!(({ (*a.borrow()).v } == 24_u32)); - SImpl::operator_div_assign(&a.as_pointer(), b.as_pointer()); + S::operator_div_assign(a.as_pointer(), b.as_pointer()); assert!(({ (*a.borrow()).v } == 6_u32)); - SImpl::operator_rem_assign(&a.as_pointer(), b.as_pointer()); + S::operator_rem_assign(a.as_pointer(), b.as_pointer()); assert!(({ (*a.borrow()).v } == 2_u32)); - SImpl::operator_bitor_assign(&a.as_pointer(), b.as_pointer()); + S::operator_bitor_assign(a.as_pointer(), b.as_pointer()); assert!(({ (*a.borrow()).v } == 6_u32)); - SImpl::operator_bitand_assign(&a.as_pointer(), b.as_pointer()); + S::operator_bitand_assign(a.as_pointer(), b.as_pointer()); assert!(({ (*a.borrow()).v } == 4_u32)); - SImpl::operator_bitxor_assign(&a.as_pointer(), b.as_pointer()); + S::operator_bitxor_assign(a.as_pointer(), b.as_pointer()); assert!(({ (*a.borrow()).v } == 0_u32)); - SImpl::operator_assign_1(&a.as_pointer(), 3_u32); + S::operator_assign_1(a.as_pointer(), 3_u32); assert!(({ (*a.borrow()).v } == 3_u32)); - SImpl::operator_shl_assign(&a.as_pointer(), 2); + S::operator_shl_assign(a.as_pointer(), 2); assert!(({ (*a.borrow()).v } == 12_u32)); - SImpl::operator_shr_assign(&a.as_pointer(), 1); + S::operator_shr_assign(a.as_pointer(), 1); assert!(({ (*a.borrow()).v } == 6_u32)); - SImpl::operator_add_assign( - &({ SImpl::operator_add_assign(&a.as_pointer(), b.as_pointer()) }), + S::operator_add_assign( + ({ S::operator_add_assign(a.as_pointer(), b.as_pointer()) }), b.as_pointer(), ); assert!(({ (*a.borrow()).v } == 14_u32)); let mut c: S = S { v: 0_u32 }; - c = (*({ SImpl::operator_assign_1(&a.as_pointer(), 1_u32) }) + c = (*({ S::operator_assign_1(a.as_pointer(), 1_u32) }) .upgrade() .deref()); assert!(({ (*a.borrow()).v } == 1_u32)); assert!((c.v == 1_u32)); return 0; } -pub trait SImpl { - fn operator_assign_1(&self, n: u32) -> Ptr; - fn operator_add_assign(&self, o: Ptr) -> Ptr; - fn operator_sub_assign(&self, o: Ptr) -> Ptr; - fn operator_mul_assign(&self, o: Ptr) -> Ptr; - fn operator_div_assign(&self, o: Ptr) -> Ptr; - fn operator_rem_assign(&self, o: Ptr) -> Ptr; - fn operator_bitand_assign(&self, o: Ptr) -> Ptr; - fn operator_bitor_assign(&self, o: Ptr) -> Ptr; - fn operator_bitxor_assign(&self, o: Ptr) -> Ptr; - fn operator_shl_assign(&self, n: i32) -> Ptr; - fn operator_shr_assign(&self, n: i32) -> Ptr; -} -impl SImpl for Ptr { - fn operator_assign_1(&self, mut n: u32) -> Ptr { - field!((*self), v).write(n); - return (*self).clone(); - } - fn operator_add_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write({ ((*self).with(|__s| __s.v)).wrapping_add(o.with(|__s| __s.v)) }); - return (*self).clone(); - } - fn operator_sub_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write({ ((*self).with(|__s| __s.v)).wrapping_sub(o.with(|__s| __s.v)) }); - return (*self).clone(); - } - fn operator_mul_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write({ ((*self).with(|__s| __s.v)).wrapping_mul(o.with(|__s| __s.v)) }); - return (*self).clone(); - } - fn operator_div_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write({ ((*self).with(|__s| __s.v)).wrapping_div(o.with(|__s| __s.v)) }); - return (*self).clone(); - } - fn operator_rem_assign(&self, o: Ptr) -> Ptr { - field!((*self), v).write({ ((*self).with(|__s| __s.v)).wrapping_rem(o.with(|__s| __s.v)) }); - return (*self).clone(); - } - fn operator_bitand_assign(&self, o: Ptr) -> Ptr { - { - let __rhs = o.with(|__s| __s.v); - field!((*self), v).with_mut(|__v| *__v = *__v & __rhs) - }; - return (*self).clone(); - } - fn operator_bitor_assign(&self, o: Ptr) -> Ptr { - { - let __rhs = o.with(|__s| __s.v); - field!((*self), v).with_mut(|__v| *__v = *__v | __rhs) - }; - return (*self).clone(); - } - fn operator_bitxor_assign(&self, o: Ptr) -> Ptr { - { - let __rhs = o.with(|__s| __s.v); - field!((*self), v).with_mut(|__v| *__v = *__v ^ __rhs) - }; - return (*self).clone(); - } - fn operator_shl_assign(&self, mut n: i32) -> Ptr { - { - field!((*self), v).with_mut(|__v| *__v = *__v << n) - }; - return (*self).clone(); - } - fn operator_shr_assign(&self, mut n: i32) -> Ptr { - { - field!((*self), v).with_mut(|__v| *__v = *__v >> n) - }; - return (*self).clone(); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_friend.rs b/tests/unit/out/refcount/operator_friend.rs index 7fe14b5f97..7355fb70d4 100644 --- a/tests/unit/out/refcount/operator_friend.rs +++ b/tests/unit/out/refcount/operator_friend.rs @@ -30,7 +30,7 @@ pub struct Defaulted { pub b: i32, } impl CppEq for Defaulted { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_0(__lhs.clone(), __rhs.clone()) } } @@ -67,12 +67,12 @@ pub struct DefaultedOrd { pub a: i32, } impl CppLess for DefaultedOrd { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { operator_cmp_1(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } impl CppEq for DefaultedOrd { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_2(__lhs.clone(), __rhs.clone()) } } @@ -105,12 +105,12 @@ pub struct Inline { pub a: i32, } impl CppLess for Inline { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { operator_lt_4(__lhs.clone(), __rhs.clone()) } } impl CppEq for Inline { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_3(__lhs.clone(), __rhs.clone()) } } @@ -132,7 +132,7 @@ pub struct OutOfLine { pub a: i32, } impl CppEq for OutOfLine { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_6(__lhs.clone(), __rhs.clone()) } } @@ -169,12 +169,12 @@ pub struct Tmpl_int_ { pub v: i32, } impl CppLess for Tmpl_int_ { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { operator_lt_9(__lhs.clone(), __rhs.clone()) } } impl CppEq for Tmpl_int_ { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_8(__lhs.clone(), __rhs.clone()) } } @@ -216,7 +216,7 @@ pub struct TmplDefaulted_int_ { pub v: i32, } impl CppEq for TmplDefaulted_int_ { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_11(__lhs.clone(), __rhs.clone()) } } diff --git a/tests/unit/out/refcount/operator_less_than.rs b/tests/unit/out/refcount/operator_less_than.rs index 3450be62fc..e62ec942fc 100644 --- a/tests/unit/out/refcount/operator_less_than.rs +++ b/tests/unit/out/refcount/operator_less_than.rs @@ -25,15 +25,22 @@ pub struct Pair { #[offset(4)] pub y: i32, } +impl Pair { + pub fn operator_lt(this: Ptr, other: Ptr) -> bool { + return ({ this.with(|__s| __s.x) } < { other.with(|__s| __s.x) }) + || (({ this.with(|__s| __s.x) } == { other.with(|__s| __s.x) }) + && ({ this.with(|__s| __s.y) } < { other.with(|__s| __s.y) })); + } +} impl CppLess for Pair { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - PairImpl::operator_lt(__lhs, __rhs.clone()) + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + Pair::operator_lt(__lhs.clone(), __rhs.clone()) } } impl CppEq for Pair { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - !(PairImpl::operator_lt(__lhs, __rhs.clone())) - && !(PairImpl::operator_lt(__rhs, __lhs.clone())) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + !(Pair::operator_lt(__lhs.clone(), __rhs.clone())) + && !(Pair::operator_lt(__rhs.clone(), __lhs.clone())) } } pub fn main() { @@ -43,17 +50,7 @@ pub fn main() { fn main_0() -> i32 { let pair1: Value = Rc::new(RefCell::new(Pair { x: 1, y: 2 })); let pair2: Value = Rc::new(RefCell::new(Pair { x: 1, y: 3 })); - assert!(({ PairImpl::operator_lt(&pair1.as_pointer(), pair2.as_pointer(),) })); + assert!(({ Pair::operator_lt(pair1.as_pointer(), pair2.as_pointer(),) })); return 0; } -pub trait PairImpl { - fn operator_lt(&self, other: Ptr) -> bool; -} -impl PairImpl for Ptr { - fn operator_lt(&self, other: Ptr) -> bool { - return ({ (*self).with(|__s| __s.x) } < { other.with(|__s| __s.x) }) - || (({ (*self).with(|__s| __s.x) } == { other.with(|__s| __s.x) }) - && ({ (*self).with(|__s| __s.y) } < { other.with(|__s| __s.y) })); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_logical_member.rs b/tests/unit/out/refcount/operator_logical_member.rs index f633eada1d..f00dcd2c1a 100644 --- a/tests/unit/out/refcount/operator_logical_member.rs +++ b/tests/unit/out/refcount/operator_logical_member.rs @@ -23,6 +23,17 @@ pub struct S { #[offset(0)] pub v: i32, } +impl S { + pub fn operator_not(this: Ptr) -> bool { + return (this.with(|__s| __s.v) == 0); + } + pub fn operator_and(this: Ptr, o: Ptr) -> bool { + return (this.with(|__s| __s.v) != 0) && (o.with(|__s| __s.v) != 0); + } + pub fn operator_or(this: Ptr, o: Ptr) -> bool { + return (this.with(|__s| __s.v) != 0) || (o.with(|__s| __s.v) != 0); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -30,28 +41,12 @@ pub fn main() { fn main_0() -> i32 { let t: Value = Rc::new(RefCell::new(S { v: 1 })); let f: Value = Rc::new(RefCell::new(S { v: 0 })); - assert!(({ SImpl::operator_not(&f.as_pointer(),) })); - assert!(!({ SImpl::operator_not(&t.as_pointer(),) })); - assert!(({ SImpl::operator_and(&t.as_pointer(), t.as_pointer(),) })); - assert!(!({ SImpl::operator_and(&t.as_pointer(), f.as_pointer(),) })); - assert!(({ SImpl::operator_or(&t.as_pointer(), f.as_pointer(),) })); - assert!(!({ SImpl::operator_or(&f.as_pointer(), f.as_pointer(),) })); + assert!(({ S::operator_not(f.as_pointer(),) })); + assert!(!({ S::operator_not(t.as_pointer(),) })); + assert!(({ S::operator_and(t.as_pointer(), t.as_pointer(),) })); + assert!(!({ S::operator_and(t.as_pointer(), f.as_pointer(),) })); + assert!(({ S::operator_or(t.as_pointer(), f.as_pointer(),) })); + assert!(!({ S::operator_or(f.as_pointer(), f.as_pointer(),) })); return 0; } -pub trait SImpl { - fn operator_not(&self) -> bool; - fn operator_and(&self, o: Ptr) -> bool; - fn operator_or(&self, o: Ptr) -> bool; -} -impl SImpl for Ptr { - fn operator_not(&self) -> bool { - return ((*self).with(|__s| __s.v) == 0); - } - fn operator_and(&self, o: Ptr) -> bool { - return ((*self).with(|__s| __s.v) != 0) && (o.with(|__s| __s.v) != 0); - } - fn operator_or(&self, o: Ptr) -> bool { - return ((*self).with(|__s| __s.v) != 0) || (o.with(|__s| __s.v) != 0); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_member_pointer_member.rs b/tests/unit/out/refcount/operator_member_pointer_member.rs index 19aad4c322..47534cf43d 100644 --- a/tests/unit/out/refcount/operator_member_pointer_member.rs +++ b/tests/unit/out/refcount/operator_member_pointer_member.rs @@ -65,6 +65,23 @@ pub struct S { #[byte_size(4)] pub inner: Inner, } +impl S { + pub fn operator_index_1(this: Ptr, mut i: i32) -> Ptr { + return array_field_ptr!(this, data).offset((i) as isize); + } + pub fn operator_index_2(this: Ptr, mut i: i32) -> Ptr { + return array_field_ptr!(this, data).offset((i) as isize); + } + pub fn operator_deref(this: Ptr) -> Ptr { + return field_ptr!(this, inner); + } + pub fn operator_arrow(this: Ptr) -> Ptr { + return (field_ptr!(this, inner)); + } + pub fn operator_addr(this: Ptr) -> Ptr { + return (array_field_ptr!(this, data).offset((0) as isize)); + } +} impl Default for S { fn default() -> Self { { @@ -84,17 +101,17 @@ fn main_0() -> i32 { data: Box::new([1, 2, 3]), inner: Inner { x: 9 }, })); - assert!(((({ SImpl::operator_index_1(&s.as_pointer(), 1,) }).read()) == 2)); - ({ SImpl::operator_index_1(&s.as_pointer(), 1) }).write(20); - assert!(((({ SImpl::operator_index_1(&s.as_pointer(), 1,) }).read()) == 20)); + assert!(((({ S::operator_index_1(s.as_pointer(), 1,) }).read()) == 2)); + ({ S::operator_index_1(s.as_pointer(), 1) }).write(20); + assert!(((({ S::operator_index_1(s.as_pointer(), 1,) }).read()) == 20)); let cs: Ptr = s.as_pointer(); - assert!(((({ SImpl::operator_index_2(&cs, 2,) }).read()) == 3)); - assert!((({ SImpl::operator_deref(&s.as_pointer(),) }).with(|__s| (__s).x) == 9)); - field!(({ SImpl::operator_deref(&s.as_pointer(),) }), x).write(10); - assert!((({ SImpl::operator_arrow(&s.as_pointer(),) }).with(|__s| __s.x) == 10)); - field!(({ SImpl::operator_arrow(&s.as_pointer(),) }), x).write(11); + assert!(((({ S::operator_index_2((cs).clone(), 2,) }).read()) == 3)); + assert!((({ S::operator_deref(s.as_pointer(),) }).with(|__s| (__s).x) == 9)); + field!(({ S::operator_deref(s.as_pointer(),) }), x).write(10); + assert!((({ S::operator_arrow(s.as_pointer(),) }).with(|__s| __s.x) == 10)); + field!(({ S::operator_arrow(s.as_pointer(),) }), x).write(11); assert!(({ (*s.borrow()).inner.x } == 11)); - let mut p: Ptr = ({ SImpl::operator_addr(&s.as_pointer()) }); + let mut p: Ptr = ({ S::operator_addr(s.as_pointer()) }); assert!(((p.read()) == 1)); p.write(5); assert!(((array_elem!(s.as_pointer(), data, 0).read()) == 5)); @@ -109,30 +126,6 @@ fn main_0() -> i32 { ); return 0; } -pub trait SImpl { - fn operator_index_1(&self, i: i32) -> Ptr; - fn operator_index_2(&self, i: i32) -> Ptr; - fn operator_deref(&self) -> Ptr; - fn operator_arrow(&self) -> Ptr; - fn operator_addr(&self) -> Ptr; -} -impl SImpl for Ptr { - fn operator_index_1(&self, mut i: i32) -> Ptr { - return array_field_ptr!((*self), data).offset((i) as isize); - } - fn operator_index_2(&self, mut i: i32) -> Ptr { - return array_field_ptr!((*self), data).offset((i) as isize); - } - fn operator_deref(&self) -> Ptr { - return field_ptr!((*self), inner); - } - fn operator_arrow(&self) -> Ptr { - return (field_ptr!((*self), inner)); - } - fn operator_addr(&self) -> Ptr { - return (array_field_ptr!((*self), data).offset((0) as isize)); - } -} pub fn __cpp2rust_init_globals() { let _ = table_0.with(|_| ()); } diff --git a/tests/unit/out/refcount/operator_other_member.rs b/tests/unit/out/refcount/operator_other_member.rs index 14e4b3ba85..462a8f50d7 100644 --- a/tests/unit/out/refcount/operator_other_member.rs +++ b/tests/unit/out/refcount/operator_other_member.rs @@ -44,6 +44,28 @@ pub struct S { #[offset(0)] pub v: i32, } +impl S { + pub fn operator_call_1(this: Ptr) -> i32 { + return this.with(|__s| __s.v); + } + pub fn operator_call_2(this: Ptr, mut a: i32) -> i32 { + return (this.with(|__s| __s.v) + a); + } + pub fn operator_call_3(this: Ptr, mut a: i32, mut b: i32) -> i32 { + return ((this.with(|__s| __s.v) + a) + b); + } + pub fn operator_comma(this: Ptr, o: Ptr) -> S { + return S { + v: ({ (this.with(|__s| __s.v) * 10) } + { o.with(|__s| __s.v) }), + }; + } + pub fn to_i32(this: Ptr) -> i32 { + return this.with(|__s| __s.v); + } + pub fn to_bool(this: Ptr) -> bool { + return (this.with(|__s| __s.v) != 0); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -51,58 +73,26 @@ pub fn main() { fn main_0() -> i32 { let s: Value = Rc::new(RefCell::new(S { v: 3 })); let t: Value = Rc::new(RefCell::new(S { v: 4 })); - assert!((({ SImpl::operator_call_1(&s.as_pointer(),) }) == 3)); - assert!((({ SImpl::operator_call_2(&s.as_pointer(), 1,) }) == 4)); - assert!((({ SImpl::operator_call_3(&s.as_pointer(), 1, 2,) }) == 6)); - assert!(({ ({ SImpl::operator_comma(&s.as_pointer(), t.as_pointer(),) }).v } == 34)); - let mut i: i32 = ({ SImpl::to_i32(&s.as_pointer()) }); + assert!((({ S::operator_call_1(s.as_pointer(),) }) == 3)); + assert!((({ S::operator_call_2(s.as_pointer(), 1,) }) == 4)); + assert!((({ S::operator_call_3(s.as_pointer(), 1, 2,) }) == 6)); + assert!(({ ({ S::operator_comma(s.as_pointer(), t.as_pointer(),) }).v } == 34)); + let mut i: i32 = ({ S::to_i32(s.as_pointer()) }); assert!((i == 3)); - assert!(((({ SImpl::to_i32(&s.as_pointer(),) }) + 1) == 4)); - if ({ SImpl::to_bool(&s.as_pointer()) }) { - assert!(({ SImpl::to_bool(&s.as_pointer(),) })); + assert!(((({ S::to_i32(s.as_pointer(),) }) + 1) == 4)); + if ({ S::to_bool(s.as_pointer()) }) { + assert!(({ S::to_bool(s.as_pointer(),) })); } else { assert!(false); } let z: Value = Rc::new(RefCell::new(S { v: 0 })); - assert!(({ SImpl::to_bool(&s.as_pointer(),) })); - assert!(!({ SImpl::to_bool(&z.as_pointer(),) })); - assert!(({ SImpl::to_bool(&s.as_pointer(),) }) && (!({ SImpl::to_bool(&z.as_pointer(),) }))); + assert!(({ S::to_bool(s.as_pointer(),) })); + assert!(!({ S::to_bool(z.as_pointer(),) })); + assert!(({ S::to_bool(s.as_pointer(),) }) && (!({ S::to_bool(z.as_pointer(),) }))); let st: Value = Rc::new(RefCell::new(::default())); assert!((({ Static::operator_call(6, 7,) }) == 42)); - assert!((({ SImpl::operator_call_1(&Rc::new(RefCell::new(S { v: 5 })).as_pointer(),) }) == 5)); - assert!( - (({ SImpl::operator_call_3(&Rc::new(RefCell::new(S { v: 5 })).as_pointer(), 1, 1,) }) == 7) - ); + assert!((({ S::operator_call_1(Rc::new(RefCell::new(S { v: 5 })).as_pointer(),) }) == 5)); + assert!((({ S::operator_call_3(Rc::new(RefCell::new(S { v: 5 })).as_pointer(), 1, 1,) }) == 7)); return 0; } -pub trait SImpl { - fn operator_call_1(&self) -> i32; - fn operator_call_2(&self, a: i32) -> i32; - fn operator_call_3(&self, a: i32, b: i32) -> i32; - fn operator_comma(&self, o: Ptr) -> S; - fn to_i32(&self) -> i32; - fn to_bool(&self) -> bool; -} -impl SImpl for Ptr { - fn operator_call_1(&self) -> i32 { - return (*self).with(|__s| __s.v); - } - fn operator_call_2(&self, mut a: i32) -> i32 { - return ((*self).with(|__s| __s.v) + a); - } - fn operator_call_3(&self, mut a: i32, mut b: i32) -> i32 { - return (((*self).with(|__s| __s.v) + a) + b); - } - fn operator_comma(&self, o: Ptr) -> S { - return S { - v: ({ ((*self).with(|__s| __s.v) * 10) } + { o.with(|__s| __s.v) }), - }; - } - fn to_i32(&self) -> i32 { - return (*self).with(|__s| __s.v); - } - fn to_bool(&self) -> bool { - return ((*self).with(|__s| __s.v) != 0); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_overloads.rs b/tests/unit/out/refcount/operator_overloads.rs index 0dace84931..9c04822e52 100644 --- a/tests/unit/out/refcount/operator_overloads.rs +++ b/tests/unit/out/refcount/operator_overloads.rs @@ -23,6 +23,37 @@ pub struct S { #[offset(0)] pub v: i32, } +impl S { + pub fn operator_eq_1(this: Ptr, mut o: i32) -> i32 { + return if (this.with(|__s| __s.v) == o) { 1 } else { 0 }; + } + pub fn operator_eq_2(this: Ptr, mut o: i64) -> i32 { + return if ((this.with(|__s| __s.v) as i64) == o) { + 2 + } else { + 0 + }; + } + pub fn operator_eq_3(this: Ptr, mut o: f64) -> i32 { + return if ((this.with(|__s| __s.v) as f64) == o) { + 3 + } else { + 0 + }; + } + pub fn operator_add(this: Ptr, o: Ptr) -> i32 { + return ({ this.with(|__s| __s.v) } + { o.with(|__s| __s.v) }); + } + pub fn operator_sub(this: Ptr, mut o: S) -> i32 { + return (this.with(|__s| __s.v) - o.v); + } + pub fn operator_mul_6(this: Ptr, o: Ptr) -> i32 { + return ({ this.with(|__s| __s.v) } * { o.with(|__s| __s.v) }); + } + pub fn operator_mul_7(this: Ptr, mut o: i32) -> i32 { + return ((this.with(|__s| __s.v) * o) + 1); + } +} pub fn operator_div_0(a: Ptr, b: Ptr) -> i32 { return ({ a.with(|__s| __s.v) } / { b.with(|__s| __s.v) }); } @@ -52,14 +83,14 @@ pub fn main() { fn main_0() -> i32 { let s: Value = Rc::new(RefCell::new(S { v: 6 })); let t: Value = Rc::new(RefCell::new(S { v: 4 })); - assert!((({ SImpl::operator_eq_1(&s.as_pointer(), 6,) }) == 1)); - assert!((({ SImpl::operator_eq_2(&s.as_pointer(), 6_i64,) }) == 2)); - assert!((({ SImpl::operator_eq_3(&s.as_pointer(), 6_f64,) }) == 3)); - assert!((({ SImpl::operator_eq_1(&s.as_pointer(), 7,) }) == 0)); - assert!((({ SImpl::operator_add(&s.as_pointer(), t.as_pointer(),) }) == 10)); - assert!((({ SImpl::operator_sub(&s.as_pointer(), { (*t.borrow()) },) }) == 2)); - assert!((({ SImpl::operator_mul_6(&s.as_pointer(), t.as_pointer(),) }) == 24)); - assert!((({ SImpl::operator_mul_7(&s.as_pointer(), 2,) }) == 13)); + assert!((({ S::operator_eq_1(s.as_pointer(), 6,) }) == 1)); + assert!((({ S::operator_eq_2(s.as_pointer(), 6_i64,) }) == 2)); + assert!((({ S::operator_eq_3(s.as_pointer(), 6_f64,) }) == 3)); + assert!((({ S::operator_eq_1(s.as_pointer(), 7,) }) == 0)); + assert!((({ S::operator_add(s.as_pointer(), t.as_pointer(),) }) == 10)); + assert!((({ S::operator_sub(s.as_pointer(), { (*t.borrow()) },) }) == 2)); + assert!((({ S::operator_mul_6(s.as_pointer(), t.as_pointer(),) }) == 24)); + assert!((({ S::operator_mul_7(s.as_pointer(), 2,) }) == 13)); assert!((({ operator_div_0(s.as_pointer(), t.as_pointer(),) }) == 1)); assert!((({ operator_div_1({ (*s.borrow()) }, 4,) }) == 2)); assert!((({ operator_rem_2({ (*s.borrow()) }, { (*t.borrow()) },) }) == 2)); @@ -68,48 +99,4 @@ fn main_0() -> i32 { assert!((({ operator_eq_5(6_i64, s.as_pointer(),) }) == 5)); return 0; } -pub trait SImpl { - fn operator_eq_1(&self, o: i32) -> i32; - fn operator_eq_2(&self, o: i64) -> i32; - fn operator_eq_3(&self, o: f64) -> i32; - fn operator_add(&self, o: Ptr) -> i32; - fn operator_sub(&self, o: S) -> i32; - fn operator_mul_6(&self, o: Ptr) -> i32; - fn operator_mul_7(&self, o: i32) -> i32; -} -impl SImpl for Ptr { - fn operator_eq_1(&self, mut o: i32) -> i32 { - return if ((*self).with(|__s| __s.v) == o) { - 1 - } else { - 0 - }; - } - fn operator_eq_2(&self, mut o: i64) -> i32 { - return if (((*self).with(|__s| __s.v) as i64) == o) { - 2 - } else { - 0 - }; - } - fn operator_eq_3(&self, mut o: f64) -> i32 { - return if (((*self).with(|__s| __s.v) as f64) == o) { - 3 - } else { - 0 - }; - } - fn operator_add(&self, o: Ptr) -> i32 { - return ({ (*self).with(|__s| __s.v) } + { o.with(|__s| __s.v) }); - } - fn operator_sub(&self, mut o: S) -> i32 { - return ((*self).with(|__s| __s.v) - o.v); - } - fn operator_mul_6(&self, o: Ptr) -> i32 { - return ({ (*self).with(|__s| __s.v) } * { o.with(|__s| __s.v) }); - } - fn operator_mul_7(&self, mut o: i32) -> i32 { - return (((*self).with(|__s| __s.v) * o) + 1); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_qualifiers.rs b/tests/unit/out/refcount/operator_qualifiers.rs index 7536bb88cb..40680854c3 100644 --- a/tests/unit/out/refcount/operator_qualifiers.rs +++ b/tests/unit/out/refcount/operator_qualifiers.rs @@ -23,68 +23,53 @@ pub struct S { #[offset(0)] pub v: i32, } -pub fn main() { - __cpp2rust_init_globals(); - libcc2rs::cpp2rust_exit(main_0()); -} -fn main_0() -> i32 { - let s: Value = Rc::new(RefCell::new(S { v: 10 })); - let cs: Value = Rc::new(RefCell::new(S { v: 10 })); - let vs: Value = Rc::new(RefCell::new(S { v: 10 })); - assert!((({ SImpl::operator_add_1(&s.as_pointer(), 1,) }) == 11)); - assert!((({ SImpl::operator_add_2(&cs.as_pointer(), 1,) }) == 12)); - assert!((({ SImpl::operator_add_3(&vs.as_pointer(), 1,) }) == 13)); - assert!((({ SImpl::operator_sub_4(&s.as_pointer(), 1,) }) == 9)); - assert!( - (({ SImpl::operator_sub_5(&Rc::new(RefCell::new(S { v: 10 })).as_pointer(), 1,) }) == 8) - ); - assert!((({ SImpl::operator_mul_6(&s.as_pointer(), 3,) }) == 30)); - assert!((({ SImpl::operator_mul_6(&cs.as_pointer(), 3,) }) == 30)); - assert!( - (({ SImpl::operator_mul_7(&Rc::new(RefCell::new(S { v: 10 })).as_pointer(), 3,) }) == 60) - ); - assert!((({ SImpl::operator_index_8(&s.as_pointer(), 2,) }) == 12)); - assert!((({ SImpl::operator_index_9(&cs.as_pointer(), 2,) }) == 112)); - return 0; -} -pub trait SImpl { - fn operator_add_1(&self, a: i32) -> i32; - fn operator_add_2(&self, a: i32) -> i32; - fn operator_add_3(&self, a: i32) -> i32; - fn operator_sub_4(&self, a: i32) -> i32; - fn operator_sub_5(&self, a: i32) -> i32; - fn operator_mul_6(&self, a: i32) -> i32; - fn operator_mul_7(&self, a: i32) -> i32; - fn operator_index_8(&self, i: i32) -> i32; - fn operator_index_9(&self, i: i32) -> i32; -} -impl SImpl for Ptr { - fn operator_add_1(&self, mut a: i32) -> i32 { - return ((*self).with(|__s| __s.v) + a); +impl S { + pub fn operator_add_1(this: Ptr, mut a: i32) -> i32 { + return (this.with(|__s| __s.v) + a); } - fn operator_add_2(&self, mut a: i32) -> i32 { - return (((*self).with(|__s| __s.v) + a) + 1); + pub fn operator_add_2(this: Ptr, mut a: i32) -> i32 { + return ((this.with(|__s| __s.v) + a) + 1); } - fn operator_add_3(&self, mut a: i32) -> i32 { - return (((*self).with(|__s| __s.v) + a) + 2); + pub fn operator_add_3(this: Ptr, mut a: i32) -> i32 { + return ((this.with(|__s| __s.v) + a) + 2); } - fn operator_sub_4(&self, mut a: i32) -> i32 { - return ((*self).with(|__s| __s.v) - a); + pub fn operator_sub_4(this: Ptr, mut a: i32) -> i32 { + return (this.with(|__s| __s.v) - a); } - fn operator_sub_5(&self, mut a: i32) -> i32 { - return (((*self).with(|__s| __s.v) - a) - 1); + pub fn operator_sub_5(this: Ptr, mut a: i32) -> i32 { + return ((this.with(|__s| __s.v) - a) - 1); } - fn operator_mul_6(&self, mut a: i32) -> i32 { - return ((*self).with(|__s| __s.v) * a); + pub fn operator_mul_6(this: Ptr, mut a: i32) -> i32 { + return (this.with(|__s| __s.v) * a); } - fn operator_mul_7(&self, mut a: i32) -> i32 { - return (((*self).with(|__s| __s.v) * a) * 2); + pub fn operator_mul_7(this: Ptr, mut a: i32) -> i32 { + return ((this.with(|__s| __s.v) * a) * 2); } - fn operator_index_8(&self, mut i: i32) -> i32 { - return ((*self).with(|__s| __s.v) + i); + pub fn operator_index_8(this: Ptr, mut i: i32) -> i32 { + return (this.with(|__s| __s.v) + i); } - fn operator_index_9(&self, mut i: i32) -> i32 { - return (((*self).with(|__s| __s.v) + i) + 100); + pub fn operator_index_9(this: Ptr, mut i: i32) -> i32 { + return ((this.with(|__s| __s.v) + i) + 100); } } +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + let s: Value = Rc::new(RefCell::new(S { v: 10 })); + let cs: Value = Rc::new(RefCell::new(S { v: 10 })); + let vs: Value = Rc::new(RefCell::new(S { v: 10 })); + assert!((({ S::operator_add_1(s.as_pointer(), 1,) }) == 11)); + assert!((({ S::operator_add_2(cs.as_pointer(), 1,) }) == 12)); + assert!((({ S::operator_add_3(vs.as_pointer(), 1,) }) == 13)); + assert!((({ S::operator_sub_4(s.as_pointer(), 1,) }) == 9)); + assert!((({ S::operator_sub_5(Rc::new(RefCell::new(S { v: 10 })).as_pointer(), 1,) }) == 8)); + assert!((({ S::operator_mul_6(s.as_pointer(), 3,) }) == 30)); + assert!((({ S::operator_mul_6(cs.as_pointer(), 3,) }) == 30)); + assert!((({ S::operator_mul_7(Rc::new(RefCell::new(S { v: 10 })).as_pointer(), 3,) }) == 60)); + assert!((({ S::operator_index_8(s.as_pointer(), 2,) }) == 12)); + assert!((({ S::operator_index_9(cs.as_pointer(), 2,) }) == 112)); + return 0; +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_three_way.rs b/tests/unit/out/refcount/operator_three_way.rs index 1989c8fa75..993d253862 100644 --- a/tests/unit/out/refcount/operator_three_way.rs +++ b/tests/unit/out/refcount/operator_three_way.rs @@ -23,14 +23,28 @@ pub struct S { #[offset(0)] pub v: i32, } +impl S { + pub fn operator_cmp(this: Ptr, o: Ptr) -> std::cmp::Ordering { + if ({ this.with(|__s| __s.v) } < { o.with(|__s| __s.v) }) { + return (*libcc2rs::strong_ordering_less().upgrade().deref()); + } + if ({ this.with(|__s| __s.v) } > { o.with(|__s| __s.v) }) { + return (*libcc2rs::strong_ordering_greater().upgrade().deref()); + } + return (*libcc2rs::strong_ordering_equal().upgrade().deref()); + } + pub fn operator_eq(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } +} impl CppLess for S { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - SImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Less + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + S::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } impl CppEq for S { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - SImpl::operator_eq(__lhs, __rhs.clone()) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + S::operator_eq(__lhs.clone(), __rhs.clone()) } } pub fn main() { @@ -40,41 +54,15 @@ pub fn main() { fn main_0() -> i32 { let a: Value = Rc::new(RefCell::new(S { v: 1 })); let b: Value = Rc::new(RefCell::new(S { v: 2 })); + assert!(({ S::operator_cmp(a.as_pointer(), b.as_pointer(),) }) == std::cmp::Ordering::Less); + assert!(({ S::operator_cmp(b.as_pointer(), a.as_pointer(),) }) == std::cmp::Ordering::Greater); + assert!(({ S::operator_cmp(a.as_pointer(), b.as_pointer(),) }) != std::cmp::Ordering::Greater); + assert!(({ S::operator_cmp(b.as_pointer(), a.as_pointer(),) }) != std::cmp::Ordering::Less); + assert!(!({ S::operator_eq(a.as_pointer(), b.as_pointer(),) })); assert!( - ({ SImpl::operator_cmp(&a.as_pointer(), b.as_pointer(),) }) == std::cmp::Ordering::Less - ); - assert!( - ({ SImpl::operator_cmp(&b.as_pointer(), a.as_pointer(),) }) == std::cmp::Ordering::Greater - ); - assert!( - ({ SImpl::operator_cmp(&a.as_pointer(), b.as_pointer(),) }) != std::cmp::Ordering::Greater - ); - assert!( - ({ SImpl::operator_cmp(&b.as_pointer(), a.as_pointer(),) }) != std::cmp::Ordering::Less - ); - assert!(!({ SImpl::operator_eq(&a.as_pointer(), b.as_pointer(),) })); - assert!( - ({ SImpl::operator_cmp(&a.as_pointer(), b.as_pointer(),) }) + ({ S::operator_cmp(a.as_pointer(), b.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_less().upgrade().deref()) }) ); return 0; } -pub trait SImpl { - fn operator_cmp(&self, o: Ptr) -> std::cmp::Ordering; - fn operator_eq(&self, o: Ptr) -> bool; -} -impl SImpl for Ptr { - fn operator_cmp(&self, o: Ptr) -> std::cmp::Ordering { - if ({ (*self).with(|__s| __s.v) } < { o.with(|__s| __s.v) }) { - return (*libcc2rs::strong_ordering_less().upgrade().deref()); - } - if ({ (*self).with(|__s| __s.v) } > { o.with(|__s| __s.v) }) { - return (*libcc2rs::strong_ordering_greater().upgrade().deref()); - } - return (*libcc2rs::strong_ordering_equal().upgrade().deref()); - } - fn operator_eq(&self, o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_traits.rs b/tests/unit/out/refcount/operator_traits.rs index cf9740e798..8aa303c76d 100644 --- a/tests/unit/out/refcount/operator_traits.rs +++ b/tests/unit/out/refcount/operator_traits.rs @@ -23,14 +23,20 @@ pub struct Lt { #[offset(0)] pub v: i32, } +impl Lt { + pub fn operator_lt(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } < { o.with(|__s| __s.v) }); + } +} impl CppLess for Lt { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - LtImpl::operator_lt(__lhs, __rhs.clone()) + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + Lt::operator_lt(__lhs.clone(), __rhs.clone()) } } impl CppEq for Lt { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - !(LtImpl::operator_lt(__lhs, __rhs.clone())) && !(LtImpl::operator_lt(__rhs, __lhs.clone())) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + !(Lt::operator_lt(__lhs.clone(), __rhs.clone())) + && !(Lt::operator_lt(__rhs.clone(), __lhs.clone())) } } #[derive( @@ -50,9 +56,14 @@ pub struct Eq { #[offset(0)] pub v: i32, } +impl Eq { + pub fn operator_eq(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } +} impl CppEq for Eq { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - EqImpl::operator_eq(__lhs, __rhs.clone()) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + Eq::operator_eq(__lhs.clone(), __rhs.clone()) } } #[derive( @@ -72,14 +83,22 @@ pub struct Cmp { #[offset(0)] pub v: i32, } +impl Cmp { + pub fn operator_cmp(this: Ptr, o: Ptr) -> std::cmp::Ordering { + return std::cmp::Ord::cmp(&(this.with(|__s| __s.v)), &(o.with(|__s| __s.v))); + } + pub fn operator_eq(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } +} impl CppLess for Cmp { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { - CmpImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Less + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + Cmp::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } impl CppEq for Cmp { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { - CmpImpl::operator_eq(__lhs, __rhs.clone()) + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { + Cmp::operator_eq(__lhs.clone(), __rhs.clone()) } } #[derive( @@ -100,12 +119,12 @@ pub struct Free { pub v: i32, } impl CppLess for Free { - fn less(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn less(__lhs: Ptr, __rhs: Ptr) -> bool { operator_lt_0(__lhs.clone(), __rhs.clone()) } } impl CppEq for Free { - fn equal(__lhs: &Ptr, __rhs: &Ptr) -> bool { + fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { operator_eq_1(__lhs.clone(), __rhs.clone()) } } @@ -167,7 +186,7 @@ fn main_0() -> i32 { let mut __tmp_1 = { eqs.decay().begin() }; let mut __tmp_2 = { eqs.decay().end() }; let mut __it = (__tmp_1).clone(); - while __it != __tmp_2 && !CppEq::equal(&__it.iter_deref(), &two.as_pointer()) { + while __it != __tmp_2 && !CppEq::equal(__it.iter_deref(), two.as_pointer().clone()) { __it.iter_inc(); } __it @@ -181,7 +200,7 @@ fn main_0() -> i32 { let mut __tmp_3 = { eqs.decay().begin() }; let mut __tmp_4 = { eqs.decay().end() }; let mut __it = (__tmp_3).clone(); - while __it != __tmp_4 && !CppEq::equal(&__it.iter_deref(), &nine.as_pointer()) { + while __it != __tmp_4 && !CppEq::equal(__it.iter_deref(), nine.as_pointer().clone()) { __it.iter_inc(); } __it @@ -208,7 +227,7 @@ fn main_0() -> i32 { let mut __tmp_6 = { cmps.decay().begin() }; let mut __tmp_7 = { cmps.decay().end() }; let mut __it = (__tmp_6).clone(); - while __it != __tmp_7 && !CppEq::equal(&__it.iter_deref(), &three.as_pointer()) { + while __it != __tmp_7 && !CppEq::equal(__it.iter_deref(), three.as_pointer().clone()) { __it.iter_inc(); } __it @@ -232,7 +251,7 @@ fn main_0() -> i32 { let mut __tmp_9 = { frees.decay().begin() }; let mut __tmp_10 = { frees.decay().end() }; let mut __it = (__tmp_9).clone(); - while __it != __tmp_10 && !CppEq::equal(&__it.iter_deref(), &ftwo.as_pointer()) { + while __it != __tmp_10 && !CppEq::equal(__it.iter_deref(), ftwo.as_pointer().clone()) { __it.iter_inc(); } __it @@ -276,32 +295,4 @@ fn main_0() -> i32 { ); return 0; } -pub trait CmpImpl { - fn operator_cmp(&self, o: Ptr) -> std::cmp::Ordering; - fn operator_eq(&self, o: Ptr) -> bool; -} -impl CmpImpl for Ptr { - fn operator_cmp(&self, o: Ptr) -> std::cmp::Ordering { - return std::cmp::Ord::cmp(&((*self).with(|__s| __s.v)), &(o.with(|__s| __s.v))); - } - fn operator_eq(&self, o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } -} -pub trait EqImpl { - fn operator_eq(&self, o: Ptr) -> bool; -} -impl EqImpl for Ptr { - fn operator_eq(&self, o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } -} -pub trait LtImpl { - fn operator_lt(&self, o: Ptr) -> bool; -} -impl LtImpl for Ptr { - fn operator_lt(&self, o: Ptr) -> bool { - return ({ (*self).with(|__s| __s.v) } < { o.with(|__s| __s.v) }); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/overload_mangling.rs b/tests/unit/out/refcount/overload_mangling.rs index 4518022b92..7de23c49e2 100644 --- a/tests/unit/out/refcount/overload_mangling.rs +++ b/tests/unit/out/refcount/overload_mangling.rs @@ -33,6 +33,20 @@ pub fn twice_2(mut n: i32) -> i32 { )] #[byte_size(1)] pub struct Access_S_ {} +impl Access_S_ { + pub fn get_1(this: Ptr, mut p: Ptr) -> i32 { + return p.with(|__s| __s.base); + } + pub fn get_2(this: Ptr, mut p: Ptr) -> i32 { + return (p.with(|__s| __s.base) + 1); + } + pub fn ref_3(this: Ptr, r: Ptr) -> i32 { + return (r.with(|__s| __s.base) + 2); + } + pub fn ref_4(this: Ptr, r: Ptr) -> i32 { + return (r.with(|__s| __s.base) + 3); + } +} #[derive( Copy, Clone, @@ -50,6 +64,83 @@ pub struct S { #[offset(0)] pub base: i32, } +impl S { + pub fn plain_4(this: Ptr, mut x: i32) -> i32 { + return (this.with(|__s| __s.base) + x); + } + pub fn plain_5(this: Ptr, mut x: i64) -> i32 { + return ((this.with(|__s| __s.base) + (x as i32)) + 1); + } + pub fn take_6(this: Ptr, x: Ptr) -> i32 { + return (({ this.with(|__s| __s.base) } + { (x.read()) }) + 1); + } + pub fn take_7(this: Ptr, x: Ptr) -> i32 { + return (({ this.with(|__s| __s.base) } + { (x.read()) }) + 2); + } + pub fn pick_8(this: Ptr, p: (Value, Value)) -> i32 { + let p: Value<(Value, Value)> = Rc::new(RefCell::new(p)); + return (this.with(|__s| __s.base) + (*(*p.borrow()).0.borrow())); + } + pub fn pick_9(this: Ptr, p: (Value, Value)) -> i32 { + let p: Value<(Value, Value)> = Rc::new(RefCell::new(p)); + return (this.with(|__s| __s.base) + ((*(*p.borrow()).1.borrow()) as i32)); + } + pub fn apply_10(this: Ptr, mut f: FnPtr)>, x: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + ({ f.call((x.as_pointer())) }); + return (this.with(|__s| __s.base) + (*x.borrow())); + } + pub fn apply_11(this: Ptr, mut f: FnPtr, i32)>, x: i32) -> i32 { + let x: Value = Rc::new(RefCell::new(x)); + ({ f.call((x.as_pointer()), 10) }); + return (this.with(|__s| __s.base) + (*x.borrow())); + } + pub fn apply_12(this: Ptr, mut f: FnPtr i32>, mut x: i32) -> i32 { + return ({ this.with(|__s| __s.base) } + { ({ f.call(x) }) }); + } + pub fn combine_13( + this: Ptr, + p: Ptr<(Value, Value)>, + mut f: FnPtr i32>, + mut q: Ptr, + mut n: u64, + ) -> i32 { + return ({ + ({ + ({ this.with(|__s| __s.base) } + { ((*(*p.upgrade().deref()).1.borrow()) as i32) }) + } + { ({ f.call((q.read())) }) }) + } + { (n as i32) }); + } + pub fn combine_14( + this: Ptr, + p: Ptr<(Value, Value)>, + mut f: FnPtr, i32)>, + mut q: Ptr, + mut n: u64, + ) -> i32 { + ({ f.call((q).clone(), (n as i32)) }); + return ({ ({ this.with(|__s| __s.base) } + { (*(*p.upgrade().deref()).0.borrow()) }) } + + { (q.read()) }); + } + pub fn width_1_char(this: Ptr, mut x: i32) -> i32 { + return (this.with(|__s| __s.base) + (x * (::std::mem::size_of::() as i32))); + } + pub fn width_1_int(this: Ptr, mut x: i32) -> i32 { + return (this.with(|__s| __s.base) + (x * (::std::mem::size_of::() as i32))); + } + pub fn scale_2_2(this: Ptr, mut x: i32) -> i32 { + return (this.with(|__s| __s.base) + (x * 2)); + } + pub fn scale_2_3(this: Ptr, mut x: i32) -> i32 { + return (this.with(|__s| __s.base) + (x * 3)); + } + pub fn count_3(this: Ptr, mut x: i32) -> i32 { + return ((this.with(|__s| __s.base) + x) + (0 as i32)); + } + pub fn count_3_int_long(this: Ptr, mut x: i32) -> i32 { + return ((this.with(|__s| __s.base) + x) + (2 as i32)); + } +} #[derive( Copy, Clone, @@ -73,45 +164,41 @@ pub fn main() { } fn main_0() -> i32 { let s: Value = Rc::new(RefCell::new(S { base: 100 })); - assert!((({ SImpl::width_1_char(&s.as_pointer(), 3,) }) == 103)); - assert!((({ SImpl::width_1_int(&s.as_pointer(), 3,) }) == 112)); - assert!((({ SImpl::scale_2_2(&s.as_pointer(), 5,) }) == 110)); - assert!((({ SImpl::scale_2_3(&s.as_pointer(), 5,) }) == 115)); - assert!((({ SImpl::count_3(&s.as_pointer(), 1,) }) == 101)); - assert!((({ SImpl::count_3_int_long(&s.as_pointer(), 1,) }) == 103)); - assert!((({ SImpl::plain_4(&s.as_pointer(), 1,) }) == 101)); - assert!((({ SImpl::plain_5(&s.as_pointer(), 1_i64,) }) == 102)); + assert!((({ S::width_1_char(s.as_pointer(), 3,) }) == 103)); + assert!((({ S::width_1_int(s.as_pointer(), 3,) }) == 112)); + assert!((({ S::scale_2_2(s.as_pointer(), 5,) }) == 110)); + assert!((({ S::scale_2_3(s.as_pointer(), 5,) }) == 115)); + assert!((({ S::count_3(s.as_pointer(), 1,) }) == 101)); + assert!((({ S::count_3_int_long(s.as_pointer(), 1,) }) == 103)); + assert!((({ S::plain_4(s.as_pointer(), 1,) }) == 101)); + assert!((({ S::plain_5(s.as_pointer(), 1_i64,) }) == 102)); let y: Value = Rc::new(RefCell::new(1)); - assert!((({ SImpl::take_6(&s.as_pointer(), y.as_pointer(),) }) == 102)); + assert!((({ S::take_6(s.as_pointer(), y.as_pointer(),) }) == 102)); assert!( (({ let _x: Value = Rc::new(RefCell::new(5)); - SImpl::take_7(&s.as_pointer(), _x.as_pointer()) + S::take_7(s.as_pointer(), _x.as_pointer()) }) == 107) ); assert!( (({ - SImpl::pick_8( - &s.as_pointer(), + S::pick_8( + s.as_pointer(), (Rc::new(RefCell::new(1)), Rc::new(RefCell::new(2))), ) }) == 101) ); assert!( (({ - SImpl::pick_9( - &s.as_pointer(), + S::pick_9( + s.as_pointer(), (Rc::new(RefCell::new(1)), Rc::new(RefCell::new(2_i64))), ) }) == 102) ); - assert!((({ SImpl::apply_10(&s.as_pointer(), FnPtr::)>::new(inc_0), 1,) }) == 102)); - assert!( - (({ SImpl::apply_11(&s.as_pointer(), FnPtr::, i32)>::new(add_1), 1,) }) == 111) - ); - assert!( - (({ SImpl::apply_12(&s.as_pointer(), FnPtr:: i32>::new(twice_2), 3,) }) == 106) - ); + assert!((({ S::apply_10(s.as_pointer(), FnPtr::)>::new(inc_0), 1,) }) == 102)); + assert!((({ S::apply_11(s.as_pointer(), FnPtr::, i32)>::new(add_1), 1,) }) == 111)); + assert!((({ S::apply_12(s.as_pointer(), FnPtr:: i32>::new(twice_2), 3,) }) == 106)); let c: Value = Rc::new(RefCell::new(3)); assert!( (({ @@ -119,8 +206,8 @@ fn main_0() -> i32 { Rc::new(RefCell::new(1)), Rc::new(RefCell::new(2_i64)), ))); - SImpl::combine_13( - &s.as_pointer(), + S::combine_13( + s.as_pointer(), _p.as_pointer(), FnPtr:: i32>::new(twice_2), (c.as_pointer()), @@ -135,8 +222,8 @@ fn main_0() -> i32 { Rc::new(RefCell::new(1)), Rc::new(RefCell::new(2)), ))); - SImpl::combine_14( - &s.as_pointer(), + S::combine_14( + s.as_pointer(), _p.as_pointer(), FnPtr::, i32)>::new(add_1), (z.as_pointer()), @@ -148,142 +235,12 @@ fn main_0() -> i32 { let a: Value = Rc::new(RefCell::new(::default())); let mut cs: Ptr = (s.as_pointer()); let cr: Ptr = s.as_pointer(); - assert!((({ Access_S_Impl::get_1(&a.as_pointer(), (s.as_pointer()),) }) == 100)); - assert!((({ Access_S_Impl::get_2(&a.as_pointer(), (cs).clone(),) }) == 101)); - assert!((({ Access_S_Impl::ref_3(&a.as_pointer(), s.as_pointer(),) }) == 102)); - assert!((({ Access_S_Impl::ref_4(&a.as_pointer(), (cr).clone(),) }) == 103)); + assert!((({ Access_S_::get_1(a.as_pointer(), (s.as_pointer()),) }) == 100)); + assert!((({ Access_S_::get_2(a.as_pointer(), (cs).clone(),) }) == 101)); + assert!((({ Access_S_::ref_3(a.as_pointer(), s.as_pointer(),) }) == 102)); + assert!((({ Access_S_::ref_4(a.as_pointer(), (cr).clone(),) }) == 103)); let mut b: Box_ = Box_ { v: 4 }; assert!((b.v == 4)); return 0; } -pub trait Access_S_Impl { - fn get_1(&self, p: Ptr) -> i32; - fn get_2(&self, p: Ptr) -> i32; - fn ref_3(&self, r: Ptr) -> i32; - fn ref_4(&self, r: Ptr) -> i32; -} -impl Access_S_Impl for Ptr { - fn get_1(&self, mut p: Ptr) -> i32 { - return p.with(|__s| __s.base); - } - fn get_2(&self, mut p: Ptr) -> i32 { - return (p.with(|__s| __s.base) + 1); - } - fn ref_3(&self, r: Ptr) -> i32 { - return (r.with(|__s| __s.base) + 2); - } - fn ref_4(&self, r: Ptr) -> i32 { - return (r.with(|__s| __s.base) + 3); - } -} -pub trait SImpl { - fn plain_4(&self, x: i32) -> i32; - fn plain_5(&self, x: i64) -> i32; - fn take_6(&self, x: Ptr) -> i32; - fn take_7(&self, x: Ptr) -> i32; - fn pick_8(&self, p: (Value, Value)) -> i32; - fn pick_9(&self, p: (Value, Value)) -> i32; - fn apply_10(&self, f: FnPtr)>, x: i32) -> i32; - fn apply_11(&self, f: FnPtr, i32)>, x: i32) -> i32; - fn apply_12(&self, f: FnPtr i32>, x: i32) -> i32; - fn combine_13( - &self, - p: Ptr<(Value, Value)>, - f: FnPtr i32>, - q: Ptr, - n: u64, - ) -> i32; - fn combine_14( - &self, - p: Ptr<(Value, Value)>, - f: FnPtr, i32)>, - q: Ptr, - n: u64, - ) -> i32; - fn width_1_char(&self, x: i32) -> i32; - fn width_1_int(&self, x: i32) -> i32; - fn scale_2_2(&self, x: i32) -> i32; - fn scale_2_3(&self, x: i32) -> i32; - fn count_3(&self, x: i32) -> i32; - fn count_3_int_long(&self, x: i32) -> i32; -} -impl SImpl for Ptr { - fn plain_4(&self, mut x: i32) -> i32 { - return ((*self).with(|__s| __s.base) + x); - } - fn plain_5(&self, mut x: i64) -> i32 { - return (((*self).with(|__s| __s.base) + (x as i32)) + 1); - } - fn take_6(&self, x: Ptr) -> i32 { - return (({ (*self).with(|__s| __s.base) } + { (x.read()) }) + 1); - } - fn take_7(&self, x: Ptr) -> i32 { - return (({ (*self).with(|__s| __s.base) } + { (x.read()) }) + 2); - } - fn pick_8(&self, p: (Value, Value)) -> i32 { - let p: Value<(Value, Value)> = Rc::new(RefCell::new(p)); - return ((*self).with(|__s| __s.base) + (*(*p.borrow()).0.borrow())); - } - fn pick_9(&self, p: (Value, Value)) -> i32 { - let p: Value<(Value, Value)> = Rc::new(RefCell::new(p)); - return ((*self).with(|__s| __s.base) + ((*(*p.borrow()).1.borrow()) as i32)); - } - fn apply_10(&self, mut f: FnPtr)>, x: i32) -> i32 { - let x: Value = Rc::new(RefCell::new(x)); - ({ f.call((x.as_pointer())) }); - return ((*self).with(|__s| __s.base) + (*x.borrow())); - } - fn apply_11(&self, mut f: FnPtr, i32)>, x: i32) -> i32 { - let x: Value = Rc::new(RefCell::new(x)); - ({ f.call((x.as_pointer()), 10) }); - return ((*self).with(|__s| __s.base) + (*x.borrow())); - } - fn apply_12(&self, mut f: FnPtr i32>, mut x: i32) -> i32 { - return ({ (*self).with(|__s| __s.base) } + { ({ f.call(x) }) }); - } - fn combine_13( - &self, - p: Ptr<(Value, Value)>, - mut f: FnPtr i32>, - mut q: Ptr, - mut n: u64, - ) -> i32 { - return ({ - ({ - ({ (*self).with(|__s| __s.base) } + { - ((*(*p.upgrade().deref()).1.borrow()) as i32) - }) - } + { ({ f.call((q.read())) }) }) - } + { (n as i32) }); - } - fn combine_14( - &self, - p: Ptr<(Value, Value)>, - mut f: FnPtr, i32)>, - mut q: Ptr, - mut n: u64, - ) -> i32 { - ({ f.call((q).clone(), (n as i32)) }); - return ({ ({ (*self).with(|__s| __s.base) } + { (*(*p.upgrade().deref()).0.borrow()) }) } - + { (q.read()) }); - } - fn width_1_char(&self, mut x: i32) -> i32 { - return ((*self).with(|__s| __s.base) + (x * (::std::mem::size_of::() as i32))); - } - fn width_1_int(&self, mut x: i32) -> i32 { - return ((*self).with(|__s| __s.base) + (x * (::std::mem::size_of::() as i32))); - } - fn scale_2_2(&self, mut x: i32) -> i32 { - return ((*self).with(|__s| __s.base) + (x * 2)); - } - fn scale_2_3(&self, mut x: i32) -> i32 { - return ((*self).with(|__s| __s.base) + (x * 3)); - } - fn count_3(&self, mut x: i32) -> i32 { - return (((*self).with(|__s| __s.base) + x) + (0 as i32)); - } - fn count_3_int_long(&self, mut x: i32) -> i32 { - return (((*self).with(|__s| __s.base) + x) + (2 as i32)); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/pair_converting_construction.rs b/tests/unit/out/refcount/pair_converting_construction.rs index ba1b6498b7..437a960d52 100644 --- a/tests/unit/out/refcount/pair_converting_construction.rs +++ b/tests/unit/out/refcount/pair_converting_construction.rs @@ -25,6 +25,11 @@ pub struct Celsius { #[offset(0)] pub degrees: i32, } +impl Celsius { + pub fn construct(this: Ptr, mut d: i32) { + field!(this, degrees).write(d); + } +} #[derive( Copy, Clone, @@ -44,6 +49,11 @@ pub struct Meters { #[offset(0)] pub value: i32, } +impl Meters { + pub fn to_i32(this: Ptr) -> i32 { + return this.with(|__s| __s.value); + } +} #[derive( Copy, Clone, @@ -63,6 +73,11 @@ pub struct Label { #[offset(0)] pub id: i32, } +impl Label { + pub fn construct(this: Ptr, c: Ptr) { + field!(this, id).write(c.with(|__s| __s.degrees)); + } +} #[derive( Copy, Clone, @@ -85,6 +100,16 @@ pub struct Owner { #[offset(4)] pub copied: i32, } +impl Owner { + pub fn construct_1(this: Ptr, c: Ptr) { + field!(this, taken).write(0); + field!(this, copied).write(c.with(|__s| __s.degrees)); + } + pub fn construct_2(this: Ptr, c: Ptr) { + field!(this, taken).write(c.with(|__s| __s.degrees)); + field!(this, copied).write(0); + } +} #[derive( Copy, Clone, @@ -104,6 +129,11 @@ pub struct Holder { #[offset(0)] pub value: i32, } +impl Holder { + pub fn construct(this: Ptr, mut c: Celsius) { + field!(this, value).write(c.degrees); + } +} #[derive( Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, TriviallyCopyable, )] @@ -113,10 +143,15 @@ pub struct Fallback { #[offset(0)] pub value: i32, } +impl Fallback { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, value).write(v); + } +} impl DefaultConstructible for Fallback { - fn default_constructor(this: &Ptr) { + fn default_constructor(this: Ptr) { { - FallbackImpl::construct(this, -1_i32); + Fallback::construct(this.clone(), -1_i32); } } } @@ -125,7 +160,7 @@ impl Default for Fallback { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - FallbackImpl::construct(&__v.as_pointer(), -1_i32); + Fallback::construct(__v.as_pointer(), -1_i32); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -167,6 +202,17 @@ pub struct Observer { #[offset(0)] pub seen: i32, } +impl Observer { + pub fn construct(this: Ptr, c: Ptr) { + field!(this, seen).write(c.with(|__s| __s.hits)); + field!(c, hits).with_mut(|__v| __v.postfix_inc()); + } +} +impl Tag { + pub fn construct(this: Ptr, u: Ptr) { + field!(this, code).write((u.with(|__s| __s.degrees) + 100)); + } +} #[derive( Copy, Clone, @@ -205,6 +251,16 @@ pub struct Name { #[offset(0)] pub len: i32, } +impl Name { + pub fn construct(this: Ptr, mut s: Ptr) { + field!(this, len).write(0); + 'loop_: while ((elem!(s, this.with(|__s| __s.len)).read()) != 0) { + field!(this, len).with_mut(|__v| { + __v.prefix_inc(); + }); + } + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -219,12 +275,12 @@ fn main_0() -> i32 { let from_ints: Value<(Value, Value)> = Rc::new(RefCell::new(( Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CelsiusImpl::construct(&__v.as_pointer(), 1); + Celsius::construct(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CelsiusImpl::construct(&__v.as_pointer(), 2); + Celsius::construct(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ))); @@ -232,10 +288,8 @@ fn main_0() -> i32 { assert!(({ (*(*from_ints.borrow()).1.borrow()).degrees } == 2)); let m: Value = Rc::new(RefCell::new(Meters { value: 7 })); let from_operators: Value<(Value, Value)> = Rc::new(RefCell::new(( - Rc::new(RefCell::new(({ MetersImpl::to_i32(&m.as_pointer()) }))), - Rc::new(RefCell::new( - (({ MetersImpl::to_i32(&m.as_pointer()) }) as i64), - )), + Rc::new(RefCell::new(({ Meters::to_i32(m.as_pointer()) }))), + Rc::new(RefCell::new((({ Meters::to_i32(m.as_pointer()) }) as i64))), ))); assert!(({ ((*(*from_operators.borrow()).0.borrow()) == 7) })); assert!(({ ((*(*from_operators.borrow()).1.borrow()) == 7_i64) })); @@ -289,12 +343,12 @@ fn main_0() -> i32 { let celsius: Value<(Value, Value)> = Rc::new(RefCell::new(( Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CelsiusImpl::construct(&__v.as_pointer(), 10); + Celsius::construct(__v.as_pointer(), 10); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CelsiusImpl::construct(&__v.as_pointer(), 11); + Celsius::construct(__v.as_pointer(), 11); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ))); @@ -313,12 +367,12 @@ fn main_0() -> i32 { match (Rc::new(RefCell::new(( Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CelsiusImpl::construct(&__v.as_pointer(), 12); + Celsius::construct(__v.as_pointer(), 12); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CelsiusImpl::construct(&__v.as_pointer(), 13); + Celsius::construct(__v.as_pointer(), 13); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ))) @@ -351,12 +405,12 @@ fn main_0() -> i32 { match (Rc::new(RefCell::new(( Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CelsiusImpl::construct(&__v.as_pointer(), 14); + Celsius::construct(__v.as_pointer(), 14); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - CelsiusImpl::construct(&__v.as_pointer(), 15); + Celsius::construct(__v.as_pointer(), 15); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ))) @@ -390,7 +444,7 @@ fn main_0() -> i32 { let forwarded_mutable_ref: Value<(Value, Value)> = Rc::new(RefCell::new(( Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ObserverImpl::construct(&__v.as_pointer(), counter.as_pointer()); + Observer::construct(__v.as_pointer(), counter.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), Rc::new(RefCell::new(0)), @@ -412,12 +466,12 @@ fn main_0() -> i32 { let forwarded_records: Value<(Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -38,8 +43,8 @@ pub struct B { pub v: i32, } impl DefaultConstructible for B { - fn default_constructor(this: &Ptr) { - field!((*this), v).write(2); + fn default_constructor(this: Ptr) { + field!(this, v).write(2); } } impl Default for B { @@ -47,7 +52,7 @@ impl Default for B { { { let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() } } @@ -72,6 +77,11 @@ pub struct NoDefault { #[offset(0)] pub v: i32, } +impl NoDefault { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } +} pub fn used_0(mut x: A) -> i32 { return x.v; } @@ -103,6 +113,14 @@ pub struct S_NoDefault_ { #[offset(0)] pub v: i32, } +impl S_NoDefault_ { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } + pub fn get(this: Ptr, mut t: NoDefault) -> i32 { + return (this.with(|__s| __s.v) + t.v); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -112,7 +130,7 @@ fn main_0() -> i32 { (({ used_0({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 1) @@ -121,7 +139,7 @@ fn main_0() -> i32 { (({ used_0({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - AImpl::construct_1(&__v.as_pointer(), 5); + A::construct_1(__v.as_pointer(), 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 5) @@ -130,7 +148,7 @@ fn main_0() -> i32 { (({ used_1({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - DefaultConstructible::default_constructor(&__v.as_pointer()); + DefaultConstructible::default_constructor(__v.as_pointer()); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 2) @@ -140,7 +158,7 @@ fn main_0() -> i32 { scaled_2( { let __v: Value = Rc::new(RefCell::new(::zero_init())); - AImpl::construct_1(&__v.as_pointer(), 3); + A::construct_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, (4usize as i32), @@ -152,7 +170,7 @@ fn main_0() -> i32 { scaled_2( { let __v: Value = Rc::new(RefCell::new(::zero_init())); - AImpl::construct_1(&__v.as_pointer(), 3); + A::construct_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }, 2, @@ -163,7 +181,7 @@ fn main_0() -> i32 { (({ always_given_3({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - NoDefaultImpl::construct(&__v.as_pointer(), 3); + NoDefault::construct(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 3) @@ -171,41 +189,13 @@ fn main_0() -> i32 { object!(s, S_NoDefault_(1)); assert!( (({ - S_NoDefault_Impl::get(&s.as_pointer(), { + S_NoDefault_::get(s.as_pointer(), { let __v: Value = Rc::new(RefCell::new(::zero_init())); - NoDefaultImpl::construct(&__v.as_pointer(), 4); + NoDefault::construct(__v.as_pointer(), 4); Rc::try_unwrap(__v).ok().unwrap().into_inner() }) }) == 5) ); return 0; } -pub trait AImpl { - fn construct_1(&self, v: i32); -} -impl AImpl for Ptr { - fn construct_1(&self, mut v: i32) { - field!((*self), v).write(v); - } -} -pub trait NoDefaultImpl { - fn construct(&self, v: i32); -} -impl NoDefaultImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - } -} -pub trait S_NoDefault_Impl { - fn construct(&self, v: i32); - fn get(&self, t: NoDefault) -> i32; -} -impl S_NoDefault_Impl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - } - fn get(&self, mut t: NoDefault) -> i32 { - return ((*self).with(|__s| __s.v) + t.v); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/temporary_field_addr.rs b/tests/unit/out/refcount/temporary_field_addr.rs index d246ec5fa3..3b40ef24e4 100644 --- a/tests/unit/out/refcount/temporary_field_addr.rs +++ b/tests/unit/out/refcount/temporary_field_addr.rs @@ -27,8 +27,8 @@ pub struct Inner { pub values: Vec, } impl DefaultConstructible for Inner { - fn default_constructor(this: &Ptr) { - field!((*this), values).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, values).write(Vec::new()); } } #[derive( @@ -58,10 +58,10 @@ pub struct Outer { pub name: Box<[i8]>, } impl DefaultConstructible for Outer { - fn default_constructor(this: &Ptr) { - field!((*this), values).write(Vec::new()); - DefaultConstructible::default_constructor(&field_ptr!(this, inner)); - field!((*this), name).write((0..8).map(|_| 0_i8).collect::>()); + fn default_constructor(this: Ptr) { + field!(this, values).write(Vec::new()); + DefaultConstructible::default_constructor(field_ptr!(this, inner)); + field!(this, name).write((0..8).map(|_| 0_i8).collect::>()); } } impl Default for Outer { diff --git a/tests/unit/out/refcount/temporary_field_ctor_arg.rs b/tests/unit/out/refcount/temporary_field_ctor_arg.rs index 2e8b87b90f..776b83083a 100644 --- a/tests/unit/out/refcount/temporary_field_ctor_arg.rs +++ b/tests/unit/out/refcount/temporary_field_ctor_arg.rs @@ -27,8 +27,8 @@ pub struct Outer { pub values: Vec, } impl DefaultConstructible for Outer { - fn default_constructor(this: &Ptr) { - field!((*this), values).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, values).write(Vec::new()); } } pub fn make_0(this: Ptr) { @@ -56,6 +56,11 @@ pub struct H { #[offset(0)] pub last: i32, } +impl H { + pub fn construct(this: Ptr, values: Ptr>) { + field!(this, last).write((index!(values, 3_usize).read())); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -63,8 +68,8 @@ pub fn main() { fn main_0() -> i32 { object!(h, H, |h| { let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); - HImpl::construct( - h, + H::construct( + h.clone(), (match { ({ make_0(Ptr::clone(&__tmp_1.as_pointer())) }); __tmp_1.as_pointer() @@ -76,12 +81,4 @@ fn main_0() -> i32 { printf!(b"%d\n", { (*h.borrow()).last }); return 0; } -pub trait HImpl { - fn construct(&self, values: Ptr>); -} -impl HImpl for Ptr { - fn construct(&self, values: Ptr>) { - field!((*self), last).write((index!(values, 3_usize).read())); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/temporary_field_two_args.rs b/tests/unit/out/refcount/temporary_field_two_args.rs index 324e8a8a43..58f50b3bfa 100644 --- a/tests/unit/out/refcount/temporary_field_two_args.rs +++ b/tests/unit/out/refcount/temporary_field_two_args.rs @@ -27,8 +27,8 @@ pub struct Inner { pub values: Vec, } impl DefaultConstructible for Inner { - fn default_constructor(this: &Ptr) { - field!((*this), values).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, values).write(Vec::new()); } } #[derive( @@ -55,9 +55,9 @@ pub struct Outer { pub inner: Inner, } impl DefaultConstructible for Outer { - fn default_constructor(this: &Ptr) { - field!((*this), values).write(Vec::new()); - DefaultConstructible::default_constructor(&field_ptr!(this, inner)); + fn default_constructor(this: Ptr) { + field!(this, values).write(Vec::new()); + DefaultConstructible::default_constructor(field_ptr!(this, inner)); } } pub fn make_0(this: Ptr) { diff --git a/tests/unit/out/refcount/this.rs b/tests/unit/out/refcount/this.rs index 831fafe88f..6967f7c14c 100644 --- a/tests/unit/out/refcount/this.rs +++ b/tests/unit/out/refcount/this.rs @@ -27,6 +27,86 @@ pub struct S { #[byte_size(8)] pub self__: Ptr, } +impl S { + pub fn construct_1(this: Ptr, mut a: i32) { + field!(this, a_).write(a); + field!(this, self__).write(Ptr::::null()); + } + pub fn construct_2(this: Ptr, mut a: i32, mut other: Ptr) { + field!(this, a_).write(a); + field!(this, self__).write(Ptr::::null()); + if (this == other) { + field!(this, self__).write(Ptr::::null()); + } else { + field!(this, self__).write((other).clone()); + } + } + pub fn construct_3(this: Ptr, mut a: i32, mut other: Ptr) { + field!(this, a_).write(a); + field!(this, self__).write(Ptr::::null()); + if (this == other) { + field!(this, self__).write(Ptr::::null()); + } + } + pub fn returns_this_reference(this: Ptr) -> Ptr { + return (this).clone(); + } + pub fn returns_this_pointer(this: Ptr) -> Ptr { + return (this).clone(); + } + pub fn inc(this: Ptr) -> Ptr { + field!(this, a_).with_mut(|__v| __v.postfix_inc()); + return (this).clone(); + } + pub fn set_from_this(this: Ptr) { + field!(this, a_).write((this.with(|__s| __s.a_) + 1)); + } + pub fn get(this: Ptr) -> i32 { + return this.with(|__s| __s.a_); + } + pub fn twice(this: Ptr) -> i32 { + return (({ S::get(this.clone()) }) * 2); + } + pub fn link(this: Ptr) { + field!(this, self__).write((this).clone()); + } + pub fn bump_me(this: Ptr) { + ({ bump_0((this).clone()) }); + } + pub fn cref(this: Ptr) -> Ptr { + return (this).clone(); + } + pub fn is(this: Ptr, mut o: Ptr) -> bool { + return (o == this); + } + pub fn destroy(this: Ptr) { + this.delete(); + } + pub fn reset(this: Ptr) { + let __rhs = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + S::construct_1(__v.as_pointer(), 0); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; + this.write(__rhs); + } + pub fn copy_if_different_const(this: Ptr, mut other: Ptr) -> bool { + if (this == other) { + return false; + } + field!(this, a_).write(other.with(|__s| __s.a_)); + field!(this, self__).write(other.with(|__s| __s.self__.clone())); + return true; + } + pub fn copy_if_different(this: Ptr, mut other: Ptr) -> bool { + if (this == other) { + return false; + } + field!(this, a_).write(other.with(|__s| __s.a_)); + field!(this, self__).write(other.with(|__s| __s.self__.clone())); + return true; + } +} pub fn bump_0(mut p: Ptr) { field!(p, a_).with_mut(|__v| __v.postfix_inc()); } @@ -49,65 +129,72 @@ pub struct D { #[offset(0)] pub a_: i32, } +impl D { + pub fn construct(this: Ptr, mut a: i32) { + field!(this, a_).write(a); + { + field!(this, a_).with_mut(|__v| *__v = *__v * 2) + }; + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { object!(s, S::construct_1(1)); - let ref_: Ptr = ({ SImpl::returns_this_reference(&s.as_pointer()) }); + let ref_: Ptr = ({ S::returns_this_reference(s.as_pointer()) }); field!(ref_, a_).with_mut(|__v| __v.postfix_inc()); assert!(({ (*s.borrow()).a_ } == 2)); - let mut ptr: Ptr = ({ SImpl::returns_this_pointer(&s.as_pointer()) }); + let mut ptr: Ptr = ({ S::returns_this_pointer(s.as_pointer()) }); field!(ptr, a_).with_mut(|__v| __v.postfix_inc()); assert!(({ (*s.borrow()).a_ } == 3)); - ({ SImpl::inc(&({ SImpl::inc(&({ SImpl::inc(&s.as_pointer()) })) })) }); + ({ S::inc(({ S::inc(({ S::inc(s.as_pointer()) })) })) }); assert!(({ (*s.borrow()).a_ } == 6)); - ({ SImpl::set_from_this(&s.as_pointer()) }); + ({ S::set_from_this(s.as_pointer()) }); assert!(({ (*s.borrow()).a_ } == 7)); - assert!((({ SImpl::twice(&s.as_pointer(),) }) == 14)); - ({ SImpl::link(&s.as_pointer()) }); + assert!((({ S::twice(s.as_pointer(),) }) == 14)); + ({ S::link(s.as_pointer()) }); assert!(({ { (*s.borrow()).self__.clone() } } == { (s.as_pointer()) })); field!({ (*s.borrow()).self__.clone() }, a_).with_mut(|__v| __v.postfix_inc()); assert!(({ (*s.borrow()).a_ } == 8)); - ({ SImpl::bump_me(&s.as_pointer()) }); + ({ S::bump_me(s.as_pointer()) }); assert!(({ (*s.borrow()).a_ } == 9)); object!(d, D(3)); assert!(({ (*d.borrow()).a_ } == 6)); - let cr: Ptr = ({ SImpl::cref(&s.as_pointer()) }); + let cr: Ptr = ({ S::cref(s.as_pointer()) }); assert!((cr.with(|__s| __s.a_) == 9)); object!(t, S::construct_1(0)); - assert!(({ SImpl::is(&s.as_pointer(), (s.as_pointer()),) })); - assert!(!({ SImpl::is(&s.as_pointer(), (t.as_pointer()),) })); + assert!(({ S::is(s.as_pointer(), (s.as_pointer()),) })); + assert!(!({ S::is(s.as_pointer(), (t.as_pointer()),) })); let mut p: Ptr = { let __p = Ptr::alloc(::zero_init()); - SImpl::construct_1(&__p, 1); + S::construct_1(__p.clone(), 1); __p }; - let mut q: Ptr = ({ SImpl::returns_this_pointer(&p) }); + let mut q: Ptr = ({ S::returns_this_pointer((p).clone()) }); field!(q, a_).with_mut(|__v| __v.postfix_inc()); assert!((p.with(|__s| __s.a_) == 2)); p.delete(); let mut h: Ptr = { let __p = Ptr::alloc(::zero_init()); - SImpl::construct_1(&__p, 5); + S::construct_1(__p.clone(), 5); __p }; - ({ SImpl::destroy(&h) }); - ({ SImpl::reset(&s.as_pointer()) }); + ({ S::destroy((h).clone()) }); + ({ S::reset(s.as_pointer()) }); assert!(({ (*s.borrow()).a_ } == 0)); assert!(({ (*s.borrow()).self__.clone() }).is_null()); assert!( - ((({ SImpl::copy_if_different(&s.as_pointer(), (s.as_pointer()),) }) as i32) - == (false as i32)) + ((({ S::copy_if_different(s.as_pointer(), (s.as_pointer()),) }) as i32) == (false as i32)) ); assert!( - ((({ SImpl::copy_if_different_const(&s.as_pointer(), (s.as_pointer()),) }) as i32) + ((({ S::copy_if_different_const(s.as_pointer(), (s.as_pointer()),) }) as i32) == (false as i32)) ); object!(other, S::construct_1(22)); assert!( - ((({ SImpl::copy_if_different(&s.as_pointer(), (other.as_pointer()),) }) as i32) + ((({ S::copy_if_different(s.as_pointer(), (other.as_pointer()),) }) as i32) == (true as i32)) ); assert!(({ (*s.borrow()).a_ } == { (*other.borrow()).a_ })); @@ -116,121 +203,11 @@ fn main_0() -> i32 { assert!(({ { (*u.borrow()).self__.clone() } } == { (s.as_pointer()) })); let s_const: Value = Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - SImpl::construct_1(&__v.as_pointer(), 100); + S::construct_1(__v.as_pointer(), 100); Rc::try_unwrap(__v).ok().unwrap().into_inner() })); object!(u1, S::construct_3(1, (s_const.as_pointer()))); assert!(({ (*u1.borrow()).self__.clone() }).is_null()); return 0; } -pub trait DImpl { - fn construct(&self, a: i32); -} -impl DImpl for Ptr { - fn construct(&self, mut a: i32) { - field!((*self), a_).write(a); - { - field!((*self), a_).with_mut(|__v| *__v = *__v * 2) - }; - } -} -pub trait SImpl { - fn construct_1(&self, a: i32); - fn construct_2(&self, a: i32, other: Ptr); - fn construct_3(&self, a: i32, other: Ptr); - fn returns_this_reference(&self) -> Ptr; - fn returns_this_pointer(&self) -> Ptr; - fn inc(&self) -> Ptr; - fn set_from_this(&self); - fn get(&self) -> i32; - fn twice(&self) -> i32; - fn link(&self); - fn bump_me(&self); - fn cref(&self) -> Ptr; - fn is(&self, o: Ptr) -> bool; - fn destroy(&self); - fn reset(&self); - fn copy_if_different_const(&self, other: Ptr) -> bool; - fn copy_if_different(&self, other: Ptr) -> bool; -} -impl SImpl for Ptr { - fn construct_1(&self, mut a: i32) { - field!((*self), a_).write(a); - field!((*self), self__).write(Ptr::::null()); - } - fn construct_2(&self, mut a: i32, mut other: Ptr) { - field!((*self), a_).write(a); - field!((*self), self__).write(Ptr::::null()); - if ((*self) == other) { - field!((*self), self__).write(Ptr::::null()); - } else { - field!((*self), self__).write((other).clone()); - } - } - fn construct_3(&self, mut a: i32, mut other: Ptr) { - field!((*self), a_).write(a); - field!((*self), self__).write(Ptr::::null()); - if ((*self) == other) { - field!((*self), self__).write(Ptr::::null()); - } - } - fn returns_this_reference(&self) -> Ptr { - return (*self).clone(); - } - fn returns_this_pointer(&self) -> Ptr { - return (*self).clone(); - } - fn inc(&self) -> Ptr { - field!((*self), a_).with_mut(|__v| __v.postfix_inc()); - return (*self).clone(); - } - fn set_from_this(&self) { - field!((*self), a_).write(((*self).with(|__s| __s.a_) + 1)); - } - fn get(&self) -> i32 { - return (*self).with(|__s| __s.a_); - } - fn twice(&self) -> i32 { - return (({ SImpl::get(self) }) * 2); - } - fn link(&self) { - field!((*self), self__).write((*self).clone()); - } - fn bump_me(&self) { - ({ bump_0((*self).clone()) }); - } - fn cref(&self) -> Ptr { - return (*self).clone(); - } - fn is(&self, mut o: Ptr) -> bool { - return (o == (*self)); - } - fn destroy(&self) { - (*self).delete(); - } - fn reset(&self) { - let __rhs = { - let __v: Value = Rc::new(RefCell::new(::zero_init())); - SImpl::construct_1(&__v.as_pointer(), 0); - Rc::try_unwrap(__v).ok().unwrap().into_inner() - }; - (*self).write(__rhs); - } - fn copy_if_different_const(&self, mut other: Ptr) -> bool { - if ((*self) == other) { - return false; - } - field!((*self), a_).write(other.with(|__s| __s.a_)); - field!((*self), self__).write(other.with(|__s| __s.self__.clone())); - return true; - } - fn copy_if_different(&self, mut other: Ptr) -> bool { - if ((*self) == other) { - return false; - } - field!((*self), a_).write(other.with(|__s| __s.a_)); - field!((*self), self__).write(other.with(|__s| __s.self__.clone())); - return true; - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/typedef-anon-struct.rs b/tests/unit/out/refcount/typedef-anon-struct.rs index d99fbe7bd9..a4735ddfbe 100644 --- a/tests/unit/out/refcount/typedef-anon-struct.rs +++ b/tests/unit/out/refcount/typedef-anon-struct.rs @@ -46,8 +46,8 @@ pub struct Outer { pub runs: Vec, } impl DefaultConstructible for Outer { - fn default_constructor(this: &Ptr) { - field!((*this), runs).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, runs).write(Vec::new()); } } pub fn main() { diff --git a/tests/unit/out/refcount/unboxed_conditional_iterator.rs b/tests/unit/out/refcount/unboxed_conditional_iterator.rs index 15b18cc32e..2f66920724 100644 --- a/tests/unit/out/refcount/unboxed_conditional_iterator.rs +++ b/tests/unit/out/refcount/unboxed_conditional_iterator.rs @@ -59,7 +59,7 @@ pub fn lehmer_3(mut sigma: Ptr, mut len: u32, mut code: Ptr) { let mut __tmp_1 = { items.decay().end() }; let mut __it = (__tmp_0).clone(); while __it != __tmp_1 - && !CppEq::equal(&__it.iter_deref(), &sigma.offset((i) as isize)) + && !CppEq::equal(__it.iter_deref(), sigma.offset((i) as isize).clone()) { __it.iter_inc(); } diff --git a/tests/unit/out/refcount/unboxed_locals.rs b/tests/unit/out/refcount/unboxed_locals.rs index 1d74367807..be10bc8eed 100644 --- a/tests/unit/out/refcount/unboxed_locals.rs +++ b/tests/unit/out/refcount/unboxed_locals.rs @@ -172,7 +172,7 @@ fn main_0() -> i32 { let high: Value = Rc::new(RefCell::new(3)); let mut low: i32 = { let __tmp_0: Value = Rc::new(RefCell::new(2)); - (if CppLess::less(&__tmp_0.as_pointer(), &high.as_pointer()) { + (if CppLess::less(__tmp_0.as_pointer().clone(), high.as_pointer().clone()) { __tmp_0.as_pointer() } else { high.as_pointer() diff --git a/tests/unit/out/refcount/unboxed_records.rs b/tests/unit/out/refcount/unboxed_records.rs index 9466e8a26b..aed059e058 100644 --- a/tests/unit/out/refcount/unboxed_records.rs +++ b/tests/unit/out/refcount/unboxed_records.rs @@ -72,9 +72,16 @@ pub struct Counter { #[offset(0)] pub n: i32, } +impl Counter { + pub fn inc(this: Ptr) { + field!(this, n).with_mut(|__v| { + __v.prefix_inc(); + }); + } +} impl DefaultConstructible for Counter { - fn default_constructor(this: &Ptr) { - field!((*this), n).write(0); + fn default_constructor(this: Ptr) { + field!(this, n).write(0); } } impl Default for Counter { @@ -142,18 +149,8 @@ fn main_0() -> i32 { ({ set_0((field_ptr!(field_addr.as_pointer(), b)), 7) }); assert!(({ (*field_addr.borrow()).b } == 7)); object!(counter, Counter); - ({ CounterImpl::inc(&counter.as_pointer()) }); + ({ Counter::inc(counter.as_pointer()) }); assert!(({ (*counter.borrow()).n } == 1)); return 0; } -pub trait CounterImpl { - fn inc(&self); -} -impl CounterImpl for Ptr { - fn inc(&self) { - field!((*self), n).with_mut(|__v| { - __v.prefix_inc(); - }); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/unique_ptr.rs b/tests/unit/out/refcount/unique_ptr.rs index 68bef48b82..bd740b79fa 100644 --- a/tests/unit/out/refcount/unique_ptr.rs +++ b/tests/unit/out/refcount/unique_ptr.rs @@ -16,9 +16,18 @@ pub struct SafePointer { #[byte_size(8)] pub ptr: Option>, } +impl SafePointer { + pub fn inc(this: Ptr) { + this.with(|__s| __s.ptr.clone()) + .as_pointer() + .with_mut(|__v| { + __v.prefix_inc(); + }); + } +} impl DefaultConstructible for SafePointer { - fn default_constructor(this: &Ptr) { - field!((*this), ptr).write(None); + fn default_constructor(this: Ptr) { + field!(this, ptr).write(None); } } #[derive( @@ -40,6 +49,16 @@ pub struct Pair { #[offset(4)] pub y: i32, } +impl Pair { + pub fn inc(this: Ptr, mut k: i32) { + { + field!(this, x).with_mut(|__v| *__v = *__v + k) + }; + { + field!(this, y).with_mut(|__v| *__v = *__v + k) + }; + } +} pub fn DoStuffWithSafePointer_0(safe_ptr: Ptr>>) { let mut x1: Option> = Some(Rc::new(RefCell::new(0))); let mut x2: Option> = Some(Rc::new(RefCell::new(0))); @@ -60,8 +79,8 @@ pub fn DoStuffWithSafePointer_0(safe_ptr: Ptr>>) { (*__b0) = x1.take(); }), }; - ({ SafePointerImpl::inc(&({ (*safe_ptr.upgrade().deref()).as_pointer() })) }); - ({ SafePointerImpl::inc(&({ (*safe_ptr.upgrade().deref()).as_pointer() })) }); + ({ SafePointer::inc(({ (*safe_ptr.upgrade().deref()).as_pointer() })) }); + ({ SafePointer::inc(({ (*safe_ptr.upgrade().deref()).as_pointer() })) }); let mut x3: Option> = Some(Rc::new(RefCell::new(10))); let mut x4: Option> = Some(Rc::new(RefCell::new(20))); x3.as_pointer() @@ -77,7 +96,7 @@ pub fn DoStuffWithSafePointer_0(safe_ptr: Ptr>>) { x: (raw_ptr2.read()), y: 5, }))); - ({ PairImpl::inc(&(pair.as_pointer()), 10) }); + ({ Pair::inc((pair.as_pointer()), 10) }); ({ (*safe_ptr.upgrade().deref()).as_pointer() }) .with(|__s| (__s).ptr.clone()) .as_pointer() @@ -159,7 +178,7 @@ pub fn RndStuff_2() { 'for_body: { assert!((elem!(p3_0, i).with(|__s| __s.x) == 1)); assert!((elem!(p3_0, i).with(|__s| __s.y) == 2)); - ({ PairImpl::inc(&({ (*x3.borrow()).decay().offset((i as usize)) }), 10) }); + ({ Pair::inc(({ (*x3.borrow()).decay().offset((i as usize)) }), 10) }); assert!((elem!(p3_0, i).with(|__s| __s.x) == 11)); assert!((elem!(p3_0, i).with(|__s| __s.y) == 12)); } @@ -194,7 +213,7 @@ pub fn RndStuff_2() { 'for_body: { assert!((elem!(p3_1, i).with(|__s| __s.x) == -1_i32)); assert!((elem!(p3_1, i).with(|__s| __s.y) == -2_i32)); - ({ PairImpl::inc(&({ (*x3.borrow()).decay().offset((i as usize)) }), -10_i32) }); + ({ Pair::inc(({ (*x3.borrow()).decay().offset((i as usize)) }), -10_i32) }); assert!((elem!(p3_1, i).with(|__s| __s.x) == -11_i32)); assert!((elem!(p3_1, i).with(|__s| __s.y) == -12_i32)); } @@ -232,30 +251,4 @@ fn main_0() -> i32 { ({ unique_ptr_that_wraps_container_3() }); return 0; } -pub trait PairImpl { - fn inc(&self, k: i32); -} -impl PairImpl for Ptr { - fn inc(&self, mut k: i32) { - { - field!((*self), x).with_mut(|__v| *__v = *__v + k) - }; - { - field!((*self), y).with_mut(|__v| *__v = *__v + k) - }; - } -} -pub trait SafePointerImpl { - fn inc(&self); -} -impl SafePointerImpl for Ptr { - fn inc(&self) { - (*self) - .with(|__s| __s.ptr.clone()) - .as_pointer() - .with_mut(|__v| { - __v.prefix_inc(); - }); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/unique_ptr_const_deref.rs b/tests/unit/out/refcount/unique_ptr_const_deref.rs index 454aaf6fff..5bdcba70e9 100644 --- a/tests/unit/out/refcount/unique_ptr_const_deref.rs +++ b/tests/unit/out/refcount/unique_ptr_const_deref.rs @@ -17,8 +17,8 @@ pub struct Holder { pub val: Option>, } impl DefaultConstructible for Holder { - fn default_constructor(this: &Ptr) { - field!((*this), val).write(None); + fn default_constructor(this: Ptr) { + field!(this, val).write(None); } } pub fn read_val_0(mut h: Ptr) -> i32 { diff --git a/tests/unit/out/refcount/unique_ptr_field_reset.rs b/tests/unit/out/refcount/unique_ptr_field_reset.rs index 4f6de52840..78a2bb0ea3 100644 --- a/tests/unit/out/refcount/unique_ptr_field_reset.rs +++ b/tests/unit/out/refcount/unique_ptr_field_reset.rs @@ -35,10 +35,18 @@ pub struct Holder { #[offset(8)] pub n: i32, } +impl Holder { + pub fn set(this: Ptr, mut p: Ptr) { + { + let _p: Ptr<_> = (p).clone(); + field_ptr!(this, data).write(_p.to_owned_opt()) + }; + } +} impl DefaultConstructible for Holder { - fn default_constructor(this: &Ptr) { - field!((*this), data).write(None); - field!((*this), n).write(0_i32); + fn default_constructor(this: Ptr) { + field!(this, data).write(None); + field!(this, n).write(0_i32); } } pub fn main() { @@ -59,7 +67,7 @@ fn main_0() -> i32 { .with(|__s| __s.v) == 3) ); - ({ HolderImpl::set(&h.as_pointer(), Ptr::alloc(Data { v: 4 })) }); + ({ Holder::set(h.as_pointer(), Ptr::alloc(Data { v: 4 })) }); assert!( (hp.with(|__s| __s.data.clone()) .as_pointer() @@ -78,15 +86,4 @@ fn main_0() -> i32 { ); return 0; } -pub trait HolderImpl { - fn set(&self, p: Ptr); -} -impl HolderImpl for Ptr { - fn set(&self, mut p: Ptr) { - { - let _p: Ptr<_> = (p).clone(); - field_ptr!((*self), data).write(_p.to_owned_opt()) - }; - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/unique_ptr_nested.rs b/tests/unit/out/refcount/unique_ptr_nested.rs index 83088c96fd..4bd124f7ec 100644 --- a/tests/unit/out/refcount/unique_ptr_nested.rs +++ b/tests/unit/out/refcount/unique_ptr_nested.rs @@ -36,8 +36,8 @@ pub struct Outer { pub inner: Option>, } impl DefaultConstructible for Outer { - fn default_constructor(this: &Ptr) { - field!((*this), inner).write(None); + fn default_constructor(this: Ptr) { + field!(this, inner).write(None); } } pub fn main() { diff --git a/tests/unit/out/refcount/va_list_field.rs b/tests/unit/out/refcount/va_list_field.rs index 7f5725c809..b1d257ca32 100644 --- a/tests/unit/out/refcount/va_list_field.rs +++ b/tests/unit/out/refcount/va_list_field.rs @@ -44,9 +44,15 @@ pub struct Guard_1 { #[offset(8)] pub active: bool, } +impl Guard_1 { + pub fn construct(this: Ptr, val: Ptr>) { + field!(this, ap).write((val).clone()); + field!(this, active).write(true); + } +} impl Destructible for Guard_1 { - fn destroy(this: &Ptr) { - if (*this).with(|__s| __s.active) {} + fn destroy(this: Ptr) { + if this.with(|__s| __s.active) {} } } pub fn sum_ptr_2(n: i32, __args: Box<[VaArg]>) -> i32 { @@ -95,13 +101,4 @@ fn main_0() -> i32 { assert!((({ sum_ptr_2(2, Box::new([(4).into(), (5).into(),])) }) == 9)); return 0; } -pub trait Guard_1Impl { - fn construct(&self, val: Ptr>); -} -impl Guard_1Impl for Ptr { - fn construct(&self, val: Ptr>) { - field!((*self), ap).write((val).clone()); - field!((*self), active).write(true); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/vector.rs b/tests/unit/out/refcount/vector.rs index 50a02a2158..47f5e85479 100644 --- a/tests/unit/out/refcount/vector.rs +++ b/tests/unit/out/refcount/vector.rs @@ -48,9 +48,9 @@ pub struct Foo { pub b: Vec, } impl DefaultConstructible for Foo { - fn default_constructor(this: &Ptr) { - field!((*this), a).write(Vec::new()); - field!((*this), b).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, a).write(Vec::new()); + field!(this, b).write(Vec::new()); } } #[derive( @@ -72,6 +72,11 @@ pub struct Wrapped { #[offset(0)] pub v: i32, } +impl Wrapped { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, v).write(v); + } +} pub fn exchange_1(x: Ptr>, y: Ptr>) { x.swap_with(&(y).clone(), |__v| __v.with_mut(std::mem::take)); } @@ -795,12 +800,4 @@ fn main_0() -> i32 { } return 0; } -pub trait WrappedImpl { - fn construct(&self, v: i32); -} -impl WrappedImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), v).write(v); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/vector_iter_range_ctor.rs b/tests/unit/out/refcount/vector_iter_range_ctor.rs index cc1b881f20..688722f1c7 100644 --- a/tests/unit/out/refcount/vector_iter_range_ctor.rs +++ b/tests/unit/out/refcount/vector_iter_range_ctor.rs @@ -25,6 +25,11 @@ pub struct Degrees { #[offset(0)] pub value: i32, } +impl Degrees { + pub fn construct(this: Ptr, mut v: i32) { + field!(this, value).write(v); + } +} #[derive( Copy, Clone, @@ -44,6 +49,11 @@ pub struct Reading { #[offset(0)] pub raw_: i32, } +impl Reading { + pub fn to_i64(this: Ptr) -> i64 { + return ((this.with(|__s| __s.raw_) as i64) * 10_i64); + } +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -237,20 +247,4 @@ fn main_0() -> i32 { assert!((v8[0_usize] == 40_i64) && (v8[1_usize] == 50_i64)); return 0; } -pub trait DegreesImpl { - fn construct(&self, v: i32); -} -impl DegreesImpl for Ptr { - fn construct(&self, mut v: i32) { - field!((*self), value).write(v); - } -} -pub trait ReadingImpl { - fn to_i64(&self) -> i64; -} -impl ReadingImpl for Ptr { - fn to_i64(&self) -> i64 { - return (((*self).with(|__s| __s.raw_) as i64) * 10_i64); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/vector_subscript_direct.rs b/tests/unit/out/refcount/vector_subscript_direct.rs index cecfe4bdc3..7eca784f53 100644 --- a/tests/unit/out/refcount/vector_subscript_direct.rs +++ b/tests/unit/out/refcount/vector_subscript_direct.rs @@ -25,6 +25,11 @@ pub struct Point { #[offset(4)] pub y: i32, } +impl Point { + pub fn sum(this: Ptr) -> i32 { + return (this.with(|__s| __s.x) + this.with(|__s| __s.y)); + } +} #[derive( Clone, Record, @@ -49,9 +54,9 @@ pub struct Holder { pub points: Vec, } impl DefaultConstructible for Holder { - fn default_constructor(this: &Ptr) { - field!((*this), values).write(Vec::new()); - field!((*this), points).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, values).write(Vec::new()); + field!(this, points).write(Vec::new()); } } pub fn push_and_index_0(v: Ptr>) -> i32 { @@ -122,9 +127,7 @@ fn main_0() -> i32 { }); field!(vec_elem!(h.as_pointer(), points, 0_usize), y).write(5); assert!(((vec_elem!(h.as_pointer(), values, 1_usize).read()) == 6)); - assert!( - (({ PointImpl::sum(&field_ref!(h.as_pointer(), points).decay().offset(0_usize),) }) == 6) - ); + assert!((({ Point::sum(field_ref!(h.as_pointer(), points).decay().offset(0_usize),) }) == 6)); let mut hp: Ptr = (h.as_pointer()); vec_elem!(hp, values, 0_usize).write(((vec_elem!(hp, values, 1_usize).read()) + 1)); field!(vec_elem!(hp, points, 0_usize), x).write((vec_elem!(hp, values, 0_usize).read())); @@ -174,12 +177,4 @@ fn main_0() -> i32 { assert!(({ (*a.borrow())[1_usize] } == 10)); return 0; } -pub trait PointImpl { - fn sum(&self) -> i32; -} -impl PointImpl for Ptr { - fn sum(&self) -> i32 { - return ((*self).with(|__s| __s.x) + (*self).with(|__s| __s.y)); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/vector_with_allocator.rs b/tests/unit/out/refcount/vector_with_allocator.rs index 2683886115..140a20b210 100644 --- a/tests/unit/out/refcount/vector_with_allocator.rs +++ b/tests/unit/out/refcount/vector_with_allocator.rs @@ -20,6 +20,14 @@ use std::rc::{Rc, Weak}; )] #[byte_size(1)] pub struct TestAllocator_int_ {} +impl TestAllocator_int_ { + pub fn allocate(this: Ptr, mut n: usize) -> Ptr { + return Ptr::alloc_array((0..n).map(|_| 0_i32).collect::>()); + } + pub fn deallocate(this: Ptr, mut p: Ptr, mut _a1: usize) { + p.delete(); + } +} #[derive( Copy, Clone, @@ -34,6 +42,14 @@ pub struct TestAllocator_int_ {} )] #[byte_size(1)] pub struct TestAllocator_double_ {} +impl TestAllocator_double_ { + pub fn allocate(this: Ptr, mut n: usize) -> Ptr { + return Ptr::alloc_array((0..n).map(|_| 0_f64).collect::>()); + } + pub fn deallocate(this: Ptr, mut p: Ptr, mut _a1: usize) { + p.delete(); + } +} pub fn copy_0(mut copy_vector: Vec) {} pub fn fn_1(v: Ptr>, v3: Vec) { let v3: Value> = Rc::new(RefCell::new(v3)); @@ -461,28 +477,4 @@ fn main_0() -> i32 { ); return 0; } -pub trait TestAllocator_double_Impl { - fn allocate(&self, n: usize) -> Ptr; - fn deallocate(&self, p: Ptr, _a1: usize); -} -impl TestAllocator_double_Impl for Ptr { - fn allocate(&self, mut n: usize) -> Ptr { - return Ptr::alloc_array((0..n).map(|_| 0_f64).collect::>()); - } - fn deallocate(&self, mut p: Ptr, mut _a1: usize) { - p.delete(); - } -} -pub trait TestAllocator_int_Impl { - fn allocate(&self, n: usize) -> Ptr; - fn deallocate(&self, p: Ptr, _a1: usize); -} -impl TestAllocator_int_Impl for Ptr { - fn allocate(&self, mut n: usize) -> Ptr { - return Ptr::alloc_array((0..n).map(|_| 0_i32).collect::>()); - } - fn deallocate(&self, mut p: Ptr, mut _a1: usize) { - p.delete(); - } -} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/void_cast.rs b/tests/unit/out/refcount/void_cast.rs index 043974a1c8..7af3f1a185 100644 --- a/tests/unit/out/refcount/void_cast.rs +++ b/tests/unit/out/refcount/void_cast.rs @@ -28,8 +28,8 @@ pub struct NonTrivial { pub data: Vec, } impl DefaultConstructible for NonTrivial { - fn default_constructor(this: &Ptr) { - field!((*this), data).write(Vec::new()); + fn default_constructor(this: Ptr) { + field!(this, data).write(Vec::new()); } } pub fn unused_ref_param_1(x: Ptr) {} @@ -69,8 +69,8 @@ pub struct NonCopyable { pub value: Option>, } impl DefaultConstructible for NonCopyable { - fn default_constructor(this: &Ptr) { - field!((*this), value).write(None); + fn default_constructor(this: Ptr) { + field!(this, value).write(None); } } pub fn unused_noncopyable_param_5(x: Ptr) {} From 9288bf389e51c883d8f660d379d985a6cef5559d Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 11:04:46 +0000 Subject: [PATCH 02/18] Stop implementing methods on SImpl --- cpp2rust/converter/converter.cpp | 34 ++- cpp2rust/converter/converter.h | 9 +- cpp2rust/converter/converter_lib.h | 22 +- .../converter/models/converter_refcount.cpp | 231 ++++-------------- .../converter/models/converter_refcount.h | 33 +-- cpp2rust/cpp2rust_lib.cpp | 6 - libcc2rs-macros/src/assign.rs | 2 +- libcc2rs-macros/src/constructor.rs | 20 +- libcc2rs-macros/src/cpp_from.rs | 5 +- libcc2rs-macros/src/destructor.rs | 4 +- libcc2rs-macros/src/initialization.rs | 5 +- libcc2rs/src/capture.rs | 18 +- libcc2rs/src/cmp.rs | 12 +- libcc2rs/src/constructor.rs | 92 +++---- libcc2rs/src/object.rs | 22 +- libcc2rs/src/swap.rs | 12 +- rules/algorithm/tgt_refcount.rs | 14 +- rules/map/shim.rs | 4 +- rules/unique_ptr/shim.rs | 6 +- rules/vector/shim.rs | 4 +- 20 files changed, 187 insertions(+), 368 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 83a2225e74..d876129cd9 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -1359,7 +1359,7 @@ bool Converter::ConvertCXXMethodDecl(clang::CXXMethodDecl *decl) { return VisitCXXConstructorDecl(ctor); } - if (method_target_ == MethodTarget::ValueImpl && !GetRecordTrait(decl) && + if (!GetRecordTrait(decl) && (decl->isStatic() || (!decl->isVirtual() && !decl->getParent()->isAbstract()))) { StrCat(AccessSpecifierAsString(decl->getAccess())); @@ -1374,11 +1374,8 @@ bool Converter::ConvertCXXMethodDecl(clang::CXXMethodDecl *decl) { ConvertFunctionParameters(decl); } ConvertFunctionReturnType(decl); - if (decl->isPureVirtual() || method_target_ == MethodTarget::TraitDecl) { + if (decl->isPureVirtual()) { StrCat(token::kSemiColon); - } else if (method_target_ == MethodTarget::TraitDefault) { - PushBrace body(*this); - StrCat("unimplemented!()"); } else { PushBrace body(*this); EmitFunctionPreamble(decl); @@ -1413,7 +1410,7 @@ bool Converter::VisitCXXConstructorDecl(clang::CXXConstructorDecl *decl) { } ScopedValue push_fn(curr_function_, decl); - if (method_target_ == MethodTarget::ValueImpl && !GetRecordTrait(decl)) { + if (!GetRecordTrait(decl)) { StrCat(AccessSpecifierAsString(decl->getAccess())); } StrCat(keyword_unsafe_, keyword::kFn, GetCtorName(decl)); @@ -1422,17 +1419,9 @@ bool Converter::VisitCXXConstructorDecl(clang::CXXConstructorDecl *decl) { StrCat(GetConstructorSelf(), token::kComma); ConvertFunctionParameters(decl); } - if (method_target_ == MethodTarget::TraitDecl) { - StrCat(token::kSemiColon); - return false; - } { PushBrace brace(*this); - if (method_target_ == MethodTarget::TraitDefault) { - StrCat("unimplemented!()"); - } else { - ConvertCXXConstructorBody(decl); - } + ConvertCXXConstructorBody(decl); } return false; @@ -1660,7 +1649,7 @@ bool Converter::VisitReturnStmt(clang::ReturnStmt *stmt) { ConstructInPlace(value, construct, GetReturnSlotReceiver()); } else { HoistMaterializedTempBindings hoist_temps(*this); - StrCat("this.write"); + StrCat("__return.write"); { PushParen paren(*this); ConvertVarInit(return_type, value); @@ -4839,7 +4828,8 @@ void Converter::EmitLocalObject(clang::VarDecl *decl, // call (parentheses, casts to its type) emit nothing else. ScopedValue scope(full_expression_temporaries_, &declarations); // Any other construction gets the storage as a reference named name. - ScopedValue in_place(in_place_, {construct, name, &tail}); + ScopedValue in_place(in_place_, + {construct, GetStorageReceiver(name), &tail}); auto *init_expr = clang::isa(construct) ? const_cast(construct) : decl->getInit(); @@ -4858,6 +4848,10 @@ void Converter::EmitLocalObject(clang::VarDecl *decl, const char *Converter::GetObjectMacro() const { return "object_unsafe!"; } +std::string Converter::GetStorageReceiver(std::string_view name) const { + return std::string(name); +} + const char *Converter::GetAssignMacro() const { return "assign_unsafe!"; } std::string Converter::ConvertObjectOperand(clang::Expr *expr, bool is_arrow) { @@ -4907,14 +4901,16 @@ bool Converter::CanConstructVarInPlace(const clang::VarDecl *decl) const { const char *Converter::TakePlacementValue() const { return "__v"; } -const char *Converter::GetReturnSlotReceiver() const { return "&mut *this"; } +const char *Converter::GetReturnSlotReceiver() const { + return "&mut *__return"; +} std::string Converter::GetReturnSlotArg(std::string_view receiver) const { return std::string(receiver); } std::string Converter::GetReturnSlotParam(clang::QualType type) { - return std::format("this: {},", + return std::format("__return: {},", ToString(ctx_.getPointerType(type.getUnqualifiedType()))); } diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index d80b182d0b..4a7fc6d8e6 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -395,6 +395,8 @@ class Converter : public clang::RecursiveASTVisitor { virtual const char *GetObjectMacro() const; + virtual std::string GetStorageReceiver(std::string_view name) const; + // The macro that calls the copy or the move operator= of a class. virtual const char *GetAssignMacro() const; @@ -1207,13 +1209,6 @@ class Converter : public clang::RecursiveASTVisitor { clang::FunctionDecl *curr_function_ = nullptr; clang::Expr *return_value_ = nullptr; bool in_function_formals_ = false; - enum class MethodTarget : uint8_t { - ValueImpl, - TraitDecl, - TraitDefault, - PtrImpl, - }; - MethodTarget method_target_ = MethodTarget::ValueImpl; std::string ufcs_receiver_; bool in_const_initializer_ = false; diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index 923520f3e3..0ef8b0845a 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -119,33 +119,35 @@ struct RecordTrait { inline constexpr RecordTrait kDefaultConstructible{ "default_constructor", - {"DefaultConstructible", "fn default_constructor(this: &Ptr)", - "this"}, + {"DefaultConstructible", "fn default_constructor(this: Ptr)", + "this.clone()"}, {"DefaultConstructibleUnsafe", "unsafe fn default_constructor(&mut self)", "&mut *self"}}; inline constexpr RecordTrait kCopyConstructible{ "copy_constructor", - {"CopyConstructible", "fn copy_constructor(this: &Ptr, _: Ptr)", - "this"}, + {"CopyConstructible", "fn copy_constructor(this: Ptr, _: Ptr)", + "this.clone()"}, {"CopyConstructibleUnsafe", "unsafe fn copy_constructor(&mut self, _: *const Self)", "&mut *self"}}; inline constexpr RecordTrait kMoveConstructible{ "move_constructor", - {"MoveConstructible", "fn move_constructor(this: &Ptr, _: Ptr)", - "this"}, + {"MoveConstructible", "fn move_constructor(this: Ptr, _: Ptr)", + "this.clone()"}, {"MoveConstructibleUnsafe", "unsafe fn move_constructor(&mut self, _: *mut Self)", "&mut *self"}}; inline constexpr RecordTrait kCopyAssignable{ "copy_assign", {"CopyAssignable", - "fn copy_assign(this: &Ptr, _: Ptr) -> Ptr", "this"}, + "fn copy_assign(this: Ptr, _: Ptr) -> Ptr", + "this.clone()"}, {"CopyAssignableUnsafe", "unsafe fn copy_assign(&mut self, _: *const Self) -> *mut Self", "&mut *self"}}; inline constexpr RecordTrait kMoveAssignable{ "move_assign", {"MoveAssignable", - "fn move_assign(this: &Ptr, _: Ptr) -> Ptr", "this"}, + "fn move_assign(this: Ptr, _: Ptr) -> Ptr", + "this.clone()"}, {"MoveAssignableUnsafe", "unsafe fn move_assign(&mut self, _: *mut Self) -> *mut Self", "&mut *self"}}; @@ -155,12 +157,12 @@ inline constexpr RecordTrait kConstructFrom{ "construct_from", {"ConstructFrom"}, {"ConstructFromUnsafe"}}; inline constexpr RecordTrait kSwappable{ "swap", - {"Swappable", "fn swap(this: &Ptr, _: Ptr)", "this"}, + {"Swappable", "fn swap(this: Ptr, _: Ptr)", "this.clone()"}, {"SwappableUnsafe", "unsafe fn swap(&mut self, _: *mut Self)", "&mut *self"}}; inline constexpr RecordTrait kDestructible{ "destroy", - {"Destructible", "fn destroy(this: &Ptr)", "this"}, + {"Destructible", "fn destroy(this: Ptr)", "this.clone()"}, {"DestructibleUnsafe", "unsafe fn destroy(&mut self)", "&mut *self"}}; inline constexpr RecordTrait kTriviallyDefaultConstructible{ nullptr, diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 3f1c01d821..8a6d96c9d8 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -20,16 +20,6 @@ #include "converter/rules/registry.h" namespace cpp2rust { -std::map - ConverterRefCount::methods_on_ptr_; - -void ConverterRefCount::EmitMethodsOnPtr(std::string &out) { - for (const auto &[name, methods] : methods_on_ptr_) { - EmitDeferredBlock(methods.trait, out); - EmitDeferredBlock(methods.impl, out); - } -} - ConverterRefCount::ConverterRefCount(std::string &rs_code, clang::ASTContext &ctx) : ConverterRefCount(rs_code, ctx, std::make_shared(ctx)) {} @@ -161,8 +151,7 @@ bool ConverterRefCount::NeedsMut(const clang::VarDecl *decl, // without a body, which can't be mutable. auto *param = clang::cast(decl); auto *function = clang::cast(param->getDeclContext()); - return !function->isPureVirtual() && - method_target_ != MethodTarget::TraitDecl; + return !function->isPureVirtual(); } bool ConverterRefCount::IsUnboxedVar(const clang::ValueDecl *decl) const { @@ -663,16 +652,16 @@ ConverterRefCount::GetComparisonArg(const clang::ParmVarDecl *param, std::string ConverterRefCount::GetComparisonResultReceiver( const clang::CXXMethodDecl *, bool returns_ref, std::string_view result) { if (returns_ref) { - return std::format("&{}", result); + return std::format("{}.clone()", result); } PushConversionKind push(*this, ConversionKind::FullRefCount); - return std::format("&{}.as_pointer()", BoxValue(std::string(result))); + return std::format("{}.as_pointer()", BoxValue(std::string(result))); } std::string ConverterRefCount::GetComparisonReceiver(const clang::CXXMethodDecl *, std::string_view lhs) { - return std::string(lhs); + return std::format("{}.clone()", lhs); } // Records implement the comparisons of the standard library (CppLess and @@ -685,8 +674,8 @@ void ConverterRefCount::ConvertOrdAndPartialOrdTraits( auto record_name = GetRecordName(decl); auto emit = [&](std::string_view trait, std::string_view fn, std::string_view body) { - StrCat(std::format("impl {} for {} {{ fn {}(__lhs: &Ptr, " - "__rhs: &Ptr) -> bool {{ {} }} }}", + StrCat(std::format("impl {} for {} {{ fn {}(__lhs: Ptr, " + "__rhs: Ptr) -> bool {{ {} }} }}", trait, record_name, fn, body)); }; if (lt) { @@ -811,7 +800,10 @@ void ConverterRefCount::EmitByteSizeAttr(const clang::RecordDecl *decl) { std::string ConverterRefCount::GetSelfMaybeWithMut(const clang::CXXMethodDecl *decl) { if (GetRecordTrait(decl)) { - return "this: &Ptr"; + return "this: Ptr"; + } + if (IsMethodOnPtr(decl)) { + return "this: Ptr"; } return NeedsMutAccess(decl, decl->getThisType()->getPointeeType()) ? "&mut self" @@ -948,14 +940,14 @@ void ConverterRefCount::EmitScopedDestructor(const clang::VarDecl *decl) { } StrCat(token::kSemiColon, std::format("let _dtor_{0} = std::mem::DropGuard::new({0}.clone(), " - "|__p| Destructible::destroy(&__p.as_pointer()))", + "|__p| Destructible::destroy(__p.as_pointer()))", GetNamedDeclAsString(decl))); } std::string ConverterRefCount::StaticDestructorCall(const clang::VarDecl *decl) { return std::format( - "Destructible::destroy(&{}.with(Value::clone).as_pointer())", + "Destructible::destroy({}.with(Value::clone).as_pointer())", GetNamedDeclAsString(decl)); } @@ -2043,7 +2035,7 @@ bool ConverterRefCount::VisitCXXNewExpr(clang::CXXNewExpr *expr) { StrCat( std::format("let __p = Ptr::alloc(<{}>::zero_init());", GetRecordName(construct->getType()->getAsCXXRecordDecl()))); - ConstructInPlace(expr->getInitializer(), construct, "&__p"); + ConstructInPlace(expr->getInitializer(), construct, "__p.clone()"); StrCat("__p"); } else { StrCat("Ptr::alloc("); @@ -2073,9 +2065,9 @@ bool ConverterRefCount::VisitCXXDeleteExpr(clang::CXXDeleteExpr *expr) { token::kSemiColon); if (expr->isArrayForm()) { StrCat("for __i in (0..__p.len()).rev() { " - "Destructible::destroy(&__p.offset(__i as isize)); }"); + "Destructible::destroy(__p.offset(__i as isize)); }"); } else { - StrCat("Destructible::destroy(&__p);"); + StrCat("Destructible::destroy(__p.clone());"); } StrCat("__p.delete();"); return false; @@ -3566,14 +3558,13 @@ bool ConverterRefCount::ShouldConvertMethod(const clang::CXXMethodDecl *decl) { return Converter::ShouldConvertMethod(decl); } -// TODO: every trait on a Ptr should receive `this`. bool ConverterRefCount::ReceivesThis() const { auto *method = clang::dyn_cast_or_null(curr_function_); return method && GetRecordTrait(method); } const char *ConverterRefCount::SelfName() const { - return ReceivesThis() ? "this" : keyword::kSelfValue; + return ReceivesThis() || ThisIsRustPtr() ? "this" : keyword::kSelfValue; } bool ConverterRefCount::ThisIsRustPtr() const { @@ -3593,166 +3584,36 @@ void ConverterRefCount::SetUFCSReceiver(clang::Expr *base, bool is_arrow, if (clang::isa(base->IgnoreParenImpCasts()) && !AsLambdaOperatorCall(curr_function_)) { if (ThisIsRustPtr()) { - ufcs_receiver_ = SelfName(); + ufcs_receiver_ = std::format("{}.clone()", SelfName()); } else { - ufcs_receiver_ = token::kRef + ConvertPointer(base); + ufcs_receiver_ = ConvertFreshPointer(base); } return; } if (IsTemporaryObject(ctx_, base) && base->getType()->isRecordType() && !IsReferenceType(base->IgnoreImplicit())) { if (KeepsTemporaryOwner(base)) { - ufcs_receiver_ = token::kRef + ConvertTemporaryPointer(base, {}); + ufcs_receiver_ = ConvertTemporaryPointer(base, {}); return; } PushConversionKind push(*this, ConversionKind::FullRefCount); - ufcs_receiver_ = - token::kRef + BoxValue(ConvertRValue(base)) + ".as_pointer()"; - return; - } - ufcs_receiver_ = token::kRef + (base_is_pointer ? ConvertRValue(base) - : ConvertPointer(base)); -} - -std::string -ConverterRefCount::GetUFCSName(const clang::CXXMethodDecl *method) const { - if (auto *trait = GetRecordTrait(method)) { - return GetCopyOrMoveTraitName(*trait); - } - if (!IsMethodOnPtr(method)) { - return GetRecordName(method->getParent()); - } - if (method->isExplicitObjectMemberFunction()) { - return std::format(" as {}>", GetRecordName(method->getParent()), - TraitName(method->getParent())); - } - return TraitName(method->getParent()); -} - -std::string -ConverterRefCount::TraitName(const clang::CXXRecordDecl *decl) const { - return GetRecordName(decl) + "Impl"; -} - -ConverterRefCount::MethodsOnPtr & -ConverterRefCount::MethodsOnPtrFor(const clang::CXXRecordDecl *decl) { - auto name = GetRecordName(decl); - auto [it, inserted] = methods_on_ptr_.try_emplace(name); - if (inserted) { - it->second.trait.header = std::format("pub trait {}", TraitName(decl)); - it->second.impl.header = - std::format("impl {} for Ptr<{}>", TraitName(decl), name); - } - return it->second; -} - -bool ConverterRefCount::ConvertOutOfLineMethod(clang::CXXMethodDecl *decl) { - if (!IsMethodOnPtr(decl)) { - return Converter::ConvertOutOfLineMethod(decl); - } - Buffer buf(*this); - { - ScopedValue push(method_target_, MethodTarget::PtrImpl); - ConvertCXXMethodDecl(decl); - } - MethodsOnPtrFor(decl->getParent()).impl.body += std::move(buf).str(); - return false; -} - -void ConverterRefCount::ConvertMethodOnPtrTraitDecl( - clang::CXXMethodDecl *method) { - if (GetRecordTrait(method)) { - return; - } - Buffer buf(*this); - { - ScopedValue push_fn(curr_function_, method); - ScopedValue push(method_target_, method->getDefinition() - ? MethodTarget::TraitDecl - : MethodTarget::TraitDefault); - ConvertCXXMethodDecl(method); - } - MethodsOnPtrFor(method->getParent()).trait.body += std::move(buf).str(); -} - -void ConverterRefCount::ConvertMethodOnPtr(clang::CXXMethodDecl *method) { - if ((!method->isThisDeclarationADefinition() && - !clang::isa(method)) || - GetRecordTrait(method)) { + ufcs_receiver_ = BoxValue(ConvertRValue(base)) + ".as_pointer()"; return; } - Buffer buf(*this); - { - ScopedValue push(method_target_, MethodTarget::PtrImpl); - VisitCXXMethodDecl(method); - } - MethodsOnPtrFor(method->getParent()).impl.body += std::move(buf).str(); -} - -void ConverterRefCount::ConvertTemplateInstantiatedCtors( - clang::CXXRecordDecl *decl) { - for (auto c : GetTemplateInstantiatedCtors(decl)) { - if (!decl_ids_.contains(GetID(c))) { - ConvertMethodOnPtrTraitDecl(c); - ConvertMethodOnPtr(c); - } + bool outer_borrows = std::exchange(borrows_, false); + ufcs_receiver_ = + base_is_pointer ? ConvertFreshRValue(base) : ConvertFreshPointer(base); + if (borrows_) { + ufcs_receiver_ = std::format("{{ {} }}", ufcs_receiver_); } -} - -void ConverterRefCount::ConvertLateInstantiatedMethods( - clang::CXXRecordDecl *decl) { - Converter::ConvertCXXMethodDecls( - decl, std::format("{} {}", keyword::kImpl, GetRecordName(decl)), - [](auto *method) { - return IsEmittableMethod(method) && method->hasBody() && - !IsMethodOnPtr(method) && - !clang::isa(method) && - !decl_ids_.contains(GetMethodID(method)); - }); - ForEachMethod(decl, [&](clang::CXXMethodDecl *method) { - if (IsEmittableMethod(method) && method->hasBody() && - (IsMethodOnPtr(method) || - clang::isa(method)) && - !decl_ids_.contains(GetMethodID(method))) { - ConvertMethodOnPtr(method); - } - }); - ConvertCopyOrMoveTraitImpls(decl, [](clang::CXXMethodDecl *method) { - return IsEmittableMethod(method) && method->hasBody() && - !decl_ids_.contains(GetMethodID(method)); - }); -} - -void ConverterRefCount::ConvertCXXRecordMethods(clang::CXXRecordDecl *decl) { - auto struct_name = GetRecordName(decl); - - ConvertCXXMethodDecls(decl, std::format("{} {}", keyword::kImpl, struct_name), - [](auto *method) { - return IsEmittableMethod(method) && - !IsMethodOnPtr(method) && - !clang::isa(method); - }); - - ForEachMethod(decl, [&](clang::CXXMethodDecl *method) { - if (auto *ctor = clang::dyn_cast(method); - ctor && IsEmittableMethod(ctor) && IsConvertedConstructor(ctor) && - !ctor->isDependentContext()) { - ConvertMethodOnPtrTraitDecl(ctor); - ConvertMethodOnPtr(ctor); - } - if (IsMethodOnPtr(method) && !method->getReturnType()->isUndeducedType()) { - ConvertMethodOnPtrTraitDecl(method); - ConvertMethodOnPtr(method); - } - }); - ConvertCopyOrMoveTraitImpls(decl, IsEmittableMethod); + borrows_ = outer_borrows; } std::string ConverterRefCount::DestroyMembers(const clang::CXXRecordDecl *decl) { std::string out; for (auto *field : FieldsToDestroy(decl)) { - out += std::format("Destructible::destroy(&field_ptr!(this, {}));\n", + out += std::format("Destructible::destroy(field_ptr!(this, {}));\n", GetNamedDeclAsString(field)); } return out; @@ -3760,6 +3621,10 @@ ConverterRefCount::DestroyMembers(const clang::CXXRecordDecl *decl) { const char *ConverterRefCount::GetObjectMacro() const { return "object!"; } +std::string ConverterRefCount::GetStorageReceiver(std::string_view name) const { + return std::format("{}.clone()", name); +} + const char *ConverterRefCount::GetAssignMacro() const { return "assign!"; } std::string ConverterRefCount::ConvertObjectOperand(clang::Expr *expr, @@ -3775,31 +3640,23 @@ std::string ConverterRefCount::ConvertObjectOperand(clang::Expr *expr, std::string ConverterRefCount::GetAssignmentTraitSignature(const RecordTrait &trait) const { - return std::format("fn {}(this: &Ptr, src: Ptr) -> Ptr", + return std::format("fn {}(this: Ptr, src: Ptr) -> Ptr", trait.method); } const char *ConverterRefCount::GetConstructorSelf() const { - return ReceivesThis() ? "this: &Ptr" : "&self"; + return "this: Ptr"; } std::string ConverterRefCount::ConvertConstructorFieldWrite(const std::string &field_name, const std::string &value) { - return std::format("field!((*{}), {}).write({});", SelfName(), field_name, + return std::format("field!({}, {}).write({});", SelfName(), field_name, value); } const char *ConverterRefCount::GetConstructorWrite() const { - return ReceivesThis() ? "this.write" : "self.write"; -} - -std::string ConverterRefCount::GetConstructorPath( - const clang::CXXConstructorDecl *ctor) const { - if (auto *trait = GetRecordTrait(ctor)) { - return GetCopyOrMoveTraitName(*trait); - } - return TraitName(ctor->getParent()); + return "this.write"; } std::string @@ -3812,16 +3669,16 @@ ConverterRefCount::CreatePlacementStorage(const std::string &record_name, std::string ConverterRefCount::GetPlacementReceiver(std::string_view name) const { - return std::format("&{}.as_pointer()", name); + return std::format("{}.as_pointer()", name); } std::string ConverterRefCount::GetFieldPlacementReceiver(std::string_view field) const { - return std::format("&field_ptr!({}, {})", SelfName(), field); + return std::format("field_ptr!({}, {})", SelfName(), field); } const char *ConverterRefCount::GetDelegatingReceiver() const { - return SelfName(); + return "this.clone()"; } // An unboxed variable has no storage to construct in. @@ -3834,11 +3691,13 @@ const char *ConverterRefCount::TakePlacementValue() const { return "Rc::try_unwrap(__v).ok().unwrap().into_inner()"; } -const char *ConverterRefCount::GetReturnSlotReceiver() const { return "&this"; } +const char *ConverterRefCount::GetReturnSlotReceiver() const { + return "__return.clone()"; +} std::string ConverterRefCount::GetReturnSlotArg(std::string_view receiver) const { - return std::format("Ptr::clone({})", receiver); + return std::format("Ptr::clone(&{})", receiver); } bool ConverterRefCount::VisitCXXThisExpr( @@ -3854,7 +3713,11 @@ bool ConverterRefCount::VisitCXXThisExpr( } return false; } - StrCat("(*", SelfName(), ')'); + if (ReceivesThis() || ThisIsRustPtr()) { + StrCat(SelfName()); + } else { + StrCat("(*", SelfName(), ')'); + } MarkNotFresh(); return false; } diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index 1d9fb0d900..d824157de8 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -21,8 +21,6 @@ class ConverterRefCount final : public Converter { std::string GetUnboxedDefaultAsString(clang::QualType qual_type) override; - static void EmitMethodsOnPtr(std::string &out); - bool VisitRecordType(clang::RecordType *type) override; bool VisitConstantArrayType(clang::ConstantArrayType *type) override; @@ -79,12 +77,12 @@ class ConverterRefCount final : public Converter { bool ShouldConvertMethod(const clang::CXXMethodDecl *decl) override; - bool ConvertOutOfLineMethod(clang::CXXMethodDecl *decl) override; - const char *GetConstructorSelf() const override; const char *GetObjectMacro() const override; + std::string GetStorageReceiver(std::string_view name) const override; + const char *GetAssignMacro() const override; std::string ConvertObjectOperand(clang::Expr *expr, bool is_arrow) override; @@ -97,9 +95,6 @@ class ConverterRefCount final : public Converter { std::string ConvertConstructorFieldWrite(const std::string &field_name, const std::string &value) override; - std::string - GetConstructorPath(const clang::CXXConstructorDecl *ctor) const override; - std::string CreatePlacementStorage(const std::string &record_name, std::string_view name = "__v") const override; @@ -119,15 +114,6 @@ class ConverterRefCount final : public Converter { std::string GetReturnSlotArg(std::string_view receiver) const override; - void ConvertCXXRecordMethods(clang::CXXRecordDecl *decl) override; - - void ConvertLateInstantiatedMethods(clang::CXXRecordDecl *decl) override; - - void ConvertTemplateInstantiatedCtors(clang::CXXRecordDecl *decl) override; - - void ConvertMethodOnPtrTraitDecl(clang::CXXMethodDecl *method); - void ConvertMethodOnPtr(clang::CXXMethodDecl *method); - bool VisitCXXThisExpr(clang::CXXThisExpr *expr) override; bool ThisIsRustPtr() const override; @@ -435,21 +421,6 @@ class ConverterRefCount final : public Converter { void SetUFCSReceiver(clang::Expr *base, bool is_arrow, const clang::CXXMethodDecl *method) override; - std::string GetUFCSName(const clang::CXXMethodDecl *method) const override; - - std::string TraitName(const clang::CXXRecordDecl *decl) const; - - struct MethodsOnPtr { - DeferredBlock trait; - DeferredBlock impl; - }; - - // record name -> trait and impl for Ptr, emitted after all - // translation units. - static std::map methods_on_ptr_; - - MethodsOnPtr &MethodsOnPtrFor(const clang::CXXRecordDecl *decl); - bool ReceivesThis() const; const char *SelfName() const; diff --git a/cpp2rust/cpp2rust_lib.cpp b/cpp2rust/cpp2rust_lib.cpp index 4196e5af85..605e46ba59 100644 --- a/cpp2rust/cpp2rust_lib.cpp +++ b/cpp2rust/cpp2rust_lib.cpp @@ -34,9 +34,6 @@ std::string TranspileSrc(std::string_view cc_code, Model model, Converter::EmitOpaqueRecords(model, rs_code); Converter::EmitVirtualMethods(rs_code); Converter::EmitUndefinedRecordTraits(model, rs_code); - if (model == Model::kRefCount) { - ConverterRefCount::EmitMethodsOnPtr(rs_code); - } Converter::EmitGlobalInits(model, rs_code); return rs_code; } @@ -80,9 +77,6 @@ std::string TranspileDir(std::string_view build_dir, Model model, Converter::EmitOpaqueRecords(model, rs_code); Converter::EmitVirtualMethods(rs_code); Converter::EmitUndefinedRecordTraits(model, rs_code); - if (model == Model::kRefCount) { - ConverterRefCount::EmitMethodsOnPtr(rs_code); - } Converter::EmitGlobalInits(model, rs_code); return rs_code; } diff --git a/libcc2rs-macros/src/assign.rs b/libcc2rs-macros/src/assign.rs index 8b5387f5e2..6cb0988342 100644 --- a/libcc2rs-macros/src/assign.rs +++ b/libcc2rs-macros/src/assign.rs @@ -56,7 +56,7 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { quote! { { let #src_name = #src; - ::libcc2rs::AssignFrom::assign_from(&#dst, #src_name) + ::libcc2rs::AssignFrom::assign_from(#dst, #src_name) } } }; diff --git a/libcc2rs-macros/src/constructor.rs b/libcc2rs-macros/src/constructor.rs index 31a3815023..c3e4857478 100644 --- a/libcc2rs-macros/src/constructor.rs +++ b/libcc2rs-macros/src/constructor.rs @@ -68,7 +68,7 @@ pub fn expand_default_constructible(input: TokenStream, is_unsafe: bool) -> Toke } else { quote! { impl #impl_generics ::libcc2rs::DefaultConstructible for #name #ty_generics #where_clause { - fn default_constructor(this: &::libcc2rs::Ptr) { + fn default_constructor(this: ::libcc2rs::Ptr) { this.write(::zero_init()); } } @@ -96,7 +96,7 @@ fn impl_swap(input: &DeriveInput, is_unsafe: bool) -> TokenStream2 { } else { quote! { impl #impl_generics ::libcc2rs::Swappable for #name #ty_generics #where_clause { - fn swap(this: &::libcc2rs::Ptr, other: ::libcc2rs::Ptr) { + fn swap(this: ::libcc2rs::Ptr, other: ::libcc2rs::Ptr) { ::libcc2rs::swap_by_move(this, other) } } @@ -175,17 +175,17 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - quote!(::libcc2rs::#copy_trait::#copy_method(this, src)) } else if is_assign { quote! { - this.write(src.with(Self::clone)); + this.write(src.with(::clone)); this.clone() } } else { - quote!(this.write(src.with(Self::clone));) + quote!(this.write(src.with(::clone));) }; // The copy of a type with Clone is a clone, and its move is its copy. let copied = match (is_move, is_assign) { (false, false) => Some(quote! { fn copied(src: ::libcc2rs::Ptr) -> Self { - src.with(Self::clone) + src.with(::clone) } fn copied_elems(src: &::libcc2rs::Ptr>) -> Vec { @@ -193,7 +193,7 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - } fn push_copied(v: &::libcc2rs::Ptr>, src: ::libcc2rs::Ptr) { - let value = src.with(Self::clone); + let value = src.with(::clone); v.with_mut(|elems| elems.push(value)); } }), @@ -209,7 +209,7 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - }; quote! { impl #impl_generics ::libcc2rs::#trait_name for #name #ty_generics #where_clause { - fn #method(this: &::libcc2rs::Ptr, src: ::libcc2rs::Ptr) #ret { + fn #method(this: ::libcc2rs::Ptr, src: ::libcc2rs::Ptr) #ret { #body } #copied @@ -275,7 +275,7 @@ pub fn expand_trivially_copyable(input: TokenStream, is_unsafe: bool) -> TokenSt } else { quote! { impl #impl_generics ::libcc2rs::Destructible for #name #ty_generics #where_clause { - fn destroy(_: &::libcc2rs::Ptr) {} + fn destroy(_: ::libcc2rs::Ptr) {} } } }; @@ -382,9 +382,9 @@ fn impl_memberwise( }; quote! { impl #impl_generics #tr for #name #ty_generics #where_clause { - fn #method(this: &::libcc2rs::Ptr, src: ::libcc2rs::Ptr) #ret { + fn #method(this: ::libcc2rs::Ptr, src: ::libcc2rs::Ptr) #ret { #(#tr::#method( - &::libcc2rs::field_ptr!(this, #members), + ::libcc2rs::field_ptr!(this, #members), ::libcc2rs::field_ptr!(src, #members), );)* #tail diff --git a/libcc2rs-macros/src/cpp_from.rs b/libcc2rs-macros/src/cpp_from.rs index 0ad9cc8b70..0119a6ff9f 100644 --- a/libcc2rs-macros/src/cpp_from.rs +++ b/libcc2rs-macros/src/cpp_from.rs @@ -3,7 +3,7 @@ use proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; -use quote::{format_ident, quote}; +use quote::quote; use syn::parse::{Parse, ParseStream}; use syn::{DeriveInput, Ident, Token, Type, parse_macro_input}; @@ -172,7 +172,6 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { } }); - let impl_trait = format_ident!("{}Impl", name); let into_impls = intos.iter().map(|conversion| { let ty = &conversion.ty; let op = &conversion.method; @@ -183,7 +182,7 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { } else if is_unsafe { quote!((*src).#op()) } else { - quote!(#impl_trait::#op(&src)) + quote!(#name::#op(src)) }; let from_fn = method(is_unsafe, quote!(fn cpp_from(src: #src) -> Self), body); quote! { diff --git a/libcc2rs-macros/src/destructor.rs b/libcc2rs-macros/src/destructor.rs index 2ff90cf8c7..7461f8fd5e 100644 --- a/libcc2rs-macros/src/destructor.rs +++ b/libcc2rs-macros/src/destructor.rs @@ -43,8 +43,8 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { }; quote! { impl #impl_generics ::libcc2rs::Destructible for #name #ty_generics #where_clause { - fn destroy(#this: &::libcc2rs::Ptr) { - #(::libcc2rs::Destructible::destroy(&::libcc2rs::field_ptr!(this, #destroyed));)* + fn destroy(#this: ::libcc2rs::Ptr) { + #(::libcc2rs::Destructible::destroy(::libcc2rs::field_ptr!(this, #destroyed));)* } } } diff --git a/libcc2rs-macros/src/initialization.rs b/libcc2rs-macros/src/initialization.rs index c03fc25495..6f26112d12 100644 --- a/libcc2rs-macros/src/initialization.rs +++ b/libcc2rs-macros/src/initialization.rs @@ -3,7 +3,7 @@ use proc_macro::TokenStream; use proc_macro2::TokenStream as TokenStream2; -use quote::{format_ident, quote}; +use quote::quote; use syn::punctuated::Punctuated; use syn::{Data, DeriveInput, Expr, Field, Fields, Ident, Index, Token, parse_macro_input}; @@ -82,12 +82,11 @@ pub(crate) fn construct( __v }} } else { - let impl_trait = format_ident!("{}Impl", name); quote! {{ let __v: ::libcc2rs::Value = ::std::rc::Rc::new(::std::cell::RefCell::new( ::zero_init(), )); - #impl_trait::#method(&::libcc2rs::AsPointer::as_pointer(&__v), #args); + #name::#method(::libcc2rs::AsPointer::as_pointer(&__v), #args); ::std::rc::Rc::try_unwrap(__v).ok().unwrap().into_inner() }} } diff --git a/libcc2rs/src/capture.rs b/libcc2rs/src/capture.rs index 5e7445edf5..369e9db11e 100644 --- a/libcc2rs/src/capture.rs +++ b/libcc2rs/src/capture.rs @@ -32,7 +32,7 @@ use crate::reinterpret::ByteRepr; // The C++ destructor of a type, in the refcount model. pub trait Destructible: Sized { - fn destroy(this: &Ptr); + fn destroy(this: Ptr); } // The C++ destructor of a type, in the unsafe model. @@ -47,7 +47,7 @@ pub trait TriviallyDestructible: Destructible {} pub trait TriviallyDestructibleUnsafe: DestructibleUnsafe {} impl Destructible for FnPtr { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { this.with(|f| f.destroy()) } } @@ -63,10 +63,10 @@ impl DestructibleUnsafe for FnPtr { impl TriviallyDestructibleUnsafe for FnPtr {} impl Destructible for Box<[T]> { - fn destroy(this: &Ptr) { + fn destroy(this: Ptr) { let elems = this.decay(); for i in (0..elems.len()).rev() { - T::destroy(&elems.offset(i)); + T::destroy(elems.offset(i)); } } } @@ -94,7 +94,7 @@ impl CopyLambda>> for &&&Capture<'_, Value>> { fn copy_capture(&self) -> Value> { let dst: Value> = Rc::new(RefCell::new(FnPtr::zero_init())); CopyConstructible::copy_constructor( - &AsPointer::>::as_pointer(&dst), + AsPointer::>::as_pointer(&dst), AsPointer::>::as_pointer(self.0), ); dst @@ -126,7 +126,7 @@ impl CopyCtor> for &Capture< fn copy_capture(&self) -> Value { let dst: Value = Rc::new(RefCell::new(T::zero_init())); T::copy_constructor( - &AsPointer::::as_pointer(&dst), + AsPointer::::as_pointer(&dst), AsPointer::::as_pointer(self.0), ); dst @@ -151,7 +151,7 @@ impl MoveWithCtor> for &&Cap fn move_capture(&self) -> Value { let dst: Value = Rc::new(RefCell::new(T::zero_init())); T::move_constructor( - &AsPointer::::as_pointer(&dst), + AsPointer::::as_pointer(&dst), AsPointer::::as_pointer(self.0), ); dst @@ -192,7 +192,7 @@ impl DestroyElems for &&Capture<'_, Value>> { fn destroy_capture(&self) { let p: Ptr = self.0.decay(); for i in (0..self.0.borrow().len()).rev() { - T::destroy(&p.offset(i)); + T::destroy(p.offset(i)); } } } @@ -203,7 +203,7 @@ pub trait DestroyWithDtor { impl DestroyWithDtor for &Capture<'_, Value> { fn destroy_capture(&self) { - T::destroy(&AsPointer::::as_pointer(self.0)) + T::destroy(AsPointer::::as_pointer(self.0)) } } diff --git a/libcc2rs/src/cmp.rs b/libcc2rs/src/cmp.rs index 427fdf1a0c..1b747a5be4 100644 --- a/libcc2rs/src/cmp.rs +++ b/libcc2rs/src/cmp.rs @@ -11,31 +11,31 @@ use crate::reinterpret::ByteRepr; // operator<. Records implement it with their comparison operators. pub trait CppLess: Sized { - fn less(lhs: &Ptr, rhs: &Ptr) -> bool; + fn less(lhs: Ptr, rhs: Ptr) -> bool; } // operator==. Records implement it with their comparison operators. pub trait CppEq: Sized { - fn equal(lhs: &Ptr, rhs: &Ptr) -> bool; + fn equal(lhs: Ptr, rhs: Ptr) -> bool; } impl CppLess for T { - fn less(lhs: &Ptr, rhs: &Ptr) -> bool { + fn less(lhs: Ptr, rhs: Ptr) -> bool { lhs.with(|a| rhs.with(|b| a < b)) } } impl + ByteRepr, U: ByteRepr> CppEq for T { - fn equal(lhs: &Ptr, rhs: &Ptr) -> bool { + fn equal(lhs: Ptr, rhs: Ptr) -> bool { lhs.with(|a| rhs.with(|b| a == b)) } } // The order of two values that std::sort and std::map derive from operator<. pub fn cpp_cmp(lhs: &Ptr, rhs: &Ptr) -> Ordering { - if T::less(lhs, rhs) { + if T::less(lhs.clone(), rhs.clone()) { Ordering::Less - } else if T::less(rhs, lhs) { + } else if T::less(rhs.clone(), lhs.clone()) { Ordering::Greater } else { Ordering::Equal diff --git a/libcc2rs/src/constructor.rs b/libcc2rs/src/constructor.rs index 7913dc19b3..f3c1086467 100644 --- a/libcc2rs/src/constructor.rs +++ b/libcc2rs/src/constructor.rs @@ -11,7 +11,7 @@ use crate::reinterpret::ByteRepr; use crate::void::AnyPtr; pub trait DefaultConstructible: Sized { - fn default_constructor(this: &Ptr); + fn default_constructor(this: Ptr); // TODO: remove default_constructed. fn default_constructed() -> Self @@ -19,13 +19,13 @@ pub trait DefaultConstructible: Sized { Self: ZeroInitialization, { let dst: Value = std::rc::Rc::new(std::cell::RefCell::new(Self::zero_init())); - Self::default_constructor(&AsPointer::::as_pointer(&dst)); + Self::default_constructor(AsPointer::::as_pointer(&dst)); std::rc::Rc::try_unwrap(dst).ok().unwrap().into_inner() } } pub trait MoveConstructible: Sized { - fn move_constructor(this: &Ptr, src: Ptr); + fn move_constructor(this: Ptr, src: Ptr); // Pushes to the vector that v points to an element that the move // constructor constructs in place from src. A type that moves by Clone, or @@ -38,7 +38,7 @@ pub trait MoveConstructible: Sized { elems.push(Self::zero_init()); elems.len() - 1 }); - Self::move_constructor(&v.decay().offset(i), src); + Self::move_constructor(v.decay().offset(i), src); } } @@ -47,7 +47,7 @@ pub trait TriviallyMoveConstructible: MoveConstructible { } pub trait CopyConstructible: MoveConstructible { - fn copy_constructor(this: &Ptr, src: Ptr); + fn copy_constructor(this: Ptr, src: Ptr); // A copy of the value that src points to, made by the copy constructor, // which a type with Clone clones. @@ -69,7 +69,7 @@ pub trait CopyConstructible: MoveConstructible { elems.push(Self::zero_init()); elems.len() - 1 }); - Self::copy_constructor(&v.decay().offset(i), src); + Self::copy_constructor(v.decay().offset(i), src); } // A copy of the elements of the vector that src points to, made by the @@ -89,19 +89,19 @@ pub trait TriviallyCopyConstructible: CopyConstructible { } pub trait CopyAssignable: MoveAssignable { - fn copy_assign(this: &Ptr, src: Ptr) -> Ptr; + fn copy_assign(this: Ptr, src: Ptr) -> Ptr; } pub trait TriviallyCopyAssignable: CopyAssignable {} pub trait MoveAssignable: Sized { - fn move_assign(this: &Ptr, src: Ptr) -> Ptr; + fn move_assign(this: Ptr, src: Ptr) -> Ptr; } pub trait TriviallyMoveAssignable: MoveAssignable {} pub trait Swappable: Sized { - fn swap(this: &Ptr, other: Ptr); + fn swap(this: Ptr, other: Ptr); } pub trait TriviallyDefaultConstructible: DefaultConstructible {} @@ -246,7 +246,7 @@ macro_rules! impl_copy_by_clone { where $ty: Clone + $crate::ByteRepr, { - fn copy_constructor(this: &$crate::Ptr, src: $crate::Ptr) { + fn copy_constructor(this: $crate::Ptr, src: $crate::Ptr) { this.write(src.with(Self::clone)); } @@ -268,7 +268,7 @@ macro_rules! impl_copy_by_clone { where $ty: Clone + $crate::ByteRepr, { - fn copy_assign(this: &$crate::Ptr, src: $crate::Ptr) -> $crate::Ptr { + fn copy_assign(this: $crate::Ptr, src: $crate::Ptr) -> $crate::Ptr { this.write(src.with(Self::clone)); this.clone() } @@ -302,7 +302,7 @@ macro_rules! impl_move_by_clone { where $ty: Clone + $crate::ByteRepr, { - fn move_constructor(this: &$crate::Ptr, src: $crate::Ptr) { + fn move_constructor(this: $crate::Ptr, src: $crate::Ptr) { this.write(src.with(Self::clone)); } @@ -316,7 +316,7 @@ macro_rules! impl_move_by_clone { where $ty: Clone + $crate::ByteRepr, { - fn move_assign(this: &$crate::Ptr, src: $crate::Ptr) -> $crate::Ptr { + fn move_assign(this: $crate::Ptr, src: $crate::Ptr) -> $crate::Ptr { this.write(src.with(Self::clone)); this.clone() } @@ -345,7 +345,7 @@ macro_rules! impl_move_by_clone { where $ty: Clone + $crate::ByteRepr, { - fn swap(this: &$crate::Ptr, other: $crate::Ptr) { + fn swap(this: $crate::Ptr, other: $crate::Ptr) { this.swap_with(&other, |p| p.with(Self::clone)); } } @@ -422,7 +422,7 @@ macro_rules! impl_trivially_copyable_by_clone { } impl<$($param),*> $crate::Destructible for $ty { - fn destroy(_this: &$crate::Ptr) {} + fn destroy(_this: $crate::Ptr) {} } impl<$($param),*> $crate::DestructibleUnsafe for $ty { @@ -455,7 +455,7 @@ macro_rules! impl_move_by_take { where $ty: Default + $crate::ByteRepr, { - fn move_constructor(this: &$crate::Ptr, src: $crate::Ptr) { + fn move_constructor(this: $crate::Ptr, src: $crate::Ptr) { let value = src.with_mut(std::mem::take); this.with_mut(|dst| *dst = value); } @@ -470,7 +470,7 @@ macro_rules! impl_move_by_take { where $ty: Default + $crate::ByteRepr, { - fn move_assign(this: &$crate::Ptr, src: $crate::Ptr) -> $crate::Ptr { + fn move_assign(this: $crate::Ptr, src: $crate::Ptr) -> $crate::Ptr { let value = src.with_mut(std::mem::take); this.with_mut(|dst| *dst = value); this.clone() @@ -500,7 +500,7 @@ macro_rules! impl_move_by_take { where $ty: Default + $crate::ByteRepr, { - fn swap(this: &$crate::Ptr, other: $crate::Ptr) { + fn swap(this: $crate::Ptr, other: $crate::Ptr) { this.swap_with(&other, |p| p.with_mut(std::mem::take)); } } @@ -533,7 +533,7 @@ macro_rules! impl_trivially_default_constructible { where $ty: Default + ByteRepr, { - fn default_constructor(this: &Ptr) { + fn default_constructor(this: Ptr) { this.write(Self::default()); } } @@ -590,7 +590,7 @@ impl TriviallyDefaultConstructibleUnsafe for *mut T {} impl TriviallyDefaultConstructibleUnsafe for *const T {} impl DefaultConstructible for FnPtr { - fn default_constructor(this: &Ptr) { + fn default_constructor(this: Ptr) { this.with_mut(|dst| *dst = ::zero_init()); } } @@ -602,11 +602,11 @@ impl DefaultConstructibleUnsafe for FnPtr { } impl DefaultConstructible for Box<[T]> { - fn default_constructor(this: &Ptr) { + fn default_constructor(this: Ptr) { let len = this.with(|elems| elems.len()); let dst = this.decay(); for i in 0..len { - T::default_constructor(&dst.offset(i)); + T::default_constructor(dst.offset(i)); } } } @@ -734,7 +734,7 @@ where } impl Destructible for (A, B) { - fn destroy(_this: &Ptr) {} + fn destroy(_this: Ptr) {} } impl TriviallyDestructible for (A, B) {} @@ -749,7 +749,7 @@ impl TriviallyDe } impl MoveConstructible for FnPtr { - fn move_constructor(this: &Ptr, src: Ptr) { + fn move_constructor(this: Ptr, src: Ptr) { let value = src.with(FnPtr::move_from); this.with_mut(|dst| *dst = value); } @@ -762,7 +762,7 @@ impl TriviallyMoveConstructible for FnPtr { } impl CopyConstructible for FnPtr { - fn copy_constructor(this: &Ptr, src: Ptr) { + fn copy_constructor(this: Ptr, src: Ptr) { let value = src.with(FnPtr::copy_from); this.with_mut(|dst| *dst = value); } @@ -775,25 +775,25 @@ impl TriviallyCopyConstructible for FnPtr { } impl MoveAssignable for FnPtr { - fn move_assign(this: &Ptr, src: Ptr) -> Ptr { - ::move_constructor(this, src); - this.clone() + fn move_assign(this: Ptr, src: Ptr) -> Ptr { + ::move_constructor(this.clone(), src); + this } } impl TriviallyMoveAssignable for FnPtr {} impl CopyAssignable for FnPtr { - fn copy_assign(this: &Ptr, src: Ptr) -> Ptr { - ::copy_constructor(this, src); - this.clone() + fn copy_assign(this: Ptr, src: Ptr) -> Ptr { + ::copy_constructor(this.clone(), src); + this } } impl TriviallyCopyAssignable for FnPtr {} impl Swappable for FnPtr { - fn swap(this: &Ptr, other: Ptr) { + fn swap(this: Ptr, other: Ptr) { this.swap_with(&other, |p| p.with(FnPtr::move_from)); } } @@ -849,32 +849,32 @@ impl TriviallyCopyAssignableUnsafe for FnPtr {} fn construct_elems( this: &Ptr>, src: &Ptr>, - construct: fn(&Ptr, Ptr), + construct: fn(Ptr, Ptr), ) { let len = src.with(|elems| elems.len()); this.with_mut(|elems| *elems = (0..len).map(|_| T::zero_init()).collect()); let (dst, src) = (this.decay(), src.decay()); for i in 0..len { - construct(&dst.offset(i), src.offset(i)); + construct(dst.offset(i), src.offset(i)); } } fn assign_elems( this: &Ptr>, src: &Ptr>, - assign: fn(&Ptr, Ptr) -> Ptr, + assign: fn(Ptr, Ptr) -> Ptr, ) -> Ptr> { let len = src.with(|elems| elems.len()); let (dst, src) = (this.decay(), src.decay()); for i in 0..len { - assign(&dst.offset(i), src.offset(i)); + assign(dst.offset(i), src.offset(i)); } this.clone() } impl MoveConstructible for Box<[T]> { - fn move_constructor(this: &Ptr, src: Ptr) { - construct_elems(this, &src, T::move_constructor); + fn move_constructor(this: Ptr, src: Ptr) { + construct_elems(&this, &src, T::move_constructor); } } @@ -887,8 +887,8 @@ impl TriviallyMov } impl CopyConstructible for Box<[T]> { - fn copy_constructor(this: &Ptr, src: Ptr) { - construct_elems(this, &src, T::copy_constructor); + fn copy_constructor(this: Ptr, src: Ptr) { + construct_elems(&this, &src, T::copy_constructor); } } @@ -901,27 +901,27 @@ impl TriviallyCop } impl MoveAssignable for Box<[T]> { - fn move_assign(this: &Ptr, src: Ptr) -> Ptr { - assign_elems(this, &src, T::move_assign) + fn move_assign(this: Ptr, src: Ptr) -> Ptr { + assign_elems(&this, &src, T::move_assign) } } impl TriviallyMoveAssignable for Box<[T]> {} impl CopyAssignable for Box<[T]> { - fn copy_assign(this: &Ptr, src: Ptr) -> Ptr { - assign_elems(this, &src, T::copy_assign) + fn copy_assign(this: Ptr, src: Ptr) -> Ptr { + assign_elems(&this, &src, T::copy_assign) } } impl TriviallyCopyAssignable for Box<[T]> {} impl Swappable for Box<[T]> { - fn swap(this: &Ptr, other: Ptr) { + fn swap(this: Ptr, other: Ptr) { let len = other.with(|elems| elems.len()); let (dst, src) = (this.decay(), other.decay()); for i in 0..len { - T::swap(&dst.offset(i), src.offset(i)); + T::swap(dst.offset(i), src.offset(i)); } } } diff --git a/libcc2rs/src/object.rs b/libcc2rs/src/object.rs index 37027338a2..5904f815ce 100644 --- a/libcc2rs/src/object.rs +++ b/libcc2rs/src/object.rs @@ -45,38 +45,38 @@ pub struct Moved

(pub P); // Construction of *self from src, in the refcount model: copy from a Ptr, // move from a Moved>. pub trait ConstructFrom { - fn construct_from(&self, src: S); + fn construct_from(self, src: S); } impl ConstructFrom> for Ptr { #[inline(always)] - fn construct_from(&self, src: Ptr) { + fn construct_from(self, src: Ptr) { T::copy_constructor(self, src) } } impl ConstructFrom>> for Ptr { #[inline(always)] - fn construct_from(&self, src: Moved>) { + fn construct_from(self, src: Moved>) { T::move_constructor(self, src.0) } } // The C++ operator= of *self from src, in the refcount model. pub trait AssignFrom: Sized { - fn assign_from(&self, src: S) -> Self; + fn assign_from(self, src: S) -> Self; } impl AssignFrom> for Ptr { #[inline(always)] - fn assign_from(&self, src: Ptr) -> Ptr { + fn assign_from(self, src: Ptr) -> Ptr { T::copy_assign(self, src) } } impl AssignFrom>> for Ptr { #[inline(always)] - fn assign_from(&self, src: Moved>) -> Ptr { + fn assign_from(self, src: Moved>) -> Ptr { T::move_assign(self, src.0) } } @@ -172,7 +172,7 @@ pub struct DestroyGuard<'a, T: Destructible>(&'a Value); impl Drop for DestroyGuard<'_, T> { #[inline(always)] fn drop(&mut self) { - T::destroy(&self.0.as_pointer()) + T::destroy(self.0.as_pointer()) } } @@ -241,7 +241,7 @@ impl GuardNoneUnsafe for LocalUnsafe {} macro_rules! object { ($name:ident, $ty:ident :: $ctor:ident ($($arg:expr),* $(,)?)) => { let $name: $crate::Value<$ty> = $crate::__object::storage::<$ty>(); - <$crate::Ptr<$ty>>::$ctor(&$crate::AsPointer::<$ty>::as_pointer(&$name), $($arg),*); + $ty::$ctor($crate::AsPointer::<$ty>::as_pointer(&$name), $($arg),*); $crate::object!(@guard $name); }; ($name:ident, $ty:ident ($($arg:expr),* $(,)?)) => { @@ -250,7 +250,7 @@ macro_rules! object { ($name:ident, $ty:ty, |$this:ident| $init:expr) => { let $name: $crate::Value<$ty> = $crate::__object::storage::<$ty>(); { - let $this: &$crate::Ptr<$ty> = &$crate::AsPointer::<$ty>::as_pointer(&$name); + let $this: $crate::Ptr<$ty> = $crate::AsPointer::<$ty>::as_pointer(&$name); $init; } $crate::object!(@guard $name); @@ -258,7 +258,7 @@ macro_rules! object { ($name:ident, $ty:ty, $src:expr) => { let $name: $crate::Value<$ty> = $crate::__object::storage::<$ty>(); $crate::ConstructFrom::construct_from( - &$crate::AsPointer::<$ty>::as_pointer(&$name), + $crate::AsPointer::<$ty>::as_pointer(&$name), $src, ); $crate::object!(@guard $name); @@ -266,7 +266,7 @@ macro_rules! object { ($name:ident, $ty:ty) => { let $name: $crate::Value<$ty> = $crate::__object::storage::<$ty>(); $crate::DefaultConstructible::default_constructor( - &$crate::AsPointer::<$ty>::as_pointer(&$name), + $crate::AsPointer::<$ty>::as_pointer(&$name), ); $crate::object!(@guard $name); }; diff --git a/libcc2rs/src/swap.rs b/libcc2rs/src/swap.rs index d23affb9cc..9ecb361890 100644 --- a/libcc2rs/src/swap.rs +++ b/libcc2rs/src/swap.rs @@ -50,7 +50,7 @@ pub fn pointer(value: &Value) -> Ptr { pub fn move_constructed(src: &Ptr) -> T { let dst: Value = Rc::new(RefCell::new(T::zero_init())); - T::move_constructor(&pointer(&dst), src.clone()); + T::move_constructor(pointer(&dst), src.clone()); Rc::try_unwrap(dst).ok().unwrap().into_inner() } @@ -64,7 +64,7 @@ pub(crate) fn copy_constructed_in_storage, ) -> T { let dst: Value = Rc::new(RefCell::new(T::zero_init())); - T::copy_constructor(&pointer(&dst), src); + T::copy_constructor(pointer(&dst), src); Rc::try_unwrap(dst).ok().unwrap().into_inner() } @@ -150,16 +150,16 @@ impl ConstructNoneUnsafe for &ConstructUnsafe { } } -pub fn swap_by_move(this: &Ptr, other: Ptr) +pub fn swap_by_move(this: Ptr, other: Ptr) where T: MoveConstructible + MoveAssignable + Destructible + ZeroInitialization, { let storage: Value = Rc::new(RefCell::new(T::zero_init())); let tmp = AsPointer::::as_pointer(&storage); - T::move_constructor(&tmp, this.clone()); + T::move_constructor(tmp.clone(), this.clone()); T::move_assign(this, other.clone()); - T::move_assign(&other, tmp.clone()); - T::destroy(&tmp); + T::move_assign(other.clone(), tmp.clone()); + T::destroy(tmp.clone()); } /// # Safety diff --git a/rules/algorithm/tgt_refcount.rs b/rules/algorithm/tgt_refcount.rs index e63cd19bb5..c4e8e12b6b 100644 --- a/rules/algorithm/tgt_refcount.rs +++ b/rules/algorithm/tgt_refcount.rs @@ -35,7 +35,7 @@ fn f2< fn f3, T2, T3: CppEq>(a0: T1, a1: T1, a2: Ptr) -> T1 { let mut __it = a0; - while __it != a1 && !CppEq::equal(&__it.iter_deref(), &a2) { + while __it != a1 && !CppEq::equal(__it.iter_deref(), a2.clone()) { __it.iter_inc(); } __it @@ -67,7 +67,7 @@ fn f8, T2: CppLess>(a0: T1, a1: T1) -> T1 { let mut __it = a0; __it.iter_inc(); while __it != a1 { - if CppLess::less(&__best.iter_deref(), &__it.iter_deref()) { + if CppLess::less(__best.iter_deref(), __it.iter_deref()) { __best = __it.clone(); } __it.iter_inc(); @@ -77,7 +77,7 @@ fn f8, T2: CppLess>(a0: T1, a1: T1) -> T1 { } fn f9(a0: Ptr, a1: Ptr) { - Swappable::swap(&a0, a1) + Swappable::swap(a0, a1) } fn f10, T2: CppEq + TriviallyCopyable + ByteRepr>( @@ -91,7 +91,7 @@ fn f10, T2: CppEq + TriviallyCopyable + ByteRepr>( let mut __it = a0; __it.iter_inc(); while __it != a1 { - if !CppEq::equal(&__write.iter_deref(), &__it.iter_deref()) { + if !CppEq::equal(__write.iter_deref(), __it.iter_deref()) { __write.iter_inc(); __write.iter_deref().write(__it.iter_deref().read()); } @@ -143,11 +143,11 @@ where } fn f16(a0: Ptr, a1: Ptr) -> Ptr { - if CppLess::less(&a1, &a0) { a1 } else { a0 } + if CppLess::less(a1.clone(), a0.clone()) { a1 } else { a0 } } fn f17(a0: Ptr, a1: Ptr) -> Ptr { - if CppLess::less(&a0, &a1) { a1 } else { a0 } + if CppLess::less(a0.clone(), a1.clone()) { a1 } else { a0 } } fn f18, T2: Swappable>(a0: T1, a1: T1) { @@ -155,6 +155,6 @@ fn f18, T2: Swappable>(a0: T1, a1: T1) { let __random = std::hash::RandomState::new(); for __i in (1..__n).rev() { let __j = (std::hash::BuildHasher::hash_one(&__random, __i) % (__i + 1) as u64) as isize; - Swappable::swap(&a0.iter_at(__i), a0.iter_at(__j)); + Swappable::swap(a0.iter_at(__i), a0.iter_at(__j)); } } diff --git a/rules/map/shim.rs b/rules/map/shim.rs index 94de6738cf..c0b044c02b 100644 --- a/rules/map/shim.rs +++ b/rules/map/shim.rs @@ -115,7 +115,7 @@ where K: CppLess + CopyConstructible + ZeroInitialization + 'static, V: CopyConstructible + ZeroInitialization + 'static, { - fn copy_constructor(this: &Ptr, src: Ptr) { + fn copy_constructor(this: Ptr, src: Ptr) { this.write(Self::copied(src)); } @@ -147,7 +147,7 @@ where K: CppLess + CopyConstructible + ZeroInitialization + 'static, V: CopyConstructible + ZeroInitialization + 'static, { - fn copy_assign(this: &Ptr, src: Ptr) -> Ptr { + fn copy_assign(this: Ptr, src: Ptr) -> Ptr { let map = Self::copied(src); this.write(map); this.clone() diff --git a/rules/unique_ptr/shim.rs b/rules/unique_ptr/shim.rs index 264aad2598..d3ac1adcf0 100644 --- a/rules/unique_ptr/shim.rs +++ b/rules/unique_ptr/shim.rs @@ -12,7 +12,7 @@ impl MoveConstructible for Option> where Self: ByteRepr, { - fn move_constructor(this: &Ptr, src: Ptr) { + fn move_constructor(this: Ptr, src: Ptr) { let value = src.with_mut(Option::take); this.with_mut(|dst| *dst = value); } @@ -22,7 +22,7 @@ impl MoveAssignable for Option> where Self: ByteRepr, { - fn move_assign(this: &Ptr, src: Ptr) -> Ptr { + fn move_assign(this: Ptr, src: Ptr) -> Ptr { let value = src.with_mut(Option::take); this.with_mut(|dst| *dst = value); this.clone() @@ -46,7 +46,7 @@ impl Swappable for Option> where Self: ByteRepr, { - fn swap(this: &Ptr, other: Ptr) { + fn swap(this: Ptr, other: Ptr) { this.swap_with(&other, |p| p.with_mut(Option::take)); } } diff --git a/rules/vector/shim.rs b/rules/vector/shim.rs index 5dd36017b1..a0ff6040a0 100644 --- a/rules/vector/shim.rs +++ b/rules/vector/shim.rs @@ -23,7 +23,7 @@ crate::constructor::impl_move_by_take!( Vec); // A vector is copied by copying its elements, each with its copy constructor. impl CopyConstructible for Vec { - fn copy_constructor(this: &Ptr, src: Ptr) { + fn copy_constructor(this: Ptr, src: Ptr) { this.write(T::copied_elems(&src)); } @@ -33,7 +33,7 @@ impl CopyConstructible for } impl CopyAssignable for Vec { - fn copy_assign(this: &Ptr, src: Ptr) -> Ptr { + fn copy_assign(this: Ptr, src: Ptr) -> Ptr { this.write(T::copied_elems(&src)); this.clone() } From 864a63353541b462506f1d317344454795b227ea Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 11:07:04 +0000 Subject: [PATCH 03/18] Update tests --- .../utility/out/refcount/forward-helpers.rs | 16 +++++++------- .../utility/out/unsafe/forward-helpers.rs | 22 ++++++++++++------- tests/unit/out/refcount/copy_ctor.rs | 4 ++-- .../out/refcount/destructor_temporaries.rs | 8 +++---- tests/unit/out/refcount/fn_ptr_struct.rs | 8 +++---- tests/unit/out/refcount/forward_basic.rs | 8 +++---- tests/unit/out/refcount/forward_explicit.rs | 4 ++-- tests/unit/out/refcount/forward_pack.rs | 4 ++-- .../out/refcount/lambda_capture_copy_ctor.rs | 4 ++-- tests/unit/out/refcount/map_key_copy_ctor.rs | 4 ++-- tests/unit/out/refcount/max.rs | 4 ++-- tests/unit/out/refcount/move_assign.rs | 4 ++-- tests/unit/out/refcount/move_ctor.rs | 4 ++-- tests/unit/out/refcount/move_this.rs | 8 +++---- tests/unit/out/refcount/rule_of_five.rs | 4 ++-- .../refcount/structured_binding_copy_ctor.rs | 4 ++-- .../structured_binding_element_ctor.rs | 4 ++-- .../refcount/structured_binding_move_ctor.rs | 4 ++-- .../unit/out/refcount/temporary_field_addr.rs | 4 ++-- .../out/refcount/temporary_field_ctor_arg.rs | 4 ++-- .../out/refcount/temporary_field_two_args.rs | 4 ++-- tests/unit/out/unsafe/copy_ctor.rs | 4 ++-- .../unit/out/unsafe/destructor_temporaries.rs | 8 +++---- tests/unit/out/unsafe/fn_ptr_struct.rs | 8 +++---- tests/unit/out/unsafe/forward_basic.rs | 8 +++---- tests/unit/out/unsafe/forward_explicit.rs | 4 ++-- tests/unit/out/unsafe/forward_pack.rs | 4 ++-- .../out/unsafe/lambda_capture_copy_ctor.rs | 4 ++-- tests/unit/out/unsafe/map_key_copy_ctor.rs | 4 ++-- tests/unit/out/unsafe/max.rs | 4 ++-- tests/unit/out/unsafe/move_assign.rs | 4 ++-- tests/unit/out/unsafe/move_ctor.rs | 4 ++-- tests/unit/out/unsafe/move_this.rs | 8 +++---- tests/unit/out/unsafe/rule_of_five.rs | 4 ++-- .../unsafe/structured_binding_copy_ctor.rs | 4 ++-- .../unsafe/structured_binding_element_ctor.rs | 4 ++-- .../unsafe/structured_binding_move_ctor.rs | 4 ++-- tests/unit/out/unsafe/temporary_field_addr.rs | 4 ++-- .../out/unsafe/temporary_field_ctor_arg.rs | 4 ++-- .../out/unsafe/temporary_field_two_args.rs | 4 ++-- 40 files changed, 114 insertions(+), 108 deletions(-) diff --git a/tests/std/utilities/utility/out/refcount/forward-helpers.rs b/tests/std/utilities/utility/out/refcount/forward-helpers.rs index 1274841391..5d5204134d 100644 --- a/tests/std/utilities/utility/out/refcount/forward-helpers.rs +++ b/tests/std/utilities/utility/out/refcount/forward-helpers.rs @@ -66,12 +66,12 @@ impl Default for p6_forward_like_Holder { } } } -pub fn take_1(this: Ptr, self_: Ptr) { - ConstructFrom::construct_from(this.clone(), field_ptr!(self_, member)); +pub fn take_1(__return: Ptr, self_: Ptr) { + ConstructFrom::construct_from(__return.clone(), field_ptr!(self_, member)); return; } -pub fn take_2(this: Ptr, self_: Ptr) { - ConstructFrom::construct_from(this.clone(), Moved(field_ptr!(self_, member))); +pub fn take_2(__return: Ptr, self_: Ptr) { + ConstructFrom::construct_from(__return.clone(), Moved(field_ptr!(self_, member))); return; } pub fn test_3() { @@ -176,12 +176,12 @@ impl Default for p10_forward_in_template_A { { ::zero_init() } } } -pub fn make_5(this: Ptr, source: Ptr) { - ConstructFrom::construct_from(this.clone(), (source).clone()); +pub fn make_5(__return: Ptr, source: Ptr) { + ConstructFrom::construct_from(__return.clone(), (source).clone()); return; } -pub fn make_6(this: Ptr, source: Ptr) { - ConstructFrom::construct_from(this.clone(), Moved((source).clone())); +pub fn make_6(__return: Ptr, source: Ptr) { + ConstructFrom::construct_from(__return.clone(), Moved((source).clone())); return; } pub fn test_7() { diff --git a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs index f4d8e19b1d..f450a59b50 100644 --- a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs +++ b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs @@ -62,12 +62,12 @@ 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); +pub unsafe fn take_1(__return: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { + ConstructFromUnsafe::construct_from(&mut *__return, &(*self_).member); return; } -pub unsafe fn take_2(this: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { - ConstructFromUnsafe::construct_from(&mut *this, Moved(&mut (*self_).member)); +pub unsafe fn take_2(__return: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { + ConstructFromUnsafe::construct_from(&mut *__return, Moved(&mut (*self_).member)); return; } pub unsafe fn test_3() { @@ -165,12 +165,18 @@ impl Default for p10_forward_in_template_A { unsafe { ::zero_init() } } } -pub unsafe fn make_5(this: *mut p10_forward_in_template_A, source: *mut p10_forward_in_template_A) { - ConstructFromUnsafe::construct_from(&mut *this, source); +pub unsafe fn make_5( + __return: *mut p10_forward_in_template_A, + source: *mut p10_forward_in_template_A, +) { + ConstructFromUnsafe::construct_from(&mut *__return, source); return; } -pub unsafe fn make_6(this: *mut p10_forward_in_template_A, source: *mut p10_forward_in_template_A) { - ConstructFromUnsafe::construct_from(&mut *this, Moved(source)); +pub unsafe fn make_6( + __return: *mut p10_forward_in_template_A, + source: *mut p10_forward_in_template_A, +) { + ConstructFromUnsafe::construct_from(&mut *__return, Moved(source)); return; } pub unsafe fn test_7() { diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index 59c7340128..1c838005ce 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -247,9 +247,9 @@ pub fn touch_1(mut t: Ptr) { pub fn by_value_2(c: Ptr) -> i32 { return c.with(|__s| __s.v); } -pub fn make_3(this: Ptr, mut v: i32) { +pub fn make_3(__return: Ptr, mut v: i32) { object!(c, Counted(v)); - ConstructFrom::construct_from(this.clone(), c.as_pointer()); + ConstructFrom::construct_from(__return.clone(), c.as_pointer()); return; } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, Destructible)] diff --git a/tests/unit/out/refcount/destructor_temporaries.rs b/tests/unit/out/refcount/destructor_temporaries.rs index c343b597f4..2c30e3fc3c 100644 --- a/tests/unit/out/refcount/destructor_temporaries.rs +++ b/tests/unit/out/refcount/destructor_temporaries.rs @@ -65,12 +65,12 @@ pub struct Outer { #[offset(4)] pub w: i32, } -pub fn make_2(this: Ptr, mut v: i32) { - this.write(S { v: v }); +pub fn make_2(__return: Ptr, mut v: i32) { + __return.write(S { v: v }); return; } -pub fn make_outer_3(this: Ptr) { - this.write(Outer { +pub fn make_outer_3(__return: Ptr) { + __return.write(Outer { inner: S { v: 7 }, w: 8, }); diff --git a/tests/unit/out/refcount/fn_ptr_struct.rs b/tests/unit/out/refcount/fn_ptr_struct.rs index 401f586c02..38d211ae47 100644 --- a/tests/unit/out/refcount/fn_ptr_struct.rs +++ b/tests/unit/out/refcount/fn_ptr_struct.rs @@ -79,12 +79,12 @@ impl MoveConstructible for MoveOnly { field!(x, data_).write(0); } } -pub fn make_move_only_2(this: Ptr) { - MoveOnly::construct(this.clone(), 4); +pub fn make_move_only_2(__return: Ptr) { + MoveOnly::construct(__return.clone(), 4); return; } -pub fn scale_move_only_3(this: Ptr, x: Ptr) { - MoveOnly::construct(this.clone(), (({ MoveOnly::get((x).clone()) }) * 10)); +pub fn scale_move_only_3(__return: Ptr, x: Ptr) { + MoveOnly::construct(__return.clone(), (({ MoveOnly::get((x).clone()) }) * 10)); return; } pub fn main() { diff --git a/tests/unit/out/refcount/forward_basic.rs b/tests/unit/out/refcount/forward_basic.rs index 909809f493..2830c24e3f 100644 --- a/tests/unit/out/refcount/forward_basic.rs +++ b/tests/unit/out/refcount/forward_basic.rs @@ -91,12 +91,12 @@ pub fn forward_twice_4(x: Ptr) -> Overload { pub fn forward_twice_5(x: Ptr) -> Overload { return ({ forward_once_3((x).clone()) }); } -pub fn forward_into_ctor_6(this: Ptr, x: Ptr) { - Holder::construct_1(this.clone(), (x).clone()); +pub fn forward_into_ctor_6(__return: Ptr, x: Ptr) { + Holder::construct_1(__return.clone(), (x).clone()); return; } -pub fn forward_into_ctor_7(this: Ptr, x: Ptr) { - Holder::construct_2(this.clone(), (x).clone()); +pub fn forward_into_ctor_7(__return: Ptr, x: Ptr) { + Holder::construct_2(__return.clone(), (x).clone()); return; } pub fn main() { diff --git a/tests/unit/out/refcount/forward_explicit.rs b/tests/unit/out/refcount/forward_explicit.rs index a273d6835b..8c178d0bd4 100644 --- a/tests/unit/out/refcount/forward_explicit.rs +++ b/tests/unit/out/refcount/forward_explicit.rs @@ -58,8 +58,8 @@ pub fn chosen_overload_2(_a0: Ptr) -> Overload { pub fn chosen_overload_3(_a0: Ptr) -> Overload { return Overload_kIntRvalueOverload; } -pub fn copy_or_move_into_param_4(this: Ptr, t: Ptr) { - ConstructFrom::construct_from(this.clone(), Moved((t).clone())); +pub fn copy_or_move_into_param_4(__return: Ptr, t: Ptr) { + ConstructFrom::construct_from(__return.clone(), Moved((t).clone())); return; } pub fn main() { diff --git a/tests/unit/out/refcount/forward_pack.rs b/tests/unit/out/refcount/forward_pack.rs index ea73959f0f..69e43be7ae 100644 --- a/tests/unit/out/refcount/forward_pack.rs +++ b/tests/unit/out/refcount/forward_pack.rs @@ -113,8 +113,8 @@ pub struct Pair { #[byte_size(12)] pub b: Tracked, } -pub fn forward_pack_into_ctor_8(this: Ptr, args_0: Ptr, args_1: Ptr) { - Pair::construct(this.clone(), (args_0).clone(), (args_1).clone()); +pub fn forward_pack_into_ctor_8(__return: Ptr, args_0: Ptr, args_1: Ptr) { + Pair::construct(__return.clone(), (args_0).clone(), (args_1).clone()); return; } pub fn main() { diff --git a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs index 8712119863..225a2866f9 100644 --- a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs @@ -99,8 +99,8 @@ fn main_0() -> i32 { Rc::try_unwrap(__v).ok().unwrap().into_inner() })); }, - |this: Ptr| { - ConstructFrom::construct_from(this.clone(), c.as_pointer()); + |__return: Ptr| { + ConstructFrom::construct_from(__return.clone(), c.as_pointer()); return; } ) diff --git a/tests/unit/out/refcount/map_key_copy_ctor.rs b/tests/unit/out/refcount/map_key_copy_ctor.rs index 27ec703703..23a1742f03 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -55,9 +55,9 @@ impl CppEq for Key { && !(Key::operator_lt(__rhs.clone(), __lhs.clone())) } } -pub fn make_key_3(this: Ptr, mut k: i32) { +pub fn make_key_3(__return: Ptr, mut k: i32) { (*made_2.with(Value::clone).borrow_mut()).prefix_inc(); - Key::construct(this.clone(), k); + Key::construct(__return.clone(), k); return; } pub fn main() { diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index ee1944e997..fdd9e50724 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -65,8 +65,8 @@ impl CppEq for Bag { pub fn operator_lt_4(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.n) } < { b.with(|__s| __s.n) }); } -pub fn make_5(this: Ptr, mut n: i32) { - Bag::construct(this.clone(), n); +pub fn make_5(__return: Ptr, mut n: i32) { + Bag::construct(__return.clone(), n); return; } pub fn main() { diff --git a/tests/unit/out/refcount/move_assign.rs b/tests/unit/out/refcount/move_assign.rs index 3abb448fc9..5664557646 100644 --- a/tests/unit/out/refcount/move_assign.rs +++ b/tests/unit/out/refcount/move_assign.rs @@ -76,9 +76,9 @@ impl Default for ConstMoveAssign { } } } -pub fn make_0(this: Ptr, mut v: i32) { +pub fn make_0(__return: Ptr, mut v: i32) { object!(m, MoveOnly(v)); - ConstructFrom::construct_from(this.clone(), Moved(m.as_pointer())); + ConstructFrom::construct_from(__return.clone(), Moved(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 5d2a0252ef..97c764b6c1 100644 --- a/tests/unit/out/refcount/move_ctor.rs +++ b/tests/unit/out/refcount/move_ctor.rs @@ -129,9 +129,9 @@ 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) { +pub fn make_1(__return: Ptr, mut v: i32) { object!(m, MoveOnly(v)); - ConstructFrom::construct_from(this.clone(), Moved(m.as_pointer())); + ConstructFrom::construct_from(__return.clone(), Moved(m.as_pointer())); return; } pub fn main() { diff --git a/tests/unit/out/refcount/move_this.rs b/tests/unit/out/refcount/move_this.rs index 4d20d16f2a..de74dd8d5d 100644 --- a/tests/unit/out/refcount/move_this.rs +++ b/tests/unit/out/refcount/move_this.rs @@ -31,12 +31,12 @@ impl Chain { }; return (this).clone(); } - pub fn take(this: Ptr, this: Ptr) { - ConstructFrom::construct_from(this.clone(), Moved((this).clone())); + pub fn take(this: Ptr, __return: Ptr) { + ConstructFrom::construct_from(__return.clone(), Moved((this).clone())); return; } - pub fn copy(this: Ptr, this: Ptr) { - ConstructFrom::construct_from(this.clone(), (this).clone()); + pub fn copy(this: Ptr, __return: Ptr) { + ConstructFrom::construct_from(__return.clone(), (this).clone()); return; } pub fn self_(this: Ptr) -> Ptr { diff --git a/tests/unit/out/refcount/rule_of_five.rs b/tests/unit/out/refcount/rule_of_five.rs index dab6217121..b497cf9c2c 100644 --- a/tests/unit/out/refcount/rule_of_five.rs +++ b/tests/unit/out/refcount/rule_of_five.rs @@ -125,9 +125,9 @@ impl MoveAssignable for Buffer { return (this).clone(); } } -pub fn make_3(this: Ptr, mut size: i32) { +pub fn make_3(__return: Ptr, mut size: i32) { object!(b, Buffer(size)); - ConstructFrom::construct_from(this.clone(), Moved(b.as_pointer())); + ConstructFrom::construct_from(__return.clone(), Moved(b.as_pointer())); return; } pub fn main() { diff --git a/tests/unit/out/refcount/structured_binding_copy_ctor.rs b/tests/unit/out/refcount/structured_binding_copy_ctor.rs index 3043636b7f..3a0162e107 100644 --- a/tests/unit/out/refcount/structured_binding_copy_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_copy_ctor.rs @@ -42,8 +42,8 @@ impl CopyConstructible for Counted { (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); } } -pub fn make_counted_1(this: Ptr) { - Counted::construct(this.clone(), 5, 6); +pub fn make_counted_1(__return: Ptr) { + Counted::construct(__return.clone(), 5, 6); return; } pub fn main() { diff --git a/tests/unit/out/refcount/structured_binding_element_ctor.rs b/tests/unit/out/refcount/structured_binding_element_ctor.rs index 02c95f90d4..405c4024d0 100644 --- a/tests/unit/out/refcount/structured_binding_element_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_element_ctor.rs @@ -52,8 +52,8 @@ pub struct Two { #[byte_size(4)] pub b: Elem, } -pub fn make_two_2(this: Ptr) { - this.write(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); diff --git a/tests/unit/out/refcount/structured_binding_move_ctor.rs b/tests/unit/out/refcount/structured_binding_move_ctor.rs index df4cb1d71f..58ccc2b8df 100644 --- a/tests/unit/out/refcount/structured_binding_move_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_move_ctor.rs @@ -66,8 +66,8 @@ pub struct Holder { pub ys: Vec, } impl Holder { - pub fn extract(this: Ptr, this: Ptr) { - this.write(Holder { + pub fn extract(this: Ptr, __return: Ptr) { + __return.write(Holder { xs: field!(this, xs).with_mut(std::mem::take), ys: field!(this, ys).with_mut(std::mem::take), }); diff --git a/tests/unit/out/refcount/temporary_field_addr.rs b/tests/unit/out/refcount/temporary_field_addr.rs index 3b40ef24e4..fff18c3bc5 100644 --- a/tests/unit/out/refcount/temporary_field_addr.rs +++ b/tests/unit/out/refcount/temporary_field_addr.rs @@ -75,11 +75,11 @@ impl Default for Outer { } } } -pub fn make_0(this: Ptr, calls: Ptr) { +pub fn make_0(__return: Ptr, calls: Ptr) { calls.with_mut(|__v| { __v.prefix_inc(); }); - this.write(Outer { + __return.write(Outer { values: Vec::from([1, 2, 3]), inner: Inner { values: Vec::from([4, 5, 6]), diff --git a/tests/unit/out/refcount/temporary_field_ctor_arg.rs b/tests/unit/out/refcount/temporary_field_ctor_arg.rs index 776b83083a..13657670a7 100644 --- a/tests/unit/out/refcount/temporary_field_ctor_arg.rs +++ b/tests/unit/out/refcount/temporary_field_ctor_arg.rs @@ -31,8 +31,8 @@ impl DefaultConstructible for Outer { field!(this, values).write(Vec::new()); } } -pub fn make_0(this: Ptr) { - this.write(Outer { +pub fn make_0(__return: Ptr) { + __return.write(Outer { values: Vec::from([1, 2, 3, 4]), }); return; diff --git a/tests/unit/out/refcount/temporary_field_two_args.rs b/tests/unit/out/refcount/temporary_field_two_args.rs index 58f50b3bfa..5dfcce5ada 100644 --- a/tests/unit/out/refcount/temporary_field_two_args.rs +++ b/tests/unit/out/refcount/temporary_field_two_args.rs @@ -60,8 +60,8 @@ impl DefaultConstructible for Outer { DefaultConstructible::default_constructor(field_ptr!(this, inner)); } } -pub fn make_0(this: Ptr) { - this.write(Outer { +pub fn make_0(__return: Ptr) { + __return.write(Outer { values: Vec::from([1, 2, 3]), inner: Inner { values: Vec::from([4, 5, 6]), diff --git a/tests/unit/out/unsafe/copy_ctor.rs b/tests/unit/out/unsafe/copy_ctor.rs index 9b07550355..8aa8637def 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -209,9 +209,9 @@ pub unsafe fn touch_1(mut t: *const Tracked) { pub unsafe fn by_value_2(c: *mut Counted) -> i32 { return (*c).v; } -pub unsafe fn make_3(this: *mut Counted, mut v: i32) { +pub unsafe fn make_3(__return: *mut Counted, mut v: i32) { object_unsafe!(c, Counted(v)); - ConstructFromUnsafe::construct_from(&mut *this, &c); + ConstructFromUnsafe::construct_from(&mut *__return, &c); return; } #[repr(C)] diff --git a/tests/unit/out/unsafe/destructor_temporaries.rs b/tests/unit/out/unsafe/destructor_temporaries.rs index b07f4a8914..68574e6748 100644 --- a/tests/unit/out/unsafe/destructor_temporaries.rs +++ b/tests/unit/out/unsafe/destructor_temporaries.rs @@ -53,12 +53,12 @@ pub struct Outer { pub inner: S, pub w: i32, } -pub unsafe fn make_2(this: *mut S, mut v: i32) { - this.write(S { v: v }); +pub unsafe fn make_2(__return: *mut S, mut v: i32) { + __return.write(S { v: v }); return; } -pub unsafe fn make_outer_3(this: *mut Outer) { - this.write(Outer { +pub unsafe fn make_outer_3(__return: *mut Outer) { + __return.write(Outer { inner: S { v: 7 }, w: 8, }); diff --git a/tests/unit/out/unsafe/fn_ptr_struct.rs b/tests/unit/out/unsafe/fn_ptr_struct.rs index 129df4dff2..db62aad441 100644 --- a/tests/unit/out/unsafe/fn_ptr_struct.rs +++ b/tests/unit/out/unsafe/fn_ptr_struct.rs @@ -72,12 +72,12 @@ impl MoveConstructibleUnsafe for MoveOnly { (*x).data_ = 0; } } -pub unsafe fn make_move_only_2(this: *mut MoveOnly) { - MoveOnly::construct(&mut *this, 4); +pub unsafe fn make_move_only_2(__return: *mut MoveOnly) { + MoveOnly::construct(&mut *__return, 4); return; } -pub unsafe fn scale_move_only_3(this: *mut MoveOnly, x: *mut MoveOnly) { - MoveOnly::construct(&mut *this, ((unsafe { MoveOnly::get(&(*x)) }) * (10))); +pub unsafe fn scale_move_only_3(__return: *mut MoveOnly, x: *mut MoveOnly) { + MoveOnly::construct(&mut *__return, ((unsafe { MoveOnly::get(&(*x)) }) * (10))); return; } pub fn main() { diff --git a/tests/unit/out/unsafe/forward_basic.rs b/tests/unit/out/unsafe/forward_basic.rs index 28acaf70ac..39a0d7b5bb 100644 --- a/tests/unit/out/unsafe/forward_basic.rs +++ b/tests/unit/out/unsafe/forward_basic.rs @@ -84,12 +84,12 @@ pub unsafe fn forward_twice_4(x: *mut Tracked) -> Overload { pub unsafe fn forward_twice_5(x: *mut Tracked) -> Overload { return (unsafe { forward_once_3(x) }); } -pub unsafe fn forward_into_ctor_6(this: *mut Holder, x: *mut Tracked) { - Holder::construct_1(&mut *this, x); +pub unsafe fn forward_into_ctor_6(__return: *mut Holder, x: *mut Tracked) { + Holder::construct_1(&mut *__return, x); return; } -pub unsafe fn forward_into_ctor_7(this: *mut Holder, x: *mut Tracked) { - Holder::construct_2(&mut *this, x); +pub unsafe fn forward_into_ctor_7(__return: *mut Holder, x: *mut Tracked) { + Holder::construct_2(&mut *__return, x); return; } pub fn main() { diff --git a/tests/unit/out/unsafe/forward_explicit.rs b/tests/unit/out/unsafe/forward_explicit.rs index bc6566496a..8e83703bd2 100644 --- a/tests/unit/out/unsafe/forward_explicit.rs +++ b/tests/unit/out/unsafe/forward_explicit.rs @@ -55,8 +55,8 @@ pub unsafe fn chosen_overload_2(_a0: *const i32) -> Overload { pub unsafe fn chosen_overload_3(_a0: *mut i32) -> Overload { return Overload_kIntRvalueOverload; } -pub unsafe fn copy_or_move_into_param_4(this: *mut Tracked, t: *mut Tracked) { - ConstructFromUnsafe::construct_from(&mut *this, Moved(t)); +pub unsafe fn copy_or_move_into_param_4(__return: *mut Tracked, t: *mut Tracked) { + ConstructFromUnsafe::construct_from(&mut *__return, Moved(t)); return; } pub fn main() { diff --git a/tests/unit/out/unsafe/forward_pack.rs b/tests/unit/out/unsafe/forward_pack.rs index 85010a2f44..c92e83a4b3 100644 --- a/tests/unit/out/unsafe/forward_pack.rs +++ b/tests/unit/out/unsafe/forward_pack.rs @@ -105,11 +105,11 @@ pub struct Pair { pub b: Tracked, } pub unsafe fn forward_pack_into_ctor_8( - this: *mut Pair, + __return: *mut Pair, args_0: *mut Tracked, args_1: *mut Tracked, ) { - Pair::construct(&mut *this, args_0, args_1); + Pair::construct(&mut *__return, args_0, args_1); return; } pub fn main() { diff --git a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs index ae9d514bae..494c57f796 100644 --- a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs @@ -97,8 +97,8 @@ unsafe fn main_0() -> i32 { __v }; }, - |this: *mut Counted| { - ConstructFromUnsafe::construct_from(&mut *this, &c); + |__return: *mut Counted| { + ConstructFromUnsafe::construct_from(&mut *__return, &c); return; } ) diff --git a/tests/unit/out/unsafe/map_key_copy_ctor.rs b/tests/unit/out/unsafe/map_key_copy_ctor.rs index 51f47533cd..1829ba8812 100644 --- a/tests/unit/out/unsafe/map_key_copy_ctor.rs +++ b/tests/unit/out/unsafe/map_key_copy_ctor.rs @@ -64,9 +64,9 @@ impl std::cmp::PartialEq for Key { } } impl std::cmp::Eq for Key {} -pub unsafe fn make_key_3(this: *mut Key, mut k: i32) { +pub unsafe fn make_key_3(__return: *mut Key, mut k: i32) { (*std::cell::LazyCell::force_mut(&mut *&raw mut made_2)).prefix_inc(); - Key::construct(&mut *this, k); + Key::construct(&mut *__return, k); return; } pub fn main() { diff --git a/tests/unit/out/unsafe/max.rs b/tests/unit/out/unsafe/max.rs index 6d058d9580..37ada6222d 100644 --- a/tests/unit/out/unsafe/max.rs +++ b/tests/unit/out/unsafe/max.rs @@ -74,8 +74,8 @@ impl std::cmp::Eq for Bag {} pub unsafe fn operator_lt_4(a: *const Bag, b: *const Bag) -> bool { return (((*a).n) < ((*b).n)); } -pub unsafe fn make_5(this: *mut Bag, mut n: i32) { - Bag::construct(&mut *this, n); +pub unsafe fn make_5(__return: *mut Bag, mut n: i32) { + Bag::construct(&mut *__return, n); return; } pub fn main() { diff --git a/tests/unit/out/unsafe/move_assign.rs b/tests/unit/out/unsafe/move_assign.rs index ac1f8d6f3c..1ebc0fc766 100644 --- a/tests/unit/out/unsafe/move_assign.rs +++ b/tests/unit/out/unsafe/move_assign.rs @@ -71,9 +71,9 @@ impl Default for ConstMoveAssign { } } } -pub unsafe fn make_0(this: *mut MoveOnly, mut v: i32) { +pub unsafe fn make_0(__return: *mut MoveOnly, mut v: i32) { object_unsafe!(m, MoveOnly(v)); - ConstructFromUnsafe::construct_from(&mut *this, Moved(&mut m)); + ConstructFromUnsafe::construct_from(&mut *__return, Moved(&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 7df880a284..225813742f 100644 --- a/tests/unit/out/unsafe/move_ctor.rs +++ b/tests/unit/out/unsafe/move_ctor.rs @@ -121,9 +121,9 @@ impl MoveConstructibleUnsafe for NoexceptMove { pub unsafe fn by_value_0(m: *mut MoveOnly) -> i32 { return (*m).v; } -pub unsafe fn make_1(this: *mut MoveOnly, mut v: i32) { +pub unsafe fn make_1(__return: *mut MoveOnly, mut v: i32) { object_unsafe!(m, MoveOnly(v)); - ConstructFromUnsafe::construct_from(&mut *this, Moved(&mut m)); + ConstructFromUnsafe::construct_from(&mut *__return, Moved(&mut m)); return; } pub fn main() { diff --git a/tests/unit/out/unsafe/move_this.rs b/tests/unit/out/unsafe/move_this.rs index f50a3cf2c6..750fa3ef3e 100644 --- a/tests/unit/out/unsafe/move_this.rs +++ b/tests/unit/out/unsafe/move_this.rs @@ -26,12 +26,12 @@ impl Chain { self.v += n; 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)))); + pub unsafe fn take(&mut self, __return: *mut Chain) { + ConstructFromUnsafe::construct_from(&mut *__return, Moved(&mut (*(self as *mut Chain)))); return; } - pub unsafe fn copy(&self, this: *mut Chain) { - ConstructFromUnsafe::construct_from(&mut *this, &(*(self as *const Chain))); + pub unsafe fn copy(&self, __return: *mut Chain) { + ConstructFromUnsafe::construct_from(&mut *__return, &(*(self as *const Chain))); return; } pub unsafe fn self_(&mut self) -> *mut Chain { diff --git a/tests/unit/out/unsafe/rule_of_five.rs b/tests/unit/out/unsafe/rule_of_five.rs index 769b92093f..fbccbe993d 100644 --- a/tests/unit/out/unsafe/rule_of_five.rs +++ b/tests/unit/out/unsafe/rule_of_five.rs @@ -115,9 +115,9 @@ impl MoveAssignableUnsafe for Buffer { return &mut (*(self as *mut Buffer)); } } -pub unsafe fn make_3(this: *mut Buffer, mut size: i32) { +pub unsafe fn make_3(__return: *mut Buffer, mut size: i32) { object_unsafe!(b, Buffer(size)); - ConstructFromUnsafe::construct_from(&mut *this, Moved(&mut b)); + ConstructFromUnsafe::construct_from(&mut *__return, Moved(&mut b)); return; } pub fn main() { diff --git a/tests/unit/out/unsafe/structured_binding_copy_ctor.rs b/tests/unit/out/unsafe/structured_binding_copy_ctor.rs index 4609748403..7e7a0a376c 100644 --- a/tests/unit/out/unsafe/structured_binding_copy_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_copy_ctor.rs @@ -36,8 +36,8 @@ impl CopyConstructibleUnsafe for Counted { (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } -pub unsafe fn make_counted_1(this: *mut Counted) { - Counted::construct(&mut *this, 5, 6); +pub unsafe fn make_counted_1(__return: *mut Counted) { + Counted::construct(&mut *__return, 5, 6); return; } pub fn main() { diff --git a/tests/unit/out/unsafe/structured_binding_element_ctor.rs b/tests/unit/out/unsafe/structured_binding_element_ctor.rs index d314ca6c61..64c9ccab97 100644 --- a/tests/unit/out/unsafe/structured_binding_element_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_element_ctor.rs @@ -43,8 +43,8 @@ pub struct Two { pub a: Elem, pub b: Elem, } -pub unsafe fn make_two_2(this: *mut Two) { - this.write(Two { +pub unsafe fn make_two_2(__return: *mut Two) { + __return.write(Two { a: { let mut __v: Elem = ::zero_init(); Elem::construct(&mut __v, 1); diff --git a/tests/unit/out/unsafe/structured_binding_move_ctor.rs b/tests/unit/out/unsafe/structured_binding_move_ctor.rs index c7ff58e922..6300b9c8f9 100644 --- a/tests/unit/out/unsafe/structured_binding_move_ctor.rs +++ b/tests/unit/out/unsafe/structured_binding_move_ctor.rs @@ -54,8 +54,8 @@ pub struct Holder { pub ys: Vec, } impl Holder { - pub unsafe fn extract(&mut self, this: *mut Holder) { - this.write(Holder { + pub unsafe fn extract(&mut self, __return: *mut Holder) { + __return.write(Holder { xs: std::mem::take(&mut self.xs), ys: std::mem::take(&mut self.ys), }); diff --git a/tests/unit/out/unsafe/temporary_field_addr.rs b/tests/unit/out/unsafe/temporary_field_addr.rs index f49b2ebbbc..2fbd73ca9a 100644 --- a/tests/unit/out/unsafe/temporary_field_addr.rs +++ b/tests/unit/out/unsafe/temporary_field_addr.rs @@ -52,9 +52,9 @@ impl DefaultConstructibleUnsafe for Outer { (&raw mut self.name).write([(0 as libc::c_char); 8]); } } -pub unsafe fn make_0(this: *mut Outer, calls: *mut i32) { +pub unsafe fn make_0(__return: *mut Outer, calls: *mut i32) { (*calls).prefix_inc(); - this.write(Outer { + __return.write(Outer { values: Vec::from([1, 2, 3]), inner: Inner { values: Vec::from([4, 5, 6]), diff --git a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs index e9174afcfd..5ab9fda79f 100644 --- a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs +++ b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs @@ -27,8 +27,8 @@ impl DefaultConstructibleUnsafe for Outer { (&raw mut self.values).write(Vec::new()); } } -pub unsafe fn make_0(this: *mut Outer) { - this.write(Outer { +pub unsafe fn make_0(__return: *mut Outer) { + __return.write(Outer { values: Vec::from([1, 2, 3, 4]), }); return; diff --git a/tests/unit/out/unsafe/temporary_field_two_args.rs b/tests/unit/out/unsafe/temporary_field_two_args.rs index 35738bb6ba..f7984fa97f 100644 --- a/tests/unit/out/unsafe/temporary_field_two_args.rs +++ b/tests/unit/out/unsafe/temporary_field_two_args.rs @@ -50,8 +50,8 @@ impl DefaultConstructibleUnsafe for Outer { DefaultConstructibleUnsafe::default_constructor(&mut self.inner); } } -pub unsafe fn make_0(this: *mut Outer) { - this.write(Outer { +pub unsafe fn make_0(__return: *mut Outer) { + __return.write(Outer { values: Vec::from([1, 2, 3]), inner: Inner { values: Vec::from([4, 5, 6]), From c71898d4de8c0a314f7a4e0829c9f0971999e3b0 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 11:18:41 +0000 Subject: [PATCH 04/18] Add EqualityComparable --- cpp2rust/converter/converter.cpp | 106 +++++++++++++++--- cpp2rust/converter/converter.h | 10 ++ cpp2rust/converter/converter_lib.cpp | 44 +++++++- cpp2rust/converter/converter_lib.h | 10 ++ .../converter/models/converter_refcount.cpp | 22 +++- .../converter/models/converter_refcount.h | 4 + libcc2rs/src/cmp.rs | 93 +++++++++++++-- rules/algorithm/tgt_refcount.rs | 8 +- rules/algorithm/tgt_unsafe.rs | 8 +- rules/iterator_category/shim.rs | 10 ++ rules/pair/tgt_refcount.rs | 4 + rules/pair/tgt_unsafe.rs | 4 +- .../expr.prim/out/unsafe/expr.prim.this.rs | 5 +- 13 files changed, 289 insertions(+), 39 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index d876129cd9..1cc1171bda 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -489,6 +489,10 @@ bool Converter::VisitFunctionDecl(clang::FunctionDecl *decl) { } DumpVerbose(decl); ScopedValue push_fn(curr_function_, decl); + if (auto *trait = GetComparisonTrait(decl)) { + ConvertComparisonTraitImpl(decl, *trait); + return false; + } std::string function_name; if (decl->isMain()) { // main_0 is private. @@ -512,6 +516,29 @@ bool Converter::VisitFunctionDecl(clang::FunctionDecl *decl) { return false; } +void Converter::ConvertComparisonTraitImpl(clang::FunctionDecl *decl, + const RecordTrait &trait) { + const auto &spelling = GetRecordTraitSpelling(trait); + auto *record = GetComparisonRecord(decl); + StrCat(keyword::kImpl, spelling.name, "for", GetRecordName(record)); + PushBrace impl_brace(*this); + StrCat(spelling.signature); + PushBrace body(*this); + auto params = DefinitionParameters(decl); + const char *operands[] = {spelling.receiver, GetComparisonRhs()}; + for (unsigned i = 0; i < 2; ++i) { + StrCat(keyword::kLet); + { + ScopedValue in_formals(in_function_formals_, true); + ConvertVarDeclSkipInit(params[i]); + } + StrCat(token::kAssign, GetComparisonArg(params[i], record, operands[i]), + token::kSemiColon); + } + EmitFunctionPreamble(decl); + ConvertFunctionBody(decl); +} + void Converter::EmitHoistedDecls(clang::CompoundStmt *body) { for (auto *child : body->body()) { if (auto *decl_stmt = clang::dyn_cast(child)) { @@ -2626,22 +2653,36 @@ void Converter::EmitArgList(const CallInfo &info) { StrCat("Moved"); } PushParen moved_paren(*this, moved); - switch (ca.kind) { - case Kind::Hoisted: - StrCat(ca.param_name); - break; - case Kind::Materialized: - StrCat(ca.ref_temp_name); - break; - case Kind::Inline: { - StrCat(ConvertArg(info.expr, - [&] { ConvertParamTy(ca.param_type, ca.expr); })); + auto emit_arg = [&] { + switch (ca.kind) { + case Kind::Hoisted: + StrCat(ca.param_name); + break; + case Kind::Materialized: + StrCat(ca.ref_temp_name); + break; + case Kind::Inline: { + StrCat(ConvertArg(info.expr, + [&] { ConvertParamTy(ca.param_type, ca.expr); })); - if (info.is_libc_passthrough) { - StrCat(std::format("as {}", Mapper::GetParamType(*this, info.expr, i))); + if (info.is_libc_passthrough) { + StrCat( + std::format("as {}", Mapper::GetParamType(*this, info.expr, i))); + } + break; } - break; - } + } + }; + if (i == 0 && info.first_arg_is_receiver) { + std::string arg; + { + Buffer buf(*this); + emit_arg(); + arg = std::move(buf).str(); + } + StrCat(GetTraitReceiverArg(arg)); + } else { + emit_arg(); } StrCat(token::kComma); @@ -2680,7 +2721,7 @@ void Converter::EmitCall(CallInfo &&info) { auto *direct_callee = info.expr->getDirectCallee(); assert(direct_callee); StrCat("libc::", direct_callee->getName()); - } else { + } else if (!EmitComparisonTraitCallee(info)) { PushExprKind push(*this, ExprKind::Callee); Convert(GetCallee(info.expr)); } @@ -2688,6 +2729,26 @@ void Converter::EmitCall(CallInfo &&info) { EmitArgList(info); } +bool Converter::EmitComparisonTraitCallee(CallInfo &info) { + auto *callee = info.expr->getDirectCallee(); + if (!callee || clang::isa(callee)) { + return false; + } + auto *trait = GetComparisonTrait(callee); + if (!trait) { + return false; + } + StrCat(GetCopyOrMoveTraitName(*trait), token::kDoubleColon, trait->method); + info.first_arg_is_receiver = true; + return true; +} + +const char *Converter::GetComparisonRhs() const { return "(&*__rhs)"; } + +std::string Converter::GetTraitReceiverArg(std::string_view ptr) const { + return std::format("&*({})", ptr); +} + void Converter::ConvertGenericCallExpr(clang::CallExpr *expr) { PushParen outer(*this); StrCat(keyword_unsafe_); @@ -2731,7 +2792,7 @@ void Converter::ConvertUserOperatorCall(clang::CXXOperatorCallExpr *expr) { SetUFCSReceiver(expr->getArg(0), false, method); } StrCat(GetUFCSName(method), token::kDoubleColon, GetMethodName(method)); - } else { + } else if (!EmitComparisonTraitCallee(info)) { StrCat(GetNamedDeclAsString(callee->getCanonicalDecl())); } EmitArgList(info); @@ -5823,6 +5884,11 @@ std::string Converter::GetComparisonCall(const clang::FunctionDecl *op, GetComparisonReceiver(method, lhs), GetComparisonArg(op->getParamDecl(0), decl, rhs)); } + if (auto *trait = GetComparisonTrait(op)) { + return std::format("{}::{}({}, {})", GetCopyOrMoveTraitName(*trait), + trait->method, lhs, + GetComparisonArg(op->getParamDecl(1), decl, rhs)); + } return std::format("{}({}, {})", GetNamedDeclAsString(op->getCanonicalDecl()), GetComparisonArg(op->getParamDecl(0), decl, lhs), GetComparisonArg(op->getParamDecl(1), decl, rhs)); @@ -5914,6 +5980,14 @@ void Converter::ConvertOrdAndPartialOrdTraits(const clang::CXXRecordDecl *decl, ConvertOrdAndPartialOrdTraitsBase( cmp_body, GetEqBody(decl, eq, lt, cmp, "self", "other"), GetRecordName(decl)); + if (eq && !GetComparisonTrait(eq)) { + const auto &spelling = + GetRecordTraitSpelling(kWeaklyEqualityComparableWith); + StrCat(std::format( + "impl {} for {} {{ {} {{ {} }} }}", spelling.name, GetRecordName(decl), + spelling.signature, + GetComparisonBool(eq, decl, spelling.receiver, GetComparisonRhs()))); + } } void Converter::AddOrdTrait(const clang::CXXRecordDecl *decl) { diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index 4a7fc6d8e6..41c5105f12 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -481,10 +481,20 @@ class Converter : public clang::RecursiveASTVisitor { bool is_variadic; bool is_fn_ptr_call; bool is_libc_passthrough; + bool first_arg_is_receiver = false; }; CallInfo CollectCallInfo(clang::CallExpr *expr); + bool EmitComparisonTraitCallee(CallInfo &info); + + void ConvertComparisonTraitImpl(clang::FunctionDecl *decl, + const RecordTrait &trait); + + virtual const char *GetComparisonRhs() const; + + virtual std::string GetTraitReceiverArg(std::string_view ptr) const; + void ConvertParamTy(clang::QualType param_type, clang::Expr *expr); virtual void ConvertParamTyConstCast(clang::QualType param_type, diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 8e93241570..63b0f1e079 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -662,8 +662,49 @@ bool HasUserCopyConstructor(const clang::RecordDecl *decl) { }); } +const clang::CXXRecordDecl *GetComparisonRecord(const clang::FunctionDecl *fn) { + if (auto *method = clang::dyn_cast(fn)) { + return method->getParent(); + } + return fn->getNumParams() == 2 ? fn->getParamDecl(0) + ->getType() + .getNonReferenceType() + ->getAsCXXRecordDecl() + : nullptr; +} + +const RecordTrait *GetComparisonTrait(const clang::FunctionDecl *fn) { + if (fn->getOverloadedOperator() != clang::OO_EqualEqual) { + return nullptr; + } + auto *record = GetComparisonRecord(fn); + if (!record || !IsUserDefinedDecl(record) || fn->isDeleted() || + fn->getDescribedFunctionTemplate() || + !fn->getReturnType()->isBooleanType() || + !IsSameTypeComparison(fn, record)) { + return nullptr; + } + if (auto *method = clang::dyn_cast(fn); + method && (method->isVirtual() || !method->isConst() || + !method->isImplicitObjectMemberFunction() || + method->getRefQualifier() == clang::RQ_RValue)) { + return nullptr; + } + for (auto *param : fn->parameters()) { + auto type = param->getType(); + if (!type->isLValueReferenceType() || + !type.getNonReferenceType().isConstQualified()) { + return nullptr; + } + } + return &kWeaklyEqualityComparableWith; +} + const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method) { method = method->getCanonicalDecl(); + if (auto *trait = GetComparisonTrait(method)) { + return trait; + } if (auto *dtor = clang::dyn_cast(method)) { return IsConvertedDestructor(dtor) && !dtor->getParent()->isAbstract() ? &kDestructible @@ -700,7 +741,8 @@ bool IsDerivedCopyOrMove(const clang::CXXMethodDecl *method) { ctor && ctor->isDefaultConstructor()) { return false; } - return !method->isUserProvided() && GetRecordTrait(method); + return !method->isUserProvided() && !GetComparisonTrait(method) && + GetRecordTrait(method); } std::vector GetDerivedCopyOrMoves(const clang::RecordDecl *decl) { diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index 0ef8b0845a..d191d9b4fe 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -164,6 +164,12 @@ inline constexpr RecordTrait kDestructible{ "destroy", {"Destructible", "fn destroy(this: Ptr)", "this.clone()"}, {"DestructibleUnsafe", "unsafe fn destroy(&mut self)", "&mut *self"}}; +inline constexpr RecordTrait kWeaklyEqualityComparableWith{ + "equal", + {"WeaklyEqualityComparableWith", + "fn equal(this: Ptr, __rhs: Ptr) -> bool", "this.clone()"}, + {"WeaklyEqualityComparableWithUnsafe", + "unsafe fn equal(&self, __rhs: *const Self) -> bool", "self"}}; inline constexpr RecordTrait kTriviallyDefaultConstructible{ nullptr, {"TriviallyDefaultConstructible"}, @@ -180,6 +186,10 @@ inline constexpr RecordTrait kMemberwise{ const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method); +const RecordTrait *GetComparisonTrait(const clang::FunctionDecl *fn); + +const clang::CXXRecordDecl *GetComparisonRecord(const clang::FunctionDecl *fn); + // 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 8a6d96c9d8..8e86688b65 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -665,9 +665,10 @@ ConverterRefCount::GetComparisonReceiver(const clang::CXXMethodDecl *, } // Records implement the comparisons of the standard library (CppLess and -// CppEq) with their comparison operators, which get pointers to the values. -// They don't implement Ord and PartialEq, which get references to the values, -// as passing those to the operators would require copying the values. +// WeaklyEqualityComparableWith) with their comparison operators, which get +// pointers to the values. They don't implement Ord and PartialEq, which get +// references to the values, as passing those to the operators would require +// copying the values. void ConverterRefCount::ConvertOrdAndPartialOrdTraits( const clang::CXXRecordDecl *decl, const clang::FunctionDecl *eq, const clang::FunctionDecl *lt, const clang::FunctionDecl *cmp) { @@ -685,7 +686,20 @@ void ConverterRefCount::ConvertOrdAndPartialOrdTraits( std::format("{} == std::cmp::Ordering::Less", GetComparisonCall(cmp, decl, "__lhs", "__rhs"))); } - emit("CppEq", "equal", GetEqBody(decl, eq, lt, cmp, "__lhs", "__rhs")); + if (eq && !GetComparisonTrait(eq)) { + const auto &spelling = + GetRecordTraitSpelling(kWeaklyEqualityComparableWith); + StrCat(std::format( + "impl {} for {} {{ {} {{ {} }} }}", spelling.name, record_name, + spelling.signature, + GetComparisonBool(eq, decl, spelling.receiver, GetComparisonRhs()))); + } +} + +const char *ConverterRefCount::GetComparisonRhs() const { return "__rhs"; } + +std::string ConverterRefCount::GetTraitReceiverArg(std::string_view ptr) const { + return std::string(ptr); } // Whether decl is copied by copying its bytes or the pointers it holds. diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index d824157de8..8e705518c8 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -58,6 +58,10 @@ class ConverterRefCount final : public Converter { const clang::FunctionDecl *lt, const clang::FunctionDecl *cmp) override; + const char *GetComparisonRhs() const override; + + std::string GetTraitReceiverArg(std::string_view ptr) const override; + bool RecordImplementsClone(const clang::RecordDecl *decl) override; bool RecordDerivesClone(const clang::RecordDecl *decl); diff --git a/libcc2rs/src/cmp.rs b/libcc2rs/src/cmp.rs index 1b747a5be4..adf7c1d830 100644 --- a/libcc2rs/src/cmp.rs +++ b/libcc2rs/src/cmp.rs @@ -2,7 +2,7 @@ // Distributed under the MIT license that can be found in the LICENSE file. // The comparisons that the C++ standard library does with operator< and -// operator==, in the refcount model. +// operator==. use std::cmp::Ordering; @@ -14,9 +14,46 @@ pub trait CppLess: Sized { fn less(lhs: Ptr, rhs: Ptr) -> bool; } -// operator==. Records implement it with their comparison operators. -pub trait CppEq: Sized { - fn equal(lhs: Ptr, rhs: Ptr) -> bool; +pub trait WeaklyEqualityComparableWith: Sized { + fn equal(this: Ptr, rhs: Ptr) -> bool; +} + +pub trait WeaklyEqualityComparableWithUnsafe: Sized { + /// # Safety + /// `rhs` must point to a live value. + unsafe fn equal(&self, rhs: *const U) -> bool; +} + +pub trait EqualityComparable: WeaklyEqualityComparableWith {} + +impl> EqualityComparable for T {} + +pub trait EqualityComparableUnsafe: WeaklyEqualityComparableWithUnsafe {} + +impl> EqualityComparableUnsafe for T {} + +pub trait EqualityComparableWith: + EqualityComparable + WeaklyEqualityComparableWith +{ +} + +impl EqualityComparableWith for T +where + T: EqualityComparable + WeaklyEqualityComparableWith, + U: EqualityComparable, +{ +} + +pub trait EqualityComparableWithUnsafe: + EqualityComparableUnsafe + WeaklyEqualityComparableWithUnsafe +{ +} + +impl EqualityComparableWithUnsafe for T +where + T: EqualityComparableUnsafe + WeaklyEqualityComparableWithUnsafe, + U: EqualityComparableUnsafe, +{ } impl CppLess for T { @@ -25,9 +62,51 @@ impl CppLess for T { } } -impl + ByteRepr, U: ByteRepr> CppEq for T { - fn equal(lhs: Ptr, rhs: Ptr) -> bool { - lhs.with(|a| rhs.with(|b| a == b)) +macro_rules! impl_weakly_equality_comparable_with { + ($(<$($param:ident $(: $bound:path)?),*> $ty:ty),* $(,)?) => {$( + impl<$($param $(: $bound)?),*> $crate::WeaklyEqualityComparableWith for $ty + where + $ty: PartialEq + $crate::ByteRepr, + { + fn equal(this: $crate::Ptr, rhs: $crate::Ptr) -> bool { + this.with(|a| rhs.with(|b| a == b)) + } + } + )*}; +} +pub(crate) use impl_weakly_equality_comparable_with; + +macro_rules! impl_weakly_equality_comparable_with_unsafe { + ($(<$($param:ident $(: $bound:path)?),*> $ty:ty),* $(,)?) => {$( + impl<$($param $(: $bound)?),*> $crate::WeaklyEqualityComparableWithUnsafe for $ty + where + $ty: PartialEq, + { + unsafe fn equal(&self, rhs: *const Self) -> bool { + unsafe { *self == *rhs } + } + } + )*}; +} +pub(crate) use impl_weakly_equality_comparable_with_unsafe; + +impl_weakly_equality_comparable_with!( + <> bool, <> i8, <> i16, <> i32, <> i64, <> i128, <> isize, + <> u8, <> u16, <> u32, <> u64, <> u128, <> usize, <> f32, <> f64, + Ptr, <> crate::AnyPtr, crate::FnPtr, + Vec, Box<[T]>, Option, (A, B), +); + +impl_weakly_equality_comparable_with_unsafe!( + <> bool, <> i8, <> i16, <> i32, <> i64, <> i128, <> isize, + <> u8, <> u16, <> u32, <> u64, <> u128, <> usize, <> f32, <> f64, + *mut T, *const T, crate::FnPtr, + Vec, Option, (A, B), +); + +impl WeaklyEqualityComparableWithUnsafe for [T; N] { + unsafe fn equal(&self, rhs: *const Self) -> bool { + unsafe { *self == *rhs } } } diff --git a/rules/algorithm/tgt_refcount.rs b/rules/algorithm/tgt_refcount.rs index c4e8e12b6b..3f52f2b689 100644 --- a/rules/algorithm/tgt_refcount.rs +++ b/rules/algorithm/tgt_refcount.rs @@ -33,9 +33,9 @@ fn f2< __out } -fn f3, T2, T3: CppEq>(a0: T1, a1: T1, a2: Ptr) -> T1 { +fn f3, T2, T3: WeaklyEqualityComparableWith>(a0: T1, a1: T1, a2: Ptr) -> T1 { let mut __it = a0; - while __it != a1 && !CppEq::equal(__it.iter_deref(), a2.clone()) { + while __it != a1 && !WeaklyEqualityComparableWith::equal(__it.iter_deref(), a2.clone()) { __it.iter_inc(); } __it @@ -80,7 +80,7 @@ fn f9(a0: Ptr, a1: Ptr) { Swappable::swap(a0, a1) } -fn f10, T2: CppEq + TriviallyCopyable + ByteRepr>( +fn f10, T2: WeaklyEqualityComparableWith + TriviallyCopyable + ByteRepr>( a0: T1, a1: T1, ) -> T1 { @@ -91,7 +91,7 @@ fn f10, T2: CppEq + TriviallyCopyable + ByteRepr>( let mut __it = a0; __it.iter_inc(); while __it != a1 { - if !CppEq::equal(__write.iter_deref(), __it.iter_deref()) { + if !WeaklyEqualityComparableWith::equal(__write.iter_deref(), __it.iter_deref()) { __write.iter_inc(); __write.iter_deref().write(__it.iter_deref().read()); } diff --git a/rules/algorithm/tgt_unsafe.rs b/rules/algorithm/tgt_unsafe.rs index b13370b5d9..721baf36e6 100644 --- a/rules/algorithm/tgt_unsafe.rs +++ b/rules/algorithm/tgt_unsafe.rs @@ -32,9 +32,9 @@ unsafe fn f2, T2: UnsafeCppIterator, T3, T4: __out } -unsafe fn f3, T2, T3: PartialEq>(a0: T1, a1: T1, a2: T2) -> T1 { +unsafe fn f3, T2, T3: WeaklyEqualityComparableWithUnsafe>(a0: T1, a1: T1, a2: T2) -> T1 { let mut __it = a0; - while __it != a1 && *__it.iter_deref() != a2 { + while __it != a1 && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &a2) { __it.iter_inc(); } __it @@ -87,7 +87,7 @@ unsafe fn f9(a0: *mut T1, a1: *mut T1) { SwappableUnsafe::swap(&mut *__a, __b) } -unsafe fn f10, T2: PartialEq + Clone>(a0: T1, a1: T1) -> T1 { +unsafe fn f10, T2: WeaklyEqualityComparableWithUnsafe + Clone>(a0: T1, a1: T1) -> T1 { if a0 == a1 { a1 } else { @@ -95,7 +95,7 @@ unsafe fn f10, T2: PartialEq + Clone>(a0: T1, a1: let mut __it = a0; __it.iter_inc(); while __it != a1 { - if *__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(); } diff --git a/rules/iterator_category/shim.rs b/rules/iterator_category/shim.rs index 7fcaaeedd4..073fdc03c0 100644 --- a/rules/iterator_category/shim.rs +++ b/rules/iterator_category/shim.rs @@ -490,6 +490,16 @@ random_access_iterator!( std::ptr::null_mut() ); +crate::cmp::impl_weakly_equality_comparable_with!( + InputIterator, OutputIterator, ForwardIterator, + BidirectionalIterator, RandomAccessIterator, +); + +crate::cmp::impl_weakly_equality_comparable_with_unsafe!( + UnsafeInputIterator, UnsafeOutputIterator, UnsafeForwardIterator, + UnsafeBidirectionalIterator, UnsafeRandomAccessIterator, +); + pub trait IterStep: Clone + PartialEq { fn iter_step(&mut self); } diff --git a/rules/pair/tgt_refcount.rs b/rules/pair/tgt_refcount.rs index 50219d6641..8233935bf1 100644 --- a/rules/pair/tgt_refcount.rs +++ b/rules/pair/tgt_refcount.rs @@ -133,3 +133,7 @@ where { 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())) +} diff --git a/rules/pair/tgt_unsafe.rs b/rules/pair/tgt_unsafe.rs index e3fa54ce19..e45a4353ce 100644 --- a/rules/pair/tgt_unsafe.rs +++ b/rules/pair/tgt_unsafe.rs @@ -98,8 +98,8 @@ where &*a0.get::() } -fn f28(a0: (T1, T2), a1: (T1, T2)) -> bool { - a0 != a1 +unsafe fn f28, T2: WeaklyEqualityComparableWithUnsafe>(a0: (T1, T2), a1: (T1, T2)) -> bool { + !(WeaklyEqualityComparableWithUnsafe::equal(&a0.0, &a1.0) && WeaklyEqualityComparableWithUnsafe::equal(&a0.1, &a1.1)) } fn f29(a0: (T1, T2), a1: (T1, T2)) -> bool { 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 b58309a70c..c8f0e3813c 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 @@ -125,4 +125,7 @@ unsafe fn main_0() -> i32 { (unsafe { test_2() }); return 0; } -pub unsafe fn __cpp2rust_init_globals() {} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const global_2); + std::cell::LazyCell::force(&*&raw const detachable_3); +} From 8d68645745d80eff962e1499361d243857c10595 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 11:20:59 +0000 Subject: [PATCH 05/18] Update tests --- .../out/refcount/friend_operator.rs | 38 ++--- .../out/unsafe/friend_operator.rs | 36 +++-- .../expr.prim/out/unsafe/expr.prim.this.rs | 5 +- .../pairs/out/refcount/pairs.pair.rs | 22 ++- .../utilities/pairs/out/unsafe/pairs.pair.rs | 10 +- tests/unit/out/refcount/class.rs | 13 +- .../refcount/elidable_iterator_copy_cxx11.rs | 5 +- tests/unit/out/refcount/find.rs | 39 +++-- tests/unit/out/refcount/friend.rs | 37 +++-- tests/unit/out/refcount/map_key_copy_ctor.rs | 6 - tests/unit/out/refcount/map_key_identity.rs | 39 +++-- tests/unit/out/refcount/max.rs | 6 - .../refcount/operator_comparison_defaulted.rs | 92 ++++------- .../out/refcount/operator_comparison_free.rs | 63 ++++---- .../refcount/operator_comparison_member.rs | 15 +- .../refcount/operator_comparison_nonbool.rs | 28 ++-- .../operator_comparison_noncopyable.rs | 23 ++- tests/unit/out/refcount/operator_friend.rs | 144 +++++++++--------- tests/unit/out/refcount/operator_less_than.rs | 6 - tests/unit/out/refcount/operator_three_way.rs | 11 +- tests/unit/out/refcount/operator_traits.rs | 62 ++++---- tests/unit/out/refcount/size_t_ssize_t.rs | 5 +- tests/unit/out/refcount/sort_no_copy.rs | 30 ++-- .../refcount/unboxed_conditional_iterator.rs | 5 +- tests/unit/out/unsafe/class.rs | 10 +- .../unsafe/elidable_iterator_copy_cxx11.rs | 3 +- tests/unit/out/unsafe/find.rs | 29 ++-- tests/unit/out/unsafe/friend.rs | 34 +++-- tests/unit/out/unsafe/map_key_identity.rs | 18 ++- .../unsafe/operator_comparison_defaulted.rs | 60 +++++--- .../out/unsafe/operator_comparison_free.rs | 65 ++++---- .../out/unsafe/operator_comparison_member.rs | 12 +- .../out/unsafe/operator_comparison_nonbool.rs | 30 +++- .../unsafe/operator_comparison_noncopyable.rs | 22 +-- tests/unit/out/unsafe/operator_friend.rs | 138 +++++++++-------- tests/unit/out/unsafe/operator_three_way.rs | 8 +- tests/unit/out/unsafe/operator_traits.rs | 38 +++-- tests/unit/out/unsafe/size_t_ssize_t.rs | 4 +- tests/unit/out/unsafe/sort_no_copy.rs | 17 ++- .../unsafe/unboxed_conditional_iterator.rs | 7 +- 40 files changed, 681 insertions(+), 554 deletions(-) diff --git a/tests/multi-file/friend_operator/out/refcount/friend_operator.rs b/tests/multi-file/friend_operator/out/refcount/friend_operator.rs index 8a185bce62..e698d54594 100644 --- a/tests/multi-file/friend_operator/out/refcount/friend_operator.rs +++ b/tests/multi-file/friend_operator/out/refcount/friend_operator.rs @@ -33,33 +33,37 @@ fn main_0() -> i32 { let s1: Value = Rc::new(RefCell::new(S { a: 1, b: 2 })); let s2: Value = Rc::new(RefCell::new(S { a: 1, b: 2 })); let s3: Value = Rc::new(RefCell::new(S { a: 1, b: 3 })); - assert!(({ operator_eq_0(s1.as_pointer(), s2.as_pointer(),) })); - assert!(({ operator_ne_1(s1.as_pointer(), s3.as_pointer(),) })); - assert!(!({ operator_eq_0(s1.as_pointer(), s3.as_pointer(),) })); - assert!(({ operator_lt_2(s1.as_pointer(), s3.as_pointer(),) })); - assert!(!({ operator_lt_2(s3.as_pointer(), s1.as_pointer(),) })); - assert!((({ compare_3(s1.as_pointer(), s3.as_pointer(),) }) == -1_i32)); - assert!((({ compare_3(s3.as_pointer(), s1.as_pointer(),) }) == 1)); - assert!((({ compare_3(s1.as_pointer(), s2.as_pointer(),) }) == 0)); + assert!(({ WeaklyEqualityComparableWith::equal(s1.as_pointer(), s2.as_pointer(),) })); + assert!(({ operator_ne_0(s1.as_pointer(), s3.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(s1.as_pointer(), s3.as_pointer(),) })); + assert!(({ operator_lt_1(s1.as_pointer(), s3.as_pointer(),) })); + assert!(!({ operator_lt_1(s3.as_pointer(), s1.as_pointer(),) })); + assert!((({ compare_2(s1.as_pointer(), s3.as_pointer(),) }) == -1_i32)); + assert!((({ compare_2(s3.as_pointer(), s1.as_pointer(),) }) == 1)); + assert!((({ compare_2(s1.as_pointer(), s2.as_pointer(),) }) == 0)); return 0; } -pub fn operator_eq_0(x: Ptr, y: Ptr) -> bool { - return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }) - && ({ x.with(|__s| __s.b) } == { y.with(|__s| __s.b) }); +impl WeaklyEqualityComparableWith for S { + fn equal(this: Ptr, __rhs: Ptr) -> bool { + let x: Ptr = this.clone().clone(); + let y: Ptr = __rhs.clone(); + return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }) + && ({ x.with(|__s| __s.b) } == { y.with(|__s| __s.b) }); + } } -pub fn operator_ne_1(x: Ptr, y: Ptr) -> bool { - return !({ operator_eq_0((x).clone(), (y).clone()) }); +pub fn operator_ne_0(x: Ptr, y: Ptr) -> bool { + return !({ WeaklyEqualityComparableWith::equal((x).clone(), (y).clone()) }); } -pub fn operator_lt_2(x: Ptr, y: Ptr) -> bool { +pub fn operator_lt_1(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.a) } < { y.with(|__s| __s.a) }) || (({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }) && ({ x.with(|__s| __s.b) } < { y.with(|__s| __s.b) })); } -pub fn compare_3(x: Ptr, y: Ptr) -> i32 { - if ({ operator_lt_2((x).clone(), (y).clone()) }) { +pub fn compare_2(x: Ptr, y: Ptr) -> i32 { + if ({ operator_lt_1((x).clone(), (y).clone()) }) { return -1_i32; } - if ({ operator_lt_2((y).clone(), (x).clone()) }) { + if ({ operator_lt_1((y).clone(), (x).clone()) }) { return 1; } return 0; diff --git a/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs b/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs index f48036273a..3b24cd2a16 100644 --- a/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs +++ b/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs @@ -34,60 +34,64 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const S = &s1; - operator_eq_0(_x, &s2) + WeaklyEqualityComparableWithUnsafe::equal(&*(_x), &s2) }) ); assert!( (unsafe { let _x: *const S = &s1; - operator_ne_1(_x, &s3) + operator_ne_0(_x, &s3) }) ); assert!( !(unsafe { let _x: *const S = &s1; - operator_eq_0(_x, &s3) + WeaklyEqualityComparableWithUnsafe::equal(&*(_x), &s3) }) ); assert!( (unsafe { let _x: *const S = &s1; - operator_lt_2(_x, &s3) + operator_lt_1(_x, &s3) }) ); assert!( !(unsafe { let _x: *const S = &s3; - operator_lt_2(_x, &s1) + operator_lt_1(_x, &s1) }) ); - assert!(((unsafe { compare_3(&s1, &s3,) }) == (-1_i32))); - assert!(((unsafe { compare_3(&s3, &s1,) }) == (1))); - assert!(((unsafe { compare_3(&s1, &s2,) }) == (0))); + assert!(((unsafe { compare_2(&s1, &s3,) }) == (-1_i32))); + assert!(((unsafe { compare_2(&s3, &s1,) }) == (1))); + assert!(((unsafe { compare_2(&s1, &s2,) }) == (0))); return 0; } -pub unsafe fn operator_eq_0(x: *const S, y: *const S) -> bool { - return (((*x).a) == ((*y).a)) && (((*x).b) == ((*y).b)); +impl WeaklyEqualityComparableWithUnsafe for S { + unsafe fn equal(&self, __rhs: *const Self) -> bool { + let x: *const S = self as *const S; + let y: *const S = (&*__rhs) as *const S; + return (((*x).a) == ((*y).a)) && (((*x).b) == ((*y).b)); + } } -pub unsafe fn operator_ne_1(x: *const S, y: *const S) -> bool { +pub unsafe fn operator_ne_0(x: *const S, y: *const S) -> bool { return !(unsafe { let _x: *const S = x; - operator_eq_0(_x, y) + WeaklyEqualityComparableWithUnsafe::equal(&*(_x), y) }); } -pub unsafe fn operator_lt_2(x: *const S, y: *const S) -> bool { +pub unsafe fn operator_lt_1(x: *const S, y: *const S) -> bool { return (((*x).a) < ((*y).a)) || ((((*x).a) == ((*y).a)) && (((*x).b) < ((*y).b))); } -pub unsafe fn compare_3(x: *const S, y: *const S) -> i32 { +pub unsafe fn compare_2(x: *const S, y: *const S) -> i32 { if (unsafe { let _x: *const S = x; - operator_lt_2(_x, y) + operator_lt_1(_x, y) }) { return -1_i32; } if (unsafe { let _x: *const S = y; - operator_lt_2(_x, x) + operator_lt_1(_x, x) }) { return 1; } 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 c8f0e3813c..b58309a70c 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 @@ -125,7 +125,4 @@ unsafe fn main_0() -> i32 { (unsafe { test_2() }); return 0; } -pub unsafe fn __cpp2rust_init_globals() { - std::cell::LazyCell::force(&*&raw const global_2); - std::cell::LazyCell::force(&*&raw const detachable_3); -} +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 4dd51e9cb0..ed07a6ef03 100644 --- a/tests/std/utilities/pairs/out/refcount/pairs.pair.rs +++ b/tests/std/utilities/pairs/out/refcount/pairs.pair.rs @@ -127,8 +127,26 @@ pub fn test_4() { Rc::new(RefCell::new(2)), Rc::new(RefCell::new(0)), ))); - assert!((*a.borrow()) != (*b.borrow())); - assert!(({ !((*a.borrow()) != (*a.borrow())) })); + assert!( + !(WeaklyEqualityComparableWith::equal( + (*a.borrow()).0.as_pointer(), + (*b.borrow()).0.as_pointer() + ) && WeaklyEqualityComparableWith::equal( + (*a.borrow()).1.as_pointer(), + (*b.borrow()).1.as_pointer() + )) + ); + assert!( + ({ + !(!(WeaklyEqualityComparableWith::equal( + (*a.borrow()).0.as_pointer(), + (*a.borrow()).0.as_pointer(), + ) && WeaklyEqualityComparableWith::equal( + (*a.borrow()).1.as_pointer(), + (*a.borrow()).1.as_pointer(), + ))) + }) + ); assert!((*a.borrow()) < (*b.borrow())); assert!(({ !((*b.borrow()) < (*a.borrow())) })); assert!((*b.borrow()) < (*c.borrow())); diff --git a/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs b/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs index c78e30a131..c109916ae7 100644 --- a/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs +++ b/tests/std/utilities/pairs/out/unsafe/pairs.pair.rs @@ -139,8 +139,14 @@ pub unsafe fn test_4() { let mut a: (i32, i32) = (1, 2); let mut b: (i32, i32) = (1, 3); let mut c: (i32, i32) = (2, 0); - assert!(a != b); - assert!(!(a != a)); + assert!( + !(WeaklyEqualityComparableWithUnsafe::equal(&a.0, &b.0) + && WeaklyEqualityComparableWithUnsafe::equal(&a.1, &b.1)) + ); + assert!( + !(!(WeaklyEqualityComparableWithUnsafe::equal(&a.0, &a.0) + && WeaklyEqualityComparableWithUnsafe::equal(&a.1, &a.1))) + ); assert!(a < b); assert!(!(b < a)); assert!(b < c); diff --git a/tests/unit/out/refcount/class.rs b/tests/unit/out/refcount/class.rs index b74e57284a..31efb77c4d 100644 --- a/tests/unit/out/refcount/class.rs +++ b/tests/unit/out/refcount/class.rs @@ -101,18 +101,15 @@ impl Counter { }); return this.with(|__s| __s.v); } - pub fn operator_eq(this: Ptr, o: Ptr) -> bool { +} +impl WeaklyEqualityComparableWith for Counter { + fn equal(this: Ptr, o: Ptr) -> bool { field!(this, calls).with_mut(|__v| { __v.prefix_inc(); }); return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); } } -impl CppEq for Counter { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Counter::operator_eq(__lhs.clone(), __rhs.clone()) - } -} #[derive( Copy, Clone, @@ -199,8 +196,8 @@ fn main_0() -> i32 { assert!((({ Counter::Get(c1.as_pointer(),) }) == 3)); assert!((({ Counter::Get(c2.as_pointer(),) }) == 3)); assert!((({ Counter::Get((pc).clone(),) }) == 3)); - assert!(({ Counter::operator_eq(c1.as_pointer(), c2.as_pointer(),) })); - assert!(({ Counter::operator_eq(c2.as_pointer(), c1.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(c1.as_pointer(), c2.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(c2.as_pointer(), c1.as_pointer(),) })); assert!(({ (*c1.borrow()).calls } == 3)); assert!(({ (*c2.borrow()).calls } == 2)); let t: Value = Rc::new(RefCell::new(Tally { calls: 0 })); diff --git a/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs b/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs index 8eb3283d6f..91c0a3793a 100644 --- a/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs +++ b/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs @@ -28,7 +28,10 @@ fn main_0() -> i32 { let mut __tmp_3 = { v.decay().end() }; let mut __it = (__tmp_2).clone(); while __it != __tmp_3 - && !CppEq::equal(__it.iter_deref(), __tmp_4.as_pointer().clone()) + && !WeaklyEqualityComparableWith::equal( + __it.iter_deref(), + __tmp_4.as_pointer().clone(), + ) { __it.iter_inc(); } diff --git a/tests/unit/out/refcount/find.rs b/tests/unit/out/refcount/find.rs index 504af54ae4..d0c17ab502 100644 --- a/tests/unit/out/refcount/find.rs +++ b/tests/unit/out/refcount/find.rs @@ -23,16 +23,11 @@ pub struct P { #[offset(0)] pub x: i32, } -impl P { - pub fn operator_eq(this: Ptr, o: Ptr

) -> bool { +impl WeaklyEqualityComparableWith for P { + fn equal(this: Ptr, o: Ptr

) -> bool { return ({ this.with(|__s| __s.x) } == { o.with(|__s| __s.x) }); } } -impl CppEq for P { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - P::operator_eq(__lhs.clone(), __rhs.clone()) - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -60,7 +55,10 @@ fn main_0() -> i32 { let mut __tmp_3 = { (*v_end.borrow()).clone() }; let mut __it = ({ (*v_begin.borrow()).clone() }); while __it != __tmp_3 - && !CppEq::equal(__it.iter_deref(), __tmp_4.as_pointer().clone()) + && !WeaklyEqualityComparableWith::equal( + __it.iter_deref(), + __tmp_4.as_pointer().clone(), + ) { __it.iter_inc(); } @@ -106,7 +104,10 @@ fn main_0() -> i32 { let mut __tmp_9 = { v.decay().begin() }; let mut __it = (__tmp_8).clone(); while __it != __tmp_9 - && !CppEq::equal(__it.iter_deref(), __tmp_10.as_pointer().clone()) + && !WeaklyEqualityComparableWith::equal( + __it.iter_deref(), + __tmp_10.as_pointer().clone(), + ) { __it.iter_inc(); } @@ -123,7 +124,10 @@ fn main_0() -> i32 { let mut __tmp_12 = { w.decay().end() }; let mut __it = (__tmp_11).clone(); while __it != __tmp_12 - && !CppEq::equal(__it.iter_deref(), __tmp_13.as_pointer().clone()) + && !WeaklyEqualityComparableWith::equal( + __it.iter_deref(), + __tmp_13.as_pointer().clone(), + ) { __it.iter_inc(); } @@ -139,7 +143,10 @@ fn main_0() -> i32 { let mut __tmp_15 = { w.decay().end() }; let mut __it = (__tmp_14).clone(); while __it != __tmp_15 - && !CppEq::equal(__it.iter_deref(), __tmp_16.as_pointer().clone()) + && !WeaklyEqualityComparableWith::equal( + __it.iter_deref(), + __tmp_16.as_pointer().clone(), + ) { __it.iter_inc(); } @@ -155,7 +162,10 @@ fn main_0() -> i32 { let mut __tmp_18 = { w.decay().begin().iter_add(4_isize) }; let mut __it = (__tmp_17).clone(); while __it != __tmp_18 - && !CppEq::equal(__it.iter_deref(), __tmp_19.as_pointer().clone()) + && !WeaklyEqualityComparableWith::equal( + __it.iter_deref(), + __tmp_19.as_pointer().clone(), + ) { __it.iter_inc(); } @@ -176,7 +186,10 @@ fn main_0() -> i32 { let mut __tmp_21 = { p.decay().end() }; let mut __it = (__tmp_20).clone(); while __it != __tmp_21 - && !CppEq::equal(__it.iter_deref(), (__tmp_22.as_pointer()).clone()) + && !WeaklyEqualityComparableWith::equal( + __it.iter_deref(), + (__tmp_22.as_pointer()).clone(), + ) { __it.iter_inc(); } diff --git a/tests/unit/out/refcount/friend.rs b/tests/unit/out/refcount/friend.rs index c9e3cff5e4..31aa5fad2c 100644 --- a/tests/unit/out/refcount/friend.rs +++ b/tests/unit/out/refcount/friend.rs @@ -9,13 +9,17 @@ use std::rc::{Rc, Weak}; pub fn get_0(v: Ptr) -> i32 { return v.with(|__s| __s.x); } -pub fn operator_eq_1(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.x) } == { b.with(|__s| __s.x) }); +impl WeaklyEqualityComparableWith for V { + fn equal(this: Ptr, __rhs: Ptr) -> bool { + let a: Ptr = this.clone().clone(); + let b: Ptr = __rhs.clone(); + return ({ a.with(|__s| __s.x) } == { b.with(|__s| __s.x) }); + } } -pub fn scaled_2(v: Ptr, mut k: i32) -> i32 { +pub fn scaled_1(v: Ptr, mut k: i32) -> i32 { return ({ v.with(|__s| __s.x) } * { k }); } -pub fn scaled_3(v: Ptr, mut k: f64) -> f64 { +pub fn scaled_2(v: Ptr, mut k: f64) -> f64 { return ({ (v.with(|__s| __s.x) as f64) } * { k }); } #[derive( @@ -35,12 +39,7 @@ pub struct V { #[offset(0)] pub x: i32, } -impl CppEq for V { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_1(__lhs.clone(), __rhs.clone()) - } -} -pub fn get_4(w: Ptr) -> i32 { +pub fn get_3(w: Ptr) -> i32 { return w.with(|__s| __s.x); } #[derive( @@ -60,7 +59,7 @@ pub struct W_int_ { #[offset(0)] pub x: i32, } -pub fn get_5(w: Ptr) -> i64 { +pub fn get_4(w: Ptr) -> i64 { return w.with(|__s| __s.x); } #[derive( @@ -97,7 +96,7 @@ pub struct D { #[offset(0)] pub x: i32, } -pub fn declared_then_defined_6(d: Ptr) -> i32 { +pub fn declared_then_defined_5(d: Ptr) -> i32 { return (d.with(|__s| __s.x) + 1); } pub fn main() { @@ -109,16 +108,16 @@ fn main_0() -> i32 { let b: Value = Rc::new(RefCell::new(V { x: 3 })); let c: Value = Rc::new(RefCell::new(V { x: 4 })); assert!((({ get_0(a.as_pointer(),) }) == 3)); - assert!(({ operator_eq_1(a.as_pointer(), b.as_pointer(),) })); - assert!(!({ operator_eq_1(a.as_pointer(), c.as_pointer(),) })); - assert!((({ scaled_2(c.as_pointer(), 2,) }) == 8)); - assert!((({ scaled_3(c.as_pointer(), 1.5_f64,) }) == 6_f64)); + assert!(({ WeaklyEqualityComparableWith::equal(a.as_pointer(), b.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(a.as_pointer(), c.as_pointer(),) })); + assert!((({ scaled_1(c.as_pointer(), 2,) }) == 8)); + assert!((({ scaled_2(c.as_pointer(), 1.5_f64,) }) == 6_f64)); let wi: Value = Rc::new(RefCell::new(W_int_ { x: 5 })); let wl: Value = Rc::new(RefCell::new(W_long_ { x: 6_i64 })); - assert!((({ get_4(wi.as_pointer(),) }) == 5)); - assert!((({ get_5(wl.as_pointer(),) }) == 6_i64)); + assert!((({ get_3(wi.as_pointer(),) }) == 5)); + assert!((({ get_4(wl.as_pointer(),) }) == 6_i64)); let d: Value = Rc::new(RefCell::new(D { x: 7 })); - assert!((({ declared_then_defined_6(d.as_pointer(),) }) == 8)); + assert!((({ declared_then_defined_5(d.as_pointer(),) }) == 8)); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/map_key_copy_ctor.rs b/tests/unit/out/refcount/map_key_copy_ctor.rs index 23a1742f03..73c930ee56 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -49,12 +49,6 @@ impl CppLess for Key { Key::operator_lt(__lhs.clone(), __rhs.clone()) } } -impl CppEq for Key { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - !(Key::operator_lt(__lhs.clone(), __rhs.clone())) - && !(Key::operator_lt(__rhs.clone(), __lhs.clone())) - } -} pub fn make_key_3(__return: Ptr, mut k: i32) { (*made_2.with(Value::clone).borrow_mut()).prefix_inc(); Key::construct(__return.clone(), k); diff --git a/tests/unit/out/refcount/map_key_identity.rs b/tests/unit/out/refcount/map_key_identity.rs index 6576af11ae..6be7a2a6af 100644 --- a/tests/unit/out/refcount/map_key_identity.rs +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -33,16 +33,15 @@ impl CppLess for Key { operator_lt_1(__lhs.clone(), __rhs.clone()) } } -impl CppEq for Key { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_2(__lhs.clone(), __rhs.clone()) - } -} pub fn operator_lt_1(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.order) } < { b.with(|__s| __s.order) }); } -pub fn operator_eq_2(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.identity) } == { b.with(|__s| __s.identity) }); +impl WeaklyEqualityComparableWith for Key { + fn equal(this: Ptr, __rhs: Ptr) -> bool { + let a: Ptr = this.clone().clone(); + let b: Ptr = __rhs.clone(); + return ({ a.with(|__s| __s.identity) } == { b.with(|__s| __s.identity) }); + } } #[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] #[byte_size(4)] @@ -82,7 +81,11 @@ fn main_0() -> i32 { identity: 7, })); ok = { - ((ok as i32) & ((operator_eq_2(distinct_a.as_pointer(), distinct_b.as_pointer())) as i32)) + ((ok as i32) + & ((WeaklyEqualityComparableWith::equal( + distinct_a.as_pointer(), + distinct_b.as_pointer(), + )) as i32)) != 0 }; let distinct: Value, Value)>> = Rc::new(RefCell::new(Map::new())); @@ -157,7 +160,11 @@ fn main_0() -> i32 { != 0 }; ok = { - ((ok as i32) & ((operator_eq_2(distinct_a.as_pointer(), distinct_b.as_pointer())) as i32)) + ((ok as i32) + & ((WeaklyEqualityComparableWith::equal( + distinct_a.as_pointer(), + distinct_b.as_pointer(), + )) as i32)) != 0 }; let mut distinct_count: usize = 0_usize; @@ -200,7 +207,12 @@ fn main_0() -> i32 { })); ok = { ((ok as i32) - & (!({ operator_eq_2(equivalent_a.as_pointer(), equivalent_b.as_pointer()) }) as i32)) + & (!({ + WeaklyEqualityComparableWith::equal( + equivalent_a.as_pointer(), + equivalent_b.as_pointer(), + ) + }) as i32)) != 0 }; let equivalent: Value, Value)>> = @@ -300,7 +312,12 @@ fn main_0() -> i32 { } ok = { ((ok as i32) - & (!({ operator_eq_2(equivalent_a.as_pointer(), equivalent_b.as_pointer()) }) as i32)) + & (!({ + WeaklyEqualityComparableWith::equal( + equivalent_a.as_pointer(), + equivalent_b.as_pointer(), + ) + }) as i32)) != 0 }; let later_key: Value = Rc::new(RefCell::new(Key { diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index fdd9e50724..9458f5bba3 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -56,12 +56,6 @@ impl CppLess for Bag { operator_lt_4(__lhs.clone(), __rhs.clone()) } } -impl CppEq for Bag { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - !(operator_lt_4(__lhs.clone(), __rhs.clone())) - && !(operator_lt_4(__rhs.clone(), __lhs.clone())) - } -} pub fn operator_lt_4(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.n) } < { b.with(|__s| __s.n) }); } diff --git a/tests/unit/out/refcount/operator_comparison_defaulted.rs b/tests/unit/out/refcount/operator_comparison_defaulted.rs index 35144fd896..fa1d4ea994 100644 --- a/tests/unit/out/refcount/operator_comparison_defaulted.rs +++ b/tests/unit/out/refcount/operator_comparison_defaulted.rs @@ -25,17 +25,12 @@ pub struct Eq { #[offset(4)] pub b: i32, } -impl Eq { - pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { +impl WeaklyEqualityComparableWith for Eq { + fn equal(this: Ptr, _a0: Ptr) -> bool { return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }) && ({ this.with(|__s| __s.b) } == { _a0.with(|__s| __s.b) }); } } -impl CppEq for Eq { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Eq::operator_eq(__lhs.clone(), __rhs.clone()) - } -} #[derive( Copy, Clone, @@ -77,7 +72,9 @@ impl Cmp { } return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } - pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { +} +impl WeaklyEqualityComparableWith for Cmp { + fn equal(this: Ptr, _a0: Ptr) -> bool { return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }) && ({ this.with(|__s| __s.b) } == { _a0.with(|__s| __s.b) }); } @@ -87,11 +84,6 @@ impl CppLess for Cmp { Cmp::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } -impl CppEq for Cmp { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Cmp::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal - } -} #[derive( Copy, Clone, @@ -110,9 +102,6 @@ pub struct Both { pub a: i32, } impl Both { - pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); - } pub fn operator_cmp(this: Ptr, _a0: Ptr) -> std::cmp::Ordering { { let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( @@ -126,16 +115,16 @@ impl Both { return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } } +impl WeaklyEqualityComparableWith for Both { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); + } +} impl CppLess for Both { fn less(__lhs: Ptr, __rhs: Ptr) -> bool { Both::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } -impl CppEq for Both { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Both::operator_eq(__lhs.clone(), __rhs.clone()) - } -} #[derive( Copy, Clone, @@ -172,11 +161,6 @@ impl CppLess for OrdOnly { OrdOnly::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } -impl CppEq for OrdOnly { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - OrdOnly::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal - } -} #[derive( Copy, Clone, @@ -207,7 +191,9 @@ impl Inner { } return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } - pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { +} +impl WeaklyEqualityComparableWith for Inner { + fn equal(this: Ptr, _a0: Ptr) -> bool { return ({ this.with(|__s| __s.x) } == { _a0.with(|__s| __s.x) }); } } @@ -216,11 +202,6 @@ impl CppLess for Inner { Inner::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } -impl CppEq for Inner { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Inner::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal - } -} #[derive( Copy, Clone, @@ -262,8 +243,10 @@ impl Outer { } return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } - pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { - return ({ Inner::operator_eq(field_ptr!(this, i), field_ptr!(_a0, i)) }) +} +impl WeaklyEqualityComparableWith for Outer { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ WeaklyEqualityComparableWith::equal(field_ptr!(this, i), field_ptr!(_a0, i)) }) && ({ this.with(|__s| __s.y) } == { _a0.with(|__s| __s.y) }); } } @@ -272,11 +255,6 @@ impl CppLess for Outer { Outer::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } -impl CppEq for Outer { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Outer::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal - } -} #[derive( Copy, Clone, @@ -295,11 +273,8 @@ pub struct Secondary { pub a: i32, } impl Secondary { - pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); - } pub fn operator_ne(this: Ptr, _a0: Ptr) -> bool { - return !({ Secondary::operator_eq((this).clone(), (_a0).clone()) }); + return !({ WeaklyEqualityComparableWith::equal((this).clone(), (_a0).clone()) }); } pub fn operator_cmp(this: Ptr, _a0: Ptr) -> std::cmp::Ordering { { @@ -322,16 +297,16 @@ impl Secondary { != std::cmp::Ordering::Less; } } +impl WeaklyEqualityComparableWith for Secondary { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); + } +} impl CppLess for Secondary { fn less(__lhs: Ptr, __rhs: Ptr) -> bool { Secondary::operator_lt(__lhs.clone(), __rhs.clone()) } } -impl CppEq for Secondary { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Secondary::operator_eq(__lhs.clone(), __rhs.clone()) - } -} #[derive( Clone, Record, @@ -362,7 +337,9 @@ impl PtrMember { } return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } - pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { +} +impl WeaklyEqualityComparableWith for PtrMember { + fn equal(this: Ptr, _a0: Ptr) -> bool { return ({ this.with(|__s| __s.p.clone()) } == { _a0.with(|__s| __s.p.clone()) }); } } @@ -371,11 +348,6 @@ impl CppLess for PtrMember { PtrMember::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } -impl CppEq for PtrMember { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - PtrMember::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -384,8 +356,8 @@ fn main_0() -> i32 { let e1: Value = Rc::new(RefCell::new(Eq { a: 1, b: 2 })); let e2: Value = Rc::new(RefCell::new(Eq { a: 1, b: 2 })); let e3: Value = Rc::new(RefCell::new(Eq { a: 1, b: 3 })); - assert!(({ Eq::operator_eq(e1.as_pointer(), e2.as_pointer(),) })); - assert!(!({ Eq::operator_eq(e1.as_pointer(), e3.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(e1.as_pointer(), e2.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(e1.as_pointer(), e3.as_pointer(),) })); let c1: Value = Rc::new(RefCell::new(Cmp { a: 1, b: 2 })); let c2: Value = Rc::new(RefCell::new(Cmp { a: 1, b: 3 })); let c3: Value = Rc::new(RefCell::new(Cmp { a: 2, b: 0 })); @@ -394,7 +366,7 @@ fn main_0() -> i32 { assert!( ({ Cmp::operator_cmp(c3.as_pointer(), c4.as_pointer(),) }) == std::cmp::Ordering::Greater ); - assert!(({ Cmp::operator_eq(c1.as_pointer(), c1.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(c1.as_pointer(), c1.as_pointer(),) })); assert!( ({ Cmp::operator_cmp(c1.as_pointer(), c2.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_less().upgrade().deref()) }) @@ -404,7 +376,7 @@ fn main_0() -> i32 { assert!( ({ Both::operator_cmp(b1.as_pointer(), b2.as_pointer(),) }) == std::cmp::Ordering::Less ); - assert!(({ Both::operator_eq(b2.as_pointer(), b2.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(b2.as_pointer(), b2.as_pointer(),) })); let o1: Value = Rc::new(RefCell::new(OrdOnly { a: 1 })); let o2: Value = Rc::new(RefCell::new(OrdOnly { a: 2 })); assert!( @@ -429,7 +401,7 @@ fn main_0() -> i32 { assert!( ({ Outer::operator_cmp(x1.as_pointer(), x2.as_pointer(),) }) == std::cmp::Ordering::Less ); - assert!(({ Outer::operator_eq(x1.as_pointer(), x3.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(x1.as_pointer(), x3.as_pointer(),) })); assert!( ({ Outer::operator_cmp(x2.as_pointer(), x1.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_greater().upgrade().deref()) }) @@ -450,7 +422,7 @@ fn main_0() -> i32 { ({ PtrMember::operator_cmp(p1.as_pointer(), p2.as_pointer(),) }) == std::cmp::Ordering::Less ); - assert!(({ PtrMember::operator_eq(p1.as_pointer(), p3.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(p1.as_pointer(), p3.as_pointer(),) })); assert!( ({ PtrMember::operator_cmp(p2.as_pointer(), p1.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_greater().upgrade().deref()) }) diff --git a/tests/unit/out/refcount/operator_comparison_free.rs b/tests/unit/out/refcount/operator_comparison_free.rs index a3cce0c780..1392a64512 100644 --- a/tests/unit/out/refcount/operator_comparison_free.rs +++ b/tests/unit/out/refcount/operator_comparison_free.rs @@ -28,33 +28,32 @@ impl CppLess for S { operator_lt_0(__lhs.clone(), __rhs.clone()) } } -impl CppEq for S { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_1(__lhs.clone(), __rhs.clone()) +impl WeaklyEqualityComparableWith for S { + fn equal(this: Ptr, __rhs: Ptr) -> bool { + let a: Ptr = this.clone().clone(); + let b: Ptr = __rhs.clone(); + return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); } } -pub fn operator_eq_1(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); -} -pub fn operator_ne_2(a: Ptr, b: Ptr) -> bool { +pub fn operator_ne_1(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } != { b.with(|__s| __s.v) }); } pub fn operator_lt_0(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } < { b.with(|__s| __s.v) }); } -pub fn operator_gt_3(a: Ptr, b: Ptr) -> bool { +pub fn operator_gt_2(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } > { b.with(|__s| __s.v) }); } -pub fn operator_le_4(a: Ptr, b: Ptr) -> bool { +pub fn operator_le_3(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } <= { b.with(|__s| __s.v) }); } -pub fn operator_ge_5(a: Ptr, b: Ptr) -> bool { +pub fn operator_ge_4(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } >= { b.with(|__s| __s.v) }); } -pub fn operator_lt_6(a: Ptr, mut b: i32) -> bool { +pub fn operator_lt_5(a: Ptr, mut b: i32) -> bool { return ({ a.with(|__s| __s.v) } < { b }); } -pub fn operator_lt_7(mut a: i32, b: Ptr) -> bool { +pub fn operator_lt_6(mut a: i32, b: Ptr) -> bool { return ({ a } < { b.with(|__s| __s.v) }); } #[derive( @@ -76,24 +75,24 @@ pub struct V { } impl CppLess for V { fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_8(__lhs.read(), __rhs.read()) + operator_lt_7(__lhs.read(), __rhs.read()) } } -impl CppEq for V { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_9(__lhs.read(), __rhs.read()) +impl WeaklyEqualityComparableWith for V { + fn equal(this: Ptr, __rhs: Ptr) -> bool { + operator_eq_8(this.clone().read(), __rhs.read()) } } -pub fn operator_eq_9(mut a: V, mut b: V) -> bool { +pub fn operator_eq_8(mut a: V, mut b: V) -> bool { return (a.v == b.v); } -pub fn operator_ne_10(mut a: V, mut b: V) -> bool { +pub fn operator_ne_9(mut a: V, mut b: V) -> bool { return (a.v != b.v); } -pub fn operator_lt_8(mut a: V, mut b: V) -> bool { +pub fn operator_lt_7(mut a: V, mut b: V) -> bool { return (a.v < b.v); } -pub fn operator_gt_11(mut a: V, mut b: V) -> bool { +pub fn operator_gt_10(mut a: V, mut b: V) -> bool { return (a.v > b.v); } pub fn main() { @@ -104,23 +103,23 @@ fn main_0() -> i32 { let mut x: V = V { v: 1 }; let mut y: V = V { v: 2 }; let mut z: V = V { v: 1 }; - assert!(({ operator_eq_9(x, z,) })); - assert!(({ operator_ne_10(x, y,) })); - assert!(({ operator_lt_8(x, y,) })); - assert!(({ operator_gt_11(y, x,) })); - assert!(!({ operator_lt_8(y, x,) })); + assert!(({ operator_eq_8(x, z,) })); + assert!(({ operator_ne_9(x, y,) })); + assert!(({ operator_lt_7(x, y,) })); + assert!(({ operator_gt_10(y, x,) })); + assert!(!({ operator_lt_7(y, x,) })); let a: Value = Rc::new(RefCell::new(S { v: 1 })); let b: Value = Rc::new(RefCell::new(S { v: 2 })); let c: Value = Rc::new(RefCell::new(S { v: 1 })); - assert!(({ operator_eq_1(a.as_pointer(), c.as_pointer(),) })); - assert!(({ operator_ne_2(a.as_pointer(), b.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(a.as_pointer(), c.as_pointer(),) })); + assert!(({ operator_ne_1(a.as_pointer(), b.as_pointer(),) })); assert!(({ operator_lt_0(a.as_pointer(), b.as_pointer(),) })); - assert!(({ operator_gt_3(b.as_pointer(), a.as_pointer(),) })); - assert!(({ operator_le_4(a.as_pointer(), c.as_pointer(),) })); - assert!(({ operator_ge_5(a.as_pointer(), c.as_pointer(),) })); + assert!(({ operator_gt_2(b.as_pointer(), a.as_pointer(),) })); + assert!(({ operator_le_3(a.as_pointer(), c.as_pointer(),) })); + assert!(({ operator_ge_4(a.as_pointer(), c.as_pointer(),) })); assert!(!({ operator_lt_0(b.as_pointer(), a.as_pointer(),) })); - assert!(({ operator_lt_6(a.as_pointer(), 5,) })); - assert!(({ operator_lt_7(0, a.as_pointer(),) })); + assert!(({ operator_lt_5(a.as_pointer(), 5,) })); + assert!(({ operator_lt_6(0, a.as_pointer(),) })); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_comparison_member.rs b/tests/unit/out/refcount/operator_comparison_member.rs index a0088dd538..0957dcc178 100644 --- a/tests/unit/out/refcount/operator_comparison_member.rs +++ b/tests/unit/out/refcount/operator_comparison_member.rs @@ -24,9 +24,6 @@ pub struct S { pub v: i32, } impl S { - pub fn operator_eq(this: Ptr, o: Ptr) -> bool { - return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } pub fn operator_ne(this: Ptr, o: Ptr) -> bool { return ({ this.with(|__s| __s.v) } != { o.with(|__s| __s.v) }); } @@ -46,16 +43,16 @@ impl S { return (this.with(|__s| __s.v) < o); } } +impl WeaklyEqualityComparableWith for S { + fn equal(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } +} impl CppLess for S { fn less(__lhs: Ptr, __rhs: Ptr) -> bool { S::operator_lt_3(__lhs.clone(), __rhs.clone()) } } -impl CppEq for S { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - S::operator_eq(__lhs.clone(), __rhs.clone()) - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -64,7 +61,7 @@ fn main_0() -> i32 { let a: Value = Rc::new(RefCell::new(S { v: 1 })); let b: Value = Rc::new(RefCell::new(S { v: 2 })); let c: Value = Rc::new(RefCell::new(S { v: 1 })); - assert!(({ S::operator_eq(a.as_pointer(), c.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(a.as_pointer(), c.as_pointer(),) })); assert!(({ S::operator_ne(a.as_pointer(), b.as_pointer(),) })); assert!(({ S::operator_lt_3(a.as_pointer(), b.as_pointer(),) })); assert!(({ S::operator_gt(b.as_pointer(), a.as_pointer(),) })); diff --git a/tests/unit/out/refcount/operator_comparison_nonbool.rs b/tests/unit/out/refcount/operator_comparison_nonbool.rs index 1229dd8525..d50fd35a6f 100644 --- a/tests/unit/out/refcount/operator_comparison_nonbool.rs +++ b/tests/unit/out/refcount/operator_comparison_nonbool.rs @@ -28,9 +28,9 @@ impl CppLess for X { ((operator_lt_0(__lhs.read(), __rhs.read())) != 0) } } -impl CppEq for X { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - ((operator_eq_1(__lhs.read(), __rhs.read())) != 0) +impl WeaklyEqualityComparableWith for X { + fn equal(this: Ptr, __rhs: Ptr) -> bool { + ((operator_eq_1(this.clone().read(), __rhs.read())) != 0) } } pub fn operator_eq_1(mut a: X, mut b: X) -> i32 { @@ -135,9 +135,9 @@ impl CppLess for Mixed { ((Mixed::operator_lt(__lhs.clone(), __rhs.clone())) != 0) } } -impl CppEq for Mixed { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - ((Mixed::operator_eq(__lhs.clone(), __rhs.clone())) != 0) +impl WeaklyEqualityComparableWith for Mixed { + fn equal(this: Ptr, __rhs: Ptr) -> bool { + ((Mixed::operator_eq(this.clone().clone(), __rhs.clone())) != 0) } } #[derive( @@ -192,10 +192,10 @@ impl CppLess for Boolish { } } } -impl CppEq for Boolish { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { +impl WeaklyEqualityComparableWith for Boolish { + fn equal(this: Ptr, __rhs: Ptr) -> bool { { - let __cmp = operator_eq_7(__lhs.read(), __rhs.read()); + let __cmp = operator_eq_7(this.clone().read(), __rhs.read()); MyBool::to_bool(Rc::new(RefCell::new(__cmp)).as_pointer()) } } @@ -269,10 +269,10 @@ impl RefInt { return ref_true_8.with(|v| v.as_pointer()); } } -impl CppEq for RefInt { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { +impl WeaklyEqualityComparableWith for RefInt { + fn equal(this: Ptr, __rhs: Ptr) -> bool { { - let __cmp = RefInt::operator_eq(__lhs.clone(), __rhs.clone()); + let __cmp = RefInt::operator_eq(this.clone().clone(), __rhs.clone()); RefBool::to_bool(__cmp.clone()) } } @@ -370,7 +370,9 @@ fn main_0() -> i32 { ({ let mut __tmp_3 = { ris.decay().offset((2) as isize) }; let mut __it = ris.decay(); - while __it != __tmp_3 && !CppEq::equal(__it.iter_deref(), ri2.as_pointer().clone()) { + while __it != __tmp_3 + && !WeaklyEqualityComparableWith::equal(__it.iter_deref(), ri2.as_pointer().clone()) + { __it.iter_inc(); } __it diff --git a/tests/unit/out/refcount/operator_comparison_noncopyable.rs b/tests/unit/out/refcount/operator_comparison_noncopyable.rs index 7edce8d200..8deb9e39be 100644 --- a/tests/unit/out/refcount/operator_comparison_noncopyable.rs +++ b/tests/unit/out/refcount/operator_comparison_noncopyable.rs @@ -6,10 +6,14 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn operator_eq_0(x: Ptr, y: Ptr) -> bool { - return ({ x.with(|__s| __s.data_) } == { y.with(|__s| __s.data_) }); +impl WeaklyEqualityComparableWith for S { + fn equal(this: Ptr, __rhs: Ptr) -> bool { + let x: Ptr = this.clone().clone(); + let y: Ptr = __rhs.clone(); + return ({ x.with(|__s| __s.data_) } == { y.with(|__s| __s.data_) }); + } } -pub fn operator_lt_1(x: Ptr, y: Ptr) -> bool { +pub fn operator_lt_0(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.data_) } < { y.with(|__s| __s.data_) }); } #[derive( @@ -36,12 +40,7 @@ impl S { } impl CppLess for S { fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_1(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for S { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_0(__lhs.clone(), __rhs.clone()) + operator_lt_0(__lhs.clone(), __rhs.clone()) } } pub fn main() { @@ -52,9 +51,9 @@ fn main_0() -> i32 { object!(a, S(1)); object!(b, S(2)); object!(c, S(1)); - assert!(({ operator_eq_0(a.as_pointer(), c.as_pointer(),) })); - assert!(({ operator_lt_1(a.as_pointer(), b.as_pointer(),) })); - assert!(!({ operator_lt_1(b.as_pointer(), a.as_pointer(),) })); + 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(),) })); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_friend.rs b/tests/unit/out/refcount/operator_friend.rs index 7355fb70d4..18990fd056 100644 --- a/tests/unit/out/refcount/operator_friend.rs +++ b/tests/unit/out/refcount/operator_friend.rs @@ -6,9 +6,13 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn operator_eq_0(_a0: Ptr, _a1: Ptr) -> bool { - return ({ _a0.with(|__s| __s.a) } == { _a1.with(|__s| __s.a) }) - && ({ _a0.with(|__s| __s.b) } == { _a1.with(|__s| __s.b) }); +impl WeaklyEqualityComparableWith for Defaulted { + fn equal(this: Ptr, __rhs: Ptr) -> bool { + let _a0: Ptr = this.clone().clone(); + let _a1: Ptr = __rhs.clone(); + return ({ _a0.with(|__s| __s.a) } == { _a1.with(|__s| __s.a) }) + && ({ _a0.with(|__s| __s.b) } == { _a1.with(|__s| __s.b) }); + } } #[derive( Copy, @@ -29,12 +33,7 @@ pub struct Defaulted { #[offset(4)] pub b: i32, } -impl CppEq for Defaulted { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_0(__lhs.clone(), __rhs.clone()) - } -} -pub fn operator_cmp_1(_a0: Ptr, _a1: Ptr) -> std::cmp::Ordering { +pub fn operator_cmp_0(_a0: Ptr, _a1: Ptr) -> std::cmp::Ordering { { let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( &(_a0.with(|__s| __s.a)), @@ -46,8 +45,12 @@ pub fn operator_cmp_1(_a0: Ptr, _a1: Ptr) -> std::cm } return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } -pub fn operator_eq_2(_a0: Ptr, _a1: Ptr) -> bool { - return ({ _a0.with(|__s| __s.a) } == { _a1.with(|__s| __s.a) }); +impl WeaklyEqualityComparableWith for DefaultedOrd { + fn equal(this: Ptr, __rhs: Ptr) -> bool { + let _a0: Ptr = this.clone().clone(); + let _a1: Ptr = __rhs.clone(); + return ({ _a0.with(|__s| __s.a) } == { _a1.with(|__s| __s.a) }); + } } #[derive( Copy, @@ -68,21 +71,20 @@ pub struct DefaultedOrd { } impl CppLess for DefaultedOrd { fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_cmp_1(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less + operator_cmp_0(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } -impl CppEq for DefaultedOrd { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_2(__lhs.clone(), __rhs.clone()) +impl WeaklyEqualityComparableWith for Inline { + fn equal(this: Ptr, __rhs: Ptr) -> bool { + let x: Ptr = this.clone().clone(); + let y: Ptr = __rhs.clone(); + return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }); } } -pub fn operator_eq_3(x: Ptr, y: Ptr) -> bool { - return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }); -} -pub fn operator_lt_4(x: Ptr, y: Ptr) -> bool { +pub fn operator_lt_1(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.a) } < { y.with(|__s| __s.a) }); } -pub fn operator_add_5(x: Ptr, y: Ptr) -> Inline { +pub fn operator_add_2(x: Ptr, y: Ptr) -> Inline { return Inline { a: ({ x.with(|__s| __s.a) } + { y.with(|__s| __s.a) }), }; @@ -106,12 +108,7 @@ pub struct Inline { } impl CppLess for Inline { fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_4(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Inline { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_3(__lhs.clone(), __rhs.clone()) + operator_lt_1(__lhs.clone(), __rhs.clone()) } } #[derive( @@ -131,24 +128,27 @@ pub struct OutOfLine { #[offset(0)] pub a: i32, } -impl CppEq for OutOfLine { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_6(__lhs.clone(), __rhs.clone()) +impl WeaklyEqualityComparableWith for OutOfLine { + fn equal(this: Ptr, __rhs: Ptr) -> bool { + let x: Ptr = this.clone().clone(); + let y: Ptr = __rhs.clone(); + return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }); } } -pub fn operator_eq_6(x: Ptr, y: Ptr) -> bool { - return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }); +pub fn operator_ne_3(x: Ptr, y: Ptr) -> bool { + return !({ WeaklyEqualityComparableWith::equal((x).clone(), (y).clone()) }); } -pub fn operator_ne_7(x: Ptr, y: Ptr) -> bool { - return !({ operator_eq_6((x).clone(), (y).clone()) }); -} -pub fn operator_eq_8(x: Ptr, y: Ptr) -> bool { - return ({ x.with(|__s| __s.v) } == { y.with(|__s| __s.v) }); +impl WeaklyEqualityComparableWith for Tmpl_int_ { + fn equal(this: Ptr, __rhs: Ptr) -> bool { + let x: Ptr = this.clone().clone(); + let y: Ptr = __rhs.clone(); + return ({ x.with(|__s| __s.v) } == { y.with(|__s| __s.v) }); + } } -pub fn operator_lt_9(x: Ptr, y: Ptr) -> bool { +pub fn operator_lt_4(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.v) } < { y.with(|__s| __s.v) }); } -pub fn operator_eq_10(x: Ptr, y: Ptr) -> bool { +pub fn operator_eq_5(x: Ptr, y: Ptr) -> bool { return ({ (x.with(|__s| __s.v) as i64) } == { y.with(|__s| __s.v) }); } #[derive( @@ -170,12 +170,7 @@ pub struct Tmpl_int_ { } impl CppLess for Tmpl_int_ { fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_9(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Tmpl_int_ { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_8(__lhs.clone(), __rhs.clone()) + operator_lt_4(__lhs.clone(), __rhs.clone()) } } #[derive( @@ -195,8 +190,12 @@ pub struct Tmpl_long_ { #[offset(0)] pub v: i64, } -pub fn operator_eq_11(_a0: Ptr, _a1: Ptr) -> bool { - return ({ _a0.with(|__s| __s.v) } == { _a1.with(|__s| __s.v) }); +impl WeaklyEqualityComparableWith for TmplDefaulted_int_ { + fn equal(this: Ptr, __rhs: Ptr) -> bool { + let _a0: Ptr = this.clone().clone(); + let _a1: Ptr = __rhs.clone(); + return ({ _a0.with(|__s| __s.v) } == { _a1.with(|__s| __s.v) }); + } } #[derive( Copy, @@ -215,11 +214,6 @@ pub struct TmplDefaulted_int_ { #[offset(0)] pub v: i32, } -impl CppEq for TmplDefaulted_int_ { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_11(__lhs.clone(), __rhs.clone()) - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -228,56 +222,56 @@ fn main_0() -> i32 { let d1: Value = Rc::new(RefCell::new(Defaulted { a: 1, b: 2 })); let d2: Value = Rc::new(RefCell::new(Defaulted { a: 1, b: 2 })); let d3: Value = Rc::new(RefCell::new(Defaulted { a: 1, b: 3 })); - assert!(({ operator_eq_0(d1.as_pointer(), d2.as_pointer(),) })); - assert!(!({ operator_eq_0(d1.as_pointer(), d3.as_pointer(),) })); - assert!(!({ operator_eq_0(d1.as_pointer(), d3.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(d1.as_pointer(), d2.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(d1.as_pointer(), d3.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(d1.as_pointer(), d3.as_pointer(),) })); let o1: Value = Rc::new(RefCell::new(DefaultedOrd { a: 1 })); let o2: Value = Rc::new(RefCell::new(DefaultedOrd { a: 2 })); - assert!(({ operator_cmp_1(o1.as_pointer(), o2.as_pointer(),) }) == std::cmp::Ordering::Less); - assert!(({ operator_cmp_1(o2.as_pointer(), o1.as_pointer(),) }) == std::cmp::Ordering::Greater); - assert!(({ operator_eq_2(o1.as_pointer(), o1.as_pointer(),) })); + assert!(({ operator_cmp_0(o1.as_pointer(), o2.as_pointer(),) }) == std::cmp::Ordering::Less); + assert!(({ operator_cmp_0(o2.as_pointer(), o1.as_pointer(),) }) == std::cmp::Ordering::Greater); + assert!(({ WeaklyEqualityComparableWith::equal(o1.as_pointer(), o1.as_pointer(),) })); assert!( - ({ operator_cmp_1(o1.as_pointer(), o2.as_pointer(),) }) + ({ operator_cmp_0(o1.as_pointer(), o2.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_less().upgrade().deref()) }) ); let i1: Value = Rc::new(RefCell::new(Inline { a: 1 })); let i2: Value = Rc::new(RefCell::new(Inline { a: 2 })); let i3: Value = Rc::new(RefCell::new(Inline { a: 1 })); - assert!(({ operator_eq_3(i1.as_pointer(), i3.as_pointer(),) })); - assert!(!({ operator_eq_3(i1.as_pointer(), i2.as_pointer(),) })); - assert!(({ operator_lt_4(i1.as_pointer(), i2.as_pointer(),) })); - assert!(!({ operator_lt_4(i2.as_pointer(), i1.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(i1.as_pointer(), i3.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(i1.as_pointer(), i2.as_pointer(),) })); + assert!(({ operator_lt_1(i1.as_pointer(), i2.as_pointer(),) })); + assert!(!({ operator_lt_1(i2.as_pointer(), i1.as_pointer(),) })); assert!( ({ let _x: Value = Rc::new(RefCell::new( - ({ operator_add_5(i1.as_pointer(), i2.as_pointer()) }), + ({ operator_add_2(i1.as_pointer(), i2.as_pointer()) }), )); let _y: Value = Rc::new(RefCell::new(Inline { a: 3 })); - operator_eq_3(_x.as_pointer(), _y.as_pointer()) + WeaklyEqualityComparableWith::equal(_x.as_pointer(), _y.as_pointer()) }) ); let f1: Value = Rc::new(RefCell::new(OutOfLine { a: 4 })); let f2: Value = Rc::new(RefCell::new(OutOfLine { a: 4 })); let f3: Value = Rc::new(RefCell::new(OutOfLine { a: 5 })); - assert!(({ operator_eq_6(f1.as_pointer(), f2.as_pointer(),) })); - assert!(({ operator_ne_7(f1.as_pointer(), f3.as_pointer(),) })); - assert!(!({ operator_eq_6(f1.as_pointer(), f3.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(f1.as_pointer(), f2.as_pointer(),) })); + assert!(({ operator_ne_3(f1.as_pointer(), f3.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(f1.as_pointer(), f3.as_pointer(),) })); let t1: Value = Rc::new(RefCell::new(Tmpl_int_ { v: 1 })); let t2: Value = Rc::new(RefCell::new(Tmpl_int_ { v: 2 })); let t3: Value = Rc::new(RefCell::new(Tmpl_int_ { v: 1 })); - assert!(({ operator_eq_8(t1.as_pointer(), t3.as_pointer(),) })); - assert!(!({ operator_eq_8(t1.as_pointer(), t2.as_pointer(),) })); - assert!(({ operator_lt_9(t1.as_pointer(), t2.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(t1.as_pointer(), t3.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(t1.as_pointer(), t2.as_pointer(),) })); + assert!(({ operator_lt_4(t1.as_pointer(), t2.as_pointer(),) })); let u1: Value = Rc::new(RefCell::new(Tmpl_long_ { v: 1_i64 })); let u2: Value = Rc::new(RefCell::new(Tmpl_long_ { v: 2_i64 })); - assert!(({ operator_eq_10(t1.as_pointer(), u1.as_pointer(),) })); - assert!(!({ operator_eq_10(t1.as_pointer(), u2.as_pointer(),) })); + assert!(({ operator_eq_5(t1.as_pointer(), u1.as_pointer(),) })); + assert!(!({ operator_eq_5(t1.as_pointer(), u2.as_pointer(),) })); let v1: Value = Rc::new(RefCell::new(TmplDefaulted_int_ { v: 7 })); let v2: Value = Rc::new(RefCell::new(TmplDefaulted_int_ { v: 7 })); let v3: Value = Rc::new(RefCell::new(TmplDefaulted_int_ { v: 8 })); - assert!(({ operator_eq_11(v1.as_pointer(), v2.as_pointer(),) })); - assert!(!({ operator_eq_11(v1.as_pointer(), v3.as_pointer(),) })); - assert!(!({ operator_eq_11(v1.as_pointer(), v3.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(v1.as_pointer(), v2.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(v1.as_pointer(), v3.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(v1.as_pointer(), v3.as_pointer(),) })); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_less_than.rs b/tests/unit/out/refcount/operator_less_than.rs index e62ec942fc..e22b8901cd 100644 --- a/tests/unit/out/refcount/operator_less_than.rs +++ b/tests/unit/out/refcount/operator_less_than.rs @@ -37,12 +37,6 @@ impl CppLess for Pair { Pair::operator_lt(__lhs.clone(), __rhs.clone()) } } -impl CppEq for Pair { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - !(Pair::operator_lt(__lhs.clone(), __rhs.clone())) - && !(Pair::operator_lt(__rhs.clone(), __lhs.clone())) - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); diff --git a/tests/unit/out/refcount/operator_three_way.rs b/tests/unit/out/refcount/operator_three_way.rs index 993d253862..2d4e427395 100644 --- a/tests/unit/out/refcount/operator_three_way.rs +++ b/tests/unit/out/refcount/operator_three_way.rs @@ -33,7 +33,9 @@ impl S { } return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } - pub fn operator_eq(this: Ptr, o: Ptr) -> bool { +} +impl WeaklyEqualityComparableWith for S { + fn equal(this: Ptr, o: Ptr) -> bool { return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); } } @@ -42,11 +44,6 @@ impl CppLess for S { S::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } -impl CppEq for S { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - S::operator_eq(__lhs.clone(), __rhs.clone()) - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -58,7 +55,7 @@ fn main_0() -> i32 { assert!(({ S::operator_cmp(b.as_pointer(), a.as_pointer(),) }) == std::cmp::Ordering::Greater); assert!(({ S::operator_cmp(a.as_pointer(), b.as_pointer(),) }) != std::cmp::Ordering::Greater); assert!(({ S::operator_cmp(b.as_pointer(), a.as_pointer(),) }) != std::cmp::Ordering::Less); - assert!(!({ S::operator_eq(a.as_pointer(), b.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(a.as_pointer(), b.as_pointer(),) })); assert!( ({ S::operator_cmp(a.as_pointer(), b.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_less().upgrade().deref()) }) diff --git a/tests/unit/out/refcount/operator_traits.rs b/tests/unit/out/refcount/operator_traits.rs index 8aa303c76d..77543f0a9c 100644 --- a/tests/unit/out/refcount/operator_traits.rs +++ b/tests/unit/out/refcount/operator_traits.rs @@ -33,12 +33,6 @@ impl CppLess for Lt { Lt::operator_lt(__lhs.clone(), __rhs.clone()) } } -impl CppEq for Lt { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - !(Lt::operator_lt(__lhs.clone(), __rhs.clone())) - && !(Lt::operator_lt(__rhs.clone(), __lhs.clone())) - } -} #[derive( Copy, Clone, @@ -56,16 +50,11 @@ pub struct Eq { #[offset(0)] pub v: i32, } -impl Eq { - pub fn operator_eq(this: Ptr, o: Ptr) -> bool { +impl WeaklyEqualityComparableWith for Eq { + fn equal(this: Ptr, o: Ptr) -> bool { return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); } } -impl CppEq for Eq { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Eq::operator_eq(__lhs.clone(), __rhs.clone()) - } -} #[derive( Copy, Clone, @@ -87,7 +76,9 @@ impl Cmp { pub fn operator_cmp(this: Ptr, o: Ptr) -> std::cmp::Ordering { return std::cmp::Ord::cmp(&(this.with(|__s| __s.v)), &(o.with(|__s| __s.v))); } - pub fn operator_eq(this: Ptr, o: Ptr) -> bool { +} +impl WeaklyEqualityComparableWith for Cmp { + fn equal(this: Ptr, o: Ptr) -> bool { return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); } } @@ -96,11 +87,6 @@ impl CppLess for Cmp { Cmp::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less } } -impl CppEq for Cmp { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Cmp::operator_eq(__lhs.clone(), __rhs.clone()) - } -} #[derive( Copy, Clone, @@ -123,16 +109,15 @@ impl CppLess for Free { operator_lt_0(__lhs.clone(), __rhs.clone()) } } -impl CppEq for Free { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_1(__lhs.clone(), __rhs.clone()) - } -} pub fn operator_lt_0(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } < { b.with(|__s| __s.v) }); } -pub fn operator_eq_1(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); +impl WeaklyEqualityComparableWith for Free { + fn equal(this: Ptr, __rhs: Ptr) -> bool { + let a: Ptr = this.clone().clone(); + let b: Ptr = __rhs.clone(); + return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); + } } #[derive( Copy, @@ -186,7 +171,9 @@ fn main_0() -> i32 { let mut __tmp_1 = { eqs.decay().begin() }; let mut __tmp_2 = { eqs.decay().end() }; let mut __it = (__tmp_1).clone(); - while __it != __tmp_2 && !CppEq::equal(__it.iter_deref(), two.as_pointer().clone()) { + while __it != __tmp_2 + && !WeaklyEqualityComparableWith::equal(__it.iter_deref(), two.as_pointer().clone()) + { __it.iter_inc(); } __it @@ -200,7 +187,12 @@ fn main_0() -> i32 { let mut __tmp_3 = { eqs.decay().begin() }; let mut __tmp_4 = { eqs.decay().end() }; let mut __it = (__tmp_3).clone(); - while __it != __tmp_4 && !CppEq::equal(__it.iter_deref(), nine.as_pointer().clone()) { + while __it != __tmp_4 + && !WeaklyEqualityComparableWith::equal( + __it.iter_deref(), + nine.as_pointer().clone(), + ) + { __it.iter_inc(); } __it @@ -227,7 +219,12 @@ fn main_0() -> i32 { let mut __tmp_6 = { cmps.decay().begin() }; let mut __tmp_7 = { cmps.decay().end() }; let mut __it = (__tmp_6).clone(); - while __it != __tmp_7 && !CppEq::equal(__it.iter_deref(), three.as_pointer().clone()) { + while __it != __tmp_7 + && !WeaklyEqualityComparableWith::equal( + __it.iter_deref(), + three.as_pointer().clone(), + ) + { __it.iter_inc(); } __it @@ -251,7 +248,12 @@ fn main_0() -> i32 { let mut __tmp_9 = { frees.decay().begin() }; let mut __tmp_10 = { frees.decay().end() }; let mut __it = (__tmp_9).clone(); - while __it != __tmp_10 && !CppEq::equal(__it.iter_deref(), ftwo.as_pointer().clone()) { + while __it != __tmp_10 + && !WeaklyEqualityComparableWith::equal( + __it.iter_deref(), + ftwo.as_pointer().clone(), + ) + { __it.iter_inc(); } __it diff --git a/tests/unit/out/refcount/size_t_ssize_t.rs b/tests/unit/out/refcount/size_t_ssize_t.rs index 28168bbd87..1615a0fa56 100644 --- a/tests/unit/out/refcount/size_t_ssize_t.rs +++ b/tests/unit/out/refcount/size_t_ssize_t.rs @@ -323,7 +323,10 @@ pub fn size_t_in_rules_3() { let mut __tmp_21 = { v3.decay().end() }; let mut __it = (__tmp_20).clone(); while __it != __tmp_21 - && !CppEq::equal(__it.iter_deref(), __tmp_22.as_pointer().clone()) + && !WeaklyEqualityComparableWith::equal( + __it.iter_deref(), + __tmp_22.as_pointer().clone(), + ) { __it.iter_inc(); } diff --git a/tests/unit/out/refcount/sort_no_copy.rs b/tests/unit/out/refcount/sort_no_copy.rs index 27aee2afb1..416935a7a1 100644 --- a/tests/unit/out/refcount/sort_no_copy.rs +++ b/tests/unit/out/refcount/sort_no_copy.rs @@ -55,12 +55,6 @@ impl CppLess for Tracked { operator_lt_1(__lhs.clone(), __rhs.clone()) } } -impl CppEq for Tracked { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - !(operator_lt_1(__lhs.clone(), __rhs.clone())) - && !(operator_lt_1(__rhs.clone(), __lhs.clone())) - } -} impl Default for Tracked { fn default() -> Self { { @@ -106,12 +100,6 @@ impl CppLess for MoveOnly { operator_lt_3(__lhs.clone(), __rhs.clone()) } } -impl CppEq for MoveOnly { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - !(operator_lt_3(__lhs.clone(), __rhs.clone())) - && !(operator_lt_3(__rhs.clone(), __lhs.clone())) - } -} pub fn operator_lt_3(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } < { b.with(|__s| __s.v) }); } @@ -135,16 +123,15 @@ impl CppLess for Bag { operator_lt_4(__lhs.clone(), __rhs.clone()) } } -impl CppEq for Bag { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_5(__lhs.clone(), __rhs.clone()) - } -} pub fn operator_lt_4(a: Ptr, b: Ptr) -> bool { return ({ (*a.upgrade().deref()).items.len() } < { (*b.upgrade().deref()).items.len() }); } -pub fn operator_eq_5(a: Ptr, b: Ptr) -> bool { - return ({ (*a.upgrade().deref()).items.len() } == { (*b.upgrade().deref()).items.len() }); +impl WeaklyEqualityComparableWith for Bag { + fn equal(this: Ptr, __rhs: Ptr) -> bool { + let a: Ptr = this.clone().clone(); + let b: Ptr = __rhs.clone(); + return ({ (*a.upgrade().deref()).items.len() } == { (*b.upgrade().deref()).items.len() }); + } } pub fn main() { __cpp2rust_init_globals(); @@ -447,7 +434,10 @@ fn main_0() -> i32 { let mut __tmp_21 = { bag_vec.decay().end() }; let mut __it = (__tmp_20).clone(); while __it != __tmp_21 - && !CppEq::equal(__it.iter_deref(), bags.decay().offset(1).clone()) + && !WeaklyEqualityComparableWith::equal( + __it.iter_deref(), + bags.decay().offset(1).clone(), + ) { __it.iter_inc(); } diff --git a/tests/unit/out/refcount/unboxed_conditional_iterator.rs b/tests/unit/out/refcount/unboxed_conditional_iterator.rs index 2f66920724..21720c30e4 100644 --- a/tests/unit/out/refcount/unboxed_conditional_iterator.rs +++ b/tests/unit/out/refcount/unboxed_conditional_iterator.rs @@ -59,7 +59,10 @@ pub fn lehmer_3(mut sigma: Ptr, mut len: u32, mut code: Ptr) { let mut __tmp_1 = { items.decay().end() }; let mut __it = (__tmp_0).clone(); while __it != __tmp_1 - && !CppEq::equal(__it.iter_deref(), sigma.offset((i) as isize).clone()) + && !WeaklyEqualityComparableWith::equal( + __it.iter_deref(), + sigma.offset((i) as isize).clone(), + ) { __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/class.rs b/tests/unit/out/unsafe/class.rs index dbd48a62a6..ed0ff616cc 100644 --- a/tests/unit/out/unsafe/class.rs +++ b/tests/unit/out/unsafe/class.rs @@ -92,14 +92,16 @@ impl Counter { (*(&raw const self.calls).cast_mut()).prefix_inc(); return self.v; } - pub unsafe fn operator_eq(&self, o: *const Counter) -> bool { +} +impl WeaklyEqualityComparableWithUnsafe for Counter { + unsafe fn equal(&self, o: *const Counter) -> bool { (*(&raw const self.calls).cast_mut()).prefix_inc(); return ((self.v) == ((*o).v)); } } impl std::cmp::PartialEq for Counter { fn eq(&self, other: &Self) -> bool { - unsafe { Counter::operator_eq(self, other as *const Counter) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Counter) } } } impl std::cmp::Eq for Counter {} @@ -180,8 +182,8 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { Counter::Get(&c1,) }) == (3))); assert!(((unsafe { Counter::Get(&c2,) }) == (3))); assert!(((unsafe { Counter::Get(&(*pc),) }) == (3))); - assert!((unsafe { Counter::operator_eq(&c1, &c2,) })); - assert!((unsafe { Counter::operator_eq(&c2, &c1,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&c1, &c2,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&c2, &c1,) })); assert!(((c1.calls) == (3))); assert!(((c2.calls) == (2))); let mut t: Tally = Tally { calls: 0 }; diff --git a/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs b/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs index 6593f96610..8c8a829046 100644 --- a/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs +++ b/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs @@ -26,7 +26,8 @@ unsafe fn main_0() -> i32 { let mut __tmp_2 = { v.begin() }; let mut __tmp_3 = { v.end() }; let mut __it = (__tmp_2).clone(); - while __it != __tmp_3 && *__it.iter_deref() != 7 { + while __it != __tmp_3 && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &7) + { __it.iter_inc(); } __it diff --git a/tests/unit/out/unsafe/find.rs b/tests/unit/out/unsafe/find.rs index 35b7cf60a8..142191d16d 100644 --- a/tests/unit/out/unsafe/find.rs +++ b/tests/unit/out/unsafe/find.rs @@ -20,14 +20,14 @@ use std::rc::Rc; pub struct P { pub x: i32, } -impl P { - pub unsafe fn operator_eq(&self, o: *const P) -> bool { +impl WeaklyEqualityComparableWithUnsafe for P { + unsafe fn equal(&self, o: *const P) -> bool { return ((self.x) == ((*o).x)); } } impl std::cmp::PartialEq for P { fn eq(&self, other: &Self) -> bool { - unsafe { P::operator_eq(self, other as *const P) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const P) } } } impl std::cmp::Eq for P {} @@ -56,7 +56,8 @@ unsafe fn main_0() -> i32 { let mut it: UnsafeRandomAccessIterator = { let mut __tmp_3 = { (v_end).clone() }; let mut __it = (v_begin).clone(); - while __it != __tmp_3 && *__it.iter_deref() != 2 { + while __it != __tmp_3 && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &2) + { __it.iter_inc(); } __it @@ -93,7 +94,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_7 = { v.begin() }; let mut __tmp_8 = { v.begin() }; let mut __it = (__tmp_7).clone(); - while __it != __tmp_8 && *__it.iter_deref() != 2 { + while __it != __tmp_8 + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &2) + { __it.iter_inc(); } __it @@ -105,7 +108,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_9 = { w.begin().iter_add(2_isize) }; let mut __tmp_10 = { w.end() }; let mut __it = (__tmp_9).clone(); - while __it != __tmp_10 && *__it.iter_deref() != 4 { + while __it != __tmp_10 + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &4) + { __it.iter_inc(); } __it @@ -116,7 +121,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_11 = { w.begin().iter_add(2_isize) }; let mut __tmp_12 = { w.end() }; let mut __it = (__tmp_11).clone(); - while __it != __tmp_12 && *__it.iter_deref() != 1 { + while __it != __tmp_12 + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &1) + { __it.iter_inc(); } __it @@ -127,7 +134,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_13 = { w.begin().iter_add(2_isize) }; let mut __tmp_14 = { w.begin().iter_add(4_isize) }; let mut __it = (__tmp_13).clone(); - while __it != __tmp_14 && *__it.iter_deref() != 5 { + while __it != __tmp_14 + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &5) + { __it.iter_inc(); } __it @@ -139,7 +148,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_15 = { p.begin() }; let mut __tmp_16 = { p.end() }; let mut __it = (__tmp_15).clone(); - while __it != __tmp_16 && *__it.iter_deref() != (P { x: 1 }) { + while __it != __tmp_16 + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &(P { x: 1 })) + { __it.iter_inc(); } __it diff --git a/tests/unit/out/unsafe/friend.rs b/tests/unit/out/unsafe/friend.rs index d1636d2ed8..2b03157d94 100644 --- a/tests/unit/out/unsafe/friend.rs +++ b/tests/unit/out/unsafe/friend.rs @@ -9,13 +9,17 @@ use std::rc::Rc; pub unsafe fn get_0(v: *const V) -> i32 { return (*v).x; } -pub unsafe fn operator_eq_1(a: *const V, b: *const V) -> bool { - return (((*a).x) == ((*b).x)); +impl WeaklyEqualityComparableWithUnsafe for V { + unsafe fn equal(&self, __rhs: *const Self) -> bool { + let a: *const V = self as *const V; + let b: *const V = (&*__rhs) as *const V; + return (((*a).x) == ((*b).x)); + } } -pub unsafe fn scaled_2(v: *const V, mut k: i32) -> i32 { +pub unsafe fn scaled_1(v: *const V, mut k: i32) -> i32 { return (((*v).x) * (k)); } -pub unsafe fn scaled_3(v: *const V, mut k: f64) -> f64 { +pub unsafe fn scaled_2(v: *const V, mut k: f64) -> f64 { return (((*v).x as f64) * (k)); } #[repr(C)] @@ -34,11 +38,11 @@ pub struct V { } impl std::cmp::PartialEq for V { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_1(self as *const V, other as *const V) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const V) } } } impl std::cmp::Eq for V {} -pub unsafe fn get_4(w: *const W_int_) -> i32 { +pub unsafe fn get_3(w: *const W_int_) -> i32 { return (*w).x; } #[repr(C)] @@ -55,7 +59,7 @@ pub unsafe fn get_4(w: *const W_int_) -> i32 { pub struct W_int_ { pub x: i32, } -pub unsafe fn get_5(w: *const W_long_) -> i64 { +pub unsafe fn get_4(w: *const W_long_) -> i64 { return (*w).x; } #[repr(C)] @@ -86,7 +90,7 @@ pub struct W_long_ { pub struct D { pub x: i32, } -pub unsafe fn declared_then_defined_6(d: *const D) -> i32 { +pub unsafe fn declared_then_defined_5(d: *const D) -> i32 { return (((*d).x) + (1)); } pub fn main() { @@ -103,23 +107,23 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _a: *const V = &a; - operator_eq_1(_a, &b) + WeaklyEqualityComparableWithUnsafe::equal(&*(_a), &b) }) ); assert!( !(unsafe { let _a: *const V = &a; - operator_eq_1(_a, &c) + WeaklyEqualityComparableWithUnsafe::equal(&*(_a), &c) }) ); - assert!(((unsafe { scaled_2(&c, 2,) }) == (8))); - assert!(((unsafe { scaled_3(&c, 1.5_f64,) }) == (6_f64))); + assert!(((unsafe { scaled_1(&c, 2,) }) == (8))); + assert!(((unsafe { scaled_2(&c, 1.5_f64,) }) == (6_f64))); let mut wi: W_int_ = W_int_ { x: 5 }; let mut wl: W_long_ = W_long_ { x: 6_i64 }; - assert!(((unsafe { get_4(&wi,) }) == (5))); - assert!(((unsafe { get_5(&wl,) }) == (6_i64))); + assert!(((unsafe { get_3(&wi,) }) == (5))); + assert!(((unsafe { get_4(&wl,) }) == (6_i64))); let mut d: D = D { x: 7 }; - assert!(((unsafe { declared_then_defined_6(&d,) }) == (8))); + assert!(((unsafe { declared_then_defined_5(&d,) }) == (8))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/map_key_identity.rs b/tests/unit/out/unsafe/map_key_identity.rs index d7f3b4279f..9e3bc44d97 100644 --- a/tests/unit/out/unsafe/map_key_identity.rs +++ b/tests/unit/out/unsafe/map_key_identity.rs @@ -43,15 +43,19 @@ impl std::cmp::PartialOrd for Key { } impl std::cmp::PartialEq for Key { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_2(self as *const Key, other as *const Key) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Key) } } } impl std::cmp::Eq for Key {} pub unsafe fn operator_lt_1(a: *const Key, b: *const Key) -> bool { return (((*a).order) < ((*b).order)); } -pub unsafe fn operator_eq_2(a: *const Key, b: *const Key) -> bool { - return (((*a).identity) == ((*b).identity)); +impl WeaklyEqualityComparableWithUnsafe for Key { + unsafe fn equal(&self, __rhs: *const Self) -> bool { + let a: *const Key = self as *const Key; + let b: *const Key = (&*__rhs) as *const Key; + return (((*a).identity) == ((*b).identity)); + } } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] @@ -94,7 +98,7 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & ((unsafe { let _a: *const Key = &distinct_a; - operator_eq_2(_a, &distinct_b) + WeaklyEqualityComparableWithUnsafe::equal(&*(_a), &distinct_b) }) as i32)) != 0; let mut distinct: UnsafeMap = UnsafeMap::new(); @@ -124,7 +128,7 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & ((unsafe { let _a: *const Key = &distinct_a; - operator_eq_2(_a, &distinct_b) + WeaklyEqualityComparableWithUnsafe::equal(&*(_a), &distinct_b) }) as i32)) != 0; let mut distinct_count: usize = 0_usize; @@ -153,7 +157,7 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & (!(unsafe { let _a: *const Key = &equivalent_a; - operator_eq_2(_a, &equivalent_b) + WeaklyEqualityComparableWithUnsafe::equal(&*(_a), &equivalent_b) }) as i32)) != 0; let mut equivalent: UnsafeMap = UnsafeMap::new(); @@ -197,7 +201,7 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & (!(unsafe { let _a: *const Key = &equivalent_a; - operator_eq_2(_a, &equivalent_b) + WeaklyEqualityComparableWithUnsafe::equal(&*(_a), &equivalent_b) }) as i32)) != 0; let later_key: Key = Key { diff --git a/tests/unit/out/unsafe/operator_comparison_defaulted.rs b/tests/unit/out/unsafe/operator_comparison_defaulted.rs index f9b1fa5a6b..ea6140516a 100644 --- a/tests/unit/out/unsafe/operator_comparison_defaulted.rs +++ b/tests/unit/out/unsafe/operator_comparison_defaulted.rs @@ -21,15 +21,15 @@ pub struct Eq { pub a: i32, pub b: i32, } -impl Eq { - pub unsafe fn operator_eq(&self, _a0: *const Eq) -> bool { +impl WeaklyEqualityComparableWithUnsafe for Eq { + unsafe fn equal(&self, _a0: *const Eq) -> bool { return (((*(self as *const Eq)).a) == ((*_a0).a)) && (((*(self as *const Eq)).b) == ((*_a0).b)); } } impl std::cmp::PartialEq for Eq { fn eq(&self, other: &Self) -> bool { - unsafe { Eq::operator_eq(self, other as *const Eq) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Eq) } } } impl std::cmp::Eq for Eq {} @@ -66,7 +66,9 @@ impl Cmp { } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(&self, _a0: *const Cmp) -> bool { +} +impl WeaklyEqualityComparableWithUnsafe for Cmp { + unsafe fn equal(&self, _a0: *const Cmp) -> bool { return (((*(self as *const Cmp)).a) == ((*_a0).a)) && (((*(self as *const Cmp)).b) == ((*_a0).b)); } @@ -102,9 +104,6 @@ pub struct Both { pub a: i32, } impl Both { - pub unsafe fn operator_eq(&self, _a0: *const Both) -> bool { - return (((*(self as *const Both)).a) == ((*_a0).a)); - } pub unsafe fn operator_cmp(&self, _a0: *const Both) -> std::cmp::Ordering { { let mut cmp: std::cmp::Ordering = @@ -116,6 +115,11 @@ impl Both { return libcc2rs::STRONG_ORDERING_EQUAL; } } +impl WeaklyEqualityComparableWithUnsafe for Both { + unsafe fn equal(&self, _a0: *const Both) -> bool { + return (((*(self as *const Both)).a) == ((*_a0).a)); + } +} impl std::cmp::Ord for Both { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { Both::operator_cmp(self, other as *const Both) } @@ -128,7 +132,7 @@ impl std::cmp::PartialOrd for Both { } impl std::cmp::PartialEq for Both { fn eq(&self, other: &Self) -> bool { - unsafe { Both::operator_eq(self, other as *const Both) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Both) } } } impl std::cmp::Eq for Both {} @@ -199,7 +203,9 @@ impl Inner { } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(&self, _a0: *const Inner) -> bool { +} +impl WeaklyEqualityComparableWithUnsafe for Inner { + unsafe fn equal(&self, _a0: *const Inner) -> bool { return (((*(self as *const Inner)).x) == ((*_a0).x)); } } @@ -254,10 +260,12 @@ impl Outer { } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(&self, _a0: *const Outer) -> bool { +} +impl WeaklyEqualityComparableWithUnsafe for Outer { + unsafe fn equal(&self, _a0: *const Outer) -> bool { return (unsafe { let _arg0: *const Inner = &(*_a0).i; - Inner::operator_eq(&(*(self as *const Outer)).i, _arg0) + WeaklyEqualityComparableWithUnsafe::equal(&(*(self as *const Outer)).i, _arg0) }) && (((*(self as *const Outer)).y) == ((*_a0).y)); } } @@ -292,11 +300,10 @@ pub struct Secondary { pub a: i32, } impl Secondary { - pub unsafe fn operator_eq(&self, _a0: *const Secondary) -> bool { - return (((*(self as *const Secondary)).a) == ((*_a0).a)); - } pub unsafe fn operator_ne(&self, _a0: *const Secondary) -> bool { - return !(unsafe { Secondary::operator_eq(&(*(self as *const Secondary)), _a0) }); + return !(unsafe { + WeaklyEqualityComparableWithUnsafe::equal(&(*(self as *const Secondary)), _a0) + }); } pub unsafe fn operator_cmp(&self, _a0: *const Secondary) -> std::cmp::Ordering { { @@ -317,6 +324,11 @@ impl Secondary { != std::cmp::Ordering::Less; } } +impl WeaklyEqualityComparableWithUnsafe for Secondary { + unsafe fn equal(&self, _a0: *const Secondary) -> bool { + return (((*(self as *const Secondary)).a) == ((*_a0).a)); + } +} impl std::cmp::Ord for Secondary { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { Secondary::operator_cmp(self, other as *const Secondary) } @@ -329,7 +341,7 @@ impl std::cmp::PartialOrd for Secondary { } impl std::cmp::PartialEq for Secondary { fn eq(&self, other: &Self) -> bool { - unsafe { Secondary::operator_eq(self, other as *const Secondary) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Secondary) } } } impl std::cmp::Eq for Secondary {} @@ -358,7 +370,9 @@ impl PtrMember { } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(&self, _a0: *const PtrMember) -> bool { +} +impl WeaklyEqualityComparableWithUnsafe for PtrMember { + unsafe fn equal(&self, _a0: *const PtrMember) -> bool { return (((*(self as *const PtrMember)).p) == ((*_a0).p)); } } @@ -390,8 +404,8 @@ unsafe fn main_0() -> i32 { let mut e1: Eq = Eq { a: 1, b: 2 }; let mut e2: Eq = Eq { a: 1, b: 2 }; let mut e3: Eq = Eq { a: 1, b: 3 }; - assert!((unsafe { Eq::operator_eq(&e1, &e2,) })); - assert!(!(unsafe { Eq::operator_eq(&e1, &e3,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&e1, &e2,) })); + assert!(!(unsafe { WeaklyEqualityComparableWithUnsafe::equal(&e1, &e3,) })); let mut c1: Cmp = Cmp { a: 1, b: 2 }; let mut c2: Cmp = Cmp { a: 1, b: 3 }; let mut c3: Cmp = Cmp { a: 2, b: 0 }; @@ -401,7 +415,7 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _arg0: *const Cmp = &c1; - Cmp::operator_eq(&c1, _arg0) + WeaklyEqualityComparableWithUnsafe::equal(&c1, _arg0) }) ); assert!((unsafe { Cmp::operator_cmp(&c1, &c2,) }) == libcc2rs::STRONG_ORDERING_LESS); @@ -411,7 +425,7 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _arg0: *const Both = &b2; - Both::operator_eq(&b2, _arg0) + WeaklyEqualityComparableWithUnsafe::equal(&b2, _arg0) }) ); let mut o1: OrdOnly = OrdOnly { a: 1 }; @@ -431,7 +445,7 @@ unsafe fn main_0() -> i32 { y: 9, }; assert!((unsafe { Outer::operator_cmp(&x1, &x2,) }) == std::cmp::Ordering::Less); - assert!((unsafe { Outer::operator_eq(&x1, &x3,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&x1, &x3,) })); assert!((unsafe { Outer::operator_cmp(&x2, &x1,) }) == libcc2rs::STRONG_ORDERING_GREATER); let mut s1: Secondary = Secondary { a: 1 }; let mut s2: Secondary = Secondary { a: 2 }; @@ -450,7 +464,7 @@ unsafe fn main_0() -> i32 { p: arr.as_mut_ptr(), }; assert!((unsafe { PtrMember::operator_cmp(&p1, &p2,) }) == std::cmp::Ordering::Less); - assert!((unsafe { PtrMember::operator_eq(&p1, &p3,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&p1, &p3,) })); assert!((unsafe { PtrMember::operator_cmp(&p2, &p1,) }) == libcc2rs::STRONG_ORDERING_GREATER); return 0; } diff --git a/tests/unit/out/unsafe/operator_comparison_free.rs b/tests/unit/out/unsafe/operator_comparison_free.rs index 9d49a17880..ca9ed3f25c 100644 --- a/tests/unit/out/unsafe/operator_comparison_free.rs +++ b/tests/unit/out/unsafe/operator_comparison_free.rs @@ -40,32 +40,36 @@ impl std::cmp::PartialOrd for S { } impl std::cmp::PartialEq for S { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_1(self as *const S, other as *const S) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const S) } } } impl std::cmp::Eq for S {} -pub unsafe fn operator_eq_1(a: *const S, b: *const S) -> bool { - return (((*a).v) == ((*b).v)); +impl WeaklyEqualityComparableWithUnsafe for S { + unsafe fn equal(&self, __rhs: *const Self) -> bool { + let a: *const S = self as *const S; + let b: *const S = (&*__rhs) as *const S; + return (((*a).v) == ((*b).v)); + } } -pub unsafe fn operator_ne_2(a: *const S, b: *const S) -> bool { +pub unsafe fn operator_ne_1(a: *const S, b: *const S) -> bool { return (((*a).v) != ((*b).v)); } pub unsafe fn operator_lt_0(a: *const S, b: *const S) -> bool { return (((*a).v) < ((*b).v)); } -pub unsafe fn operator_gt_3(a: *const S, b: *const S) -> bool { +pub unsafe fn operator_gt_2(a: *const S, b: *const S) -> bool { return (((*a).v) > ((*b).v)); } -pub unsafe fn operator_le_4(a: *const S, b: *const S) -> bool { +pub unsafe fn operator_le_3(a: *const S, b: *const S) -> bool { return (((*a).v) <= ((*b).v)); } -pub unsafe fn operator_ge_5(a: *const S, b: *const S) -> bool { +pub unsafe fn operator_ge_4(a: *const S, b: *const S) -> bool { return (((*a).v) >= ((*b).v)); } -pub unsafe fn operator_lt_6(a: *const S, mut b: i32) -> bool { +pub unsafe fn operator_lt_5(a: *const S, mut b: i32) -> bool { return (((*a).v) < (b)); } -pub unsafe fn operator_lt_7(mut a: i32, b: *const S) -> bool { +pub unsafe fn operator_lt_6(mut a: i32, b: *const S) -> bool { return ((a) < ((*b).v)); } #[repr(C)] @@ -85,9 +89,9 @@ pub struct V { impl std::cmp::Ord for V { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_8(self.clone(), other.clone()) { + if operator_lt_7(self.clone(), other.clone()) { std::cmp::Ordering::Less - } else if operator_lt_8(other.clone(), self.clone()) { + } else if operator_lt_7(other.clone(), self.clone()) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -102,20 +106,25 @@ impl std::cmp::PartialOrd for V { } impl std::cmp::PartialEq for V { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_9(self.clone(), other.clone()) } + unsafe { operator_eq_8(self.clone(), other.clone()) } } } impl std::cmp::Eq for V {} -pub unsafe fn operator_eq_9(mut a: V, mut b: V) -> bool { +impl WeaklyEqualityComparableWithUnsafe for V { + unsafe fn equal(&self, __rhs: *const Self) -> bool { + operator_eq_8(self.clone(), (&*__rhs).clone()) + } +} +pub unsafe fn operator_eq_8(mut a: V, mut b: V) -> bool { return ((a.v) == (b.v)); } -pub unsafe fn operator_ne_10(mut a: V, mut b: V) -> bool { +pub unsafe fn operator_ne_9(mut a: V, mut b: V) -> bool { return ((a.v) != (b.v)); } -pub unsafe fn operator_lt_8(mut a: V, mut b: V) -> bool { +pub unsafe fn operator_lt_7(mut a: V, mut b: V) -> bool { return ((a.v) < (b.v)); } -pub unsafe fn operator_gt_11(mut a: V, mut b: V) -> bool { +pub unsafe fn operator_gt_10(mut a: V, mut b: V) -> bool { return ((a.v) > (b.v)); } pub fn main() { @@ -131,31 +140,31 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _a: V = x; - operator_eq_9(_a, z) + operator_eq_8(_a, z) }) ); assert!( (unsafe { let _a: V = x; - operator_ne_10(_a, y) + operator_ne_9(_a, y) }) ); assert!( (unsafe { let _a: V = x; - operator_lt_8(_a, y) + operator_lt_7(_a, y) }) ); assert!( (unsafe { let _a: V = y; - operator_gt_11(_a, x) + operator_gt_10(_a, x) }) ); assert!( !(unsafe { let _a: V = y; - operator_lt_8(_a, x) + operator_lt_7(_a, x) }) ); let mut a: S = S { v: 1 }; @@ -164,13 +173,13 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _a: *const S = &a; - operator_eq_1(_a, &c) + WeaklyEqualityComparableWithUnsafe::equal(&*(_a), &c) }) ); assert!( (unsafe { let _a: *const S = &a; - operator_ne_2(_a, &b) + operator_ne_1(_a, &b) }) ); assert!( @@ -182,19 +191,19 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _a: *const S = &b; - operator_gt_3(_a, &a) + operator_gt_2(_a, &a) }) ); assert!( (unsafe { let _a: *const S = &a; - operator_le_4(_a, &c) + operator_le_3(_a, &c) }) ); assert!( (unsafe { let _a: *const S = &a; - operator_ge_5(_a, &c) + operator_ge_4(_a, &c) }) ); assert!( @@ -206,10 +215,10 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _a: *const S = &a; - operator_lt_6(_a, 5) + operator_lt_5(_a, 5) }) ); - assert!((unsafe { operator_lt_7(0, &a,) })); + assert!((unsafe { operator_lt_6(0, &a,) })); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_comparison_member.rs b/tests/unit/out/unsafe/operator_comparison_member.rs index 8f040647f7..692850292a 100644 --- a/tests/unit/out/unsafe/operator_comparison_member.rs +++ b/tests/unit/out/unsafe/operator_comparison_member.rs @@ -21,9 +21,6 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn operator_eq(&self, o: *const S) -> bool { - return ((self.v) == ((*o).v)); - } pub unsafe fn operator_ne(&self, o: *const S) -> bool { return ((self.v) != ((*o).v)); } @@ -43,6 +40,11 @@ impl S { return ((self.v) < (o)); } } +impl WeaklyEqualityComparableWithUnsafe for S { + unsafe fn equal(&self, o: *const S) -> bool { + return ((self.v) == ((*o).v)); + } +} impl std::cmp::Ord for S { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { @@ -63,7 +65,7 @@ impl std::cmp::PartialOrd for S { } impl std::cmp::PartialEq for S { fn eq(&self, other: &Self) -> bool { - unsafe { S::operator_eq(self, other as *const S) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const S) } } } impl std::cmp::Eq for S {} @@ -77,7 +79,7 @@ unsafe fn main_0() -> i32 { let mut a: S = S { v: 1 }; let mut b: S = S { v: 2 }; let mut c: S = S { v: 1 }; - assert!((unsafe { S::operator_eq(&a, &c,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&a, &c,) })); assert!((unsafe { S::operator_ne(&a, &b,) })); assert!((unsafe { S::operator_lt_3(&a, &b,) })); assert!((unsafe { S::operator_gt(&b, &a,) })); diff --git a/tests/unit/out/unsafe/operator_comparison_nonbool.rs b/tests/unit/out/unsafe/operator_comparison_nonbool.rs index 3c1fd305f9..7d5ad984df 100644 --- a/tests/unit/out/unsafe/operator_comparison_nonbool.rs +++ b/tests/unit/out/unsafe/operator_comparison_nonbool.rs @@ -44,6 +44,11 @@ impl std::cmp::PartialEq for X { } } impl std::cmp::Eq for X {} +impl WeaklyEqualityComparableWithUnsafe for X { + unsafe fn equal(&self, __rhs: *const Self) -> bool { + ((operator_eq_1(self.clone(), (&*__rhs).clone())) != 0) + } +} pub unsafe fn operator_eq_1(mut a: X, mut b: X) -> i32 { return if ((a.v) == (b.v)) { 2 } else { 0 }; } @@ -148,6 +153,11 @@ impl std::cmp::PartialEq for Mixed { } } impl std::cmp::Eq for Mixed {} +impl WeaklyEqualityComparableWithUnsafe for Mixed { + unsafe fn equal(&self, __rhs: *const Self) -> bool { + ((Mixed::operator_eq(self, (&*__rhs) as *const Mixed)) != 0) + } +} #[repr(C)] #[derive( Copy, @@ -221,6 +231,14 @@ impl std::cmp::PartialEq for Boolish { } } impl std::cmp::Eq for Boolish {} +impl WeaklyEqualityComparableWithUnsafe for Boolish { + unsafe fn equal(&self, __rhs: *const Self) -> bool { + { + let __cmp = operator_eq_7(self.clone(), (&*__rhs).clone()); + MyBool::to_bool(&__cmp) + } + } +} pub unsafe fn operator_eq_7(mut a: Boolish, mut b: Boolish) -> MyBool { return { let mut __v: MyBool = ::zero_init(); @@ -295,6 +313,14 @@ impl std::cmp::PartialEq for RefInt { } } impl std::cmp::Eq for RefInt {} +impl WeaklyEqualityComparableWithUnsafe for RefInt { + unsafe fn equal(&self, __rhs: *const Self) -> bool { + { + let __cmp = RefInt::operator_eq(self, (&*__rhs) as *const RefInt); + RefBool::to_bool(&*__cmp) + } + } +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -450,7 +476,9 @@ unsafe fn main_0() -> i32 { (({ let mut __tmp_3 = { ris.as_mut_ptr().offset((2) as isize) }; let mut __it = ris.as_mut_ptr(); - while __it != __tmp_3 && *__it.iter_deref() != ri2 { + while __it != __tmp_3 + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &ri2) + { __it.iter_inc(); } __it diff --git a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs index 7a34aa7e3a..76926cbb1e 100644 --- a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs +++ b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs @@ -6,10 +6,14 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub unsafe fn operator_eq_0(x: *const S, y: *const S) -> bool { - return (((*x).data_) == ((*y).data_)); +impl WeaklyEqualityComparableWithUnsafe for S { + unsafe fn equal(&self, __rhs: *const Self) -> bool { + let x: *const S = self as *const S; + let y: *const S = (&*__rhs) as *const S; + return (((*x).data_) == ((*y).data_)); + } } -pub unsafe fn operator_lt_1(x: *const S, y: *const S) -> bool { +pub unsafe fn operator_lt_0(x: *const S, y: *const S) -> bool { return (((*x).data_) < ((*y).data_)); } #[repr(C)] @@ -34,9 +38,9 @@ impl S { impl std::cmp::Ord for S { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_1(self as *const S, other as *const S) { + if operator_lt_0(self as *const S, other as *const S) { std::cmp::Ordering::Less - } else if operator_lt_1(other as *const S, self as *const S) { + } else if operator_lt_0(other as *const S, self as *const S) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -51,7 +55,7 @@ impl std::cmp::PartialOrd for S { } impl std::cmp::PartialEq for S { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_0(self as *const S, other as *const S) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const S) } } } impl std::cmp::Eq for S {} @@ -68,19 +72,19 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const S = &a; - operator_eq_0(_x, &c) + WeaklyEqualityComparableWithUnsafe::equal(&*(_x), &c) }) ); assert!( (unsafe { let _x: *const S = &a; - operator_lt_1(_x, &b) + operator_lt_0(_x, &b) }) ); assert!( !(unsafe { let _x: *const S = &b; - operator_lt_1(_x, &a) + operator_lt_0(_x, &a) }) ); return 0; diff --git a/tests/unit/out/unsafe/operator_friend.rs b/tests/unit/out/unsafe/operator_friend.rs index f87c82e9c5..c47d47f696 100644 --- a/tests/unit/out/unsafe/operator_friend.rs +++ b/tests/unit/out/unsafe/operator_friend.rs @@ -6,8 +6,12 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub unsafe fn operator_eq_0(_a0: *const Defaulted, _a1: *const Defaulted) -> bool { - return (((*_a0).a) == ((*_a1).a)) && (((*_a0).b) == ((*_a1).b)); +impl WeaklyEqualityComparableWithUnsafe for Defaulted { + unsafe fn equal(&self, __rhs: *const Self) -> bool { + let _a0: *const Defaulted = self as *const Defaulted; + let _a1: *const Defaulted = (&*__rhs) as *const Defaulted; + return (((*_a0).a) == ((*_a1).a)) && (((*_a0).b) == ((*_a1).b)); + } } #[repr(C)] #[derive( @@ -26,11 +30,11 @@ pub struct Defaulted { } impl std::cmp::PartialEq for Defaulted { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_0(self as *const Defaulted, other as *const Defaulted) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Defaulted) } } } impl std::cmp::Eq for Defaulted {} -pub unsafe fn operator_cmp_1( +pub unsafe fn operator_cmp_0( _a0: *const DefaultedOrd, _a1: *const DefaultedOrd, ) -> std::cmp::Ordering { @@ -42,8 +46,12 @@ pub unsafe fn operator_cmp_1( } return libcc2rs::STRONG_ORDERING_EQUAL; } -pub unsafe fn operator_eq_2(_a0: *const DefaultedOrd, _a1: *const DefaultedOrd) -> bool { - return (((*_a0).a) == ((*_a1).a)); +impl WeaklyEqualityComparableWithUnsafe for DefaultedOrd { + unsafe fn equal(&self, __rhs: *const Self) -> bool { + let _a0: *const DefaultedOrd = self as *const DefaultedOrd; + let _a1: *const DefaultedOrd = (&*__rhs) as *const DefaultedOrd; + return (((*_a0).a) == ((*_a1).a)); + } } #[repr(C)] #[derive( @@ -61,7 +69,7 @@ pub struct DefaultedOrd { } impl std::cmp::Ord for DefaultedOrd { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { operator_cmp_1(self as *const DefaultedOrd, other as *const DefaultedOrd) } + unsafe { operator_cmp_0(self as *const DefaultedOrd, other as *const DefaultedOrd) } } } impl std::cmp::PartialOrd for DefaultedOrd { @@ -71,17 +79,21 @@ impl std::cmp::PartialOrd for DefaultedOrd { } impl std::cmp::PartialEq for DefaultedOrd { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_2(self as *const DefaultedOrd, other as *const DefaultedOrd) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const DefaultedOrd) } } } impl std::cmp::Eq for DefaultedOrd {} -pub unsafe fn operator_eq_3(x: *const Inline, y: *const Inline) -> bool { - return (((*x).a) == ((*y).a)); +impl WeaklyEqualityComparableWithUnsafe for Inline { + unsafe fn equal(&self, __rhs: *const Self) -> bool { + let x: *const Inline = self as *const Inline; + let y: *const Inline = (&*__rhs) as *const Inline; + return (((*x).a) == ((*y).a)); + } } -pub unsafe fn operator_lt_4(x: *const Inline, y: *const Inline) -> bool { +pub unsafe fn operator_lt_1(x: *const Inline, y: *const Inline) -> bool { return (((*x).a) < ((*y).a)); } -pub unsafe fn operator_add_5(x: *const Inline, y: *const Inline) -> Inline { +pub unsafe fn operator_add_2(x: *const Inline, y: *const Inline) -> Inline { return Inline { a: (((*x).a) + ((*y).a)), }; @@ -103,9 +115,9 @@ pub struct Inline { impl std::cmp::Ord for Inline { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_4(self as *const Inline, other as *const Inline) { + if operator_lt_1(self as *const Inline, other as *const Inline) { std::cmp::Ordering::Less - } else if operator_lt_4(other as *const Inline, self as *const Inline) { + } else if operator_lt_1(other as *const Inline, self as *const Inline) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -120,7 +132,7 @@ impl std::cmp::PartialOrd for Inline { } impl std::cmp::PartialEq for Inline { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_3(self as *const Inline, other as *const Inline) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Inline) } } } impl std::cmp::Eq for Inline {} @@ -140,26 +152,34 @@ pub struct OutOfLine { } impl std::cmp::PartialEq for OutOfLine { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_6(self as *const OutOfLine, other as *const OutOfLine) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const OutOfLine) } } } impl std::cmp::Eq for OutOfLine {} -pub unsafe fn operator_eq_6(x: *const OutOfLine, y: *const OutOfLine) -> bool { - return (((*x).a) == ((*y).a)); +impl WeaklyEqualityComparableWithUnsafe for OutOfLine { + unsafe fn equal(&self, __rhs: *const Self) -> bool { + let x: *const OutOfLine = self as *const OutOfLine; + let y: *const OutOfLine = (&*__rhs) as *const OutOfLine; + return (((*x).a) == ((*y).a)); + } } -pub unsafe fn operator_ne_7(x: *const OutOfLine, y: *const OutOfLine) -> bool { +pub unsafe fn operator_ne_3(x: *const OutOfLine, y: *const OutOfLine) -> bool { return !(unsafe { let _x: *const OutOfLine = x; - operator_eq_6(_x, y) + WeaklyEqualityComparableWithUnsafe::equal(&*(_x), y) }); } -pub unsafe fn operator_eq_8(x: *const Tmpl_int_, y: *const Tmpl_int_) -> bool { - return (((*x).v) == ((*y).v)); +impl WeaklyEqualityComparableWithUnsafe for Tmpl_int_ { + unsafe fn equal(&self, __rhs: *const Self) -> bool { + let x: *const Tmpl_int_ = self as *const Tmpl_int_; + let y: *const Tmpl_int_ = (&*__rhs) as *const Tmpl_int_; + return (((*x).v) == ((*y).v)); + } } -pub unsafe fn operator_lt_9(x: *const Tmpl_int_, y: *const Tmpl_int_) -> bool { +pub unsafe fn operator_lt_4(x: *const Tmpl_int_, y: *const Tmpl_int_) -> bool { return (((*x).v) < ((*y).v)); } -pub unsafe fn operator_eq_10(x: *const Tmpl_int_, y: *const Tmpl_long_) -> bool { +pub unsafe fn operator_eq_5(x: *const Tmpl_int_, y: *const Tmpl_long_) -> bool { return (((*x).v as i64) == ((*y).v)); } #[repr(C)] @@ -179,9 +199,9 @@ pub struct Tmpl_int_ { impl std::cmp::Ord for Tmpl_int_ { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_9(self as *const Tmpl_int_, other as *const Tmpl_int_) { + if operator_lt_4(self as *const Tmpl_int_, other as *const Tmpl_int_) { std::cmp::Ordering::Less - } else if operator_lt_9(other as *const Tmpl_int_, self as *const Tmpl_int_) { + } else if operator_lt_4(other as *const Tmpl_int_, self as *const Tmpl_int_) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -196,7 +216,7 @@ impl std::cmp::PartialOrd for Tmpl_int_ { } impl std::cmp::PartialEq for Tmpl_int_ { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_8(self as *const Tmpl_int_, other as *const Tmpl_int_) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Tmpl_int_) } } } impl std::cmp::Eq for Tmpl_int_ {} @@ -214,11 +234,12 @@ impl std::cmp::Eq for Tmpl_int_ {} pub struct Tmpl_long_ { pub v: i64, } -pub unsafe fn operator_eq_11( - _a0: *const TmplDefaulted_int_, - _a1: *const TmplDefaulted_int_, -) -> bool { - return (((*_a0).v) == ((*_a1).v)); +impl WeaklyEqualityComparableWithUnsafe for TmplDefaulted_int_ { + unsafe fn equal(&self, __rhs: *const Self) -> bool { + let _a0: *const TmplDefaulted_int_ = self as *const TmplDefaulted_int_; + let _a1: *const TmplDefaulted_int_ = (&*__rhs) as *const TmplDefaulted_int_; + return (((*_a0).v) == ((*_a1).v)); + } } #[repr(C)] #[derive( @@ -237,10 +258,7 @@ pub struct TmplDefaulted_int_ { impl std::cmp::PartialEq for TmplDefaulted_int_ { fn eq(&self, other: &Self) -> bool { unsafe { - operator_eq_11( - self as *const TmplDefaulted_int_, - other as *const TmplDefaulted_int_, - ) + WeaklyEqualityComparableWithUnsafe::equal(self, other as *const TmplDefaulted_int_) } } } @@ -258,19 +276,19 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _arg0: *const Defaulted = &d1; - operator_eq_0(_arg0, &d2) + WeaklyEqualityComparableWithUnsafe::equal(&*(_arg0), &d2) }) ); assert!( !(unsafe { let _arg0: *const Defaulted = &d1; - operator_eq_0(_arg0, &d3) + WeaklyEqualityComparableWithUnsafe::equal(&*(_arg0), &d3) }) ); assert!( !(unsafe { let _arg0: *const Defaulted = &d1; - operator_eq_0(_arg0, &d3) + WeaklyEqualityComparableWithUnsafe::equal(&*(_arg0), &d3) }) ); let mut o1: DefaultedOrd = DefaultedOrd { a: 1 }; @@ -278,26 +296,26 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _arg0: *const DefaultedOrd = &o1; - operator_cmp_1(_arg0, &o2) + operator_cmp_0(_arg0, &o2) }) == std::cmp::Ordering::Less ); assert!( (unsafe { let _arg0: *const DefaultedOrd = &o2; - operator_cmp_1(_arg0, &o1) + operator_cmp_0(_arg0, &o1) }) == std::cmp::Ordering::Greater ); assert!( (unsafe { let _arg0: *const DefaultedOrd = &o1; let _arg1: *const DefaultedOrd = &o1; - operator_eq_2(_arg0, _arg1) + WeaklyEqualityComparableWithUnsafe::equal(&*(_arg0), _arg1) }) ); assert!( (unsafe { let _arg0: *const DefaultedOrd = &o1; - operator_cmp_1(_arg0, &o2) + operator_cmp_0(_arg0, &o2) }) == libcc2rs::STRONG_ORDERING_LESS ); let mut i1: Inline = Inline { a: 1 }; @@ -306,35 +324,35 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const Inline = &i1; - operator_eq_3(_x, &i3) + WeaklyEqualityComparableWithUnsafe::equal(&*(_x), &i3) }) ); assert!( !(unsafe { let _x: *const Inline = &i1; - operator_eq_3(_x, &i2) + WeaklyEqualityComparableWithUnsafe::equal(&*(_x), &i2) }) ); assert!( (unsafe { let _x: *const Inline = &i1; - operator_lt_4(_x, &i2) + operator_lt_1(_x, &i2) }) ); assert!( !(unsafe { let _x: *const Inline = &i2; - operator_lt_4(_x, &i1) + operator_lt_1(_x, &i1) }) ); assert!( (unsafe { let mut _x: Inline = (unsafe { let _x: *const Inline = &i1; - operator_add_5(_x, &i2) + operator_add_2(_x, &i2) }); let mut _y: Inline = Inline { a: 3 }; - operator_eq_3(&mut _x, &mut _y) + WeaklyEqualityComparableWithUnsafe::equal(&*(&mut _x), &mut _y) }) ); let mut f1: OutOfLine = OutOfLine { a: 4 }; @@ -343,19 +361,19 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const OutOfLine = &f1; - operator_eq_6(_x, &f2) + WeaklyEqualityComparableWithUnsafe::equal(&*(_x), &f2) }) ); assert!( (unsafe { let _x: *const OutOfLine = &f1; - operator_ne_7(_x, &f3) + operator_ne_3(_x, &f3) }) ); assert!( !(unsafe { let _x: *const OutOfLine = &f1; - operator_eq_6(_x, &f3) + WeaklyEqualityComparableWithUnsafe::equal(&*(_x), &f3) }) ); let mut t1: Tmpl_int_ = Tmpl_int_ { v: 1 }; @@ -364,19 +382,19 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const Tmpl_int_ = &t1; - operator_eq_8(_x, &t3) + WeaklyEqualityComparableWithUnsafe::equal(&*(_x), &t3) }) ); assert!( !(unsafe { let _x: *const Tmpl_int_ = &t1; - operator_eq_8(_x, &t2) + WeaklyEqualityComparableWithUnsafe::equal(&*(_x), &t2) }) ); assert!( (unsafe { let _x: *const Tmpl_int_ = &t1; - operator_lt_9(_x, &t2) + operator_lt_4(_x, &t2) }) ); let mut u1: Tmpl_long_ = Tmpl_long_ { v: 1_i64 }; @@ -384,13 +402,13 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const Tmpl_int_ = &t1; - operator_eq_10(_x, &u1) + operator_eq_5(_x, &u1) }) ); assert!( !(unsafe { let _x: *const Tmpl_int_ = &t1; - operator_eq_10(_x, &u2) + operator_eq_5(_x, &u2) }) ); let mut v1: TmplDefaulted_int_ = TmplDefaulted_int_ { v: 7 }; @@ -399,19 +417,19 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _arg0: *const TmplDefaulted_int_ = &v1; - operator_eq_11(_arg0, &v2) + WeaklyEqualityComparableWithUnsafe::equal(&*(_arg0), &v2) }) ); assert!( !(unsafe { let _arg0: *const TmplDefaulted_int_ = &v1; - operator_eq_11(_arg0, &v3) + WeaklyEqualityComparableWithUnsafe::equal(&*(_arg0), &v3) }) ); assert!( !(unsafe { let _arg0: *const TmplDefaulted_int_ = &v1; - operator_eq_11(_arg0, &v3) + WeaklyEqualityComparableWithUnsafe::equal(&*(_arg0), &v3) }) ); return 0; diff --git a/tests/unit/out/unsafe/operator_three_way.rs b/tests/unit/out/unsafe/operator_three_way.rs index eb74b41521..7baca4ee3b 100644 --- a/tests/unit/out/unsafe/operator_three_way.rs +++ b/tests/unit/out/unsafe/operator_three_way.rs @@ -30,7 +30,9 @@ impl S { } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(&self, o: *const S) -> bool { +} +impl WeaklyEqualityComparableWithUnsafe for S { + unsafe fn equal(&self, o: *const S) -> bool { return ((self.v) == ((*o).v)); } } @@ -46,7 +48,7 @@ impl std::cmp::PartialOrd for S { } impl std::cmp::PartialEq for S { fn eq(&self, other: &Self) -> bool { - unsafe { S::operator_eq(self, other as *const S) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const S) } } } impl std::cmp::Eq for S {} @@ -63,7 +65,7 @@ unsafe fn main_0() -> i32 { assert!((unsafe { S::operator_cmp(&b, &a,) }) == std::cmp::Ordering::Greater); assert!((unsafe { S::operator_cmp(&a, &b,) }) != std::cmp::Ordering::Greater); assert!((unsafe { S::operator_cmp(&b, &a,) }) != std::cmp::Ordering::Less); - assert!(!(unsafe { S::operator_eq(&a, &b,) })); + assert!(!(unsafe { WeaklyEqualityComparableWithUnsafe::equal(&a, &b,) })); assert!((unsafe { S::operator_cmp(&a, &b,) }) == libcc2rs::STRONG_ORDERING_LESS); return 0; } diff --git a/tests/unit/out/unsafe/operator_traits.rs b/tests/unit/out/unsafe/operator_traits.rs index ff4e03fc64..19c0677075 100644 --- a/tests/unit/out/unsafe/operator_traits.rs +++ b/tests/unit/out/unsafe/operator_traits.rs @@ -66,14 +66,14 @@ impl std::cmp::Eq for Lt {} pub struct Eq { pub v: i32, } -impl Eq { - pub unsafe fn operator_eq(&self, o: *const Eq) -> bool { +impl WeaklyEqualityComparableWithUnsafe for Eq { + unsafe fn equal(&self, o: *const Eq) -> bool { return ((self.v) == ((*o).v)); } } impl std::cmp::PartialEq for Eq { fn eq(&self, other: &Self) -> bool { - unsafe { Eq::operator_eq(self, other as *const Eq) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Eq) } } } impl std::cmp::Eq for Eq {} @@ -95,7 +95,9 @@ impl Cmp { pub unsafe fn operator_cmp(&self, o: *const Cmp) -> std::cmp::Ordering { return std::cmp::Ord::cmp(&(self.v), &((*o).v)); } - pub unsafe fn operator_eq(&self, o: *const Cmp) -> bool { +} +impl WeaklyEqualityComparableWithUnsafe for Cmp { + unsafe fn equal(&self, o: *const Cmp) -> bool { return ((self.v) == ((*o).v)); } } @@ -111,7 +113,7 @@ impl std::cmp::PartialOrd for Cmp { } impl std::cmp::PartialEq for Cmp { fn eq(&self, other: &Self) -> bool { - unsafe { Cmp::operator_eq(self, other as *const Cmp) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Cmp) } } } impl std::cmp::Eq for Cmp {} @@ -149,15 +151,19 @@ impl std::cmp::PartialOrd for Free { } impl std::cmp::PartialEq for Free { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_1(self as *const Free, other as *const Free) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Free) } } } impl std::cmp::Eq for Free {} pub unsafe fn operator_lt_0(a: *const Free, b: *const Free) -> bool { return (((*a).v) < ((*b).v)); } -pub unsafe fn operator_eq_1(a: *const Free, b: *const Free) -> bool { - return (((*a).v) == ((*b).v)); +impl WeaklyEqualityComparableWithUnsafe for Free { + unsafe fn equal(&self, __rhs: *const Self) -> bool { + let a: *const Free = self as *const Free; + let b: *const Free = (&*__rhs) as *const Free; + return (((*a).v) == ((*b).v)); + } } #[repr(C)] #[derive( @@ -207,7 +213,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { eqs.begin() }; let mut __tmp_2 = { eqs.end() }; let mut __it = (__tmp_1).clone(); - while __it != __tmp_2 && *__it.iter_deref() != two { + while __it != __tmp_2 + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &two) + { __it.iter_inc(); } __it @@ -220,7 +228,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_3 = { eqs.begin() }; let mut __tmp_4 = { eqs.end() }; let mut __it = (__tmp_3).clone(); - while __it != __tmp_4 && *__it.iter_deref() != nine { + while __it != __tmp_4 + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &nine) + { __it.iter_inc(); } __it @@ -247,7 +257,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_6 = { cmps.begin() }; let mut __tmp_7 = { cmps.end() }; let mut __it = (__tmp_6).clone(); - while __it != __tmp_7 && *__it.iter_deref() != three { + while __it != __tmp_7 + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &three) + { __it.iter_inc(); } __it @@ -276,7 +288,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_9 = { frees.begin() }; let mut __tmp_10 = { frees.end() }; let mut __it = (__tmp_9).clone(); - while __it != __tmp_10 && *__it.iter_deref() != ftwo { + while __it != __tmp_10 + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &ftwo) + { __it.iter_inc(); } __it diff --git a/tests/unit/out/unsafe/size_t_ssize_t.rs b/tests/unit/out/unsafe/size_t_ssize_t.rs index bda3ad0366..28b7541040 100644 --- a/tests/unit/out/unsafe/size_t_ssize_t.rs +++ b/tests/unit/out/unsafe/size_t_ssize_t.rs @@ -222,7 +222,9 @@ pub unsafe fn size_t_in_rules_3() { let mut __tmp_12 = { v3.begin() }; let mut __tmp_13 = { v3.end() }; let mut __it = (__tmp_12).clone(); - while __it != __tmp_13 && *__it.iter_deref() != (k as u64) { + while __it != __tmp_13 + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &(k as u64)) + { __it.iter_inc(); } __it diff --git a/tests/unit/out/unsafe/sort_no_copy.rs b/tests/unit/out/unsafe/sort_no_copy.rs index fda45f4697..33d253a0c7 100644 --- a/tests/unit/out/unsafe/sort_no_copy.rs +++ b/tests/unit/out/unsafe/sort_no_copy.rs @@ -181,15 +181,19 @@ impl std::cmp::PartialOrd for Bag { } impl std::cmp::PartialEq for Bag { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_5(self as *const Bag, other as *const Bag) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Bag) } } } impl std::cmp::Eq for Bag {} pub unsafe fn operator_lt_4(a: *const Bag, b: *const Bag) -> bool { return (((*a).items.len()) < ((*b).items.len())); } -pub unsafe fn operator_eq_5(a: *const Bag, b: *const Bag) -> bool { - return (((*a).items.len()) == ((*b).items.len())); +impl WeaklyEqualityComparableWithUnsafe for Bag { + unsafe fn equal(&self, __rhs: *const Self) -> bool { + let a: *const Bag = self as *const Bag; + let b: *const Bag = (&*__rhs) as *const Bag; + return (((*a).items.len()) == ((*b).items.len())); + } } pub fn main() { unsafe { @@ -470,7 +474,12 @@ unsafe fn main_0() -> i32 { let mut __tmp_7 = { bag_vec.begin() }; let mut __tmp_8 = { bag_vec.end() }; let mut __it = (__tmp_7).clone(); - while __it != __tmp_8 && *__it.iter_deref() != bags[(1) as usize] { + while __it != __tmp_8 + && !WeaklyEqualityComparableWithUnsafe::equal( + &*__it.iter_deref(), + &bags[(1) as usize], + ) + { __it.iter_inc(); } __it diff --git a/tests/unit/out/unsafe/unboxed_conditional_iterator.rs b/tests/unit/out/unsafe/unboxed_conditional_iterator.rs index ac00d71ea8..4743c5d503 100644 --- a/tests/unit/out/unsafe/unboxed_conditional_iterator.rs +++ b/tests/unit/out/unsafe/unboxed_conditional_iterator.rs @@ -55,7 +55,12 @@ pub unsafe fn lehmer_3(mut sigma: *const u32, mut len: u32, mut code: *mut u32) let mut __tmp_0 = { items.begin() }; let mut __tmp_1 = { items.end() }; let mut __it = (__tmp_0).clone(); - while __it != __tmp_1 && *__it.iter_deref() != (*sigma.offset((i) as isize)) { + while __it != __tmp_1 + && !WeaklyEqualityComparableWithUnsafe::equal( + &*__it.iter_deref(), + &(*sigma.offset((i) as isize)), + ) + { __it.iter_inc(); } __it From f25479c5f3a720894fa38a5c9b39d0b69fc2b898 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 11:36:50 +0000 Subject: [PATCH 06/18] Receive raw pointer in unsafe instead of reference --- cpp2rust/converter/converter.cpp | 77 ++++-- cpp2rust/converter/converter.h | 2 +- cpp2rust/converter/converter_lib.h | 22 +- libcc2rs-macros/src/assign.rs | 2 +- libcc2rs-macros/src/constructor.rs | 26 +- libcc2rs-macros/src/cpp_from.rs | 4 +- libcc2rs-macros/src/destructor.rs | 4 +- libcc2rs-macros/src/initialization.rs | 2 +- libcc2rs/src/capture.rs | 19 +- libcc2rs/src/constructor.rs | 146 +++++------ libcc2rs/src/object.rs | 30 +-- libcc2rs/src/swap.rs | 15 +- rules/deque/tgt_unsafe.rs | 2 +- rules/iterator_category/shim.rs | 8 +- rules/map/shim.rs | 29 ++- rules/map/tgt_unsafe.rs | 2 +- rules/unique_ptr/shim.rs | 14 +- rules/vector/shim.rs | 29 ++- rules/vector/tgt_unsafe.rs | 2 +- .../out/unsafe/defaulted_move_cross_tu.rs | 21 +- .../unsafe/out_of_line_methods_cross_tu.rs | 44 ++-- .../template_method_late_instantiation.rs | 16 +- .../out/unsafe/p14-class-in-two-files.rs | 36 +-- .../p15-class-template-static-member.rs | 30 ++- .../out/unsafe/p15-function-template.rs | 28 ++- .../out/unsafe/p15-inline-function.rs | 26 +- .../out/unsafe/p15-inline-variable.rs | 30 ++- .../p16-default-argument-lambda-in-class.rs | 38 +-- .../unsafe/p16-lambda-in-inline-function.rs | 24 +- .../basic/basic.link/out/unsafe/basic.link.rs | 32 +-- .../out/unsafe/basic.scope.block.rs | 40 +-- .../out/unsafe/basic.scope.class.rs | 28 +-- .../out/unsafe/basic.scope.param.rs | 15 +- .../out/unsafe/basic.scope.pdecl.rs | 8 +- .../out/unsafe/basic.scope.scope.rs | 80 +++--- .../out/unsafe/basic.start.term-p1-exit.rs | 17 +- .../out/unsafe/basic.start.term.rs | 53 ++-- tests/std/basic/out/unsafe/basic.def.odr.rs | 125 +++++----- .../class.init/out/unsafe/class.base.init.rs | 6 +- .../class.conv/out/unsafe/class.conv.ctor.rs | 11 +- .../class.conv/out/unsafe/class.conv.fct.rs | 6 +- .../class.ctor/out/unsafe/class.copy.ctor.rs | 8 +- .../class.mem/out/unsafe/class.mem.general.rs | 35 +-- .../dcl.init/out/unsafe/dcl.init.general.rs | 22 +- .../dcl.meaning/out/unsafe/dcl.fct.default.rs | 45 ++-- .../expr.unary/out/unsafe/expr.unary.op.rs | 12 +- .../out/unsafe/expr.mptr.oper.rs | 4 +- .../expr.prim/out/unsafe/expr.prim.this.rs | 31 ++- .../unsafe/allocator.requirements.general.rs | 4 +- .../stmt.iter/out/unsafe/stmt.while.rs | 29 ++- .../stmt.select/out/unsafe/stmt.if.rs | 18 +- .../stmt.select/out/unsafe/stmt.switch.rs | 28 ++- .../temp/temp.spec/out/unsafe/temp.inst.rs | 12 +- .../utility/out/unsafe/forward-helpers.rs | 82 +++---- .../utilities/utility/out/unsafe/forward.rs | 8 +- .../utility/out/unsafe/utility.as.const.rs | 12 +- tests/ub/out/unsafe/ctor_ref_member.rs | 4 +- tests/unit/out/unsafe/05_new.rs | 2 +- tests/unit/out/unsafe/10_struct.rs | 18 +- tests/unit/out/unsafe/any.rs | 10 +- .../out/unsafe/array_of_noncopy_struct.rs | 8 +- tests/unit/out/unsafe/as_const.rs | 24 +- .../unit/out/unsafe/assignment_single_eval.rs | 10 +- tests/unit/out/unsafe/cast.rs | 6 +- tests/unit/out/unsafe/class.rs | 84 +++---- .../out/unsafe/class_template_lazy_member.rs | 24 +- tests/unit/out/unsafe/class_templates.rs | 162 ++++++------ tests/unit/out/unsafe/clone_vs_move.rs | 2 +- tests/unit/out/unsafe/complex_function.rs | 113 ++++++--- tests/unit/out/unsafe/concepts.rs | 2 +- tests/unit/out/unsafe/constexpr_function.rs | 12 +- tests/unit/out/unsafe/constructor.rs | 42 ++-- tests/unit/out/unsafe/container_field_addr.rs | 8 +- .../conversion_operator_same_translation.rs | 27 +- tests/unit/out/unsafe/copy_assign.rs | 171 +++++++------ tests/unit/out/unsafe/copy_ctor.rs | 94 +++---- tests/unit/out/unsafe/copy_move_defaulted.rs | 232 +++++++++--------- tests/unit/out/unsafe/copy_move_deleted.rs | 46 ++-- .../out/unsafe/default_function_arguments.rs | 30 +-- tests/unit/out/unsafe/delete_array_order.rs | 8 +- tests/unit/out/unsafe/destructor.rs | 40 +-- tests/unit/out/unsafe/destructor_params.rs | 16 +- .../unit/out/unsafe/destructor_temporaries.rs | 28 +-- tests/unit/out/unsafe/doubly_linked_list.rs | 12 +- tests/unit/out/unsafe/enum_underlying_type.rs | 4 +- tests/unit/out/unsafe/exprs.rs | 14 +- .../unit/out/unsafe/field_method_receiver.rs | 62 ++--- tests/unit/out/unsafe/field_pointers.rs | 34 +-- tests/unit/out/unsafe/find.rs | 4 +- tests/unit/out/unsafe/fn_ptr.rs | 4 +- tests/unit/out/unsafe/fn_ptr_struct.rs | 27 +- tests/unit/out/unsafe/fn_ref.rs | 6 +- tests/unit/out/unsafe/for_body_destructor.rs | 38 +-- .../unsafe/foreach_disjoint_field_borrow.rs | 6 +- tests/unit/out/unsafe/forward_basic.rs | 42 ++-- tests/unit/out/unsafe/forward_decltype.rs | 30 +-- tests/unit/out/unsafe/forward_explicit.rs | 30 +-- tests/unit/out/unsafe/forward_pack.rs | 38 +-- tests/unit/out/unsafe/function_overloading.rs | 20 +- .../out/unsafe/global_init_side_effect.rs | 6 +- .../unit/out/unsafe/global_non_const_init.rs | 26 +- tests/unit/out/unsafe/huffman.rs | 104 ++++---- .../unsafe/immutable-deref-on-func-call.rs | 4 +- tests/unit/out/unsafe/implicit_autoref.rs | 4 +- .../out/unsafe/in_class_field_initializer.rs | 22 +- tests/unit/out/unsafe/init_list.rs | 16 +- .../out/unsafe/inline_container_fields.rs | 44 ++-- tests/unit/out/unsafe/kruskal.rs | 68 ++--- tests/unit/out/unsafe/lambda_as_field.rs | 51 ++-- .../out/unsafe/lambda_capture_copy_ctor.rs | 58 ++--- .../out/unsafe/lambda_capture_star_this.rs | 30 +-- tests/unit/out/unsafe/lambda_capture_this.rs | 30 +-- tests/unit/out/unsafe/lambda_decltype_type.rs | 56 ++--- .../unit/out/unsafe/lambda_immediate_init.rs | 6 +- .../out/unsafe/lambda_move_only_capture.rs | 33 ++- tests/unit/out/unsafe/lambda_nested.rs | 6 +- .../out/unsafe/libc_struct_without_default.rs | 6 +- tests/unit/out/unsafe/linked_list.rs | 6 +- tests/unit/out/unsafe/map.rs | 18 +- tests/unit/out/unsafe/map_key_copy_ctor.rs | 24 +- tests/unit/out/unsafe/map_key_identity.rs | 6 +- tests/unit/out/unsafe/map_try_emplace.rs | 52 ++-- .../out/unsafe/map_try_emplace_lvalues.rs | 122 ++++----- tests/unit/out/unsafe/max.rs | 18 +- tests/unit/out/unsafe/move_assign.rs | 56 +++-- tests/unit/out/unsafe/move_ctor.rs | 80 +++--- tests/unit/out/unsafe/move_this.rs | 51 ++-- .../unsafe/nttp_distinct_specializations.rs | 18 +- .../out/unsafe/operator_arithmetic_member.rs | 80 +++--- .../out/unsafe/operator_bitwise_member.rs | 36 +-- .../unsafe/operator_comparison_defaulted.rs | 132 +++++----- .../out/unsafe/operator_comparison_member.rs | 44 ++-- .../out/unsafe/operator_comparison_mixed.rs | 36 +-- .../out/unsafe/operator_comparison_nonbool.rs | 54 ++-- .../unsafe/operator_comparison_noncopyable.rs | 4 +- .../operator_compound_assignment_member.rs | 95 +++---- tests/unit/out/unsafe/operator_less_than.rs | 16 +- .../out/unsafe/operator_logical_member.rs | 24 +- .../unsafe/operator_member_pointer_member.rs | 38 +-- .../unit/out/unsafe/operator_other_member.rs | 46 ++-- tests/unit/out/unsafe/operator_overloads.rs | 44 ++-- tests/unit/out/unsafe/operator_qualifiers.rs | 52 ++-- tests/unit/out/unsafe/operator_three_way.rs | 22 +- tests/unit/out/unsafe/operator_traits.rs | 16 +- tests/unit/out/unsafe/overload_mangling.rs | 142 ++++++----- .../unsafe/pair_converting_construction.rs | 84 +++---- tests/unit/out/unsafe/pointers.rs | 22 +- tests/unit/out/unsafe/polymorphism.rs | 2 +- tests/unit/out/unsafe/push_emplace_back.rs | 56 ++--- tests/unit/out/unsafe/random.rs | 32 +-- tests/unit/out/unsafe/rule_of_five.rs | 52 ++-- tests/unit/out/unsafe/rule_of_three.rs | 30 +-- tests/unit/out/unsafe/rvalue_rule_arg_move.rs | 12 +- tests/unit/out/unsafe/rvalue_struct.rs | 6 +- .../unsafe/self_referencing_initializer.rs | 6 +- .../unit/out/unsafe/size_t_template_param.rs | 8 +- tests/unit/out/unsafe/sort_no_copy.rs | 76 +++--- tests/unit/out/unsafe/static_local.rs | 2 +- tests/unit/out/unsafe/static_var_in_class.rs | 4 +- tests/unit/out/unsafe/stdcopy.rs | 6 +- tests/unit/out/unsafe/struct_ctor.rs | 34 +-- tests/unit/out/unsafe/struct_default_ctor.rs | 20 +- .../unsafe/structured_binding_copy_ctor.rs | 18 +- .../unsafe/structured_binding_element_ctor.rs | 34 +-- .../unsafe/structured_binding_move_ctor.rs | 34 +-- tests/unit/out/unsafe/swap_map_no_copy.rs | 150 +++++------ tests/unit/out/unsafe/template_default_arg.rs | 44 ++-- tests/unit/out/unsafe/temporary_field_addr.rs | 20 +- .../out/unsafe/temporary_field_ctor_arg.rs | 10 +- .../out/unsafe/temporary_field_two_args.rs | 14 +- tests/unit/out/unsafe/this.rs | 144 +++++------ tests/unit/out/unsafe/typedef-anon-struct.rs | 4 +- tests/unit/out/unsafe/unboxed_records.rs | 10 +- tests/unit/out/unsafe/unique_ptr.rs | 24 +- .../unit/out/unsafe/unique_ptr_const_deref.rs | 4 +- .../unit/out/unsafe/unique_ptr_field_reset.rs | 17 +- tests/unit/out/unsafe/unique_ptr_nested.rs | 4 +- tests/unit/out/unsafe/va_list_field.rs | 10 +- tests/unit/out/unsafe/vector.rs | 10 +- tests/unit/out/unsafe/vector2.rs | 2 +- .../unit/out/unsafe/vector_iter_range_ctor.rs | 8 +- .../out/unsafe/vector_subscript_direct.rs | 12 +- .../unit/out/unsafe/vector_with_allocator.rs | 8 +- tests/unit/out/unsafe/void_cast.rs | 8 +- 184 files changed, 3135 insertions(+), 2901 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index d876129cd9..72af86963a 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -816,11 +816,10 @@ void Converter::EmitScopedDestructor(const clang::VarDecl *decl) { if (!NeedsScopedDestructor(decl)) { return; } - StrCat( - token::kSemiColon, - std::format("let _dtor_{0} = std::mem::DropGuard::new(&raw mut {0}, " - "|__p| unsafe {{ DestructibleUnsafe::destroy(&mut *__p) }})", - GetNamedDeclAsString(decl))); + StrCat(token::kSemiColon, + std::format("let _dtor_{0} = std::mem::DropGuard::new(&raw mut {0}, " + "|__p| unsafe {{ DestructibleUnsafe::destroy(__p) }})", + GetNamedDeclAsString(decl))); } bool Converter::RecordDerivesDefault(const clang::RecordDecl *decl) { @@ -1087,7 +1086,7 @@ void Converter::AddAssignmentTraits(const clang::CXXRecordDecl *decl) { std::string Converter::GetAssignmentTraitSignature(const RecordTrait &trait) const { - return std::format("unsafe fn {}(&mut self, src: {} Self) -> *mut Self", + return std::format("unsafe fn {}(this: *mut Self, src: {} Self) -> *mut Self", trait.method, &trait == &kMoveAssignable ? "*mut" : "*const"); } @@ -1154,7 +1153,8 @@ std::string Converter::DestroyMembers(const clang::CXXRecordDecl *decl) { std::string out; for (auto *field : FieldsToDestroy(decl)) { auto name = GetNamedDeclAsString(field); - out += std::format("DestructibleUnsafe::destroy(&mut self.{});\n", name); + out += std::format("DestructibleUnsafe::destroy(&raw mut (*this).{});\n", + name); } return out; } @@ -1385,7 +1385,11 @@ bool Converter::ConvertCXXMethodDecl(clang::CXXMethodDecl *decl) { } std::string Converter::GetSelfMaybeWithMut(const clang::CXXMethodDecl *decl) { - return MethodNeedsMutableReceiver(decl) ? "&mut self" : "&self"; + bool is_mut = MethodNeedsMutableReceiver(decl); + if (GetRecordTrait(decl) || IsMethodOnPtr(decl)) { + return is_mut ? "this: *mut Self" : "this: *const Self"; + } + return is_mut ? "&mut self" : "&self"; } std::string Converter::GetCtorName(clang::CXXConstructorDecl *decl) { @@ -1486,7 +1490,7 @@ void Converter::EmitConstructorFieldInits(clang::CXXConstructorDecl *decl) { std::string Converter::ConvertConstructorFieldWrite(const std::string &field_name, const std::string &value) { - return std::format("(&raw mut self.{}).write({});", field_name, value); + return std::format("(&raw mut (*this).{}).write({});", field_name, value); } bool Converter::VisitFieldDecl(clang::FieldDecl *decl) { @@ -4282,14 +4286,26 @@ bool Converter::VisitMemberExpr(clang::MemberExpr *expr) { void Converter::SetUFCSReceiver(clang::Expr *base, bool is_arrow, const clang::CXXMethodDecl *method) { + bool is_mut = MethodNeedsMutableReceiver(method); + bool takes_pointer = GetRecordTrait(method) || IsMethodOnPtr(method); if (clang::isa(base->IgnoreParenImpCasts()) && !AsLambdaOperatorCall(curr_function_)) { - ufcs_receiver_ = keyword::kSelfValue; - return; + if (takes_pointer) { + ufcs_receiver_ = ConvertFreshRValue(base); + return; + } + if (!ThisIsRustPtr()) { + ufcs_receiver_ = keyword::kSelfValue; + return; + } } Buffer buf(*this); PushExprKind push(*this, ExprKind::LValue); - StrCat(MethodNeedsMutableReceiver(method) ? "&mut" : "&"); + if (takes_pointer && (is_arrow || !IsTemporaryObject(ctx_, base))) { + StrCat(is_mut ? "&raw mut" : "&raw const"); + } else { + StrCat(is_mut ? "&mut" : "&"); + } if (is_arrow) { ConvertArrow(base); } else { @@ -4377,6 +4393,12 @@ const clang::Expr *Converter::GetFieldReadCall(const clang::MemberExpr *expr) { return clang::isa(base) ? base : nullptr; } +bool Converter::ThisIsRustPtr() const { + auto *method = clang::dyn_cast_or_null(curr_function_); + return method && (GetRecordTrait(method) || IsMethodOnPtr(method) || + clang::isa(method)); +} + bool Converter::VisitCXXThisExpr(clang::CXXThisExpr *expr) { if (auto field = AsLambdaCaptureThis(curr_function_)) { auto name = GetNamedDeclAsString(field); @@ -4385,7 +4407,9 @@ bool Converter::VisitCXXThisExpr(clang::CXXThisExpr *expr) { : std::format("(&raw mut {})", name)); return false; } - { + if (ThisIsRustPtr()) { + StrCat("this"); + } else { PushParen paren(*this); StrCat(keyword::kSelfValue, keyword::kAs, ToString(expr->getType())); } @@ -4660,7 +4684,7 @@ bool Converter::VisitCXXNewExpr(clang::CXXNewExpr *expr) { std::format("let __p: *mut {0} = Box::leak(Box::new(<{0}>::" "zero_init()));", GetRecordName(construct->getType()->getAsCXXRecordDecl()))); - ConstructInPlace(expr->getInitializer(), construct, "&mut *__p"); + ConstructInPlace(expr->getInitializer(), construct, "__p"); StrCat("__p"); } else if (pointee) { StrCat( @@ -4700,10 +4724,10 @@ bool Converter::VisitCXXDeleteExpr(clang::CXXDeleteExpr *expr) { StrCat( std::format("for __i in (0..libcc2rs::malloc_usable_size(__p as *mut " "::libc::c_void) / ::std::mem::size_of::<{0}>()).rev() {{ " - "DestructibleUnsafe::destroy(&mut *__p.add(__i)); }}", + "DestructibleUnsafe::destroy(__p.add(__i)); }}", record_name)); } else { - StrCat("DestructibleUnsafe::destroy(&mut *__p)", token::kSemiColon); + StrCat("DestructibleUnsafe::destroy(__p)", token::kSemiColon); } EmitDeallocation(expr, "__p"); return false; @@ -4865,11 +4889,9 @@ std::string Converter::ConvertObjectOperand(clang::Expr *expr, bool is_arrow) { return std::move(buf).str(); } -const char *Converter::GetConstructorSelf() const { return "&mut self"; } +const char *Converter::GetConstructorSelf() const { return "this: *mut Self"; } -const char *Converter::GetConstructorWrite() const { - return "(self as *mut Self).write"; -} +const char *Converter::GetConstructorWrite() const { return "this.write"; } std::string Converter::GetConstructorPath(const clang::CXXConstructorDecl *ctor) const { @@ -4886,14 +4908,14 @@ std::string Converter::CreatePlacementStorage(const std::string &record_name, } std::string Converter::GetPlacementReceiver(std::string_view name) const { - return std::format("&mut {}", name); + return std::format("&raw mut {}", name); } std::string Converter::GetFieldPlacementReceiver(std::string_view field) const { - return std::format("&mut self.{}", field); + return std::format("&raw mut (*this).{}", field); } -const char *Converter::GetDelegatingReceiver() const { return "&mut *self"; } +const char *Converter::GetDelegatingReceiver() const { return "this"; } bool Converter::CanConstructVarInPlace(const clang::VarDecl *decl) const { return true; @@ -4901,9 +4923,7 @@ bool Converter::CanConstructVarInPlace(const clang::VarDecl *decl) const { const char *Converter::TakePlacementValue() const { return "__v"; } -const char *Converter::GetReturnSlotReceiver() const { - return "&mut *__return"; -} +const char *Converter::GetReturnSlotReceiver() const { return "__return"; } std::string Converter::GetReturnSlotArg(std::string_view receiver) const { return std::string(receiver); @@ -5878,7 +5898,10 @@ std::string Converter::GetComparisonReceiver(const clang::CXXMethodDecl *method, if (!MethodNeedsMutableReceiver(method)) { return std::string(lhs); } - return std::format("&mut *(&raw const *{}).cast_mut()", lhs); + if (!IsMethodOnPtr(method)) { + return std::format("&mut *(&raw const *{}).cast_mut()", lhs); + } + return std::format("(&raw const *{}).cast_mut()", lhs); } std::string Converter::GetEqBody(const clang::CXXRecordDecl *decl, diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index 4a7fc6d8e6..ef5f2b43a6 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -244,7 +244,7 @@ class Converter : public clang::RecursiveASTVisitor { virtual std::string GetUFCSName(const clang::CXXMethodDecl *method) const; - virtual bool ThisIsRustPtr() const { return false; } + virtual bool ThisIsRustPtr() const; void ConvertCXXConstructorBody(clang::CXXConstructorDecl *decl); // The object that decl constructs, before its body runs. diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index 0ef8b0845a..c89d862b37 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -121,36 +121,36 @@ inline constexpr RecordTrait kDefaultConstructible{ "default_constructor", {"DefaultConstructible", "fn default_constructor(this: Ptr)", "this.clone()"}, - {"DefaultConstructibleUnsafe", "unsafe fn default_constructor(&mut self)", - "&mut *self"}}; + {"DefaultConstructibleUnsafe", + "unsafe fn default_constructor(this: *mut Self)", "this"}}; inline constexpr RecordTrait kCopyConstructible{ "copy_constructor", {"CopyConstructible", "fn copy_constructor(this: Ptr, _: Ptr)", "this.clone()"}, {"CopyConstructibleUnsafe", - "unsafe fn copy_constructor(&mut self, _: *const Self)", "&mut *self"}}; + "unsafe fn copy_constructor(this: *mut Self, _: *const Self)", "this"}}; inline constexpr RecordTrait kMoveConstructible{ "move_constructor", {"MoveConstructible", "fn move_constructor(this: Ptr, _: Ptr)", "this.clone()"}, {"MoveConstructibleUnsafe", - "unsafe fn move_constructor(&mut self, _: *mut Self)", "&mut *self"}}; + "unsafe fn move_constructor(this: *mut Self, _: *mut Self)", "this"}}; inline constexpr RecordTrait kCopyAssignable{ "copy_assign", {"CopyAssignable", "fn copy_assign(this: Ptr, _: Ptr) -> Ptr", "this.clone()"}, {"CopyAssignableUnsafe", - "unsafe fn copy_assign(&mut self, _: *const Self) -> *mut Self", - "&mut *self"}}; + "unsafe fn copy_assign(this: *mut Self, _: *const Self) -> *mut Self", + "this"}}; inline constexpr RecordTrait kMoveAssignable{ "move_assign", {"MoveAssignable", "fn move_assign(this: Ptr, _: Ptr) -> Ptr", "this.clone()"}, {"MoveAssignableUnsafe", - "unsafe fn move_assign(&mut self, _: *mut Self) -> *mut Self", - "&mut *self"}}; + "unsafe fn move_assign(this: *mut Self, _: *mut Self) -> *mut Self", + "this"}}; // The construction from a source, which picks the copy or the move // constructor from the type of the source. inline constexpr RecordTrait kConstructFrom{ @@ -158,12 +158,12 @@ inline constexpr RecordTrait kConstructFrom{ inline constexpr RecordTrait kSwappable{ "swap", {"Swappable", "fn swap(this: Ptr, _: Ptr)", "this.clone()"}, - {"SwappableUnsafe", "unsafe fn swap(&mut self, _: *mut Self)", - "&mut *self"}}; + {"SwappableUnsafe", "unsafe fn swap(this: *mut Self, _: *mut Self)", + "this"}}; inline constexpr RecordTrait kDestructible{ "destroy", {"Destructible", "fn destroy(this: Ptr)", "this.clone()"}, - {"DestructibleUnsafe", "unsafe fn destroy(&mut self)", "&mut *self"}}; + {"DestructibleUnsafe", "unsafe fn destroy(this: *mut Self)", "this"}}; inline constexpr RecordTrait kTriviallyDefaultConstructible{ nullptr, {"TriviallyDefaultConstructible"}, diff --git a/libcc2rs-macros/src/assign.rs b/libcc2rs-macros/src/assign.rs index 6cb0988342..a374c0b6f1 100644 --- a/libcc2rs-macros/src/assign.rs +++ b/libcc2rs-macros/src/assign.rs @@ -41,7 +41,7 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { quote! { unsafe { let #src_name = #src; - ::libcc2rs::AssignFromUnsafe::assign_from(&mut #left, #src_name) + ::libcc2rs::AssignFromUnsafe::assign_from(&raw mut #left, #src_name) } } } else { diff --git a/libcc2rs-macros/src/constructor.rs b/libcc2rs-macros/src/constructor.rs index c3e4857478..33d68ff76a 100644 --- a/libcc2rs-macros/src/constructor.rs +++ b/libcc2rs-macros/src/constructor.rs @@ -55,10 +55,10 @@ pub fn expand_default_constructible(input: TokenStream, is_unsafe: bool) -> Toke if is_unsafe { quote! { impl #impl_generics ::libcc2rs::DefaultConstructibleUnsafe for #name #ty_generics #where_clause { - unsafe fn default_constructor(&mut self) { + unsafe fn default_constructor(this: *mut Self) { unsafe { ::std::ptr::write( - self, + this, ::zero_init(), ) } @@ -88,8 +88,8 @@ fn impl_swap(input: &DeriveInput, is_unsafe: bool) -> TokenStream2 { if is_unsafe { quote! { impl #impl_generics ::libcc2rs::SwappableUnsafe for #name #ty_generics #where_clause { - unsafe fn swap(&mut self, other: *mut Self) { - unsafe { ::libcc2rs::swap_by_move_unsafe(self, other) } + unsafe fn swap(this: *mut Self, other: *mut Self) { + unsafe { ::libcc2rs::swap_by_move_unsafe(this, other) } } } } @@ -144,14 +144,14 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - quote!(*const Self) }; let body = if is_move { - quote!(unsafe { ::libcc2rs::#copy_trait::#copy_method(self, src) }) + quote!(unsafe { ::libcc2rs::#copy_trait::#copy_method(this, src) }) } else if is_assign { quote! { - unsafe { *self = (*src).clone() }; - self + unsafe { *this = (*src).clone() }; + this } } else { - quote!(unsafe { ::std::ptr::write(self, (*src).clone()) }) + quote!(unsafe { ::std::ptr::write(this, (*src).clone()) }) }; let ret = if is_assign { quote!(-> *mut Self) @@ -160,7 +160,7 @@ fn impl_trait(input: &DeriveInput, op: &str, is_assign: bool, is_unsafe: bool) - }; quote! { impl #impl_generics ::libcc2rs::#trait_name for #name #ty_generics #where_clause { - unsafe fn #method(&mut self, src: #src_ty) #ret { + unsafe fn #method(this: *mut Self, src: #src_ty) #ret { #body } } @@ -269,7 +269,7 @@ pub fn expand_trivially_copyable(input: TokenStream, is_unsafe: bool) -> TokenSt let destroy = if is_unsafe { quote! { impl #impl_generics ::libcc2rs::DestructibleUnsafe for #name #ty_generics #where_clause { - unsafe fn destroy(&mut self) {} + unsafe fn destroy(_: *mut Self) {} } } } else { @@ -362,14 +362,14 @@ fn impl_memberwise( (quote!(*const Self), quote!(&raw const)) }; let (ret, tail) = if is_assign { - (quote!(-> *mut Self), quote!(self)) + (quote!(-> *mut Self), quote!(this)) } else { (quote!(), quote!()) }; return quote! { impl #impl_generics #tr for #name #ty_generics #where_clause { - unsafe fn #method(&mut self, src: #src_ty) #ret { - #(unsafe { #tr::#method(&mut self.#members, #src_field (*src).#members) };)* + unsafe fn #method(this: *mut Self, src: #src_ty) #ret { + #(unsafe { #tr::#method(&raw mut (*this).#members, #src_field (*src).#members) };)* #tail } } diff --git a/libcc2rs-macros/src/cpp_from.rs b/libcc2rs-macros/src/cpp_from.rs index 0119a6ff9f..92bfec834b 100644 --- a/libcc2rs-macros/src/cpp_from.rs +++ b/libcc2rs-macros/src/cpp_from.rs @@ -178,9 +178,9 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { let self_ty = quote!(#name #ty_generics); let src = pointer(&syn::parse_quote!(#self_ty), false); let body = if is_unsafe && matches!(conversion.kind, Kind::MutPtr) { - quote!((*src.cast_mut()).#op()) + quote!(#name::#op(src.cast_mut())) } else if is_unsafe { - quote!((*src).#op()) + quote!(#name::#op(src)) } else { quote!(#name::#op(src)) }; diff --git a/libcc2rs-macros/src/destructor.rs b/libcc2rs-macros/src/destructor.rs index 7461f8fd5e..442354bafa 100644 --- a/libcc2rs-macros/src/destructor.rs +++ b/libcc2rs-macros/src/destructor.rs @@ -30,8 +30,8 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { let destroy = if is_unsafe { quote! { impl #impl_generics ::libcc2rs::DestructibleUnsafe for #name #ty_generics #where_clause { - unsafe fn destroy(&mut self) { - #(unsafe { ::libcc2rs::DestructibleUnsafe::destroy(&mut self.#destroyed) };)* + unsafe fn destroy(this: *mut Self) { + #(unsafe { ::libcc2rs::DestructibleUnsafe::destroy(&raw mut (*this).#destroyed) };)* } } } diff --git a/libcc2rs-macros/src/initialization.rs b/libcc2rs-macros/src/initialization.rs index 6f26112d12..cc7eb3c7cf 100644 --- a/libcc2rs-macros/src/initialization.rs +++ b/libcc2rs-macros/src/initialization.rs @@ -78,7 +78,7 @@ pub(crate) fn construct( if is_unsafe { quote! {{ let mut __v: Self = ::zero_init(); - #name::#method(&mut __v, #args); + #name::#method(&raw mut __v, #args); __v }} } else { diff --git a/libcc2rs/src/capture.rs b/libcc2rs/src/capture.rs index 369e9db11e..b1fcc4473d 100644 --- a/libcc2rs/src/capture.rs +++ b/libcc2rs/src/capture.rs @@ -39,7 +39,7 @@ pub trait Destructible: Sized { pub trait DestructibleUnsafe: Sized { /// # Safety /// `self` must be a live value. - unsafe fn destroy(&mut self); + unsafe fn destroy(this: *mut Self); } pub trait TriviallyDestructible: Destructible {} @@ -55,8 +55,8 @@ impl Destructible for FnPtr { impl TriviallyDestructible for FnPtr {} impl DestructibleUnsafe for FnPtr { - unsafe fn destroy(&mut self) { - FnPtr::destroy(self) + unsafe fn destroy(this: *mut Self) { + unsafe { FnPtr::destroy(&*this) } } } @@ -74,9 +74,10 @@ impl Destructible for Box<[T]> { impl TriviallyDestructible for Box<[T]> {} impl DestructibleUnsafe for [T; N] { - unsafe fn destroy(&mut self) { - for elem in self.iter_mut().rev() { - unsafe { DestructibleUnsafe::destroy(elem) } + unsafe fn destroy(this: *mut Self) { + let elems = this as *mut T; + for i in (0..N).rev() { + unsafe { DestructibleUnsafe::destroy(elems.add(i)) } } } } @@ -227,7 +228,7 @@ impl CopyLambdaUnsafe> for &&&CaptureUnsafe> { unsafe fn copy_capture(&self) -> FnPtr { let mut dst = std::mem::MaybeUninit::>::uninit(); unsafe { - (*dst.as_mut_ptr()).copy_constructor(self.0); + CopyConstructibleUnsafe::copy_constructor(dst.as_mut_ptr(), self.0); dst.assume_init() } } @@ -251,7 +252,7 @@ impl CopyCtorUnsafe for &CaptureUnsafe { unsafe fn copy_capture(&self) -> T { let mut dst = std::mem::MaybeUninit::::uninit(); unsafe { - (*dst.as_mut_ptr()).copy_constructor(self.0); + T::copy_constructor(dst.as_mut_ptr(), self.0); dst.assume_init() } } @@ -275,7 +276,7 @@ impl MoveWithCtorUnsafe for &&CaptureUnsafe { unsafe fn move_capture(&self) -> T { let mut dst = std::mem::MaybeUninit::::uninit(); unsafe { - (*dst.as_mut_ptr()).move_constructor(self.0); + T::move_constructor(dst.as_mut_ptr(), self.0); dst.assume_init() } } diff --git a/libcc2rs/src/constructor.rs b/libcc2rs/src/constructor.rs index f3c1086467..1cbedde0c1 100644 --- a/libcc2rs/src/constructor.rs +++ b/libcc2rs/src/constructor.rs @@ -140,7 +140,7 @@ impl< pub trait DefaultConstructibleUnsafe { /// # Safety /// `self` must be valid for writes. - unsafe fn default_constructor(&mut self); + unsafe fn default_constructor(this: *mut Self); // TODO: remove default_constructed. fn default_constructed() -> Self @@ -149,7 +149,7 @@ pub trait DefaultConstructibleUnsafe { { let mut dst = std::mem::MaybeUninit::::zeroed(); unsafe { - (*dst.as_mut_ptr()).default_constructor(); + Self::default_constructor(dst.as_mut_ptr()); dst.assume_init() } } @@ -158,13 +158,13 @@ pub trait DefaultConstructibleUnsafe { pub trait MoveConstructibleUnsafe { /// # Safety /// `src` must point to a live value. - unsafe fn move_constructor(&mut self, src: *mut Self); + unsafe fn move_constructor(this: *mut Self, src: *mut Self); } pub trait CopyConstructibleUnsafe: MoveConstructibleUnsafe { /// # Safety /// `src` must point to a live value. - unsafe fn copy_constructor(&mut self, src: *const Self); + unsafe fn copy_constructor(this: *mut Self, src: *const Self); } pub trait TriviallyMoveConstructibleUnsafe: MoveConstructibleUnsafe { @@ -182,7 +182,7 @@ pub trait TriviallyCopyConstructibleUnsafe: CopyConstructibleUnsafe { pub trait CopyAssignableUnsafe: MoveAssignableUnsafe { /// # Safety /// `src` must point to a live value. - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self; + unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self; } pub trait TriviallyCopyAssignableUnsafe: CopyAssignableUnsafe {} @@ -190,7 +190,7 @@ pub trait TriviallyCopyAssignableUnsafe: CopyAssignableUnsafe {} pub trait MoveAssignableUnsafe { /// # Safety /// `src` must point to a live value. - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self; + unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self; } pub trait TriviallyMoveAssignableUnsafe: MoveAssignableUnsafe {} @@ -198,7 +198,7 @@ pub trait TriviallyMoveAssignableUnsafe: MoveAssignableUnsafe {} pub trait SwappableUnsafe { /// # Safety /// `other` must point to a live value. - unsafe fn swap(&mut self, other: *mut Self); + unsafe fn swap(this: *mut Self, other: *mut Self); } pub trait TriviallyDefaultConstructibleUnsafe: DefaultConstructibleUnsafe {} @@ -278,8 +278,8 @@ macro_rules! impl_copy_by_clone { where $ty: Clone, { - unsafe fn copy_constructor(&mut self, src: *const Self) { - unsafe { std::ptr::write(self, (*src).clone()) } + unsafe fn copy_constructor(this: *mut Self, src: *const Self) { + unsafe { std::ptr::write(this, (*src).clone()) } } } @@ -287,9 +287,9 @@ macro_rules! impl_copy_by_clone { where $ty: Clone, { - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { - unsafe { *self = (*src).clone() }; - self + unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self { + unsafe { *this = (*src).clone() }; + this } } )*}; @@ -326,8 +326,8 @@ macro_rules! impl_move_by_clone { where $ty: Clone, { - unsafe fn move_constructor(&mut self, src: *mut Self) { - unsafe { std::ptr::write(self, (*src).clone()) } + unsafe fn move_constructor(this: *mut Self, src: *mut Self) { + unsafe { std::ptr::write(this, (*src).clone()) } } } @@ -335,9 +335,9 @@ macro_rules! impl_move_by_clone { where $ty: Clone, { - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { - unsafe { *self = (*src).clone() }; - self + unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { + unsafe { *this = (*src).clone() }; + this } } @@ -351,8 +351,8 @@ macro_rules! impl_move_by_clone { } impl<$($param),*> $crate::SwappableUnsafe for $ty { - unsafe fn swap(&mut self, other: *mut Self) { - unsafe { std::ptr::swap(self, other) } + unsafe fn swap(this: *mut Self, other: *mut Self) { + unsafe { std::ptr::swap(this, other) } } } )*}; @@ -426,7 +426,7 @@ macro_rules! impl_trivially_copyable_by_clone { } impl<$($param),*> $crate::DestructibleUnsafe for $ty { - unsafe fn destroy(&mut self) {} + unsafe fn destroy(_this: *mut Self) {} } impl<$($param),*> $crate::capture::TriviallyDestructible for $ty {} @@ -481,8 +481,8 @@ macro_rules! impl_move_by_take { where $ty: Default, { - unsafe fn move_constructor(&mut self, src: *mut Self) { - unsafe { std::ptr::write(self, std::mem::take(&mut *src)) } + unsafe fn move_constructor(this: *mut Self, src: *mut Self) { + unsafe { std::ptr::write(this, std::mem::take(&mut *src)) } } } @@ -490,9 +490,9 @@ macro_rules! impl_move_by_take { where $ty: Default, { - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { - unsafe { *self = std::mem::take(&mut *src) }; - self + unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { + unsafe { *this = std::mem::take(&mut *src) }; + this } } @@ -506,8 +506,8 @@ macro_rules! impl_move_by_take { } impl<$($param),*> $crate::SwappableUnsafe for $ty { - unsafe fn swap(&mut self, other: *mut Self) { - unsafe { std::ptr::swap(self, other) } + unsafe fn swap(this: *mut Self, other: *mut Self) { + unsafe { std::ptr::swap(this, other) } } } )*}; @@ -517,8 +517,8 @@ pub(crate) use impl_move_by_take; macro_rules! impl_default_by_zeroed { ($($ty:ty),* $(,)?) => {$( impl $crate::DefaultConstructibleUnsafe for $ty { - unsafe fn default_constructor(&mut self) { - unsafe { std::ptr::write(self, std::mem::zeroed()) } + unsafe fn default_constructor(this: *mut Self) { + unsafe { std::ptr::write(this, std::mem::zeroed()) } } } @@ -544,8 +544,8 @@ macro_rules! impl_trivially_default_constructible { where $ty: Default, { - unsafe fn default_constructor(&mut self) { - unsafe { std::ptr::write(self, Self::default()) } + unsafe fn default_constructor(this: *mut Self) { + unsafe { std::ptr::write(this, Self::default()) } } } @@ -596,8 +596,8 @@ impl DefaultConstructible for FnPtr { } impl DefaultConstructibleUnsafe for FnPtr { - unsafe fn default_constructor(&mut self) { - unsafe { std::ptr::write(self, ::zero_init()) } + unsafe fn default_constructor(this: *mut Self) { + unsafe { std::ptr::write(this, ::zero_init()) } } } @@ -612,22 +612,23 @@ impl DefaultConstructible for Box<[T]> { } impl DefaultConstructibleUnsafe for [T; N] { - unsafe fn default_constructor(&mut self) { - for elem in self.iter_mut() { - unsafe { elem.default_constructor() } + unsafe fn default_constructor(this: *mut Self) { + let this = this as *mut T; + for i in 0..N { + unsafe { T::default_constructor(this.add(i)) } } } } impl DefaultConstructibleUnsafe for *mut T { - unsafe fn default_constructor(&mut self) { - unsafe { std::ptr::write(self, std::ptr::null_mut()) } + unsafe fn default_constructor(this: *mut Self) { + unsafe { std::ptr::write(this, std::ptr::null_mut()) } } } impl DefaultConstructibleUnsafe for *const T { - unsafe fn default_constructor(&mut self) { - unsafe { std::ptr::write(self, std::ptr::null()) } + unsafe fn default_constructor(this: *mut Self) { + unsafe { std::ptr::write(this, std::ptr::null()) } } } @@ -740,7 +741,7 @@ impl Destructible for (A, B) impl TriviallyDestructible for (A, B) {} impl DestructibleUnsafe for (A, B) { - unsafe fn destroy(&mut self) {} + unsafe fn destroy(_this: *mut Self) {} } impl TriviallyDestructibleUnsafe @@ -799,20 +800,20 @@ impl Swappable for FnPtr { } impl SwappableUnsafe for FnPtr { - unsafe fn swap(&mut self, other: *mut Self) { - unsafe { std::ptr::swap(self, other) } + unsafe fn swap(this: *mut Self, other: *mut Self) { + unsafe { std::ptr::swap(this, other) } } } impl MoveConstructibleUnsafe for FnPtr { - unsafe fn move_constructor(&mut self, src: *mut Self) { - unsafe { std::ptr::write(self, (*src).move_from()) } + unsafe fn move_constructor(this: *mut Self, src: *mut Self) { + unsafe { std::ptr::write(this, (*src).move_from()) } } } impl CopyConstructibleUnsafe for FnPtr { - unsafe fn copy_constructor(&mut self, src: *const Self) { - unsafe { std::ptr::write(self, (*src).copy_from()) } + unsafe fn copy_constructor(this: *mut Self, src: *const Self) { + unsafe { std::ptr::write(this, (*src).copy_from()) } } } @@ -829,16 +830,16 @@ impl TriviallyCopyConstructibleUnsafe for FnPtr { } impl MoveAssignableUnsafe for FnPtr { - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { - unsafe { *self = (*src).move_from() }; - self + unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { + unsafe { *this = (*src).move_from() }; + this } } impl CopyAssignableUnsafe for FnPtr { - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { - unsafe { *self = (*src).copy_from() }; - self + unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self { + unsafe { *this = (*src).copy_from() }; + this } } @@ -927,28 +928,31 @@ impl Swappable for Box<[T]> { } impl SwappableUnsafe for [T; N] { - unsafe fn swap(&mut self, other: *mut Self) { + unsafe fn swap(this: *mut Self, other: *mut Self) { let other = other as *mut T; - for (i, elem) in self.iter_mut().enumerate() { - unsafe { SwappableUnsafe::swap(elem, other.add(i)) } + let this = this as *mut T; + for i in 0..N { + unsafe { SwappableUnsafe::swap(this.add(i), other.add(i)) } } } } impl MoveConstructibleUnsafe for [T; N] { - unsafe fn move_constructor(&mut self, src: *mut Self) { + unsafe fn move_constructor(this: *mut Self, src: *mut Self) { let src = src as *mut T; - for (i, elem) in self.iter_mut().enumerate() { - unsafe { elem.move_constructor(src.add(i)) } + let this = this as *mut T; + for i in 0..N { + unsafe { T::move_constructor(this.add(i), src.add(i)) } } } } impl CopyConstructibleUnsafe for [T; N] { - unsafe fn copy_constructor(&mut self, src: *const Self) { + unsafe fn copy_constructor(this: *mut Self, src: *const Self) { let src = src as *const T; - for (i, elem) in self.iter_mut().enumerate() { - unsafe { elem.copy_constructor(src.add(i)) } + let this = this as *mut T; + for i in 0..N { + unsafe { T::copy_constructor(this.add(i), src.add(i)) } } } } @@ -972,22 +976,24 @@ impl TriviallyCopyConstruct } impl MoveAssignableUnsafe for [T; N] { - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { + unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { let src = src as *mut T; - for (i, elem) in self.iter_mut().enumerate() { - unsafe { elem.move_assign(src.add(i)) }; + let dst = this as *mut T; + for i in 0..N { + unsafe { T::move_assign(dst.add(i), src.add(i)) }; } - self + this } } impl CopyAssignableUnsafe for [T; N] { - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { + unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self { let src = src as *const T; - for (i, elem) in self.iter_mut().enumerate() { - unsafe { elem.copy_assign(src.add(i)) }; + let dst = this as *mut T; + for i in 0..N { + unsafe { T::copy_assign(dst.add(i), src.add(i)) }; } - self + this } } diff --git a/libcc2rs/src/object.rs b/libcc2rs/src/object.rs index 5904f815ce..fc0575a955 100644 --- a/libcc2rs/src/object.rs +++ b/libcc2rs/src/object.rs @@ -86,14 +86,14 @@ impl AssignFrom>> for Ptr { pub trait ConstructFromUnsafe { /// # Safety /// `src` must point to a live value. - unsafe fn construct_from(&mut self, src: S); + unsafe fn construct_from(this: *mut Self, src: S); } // The C++ operator= of self from src, in the unsafe model. pub trait AssignFromUnsafe { /// # Safety /// `src` must point to a live value. - unsafe fn assign_from(&mut self, src: S) -> *mut Self; + unsafe fn assign_from(this: *mut Self, src: S) -> *mut Self; } // The sources of the unsafe model: a reference or a raw pointer copies, and a @@ -102,15 +102,15 @@ macro_rules! unsafe_sources { ($($src:ty),*) => {$( impl<'a, T: CopyConstructibleUnsafe> ConstructFromUnsafe<$src> for T { #[inline(always)] - unsafe fn construct_from(&mut self, src: $src) { - unsafe { T::copy_constructor(self, src) } + unsafe fn construct_from(this: *mut Self, src: $src) { + unsafe { T::copy_constructor(this, src) } } } impl<'a, T: CopyAssignableUnsafe> AssignFromUnsafe<$src> for T { #[inline(always)] - unsafe fn assign_from(&mut self, src: $src) -> *mut T { - unsafe { T::copy_assign(self, src) } + unsafe fn assign_from(this: *mut Self, src: $src) -> *mut T { + unsafe { T::copy_assign(this, src) } } } )*}; @@ -122,15 +122,15 @@ macro_rules! unsafe_moved_sources { ($($src:ty),*) => {$( impl<'a, T: MoveConstructibleUnsafe> ConstructFromUnsafe> for T { #[inline(always)] - unsafe fn construct_from(&mut self, src: Moved<$src>) { - unsafe { T::move_constructor(self, src.0) } + unsafe fn construct_from(this: *mut Self, src: Moved<$src>) { + unsafe { T::move_constructor(this, src.0) } } } impl<'a, T: MoveAssignableUnsafe> AssignFromUnsafe> for T { #[inline(always)] - unsafe fn assign_from(&mut self, src: Moved<$src>) -> *mut T { - unsafe { T::move_assign(self, src.0) } + unsafe fn assign_from(this: *mut Self, src: Moved<$src>) -> *mut T { + unsafe { T::move_assign(this, src.0) } } } )*}; @@ -208,7 +208,7 @@ pub struct DestroyGuardUnsafe(*mut T); impl Drop for DestroyGuardUnsafe { #[inline(always)] fn drop(&mut self) { - unsafe { DestructibleUnsafe::destroy(&mut *self.0) } + unsafe { DestructibleUnsafe::destroy(self.0) } } } @@ -283,7 +283,7 @@ macro_rules! object_unsafe { let mut $name: $ty = <$ty as $crate::ZeroInitializationUnsafe>::zero_init(); #[allow(unused_unsafe)] unsafe { - <$ty>::$ctor(&mut $name, $($arg),*) + <$ty>::$ctor(&raw mut $name, $($arg),*) }; $crate::object_unsafe!(@guard $name); }; @@ -293,7 +293,7 @@ macro_rules! object_unsafe { ($name:ident, $ty:ty, |$this:ident| $init:expr) => { let mut $name: $ty = <$ty as $crate::ZeroInitializationUnsafe>::zero_init(); { - let $this: &mut $ty = &mut $name; + let $this: *mut $ty = &raw mut $name; $init; } $crate::object_unsafe!(@guard $name); @@ -302,7 +302,7 @@ macro_rules! object_unsafe { let mut $name: $ty = <$ty as $crate::ZeroInitializationUnsafe>::zero_init(); #[allow(unused_unsafe)] unsafe { - $crate::ConstructFromUnsafe::construct_from(&mut $name, $src) + $crate::ConstructFromUnsafe::construct_from(&raw mut $name, $src) }; $crate::object_unsafe!(@guard $name); }; @@ -310,7 +310,7 @@ macro_rules! object_unsafe { let mut $name: $ty = <$ty as $crate::ZeroInitializationUnsafe>::zero_init(); #[allow(unused_unsafe)] unsafe { - $crate::DefaultConstructibleUnsafe::default_constructor(&mut $name) + $crate::DefaultConstructibleUnsafe::default_constructor(&raw mut $name) }; $crate::object_unsafe!(@guard $name); }; diff --git a/libcc2rs/src/swap.rs b/libcc2rs/src/swap.rs index 9ecb361890..3928183a5a 100644 --- a/libcc2rs/src/swap.rs +++ b/libcc2rs/src/swap.rs @@ -73,7 +73,7 @@ pub(crate) fn copy_constructed_in_storage(src: *const T) -> T { let mut dst = std::mem::MaybeUninit::::uninit(); unsafe { - (*dst.as_mut_ptr()).copy_constructor(src); + T::copy_constructor(dst.as_mut_ptr(), src); dst.assume_init() } } @@ -81,7 +81,7 @@ pub unsafe fn copy_constructed_unsafe(src: *const T) pub unsafe fn move_constructed_unsafe(src: *mut T) -> T { let mut dst = std::mem::MaybeUninit::::uninit(); unsafe { - (*dst.as_mut_ptr()).move_constructor(src); + T::move_constructor(dst.as_mut_ptr(), src); dst.assume_init() } } @@ -164,16 +164,15 @@ where /// # Safety /// `other` must point to a live value. -pub unsafe fn swap_by_move_unsafe(this: &mut T, other: *mut T) +pub unsafe fn swap_by_move_unsafe(this: *mut T, other: *mut T) where T: MoveConstructibleUnsafe + MoveAssignableUnsafe + DestructibleUnsafe, { - let this: *mut T = this; let mut tmp = MaybeUninit::::uninit(); unsafe { - MoveConstructibleUnsafe::move_constructor(&mut *tmp.as_mut_ptr(), this); - MoveAssignableUnsafe::move_assign(&mut *this, other); - MoveAssignableUnsafe::move_assign(&mut *other, tmp.as_mut_ptr()); - DestructibleUnsafe::destroy(&mut *tmp.as_mut_ptr()); + MoveConstructibleUnsafe::move_constructor(tmp.as_mut_ptr(), this); + MoveAssignableUnsafe::move_assign(this, other); + MoveAssignableUnsafe::move_assign(other, tmp.as_mut_ptr()); + DestructibleUnsafe::destroy(tmp.as_mut_ptr()); } } diff --git a/rules/deque/tgt_unsafe.rs b/rules/deque/tgt_unsafe.rs index d2b5a47390..7ef71bfc24 100644 --- a/rules/deque/tgt_unsafe.rs +++ b/rules/deque/tgt_unsafe.rs @@ -59,7 +59,7 @@ unsafe fn f9(a0: &mut Vec) -> Vec { } unsafe fn f10<'a, T1: CopyConstructibleUnsafe>(a0: &'a mut Vec, a1: *const Vec) -> &'a mut Vec { - a0.assign_from(a1); + AssignFromUnsafe::assign_from(&raw mut *a0, a1); a0 } diff --git a/rules/iterator_category/shim.rs b/rules/iterator_category/shim.rs index 7fcaaeedd4..ee31e5ba33 100644 --- a/rules/iterator_category/shim.rs +++ b/rules/iterator_category/shim.rs @@ -7,7 +7,9 @@ use std::marker::PhantomData; use std::rc::Rc; -use crate::{ByteRepr, MapNode, PostfixDec, PostfixInc, PrefixDec, PrefixInc, Ptr, UnsafeMapNode, Value}; +use crate::{ + ByteRepr, MapNode, PostfixDec, PostfixInc, PrefixDec, PrefixInc, Ptr, UnsafeMapNode, Value, +}; pub trait CppIterator: Clone { fn iter_deref(&self) -> Ptr; @@ -42,9 +44,7 @@ pub trait UnsafeCppBidirectionalIterator: UnsafeCppInputIterator { fn iter_post_dec(&mut self) -> Self; } -pub trait UnsafeCppRandomAccessIterator: - UnsafeCppBidirectionalIterator + PartialOrd -{ +pub trait UnsafeCppRandomAccessIterator: UnsafeCppBidirectionalIterator + PartialOrd { fn iter_add(&self, n: isize) -> Self; fn iter_add_assign(&mut self, n: isize) -> Self; fn iter_distance(&self, from: &Self) -> isize; diff --git a/rules/map/shim.rs b/rules/map/shim.rs index c0b044c02b..b907981b15 100644 --- a/rules/map/shim.rs +++ b/rules/map/shim.rs @@ -10,8 +10,8 @@ use std::rc::{Rc, Weak}; use crate::{ AsPointer, BidirectionalIterator, ByteRepr, CopyAssignable, CopyAssignableUnsafe, CopyConstructible, CopyConstructibleUnsafe, CppIterator, CppLess, Ptr, - UnsafeBidirectionalIterator, UnsafeCppIterator, Value, ZeroInitialization, - copy_constructed, copy_constructed_unsafe, cpp_cmp, + UnsafeBidirectionalIterator, UnsafeCppIterator, Value, ZeroInitialization, copy_constructed, + copy_constructed_unsafe, cpp_cmp, }; impl ByteRepr for BTreeMap {} @@ -273,7 +273,6 @@ impl Map> { next.borrow_mut().prev = Rc::downgrade(&prev); next } - } // The functions that modify a map take a pointer to it, and borrow it after @@ -315,7 +314,10 @@ impl Map> { ) -> (BidirectionalIterator>, bool) { map.with_mut(|map| match map.search(key) { Ok(node) => (BidirectionalIterator::Map(node), false), - Err(prev) => (BidirectionalIterator::Map(map.link_after(prev, entry())), true), + Err(prev) => ( + BidirectionalIterator::Map(map.link_after(prev, entry())), + true, + ), }) } @@ -466,17 +468,17 @@ impl UnsafeMap CopyConstructibleUnsafe for UnsafeMap { - unsafe fn copy_constructor(&mut self, src: *const Self) { - unsafe { std::ptr::write(self, (*src).copied()) } + unsafe fn copy_constructor(this: *mut Self, src: *const Self) { + unsafe { std::ptr::write(this, (*src).copied()) } } } impl CopyAssignableUnsafe for UnsafeMap { - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { - unsafe { *self = (*src).copied() }; - self + unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self { + unsafe { *this = (*src).copied() }; + this } } @@ -607,7 +609,10 @@ impl UnsafeMap { pub fn emplace(&mut self, entry: (K, V)) -> (UnsafeBidirectionalIterator<(K, V)>, bool) { match self.search(&entry.0) { Ok(node) => (UnsafeBidirectionalIterator::Map(node), false), - Err(prev) => (UnsafeBidirectionalIterator::Map(self.link_after(prev, entry)), true), + Err(prev) => ( + UnsafeBidirectionalIterator::Map(self.link_after(prev, entry)), + true, + ), } } @@ -627,7 +632,9 @@ impl UnsafeMap { pub fn get(&self, key: &K) -> Option<*mut (K, V)> { self.nodes.get(&UnsafeMapKey(key)).map(|node| { - UnsafeMapNode::value(&**node as *const UnsafeMapNode<(K, V)> as *mut UnsafeMapNode<(K, V)>) + UnsafeMapNode::value( + &**node as *const UnsafeMapNode<(K, V)> as *mut UnsafeMapNode<(K, V)>, + ) }) } diff --git a/rules/map/tgt_unsafe.rs b/rules/map/tgt_unsafe.rs index e9de45d444..ef84fb347d 100644 --- a/rules/map/tgt_unsafe.rs +++ b/rules/map/tgt_unsafe.rs @@ -81,7 +81,7 @@ unsafe fn f25<'a, T1, T2>(a0: &'a mut UnsafeMap, a1: &mut UnsafeMa } unsafe fn f26<'a, T1: Ord + CopyConstructibleUnsafe, T2: CopyConstructibleUnsafe>(a0: &'a mut UnsafeMap, a1: *const UnsafeMap) -> &'a mut UnsafeMap { - a0.assign_from(a1); + AssignFromUnsafe::assign_from(&raw mut *a0, a1); a0 } diff --git a/rules/unique_ptr/shim.rs b/rules/unique_ptr/shim.rs index d3ac1adcf0..bba738f7c5 100644 --- a/rules/unique_ptr/shim.rs +++ b/rules/unique_ptr/shim.rs @@ -30,15 +30,15 @@ where } impl MoveConstructibleUnsafe for Option> { - unsafe fn move_constructor(&mut self, src: *mut Self) { - unsafe { std::ptr::write(self, (*src).take()) } + unsafe fn move_constructor(this: *mut Self, src: *mut Self) { + unsafe { std::ptr::write(this, (*src).take()) } } } impl MoveAssignableUnsafe for Option> { - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { - unsafe { *self = (*src).take() }; - self + unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { + unsafe { *this = (*src).take() }; + this } } @@ -52,7 +52,7 @@ where } impl SwappableUnsafe for Option> { - unsafe fn swap(&mut self, other: *mut Self) { - unsafe { std::ptr::swap(self, other) } + unsafe fn swap(this: *mut Self, other: *mut Self) { + unsafe { std::ptr::swap(this, other) } } } diff --git a/rules/vector/shim.rs b/rules/vector/shim.rs index a0ff6040a0..f3047eaaf3 100644 --- a/rules/vector/shim.rs +++ b/rules/vector/shim.rs @@ -41,7 +41,7 @@ impl CopyAssignable for Ve // Pushes to v an element that construct constructs in place from src, which // may point into v, and so into the storage that the push reallocates. -unsafe fn push_constructed(v: &mut Vec, src: *mut T, construct: impl FnOnce(&mut T, *mut T)) { +unsafe fn push_constructed(v: &mut Vec, src: *mut T, construct: impl FnOnce(*mut T, *mut T)) { let len = v.len(); let size = std::mem::size_of::(); let offset = (src as usize).wrapping_sub(v.as_ptr() as usize); @@ -52,7 +52,7 @@ unsafe fn push_constructed(v: &mut Vec, src: *mut T, construct: impl FnOnc None => src, }; unsafe { - construct(&mut *v.as_mut_ptr().add(len), src); + construct(v.as_mut_ptr().add(len), src); v.set_len(len + 1); } } @@ -84,7 +84,7 @@ impl PushConstructedUnsafe for Vec { { unsafe { push_constructed(self, src.cast_mut(), |dst, src| { - dst.construct_from(src.cast_const()) + ConstructFromUnsafe::construct_from(dst, src.cast_const()) }) } } @@ -93,23 +93,32 @@ impl PushConstructedUnsafe for Vec { where T: MoveConstructibleUnsafe, { - unsafe { push_constructed(self, src, |dst, src| dst.construct_from(Moved(src))) } + unsafe { + push_constructed(self, src, |dst, src| { + ConstructFromUnsafe::construct_from(dst, Moved(src)) + }) + } } } unsafe fn copied_elems_unsafe(src: *const Vec) -> Vec { - unsafe { (*src).iter().map(|elem| copy_constructed_unsafe(elem)).collect() } + unsafe { + (*src) + .iter() + .map(|elem| copy_constructed_unsafe(elem)) + .collect() + } } impl CopyConstructibleUnsafe for Vec { - unsafe fn copy_constructor(&mut self, src: *const Self) { - unsafe { std::ptr::write(self, copied_elems_unsafe(src)) } + unsafe fn copy_constructor(this: *mut Self, src: *const Self) { + unsafe { std::ptr::write(this, copied_elems_unsafe(src)) } } } impl CopyAssignableUnsafe for Vec { - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { - unsafe { *self = copied_elems_unsafe(src) }; - self + unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self { + unsafe { *this = copied_elems_unsafe(src) }; + this } } diff --git a/rules/vector/tgt_unsafe.rs b/rules/vector/tgt_unsafe.rs index 99f8530687..c10cb2cb55 100644 --- a/rules/vector/tgt_unsafe.rs +++ b/rules/vector/tgt_unsafe.rs @@ -222,7 +222,7 @@ fn f104(a0: Vec) -> UnsafeRandomAccessIterator { } unsafe fn f105<'a, T1: CopyConstructibleUnsafe>(a0: &'a mut Vec, a1: *const Vec) -> &'a mut Vec { - a0.assign_from(a1); + AssignFromUnsafe::assign_from(&raw mut *a0, a1); a0 } diff --git a/tests/multi-file/defaulted_move_cross_tu/out/unsafe/defaulted_move_cross_tu.rs b/tests/multi-file/defaulted_move_cross_tu/out/unsafe/defaulted_move_cross_tu.rs index ec85bb481c..e9e6c05d71 100644 --- a/tests/multi-file/defaulted_move_cross_tu/out/unsafe/defaulted_move_cross_tu.rs +++ b/tests/multi-file/defaulted_move_cross_tu/out/unsafe/defaulted_move_cross_tu.rs @@ -23,11 +23,11 @@ pub struct S { pub n: [i32; 2], } impl S { - pub unsafe fn construct(&mut self, mut x: i32) { - (&raw mut self.v).write(Vec::from_fn((x as usize), |_| { + pub unsafe fn construct(this: *mut Self, mut x: i32) { + (&raw mut (*this).v).write(Vec::from_fn((x as usize), |_| { copy_constructed_unsafe(&mut x) })); - (&raw mut self.n).write([x, ((x) + (1))]); + (&raw mut (*this).n).write([x, ((x) + (1))]); } } #[repr(C)] @@ -47,13 +47,13 @@ pub struct T { pub v: Vec, } impl T { - pub unsafe fn size(&self) -> i32 { - return ((self.v.len()) as i32); + pub unsafe fn size(this: *const Self) -> i32 { + return (((*this).v.len()) as i32); } } impl DefaultConstructibleUnsafe for T { - unsafe fn default_constructor(&mut self) { - (&raw mut self.v).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).v).write(Vec::new()); } } pub unsafe fn sum_0(s: *const S) -> i32 { @@ -72,7 +72,7 @@ unsafe fn main_0() -> i32 { let mut t: T = T { v: Vec::from([1, 2]), }; - assert!(((unsafe { T::size(&t,) }) == (2))); + assert!(((unsafe { T::size(&raw const t,) }) == (2))); return 0; } pub unsafe fn shuffle_1(mut x: i32) -> i32 { @@ -87,8 +87,9 @@ pub unsafe fn shuffle_1(mut x: i32) -> i32 { object_unsafe!(w, T); assign_unsafe!(w = Moved(u)); assert!( - (((unsafe { T::size(&t,) }) == (0)) && ((unsafe { T::size(&u,) }) == (0))) - && ((unsafe { T::size(&w,) }) == (1)) + (((unsafe { T::size(&raw const t,) }) == (0)) + && ((unsafe { T::size(&raw const u,) }) == (0))) + && ((unsafe { T::size(&raw const w,) }) == (1)) ); return (unsafe { sum_0(&c) }); } diff --git a/tests/multi-file/out_of_line_methods_cross_tu/out/unsafe/out_of_line_methods_cross_tu.rs b/tests/multi-file/out_of_line_methods_cross_tu/out/unsafe/out_of_line_methods_cross_tu.rs index 5f7baa55a3..b8cec259eb 100644 --- a/tests/multi-file/out_of_line_methods_cross_tu/out/unsafe/out_of_line_methods_cross_tu.rs +++ b/tests/multi-file/out_of_line_methods_cross_tu/out/unsafe/out_of_line_methods_cross_tu.rs @@ -22,8 +22,8 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn get(&self) -> i32 { - return self.v; + pub unsafe fn get(this: *const Self) -> i32 { + return (*this).v; } } #[repr(C)] @@ -76,10 +76,10 @@ pub fn main() { } unsafe fn main_0() -> i32 { object_unsafe!(s, S(1)); - assert!(((unsafe { S::get(&s,) }) == (1))); - (unsafe { S::set(&mut s, 4) }); - assert!(((unsafe { S::get(&s,) }) == (4))); - assert!(((unsafe { S::add(&mut s, 2,) }) == (6))); + assert!(((unsafe { S::get(&raw const s,) }) == (1))); + (unsafe { S::set(&raw mut s, 4) }); + assert!(((unsafe { S::get(&raw const s,) }) == (4))); + assert!(((unsafe { S::add(&raw mut s, 2,) }) == (6))); object_unsafe!(m, M(2)); object_unsafe!(n, M, Moved(&mut m)); assert!(((n.v) == (2))); @@ -98,43 +98,43 @@ unsafe fn main_0() -> i32 { return 0; } impl S { - pub unsafe fn construct(&mut self, mut x: i32) { - (&raw mut self.v).write(x); + pub unsafe fn construct(this: *mut Self, mut x: i32) { + (&raw mut (*this).v).write(x); } } impl M { - pub unsafe fn construct(&mut self, mut x: i32) { - (&raw mut self.v).write(x); + pub unsafe fn construct(this: *mut Self, mut x: i32) { + (&raw mut (*this).v).write(x); } } impl MoveConstructibleUnsafe for M { - unsafe fn move_constructor(&mut self, _a0: *mut M) { - (&raw mut self.v).write((*_a0).v); + unsafe fn move_constructor(this: *mut Self, _a0: *mut M) { + (&raw mut (*this).v).write((*_a0).v); } } impl CopyConstructibleUnsafe for M { - unsafe fn copy_constructor(&mut self, o: *const M) { - (&raw mut self.v).write((((*o).v) + (1))); + unsafe fn copy_constructor(this: *mut Self, o: *const M) { + (&raw mut (*this).v).write((((*o).v) + (1))); } } impl Derived { - pub unsafe fn construct(&mut self, mut factor: i32) { - (&raw mut self.factor).write(factor); + pub unsafe fn construct(this: *mut Self, mut factor: i32) { + (&raw mut (*this).factor).write(factor); } } impl S {} impl DestructibleUnsafe for S { - unsafe fn destroy(&mut self) {} + unsafe fn destroy(this: *mut Self) {} } impl S { - pub unsafe fn set(&mut self, mut x: i32) { - self.v = x; + pub unsafe fn set(this: *mut Self, mut x: i32) { + (*this).v = x; } } impl S { - pub unsafe fn add(&mut self, mut x: i32) -> i32 { - self.v += x; - return self.v; + pub unsafe fn add(this: *mut Self, mut x: i32) -> i32 { + (*this).v += x; + return (*this).v; } } impl M {} diff --git a/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs b/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs index 8e77fce3de..71c5b881a5 100644 --- a/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs +++ b/tests/multi-file/template_method_late_instantiation/out/unsafe/template_method_late_instantiation.rs @@ -12,13 +12,13 @@ pub struct S_int_ { pub x: i32, } impl S_int_ { - pub unsafe fn set(&mut self, mut v: i32) { - self.x = v; + pub unsafe fn set(this: *mut Self, mut v: i32) { + (*this).x = v; } } impl DefaultConstructibleUnsafe for S_int_ { - unsafe fn default_constructor(&mut self) { - (&raw mut self.x).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).x).write(0); } } impl Default for S_int_ { @@ -34,16 +34,16 @@ pub fn main() { } unsafe fn main_0() -> i32 { object_unsafe!(p, S_int_); - (unsafe { S_int_::set(&mut p, 3) }); + (unsafe { S_int_::set(&raw mut p, 3) }); assert!(((unsafe { f_0((&mut p as *mut S_int_),) }) == (3))); return 0; } impl S_int_ { - pub unsafe fn get(&mut self) -> i32 { - return self.x; + pub unsafe fn get(this: *mut Self) -> i32 { + return (*this).x; } } pub unsafe fn f_0(mut p: *mut S_int_) -> i32 { - return (unsafe { S_int_::get(&mut (*p)) }); + return (unsafe { S_int_::get(&raw mut (*p)) }); } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs index dd845ee0e4..eac9cfd4f8 100644 --- a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs +++ b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs @@ -36,25 +36,25 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { - (&raw mut self.uses).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -74,8 +74,10 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl DestructibleUnsafe for AssertsDtorCountAtExit { - unsafe fn destroy(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + unsafe fn destroy(this: *mut Self) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == ((*this).expected)) + ); } } pub static mut check_4: std::cell::LazyCell = @@ -93,7 +95,7 @@ pub static mut shared_5: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -123,7 +125,7 @@ static mut local_6: std::cell::LazyCell = std::cell::LazyCell:: { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -139,8 +141,10 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) }); - (unsafe { LifetimeTracked::use_(&(*(unsafe { HasInlineMembers::instance() }))) }); + (unsafe { + LifetimeTracked::use_(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) + }); + (unsafe { LifetimeTracked::use_(&raw const (*(unsafe { HasInlineMembers::instance() }))) }); (unsafe { b_use_7() }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2))); assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5)).uses) == (2))); @@ -155,8 +159,10 @@ unsafe fn main_0() -> i32 { return 0; } pub unsafe fn b_use_7() { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) }); - (unsafe { LifetimeTracked::use_(&(*(unsafe { HasInlineMembers::instance() }))) }); + (unsafe { + LifetimeTracked::use_(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) + }); + (unsafe { LifetimeTracked::use_(&raw const (*(unsafe { HasInlineMembers::instance() }))) }); } pub unsafe fn b_shared_address_8() -> *mut LifetimeTracked { return (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5)) diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs index 8682ae7d9d..f7bd50ec67 100644 --- a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs +++ b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs @@ -36,25 +36,25 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { - (&raw mut self.uses).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -63,7 +63,7 @@ pub static mut member_4: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -89,7 +89,7 @@ pub static mut member_5: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -117,7 +117,9 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut member_4))) }); + (unsafe { + LifetimeTracked::use_(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut member_4))) + }); (unsafe { b_use_int_6() }); (unsafe { b_use_long_7() }); assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut member_4)).uses) == (2))); @@ -132,10 +134,14 @@ unsafe fn main_0() -> i32 { return 0; } pub unsafe fn b_use_int_6() { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut member_4))) }); + (unsafe { + LifetimeTracked::use_(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut member_4))) + }); } pub unsafe fn b_use_long_7() { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut member_5))) }); + (unsafe { + LifetimeTracked::use_(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut member_5))) + }); } pub unsafe fn b_int_address_8() -> *mut LifetimeTracked { return (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut member_4)) diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs index 240049d3f0..27a7a19458 100644 --- a/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs +++ b/tests/std/basic/basic.def.odr/p15-function-template/out/unsafe/p15-function-template.rs @@ -36,25 +36,25 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { - (&raw mut self.uses).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -74,8 +74,10 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl DestructibleUnsafe for AssertsDtorCountAtExit { - unsafe fn destroy(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + unsafe fn destroy(this: *mut Self) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == ((*this).expected)) + ); } } pub unsafe fn count_4() -> i32 { @@ -91,7 +93,7 @@ static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new( { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -105,7 +107,7 @@ static mut t_8: std::cell::LazyCell = std::cell::LazyCell::new( { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -119,7 +121,7 @@ static mut t_11: std::cell::LazyCell = std::cell::LazyCell::new { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -178,7 +180,7 @@ static mut t_19: std::cell::LazyCell = std::cell::LazyCell::new { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs index b89d4469b2..5b95a4faa2 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-function/out/unsafe/p15-inline-function.rs @@ -36,25 +36,25 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { - (&raw mut self.uses).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -74,8 +74,10 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl DestructibleUnsafe for AssertsDtorCountAtExit { - unsafe fn destroy(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + unsafe fn destroy(this: *mut Self) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == ((*this).expected)) + ); } } pub unsafe fn instance_4() -> *mut LifetimeTracked { @@ -85,7 +87,7 @@ static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new( { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -112,7 +114,7 @@ pub fn main() { } unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0))); - (unsafe { LifetimeTracked::use_(&(*(unsafe { instance_4() }))) }); + (unsafe { LifetimeTracked::use_(&raw const (*(unsafe { instance_4() }))) }); (unsafe { b_use_7() }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (2))); @@ -123,7 +125,7 @@ unsafe fn main_0() -> i32 { return 0; } pub unsafe fn b_use_7() { - (unsafe { LifetimeTracked::use_(&(*(unsafe { instance_4() }))) }); + (unsafe { LifetimeTracked::use_(&raw const (*(unsafe { instance_4() }))) }); } pub unsafe fn b_address_8() -> *mut LifetimeTracked { return (unsafe { instance_4() }); diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs index 8dc8692001..947b8ea2a9 100644 --- a/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs +++ b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs @@ -36,25 +36,25 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { - (&raw mut self.uses).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -74,8 +74,10 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl DestructibleUnsafe for AssertsDtorCountAtExit { - unsafe fn destroy(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + unsafe fn destroy(this: *mut Self) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == ((*this).expected)) + ); } } pub static mut check_4: std::cell::LazyCell = @@ -93,7 +95,7 @@ pub static mut shared_5: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -109,7 +111,9 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) }); + (unsafe { + LifetimeTracked::use_(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) + }); (unsafe { b_use_6() }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (2))); @@ -123,7 +127,9 @@ unsafe fn main_0() -> i32 { return 0; } pub unsafe fn b_use_6() { - (unsafe { LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) }); + (unsafe { + LifetimeTracked::use_(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5))) + }); } pub unsafe fn b_address_7() -> *mut LifetimeTracked { return (&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5)) diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs index ca65a2f79b..e64c52a6e7 100644 --- a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs +++ b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs @@ -36,25 +36,25 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { - (&raw mut self.uses).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -74,8 +74,10 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl DestructibleUnsafe for AssertsDtorCountAtExit { - unsafe fn destroy(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + unsafe fn destroy(this: *mut Self) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == ((*this).expected)) + ); } } #[repr(C)] @@ -91,16 +93,18 @@ impl DestructibleUnsafe for AssertsDtorCountAtExit { )] pub struct X {} impl X { - pub unsafe fn h(&mut self, mut cond: bool, mut p: Option) { + pub unsafe fn h(this: *mut Self, mut cond: bool, mut p: Option) { if cond { (unsafe { X::h( - self, + this, false, Some(|| unsafe { (unsafe { LifetimeTracked::use_( - &(*std::cell::LazyCell::force_mut(&mut *&raw mut local_4)), + &raw const (*std::cell::LazyCell::force_mut( + &mut *&raw mut local_4, + )), ) }); }), @@ -115,7 +119,7 @@ static mut local_4: std::cell::LazyCell = std::cell::LazyCell:: { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -145,12 +149,12 @@ unsafe fn main_0() -> i32 { let mut x: X = ::default(); (unsafe { X::h( - &mut x, + &raw mut x, true, Some(|| unsafe { (unsafe { LifetimeTracked::use_( - &(*std::cell::LazyCell::force_mut(&mut *&raw mut local_4)), + &raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut local_4)), ) }); }), @@ -167,12 +171,12 @@ pub unsafe fn b_call_6() { let mut x: X = ::default(); (unsafe { X::h( - &mut x, + &raw mut x, true, Some(|| unsafe { (unsafe { LifetimeTracked::use_( - &(*std::cell::LazyCell::force_mut(&mut *&raw mut local_4)), + &raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut local_4)), ) }); }), diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs index 605541690b..8d40bf22f8 100644 --- a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs +++ b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs @@ -36,25 +36,25 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { - (&raw mut self.uses).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -74,8 +74,10 @@ pub struct AssertsDtorCountAtExit { pub expected: i32, } impl DestructibleUnsafe for AssertsDtorCountAtExit { - unsafe fn destroy(&mut self) { - assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (self.expected))); + unsafe fn destroy(this: *mut Self) { + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == ((*this).expected)) + ); } } pub unsafe fn f_4(mut cond: bool, mut p: Option) { @@ -86,7 +88,7 @@ pub unsafe fn f_4(mut cond: bool, mut p: Option) { Some(|| unsafe { (unsafe { LifetimeTracked::use_( - &(*std::cell::LazyCell::force_mut(&mut *&raw mut local_5)), + &raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut local_5)), ) }); }), @@ -100,7 +102,7 @@ static mut local_5: std::cell::LazyCell = std::cell::LazyCell:: { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/basic.link/out/unsafe/basic.link.rs b/tests/std/basic/basic.link/out/unsafe/basic.link.rs index 81795fc7bc..401a10dbee 100644 --- a/tests/std/basic/basic.link/out/unsafe/basic.link.rs +++ b/tests/std/basic/basic.link/out/unsafe/basic.link.rs @@ -73,8 +73,8 @@ pub struct Record_19 { pub id: i32, } impl DefaultConstructibleUnsafe for Record_19 { - unsafe fn default_constructor(&mut self) { - (&raw mut self.id).write(100); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).id).write(100); } } impl Default for Record_19 { @@ -118,7 +118,7 @@ pub unsafe fn test_29() { )] pub struct Tally_31 {} impl Tally_31 { - pub unsafe fn add(&mut self, mut amount: i32) -> i32 { + pub unsafe fn add(this: *mut Self, mut amount: i32) -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut total_32)) += amount; return (*std::cell::LazyCell::force_mut(&mut *&raw mut total_32)); } @@ -126,7 +126,7 @@ impl Tally_31 { pub static mut total_32: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10 }); pub unsafe fn test_33() { let mut tally: Tally_31 = ::default(); - assert!(((unsafe { Tally_31::add(&mut tally, 1,) }) == (11))); + assert!(((unsafe { Tally_31::add(&raw mut tally, 1,) }) == (11))); assert!(((unsafe { add_in_b_34(1,) }) == (102))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_32)) == (11))); } @@ -207,8 +207,8 @@ pub struct Entry_52 { pub key: i32, } impl DefaultConstructibleUnsafe for Entry_52 { - unsafe fn default_constructor(&mut self) { - (&raw mut self.key).write(1); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).key).write(1); } } impl Default for Entry_52 { @@ -223,9 +223,9 @@ pub struct Entry_54 { pub value: i32, } impl DefaultConstructibleUnsafe for Entry_54 { - unsafe fn default_constructor(&mut self) { - (&raw mut self.key).write(2); - (&raw mut self.value).write(30); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).key).write(2); + (&raw mut (*this).value).write(30); } } impl Default for Entry_54 { @@ -322,9 +322,9 @@ pub struct Record_65 { pub extra: i32, } impl DefaultConstructibleUnsafe for Record_65 { - unsafe fn default_constructor(&mut self) { - (&raw mut self.id).write(200_i64); - (&raw mut self.extra).write(1); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).id).write(200_i64); + (&raw mut (*this).extra).write(1); } } impl Default for Record_65 { @@ -371,7 +371,7 @@ pub unsafe fn raise_30(mut by: i32) -> i32 { )] pub struct Tally_67 {} impl Tally_67 { - pub unsafe fn add(&mut self, mut amount: i32) -> i32 { + pub unsafe fn add(this: *mut Self, mut amount: i32) -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut total_68)) += ((amount) * (2)); return (*std::cell::LazyCell::force_mut(&mut *&raw mut total_68)); } @@ -379,7 +379,7 @@ impl Tally_67 { pub static mut total_68: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 100 }); pub unsafe fn add_in_b_34(mut amount: i32) -> i32 { let mut tally: Tally_67 = ::default(); - return (unsafe { Tally_67::add(&mut tally, amount) }); + return (unsafe { Tally_67::add(&raw mut tally, amount) }); } pub static mut balance_35: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 50 }); impl p5_members_of_class_with_external_linkage_Ledger { @@ -411,8 +411,8 @@ pub struct Entry_71 { pub key: i64, } impl DefaultConstructibleUnsafe for Entry_71 { - unsafe fn default_constructor(&mut self) { - (&raw mut self.key).write(400_i64); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).key).write(400_i64); } } impl Default for Entry_71 { diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs index fe6fa8f0ec..4b2bbc17d3 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.block.rs @@ -36,25 +36,25 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { - (&raw mut self.uses).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -79,12 +79,12 @@ pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { pub value: i32, } impl p1_1_condition_variable_visible_in_else_ConvertsToBool { - pub unsafe fn to_bool(&self) -> bool { - return ((self.value) != (0)); + pub unsafe fn to_bool(this: *const Self) -> bool { + return (((*this).value) != (0)); } } impl DestructibleUnsafe for p1_1_condition_variable_visible_in_else_ConvertsToBool { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_6)).prefix_inc(); } } @@ -93,10 +93,11 @@ pub unsafe fn test_7() { let mut condition: p1_1_condition_variable_visible_in_else_ConvertsToBool = p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 0 }; let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); - if (unsafe { p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(&condition) }) - { + if (unsafe { + p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(&raw const condition) + }) { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); } else { (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)).prefix_inc(); @@ -111,10 +112,11 @@ pub unsafe fn test_7() { let mut condition: p1_1_condition_variable_visible_in_else_ConvertsToBool = p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 6 }; let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); - if (unsafe { p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(&condition) }) - { + if (unsafe { + p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(&raw const condition) + }) { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); assert!(((condition.value) == (6))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_6)) == (1))); @@ -170,7 +172,7 @@ pub unsafe fn test_9() { } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (6))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (5))); - (unsafe { LifetimeTracked::use_(&scoped) }); + (unsafe { LifetimeTracked::use_(&raw const scoped) }); assert!(((scoped.uses) == (1))); } pub unsafe fn test_10() { @@ -195,13 +197,13 @@ pub unsafe fn test_11() { { object_unsafe!(tracked, LifetimeTracked); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2))); - (unsafe { LifetimeTracked::use_(&tracked) }); + (unsafe { LifetimeTracked::use_(&raw const tracked) }); assert!(((tracked.uses) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (0))); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (1))); assert!(((tracked.uses) == (0))); - (unsafe { LifetimeTracked::use_(&tracked) }); + (unsafe { LifetimeTracked::use_(&raw const tracked) }); assert!(((tracked.uses) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)) == (2))); } diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs index f6bfd2af94..074260bb41 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.class.rs @@ -13,18 +13,18 @@ pub struct p1_member_hides_namespace_variable_HasBalance { pub balance: i32, } impl p1_member_hides_namespace_variable_HasBalance { - pub unsafe fn deposit(&mut self, mut amount: i32) -> i32 { - self.balance += amount; - return self.balance; + pub unsafe fn deposit(this: *mut Self, mut amount: i32) -> i32 { + (*this).balance += amount; + return (*this).balance; } - pub unsafe fn deposit_globally(&mut self, mut amount: i32) -> i32 { + pub unsafe fn deposit_globally(this: *mut Self, mut amount: i32) -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_0)) += amount; return (*std::cell::LazyCell::force_mut(&mut *&raw mut balance_0)); } } impl DefaultConstructibleUnsafe for p1_member_hides_namespace_variable_HasBalance { - unsafe fn default_constructor(&mut self) { - (&raw mut self.balance).write(7); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).balance).write(7); } } impl Default for p1_member_hides_namespace_variable_HasBalance { @@ -35,14 +35,14 @@ impl Default for p1_member_hides_namespace_variable_HasBalance { pub unsafe fn test_1() { object_unsafe!(object, p1_member_hides_namespace_variable_HasBalance); assert!( - ((unsafe { p1_member_hides_namespace_variable_HasBalance::deposit(&mut object, 3,) }) + ((unsafe { p1_member_hides_namespace_variable_HasBalance::deposit(&raw mut object, 3,) }) == (10)) ); assert!(((object.balance) == (10))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut balance_0)) == (50))); assert!( ((unsafe { - p1_member_hides_namespace_variable_HasBalance::deposit_globally(&mut object, 4) + p1_member_hides_namespace_variable_HasBalance::deposit_globally(&raw mut object, 4) }) == (54)) ); assert!(((object.balance) == (10))); @@ -55,8 +55,8 @@ pub struct p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { pub held: i32, } impl DefaultConstructibleUnsafe for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { - unsafe fn default_constructor(&mut self) { - (&raw mut self.held).write(1); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).held).write(1); } } impl Default for p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { @@ -69,11 +69,11 @@ pub static mut total_4: std::cell::LazyCell = std::cell::LazyCell::new(|| u ((*std::cell::LazyCell::force_mut(&mut *&raw mut initial_3)) + (1)) }); impl p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { - pub unsafe fn add(&mut self, mut amount: i32) -> i32 { - self.held += amount; + pub unsafe fn add(this: *mut Self, mut amount: i32) -> i32 { + (*this).held += amount; (*std::cell::LazyCell::force_mut(&mut *&raw mut total_4)) += (*std::cell::LazyCell::force_mut(&mut *&raw mut initial_3)); - return self.held; + return (*this).held; } } pub unsafe fn test_5() { @@ -84,7 +84,7 @@ pub unsafe fn test_5() { ); assert!( ((unsafe { - p1_out_of_class_definition_is_in_class_scope_HasStaticTotal::add(&mut object, 4) + p1_out_of_class_definition_is_in_class_scope_HasStaticTotal::add(&raw mut object, 4) }) == (5)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_4)) == (13))); diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs index 9d1af9da89..fab158ea2c 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.param.rs @@ -23,14 +23,14 @@ pub struct p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParamete pub amount: i32, } impl p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { - pub unsafe fn construct(&mut self, mut amount: i32) { - (&raw mut self.amount).write(((amount) + (1))); + pub unsafe fn construct(this: *mut Self, mut amount: i32) { + (&raw mut (*this).amount).write(((amount) + (1))); amount += 10; assert!(((amount) == (14))); - assert!(((self.amount) == (5))); + assert!((((*this).amount) == (5))); } - pub unsafe fn add(&self, mut amount: i32) -> i32 { - return ((self.amount) + (amount)); + pub unsafe fn add(this: *const Self, mut amount: i32) -> i32 { + return (((*this).amount) + (amount)); } } pub unsafe fn test_0() { @@ -41,7 +41,10 @@ pub unsafe fn test_0() { assert!(((object.amount) == (5))); assert!( ((unsafe { - p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter::add(&object, 20) + p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter::add( + &raw const object, + 20, + ) }) == (25)) ); assert!(((object.amount) == (5))); diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs index 39cdf52ee8..c19845dfca 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.pdecl.rs @@ -86,9 +86,9 @@ pub struct p9_func_declared_before_function_body_RecordsConstructorName { pub name: *const libc::c_char, } impl DefaultConstructibleUnsafe for p9_func_declared_before_function_body_RecordsConstructorName { - unsafe fn default_constructor(&mut self) { - (&raw mut self.name).write(c"RecordsConstructorName".as_ptr()); - assert!(((self.name) == (c"RecordsConstructorName".as_ptr()))); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).name).write(c"RecordsConstructorName".as_ptr()); + assert!((((*this).name) == (c"RecordsConstructorName".as_ptr()))); } } impl Default for p9_func_declared_before_function_body_RecordsConstructorName { @@ -97,7 +97,7 @@ impl Default for p9_func_declared_before_function_body_RecordsConstructorName { { let mut __v: p9_func_declared_before_function_body_RecordsConstructorName = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } diff --git a/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs b/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs index ee2c27079b..55ac501b18 100644 --- a/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs +++ b/tests/std/basic/basic.scope/out/unsafe/basic.scope.scope.rs @@ -54,7 +54,7 @@ pub const p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large: )] pub struct p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum {} impl p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum { - pub unsafe fn scale(&self, mut count: i32) -> i32 { + pub unsafe fn scale(this: *const Self, mut count: i32) -> i32 { return ((count) * (p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large as i32)); } @@ -71,8 +71,9 @@ pub unsafe fn test_5() { let mut object: p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum = ::default(); assert!( - ((unsafe { p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum::scale(&object, 2,) }) - == (16)) + ((unsafe { + p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum::scale(&raw const object, 2) + }) == (16)) ); assert!(((p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_small as i32) == (3))); } @@ -158,8 +159,8 @@ pub struct p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion { pub anon_9: anon_9, } impl p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion { - pub unsafe fn read_count(&self) -> i32 { - return self.anon_9.member_count; + pub unsafe fn read_count(this: *const Self) -> i32 { + return (*this).anon_9.member_count; } } pub unsafe fn test_10() { @@ -176,7 +177,9 @@ pub unsafe fn test_10() { assert!(((object.anon_9.member_count) == (6))); assert!( ((unsafe { - p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion::read_count(&object) + p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion::read_count( + &raw const object, + ) }) == (6)) ); object.anon_9.member_ratio = 0.5_f64; @@ -214,19 +217,19 @@ pub struct p3_2_const_qualified_member_is_distinct_HasConstOverload { pub const_calls: i32, } impl p3_2_const_qualified_member_is_distinct_HasConstOverload { - pub unsafe fn get_1(&mut self) -> i32 { - self.plain_calls.prefix_inc(); + pub unsafe fn get_1(this: *mut Self) -> i32 { + (*this).plain_calls.prefix_inc(); return 1; } - pub unsafe fn get_2(&self) -> i32 { - (*(&raw const self.const_calls).cast_mut()).prefix_inc(); + pub unsafe fn get_2(this: *const Self) -> i32 { + (*(&raw const (*this).const_calls).cast_mut()).prefix_inc(); return 2; } } impl DefaultConstructibleUnsafe for p3_2_const_qualified_member_is_distinct_HasConstOverload { - unsafe fn default_constructor(&mut self) { - (&raw mut self.plain_calls).write(0); - (&raw mut self.const_calls).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).plain_calls).write(0); + (&raw mut (*this).const_calls).write(0); } } impl Default for p3_2_const_qualified_member_is_distinct_HasConstOverload { @@ -247,14 +250,15 @@ pub unsafe fn test_12() { let view: *const p3_2_const_qualified_member_is_distinct_HasConstOverload = &object; assert!( ((unsafe { - p3_2_const_qualified_member_is_distinct_HasConstOverload::get_1(&mut object) + p3_2_const_qualified_member_is_distinct_HasConstOverload::get_1(&raw mut object) }) == (1)) ); assert!(((object.plain_calls) == (1))); assert!(((object.const_calls) == (0))); assert!( - ((unsafe { p3_2_const_qualified_member_is_distinct_HasConstOverload::get_2(&(*view),) }) - == (2)) + ((unsafe { + p3_2_const_qualified_member_is_distinct_HasConstOverload::get_2(&raw const (*view)) + }) == (2)) ); assert!(((object.plain_calls) == (1))); assert!(((object.const_calls) == (1))); @@ -276,16 +280,16 @@ impl p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverl (*std::cell::LazyCell::force_mut(&mut *&raw mut explicit_calls_13)).prefix_inc(); return (((*self_).base) + (amount)); } - pub unsafe fn pick_2(&mut self, mut amount: i32) -> i32 { + pub unsafe fn pick_2(this: *mut Self, mut amount: i32) -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_14)).prefix_inc(); - return (((self.base) + (amount)) + (100)); + return ((((*this).base) + (amount)) + (100)); } } impl DefaultConstructibleUnsafe for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { - unsafe fn default_constructor(&mut self) { - (&raw mut self.base).write(10); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).base).write(10); } } impl Default for p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { @@ -316,7 +320,7 @@ pub unsafe fn test_15() { let mut __tmp_0: p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload = ::zero_init(); assert!( ((unsafe { - p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( &mut (*{ DefaultConstructibleUnsafe::default_constructor(&mut __tmp_0) ; & mut __tmp_0 } ) , 2 , ) + p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload :: pick_2 ( &mut (*{ DefaultConstructibleUnsafe::default_constructor(&raw mut __tmp_0) ; & mut __tmp_0 } ) , 2 , ) }) == (112)) ) }; @@ -340,11 +344,11 @@ pub static mut rvalue_calls_17: std::cell::LazyCell = )] pub struct p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads {} impl p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads { - pub unsafe fn get_1(&mut self) -> i32 { + pub unsafe fn get_1(this: *mut Self) -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut lvalue_calls_16)).prefix_inc(); return 3; } - pub unsafe fn get_2(&mut self) -> i32 { + pub unsafe fn get_2(this: *mut Self) -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_17)).prefix_inc(); return 4; } @@ -354,7 +358,7 @@ pub unsafe fn test_18() { ::default(); assert!( ((unsafe { - p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads::get_1(&mut object) + p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads::get_1(&raw mut object) }) == (3)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut lvalue_calls_16)) == (1))); @@ -370,7 +374,7 @@ pub unsafe fn test_18() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_17)) == (1))); assert!( ((unsafe { - p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads::get_2(&mut object) + p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads::get_2(&raw mut object) }) == (4)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut lvalue_calls_16)) == (1))); @@ -383,21 +387,21 @@ pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOv pub const_calls: i32, } impl p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { - pub unsafe fn get_1_int(&mut self, mut value: i32) -> i32 { - self.plain_calls.prefix_inc(); + pub unsafe fn get_1_int(this: *mut Self, mut value: i32) -> i32 { + (*this).plain_calls.prefix_inc(); return ((value) + (1)); } - pub unsafe fn get_2_int(&self, mut value: i32) -> i32 { - (*(&raw const self.const_calls).cast_mut()).prefix_inc(); + pub unsafe fn get_2_int(this: *const Self, mut value: i32) -> i32 { + (*(&raw const (*this).const_calls).cast_mut()).prefix_inc(); return ((value) + (2)); } } impl DefaultConstructibleUnsafe for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { - unsafe fn default_constructor(&mut self) { - (&raw mut self.plain_calls).write(0); - (&raw mut self.const_calls).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).plain_calls).write(0); + (&raw mut (*this).const_calls).write(0); } } impl Default for p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { @@ -420,7 +424,7 @@ pub unsafe fn test_19() { assert!( ((unsafe { p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload::get_1_int( - &mut object, + &raw mut object, 10, ) }) == (11)) @@ -430,7 +434,7 @@ pub unsafe fn test_19() { assert!( ((unsafe { p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload::get_2_int( - &(*view), + &raw const (*view), 10, ) }) == (12)) @@ -455,11 +459,11 @@ pub static mut rvalue_calls_21: std::cell::LazyCell = )] pub struct p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads {} impl p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads { - pub unsafe fn get_1_int(&mut self, mut value: i32) -> i32 { + pub unsafe fn get_1_int(this: *mut Self, mut value: i32) -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut lvalue_calls_20)).prefix_inc(); return ((value) + (3)); } - pub unsafe fn get_2_int(&mut self, mut value: i32) -> i32 { + pub unsafe fn get_2_int(this: *mut Self, mut value: i32) -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_21)).prefix_inc(); return ((value) + (4)); } @@ -468,7 +472,7 @@ pub unsafe fn test_22() { let mut object : p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads = ::default() ; assert!( ((unsafe { - p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads :: get_1_int ( &mut object , 10 , ) + p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads :: get_1_int ( &raw mut object , 10 , ) }) == (13)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut lvalue_calls_20)) == (1))); @@ -482,7 +486,7 @@ pub unsafe fn test_22() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut rvalue_calls_21)) == (1))); assert!( ((unsafe { - p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads :: get_2_int ( &mut object , 10 , ) + p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads :: get_2_int ( &raw mut object , 10 , ) }) == (14)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut lvalue_calls_20)) == (1))); diff --git a/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs b/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs index a4bb703216..1c893a7688 100644 --- a/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs +++ b/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs @@ -22,21 +22,26 @@ pub struct Tracker { pub tag: i32, } impl Tracker { - pub unsafe fn construct(&mut self, mut tag: i32) { - (&raw mut self.tag).write(tag); + pub unsafe fn construct(this: *mut Self, mut tag: i32) { + (&raw mut (*this).tag).write(tag); (unsafe { libc::printf(c"construct %d\n".as_ptr() as *const libc::c_char, (tag)) }); } } impl DestructibleUnsafe for Tracker { - unsafe fn destroy(&mut self) { - (unsafe { libc::printf(c"destroy %d\n".as_ptr() as *const libc::c_char, (self.tag)) }); + unsafe fn destroy(this: *mut Self) { + (unsafe { + libc::printf( + c"destroy %d\n".as_ptr() as *const libc::c_char, + ((*this).tag), + ) + }); } } pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { let mut __v: Tracker = ::zero_init(); - Tracker::construct(&mut __v, 1); + Tracker::construct(&raw mut __v, 1); __v }; libcc2rs::register_static_destructor(|| { @@ -59,7 +64,7 @@ static mut local_static_2: std::cell::LazyCell = std::cell::LazyCell::n { let __static = { let mut __v: Tracker = ::zero_init(); - Tracker::construct(&mut __v, 2); + Tracker::construct(&raw mut __v, 2); __v }; libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs b/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs index 1dd4b73a5b..19cda7aef8 100644 --- a/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs +++ b/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs @@ -22,17 +22,22 @@ pub struct Tracker { pub tag: i32, } impl Tracker { - pub unsafe fn construct(&mut self, mut tag: i32) { - (&raw mut self.tag).write(tag); + pub unsafe fn construct(this: *mut Self, mut tag: i32) { + (&raw mut (*this).tag).write(tag); (unsafe { libc::printf(c"construct %d\n".as_ptr() as *const libc::c_char, (tag)) }); } - pub unsafe fn touch(&self) { - (unsafe { libc::printf(c"touch %d\n".as_ptr() as *const libc::c_char, (self.tag)) }); + pub unsafe fn touch(this: *const Self) { + (unsafe { libc::printf(c"touch %d\n".as_ptr() as *const libc::c_char, ((*this).tag)) }); } } impl DestructibleUnsafe for Tracker { - unsafe fn destroy(&mut self) { - (unsafe { libc::printf(c"destroy %d\n".as_ptr() as *const libc::c_char, (self.tag)) }); + unsafe fn destroy(this: *mut Self) { + (unsafe { + libc::printf( + c"destroy %d\n".as_ptr() as *const libc::c_char, + ((*this).tag), + ) + }); } } #[repr(C)] @@ -70,7 +75,7 @@ pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new { let __static = { let mut __v: Tracker = ::zero_init(); - Tracker::construct(&mut __v, 1); + Tracker::construct(&raw mut __v, 1); __v }; libcc2rs::register_static_destructor(|| { @@ -81,18 +86,22 @@ pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new }); pub unsafe fn never_called_1() { (unsafe { - Tracker::touch(&(*std::cell::LazyCell::force_mut(&mut *&raw mut never_constructed_2))) + Tracker::touch( + &raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut never_constructed_2)), + ) }); } pub unsafe fn test_3() { - (unsafe { Tracker::touch(&(*std::cell::LazyCell::force_mut(&mut *&raw mut global_0))) }); + (unsafe { + Tracker::touch(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0))) + }); } static mut never_constructed_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = { let mut __v: Tracker = ::zero_init(); - Tracker::construct(&mut __v, 100); + Tracker::construct(&raw mut __v, 100); __v }; libcc2rs::register_static_destructor(|| { @@ -110,7 +119,7 @@ pub static mut before_6: std::cell::LazyCell = std::cell::LazyCell::new { let __static = { let mut __v: Tracker = ::zero_init(); - Tracker::construct(&mut __v, 2); + Tracker::construct(&raw mut __v, 2); __v }; libcc2rs::register_static_destructor(|| { @@ -124,7 +133,7 @@ pub static mut after_7: std::cell::LazyCell = std::cell::LazyCell::new( let __static = { let mut __v: Tracker = ::zero_init(); Tracker::construct( - &mut __v, + &raw mut __v, (((*(unsafe { local_static_during_global_init_4() })).tag) + (1)), ); __v @@ -140,7 +149,7 @@ pub static mut holder_8: std::cell::LazyCell = std::cell::LazyCell let __static = HoldsTracker { member: { let mut __v: Tracker = ::zero_init(); - Tracker::construct(&mut __v, 5); + Tracker::construct(&raw mut __v, 5); __v }, }; @@ -168,7 +177,7 @@ pub static mut member_10: std::cell::LazyCell = std::cell::LazyCell::ne { let __static = { let mut __v: Tracker = ::zero_init(); - Tracker::construct(&mut __v, 7); + Tracker::construct(&raw mut __v, 7); __v }; libcc2rs::register_static_destructor(|| { @@ -184,7 +193,7 @@ pub static mut capturing_11: std::cell::LazyCell i32>> = { let captured: Tracker = { let mut __v: Tracker = ::zero_init(); - Tracker::construct(&mut __v, 8); + Tracker::construct(&raw mut __v, 8); __v }; }, @@ -201,19 +210,23 @@ pub static mut capturing_11: std::cell::LazyCell i32>> = } }); pub unsafe fn run_local_static_12() { - (unsafe { Tracker::touch(&(*std::cell::LazyCell::force_mut(&mut *&raw mut during_main_13))) }); + (unsafe { + Tracker::touch(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut during_main_13))) + }); } pub unsafe fn test_14() { (unsafe { run_local_static_12() }); (unsafe { run_local_static_12() }); - (unsafe { Tracker::touch(&(*(unsafe { local_static_during_global_init_4() }))) }); + (unsafe { Tracker::touch(&raw const (*(unsafe { local_static_during_global_init_4() }))) }); (unsafe { libc::printf( c"trivial %d\n".as_ptr() as *const libc::c_char, ((*std::cell::LazyCell::force_mut(&mut *&raw mut trivial_9)).value), ) }); - (unsafe { Tracker::touch(&(*std::cell::LazyCell::force_mut(&mut *&raw mut member_10))) }); + (unsafe { + Tracker::touch(&raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut member_10))) + }); (unsafe { libc::printf( c"captured %d\n".as_ptr() as *const libc::c_char, @@ -225,7 +238,7 @@ static mut during_init_5: std::cell::LazyCell = std::cell::LazyCell::ne { let __static = { let mut __v: Tracker = ::zero_init(); - Tracker::construct(&mut __v, 3); + Tracker::construct(&raw mut __v, 3); __v }; libcc2rs::register_static_destructor(|| { @@ -240,7 +253,7 @@ static mut during_main_13: std::cell::LazyCell = std::cell::LazyCell::n { let __static = { let mut __v: Tracker = ::zero_init(); - Tracker::construct(&mut __v, 9); + Tracker::construct(&raw mut __v, 9); __v }; libcc2rs::register_static_destructor(|| { diff --git a/tests/std/basic/out/unsafe/basic.def.odr.rs b/tests/std/basic/out/unsafe/basic.def.odr.rs index 1dba12b2f0..9b239de46c 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -28,13 +28,13 @@ impl HasConstexprCtor { pub unsafe fn reset() { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) = 0; } - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.m).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).m).write(v); } } impl CopyConstructibleUnsafe for HasConstexprCtor { - unsafe fn copy_constructor(&mut self, o: *const HasConstexprCtor) { - (&raw mut self.m).write((*o).m); + unsafe fn copy_constructor(this: *mut Self, o: *const HasConstexprCtor) { + (&raw mut (*this).m).write((*o).m); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)).prefix_inc(); } } @@ -68,25 +68,25 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_1)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { - (&raw mut self.uses).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_3)).prefix_inc(); } } @@ -95,12 +95,12 @@ pub unsafe fn test_5() { let arr: [HasConstexprCtor; 2] = [ { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 3); + HasConstexprCtor::construct(&raw mut __v, 3); __v }, { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 4); + HasConstexprCtor::construct(&raw mut __v, 4); __v }, ]; @@ -109,12 +109,12 @@ pub unsafe fn test_5() { return [ { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 3); + HasConstexprCtor::construct(&raw mut __v, 3); __v }, { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 4); + HasConstexprCtor::construct(&raw mut __v, 4); __v }, ][(1) as usize] @@ -132,7 +132,7 @@ pub unsafe fn test_6() { unsafe { return { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 5); + HasConstexprCtor::construct(&raw mut __v, 5); __v } .m; @@ -151,13 +151,13 @@ pub unsafe fn test_7() { return (if b { { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 7); + HasConstexprCtor::construct(&raw mut __v, 7); __v } } else { { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 9); + HasConstexprCtor::construct(&raw mut __v, 9); __v } }) @@ -179,7 +179,7 @@ pub unsafe fn test_9() { (*std::cell::LazyCell::force_mut(&mut *&raw mut left_8)).prefix_inc(); { let mut __v: HasConstexprCtor = ::zero_init(); - HasConstexprCtor::construct(&mut __v, 5); + HasConstexprCtor::construct(&raw mut __v, 5); __v } } @@ -222,7 +222,7 @@ pub static mut global_12: std::cell::LazyCell = { let __static = { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; libcc2rs::register_static_destructor(|| { @@ -238,7 +238,9 @@ pub unsafe fn test_13() { let r: *mut LifetimeTracked = &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut global_12)); let mut f: FnPtr = FnPtr::::new(|| unsafe { (unsafe { - LifetimeTracked::use_(&(*std::cell::LazyCell::force_mut(&mut *&raw mut global_12))) + LifetimeTracked::use_( + &raw const (*std::cell::LazyCell::force_mut(&mut *&raw mut global_12)), + ) }); }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (0))); @@ -255,16 +257,16 @@ pub unsafe fn test_14() { { let r: LifetimeTracked = { let mut __v: LifetimeTracked = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, r); + ConstructFromUnsafe::construct_from(&raw mut __v, r); __v }; }, || { - (unsafe { LifetimeTracked::use_(&r) }); + (unsafe { LifetimeTracked::use_(&raw const r) }); } ); let _dtor_f = std::mem::DropGuard::new(&raw mut f, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (1))); (unsafe { f.call() }); @@ -292,7 +294,7 @@ pub unsafe fn test_16() { { let k: HasConstexprCtor = { let mut __v: HasConstexprCtor = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, &k); + ConstructFromUnsafe::construct_from(&raw mut __v, &k); __v }; }, @@ -334,18 +336,18 @@ pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { pub scratch: i32, } impl p5_2_mutable_subobject_is_odr_used_HasMutableMember { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.value).write(v); - (&raw mut self.scratch).write(0); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).value).write(v); + (&raw mut (*this).scratch).write(0); } } impl CopyConstructibleUnsafe for p5_2_mutable_subobject_is_odr_used_HasMutableMember { unsafe fn copy_constructor( - &mut self, + this: *mut Self, o: *const p5_2_mutable_subobject_is_odr_used_HasMutableMember, ) { - (&raw mut self.value).write((*o).value); - (&raw mut self.scratch).write((*o).scratch); + (&raw mut (*this).value).write((*o).value); + (&raw mut (*this).scratch).write((*o).scratch); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_18)).prefix_inc(); } } @@ -356,7 +358,7 @@ pub unsafe fn test_19() { let k: p5_2_mutable_subobject_is_odr_used_HasMutableMember = { let mut __v: p5_2_mutable_subobject_is_odr_used_HasMutableMember = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, &k); + ConstructFromUnsafe::construct_from(&raw mut __v, &k); __v }; }, @@ -380,9 +382,9 @@ pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { pub b: LifetimeTracked, } impl DefaultConstructibleUnsafe for p6_unevaluated_binding_needs_no_capture_HasTwoMembers { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.a); - DefaultConstructibleUnsafe::default_constructor(&mut self.b); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).a); + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).b); } } pub unsafe fn test_20() { @@ -391,17 +393,17 @@ pub unsafe fn test_20() { p6_unevaluated_binding_needs_no_capture_HasTwoMembers { a: { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }, b: { let mut __v: LifetimeTracked = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }, }; let _dtor_p = std::mem::DropGuard::new(&raw mut p, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); let __decomp_21: *mut p6_unevaluated_binding_needs_no_capture_HasTwoMembers = &mut p; let mut f: FnPtr usize> = FnPtr:: usize>::new(|| -> usize { @@ -425,30 +427,29 @@ pub struct p7_member_access_captures_this_HasMemberUsedInLambda { pub n: i32, } impl p7_member_access_captures_this_HasMemberUsedInLambda { - pub unsafe fn makeLambda(&mut self) -> FnPtr i32> { + pub unsafe fn makeLambda(this: *mut Self) -> FnPtr i32> { return lambda_unsafe!( { - let this_: *mut p7_member_access_captures_this_HasMemberUsedInLambda = - (self as *mut p7_member_access_captures_this_HasMemberUsedInLambda); + let this_: *mut p7_member_access_captures_this_HasMemberUsedInLambda = this; }, || -> i32 { - (unsafe { LifetimeTracked::use_(&(*this_).x) }); + (unsafe { LifetimeTracked::use_(&raw const (*this_).x) }); return (*this_).n; } ); } } impl DefaultConstructibleUnsafe for p7_member_access_captures_this_HasMemberUsedInLambda { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.x); - (&raw mut self.n).write(1); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).x); + (&raw mut (*this).n).write(1); } } pub unsafe fn test_22() { (unsafe { LifetimeTracked::reset() }); object_unsafe!(c, p7_member_access_captures_this_HasMemberUsedInLambda); let mut f: FnPtr i32> = - (unsafe { p7_member_access_captures_this_HasMemberUsedInLambda::makeLambda(&mut c) }); + (unsafe { p7_member_access_captures_this_HasMemberUsedInLambda::makeLambda(&raw mut c) }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (0))); assert!(((unsafe { f.call() }) == (1))); assert!(((c.x.uses) == (1))); @@ -467,7 +468,7 @@ pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { pub x: LifetimeTracked, } impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { - pub unsafe fn sizer(&mut self) -> FnPtr usize> { + pub unsafe fn sizer(this: *mut Self) -> FnPtr usize> { return FnPtr:: usize>::new(|| -> usize { unsafe { return ::std::mem::size_of::(); @@ -476,8 +477,8 @@ impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { } } impl DefaultConstructibleUnsafe for p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.x); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).x); } } pub unsafe fn test_23() { @@ -487,7 +488,7 @@ pub unsafe fn test_23() { p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda ); let mut f: FnPtr usize> = - (unsafe { p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::sizer(&mut c) }); + (unsafe { p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::sizer(&raw mut c) }); assert!(((unsafe { f.call() }) == (::std::mem::size_of::()))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (0))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)) == (0))); @@ -527,7 +528,7 @@ pub static mut t_ctors_27: std::cell::LazyCell = std::cell::LazyCell::new(| #[memberwise(copy_assign)] pub struct p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} impl DefaultConstructibleUnsafe for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { - unsafe fn default_constructor(&mut self) { + unsafe fn default_constructor(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut t_ctors_27)).prefix_inc(); } } @@ -536,7 +537,7 @@ pub unsafe fn test_28() { let __p: *mut p9_destructor_not_potentially_invoked_HasUndefinedDestructor = Box::leak( Box::new(::zero_init()), ); - DefaultConstructibleUnsafe::default_constructor(&mut *__p); + DefaultConstructibleUnsafe::default_constructor(__p); __p }; assert!(!((p).is_null())); @@ -559,8 +560,8 @@ pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { pub value: i32, } impl DefaultConstructibleUnsafe for p9_unused_copy_constructor_HasUndefinedCopyCtor { - unsafe fn default_constructor(&mut self) { - (&raw mut self.value).write(3); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).value).write(3); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctor_calls_29)).prefix_inc(); } } @@ -570,7 +571,7 @@ impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { { let mut __v: p9_unused_copy_constructor_HasUndefinedCopyCtor = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -598,7 +599,7 @@ pub static mut m_ctors_32: std::cell::LazyCell = std::cell::LazyCell::new(| )] pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} impl DefaultConstructibleUnsafe for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - unsafe fn default_constructor(&mut self) { + unsafe fn default_constructor(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut m_ctors_32)).prefix_inc(); } } @@ -608,7 +609,7 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { { let mut __v: p9_unused_implicit_assignment_HasUndefinedCopyAssignment = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -631,8 +632,8 @@ pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { impl DefaultConstructibleUnsafe for p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.m); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).m); } } pub unsafe fn test_33() { @@ -765,21 +766,21 @@ unsafe impl p4_1_pure_virtual_without_definition_HasPureVirtual } } impl DestructibleUnsafe for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { unreachable!( "p9_destructor_not_potentially_invoked_HasUndefinedDestructor::destroy is never defined" ) } } impl CopyConstructibleUnsafe for p9_unused_copy_constructor_HasUndefinedCopyCtor { - unsafe fn copy_constructor(&mut self, _: *const Self) { + unsafe fn copy_constructor(this: *mut Self, _: *const Self) { unreachable!( "p9_unused_copy_constructor_HasUndefinedCopyCtor::copy_constructor is never defined" ) } } impl CopyAssignableUnsafe for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - unsafe fn copy_assign(&mut self, _: *const Self) -> *mut Self { + unsafe fn copy_assign(this: *mut Self, _: *const Self) -> *mut Self { unreachable!( "p9_unused_implicit_assignment_HasUndefinedCopyAssignment::copy_assign is never defined" ) diff --git a/tests/std/class/class.init/out/unsafe/class.base.init.rs b/tests/std/class/class.init/out/unsafe/class.base.init.rs index 6f3620e491..49daa0771f 100644 --- a/tests/std/class/class.init/out/unsafe/class.base.init.rs +++ b/tests/std/class/class.init/out/unsafe/class.base.init.rs @@ -24,9 +24,9 @@ pub struct p13_3_member_reads_earlier_member_Pair { pub second: i32, } impl p13_3_member_reads_earlier_member_Pair { - pub unsafe fn construct(&mut self, mut first: i32) { - (&raw mut self.first).write(first); - (&raw mut self.second).write(((self.first) + (1))); + pub unsafe fn construct(this: *mut Self, mut first: i32) { + (&raw mut (*this).first).write(first); + (&raw mut (*this).second).write((((*this).first) + (1))); } } pub unsafe fn test_0() { diff --git a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs index 696f420f4b..22ce4586f5 100644 --- a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs +++ b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.ctor.rs @@ -7,8 +7,11 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; impl p1_template_constructor_from_own_type_Probe { - pub unsafe fn construct_1(&mut self, u: *mut p1_template_constructor_from_own_type_Probe) { - (&raw mut self.value).write((((*u).value) + (1))); + pub unsafe fn construct_1( + this: *mut Self, + u: *mut p1_template_constructor_from_own_type_Probe, + ) { + (&raw mut (*this).value).write((((*u).value) + (1))); } } #[repr(C)] @@ -28,8 +31,8 @@ pub struct p1_template_constructor_from_own_type_Probe { pub value: i32, } impl p1_template_constructor_from_own_type_Probe { - pub unsafe fn construct_2(&mut self, mut v: i32) { - (&raw mut self.value).write(v); + pub unsafe fn construct_2(this: *mut Self, mut v: i32) { + (&raw mut (*this).value).write(v); } } pub unsafe fn test_0() { diff --git a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs index 0688a1be3f..ef93a9bc00 100644 --- a/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs +++ b/tests/std/class/class.mem/class.conv/out/unsafe/class.conv.fct.rs @@ -23,15 +23,15 @@ pub struct p2_non_const_conversion_function_Gauge { pub value: i64, } impl p2_non_const_conversion_function_Gauge { - pub unsafe fn to_i64(&mut self) -> i64 { - return (*self.value.prefix_inc()); + pub unsafe fn to_i64(this: *mut Self) -> i64 { + return (*(*this).value.prefix_inc()); } } pub unsafe fn test_0() { let mut gauge: p2_non_const_conversion_function_Gauge = p2_non_const_conversion_function_Gauge { value: 20_i64 }; let mut converted: i64 = - (unsafe { p2_non_const_conversion_function_Gauge::to_i64(&mut gauge) }); + (unsafe { p2_non_const_conversion_function_Gauge::to_i64(&raw mut gauge) }); assert!(((converted) == (21_i64))); assert!(((gauge.value) == (21_i64))); } diff --git a/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs b/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs index 46f516516e..6bdefc877d 100644 --- a/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs +++ b/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs @@ -21,8 +21,8 @@ pub struct p11_defaulted_move_constructor_is_trivial_MoveOnly { pub value: i32, } impl p11_defaulted_move_constructor_is_trivial_MoveOnly { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); } } pub unsafe fn pass_0( @@ -31,7 +31,7 @@ pub unsafe fn pass_0( return { let mut __v: p11_defaulted_move_constructor_is_trivial_MoveOnly = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(&mut object)); + ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut object)); __v }; } @@ -40,7 +40,7 @@ pub unsafe fn test_1() { pass_0({ let mut __v: p11_defaulted_move_constructor_is_trivial_MoveOnly = ::zero_init(); - p11_defaulted_move_constructor_is_trivial_MoveOnly::construct(&mut __v, 7); + p11_defaulted_move_constructor_is_trivial_MoveOnly::construct(&raw mut __v, 7); __v }) }); diff --git a/tests/std/class/class.mem/out/unsafe/class.mem.general.rs b/tests/std/class/class.mem/out/unsafe/class.mem.general.rs index dd49b62cf0..f67e1176e4 100644 --- a/tests/std/class/class.mem/out/unsafe/class.mem.general.rs +++ b/tests/std/class/class.mem/out/unsafe/class.mem.general.rs @@ -18,19 +18,21 @@ pub struct p7_1_function_body_names_later_member_HasLaterMembers { pub stock: i32, } impl p7_1_function_body_names_later_member_HasLaterMembers { - pub unsafe fn take(&mut self, mut amount: i32) -> i32 { - self.stock -= amount; - return (((self.stock) - + (unsafe { p7_1_function_body_names_later_member_HasLaterMembers::minimum(self) })) + pub unsafe fn take(this: *mut Self, mut amount: i32) -> i32 { + (*this).stock -= amount; + return ((((*this).stock) + + (unsafe { + p7_1_function_body_names_later_member_HasLaterMembers::minimum((this).cast_const()) + })) + (anon_2_reserve as i32)); } - pub unsafe fn minimum(&self) -> i32 { + pub unsafe fn minimum(this: *const Self) -> i32 { return 2; } } impl DefaultConstructibleUnsafe for p7_1_function_body_names_later_member_HasLaterMembers { - unsafe fn default_constructor(&mut self) { - (&raw mut self.stock).write(9); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).stock).write(9); } } impl Default for p7_1_function_body_names_later_member_HasLaterMembers { @@ -44,8 +46,9 @@ pub unsafe fn test_3() { p7_1_function_body_names_later_member_HasLaterMembers ); assert!( - ((unsafe { p7_1_function_body_names_later_member_HasLaterMembers::take(&mut object, 3,) }) - == (38)) + ((unsafe { + p7_1_function_body_names_later_member_HasLaterMembers::take(&raw mut object, 3) + }) == (38)) ); assert!(((object.stock) == (6))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut stock_0)) == (100))); @@ -58,14 +61,14 @@ pub struct p7_2_default_argument_names_later_member_HasLaterStaticStep { pub total: i32, } impl p7_2_default_argument_names_later_member_HasLaterStaticStep { - pub unsafe fn advance(&mut self, mut amount: i32) -> i32 { - self.total += amount; - return self.total; + pub unsafe fn advance(this: *mut Self, mut amount: i32) -> i32 { + (*this).total += amount; + return (*this).total; } } impl DefaultConstructibleUnsafe for p7_2_default_argument_names_later_member_HasLaterStaticStep { - unsafe fn default_constructor(&mut self) { - (&raw mut self.total).write(1); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).total).write(1); } } impl Default for p7_2_default_argument_names_later_member_HasLaterStaticStep { @@ -81,14 +84,14 @@ pub unsafe fn test_6() { assert!( ((unsafe { p7_2_default_argument_names_later_member_HasLaterStaticStep::advance( - &mut object, + &raw mut object, (*std::cell::LazyCell::force_mut(&mut *&raw mut step_5)), ) }) == (5)) ); assert!( ((unsafe { - p7_2_default_argument_names_later_member_HasLaterStaticStep::advance(&mut object, 2) + p7_2_default_argument_names_later_member_HasLaterStaticStep::advance(&raw mut object, 2) }) == (7)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut step_4)) == (100))); diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs index cef1096ddd..8b2c7d2d64 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/out/unsafe/dcl.init.general.rs @@ -333,9 +333,9 @@ pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { pub five: i32, } impl DefaultConstructibleUnsafe for p9_1_2_zero_then_default_initialized_WithDefaultMember { - unsafe fn default_constructor(&mut self) { - (&raw mut self.zeroed).write(0_i32); - (&raw mut self.five).write(5); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).zeroed).write(0_i32); + (&raw mut (*this).five).write(5); } } impl Default for p9_1_2_zero_then_default_initialized_WithDefaultMember { @@ -354,8 +354,8 @@ pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { pub untouched: i32, } impl DefaultConstructibleUnsafe for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { - unsafe fn default_constructor(&mut self) { - (&raw mut self.untouched).write(0_i32); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).untouched).write(0_i32); } } impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { @@ -364,7 +364,7 @@ impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { { let mut __v: p9_1_2_zero_then_default_initialized_LeavesMemberAlone = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -379,9 +379,9 @@ pub struct p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { pub member: p9_1_2_zero_then_default_initialized_LeavesMemberAlone, } impl DefaultConstructibleUnsafe for p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { - unsafe fn default_constructor(&mut self) { - (&raw mut self.number).write(0_i32); - DefaultConstructibleUnsafe::default_constructor(&mut self.member); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).number).write(0_i32); + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).member); } } pub unsafe fn test_22() { @@ -395,7 +395,7 @@ pub unsafe fn test_22() { let __p: *mut p9_1_2_zero_then_default_initialized_WithDefaultMember = Box::leak(Box::new( ::zero_init(), )); - DefaultConstructibleUnsafe::default_constructor(&mut *__p); + DefaultConstructibleUnsafe::default_constructor(__p); __p }; assert!((((*heap).zeroed) == (0))); @@ -416,7 +416,7 @@ pub unsafe fn test_22() { let __p: *mut p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone = Box::leak( Box::new(::zero_init()), ); - DefaultConstructibleUnsafe::default_constructor(&mut *__p); + DefaultConstructibleUnsafe::default_constructor(__p); __p }; assert!((((*heap_holder).number) == (0))); diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs index eae9df980c..8ba134d982 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/unsafe/dcl.fct.default.rs @@ -59,14 +59,14 @@ pub struct p9_static_member_hides_namespace_variable_HasStaticStep { pub total: i32, } impl p9_static_member_hides_namespace_variable_HasStaticStep { - pub unsafe fn advance(&mut self, mut amount: i32) -> i32 { - self.total += amount; - return self.total; + pub unsafe fn advance(this: *mut Self, mut amount: i32) -> i32 { + (*this).total += amount; + return (*this).total; } } impl DefaultConstructibleUnsafe for p9_static_member_hides_namespace_variable_HasStaticStep { - unsafe fn default_constructor(&mut self) { - (&raw mut self.total).write(1); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).total).write(1); } } impl Default for p9_static_member_hides_namespace_variable_HasStaticStep { @@ -82,7 +82,7 @@ pub unsafe fn test_11() { assert!( ((unsafe { p9_static_member_hides_namespace_variable_HasStaticStep::advance( - &mut object, + &raw mut object, (*std::cell::LazyCell::force_mut(&mut *&raw mut step_10)), ) }) == (5)) @@ -91,14 +91,14 @@ pub unsafe fn test_11() { assert!( ((unsafe { p9_static_member_hides_namespace_variable_HasStaticStep::advance( - &mut object, + &raw mut object, (*std::cell::LazyCell::force_mut(&mut *&raw mut step_10)), ) }) == (11)) ); assert!( ((unsafe { - p9_static_member_hides_namespace_variable_HasStaticStep::advance(&mut object, 2) + p9_static_member_hides_namespace_variable_HasStaticStep::advance(&raw mut object, 2) }) == (13)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut step_9)) == (100))); @@ -120,17 +120,14 @@ pub struct p9_evaluated_each_time_called_Widget { pub id: i32, } impl p9_evaluated_each_time_called_Widget { - pub unsafe fn construct(&mut self, mut id: i32) { - (&raw mut self.id).write(id); + pub unsafe fn construct(this: *mut Self, mut id: i32) { + (&raw mut (*this).id).write(id); } } impl DefaultConstructibleUnsafe for p9_evaluated_each_time_called_Widget { - unsafe fn default_constructor(&mut self) { + unsafe fn default_constructor(this: *mut Self) { unsafe { - p9_evaluated_each_time_called_Widget::construct( - &mut *self, - (unsafe { count_default_13() }), - ); + p9_evaluated_each_time_called_Widget::construct(this, (unsafe { count_default_13() })); } } } @@ -141,7 +138,7 @@ impl Default for p9_evaluated_each_time_called_Widget { let mut __v: p9_evaluated_each_time_called_Widget = ::zero_init(); p9_evaluated_each_time_called_Widget::construct( - &mut __v, + &raw mut __v, (unsafe { count_default_13() }), ); __v @@ -161,17 +158,17 @@ impl p9_evaluated_each_time_called_Account { unsafe fn twice(mut value: i32) -> i32 { return ((2) * (value)); } - pub unsafe fn deposit(&mut self, mut amount: i32) -> i32 { - self.balance += amount; - return self.balance; + pub unsafe fn deposit(this: *mut Self, mut amount: i32) -> i32 { + (*this).balance += amount; + return (*this).balance; } pub unsafe fn set_base(mut value: i32) { (*std::cell::LazyCell::force_mut(&mut *&raw mut base_15)) = value; } } impl DefaultConstructibleUnsafe for p9_evaluated_each_time_called_Account { - unsafe fn default_constructor(&mut self) { - (&raw mut self.balance).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).balance).write(0); } } impl Default for p9_evaluated_each_time_called_Account { @@ -208,7 +205,7 @@ pub unsafe fn test_17() { assert!( ((unsafe { p9_evaluated_each_time_called_Account::deposit( - &mut account, + &raw mut account, ((unsafe { p9_evaluated_each_time_called_Account::twice( (*std::cell::LazyCell::force_mut(&mut *&raw mut base_15)), @@ -221,7 +218,7 @@ pub unsafe fn test_17() { assert!( ((unsafe { p9_evaluated_each_time_called_Account::deposit( - &mut account, + &raw mut account, ((unsafe { p9_evaluated_each_time_called_Account::twice( (*std::cell::LazyCell::force_mut(&mut *&raw mut base_15)), @@ -231,7 +228,7 @@ pub unsafe fn test_17() { }) == (32)) ); assert!( - ((unsafe { p9_evaluated_each_time_called_Account::deposit(&mut account, 3,) }) == (35)) + ((unsafe { p9_evaluated_each_time_called_Account::deposit(&raw mut account, 3,) }) == (35)) ); } pub unsafe fn add_18(mut a: i32, mut b: i32) -> i32 { diff --git a/tests/std/expr/expr.compound/expr.unary/out/unsafe/expr.unary.op.rs b/tests/std/expr/expr.compound/expr.unary/out/unsafe/expr.unary.op.rs index d6ab330b13..47ba7f3017 100644 --- a/tests/std/expr/expr.compound/expr.unary/out/unsafe/expr.unary.op.rs +++ b/tests/std/expr/expr.compound/expr.unary/out/unsafe/expr.unary.op.rs @@ -86,11 +86,11 @@ pub struct p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMemb pub value: i32, } impl p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMember { - pub unsafe fn parenthesized(&mut self) -> *mut i32 { - return (&mut (self.value) as *mut i32); + pub unsafe fn parenthesized(this: *mut Self) -> *mut i32 { + return (&mut ((*this).value) as *mut i32); } - pub unsafe fn unqualified(&mut self) -> *mut i32 { - return (&mut self.value as *mut i32); + pub unsafe fn unqualified(this: *mut Self) -> *mut i32 { + return (&mut (*this).value as *mut i32); } } pub unsafe fn test_4() { @@ -100,7 +100,7 @@ pub unsafe fn test_4() { p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMember { value: 4 }; let mut p: *mut i32 = (unsafe { p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMember::parenthesized( - &mut first, + &raw mut first, ) }); assert!(((p) == (&mut first.value as *mut i32))); @@ -109,7 +109,7 @@ pub unsafe fn test_4() { assert!(((second.value) == (4))); let mut q: *mut i32 = (unsafe { p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMember::unqualified( - &mut second, + &raw mut second, ) }); assert!(((q) == (&mut second.value as *mut i32))); diff --git a/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs b/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs index ec45af9fb2..94eb7fbc68 100644 --- a/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs +++ b/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs @@ -131,7 +131,7 @@ pub static mut moveCount_10: std::cell::LazyCell = std::cell::LazyCell::new pub struct p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} impl CopyConstructibleUnsafe for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { unsafe fn copy_constructor( - &mut self, + this: *mut Self, _a0: *const p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, ) { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_9)).prefix_inc(); @@ -139,7 +139,7 @@ impl CopyConstructibleUnsafe for p6_data_member_of_rvalue_is_xvalue_CountsCopies } impl MoveConstructibleUnsafe for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { unsafe fn move_constructor( - &mut self, + this: *mut Self, _a0: *mut p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, ) { (*std::cell::LazyCell::force_mut(&mut *&raw mut moveCount_10)).prefix_inc(); diff --git a/tests/std/expr/expr.prim/out/unsafe/expr.prim.this.rs b/tests/std/expr/expr.prim/out/unsafe/expr.prim.this.rs index b58309a70c..9f76306c66 100644 --- a/tests/std/expr/expr.prim/out/unsafe/expr.prim.this.rs +++ b/tests/std/expr/expr.prim/out/unsafe/expr.prim.this.rs @@ -23,12 +23,11 @@ pub struct p1_default_member_initializer_names_object_Holder { pub value: i32, } impl p1_default_member_initializer_names_object_Holder { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.self_) - .write((self as *mut p1_default_member_initializer_names_object_Holder)); - (&raw mut self.value).write(value); - assert!(((self.self_) == (self as *mut p1_default_member_initializer_names_object_Holder))); - assert!((((*self.self_).value) == (value))); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).self_).write(this); + (&raw mut (*this).value).write(value); + assert!((((*this).self_) == (this))); + assert!((((*(*this).self_).value) == (value))); } } impl Default for p1_default_member_initializer_names_object_Holder { @@ -58,12 +57,12 @@ pub struct p1_mem_initializer_names_object_Holder { pub value: i32, } impl p1_mem_initializer_names_object_Holder { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.self_).write((self as *mut p1_mem_initializer_names_object_Holder)); - (&raw mut self.value).write(value); - assert!(((self.self_) == (self as *mut p1_mem_initializer_names_object_Holder))); - (*self.self_).value += 1; - assert!(((self.value) == ((value) + (1)))); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).self_).write(this); + (&raw mut (*this).value).write(value); + assert!((((*this).self_) == (this))); + (*(*this).self_).value += 1; + assert!((((*this).value) == ((value) + (1)))); } } pub unsafe fn test_1() { @@ -87,11 +86,11 @@ pub struct p1_this_is_a_copy_of_the_pointer_Node { } impl p1_this_is_a_copy_of_the_pointer_Node { pub unsafe fn advance( - &mut self, + this: *mut Self, cursor: *mut *mut p1_this_is_a_copy_of_the_pointer_Node, ) -> i32 { - (*cursor) = self.next; - return self.value; + (*cursor) = (*this).next; + return (*this).value; } } pub unsafe fn test_2() { @@ -108,7 +107,7 @@ pub unsafe fn test_2() { assert!( ((unsafe { let _cursor: *mut *mut p1_this_is_a_copy_of_the_pointer_Node = &mut cursor; - p1_this_is_a_copy_of_the_pointer_Node::advance(&mut (*cursor), _cursor) + p1_this_is_a_copy_of_the_pointer_Node::advance(&raw mut (*cursor), _cursor) }) == (1)) ); assert!(((cursor) == (&mut second as *mut p1_this_is_a_copy_of_the_pointer_Node))); diff --git a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs index 24bd0567b2..0f080d78b2 100644 --- a/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs +++ b/tests/std/library/requirements/utility.requirements/allocator.requirements/out/unsafe/allocator.requirements.general.rs @@ -24,8 +24,8 @@ pub struct p16_rebind_member_Alloc_std_pair_const_int__int__ { pub id: i32, } impl DefaultConstructibleUnsafe for p16_rebind_member_Alloc_std_pair_const_int__int__ { - unsafe fn default_constructor(&mut self) { - (&raw mut self.id).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).id).write(0); } } impl Default for p16_rebind_member_Alloc_std_pair_const_int__int__ { diff --git a/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs b/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs index 68d9d72333..4a245a6df0 100644 --- a/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs +++ b/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs @@ -26,16 +26,16 @@ pub struct p2_condition_variable_created_each_iteration_ConvertsToBool { pub value: i32, } impl p2_condition_variable_created_each_iteration_ConvertsToBool { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } - pub unsafe fn to_bool(&self) -> bool { - return ((self.value) != (0)); + pub unsafe fn to_bool(this: *const Self) -> bool { + return (((*this).value) != (0)); } } impl DestructibleUnsafe for p2_condition_variable_created_each_iteration_ConvertsToBool { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_1)).prefix_inc(); } } @@ -48,7 +48,9 @@ pub unsafe fn test_2() { p2_condition_variable_created_each_iteration_ConvertsToBool(remaining) ); if !(unsafe { - p2_condition_variable_created_each_iteration_ConvertsToBool::to_bool(&condition) + p2_condition_variable_created_each_iteration_ConvertsToBool::to_bool( + &raw const condition, + ) }) { break; } @@ -84,16 +86,16 @@ pub struct p2_continue_destroys_condition_variable_ConvertsToBool { pub value: i32, } impl p2_continue_destroys_condition_variable_ConvertsToBool { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_3)).prefix_inc(); } - pub unsafe fn to_bool(&self) -> bool { - return ((self.value) != (0)); + pub unsafe fn to_bool(this: *const Self) -> bool { + return (((*this).value) != (0)); } } impl DestructibleUnsafe for p2_continue_destroys_condition_variable_ConvertsToBool { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_4)).prefix_inc(); } } @@ -106,8 +108,9 @@ pub unsafe fn test_5() { condition, p2_continue_destroys_condition_variable_ConvertsToBool(remaining) ); - if !(unsafe { p2_continue_destroys_condition_variable_ConvertsToBool::to_bool(&condition) }) - { + if !(unsafe { + p2_continue_destroys_condition_variable_ConvertsToBool::to_bool(&raw const condition) + }) { break; } remaining.prefix_dec(); diff --git a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs index 0712640fcc..1d35d3d76e 100644 --- a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs +++ b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs @@ -36,25 +36,25 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { - (&raw mut self.uses).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -72,7 +72,7 @@ pub unsafe fn test_6() { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); } else { (*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)).prefix_inc(); - (unsafe { LifetimeTracked::use_(&guard) }); + (unsafe { LifetimeTracked::use_(&raw const guard) }); assert!(((guard.uses) == (1))); assert!(((choice) == (0))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (0))); @@ -86,7 +86,7 @@ pub unsafe fn test_6() { let mut choice: i32 = 4; if (choice != 0) { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); - (unsafe { LifetimeTracked::use_(&guard) }); + (unsafe { LifetimeTracked::use_(&raw const guard) }); assert!(((guard.uses) == (1))); assert!(((choice) == (4))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (1))); diff --git a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs index 1b4268c052..e8d742890a 100644 --- a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs +++ b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs @@ -36,25 +36,25 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn use_(&self) { - (*(&raw const self.uses).cast_mut()).prefix_inc(); + pub unsafe fn use_(this: *const Self) { + (*(&raw const (*this).uses).cast_mut()).prefix_inc(); (*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_3)).prefix_inc(); } } impl DefaultConstructibleUnsafe for LifetimeTracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.uses).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); } } impl CopyConstructibleUnsafe for LifetimeTracked { - unsafe fn copy_constructor(&mut self, _a0: *const LifetimeTracked) { - (&raw mut self.uses).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const LifetimeTracked) { + (&raw mut (*this).uses).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); } } impl DestructibleUnsafe for LifetimeTracked { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); } } @@ -81,12 +81,12 @@ pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { pub value: i32, } impl p2_condition_variable_lives_for_whole_statement_ConvertsToInt { - pub unsafe fn to_i32(&self) -> i32 { - return self.value; + pub unsafe fn to_i32(this: *const Self) -> i32 { + return (*this).value; } } impl DestructibleUnsafe for p2_condition_variable_lives_for_whole_statement_ConvertsToInt { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_6)).prefix_inc(); } } @@ -95,12 +95,14 @@ pub unsafe fn test_7() { let mut selector: p2_condition_variable_lives_for_whole_statement_ConvertsToInt = p2_condition_variable_lives_for_whole_statement_ConvertsToInt { value: 2 }; let _dtor_selector = std::mem::DropGuard::new(&raw mut selector, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); 'switch: { match { (unsafe { - p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32(&selector) + p2_condition_variable_lives_for_whole_statement_ConvertsToInt::to_i32( + &raw const selector, + ) }) } { __v if __v == 2 => { @@ -137,7 +139,7 @@ pub unsafe fn test_10() { __v if __v == 2 => { (*std::cell::LazyCell::force_mut(&mut *&raw mut matching_case_runs_8)) .prefix_inc(); - (unsafe { LifetimeTracked::use_(&guard) }); + (unsafe { LifetimeTracked::use_(&raw const guard) }); assert!(((guard.uses) == (1))); assert!(((selector) == (2))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (0))); diff --git a/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs b/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs index 03363dd36a..f438666927 100644 --- a/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs +++ b/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs @@ -13,15 +13,15 @@ pub struct p2_reference_does_not_instantiate_Member { } impl p2_reference_does_not_instantiate_Member { pub unsafe fn construct_1( - &mut self, + this: *mut Self, _a0: *const p2_reference_does_not_instantiate_Wrapper_int_, ) { - (&raw mut self.value).write(2); + (&raw mut (*this).value).write(2); } } impl DefaultConstructibleUnsafe for p2_reference_does_not_instantiate_Member { - unsafe fn default_constructor(&mut self) { - (&raw mut self.value).write(1); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).value).write(1); } } impl Default for p2_reference_does_not_instantiate_Member { @@ -36,8 +36,8 @@ pub struct p2_reference_does_not_instantiate_Holder { pub member: p2_reference_does_not_instantiate_Member, } impl DefaultConstructibleUnsafe for p2_reference_does_not_instantiate_Holder { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.member); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).member); } } pub unsafe fn test_0() { diff --git a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs index f450a59b50..c670d40b34 100644 --- a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs +++ b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs @@ -23,18 +23,18 @@ pub struct p6_forward_like_Movable { pub value: i32, } impl p6_forward_like_Movable { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); } } impl CopyConstructibleUnsafe for p6_forward_like_Movable { - unsafe fn copy_constructor(&mut self, other: *const p6_forward_like_Movable) { - (&raw mut self.value).write((*other).value); + unsafe fn copy_constructor(this: *mut Self, other: *const p6_forward_like_Movable) { + (&raw mut (*this).value).write((*other).value); } } impl MoveConstructibleUnsafe for p6_forward_like_Movable { - unsafe fn move_constructor(&mut self, other: *mut p6_forward_like_Movable) { - (&raw mut self.value).write((*other).value); + unsafe fn move_constructor(this: *mut Self, other: *mut p6_forward_like_Movable) { + (&raw mut (*this).value).write((*other).value); (*other).value = 0; } } @@ -45,8 +45,8 @@ pub struct p6_forward_like_Holder { pub member: p6_forward_like_Movable, } impl DefaultConstructibleUnsafe for p6_forward_like_Holder { - unsafe fn default_constructor(&mut self) { - p6_forward_like_Movable::construct(&mut self.member, 1); + unsafe fn default_constructor(this: *mut Self) { + p6_forward_like_Movable::construct(&raw mut (*this).member, 1); } } impl Default for p6_forward_like_Holder { @@ -55,7 +55,7 @@ impl Default for p6_forward_like_Holder { p6_forward_like_Holder { member: { let mut __v: p6_forward_like_Movable = ::zero_init(); - p6_forward_like_Movable::construct(&mut __v, 1); + p6_forward_like_Movable::construct(&raw mut __v, 1); __v }, } @@ -63,11 +63,11 @@ impl Default for p6_forward_like_Holder { } } pub unsafe fn take_1(__return: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { - ConstructFromUnsafe::construct_from(&mut *__return, &(*self_).member); + ConstructFromUnsafe::construct_from(__return, &(*self_).member); return; } pub unsafe fn take_2(__return: *mut p6_forward_like_Movable, self_: *mut p6_forward_like_Holder) { - ConstructFromUnsafe::construct_from(&mut *__return, Moved(&mut (*self_).member)); + ConstructFromUnsafe::construct_from(__return, Moved(&mut (*self_).member)); return; } pub unsafe fn test_3() { @@ -90,13 +90,13 @@ pub struct p9_move_Movable { pub value: i32, } impl p9_move_Movable { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); } } impl MoveConstructibleUnsafe for p9_move_Movable { - unsafe fn move_constructor(&mut self, other: *mut p9_move_Movable) { - (&raw mut self.value).write((*other).value); + unsafe fn move_constructor(this: *mut Self, other: *mut p9_move_Movable) { + (&raw mut (*this).value).write((*other).value); (*other).value = 0; } } @@ -139,24 +139,24 @@ pub struct p10_forward_in_template_A { pub moves: i32, } impl p10_forward_in_template_A { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); - (&raw mut self.copies).write(0); - (&raw mut self.moves).write(0); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); + (&raw mut (*this).copies).write(0); + (&raw mut (*this).moves).write(0); } } impl CopyConstructibleUnsafe for p10_forward_in_template_A { - unsafe fn copy_constructor(&mut self, other: *const p10_forward_in_template_A) { - (&raw mut self.value).write((*other).value); - (&raw mut self.copies).write((((*other).copies) + (1))); - (&raw mut self.moves).write(0); + unsafe fn copy_constructor(this: *mut Self, other: *const p10_forward_in_template_A) { + (&raw mut (*this).value).write((*other).value); + (&raw mut (*this).copies).write((((*other).copies) + (1))); + (&raw mut (*this).moves).write(0); } } impl MoveConstructibleUnsafe for p10_forward_in_template_A { - unsafe fn move_constructor(&mut self, other: *mut p10_forward_in_template_A) { - (&raw mut self.value).write((*other).value); - (&raw mut self.copies).write(0); - (&raw mut self.moves).write((((*other).moves) + (1))); + unsafe fn move_constructor(this: *mut Self, other: *mut p10_forward_in_template_A) { + (&raw mut (*this).value).write((*other).value); + (&raw mut (*this).copies).write(0); + (&raw mut (*this).moves).write((((*other).moves) + (1))); (*other).value = 0; } } @@ -169,14 +169,14 @@ pub unsafe fn make_5( __return: *mut p10_forward_in_template_A, source: *mut p10_forward_in_template_A, ) { - ConstructFromUnsafe::construct_from(&mut *__return, source); + ConstructFromUnsafe::construct_from(__return, source); return; } pub unsafe fn make_6( __return: *mut p10_forward_in_template_A, source: *mut p10_forward_in_template_A, ) { - ConstructFromUnsafe::construct_from(&mut *__return, Moved(source)); + ConstructFromUnsafe::construct_from(__return, Moved(source)); return; } pub unsafe fn test_7() { @@ -201,18 +201,18 @@ pub struct p11_move_if_noexcept_NoexceptMove { pub value: i32, } impl p11_move_if_noexcept_NoexceptMove { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); } } impl CopyConstructibleUnsafe for p11_move_if_noexcept_NoexceptMove { - unsafe fn copy_constructor(&mut self, other: *const p11_move_if_noexcept_NoexceptMove) { - (&raw mut self.value).write((*other).value); + unsafe fn copy_constructor(this: *mut Self, other: *const p11_move_if_noexcept_NoexceptMove) { + (&raw mut (*this).value).write((*other).value); } } impl MoveConstructibleUnsafe for p11_move_if_noexcept_NoexceptMove { - unsafe fn move_constructor(&mut self, other: *mut p11_move_if_noexcept_NoexceptMove) { - (&raw mut self.value).write((*other).value); + unsafe fn move_constructor(this: *mut Self, other: *mut p11_move_if_noexcept_NoexceptMove) { + (&raw mut (*this).value).write((*other).value); (*other).value = 0; } } @@ -225,18 +225,18 @@ pub struct p11_move_if_noexcept_ThrowingMove { pub value: i32, } impl p11_move_if_noexcept_ThrowingMove { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); } } impl CopyConstructibleUnsafe for p11_move_if_noexcept_ThrowingMove { - unsafe fn copy_constructor(&mut self, other: *const p11_move_if_noexcept_ThrowingMove) { - (&raw mut self.value).write((*other).value); + unsafe fn copy_constructor(this: *mut Self, other: *const p11_move_if_noexcept_ThrowingMove) { + (&raw mut (*this).value).write((*other).value); } } impl MoveConstructibleUnsafe for p11_move_if_noexcept_ThrowingMove { - unsafe fn move_constructor(&mut self, other: *mut p11_move_if_noexcept_ThrowingMove) { - (&raw mut self.value).write((*other).value); + unsafe fn move_constructor(this: *mut Self, other: *mut p11_move_if_noexcept_ThrowingMove) { + (&raw mut (*this).value).write((*other).value); (*other).value = 0; } } diff --git a/tests/std/utilities/utility/out/unsafe/forward.rs b/tests/std/utilities/utility/out/unsafe/forward.rs index 41d519b89c..e9ed628da7 100644 --- a/tests/std/utilities/utility/out/unsafe/forward.rs +++ b/tests/std/utilities/utility/out/unsafe/forward.rs @@ -56,13 +56,13 @@ pub struct p10_move_constructor_A { pub value: i32, } impl p10_move_constructor_A { - pub unsafe fn construct(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); } } impl MoveConstructibleUnsafe for p10_move_constructor_A { - unsafe fn move_constructor(&mut self, other: *mut p10_move_constructor_A) { - (&raw mut self.value).write((*other).value); + unsafe fn move_constructor(this: *mut Self, other: *mut p10_move_constructor_A) { + (&raw mut (*this).value).write((*other).value); (*other).value = 0; } } diff --git a/tests/std/utilities/utility/out/unsafe/utility.as.const.rs b/tests/std/utilities/utility/out/unsafe/utility.as.const.rs index 9e25c6649a..3968b3170c 100644 --- a/tests/std/utilities/utility/out/unsafe/utility.as.const.rs +++ b/tests/std/utilities/utility/out/unsafe/utility.as.const.rs @@ -21,11 +21,11 @@ pub struct p1_as_const_Counter { pub value: i32, } impl p1_as_const_Counter { - pub unsafe fn get_1(&mut self) -> i32 { - return ((self.value) + (1)); + pub unsafe fn get_1(this: *mut Self) -> i32 { + return (((*this).value) + (1)); } - pub unsafe fn get_2(&self) -> i32 { - return self.value; + pub unsafe fn get_2(this: *const Self) -> i32 { + return (*this).value; } } pub unsafe fn test_0() { @@ -38,8 +38,8 @@ pub unsafe fn test_0() { let mut pointer: *mut i32 = (&mut number as *mut i32); assert!(((pointer) == (&mut number as *mut i32))); let mut counter: p1_as_const_Counter = p1_as_const_Counter { value: 5 }; - assert!(((unsafe { p1_as_const_Counter::get_2(&counter,) }) == (5))); - assert!(((unsafe { p1_as_const_Counter::get_1(&mut counter,) }) == (6))); + assert!(((unsafe { p1_as_const_Counter::get_2(&raw const counter,) }) == (5))); + assert!(((unsafe { p1_as_const_Counter::get_1(&raw mut counter,) }) == (6))); } pub fn main() { unsafe { diff --git a/tests/ub/out/unsafe/ctor_ref_member.rs b/tests/ub/out/unsafe/ctor_ref_member.rs index 3c1669bbb0..df6ec800d2 100644 --- a/tests/ub/out/unsafe/ctor_ref_member.rs +++ b/tests/ub/out/unsafe/ctor_ref_member.rs @@ -23,8 +23,8 @@ pub struct S { pub r: *const i32, } impl S { - pub unsafe fn construct(&mut self, x: *const i32) { - (&raw mut self.r).write(x); + pub unsafe fn construct(this: *mut Self, x: *const i32) { + (&raw mut (*this).r).write(x); } } pub fn main() { diff --git a/tests/unit/out/unsafe/05_new.rs b/tests/unit/out/unsafe/05_new.rs index e759fb132e..a1efffa008 100644 --- a/tests/unit/out/unsafe/05_new.rs +++ b/tests/unit/out/unsafe/05_new.rs @@ -31,7 +31,7 @@ pub struct A {} )] pub struct D {} impl D { - pub unsafe fn operator_call(&self, mut ptr: *const A) { + pub unsafe fn operator_call(this: *const Self, mut ptr: *const A) { { let __p = ptr; if !__p.is_null() { diff --git a/tests/unit/out/unsafe/10_struct.rs b/tests/unit/out/unsafe/10_struct.rs index ec9f7117a2..62398003c9 100644 --- a/tests/unit/out/unsafe/10_struct.rs +++ b/tests/unit/out/unsafe/10_struct.rs @@ -37,14 +37,14 @@ pub struct Graph { pub adj: *mut *mut GraphNode, } impl Graph { - pub unsafe fn push(&self, mut src: u32, mut dst: u32) { - (*self.adj.offset((src) as isize)) = (Box::leak(Box::new(GraphNode { + pub unsafe fn push(this: *const Self, mut src: u32, mut dst: u32) { + (*(*this).adj.offset((src) as isize)) = (Box::leak(Box::new(GraphNode { dst: dst, - next: (*self.adj.offset((src) as isize)), + next: (*(*this).adj.offset((src) as isize)), })) as *mut GraphNode); - (*self.adj.offset((dst) as isize)) = (Box::leak(Box::new(GraphNode { + (*(*this).adj.offset((dst) as isize)) = (Box::leak(Box::new(GraphNode { dst: src, - next: (*self.adj.offset((dst) as isize)), + next: (*(*this).adj.offset((dst) as isize)), })) as *mut GraphNode); } } @@ -54,13 +54,13 @@ pub struct Partial { pub p: *mut i32, } impl Partial { - pub unsafe fn construct_1(&mut self, mut q: *mut i32) { - (&raw mut self.p).write(q); + pub unsafe fn construct_1(this: *mut Self, mut q: *mut i32) { + (&raw mut (*this).p).write(q); } } impl DefaultConstructibleUnsafe for Partial { - unsafe fn default_constructor(&mut self) { - (&raw mut self.p).write(std::ptr::null_mut()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).p).write(std::ptr::null_mut()); } } impl Default for Partial { diff --git a/tests/unit/out/unsafe/any.rs b/tests/unit/out/unsafe/any.rs index 79f9527793..676e6ad93b 100644 --- a/tests/unit/out/unsafe/any.rs +++ b/tests/unit/out/unsafe/any.rs @@ -22,9 +22,9 @@ pub struct Point { pub y: i32, } impl Point { - pub unsafe fn construct(&mut self, mut x: i32, mut y: i32) { - (&raw mut self.x).write(x); - (&raw mut self.y).write(y); + pub unsafe fn construct(this: *mut Self, mut x: i32, mut y: i32) { + (&raw mut (*this).x).write(x); + (&raw mut (*this).y).write(y); } } pub fn main() { @@ -36,7 +36,7 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut a: Option> = Some(Box::new({ let mut __v: Point = ::zero_init(); - Point::construct(&mut __v, 3, 4); + Point::construct(&raw mut __v, 3, 4); __v })); assert!(a.is_some()); @@ -65,7 +65,7 @@ unsafe fn main_0() -> i32 { let q: *mut Point = { a = Some(Box::new({ let mut __v: Point = ::zero_init(); - Point::construct(&mut __v, 5, 6); + Point::construct(&raw mut __v, 5, 6); __v })); a.as_mut().unwrap().downcast_mut::().unwrap() diff --git a/tests/unit/out/unsafe/array_of_noncopy_struct.rs b/tests/unit/out/unsafe/array_of_noncopy_struct.rs index 1a149bffad..26b8dd2b99 100644 --- a/tests/unit/out/unsafe/array_of_noncopy_struct.rs +++ b/tests/unit/out/unsafe/array_of_noncopy_struct.rs @@ -23,9 +23,9 @@ pub struct NonCopy { pub tag: i32, } impl DefaultConstructibleUnsafe for NonCopy { - unsafe fn default_constructor(&mut self) { - (&raw mut self.data).write(Vec::new()); - (&raw mut self.tag).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).data).write(Vec::new()); + (&raw mut (*this).tag).write(0); } } impl Default for NonCopy { @@ -47,7 +47,7 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut arr: [NonCopy; 3] = std::array::from_fn::<_, 3, _>(|_| { let mut __v: NonCopy = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }); arr[(0) as usize].tag = 7; diff --git a/tests/unit/out/unsafe/as_const.rs b/tests/unit/out/unsafe/as_const.rs index cfe9e4b522..90835907eb 100644 --- a/tests/unit/out/unsafe/as_const.rs +++ b/tests/unit/out/unsafe/as_const.rs @@ -24,17 +24,17 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn f_1(&mut self) -> Overload { + pub unsafe fn f_1(this: *mut Self) -> Overload { return Overload_kMutableOverload; } - pub unsafe fn f_2(&self) -> Overload { + pub unsafe fn f_2(this: *const Self) -> Overload { return Overload_kConstOverload; } - pub unsafe fn value_ref_3(&mut self) -> *mut i32 { - return &mut self.v; + pub unsafe fn value_ref_3(this: *mut Self) -> *mut i32 { + return &mut (*this).v; } - pub unsafe fn value_ref_4(&self) -> *const i32 { - return &self.v; + pub unsafe fn value_ref_4(this: *const Self) -> *const i32 { + return &(*this).v; } } pub unsafe fn g_0(_a0: *mut S) -> Overload { @@ -51,20 +51,20 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut s: S = S { v: 7 }; - assert!((((unsafe { S::f_1(&mut s,) }) as i32) == (Overload_kMutableOverload as i32))); - assert!((((unsafe { S::f_2(&s,) }) as i32) == (Overload_kConstOverload as i32))); + assert!((((unsafe { S::f_1(&raw mut s,) }) as i32) == (Overload_kMutableOverload as i32))); + assert!((((unsafe { S::f_2(&raw const s,) }) as i32) == (Overload_kConstOverload as i32))); assert!((((unsafe { g_0(&mut s,) }) as i32) == (Overload_kMutableOverload as i32))); assert!((((unsafe { g_1(&s,) }) as i32) == (Overload_kConstOverload as i32))); - (*(unsafe { S::value_ref_3(&mut s) })) = 9; + (*(unsafe { S::value_ref_3(&raw mut s) })) = 9; assert!(((s.v) == (9))); - assert!(((*(unsafe { S::value_ref_4(&s,) })) == (9))); + assert!(((*(unsafe { S::value_ref_4(&raw const s,) })) == (9))); let cs: *const S = &s; - assert!((((unsafe { S::f_2(&(*cs),) }) as i32) == (Overload_kConstOverload as i32))); + assert!((((unsafe { S::f_2(&raw const (*cs),) }) as i32) == (Overload_kConstOverload as i32))); assert!((((*cs).v) == (9))); let mut p: *mut S = (&mut s as *mut S); (*p).v = 11; assert!(((s.v) == (11))); - assert!((((unsafe { S::f_1(&mut (*p),) }) as i32) == (Overload_kMutableOverload as i32))); + assert!((((unsafe { S::f_1(&raw mut (*p),) }) as i32) == (Overload_kMutableOverload as i32))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/assignment_single_eval.rs b/tests/unit/out/unsafe/assignment_single_eval.rs index 99b439ee17..a6d55f72e3 100644 --- a/tests/unit/out/unsafe/assignment_single_eval.rs +++ b/tests/unit/out/unsafe/assignment_single_eval.rs @@ -1461,7 +1461,7 @@ pub static mut selected_values_34: std::cell::LazyCell<[u32; 3]> = )] pub struct IndexedBinding {} impl IndexedBinding { - pub unsafe fn get_1_0(&mut self) -> *mut u32 { + pub unsafe fn get_1_0(this: *mut Self) -> *mut u32 { return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_34)) [((*std::cell::LazyCell::force_mut(&mut *&raw mut selected_values_34))[(0) as usize]) as usize]; @@ -1470,10 +1470,10 @@ impl IndexedBinding { pub unsafe fn test_binding_35() { let mut owner: IndexedBinding = ::default(); let __decomp_36: *mut IndexedBinding = &mut owner; - let value: *mut u32 = (unsafe { IndexedBinding::get_1_0(&mut (*__decomp_36)) }); + let value: *mut u32 = (unsafe { IndexedBinding::get_1_0(&raw mut (*__decomp_36)) }); let mut result: u32 = (match ( { 1_u32 }, - &mut (*(unsafe { IndexedBinding::get_1_0(&mut (*__decomp_36)) })), + &mut (*(unsafe { IndexedBinding::get_1_0(&raw mut (*__decomp_36)) })), ) { (__tmp_97, __tmp_98) => { (*__tmp_98) = (*__tmp_98).wrapping_add(__tmp_97); @@ -2134,8 +2134,8 @@ pub struct Counts_59 { pub counts: Vec, } impl DefaultConstructibleUnsafe for Counts_59 { - unsafe fn default_constructor(&mut self) { - (&raw mut self.counts).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).counts).write(Vec::new()); } } #[repr(C)] diff --git a/tests/unit/out/unsafe/cast.rs b/tests/unit/out/unsafe/cast.rs index 836987073e..64c45ff4cc 100644 --- a/tests/unit/out/unsafe/cast.rs +++ b/tests/unit/out/unsafe/cast.rs @@ -73,9 +73,9 @@ pub struct Bag { pub items: Vec, } impl DefaultConstructibleUnsafe for Bag { - unsafe fn default_constructor(&mut self) { - (&raw mut self.n).write(0_i32); - (&raw mut self.items).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).n).write(0_i32); + (&raw mut (*this).items).write(Vec::new()); } } pub unsafe fn adjacent_arrays_0() { diff --git a/tests/unit/out/unsafe/class.rs b/tests/unit/out/unsafe/class.rs index dbd48a62a6..8bb913f0e5 100644 --- a/tests/unit/out/unsafe/class.rs +++ b/tests/unit/out/unsafe/class.rs @@ -22,31 +22,31 @@ pub struct Pair { pub second: i32, } impl Pair { - pub unsafe fn NOP(&mut self) {} - pub unsafe fn GetFirst(&self) -> i32 { - return self.first; + pub unsafe fn NOP(this: *mut Self) {} + pub unsafe fn GetFirst(this: *const Self) -> i32 { + return (*this).first; } - pub unsafe fn GetSecond(&self) -> i32 { - return self.second; + pub unsafe fn GetSecond(this: *const Self) -> i32 { + return (*this).second; } - pub unsafe fn Set(&mut self, field: *mut i32, mut new_val: i32) -> i32 { - (unsafe { Pair::NOP(self) }); + pub unsafe fn Set(this: *mut Self, field: *mut i32, mut new_val: i32) -> i32 { + (unsafe { Pair::NOP(this) }); let mut old_val: i32 = (*field); (*field) = new_val; return old_val; } - pub unsafe fn SetFirst(&mut self, mut new_first: i32) -> i32 { - return ((unsafe { Pair::GetFirst(self) }) + pub unsafe fn SetFirst(this: *mut Self, mut new_first: i32) -> i32 { + return ((unsafe { Pair::GetFirst((this).cast_const()) }) + (unsafe { - let _field: *mut i32 = &mut self.first; - Pair::Set(self, _field, new_first) + let _field: *mut i32 = &mut (*this).first; + Pair::Set(this, _field, new_first) })); } - pub unsafe fn SetSecond(&mut self, mut new_second: i32) -> i32 { - return ((unsafe { Pair::GetSecond(self) }) + pub unsafe fn SetSecond(this: *mut Self, mut new_second: i32) -> i32 { + return ((unsafe { Pair::GetSecond((this).cast_const()) }) + (unsafe { - let _field: *mut i32 = &mut self.second; - Pair::Set(self, _field, new_second) + let _field: *mut i32 = &mut (*this).second; + Pair::Set(this, _field, new_second) })); } } @@ -66,9 +66,9 @@ pub struct Route { pub cost: f64, } impl Route { - pub unsafe fn SetCost(&mut self, mut new_cost: f64) -> f64 { - let mut old_cost: f64 = self.cost; - self.cost = new_cost; + pub unsafe fn SetCost(this: *mut Self, mut new_cost: f64) -> f64 { + let mut old_cost: f64 = (*this).cost; + (*this).cost = new_cost; return old_cost; } } @@ -88,13 +88,13 @@ pub struct Counter { pub calls: i32, } impl Counter { - pub unsafe fn Get(&self) -> i32 { - (*(&raw const self.calls).cast_mut()).prefix_inc(); - return self.v; + pub unsafe fn Get(this: *const Self) -> i32 { + (*(&raw const (*this).calls).cast_mut()).prefix_inc(); + return (*this).v; } - pub unsafe fn operator_eq(&self, o: *const Counter) -> bool { - (*(&raw const self.calls).cast_mut()).prefix_inc(); - return ((self.v) == ((*o).v)); + pub unsafe fn operator_eq(this: *const Self, o: *const Counter) -> bool { + (*(&raw const (*this).calls).cast_mut()).prefix_inc(); + return (((*this).v) == ((*o).v)); } } impl std::cmp::PartialEq for Counter { @@ -118,25 +118,25 @@ pub struct Tally { pub calls: i32, } impl Tally { - pub unsafe fn SameNameBetweenConstAndNonConst_1(&mut self) -> i32 { - self.calls += 1; + pub unsafe fn SameNameBetweenConstAndNonConst_1(this: *mut Self) -> i32 { + (*this).calls += 1; return 1; } - pub unsafe fn SameNameBetweenConstAndNonConst_2(&self) -> i32 { - (*(&raw const self.calls).cast_mut()) += 10; + pub unsafe fn SameNameBetweenConstAndNonConst_2(this: *const Self) -> i32 { + (*(&raw const (*this).calls).cast_mut()) += 10; return 2; } } pub unsafe fn RandomRoute_0(route: *mut Route) -> i32 { if ((((*route).path.first) % (2)) != 0) { return (unsafe { - let _new_first: i32 = (unsafe { Pair::SetSecond(&mut (*route).path, 10) }); - Pair::SetFirst(&mut (*route).path, _new_first) + let _new_first: i32 = (unsafe { Pair::SetSecond(&raw mut (*route).path, 10) }); + Pair::SetFirst(&raw mut (*route).path, _new_first) }); } else { return (unsafe { - let _new_second: i32 = (unsafe { Pair::SetFirst(&mut (*route).path, -10_i32) }); - Pair::SetSecond(&mut (*route).path, _new_second) + let _new_second: i32 = (unsafe { Pair::SetFirst(&raw mut (*route).path, -10_i32) }); + Pair::SetSecond(&raw mut (*route).path, _new_second) }); } panic!("ub: non-void function does not return a value") @@ -164,8 +164,8 @@ unsafe fn main_0() -> i32 { }; let mut old_cost: f64 = (unsafe { Route::SetCost( - &mut route1, - (unsafe { Route::SetCost(&mut route2, 15_f64) }), + &raw mut route1, + (unsafe { Route::SetCost(&raw mut route2, 15_f64) }), ) }); assert!( @@ -177,19 +177,19 @@ unsafe fn main_0() -> i32 { let mut c1: Counter = Counter { v: 3, calls: 0 }; let c2: Counter = Counter { v: 3, calls: 0 }; let mut pc: *const Counter = (&mut c1 as *mut Counter).cast_const(); - assert!(((unsafe { Counter::Get(&c1,) }) == (3))); - assert!(((unsafe { Counter::Get(&c2,) }) == (3))); - assert!(((unsafe { Counter::Get(&(*pc),) }) == (3))); - assert!((unsafe { Counter::operator_eq(&c1, &c2,) })); - assert!((unsafe { Counter::operator_eq(&c2, &c1,) })); + assert!(((unsafe { Counter::Get(&raw const c1,) }) == (3))); + assert!(((unsafe { Counter::Get(&raw const c2,) }) == (3))); + assert!(((unsafe { Counter::Get(&raw const (*pc),) }) == (3))); + assert!((unsafe { Counter::operator_eq(&raw const c1, &c2,) })); + assert!((unsafe { Counter::operator_eq(&raw const c2, &c1,) })); assert!(((c1.calls) == (3))); assert!(((c2.calls) == (2))); let mut t: Tally = Tally { calls: 0 }; let ct: Tally = Tally { calls: 0 }; let rt: *const Tally = &t; - assert!(((unsafe { Tally::SameNameBetweenConstAndNonConst_1(&mut t,) }) == (1))); - assert!(((unsafe { Tally::SameNameBetweenConstAndNonConst_2(&ct,) }) == (2))); - assert!(((unsafe { Tally::SameNameBetweenConstAndNonConst_2(&(*rt),) }) == (2))); + assert!(((unsafe { Tally::SameNameBetweenConstAndNonConst_1(&raw mut t,) }) == (1))); + assert!(((unsafe { Tally::SameNameBetweenConstAndNonConst_2(&raw const ct,) }) == (2))); + assert!(((unsafe { Tally::SameNameBetweenConstAndNonConst_2(&raw const (*rt),) }) == (2))); assert!(((t.calls) == (11))); assert!(((ct.calls) == (10))); return 0; diff --git a/tests/unit/out/unsafe/class_template_lazy_member.rs b/tests/unit/out/unsafe/class_template_lazy_member.rs index acb08b983b..dbb14b2a0e 100644 --- a/tests/unit/out/unsafe/class_template_lazy_member.rs +++ b/tests/unit/out/unsafe/class_template_lazy_member.rs @@ -35,8 +35,8 @@ pub struct Box_int_ { pub val: i32, } impl Box_int_ { - pub unsafe fn twice(&mut self) -> i32 { - return ((self.val) + (self.val)); + pub unsafe fn twice(this: *mut Self) -> i32 { + return (((*this).val) + ((*this).val)); } } #[repr(C)] @@ -54,8 +54,8 @@ pub struct Box_Point_ { pub val: Point, } impl Box_Point_ { - pub unsafe fn get(&mut self) -> Point { - return self.val; + pub unsafe fn get(this: *mut Self) -> Point { + return (*this).val; } } #[repr(C)] @@ -73,8 +73,8 @@ pub struct Deduced_int_ { pub val: i32, } impl Deduced_int_ { - pub unsafe fn twice(&mut self) -> i32 { - return ((self.val) + (self.val)); + pub unsafe fn twice(this: *mut Self) -> i32 { + return (((*this).val) + ((*this).val)); } } #[repr(C)] @@ -92,8 +92,8 @@ pub struct Deduced_Point_ { pub val: Point, } impl Deduced_Point_ { - pub unsafe fn get(&mut self) -> Point { - return self.val; + pub unsafe fn get(this: *mut Self) -> Point { + return (*this).val; } } pub fn main() { @@ -104,17 +104,17 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut i: Box_int_ = Box_int_ { val: 3 }; - assert!(((unsafe { Box_int_::twice(&mut i,) }) == (6))); + assert!(((unsafe { Box_int_::twice(&raw mut i,) }) == (6))); let mut p: Box_Point_ = Box_Point_ { val: Point { x: 4 }, }; - assert!((((unsafe { Box_Point_::get(&mut p,) }).x) == (4))); + assert!((((unsafe { Box_Point_::get(&raw mut p,) }).x) == (4))); let mut d: Deduced_int_ = Deduced_int_ { val: 5 }; - assert!(((unsafe { Deduced_int_::twice(&mut d,) }) == (10))); + assert!(((unsafe { Deduced_int_::twice(&raw mut d,) }) == (10))); let mut dp: Deduced_Point_ = Deduced_Point_ { val: Point { x: 6 }, }; - assert!((((unsafe { Deduced_Point_::get(&mut dp,) }).x) == (6))); + assert!((((unsafe { Deduced_Point_::get(&raw mut dp,) }).x) == (6))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/class_templates.rs b/tests/unit/out/unsafe/class_templates.rs index 999d8bac36..91c1cf5f86 100644 --- a/tests/unit/out/unsafe/class_templates.rs +++ b/tests/unit/out/unsafe/class_templates.rs @@ -23,29 +23,29 @@ pub struct MyContainer_int_ { vec_: Vec, } impl MyContainer_int_ { - pub unsafe fn empty(&self) -> bool { - return self.vec_.is_empty(); + pub unsafe fn empty(this: *const Self) -> bool { + return (*this).vec_.is_empty(); } - pub unsafe fn size(&self) -> usize { - return self.vec_.len(); + pub unsafe fn size(this: *const Self) -> usize { + return (*this).vec_.len(); } - pub unsafe fn back_4(&mut self) -> *mut i32 { + pub unsafe fn back_4(this: *mut Self) -> *mut i32 { return { - let __n = self.vec_.len() - 1; - &raw mut self.vec_[__n] + let __n = (*this).vec_.len() - 1; + &raw mut (&mut (*this)).vec_[__n] }; } - pub unsafe fn pop_back(&mut self) { - self.vec_.pop(); + pub unsafe fn pop_back(this: *mut Self) { + (*this).vec_.pop(); return; } - pub unsafe fn push_back(&mut self, item: *const i32) { - self.vec_.push_copied(item); + pub unsafe fn push_back(this: *mut Self, item: *const i32) { + (*this).vec_.push_copied(item); } } impl DefaultConstructibleUnsafe for MyContainer_int_ { - unsafe fn default_constructor(&mut self) { - (&raw mut self.vec_).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).vec_).write(Vec::new()); } } #[repr(C)] @@ -65,29 +65,29 @@ pub struct MyContainer_char_ { vec_: Vec, } impl MyContainer_char_ { - pub unsafe fn empty(&self) -> bool { - return self.vec_.is_empty(); + pub unsafe fn empty(this: *const Self) -> bool { + return (*this).vec_.is_empty(); } - pub unsafe fn size(&self) -> usize { - return self.vec_.len(); + pub unsafe fn size(this: *const Self) -> usize { + return (*this).vec_.len(); } - pub unsafe fn back_4(&mut self) -> *mut libc::c_char { + pub unsafe fn back_4(this: *mut Self) -> *mut libc::c_char { return { - let __n = self.vec_.len() - 1; - &raw mut self.vec_[__n] + let __n = (*this).vec_.len() - 1; + &raw mut (&mut (*this)).vec_[__n] }; } - pub unsafe fn pop_back(&mut self) { - self.vec_.pop(); + pub unsafe fn pop_back(this: *mut Self) { + (*this).vec_.pop(); return; } - pub unsafe fn push_back(&mut self, item: *const libc::c_char) { - self.vec_.push_copied(item); + pub unsafe fn push_back(this: *mut Self, item: *const libc::c_char) { + (*this).vec_.push_copied(item); } } impl DefaultConstructibleUnsafe for MyContainer_char_ { - unsafe fn default_constructor(&mut self) { - (&raw mut self.vec_).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).vec_).write(Vec::new()); } } #[repr(C)] @@ -107,29 +107,29 @@ pub struct MyContainer_float_ { vec_: Vec, } impl MyContainer_float_ { - pub unsafe fn empty(&self) -> bool { - return self.vec_.is_empty(); + pub unsafe fn empty(this: *const Self) -> bool { + return (*this).vec_.is_empty(); } - pub unsafe fn size(&self) -> usize { - return self.vec_.len(); + pub unsafe fn size(this: *const Self) -> usize { + return (*this).vec_.len(); } - pub unsafe fn back_4(&mut self) -> *mut f32 { + pub unsafe fn back_4(this: *mut Self) -> *mut f32 { return { - let __n = self.vec_.len() - 1; - &raw mut self.vec_[__n] + let __n = (*this).vec_.len() - 1; + &raw mut (&mut (*this)).vec_[__n] }; } - pub unsafe fn pop_back(&mut self) { - self.vec_.pop(); + pub unsafe fn pop_back(this: *mut Self) { + (*this).vec_.pop(); return; } - pub unsafe fn push_back(&mut self, item: *const f32) { - self.vec_.push_copied(item); + pub unsafe fn push_back(this: *mut Self, item: *const f32) { + (*this).vec_.push_copied(item); } } impl DefaultConstructibleUnsafe for MyContainer_float_ { - unsafe fn default_constructor(&mut self) { - (&raw mut self.vec_).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).vec_).write(Vec::new()); } } #[repr(C)] @@ -150,8 +150,8 @@ impl Boxed_short_ { pub unsafe fn twice(mut v: i16) -> i16 { return (((v as i32) + (v as i32)) as i16); } - pub unsafe fn plus(&self, mut other: i16) -> i16 { - return (((self.value as i32) + (other as i32)) as i16); + pub unsafe fn plus(this: *const Self, mut other: i16) -> i16 { + return ((((*this).value as i32) + (other as i32)) as i16); } } #[repr(C)] @@ -172,8 +172,8 @@ impl Boxed_int_ { pub unsafe fn twice(mut v: i32) -> i32 { return ((v) + (v)); } - pub unsafe fn plus(&self, mut other: i32) -> i32 { - return ((self.value) + (other)); + pub unsafe fn plus(this: *const Self, mut other: i32) -> i32 { + return (((*this).value) + (other)); } } #[repr(C)] @@ -194,8 +194,8 @@ impl Boxed_long_ { pub unsafe fn twice(mut v: i64) -> i64 { return ((v) + (v)); } - pub unsafe fn plus(&self, mut other: i64) -> i64 { - return ((self.value) + (other)); + pub unsafe fn plus(this: *const Self, mut other: i64) -> i64 { + return (((*this).value) + (other)); } } #[repr(C)] @@ -214,8 +214,8 @@ pub struct Outer_int__Inner_int_ { pub u: i32, } impl Outer_int__Inner_int_ { - pub unsafe fn sum(&self) -> i32 { - return ((self.t as i32) + (self.u as i32)); + pub unsafe fn sum(this: *const Self) -> i32 { + return (((*this).t as i32) + ((*this).u as i32)); } } #[repr(C)] @@ -233,8 +233,8 @@ pub struct Outer_int_ { pub v: i32, } impl Outer_int_ { - pub unsafe fn with(&self, mut n: i32) -> Outer_int__Inner_int_ { - return Outer_int__Inner_int_ { t: self.v, u: n }; + pub unsafe fn with(this: *const Self, mut n: i32) -> Outer_int__Inner_int_ { + return Outer_int__Inner_int_ { t: (*this).v, u: n }; } } #[repr(C)] @@ -253,8 +253,8 @@ pub struct Outer_long__Inner_int_ { pub u: i32, } impl Outer_long__Inner_int_ { - pub unsafe fn sum(&self) -> i32 { - return ((self.t as i32) + (self.u as i32)); + pub unsafe fn sum(this: *const Self) -> i32 { + return (((*this).t as i32) + ((*this).u as i32)); } } #[repr(C)] @@ -273,8 +273,8 @@ pub struct Outer_long__Inner_char_ { pub u: libc::c_char, } impl Outer_long__Inner_char_ { - pub unsafe fn sum(&self) -> i32 { - return ((self.t as i32) + (self.u as i32)); + pub unsafe fn sum(this: *const Self) -> i32 { + return (((*this).t as i32) + ((*this).u as i32)); } } #[repr(C)] @@ -292,8 +292,8 @@ pub struct Outer_long_ { pub v: i64, } impl Outer_long_ { - pub unsafe fn with(&self, mut n: i32) -> Outer_long__Inner_int_ { - return Outer_long__Inner_int_ { t: self.v, u: n }; + pub unsafe fn with(this: *const Self, mut n: i32) -> Outer_long__Inner_int_ { + return Outer_long__Inner_int_ { t: (*this).v, u: n }; } } #[repr(C)] @@ -326,7 +326,9 @@ unsafe fn main_0() -> i32 { assert!((((unsafe { Boxed_short_::twice(2_i16,) }) as i32) == (4))); let mut oi: Outer_int_ = Outer_int_ { v: 3 }; assert!( - ((unsafe { Outer_int__Inner_int_::sum(&(unsafe { Outer_int_::with(&oi, 4,) }),) }) == (7)) + ((unsafe { + Outer_int__Inner_int_::sum(&(unsafe { Outer_int_::with(&raw const oi, 4) })) + }) == (7)) ); let mut ol: Outer_long_ = Outer_long_ { v: 5_i64 }; let mut ic: Outer_long__Inner_char_ = Outer_long__Inner_char_ { @@ -334,55 +336,57 @@ unsafe fn main_0() -> i32 { u: ('a' as libc::c_char), }; assert!( - ((unsafe { Outer_long__Inner_int_::sum(&(unsafe { Outer_long_::with(&ol, 2,) }),) }) - == (7)) + ((unsafe { + Outer_long__Inner_int_::sum(&(unsafe { Outer_long_::with(&raw const ol, 2) })) + }) == (7)) ); assert!( - ((unsafe { Outer_long__Inner_char_::sum(&ic,) }) == ((6) + (('a' as libc::c_char) as i32))) + ((unsafe { Outer_long__Inner_char_::sum(&raw const ic,) }) + == ((6) + (('a' as libc::c_char) as i32))) ); assert!(((unsafe { Boxed_int_::twice(3,) }) == (6))); let mut bi: Boxed_int_ = Boxed_int_ { value: 4 }; - assert!(((unsafe { Boxed_int_::plus(&bi, 5,) }) == (9))); + assert!(((unsafe { Boxed_int_::plus(&raw const bi, 5,) }) == (9))); assert!(((unsafe { Boxed_long_::twice(10_i64,) }) == (20_i64))); let mut bl: Boxed_long_ = Boxed_long_ { value: 7_i64 }; - assert!(((unsafe { Boxed_long_::plus(&bl, 1_i64,) }) == (8_i64))); + assert!(((unsafe { Boxed_long_::plus(&raw const bl, 1_i64,) }) == (8_i64))); object_unsafe!(imc, MyContainer_int_); - assert!((unsafe { MyContainer_int_::empty(&imc,) })); + assert!((unsafe { MyContainer_int_::empty(&raw const imc,) })); (unsafe { let mut _item: i32 = 1; - MyContainer_int_::push_back(&mut imc, &mut _item) + MyContainer_int_::push_back(&raw mut imc, &mut _item) }); assert!( - ((unsafe { MyContainer_int_::size(&imc,) }) == (1_usize)) - && ((*(unsafe { MyContainer_int_::back_4(&mut imc,) })) == (1)) + ((unsafe { MyContainer_int_::size(&raw const imc,) }) == (1_usize)) + && ((*(unsafe { MyContainer_int_::back_4(&raw mut imc,) })) == (1)) ); - (unsafe { MyContainer_int_::pop_back(&mut imc) }); - assert!((unsafe { MyContainer_int_::empty(&imc,) })); + (unsafe { MyContainer_int_::pop_back(&raw mut imc) }); + assert!((unsafe { MyContainer_int_::empty(&raw const imc,) })); object_unsafe!(cmc, MyContainer_char_); - assert!((unsafe { MyContainer_char_::empty(&cmc,) })); + assert!((unsafe { MyContainer_char_::empty(&raw const cmc,) })); (unsafe { let mut _item: libc::c_char = ('a' as libc::c_char); - MyContainer_char_::push_back(&mut cmc, &mut _item) + MyContainer_char_::push_back(&raw mut cmc, &mut _item) }); assert!( - ((unsafe { MyContainer_char_::size(&cmc,) }) == (1_usize)) - && (((*(unsafe { MyContainer_char_::back_4(&mut cmc,) })) as i32) + ((unsafe { MyContainer_char_::size(&raw const cmc,) }) == (1_usize)) + && (((*(unsafe { MyContainer_char_::back_4(&raw mut cmc,) })) as i32) == (('a' as libc::c_char) as i32)) ); - (unsafe { MyContainer_char_::pop_back(&mut cmc) }); - assert!((unsafe { MyContainer_char_::empty(&cmc,) })); + (unsafe { MyContainer_char_::pop_back(&raw mut cmc) }); + assert!((unsafe { MyContainer_char_::empty(&raw const cmc,) })); object_unsafe!(fmc, MyContainer_float_); - assert!((unsafe { MyContainer_float_::empty(&fmc,) })); + assert!((unsafe { MyContainer_float_::empty(&raw const fmc,) })); (unsafe { let mut _item: f32 = (1_f64 as f32); - MyContainer_float_::push_back(&mut fmc, &mut _item) + MyContainer_float_::push_back(&raw mut fmc, &mut _item) }); assert!( - ((unsafe { MyContainer_float_::size(&fmc,) }) == (1_usize)) - && (((*(unsafe { MyContainer_float_::back_4(&mut fmc,) })) as f64) == (1_f64)) + ((unsafe { MyContainer_float_::size(&raw const fmc,) }) == (1_usize)) + && (((*(unsafe { MyContainer_float_::back_4(&raw mut fmc,) })) as f64) == (1_f64)) ); - (unsafe { MyContainer_float_::pop_back(&mut fmc) }); - assert!((unsafe { MyContainer_float_::empty(&fmc,) })); + (unsafe { MyContainer_float_::pop_back(&raw mut fmc) }); + assert!((unsafe { MyContainer_float_::empty(&raw const fmc,) })); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/clone_vs_move.rs b/tests/unit/out/unsafe/clone_vs_move.rs index ed66325643..11379eabf7 100644 --- a/tests/unit/out/unsafe/clone_vs_move.rs +++ b/tests/unit/out/unsafe/clone_vs_move.rs @@ -310,7 +310,7 @@ unsafe fn main_0() -> i32 { assert!(((b2.w) == (2))); let mut v4: Vec = Vec::new(); { - v4.assign_from(&mut v2); + AssignFromUnsafe::assign_from(&raw mut v4, &mut v2); }; { let mut i: i32 = 0; diff --git a/tests/unit/out/unsafe/complex_function.rs b/tests/unit/out/unsafe/complex_function.rs index 6d0fe914cd..99d90add18 100644 --- a/tests/unit/out/unsafe/complex_function.rs +++ b/tests/unit/out/unsafe/complex_function.rs @@ -44,8 +44,8 @@ pub struct X2 { pub v: *mut X1, } impl X2 { - pub unsafe fn get(&mut self) -> *mut X1 { - return self.v; + pub unsafe fn get(this: *mut Self) -> *mut X1 { + return (*this).v; } } #[repr(C)] @@ -63,8 +63,8 @@ pub struct X3 { pub v: *mut X2, } impl X3 { - pub unsafe fn get(&mut self) -> *mut X2 { - return self.v; + pub unsafe fn get(this: *mut Self) -> *mut X2 { + return (*this).v; } } #[repr(C)] @@ -82,8 +82,8 @@ pub struct X4 { pub v: X3, } impl X4 { - pub unsafe fn get(&mut self) -> *mut X3 { - return &mut self.v; + pub unsafe fn get(this: *mut Self) -> *mut X3 { + return &mut (*this).v; } } pub fn main() { @@ -117,28 +117,35 @@ unsafe fn main_0() -> i32 { }; let mut d: X4 = X4 { v: c }; (*(*d.v.v).v).v = 0; - (*(unsafe { X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) })).v = - 0; + (*(unsafe { + X2::get(&raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) }))) + })) + .v = 0; d.v.v = (&mut b as *mut X2); let r4: *const i32 = &(*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get(&raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) }))) })) .v; - let r5: *mut X1 = - (unsafe { X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) }); - let mut p: *mut X2 = (unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }); - let r6: *mut X3 = (unsafe { X4::get(&mut d) }); + let r5: *mut X1 = (unsafe { + X2::get(&raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) }))) + }); + let mut p: *mut X2 = (unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) }); + let r6: *mut X3 = (unsafe { X4::get(&raw mut d) }); let r7: *mut X3 = &mut d.v; - let r8: *mut i32 = &mut (*(unsafe { X2::get(&mut (*(unsafe { X3::get(&mut d.v) }))) })).v; - let mut x5: i32 = - (*(unsafe { X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) })) - .v; + let r8: *mut i32 = + &mut (*(unsafe { X2::get(&raw mut (*(unsafe { X3::get(&raw mut d.v) }))) })).v; + let mut x5: i32 = (*(unsafe { + X2::get(&raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) }))) + })) + .v; (*(unsafe { bar_2(&mut x1) })) += 10; (*(unsafe { bar_2(&mut x1) })).postfix_inc(); let mut bar_out: i32 = (*(unsafe { bar_2( &mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v, ) @@ -149,7 +156,9 @@ unsafe fn main_0() -> i32 { (*(unsafe { bar_2( &mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v, ) @@ -157,7 +166,9 @@ unsafe fn main_0() -> i32 { (*(unsafe { bar_2( &mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v, ) @@ -166,7 +177,9 @@ unsafe fn main_0() -> i32 { let mut bar_inc2: i32 = (*(*(unsafe { bar_2( &mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v, ) @@ -175,7 +188,9 @@ unsafe fn main_0() -> i32 { bar_inc2 = (*(unsafe { bar_2( &mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v, ) @@ -186,7 +201,9 @@ unsafe fn main_0() -> i32 { (*(unsafe { ptr_1( (&mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v as *mut i32), ) @@ -195,7 +212,9 @@ unsafe fn main_0() -> i32 { (*(unsafe { ptr_1( (&mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v as *mut i32), ) @@ -203,7 +222,9 @@ unsafe fn main_0() -> i32 { (*(&mut (*(unsafe { ptr_1( (&mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v as *mut i32), ) @@ -211,7 +232,9 @@ unsafe fn main_0() -> i32 { let mut ptr1: i32 = (*(unsafe { ptr_1( (&mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v as *mut i32), ) @@ -220,7 +243,9 @@ unsafe fn main_0() -> i32 { let ptr2: *mut i32 = &mut (*(unsafe { ptr_1( (&mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v as *mut i32), ) @@ -228,7 +253,9 @@ unsafe fn main_0() -> i32 { let mut ptr3: *mut i32 = (&mut (*(unsafe { ptr_1( (&mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v as *mut i32), ) @@ -236,7 +263,9 @@ unsafe fn main_0() -> i32 { let mut vptr: i32 = (*(unsafe { ptr_1( (&mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v as *mut i32), ) @@ -244,7 +273,9 @@ unsafe fn main_0() -> i32 { let mut pref: *mut i32 = (unsafe { bar_2( &mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v, ) @@ -252,7 +283,9 @@ unsafe fn main_0() -> i32 { (*(unsafe { bar_2( &mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) })), + ) })) .v, ) @@ -262,21 +295,33 @@ unsafe fn main_0() -> i32 { ((((*(unsafe { ptr_1( (&mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { + X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) + })), + ) })) .v as *mut i32), ) })) + (*(unsafe { bar_2( &mut (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { + X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) + })), + ) })) .v, ) }))) + (unsafe { foo_0( (*(unsafe { - X2::get(&mut (*(unsafe { X3::get(&mut (*(unsafe { X4::get(&mut d) }))) }))) + X2::get( + &raw mut (*(unsafe { + X3::get(&raw mut (*(unsafe { X4::get(&raw mut d) }))) + })), + ) })) .v, ) diff --git a/tests/unit/out/unsafe/concepts.rs b/tests/unit/out/unsafe/concepts.rs index 23116f6ce1..2423f931ca 100644 --- a/tests/unit/out/unsafe/concepts.rs +++ b/tests/unit/out/unsafe/concepts.rs @@ -24,7 +24,7 @@ const _: () = assert!( )] pub struct Sized {} impl Sized { - pub unsafe fn size(&mut self) -> i32 { + pub unsafe fn size(this: *mut Self) -> i32 { return 4; } } diff --git a/tests/unit/out/unsafe/constexpr_function.rs b/tests/unit/out/unsafe/constexpr_function.rs index 270760aadd..3e63c0340c 100644 --- a/tests/unit/out/unsafe/constexpr_function.rs +++ b/tests/unit/out/unsafe/constexpr_function.rs @@ -36,12 +36,12 @@ pub struct Flag { pub v: i32, } impl Flag { - pub unsafe fn to_bool(&self) -> bool { - return ((self.v) != (0)); + pub unsafe fn to_bool(this: *const Self) -> bool { + return (((*this).v) != (0)); } } pub unsafe fn use_4(mut f: Flag) -> i32 { - assert!((unsafe { Flag::to_bool(&f,) })); + assert!((unsafe { Flag::to_bool(&raw const f,) })); return f.v; } pub unsafe fn checked_5(mut x: i32) -> i32 { @@ -71,8 +71,8 @@ pub struct P { pub v: i32, } impl P { - pub unsafe fn get(&self) -> i32 { - return self.v; + pub unsafe fn get(this: *const Self) -> i32 { + return (*this).v; } } pub fn main() { @@ -99,7 +99,7 @@ unsafe fn main_0() -> i32 { let mut ptr: *mut i32 = arr.as_mut_ptr(); assert!(!(ptr).is_null()); let mut p: P = P { v: 9 }; - assert!(((unsafe { P::get(&p,) }) == (9))); + assert!(((unsafe { P::get(&raw const p,) }) == (9))); let k: i32 = (unsafe { scaled_2(4) }); assert!(((k) == (4))); let ce: bool = true; diff --git a/tests/unit/out/unsafe/constructor.rs b/tests/unit/out/unsafe/constructor.rs index 060a95a2e0..c90dd9a043 100644 --- a/tests/unit/out/unsafe/constructor.rs +++ b/tests/unit/out/unsafe/constructor.rs @@ -25,24 +25,24 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn const_method(&self) -> i32 { - return ((self.v) * (2)); + pub unsafe fn const_method(this: *const Self) -> i32 { + return (((*this).v) * (2)); } - pub unsafe fn mut_method(&mut self) { - self.v += 1; + pub unsafe fn mut_method(this: *mut Self) { + (*this).v += 1; } - pub unsafe fn construct(&mut self, mut init: i32) { - (&raw mut self.v).write(init); - (unsafe { S::mut_method(self) }); + pub unsafe fn construct(this: *mut Self, mut init: i32) { + (&raw mut (*this).v).write(init); + (unsafe { S::mut_method(this) }); (*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) += - (unsafe { S::const_method(self) }); + (unsafe { S::const_method((this).cast_const()) }); } } impl DestructibleUnsafe for S { - unsafe fn destroy(&mut self) { - (unsafe { S::mut_method(self) }); + unsafe fn destroy(this: *mut Self) { + (unsafe { S::mut_method(this) }); (*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) += - (unsafe { S::const_method(self) }); + (unsafe { S::const_method((this).cast_const()) }); } } #[repr(C)] @@ -55,19 +55,19 @@ pub struct Point { pub y: i32, } impl Point { - pub unsafe fn construct_2(&mut self, mut x: i32, mut y: i32) { - (&raw mut self.x).write(x); - (&raw mut self.y).write(y); + pub unsafe fn construct_2(this: *mut Self, mut x: i32, mut y: i32) { + (&raw mut (*this).x).write(x); + (&raw mut (*this).y).write(y); } - pub unsafe fn construct_1(&mut self, mut v: i32) { - Point::construct_2(&mut *self, v, ((v) + (1))); - self.y *= 10; + pub unsafe fn construct_1(this: *mut Self, mut v: i32) { + Point::construct_2(this, v, ((v) + (1))); + (*this).y *= 10; } } impl DefaultConstructibleUnsafe for Point { - unsafe fn default_constructor(&mut self) { - Point::construct_1(&mut *self, 4); - self.x += 100; + unsafe fn default_constructor(this: *mut Self) { + Point::construct_1(this, 4); + (*this).x += 100; } } impl Default for Point { @@ -75,7 +75,7 @@ impl Default for Point { unsafe { { let mut __v: Point = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } diff --git a/tests/unit/out/unsafe/container_field_addr.rs b/tests/unit/out/unsafe/container_field_addr.rs index e72489b20c..261c0dc092 100644 --- a/tests/unit/out/unsafe/container_field_addr.rs +++ b/tests/unit/out/unsafe/container_field_addr.rs @@ -24,9 +24,9 @@ pub struct S { pub v: Vec, } impl DefaultConstructibleUnsafe for S { - unsafe fn default_constructor(&mut self) { - (&raw mut self.tag).write(0_i32); - (&raw mut self.v).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).tag).write(0_i32); + (&raw mut (*this).v).write(Vec::new()); } } pub unsafe fn add_0(mut v: *mut Vec, mut k: i32) { @@ -60,7 +60,7 @@ unsafe fn main_0() -> i32 { (unsafe { run_1((&mut local as *mut S)) }); let mut heap: *mut S = { let __p: *mut S = Box::leak(Box::new(::zero_init())); - DefaultConstructibleUnsafe::default_constructor(&mut *__p); + DefaultConstructibleUnsafe::default_constructor(__p); __p }; (*heap).tag = 7; diff --git a/tests/unit/out/unsafe/conversion_operator_same_translation.rs b/tests/unit/out/unsafe/conversion_operator_same_translation.rs index 292c0bd955..f6ff700658 100644 --- a/tests/unit/out/unsafe/conversion_operator_same_translation.rs +++ b/tests/unit/out/unsafe/conversion_operator_same_translation.rs @@ -24,11 +24,11 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn to_libcc_char(&self) -> libc::c_char { - return (self.v as libc::c_char); + pub unsafe fn to_libcc_char(this: *const Self) -> libc::c_char { + return ((*this).v as libc::c_char); } - pub unsafe fn to_u8(&self) -> u8 { - return (((self.v) + (1)) as u8); + pub unsafe fn to_u8(this: *const Self) -> u8 { + return ((((*this).v) + (1)) as u8); } } #[repr(C)] @@ -48,11 +48,11 @@ pub struct T { pub v: i32, } impl T { - pub unsafe fn to_i64_1(&self) -> i64 { - return (self.v as i64); + pub unsafe fn to_i64_1(this: *const Self) -> i64 { + return ((*this).v as i64); } - pub unsafe fn to_i64_2(&self) -> i64 { - return (((self.v) + (1)) as i64); + pub unsafe fn to_i64_2(this: *const Self) -> i64 { + return ((((*this).v) + (1)) as i64); } } pub fn main() { @@ -63,17 +63,18 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut s: S = S { v: 65 }; - let mut a: libc::c_char = (unsafe { S::to_libcc_char(&s) }); - let mut b: u8 = (unsafe { S::to_u8(&s) }); + let mut a: libc::c_char = (unsafe { S::to_libcc_char(&raw const s) }); + let mut b: u8 = (unsafe { S::to_u8(&raw const s) }); assert!(((a as i32) == (('A' as libc::c_char) as i32))); assert!(((b as i32) == ((66 as u8) as i32))); assert!( - ((((unsafe { S::to_libcc_char(&s,) }) as i32) + ((unsafe { S::to_u8(&s,) }) as i32)) + ((((unsafe { S::to_libcc_char(&raw const s,) }) as i32) + + ((unsafe { S::to_u8(&raw const s,) }) as i32)) == (131)) ); let mut t: T = T { v: 3 }; - let mut c: i64 = (unsafe { T::to_i64_1(&t) }); - let mut d: i64 = (unsafe { T::to_i64_2(&t) }); + let mut c: i64 = (unsafe { T::to_i64_1(&raw const t) }); + let mut d: i64 = (unsafe { T::to_i64_2(&raw const t) }); assert!(((c) == (3_i64))); assert!(((d) == (4_i64))); return 0; diff --git a/tests/unit/out/unsafe/copy_assign.rs b/tests/unit/out/unsafe/copy_assign.rs index 307254d0b7..f4702998d3 100644 --- a/tests/unit/out/unsafe/copy_assign.rs +++ b/tests/unit/out/unsafe/copy_assign.rs @@ -22,25 +22,25 @@ pub struct Partial { pub keep: i32, } impl Partial { - pub unsafe fn construct(&mut self, mut v: i32, mut keep: i32) { - (&raw mut self.v).write(v); - (&raw mut self.keep).write(keep); + pub unsafe fn construct(this: *mut Self, mut v: i32, mut keep: i32) { + (&raw mut (*this).v).write(v); + (&raw mut (*this).keep).write(keep); } } impl CopyConstructibleUnsafe for Partial { - unsafe fn copy_constructor(&mut self, o: *const Partial) { - (&raw mut self.v).write((*o).v); - (&raw mut self.keep).write((*o).keep); + unsafe fn copy_constructor(this: *mut Self, o: *const Partial) { + (&raw mut (*this).v).write((*o).v); + (&raw mut (*this).keep).write((*o).keep); } } impl CopyAssignableUnsafe for Partial { - unsafe fn copy_assign(&mut self, o: *const Partial) -> *mut Partial { - if (((self as *mut Partial).cast_const()) == (o)) { - return &mut (*(self as *mut Partial)); + unsafe fn copy_assign(this: *mut Self, o: *const Partial) -> *mut Partial { + if (((this).cast_const()) == (o)) { + return &mut (*this); } - self.v = (*o).v; + (*this).v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)).prefix_inc(); - return &mut (*(self as *mut Partial)); + return &mut (*this); } } #[repr(C)] @@ -51,18 +51,24 @@ pub struct NonConstAssign { pub mark: i32, } impl NonConstAssign { - pub unsafe fn operator_assign_2(&mut self, o: *mut NonConstAssign) -> *mut NonConstAssign { - self.mark = (((*o).mark) + (1)); - return &mut (*(self as *mut NonConstAssign)); + pub unsafe fn operator_assign_2( + this: *mut Self, + o: *mut NonConstAssign, + ) -> *mut NonConstAssign { + (*this).mark = (((*o).mark) + (1)); + return &mut (*this); } - pub unsafe fn operator_assign_3(&mut self, o: *const NonConstAssign) -> *mut NonConstAssign { - self.mark = (((*o).mark) + (10)); - return &mut (*(self as *mut NonConstAssign)); + pub unsafe fn operator_assign_3( + this: *mut Self, + o: *const NonConstAssign, + ) -> *mut NonConstAssign { + (*this).mark = (((*o).mark) + (10)); + return &mut (*this); } } impl DefaultConstructibleUnsafe for NonConstAssign { - unsafe fn default_constructor(&mut self) { - (&raw mut self.mark).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).mark).write(0); } } impl Default for NonConstAssign { @@ -70,7 +76,7 @@ impl Default for NonConstAssign { unsafe { { let mut __v: NonConstAssign = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -91,14 +97,14 @@ pub struct RefQualified { pub mark: i32, } impl DefaultConstructibleUnsafe for RefQualified { - unsafe fn default_constructor(&mut self) { - (&raw mut self.mark).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).mark).write(0); } } impl CopyAssignableUnsafe for RefQualified { - unsafe fn copy_assign(&mut self, o: *const RefQualified) -> *mut RefQualified { - self.mark = (((*o).mark) + (1)); - return &mut (*(self as *mut RefQualified)); + unsafe fn copy_assign(this: *mut Self, o: *const RefQualified) -> *mut RefQualified { + (*this).mark = (((*o).mark) + (1)); + return &mut (*this); } } impl Default for RefQualified { @@ -106,7 +112,7 @@ impl Default for RefQualified { unsafe { { let mut __v: RefQualified = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -145,13 +151,13 @@ pub struct CopyCounted { pub v: i32, } impl CopyCounted { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } impl CopyConstructibleUnsafe for CopyCounted { - unsafe fn copy_constructor(&mut self, o: *const CopyCounted) { - (&raw mut self.v).write((*o).v); + unsafe fn copy_constructor(this: *mut Self, o: *const CopyCounted) { + (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)).prefix_inc(); } } @@ -184,16 +190,19 @@ pub struct ExplicitOperatorCall { pub w: Vec, } impl CopyAssignableUnsafe for ExplicitOperatorCall { - unsafe fn copy_assign(&mut self, o: *const ExplicitOperatorCall) -> *mut ExplicitOperatorCall { + unsafe fn copy_assign( + this: *mut Self, + o: *const ExplicitOperatorCall, + ) -> *mut ExplicitOperatorCall { { - self.w.assign_from(&(*o).w); + AssignFromUnsafe::assign_from(&raw mut (*this).w, &(*o).w); }; - return &mut (*(self as *mut ExplicitOperatorCall)); + return &mut (*this); } } impl DefaultConstructibleUnsafe for ExplicitOperatorCall { - unsafe fn default_constructor(&mut self) { - (&raw mut self.w).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).w).write(Vec::new()); } } pub static mut swap_copies_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); @@ -212,34 +221,34 @@ pub struct Swapped { pub v: i32, } impl Swapped { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } - pub unsafe fn copy_assign(&mut self, o: *mut Swapped) -> *mut Swapped { - let mut t: i32 = self.v; - self.v = (*o).v; + pub unsafe fn copy_assign(this: *mut Self, o: *mut Swapped) -> *mut Swapped { + let mut t: i32 = (*this).v; + (*this).v = (*o).v; (*o).v = t; - return &mut (*(self as *mut Swapped)); + return &mut (*this); } } impl CopyConstructibleUnsafe for Swapped { - unsafe fn copy_constructor(&mut self, o: *const Swapped) { - (&raw mut self.v).write((*o).v); + unsafe fn copy_constructor(this: *mut Self, o: *const Swapped) { + (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut swap_copies_2)).prefix_inc(); } } impl CopyAssignableUnsafe for Swapped { - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { + unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self { object_unsafe!(__o, Swapped, src); - Swapped::copy_assign(&mut *self, &mut __o); - &mut *self + Swapped::copy_assign(this, &raw mut __o); + this } } impl MoveAssignableUnsafe for Swapped { - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { + unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { object_unsafe!(__o, Swapped, Moved(src)); - Swapped::copy_assign(&mut *self, &mut __o); - &mut *self + Swapped::copy_assign(this, &raw mut __o); + this } } #[repr(C)] @@ -271,25 +280,25 @@ pub struct VoidAssign { pub x: i32, } impl VoidAssign { - pub unsafe fn copy_assign(&mut self, o: *const VoidAssign) { - self.x = (((*o).x) + (5)); + pub unsafe fn copy_assign(this: *mut Self, o: *const VoidAssign) { + (*this).x = (((*o).x) + (5)); } } impl DefaultConstructibleUnsafe for VoidAssign { - unsafe fn default_constructor(&mut self) { - (&raw mut self.x).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).x).write(0); } } impl CopyAssignableUnsafe for VoidAssign { - unsafe fn copy_assign(&mut self, src: *const Self) -> *mut Self { - VoidAssign::copy_assign(&mut *self, src); - &mut *self + unsafe fn copy_assign(this: *mut Self, src: *const Self) -> *mut Self { + VoidAssign::copy_assign(this, src); + this } } impl MoveAssignableUnsafe for VoidAssign { - unsafe fn move_assign(&mut self, src: *mut Self) -> *mut Self { - VoidAssign::copy_assign(&mut *self, src); - &mut *self + unsafe fn move_assign(this: *mut Self, src: *mut Self) -> *mut Self { + VoidAssign::copy_assign(this, src); + this } } impl Default for VoidAssign { @@ -297,7 +306,7 @@ impl Default for VoidAssign { unsafe { { let mut __v: VoidAssign = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -321,8 +330,8 @@ pub struct HoldsVoidAssign { pub v: VoidAssign, } impl DefaultConstructibleUnsafe for HoldsVoidAssign { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.v); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).v); } } pub fn main() { @@ -348,7 +357,7 @@ unsafe fn main_0() -> i32 { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut assigns_0)) == (3))); (unsafe { let mut _o: Partial = ::zero_init(); - Partial::construct(&mut _o, 9, 900); + Partial::construct(&raw mut _o, 9, 900); assign_unsafe!(a = _o) }); assert!(((a.v) == (9)) && ((a.keep) == (100))); @@ -363,18 +372,18 @@ unsafe fn main_0() -> i32 { let mut h: Holder = Holder { p: { let mut __v: Partial = ::zero_init(); - Partial::construct(&mut __v, 4, 40); + Partial::construct(&raw mut __v, 4, 40); __v }, arr: [ { let mut __v: Partial = ::zero_init(); - Partial::construct(&mut __v, 5, 50); + Partial::construct(&raw mut __v, 5, 50); __v }, { let mut __v: Partial = ::zero_init(); - Partial::construct(&mut __v, 6, 60); + Partial::construct(&raw mut __v, 6, 60); __v }, ], @@ -388,8 +397,8 @@ unsafe fn main_0() -> i32 { object_unsafe!(n1, NonConstAssign); object_unsafe!(n2, NonConstAssign); object_unsafe!(cn, NonConstAssign); - (unsafe { NonConstAssign::operator_assign_2(&mut n1, &mut n) }); - (unsafe { NonConstAssign::operator_assign_3(&mut n2, &cn) }); + (unsafe { NonConstAssign::operator_assign_2(&raw mut n1, &mut n) }); + (unsafe { NonConstAssign::operator_assign_3(&raw mut n2, &cn) }); assert!(((n1.mark) == (1))); assert!(((n2.mark) == (10))); object_unsafe!(r, RefQualified); @@ -399,18 +408,18 @@ unsafe fn main_0() -> i32 { let mut h2: Holder = Holder { p: { let mut __v: Partial = ::zero_init(); - Partial::construct(&mut __v, 7, 70); + Partial::construct(&raw mut __v, 7, 70); __v }, arr: [ { let mut __v: Partial = ::zero_init(); - Partial::construct(&mut __v, 8, 80); + Partial::construct(&raw mut __v, 8, 80); __v }, { let mut __v: Partial = ::zero_init(); - Partial::construct(&mut __v, 9, 90); + Partial::construct(&raw mut __v, 9, 90); __v }, ], @@ -426,18 +435,18 @@ unsafe fn main_0() -> i32 { let mut hc1: HasCopyCounted = HasCopyCounted { c: { let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&mut __v, 1); + CopyCounted::construct(&raw mut __v, 1); __v }, arr: [ { let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&mut __v, 2); + CopyCounted::construct(&raw mut __v, 2); __v }, { let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&mut __v, 3); + CopyCounted::construct(&raw mut __v, 3); __v }, ], @@ -445,18 +454,18 @@ unsafe fn main_0() -> i32 { let mut hc2: HasCopyCounted = HasCopyCounted { c: { let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&mut __v, 4); + CopyCounted::construct(&raw mut __v, 4); __v }, arr: [ { let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&mut __v, 5); + CopyCounted::construct(&raw mut __v, 5); __v }, { let mut __v: CopyCounted = ::zero_init(); - CopyCounted::construct(&mut __v, 6); + CopyCounted::construct(&raw mut __v, 6); __v }, ], @@ -481,8 +490,8 @@ unsafe fn main_0() -> i32 { object_unsafe!(sw2, Swapped(2)); (unsafe { let mut _o: Swapped = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut _o, &sw2); - Swapped::copy_assign(&mut sw1, &mut _o) + ConstructFromUnsafe::construct_from(&raw mut _o, &sw2); + Swapped::copy_assign(&raw mut sw1, &mut _o) }); assert!( ((sw1.v) == (2)) @@ -491,14 +500,14 @@ unsafe fn main_0() -> i32 { let mut hs1: HoldsSwapped = HoldsSwapped { s: { let mut __v: Swapped = ::zero_init(); - Swapped::construct(&mut __v, 3); + Swapped::construct(&raw mut __v, 3); __v }, }; let mut hs2: HoldsSwapped = HoldsSwapped { s: { let mut __v: Swapped = ::zero_init(); - Swapped::construct(&mut __v, 4); + Swapped::construct(&raw mut __v, 4); __v }, }; diff --git a/tests/unit/out/unsafe/copy_ctor.rs b/tests/unit/out/unsafe/copy_ctor.rs index 8aa8637def..0c83840e9f 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -25,13 +25,13 @@ pub struct Counted { pub v: i32, } impl Counted { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(&mut self, o: *const Counted) { - (&raw mut self.v).write((*o).v); + unsafe fn copy_constructor(this: *mut Self, o: *const Counted) { + (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } @@ -44,16 +44,16 @@ pub struct NonConst { pub mark: i32, } impl NonConst { - pub unsafe fn construct_1(&mut self, o: *mut NonConst) { - (&raw mut self.mark).write((((*o).mark) + (1))); + pub unsafe fn construct_1(this: *mut Self, o: *mut NonConst) { + (&raw mut (*this).mark).write((((*o).mark) + (1))); } - pub unsafe fn construct_2(&mut self, o: *const NonConst) { - (&raw mut self.mark).write((((*o).mark) + (10))); + pub unsafe fn construct_2(this: *mut Self, o: *const NonConst) { + (&raw mut (*this).mark).write((((*o).mark) + (10))); } } impl DefaultConstructibleUnsafe for NonConst { - unsafe fn default_constructor(&mut self) { - (&raw mut self.mark).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).mark).write(0); } } impl Default for NonConst { @@ -61,7 +61,7 @@ impl Default for NonConst { unsafe { { let mut __v: NonConst = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -85,13 +85,13 @@ pub struct Ignored { pub v: i32, } impl Ignored { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } impl CopyConstructibleUnsafe for Ignored { - unsafe fn copy_constructor(&mut self, _a0: *const Ignored) { - (&raw mut self.v).write(-1_i32); + unsafe fn copy_constructor(this: *mut Self, _a0: *const Ignored) { + (&raw mut (*this).v).write(-1_i32); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } @@ -124,13 +124,13 @@ pub struct Box_int_ { pub val: i32, } impl Box_int_ { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.val).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).val).write(v); } } impl CopyConstructibleUnsafe for Box_int_ { - unsafe fn copy_constructor(&mut self, o: *const Box_int_) { - (&raw mut self.val).write((*o).val); + unsafe fn copy_constructor(this: *mut Self, o: *const Box_int_) { + (&raw mut (*this).val).write((*o).val); } } #[repr(C)] @@ -159,13 +159,13 @@ pub struct OutOfLine { pub v: i32, } impl OutOfLine { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } impl CopyConstructibleUnsafe for OutOfLine { - unsafe fn copy_constructor(&mut self, o: *const OutOfLine) { - (&raw mut self.v).write((((*o).v) + (100))); + unsafe fn copy_constructor(this: *mut Self, o: *const OutOfLine) { + (&raw mut (*this).v).write((((*o).v) + (100))); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } @@ -182,20 +182,20 @@ pub struct Tracked { pub copied_from: i32, } impl DefaultConstructibleUnsafe for Tracked { - unsafe fn default_constructor(&mut self) { - (&raw mut self.copied_from).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).copied_from).write(0); } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(&mut self, o: *const Tracked) { - (&raw mut self.copied_from).write(0); + unsafe fn copy_constructor(this: *mut Self, o: *const Tracked) { + (&raw mut (*this).copied_from).write(0); (*(&raw const (*o).copied_from).cast_mut()).prefix_inc(); } } impl CopyAssignableUnsafe for Tracked { - unsafe fn copy_assign(&mut self, o: *const Tracked) -> *mut Tracked { + unsafe fn copy_assign(this: *mut Self, o: *const Tracked) -> *mut Tracked { (*(&raw const (*o).copied_from).cast_mut()).prefix_inc(); - return &mut (*(self as *mut Tracked)); + return &mut (*this); } } impl Default for Tracked { @@ -211,7 +211,7 @@ pub unsafe fn by_value_2(c: *mut Counted) -> i32 { } pub unsafe fn make_3(__return: *mut Counted, mut v: i32) { object_unsafe!(c, Counted(v)); - ConstructFromUnsafe::construct_from(&mut *__return, &c); + ConstructFromUnsafe::construct_from(__return, &c); return; } #[repr(C)] @@ -220,18 +220,18 @@ pub struct SelfPtr { pub self_: *mut SelfPtr, } impl DefaultConstructibleUnsafe for SelfPtr { - unsafe fn default_constructor(&mut self) { - (&raw mut self.self_).write((self as *mut SelfPtr)); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).self_).write(this); } } impl CopyConstructibleUnsafe for SelfPtr { - unsafe fn copy_constructor(&mut self, _a0: *const SelfPtr) { - (&raw mut self.self_).write((self as *mut SelfPtr)); + unsafe fn copy_constructor(this: *mut Self, _a0: *const SelfPtr) { + (&raw mut (*this).self_).write(this); } } impl MoveConstructibleUnsafe for SelfPtr { - unsafe fn move_constructor(&mut self, _a0: *mut SelfPtr) { - (&raw mut self.self_).write((self as *mut SelfPtr)); + unsafe fn move_constructor(this: *mut Self, _a0: *mut SelfPtr) { + (&raw mut (*this).self_).write(this); } } impl Default for SelfPtr { @@ -239,7 +239,7 @@ impl Default for SelfPtr { unsafe { { let mut __v: SelfPtr = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -266,8 +266,8 @@ pub struct Derived { pub c: Counted, } impl DefaultConstructibleUnsafe for Derived { - unsafe fn default_constructor(&mut self) { - Counted::construct(&mut self.c, 20); + unsafe fn default_constructor(this: *mut Self) { + Counted::construct(&raw mut (*this).c, 20); } } impl Default for Derived { @@ -275,7 +275,7 @@ impl Default for Derived { unsafe { { let mut __v: Derived = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -297,7 +297,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _c: Counted = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut _c, &a); + ConstructFromUnsafe::construct_from(&raw mut _c, &a); by_value_2(&mut _c) }) == (1)) ); @@ -315,18 +315,18 @@ unsafe fn main_0() -> i32 { let mut hold: Holder = Holder { c: { let mut __v: Counted = ::zero_init(); - Counted::construct(&mut __v, 8); + Counted::construct(&raw mut __v, 8); __v }, arr: [ { let mut __v: Counted = ::zero_init(); - Counted::construct(&mut __v, 9); + Counted::construct(&raw mut __v, 9); __v }, { let mut __v: Counted = ::zero_init(); - Counted::construct(&mut __v, 10); + Counted::construct(&raw mut __v, 10); __v }, ], @@ -348,7 +348,7 @@ unsafe fn main_0() -> i32 { let mut o: Owner = Owner { box_: { let mut __v: Box_int_ = ::zero_init(); - Box_int_::construct(&mut __v, 3); + Box_int_::construct(&raw mut __v, 3); __v }, }; @@ -404,7 +404,7 @@ unsafe fn main_0() -> i32 { { let mut __tmp_3: SelfPtr = ::zero_init(); match (({ - DefaultConstructibleUnsafe::default_constructor(&mut __tmp_3); + DefaultConstructibleUnsafe::default_constructor(&raw mut __tmp_3); &mut __tmp_3 } as *mut SelfPtr),) { @@ -425,7 +425,7 @@ unsafe fn main_0() -> i32 { { let mut __tmp_5: Counted = ::zero_init(); match (({ - Counted::construct(&mut __tmp_5, 30); + Counted::construct(&raw mut __tmp_5, 30); &mut __tmp_5 } as *mut Counted),) { diff --git a/tests/unit/out/unsafe/copy_move_defaulted.rs b/tests/unit/out/unsafe/copy_move_defaulted.rs index 9c2e761bf4..234e910395 100644 --- a/tests/unit/out/unsafe/copy_move_defaulted.rs +++ b/tests/unit/out/unsafe/copy_move_defaulted.rs @@ -41,14 +41,14 @@ pub struct Explicit { pub arr: [i32; 2], } impl Explicit { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); - (&raw mut self.inner).write(Inner { x: ((v) * (10)) }); - (&raw mut self.arr).write([v, ((v) + (1))]); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); + (&raw mut (*this).inner).write(Inner { x: ((v) * (10)) }); + (&raw mut (*this).arr).write([v, ((v) + (1))]); } } impl DestructibleUnsafe for Explicit { - unsafe fn destroy(&mut self) {} + unsafe fn destroy(this: *mut Self) {} } #[repr(C)] #[derive( @@ -86,21 +86,24 @@ pub struct DefaultCopyUserMove { pub v: i32, } impl DefaultCopyUserMove { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } impl MoveConstructibleUnsafe for DefaultCopyUserMove { - unsafe fn move_constructor(&mut self, o: *mut DefaultCopyUserMove) { - (&raw mut self.v).write((*o).v); + unsafe fn move_constructor(this: *mut Self, o: *mut DefaultCopyUserMove) { + (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } impl MoveAssignableUnsafe for DefaultCopyUserMove { - unsafe fn move_assign(&mut self, o: *mut DefaultCopyUserMove) -> *mut DefaultCopyUserMove { - self.v = (*o).v; + unsafe fn move_assign( + this: *mut Self, + o: *mut DefaultCopyUserMove, + ) -> *mut DefaultCopyUserMove { + (*this).v = (*o).v; (*o).v = 0; - return &mut (*(self as *mut DefaultCopyUserMove)); + return &mut (*this); } } #[repr(C)] @@ -119,19 +122,22 @@ pub struct UserCopyDefaultMove { pub v: i32, } impl UserCopyDefaultMove { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } impl CopyConstructibleUnsafe for UserCopyDefaultMove { - unsafe fn copy_constructor(&mut self, o: *const UserCopyDefaultMove) { - (&raw mut self.v).write((((*o).v) + (100))); + unsafe fn copy_constructor(this: *mut Self, o: *const UserCopyDefaultMove) { + (&raw mut (*this).v).write((((*o).v) + (100))); } } impl CopyAssignableUnsafe for UserCopyDefaultMove { - unsafe fn copy_assign(&mut self, o: *const UserCopyDefaultMove) -> *mut UserCopyDefaultMove { - self.v = (((*o).v) + (100)); - return &mut (*(self as *mut UserCopyDefaultMove)); + unsafe fn copy_assign( + this: *mut Self, + o: *const UserCopyDefaultMove, + ) -> *mut UserCopyDefaultMove { + (*this).v = (((*o).v) + (100)); + return &mut (*this); } } #[repr(C)] @@ -153,14 +159,14 @@ pub struct Buffer { pub arr: [i32; 2], } impl Buffer { - pub unsafe fn construct(&mut self, mut n: i32) { - (&raw mut self.data).write(Vec::from_fn((n as usize), |_| { + pub unsafe fn construct(this: *mut Self, mut n: i32) { + (&raw mut (*this).data).write(Vec::from_fn((n as usize), |_| { copy_constructed_unsafe(&mut n) })); - (&raw mut self.rows).write(Vec::new()); - (&raw mut self.n).write(n); - (&raw mut self.arr).write([n, ((n) + (1))]); - self.rows.push_copied(&mut self.data); + (&raw mut (*this).rows).write(Vec::new()); + (&raw mut (*this).n).write(n); + (&raw mut (*this).arr).write([n, ((n) + (1))]); + (*this).rows.push_copied(&mut (*this).data); } } #[repr(C)] @@ -180,11 +186,11 @@ pub struct Owner { pub p: Option>, } impl DefaultConstructibleUnsafe for Owner { - unsafe fn default_constructor(&mut self) { - (&raw mut self.data).write(Vec::new()); - (&raw mut self.n).write(0_i32); - (&raw mut self.arr).write([0_i32; 2]); - (&raw mut self.p).write(None); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).data).write(Vec::new()); + (&raw mut (*this).n).write(0_i32); + (&raw mut (*this).arr).write([0_i32; 2]); + (&raw mut (*this).p).write(None); } } #[repr(C)] @@ -204,8 +210,8 @@ pub struct Copyable { pub data: Vec, } impl DefaultConstructibleUnsafe for Copyable { - unsafe fn default_constructor(&mut self) { - (&raw mut self.data).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).data).write(Vec::new()); } } #[repr(C)] @@ -226,10 +232,10 @@ pub struct Holder { pub p: Option>, } impl Holder { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.inner).write(Inner { x: v }); - Explicit::construct(&mut self.e, v); - (&raw mut self.p).write(None); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).inner).write(Inner { x: v }); + Explicit::construct(&raw mut (*this).e, v); + (&raw mut (*this).p).write(None); } } pub unsafe fn same_0(a: *const Explicit, b: *const Explicit) -> bool { @@ -243,20 +249,20 @@ pub struct SeesThis { pub self_: *mut SeesThis, } impl CopyAssignableUnsafe for SeesThis { - unsafe fn copy_assign(&mut self, _a0: *const SeesThis) -> *mut SeesThis { - self.self_ = (self as *mut SeesThis); - return &mut (*(self as *mut SeesThis)); + unsafe fn copy_assign(this: *mut Self, _a0: *const SeesThis) -> *mut SeesThis { + (*this).self_ = this; + return &mut (*this); } } impl MoveAssignableUnsafe for SeesThis { - unsafe fn move_assign(&mut self, _a0: *mut SeesThis) -> *mut SeesThis { - self.self_ = (self as *mut SeesThis); - return &mut (*(self as *mut SeesThis)); + unsafe fn move_assign(this: *mut Self, _a0: *mut SeesThis) -> *mut SeesThis { + (*this).self_ = this; + return &mut (*this); } } impl DefaultConstructibleUnsafe for SeesThis { - unsafe fn default_constructor(&mut self) { - (&raw mut self.self_).write(std::ptr::null_mut()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).self_).write(std::ptr::null_mut()); } } impl Default for SeesThis { @@ -276,9 +282,9 @@ pub struct HasSeesThis { pub v: Vec, } impl DefaultConstructibleUnsafe for HasSeesThis { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.s); - (&raw mut self.v).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).s); + (&raw mut (*this).v).write(Vec::new()); } } #[repr(C)] @@ -288,22 +294,22 @@ pub struct Counted_int_ { pub moves: i32, } impl DefaultConstructibleUnsafe for Counted_int_ { - unsafe fn default_constructor(&mut self) { - (&raw mut self.v).write(0_i32); - (&raw mut self.moves).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).v).write(0_i32); + (&raw mut (*this).moves).write(0); } } impl MoveConstructibleUnsafe for Counted_int_ { - unsafe fn move_constructor(&mut self, o: *mut Counted_int_) { - (&raw mut self.v).write((*o).v); - (&raw mut self.moves).write((((*o).moves) + (1))); + unsafe fn move_constructor(this: *mut Self, o: *mut Counted_int_) { + (&raw mut (*this).v).write((*o).v); + (&raw mut (*this).moves).write((((*o).moves) + (1))); } } impl MoveAssignableUnsafe for Counted_int_ { - unsafe fn move_assign(&mut self, o: *mut Counted_int_) -> *mut Counted_int_ { - self.v = (*o).v; - self.moves = (((*o).moves) + (1)); - return &mut (*(self as *mut Counted_int_)); + unsafe fn move_assign(this: *mut Self, o: *mut Counted_int_) -> *mut Counted_int_ { + (*this).v = (*o).v; + (*this).moves = (((*o).moves) + (1)); + return &mut (*this); } } impl Default for Counted_int_ { @@ -326,9 +332,9 @@ pub struct HasCounted { pub w: Vec, } impl DefaultConstructibleUnsafe for HasCounted { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.c); - (&raw mut self.w).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).c); + (&raw mut (*this).w).write(Vec::new()); } } #[repr(C)] @@ -341,37 +347,37 @@ pub struct CtorSeesThis { pub id: i32, } impl CtorSeesThis { - pub unsafe fn construct_1(&mut self, mut id: i32) { - DefaultConstructibleUnsafe::default_constructor(&mut *self); - self.id = id; + pub unsafe fn construct_1(this: *mut Self, mut id: i32) { + DefaultConstructibleUnsafe::default_constructor(this); + (*this).id = id; } } impl DefaultConstructibleUnsafe for CtorSeesThis { - unsafe fn default_constructor(&mut self) { - (&raw mut self.self_).write((self as *mut CtorSeesThis)); - (&raw mut self.id).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).self_).write(this); + (&raw mut (*this).id).write(0); } } impl CopyConstructibleUnsafe for CtorSeesThis { - unsafe fn copy_constructor(&mut self, _a0: *const CtorSeesThis) { - (&raw mut self.self_).write((self as *mut CtorSeesThis)); - (&raw mut self.id).write(0); + unsafe fn copy_constructor(this: *mut Self, _a0: *const CtorSeesThis) { + (&raw mut (*this).self_).write(this); + (&raw mut (*this).id).write(0); } } impl MoveConstructibleUnsafe for CtorSeesThis { - unsafe fn move_constructor(&mut self, _a0: *mut CtorSeesThis) { - (&raw mut self.self_).write((self as *mut CtorSeesThis)); - (&raw mut self.id).write(0); + unsafe fn move_constructor(this: *mut Self, _a0: *mut CtorSeesThis) { + (&raw mut (*this).self_).write(this); + (&raw mut (*this).id).write(0); } } impl CopyAssignableUnsafe for CtorSeesThis { - unsafe fn copy_assign(&mut self, _a0: *const CtorSeesThis) -> *mut CtorSeesThis { - return &mut (*(self as *mut CtorSeesThis)); + unsafe fn copy_assign(this: *mut Self, _a0: *const CtorSeesThis) -> *mut CtorSeesThis { + return &mut (*this); } } impl MoveAssignableUnsafe for CtorSeesThis { - unsafe fn move_assign(&mut self, _a0: *mut CtorSeesThis) -> *mut CtorSeesThis { - return &mut (*(self as *mut CtorSeesThis)); + unsafe fn move_assign(this: *mut Self, _a0: *mut CtorSeesThis) -> *mut CtorSeesThis { + return &mut (*this); } } impl Default for CtorSeesThis { @@ -379,7 +385,7 @@ impl Default for CtorSeesThis { unsafe { { let mut __v: CtorSeesThis = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -400,9 +406,9 @@ pub struct HasCtorSeesThis { pub v: Vec, } impl DefaultConstructibleUnsafe for HasCtorSeesThis { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.x); - (&raw mut self.v).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).x); + (&raw mut (*this).v).write(Vec::new()); } } #[repr(C)] @@ -415,9 +421,9 @@ pub struct InitsCtorSeesThis { pub y: CtorSeesThis, } impl DefaultConstructibleUnsafe for InitsCtorSeesThis { - unsafe fn default_constructor(&mut self) { - CtorSeesThis::construct_1(&mut self.x, 1); - CtorSeesThis::construct_1(&mut self.y, 2); + unsafe fn default_constructor(this: *mut Self) { + CtorSeesThis::construct_1(&raw mut (*this).x, 1); + CtorSeesThis::construct_1(&raw mut (*this).y, 2); } } impl Default for InitsCtorSeesThis { @@ -425,7 +431,7 @@ impl Default for InitsCtorSeesThis { unsafe { { let mut __v: InitsCtorSeesThis = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -447,21 +453,21 @@ pub struct OutOfLineDefaulted { pub v: i32, } impl OutOfLineDefaulted { - pub unsafe fn construct(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.x); - (&raw mut self.v).write(1); + pub unsafe fn construct(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).x); + (&raw mut (*this).v).write(1); } } impl CopyConstructibleUnsafe for OutOfLineDefaulted { - unsafe fn copy_constructor(&mut self, _a0: *const OutOfLineDefaulted) { - ConstructFromUnsafe::construct_from(&mut self.x, &(*_a0).x); - (&raw mut self.v).write((*_a0).v); + unsafe fn copy_constructor(this: *mut Self, _a0: *const OutOfLineDefaulted) { + ConstructFromUnsafe::construct_from(&raw mut (*this).x, &(*_a0).x); + (&raw mut (*this).v).write((*_a0).v); } } impl DefaultConstructibleUnsafe for OutOfLineDefaulted { - unsafe fn default_constructor(&mut self) { + unsafe fn default_constructor(this: *mut Self) { unsafe { - OutOfLineDefaulted::construct(&mut *self); + OutOfLineDefaulted::construct(this); } } } @@ -470,7 +476,7 @@ impl Default for OutOfLineDefaulted { unsafe { { let mut __v: OutOfLineDefaulted = ::zero_init(); - OutOfLineDefaulted::construct(&mut __v); + OutOfLineDefaulted::construct(&raw mut __v); __v } } @@ -485,10 +491,10 @@ pub struct OutOfLineAssign { pub w: Vec, } impl DefaultConstructibleUnsafe for OutOfLineAssign { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.s); - (&raw mut self.v).write(1); - (&raw mut self.w).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).s); + (&raw mut (*this).v).write(1); + (&raw mut (*this).w).write(Vec::new()); } } impl Default for OutOfLineAssign { @@ -503,29 +509,29 @@ impl Default for OutOfLineAssign { } } impl CopyAssignableUnsafe for OutOfLineAssign { - unsafe fn copy_assign(&mut self, _a0: *const OutOfLineAssign) -> *mut OutOfLineAssign { + unsafe fn copy_assign(this: *mut Self, _a0: *const OutOfLineAssign) -> *mut OutOfLineAssign { (unsafe { let _arg0: *const SeesThis = &(*_a0).s; - assign_unsafe!(self.s = *_arg0) + assign_unsafe!((*this).s = *_arg0) }); - self.v = (*_a0).v; + (*this).v = (*_a0).v; { - self.w.assign_from(&(*_a0).w); + AssignFromUnsafe::assign_from(&raw mut (*this).w, &(*_a0).w); }; - return &mut (*(self as *mut OutOfLineAssign)); + return &mut (*this); } } impl MoveAssignableUnsafe for OutOfLineAssign { - unsafe fn move_assign(&mut self, _a0: *mut OutOfLineAssign) -> *mut OutOfLineAssign { + unsafe fn move_assign(this: *mut Self, _a0: *mut OutOfLineAssign) -> *mut OutOfLineAssign { (unsafe { let _arg0: *mut SeesThis = &mut (*_a0).s; - assign_unsafe!(self.s = Moved(*_arg0)) + assign_unsafe!((*this).s = Moved(*_arg0)) }); - self.v = (*_a0).v; + (*this).v = (*_a0).v; { - self.w = std::mem::take(&mut (*_a0).w); + (*this).w = std::mem::take(&mut (*_a0).w); }; - return &mut (*(self as *mut OutOfLineAssign)); + return &mut (*this); } } pub fn main() { @@ -538,15 +544,15 @@ unsafe fn main_0() -> i32 { object_unsafe!(a, Explicit(1)); let mut b: Explicit = a.clone(); let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); let mut c: Explicit = a.clone(); let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); let mut d: Explicit = a.clone(); let _dtor_d = std::mem::DropGuard::new(&raw mut d, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); assert!( ((unsafe { same_0(&b, &a,) }) && (unsafe { same_0(&c, &a,) })) @@ -580,7 +586,7 @@ unsafe fn main_0() -> i32 { vec_.push_copied(&mut b); match ((&mut { let mut __v: Explicit = ::zero_init(); - Explicit::construct(&mut __v, 9); + Explicit::construct(&raw mut __v, 9); __v } as *mut Explicit),) { @@ -627,7 +633,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { { let mut __v: Buffer = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(&mut bufs[(0_usize)])); + ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut bufs[(0_usize)])); __v } }; @@ -771,7 +777,7 @@ unsafe fn main_0() -> i32 { assert!(((i.y.self_) == (&mut i.y as *mut CtorSeesThis)) && ((i.y.id) == (2))); let mut p: *mut CtorSeesThis = { let __p: *mut CtorSeesThis = Box::leak(Box::new(::zero_init())); - CtorSeesThis::construct_1(&mut *__p, 4); + CtorSeesThis::construct_1(__p, 4); __p }; assert!((((*p).self_) == (p)) && (((*p).id) == (4))); diff --git a/tests/unit/out/unsafe/copy_move_deleted.rs b/tests/unit/out/unsafe/copy_move_deleted.rs index 08f7648ccb..d2aebc4c55 100644 --- a/tests/unit/out/unsafe/copy_move_deleted.rs +++ b/tests/unit/out/unsafe/copy_move_deleted.rs @@ -20,21 +20,21 @@ pub struct NoCopy { pub v: i32, } impl NoCopy { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } impl MoveConstructibleUnsafe for NoCopy { - unsafe fn move_constructor(&mut self, o: *mut NoCopy) { - (&raw mut self.v).write((*o).v); + unsafe fn move_constructor(this: *mut Self, o: *mut NoCopy) { + (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } impl MoveAssignableUnsafe for NoCopy { - unsafe fn move_assign(&mut self, o: *mut NoCopy) -> *mut NoCopy { - self.v = (*o).v; + unsafe fn move_assign(this: *mut Self, o: *mut NoCopy) -> *mut NoCopy { + (*this).v = (*o).v; (*o).v = 0; - return &mut (*(self as *mut NoCopy)); + return &mut (*this); } } #[repr(C)] @@ -43,21 +43,21 @@ pub struct PrivateCopy { pub v: i32, } impl DefaultConstructibleUnsafe for PrivateCopy { - unsafe fn default_constructor(&mut self) { - (&raw mut self.v).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).v).write(0); } } impl MoveConstructibleUnsafe for PrivateCopy { - unsafe fn move_constructor(&mut self, o: *mut PrivateCopy) { - (&raw mut self.v).write((*o).v); + unsafe fn move_constructor(this: *mut Self, o: *mut PrivateCopy) { + (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } impl MoveAssignableUnsafe for PrivateCopy { - unsafe fn move_assign(&mut self, o: *mut PrivateCopy) -> *mut PrivateCopy { - self.v = (*o).v; + unsafe fn move_assign(this: *mut Self, o: *mut PrivateCopy) -> *mut PrivateCopy { + (*this).v = (*o).v; (*o).v = 0; - return &mut (*(self as *mut PrivateCopy)); + return &mut (*this); } } impl Default for PrivateCopy { @@ -65,7 +65,7 @@ impl Default for PrivateCopy { unsafe { { let mut __v: PrivateCopy = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -77,8 +77,8 @@ pub struct Immovable { pub v: i32, } impl DefaultConstructibleUnsafe for Immovable { - unsafe fn default_constructor(&mut self) { - (&raw mut self.v).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).v).write(0); } } impl Default for Immovable { @@ -86,7 +86,7 @@ impl Default for Immovable { unsafe { { let mut __v: Immovable = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -120,8 +120,8 @@ pub struct VecHolder { pub items: Vec, } impl DefaultConstructibleUnsafe for VecHolder { - unsafe fn default_constructor(&mut self) { - (&raw mut self.items).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).items).write(Vec::new()); } } pub unsafe fn bump_0(mut p: *mut NoCopy) { @@ -158,7 +158,7 @@ unsafe fn main_0() -> i32 { let mut c: Container = Container { inner: { let mut __v: NoCopy = ::zero_init(); - NoCopy::construct(&mut __v, 6); + NoCopy::construct(&raw mut __v, 6); __v }, tag: 7, @@ -171,12 +171,12 @@ unsafe fn main_0() -> i32 { return 0; } impl CopyAssignableUnsafe for PrivateCopy { - unsafe fn copy_assign(&mut self, _: *const Self) -> *mut Self { + unsafe fn copy_assign(this: *mut Self, _: *const Self) -> *mut Self { unreachable!("PrivateCopy::copy_assign is never defined") } } impl CopyConstructibleUnsafe for PrivateCopy { - unsafe fn copy_constructor(&mut self, _: *const Self) { + unsafe fn copy_constructor(this: *mut Self, _: *const Self) { unreachable!("PrivateCopy::copy_constructor is never defined") } } diff --git a/tests/unit/out/unsafe/default_function_arguments.rs b/tests/unit/out/unsafe/default_function_arguments.rs index 33af2f9951..90b63a8497 100644 --- a/tests/unit/out/unsafe/default_function_arguments.rs +++ b/tests/unit/out/unsafe/default_function_arguments.rs @@ -21,14 +21,14 @@ pub struct Bar { pub v: i32, } impl Bar { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } impl DefaultConstructibleUnsafe for Bar { - unsafe fn default_constructor(&mut self) { + unsafe fn default_constructor(this: *mut Self) { unsafe { - Bar::construct(&mut *self, 1); + Bar::construct(this, 1); } } } @@ -37,7 +37,7 @@ impl Default for Bar { unsafe { { let mut __v: Bar = ::zero_init(); - Bar::construct(&mut __v, 1); + Bar::construct(&raw mut __v, 1); __v } } @@ -56,7 +56,7 @@ pub unsafe fn by_ref_5(b: *const Bar) -> i32 { pub static mut global_bar_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: Bar = ::zero_init(); - Bar::construct(&mut __v, 9); + Bar::construct(&raw mut __v, 9); __v } }); @@ -84,8 +84,8 @@ pub struct Holder_int_ { pub v: i32, } impl Holder_int_ { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } pub fn main() { @@ -116,7 +116,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_0: Bar = ::zero_init(); assert!( (((*{ - Bar::construct(&mut __tmp_0, 2); + Bar::construct(&raw mut __tmp_0, 2); &mut __tmp_0 }) .v) == (2)) @@ -125,17 +125,17 @@ unsafe fn main_0() -> i32 { let mut arr: [Bar; 3] = [ { let mut __v: Bar = ::zero_init(); - Bar::construct(&mut __v, 1); + Bar::construct(&raw mut __v, 1); __v }, { let mut __v: Bar = ::zero_init(); - Bar::construct(&mut __v, 1); + Bar::construct(&raw mut __v, 1); __v }, { let mut __v: Bar = ::zero_init(); - Bar::construct(&mut __v, 1); + Bar::construct(&raw mut __v, 1); __v }, ]; @@ -148,14 +148,14 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _b: Bar = ::zero_init(); - Bar::construct(&mut _b, 7); + Bar::construct(&raw mut _b, 7); by_ref_5(&mut _b) }) == (7)) ); assert!( ((unsafe { let mut _b: Bar = ::zero_init(); - Bar::construct(&mut _b, 3); + Bar::construct(&raw mut _b, 3); by_ref_5(&mut _b) }) == (3)) ); @@ -167,7 +167,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _b: Bar = ::zero_init(); - Bar::construct(&mut _b, 4); + Bar::construct(&raw mut _b, 4); by_global_ref_7(&mut _b) }) == (4)) ); diff --git a/tests/unit/out/unsafe/delete_array_order.rs b/tests/unit/out/unsafe/delete_array_order.rs index d93c32b7e8..37887d77ab 100644 --- a/tests/unit/out/unsafe/delete_array_order.rs +++ b/tests/unit/out/unsafe/delete_array_order.rs @@ -23,12 +23,12 @@ pub struct Element { pub value: i64, } impl DestructibleUnsafe for Element { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (unsafe { libc::printf( c"%ld:%ld ".as_ptr() as *const libc::c_char, - (self.id), - (self.value), + ((*this).id), + ((*this).value), ) }); } @@ -62,7 +62,7 @@ unsafe fn main_0() -> i32 { / ::std::mem::size_of::()) .rev() { - DestructibleUnsafe::destroy(&mut *__p.add(__i)); + DestructibleUnsafe::destroy(__p.add(__i)); } ::std::mem::drop(Box::from_raw(::std::slice::from_raw_parts_mut( __p, diff --git a/tests/unit/out/unsafe/destructor.rs b/tests/unit/out/unsafe/destructor.rs index 22b6c1b551..3addd21275 100644 --- a/tests/unit/out/unsafe/destructor.rs +++ b/tests/unit/out/unsafe/destructor.rs @@ -21,7 +21,7 @@ pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new(|| #[memberwise(copy_assign)] pub struct S {} impl DestructibleUnsafe for S { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)).postfix_inc(); } } @@ -112,8 +112,8 @@ pub struct EmptyBody { pub s: S, } impl DestructibleUnsafe for EmptyBody { - unsafe fn destroy(&mut self) { - DestructibleUnsafe::destroy(&mut self.s); + unsafe fn destroy(this: *mut Self) { + DestructibleUnsafe::destroy(&raw mut (*this).s); } } #[repr(C)] @@ -132,7 +132,7 @@ pub struct Templated_char_ { pub v: libc::c_char, } impl DestructibleUnsafe for Templated_char_ { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) = (((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) as usize) .wrapping_add((::std::mem::size_of::() as usize))) as i32; @@ -154,7 +154,7 @@ pub struct Templated_int_ { pub v: i32, } impl DestructibleUnsafe for Templated_int_ { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) = (((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) as usize) .wrapping_add((::std::mem::size_of::() as usize))) as i32; @@ -176,7 +176,7 @@ pub struct Copied { pub v: i32, } impl DestructibleUnsafe for Copied { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)).postfix_inc(); } } @@ -199,10 +199,10 @@ pub struct Tagged { pub tag: i32, } impl DestructibleUnsafe for Tagged { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut order_1)) [((*std::cell::LazyCell::force_mut(&mut *&raw mut order_count_2)).postfix_inc()) - as usize] = self.tag; + as usize] = (*this).tag; } } #[repr(C)] @@ -239,64 +239,64 @@ unsafe fn main_0() -> i32 { { let mut s: S = ::default_constructed(); let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (1))); { let mut s: S = ::default_constructed(); let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (2))); { let mut d: Defaulted = ::default_constructed(); let _dtor_d = std::mem::DropGuard::new(&raw mut d, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (3))); { let mut o: Outer = ::default_constructed(); let _dtor_o = std::mem::DropGuard::new(&raw mut o, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (4))); { let mut am: ArrayMember = ::default_constructed(); let _dtor_am = std::mem::DropGuard::new(&raw mut am, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (7))); { let mut e: EmptyBody = ::default_constructed(); let _dtor_e = std::mem::DropGuard::new(&raw mut e, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (8))); { let mut tc: Templated_char_ = ::default_constructed(); let _dtor_tc = std::mem::DropGuard::new(&raw mut tc, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); let mut ti: Templated_int_ = ::default_constructed(); let _dtor_ti = std::mem::DropGuard::new(&raw mut ti, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (13))); { let mut a: Copied = Copied { v: 5 }; let _dtor_a = std::mem::DropGuard::new(&raw mut a, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); let mut b: Copied = a.clone(); let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); assert!(((b.v) == (5))); } @@ -310,7 +310,7 @@ unsafe fn main_0() -> i32 { third: Tagged { tag: 3 }, }; let _dtor_o = std::mem::DropGuard::new(&raw mut o, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut order_count_2)) == (3))); @@ -321,7 +321,7 @@ unsafe fn main_0() -> i32 { { let mut cs: S = ::default_constructed(); let _dtor_cs = std::mem::DropGuard::new(&raw mut cs, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == ((before) + (1)))); diff --git a/tests/unit/out/unsafe/destructor_params.rs b/tests/unit/out/unsafe/destructor_params.rs index 55b96ce8cf..985751c001 100644 --- a/tests/unit/out/unsafe/destructor_params.rs +++ b/tests/unit/out/unsafe/destructor_params.rs @@ -24,9 +24,9 @@ pub struct S { pub v: i32, } impl DestructibleUnsafe for S { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)).postfix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) = self.v; + (*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) = (*this).v; } } pub unsafe fn by_value_2(s: *mut S) -> i32 { @@ -51,11 +51,11 @@ pub struct Holder { pub v: i32, } impl Holder { - pub unsafe fn construct(&mut self, s: *mut S) { - (&raw mut self.v).write((*s).v); + pub unsafe fn construct(this: *mut Self, s: *mut S) { + (&raw mut (*this).v).write((*s).v); } - pub unsafe fn add(&self, s: *mut S) -> i32 { - return ((self.v) + ((*s).v)); + pub unsafe fn add(this: *const Self, s: *mut S) -> i32 { + return (((*this).v) + ((*s).v)); } } pub fn main() { @@ -68,7 +68,7 @@ unsafe fn main_0() -> i32 { { let mut s: S = S { v: 1 }; let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); assert!( ((unsafe { @@ -117,7 +117,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _s: S = S { v: 4 }; - Holder::add(&h, &mut _s) + Holder::add(&raw const h, &mut _s) }) == (7)) ); assert!( diff --git a/tests/unit/out/unsafe/destructor_temporaries.rs b/tests/unit/out/unsafe/destructor_temporaries.rs index 68574e6748..b1f69ed8dc 100644 --- a/tests/unit/out/unsafe/destructor_temporaries.rs +++ b/tests/unit/out/unsafe/destructor_temporaries.rs @@ -24,14 +24,14 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn get(&self) -> i32 { - return self.v; + pub unsafe fn get(this: *const Self) -> i32 { + return (*this).v; } } impl DestructibleUnsafe for S { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)).postfix_inc(); - (*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) = self.v; + (*std::cell::LazyCell::force_mut(&mut *&raw mut last_1)) = (*this).v; } } #[repr(C)] @@ -80,7 +80,7 @@ pub fn main() { unsafe fn main_0() -> i32 { { let mut __v: S = ::zero_init(); - (unsafe { make_2(&mut __v, 1) }); + (unsafe { make_2(&raw mut __v, 1) }); }; assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1)) @@ -89,7 +89,7 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; &({ let mut __v: S = ::zero_init(); - (unsafe { make_2(&mut __v, 2) }); + (unsafe { make_2(&raw mut __v, 2) }); }); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1)) @@ -99,7 +99,7 @@ unsafe fn main_0() -> i32 { let mut x: i32 = { let mut __tmp_0: S = ::zero_init(); (*{ - (unsafe { make_2(&mut __tmp_0, 3) }); + (unsafe { make_2(&raw mut __tmp_0, 3) }); &mut __tmp_0 }) .v @@ -114,7 +114,7 @@ unsafe fn main_0() -> i32 { x = (unsafe { S::get( &(*{ - (unsafe { make_2(&mut __tmp_1, 4) }); + (unsafe { make_2(&raw mut __tmp_1, 4) }); &mut __tmp_1 }), ) @@ -128,7 +128,7 @@ unsafe fn main_0() -> i32 { { let mut __tmp_2: Outer = ::zero_init(); x = (*{ - (unsafe { make_outer_3(&mut __tmp_2) }); + (unsafe { make_outer_3(&raw mut __tmp_2) }); &mut __tmp_2 }) .inner @@ -144,7 +144,7 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; x = (unsafe { let mut _s: S = ::zero_init(); - (unsafe { make_2(&mut _s, 6) }); + (unsafe { make_2(&raw mut _s, 6) }); use_4(&mut _s) }); assert!( @@ -164,7 +164,7 @@ unsafe fn main_0() -> i32 { x = (if ((x) == (3)) { { let mut __v: S = ::zero_init(); - (unsafe { make_2(&mut __v, 9) }); + (unsafe { make_2(&raw mut __v, 9) }); __v } } else { @@ -178,7 +178,7 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; { let mut __tmp_3: S = ::zero_init(); - (unsafe { make_2(&mut __tmp_3, 11) }); + (unsafe { make_2(&raw mut __tmp_3, 11) }); let r: *const S = &mut __tmp_3; assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (0)) @@ -193,11 +193,11 @@ unsafe fn main_0() -> i32 { { let mut s: S = S { v: 12 }; let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); (unsafe { let mut _arg0: S = ::zero_init(); - (unsafe { make_2(&mut _arg0, 13) }); + (unsafe { make_2(&raw mut _arg0, 13) }); assign_unsafe!(s = _arg0) }); assert!( diff --git a/tests/unit/out/unsafe/doubly_linked_list.rs b/tests/unit/out/unsafe/doubly_linked_list.rs index dc47af772b..3a382f5f2d 100644 --- a/tests/unit/out/unsafe/doubly_linked_list.rs +++ b/tests/unit/out/unsafe/doubly_linked_list.rs @@ -23,11 +23,11 @@ pub struct Node { pub prev: *mut Node, } impl Node { - pub unsafe fn SetNext(&mut self, mut n: *mut Node) { - self.next = n; + pub unsafe fn SetNext(this: *mut Self, mut n: *mut Node) { + (*this).next = n; } - pub unsafe fn SetPrev(&mut self, mut p: *mut Node) { - self.prev = p; + pub unsafe fn SetPrev(this: *mut Self, mut p: *mut Node) { + (*this).prev = p; } } pub unsafe fn Find_0(mut head: *mut Node, mut idx: i32) -> *mut Node { @@ -61,8 +61,8 @@ pub unsafe fn Append_2(head: *mut Node, new_node: *mut Node) { 'loop_: while !(((*curr).next).is_null()) { curr = (*curr).next; } - (unsafe { Node::SetNext(&mut (*curr), (new_node)) }); - (unsafe { Node::SetPrev(&mut (*new_node), curr) }); + (unsafe { Node::SetNext(&raw mut (*curr), (new_node)) }); + (unsafe { Node::SetPrev(&raw mut (*new_node), curr) }); } pub unsafe fn Delete_3(mut head: *mut Node, mut val: i32) -> *mut Node { let mut curr: *mut Node = head; diff --git a/tests/unit/out/unsafe/enum_underlying_type.rs b/tests/unit/out/unsafe/enum_underlying_type.rs index 55f7fe3ba5..1b958a6d17 100644 --- a/tests/unit/out/unsafe/enum_underlying_type.rs +++ b/tests/unit/out/unsafe/enum_underlying_type.rs @@ -31,8 +31,8 @@ pub struct HoldsEmpty { pub e: Empty, } impl DefaultConstructibleUnsafe for HoldsEmpty { - unsafe fn default_constructor(&mut self) { - (&raw mut self.e).write(false); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).e).write(false); } } impl Default for HoldsEmpty { diff --git a/tests/unit/out/unsafe/exprs.rs b/tests/unit/out/unsafe/exprs.rs index 496aac9ce2..4608f32b8e 100644 --- a/tests/unit/out/unsafe/exprs.rs +++ b/tests/unit/out/unsafe/exprs.rs @@ -36,11 +36,11 @@ pub struct Y { pub p: *mut X, } impl Y { - pub unsafe fn foo(&mut self) -> *mut X { - return &mut self.x; + pub unsafe fn foo(this: *mut Self) -> *mut X { + return &mut (*this).x; } - pub unsafe fn ptr(&mut self) -> *mut X { - return (&mut self.x as *mut X); + pub unsafe fn ptr(this: *mut Self) -> *mut X { + return (&mut (*this).x as *mut X); } } pub fn main() { @@ -76,12 +76,12 @@ unsafe fn main_0() -> i32 { p: (&mut x as *mut X), }; y.x.x = 5; - (*(unsafe { Y::foo(&mut y) })).x = 1; + (*(unsafe { Y::foo(&raw mut y) })).x = 1; (*y.p).x = 10; let mut p3: *mut Y = (&mut y as *mut Y); (*(*p3).p).x = 100; - (*(unsafe { Y::ptr(&mut y) })).x = 1; - (*(unsafe { Y::ptr(&mut y) })).x = 50; + (*(unsafe { Y::ptr(&raw mut y) })).x = 1; + (*(unsafe { Y::ptr(&raw mut y) })).x = 50; assert!(((x.x) == (100))); return 0; } diff --git a/tests/unit/out/unsafe/field_method_receiver.rs b/tests/unit/out/unsafe/field_method_receiver.rs index aa79f7d35d..d5c643bb92 100644 --- a/tests/unit/out/unsafe/field_method_receiver.rs +++ b/tests/unit/out/unsafe/field_method_receiver.rs @@ -21,17 +21,17 @@ pub struct Counter { pub n: i32, } impl Counter { - pub unsafe fn get(&self) -> i32 { - return self.n; + pub unsafe fn get(this: *const Self) -> i32 { + return (*this).n; } - pub unsafe fn add(&mut self, mut k: i32) { - self.n += k; + pub unsafe fn add(this: *mut Self, mut k: i32) { + (*this).n += k; } - pub unsafe fn self_(&mut self) -> *mut Counter { - return (self as *mut Counter); + pub unsafe fn self_(this: *mut Self) -> *mut Counter { + return this; } - pub unsafe fn take(&mut self, mut other: *mut Counter) { - self.n += (*other).n; + pub unsafe fn take(this: *mut Self, mut other: *mut Counter) { + (*this).n += (*other).n; (*other).n = 0; } } @@ -55,45 +55,45 @@ pub struct S { pub v: Vec, } impl S { - pub unsafe fn bump(&mut self) { + pub unsafe fn bump(this: *mut Self) { (unsafe { - let _k: i32 = self.tag; - Counter::add(&mut self.c, _k) + let _k: i32 = (*this).tag; + Counter::add(&raw mut (*this).c, _k) }); } } impl DefaultConstructibleUnsafe for S { - unsafe fn default_constructor(&mut self) { - (&raw mut self.tag).write(0_i32); - (&raw mut self.c).write(::default()); - (&raw mut self.arr).write([::default(); 2]); - (&raw mut self.v).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).tag).write(0_i32); + (&raw mut (*this).c).write(::default()); + (&raw mut (*this).arr).write([::default(); 2]); + (&raw mut (*this).v).write(Vec::new()); } } pub unsafe fn run_0(mut o: *mut S) { - (unsafe { Counter::add(&mut (*o).c, 2) }); - assert!(((unsafe { Counter::get(&(*o).c,) }) == (2))); - (unsafe { Counter::add(&mut (*o).arr[(1) as usize], 5) }); - assert!(((unsafe { Counter::get(&(*o).arr[(1) as usize],) }) == (5))); - (unsafe { Counter::add(&mut (*(unsafe { Counter::self_(&mut (*o).c) })), 1) }); - assert!(((unsafe { Counter::get(&(*o).c,) }) == (3))); - assert!(((unsafe { Counter::self_(&mut (*o).c,) }) == (&mut (*o).c as *mut Counter))); + (unsafe { Counter::add(&raw mut (*o).c, 2) }); + assert!(((unsafe { Counter::get(&raw const (*o).c,) }) == (2))); + (unsafe { Counter::add(&raw mut (*o).arr[(1) as usize], 5) }); + assert!(((unsafe { Counter::get(&raw const (*o).arr[(1) as usize],) }) == (5))); + (unsafe { Counter::add(&raw mut (*(unsafe { Counter::self_(&raw mut (*o).c) })), 1) }); + assert!(((unsafe { Counter::get(&raw const (*o).c,) }) == (3))); + assert!(((unsafe { Counter::self_(&raw mut (*o).c,) }) == (&mut (*o).c as *mut Counter))); (unsafe { let _other: *mut Counter = (&mut (*o).arr[(1) as usize] as *mut Counter); - Counter::take(&mut (*o).arr[(0) as usize], _other) + Counter::take(&raw mut (*o).arr[(0) as usize], _other) }); assert!( - ((unsafe { Counter::get(&(*o).arr[(0) as usize],) }) == (5)) - && ((unsafe { Counter::get(&(*o).arr[(1) as usize],) }) == (0)) + ((unsafe { Counter::get(&raw const (*o).arr[(0) as usize],) }) == (5)) + && ((unsafe { Counter::get(&raw const (*o).arr[(1) as usize],) }) == (0)) ); (unsafe { let _other: *mut Counter = (&mut (*o).c as *mut Counter); - Counter::take(&mut (*o).c, _other) + Counter::take(&raw mut (*o).c, _other) }); - assert!(((unsafe { Counter::get(&(*o).c,) }) == (0))); - (unsafe { S::bump(&mut (*o)) }); - assert!(((unsafe { Counter::get(&(*o).c,) }) == (1))); - match ((&mut (unsafe { Counter::get(&(*o).c) }) as *mut i32),) { + assert!(((unsafe { Counter::get(&raw const (*o).c,) }) == (0))); + (unsafe { S::bump(&raw mut (*o)) }); + assert!(((unsafe { Counter::get(&raw const (*o).c,) }) == (1))); + match ((&mut (unsafe { Counter::get(&raw const (*o).c) }) as *mut i32),) { (__tmp_0,) => (*o).v.push_moved(__tmp_0), }; assert!((((*o).v.len()) == (1_usize)) && (((&mut (*o)).v[(0_usize)]) == (1))); diff --git a/tests/unit/out/unsafe/field_pointers.rs b/tests/unit/out/unsafe/field_pointers.rs index c2188bddb9..c913579ed6 100644 --- a/tests/unit/out/unsafe/field_pointers.rs +++ b/tests/unit/out/unsafe/field_pointers.rs @@ -58,27 +58,27 @@ pub struct Outer { pub buf: [i32; 4], } impl Outer { - pub unsafe fn next(&mut self) -> i32 { - return self.buf[(self.x.postfix_inc()) as usize]; + pub unsafe fn next(this: *mut Self) -> i32 { + return (*this).buf[((*this).x.postfix_inc()) as usize]; } - pub unsafe fn sum(&self) -> i32 { - return ((self.x) + (self.inner.a)); + pub unsafe fn sum(this: *const Self) -> i32 { + return (((*this).x) + ((*this).inner.a)); } - pub unsafe fn push(&mut self, mut k: i32) { + pub unsafe fn push(this: *mut Self, mut k: i32) { { - let mut __tmp_0: i32 = ((k) + (self.x)); - self.v.push_moved(&mut __tmp_0) + let mut __tmp_0: i32 = ((k) + ((*this).x)); + (*this).v.push_moved(&mut __tmp_0) }; } } impl DefaultConstructibleUnsafe for Outer { - unsafe fn default_constructor(&mut self) { - (&raw mut self.x).write(0_i32); - (&raw mut self.inner).write(::default()); - (&raw mut self.items).write([::default(); 3]); - (&raw mut self.v).write(Vec::new()); - (&raw mut self.cursor).write(std::ptr::null_mut()); - (&raw mut self.buf).write([0_i32; 4]); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).x).write(0_i32); + (&raw mut (*this).inner).write(::default()); + (&raw mut (*this).items).write([::default(); 3]); + (&raw mut (*this).v).write(Vec::new()); + (&raw mut (*this).cursor).write(std::ptr::null_mut()); + (&raw mut (*this).buf).write([0_i32; 4]); } } pub unsafe fn set_0(mut p: *mut i32, mut value: i32) { @@ -129,16 +129,16 @@ unsafe fn main_0() -> i32 { ((o.buf[(1) as usize]) == (6)) && ((o.cursor) == (&mut o.buf[(2) as usize] as *mut i32)) ); o.x = 0; - let mut first: i32 = (unsafe { Outer::next(&mut o) }); + let mut first: i32 = (unsafe { Outer::next(&raw mut o) }); assert!(((first) == (0)) && ((o.x) == (1))); o.x = ((o.inner.a) + (unsafe { bump_1((&mut o as *mut Outer)) })); assert!(((o.x) == (4))); (unsafe { let _k: i32 = o.inner.a; - Outer::push(&mut o, _k) + Outer::push(&raw mut o, _k) }); assert!(((o.v.len()) == (1_usize)) && ((o.v[(0_usize)]) == (7))); - assert!(((unsafe { Outer::sum(&o,) }) == (7))); + assert!(((unsafe { Outer::sum(&raw const o,) }) == (7))); let mut y: i32 = 0; { let mut __tmp_1 = { ((&mut o.items[(2) as usize].a as *mut i32) as *mut ::libc::c_void) }; diff --git a/tests/unit/out/unsafe/find.rs b/tests/unit/out/unsafe/find.rs index 35b7cf60a8..62eb6c3e8c 100644 --- a/tests/unit/out/unsafe/find.rs +++ b/tests/unit/out/unsafe/find.rs @@ -21,8 +21,8 @@ pub struct P { pub x: i32, } impl P { - pub unsafe fn operator_eq(&self, o: *const P) -> bool { - return ((self.x) == ((*o).x)); + pub unsafe fn operator_eq(this: *const Self, o: *const P) -> bool { + return (((*this).x) == ((*o).x)); } } impl std::cmp::PartialEq for P { diff --git a/tests/unit/out/unsafe/fn_ptr.rs b/tests/unit/out/unsafe/fn_ptr.rs index f0bcf58aae..33631eaf0e 100644 --- a/tests/unit/out/unsafe/fn_ptr.rs +++ b/tests/unit/out/unsafe/fn_ptr.rs @@ -48,8 +48,8 @@ pub struct HashHolder_unsigned_long__ptr__bool__ { pub h: Option u64>, } impl HashHolder_unsigned_long__ptr__bool__ { - pub unsafe fn construct(&mut self, h: *const Option u64>) { - (&raw mut self.h).write((*h)); + pub unsafe fn construct(this: *mut Self, h: *const Option u64>) { + (&raw mut (*this).h).write((*h)); } } pub static mut total_7: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); diff --git a/tests/unit/out/unsafe/fn_ptr_struct.rs b/tests/unit/out/unsafe/fn_ptr_struct.rs index db62aad441..02770b369d 100644 --- a/tests/unit/out/unsafe/fn_ptr_struct.rs +++ b/tests/unit/out/unsafe/fn_ptr_struct.rs @@ -59,25 +59,28 @@ pub struct MoveOnly { pub data_: i32, } impl MoveOnly { - pub unsafe fn construct(&mut self, mut data: i32) { - (&raw mut self.data_).write(data); + pub unsafe fn construct(this: *mut Self, mut data: i32) { + (&raw mut (*this).data_).write(data); } - pub unsafe fn get(&self) -> i32 { - return self.data_; + pub unsafe fn get(this: *const Self) -> i32 { + return (*this).data_; } } impl MoveConstructibleUnsafe for MoveOnly { - unsafe fn move_constructor(&mut self, x: *mut MoveOnly) { - (&raw mut self.data_).write((*x).data_); + unsafe fn move_constructor(this: *mut Self, x: *mut MoveOnly) { + (&raw mut (*this).data_).write((*x).data_); (*x).data_ = 0; } } pub unsafe fn make_move_only_2(__return: *mut MoveOnly) { - MoveOnly::construct(&mut *__return, 4); + MoveOnly::construct(__return, 4); return; } pub unsafe fn scale_move_only_3(__return: *mut MoveOnly, x: *mut MoveOnly) { - MoveOnly::construct(&mut *__return, ((unsafe { MoveOnly::get(&(*x)) }) * (10))); + MoveOnly::construct( + __return, + ((unsafe { MoveOnly::get(&raw const (*x)) }) * (10)), + ); return; } pub fn main() { @@ -113,15 +116,15 @@ unsafe fn main_0() -> i32 { assert!(((h1.cb) == (h2.cb))); let mut mk: Option = Some(make_move_only_2); object_unsafe!(m, MoveOnly, |m| (unsafe { (mk).unwrap()(m,) })); - assert!(((unsafe { MoveOnly::get(&m,) }) == (4))); + assert!(((unsafe { MoveOnly::get(&raw const m,) }) == (4))); let mut sc: Option = Some(scale_move_only_3); object_unsafe!(n, MoveOnly, |n| (unsafe { let mut _arg0: MoveOnly = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut _arg0, Moved(&mut m)); + ConstructFromUnsafe::construct_from(&raw mut _arg0, Moved(&mut m)); (sc).unwrap()(n, &mut _arg0) })); - assert!(((unsafe { MoveOnly::get(&n,) }) == (40))); - assert!(((unsafe { MoveOnly::get(&m,) }) == (0))); + assert!(((unsafe { MoveOnly::get(&raw const n,) }) == (40))); + assert!(((unsafe { MoveOnly::get(&raw const m,) }) == (0))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/fn_ref.rs b/tests/unit/out/unsafe/fn_ref.rs index 85484ae166..0ecb990a2e 100644 --- a/tests/unit/out/unsafe/fn_ref.rs +++ b/tests/unit/out/unsafe/fn_ref.rs @@ -36,8 +36,8 @@ pub struct Holder { pub f: Option i32>, } impl Holder { - pub unsafe fn run(&self, mut x: i32) -> i32 { - return (unsafe { (self.f).unwrap()(x) }); + pub unsafe fn run(this: *const Self, mut x: i32) -> i32 { + return (unsafe { ((*this).f).unwrap()(x) }); } } pub fn main() { @@ -55,7 +55,7 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { call_deduced_3(Some(twice_1), 7,) }) == (14))); assert!(((unsafe { call_forwarded_4(Some(square_0), 6,) }) == (36))); let mut h: Holder = Holder { f: Some(twice_1) }; - assert!(((unsafe { Holder::run(&h, 8,) }) == (16))); + assert!(((unsafe { Holder::run(&raw const h, 8,) }) == (16))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/for_body_destructor.rs b/tests/unit/out/unsafe/for_body_destructor.rs index 9f321e61b1..f1fb22888d 100644 --- a/tests/unit/out/unsafe/for_body_destructor.rs +++ b/tests/unit/out/unsafe/for_body_destructor.rs @@ -22,13 +22,13 @@ pub struct Guard { pub digit: i32, } impl Guard { - pub unsafe fn to_bool(&self) -> bool { - return ((self.digit) != (0)); + pub unsafe fn to_bool(this: *const Self) -> bool { + return (((*this).digit) != (0)); } } impl DestructibleUnsafe for Guard { - unsafe fn destroy(&mut self) { - (unsafe { libc::printf(c"%d ".as_ptr() as *const libc::c_char, (self.digit)) }); + unsafe fn destroy(this: *mut Self) { + (unsafe { libc::printf(c"%d ".as_ptr() as *const libc::c_char, ((*this).digit)) }); } } pub unsafe fn step_0(i: *mut i32) { @@ -49,11 +49,11 @@ unsafe fn main_0() -> i32 { 'for_body: { let mut first: Guard = Guard { digit: 1 }; let _dtor_first = std::mem::DropGuard::new(&raw mut first, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); let mut second: Guard = Guard { digit: 2 }; let _dtor_second = std::mem::DropGuard::new(&raw mut second, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); if ((i) == (0)) { break 'for_body; @@ -69,7 +69,7 @@ unsafe fn main_0() -> i32 { 'for_body: { let mut g: Guard = Guard { digit: 3 }; let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); break 'loop_; } @@ -83,7 +83,7 @@ unsafe fn main_0() -> i32 { 'for_body: { let mut outer: Guard = Guard { digit: 4 }; let _dtor_outer = std::mem::DropGuard::new(&raw mut outer, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); { let mut j: i32 = 0; @@ -92,7 +92,7 @@ unsafe fn main_0() -> i32 { let mut inner: Guard = Guard { digit: 5 }; let _dtor_inner = std::mem::DropGuard::new(&raw mut inner, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); if ((j) == (0)) { break 'for_body; @@ -114,13 +114,13 @@ unsafe fn main_0() -> i32 { 'for_body: { let mut outer: Guard = Guard { digit: 4 }; let _dtor_outer = std::mem::DropGuard::new(&raw mut outer, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); let mut j: i32 = 0; 'loop_: while ((*j.prefix_inc()) < (3)) { let mut inner: Guard = Guard { digit: 5 }; let _dtor_inner = std::mem::DropGuard::new(&raw mut inner, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); if ((j) == (1)) { continue 'loop_; @@ -132,7 +132,7 @@ unsafe fn main_0() -> i32 { __do_while = false; let mut inner: Guard = Guard { digit: 6 }; let _dtor_inner = std::mem::DropGuard::new(&raw mut inner, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); continue 'loop_; } @@ -144,7 +144,7 @@ unsafe fn main_0() -> i32 { let mut value: i32 = (*value); let mut inner: Guard = Guard { digit: value }; let _dtor_inner = std::mem::DropGuard::new(&raw mut inner, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); if ((value) == (1)) { continue 'loop_; @@ -162,15 +162,15 @@ unsafe fn main_0() -> i32 { 'loop_: loop { let mut condition: Guard = Guard { digit: i }; let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); - if !(unsafe { Guard::to_bool(&condition) }) { + if !(unsafe { Guard::to_bool(&raw const condition) }) { break; } 'for_body: { let mut body: Guard = Guard { digit: 4 }; let _dtor_body = std::mem::DropGuard::new(&raw mut body, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); if ((i) == (2)) { break 'for_body; @@ -189,13 +189,13 @@ unsafe fn main_0() -> i32 { { let mut init: Guard = Guard { digit: 5 }; let _dtor_init = std::mem::DropGuard::new(&raw mut init, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); 'loop_: while ((i) < (2)) { 'for_body: { let mut body: Guard = Guard { digit: 6 }; let _dtor_body = std::mem::DropGuard::new(&raw mut body, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } (unsafe { step_0(&mut i) }); @@ -209,7 +209,7 @@ unsafe fn main_0() -> i32 { digit: (*j.prefix_inc()), }; let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); continue 'loop_; } diff --git a/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs b/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs index b082ddc614..4cee7d467c 100644 --- a/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/unsafe/foreach_disjoint_field_borrow.rs @@ -24,9 +24,9 @@ pub struct S { pub a: i32, } impl DefaultConstructibleUnsafe for S { - unsafe fn default_constructor(&mut self) { - (&raw mut self.v).write(Vec::new()); - (&raw mut self.a).write(0_i32); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).v).write(Vec::new()); + (&raw mut (*this).a).write(0_i32); } } pub fn main() { diff --git a/tests/unit/out/unsafe/forward_basic.rs b/tests/unit/out/unsafe/forward_basic.rs index 39a0d7b5bb..36855b01cc 100644 --- a/tests/unit/out/unsafe/forward_basic.rs +++ b/tests/unit/out/unsafe/forward_basic.rs @@ -20,24 +20,24 @@ pub struct Tracked { pub moves: i32, } impl Tracked { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); - (&raw mut self.copies).write(0); - (&raw mut self.moves).write(0); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); + (&raw mut (*this).copies).write(0); + (&raw mut (*this).moves).write(0); } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(&mut self, o: *const Tracked) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((((*o).copies) + (1))); - (&raw mut self.moves).write((*o).moves); + unsafe fn copy_constructor(this: *mut Self, o: *const Tracked) { + (&raw mut (*this).v).write((*o).v); + (&raw mut (*this).copies).write((((*o).copies) + (1))); + (&raw mut (*this).moves).write((*o).moves); } } impl MoveConstructibleUnsafe for Tracked { - unsafe fn move_constructor(&mut self, o: *mut Tracked) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((*o).copies); - (&raw mut self.moves).write((((*o).moves) + (1))); + unsafe fn move_constructor(this: *mut Self, o: *mut Tracked) { + (&raw mut (*this).v).write((*o).v); + (&raw mut (*this).copies).write((*o).copies); + (&raw mut (*this).moves).write((((*o).moves) + (1))); (*o).v = 0; } } @@ -48,13 +48,13 @@ pub unsafe fn chosen_overload_1(_a0: *mut Tracked) -> Overload { return Overload_kRvalueOverload; } impl Holder { - pub unsafe fn construct_1(&mut self, x: *mut Tracked) { - ConstructFromUnsafe::construct_from(&mut self.t, x); + pub unsafe fn construct_1(this: *mut Self, x: *mut Tracked) { + ConstructFromUnsafe::construct_from(&raw mut (*this).t, x); } } impl Holder { - pub unsafe fn construct_2(&mut self, x: *mut Tracked) { - ConstructFromUnsafe::construct_from(&mut self.t, Moved(x)); + pub unsafe fn construct_2(this: *mut Self, x: *mut Tracked) { + ConstructFromUnsafe::construct_from(&raw mut (*this).t, Moved(x)); } } #[repr(C)] @@ -85,11 +85,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(&mut *__return, x); + Holder::construct_1(__return, x); return; } pub unsafe fn forward_into_ctor_7(__return: *mut Holder, x: *mut Tracked) { - Holder::construct_2(&mut *__return, x); + Holder::construct_2(__return, x); return; } pub fn main() { @@ -107,7 +107,7 @@ unsafe fn main_0() -> i32 { assert!( (((unsafe { let mut _x: Tracked = ::zero_init(); - Tracked::construct(&mut _x, 8); + Tracked::construct(&raw mut _x, 8); forward_once_3(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) @@ -120,7 +120,7 @@ unsafe fn main_0() -> i32 { assert!( (((unsafe { let mut _x: Tracked = ::zero_init(); - Tracked::construct(&mut _x, 10); + Tracked::construct(&raw mut _x, 10); forward_twice_5(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) @@ -135,7 +135,7 @@ unsafe fn main_0() -> i32 { assert!(((kept.v) == (11))); object_unsafe!(from_rvalue, Holder, |from_rvalue| (unsafe { let mut _x: Tracked = ::zero_init(); - Tracked::construct(&mut _x, 12); + Tracked::construct(&raw mut _x, 12); forward_into_ctor_7(from_rvalue, &mut _x) })); assert!(((from_rvalue.t.v) == (12))); diff --git a/tests/unit/out/unsafe/forward_decltype.rs b/tests/unit/out/unsafe/forward_decltype.rs index da2ffa87cd..719d60dd5d 100644 --- a/tests/unit/out/unsafe/forward_decltype.rs +++ b/tests/unit/out/unsafe/forward_decltype.rs @@ -20,24 +20,24 @@ pub struct Tracked { pub moves: i32, } impl Tracked { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); - (&raw mut self.copies).write(0); - (&raw mut self.moves).write(0); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); + (&raw mut (*this).copies).write(0); + (&raw mut (*this).moves).write(0); } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(&mut self, o: *const Tracked) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((((*o).copies) + (1))); - (&raw mut self.moves).write((*o).moves); + unsafe fn copy_constructor(this: *mut Self, o: *const Tracked) { + (&raw mut (*this).v).write((*o).v); + (&raw mut (*this).copies).write((((*o).copies) + (1))); + (&raw mut (*this).moves).write((*o).moves); } } impl MoveConstructibleUnsafe for Tracked { - unsafe fn move_constructor(&mut self, o: *mut Tracked) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((*o).copies); - (&raw mut self.moves).write((((*o).moves) + (1))); + unsafe fn move_constructor(this: *mut Self, o: *mut Tracked) { + (&raw mut (*this).v).write((*o).v); + (&raw mut (*this).copies).write((*o).copies); + (&raw mut (*this).moves).write((((*o).moves) + (1))); (*o).v = 0; } } @@ -78,7 +78,7 @@ unsafe fn main_0() -> i32 { assert!( (((unsafe { let mut _x: Tracked = ::zero_init(); - Tracked::construct(&mut _x, 4); + Tracked::construct(&raw mut _x, 4); forward_by_decltype_3(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) @@ -91,7 +91,7 @@ unsafe fn main_0() -> i32 { assert!( (((unsafe { let mut _x: Tracked = ::zero_init(); - Tracked::construct(&mut _x, 6); + Tracked::construct(&raw mut _x, 6); forward_abbreviated_5(&mut _x) }) as i32) == (Overload_kRvalueOverload as i32)) @@ -100,7 +100,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _args_1: Tracked = ::zero_init(); - Tracked::construct(&mut _args_1, 8); + Tracked::construct(&raw mut _args_1, 8); forward_abbreviated_pack_6(&mut c, &mut _args_1) }) == ((Overload_kLvalueOverload as i32) + (Overload_kRvalueOverload as i32))) ); diff --git a/tests/unit/out/unsafe/forward_explicit.rs b/tests/unit/out/unsafe/forward_explicit.rs index 8e83703bd2..d787f5307c 100644 --- a/tests/unit/out/unsafe/forward_explicit.rs +++ b/tests/unit/out/unsafe/forward_explicit.rs @@ -22,24 +22,24 @@ pub struct Tracked { pub moves: i32, } impl Tracked { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); - (&raw mut self.copies).write(0); - (&raw mut self.moves).write(0); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); + (&raw mut (*this).copies).write(0); + (&raw mut (*this).moves).write(0); } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(&mut self, o: *const Tracked) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((((*o).copies) + (1))); - (&raw mut self.moves).write((*o).moves); + unsafe fn copy_constructor(this: *mut Self, o: *const Tracked) { + (&raw mut (*this).v).write((*o).v); + (&raw mut (*this).copies).write((((*o).copies) + (1))); + (&raw mut (*this).moves).write((*o).moves); } } impl MoveConstructibleUnsafe for Tracked { - unsafe fn move_constructor(&mut self, o: *mut Tracked) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((*o).copies); - (&raw mut self.moves).write((((*o).moves) + (1))); + unsafe fn move_constructor(this: *mut Self, o: *mut Tracked) { + (&raw mut (*this).v).write((*o).v); + (&raw mut (*this).copies).write((*o).copies); + (&raw mut (*this).moves).write((((*o).moves) + (1))); (*o).v = 0; } } @@ -56,7 +56,7 @@ pub unsafe fn chosen_overload_3(_a0: *mut i32) -> Overload { return Overload_kIntRvalueOverload; } pub unsafe fn copy_or_move_into_param_4(__return: *mut Tracked, t: *mut Tracked) { - ConstructFromUnsafe::construct_from(&mut *__return, Moved(t)); + ConstructFromUnsafe::construct_from(__return, Moved(t)); return; } pub fn main() { @@ -76,7 +76,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(b, Tracked(6)); object_unsafe!(moved, Tracked, |moved| (unsafe { let mut _t: Tracked = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut _t, Moved(&mut b)); + ConstructFromUnsafe::construct_from(&raw mut _t, Moved(&mut b)); copy_or_move_into_param_4(moved, &mut _t) })); assert!(((moved.v) == (6))); @@ -86,7 +86,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(c, Tracked(7)); object_unsafe!(copied, Tracked, |copied| (unsafe { let mut _t: Tracked = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut _t, &c); + ConstructFromUnsafe::construct_from(&raw mut _t, &c); copy_or_move_into_param_4(copied, &mut _t) })); assert!(((copied.v) == (7))); diff --git a/tests/unit/out/unsafe/forward_pack.rs b/tests/unit/out/unsafe/forward_pack.rs index c92e83a4b3..f848da77e0 100644 --- a/tests/unit/out/unsafe/forward_pack.rs +++ b/tests/unit/out/unsafe/forward_pack.rs @@ -22,24 +22,24 @@ pub struct Tracked { pub moves: i32, } impl Tracked { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); - (&raw mut self.copies).write(0); - (&raw mut self.moves).write(0); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); + (&raw mut (*this).copies).write(0); + (&raw mut (*this).moves).write(0); } } impl CopyConstructibleUnsafe for Tracked { - unsafe fn copy_constructor(&mut self, o: *const Tracked) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((((*o).copies) + (1))); - (&raw mut self.moves).write((*o).moves); + unsafe fn copy_constructor(this: *mut Self, o: *const Tracked) { + (&raw mut (*this).v).write((*o).v); + (&raw mut (*this).copies).write((((*o).copies) + (1))); + (&raw mut (*this).moves).write((*o).moves); } } impl MoveConstructibleUnsafe for Tracked { - unsafe fn move_constructor(&mut self, o: *mut Tracked) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((*o).copies); - (&raw mut self.moves).write((((*o).moves) + (1))); + unsafe fn move_constructor(this: *mut Self, o: *mut Tracked) { + (&raw mut (*this).v).write((*o).v); + (&raw mut (*this).copies).write((*o).copies); + (&raw mut (*this).moves).write((((*o).moves) + (1))); (*o).v = 0; } } @@ -90,9 +90,9 @@ pub unsafe fn forward_pack_7( return digits; } impl Pair { - pub unsafe fn construct(&mut self, x: *mut Tracked, y: *mut Tracked) { - ConstructFromUnsafe::construct_from(&mut self.a, x); - ConstructFromUnsafe::construct_from(&mut self.b, Moved(y)); + pub unsafe fn construct(this: *mut Self, x: *mut Tracked, y: *mut Tracked) { + ConstructFromUnsafe::construct_from(&raw mut (*this).a, x); + ConstructFromUnsafe::construct_from(&raw mut (*this).b, Moved(y)); } } #[repr(C)] @@ -109,7 +109,7 @@ pub unsafe fn forward_pack_into_ctor_8( args_0: *mut Tracked, args_1: *mut Tracked, ) { - Pair::construct(&mut *__return, args_0, args_1); + Pair::construct(__return, args_0, args_1); return; } pub fn main() { @@ -126,7 +126,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _args: Tracked = ::zero_init(); - Tracked::construct(&mut _args, 2); + Tracked::construct(&raw mut _args, 2); forward_pack_6(&mut _args) }) == (Overload_kRvalueOverload as i32)) ); @@ -134,7 +134,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _args_1: Tracked = ::zero_init(); - Tracked::construct(&mut _args_1, 4); + Tracked::construct(&raw mut _args_1, 4); let mut _args_3: i32 = 5; forward_pack_7(&mut a, &mut _args_1, &mut i, &mut _args_3) }) == (1234)) @@ -144,7 +144,7 @@ unsafe fn main_0() -> i32 { object_unsafe!(lhs, Tracked(6)); object_unsafe!(p, Pair, |p| (unsafe { let mut _args_1: Tracked = ::zero_init(); - Tracked::construct(&mut _args_1, 7); + Tracked::construct(&raw mut _args_1, 7); forward_pack_into_ctor_8(p, &mut lhs, &mut _args_1) })); assert!(((p.a.v) == (6))); diff --git a/tests/unit/out/unsafe/function_overloading.rs b/tests/unit/out/unsafe/function_overloading.rs index d35fad6066..907ea78ec0 100644 --- a/tests/unit/out/unsafe/function_overloading.rs +++ b/tests/unit/out/unsafe/function_overloading.rs @@ -34,12 +34,12 @@ pub unsafe fn bar_4(x: *mut i32) -> i32 { )] pub struct Foo {} impl Foo { - pub unsafe fn foo_1(&self) {} - pub unsafe fn foo_2(&mut self) {} - pub unsafe fn method_3(&mut self, mut x: i32) {} - pub unsafe fn method_4(&self, mut x: i32) {} - pub unsafe fn method2_5(&self, mut x: i32, mut y: i32) {} - pub unsafe fn method2_6(&self, mut x: f64, mut y: f64) {} + pub unsafe fn foo_1(this: *const Self) {} + pub unsafe fn foo_2(this: *mut Self) {} + pub unsafe fn method_3(this: *mut Self, mut x: i32) {} + pub unsafe fn method_4(this: *const Self, mut x: i32) {} + pub unsafe fn method2_5(this: *const Self, mut x: i32, mut y: i32) {} + pub unsafe fn method2_6(this: *const Self, mut x: f64, mut y: f64) {} } pub unsafe fn func_5(mut x: i32) -> i32 { return 1; @@ -74,10 +74,10 @@ unsafe fn main_0() -> i32 { out += (((bar) + (unsafe { foo_0(0) })) + (unsafe { foo_1((&mut x as *mut i32)) })); let mut foo1: Foo = ::default(); let foo2: Foo = ::default(); - (unsafe { Foo::foo_2(&mut foo1) }); - (unsafe { Foo::method_3(&mut foo1, 1) }); - (unsafe { Foo::foo_1(&foo2) }); - (unsafe { Foo::method_4(&foo2, 2) }); + (unsafe { Foo::foo_2(&raw mut foo1) }); + (unsafe { Foo::method_3(&raw mut foo1, 1) }); + (unsafe { Foo::foo_1(&raw const foo2) }); + (unsafe { Foo::method_4(&raw const foo2, 2) }); assert!(((out) == (13))); return 0; } diff --git a/tests/unit/out/unsafe/global_init_side_effect.rs b/tests/unit/out/unsafe/global_init_side_effect.rs index 8bf88c678d..53c5e4a197 100644 --- a/tests/unit/out/unsafe/global_init_side_effect.rs +++ b/tests/unit/out/unsafe/global_init_side_effect.rs @@ -22,21 +22,21 @@ pub static mut total_0: std::cell::LazyCell = std::cell::LazyCell::new(|| u #[cpp_from(i32, construct, value)] pub struct S {} impl S { - pub unsafe fn construct(&mut self, mut x: i32) { + pub unsafe fn construct(this: *mut Self, mut x: i32) { (*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) += x; } } pub static mut a_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: S = ::zero_init(); - S::construct(&mut __v, 1); + S::construct(&raw mut __v, 1); __v } }); pub static mut b_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: S = ::zero_init(); - S::construct(&mut __v, 10); + S::construct(&raw mut __v, 10); __v } }); diff --git a/tests/unit/out/unsafe/global_non_const_init.rs b/tests/unit/out/unsafe/global_non_const_init.rs index 110bdf2dde..667aebda32 100644 --- a/tests/unit/out/unsafe/global_non_const_init.rs +++ b/tests/unit/out/unsafe/global_non_const_init.rs @@ -33,13 +33,13 @@ pub struct Ctor { pub v: i32, } impl Ctor { - pub unsafe fn construct_1(&mut self, mut x: i32) { - (&raw mut self.v).write(x); + pub unsafe fn construct_1(this: *mut Self, mut x: i32) { + (&raw mut (*this).v).write(x); } } impl DefaultConstructibleUnsafe for Ctor { - unsafe fn default_constructor(&mut self) { - (&raw mut self.v).write((unsafe { next_0() })); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).v).write((unsafe { next_0() })); } } impl Default for Ctor { @@ -47,7 +47,7 @@ impl Default for Ctor { unsafe { { let mut __v: Ctor = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -56,14 +56,14 @@ impl Default for Ctor { pub static mut default_ctor_7: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: Ctor = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } }); pub static mut arg_ctor_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: Ctor = ::zero_init(); - Ctor::construct_1(&mut __v, 7); + Ctor::construct_1(&raw mut __v, 7); __v } }); @@ -78,7 +78,7 @@ pub static mut str_9: std::cell::LazyCell> = pub static mut inline_member_11: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: Ctor = ::zero_init(); - Ctor::construct_1(&mut __v, 5); + Ctor::construct_1(&raw mut __v, 5); __v } }); @@ -105,7 +105,7 @@ static mut once_13: std::cell::LazyCell = static mut local_ctor_14: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: Ctor = ::zero_init(); - Ctor::construct_1(&mut __v, 3); + Ctor::construct_1(&raw mut __v, 3); __v } }); @@ -120,8 +120,8 @@ impl Singleton { } } impl DefaultConstructibleUnsafe for Singleton { - unsafe fn default_constructor(&mut self) { - (&raw mut self.hits).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).hits).write(0); } } impl Default for Singleton { @@ -129,7 +129,7 @@ impl Default for Singleton { unsafe { { let mut __v: Singleton = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -138,7 +138,7 @@ impl Default for Singleton { static mut s_15: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: Singleton = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } }); diff --git a/tests/unit/out/unsafe/huffman.rs b/tests/unit/out/unsafe/huffman.rs index 7bd66bd8f0..b08a31aac0 100644 --- a/tests/unit/out/unsafe/huffman.rs +++ b/tests/unit/out/unsafe/huffman.rs @@ -24,8 +24,8 @@ pub struct MinHeapNode { pub right: *mut MinHeapNode, } impl MinHeapNode { - pub unsafe fn IsLeaf(&self) -> bool { - return ((self.left).is_null()) && ((self.right).is_null()); + pub unsafe fn IsLeaf(this: *const Self) -> bool { + return (((*this).left).is_null()) && (((*this).right).is_null()); } } pub unsafe fn Swap_0(a: *mut MinHeapNode, b: *mut MinHeapNode) { @@ -66,29 +66,33 @@ pub struct MinHeap { pub alloc: Option>, } impl MinHeap { - pub unsafe fn Alloc(&mut self, mut data: libc::c_char, mut freq: i32) -> *mut MinHeapNode { - (*self + pub unsafe fn Alloc( + this: *mut Self, + mut data: libc::c_char, + mut freq: i32, + ) -> *mut MinHeapNode { + (*(*this) .alloc .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut MinHeapNode) - .add((self.next as usize))) = MinHeapNode { + .add(((*this).next as usize))) = MinHeapNode { data: data, freq: freq, left: std::ptr::null_mut(), right: std::ptr::null_mut(), }; - return (&mut (*self + return (&mut (*(*this) .alloc .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut MinHeapNode) - .add((self.next.postfix_inc() as usize))) as *mut MinHeapNode); + .add(((*this).next.postfix_inc() as usize))) as *mut MinHeapNode); } - pub unsafe fn Heapify(&mut self, mut idx: i32) { + pub unsafe fn Heapify(this: *mut Self, mut idx: i32) { let mut smallest: i32 = idx; let mut left: i32 = (((2) * (idx)) + (1)); let mut right: i32 = (((2) * (idx)) + (2)); - if ((left) < (self.size)) - && (((*(*self + if ((left) < ((*this).size)) + && (((*(*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { @@ -96,7 +100,7 @@ impl MinHeap { }) .add((left as usize)))) .freq) - < ((*(*self + < ((*(*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { @@ -107,8 +111,8 @@ impl MinHeap { { smallest = left; } - if ((right) < (self.size)) - && (((*(*self + if ((right) < ((*this).size)) + && (((*(*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { @@ -116,7 +120,7 @@ impl MinHeap { }) .add((right as usize)))) .freq) - < ((*(*self + < ((*(*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { @@ -129,14 +133,14 @@ impl MinHeap { } if ((smallest) != (idx)) { (unsafe { - let _a: *mut MinHeapNode = &mut (*(*self + let _a: *mut MinHeapNode = &mut (*(*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { s.as_ptr() as *mut *mut MinHeapNode }) .add((smallest as usize)))); - let _b: *mut MinHeapNode = &mut (*(*self + let _b: *mut MinHeapNode = &mut (*(*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { @@ -145,40 +149,40 @@ impl MinHeap { .add((idx as usize)))); Swap_0(_a, _b) }); - (unsafe { MinHeap::Heapify(self, smallest) }); + (unsafe { MinHeap::Heapify(this, smallest) }); } } - pub unsafe fn ExtractMin(&mut self) -> *mut MinHeapNode { - let mut out: *mut MinHeapNode = (*self + pub unsafe fn ExtractMin(this: *mut Self) -> *mut MinHeapNode { + let mut out: *mut MinHeapNode = (*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { s.as_ptr() as *mut *mut MinHeapNode }) .add(0_usize)); - self.size.prefix_dec(); - (*self + (*this).size.prefix_dec(); + (*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { s.as_ptr() as *mut *mut MinHeapNode }) - .add(0_usize)) = (*self + .add(0_usize)) = (*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { s.as_ptr() as *mut *mut MinHeapNode }) - .add((self.size as usize))); - (unsafe { MinHeap::Heapify(self, 0) }); + .add(((*this).size as usize))); + (unsafe { MinHeap::Heapify(this, 0) }); return out; } - pub unsafe fn Insert(&mut self, mut node: *mut MinHeapNode) { - self.size.prefix_inc(); - let mut i: i32 = ((self.size) - (1)); + pub unsafe fn Insert(this: *mut Self, mut node: *mut MinHeapNode) { + (*this).size.prefix_inc(); + let mut i: i32 = (((*this).size) - (1)); 'loop_: while ((i) != (0)) && (((*node).freq) - < ((*(*self + < ((*(*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { @@ -187,13 +191,13 @@ impl MinHeap { .add(((((i) - (1)) / (2)) as usize)))) .freq)) { - (*self + (*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { s.as_ptr() as *mut *mut MinHeapNode }) - .add((i as usize))) = (*self + .add((i as usize))) = (*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { @@ -202,7 +206,7 @@ impl MinHeap { .add(((((i) - (1)) / (2)) as usize))); i = (((i) - (1)) / (2)); } - (*self + (*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { @@ -211,7 +215,7 @@ impl MinHeap { .add((i as usize))) = node; } pub unsafe fn Build( - &mut self, + this: *mut Self, data: *mut Option>, freq: *mut Option>, mut n: i32, @@ -220,13 +224,13 @@ impl MinHeap { let mut i: i32 = 0; 'loop_: while ((i) < (n)) { 'for_body: { - (*self + (*(*this) .arr .as_deref() .map_or(::std::ptr::null_mut(), |s| { s.as_ptr() as *mut *mut MinHeapNode }) - .add((self.size.postfix_inc() as usize))) = (unsafe { + .add(((*this).size.postfix_inc() as usize))) = (unsafe { let _data: libc::c_char = (*(*data) .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut libc::c_char) @@ -235,17 +239,17 @@ impl MinHeap { .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((i as usize))); - MinHeap::Alloc(self, _data, _freq) + MinHeap::Alloc(this, _data, _freq) }); } i.prefix_inc(); } } { - let mut i: i32 = (((self.size) - (2)) / (2)); + let mut i: i32 = ((((*this).size) - (2)) / (2)); 'loop_: while ((i) >= (0)) { 'for_body: { - (unsafe { MinHeap::Heapify(self, i) }); + (unsafe { MinHeap::Heapify(this, i) }); } i.prefix_dec(); } @@ -253,12 +257,12 @@ impl MinHeap { } } impl DefaultConstructibleUnsafe for MinHeap { - unsafe fn default_constructor(&mut self) { - (&raw mut self.size).write(0_i32); - (&raw mut self.capacity).write(0_i32); - (&raw mut self.arr).write(None); - (&raw mut self.next).write(0_i32); - (&raw mut self.alloc).write(None); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).size).write(0_i32); + (&raw mut (*this).capacity).write(0_i32); + (&raw mut (*this).arr).write(None); + (&raw mut (*this).next).write(0_i32); + (&raw mut (*this).alloc).write(None); } } pub unsafe fn AllocMinHeap_1(mut capacity: i32) -> Option> { @@ -287,7 +291,7 @@ pub unsafe fn Huffman_2( let mut minHeap: Option> = (unsafe { AllocMinHeap_1(size) }); (unsafe { MinHeap::Build( - &mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { + &raw mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { v as *const MinHeap as *mut MinHeap })), data, @@ -303,21 +307,21 @@ pub unsafe fn Huffman_2( { let mut left: *mut MinHeapNode = (unsafe { MinHeap::ExtractMin( - &mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { + &raw mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { v as *const MinHeap as *mut MinHeap })), ) }); let mut right: *mut MinHeapNode = (unsafe { MinHeap::ExtractMin( - &mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { + &raw mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { v as *const MinHeap as *mut MinHeap })), ) }); let mut top: *mut MinHeapNode = (unsafe { MinHeap::Alloc( - &mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { + &raw mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { v as *const MinHeap as *mut MinHeap })), ('$' as libc::c_char), @@ -328,7 +332,7 @@ pub unsafe fn Huffman_2( (*top).right = right; (unsafe { MinHeap::Insert( - &mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { + &raw mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { v as *const MinHeap as *mut MinHeap })), top, @@ -397,7 +401,7 @@ pub unsafe fn CollectCodes_4( .add((top as usize))) = 1; (unsafe { CollectCodes_4((*root).right, arr, ((top) + (1)), out, next) }); } - if (unsafe { MinHeapNode::IsLeaf(&(*(root).cast_const())) }) { + if (unsafe { MinHeapNode::IsLeaf(&raw const (*(root).cast_const())) }) { (unsafe { CollectCode_3(arr, top, out, next) }); } } @@ -409,7 +413,7 @@ pub unsafe fn HuffmanCodes_5( let mut minHeap: Option> = (unsafe { Huffman_2(data, freq, size) }); let mut root: *mut MinHeapNode = (unsafe { MinHeap::ExtractMin( - &mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { + &raw mut (*minHeap.as_deref().map_or(::std::ptr::null_mut(), |v| { v as *const MinHeap as *mut MinHeap })), ) diff --git a/tests/unit/out/unsafe/immutable-deref-on-func-call.rs b/tests/unit/out/unsafe/immutable-deref-on-func-call.rs index dfb8ab5645..f3768f61ff 100644 --- a/tests/unit/out/unsafe/immutable-deref-on-func-call.rs +++ b/tests/unit/out/unsafe/immutable-deref-on-func-call.rs @@ -21,7 +21,7 @@ pub struct Item { pub value: i32, } impl Item { - pub unsafe fn foo(&mut self, mut other: *mut Item) { + pub unsafe fn foo(this: *mut Self, mut other: *mut Item) { (*other).value = 10; } } @@ -42,7 +42,7 @@ unsafe fn main_0() -> i32 { (*arr.offset((1) as isize)).value = 2; (unsafe { let _other: *mut Item = (&mut (*arr.offset((1) as isize)) as *mut Item); - Item::foo(&mut (*arr.offset((0) as isize)), _other) + Item::foo(&raw mut (*arr.offset((0) as isize)), _other) }); let mut result: i32 = (((*arr.offset((0) as isize)).value) + ((*arr.offset((1) as isize)).value)); diff --git a/tests/unit/out/unsafe/implicit_autoref.rs b/tests/unit/out/unsafe/implicit_autoref.rs index 9008386eb7..8528b4c6d6 100644 --- a/tests/unit/out/unsafe/implicit_autoref.rs +++ b/tests/unit/out/unsafe/implicit_autoref.rs @@ -23,8 +23,8 @@ pub struct Holder { pub v: Vec, } impl DefaultConstructibleUnsafe for Holder { - unsafe fn default_constructor(&mut self) { - (&raw mut self.v).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).v).write(Vec::new()); } } pub unsafe fn write_through_0(mut p: *mut i32) { diff --git a/tests/unit/out/unsafe/in_class_field_initializer.rs b/tests/unit/out/unsafe/in_class_field_initializer.rs index 81acf09748..8dbb959f6a 100644 --- a/tests/unit/out/unsafe/in_class_field_initializer.rs +++ b/tests/unit/out/unsafe/in_class_field_initializer.rs @@ -13,9 +13,9 @@ pub struct Inner { pub y: i32, } impl DefaultConstructibleUnsafe for Inner { - unsafe fn default_constructor(&mut self) { - (&raw mut self.x).write(3); - (&raw mut self.y).write(4); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).x).write(3); + (&raw mut (*this).y).write(4); } } impl Default for Inner { @@ -32,11 +32,11 @@ pub struct S { pub d: Inner, } impl DefaultConstructibleUnsafe for S { - unsafe fn default_constructor(&mut self) { - (&raw mut self.a).write(1); - (&raw mut self.b).write((2 as libc::c_char)); - (&raw mut self.c).write(::default()); - DefaultConstructibleUnsafe::default_constructor(&mut self.d); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).a).write(1); + (&raw mut (*this).b).write((2 as libc::c_char)); + (&raw mut (*this).c).write(::default()); + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).d); } } impl Default for S { @@ -66,9 +66,9 @@ pub struct Boxed_int_ { pub tag: i32, } impl Boxed_int_ { - pub unsafe fn construct(&mut self, mut x: i32, mut t: i32) { - (&raw mut self.v).write(x); - (&raw mut self.tag).write(t); + pub unsafe fn construct(this: *mut Self, mut x: i32, mut t: i32) { + (&raw mut (*this).v).write(x); + (&raw mut (*this).tag).write(t); } } impl Default for Boxed_int_ { diff --git a/tests/unit/out/unsafe/init_list.rs b/tests/unit/out/unsafe/init_list.rs index 9d3b585001..ac9d1c1658 100644 --- a/tests/unit/out/unsafe/init_list.rs +++ b/tests/unit/out/unsafe/init_list.rs @@ -28,14 +28,14 @@ pub struct Holder { pub p: Pair, } impl Holder { - pub unsafe fn operator_assign_1(&mut self, o: *mut Pair) -> *mut Holder { - self.p = (*o); - return &mut (*(self as *mut Holder)); + pub unsafe fn operator_assign_1(this: *mut Self, o: *mut Pair) -> *mut Holder { + (*this).p = (*o); + return &mut (*this); } } impl DefaultConstructibleUnsafe for Holder { - unsafe fn default_constructor(&mut self) { - (&raw mut self.p).write(Pair { a: 0, b: 0 }); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).p).write(Pair { a: 0, b: 0 }); } } impl Default for Holder { @@ -56,8 +56,8 @@ pub struct Seven { pub v: i32, } impl DefaultConstructibleUnsafe for Seven { - unsafe fn default_constructor(&mut self) { - (&raw mut self.v).write(7); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).v).write(7); } } impl Default for Seven { @@ -81,7 +81,7 @@ unsafe fn main_0() -> i32 { (unsafe { f_0(Vec::from([1, 2, 3, 4])) }); let mut p: Pair = Pair { a: 1, b: 2 }; object_unsafe!(h, Holder); - (unsafe { Holder::operator_assign_1(&mut h, &mut p) }); + (unsafe { Holder::operator_assign_1(&raw mut h, &mut p) }); assert!(((h.p.a) == (1)) && ((h.p.b) == (2))); assert!(((unsafe { sum_1(&p,) }) == (3))); let mut sevens: [Seven; 4] = [::default(); 4]; diff --git a/tests/unit/out/unsafe/inline_container_fields.rs b/tests/unit/out/unsafe/inline_container_fields.rs index 0b21b79238..47a07f2ea9 100644 --- a/tests/unit/out/unsafe/inline_container_fields.rs +++ b/tests/unit/out/unsafe/inline_container_fields.rs @@ -25,10 +25,10 @@ pub struct Elem { pub coeffs: Vec, } impl DefaultConstructibleUnsafe for Elem { - unsafe fn default_constructor(&mut self) { - (&raw mut self.id).write(0_i32); - (&raw mut self.hist).write([0_i32; 4]); - (&raw mut self.coeffs).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).id).write(0_i32); + (&raw mut (*this).hist).write([0_i32; 4]); + (&raw mut (*this).coeffs).write(Vec::new()); } } #[repr(C)] @@ -51,12 +51,12 @@ pub struct State { pub rows: Vec>, } impl DefaultConstructibleUnsafe for State { - unsafe fn default_constructor(&mut self) { - (&raw mut self.count).write(0_i32); - (&raw mut self.grid).write([[0_i32; 3]; 2]); - (&raw mut self.arr).write(std::array::from_fn::<_, 3, _>(|_| 0_i32)); - (&raw mut self.elems).write(Vec::new()); - (&raw mut self.rows).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).count).write(0_i32); + (&raw mut (*this).grid).write([[0_i32; 3]; 2]); + (&raw mut (*this).arr).write(std::array::from_fn::<_, 3, _>(|_| 0_i32)); + (&raw mut (*this).elems).write(Vec::new()); + (&raw mut (*this).rows).write(Vec::new()); } } impl Default for State { @@ -143,36 +143,36 @@ pub struct Counted { pub v: i32, } impl DefaultConstructibleUnsafe for Counted { - unsafe fn default_constructor(&mut self) { - (&raw mut self.v).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).v).write(0); } } impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(&mut self, o: *const Counted) { - (&raw mut self.v).write((*o).v); + unsafe fn copy_constructor(this: *mut Self, o: *const Counted) { + (&raw mut (*this).v).write((*o).v); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)).prefix_inc(); } } impl MoveConstructibleUnsafe for Counted { - unsafe fn move_constructor(&mut self, o: *mut Counted) { - (&raw mut self.v).write((*o).v); + unsafe fn move_constructor(this: *mut Self, o: *mut Counted) { + (&raw mut (*this).v).write((*o).v); (*o).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)).prefix_inc(); } } impl CopyAssignableUnsafe for Counted { - unsafe fn copy_assign(&mut self, o: *const Counted) -> *mut Counted { - self.v = (*o).v; + unsafe fn copy_assign(this: *mut Self, o: *const Counted) -> *mut Counted { + (*this).v = (*o).v; (*std::cell::LazyCell::force_mut(&mut *&raw mut copy_assigns_4)).prefix_inc(); - return &mut (*(self as *mut Counted)); + return &mut (*this); } } impl MoveAssignableUnsafe for Counted { - unsafe fn move_assign(&mut self, o: *mut Counted) -> *mut Counted { - self.v = (*o).v; + unsafe fn move_assign(this: *mut Self, o: *mut Counted) -> *mut Counted { + (*this).v = (*o).v; (*o).v = -1_i32; (*std::cell::LazyCell::force_mut(&mut *&raw mut move_assigns_5)).prefix_inc(); - return &mut (*(self as *mut Counted)); + return &mut (*this); } } impl Default for Counted { diff --git a/tests/unit/out/unsafe/kruskal.rs b/tests/unit/out/unsafe/kruskal.rs index 897b47150b..2f887245a5 100644 --- a/tests/unit/out/unsafe/kruskal.rs +++ b/tests/unit/out/unsafe/kruskal.rs @@ -188,17 +188,17 @@ pub struct DisjointSet { pub n: i32, } impl DisjointSet { - pub unsafe fn makeSet(&mut self) { + pub unsafe fn makeSet(this: *mut Self) { { let mut i: i32 = 0; - 'loop_: while ((i) < (self.n)) { + 'loop_: while ((i) < ((*this).n)) { 'for_body: { - (*self + (*(*this) .parent .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((i as usize))) = i; - (*self + (*(*this) .rank .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) @@ -208,82 +208,82 @@ impl DisjointSet { } } } - pub unsafe fn find(&mut self, mut x: i32) -> i32 { - if ((*self + pub unsafe fn find(this: *mut Self, mut x: i32) -> i32 { + if ((*(*this) .parent .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((x as usize))) != (x)) { - (*self + (*(*this) .parent .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((x as usize))) = (unsafe { - let _x: i32 = (*self + let _x: i32 = (*(*this) .parent .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((x as usize))); - DisjointSet::find(self, _x) + DisjointSet::find(this, _x) }); } - return (*self + return (*(*this) .parent .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((x as usize))); } - pub unsafe fn merge(&mut self, mut x: i32, mut y: i32) { - let mut xset: i32 = (unsafe { DisjointSet::find(self, x) }); - let mut yset: i32 = (unsafe { DisjointSet::find(self, y) }); + pub unsafe fn merge(this: *mut Self, mut x: i32, mut y: i32) { + let mut xset: i32 = (unsafe { DisjointSet::find(this, x) }); + let mut yset: i32 = (unsafe { DisjointSet::find(this, y) }); if ((xset) == (yset)) { return; } - if ((*self + if ((*(*this) .rank .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((xset as usize))) - < (*self + < (*(*this) .rank .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((yset as usize)))) { - (*self + (*(*this) .parent .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((xset as usize))) = yset; - } else if ((*self + } else if ((*(*this) .rank .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((xset as usize))) - > (*self + > (*(*this) .rank .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((yset as usize)))) { - (*self + (*(*this) .parent .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((yset as usize))) = xset; } else { - (*self + (*(*this) .parent .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) .add((yset as usize))) = xset; - (*self + (*(*this) .rank .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) - .add((xset as usize))) = ((*self + .add((xset as usize))) = ((*(*this) .rank .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut i32) @@ -293,10 +293,10 @@ impl DisjointSet { } } impl DefaultConstructibleUnsafe for DisjointSet { - unsafe fn default_constructor(&mut self) { - (&raw mut self.rank).write(None); - (&raw mut self.parent).write(None); - (&raw mut self.n).write(0_i32); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).rank).write(None); + (&raw mut (*this).parent).write(None); + (&raw mut (*this).n).write(0_i32); } } #[repr(C)] @@ -315,10 +315,10 @@ pub struct Graph { pub E: i32, } impl DefaultConstructibleUnsafe for Graph { - unsafe fn default_constructor(&mut self) { - (&raw mut self.edges).write(None); - (&raw mut self.V).write(0_i32); - (&raw mut self.E).write(0_i32); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).edges).write(None); + (&raw mut (*this).V).write(0_i32); + (&raw mut (*this).E).write(0_i32); } } pub unsafe fn MSTKruskal_2(graph: *mut Graph) -> f64 { @@ -340,7 +340,7 @@ pub unsafe fn MSTKruskal_2(graph: *mut Graph) -> f64 { ), n: (*graph).V, }; - (unsafe { DisjointSet::makeSet(&mut set) }); + (unsafe { DisjointSet::makeSet(&raw mut set) }); let mut total_weight: f64 = 0_f64; { let mut i: i32 = 0; @@ -364,10 +364,10 @@ pub unsafe fn MSTKruskal_2(graph: *mut Graph) -> f64 { .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Edge) .add((i as usize))) .weight; - if ((unsafe { DisjointSet::find(&mut set, x) }) - != (unsafe { DisjointSet::find(&mut set, y) })) + if ((unsafe { DisjointSet::find(&raw mut set, x) }) + != (unsafe { DisjointSet::find(&raw mut set, y) })) { - (unsafe { DisjointSet::merge(&mut set, x, y) }); + (unsafe { DisjointSet::merge(&raw mut set, x, y) }); total_weight += w; } } diff --git a/tests/unit/out/unsafe/lambda_as_field.rs b/tests/unit/out/unsafe/lambda_as_field.rs index 8e632c6980..9427def813 100644 --- a/tests/unit/out/unsafe/lambda_as_field.rs +++ b/tests/unit/out/unsafe/lambda_as_field.rs @@ -22,8 +22,8 @@ pub struct Guard__lambda_at_lambda_as_field_cpp_34_13__ { pub f: FnPtr, } impl DestructibleUnsafe for Guard__lambda_at_lambda_as_field_cpp_34_13__ { - unsafe fn destroy(&mut self) { - (unsafe { self.f.call() }); + unsafe fn destroy(this: *mut Self) { + (unsafe { (*this).f.call() }); } } #[repr(C)] @@ -34,8 +34,8 @@ pub struct Guard__lambda_at_lambda_as_field_cpp_45_13__ { pub f: FnPtr, } impl DestructibleUnsafe for Guard__lambda_at_lambda_as_field_cpp_45_13__ { - unsafe fn destroy(&mut self) { - (unsafe { self.f.call() }); + unsafe fn destroy(this: *mut Self) { + (unsafe { (*this).f.call() }); } } #[repr(C)] @@ -52,9 +52,9 @@ pub struct Holder__lambda_at_lambda_as_field_cpp_39_12__ { pub calls: i32, } impl Holder__lambda_at_lambda_as_field_cpp_39_12__ { - pub unsafe fn call(&mut self, mut x: i32) -> i32 { - self.calls.postfix_inc(); - return (unsafe { self.f.call(x) }); + pub unsafe fn call(this: *mut Self, mut x: i32) -> i32 { + (*this).calls.postfix_inc(); + return (unsafe { (*this).f.call(x) }); } } impl Default for Holder__lambda_at_lambda_as_field_cpp_39_12__ { @@ -86,9 +86,9 @@ pub struct Holder__lambda_at_lambda_as_field_cpp_51_12__ { pub calls: i32, } impl Holder__lambda_at_lambda_as_field_cpp_51_12__ { - pub unsafe fn call(&mut self, mut x: i32) -> i32 { - self.calls.postfix_inc(); - return (unsafe { self.f.call(x) }); + pub unsafe fn call(this: *mut Self, mut x: i32) -> i32 { + (*this).calls.postfix_inc(); + return (unsafe { (*this).f.call(x) }); } } #[repr(C)] @@ -99,15 +99,18 @@ pub struct Moving__lambda_at_lambda_as_field_cpp_64_12__ { pub moves: i32, } impl Moving__lambda_at_lambda_as_field_cpp_64_12__ { - pub unsafe fn construct(&mut self, mut f: FnPtr i32>) { - (&raw mut self.f).write(f.copy_from()); - (&raw mut self.moves).write(0); + pub unsafe fn construct(this: *mut Self, mut f: FnPtr i32>) { + (&raw mut (*this).f).write(f.copy_from()); + (&raw mut (*this).moves).write(0); } } impl MoveConstructibleUnsafe for Moving__lambda_at_lambda_as_field_cpp_64_12__ { - unsafe fn move_constructor(&mut self, o: *mut Moving__lambda_at_lambda_as_field_cpp_64_12__) { - (&raw mut self.f).write((*o).f.move_from()); - (&raw mut self.moves).write((((*o).moves) + (1))); + unsafe fn move_constructor( + this: *mut Self, + o: *mut Moving__lambda_at_lambda_as_field_cpp_64_12__, + ) { + (&raw mut (*this).f).write((*o).f.move_from()); + (&raw mut (*this).moves).write((((*o).moves) + (1))); } } impl Default for Moving__lambda_at_lambda_as_field_cpp_64_12__ { @@ -151,7 +154,7 @@ unsafe fn main_0() -> i32 { }), }; let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut count_2)) == (0))); } @@ -165,7 +168,9 @@ unsafe fn main_0() -> i32 { }), calls: 0, }; - assert!(((unsafe { Holder__lambda_at_lambda_as_field_cpp_39_12__::call(&mut n, 2,) }) == (3))); + assert!( + ((unsafe { Holder__lambda_at_lambda_as_field_cpp_39_12__::call(&raw mut n, 2,) }) == (3)) + ); assert!(((n.calls) == (1))); let mut cleaned: i32 = 0; { @@ -181,7 +186,7 @@ unsafe fn main_0() -> i32 { ), }; let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); assert!(((cleaned) == (0))); } @@ -200,8 +205,12 @@ unsafe fn main_0() -> i32 { calls: 0, }; factor = 100; - assert!(((unsafe { Holder__lambda_at_lambda_as_field_cpp_51_12__::call(&mut h, 2,) }) == (6))); - assert!(((unsafe { Holder__lambda_at_lambda_as_field_cpp_51_12__::call(&mut h, 5,) }) == (15))); + assert!( + ((unsafe { Holder__lambda_at_lambda_as_field_cpp_51_12__::call(&raw mut h, 2,) }) == (6)) + ); + assert!( + ((unsafe { Holder__lambda_at_lambda_as_field_cpp_51_12__::call(&raw mut h, 5,) }) == (15)) + ); assert!(((h.calls) == (2))); let mut w: FnPtr i32> = (unsafe { wrap_0(lambda_unsafe!( diff --git a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs index 494c57f796..9fdb98268b 100644 --- a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs @@ -13,21 +13,21 @@ pub struct Counted { pub moves: i32, } impl DefaultConstructibleUnsafe for Counted { - unsafe fn default_constructor(&mut self) { - (&raw mut self.copies).write(0); - (&raw mut self.moves).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).copies).write(0); + (&raw mut (*this).moves).write(0); } } impl CopyConstructibleUnsafe for Counted { - unsafe fn copy_constructor(&mut self, o: *const Counted) { - (&raw mut self.copies).write((((*o).copies) + (1))); - (&raw mut self.moves).write((*o).moves); + unsafe fn copy_constructor(this: *mut Self, o: *const Counted) { + (&raw mut (*this).copies).write((((*o).copies) + (1))); + (&raw mut (*this).moves).write((*o).moves); } } impl MoveConstructibleUnsafe for Counted { - unsafe fn move_constructor(&mut self, o: *mut Counted) { - (&raw mut self.copies).write((*o).copies); - (&raw mut self.moves).write((((*o).moves) + (1))); + unsafe fn move_constructor(this: *mut Self, o: *mut Counted) { + (&raw mut (*this).copies).write((*o).copies); + (&raw mut (*this).moves).write((((*o).moves) + (1))); } } impl Default for Counted { @@ -35,7 +35,7 @@ impl Default for Counted { unsafe { { let mut __v: Counted = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -46,16 +46,16 @@ pub static mut drops_0: std::cell::LazyCell = std::cell::LazyCell::new(|| u #[derive(FnPtrArg, ZeroInitializationUnsafe)] pub struct Dropped {} impl DefaultConstructibleUnsafe for Dropped { - unsafe fn default_constructor(&mut self) {} + unsafe fn default_constructor(this: *mut Self) {} } impl CopyConstructibleUnsafe for Dropped { - unsafe fn copy_constructor(&mut self, _a0: *const Dropped) {} + unsafe fn copy_constructor(this: *mut Self, _a0: *const Dropped) {} } impl MoveConstructibleUnsafe for Dropped { - unsafe fn move_constructor(&mut self, _a0: *mut Dropped) {} + unsafe fn move_constructor(this: *mut Self, _a0: *mut Dropped) {} } impl DestructibleUnsafe for Dropped { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut drops_0)).postfix_inc(); } } @@ -71,7 +71,7 @@ unsafe fn main_0() -> i32 { { let c: Counted = { let mut __v: Counted = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, &c); + ConstructFromUnsafe::construct_from(&raw mut __v, &c); __v }; }, @@ -93,16 +93,16 @@ unsafe fn main_0() -> i32 { { let c: Counted = { let mut __v: Counted = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, &c); + ConstructFromUnsafe::construct_from(&raw mut __v, &c); __v }; }, |__return: *mut Counted| { - ConstructFromUnsafe::construct_from(&mut *__return, &c); + ConstructFromUnsafe::construct_from(__return, &c); return; } ) - .call(&mut __tmp_0) + .call(&raw mut __tmp_0) }); &mut __tmp_0 }) @@ -111,14 +111,14 @@ unsafe fn main_0() -> i32 { assert!(((returned) == (2))); let mut arr: [Counted; 2] = std::array::from_fn::<_, 2, _>(|_| { let mut __v: Counted = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }); let mut a: FnPtr i32> = lambda_unsafe!( { let arr: [Counted; 2] = std::array::from_fn::<_, 2, _>(|__i: usize| { let mut __v: Counted = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, &arr[(__i)]); + ConstructFromUnsafe::construct_from(&raw mut __v, &arr[(__i)]); __v }); }, @@ -136,18 +136,18 @@ unsafe fn main_0() -> i32 { { let d: Dropped = { let mut __v: Dropped = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; }, || {} ); let _dtor_m = std::mem::DropGuard::new(&raw mut m, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); let mut m2: FnPtr = m.move_from(); let _dtor_m2 = std::mem::DropGuard::new(&raw mut m2, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut drops_0)) == (2))); @@ -156,18 +156,18 @@ unsafe fn main_0() -> i32 { { let d: Dropped = { let mut __v: Dropped = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; }, || {} ); let _dtor_k = std::mem::DropGuard::new(&raw mut k, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); let mut k2: FnPtr = k.copy_from(); let _dtor_k2 = std::mem::DropGuard::new(&raw mut k2, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut drops_0)) == (4))); @@ -176,14 +176,14 @@ unsafe fn main_0() -> i32 { { let d: Dropped = { let mut __v: Dropped = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; }, || {} ); let _dtor_inner = std::mem::DropGuard::new(&raw mut inner, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); let mut outer: FnPtr = lambda_unsafe!( { @@ -192,7 +192,7 @@ unsafe fn main_0() -> i32 { || {} ); let _dtor_outer = std::mem::DropGuard::new(&raw mut outer, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut drops_0)) == (6))); diff --git a/tests/unit/out/unsafe/lambda_capture_star_this.rs b/tests/unit/out/unsafe/lambda_capture_star_this.rs index da181b4648..90c2955b37 100644 --- a/tests/unit/out/unsafe/lambda_capture_star_this.rs +++ b/tests/unit/out/unsafe/lambda_capture_star_this.rs @@ -21,13 +21,13 @@ pub struct S { pub n: i32, } impl S { - pub unsafe fn twice(&self) -> i32 { - return ((self.n) * (2)); + pub unsafe fn twice(this: *const Self) -> i32 { + return (((*this).n) * (2)); } - pub unsafe fn modify_copy(&mut self) -> i32 { + pub unsafe fn modify_copy(this: *mut Self) -> i32 { let mut f: FnPtr i32> = lambda_unsafe!( { - let this_: S = (*(self as *mut S)); + let this_: S = (*this); }, || -> i32 { (*(&raw mut this_)).n += 10; @@ -35,31 +35,31 @@ impl S { } ); let mut r: i32 = (unsafe { f.call() }); - return (((r) * (100)) + (self.n)); + return (((r) * (100)) + ((*this).n)); } - pub unsafe fn snapshot(&mut self) -> i32 { + pub unsafe fn snapshot(this: *mut Self) -> i32 { let mut f: FnPtr i32> = lambda_unsafe!( { - let this_: S = (*(self as *mut S)); + let this_: S = (*this); }, || -> i32 { - return (unsafe { S::twice(&(*(&raw mut this_))) }); + return (unsafe { S::twice(&raw const (*(&raw mut this_))) }); } ); - self.n = 99; + (*this).n = 99; return (unsafe { f.call() }); } - pub unsafe fn mixed(&mut self, mut k: i32) -> i32 { + pub unsafe fn mixed(this: *mut Self, mut k: i32) -> i32 { let mut f: FnPtr i32> = lambda_unsafe!( { - let this_: S = (*(self as *mut S)); + let this_: S = (*this); let k: i32 = k; }, || -> i32 { return (((*(&raw mut this_)).n) + (k)); } ); - self.n = 0; + (*this).n = 0; return (unsafe { f.call() }); } } @@ -71,11 +71,11 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut s: S = S { n: 1 }; - assert!(((unsafe { S::modify_copy(&mut s,) }) == (1101))); + assert!(((unsafe { S::modify_copy(&raw mut s,) }) == (1101))); assert!(((s.n) == (1))); - assert!(((unsafe { S::snapshot(&mut s,) }) == (2))); + assert!(((unsafe { S::snapshot(&raw mut s,) }) == (2))); assert!(((s.n) == (99))); - assert!(((unsafe { S::mixed(&mut s, 1,) }) == (100))); + assert!(((unsafe { S::mixed(&raw mut s, 1,) }) == (100))); assert!(((s.n) == (0))); return 0; } diff --git a/tests/unit/out/unsafe/lambda_capture_this.rs b/tests/unit/out/unsafe/lambda_capture_this.rs index 77bec8611a..f055abe092 100644 --- a/tests/unit/out/unsafe/lambda_capture_this.rs +++ b/tests/unit/out/unsafe/lambda_capture_this.rs @@ -22,16 +22,16 @@ pub struct S { pub step: i32, } impl S { - pub unsafe fn add(&mut self, mut k: i32) { - self.n += k; + pub unsafe fn add(this: *mut Self, mut k: i32) { + (*this).n += k; } - pub unsafe fn scaled(&self) -> i32 { - return ((self.n) * (self.step)); + pub unsafe fn scaled(this: *const Self) -> i32 { + return (((*this).n) * ((*this).step)); } - pub unsafe fn bump(&mut self, mut by: i32) { + pub unsafe fn bump(this: *mut Self, mut by: i32) { let mut inc: FnPtr = lambda_unsafe!( { - let this_: *mut S = (self as *mut S); + let this_: *mut S = this; }, |mut k: i32| { (*this_).n += k; @@ -40,24 +40,24 @@ impl S { (unsafe { inc.call(by) }); (unsafe { inc.call(by) }); } - pub unsafe fn bump_via_method(&mut self, mut by: i32) { + pub unsafe fn bump_via_method(this: *mut Self, mut by: i32) { let mut inc: FnPtr = lambda_unsafe!( { - let this_: *mut S = (self as *mut S); + let this_: *mut S = this; }, |mut k: i32| { - (unsafe { S::add(&mut (*this_), k) }); + (unsafe { S::add(&raw mut (*this_), k) }); } ); (unsafe { inc.call(by) }); } - pub unsafe fn read_scaled(&self) -> i32 { + pub unsafe fn read_scaled(this: *const Self) -> i32 { let mut get: FnPtr i32> = lambda_unsafe!( { - let this_: *const S = (self as *const S); + let this_: *const S = this; }, || -> i32 { - return (unsafe { S::scaled(&(*this_)) }); + return (unsafe { S::scaled(&raw const (*this_)) }); } ); return (unsafe { get.call() }); @@ -71,11 +71,11 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut s: S = S { n: 0, step: 2 }; - (unsafe { S::bump(&mut s, 3) }); + (unsafe { S::bump(&raw mut s, 3) }); assert!(((s.n) == (6))); - (unsafe { S::bump_via_method(&mut s, 4) }); + (unsafe { S::bump_via_method(&raw mut s, 4) }); assert!(((s.n) == (10))); - assert!(((unsafe { S::read_scaled(&s,) }) == (20))); + assert!(((unsafe { S::read_scaled(&raw const s,) }) == (20))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/lambda_decltype_type.rs b/tests/unit/out/unsafe/lambda_decltype_type.rs index 9363c82547..08727a0734 100644 --- a/tests/unit/out/unsafe/lambda_decltype_type.rs +++ b/tests/unit/out/unsafe/lambda_decltype_type.rs @@ -14,26 +14,26 @@ pub struct Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { pub cmp: FnPtr bool>, } impl Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { - pub unsafe fn insert(&mut self, mut v: i32) { - let mut i: i32 = self.size; + pub unsafe fn insert(this: *mut Self, mut v: i32) { + let mut i: i32 = (*this).size; 'loop_: while ((i) > (0)) && (unsafe { - let _b: i32 = self.items[((i) - (1)) as usize]; - self.cmp.call(v, _b) + let _b: i32 = (*this).items[((i) - (1)) as usize]; + (*this).cmp.call(v, _b) }) { - self.items[(i) as usize] = self.items[((i) - (1)) as usize]; + (*this).items[(i) as usize] = (*this).items[((i) - (1)) as usize]; i.postfix_dec(); } - self.items[(i) as usize] = v; - self.size.postfix_inc(); + (*this).items[(i) as usize] = v; + (*this).size.postfix_inc(); } } impl DefaultConstructibleUnsafe for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { - unsafe fn default_constructor(&mut self) { - (&raw mut self.items).write([0_i32; 4]); - (&raw mut self.size).write(0); - (&raw mut self.cmp).write(FnPtr:: bool>::new( + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).items).write([0_i32; 4]); + (&raw mut (*this).size).write(0); + (&raw mut (*this).cmp).write(FnPtr:: bool>::new( |mut a: i32, mut b: i32| -> bool { unsafe { return ((a) > (b)); @@ -65,26 +65,26 @@ pub struct Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { pub cmp: FnPtr bool>, } impl Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { - pub unsafe fn insert(&mut self, mut v: i32) { - let mut i: i32 = self.size; + pub unsafe fn insert(this: *mut Self, mut v: i32) { + let mut i: i32 = (*this).size; 'loop_: while ((i) > (0)) && (unsafe { - let _b: i32 = self.items[((i) - (1)) as usize]; - self.cmp.call(v, _b) + let _b: i32 = (*this).items[((i) - (1)) as usize]; + (*this).cmp.call(v, _b) }) { - self.items[(i) as usize] = self.items[((i) - (1)) as usize]; + (*this).items[(i) as usize] = (*this).items[((i) - (1)) as usize]; i.postfix_dec(); } - self.items[(i) as usize] = v; - self.size.postfix_inc(); + (*this).items[(i) as usize] = v; + (*this).size.postfix_inc(); } } impl DefaultConstructibleUnsafe for Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { - unsafe fn default_constructor(&mut self) { - (&raw mut self.items).write([0_i32; 4]); - (&raw mut self.size).write(0); - (&raw mut self.cmp).write(FnPtr:: bool>::new( + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).items).write([0_i32; 4]); + (&raw mut (*this).size).write(0); + (&raw mut (*this).cmp).write(FnPtr:: bool>::new( |mut a: i32, mut b: i32| -> bool { unsafe { return ((a) < (b)); @@ -122,16 +122,16 @@ unsafe fn main_0() -> i32 { } }); object_unsafe!(desc, Sorted__lambda_at_lambda_decltype_type_cpp_22_18__); - (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&mut desc, 2) }); - (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&mut desc, 7) }); - (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&mut desc, 4) }); + (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&raw mut desc, 2) }); + (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&raw mut desc, 7) }); + (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_22_18__::insert(&raw mut desc, 4) }); assert!(((desc.items[(0) as usize]) == (7))); assert!(((desc.items[(1) as usize]) == (4))); assert!(((desc.items[(2) as usize]) == (2))); object_unsafe!(asc, Sorted__lambda_at_lambda_decltype_type_cpp_19_23__); - (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&mut asc, 2) }); - (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&mut asc, 7) }); - (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&mut asc, 4) }); + (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&raw mut asc, 2) }); + (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&raw mut asc, 7) }); + (unsafe { Sorted__lambda_at_lambda_decltype_type_cpp_19_23__::insert(&raw mut asc, 4) }); assert!(((asc.items[(0) as usize]) == (2))); assert!(((asc.items[(1) as usize]) == (4))); assert!(((asc.items[(2) as usize]) == (7))); diff --git a/tests/unit/out/unsafe/lambda_immediate_init.rs b/tests/unit/out/unsafe/lambda_immediate_init.rs index ed176294c7..cd9d7a8e24 100644 --- a/tests/unit/out/unsafe/lambda_immediate_init.rs +++ b/tests/unit/out/unsafe/lambda_immediate_init.rs @@ -16,9 +16,9 @@ pub struct S { pub k: i32, } impl DefaultConstructibleUnsafe for S { - unsafe fn default_constructor(&mut self) { - (&raw mut self.j).write(10); - (&raw mut self.k).write( + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).j).write(10); + (&raw mut (*this).k).write( ((unsafe { FnPtr:: i32>::new(|| -> i32 { unsafe { diff --git a/tests/unit/out/unsafe/lambda_move_only_capture.rs b/tests/unit/out/unsafe/lambda_move_only_capture.rs index e722c7be24..1c66791fba 100644 --- a/tests/unit/out/unsafe/lambda_move_only_capture.rs +++ b/tests/unit/out/unsafe/lambda_move_only_capture.rs @@ -13,18 +13,15 @@ pub struct Owner { pub p: *mut i32, } impl Owner { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.p).write((Box::leak(Box::new(v)) as *mut i32)); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).p).write((Box::leak(Box::new(v)) as *mut i32)); } - pub unsafe fn take(&mut self) -> FnPtr i32> { + pub unsafe fn take(this: *mut Self) -> FnPtr i32> { return lambda_unsafe!( { let self_: Owner = { let mut __v: Owner = ::zero_init(); - ConstructFromUnsafe::construct_from( - &mut __v, - Moved(&mut (*(self as *mut Owner))), - ); + ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut (*this))); __v }; }, @@ -35,15 +32,15 @@ impl Owner { } } impl MoveConstructibleUnsafe for Owner { - unsafe fn move_constructor(&mut self, o: *mut Owner) { - (&raw mut self.p).write((*o).p); + unsafe fn move_constructor(this: *mut Self, o: *mut Owner) { + (&raw mut (*this).p).write((*o).p); (*o).p = std::ptr::null_mut(); } } impl DestructibleUnsafe for Owner { - unsafe fn destroy(&mut self) { + unsafe fn destroy(this: *mut Self) { { - let __p = self.p; + let __p = (*this).p; if !__p.is_null() { ::std::mem::drop(Box::from_raw(__p)) } @@ -62,7 +59,7 @@ unsafe fn main_0() -> i32 { { let h: Owner = { let mut __v: Owner = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(&mut o)); + ConstructFromUnsafe::construct_from(&raw mut __v, Moved(&mut o)); __v }; }, @@ -71,13 +68,13 @@ unsafe fn main_0() -> i32 { } ); let _dtor_f = std::mem::DropGuard::new(&raw mut f, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); assert!((o.p).is_null()); assert!(((unsafe { f.call() }) == (5))); let mut g: FnPtr i32> = f.move_from(); let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); assert!(((unsafe { g.call() }) == (5))); let mut total: i32 = 0; @@ -85,7 +82,7 @@ unsafe fn main_0() -> i32 { { let h: Owner = { let mut __v: Owner = ::zero_init(); - Owner::construct(&mut __v, 7); + Owner::construct(&raw mut __v, 7); __v }; let total: *mut i32 = &mut total; @@ -96,15 +93,15 @@ unsafe fn main_0() -> i32 { } ); let _dtor_consume = std::mem::DropGuard::new(&raw mut consume, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); (unsafe { consume.call() }); (unsafe { consume.call() }); assert!(((total) == (7))); object_unsafe!(o2, Owner(9)); - let mut t: FnPtr i32> = (unsafe { Owner::take(&mut o2) }); + let mut t: FnPtr i32> = (unsafe { Owner::take(&raw mut o2) }); let _dtor_t = std::mem::DropGuard::new(&raw mut t, |__p| unsafe { - DestructibleUnsafe::destroy(&mut *__p) + DestructibleUnsafe::destroy(__p) }); assert!((o2.p).is_null()); assert!(((unsafe { t.call() }) == (9))); diff --git a/tests/unit/out/unsafe/lambda_nested.rs b/tests/unit/out/unsafe/lambda_nested.rs index 9617322fc0..57e99f3436 100644 --- a/tests/unit/out/unsafe/lambda_nested.rs +++ b/tests/unit/out/unsafe/lambda_nested.rs @@ -21,10 +21,10 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn nested_this(&mut self) -> i32 { + pub unsafe fn nested_this(this: *mut Self) -> i32 { let mut outer: FnPtr i32> = lambda_unsafe!( { - let this_: *mut S = (self as *mut S); + let this_: *mut S = this; }, |mut y: i32| -> i32 { let mut inner: FnPtr i32> = lambda_unsafe!( @@ -71,7 +71,7 @@ unsafe fn main_0() -> i32 { x = 100; assert!(((unsafe { outer.call(20,) }) == (121))); let mut s: S = S { v: 5 }; - assert!(((unsafe { S::nested_this(&mut s,) }) == (26))); + assert!(((unsafe { S::nested_this(&raw mut s,) }) == (26))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/libc_struct_without_default.rs b/tests/unit/out/unsafe/libc_struct_without_default.rs index 9c72ff7f29..b5d7cfed8e 100644 --- a/tests/unit/out/unsafe/libc_struct_without_default.rs +++ b/tests/unit/out/unsafe/libc_struct_without_default.rs @@ -23,9 +23,9 @@ pub struct UserDefined { pub v: Vec, } impl DefaultConstructibleUnsafe for UserDefined { - unsafe fn default_constructor(&mut self) { - (&raw mut self.a).write(std::array::from_fn::<_, 1, _>(|_| 0_i32)); - (&raw mut self.v).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).a).write(std::array::from_fn::<_, 1, _>(|_| 0_i32)); + (&raw mut (*this).v).write(Vec::new()); } } impl Default for UserDefined { diff --git a/tests/unit/out/unsafe/linked_list.rs b/tests/unit/out/unsafe/linked_list.rs index 6cf73c6397..3101cc9ed8 100644 --- a/tests/unit/out/unsafe/linked_list.rs +++ b/tests/unit/out/unsafe/linked_list.rs @@ -22,8 +22,8 @@ pub struct Node { pub next: *mut Node, } impl Node { - pub unsafe fn SetNext(&mut self, mut next: *mut Node) { - self.next = next; + pub unsafe fn SetNext(this: *mut Self, mut next: *mut Node) { + (*this).next = next; } } pub unsafe fn Find_0(mut head: *mut Node, mut idx: i32) -> *mut Node { @@ -44,7 +44,7 @@ pub unsafe fn Append_1(head: *mut Node, new_node: *mut Node) { 'loop_: while !(((*curr).next).is_null()) { curr = (*curr).next; } - (unsafe { Node::SetNext(&mut (*curr), (new_node)) }); + (unsafe { Node::SetNext(&raw mut (*curr), (new_node)) }); } pub unsafe fn Delete_2(mut head: *mut Node, mut val: i32) -> *mut Node { let mut curr: *mut Node = head; diff --git a/tests/unit/out/unsafe/map.rs b/tests/unit/out/unsafe/map.rs index ef4c06e1b6..b1c75afbca 100644 --- a/tests/unit/out/unsafe/map.rs +++ b/tests/unit/out/unsafe/map.rs @@ -22,15 +22,15 @@ pub struct Point { pub y: i32, } impl Point { - pub unsafe fn construct_1(&mut self, mut x: i32, mut y: i32) { - (&raw mut self.x).write(x); - (&raw mut self.y).write(y); + pub unsafe fn construct_1(this: *mut Self, mut x: i32, mut y: i32) { + (&raw mut (*this).x).write(x); + (&raw mut (*this).y).write(y); } } impl DefaultConstructibleUnsafe for Point { - unsafe fn default_constructor(&mut self) { - (&raw mut self.x).write(0); - (&raw mut self.y).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).x).write(0); + (&raw mut (*this).y).write(0); } } impl Default for Point { @@ -38,7 +38,7 @@ impl Default for Point { unsafe { { let mut __v: Point = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -447,7 +447,7 @@ unsafe fn main_0() -> i32 { let mut point_new: (UnsafeBidirectionalIterator<(i32, Point)>, bool) = points.try_emplace(key1, || { let mut __v: Point = ::zero_init(); - Point::construct_1(&mut __v, 3, 4); + Point::construct_1(&raw mut __v, 3, 4); __v }); assert!(((point_new.1) as bool)); @@ -481,7 +481,7 @@ unsafe fn main_0() -> i32 { }; points.emplace((key8, { let mut __v: Point = ::zero_init(); - Point::construct_1(&mut __v, 5, 6); + Point::construct_1(&raw mut __v, 5, 6); __v })); { diff --git a/tests/unit/out/unsafe/map_key_copy_ctor.rs b/tests/unit/out/unsafe/map_key_copy_ctor.rs index 1829ba8812..3db77d5c8f 100644 --- a/tests/unit/out/unsafe/map_key_copy_ctor.rs +++ b/tests/unit/out/unsafe/map_key_copy_ctor.rs @@ -18,22 +18,22 @@ pub struct Key { pub k: i32, } impl Key { - pub unsafe fn construct(&mut self, mut k: i32) { - (&raw mut self.k).write(k); + pub unsafe fn construct(this: *mut Self, mut k: i32) { + (&raw mut (*this).k).write(k); } - pub unsafe fn operator_lt(&self, o: *const Key) -> bool { - return ((self.k) < ((*o).k)); + pub unsafe fn operator_lt(this: *const Self, o: *const Key) -> bool { + return (((*this).k) < ((*o).k)); } } impl CopyConstructibleUnsafe for Key { - unsafe fn copy_constructor(&mut self, o: *const Key) { - (&raw mut self.k).write((*o).k); + unsafe fn copy_constructor(this: *mut Self, o: *const Key) { + (&raw mut (*this).k).write((*o).k); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)).prefix_inc(); } } impl MoveConstructibleUnsafe for Key { - unsafe fn move_constructor(&mut self, o: *mut Key) { - (&raw mut self.k).write((*o).k); + unsafe fn move_constructor(this: *mut Self, o: *mut Key) { + (&raw mut (*this).k).write((*o).k); (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_1)).prefix_inc(); } } @@ -66,7 +66,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(); - Key::construct(&mut *__return, k); + Key::construct(__return, k); return; } pub fn main() { @@ -101,7 +101,7 @@ unsafe fn main_0() -> i32 { { let mut __tmp_1: Key = ::zero_init(); (*match (({ - (unsafe { make_key_3(&mut __tmp_1, 4) }); + (unsafe { make_key_3(&raw mut __tmp_1, 4) }); &mut __tmp_1 } as *mut Key),) { @@ -111,7 +111,7 @@ unsafe fn main_0() -> i32 { { let mut __tmp_3: Key = ::zero_init(); (*match (({ - (unsafe { make_key_3(&mut __tmp_3, 4) }); + (unsafe { make_key_3(&raw mut __tmp_3, 4) }); &mut __tmp_3 } as *mut Key),) { @@ -141,7 +141,7 @@ unsafe fn main_0() -> i32 { { let mut __tmp_5: Key = ::zero_init(); (*match (({ - Key::construct(&mut __tmp_5, 0); + Key::construct(&raw mut __tmp_5, 0); &mut __tmp_5 } as *mut Key),) { diff --git a/tests/unit/out/unsafe/map_key_identity.rs b/tests/unit/out/unsafe/map_key_identity.rs index d7f3b4279f..62f5ce6810 100644 --- a/tests/unit/out/unsafe/map_key_identity.rs +++ b/tests/unit/out/unsafe/map_key_identity.rs @@ -59,8 +59,8 @@ pub struct Mapped { pub value: i32, } impl DefaultConstructibleUnsafe for Mapped { - unsafe fn default_constructor(&mut self) { - (&raw mut self.value).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).value).write(0); (*std::cell::LazyCell::force_mut(&mut *&raw mut default_constructions_0)).prefix_inc(); } } @@ -69,7 +69,7 @@ impl Default for Mapped { unsafe { { let mut __v: Mapped = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } diff --git a/tests/unit/out/unsafe/map_try_emplace.rs b/tests/unit/out/unsafe/map_try_emplace.rs index aa77d462f1..50b537fdfa 100644 --- a/tests/unit/out/unsafe/map_try_emplace.rs +++ b/tests/unit/out/unsafe/map_try_emplace.rs @@ -17,25 +17,25 @@ pub struct Item { pub value: i32, } impl Item { - pub unsafe fn construct_1(&mut self, mut value: i32) { - (&raw mut self.value).write(value); + pub unsafe fn construct_1(this: *mut Self, mut value: i32) { + (&raw mut (*this).value).write(value); (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)).prefix_inc(); } } impl DefaultConstructibleUnsafe for Item { - unsafe fn default_constructor(&mut self) { - (&raw mut self.value).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).value).write(0); } } impl CopyConstructibleUnsafe for Item { - unsafe fn copy_constructor(&mut self, other: *const Item) { - (&raw mut self.value).write((*other).value); + unsafe fn copy_constructor(this: *mut Self, other: *const Item) { + (&raw mut (*this).value).write((*other).value); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_2)).prefix_inc(); } } impl MoveConstructibleUnsafe for Item { - unsafe fn move_constructor(&mut self, other: *mut Item) { - (&raw mut self.value).write((*other).value); + unsafe fn move_constructor(this: *mut Self, other: *mut Item) { + (&raw mut (*this).value).write((*other).value); (*std::cell::LazyCell::force_mut(&mut *&raw mut moves_3)).prefix_inc(); (*other).value = -1_i32; } @@ -45,7 +45,7 @@ impl Default for Item { unsafe { { let mut __v: Item = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -61,8 +61,8 @@ pub struct RefItem { pub value: i32, } impl RefItem { - pub unsafe fn construct_1(&mut self, counter: *mut i32, mut amount: i32) { - (&raw mut self.value).write({ + pub unsafe fn construct_1(this: *mut Self, counter: *mut i32, mut amount: i32) { + (&raw mut (*this).value).write({ (*counter) += amount; (*counter) }); @@ -70,8 +70,8 @@ impl RefItem { } } impl DefaultConstructibleUnsafe for RefItem { - unsafe fn default_constructor(&mut self) { - (&raw mut self.value).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).value).write(0); } } impl Default for RefItem { @@ -79,7 +79,7 @@ impl Default for RefItem { unsafe { { let mut __v: RefItem = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -251,7 +251,7 @@ unsafe fn main_0() -> i32 { let mut key: i32 = 0; items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, 10); + Item::construct_1(&raw mut __v, 10); __v }); object_unsafe!(source, Item::construct_1(20)); @@ -266,7 +266,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { argument_4(&mut source) }) as *mut Item),) { (__tmp_6,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, __tmp_6); + ConstructFromUnsafe::construct_from(&raw mut __v, __tmp_6); __v }), }; @@ -282,7 +282,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { argument_4(&mut source) }) as *mut Item),) { (__tmp_7,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(__tmp_7)); + ConstructFromUnsafe::construct_from(&raw mut __v, Moved(__tmp_7)); __v }), }; @@ -299,7 +299,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { argument_4(&mut source) }) as *mut Item),) { (__tmp_8,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, __tmp_8); + ConstructFromUnsafe::construct_from(&raw mut __v, __tmp_8); __v }), }; @@ -316,7 +316,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { argument_4(&mut source) }) as *mut Item),) { (__tmp_9,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(__tmp_9)); + ConstructFromUnsafe::construct_from(&raw mut __v, Moved(__tmp_9)); __v }), }; @@ -336,7 +336,7 @@ unsafe fn main_0() -> i32 { let mut counter: i32 = 0; refs.try_emplace(key, || { let mut __v: RefItem = ::zero_init(); - RefItem::construct_1(&mut __v, &mut counter, 5); + RefItem::construct_1(&raw mut __v, &mut counter, 5); __v }); (*std::cell::LazyCell::force_mut(&mut *&raw mut made_1)) = 0; @@ -344,7 +344,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { reference_5(&mut counter) }) as *mut i32),) { (__tmp_10,) => refs.try_emplace(key, || { let mut __v: RefItem = ::zero_init(); - RefItem::construct_1(&mut __v, __tmp_10, 2); + RefItem::construct_1(&raw mut __v, __tmp_10, 2); __v }), }; @@ -359,7 +359,7 @@ unsafe fn main_0() -> i32 { match (((unsafe { reference_5(&mut counter) }) as *mut i32),) { (__tmp_11,) => refs.try_emplace(key, || { let mut __v: RefItem = ::zero_init(); - RefItem::construct_1(&mut __v, __tmp_11, 2); + RefItem::construct_1(&raw mut __v, __tmp_11, 2); __v }), }; @@ -384,13 +384,13 @@ unsafe fn main_0() -> i32 { let mut temporary_hit: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = { let mut __tmp_13: Item = ::zero_init(); match (({ - Item::construct_1(&mut __tmp_13, 30); + Item::construct_1(&raw mut __tmp_13, 30); &mut __tmp_13 } as *mut Item),) { (__tmp_12,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(__tmp_12)); + ConstructFromUnsafe::construct_from(&raw mut __v, Moved(__tmp_12)); __v }), } @@ -407,13 +407,13 @@ unsafe fn main_0() -> i32 { let mut temporary_new: (UnsafeBidirectionalIterator<(i32, Item)>, bool) = { let mut __tmp_15: Item = ::zero_init(); match (({ - Item::construct_1(&mut __tmp_15, 40); + Item::construct_1(&raw mut __tmp_15, 40); &mut __tmp_15 } as *mut Item),) { (__tmp_14,) => items.try_emplace(key, || { let mut __v: Item = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut __v, Moved(__tmp_14)); + ConstructFromUnsafe::construct_from(&raw mut __v, Moved(__tmp_14)); __v }), } diff --git a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs index 1c48fa5c3d..4fb0165186 100644 --- a/tests/unit/out/unsafe/map_try_emplace_lvalues.rs +++ b/tests/unit/out/unsafe/map_try_emplace_lvalues.rs @@ -14,8 +14,8 @@ pub struct Item { pub value: i32, } impl Item { - pub unsafe fn construct_1(&mut self, counter: *mut i32, mut amount: i32) { - (&raw mut self.value).write({ + pub unsafe fn construct_1(this: *mut Self, counter: *mut i32, mut amount: i32) { + (&raw mut (*this).value).write({ (*counter) += amount; (*counter) }); @@ -23,8 +23,8 @@ impl Item { } } impl DefaultConstructibleUnsafe for Item { - unsafe fn default_constructor(&mut self) { - (&raw mut self.value).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).value).write(0); } } impl Default for Item { @@ -32,7 +32,7 @@ impl Default for Item { unsafe { { let mut __v: Item = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -55,9 +55,9 @@ pub struct Temporary { pub data: [i32; 2], } impl DefaultConstructibleUnsafe for Temporary { - unsafe fn default_constructor(&mut self) { - (&raw mut self.n).write(5); - (&raw mut self.data).write([6, 7]); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).n).write(5); + (&raw mut (*this).data).write([6, 7]); (*std::cell::LazyCell::force_mut(&mut *&raw mut temporary_calls_4)).prefix_inc(); } } @@ -66,7 +66,7 @@ impl Default for Temporary { unsafe { { let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -80,21 +80,21 @@ pub struct Nested { pub inner: Temporary, } impl DefaultConstructibleUnsafe for Nested { - unsafe fn default_constructor(&mut self) { - DefaultConstructibleUnsafe::default_constructor(&mut self.inner); + unsafe fn default_constructor(this: *mut Self) { + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).inner); } } pub unsafe fn make_temporary_5() -> Temporary { return { let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; } pub unsafe fn make_nested_6() -> Nested { return { let mut __v: Nested = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }; } @@ -107,18 +107,18 @@ pub struct Owner { pub ptr: Option>, } impl Owner { - pub unsafe fn value(&mut self) -> *const i32 { - return &(*self.ptr.as_deref().map_or(::std::ptr::null_mut(), |v| { + pub unsafe fn value(this: *mut Self) -> *const i32 { + return &(*(*this).ptr.as_deref().map_or(::std::ptr::null_mut(), |v| { v as *const Temporary as *mut Temporary })) .n; } } impl DefaultConstructibleUnsafe for Owner { - unsafe fn default_constructor(&mut self) { - (&raw mut self.ptr).write(Some(Box::new({ + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).ptr).write(Some(Box::new({ let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }))); } @@ -128,7 +128,7 @@ impl Default for Owner { unsafe { { let mut __v: Owner = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -140,8 +140,8 @@ pub struct Noncopy { pub n: i32, } impl DefaultConstructibleUnsafe for Noncopy { - unsafe fn default_constructor(&mut self) { - (&raw mut self.n).write(5); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).n).write(5); } } impl Default for Noncopy { @@ -158,16 +158,16 @@ pub struct Held { pub ptr: *const i32, } impl Held { - pub unsafe fn construct_1(&mut self, n: *const i32) { - (&raw mut self.ptr).write((n)); + pub unsafe fn construct_1(this: *mut Self, n: *const i32) { + (&raw mut (*this).ptr).write((n)); } - pub unsafe fn construct_2(&mut self, n: *const [i32; 2], mut _a1: i32) { - (&raw mut self.ptr).write((*n).as_ptr()); + pub unsafe fn construct_2(this: *mut Self, n: *const [i32; 2], mut _a1: i32) { + (&raw mut (*this).ptr).write((*n).as_ptr()); } } impl DefaultConstructibleUnsafe for Held { - unsafe fn default_constructor(&mut self) { - (&raw mut self.ptr).write(std::ptr::null()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).ptr).write(std::ptr::null()); } } impl Default for Held { @@ -175,7 +175,7 @@ impl Default for Held { unsafe { { let mut __v: Held = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -246,7 +246,7 @@ pub static mut global_owned_16: std::cell::LazyCell<( match ((&mut (*(*{ __tmp_6 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v })); &mut __tmp_6 @@ -300,7 +300,7 @@ unsafe fn main_0() -> i32 { let mut counter: i32 = 0; m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, &mut counter, 3); + Item::construct_1(&raw mut __v, &mut counter, 3); __v }); (*std::cell::LazyCell::force_mut(&mut *&raw mut made_0)) = 0; @@ -314,7 +314,7 @@ unsafe fn main_0() -> i32 { ) { (__tmp_7, __tmp_8) => (*__tmp_7).try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_8, 2); + Item::construct_1(&raw mut __v, __tmp_8, 2); __v }), }; @@ -332,7 +332,7 @@ unsafe fn main_0() -> i32 { { (__tmp_10,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_10, 2); + Item::construct_1(&raw mut __v, __tmp_10, 2); __v }), }; @@ -350,7 +350,7 @@ unsafe fn main_0() -> i32 { { (__tmp_12,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_12, 2); + Item::construct_1(&raw mut __v, __tmp_12, 2); __v }), }; @@ -369,7 +369,7 @@ unsafe fn main_0() -> i32 { { (__tmp_15,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_15, 2); + Item::construct_1(&raw mut __v, __tmp_15, 2); __v }), }; @@ -392,7 +392,7 @@ unsafe fn main_0() -> i32 { { (__tmp_18,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_18, 3); + Item::construct_1(&raw mut __v, __tmp_18, 3); __v }), }; @@ -413,7 +413,7 @@ unsafe fn main_0() -> i32 { { (__tmp_20,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_20, 3); + Item::construct_1(&raw mut __v, __tmp_20, 3); __v }), }; @@ -430,7 +430,7 @@ unsafe fn main_0() -> i32 { { (__tmp_23,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_23, 3); + Item::construct_1(&raw mut __v, __tmp_23, 3); __v }), }; @@ -456,7 +456,7 @@ unsafe fn main_0() -> i32 { { (__tmp_26,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_26, 3); + Item::construct_1(&raw mut __v, __tmp_26, 3); __v }), }; @@ -481,7 +481,7 @@ unsafe fn main_0() -> i32 { { (__tmp_29,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_29, 3); + Item::construct_1(&raw mut __v, __tmp_29, 3); __v }), }; @@ -496,7 +496,7 @@ unsafe fn main_0() -> i32 { { (__tmp_32,) => m.try_emplace(key, || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_32, 3); + Item::construct_1(&raw mut __v, __tmp_32, 3); __v }), }; @@ -727,7 +727,7 @@ unsafe fn main_0() -> i32 { { (__tmp_60,) => selected.try_emplace(keys[(0) as usize], || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_60, 2); + Item::construct_1(&raw mut __v, __tmp_60, 2); __v }), }; @@ -750,7 +750,7 @@ unsafe fn main_0() -> i32 { { (__tmp_63,) => selected.try_emplace(keys[(1) as usize], || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_63, 2); + Item::construct_1(&raw mut __v, __tmp_63, 2); __v }), }; @@ -773,7 +773,7 @@ unsafe fn main_0() -> i32 { { (__tmp_68,) => selected.try_emplace(keys[(2) as usize], || { let mut __v: Item = ::zero_init(); - Item::construct_1(&mut __v, __tmp_68, 2); + Item::construct_1(&raw mut __v, __tmp_68, 2); __v }), }; @@ -913,7 +913,7 @@ unsafe fn main_0() -> i32 { if (hit != 0) { references.try_emplace(key, || { let mut __v: Held = ::zero_init(); - Held::construct_1(&mut __v, &ordinary); + Held::construct_1(&raw mut __v, &ordinary); __v }); } @@ -944,7 +944,7 @@ unsafe fn main_0() -> i32 { { (__tmp_79,) => references.try_emplace(key, || { let mut __v: Held = ::zero_init(); - Held::construct_1(&mut __v, __tmp_79); + Held::construct_1(&raw mut __v, __tmp_79); __v }), }; @@ -971,7 +971,7 @@ unsafe fn main_0() -> i32 { if (hit != 0) { arrays.try_emplace(key, || { let mut __v: Held = ::zero_init(); - Held::construct_2(&mut __v, &ordinary_array, 0); + Held::construct_2(&raw mut __v, &ordinary_array, 0); __v }); } @@ -1000,7 +1000,7 @@ unsafe fn main_0() -> i32 { { (__tmp_82,) => arrays.try_emplace(key, || { let mut __v: Held = ::zero_init(); - Held::construct_2(&mut __v, __tmp_82, 0); + Held::construct_2(&raw mut __v, __tmp_82, 0); __v }), }; @@ -1045,7 +1045,7 @@ unsafe fn main_0() -> i32 { match ((&mut (*(*{ __tmp_86 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v })); &mut __tmp_86 @@ -1064,7 +1064,7 @@ unsafe fn main_0() -> i32 { match ((&mut (*&mut (*(*{ __tmp_88 = Some(Box::new({ let mut __v: Nested = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v })); &mut __tmp_88 @@ -1084,7 +1084,7 @@ unsafe fn main_0() -> i32 { match ((&mut (*(*{ __tmp_90 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v })); &mut __tmp_90 @@ -1103,7 +1103,7 @@ unsafe fn main_0() -> i32 { match ((&mut (*(*{ __tmp_92 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v })); &mut __tmp_92 @@ -1120,7 +1120,7 @@ unsafe fn main_0() -> i32 { match ((&mut (*((*{ __tmp_94 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v })); &mut __tmp_94 @@ -1139,7 +1139,7 @@ unsafe fn main_0() -> i32 { match ((&mut (*((*(*{ __tmp_96 = Some(Box::new(Some(Box::new({ let mut __v: Temporary = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v })))); &mut __tmp_96 @@ -1192,7 +1192,7 @@ unsafe fn main_0() -> i32 { if (hit != 0) { references.try_emplace(key, || { let mut __v: Held = ::zero_init(); - Held::construct_1(&mut __v, &ordinary); + Held::construct_1(&raw mut __v, &ordinary); __v }); } @@ -1209,7 +1209,7 @@ unsafe fn main_0() -> i32 { __tmp_98 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); DefaultConstructibleUnsafe::default_constructor( - &mut __v, + &raw mut __v, ); __v })); @@ -1225,7 +1225,7 @@ unsafe fn main_0() -> i32 { __tmp_99 = Some(Box::new({ let mut __v: Temporary = ::zero_init(); DefaultConstructibleUnsafe::default_constructor( - &mut __v, + &raw mut __v, ); __v })); @@ -1242,7 +1242,7 @@ unsafe fn main_0() -> i32 { { (__tmp_97,) => references.try_emplace(key, || { let mut __v: Held = ::zero_init(); - Held::construct_1(&mut __v, __tmp_97); + Held::construct_1(&raw mut __v, __tmp_97); __v }), }; @@ -1272,7 +1272,7 @@ unsafe fn main_0() -> i32 { Owner::value( &mut (*{ DefaultConstructibleUnsafe::default_constructor( - &mut __tmp_101, + &raw mut __tmp_101, ); &mut __tmp_101 }), @@ -1281,7 +1281,7 @@ unsafe fn main_0() -> i32 { { (__tmp_100,) => owners.try_emplace(key, || { let mut __v: Held = ::zero_init(); - Held::construct_1(&mut __v, __tmp_100); + Held::construct_1(&raw mut __v, __tmp_100); __v }), }; @@ -1306,7 +1306,7 @@ unsafe fn main_0() -> i32 { match (({ __tmp_103 = Some(Box::new({ let mut __v: Noncopy = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v })); &mut __tmp_103 @@ -1323,7 +1323,7 @@ unsafe fn main_0() -> i32 { match (({ __tmp_105 = Some(Box::new({ let mut __v: Noncopy = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v })); &mut __tmp_105 diff --git a/tests/unit/out/unsafe/max.rs b/tests/unit/out/unsafe/max.rs index 37ada6222d..2418d926f2 100644 --- a/tests/unit/out/unsafe/max.rs +++ b/tests/unit/out/unsafe/max.rs @@ -34,13 +34,13 @@ pub struct Bag { pub n: i32, } impl Bag { - pub unsafe fn construct(&mut self, mut n: i32) { - (&raw mut self.n).write(n); + pub unsafe fn construct(this: *mut Self, mut n: i32) { + (&raw mut (*this).n).write(n); } } impl CopyConstructibleUnsafe for Bag { - unsafe fn copy_constructor(&mut self, o: *const Bag) { - (&raw mut self.n).write((*o).n); + unsafe fn copy_constructor(this: *mut Self, o: *const Bag) { + (&raw mut (*this).n).write((*o).n); (*std::cell::LazyCell::force_mut(&mut *&raw mut calls_0)).prefix_inc(); } } @@ -75,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) { - Bag::construct(&mut *__return, n); + Bag::construct(__return, n); return; } pub fn main() { @@ -162,11 +162,11 @@ unsafe fn main_0() -> i32 { let mut __tmp_7: Bag = ::zero_init(); (((*match ( ({ - (unsafe { make_5(&mut __tmp_5, 1) }); + (unsafe { make_5(&raw mut __tmp_5, 1) }); &mut __tmp_5 } as *const Bag), ({ - (unsafe { make_5(&mut __tmp_7, 2) }); + (unsafe { make_5(&raw mut __tmp_7, 2) }); &mut __tmp_7 } as *const Bag), ) { @@ -182,11 +182,11 @@ unsafe fn main_0() -> i32 { let mut __tmp_11: Bag = ::zero_init(); (((*match ( ({ - (unsafe { make_5(&mut __tmp_9, 1) }); + (unsafe { make_5(&raw mut __tmp_9, 1) }); &mut __tmp_9 } as *const Bag), ({ - (unsafe { make_5(&mut __tmp_11, 2) }); + (unsafe { make_5(&raw mut __tmp_11, 2) }); &mut __tmp_11 } as *const Bag), ) { diff --git a/tests/unit/out/unsafe/move_assign.rs b/tests/unit/out/unsafe/move_assign.rs index 1ebc0fc766..d8a0ea3fa0 100644 --- a/tests/unit/out/unsafe/move_assign.rs +++ b/tests/unit/out/unsafe/move_assign.rs @@ -20,24 +20,24 @@ pub struct MoveOnly { pub v: i32, } impl MoveOnly { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } impl MoveConstructibleUnsafe for MoveOnly { - unsafe fn move_constructor(&mut self, o: *mut MoveOnly) { - (&raw mut self.v).write((*o).v); + unsafe fn move_constructor(this: *mut Self, o: *mut MoveOnly) { + (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } impl MoveAssignableUnsafe for MoveOnly { - unsafe fn move_assign(&mut self, o: *mut MoveOnly) -> *mut MoveOnly { - if ((self as *mut MoveOnly) == (o)) { - return &mut (*(self as *mut MoveOnly)); + unsafe fn move_assign(this: *mut Self, o: *mut MoveOnly) -> *mut MoveOnly { + if ((this) == (o)) { + return &mut (*this); } - self.v = (*o).v; + (*this).v = (*o).v; (*o).v = 0; - return &mut (*(self as *mut MoveOnly)); + return &mut (*this); } } #[repr(C)] @@ -46,18 +46,24 @@ pub struct ConstMoveAssign { pub mark: i32, } impl ConstMoveAssign { - pub unsafe fn operator_assign_2(&mut self, o: *mut ConstMoveAssign) -> *mut ConstMoveAssign { - self.mark = (((*o).mark) + (1)); - return &mut (*(self as *mut ConstMoveAssign)); + pub unsafe fn operator_assign_2( + this: *mut Self, + o: *mut ConstMoveAssign, + ) -> *mut ConstMoveAssign { + (*this).mark = (((*o).mark) + (1)); + return &mut (*this); } - pub unsafe fn operator_assign_3(&mut self, o: *const ConstMoveAssign) -> *mut ConstMoveAssign { - self.mark = (((*o).mark) + (10)); - return &mut (*(self as *mut ConstMoveAssign)); + pub unsafe fn operator_assign_3( + this: *mut Self, + o: *const ConstMoveAssign, + ) -> *mut ConstMoveAssign { + (*this).mark = (((*o).mark) + (10)); + return &mut (*this); } } impl DefaultConstructibleUnsafe for ConstMoveAssign { - unsafe fn default_constructor(&mut self) { - (&raw mut self.mark).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).mark).write(0); } } impl Default for ConstMoveAssign { @@ -65,7 +71,7 @@ impl Default for ConstMoveAssign { unsafe { { let mut __v: ConstMoveAssign = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -73,7 +79,7 @@ impl Default for ConstMoveAssign { } pub unsafe fn make_0(__return: *mut MoveOnly, mut v: i32) { object_unsafe!(m, MoveOnly(v)); - ConstructFromUnsafe::construct_from(&mut *__return, Moved(&mut m)); + ConstructFromUnsafe::construct_from(__return, Moved(&mut m)); return; } pub fn main() { @@ -91,20 +97,20 @@ unsafe fn main_0() -> i32 { assert!(((b.v) == (0))); (unsafe { let mut _o: MoveOnly = ::zero_init(); - MoveOnly::construct(&mut _o, 3); + MoveOnly::construct(&raw mut _o, 3); assign_unsafe!(b = Moved(_o)) }); assign_unsafe!(c = Moved((*assign_unsafe!(a = Moved(b))))); assert!((((b.v) == (0)) && ((a.v) == (0))) && ((c.v) == (3))); (unsafe { let mut _o: MoveOnly = ::zero_init(); - MoveOnly::construct(&mut _o, 5); + MoveOnly::construct(&raw mut _o, 5); assign_unsafe!(a = Moved(_o)) }); assert!(((a.v) == (5))); (unsafe { let mut _o: MoveOnly = ::zero_init(); - (unsafe { make_0(&mut _o, 6) }); + (unsafe { make_0(&raw mut _o, 6) }); assign_unsafe!(a = Moved(_o)) }); assert!(((a.v) == (6))); @@ -117,7 +123,7 @@ unsafe fn main_0() -> i32 { { let mut __tmp_1: MoveOnly = ::zero_init(); match (({ - MoveOnly::construct(&mut __tmp_1, 7); + MoveOnly::construct(&raw mut __tmp_1, 7); &mut __tmp_1 } as *mut MoveOnly),) { @@ -132,8 +138,8 @@ unsafe fn main_0() -> i32 { object_unsafe!(m1, ConstMoveAssign); object_unsafe!(m2, ConstMoveAssign); object_unsafe!(cm, ConstMoveAssign); - (unsafe { ConstMoveAssign::operator_assign_2(&mut m1, &mut m) }); - (unsafe { ConstMoveAssign::operator_assign_3(&mut m2, &cm) }); + (unsafe { ConstMoveAssign::operator_assign_2(&raw mut m1, &mut m) }); + (unsafe { ConstMoveAssign::operator_assign_3(&raw mut m2, &cm) }); assert!(((m1.mark) == (1))); assert!(((m2.mark) == (10))); return 0; diff --git a/tests/unit/out/unsafe/move_ctor.rs b/tests/unit/out/unsafe/move_ctor.rs index 225813742f..314099031b 100644 --- a/tests/unit/out/unsafe/move_ctor.rs +++ b/tests/unit/out/unsafe/move_ctor.rs @@ -15,13 +15,13 @@ pub struct MoveOnly { pub v: i32, } impl MoveOnly { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } impl MoveConstructibleUnsafe for MoveOnly { - unsafe fn move_constructor(&mut self, o: *mut MoveOnly) { - (&raw mut self.v).write((*o).v); + unsafe fn move_constructor(this: *mut Self, o: *mut MoveOnly) { + (&raw mut (*this).v).write((*o).v); (*o).v = 0; } } @@ -31,16 +31,16 @@ pub struct ConstMove { pub mark: i32, } impl ConstMove { - pub unsafe fn construct_1(&mut self, o: *mut ConstMove) { - (&raw mut self.mark).write((((*o).mark) + (1))); + pub unsafe fn construct_1(this: *mut Self, o: *mut ConstMove) { + (&raw mut (*this).mark).write((((*o).mark) + (1))); } - pub unsafe fn construct_2(&mut self, o: *const ConstMove) { - (&raw mut self.mark).write((((*o).mark) + (10))); + pub unsafe fn construct_2(this: *mut Self, o: *const ConstMove) { + (&raw mut (*this).mark).write((((*o).mark) + (10))); } } impl DefaultConstructibleUnsafe for ConstMove { - unsafe fn default_constructor(&mut self) { - (&raw mut self.mark).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).mark).write(0); } } impl Default for ConstMove { @@ -48,7 +48,7 @@ impl Default for ConstMove { unsafe { { let mut __v: ConstMove = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -65,24 +65,24 @@ pub struct ThrowingMove { pub moves: i32, } impl ThrowingMove { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); - (&raw mut self.copies).write(0); - (&raw mut self.moves).write(0); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); + (&raw mut (*this).copies).write(0); + (&raw mut (*this).moves).write(0); } } impl CopyConstructibleUnsafe for ThrowingMove { - unsafe fn copy_constructor(&mut self, o: *const ThrowingMove) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((((*o).copies) + (1))); - (&raw mut self.moves).write((*o).moves); + unsafe fn copy_constructor(this: *mut Self, o: *const ThrowingMove) { + (&raw mut (*this).v).write((*o).v); + (&raw mut (*this).copies).write((((*o).copies) + (1))); + (&raw mut (*this).moves).write((*o).moves); } } impl MoveConstructibleUnsafe for ThrowingMove { - unsafe fn move_constructor(&mut self, o: *mut ThrowingMove) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((*o).copies); - (&raw mut self.moves).write((((*o).moves) + (1))); + unsafe fn move_constructor(this: *mut Self, o: *mut ThrowingMove) { + (&raw mut (*this).v).write((*o).v); + (&raw mut (*this).copies).write((*o).copies); + (&raw mut (*this).moves).write((((*o).moves) + (1))); (*o).v = 0; } } @@ -97,24 +97,24 @@ pub struct NoexceptMove { pub moves: i32, } impl NoexceptMove { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); - (&raw mut self.copies).write(0); - (&raw mut self.moves).write(0); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); + (&raw mut (*this).copies).write(0); + (&raw mut (*this).moves).write(0); } } impl CopyConstructibleUnsafe for NoexceptMove { - unsafe fn copy_constructor(&mut self, o: *const NoexceptMove) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((((*o).copies) + (1))); - (&raw mut self.moves).write((*o).moves); + unsafe fn copy_constructor(this: *mut Self, o: *const NoexceptMove) { + (&raw mut (*this).v).write((*o).v); + (&raw mut (*this).copies).write((((*o).copies) + (1))); + (&raw mut (*this).moves).write((*o).moves); } } impl MoveConstructibleUnsafe for NoexceptMove { - unsafe fn move_constructor(&mut self, o: *mut NoexceptMove) { - (&raw mut self.v).write((*o).v); - (&raw mut self.copies).write((*o).copies); - (&raw mut self.moves).write((((*o).moves) + (1))); + unsafe fn move_constructor(this: *mut Self, o: *mut NoexceptMove) { + (&raw mut (*this).v).write((*o).v); + (&raw mut (*this).copies).write((*o).copies); + (&raw mut (*this).moves).write((((*o).moves) + (1))); (*o).v = 0; } } @@ -123,7 +123,7 @@ pub unsafe fn by_value_0(m: *mut MoveOnly) -> i32 { } pub unsafe fn make_1(__return: *mut MoveOnly, mut v: i32) { object_unsafe!(m, MoveOnly(v)); - ConstructFromUnsafe::construct_from(&mut *__return, Moved(&mut m)); + ConstructFromUnsafe::construct_from(__return, Moved(&mut m)); return; } pub fn main() { @@ -148,14 +148,14 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let mut _m: MoveOnly = ::zero_init(); - MoveOnly::construct(&mut _m, 6); + MoveOnly::construct(&raw mut _m, 6); by_value_0(&mut _m) }) == (6)) ); assert!( ((unsafe { let mut _m: MoveOnly = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut _m, Moved(&mut e)); + ConstructFromUnsafe::construct_from(&raw mut _m, Moved(&mut e)); by_value_0(&mut _m) }) == (5)) ); @@ -164,7 +164,7 @@ unsafe fn main_0() -> i32 { { let mut __tmp_1: MoveOnly = ::zero_init(); match (({ - MoveOnly::construct(&mut __tmp_1, 7); + MoveOnly::construct(&raw mut __tmp_1, 7); &mut __tmp_1 } as *mut MoveOnly),) { @@ -201,7 +201,7 @@ unsafe fn main_0() -> i32 { { let mut __tmp_3: NoexceptMove = ::zero_init(); match (({ - NoexceptMove::construct(&mut __tmp_3, 4); + NoexceptMove::construct(&raw mut __tmp_3, 4); &mut __tmp_3 } as *mut NoexceptMove),) { diff --git a/tests/unit/out/unsafe/move_this.rs b/tests/unit/out/unsafe/move_this.rs index 750fa3ef3e..65caaec186 100644 --- a/tests/unit/out/unsafe/move_this.rs +++ b/tests/unit/out/unsafe/move_this.rs @@ -15,37 +15,37 @@ pub struct Chain { pub v: i32, } impl Chain { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } - pub unsafe fn add_4(&mut self, mut n: i32) -> *mut Chain { - self.v += n; - return &mut (*(self as *mut Chain)); + pub unsafe fn add_4(this: *mut Self, mut n: i32) -> *mut Chain { + (*this).v += n; + return &mut (*this); } - pub unsafe fn add_5(&mut self, mut n: i32) -> *mut Chain { - self.v += n; - return &mut (*(self as *mut Chain)); + pub unsafe fn add_5(this: *mut Self, mut n: i32) -> *mut Chain { + (*this).v += n; + return &mut (*this); } - pub unsafe fn take(&mut self, __return: *mut Chain) { - ConstructFromUnsafe::construct_from(&mut *__return, Moved(&mut (*(self as *mut Chain)))); + pub unsafe fn take(this: *mut Self, __return: *mut Chain) { + ConstructFromUnsafe::construct_from(__return, Moved(&mut (*this))); return; } - pub unsafe fn copy(&self, __return: *mut Chain) { - ConstructFromUnsafe::construct_from(&mut *__return, &(*(self as *const Chain))); + pub unsafe fn copy(this: *const Self, __return: *mut Chain) { + ConstructFromUnsafe::construct_from(__return, &(*this)); return; } - pub unsafe fn self_(&mut self) -> *mut Chain { - return &mut (*(self as *mut Chain)); + pub unsafe fn self_(this: *mut Self) -> *mut Chain { + return &mut (*this); } } impl CopyConstructibleUnsafe for Chain { - unsafe fn copy_constructor(&mut self, o: *const Chain) { - (&raw mut self.v).write((((*o).v) + (100))); + unsafe fn copy_constructor(this: *mut Self, o: *const Chain) { + (&raw mut (*this).v).write((((*o).v) + (100))); } } impl MoveConstructibleUnsafe for Chain { - unsafe fn move_constructor(&mut self, o: *mut Chain) { - (&raw mut self.v).write((((*o).v) + (1))); + unsafe fn move_constructor(this: *mut Self, o: *mut Chain) { + (&raw mut (*this).v).write((((*o).v) + (1))); (*o).v = 0; } } @@ -60,13 +60,13 @@ pub fn main() { } unsafe fn main_0() -> i32 { object_unsafe!(a, Chain(1)); - (unsafe { Chain::add_4(&mut (*(unsafe { Chain::add_4(&mut a, 1) })), 1) }); + (unsafe { Chain::add_4(&raw mut (*(unsafe { Chain::add_4(&raw mut a, 1) })), 1) }); assert!(((a.v) == (3))); object_unsafe!(b0, Chain(5)); object_unsafe!( b, Chain, - Moved((unsafe { Chain::add_5(&mut (*(unsafe { Chain::add_5(&mut b0, 1,) })), 1,) })) + Moved((unsafe { Chain::add_5(&mut (*(unsafe { Chain::add_5(&raw mut b0, 1,) })), 1,) })) ); assert!(((b.v) == (8)) && ((b0.v) == (0))); object_unsafe!(c, Chain, |c| { @@ -74,7 +74,7 @@ unsafe fn main_0() -> i32 { (unsafe { Chain::take( &mut (*{ - Chain::construct(&mut __tmp_0, 10); + Chain::construct(&raw mut __tmp_0, 10); &mut __tmp_0 }), c, @@ -82,18 +82,21 @@ unsafe fn main_0() -> i32 { }) }); assert!(((c.v) == (11))); - object_unsafe!(d, Chain, |d| (unsafe { Chain::copy(&c, d,) })); + object_unsafe!(d, Chain, |d| (unsafe { Chain::copy(&raw const c, d,) })); assert!(((d.v) == (111)) && ((c.v) == (11))); object_unsafe!(g, Chain(20)); assert!( ((unsafe { let mut _c: Chain = ::zero_init(); - ConstructFromUnsafe::construct_from(&mut _c, Moved((unsafe { Chain::self_(&mut g) }))); + ConstructFromUnsafe::construct_from( + &raw mut _c, + Moved((unsafe { Chain::self_(&raw mut g) })), + ); consume_0(&mut _c) }) == (21)) ); object_unsafe!(e, Chain(30)); - object_unsafe!(f, Chain, |f| (unsafe { Chain::take(&mut e, f,) })); + object_unsafe!(f, Chain, |f| (unsafe { Chain::take(&raw mut e, f,) })); assert!(((f.v) == (31)) && ((e.v) == (0))); return 0; } diff --git a/tests/unit/out/unsafe/nttp_distinct_specializations.rs b/tests/unit/out/unsafe/nttp_distinct_specializations.rs index f9f374e227..72c4559f6c 100644 --- a/tests/unit/out/unsafe/nttp_distinct_specializations.rs +++ b/tests/unit/out/unsafe/nttp_distinct_specializations.rs @@ -22,8 +22,8 @@ pub struct S_2_ { pub w: i32, } impl S_2_ { - pub unsafe fn get(&self) -> i32 { - return ((self.v) - (self.w)); + pub unsafe fn get(this: *const Self) -> i32 { + return (((*this).v) - ((*this).w)); } } #[repr(C)] @@ -41,8 +41,8 @@ pub struct S_1_ { pub v: i32, } impl S_1_ { - pub unsafe fn get(&self) -> i32 { - return ((self.v) * (1)); + pub unsafe fn get(this: *const Self) -> i32 { + return (((*this).v) * (1)); } } #[repr(C)] @@ -60,8 +60,8 @@ pub struct S_3_ { pub v: i32, } impl S_3_ { - pub unsafe fn get(&self) -> i32 { - return ((self.v) * (3)); + pub unsafe fn get(this: *const Self) -> i32 { + return (((*this).v) * (3)); } } pub unsafe fn scale_0(mut x: i32) -> i32 { @@ -101,9 +101,9 @@ unsafe fn main_0() -> i32 { let mut s1: S_1_ = S_1_ { v: 5 }; let mut s2: S_2_ = S_2_ { v: 5, w: 1 }; let mut s3: S_3_ = S_3_ { v: 5 }; - assert!(((unsafe { S_1_::get(&s1,) }) == (5))); - assert!(((unsafe { S_2_::get(&s2,) }) == (4))); - assert!(((unsafe { S_3_::get(&s3,) }) == (15))); + assert!(((unsafe { S_1_::get(&raw const s1,) }) == (5))); + assert!(((unsafe { S_2_::get(&raw const s2,) }) == (4))); + assert!(((unsafe { S_3_::get(&raw const s3,) }) == (15))); assert!(((unsafe { scale_0(7,) }) == (7))); assert!(((unsafe { scale_2(7,) }) == (5))); assert!(((unsafe { scale_1(7,) }) == (21))); diff --git a/tests/unit/out/unsafe/operator_arithmetic_member.rs b/tests/unit/out/unsafe/operator_arithmetic_member.rs index 5cae6acad9..2c3c8bda4b 100644 --- a/tests/unit/out/unsafe/operator_arithmetic_member.rs +++ b/tests/unit/out/unsafe/operator_arithmetic_member.rs @@ -21,53 +21,53 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn operator_add_1(&self, o: *const S) -> S { + pub unsafe fn operator_add_1(this: *const Self, o: *const S) -> S { return S { - v: ((self.v) + ((*o).v)), + v: (((*this).v) + ((*o).v)), }; } - pub unsafe fn operator_sub_2(&self, o: *const S) -> S { + pub unsafe fn operator_sub_2(this: *const Self, o: *const S) -> S { return S { - v: ((self.v) - ((*o).v)), + v: (((*this).v) - ((*o).v)), }; } - pub unsafe fn operator_mul(&self, o: *const S) -> S { + pub unsafe fn operator_mul(this: *const Self, o: *const S) -> S { return S { - v: ((self.v) * ((*o).v)), + v: (((*this).v) * ((*o).v)), }; } - pub unsafe fn operator_div(&self, o: *const S) -> S { + pub unsafe fn operator_div(this: *const Self, o: *const S) -> S { return S { - v: ((self.v) / ((*o).v)), + v: (((*this).v) / ((*o).v)), }; } - pub unsafe fn operator_rem(&self, o: *const S) -> S { + pub unsafe fn operator_rem(this: *const Self, o: *const S) -> S { return S { - v: ((self.v) % ((*o).v)), + v: (((*this).v) % ((*o).v)), }; } - pub unsafe fn operator_pos_6(&self) -> S { - return S { v: self.v }; + pub unsafe fn operator_pos_6(this: *const Self) -> S { + return S { v: (*this).v }; } - pub unsafe fn operator_neg_7(&self) -> S { - return S { v: -self.v }; + pub unsafe fn operator_neg_7(this: *const Self) -> S { + return S { v: -(*this).v }; } - pub unsafe fn operator_inc_8(&mut self) -> *mut S { - self.v.prefix_inc(); - return &mut (*(self as *mut S)); + pub unsafe fn operator_inc_8(this: *mut Self) -> *mut S { + (*this).v.prefix_inc(); + return &mut (*this); } - pub unsafe fn operator_post_inc_9(&mut self, mut _a0: i32) -> S { - let mut old: S = (*(self as *mut S)); - self.v.prefix_inc(); + pub unsafe fn operator_post_inc_9(this: *mut Self, mut _a0: i32) -> S { + let mut old: S = (*this); + (*this).v.prefix_inc(); return old; } - pub unsafe fn operator_dec_10(&mut self) -> *mut S { - self.v.prefix_dec(); - return &mut (*(self as *mut S)); + pub unsafe fn operator_dec_10(this: *mut Self) -> *mut S { + (*this).v.prefix_dec(); + return &mut (*this); } - pub unsafe fn operator_post_dec_11(&mut self, mut _a0: i32) -> S { - let mut old: S = (*(self as *mut S)); - self.v.prefix_dec(); + pub unsafe fn operator_post_dec_11(this: *mut Self, mut _a0: i32) -> S { + let mut old: S = (*this); + (*this).v.prefix_dec(); return old; } } @@ -80,22 +80,24 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut a: S = S { v: 7 }; let mut b: S = S { v: 2 }; - assert!((((unsafe { S::operator_add_1(&a, &b,) }).v) == (9))); - assert!((((unsafe { S::operator_sub_2(&a, &b,) }).v) == (5))); - assert!((((unsafe { S::operator_mul(&a, &b,) }).v) == (14))); - assert!((((unsafe { S::operator_div(&a, &b,) }).v) == (3))); - assert!((((unsafe { S::operator_rem(&a, &b,) }).v) == (1))); - assert!((((unsafe { S::operator_pos_6(&a,) }).v) == (7))); - assert!((((unsafe { S::operator_neg_7(&a,) }).v) == (-7_i32))); - assert!((((*(unsafe { S::operator_inc_8(&mut a,) })).v) == (8))); - assert!((((unsafe { S::operator_post_inc_9(&mut a, 0,) }).v) == (8))); + assert!((((unsafe { S::operator_add_1(&raw const a, &b,) }).v) == (9))); + assert!((((unsafe { S::operator_sub_2(&raw const a, &b,) }).v) == (5))); + assert!((((unsafe { S::operator_mul(&raw const a, &b,) }).v) == (14))); + assert!((((unsafe { S::operator_div(&raw const a, &b,) }).v) == (3))); + assert!((((unsafe { S::operator_rem(&raw const a, &b,) }).v) == (1))); + assert!((((unsafe { S::operator_pos_6(&raw const a,) }).v) == (7))); + assert!((((unsafe { S::operator_neg_7(&raw const a,) }).v) == (-7_i32))); + assert!((((*(unsafe { S::operator_inc_8(&raw mut a,) })).v) == (8))); + assert!((((unsafe { S::operator_post_inc_9(&raw mut a, 0,) }).v) == (8))); assert!(((a.v) == (9))); - assert!((((*(unsafe { S::operator_dec_10(&mut a,) })).v) == (8))); - assert!((((unsafe { S::operator_post_dec_11(&mut a, 0,) }).v) == (8))); + assert!((((*(unsafe { S::operator_dec_10(&raw mut a,) })).v) == (8))); + assert!((((unsafe { S::operator_post_dec_11(&raw mut a, 0,) }).v) == (8))); assert!(((a.v) == (7))); assert!( - (((*(unsafe { S::operator_inc_8(&mut (*(unsafe { S::operator_inc_8(&mut a,) })),) })).v) - == (9)) + (((*(unsafe { + S::operator_inc_8(&raw mut (*(unsafe { S::operator_inc_8(&raw mut a) }))) + })) + .v) == (9)) ); assert!( (((unsafe { diff --git a/tests/unit/out/unsafe/operator_bitwise_member.rs b/tests/unit/out/unsafe/operator_bitwise_member.rs index df6d2e2d6c..e3907641d2 100644 --- a/tests/unit/out/unsafe/operator_bitwise_member.rs +++ b/tests/unit/out/unsafe/operator_bitwise_member.rs @@ -21,32 +21,32 @@ pub struct S { pub v: u32, } impl S { - pub unsafe fn operator_bitnot(&self) -> S { - return S { v: !self.v }; + pub unsafe fn operator_bitnot(this: *const Self) -> S { + return S { v: !(*this).v }; } - pub unsafe fn operator_bitand(&self, o: *const S) -> S { + pub unsafe fn operator_bitand(this: *const Self, o: *const S) -> S { return S { - v: ((self.v) & ((*o).v)), + v: (((*this).v) & ((*o).v)), }; } - pub unsafe fn operator_bitor(&self, o: *const S) -> S { + pub unsafe fn operator_bitor(this: *const Self, o: *const S) -> S { return S { - v: ((self.v) | ((*o).v)), + v: (((*this).v) | ((*o).v)), }; } - pub unsafe fn operator_bitxor(&self, o: *const S) -> S { + pub unsafe fn operator_bitxor(this: *const Self, o: *const S) -> S { return S { - v: ((self.v) ^ ((*o).v)), + v: (((*this).v) ^ ((*o).v)), }; } - pub unsafe fn operator_shl(&self, mut n: i32) -> S { + pub unsafe fn operator_shl(this: *const Self, mut n: i32) -> S { return S { - v: ((self.v) << (n)), + v: (((*this).v) << (n)), }; } - pub unsafe fn operator_shr(&self, mut n: i32) -> S { + pub unsafe fn operator_shr(this: *const Self, mut n: i32) -> S { return S { - v: ((self.v) >> (n)), + v: (((*this).v) >> (n)), }; } } @@ -59,12 +59,12 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut a: S = S { v: 12_u32 }; let mut b: S = S { v: 10_u32 }; - assert!((((unsafe { S::operator_bitnot(&a,) }).v) == (!12_u32))); - assert!((((unsafe { S::operator_bitand(&a, &b,) }).v) == (8_u32))); - assert!((((unsafe { S::operator_bitor(&a, &b,) }).v) == (14_u32))); - assert!((((unsafe { S::operator_bitxor(&a, &b,) }).v) == (6_u32))); - assert!((((unsafe { S::operator_shl(&a, 2,) }).v) == (48_u32))); - assert!((((unsafe { S::operator_shr(&a, 2,) }).v) == (3_u32))); + assert!((((unsafe { S::operator_bitnot(&raw const a,) }).v) == (!12_u32))); + assert!((((unsafe { S::operator_bitand(&raw const a, &b,) }).v) == (8_u32))); + assert!((((unsafe { S::operator_bitor(&raw const a, &b,) }).v) == (14_u32))); + assert!((((unsafe { S::operator_bitxor(&raw const a, &b,) }).v) == (6_u32))); + assert!((((unsafe { S::operator_shl(&raw const a, 2,) }).v) == (48_u32))); + assert!((((unsafe { S::operator_shr(&raw const a, 2,) }).v) == (3_u32))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_comparison_defaulted.rs b/tests/unit/out/unsafe/operator_comparison_defaulted.rs index f9b1fa5a6b..3ed17b1d67 100644 --- a/tests/unit/out/unsafe/operator_comparison_defaulted.rs +++ b/tests/unit/out/unsafe/operator_comparison_defaulted.rs @@ -22,9 +22,8 @@ pub struct Eq { pub b: i32, } impl Eq { - pub unsafe fn operator_eq(&self, _a0: *const Eq) -> bool { - return (((*(self as *const Eq)).a) == ((*_a0).a)) - && (((*(self as *const Eq)).b) == ((*_a0).b)); + pub unsafe fn operator_eq(this: *const Self, _a0: *const Eq) -> bool { + return (((*this).a) == ((*_a0).a)) && (((*this).b) == ((*_a0).b)); } } impl std::cmp::PartialEq for Eq { @@ -49,26 +48,23 @@ pub struct Cmp { pub b: i32, } impl Cmp { - pub unsafe fn operator_cmp(&self, _a0: *const Cmp) -> std::cmp::Ordering { + pub unsafe fn operator_cmp(this: *const Self, _a0: *const Cmp) -> std::cmp::Ordering { { - let mut cmp: std::cmp::Ordering = - std::cmp::Ord::cmp(&((*(self as *const Cmp)).a), &((*_a0).a)); + let mut cmp: std::cmp::Ordering = std::cmp::Ord::cmp(&((*this).a), &((*_a0).a)); if !(cmp == std::cmp::Ordering::Equal) { return cmp; } } { - let mut cmp: std::cmp::Ordering = - std::cmp::Ord::cmp(&((*(self as *const Cmp)).b), &((*_a0).b)); + let mut cmp: std::cmp::Ordering = std::cmp::Ord::cmp(&((*this).b), &((*_a0).b)); if !(cmp == std::cmp::Ordering::Equal) { return cmp; } } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(&self, _a0: *const Cmp) -> bool { - return (((*(self as *const Cmp)).a) == ((*_a0).a)) - && (((*(self as *const Cmp)).b) == ((*_a0).b)); + pub unsafe fn operator_eq(this: *const Self, _a0: *const Cmp) -> bool { + return (((*this).a) == ((*_a0).a)) && (((*this).b) == ((*_a0).b)); } } impl std::cmp::Ord for Cmp { @@ -102,13 +98,12 @@ pub struct Both { pub a: i32, } impl Both { - pub unsafe fn operator_eq(&self, _a0: *const Both) -> bool { - return (((*(self as *const Both)).a) == ((*_a0).a)); + pub unsafe fn operator_eq(this: *const Self, _a0: *const Both) -> bool { + return (((*this).a) == ((*_a0).a)); } - pub unsafe fn operator_cmp(&self, _a0: *const Both) -> std::cmp::Ordering { + pub unsafe fn operator_cmp(this: *const Self, _a0: *const Both) -> std::cmp::Ordering { { - let mut cmp: std::cmp::Ordering = - std::cmp::Ord::cmp(&((*(self as *const Both)).a), &((*_a0).a)); + let mut cmp: std::cmp::Ordering = std::cmp::Ord::cmp(&((*this).a), &((*_a0).a)); if !(cmp == std::cmp::Ordering::Equal) { return cmp; } @@ -147,10 +142,9 @@ pub struct OrdOnly { pub a: i32, } impl OrdOnly { - pub unsafe fn operator_cmp(&self, _a0: *const OrdOnly) -> std::cmp::Ordering { + pub unsafe fn operator_cmp(this: *const Self, _a0: *const OrdOnly) -> std::cmp::Ordering { { - let mut cmp: std::cmp::Ordering = - std::cmp::Ord::cmp(&((*(self as *const OrdOnly)).a), &((*_a0).a)); + let mut cmp: std::cmp::Ordering = std::cmp::Ord::cmp(&((*this).a), &((*_a0).a)); if !(cmp == std::cmp::Ordering::Equal) { return cmp; } @@ -189,18 +183,17 @@ pub struct Inner { pub x: i32, } impl Inner { - pub unsafe fn operator_cmp(&self, _a0: *const Inner) -> std::cmp::Ordering { + pub unsafe fn operator_cmp(this: *const Self, _a0: *const Inner) -> std::cmp::Ordering { { - let mut cmp: std::cmp::Ordering = - std::cmp::Ord::cmp(&((*(self as *const Inner)).x), &((*_a0).x)); + let mut cmp: std::cmp::Ordering = std::cmp::Ord::cmp(&((*this).x), &((*_a0).x)); if !(cmp == std::cmp::Ordering::Equal) { return cmp; } } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(&self, _a0: *const Inner) -> bool { - return (((*(self as *const Inner)).x) == ((*_a0).x)); + pub unsafe fn operator_eq(this: *const Self, _a0: *const Inner) -> bool { + return (((*this).x) == ((*_a0).x)); } } impl std::cmp::Ord for Inner { @@ -235,30 +228,29 @@ pub struct Outer { pub y: i32, } impl Outer { - pub unsafe fn operator_cmp(&self, _a0: *const Outer) -> std::cmp::Ordering { + pub unsafe fn operator_cmp(this: *const Self, _a0: *const Outer) -> std::cmp::Ordering { { let mut cmp: std::cmp::Ordering = (unsafe { let _arg0: *const Inner = &(*_a0).i; - Inner::operator_cmp(&(*(self as *const Outer)).i, _arg0) + Inner::operator_cmp(&raw const (*this).i, _arg0) }); if !(cmp == std::cmp::Ordering::Equal) { return cmp; } } { - let mut cmp: std::cmp::Ordering = - std::cmp::Ord::cmp(&((*(self as *const Outer)).y), &((*_a0).y)); + let mut cmp: std::cmp::Ordering = std::cmp::Ord::cmp(&((*this).y), &((*_a0).y)); if !(cmp == std::cmp::Ordering::Equal) { return cmp; } } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(&self, _a0: *const Outer) -> bool { + pub unsafe fn operator_eq(this: *const Self, _a0: *const Outer) -> bool { return (unsafe { let _arg0: *const Inner = &(*_a0).i; - Inner::operator_eq(&(*(self as *const Outer)).i, _arg0) - }) && (((*(self as *const Outer)).y) == ((*_a0).y)); + Inner::operator_eq(&raw const (*this).i, _arg0) + }) && (((*this).y) == ((*_a0).y)); } } impl std::cmp::Ord for Outer { @@ -292,28 +284,27 @@ pub struct Secondary { pub a: i32, } impl Secondary { - pub unsafe fn operator_eq(&self, _a0: *const Secondary) -> bool { - return (((*(self as *const Secondary)).a) == ((*_a0).a)); + pub unsafe fn operator_eq(this: *const Self, _a0: *const Secondary) -> bool { + return (((*this).a) == ((*_a0).a)); } - pub unsafe fn operator_ne(&self, _a0: *const Secondary) -> bool { - return !(unsafe { Secondary::operator_eq(&(*(self as *const Secondary)), _a0) }); + pub unsafe fn operator_ne(this: *const Self, _a0: *const Secondary) -> bool { + return !(unsafe { Secondary::operator_eq(&raw const (*this), _a0) }); } - pub unsafe fn operator_cmp(&self, _a0: *const Secondary) -> std::cmp::Ordering { + pub unsafe fn operator_cmp(this: *const Self, _a0: *const Secondary) -> std::cmp::Ordering { { - let mut cmp: std::cmp::Ordering = - std::cmp::Ord::cmp(&((*(self as *const Secondary)).a), &((*_a0).a)); + let mut cmp: std::cmp::Ordering = std::cmp::Ord::cmp(&((*this).a), &((*_a0).a)); if !(cmp == std::cmp::Ordering::Equal) { return cmp; } } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_lt(&self, _a0: *const Secondary) -> bool { - return (unsafe { Secondary::operator_cmp(&(*(self as *const Secondary)), _a0) }) + pub unsafe fn operator_lt(this: *const Self, _a0: *const Secondary) -> bool { + return (unsafe { Secondary::operator_cmp(&raw const (*this), _a0) }) == std::cmp::Ordering::Less; } - pub unsafe fn operator_ge(&self, _a0: *const Secondary) -> bool { - return (unsafe { Secondary::operator_cmp(&(*(self as *const Secondary)), _a0) }) + pub unsafe fn operator_ge(this: *const Self, _a0: *const Secondary) -> bool { + return (unsafe { Secondary::operator_cmp(&raw const (*this), _a0) }) != std::cmp::Ordering::Less; } } @@ -348,18 +339,17 @@ pub struct PtrMember { pub p: *mut i32, } impl PtrMember { - pub unsafe fn operator_cmp(&self, _a0: *const PtrMember) -> std::cmp::Ordering { + pub unsafe fn operator_cmp(this: *const Self, _a0: *const PtrMember) -> std::cmp::Ordering { { - let mut cmp: std::cmp::Ordering = - std::cmp::Ord::cmp(&((*(self as *const PtrMember)).p), &((*_a0).p)); + let mut cmp: std::cmp::Ordering = std::cmp::Ord::cmp(&((*this).p), &((*_a0).p)); if !(cmp == std::cmp::Ordering::Equal) { return cmp; } } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(&self, _a0: *const PtrMember) -> bool { - return (((*(self as *const PtrMember)).p) == ((*_a0).p)); + pub unsafe fn operator_eq(this: *const Self, _a0: *const PtrMember) -> bool { + return (((*this).p) == ((*_a0).p)); } } impl std::cmp::Ord for PtrMember { @@ -390,34 +380,37 @@ unsafe fn main_0() -> i32 { let mut e1: Eq = Eq { a: 1, b: 2 }; let mut e2: Eq = Eq { a: 1, b: 2 }; let mut e3: Eq = Eq { a: 1, b: 3 }; - assert!((unsafe { Eq::operator_eq(&e1, &e2,) })); - assert!(!(unsafe { Eq::operator_eq(&e1, &e3,) })); + assert!((unsafe { Eq::operator_eq(&raw const e1, &e2,) })); + assert!(!(unsafe { Eq::operator_eq(&raw const e1, &e3,) })); let mut c1: Cmp = Cmp { a: 1, b: 2 }; let mut c2: Cmp = Cmp { a: 1, b: 3 }; let mut c3: Cmp = Cmp { a: 2, b: 0 }; let mut c4: Cmp = Cmp { a: 1, b: 9 }; - assert!((unsafe { Cmp::operator_cmp(&c1, &c2,) }) == std::cmp::Ordering::Less); - assert!((unsafe { Cmp::operator_cmp(&c3, &c4,) }) == std::cmp::Ordering::Greater); + assert!((unsafe { Cmp::operator_cmp(&raw const c1, &c2,) }) == std::cmp::Ordering::Less); + assert!((unsafe { Cmp::operator_cmp(&raw const c3, &c4,) }) == std::cmp::Ordering::Greater); assert!( (unsafe { let _arg0: *const Cmp = &c1; - Cmp::operator_eq(&c1, _arg0) + Cmp::operator_eq(&raw const c1, _arg0) }) ); - assert!((unsafe { Cmp::operator_cmp(&c1, &c2,) }) == libcc2rs::STRONG_ORDERING_LESS); + assert!((unsafe { Cmp::operator_cmp(&raw const c1, &c2,) }) == libcc2rs::STRONG_ORDERING_LESS); let mut b1: Both = Both { a: 1 }; let mut b2: Both = Both { a: 2 }; - assert!((unsafe { Both::operator_cmp(&b1, &b2,) }) == std::cmp::Ordering::Less); + assert!((unsafe { Both::operator_cmp(&raw const b1, &b2,) }) == std::cmp::Ordering::Less); assert!( (unsafe { let _arg0: *const Both = &b2; - Both::operator_eq(&b2, _arg0) + Both::operator_eq(&raw const b2, _arg0) }) ); let mut o1: OrdOnly = OrdOnly { a: 1 }; let mut o2: OrdOnly = OrdOnly { a: 2 }; - assert!((unsafe { OrdOnly::operator_cmp(&o1, &o2,) }) == std::cmp::Ordering::Less); - assert!((unsafe { OrdOnly::operator_cmp(&o2, &o1,) }) == libcc2rs::STRONG_ORDERING_GREATER); + assert!((unsafe { OrdOnly::operator_cmp(&raw const o1, &o2,) }) == std::cmp::Ordering::Less); + assert!( + (unsafe { OrdOnly::operator_cmp(&raw const o2, &o1,) }) + == libcc2rs::STRONG_ORDERING_GREATER + ); let mut x1: Outer = Outer { i: Inner { x: 1 }, y: 9, @@ -430,15 +423,17 @@ unsafe fn main_0() -> i32 { i: Inner { x: 1 }, y: 9, }; - assert!((unsafe { Outer::operator_cmp(&x1, &x2,) }) == std::cmp::Ordering::Less); - assert!((unsafe { Outer::operator_eq(&x1, &x3,) })); - assert!((unsafe { Outer::operator_cmp(&x2, &x1,) }) == libcc2rs::STRONG_ORDERING_GREATER); + assert!((unsafe { Outer::operator_cmp(&raw const x1, &x2,) }) == std::cmp::Ordering::Less); + assert!((unsafe { Outer::operator_eq(&raw const x1, &x3,) })); + assert!( + (unsafe { Outer::operator_cmp(&raw const x2, &x1,) }) == libcc2rs::STRONG_ORDERING_GREATER + ); let mut s1: Secondary = Secondary { a: 1 }; let mut s2: Secondary = Secondary { a: 2 }; - assert!((unsafe { Secondary::operator_ne(&s1, &s2,) })); - assert!((unsafe { Secondary::operator_lt(&s1, &s2,) })); - assert!((unsafe { Secondary::operator_ge(&s2, &s1,) })); - assert!(!(unsafe { Secondary::operator_lt(&s2, &s1,) })); + assert!((unsafe { Secondary::operator_ne(&raw const s1, &s2,) })); + assert!((unsafe { Secondary::operator_lt(&raw const s1, &s2,) })); + assert!((unsafe { Secondary::operator_ge(&raw const s2, &s1,) })); + assert!(!(unsafe { Secondary::operator_lt(&raw const s2, &s1,) })); let mut arr: [i32; 2] = [0, 0]; let mut p1: PtrMember = PtrMember { p: arr.as_mut_ptr(), @@ -449,9 +444,12 @@ unsafe fn main_0() -> i32 { let mut p3: PtrMember = PtrMember { p: arr.as_mut_ptr(), }; - assert!((unsafe { PtrMember::operator_cmp(&p1, &p2,) }) == std::cmp::Ordering::Less); - assert!((unsafe { PtrMember::operator_eq(&p1, &p3,) })); - assert!((unsafe { PtrMember::operator_cmp(&p2, &p1,) }) == libcc2rs::STRONG_ORDERING_GREATER); + assert!((unsafe { PtrMember::operator_cmp(&raw const p1, &p2,) }) == std::cmp::Ordering::Less); + assert!((unsafe { PtrMember::operator_eq(&raw const p1, &p3,) })); + assert!( + (unsafe { PtrMember::operator_cmp(&raw const p2, &p1,) }) + == libcc2rs::STRONG_ORDERING_GREATER + ); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_comparison_member.rs b/tests/unit/out/unsafe/operator_comparison_member.rs index 8f040647f7..8901e9a173 100644 --- a/tests/unit/out/unsafe/operator_comparison_member.rs +++ b/tests/unit/out/unsafe/operator_comparison_member.rs @@ -21,26 +21,26 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn operator_eq(&self, o: *const S) -> bool { - return ((self.v) == ((*o).v)); + pub unsafe fn operator_eq(this: *const Self, o: *const S) -> bool { + return (((*this).v) == ((*o).v)); } - pub unsafe fn operator_ne(&self, o: *const S) -> bool { - return ((self.v) != ((*o).v)); + pub unsafe fn operator_ne(this: *const Self, o: *const S) -> bool { + return (((*this).v) != ((*o).v)); } - pub unsafe fn operator_lt_3(&self, o: *const S) -> bool { - return ((self.v) < ((*o).v)); + pub unsafe fn operator_lt_3(this: *const Self, o: *const S) -> bool { + return (((*this).v) < ((*o).v)); } - pub unsafe fn operator_gt(&self, o: *const S) -> bool { - return ((self.v) > ((*o).v)); + pub unsafe fn operator_gt(this: *const Self, o: *const S) -> bool { + return (((*this).v) > ((*o).v)); } - pub unsafe fn operator_le(&self, o: *const S) -> bool { - return ((self.v) <= ((*o).v)); + pub unsafe fn operator_le(this: *const Self, o: *const S) -> bool { + return (((*this).v) <= ((*o).v)); } - pub unsafe fn operator_ge(&self, o: *const S) -> bool { - return ((self.v) >= ((*o).v)); + pub unsafe fn operator_ge(this: *const Self, o: *const S) -> bool { + return (((*this).v) >= ((*o).v)); } - pub unsafe fn operator_lt_7(&self, mut o: i32) -> bool { - return ((self.v) < (o)); + pub unsafe fn operator_lt_7(this: *const Self, mut o: i32) -> bool { + return (((*this).v) < (o)); } } impl std::cmp::Ord for S { @@ -77,14 +77,14 @@ unsafe fn main_0() -> i32 { let mut a: S = S { v: 1 }; let mut b: S = S { v: 2 }; let mut c: S = S { v: 1 }; - assert!((unsafe { S::operator_eq(&a, &c,) })); - assert!((unsafe { S::operator_ne(&a, &b,) })); - assert!((unsafe { S::operator_lt_3(&a, &b,) })); - assert!((unsafe { S::operator_gt(&b, &a,) })); - assert!((unsafe { S::operator_le(&a, &c,) })); - assert!((unsafe { S::operator_ge(&a, &c,) })); - assert!(!(unsafe { S::operator_lt_3(&b, &a,) })); - assert!((unsafe { S::operator_lt_7(&a, 5,) })); + assert!((unsafe { S::operator_eq(&raw const a, &c,) })); + assert!((unsafe { S::operator_ne(&raw const a, &b,) })); + assert!((unsafe { S::operator_lt_3(&raw const a, &b,) })); + assert!((unsafe { S::operator_gt(&raw const b, &a,) })); + assert!((unsafe { S::operator_le(&raw const a, &c,) })); + assert!((unsafe { S::operator_ge(&raw const a, &c,) })); + assert!(!(unsafe { S::operator_lt_3(&raw const b, &a,) })); + assert!((unsafe { S::operator_lt_7(&raw const a, 5,) })); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_comparison_mixed.rs b/tests/unit/out/unsafe/operator_comparison_mixed.rs index eecee4a3b6..d70ad8a71d 100644 --- a/tests/unit/out/unsafe/operator_comparison_mixed.rs +++ b/tests/unit/out/unsafe/operator_comparison_mixed.rs @@ -21,23 +21,23 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn operator_eq(&self, mut o: i32) -> bool { - return ((self.v) == (o)); + pub unsafe fn operator_eq(this: *const Self, mut o: i32) -> bool { + return (((*this).v) == (o)); } - pub unsafe fn operator_ne(&self, mut o: i32) -> bool { - return ((self.v) != (o)); + pub unsafe fn operator_ne(this: *const Self, mut o: i32) -> bool { + return (((*this).v) != (o)); } - pub unsafe fn operator_lt(&self, mut o: i32) -> bool { - return ((self.v) < (o)); + pub unsafe fn operator_lt(this: *const Self, mut o: i32) -> bool { + return (((*this).v) < (o)); } - pub unsafe fn operator_gt(&self, mut o: f64) -> bool { - return ((self.v as f64) > (o)); + pub unsafe fn operator_gt(this: *const Self, mut o: f64) -> bool { + return (((*this).v as f64) > (o)); } - pub unsafe fn operator_le(&self, mut o: i64) -> bool { - return ((self.v as i64) <= (o)); + pub unsafe fn operator_le(this: *const Self, mut o: i64) -> bool { + return (((*this).v as i64) <= (o)); } - pub unsafe fn operator_ge(&self, mut o: *const libc::c_char) -> bool { - return ((self.v) >= (((*o) as i32) - (('0' as libc::c_char) as i32))); + pub unsafe fn operator_ge(this: *const Self, mut o: *const libc::c_char) -> bool { + return (((*this).v) >= (((*o) as i32) - (('0' as libc::c_char) as i32))); } } pub unsafe fn operator_eq_0(mut a: i32, b: *const S) -> bool { @@ -70,12 +70,12 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut s: S = S { v: 5 }; let cs: *const S = &s; - assert!((unsafe { S::operator_eq(&(*cs), 5,) })); - assert!((unsafe { S::operator_ne(&(*cs), 4,) })); - assert!((unsafe { S::operator_lt(&(*cs), 6,) })); - assert!((unsafe { S::operator_gt(&(*cs), 4.5_f64,) })); - assert!((unsafe { S::operator_le(&(*cs), 5_i64,) })); - assert!((unsafe { S::operator_ge(&(*cs), c"3".as_ptr(),) })); + assert!((unsafe { S::operator_eq(&raw const (*cs), 5,) })); + assert!((unsafe { S::operator_ne(&raw const (*cs), 4,) })); + assert!((unsafe { S::operator_lt(&raw const (*cs), 6,) })); + assert!((unsafe { S::operator_gt(&raw const (*cs), 4.5_f64,) })); + assert!((unsafe { S::operator_le(&raw const (*cs), 5_i64,) })); + assert!((unsafe { S::operator_ge(&raw const (*cs), c"3".as_ptr(),) })); assert!((unsafe { operator_eq_0(5, &s,) })); assert!((unsafe { operator_ne_1(4, &s,) })); assert!((unsafe { operator_lt_2(4, &s,) })); diff --git a/tests/unit/out/unsafe/operator_comparison_nonbool.rs b/tests/unit/out/unsafe/operator_comparison_nonbool.rs index 3c1fd305f9..dec785d640 100644 --- a/tests/unit/out/unsafe/operator_comparison_nonbool.rs +++ b/tests/unit/out/unsafe/operator_comparison_nonbool.rs @@ -91,9 +91,9 @@ pub struct Custom { pub v: i32, } impl Custom { - pub unsafe fn operator_cmp(&self, o: *const Custom) -> Result { + pub unsafe fn operator_cmp(this: *const Self, o: *const Custom) -> Result { return Result { - r: ((self.v) - ((*o).v)), + r: (((*this).v) - ((*o).v)), }; } } @@ -112,16 +112,16 @@ pub struct Mixed { pub v: i32, } impl Mixed { - pub unsafe fn operator_cmp(&self, o: *const Mixed) -> Result { + pub unsafe fn operator_cmp(this: *const Self, o: *const Mixed) -> Result { return Result { - r: ((self.v) - ((*o).v)), + r: (((*this).v) - ((*o).v)), }; } - pub unsafe fn operator_lt(&self, o: *const Mixed) -> i32 { - return if ((self.v) < ((*o).v)) { 8 } else { 0 }; + pub unsafe fn operator_lt(this: *const Self, o: *const Mixed) -> i32 { + return if (((*this).v) < ((*o).v)) { 8 } else { 0 }; } - pub unsafe fn operator_eq(&self, o: *const Mixed) -> i32 { - return if ((self.v) == ((*o).v)) { 9 } else { 0 }; + pub unsafe fn operator_eq(this: *const Self, o: *const Mixed) -> i32 { + return if (((*this).v) == ((*o).v)) { 9 } else { 0 }; } } impl std::cmp::Ord for Mixed { @@ -165,11 +165,11 @@ pub struct MyBool { pub value: bool, } impl MyBool { - pub unsafe fn construct(&mut self, mut v: bool) { - (&raw mut self.value).write(v); + pub unsafe fn construct(this: *mut Self, mut v: bool) { + (&raw mut (*this).value).write(v); } - pub unsafe fn to_bool(&self) -> bool { - return self.value; + pub unsafe fn to_bool(this: *const Self) -> bool { + return (*this).value; } } #[repr(C)] @@ -224,14 +224,14 @@ impl std::cmp::Eq for Boolish {} pub unsafe fn operator_eq_7(mut a: Boolish, mut b: Boolish) -> MyBool { return { let mut __v: MyBool = ::zero_init(); - MyBool::construct(&mut __v, ((a.v) == (b.v))); + MyBool::construct(&raw mut __v, ((a.v) == (b.v))); __v }; } pub unsafe fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { return { let mut __v: MyBool = ::zero_init(); - MyBool::construct(&mut __v, ((a.v) < (b.v))); + MyBool::construct(&raw mut __v, ((a.v) < (b.v))); __v }; } @@ -251,17 +251,17 @@ pub struct RefBool { pub value: bool, } impl RefBool { - pub unsafe fn construct(&mut self, mut v: bool) { - (&raw mut self.value).write(v); + pub unsafe fn construct(this: *mut Self, mut v: bool) { + (&raw mut (*this).value).write(v); } - pub unsafe fn to_bool(&self) -> bool { - return self.value; + pub unsafe fn to_bool(this: *const Self) -> bool { + return (*this).value; } } pub static mut ref_true_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let mut __v: RefBool = ::zero_init(); - RefBool::construct(&mut __v, true); + RefBool::construct(&raw mut __v, true); __v } }); @@ -280,7 +280,7 @@ pub struct RefInt { pub v: i32, } impl RefInt { - pub unsafe fn operator_eq(&self, _a0: *const RefInt) -> *mut RefBool { + pub unsafe fn operator_eq(this: *const Self, _a0: *const RefInt) -> *mut RefBool { return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut ref_true_8)); } } @@ -367,12 +367,12 @@ unsafe fn main_0() -> i32 { ); let mut p: Custom = Custom { v: 5 }; let mut q: Custom = Custom { v: 2 }; - let mut r: Result = (unsafe { Custom::operator_cmp(&p, &q) }); + let mut r: Result = (unsafe { Custom::operator_cmp(&raw const p, &q) }); assert!(((r.r) == (3))); let mut m: Mixed = Mixed { v: 4 }; let mut n: Mixed = Mixed { v: 4 }; - assert!(((unsafe { Mixed::operator_eq(&m, &n,) }) == (9))); - assert!((((unsafe { Mixed::operator_cmp(&m, &n,) }).r) == (0))); + assert!(((unsafe { Mixed::operator_eq(&raw const m, &n,) }) == (9))); + assert!((((unsafe { Mixed::operator_cmp(&raw const m, &n,) }).r) == (0))); let mut ms: [Mixed; 3] = [Mixed { v: 6 }, Mixed { v: 4 }, Mixed { v: 5 }]; { let mut __tmp_1 = { ms.as_mut_ptr() }; @@ -394,7 +394,7 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let _o: *const Mixed = &ms[(1) as usize]; - Mixed::operator_lt(&ms[(0) as usize], _o) + Mixed::operator_lt(&raw const ms[(0) as usize], _o) }) == (8)) ); let mut b1: Boolish = Boolish { v: 1 }; @@ -444,7 +444,11 @@ unsafe fn main_0() -> i32 { ); let mut ri1: RefInt = RefInt { v: 1 }; let mut ri2: RefInt = RefInt { v: 2 }; - assert!((unsafe { RefBool::to_bool(&(*(unsafe { RefInt::operator_eq(&ri1, &ri2,) })),) })); + assert!( + (unsafe { + RefBool::to_bool(&raw const (*(unsafe { RefInt::operator_eq(&raw const ri1, &ri2) }))) + }) + ); let mut ris: [RefInt; 2] = [RefInt { v: 1 }, RefInt { v: 2 }]; assert!( (({ diff --git a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs index 7a34aa7e3a..8da1438508 100644 --- a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs +++ b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs @@ -27,8 +27,8 @@ pub struct S { data_: i32, } impl S { - pub unsafe fn construct(&mut self, mut data: i32) { - (&raw mut self.data_).write(data); + pub unsafe fn construct(this: *mut Self, mut data: i32) { + (&raw mut (*this).data_).write(data); } } impl std::cmp::Ord for S { diff --git a/tests/unit/out/unsafe/operator_compound_assignment_member.rs b/tests/unit/out/unsafe/operator_compound_assignment_member.rs index 3989e666b1..6cc08edab3 100644 --- a/tests/unit/out/unsafe/operator_compound_assignment_member.rs +++ b/tests/unit/out/unsafe/operator_compound_assignment_member.rs @@ -21,49 +21,49 @@ pub struct S { pub v: u32, } impl S { - pub unsafe fn operator_assign_1(&mut self, mut n: u32) -> *mut S { - self.v = n; - return &mut (*(self as *mut S)); + pub unsafe fn operator_assign_1(this: *mut Self, mut n: u32) -> *mut S { + (*this).v = n; + return &mut (*this); } - pub unsafe fn operator_add_assign(&mut self, o: *const S) -> *mut S { - self.v = (self.v).wrapping_add((*o).v); - return &mut (*(self as *mut S)); + pub unsafe fn operator_add_assign(this: *mut Self, o: *const S) -> *mut S { + (*this).v = ((*this).v).wrapping_add((*o).v); + return &mut (*this); } - pub unsafe fn operator_sub_assign(&mut self, o: *const S) -> *mut S { - self.v = (self.v).wrapping_sub((*o).v); - return &mut (*(self as *mut S)); + pub unsafe fn operator_sub_assign(this: *mut Self, o: *const S) -> *mut S { + (*this).v = ((*this).v).wrapping_sub((*o).v); + return &mut (*this); } - pub unsafe fn operator_mul_assign(&mut self, o: *const S) -> *mut S { - self.v = (self.v).wrapping_mul((*o).v); - return &mut (*(self as *mut S)); + pub unsafe fn operator_mul_assign(this: *mut Self, o: *const S) -> *mut S { + (*this).v = ((*this).v).wrapping_mul((*o).v); + return &mut (*this); } - pub unsafe fn operator_div_assign(&mut self, o: *const S) -> *mut S { - self.v = (self.v).wrapping_div((*o).v); - return &mut (*(self as *mut S)); + pub unsafe fn operator_div_assign(this: *mut Self, o: *const S) -> *mut S { + (*this).v = ((*this).v).wrapping_div((*o).v); + return &mut (*this); } - pub unsafe fn operator_rem_assign(&mut self, o: *const S) -> *mut S { - self.v = (self.v).wrapping_rem((*o).v); - return &mut (*(self as *mut S)); + pub unsafe fn operator_rem_assign(this: *mut Self, o: *const S) -> *mut S { + (*this).v = ((*this).v).wrapping_rem((*o).v); + return &mut (*this); } - pub unsafe fn operator_bitand_assign(&mut self, o: *const S) -> *mut S { - self.v &= (*o).v; - return &mut (*(self as *mut S)); + pub unsafe fn operator_bitand_assign(this: *mut Self, o: *const S) -> *mut S { + (*this).v &= (*o).v; + return &mut (*this); } - pub unsafe fn operator_bitor_assign(&mut self, o: *const S) -> *mut S { - self.v |= (*o).v; - return &mut (*(self as *mut S)); + pub unsafe fn operator_bitor_assign(this: *mut Self, o: *const S) -> *mut S { + (*this).v |= (*o).v; + return &mut (*this); } - pub unsafe fn operator_bitxor_assign(&mut self, o: *const S) -> *mut S { - self.v ^= (*o).v; - return &mut (*(self as *mut S)); + pub unsafe fn operator_bitxor_assign(this: *mut Self, o: *const S) -> *mut S { + (*this).v ^= (*o).v; + return &mut (*this); } - pub unsafe fn operator_shl_assign(&mut self, mut n: i32) -> *mut S { - self.v <<= n; - return &mut (*(self as *mut S)); + pub unsafe fn operator_shl_assign(this: *mut Self, mut n: i32) -> *mut S { + (*this).v <<= n; + return &mut (*this); } - pub unsafe fn operator_shr_assign(&mut self, mut n: i32) -> *mut S { - self.v >>= n; - return &mut (*(self as *mut S)); + pub unsafe fn operator_shr_assign(this: *mut Self, mut n: i32) -> *mut S { + (*this).v >>= n; + return &mut (*this); } } pub fn main() { @@ -75,35 +75,38 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut a: S = S { v: 6_u32 }; let mut b: S = S { v: 4_u32 }; - (unsafe { S::operator_add_assign(&mut a, &b) }); + (unsafe { S::operator_add_assign(&raw mut a, &b) }); assert!(((a.v) == (10_u32))); - (unsafe { S::operator_sub_assign(&mut a, &b) }); + (unsafe { S::operator_sub_assign(&raw mut a, &b) }); assert!(((a.v) == (6_u32))); - (unsafe { S::operator_mul_assign(&mut a, &b) }); + (unsafe { S::operator_mul_assign(&raw mut a, &b) }); assert!(((a.v) == (24_u32))); - (unsafe { S::operator_div_assign(&mut a, &b) }); + (unsafe { S::operator_div_assign(&raw mut a, &b) }); assert!(((a.v) == (6_u32))); - (unsafe { S::operator_rem_assign(&mut a, &b) }); + (unsafe { S::operator_rem_assign(&raw mut a, &b) }); assert!(((a.v) == (2_u32))); - (unsafe { S::operator_bitor_assign(&mut a, &b) }); + (unsafe { S::operator_bitor_assign(&raw mut a, &b) }); assert!(((a.v) == (6_u32))); - (unsafe { S::operator_bitand_assign(&mut a, &b) }); + (unsafe { S::operator_bitand_assign(&raw mut a, &b) }); assert!(((a.v) == (4_u32))); - (unsafe { S::operator_bitxor_assign(&mut a, &b) }); + (unsafe { S::operator_bitxor_assign(&raw mut a, &b) }); assert!(((a.v) == (0_u32))); - (unsafe { S::operator_assign_1(&mut a, 3_u32) }); + (unsafe { S::operator_assign_1(&raw mut a, 3_u32) }); assert!(((a.v) == (3_u32))); - (unsafe { S::operator_shl_assign(&mut a, 2) }); + (unsafe { S::operator_shl_assign(&raw mut a, 2) }); assert!(((a.v) == (12_u32))); - (unsafe { S::operator_shr_assign(&mut a, 1) }); + (unsafe { S::operator_shr_assign(&raw mut a, 1) }); assert!(((a.v) == (6_u32))); (unsafe { let _o: *const S = &b; - S::operator_add_assign(&mut (*(unsafe { S::operator_add_assign(&mut a, &b) })), _o) + S::operator_add_assign( + &raw mut (*(unsafe { S::operator_add_assign(&raw mut a, &b) })), + _o, + ) }); assert!(((a.v) == (14_u32))); let mut c: S = S { v: 0_u32 }; - c = (*(unsafe { S::operator_assign_1(&mut a, 1_u32) })); + c = (*(unsafe { S::operator_assign_1(&raw mut a, 1_u32) })); assert!(((a.v) == (1_u32))); assert!(((c.v) == (1_u32))); return 0; diff --git a/tests/unit/out/unsafe/operator_less_than.rs b/tests/unit/out/unsafe/operator_less_than.rs index 6f57bf5217..5bf2faffa5 100644 --- a/tests/unit/out/unsafe/operator_less_than.rs +++ b/tests/unit/out/unsafe/operator_less_than.rs @@ -22,17 +22,17 @@ pub struct Pair { pub y: i32, } impl Pair { - pub unsafe fn operator_lt(&mut self, other: *const Pair) -> bool { - return ((self.x) < ((*other).x)) - || (((self.x) == ((*other).x)) && ((self.y) < ((*other).y))); + pub unsafe fn operator_lt(this: *mut Self, other: *const Pair) -> bool { + return (((*this).x) < ((*other).x)) + || ((((*this).x) == ((*other).x)) && (((*this).y) < ((*other).y))); } } impl std::cmp::Ord for Pair { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if Pair::operator_lt(&mut *(&raw const *self).cast_mut(), other as *const Pair) { + if Pair::operator_lt((&raw const *self).cast_mut(), other as *const Pair) { std::cmp::Ordering::Less - } else if Pair::operator_lt(&mut *(&raw const *other).cast_mut(), self as *const Pair) { + } else if Pair::operator_lt((&raw const *other).cast_mut(), self as *const Pair) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -48,8 +48,8 @@ impl std::cmp::PartialOrd for Pair { impl std::cmp::PartialEq for Pair { fn eq(&self, other: &Self) -> bool { unsafe { - !(Pair::operator_lt(&mut *(&raw const *self).cast_mut(), other as *const Pair)) - && !(Pair::operator_lt(&mut *(&raw const *other).cast_mut(), self as *const Pair)) + !(Pair::operator_lt((&raw const *self).cast_mut(), other as *const Pair)) + && !(Pair::operator_lt((&raw const *other).cast_mut(), self as *const Pair)) } } } @@ -63,7 +63,7 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut pair1: Pair = Pair { x: 1, y: 2 }; let mut pair2: Pair = Pair { x: 1, y: 3 }; - assert!((unsafe { Pair::operator_lt(&mut pair1, &pair2,) })); + assert!((unsafe { Pair::operator_lt(&raw mut pair1, &pair2,) })); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_logical_member.rs b/tests/unit/out/unsafe/operator_logical_member.rs index 562497a560..839cbe90ce 100644 --- a/tests/unit/out/unsafe/operator_logical_member.rs +++ b/tests/unit/out/unsafe/operator_logical_member.rs @@ -21,14 +21,14 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn operator_not(&self) -> bool { - return ((self.v) == (0)); + pub unsafe fn operator_not(this: *const Self) -> bool { + return (((*this).v) == (0)); } - pub unsafe fn operator_and(&self, o: *const S) -> bool { - return ((self.v) != (0)) && (((*o).v) != (0)); + pub unsafe fn operator_and(this: *const Self, o: *const S) -> bool { + return (((*this).v) != (0)) && (((*o).v) != (0)); } - pub unsafe fn operator_or(&self, o: *const S) -> bool { - return ((self.v) != (0)) || (((*o).v) != (0)); + pub unsafe fn operator_or(this: *const Self, o: *const S) -> bool { + return (((*this).v) != (0)) || (((*o).v) != (0)); } } pub fn main() { @@ -40,20 +40,20 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut t: S = S { v: 1 }; let mut f: S = S { v: 0 }; - assert!((unsafe { S::operator_not(&f,) })); - assert!(!(unsafe { S::operator_not(&t,) })); + assert!((unsafe { S::operator_not(&raw const f,) })); + assert!(!(unsafe { S::operator_not(&raw const t,) })); assert!( (unsafe { let _o: *const S = &t; - S::operator_and(&t, _o) + S::operator_and(&raw const t, _o) }) ); - assert!(!(unsafe { S::operator_and(&t, &f,) })); - assert!((unsafe { S::operator_or(&t, &f,) })); + assert!(!(unsafe { S::operator_and(&raw const t, &f,) })); + assert!((unsafe { S::operator_or(&raw const t, &f,) })); assert!( !(unsafe { let _o: *const S = &f; - S::operator_or(&f, _o) + S::operator_or(&raw const f, _o) }) ); return 0; diff --git a/tests/unit/out/unsafe/operator_member_pointer_member.rs b/tests/unit/out/unsafe/operator_member_pointer_member.rs index 1da1aa4c95..acd45f374d 100644 --- a/tests/unit/out/unsafe/operator_member_pointer_member.rs +++ b/tests/unit/out/unsafe/operator_member_pointer_member.rs @@ -55,20 +55,20 @@ pub struct S { pub inner: Inner, } impl S { - pub unsafe fn operator_index_1(&mut self, mut i: i32) -> *mut i32 { - return &mut self.data[(i) as usize]; + pub unsafe fn operator_index_1(this: *mut Self, mut i: i32) -> *mut i32 { + return &mut (*this).data[(i) as usize]; } - pub unsafe fn operator_index_2(&self, mut i: i32) -> *const i32 { - return &self.data[(i) as usize]; + pub unsafe fn operator_index_2(this: *const Self, mut i: i32) -> *const i32 { + return &(*this).data[(i) as usize]; } - pub unsafe fn operator_deref(&mut self) -> *mut Inner { - return &mut self.inner; + pub unsafe fn operator_deref(this: *mut Self) -> *mut Inner { + return &mut (*this).inner; } - pub unsafe fn operator_arrow(&mut self) -> *mut Inner { - return (&mut self.inner as *mut Inner); + pub unsafe fn operator_arrow(this: *mut Self) -> *mut Inner { + return (&mut (*this).inner as *mut Inner); } - pub unsafe fn operator_addr(&mut self) -> *mut i32 { - return (&mut self.data[(0) as usize] as *mut i32); + pub unsafe fn operator_addr(this: *mut Self) -> *mut i32 { + return (&mut (*this).data[(0) as usize] as *mut i32); } } pub fn main() { @@ -82,17 +82,17 @@ unsafe fn main_0() -> i32 { data: [1, 2, 3], inner: Inner { x: 9 }, }; - assert!(((*(unsafe { S::operator_index_1(&mut s, 1,) })) == (2))); - (*(unsafe { S::operator_index_1(&mut s, 1) })) = 20; - assert!(((*(unsafe { S::operator_index_1(&mut s, 1,) })) == (20))); + assert!(((*(unsafe { S::operator_index_1(&raw mut s, 1,) })) == (2))); + (*(unsafe { S::operator_index_1(&raw mut s, 1) })) = 20; + assert!(((*(unsafe { S::operator_index_1(&raw mut s, 1,) })) == (20))); let cs: *const S = &s; - assert!(((*(unsafe { S::operator_index_2(&(*cs), 2,) })) == (3))); - assert!((((*(unsafe { S::operator_deref(&mut s,) })).x) == (9))); - (*(unsafe { S::operator_deref(&mut s) })).x = 10; - assert!((((*(unsafe { S::operator_arrow(&mut s,) })).x) == (10))); - (*(unsafe { S::operator_arrow(&mut s) })).x = 11; + assert!(((*(unsafe { S::operator_index_2(&raw const (*cs), 2,) })) == (3))); + assert!((((*(unsafe { S::operator_deref(&raw mut s,) })).x) == (9))); + (*(unsafe { S::operator_deref(&raw mut s) })).x = 10; + assert!((((*(unsafe { S::operator_arrow(&raw mut s,) })).x) == (10))); + (*(unsafe { S::operator_arrow(&raw mut s) })).x = 11; assert!(((s.inner.x) == (11))); - let mut p: *mut i32 = (unsafe { S::operator_addr(&mut s) }); + let mut p: *mut i32 = (unsafe { S::operator_addr(&raw mut s) }); assert!(((*p) == (1))); (*p) = 5; assert!(((s.data[(0) as usize]) == (5))); diff --git a/tests/unit/out/unsafe/operator_other_member.rs b/tests/unit/out/unsafe/operator_other_member.rs index c20b77e1cd..06b1da4f26 100644 --- a/tests/unit/out/unsafe/operator_other_member.rs +++ b/tests/unit/out/unsafe/operator_other_member.rs @@ -40,25 +40,25 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn operator_call_1(&self) -> i32 { - return self.v; + pub unsafe fn operator_call_1(this: *const Self) -> i32 { + return (*this).v; } - pub unsafe fn operator_call_2(&self, mut a: i32) -> i32 { - return ((self.v) + (a)); + pub unsafe fn operator_call_2(this: *const Self, mut a: i32) -> i32 { + return (((*this).v) + (a)); } - pub unsafe fn operator_call_3(&self, mut a: i32, mut b: i32) -> i32 { - return (((self.v) + (a)) + (b)); + pub unsafe fn operator_call_3(this: *const Self, mut a: i32, mut b: i32) -> i32 { + return ((((*this).v) + (a)) + (b)); } - pub unsafe fn operator_comma(&self, o: *const S) -> S { + pub unsafe fn operator_comma(this: *const Self, o: *const S) -> S { return S { - v: (((self.v) * (10)) + ((*o).v)), + v: ((((*this).v) * (10)) + ((*o).v)), }; } - pub unsafe fn to_i32(&self) -> i32 { - return self.v; + pub unsafe fn to_i32(this: *const Self) -> i32 { + return (*this).v; } - pub unsafe fn to_bool(&self) -> bool { - return ((self.v) != (0)); + pub unsafe fn to_bool(this: *const Self) -> bool { + return (((*this).v) != (0)); } } pub fn main() { @@ -70,22 +70,22 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut s: S = S { v: 3 }; let mut t: S = S { v: 4 }; - assert!(((unsafe { S::operator_call_1(&s,) }) == (3))); - assert!(((unsafe { S::operator_call_2(&s, 1,) }) == (4))); - assert!(((unsafe { S::operator_call_3(&s, 1, 2,) }) == (6))); - assert!((((unsafe { S::operator_comma(&s, &t,) }).v) == (34))); - let mut i: i32 = (unsafe { S::to_i32(&s) }); + assert!(((unsafe { S::operator_call_1(&raw const s,) }) == (3))); + assert!(((unsafe { S::operator_call_2(&raw const s, 1,) }) == (4))); + assert!(((unsafe { S::operator_call_3(&raw const s, 1, 2,) }) == (6))); + assert!((((unsafe { S::operator_comma(&raw const s, &t,) }).v) == (34))); + let mut i: i32 = (unsafe { S::to_i32(&raw const s) }); assert!(((i) == (3))); - assert!((((unsafe { S::to_i32(&s,) }) + (1)) == (4))); - if (unsafe { S::to_bool(&s) }) { - assert!((unsafe { S::to_bool(&s,) })); + assert!((((unsafe { S::to_i32(&raw const s,) }) + (1)) == (4))); + if (unsafe { S::to_bool(&raw const s) }) { + assert!((unsafe { S::to_bool(&raw const s,) })); } else { assert!(false); } let mut z: S = S { v: 0 }; - assert!((unsafe { S::to_bool(&s,) })); - assert!(!(unsafe { S::to_bool(&z,) })); - assert!((unsafe { S::to_bool(&s,) }) && (!(unsafe { S::to_bool(&z,) }))); + assert!((unsafe { S::to_bool(&raw const s,) })); + assert!(!(unsafe { S::to_bool(&raw const z,) })); + assert!((unsafe { S::to_bool(&raw const s,) }) && (!(unsafe { S::to_bool(&raw const z,) }))); let mut st: Static = ::default(); assert!(((unsafe { Static::operator_call(6, 7,) }) == (42))); assert!(((unsafe { S::operator_call_1(&S { v: 5 },) }) == (5))); diff --git a/tests/unit/out/unsafe/operator_overloads.rs b/tests/unit/out/unsafe/operator_overloads.rs index fc09de884e..297a4a697c 100644 --- a/tests/unit/out/unsafe/operator_overloads.rs +++ b/tests/unit/out/unsafe/operator_overloads.rs @@ -21,26 +21,26 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn operator_eq_1(&self, mut o: i32) -> i32 { - return if ((self.v) == (o)) { 1 } else { 0 }; + pub unsafe fn operator_eq_1(this: *const Self, mut o: i32) -> i32 { + return if (((*this).v) == (o)) { 1 } else { 0 }; } - pub unsafe fn operator_eq_2(&self, mut o: i64) -> i32 { - return if ((self.v as i64) == (o)) { 2 } else { 0 }; + pub unsafe fn operator_eq_2(this: *const Self, mut o: i64) -> i32 { + return if (((*this).v as i64) == (o)) { 2 } else { 0 }; } - pub unsafe fn operator_eq_3(&self, mut o: f64) -> i32 { - return if ((self.v as f64) == (o)) { 3 } else { 0 }; + pub unsafe fn operator_eq_3(this: *const Self, mut o: f64) -> i32 { + return if (((*this).v as f64) == (o)) { 3 } else { 0 }; } - pub unsafe fn operator_add(&self, o: *const S) -> i32 { - return ((self.v) + ((*o).v)); + pub unsafe fn operator_add(this: *const Self, o: *const S) -> i32 { + return (((*this).v) + ((*o).v)); } - pub unsafe fn operator_sub(&self, mut o: S) -> i32 { - return ((self.v) - (o.v)); + pub unsafe fn operator_sub(this: *const Self, mut o: S) -> i32 { + return (((*this).v) - (o.v)); } - pub unsafe fn operator_mul_6(&self, o: *const S) -> i32 { - return ((self.v) * ((*o).v)); + pub unsafe fn operator_mul_6(this: *const Self, o: *const S) -> i32 { + return (((*this).v) * ((*o).v)); } - pub unsafe fn operator_mul_7(&self, mut o: i32) -> i32 { - return (((self.v) * (o)) + (1)); + pub unsafe fn operator_mul_7(this: *const Self, mut o: i32) -> i32 { + return ((((*this).v) * (o)) + (1)); } } pub unsafe fn operator_div_0(a: *const S, b: *const S) -> i32 { @@ -70,14 +70,14 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut s: S = S { v: 6 }; let mut t: S = S { v: 4 }; - assert!(((unsafe { S::operator_eq_1(&s, 6,) }) == (1))); - assert!(((unsafe { S::operator_eq_2(&s, 6_i64,) }) == (2))); - assert!(((unsafe { S::operator_eq_3(&s, 6_f64,) }) == (3))); - assert!(((unsafe { S::operator_eq_1(&s, 7,) }) == (0))); - assert!(((unsafe { S::operator_add(&s, &t,) }) == (10))); - assert!(((unsafe { S::operator_sub(&s, t,) }) == (2))); - assert!(((unsafe { S::operator_mul_6(&s, &t,) }) == (24))); - assert!(((unsafe { S::operator_mul_7(&s, 2,) }) == (13))); + assert!(((unsafe { S::operator_eq_1(&raw const s, 6,) }) == (1))); + assert!(((unsafe { S::operator_eq_2(&raw const s, 6_i64,) }) == (2))); + assert!(((unsafe { S::operator_eq_3(&raw const s, 6_f64,) }) == (3))); + assert!(((unsafe { S::operator_eq_1(&raw const s, 7,) }) == (0))); + assert!(((unsafe { S::operator_add(&raw const s, &t,) }) == (10))); + assert!(((unsafe { S::operator_sub(&raw const s, t,) }) == (2))); + assert!(((unsafe { S::operator_mul_6(&raw const s, &t,) }) == (24))); + assert!(((unsafe { S::operator_mul_7(&raw const s, 2,) }) == (13))); assert!( ((unsafe { let _a: *const S = &s; diff --git a/tests/unit/out/unsafe/operator_qualifiers.rs b/tests/unit/out/unsafe/operator_qualifiers.rs index af429253b9..41a39f0738 100644 --- a/tests/unit/out/unsafe/operator_qualifiers.rs +++ b/tests/unit/out/unsafe/operator_qualifiers.rs @@ -21,32 +21,32 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn operator_add_1(&mut self, mut a: i32) -> i32 { - return ((self.v) + (a)); + pub unsafe fn operator_add_1(this: *mut Self, mut a: i32) -> i32 { + return (((*this).v) + (a)); } - pub unsafe fn operator_add_2(&self, mut a: i32) -> i32 { - return (((self.v) + (a)) + (1)); + pub unsafe fn operator_add_2(this: *const Self, mut a: i32) -> i32 { + return ((((*this).v) + (a)) + (1)); } - pub unsafe fn operator_add_3(&mut self, mut a: i32) -> i32 { - return (((self.v) + (a)) + (2)); + pub unsafe fn operator_add_3(this: *mut Self, mut a: i32) -> i32 { + return ((((*this).v) + (a)) + (2)); } - pub unsafe fn operator_sub_4(&mut self, mut a: i32) -> i32 { - return ((self.v) - (a)); + pub unsafe fn operator_sub_4(this: *mut Self, mut a: i32) -> i32 { + return (((*this).v) - (a)); } - pub unsafe fn operator_sub_5(&mut self, mut a: i32) -> i32 { - return (((self.v) - (a)) - (1)); + pub unsafe fn operator_sub_5(this: *mut Self, mut a: i32) -> i32 { + return ((((*this).v) - (a)) - (1)); } - pub unsafe fn operator_mul_6(&self, mut a: i32) -> i32 { - return ((self.v) * (a)); + pub unsafe fn operator_mul_6(this: *const Self, mut a: i32) -> i32 { + return (((*this).v) * (a)); } - pub unsafe fn operator_mul_7(&self, mut a: i32) -> i32 { - return (((self.v) * (a)) * (2)); + pub unsafe fn operator_mul_7(this: *const Self, mut a: i32) -> i32 { + return ((((*this).v) * (a)) * (2)); } - pub unsafe fn operator_index_8(&mut self, mut i: i32) -> i32 { - return ((self.v) + (i)); + pub unsafe fn operator_index_8(this: *mut Self, mut i: i32) -> i32 { + return (((*this).v) + (i)); } - pub unsafe fn operator_index_9(&self, mut i: i32) -> i32 { - return (((self.v) + (i)) + (100)); + pub unsafe fn operator_index_9(this: *const Self, mut i: i32) -> i32 { + return ((((*this).v) + (i)) + (100)); } } pub fn main() { @@ -59,16 +59,16 @@ unsafe fn main_0() -> i32 { let mut s: S = S { v: 10 }; let cs: S = S { v: 10 }; let mut vs: S = S { v: 10 }; - assert!(((unsafe { S::operator_add_1(&mut s, 1,) }) == (11))); - assert!(((unsafe { S::operator_add_2(&cs, 1,) }) == (12))); - assert!(((unsafe { S::operator_add_3(&mut vs, 1,) }) == (13))); - assert!(((unsafe { S::operator_sub_4(&mut s, 1,) }) == (9))); + assert!(((unsafe { S::operator_add_1(&raw mut s, 1,) }) == (11))); + assert!(((unsafe { S::operator_add_2(&raw const cs, 1,) }) == (12))); + assert!(((unsafe { S::operator_add_3(&raw mut vs, 1,) }) == (13))); + assert!(((unsafe { S::operator_sub_4(&raw mut s, 1,) }) == (9))); assert!(((unsafe { S::operator_sub_5(&mut S { v: 10 }, 1,) }) == (8))); - assert!(((unsafe { S::operator_mul_6(&s, 3,) }) == (30))); - assert!(((unsafe { S::operator_mul_6(&cs, 3,) }) == (30))); + assert!(((unsafe { S::operator_mul_6(&raw const s, 3,) }) == (30))); + assert!(((unsafe { S::operator_mul_6(&raw const cs, 3,) }) == (30))); assert!(((unsafe { S::operator_mul_7(&S { v: 10 }, 3,) }) == (60))); - assert!(((unsafe { S::operator_index_8(&mut s, 2,) }) == (12))); - assert!(((unsafe { S::operator_index_9(&cs, 2,) }) == (112))); + assert!(((unsafe { S::operator_index_8(&raw mut s, 2,) }) == (12))); + assert!(((unsafe { S::operator_index_9(&raw const cs, 2,) }) == (112))); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_three_way.rs b/tests/unit/out/unsafe/operator_three_way.rs index eb74b41521..001ceea13f 100644 --- a/tests/unit/out/unsafe/operator_three_way.rs +++ b/tests/unit/out/unsafe/operator_three_way.rs @@ -21,17 +21,17 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn operator_cmp(&self, o: *const S) -> std::cmp::Ordering { - if ((self.v) < ((*o).v)) { + pub unsafe fn operator_cmp(this: *const Self, o: *const S) -> std::cmp::Ordering { + if (((*this).v) < ((*o).v)) { return libcc2rs::STRONG_ORDERING_LESS; } - if ((self.v) > ((*o).v)) { + if (((*this).v) > ((*o).v)) { return libcc2rs::STRONG_ORDERING_GREATER; } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(&self, o: *const S) -> bool { - return ((self.v) == ((*o).v)); + pub unsafe fn operator_eq(this: *const Self, o: *const S) -> bool { + return (((*this).v) == ((*o).v)); } } impl std::cmp::Ord for S { @@ -59,12 +59,12 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut a: S = S { v: 1 }; let mut b: S = S { v: 2 }; - assert!((unsafe { S::operator_cmp(&a, &b,) }) == std::cmp::Ordering::Less); - assert!((unsafe { S::operator_cmp(&b, &a,) }) == std::cmp::Ordering::Greater); - assert!((unsafe { S::operator_cmp(&a, &b,) }) != std::cmp::Ordering::Greater); - assert!((unsafe { S::operator_cmp(&b, &a,) }) != std::cmp::Ordering::Less); - assert!(!(unsafe { S::operator_eq(&a, &b,) })); - assert!((unsafe { S::operator_cmp(&a, &b,) }) == libcc2rs::STRONG_ORDERING_LESS); + assert!((unsafe { S::operator_cmp(&raw const a, &b,) }) == std::cmp::Ordering::Less); + assert!((unsafe { S::operator_cmp(&raw const b, &a,) }) == std::cmp::Ordering::Greater); + assert!((unsafe { S::operator_cmp(&raw const a, &b,) }) != std::cmp::Ordering::Greater); + assert!((unsafe { S::operator_cmp(&raw const b, &a,) }) != std::cmp::Ordering::Less); + assert!(!(unsafe { S::operator_eq(&raw const a, &b,) })); + assert!((unsafe { S::operator_cmp(&raw const a, &b,) }) == libcc2rs::STRONG_ORDERING_LESS); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_traits.rs b/tests/unit/out/unsafe/operator_traits.rs index ff4e03fc64..c5e3127926 100644 --- a/tests/unit/out/unsafe/operator_traits.rs +++ b/tests/unit/out/unsafe/operator_traits.rs @@ -21,8 +21,8 @@ pub struct Lt { pub v: i32, } impl Lt { - pub unsafe fn operator_lt(&self, o: *const Lt) -> bool { - return ((self.v) < ((*o).v)); + pub unsafe fn operator_lt(this: *const Self, o: *const Lt) -> bool { + return (((*this).v) < ((*o).v)); } } impl std::cmp::Ord for Lt { @@ -67,8 +67,8 @@ pub struct Eq { pub v: i32, } impl Eq { - pub unsafe fn operator_eq(&self, o: *const Eq) -> bool { - return ((self.v) == ((*o).v)); + pub unsafe fn operator_eq(this: *const Self, o: *const Eq) -> bool { + return (((*this).v) == ((*o).v)); } } impl std::cmp::PartialEq for Eq { @@ -92,11 +92,11 @@ pub struct Cmp { pub v: i32, } impl Cmp { - pub unsafe fn operator_cmp(&self, o: *const Cmp) -> std::cmp::Ordering { - return std::cmp::Ord::cmp(&(self.v), &((*o).v)); + pub unsafe fn operator_cmp(this: *const Self, o: *const Cmp) -> std::cmp::Ordering { + return std::cmp::Ord::cmp(&((*this).v), &((*o).v)); } - pub unsafe fn operator_eq(&self, o: *const Cmp) -> bool { - return ((self.v) == ((*o).v)); + pub unsafe fn operator_eq(this: *const Self, o: *const Cmp) -> bool { + return (((*this).v) == ((*o).v)); } } impl std::cmp::Ord for Cmp { diff --git a/tests/unit/out/unsafe/overload_mangling.rs b/tests/unit/out/unsafe/overload_mangling.rs index a508eda753..14ba1ffaaf 100644 --- a/tests/unit/out/unsafe/overload_mangling.rs +++ b/tests/unit/out/unsafe/overload_mangling.rs @@ -28,16 +28,16 @@ pub unsafe fn twice_2(mut n: i32) -> i32 { )] pub struct Access_S_ {} impl Access_S_ { - pub unsafe fn get_1(&mut self, mut p: *mut S) -> i32 { + pub unsafe fn get_1(this: *mut Self, mut p: *mut S) -> i32 { return (*p).base; } - pub unsafe fn get_2(&mut self, mut p: *const S) -> i32 { + pub unsafe fn get_2(this: *mut Self, mut p: *const S) -> i32 { return (((*p).base) + (1)); } - pub unsafe fn ref_3(&mut self, r: *mut S) -> i32 { + pub unsafe fn ref_3(this: *mut Self, r: *mut S) -> i32 { return (((*r).base) + (2)); } - pub unsafe fn ref_4(&mut self, r: *const S) -> i32 { + pub unsafe fn ref_4(this: *mut Self, r: *const S) -> i32 { return (((*r).base) + (3)); } } @@ -56,72 +56,84 @@ pub struct S { pub base: i32, } impl S { - pub unsafe fn plain_4(&self, mut x: i32) -> i32 { - return ((self.base) + (x)); + pub unsafe fn plain_4(this: *const Self, mut x: i32) -> i32 { + return (((*this).base) + (x)); } - pub unsafe fn plain_5(&self, mut x: i64) -> i32 { - return (((self.base) + (x as i32)) + (1)); + pub unsafe fn plain_5(this: *const Self, mut x: i64) -> i32 { + return ((((*this).base) + (x as i32)) + (1)); } - pub unsafe fn take_6(&self, x: *mut i32) -> i32 { - return (((self.base) + (*x)) + (1)); + pub unsafe fn take_6(this: *const Self, x: *mut i32) -> i32 { + return ((((*this).base) + (*x)) + (1)); } - pub unsafe fn take_7(&self, x: *mut i32) -> i32 { - return (((self.base) + (*x)) + (2)); + pub unsafe fn take_7(this: *const Self, x: *mut i32) -> i32 { + return ((((*this).base) + (*x)) + (2)); } - pub unsafe fn pick_8(&self, mut p: (i32, i32)) -> i32 { - return ((self.base) + (p.0)); + pub unsafe fn pick_8(this: *const Self, mut p: (i32, i32)) -> i32 { + return (((*this).base) + (p.0)); } - pub unsafe fn pick_9(&self, mut p: (i32, i64)) -> i32 { - return ((self.base) + ((p.1) as i32)); + pub unsafe fn pick_9(this: *const Self, mut p: (i32, i64)) -> i32 { + return (((*this).base) + ((p.1) as i32)); } - pub unsafe fn apply_10(&self, mut f: Option, mut x: i32) -> i32 { + pub unsafe fn apply_10( + this: *const Self, + mut f: Option, + mut x: i32, + ) -> i32 { (unsafe { (f).unwrap()((&mut x as *mut i32)) }); - return ((self.base) + (x)); + return (((*this).base) + (x)); } - pub unsafe fn apply_11(&self, mut f: Option, mut x: i32) -> i32 { + pub unsafe fn apply_11( + this: *const Self, + mut f: Option, + mut x: i32, + ) -> i32 { (unsafe { (f).unwrap()((&mut x as *mut i32), 10) }); - return ((self.base) + (x)); + return (((*this).base) + (x)); } - pub unsafe fn apply_12(&self, mut f: Option i32>, mut x: i32) -> i32 { - return ((self.base) + (unsafe { (f).unwrap()(x) })); + pub unsafe fn apply_12( + this: *const Self, + mut f: Option i32>, + mut x: i32, + ) -> i32 { + return (((*this).base) + (unsafe { (f).unwrap()(x) })); } pub unsafe fn combine_13( - &self, + this: *const Self, p: *const (i32, i64), mut f: Option i32>, mut q: *const i32, mut n: u64, ) -> i32 { - return ((((self.base) + (((*p).1) as i32)) + (unsafe { (f).unwrap()((*q)) })) + return (((((*this).base) + (((*p).1) as i32)) + (unsafe { (f).unwrap()((*q)) })) + (n as i32)); } pub unsafe fn combine_14( - &self, + this: *const Self, p: *const (i32, i32), mut f: Option, mut q: *mut i32, mut n: u64, ) -> i32 { (unsafe { (f).unwrap()(q, (n as i32)) }); - return (((self.base) + ((*p).0)) + (*q)); + return ((((*this).base) + ((*p).0)) + (*q)); } - pub unsafe fn width_1_char(&self, mut x: i32) -> i32 { - return ((self.base) + ((x) * (::std::mem::size_of::() as i32))); + pub unsafe fn width_1_char(this: *const Self, mut x: i32) -> i32 { + return (((*this).base) + ((x) * (::std::mem::size_of::() as i32))); } - pub unsafe fn width_1_int(&self, mut x: i32) -> i32 { - return ((self.base) + ((x) * (::std::mem::size_of::() as i32))); + pub unsafe fn width_1_int(this: *const Self, mut x: i32) -> i32 { + return (((*this).base) + ((x) * (::std::mem::size_of::() as i32))); } - pub unsafe fn scale_2_2(&self, mut x: i32) -> i32 { - return ((self.base) + ((x) * (2))); + pub unsafe fn scale_2_2(this: *const Self, mut x: i32) -> i32 { + return (((*this).base) + ((x) * (2))); } - pub unsafe fn scale_2_3(&self, mut x: i32) -> i32 { - return ((self.base) + ((x) * (3))); + pub unsafe fn scale_2_3(this: *const Self, mut x: i32) -> i32 { + return (((*this).base) + ((x) * (3))); } - pub unsafe fn count_3(&self, mut x: i32) -> i32 { - return (((self.base) + (x)) + (0 as i32)); + pub unsafe fn count_3(this: *const Self, mut x: i32) -> i32 { + return ((((*this).base) + (x)) + (0 as i32)); } - pub unsafe fn count_3_int_long(&self, mut x: i32) -> i32 { - return (((self.base) + (x)) + (2 as i32)); + pub unsafe fn count_3_int_long(this: *const Self, mut x: i32) -> i32 { + return ((((*this).base) + (x)) + (2 as i32)); } } #[repr(C)] @@ -146,49 +158,61 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut s: S = S { base: 100 }; - assert!(((unsafe { S::width_1_char(&s, 3,) }) == (103))); - assert!(((unsafe { S::width_1_int(&s, 3,) }) == (112))); - assert!(((unsafe { S::scale_2_2(&s, 5,) }) == (110))); - assert!(((unsafe { S::scale_2_3(&s, 5,) }) == (115))); - assert!(((unsafe { S::count_3(&s, 1,) }) == (101))); - assert!(((unsafe { S::count_3_int_long(&s, 1,) }) == (103))); - assert!(((unsafe { S::plain_4(&s, 1,) }) == (101))); - assert!(((unsafe { S::plain_5(&s, 1_i64,) }) == (102))); + assert!(((unsafe { S::width_1_char(&raw const s, 3,) }) == (103))); + assert!(((unsafe { S::width_1_int(&raw const s, 3,) }) == (112))); + assert!(((unsafe { S::scale_2_2(&raw const s, 5,) }) == (110))); + assert!(((unsafe { S::scale_2_3(&raw const s, 5,) }) == (115))); + assert!(((unsafe { S::count_3(&raw const s, 1,) }) == (101))); + assert!(((unsafe { S::count_3_int_long(&raw const s, 1,) }) == (103))); + assert!(((unsafe { S::plain_4(&raw const s, 1,) }) == (101))); + assert!(((unsafe { S::plain_5(&raw const s, 1_i64,) }) == (102))); let mut y: i32 = 1; - assert!(((unsafe { S::take_6(&s, &mut y,) }) == (102))); + assert!(((unsafe { S::take_6(&raw const s, &mut y,) }) == (102))); assert!( ((unsafe { let mut _x: i32 = 5; - S::take_7(&s, &mut _x) + S::take_7(&raw const s, &mut _x) }) == (107)) ); - assert!(((unsafe { S::pick_8(&s, (1, 2),) }) == (101))); - assert!(((unsafe { S::pick_9(&s, (1, 2_i64),) }) == (102))); - assert!(((unsafe { S::apply_10(&s, Some(inc_0), 1,) }) == (102))); - assert!(((unsafe { S::apply_11(&s, Some(add_1), 1,) }) == (111))); - assert!(((unsafe { S::apply_12(&s, Some(twice_2), 3,) }) == (106))); + assert!(((unsafe { S::pick_8(&raw const s, (1, 2),) }) == (101))); + assert!(((unsafe { S::pick_9(&raw const s, (1, 2_i64),) }) == (102))); + assert!(((unsafe { S::apply_10(&raw const s, Some(inc_0), 1,) }) == (102))); + assert!(((unsafe { S::apply_11(&raw const s, Some(add_1), 1,) }) == (111))); + assert!(((unsafe { S::apply_12(&raw const s, Some(twice_2), 3,) }) == (106))); let c: i32 = 3; assert!( ((unsafe { let mut _p: (i32, i64) = (1, 2_i64); - S::combine_13(&s, &mut _p, Some(twice_2), (&c as *const i32), 4_u64) + S::combine_13( + &raw const s, + &mut _p, + Some(twice_2), + (&c as *const i32), + 4_u64, + ) }) == (112)) ); let mut z: i32 = 1; assert!( ((unsafe { let mut _p: (i32, i32) = (1, 2); - S::combine_14(&s, &mut _p, Some(add_1), (&mut z as *mut i32), 5_u64) + S::combine_14( + &raw const s, + &mut _p, + Some(add_1), + (&mut z as *mut i32), + 5_u64, + ) }) == (107)) ); assert!(((z) == (6))); let mut a: Access_S_ = ::default(); let mut cs: *const S = (&mut s as *mut S).cast_const(); let cr: *const S = &s; - assert!(((unsafe { Access_S_::get_1(&mut a, (&mut s as *mut S),) }) == (100))); - assert!(((unsafe { Access_S_::get_2(&mut a, cs,) }) == (101))); - assert!(((unsafe { Access_S_::ref_3(&mut a, &mut s,) }) == (102))); - assert!(((unsafe { Access_S_::ref_4(&mut a, cr,) }) == (103))); + assert!(((unsafe { Access_S_::get_1(&raw mut a, (&mut s as *mut S),) }) == (100))); + assert!(((unsafe { Access_S_::get_2(&raw mut a, cs,) }) == (101))); + assert!(((unsafe { Access_S_::ref_3(&raw mut a, &mut s,) }) == (102))); + assert!(((unsafe { Access_S_::ref_4(&raw mut a, cr,) }) == (103))); let mut b: Box_ = Box_ { v: 4 }; assert!(((b.v) == (4))); return 0; diff --git a/tests/unit/out/unsafe/pair_converting_construction.rs b/tests/unit/out/unsafe/pair_converting_construction.rs index 67b176c8fe..9228e4c5cc 100644 --- a/tests/unit/out/unsafe/pair_converting_construction.rs +++ b/tests/unit/out/unsafe/pair_converting_construction.rs @@ -23,8 +23,8 @@ pub struct Celsius { pub degrees: i32, } impl Celsius { - pub unsafe fn construct(&mut self, mut d: i32) { - (&raw mut self.degrees).write(d); + pub unsafe fn construct(this: *mut Self, mut d: i32) { + (&raw mut (*this).degrees).write(d); } } #[repr(C)] @@ -44,8 +44,8 @@ pub struct Meters { pub value: i32, } impl Meters { - pub unsafe fn to_i32(&self) -> i32 { - return self.value; + pub unsafe fn to_i32(this: *const Self) -> i32 { + return (*this).value; } } #[repr(C)] @@ -65,8 +65,8 @@ pub struct Label { pub id: i32, } impl Label { - pub unsafe fn construct(&mut self, c: *const Celsius) { - (&raw mut self.id).write((*c).degrees); + pub unsafe fn construct(this: *mut Self, c: *const Celsius) { + (&raw mut (*this).id).write((*c).degrees); } } #[repr(C)] @@ -88,13 +88,13 @@ pub struct Owner { pub copied: i32, } impl Owner { - pub unsafe fn construct_1(&mut self, c: *const Celsius) { - (&raw mut self.taken).write(0); - (&raw mut self.copied).write((*c).degrees); + pub unsafe fn construct_1(this: *mut Self, c: *const Celsius) { + (&raw mut (*this).taken).write(0); + (&raw mut (*this).copied).write((*c).degrees); } - pub unsafe fn construct_2(&mut self, c: *mut Celsius) { - (&raw mut self.taken).write((*c).degrees); - (&raw mut self.copied).write(0); + pub unsafe fn construct_2(this: *mut Self, c: *mut Celsius) { + (&raw mut (*this).taken).write((*c).degrees); + (&raw mut (*this).copied).write(0); } } #[repr(C)] @@ -114,8 +114,8 @@ pub struct Holder { pub value: i32, } impl Holder { - pub unsafe fn construct(&mut self, mut c: Celsius) { - (&raw mut self.value).write(c.degrees); + pub unsafe fn construct(this: *mut Self, mut c: Celsius) { + (&raw mut (*this).value).write(c.degrees); } } #[repr(C)] @@ -127,14 +127,14 @@ pub struct Fallback { pub value: i32, } impl Fallback { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.value).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).value).write(v); } } impl DefaultConstructibleUnsafe for Fallback { - unsafe fn default_constructor(&mut self) { + unsafe fn default_constructor(this: *mut Self) { unsafe { - Fallback::construct(&mut *self, -1_i32); + Fallback::construct(this, -1_i32); } } } @@ -143,7 +143,7 @@ impl Default for Fallback { unsafe { { let mut __v: Fallback = ::zero_init(); - Fallback::construct(&mut __v, -1_i32); + Fallback::construct(&raw mut __v, -1_i32); __v } } @@ -180,14 +180,14 @@ pub struct Observer { pub seen: i32, } impl Observer { - pub unsafe fn construct(&mut self, c: *mut Counter) { - (&raw mut self.seen).write((*c).hits); + pub unsafe fn construct(this: *mut Self, c: *mut Counter) { + (&raw mut (*this).seen).write((*c).hits); (*c).hits.postfix_inc(); } } impl Tag { - pub unsafe fn construct(&mut self, u: *const Celsius) { - (&raw mut self.code).write((((*u).degrees) + (100))); + pub unsafe fn construct(this: *mut Self, u: *const Celsius) { + (&raw mut (*this).code).write((((*u).degrees) + (100))); } } #[repr(C)] @@ -223,10 +223,10 @@ pub struct Name { pub len: i32, } impl Name { - pub unsafe fn construct(&mut self, mut s: *const libc::c_char) { - (&raw mut self.len).write(0); - 'loop_: while ((*s.offset((self.len) as isize)) != 0) { - self.len.prefix_inc(); + pub unsafe fn construct(this: *mut Self, mut s: *const libc::c_char) { + (&raw mut (*this).len).write(0); + 'loop_: while ((*s.offset(((*this).len) as isize)) != 0) { + (*this).len.prefix_inc(); } } } @@ -243,12 +243,12 @@ unsafe fn main_0() -> i32 { let mut from_ints: (Celsius, Celsius) = ( { let mut __v: Celsius = ::zero_init(); - Celsius::construct(&mut __v, 1); + Celsius::construct(&raw mut __v, 1); __v }, { let mut __v: Celsius = ::zero_init(); - Celsius::construct(&mut __v, 2); + Celsius::construct(&raw mut __v, 2); __v }, ); @@ -256,8 +256,8 @@ unsafe fn main_0() -> i32 { assert!(((from_ints.1.degrees) == (2))); let mut m: Meters = Meters { value: 7 }; let mut from_operators: (i32, i64) = ( - (unsafe { Meters::to_i32(&m) }), - ((unsafe { Meters::to_i32(&m) }) as i64), + (unsafe { Meters::to_i32(&raw const m) }), + ((unsafe { Meters::to_i32(&raw const m) }) as i64), ); assert!(((from_operators.0) == (7))); assert!(((from_operators.1) == (7_i64))); @@ -283,12 +283,12 @@ unsafe fn main_0() -> i32 { let mut celsius: (Celsius, Celsius) = ( { let mut __v: Celsius = ::zero_init(); - Celsius::construct(&mut __v, 10); + Celsius::construct(&raw mut __v, 10); __v }, { let mut __v: Celsius = ::zero_init(); - Celsius::construct(&mut __v, 11); + Celsius::construct(&raw mut __v, 11); __v }, ); @@ -302,12 +302,12 @@ unsafe fn main_0() -> i32 { let mut from_moved_record_pair: (Label, Owner) = match ((&mut ( { let mut __v: Celsius = ::zero_init(); - Celsius::construct(&mut __v, 12); + Celsius::construct(&raw mut __v, 12); __v }, { let mut __v: Celsius = ::zero_init(); - Celsius::construct(&mut __v, 13); + Celsius::construct(&raw mut __v, 13); __v }, ) as *mut (Celsius, Celsius)),) @@ -329,12 +329,12 @@ unsafe fn main_0() -> i32 { let mut from_moved_by_value_pair: (Holder, Holder) = match ((&mut ( { let mut __v: Celsius = ::zero_init(); - Celsius::construct(&mut __v, 14); + Celsius::construct(&raw mut __v, 14); __v }, { let mut __v: Celsius = ::zero_init(); - Celsius::construct(&mut __v, 15); + Celsius::construct(&raw mut __v, 15); __v }, ) as *mut (Celsius, Celsius)),) @@ -358,7 +358,7 @@ unsafe fn main_0() -> i32 { let mut forwarded_mutable_ref: (Observer, i32) = ( { let mut __v: Observer = ::zero_init(); - Observer::construct(&mut __v, &mut counter); + Observer::construct(&raw mut __v, &mut counter); __v }, 0, @@ -376,12 +376,12 @@ unsafe fn main_0() -> i32 { let mut forwarded_records: (Label, Owner) = ( { let mut __v: Label = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -41,8 +41,8 @@ pub struct B { pub v: i32, } impl DefaultConstructibleUnsafe for B { - unsafe fn default_constructor(&mut self) { - (&raw mut self.v).write(2); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).v).write(2); } } impl Default for B { @@ -50,7 +50,7 @@ impl Default for B { unsafe { { let mut __v: B = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v } } @@ -73,8 +73,8 @@ pub struct NoDefault { pub v: i32, } impl NoDefault { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } pub unsafe fn used_0(mut x: A) -> i32 { @@ -106,11 +106,11 @@ pub struct S_NoDefault_ { pub v: i32, } impl S_NoDefault_ { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } - pub unsafe fn get(&self, mut t: NoDefault) -> i32 { - return ((self.v) + (t.v)); + pub unsafe fn get(this: *const Self, mut t: NoDefault) -> i32 { + return (((*this).v) + (t.v)); } } pub fn main() { @@ -124,7 +124,7 @@ unsafe fn main_0() -> i32 { ((unsafe { used_0({ let mut __v: A = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }) }) == (1)) @@ -133,7 +133,7 @@ unsafe fn main_0() -> i32 { ((unsafe { used_0({ let mut __v: A = ::zero_init(); - A::construct_1(&mut __v, 5); + A::construct_1(&raw mut __v, 5); __v }) }) == (5)) @@ -142,7 +142,7 @@ unsafe fn main_0() -> i32 { ((unsafe { used_1({ let mut __v: B = ::zero_init(); - DefaultConstructibleUnsafe::default_constructor(&mut __v); + DefaultConstructibleUnsafe::default_constructor(&raw mut __v); __v }) }) == (2)) @@ -152,7 +152,7 @@ unsafe fn main_0() -> i32 { scaled_2( { let mut __v: A = ::zero_init(); - A::construct_1(&mut __v, 3); + A::construct_1(&raw mut __v, 3); __v }, (::std::mem::size_of::() as i32), @@ -164,7 +164,7 @@ unsafe fn main_0() -> i32 { scaled_2( { let mut __v: A = ::zero_init(); - A::construct_1(&mut __v, 3); + A::construct_1(&raw mut __v, 3); __v }, 2, @@ -175,7 +175,7 @@ unsafe fn main_0() -> i32 { ((unsafe { always_given_3({ let mut __v: NoDefault = ::zero_init(); - NoDefault::construct(&mut __v, 3); + NoDefault::construct(&raw mut __v, 3); __v }) }) == (3)) @@ -183,9 +183,9 @@ unsafe fn main_0() -> i32 { object_unsafe!(s, S_NoDefault_(1)); assert!( ((unsafe { - S_NoDefault_::get(&s, { + S_NoDefault_::get(&raw const s, { let mut __v: NoDefault = ::zero_init(); - NoDefault::construct(&mut __v, 4); + NoDefault::construct(&raw mut __v, 4); __v }) }) == (5)) diff --git a/tests/unit/out/unsafe/temporary_field_addr.rs b/tests/unit/out/unsafe/temporary_field_addr.rs index 2fbd73ca9a..6213be8029 100644 --- a/tests/unit/out/unsafe/temporary_field_addr.rs +++ b/tests/unit/out/unsafe/temporary_field_addr.rs @@ -23,8 +23,8 @@ pub struct Inner { pub values: Vec, } impl DefaultConstructibleUnsafe for Inner { - unsafe fn default_constructor(&mut self) { - (&raw mut self.values).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).values).write(Vec::new()); } } #[repr(C)] @@ -46,10 +46,10 @@ pub struct Outer { pub name: [libc::c_char; 8], } impl DefaultConstructibleUnsafe for Outer { - unsafe fn default_constructor(&mut self) { - (&raw mut self.values).write(Vec::new()); - DefaultConstructibleUnsafe::default_constructor(&mut self.inner); - (&raw mut self.name).write([(0 as libc::c_char); 8]); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).values).write(Vec::new()); + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).inner); + (&raw mut (*this).name).write([(0 as libc::c_char); 8]); } } pub unsafe fn make_0(__return: *mut Outer, calls: *mut i32) { @@ -84,7 +84,7 @@ unsafe fn main_0() -> i32 { (unsafe { sum_1( &(*{ - (unsafe { make_0(&mut __tmp_0, &mut calls) }); + (unsafe { make_0(&raw mut __tmp_0, &mut calls) }); &mut __tmp_0 }) .values, @@ -96,7 +96,7 @@ unsafe fn main_0() -> i32 { (unsafe { sum_1( &(*{ - (unsafe { make_0(&mut __tmp_1, &mut calls) }); + (unsafe { make_0(&raw mut __tmp_1, &mut calls) }); &mut __tmp_1 }) .inner @@ -107,7 +107,7 @@ unsafe fn main_0() -> i32 { let mut element: i32 = { let mut __tmp_2: Outer = ::zero_init(); (*{ - (unsafe { make_0(&mut __tmp_2, &mut calls) }); + (unsafe { make_0(&raw mut __tmp_2, &mut calls) }); &mut __tmp_2 }) .values[(((calls) - (2)) as usize)] @@ -116,7 +116,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_3: Outer = ::zero_init(); libc::strlen( ((*{ - (unsafe { make_0(&mut __tmp_3, &mut calls) }); + (unsafe { make_0(&raw mut __tmp_3, &mut calls) }); &mut __tmp_3 }) .name diff --git a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs index 5ab9fda79f..7ccbb9e43c 100644 --- a/tests/unit/out/unsafe/temporary_field_ctor_arg.rs +++ b/tests/unit/out/unsafe/temporary_field_ctor_arg.rs @@ -23,8 +23,8 @@ pub struct Outer { pub values: Vec, } impl DefaultConstructibleUnsafe for Outer { - unsafe fn default_constructor(&mut self) { - (&raw mut self.values).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).values).write(Vec::new()); } } pub unsafe fn make_0(__return: *mut Outer) { @@ -50,8 +50,8 @@ pub struct H { pub last: i32, } impl H { - pub unsafe fn construct(&mut self, values: *const Vec) { - (&raw mut self.last).write((&(*values))[(3_usize)]); + pub unsafe fn construct(this: *mut Self, values: *const Vec) { + (&raw mut (*this).last).write((&(*values))[(3_usize)]); } } pub fn main() { @@ -66,7 +66,7 @@ unsafe fn main_0() -> i32 { H::construct( h, &(*{ - (unsafe { make_0(&mut __tmp_0) }); + (unsafe { make_0(&raw mut __tmp_0) }); &mut __tmp_0 }) .values, diff --git a/tests/unit/out/unsafe/temporary_field_two_args.rs b/tests/unit/out/unsafe/temporary_field_two_args.rs index f7984fa97f..7a3f5dc295 100644 --- a/tests/unit/out/unsafe/temporary_field_two_args.rs +++ b/tests/unit/out/unsafe/temporary_field_two_args.rs @@ -23,8 +23,8 @@ pub struct Inner { pub values: Vec, } impl DefaultConstructibleUnsafe for Inner { - unsafe fn default_constructor(&mut self) { - (&raw mut self.values).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).values).write(Vec::new()); } } #[repr(C)] @@ -45,9 +45,9 @@ pub struct Outer { pub inner: Inner, } impl DefaultConstructibleUnsafe for Outer { - unsafe fn default_constructor(&mut self) { - (&raw mut self.values).write(Vec::new()); - DefaultConstructibleUnsafe::default_constructor(&mut self.inner); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).values).write(Vec::new()); + DefaultConstructibleUnsafe::default_constructor(&raw mut (*this).inner); } } pub unsafe fn make_0(__return: *mut Outer) { @@ -77,12 +77,12 @@ unsafe fn main_0() -> i32 { c"%d\n".as_ptr() as *const libc::c_char, (unsafe { let _a: *const Vec = &(*{ - (unsafe { make_0(&mut __tmp_0) }); + (unsafe { make_0(&raw mut __tmp_0) }); &mut __tmp_0 }) .values; let _b: *const Vec = &(*{ - (unsafe { make_0(&mut __tmp_1) }); + (unsafe { make_0(&raw mut __tmp_1) }); &mut __tmp_1 }) .inner diff --git a/tests/unit/out/unsafe/this.rs b/tests/unit/out/unsafe/this.rs index 2f023161df..754894f450 100644 --- a/tests/unit/out/unsafe/this.rs +++ b/tests/unit/out/unsafe/this.rs @@ -24,86 +24,86 @@ pub struct S { pub self__: *mut S, } impl S { - pub unsafe fn construct_1(&mut self, mut a: i32) { - (&raw mut self.a_).write(a); - (&raw mut self.self__).write(std::ptr::null_mut()); - } - pub unsafe fn construct_2(&mut self, mut a: i32, mut other: *mut S) { - (&raw mut self.a_).write(a); - (&raw mut self.self__).write(std::ptr::null_mut()); - if ((self as *mut S) == (other)) { - self.self__ = std::ptr::null_mut(); + pub unsafe fn construct_1(this: *mut Self, mut a: i32) { + (&raw mut (*this).a_).write(a); + (&raw mut (*this).self__).write(std::ptr::null_mut()); + } + pub unsafe fn construct_2(this: *mut Self, mut a: i32, mut other: *mut S) { + (&raw mut (*this).a_).write(a); + (&raw mut (*this).self__).write(std::ptr::null_mut()); + if ((this) == (other)) { + (*this).self__ = std::ptr::null_mut(); } else { - self.self__ = other; + (*this).self__ = other; } } - pub unsafe fn construct_3(&mut self, mut a: i32, mut other: *const S) { - (&raw mut self.a_).write(a); - (&raw mut self.self__).write(std::ptr::null_mut()); - if (((self as *mut S).cast_const()) == (other)) { - self.self__ = std::ptr::null_mut(); + pub unsafe fn construct_3(this: *mut Self, mut a: i32, mut other: *const S) { + (&raw mut (*this).a_).write(a); + (&raw mut (*this).self__).write(std::ptr::null_mut()); + if (((this).cast_const()) == (other)) { + (*this).self__ = std::ptr::null_mut(); } } - pub unsafe fn returns_this_reference(&mut self) -> *mut S { - return &mut (*(self as *mut S)); + pub unsafe fn returns_this_reference(this: *mut Self) -> *mut S { + return &mut (*this); } - pub unsafe fn returns_this_pointer(&mut self) -> *mut S { - return (self as *mut S); + pub unsafe fn returns_this_pointer(this: *mut Self) -> *mut S { + return this; } - pub unsafe fn inc(&mut self) -> *mut S { - self.a_.postfix_inc(); - return &mut (*(self as *mut S)); + pub unsafe fn inc(this: *mut Self) -> *mut S { + (*this).a_.postfix_inc(); + return &mut (*this); } - pub unsafe fn set_from_this(&mut self) { - self.a_ = ((self.a_) + (1)); + pub unsafe fn set_from_this(this: *mut Self) { + (*this).a_ = (((*this).a_) + (1)); } - pub unsafe fn get(&mut self) -> i32 { - return self.a_; + pub unsafe fn get(this: *mut Self) -> i32 { + return (*this).a_; } - pub unsafe fn twice(&mut self) -> i32 { - return ((unsafe { S::get(self) }) * (2)); + pub unsafe fn twice(this: *mut Self) -> i32 { + return ((unsafe { S::get(this) }) * (2)); } - pub unsafe fn link(&mut self) { - self.self__ = (self as *mut S); + pub unsafe fn link(this: *mut Self) { + (*this).self__ = this; } - pub unsafe fn bump_me(&mut self) { - (unsafe { bump_0((self as *mut S)) }); + pub unsafe fn bump_me(this: *mut Self) { + (unsafe { bump_0(this) }); } - pub unsafe fn cref(&self) -> *const S { - return &(*(self as *const S)); + pub unsafe fn cref(this: *const Self) -> *const S { + return &(*this); } - pub unsafe fn is(&self, mut o: *const S) -> bool { - return ((o) == (self as *const S)); + pub unsafe fn is(this: *const Self, mut o: *const S) -> bool { + return ((o) == (this)); } - pub unsafe fn destroy(&mut self) { + pub unsafe fn destroy(this: *mut Self) { { - let __p = (self as *mut S); + let __p = this; if !__p.is_null() { ::std::mem::drop(Box::from_raw(__p)) } }; } - pub unsafe fn reset(&mut self) { - (*(self as *mut S)) = { + pub unsafe fn reset(this: *mut Self) { + (*this) = { let mut __v: S = ::zero_init(); - S::construct_1(&mut __v, 0); + S::construct_1(&raw mut __v, 0); __v }; } - pub unsafe fn copy_if_different_const(&mut self, mut other: *const S) -> bool { - if (((self as *mut S).cast_const()) == (other)) { + pub unsafe fn copy_if_different_const(this: *mut Self, mut other: *const S) -> bool { + if (((this).cast_const()) == (other)) { return false; } - self.a_ = (*other).a_; - self.self__ = (*other).self__; + (*this).a_ = (*other).a_; + (*this).self__ = (*other).self__; return true; } - pub unsafe fn copy_if_different(&mut self, mut other: *mut S) -> bool { - if ((self as *mut S) == (other)) { + pub unsafe fn copy_if_different(this: *mut Self, mut other: *mut S) -> bool { + if ((this) == (other)) { return false; } - self.a_ = (*other).a_; - self.self__ = (*other).self__; + (*this).a_ = (*other).a_; + (*this).self__ = (*other).self__; return true; } } @@ -127,9 +127,9 @@ pub struct D { pub a_: i32, } impl D { - pub unsafe fn construct(&mut self, mut a: i32) { - (&raw mut self.a_).write(a); - self.a_ *= 2; + pub unsafe fn construct(this: *mut Self, mut a: i32) { + (&raw mut (*this).a_).write(a); + (*this).a_ *= 2; } } pub fn main() { @@ -140,41 +140,43 @@ pub fn main() { } unsafe fn main_0() -> i32 { object_unsafe!(s, S::construct_1(1)); - let ref_: *mut S = (unsafe { S::returns_this_reference(&mut s) }); + let ref_: *mut S = (unsafe { S::returns_this_reference(&raw mut s) }); (*ref_).a_.postfix_inc(); assert!(((s.a_) == (2))); - let mut ptr: *mut S = (unsafe { S::returns_this_pointer(&mut s) }); + let mut ptr: *mut S = (unsafe { S::returns_this_pointer(&raw mut s) }); (*ptr).a_.postfix_inc(); assert!(((s.a_) == (3))); - (unsafe { S::inc(&mut (*(unsafe { S::inc(&mut (*(unsafe { S::inc(&mut s) }))) }))) }); + (unsafe { + S::inc(&raw mut (*(unsafe { S::inc(&raw mut (*(unsafe { S::inc(&raw mut s) }))) }))) + }); assert!(((s.a_) == (6))); - (unsafe { S::set_from_this(&mut s) }); + (unsafe { S::set_from_this(&raw mut s) }); assert!(((s.a_) == (7))); - assert!(((unsafe { S::twice(&mut s,) }) == (14))); - (unsafe { S::link(&mut s) }); + assert!(((unsafe { S::twice(&raw mut s,) }) == (14))); + (unsafe { S::link(&raw mut s) }); assert!(((s.self__) == (&mut s as *mut S))); (*s.self__).a_.postfix_inc(); assert!(((s.a_) == (8))); - (unsafe { S::bump_me(&mut s) }); + (unsafe { S::bump_me(&raw mut s) }); assert!(((s.a_) == (9))); object_unsafe!(d, D(3)); assert!(((d.a_) == (6))); - let cr: *const S = (unsafe { S::cref(&s) }); + let cr: *const S = (unsafe { S::cref(&raw const s) }); assert!((((*cr).a_) == (9))); object_unsafe!(t, S::construct_1(0)); assert!( (unsafe { let _o: *const S = (&mut s as *mut S).cast_const(); - S::is(&s, _o) + S::is(&raw const s, _o) }) ); - assert!(!(unsafe { S::is(&s, (&mut t as *mut S).cast_const(),) })); + assert!(!(unsafe { S::is(&raw const s, (&mut t as *mut S).cast_const(),) })); let mut p: *mut S = { let __p: *mut S = Box::leak(Box::new(::zero_init())); - S::construct_1(&mut *__p, 1); + S::construct_1(__p, 1); __p }; - let mut q: *mut S = (unsafe { S::returns_this_pointer(&mut (*p)) }); + let mut q: *mut S = (unsafe { S::returns_this_pointer(&raw mut (*p)) }); (*q).a_.postfix_inc(); assert!((((*p).a_) == (2))); { @@ -185,30 +187,30 @@ unsafe fn main_0() -> i32 { }; let mut h: *mut S = { let __p: *mut S = Box::leak(Box::new(::zero_init())); - S::construct_1(&mut *__p, 5); + S::construct_1(__p, 5); __p }; - (unsafe { S::destroy(&mut (*h)) }); - (unsafe { S::reset(&mut s) }); + (unsafe { S::destroy(&raw mut (*h)) }); + (unsafe { S::reset(&raw mut s) }); assert!(((s.a_) == (0))); assert!((s.self__).is_null()); assert!( (((unsafe { let _other: *mut S = (&mut s as *mut S); - S::copy_if_different(&mut s, _other) + S::copy_if_different(&raw mut s, _other) }) as i32) == (false as i32)) ); assert!( (((unsafe { let _other: *const S = (&mut s as *mut S).cast_const(); - S::copy_if_different_const(&mut s, _other) + S::copy_if_different_const(&raw mut s, _other) }) as i32) == (false as i32)) ); object_unsafe!(other, S::construct_1(22)); assert!( - (((unsafe { S::copy_if_different(&mut s, (&mut other as *mut S),) }) as i32) + (((unsafe { S::copy_if_different(&raw mut s, (&mut other as *mut S),) }) as i32) == (true as i32)) ); assert!(((s.a_) == (other.a_))); @@ -217,7 +219,7 @@ unsafe fn main_0() -> i32 { assert!(((u.self__) == (&mut s as *mut S))); let s_const: S = { let mut __v: S = ::zero_init(); - S::construct_1(&mut __v, 100); + S::construct_1(&raw mut __v, 100); __v }; object_unsafe!(u1, S::construct_3(1, (&s_const as *const S))); diff --git a/tests/unit/out/unsafe/typedef-anon-struct.rs b/tests/unit/out/unsafe/typedef-anon-struct.rs index efe21ea088..025c03922c 100644 --- a/tests/unit/out/unsafe/typedef-anon-struct.rs +++ b/tests/unit/out/unsafe/typedef-anon-struct.rs @@ -38,8 +38,8 @@ pub struct Outer { pub runs: Vec, } impl DefaultConstructibleUnsafe for Outer { - unsafe fn default_constructor(&mut self) { - (&raw mut self.runs).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).runs).write(Vec::new()); } } pub fn main() { diff --git a/tests/unit/out/unsafe/unboxed_records.rs b/tests/unit/out/unsafe/unboxed_records.rs index 31f9b28835..4bd99e639c 100644 --- a/tests/unit/out/unsafe/unboxed_records.rs +++ b/tests/unit/out/unsafe/unboxed_records.rs @@ -45,13 +45,13 @@ pub struct Counter { pub n: i32, } impl Counter { - pub unsafe fn inc(&mut self) { - self.n.prefix_inc(); + pub unsafe fn inc(this: *mut Self) { + (*this).n.prefix_inc(); } } impl DefaultConstructibleUnsafe for Counter { - unsafe fn default_constructor(&mut self) { - (&raw mut self.n).write(0); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).n).write(0); } } impl Default for Counter { @@ -122,7 +122,7 @@ unsafe fn main_0() -> i32 { (unsafe { set_0((&mut field_addr.b as *mut i32), 7) }); assert!(((field_addr.b) == (7))); object_unsafe!(counter, Counter); - (unsafe { Counter::inc(&mut counter) }); + (unsafe { Counter::inc(&raw mut counter) }); assert!(((counter.n) == (1))); return 0; } diff --git a/tests/unit/out/unsafe/unique_ptr.rs b/tests/unit/out/unsafe/unique_ptr.rs index c0dcabc255..6532b67105 100644 --- a/tests/unit/out/unsafe/unique_ptr.rs +++ b/tests/unit/out/unsafe/unique_ptr.rs @@ -20,8 +20,8 @@ pub struct SafePointer { pub ptr: Option>, } impl SafePointer { - pub unsafe fn inc(&mut self) { - (*self + pub unsafe fn inc(this: *mut Self) { + (*(*this) .ptr .as_deref() .map_or(::std::ptr::null_mut(), |v| v as *const i32 as *mut i32)) @@ -29,8 +29,8 @@ impl SafePointer { } } impl DefaultConstructibleUnsafe for SafePointer { - unsafe fn default_constructor(&mut self) { - (&raw mut self.ptr).write(None); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).ptr).write(None); } } #[repr(C)] @@ -49,9 +49,9 @@ pub struct Pair { pub y: i32, } impl Pair { - pub unsafe fn inc(&mut self, mut k: i32) { - self.x += k; - self.y += k; + pub unsafe fn inc(this: *mut Self, mut k: i32) { + (*this).x += k; + (*this).y += k; } } pub unsafe fn DoStuffWithSafePointer_0(safe_ptr: *mut Option>) { @@ -79,14 +79,14 @@ pub unsafe fn DoStuffWithSafePointer_0(safe_ptr: *mut Option>) }; (unsafe { SafePointer::inc( - &mut (*(*safe_ptr).as_deref().map_or(::std::ptr::null_mut(), |v| { + &raw mut (*(*safe_ptr).as_deref().map_or(::std::ptr::null_mut(), |v| { v as *const SafePointer as *mut SafePointer })), ) }); (unsafe { SafePointer::inc( - &mut (*(*safe_ptr).as_deref().map_or(::std::ptr::null_mut(), |v| { + &raw mut (*(*safe_ptr).as_deref().map_or(::std::ptr::null_mut(), |v| { v as *const SafePointer as *mut SafePointer })), ) @@ -114,7 +114,7 @@ pub unsafe fn DoStuffWithSafePointer_0(safe_ptr: *mut Option>) })); (unsafe { Pair::inc( - &mut (*pair + &raw mut (*pair .as_deref() .map_or(::std::ptr::null_mut(), |v| v as *const Pair as *mut Pair)), 10, @@ -226,7 +226,7 @@ pub unsafe fn RndStuff_2() { assert!((((*p3_0.offset((i) as isize)).y) == (2))); (unsafe { Pair::inc( - &mut (*x3 + &raw mut (*x3 .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Pair) .add((i as usize))), @@ -270,7 +270,7 @@ pub unsafe fn RndStuff_2() { assert!((((*p3_1.offset((i) as isize)).y) == (-2_i32))); (unsafe { Pair::inc( - &mut (*x3 + &raw mut (*x3 .as_deref() .map_or(::std::ptr::null_mut(), |s| s.as_ptr() as *mut Pair) .add((i as usize))), diff --git a/tests/unit/out/unsafe/unique_ptr_const_deref.rs b/tests/unit/out/unsafe/unique_ptr_const_deref.rs index 8b3e2ab11e..6ee90dac3a 100644 --- a/tests/unit/out/unsafe/unique_ptr_const_deref.rs +++ b/tests/unit/out/unsafe/unique_ptr_const_deref.rs @@ -20,8 +20,8 @@ pub struct Holder { pub val: Option>, } impl DefaultConstructibleUnsafe for Holder { - unsafe fn default_constructor(&mut self) { - (&raw mut self.val).write(None); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).val).write(None); } } pub unsafe fn read_val_0(mut h: *const Holder) -> i32 { diff --git a/tests/unit/out/unsafe/unique_ptr_field_reset.rs b/tests/unit/out/unsafe/unique_ptr_field_reset.rs index 9dcd1abc2e..141884ba74 100644 --- a/tests/unit/out/unsafe/unique_ptr_field_reset.rs +++ b/tests/unit/out/unsafe/unique_ptr_field_reset.rs @@ -35,10 +35,10 @@ pub struct Holder { pub n: i32, } impl Holder { - pub unsafe fn set(&mut self, mut p: *mut Data) { + pub unsafe fn set(this: *mut Self, mut p: *mut Data) { { let _a0: *mut Data = p; - self.data = if _a0.is_null() { + (*this).data = if _a0.is_null() { None } else { Some(Box::from_raw(_a0)) @@ -47,9 +47,9 @@ impl Holder { } } impl DefaultConstructibleUnsafe for Holder { - unsafe fn default_constructor(&mut self) { - (&raw mut self.data).write(None); - (&raw mut self.n).write(0_i32); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).data).write(None); + (&raw mut (*this).n).write(0_i32); } } pub fn main() { @@ -77,7 +77,12 @@ unsafe fn main_0() -> i32 { .map_or(::std::ptr::null_mut(), |v| v as *const Data as *mut Data)) .v) == (3)) ); - (unsafe { Holder::set(&mut h, (Box::leak(Box::new(Data { v: 4 })) as *mut Data)) }); + (unsafe { + Holder::set( + &raw mut h, + (Box::leak(Box::new(Data { v: 4 })) as *mut Data), + ) + }); assert!( (((*(*hp) .data diff --git a/tests/unit/out/unsafe/unique_ptr_nested.rs b/tests/unit/out/unsafe/unique_ptr_nested.rs index 3ff0cfe3eb..1d6e66ec66 100644 --- a/tests/unit/out/unsafe/unique_ptr_nested.rs +++ b/tests/unit/out/unsafe/unique_ptr_nested.rs @@ -35,8 +35,8 @@ pub struct Outer { pub inner: Option>, } impl DefaultConstructibleUnsafe for Outer { - unsafe fn default_constructor(&mut self) { - (&raw mut self.inner).write(None); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).inner).write(None); } } pub fn main() { diff --git a/tests/unit/out/unsafe/va_list_field.rs b/tests/unit/out/unsafe/va_list_field.rs index 9536d30ea9..3c13297f45 100644 --- a/tests/unit/out/unsafe/va_list_field.rs +++ b/tests/unit/out/unsafe/va_list_field.rs @@ -38,14 +38,14 @@ pub struct Guard_1 { pub active: bool, } impl Guard_1 { - pub unsafe fn construct(&mut self, val: *mut *const VaArg) { - (&raw mut self.ap).write(val); - (&raw mut self.active).write(true); + pub unsafe fn construct(this: *mut Self, val: *mut *const VaArg) { + (&raw mut (*this).ap).write(val); + (&raw mut (*this).active).write(true); } } impl DestructibleUnsafe for Guard_1 { - unsafe fn destroy(&mut self) { - if self.active {} + unsafe fn destroy(this: *mut Self) { + if (*this).active {} } } pub unsafe fn sum_ptr_2(mut n: i32, __args: Box<[VaArg]>) -> i32 { diff --git a/tests/unit/out/unsafe/vector.rs b/tests/unit/out/unsafe/vector.rs index d24a3c8bed..1e1283e461 100644 --- a/tests/unit/out/unsafe/vector.rs +++ b/tests/unit/out/unsafe/vector.rs @@ -39,9 +39,9 @@ pub struct Foo { pub b: Vec, } impl DefaultConstructibleUnsafe for Foo { - unsafe fn default_constructor(&mut self) { - (&raw mut self.a).write(Vec::new()); - (&raw mut self.b).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).a).write(Vec::new()); + (&raw mut (*this).b).write(Vec::new()); } } #[repr(C)] @@ -61,8 +61,8 @@ pub struct Wrapped { pub v: i32, } impl Wrapped { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.v).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).v).write(v); } } pub unsafe fn exchange_1(x: *mut Vec, y: *mut Vec) { diff --git a/tests/unit/out/unsafe/vector2.rs b/tests/unit/out/unsafe/vector2.rs index f678ef14b3..69dde434ba 100644 --- a/tests/unit/out/unsafe/vector2.rs +++ b/tests/unit/out/unsafe/vector2.rs @@ -34,7 +34,7 @@ pub unsafe fn fn_0(v: *mut Vec, mut v3: Vec) { (v) }))[(0_usize)] = 7; { - v2.assign_from(v); + AssignFromUnsafe::assign_from(&raw mut v2, v); }; (&mut (*v4))[(1_usize)] = 13; assert!(((x) == (6))); diff --git a/tests/unit/out/unsafe/vector_iter_range_ctor.rs b/tests/unit/out/unsafe/vector_iter_range_ctor.rs index 950aef3614..02864261d4 100644 --- a/tests/unit/out/unsafe/vector_iter_range_ctor.rs +++ b/tests/unit/out/unsafe/vector_iter_range_ctor.rs @@ -23,8 +23,8 @@ pub struct Degrees { pub value: i32, } impl Degrees { - pub unsafe fn construct(&mut self, mut v: i32) { - (&raw mut self.value).write(v); + pub unsafe fn construct(this: *mut Self, mut v: i32) { + (&raw mut (*this).value).write(v); } } #[repr(C)] @@ -44,8 +44,8 @@ pub struct Reading { pub raw_: i32, } impl Reading { - pub unsafe fn to_i64(&self) -> i64 { - return ((self.raw_ as i64) * (10_i64)); + pub unsafe fn to_i64(this: *const Self) -> i64 { + return (((*this).raw_ as i64) * (10_i64)); } } pub fn main() { diff --git a/tests/unit/out/unsafe/vector_subscript_direct.rs b/tests/unit/out/unsafe/vector_subscript_direct.rs index 9fb3c0edcc..3811ac10a2 100644 --- a/tests/unit/out/unsafe/vector_subscript_direct.rs +++ b/tests/unit/out/unsafe/vector_subscript_direct.rs @@ -22,8 +22,8 @@ pub struct Point { pub y: i32, } impl Point { - pub unsafe fn sum(&self) -> i32 { - return ((self.x) + (self.y)); + pub unsafe fn sum(this: *const Self) -> i32 { + return (((*this).x) + ((*this).y)); } } #[repr(C)] @@ -44,9 +44,9 @@ pub struct Holder { pub points: Vec, } impl DefaultConstructibleUnsafe for Holder { - unsafe fn default_constructor(&mut self) { - (&raw mut self.values).write(Vec::new()); - (&raw mut self.points).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).values).write(Vec::new()); + (&raw mut (*this).points).write(Vec::new()); } } pub unsafe fn push_and_index_0(v: *mut Vec) -> i32 { @@ -118,7 +118,7 @@ unsafe fn main_0() -> i32 { }; h.points[(0_usize)].y = 5; assert!(((h.values[(1_usize)]) == (6))); - assert!(((unsafe { Point::sum(&h.points[(0_usize)],) }) == (6))); + assert!(((unsafe { Point::sum(&raw const h.points[(0_usize)],) }) == (6))); let mut hp: *mut Holder = (&mut h as *mut Holder); (&mut (*hp)).values[(0_usize)] = (((&mut (*hp)).values[(1_usize)]) + (1)); (&mut (*hp)).points[(0_usize)].x = (&mut (*hp)).values[(0_usize)]; diff --git a/tests/unit/out/unsafe/vector_with_allocator.rs b/tests/unit/out/unsafe/vector_with_allocator.rs index 2998d58793..34293aab10 100644 --- a/tests/unit/out/unsafe/vector_with_allocator.rs +++ b/tests/unit/out/unsafe/vector_with_allocator.rs @@ -19,10 +19,10 @@ use std::rc::Rc; )] pub struct TestAllocator_int_ {} impl TestAllocator_int_ { - pub unsafe fn allocate(&mut self, mut n: usize) -> *mut i32 { + pub unsafe fn allocate(this: *mut Self, mut n: usize) -> *mut i32 { return Box::leak((0..n).map(|_| 0_i32).collect::>()).as_mut_ptr(); } - pub unsafe fn deallocate(&mut self, mut p: *mut i32, mut _a1: usize) { + pub unsafe fn deallocate(this: *mut Self, mut p: *mut i32, mut _a1: usize) { { let __p = p; if !__p.is_null() { @@ -48,10 +48,10 @@ impl TestAllocator_int_ { )] pub struct TestAllocator_double_ {} impl TestAllocator_double_ { - pub unsafe fn allocate(&mut self, mut n: usize) -> *mut f64 { + pub unsafe fn allocate(this: *mut Self, mut n: usize) -> *mut f64 { return Box::leak((0..n).map(|_| 0_f64).collect::>()).as_mut_ptr(); } - pub unsafe fn deallocate(&mut self, mut p: *mut f64, mut _a1: usize) { + pub unsafe fn deallocate(this: *mut Self, mut p: *mut f64, mut _a1: usize) { { let __p = p; if !__p.is_null() { diff --git a/tests/unit/out/unsafe/void_cast.rs b/tests/unit/out/unsafe/void_cast.rs index ce227797ee..a118dad1d3 100644 --- a/tests/unit/out/unsafe/void_cast.rs +++ b/tests/unit/out/unsafe/void_cast.rs @@ -24,8 +24,8 @@ pub struct NonTrivial { pub data: Vec, } impl DefaultConstructibleUnsafe for NonTrivial { - unsafe fn default_constructor(&mut self) { - (&raw mut self.data).write(Vec::new()); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).data).write(Vec::new()); } } pub unsafe fn unused_ref_param_1(x: *const NonTrivial) {} @@ -64,8 +64,8 @@ pub struct NonCopyable { pub value: Option>, } impl DefaultConstructibleUnsafe for NonCopyable { - unsafe fn default_constructor(&mut self) { - (&raw mut self.value).write(None); + unsafe fn default_constructor(this: *mut Self) { + (&raw mut (*this).value).write(None); } } pub unsafe fn unused_noncopyable_param_5(x: *const NonCopyable) {} From a6dfbbcaa6bf48bac252ce567ed6d3230f37ee7c Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 11:42:58 +0000 Subject: [PATCH 07/18] format --- libcc2rs-macros/src/cpp_from.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/libcc2rs-macros/src/cpp_from.rs b/libcc2rs-macros/src/cpp_from.rs index 92bfec834b..0f3d39bd1d 100644 --- a/libcc2rs-macros/src/cpp_from.rs +++ b/libcc2rs-macros/src/cpp_from.rs @@ -179,8 +179,6 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { let src = pointer(&syn::parse_quote!(#self_ty), false); let body = if is_unsafe && matches!(conversion.kind, Kind::MutPtr) { quote!(#name::#op(src.cast_mut())) - } else if is_unsafe { - quote!(#name::#op(src)) } else { quote!(#name::#op(src)) }; From 9b9e0dd3473f646793774339f9f9908a0da2f6fd Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 11:46:02 +0000 Subject: [PATCH 08/18] Update tests --- .../out/refcount/friend_operator.rs | 4 +- .../out/unsafe/friend_operator.rs | 10 ++-- tests/unit/out/refcount/friend.rs | 4 +- tests/unit/out/refcount/map_key_copy_ctor.rs | 4 +- tests/unit/out/refcount/map_key_identity.rs | 8 +-- tests/unit/out/refcount/max.rs | 4 +- .../refcount/operator_comparison_defaulted.rs | 28 ++++----- .../out/refcount/operator_comparison_free.rs | 16 +++-- .../refcount/operator_comparison_member.rs | 4 +- .../refcount/operator_comparison_nonbool.rs | 28 ++++----- .../operator_comparison_noncopyable.rs | 8 +-- tests/unit/out/refcount/operator_friend.rs | 36 ++++-------- tests/unit/out/refcount/operator_less_than.rs | 4 +- tests/unit/out/refcount/operator_three_way.rs | 4 +- tests/unit/out/refcount/operator_traits.rs | 16 +++-- tests/unit/out/refcount/sort_no_copy.rs | 16 +++-- tests/unit/out/unsafe/class.rs | 10 ++-- tests/unit/out/unsafe/find.rs | 29 +++++++--- tests/unit/out/unsafe/friend.rs | 8 +-- tests/unit/out/unsafe/map_key_identity.rs | 16 ++--- .../unsafe/operator_comparison_defaulted.rs | 58 +++++++++++-------- .../out/unsafe/operator_comparison_free.rs | 10 ++-- .../out/unsafe/operator_comparison_member.rs | 12 ++-- .../out/unsafe/operator_comparison_nonbool.rs | 30 +++++++++- .../unsafe/operator_comparison_noncopyable.rs | 20 ++++--- tests/unit/out/unsafe/operator_friend.rs | 54 +++++++---------- tests/unit/out/unsafe/operator_three_way.rs | 8 ++- tests/unit/out/unsafe/operator_traits.rs | 36 ++++++++---- tests/unit/out/unsafe/sort_no_copy.rs | 15 +++-- 29 files changed, 268 insertions(+), 232 deletions(-) diff --git a/tests/multi-file/friend_operator/out/refcount/friend_operator.rs b/tests/multi-file/friend_operator/out/refcount/friend_operator.rs index e698d54594..070a1725f1 100644 --- a/tests/multi-file/friend_operator/out/refcount/friend_operator.rs +++ b/tests/multi-file/friend_operator/out/refcount/friend_operator.rs @@ -44,9 +44,7 @@ fn main_0() -> i32 { return 0; } impl WeaklyEqualityComparableWith for S { - fn equal(this: Ptr, __rhs: Ptr) -> bool { - let x: Ptr = this.clone().clone(); - let y: Ptr = __rhs.clone(); + fn equal(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }) && ({ x.with(|__s| __s.b) } == { y.with(|__s| __s.b) }); } diff --git a/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs b/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs index 3b24cd2a16..572e6c8c57 100644 --- a/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs +++ b/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs @@ -34,7 +34,7 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const S = &s1; - WeaklyEqualityComparableWithUnsafe::equal(&*(_x), &s2) + WeaklyEqualityComparableWithUnsafe::equal(_x, &s2) }) ); assert!( @@ -46,7 +46,7 @@ unsafe fn main_0() -> i32 { assert!( !(unsafe { let _x: *const S = &s1; - WeaklyEqualityComparableWithUnsafe::equal(&*(_x), &s3) + WeaklyEqualityComparableWithUnsafe::equal(_x, &s3) }) ); assert!( @@ -67,16 +67,14 @@ unsafe fn main_0() -> i32 { return 0; } impl WeaklyEqualityComparableWithUnsafe for S { - unsafe fn equal(&self, __rhs: *const Self) -> bool { - let x: *const S = self as *const S; - let y: *const S = (&*__rhs) as *const S; + unsafe fn equal(x: *const S, y: *const S) -> bool { return (((*x).a) == ((*y).a)) && (((*x).b) == ((*y).b)); } } pub unsafe fn operator_ne_0(x: *const S, y: *const S) -> bool { return !(unsafe { let _x: *const S = x; - WeaklyEqualityComparableWithUnsafe::equal(&*(_x), y) + WeaklyEqualityComparableWithUnsafe::equal(_x, y) }); } pub unsafe fn operator_lt_1(x: *const S, y: *const S) -> bool { diff --git a/tests/unit/out/refcount/friend.rs b/tests/unit/out/refcount/friend.rs index 31aa5fad2c..11036f9e7e 100644 --- a/tests/unit/out/refcount/friend.rs +++ b/tests/unit/out/refcount/friend.rs @@ -10,9 +10,7 @@ pub fn get_0(v: Ptr) -> i32 { return v.with(|__s| __s.x); } impl WeaklyEqualityComparableWith for V { - fn equal(this: Ptr, __rhs: Ptr) -> bool { - let a: Ptr = this.clone().clone(); - let b: Ptr = __rhs.clone(); + fn equal(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.x) } == { b.with(|__s| __s.x) }); } } diff --git a/tests/unit/out/refcount/map_key_copy_ctor.rs b/tests/unit/out/refcount/map_key_copy_ctor.rs index 73c930ee56..6b30fb39c0 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -45,8 +45,8 @@ impl MoveConstructible for Key { } } impl CppLess for Key { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Key::operator_lt(__lhs.clone(), __rhs.clone()) + fn less(this: Ptr, o: Ptr) -> bool { + Key::operator_lt(this.clone(), o.clone()) } } pub fn make_key_3(__return: Ptr, mut k: i32) { diff --git a/tests/unit/out/refcount/map_key_identity.rs b/tests/unit/out/refcount/map_key_identity.rs index 6be7a2a6af..90a0a4f8b7 100644 --- a/tests/unit/out/refcount/map_key_identity.rs +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -29,17 +29,15 @@ pub struct Key { pub identity: i32, } impl CppLess for Key { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_1(__lhs.clone(), __rhs.clone()) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_1(a.clone(), b.clone()) } } pub fn operator_lt_1(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.order) } < { b.with(|__s| __s.order) }); } impl WeaklyEqualityComparableWith for Key { - fn equal(this: Ptr, __rhs: Ptr) -> bool { - let a: Ptr = this.clone().clone(); - let b: Ptr = __rhs.clone(); + fn equal(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.identity) } == { b.with(|__s| __s.identity) }); } } diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index 9458f5bba3..5c273a875b 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -52,8 +52,8 @@ impl CopyConstructible for Bag { } } impl CppLess for Bag { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_4(__lhs.clone(), __rhs.clone()) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_4(a.clone(), b.clone()) } } pub fn operator_lt_4(a: Ptr, b: Ptr) -> bool { diff --git a/tests/unit/out/refcount/operator_comparison_defaulted.rs b/tests/unit/out/refcount/operator_comparison_defaulted.rs index fa1d4ea994..da9da2a9a3 100644 --- a/tests/unit/out/refcount/operator_comparison_defaulted.rs +++ b/tests/unit/out/refcount/operator_comparison_defaulted.rs @@ -80,8 +80,8 @@ impl WeaklyEqualityComparableWith for Cmp { } } impl CppLess for Cmp { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Cmp::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less + fn less(this: Ptr, _a0: Ptr) -> bool { + Cmp::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less } } #[derive( @@ -121,8 +121,8 @@ impl WeaklyEqualityComparableWith for Both { } } impl CppLess for Both { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Both::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less + fn less(this: Ptr, _a0: Ptr) -> bool { + Both::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less } } #[derive( @@ -157,8 +157,8 @@ impl OrdOnly { } } impl CppLess for OrdOnly { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - OrdOnly::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less + fn less(this: Ptr, _a0: Ptr) -> bool { + OrdOnly::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less } } #[derive( @@ -198,8 +198,8 @@ impl WeaklyEqualityComparableWith for Inner { } } impl CppLess for Inner { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Inner::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less + fn less(this: Ptr, _a0: Ptr) -> bool { + Inner::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less } } #[derive( @@ -251,8 +251,8 @@ impl WeaklyEqualityComparableWith for Outer { } } impl CppLess for Outer { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Outer::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less + fn less(this: Ptr, _a0: Ptr) -> bool { + Outer::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less } } #[derive( @@ -303,8 +303,8 @@ impl WeaklyEqualityComparableWith for Secondary { } } impl CppLess for Secondary { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Secondary::operator_lt(__lhs.clone(), __rhs.clone()) + fn less(this: Ptr, _a0: Ptr) -> bool { + Secondary::operator_lt(this.clone(), _a0.clone()) } } #[derive( @@ -344,8 +344,8 @@ impl WeaklyEqualityComparableWith for PtrMember { } } impl CppLess for PtrMember { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - PtrMember::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less + fn less(this: Ptr, _a0: Ptr) -> bool { + PtrMember::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less } } pub fn main() { diff --git a/tests/unit/out/refcount/operator_comparison_free.rs b/tests/unit/out/refcount/operator_comparison_free.rs index 1392a64512..4d00fa46e3 100644 --- a/tests/unit/out/refcount/operator_comparison_free.rs +++ b/tests/unit/out/refcount/operator_comparison_free.rs @@ -24,14 +24,12 @@ pub struct S { pub v: i32, } impl CppLess for S { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_0(__lhs.clone(), __rhs.clone()) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_0(a.clone(), b.clone()) } } impl WeaklyEqualityComparableWith for S { - fn equal(this: Ptr, __rhs: Ptr) -> bool { - let a: Ptr = this.clone().clone(); - let b: Ptr = __rhs.clone(); + fn equal(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); } } @@ -74,13 +72,13 @@ pub struct V { pub v: i32, } impl CppLess for V { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_7(__lhs.read(), __rhs.read()) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_7(a.read(), b.read()) } } impl WeaklyEqualityComparableWith for V { - fn equal(this: Ptr, __rhs: Ptr) -> bool { - operator_eq_8(this.clone().read(), __rhs.read()) + fn equal(a: Ptr, b: Ptr) -> bool { + operator_eq_8(a.read(), b.read()) } } pub fn operator_eq_8(mut a: V, mut b: V) -> bool { diff --git a/tests/unit/out/refcount/operator_comparison_member.rs b/tests/unit/out/refcount/operator_comparison_member.rs index 0957dcc178..f6224ca220 100644 --- a/tests/unit/out/refcount/operator_comparison_member.rs +++ b/tests/unit/out/refcount/operator_comparison_member.rs @@ -49,8 +49,8 @@ impl WeaklyEqualityComparableWith for S { } } impl CppLess for S { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - S::operator_lt_3(__lhs.clone(), __rhs.clone()) + fn less(this: Ptr, o: Ptr) -> bool { + S::operator_lt_3(this.clone(), o.clone()) } } pub fn main() { diff --git a/tests/unit/out/refcount/operator_comparison_nonbool.rs b/tests/unit/out/refcount/operator_comparison_nonbool.rs index d50fd35a6f..2499645a9d 100644 --- a/tests/unit/out/refcount/operator_comparison_nonbool.rs +++ b/tests/unit/out/refcount/operator_comparison_nonbool.rs @@ -24,13 +24,13 @@ pub struct X { pub v: i32, } impl CppLess for X { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - ((operator_lt_0(__lhs.read(), __rhs.read())) != 0) + fn less(a: Ptr, b: Ptr) -> bool { + ((operator_lt_0(a.read(), b.read())) != 0) } } impl WeaklyEqualityComparableWith for X { - fn equal(this: Ptr, __rhs: Ptr) -> bool { - ((operator_eq_1(this.clone().read(), __rhs.read())) != 0) + fn equal(a: Ptr, b: Ptr) -> bool { + ((operator_eq_1(a.read(), b.read())) != 0) } } pub fn operator_eq_1(mut a: X, mut b: X) -> i32 { @@ -131,13 +131,13 @@ impl Mixed { } } impl CppLess for Mixed { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - ((Mixed::operator_lt(__lhs.clone(), __rhs.clone())) != 0) + fn less(this: Ptr, o: Ptr) -> bool { + ((Mixed::operator_lt(this.clone(), o.clone())) != 0) } } impl WeaklyEqualityComparableWith for Mixed { - fn equal(this: Ptr, __rhs: Ptr) -> bool { - ((Mixed::operator_eq(this.clone().clone(), __rhs.clone())) != 0) + fn equal(this: Ptr, o: Ptr) -> bool { + ((Mixed::operator_eq(this.clone(), o.clone())) != 0) } } #[derive( @@ -185,17 +185,17 @@ pub struct Boolish { pub v: i32, } impl CppLess for Boolish { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + fn less(a: Ptr, b: Ptr) -> bool { { - let __cmp = operator_lt_6(__lhs.read(), __rhs.read()); + let __cmp = operator_lt_6(a.read(), b.read()); MyBool::to_bool(Rc::new(RefCell::new(__cmp)).as_pointer()) } } } impl WeaklyEqualityComparableWith for Boolish { - fn equal(this: Ptr, __rhs: Ptr) -> bool { + fn equal(a: Ptr, b: Ptr) -> bool { { - let __cmp = operator_eq_7(this.clone().read(), __rhs.read()); + let __cmp = operator_eq_7(a.read(), b.read()); MyBool::to_bool(Rc::new(RefCell::new(__cmp)).as_pointer()) } } @@ -270,9 +270,9 @@ impl RefInt { } } impl WeaklyEqualityComparableWith for RefInt { - fn equal(this: Ptr, __rhs: Ptr) -> bool { + fn equal(this: Ptr, _a0: Ptr) -> bool { { - let __cmp = RefInt::operator_eq(this.clone().clone(), __rhs.clone()); + let __cmp = RefInt::operator_eq(this.clone(), _a0.clone()); RefBool::to_bool(__cmp.clone()) } } diff --git a/tests/unit/out/refcount/operator_comparison_noncopyable.rs b/tests/unit/out/refcount/operator_comparison_noncopyable.rs index 8deb9e39be..f9ed7ab8cb 100644 --- a/tests/unit/out/refcount/operator_comparison_noncopyable.rs +++ b/tests/unit/out/refcount/operator_comparison_noncopyable.rs @@ -7,9 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; impl WeaklyEqualityComparableWith for S { - fn equal(this: Ptr, __rhs: Ptr) -> bool { - let x: Ptr = this.clone().clone(); - let y: Ptr = __rhs.clone(); + fn equal(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.data_) } == { y.with(|__s| __s.data_) }); } } @@ -39,8 +37,8 @@ impl S { } } impl CppLess for S { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_0(__lhs.clone(), __rhs.clone()) + fn less(x: Ptr, y: Ptr) -> bool { + operator_lt_0(x.clone(), y.clone()) } } pub fn main() { diff --git a/tests/unit/out/refcount/operator_friend.rs b/tests/unit/out/refcount/operator_friend.rs index 18990fd056..ad1cebf1da 100644 --- a/tests/unit/out/refcount/operator_friend.rs +++ b/tests/unit/out/refcount/operator_friend.rs @@ -7,9 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; impl WeaklyEqualityComparableWith for Defaulted { - fn equal(this: Ptr, __rhs: Ptr) -> bool { - let _a0: Ptr = this.clone().clone(); - let _a1: Ptr = __rhs.clone(); + fn equal(_a0: Ptr, _a1: Ptr) -> bool { return ({ _a0.with(|__s| __s.a) } == { _a1.with(|__s| __s.a) }) && ({ _a0.with(|__s| __s.b) } == { _a1.with(|__s| __s.b) }); } @@ -46,9 +44,7 @@ pub fn operator_cmp_0(_a0: Ptr, _a1: Ptr) -> std::cm return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } impl WeaklyEqualityComparableWith for DefaultedOrd { - fn equal(this: Ptr, __rhs: Ptr) -> bool { - let _a0: Ptr = this.clone().clone(); - let _a1: Ptr = __rhs.clone(); + fn equal(_a0: Ptr, _a1: Ptr) -> bool { return ({ _a0.with(|__s| __s.a) } == { _a1.with(|__s| __s.a) }); } } @@ -70,14 +66,12 @@ pub struct DefaultedOrd { pub a: i32, } impl CppLess for DefaultedOrd { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_cmp_0(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less + fn less(_a0: Ptr, _a1: Ptr) -> bool { + operator_cmp_0(_a0.clone(), _a1.clone()) == std::cmp::Ordering::Less } } impl WeaklyEqualityComparableWith for Inline { - fn equal(this: Ptr, __rhs: Ptr) -> bool { - let x: Ptr = this.clone().clone(); - let y: Ptr = __rhs.clone(); + fn equal(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }); } } @@ -107,8 +101,8 @@ pub struct Inline { pub a: i32, } impl CppLess for Inline { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_1(__lhs.clone(), __rhs.clone()) + fn less(x: Ptr, y: Ptr) -> bool { + operator_lt_1(x.clone(), y.clone()) } } #[derive( @@ -129,9 +123,7 @@ pub struct OutOfLine { pub a: i32, } impl WeaklyEqualityComparableWith for OutOfLine { - fn equal(this: Ptr, __rhs: Ptr) -> bool { - let x: Ptr = this.clone().clone(); - let y: Ptr = __rhs.clone(); + fn equal(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }); } } @@ -139,9 +131,7 @@ pub fn operator_ne_3(x: Ptr, y: Ptr) -> bool { return !({ WeaklyEqualityComparableWith::equal((x).clone(), (y).clone()) }); } impl WeaklyEqualityComparableWith for Tmpl_int_ { - fn equal(this: Ptr, __rhs: Ptr) -> bool { - let x: Ptr = this.clone().clone(); - let y: Ptr = __rhs.clone(); + fn equal(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.v) } == { y.with(|__s| __s.v) }); } } @@ -169,8 +159,8 @@ pub struct Tmpl_int_ { pub v: i32, } impl CppLess for Tmpl_int_ { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_4(__lhs.clone(), __rhs.clone()) + fn less(x: Ptr, y: Ptr) -> bool { + operator_lt_4(x.clone(), y.clone()) } } #[derive( @@ -191,9 +181,7 @@ pub struct Tmpl_long_ { pub v: i64, } impl WeaklyEqualityComparableWith for TmplDefaulted_int_ { - fn equal(this: Ptr, __rhs: Ptr) -> bool { - let _a0: Ptr = this.clone().clone(); - let _a1: Ptr = __rhs.clone(); + fn equal(_a0: Ptr, _a1: Ptr) -> bool { return ({ _a0.with(|__s| __s.v) } == { _a1.with(|__s| __s.v) }); } } diff --git a/tests/unit/out/refcount/operator_less_than.rs b/tests/unit/out/refcount/operator_less_than.rs index e22b8901cd..47bb4adc05 100644 --- a/tests/unit/out/refcount/operator_less_than.rs +++ b/tests/unit/out/refcount/operator_less_than.rs @@ -33,8 +33,8 @@ impl Pair { } } impl CppLess for Pair { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Pair::operator_lt(__lhs.clone(), __rhs.clone()) + fn less(this: Ptr, other: Ptr) -> bool { + Pair::operator_lt(this.clone(), other.clone()) } } pub fn main() { diff --git a/tests/unit/out/refcount/operator_three_way.rs b/tests/unit/out/refcount/operator_three_way.rs index 2d4e427395..3924a32fcf 100644 --- a/tests/unit/out/refcount/operator_three_way.rs +++ b/tests/unit/out/refcount/operator_three_way.rs @@ -40,8 +40,8 @@ impl WeaklyEqualityComparableWith for S { } } impl CppLess for S { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - S::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less + fn less(this: Ptr, o: Ptr) -> bool { + S::operator_cmp(this.clone(), o.clone()) == std::cmp::Ordering::Less } } pub fn main() { diff --git a/tests/unit/out/refcount/operator_traits.rs b/tests/unit/out/refcount/operator_traits.rs index 77543f0a9c..83368ac2cf 100644 --- a/tests/unit/out/refcount/operator_traits.rs +++ b/tests/unit/out/refcount/operator_traits.rs @@ -29,8 +29,8 @@ impl Lt { } } impl CppLess for Lt { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Lt::operator_lt(__lhs.clone(), __rhs.clone()) + fn less(this: Ptr, o: Ptr) -> bool { + Lt::operator_lt(this.clone(), o.clone()) } } #[derive( @@ -83,8 +83,8 @@ impl WeaklyEqualityComparableWith for Cmp { } } impl CppLess for Cmp { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Cmp::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less + fn less(this: Ptr, o: Ptr) -> bool { + Cmp::operator_cmp(this.clone(), o.clone()) == std::cmp::Ordering::Less } } #[derive( @@ -105,17 +105,15 @@ pub struct Free { pub v: i32, } impl CppLess for Free { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_0(__lhs.clone(), __rhs.clone()) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_0(a.clone(), b.clone()) } } pub fn operator_lt_0(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } < { b.with(|__s| __s.v) }); } impl WeaklyEqualityComparableWith for Free { - fn equal(this: Ptr, __rhs: Ptr) -> bool { - let a: Ptr = this.clone().clone(); - let b: Ptr = __rhs.clone(); + fn equal(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); } } diff --git a/tests/unit/out/refcount/sort_no_copy.rs b/tests/unit/out/refcount/sort_no_copy.rs index 416935a7a1..98193c39e2 100644 --- a/tests/unit/out/refcount/sort_no_copy.rs +++ b/tests/unit/out/refcount/sort_no_copy.rs @@ -51,8 +51,8 @@ impl MoveAssignable for Tracked { } } impl CppLess for Tracked { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_1(__lhs.clone(), __rhs.clone()) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_1(a.clone(), b.clone()) } } impl Default for Tracked { @@ -96,8 +96,8 @@ impl MoveOnly { } } impl CppLess for MoveOnly { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_3(__lhs.clone(), __rhs.clone()) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_3(a.clone(), b.clone()) } } pub fn operator_lt_3(a: Ptr, b: Ptr) -> bool { @@ -119,17 +119,15 @@ impl DefaultConstructible for Bag { } } impl CppLess for Bag { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_4(__lhs.clone(), __rhs.clone()) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_4(a.clone(), b.clone()) } } pub fn operator_lt_4(a: Ptr, b: Ptr) -> bool { return ({ (*a.upgrade().deref()).items.len() } < { (*b.upgrade().deref()).items.len() }); } impl WeaklyEqualityComparableWith for Bag { - fn equal(this: Ptr, __rhs: Ptr) -> bool { - let a: Ptr = this.clone().clone(); - let b: Ptr = __rhs.clone(); + fn equal(a: Ptr, b: Ptr) -> bool { return ({ (*a.upgrade().deref()).items.len() } == { (*b.upgrade().deref()).items.len() }); } } diff --git a/tests/unit/out/unsafe/class.rs b/tests/unit/out/unsafe/class.rs index 8bb913f0e5..a9e1375d63 100644 --- a/tests/unit/out/unsafe/class.rs +++ b/tests/unit/out/unsafe/class.rs @@ -92,14 +92,16 @@ impl Counter { (*(&raw const (*this).calls).cast_mut()).prefix_inc(); return (*this).v; } - pub unsafe fn operator_eq(this: *const Self, o: *const Counter) -> bool { +} +impl WeaklyEqualityComparableWithUnsafe for Counter { + unsafe fn equal(this: *const Self, o: *const Counter) -> bool { (*(&raw const (*this).calls).cast_mut()).prefix_inc(); return (((*this).v) == ((*o).v)); } } impl std::cmp::PartialEq for Counter { fn eq(&self, other: &Self) -> bool { - unsafe { Counter::operator_eq(self, other as *const Counter) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Counter) } } } impl std::cmp::Eq for Counter {} @@ -180,8 +182,8 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { Counter::Get(&raw const c1,) }) == (3))); assert!(((unsafe { Counter::Get(&raw const c2,) }) == (3))); assert!(((unsafe { Counter::Get(&raw const (*pc),) }) == (3))); - assert!((unsafe { Counter::operator_eq(&raw const c1, &c2,) })); - assert!((unsafe { Counter::operator_eq(&raw const c2, &c1,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const c1, &c2,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const c2, &c1,) })); assert!(((c1.calls) == (3))); assert!(((c2.calls) == (2))); let mut t: Tally = Tally { calls: 0 }; diff --git a/tests/unit/out/unsafe/find.rs b/tests/unit/out/unsafe/find.rs index 62eb6c3e8c..ed78867061 100644 --- a/tests/unit/out/unsafe/find.rs +++ b/tests/unit/out/unsafe/find.rs @@ -20,14 +20,14 @@ use std::rc::Rc; pub struct P { pub x: i32, } -impl P { - pub unsafe fn operator_eq(this: *const Self, o: *const P) -> bool { +impl WeaklyEqualityComparableWithUnsafe for P { + unsafe fn equal(this: *const Self, o: *const P) -> bool { return (((*this).x) == ((*o).x)); } } impl std::cmp::PartialEq for P { fn eq(&self, other: &Self) -> bool { - unsafe { P::operator_eq(self, other as *const P) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const P) } } } impl std::cmp::Eq for P {} @@ -56,7 +56,8 @@ unsafe fn main_0() -> i32 { let mut it: UnsafeRandomAccessIterator = { let mut __tmp_3 = { (v_end).clone() }; let mut __it = (v_begin).clone(); - while __it != __tmp_3 && *__it.iter_deref() != 2 { + while __it != __tmp_3 && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &2) + { __it.iter_inc(); } __it @@ -93,7 +94,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_7 = { v.begin() }; let mut __tmp_8 = { v.begin() }; let mut __it = (__tmp_7).clone(); - while __it != __tmp_8 && *__it.iter_deref() != 2 { + while __it != __tmp_8 + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &2) + { __it.iter_inc(); } __it @@ -105,7 +108,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_9 = { w.begin().iter_add(2_isize) }; let mut __tmp_10 = { w.end() }; let mut __it = (__tmp_9).clone(); - while __it != __tmp_10 && *__it.iter_deref() != 4 { + while __it != __tmp_10 + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &4) + { __it.iter_inc(); } __it @@ -116,7 +121,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_11 = { w.begin().iter_add(2_isize) }; let mut __tmp_12 = { w.end() }; let mut __it = (__tmp_11).clone(); - while __it != __tmp_12 && *__it.iter_deref() != 1 { + while __it != __tmp_12 + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &1) + { __it.iter_inc(); } __it @@ -127,7 +134,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_13 = { w.begin().iter_add(2_isize) }; let mut __tmp_14 = { w.begin().iter_add(4_isize) }; let mut __it = (__tmp_13).clone(); - while __it != __tmp_14 && *__it.iter_deref() != 5 { + while __it != __tmp_14 + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &5) + { __it.iter_inc(); } __it @@ -139,7 +148,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_15 = { p.begin() }; let mut __tmp_16 = { p.end() }; let mut __it = (__tmp_15).clone(); - while __it != __tmp_16 && *__it.iter_deref() != (P { x: 1 }) { + while __it != __tmp_16 + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &(P { x: 1 })) + { __it.iter_inc(); } __it diff --git a/tests/unit/out/unsafe/friend.rs b/tests/unit/out/unsafe/friend.rs index 2b03157d94..f12ece54cb 100644 --- a/tests/unit/out/unsafe/friend.rs +++ b/tests/unit/out/unsafe/friend.rs @@ -10,9 +10,7 @@ pub unsafe fn get_0(v: *const V) -> i32 { return (*v).x; } impl WeaklyEqualityComparableWithUnsafe for V { - unsafe fn equal(&self, __rhs: *const Self) -> bool { - let a: *const V = self as *const V; - let b: *const V = (&*__rhs) as *const V; + unsafe fn equal(a: *const V, b: *const V) -> bool { return (((*a).x) == ((*b).x)); } } @@ -107,13 +105,13 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _a: *const V = &a; - WeaklyEqualityComparableWithUnsafe::equal(&*(_a), &b) + WeaklyEqualityComparableWithUnsafe::equal(_a, &b) }) ); assert!( !(unsafe { let _a: *const V = &a; - WeaklyEqualityComparableWithUnsafe::equal(&*(_a), &c) + WeaklyEqualityComparableWithUnsafe::equal(_a, &c) }) ); assert!(((unsafe { scaled_1(&c, 2,) }) == (8))); diff --git a/tests/unit/out/unsafe/map_key_identity.rs b/tests/unit/out/unsafe/map_key_identity.rs index 62f5ce6810..2b2431c20f 100644 --- a/tests/unit/out/unsafe/map_key_identity.rs +++ b/tests/unit/out/unsafe/map_key_identity.rs @@ -43,15 +43,17 @@ impl std::cmp::PartialOrd for Key { } impl std::cmp::PartialEq for Key { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_2(self as *const Key, other as *const Key) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Key) } } } impl std::cmp::Eq for Key {} pub unsafe fn operator_lt_1(a: *const Key, b: *const Key) -> bool { return (((*a).order) < ((*b).order)); } -pub unsafe fn operator_eq_2(a: *const Key, b: *const Key) -> bool { - return (((*a).identity) == ((*b).identity)); +impl WeaklyEqualityComparableWithUnsafe for Key { + unsafe fn equal(a: *const Key, b: *const Key) -> bool { + return (((*a).identity) == ((*b).identity)); + } } #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] @@ -94,7 +96,7 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & ((unsafe { let _a: *const Key = &distinct_a; - operator_eq_2(_a, &distinct_b) + WeaklyEqualityComparableWithUnsafe::equal(_a, &distinct_b) }) as i32)) != 0; let mut distinct: UnsafeMap = UnsafeMap::new(); @@ -124,7 +126,7 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & ((unsafe { let _a: *const Key = &distinct_a; - operator_eq_2(_a, &distinct_b) + WeaklyEqualityComparableWithUnsafe::equal(_a, &distinct_b) }) as i32)) != 0; let mut distinct_count: usize = 0_usize; @@ -153,7 +155,7 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & (!(unsafe { let _a: *const Key = &equivalent_a; - operator_eq_2(_a, &equivalent_b) + WeaklyEqualityComparableWithUnsafe::equal(_a, &equivalent_b) }) as i32)) != 0; let mut equivalent: UnsafeMap = UnsafeMap::new(); @@ -197,7 +199,7 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & (!(unsafe { let _a: *const Key = &equivalent_a; - operator_eq_2(_a, &equivalent_b) + WeaklyEqualityComparableWithUnsafe::equal(_a, &equivalent_b) }) as i32)) != 0; let later_key: Key = Key { diff --git a/tests/unit/out/unsafe/operator_comparison_defaulted.rs b/tests/unit/out/unsafe/operator_comparison_defaulted.rs index 3ed17b1d67..fee2384db5 100644 --- a/tests/unit/out/unsafe/operator_comparison_defaulted.rs +++ b/tests/unit/out/unsafe/operator_comparison_defaulted.rs @@ -21,14 +21,14 @@ pub struct Eq { pub a: i32, pub b: i32, } -impl Eq { - pub unsafe fn operator_eq(this: *const Self, _a0: *const Eq) -> bool { +impl WeaklyEqualityComparableWithUnsafe for Eq { + unsafe fn equal(this: *const Self, _a0: *const Eq) -> bool { return (((*this).a) == ((*_a0).a)) && (((*this).b) == ((*_a0).b)); } } impl std::cmp::PartialEq for Eq { fn eq(&self, other: &Self) -> bool { - unsafe { Eq::operator_eq(self, other as *const Eq) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Eq) } } } impl std::cmp::Eq for Eq {} @@ -63,7 +63,9 @@ impl Cmp { } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(this: *const Self, _a0: *const Cmp) -> bool { +} +impl WeaklyEqualityComparableWithUnsafe for Cmp { + unsafe fn equal(this: *const Self, _a0: *const Cmp) -> bool { return (((*this).a) == ((*_a0).a)) && (((*this).b) == ((*_a0).b)); } } @@ -98,9 +100,6 @@ pub struct Both { pub a: i32, } impl Both { - pub unsafe fn operator_eq(this: *const Self, _a0: *const Both) -> bool { - return (((*this).a) == ((*_a0).a)); - } pub unsafe fn operator_cmp(this: *const Self, _a0: *const Both) -> std::cmp::Ordering { { let mut cmp: std::cmp::Ordering = std::cmp::Ord::cmp(&((*this).a), &((*_a0).a)); @@ -111,6 +110,11 @@ impl Both { return libcc2rs::STRONG_ORDERING_EQUAL; } } +impl WeaklyEqualityComparableWithUnsafe for Both { + unsafe fn equal(this: *const Self, _a0: *const Both) -> bool { + return (((*this).a) == ((*_a0).a)); + } +} impl std::cmp::Ord for Both { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { Both::operator_cmp(self, other as *const Both) } @@ -123,7 +127,7 @@ impl std::cmp::PartialOrd for Both { } impl std::cmp::PartialEq for Both { fn eq(&self, other: &Self) -> bool { - unsafe { Both::operator_eq(self, other as *const Both) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Both) } } } impl std::cmp::Eq for Both {} @@ -192,7 +196,9 @@ impl Inner { } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(this: *const Self, _a0: *const Inner) -> bool { +} +impl WeaklyEqualityComparableWithUnsafe for Inner { + unsafe fn equal(this: *const Self, _a0: *const Inner) -> bool { return (((*this).x) == ((*_a0).x)); } } @@ -246,10 +252,12 @@ impl Outer { } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(this: *const Self, _a0: *const Outer) -> bool { +} +impl WeaklyEqualityComparableWithUnsafe for Outer { + unsafe fn equal(this: *const Self, _a0: *const Outer) -> bool { return (unsafe { let _arg0: *const Inner = &(*_a0).i; - Inner::operator_eq(&raw const (*this).i, _arg0) + WeaklyEqualityComparableWithUnsafe::equal(&raw const (*this).i, _arg0) }) && (((*this).y) == ((*_a0).y)); } } @@ -284,11 +292,8 @@ pub struct Secondary { pub a: i32, } impl Secondary { - pub unsafe fn operator_eq(this: *const Self, _a0: *const Secondary) -> bool { - return (((*this).a) == ((*_a0).a)); - } pub unsafe fn operator_ne(this: *const Self, _a0: *const Secondary) -> bool { - return !(unsafe { Secondary::operator_eq(&raw const (*this), _a0) }); + return !(unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const (*this), _a0) }); } pub unsafe fn operator_cmp(this: *const Self, _a0: *const Secondary) -> std::cmp::Ordering { { @@ -308,6 +313,11 @@ impl Secondary { != std::cmp::Ordering::Less; } } +impl WeaklyEqualityComparableWithUnsafe for Secondary { + unsafe fn equal(this: *const Self, _a0: *const Secondary) -> bool { + return (((*this).a) == ((*_a0).a)); + } +} impl std::cmp::Ord for Secondary { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { Secondary::operator_cmp(self, other as *const Secondary) } @@ -320,7 +330,7 @@ impl std::cmp::PartialOrd for Secondary { } impl std::cmp::PartialEq for Secondary { fn eq(&self, other: &Self) -> bool { - unsafe { Secondary::operator_eq(self, other as *const Secondary) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Secondary) } } } impl std::cmp::Eq for Secondary {} @@ -348,7 +358,9 @@ impl PtrMember { } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(this: *const Self, _a0: *const PtrMember) -> bool { +} +impl WeaklyEqualityComparableWithUnsafe for PtrMember { + unsafe fn equal(this: *const Self, _a0: *const PtrMember) -> bool { return (((*this).p) == ((*_a0).p)); } } @@ -380,8 +392,8 @@ unsafe fn main_0() -> i32 { let mut e1: Eq = Eq { a: 1, b: 2 }; let mut e2: Eq = Eq { a: 1, b: 2 }; let mut e3: Eq = Eq { a: 1, b: 3 }; - assert!((unsafe { Eq::operator_eq(&raw const e1, &e2,) })); - assert!(!(unsafe { Eq::operator_eq(&raw const e1, &e3,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const e1, &e2,) })); + assert!(!(unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const e1, &e3,) })); let mut c1: Cmp = Cmp { a: 1, b: 2 }; let mut c2: Cmp = Cmp { a: 1, b: 3 }; let mut c3: Cmp = Cmp { a: 2, b: 0 }; @@ -391,7 +403,7 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _arg0: *const Cmp = &c1; - Cmp::operator_eq(&raw const c1, _arg0) + WeaklyEqualityComparableWithUnsafe::equal(&raw const c1, _arg0) }) ); assert!((unsafe { Cmp::operator_cmp(&raw const c1, &c2,) }) == libcc2rs::STRONG_ORDERING_LESS); @@ -401,7 +413,7 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _arg0: *const Both = &b2; - Both::operator_eq(&raw const b2, _arg0) + WeaklyEqualityComparableWithUnsafe::equal(&raw const b2, _arg0) }) ); let mut o1: OrdOnly = OrdOnly { a: 1 }; @@ -424,7 +436,7 @@ unsafe fn main_0() -> i32 { y: 9, }; assert!((unsafe { Outer::operator_cmp(&raw const x1, &x2,) }) == std::cmp::Ordering::Less); - assert!((unsafe { Outer::operator_eq(&raw const x1, &x3,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const x1, &x3,) })); assert!( (unsafe { Outer::operator_cmp(&raw const x2, &x1,) }) == libcc2rs::STRONG_ORDERING_GREATER ); @@ -445,7 +457,7 @@ unsafe fn main_0() -> i32 { p: arr.as_mut_ptr(), }; assert!((unsafe { PtrMember::operator_cmp(&raw const p1, &p2,) }) == std::cmp::Ordering::Less); - assert!((unsafe { PtrMember::operator_eq(&raw const p1, &p3,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const p1, &p3,) })); assert!( (unsafe { PtrMember::operator_cmp(&raw const p2, &p1,) }) == libcc2rs::STRONG_ORDERING_GREATER diff --git a/tests/unit/out/unsafe/operator_comparison_free.rs b/tests/unit/out/unsafe/operator_comparison_free.rs index ca9ed3f25c..2e2e9eb9fd 100644 --- a/tests/unit/out/unsafe/operator_comparison_free.rs +++ b/tests/unit/out/unsafe/operator_comparison_free.rs @@ -45,9 +45,7 @@ impl std::cmp::PartialEq for S { } impl std::cmp::Eq for S {} impl WeaklyEqualityComparableWithUnsafe for S { - unsafe fn equal(&self, __rhs: *const Self) -> bool { - let a: *const S = self as *const S; - let b: *const S = (&*__rhs) as *const S; + unsafe fn equal(a: *const S, b: *const S) -> bool { return (((*a).v) == ((*b).v)); } } @@ -111,8 +109,8 @@ impl std::cmp::PartialEq for V { } impl std::cmp::Eq for V {} impl WeaklyEqualityComparableWithUnsafe for V { - unsafe fn equal(&self, __rhs: *const Self) -> bool { - operator_eq_8(self.clone(), (&*__rhs).clone()) + unsafe fn equal(a: *const Self, b: *const Self) -> bool { + operator_eq_8((&*a).clone(), (&*b).clone()) } } pub unsafe fn operator_eq_8(mut a: V, mut b: V) -> bool { @@ -173,7 +171,7 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _a: *const S = &a; - WeaklyEqualityComparableWithUnsafe::equal(&*(_a), &c) + WeaklyEqualityComparableWithUnsafe::equal(_a, &c) }) ); assert!( diff --git a/tests/unit/out/unsafe/operator_comparison_member.rs b/tests/unit/out/unsafe/operator_comparison_member.rs index 8901e9a173..e17c1b0739 100644 --- a/tests/unit/out/unsafe/operator_comparison_member.rs +++ b/tests/unit/out/unsafe/operator_comparison_member.rs @@ -21,9 +21,6 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn operator_eq(this: *const Self, o: *const S) -> bool { - return (((*this).v) == ((*o).v)); - } pub unsafe fn operator_ne(this: *const Self, o: *const S) -> bool { return (((*this).v) != ((*o).v)); } @@ -43,6 +40,11 @@ impl S { return (((*this).v) < (o)); } } +impl WeaklyEqualityComparableWithUnsafe for S { + unsafe fn equal(this: *const Self, o: *const S) -> bool { + return (((*this).v) == ((*o).v)); + } +} impl std::cmp::Ord for S { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { @@ -63,7 +65,7 @@ impl std::cmp::PartialOrd for S { } impl std::cmp::PartialEq for S { fn eq(&self, other: &Self) -> bool { - unsafe { S::operator_eq(self, other as *const S) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const S) } } } impl std::cmp::Eq for S {} @@ -77,7 +79,7 @@ unsafe fn main_0() -> i32 { let mut a: S = S { v: 1 }; let mut b: S = S { v: 2 }; let mut c: S = S { v: 1 }; - assert!((unsafe { S::operator_eq(&raw const a, &c,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const a, &c,) })); assert!((unsafe { S::operator_ne(&raw const a, &b,) })); assert!((unsafe { S::operator_lt_3(&raw const a, &b,) })); assert!((unsafe { S::operator_gt(&raw const b, &a,) })); diff --git a/tests/unit/out/unsafe/operator_comparison_nonbool.rs b/tests/unit/out/unsafe/operator_comparison_nonbool.rs index dec785d640..cf9a37ae36 100644 --- a/tests/unit/out/unsafe/operator_comparison_nonbool.rs +++ b/tests/unit/out/unsafe/operator_comparison_nonbool.rs @@ -44,6 +44,11 @@ impl std::cmp::PartialEq for X { } } impl std::cmp::Eq for X {} +impl WeaklyEqualityComparableWithUnsafe for X { + unsafe fn equal(a: *const Self, b: *const Self) -> bool { + ((operator_eq_1((&*a).clone(), (&*b).clone())) != 0) + } +} pub unsafe fn operator_eq_1(mut a: X, mut b: X) -> i32 { return if ((a.v) == (b.v)) { 2 } else { 0 }; } @@ -148,6 +153,11 @@ impl std::cmp::PartialEq for Mixed { } } impl std::cmp::Eq for Mixed {} +impl WeaklyEqualityComparableWithUnsafe for Mixed { + unsafe fn equal(this: *const Self, o: *const Self) -> bool { + ((Mixed::operator_eq((&*this), (&*o) as *const Mixed)) != 0) + } +} #[repr(C)] #[derive( Copy, @@ -221,6 +231,14 @@ impl std::cmp::PartialEq for Boolish { } } impl std::cmp::Eq for Boolish {} +impl WeaklyEqualityComparableWithUnsafe for Boolish { + unsafe fn equal(a: *const Self, b: *const Self) -> bool { + { + let __cmp = operator_eq_7((&*a).clone(), (&*b).clone()); + MyBool::to_bool(&__cmp) + } + } +} pub unsafe fn operator_eq_7(mut a: Boolish, mut b: Boolish) -> MyBool { return { let mut __v: MyBool = ::zero_init(); @@ -295,6 +313,14 @@ impl std::cmp::PartialEq for RefInt { } } impl std::cmp::Eq for RefInt {} +impl WeaklyEqualityComparableWithUnsafe for RefInt { + unsafe fn equal(this: *const Self, _a0: *const Self) -> bool { + { + let __cmp = RefInt::operator_eq((&*this), (&*_a0) as *const RefInt); + RefBool::to_bool(&*__cmp) + } + } +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -454,7 +480,9 @@ unsafe fn main_0() -> i32 { (({ let mut __tmp_3 = { ris.as_mut_ptr().offset((2) as isize) }; let mut __it = ris.as_mut_ptr(); - while __it != __tmp_3 && *__it.iter_deref() != ri2 { + while __it != __tmp_3 + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &ri2) + { __it.iter_inc(); } __it diff --git a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs index 8da1438508..7f3188b42b 100644 --- a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs +++ b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs @@ -6,10 +6,12 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub unsafe fn operator_eq_0(x: *const S, y: *const S) -> bool { - return (((*x).data_) == ((*y).data_)); +impl WeaklyEqualityComparableWithUnsafe for S { + unsafe fn equal(x: *const S, y: *const S) -> bool { + return (((*x).data_) == ((*y).data_)); + } } -pub unsafe fn operator_lt_1(x: *const S, y: *const S) -> bool { +pub unsafe fn operator_lt_0(x: *const S, y: *const S) -> bool { return (((*x).data_) < ((*y).data_)); } #[repr(C)] @@ -34,9 +36,9 @@ impl S { impl std::cmp::Ord for S { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_1(self as *const S, other as *const S) { + if operator_lt_0(self as *const S, other as *const S) { std::cmp::Ordering::Less - } else if operator_lt_1(other as *const S, self as *const S) { + } else if operator_lt_0(other as *const S, self as *const S) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -51,7 +53,7 @@ impl std::cmp::PartialOrd for S { } impl std::cmp::PartialEq for S { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_0(self as *const S, other as *const S) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const S) } } } impl std::cmp::Eq for S {} @@ -68,19 +70,19 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const S = &a; - operator_eq_0(_x, &c) + WeaklyEqualityComparableWithUnsafe::equal(_x, &c) }) ); assert!( (unsafe { let _x: *const S = &a; - operator_lt_1(_x, &b) + operator_lt_0(_x, &b) }) ); assert!( !(unsafe { let _x: *const S = &b; - operator_lt_1(_x, &a) + operator_lt_0(_x, &a) }) ); return 0; diff --git a/tests/unit/out/unsafe/operator_friend.rs b/tests/unit/out/unsafe/operator_friend.rs index c47d47f696..cf29633f8d 100644 --- a/tests/unit/out/unsafe/operator_friend.rs +++ b/tests/unit/out/unsafe/operator_friend.rs @@ -7,9 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; impl WeaklyEqualityComparableWithUnsafe for Defaulted { - unsafe fn equal(&self, __rhs: *const Self) -> bool { - let _a0: *const Defaulted = self as *const Defaulted; - let _a1: *const Defaulted = (&*__rhs) as *const Defaulted; + unsafe fn equal(_a0: *const Defaulted, _a1: *const Defaulted) -> bool { return (((*_a0).a) == ((*_a1).a)) && (((*_a0).b) == ((*_a1).b)); } } @@ -47,9 +45,7 @@ pub unsafe fn operator_cmp_0( return libcc2rs::STRONG_ORDERING_EQUAL; } impl WeaklyEqualityComparableWithUnsafe for DefaultedOrd { - unsafe fn equal(&self, __rhs: *const Self) -> bool { - let _a0: *const DefaultedOrd = self as *const DefaultedOrd; - let _a1: *const DefaultedOrd = (&*__rhs) as *const DefaultedOrd; + unsafe fn equal(_a0: *const DefaultedOrd, _a1: *const DefaultedOrd) -> bool { return (((*_a0).a) == ((*_a1).a)); } } @@ -84,9 +80,7 @@ impl std::cmp::PartialEq for DefaultedOrd { } impl std::cmp::Eq for DefaultedOrd {} impl WeaklyEqualityComparableWithUnsafe for Inline { - unsafe fn equal(&self, __rhs: *const Self) -> bool { - let x: *const Inline = self as *const Inline; - let y: *const Inline = (&*__rhs) as *const Inline; + unsafe fn equal(x: *const Inline, y: *const Inline) -> bool { return (((*x).a) == ((*y).a)); } } @@ -157,22 +151,18 @@ impl std::cmp::PartialEq for OutOfLine { } impl std::cmp::Eq for OutOfLine {} impl WeaklyEqualityComparableWithUnsafe for OutOfLine { - unsafe fn equal(&self, __rhs: *const Self) -> bool { - let x: *const OutOfLine = self as *const OutOfLine; - let y: *const OutOfLine = (&*__rhs) as *const OutOfLine; + unsafe fn equal(x: *const OutOfLine, y: *const OutOfLine) -> bool { return (((*x).a) == ((*y).a)); } } pub unsafe fn operator_ne_3(x: *const OutOfLine, y: *const OutOfLine) -> bool { return !(unsafe { let _x: *const OutOfLine = x; - WeaklyEqualityComparableWithUnsafe::equal(&*(_x), y) + WeaklyEqualityComparableWithUnsafe::equal(_x, y) }); } impl WeaklyEqualityComparableWithUnsafe for Tmpl_int_ { - unsafe fn equal(&self, __rhs: *const Self) -> bool { - let x: *const Tmpl_int_ = self as *const Tmpl_int_; - let y: *const Tmpl_int_ = (&*__rhs) as *const Tmpl_int_; + unsafe fn equal(x: *const Tmpl_int_, y: *const Tmpl_int_) -> bool { return (((*x).v) == ((*y).v)); } } @@ -235,9 +225,7 @@ pub struct Tmpl_long_ { pub v: i64, } impl WeaklyEqualityComparableWithUnsafe for TmplDefaulted_int_ { - unsafe fn equal(&self, __rhs: *const Self) -> bool { - let _a0: *const TmplDefaulted_int_ = self as *const TmplDefaulted_int_; - let _a1: *const TmplDefaulted_int_ = (&*__rhs) as *const TmplDefaulted_int_; + unsafe fn equal(_a0: *const TmplDefaulted_int_, _a1: *const TmplDefaulted_int_) -> bool { return (((*_a0).v) == ((*_a1).v)); } } @@ -276,19 +264,19 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _arg0: *const Defaulted = &d1; - WeaklyEqualityComparableWithUnsafe::equal(&*(_arg0), &d2) + WeaklyEqualityComparableWithUnsafe::equal(_arg0, &d2) }) ); assert!( !(unsafe { let _arg0: *const Defaulted = &d1; - WeaklyEqualityComparableWithUnsafe::equal(&*(_arg0), &d3) + WeaklyEqualityComparableWithUnsafe::equal(_arg0, &d3) }) ); assert!( !(unsafe { let _arg0: *const Defaulted = &d1; - WeaklyEqualityComparableWithUnsafe::equal(&*(_arg0), &d3) + WeaklyEqualityComparableWithUnsafe::equal(_arg0, &d3) }) ); let mut o1: DefaultedOrd = DefaultedOrd { a: 1 }; @@ -309,7 +297,7 @@ unsafe fn main_0() -> i32 { (unsafe { let _arg0: *const DefaultedOrd = &o1; let _arg1: *const DefaultedOrd = &o1; - WeaklyEqualityComparableWithUnsafe::equal(&*(_arg0), _arg1) + WeaklyEqualityComparableWithUnsafe::equal(_arg0, _arg1) }) ); assert!( @@ -324,13 +312,13 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const Inline = &i1; - WeaklyEqualityComparableWithUnsafe::equal(&*(_x), &i3) + WeaklyEqualityComparableWithUnsafe::equal(_x, &i3) }) ); assert!( !(unsafe { let _x: *const Inline = &i1; - WeaklyEqualityComparableWithUnsafe::equal(&*(_x), &i2) + WeaklyEqualityComparableWithUnsafe::equal(_x, &i2) }) ); assert!( @@ -352,7 +340,7 @@ unsafe fn main_0() -> i32 { operator_add_2(_x, &i2) }); let mut _y: Inline = Inline { a: 3 }; - WeaklyEqualityComparableWithUnsafe::equal(&*(&mut _x), &mut _y) + WeaklyEqualityComparableWithUnsafe::equal(&mut _x, &mut _y) }) ); let mut f1: OutOfLine = OutOfLine { a: 4 }; @@ -361,7 +349,7 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const OutOfLine = &f1; - WeaklyEqualityComparableWithUnsafe::equal(&*(_x), &f2) + WeaklyEqualityComparableWithUnsafe::equal(_x, &f2) }) ); assert!( @@ -373,7 +361,7 @@ unsafe fn main_0() -> i32 { assert!( !(unsafe { let _x: *const OutOfLine = &f1; - WeaklyEqualityComparableWithUnsafe::equal(&*(_x), &f3) + WeaklyEqualityComparableWithUnsafe::equal(_x, &f3) }) ); let mut t1: Tmpl_int_ = Tmpl_int_ { v: 1 }; @@ -382,13 +370,13 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const Tmpl_int_ = &t1; - WeaklyEqualityComparableWithUnsafe::equal(&*(_x), &t3) + WeaklyEqualityComparableWithUnsafe::equal(_x, &t3) }) ); assert!( !(unsafe { let _x: *const Tmpl_int_ = &t1; - WeaklyEqualityComparableWithUnsafe::equal(&*(_x), &t2) + WeaklyEqualityComparableWithUnsafe::equal(_x, &t2) }) ); assert!( @@ -417,19 +405,19 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _arg0: *const TmplDefaulted_int_ = &v1; - WeaklyEqualityComparableWithUnsafe::equal(&*(_arg0), &v2) + WeaklyEqualityComparableWithUnsafe::equal(_arg0, &v2) }) ); assert!( !(unsafe { let _arg0: *const TmplDefaulted_int_ = &v1; - WeaklyEqualityComparableWithUnsafe::equal(&*(_arg0), &v3) + WeaklyEqualityComparableWithUnsafe::equal(_arg0, &v3) }) ); assert!( !(unsafe { let _arg0: *const TmplDefaulted_int_ = &v1; - WeaklyEqualityComparableWithUnsafe::equal(&*(_arg0), &v3) + WeaklyEqualityComparableWithUnsafe::equal(_arg0, &v3) }) ); return 0; diff --git a/tests/unit/out/unsafe/operator_three_way.rs b/tests/unit/out/unsafe/operator_three_way.rs index 001ceea13f..91a9003428 100644 --- a/tests/unit/out/unsafe/operator_three_way.rs +++ b/tests/unit/out/unsafe/operator_three_way.rs @@ -30,7 +30,9 @@ impl S { } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(this: *const Self, o: *const S) -> bool { +} +impl WeaklyEqualityComparableWithUnsafe for S { + unsafe fn equal(this: *const Self, o: *const S) -> bool { return (((*this).v) == ((*o).v)); } } @@ -46,7 +48,7 @@ impl std::cmp::PartialOrd for S { } impl std::cmp::PartialEq for S { fn eq(&self, other: &Self) -> bool { - unsafe { S::operator_eq(self, other as *const S) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const S) } } } impl std::cmp::Eq for S {} @@ -63,7 +65,7 @@ unsafe fn main_0() -> i32 { assert!((unsafe { S::operator_cmp(&raw const b, &a,) }) == std::cmp::Ordering::Greater); assert!((unsafe { S::operator_cmp(&raw const a, &b,) }) != std::cmp::Ordering::Greater); assert!((unsafe { S::operator_cmp(&raw const b, &a,) }) != std::cmp::Ordering::Less); - assert!(!(unsafe { S::operator_eq(&raw const a, &b,) })); + assert!(!(unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const a, &b,) })); assert!((unsafe { S::operator_cmp(&raw const a, &b,) }) == libcc2rs::STRONG_ORDERING_LESS); return 0; } diff --git a/tests/unit/out/unsafe/operator_traits.rs b/tests/unit/out/unsafe/operator_traits.rs index c5e3127926..9cdd91dc44 100644 --- a/tests/unit/out/unsafe/operator_traits.rs +++ b/tests/unit/out/unsafe/operator_traits.rs @@ -66,14 +66,14 @@ impl std::cmp::Eq for Lt {} pub struct Eq { pub v: i32, } -impl Eq { - pub unsafe fn operator_eq(this: *const Self, o: *const Eq) -> bool { +impl WeaklyEqualityComparableWithUnsafe for Eq { + unsafe fn equal(this: *const Self, o: *const Eq) -> bool { return (((*this).v) == ((*o).v)); } } impl std::cmp::PartialEq for Eq { fn eq(&self, other: &Self) -> bool { - unsafe { Eq::operator_eq(self, other as *const Eq) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Eq) } } } impl std::cmp::Eq for Eq {} @@ -95,7 +95,9 @@ impl Cmp { pub unsafe fn operator_cmp(this: *const Self, o: *const Cmp) -> std::cmp::Ordering { return std::cmp::Ord::cmp(&((*this).v), &((*o).v)); } - pub unsafe fn operator_eq(this: *const Self, o: *const Cmp) -> bool { +} +impl WeaklyEqualityComparableWithUnsafe for Cmp { + unsafe fn equal(this: *const Self, o: *const Cmp) -> bool { return (((*this).v) == ((*o).v)); } } @@ -111,7 +113,7 @@ impl std::cmp::PartialOrd for Cmp { } impl std::cmp::PartialEq for Cmp { fn eq(&self, other: &Self) -> bool { - unsafe { Cmp::operator_eq(self, other as *const Cmp) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Cmp) } } } impl std::cmp::Eq for Cmp {} @@ -149,15 +151,17 @@ impl std::cmp::PartialOrd for Free { } impl std::cmp::PartialEq for Free { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_1(self as *const Free, other as *const Free) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Free) } } } impl std::cmp::Eq for Free {} pub unsafe fn operator_lt_0(a: *const Free, b: *const Free) -> bool { return (((*a).v) < ((*b).v)); } -pub unsafe fn operator_eq_1(a: *const Free, b: *const Free) -> bool { - return (((*a).v) == ((*b).v)); +impl WeaklyEqualityComparableWithUnsafe for Free { + unsafe fn equal(a: *const Free, b: *const Free) -> bool { + return (((*a).v) == ((*b).v)); + } } #[repr(C)] #[derive( @@ -207,7 +211,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { eqs.begin() }; let mut __tmp_2 = { eqs.end() }; let mut __it = (__tmp_1).clone(); - while __it != __tmp_2 && *__it.iter_deref() != two { + while __it != __tmp_2 + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &two) + { __it.iter_inc(); } __it @@ -220,7 +226,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_3 = { eqs.begin() }; let mut __tmp_4 = { eqs.end() }; let mut __it = (__tmp_3).clone(); - while __it != __tmp_4 && *__it.iter_deref() != nine { + while __it != __tmp_4 + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &nine) + { __it.iter_inc(); } __it @@ -247,7 +255,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_6 = { cmps.begin() }; let mut __tmp_7 = { cmps.end() }; let mut __it = (__tmp_6).clone(); - while __it != __tmp_7 && *__it.iter_deref() != three { + while __it != __tmp_7 + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &three) + { __it.iter_inc(); } __it @@ -276,7 +286,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_9 = { frees.begin() }; let mut __tmp_10 = { frees.end() }; let mut __it = (__tmp_9).clone(); - while __it != __tmp_10 && *__it.iter_deref() != ftwo { + while __it != __tmp_10 + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &ftwo) + { __it.iter_inc(); } __it diff --git a/tests/unit/out/unsafe/sort_no_copy.rs b/tests/unit/out/unsafe/sort_no_copy.rs index 3ec644d0cc..34401bf3a7 100644 --- a/tests/unit/out/unsafe/sort_no_copy.rs +++ b/tests/unit/out/unsafe/sort_no_copy.rs @@ -181,15 +181,17 @@ impl std::cmp::PartialOrd for Bag { } impl std::cmp::PartialEq for Bag { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_5(self as *const Bag, other as *const Bag) } + unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Bag) } } } impl std::cmp::Eq for Bag {} pub unsafe fn operator_lt_4(a: *const Bag, b: *const Bag) -> bool { return (((*a).items.len()) < ((*b).items.len())); } -pub unsafe fn operator_eq_5(a: *const Bag, b: *const Bag) -> bool { - return (((*a).items.len()) == ((*b).items.len())); +impl WeaklyEqualityComparableWithUnsafe for Bag { + unsafe fn equal(a: *const Bag, b: *const Bag) -> bool { + return (((*a).items.len()) == ((*b).items.len())); + } } pub fn main() { unsafe { @@ -470,7 +472,12 @@ unsafe fn main_0() -> i32 { let mut __tmp_7 = { bag_vec.begin() }; let mut __tmp_8 = { bag_vec.end() }; let mut __it = (__tmp_7).clone(); - while __it != __tmp_8 && *__it.iter_deref() != bags[(1) as usize] { + while __it != __tmp_8 + && !WeaklyEqualityComparableWithUnsafe::equal( + &*__it.iter_deref(), + &bags[(1) as usize], + ) + { __it.iter_inc(); } __it From 8bab5d5c10374f16dec3af9840bb0bfb9e5bb05b Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 12:56:20 +0000 Subject: [PATCH 09/18] Fix signature of trait derived from free function operator --- cpp2rust/converter/converter.cpp | 71 +++++++++++++------ cpp2rust/converter/converter.h | 10 ++- cpp2rust/converter/converter_lib.h | 5 +- .../converter/models/converter_refcount.cpp | 36 +++++----- .../converter/models/converter_refcount.h | 4 +- 5 files changed, 80 insertions(+), 46 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index e734aa53ff..a9e7c973e4 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -2726,8 +2726,6 @@ bool Converter::EmitComparisonTraitCallee(const CallInfo &info) { return true; } -const char *Converter::GetComparisonRhs() const { return "(&*__rhs)"; } - void Converter::ConvertGenericCallExpr(clang::CallExpr *expr) { PushParen outer(*this); StrCat(keyword_unsafe_); @@ -5918,12 +5916,16 @@ std::string Converter::GetComparisonBool(const clang::FunctionDecl *op, } std::string Converter::GetComparisonArg(const clang::ParmVarDecl *param, - const clang::CXXRecordDecl *decl, + const clang::CXXRecordDecl *, std::string_view value) { - if (param->getType()->isReferenceType()) { - return std::format("{} as *const {}", value, GetRecordName(decl)); + auto type = param->getType(); + if (!type->isReferenceType()) { + return std::format("(*{}).clone()", value); + } + if (type.getNonReferenceType().isConstQualified()) { + return std::string(value); } - return std::format("{}.clone()", value); + return std::format("{}.cast_mut()", value); } std::string @@ -5931,18 +5933,18 @@ Converter::GetComparisonResultReceiver(const clang::CXXMethodDecl *method, bool returns_ref, std::string_view result) { return GetComparisonReceiver( - method, std::format("{}{}", returns_ref ? "&*" : "&", result)); + method, returns_ref ? std::format("({} as *const _)", result) + : std::format("(&raw const {})", result)); } std::string Converter::GetComparisonReceiver(const clang::CXXMethodDecl *method, std::string_view lhs) { - if (!MethodNeedsMutableReceiver(method)) { - return std::string(lhs); - } + bool is_mut = MethodNeedsMutableReceiver(method); if (!IsMethodOnPtr(method)) { - return std::format("&mut *(&raw const *{}).cast_mut()", lhs); + return is_mut ? std::format("&mut *{}.cast_mut()", lhs) + : std::format("&*{}", lhs); } - return std::format("(&raw const *{}).cast_mut()", lhs); + return is_mut ? std::format("{}.cast_mut()", lhs) : std::string(lhs); } std::string Converter::GetEqBody(const clang::CXXRecordDecl *decl, @@ -5965,29 +5967,54 @@ void Converter::ConvertOrdAndPartialOrdTraits(const clang::CXXRecordDecl *decl, const clang::FunctionDecl *eq, const clang::FunctionDecl *lt, const clang::FunctionDecl *cmp) { + const char *kSelfPtr = "(self as *const Self)"; + const char *kOtherPtr = "(other as *const Self)"; std::string cmp_body; if (cmp) { - cmp_body = GetComparisonCall(cmp, decl, "self", "other"); + cmp_body = GetComparisonCall(cmp, decl, kSelfPtr, kOtherPtr); } else if (lt) { cmp_body = std::format("if {} {{ std::cmp::Ordering::Less }} else if {} {{ " "std::cmp::Ordering::Greater }} else {{ " "std::cmp::Ordering::Equal }}", - GetComparisonBool(lt, decl, "self", "other"), - GetComparisonBool(lt, decl, "other", "self")); + GetComparisonBool(lt, decl, kSelfPtr, kOtherPtr), + GetComparisonBool(lt, decl, kOtherPtr, kSelfPtr)); } ConvertOrdAndPartialOrdTraitsBase( - cmp_body, GetEqBody(decl, eq, lt, cmp, "self", "other"), + cmp_body, GetEqBody(decl, eq, lt, cmp, kSelfPtr, kOtherPtr), GetRecordName(decl)); if (eq && !GetComparisonTrait(eq)) { - const auto &spelling = - GetRecordTraitSpelling(kWeaklyEqualityComparableWith); - StrCat(std::format( - "impl {} for {} {{ {} {{ {} }} }}", spelling.name, GetRecordName(decl), - spelling.signature, - GetComparisonBool(eq, decl, spelling.receiver, GetComparisonRhs()))); + ConvertEqualityComparableImpl(decl, eq); } } +std::pair +Converter::GetComparisonOperandNames(const clang::FunctionDecl *op) { + auto params = DefinitionParameters(op); + return {clang::isa(op) + ? "this" + : GetNamedDeclAsString(params.front()), + GetNamedDeclAsString(params.back())}; +} + +void Converter::ConvertEqualityComparableImpl(const clang::CXXRecordDecl *decl, + const clang::FunctionDecl *eq) { + const auto &trait = kWeaklyEqualityComparableWith; + auto [lhs, rhs] = GetComparisonOperandNames(eq); + StrCat(keyword::kImpl, GetRecordTraitSpelling(trait).name, "for", + GetRecordName(decl)); + PushBrace impl_brace(*this); + StrCat(GetComparisonTraitSignature(trait, lhs, rhs)); + PushBrace body(*this); + StrCat(GetComparisonBool(eq, decl, lhs, rhs)); +} + +std::string Converter::GetComparisonTraitSignature(const RecordTrait &trait, + std::string_view lhs, + std::string_view rhs) const { + return std::format("unsafe fn {}({}: *const Self, {}: *const Self) -> bool", + trait.method, lhs, rhs); +} + void Converter::AddOrdTrait(const clang::CXXRecordDecl *decl) { const clang::FunctionDecl *eq = nullptr; const clang::FunctionDecl *lt = nullptr; diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index a10fbb1971..cebf68db0a 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -490,7 +490,15 @@ class Converter : public clang::RecursiveASTVisitor { void ConvertComparisonTraitImpl(clang::FunctionDecl *decl, const RecordTrait &trait); - virtual const char *GetComparisonRhs() const; + virtual std::string GetComparisonTraitSignature(const RecordTrait &trait, + std::string_view lhs, + std::string_view rhs) const; + + std::pair + GetComparisonOperandNames(const clang::FunctionDecl *op); + + void ConvertEqualityComparableImpl(const clang::CXXRecordDecl *decl, + const clang::FunctionDecl *eq); void ConvertParamTy(clang::QualType param_type, clang::Expr *expr); diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index aaf40644fa..b62df6f3b1 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -167,10 +167,9 @@ inline constexpr RecordTrait kDestructible{ inline constexpr RecordTrait kWeaklyEqualityComparableWith{ "equal", {"WeaklyEqualityComparableWith", - "fn equal(this: Ptr, __rhs: Ptr) -> bool", "this.clone()"}, + "fn equal(this: Ptr, _: Ptr) -> bool", "this.clone()"}, {"WeaklyEqualityComparableWithUnsafe", - "unsafe fn equal(this: *const Self, __rhs: *const Self) -> bool", - "(&*this)"}}; + "unsafe fn equal(this: *const Self, _: *const Self) -> bool", "this"}}; inline constexpr RecordTrait kTriviallyDefaultConstructible{ nullptr, {"TriviallyDefaultConstructible"}, diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 144c095d5d..acbb6d60fb 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -673,30 +673,28 @@ void ConverterRefCount::ConvertOrdAndPartialOrdTraits( const clang::CXXRecordDecl *decl, const clang::FunctionDecl *eq, const clang::FunctionDecl *lt, const clang::FunctionDecl *cmp) { auto record_name = GetRecordName(decl); - auto emit = [&](std::string_view trait, std::string_view fn, - std::string_view body) { - StrCat(std::format("impl {} for {} {{ fn {}(__lhs: Ptr, " - "__rhs: Ptr) -> bool {{ {} }} }}", - trait, record_name, fn, body)); - }; - if (lt) { - emit("CppLess", "less", GetComparisonBool(lt, decl, "__lhs", "__rhs")); - } else if (cmp) { - emit("CppLess", "less", - std::format("{} == std::cmp::Ordering::Less", - GetComparisonCall(cmp, decl, "__lhs", "__rhs"))); + if (auto *op = lt ? lt : cmp) { + auto [lhs, rhs] = GetComparisonOperandNames(op); + StrCat(std::format( + "impl CppLess for {} {{ fn less({}: Ptr, {}: Ptr) -> bool " + "{{ {} }} }}", + record_name, lhs, rhs, + lt ? GetComparisonBool(lt, decl, lhs, rhs) + : std::format("{} == std::cmp::Ordering::Less", + GetComparisonCall(cmp, decl, lhs, rhs)))); } if (eq && !GetComparisonTrait(eq)) { - const auto &spelling = - GetRecordTraitSpelling(kWeaklyEqualityComparableWith); - StrCat(std::format( - "impl {} for {} {{ {} {{ {} }} }}", spelling.name, record_name, - spelling.signature, - GetComparisonBool(eq, decl, spelling.receiver, GetComparisonRhs()))); + ConvertEqualityComparableImpl(decl, eq); } } -const char *ConverterRefCount::GetComparisonRhs() const { return "__rhs"; } +std::string +ConverterRefCount::GetComparisonTraitSignature(const RecordTrait &trait, + std::string_view lhs, + std::string_view rhs) const { + return std::format("fn {}({}: Ptr, {}: Ptr) -> bool", + trait.method, lhs, rhs); +} // Whether decl is copied by copying its bytes or the pointers it holds. static bool IsClonedShallowly(const clang::RecordDecl *decl) { diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index 0114ab1513..a3a1465525 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -58,7 +58,9 @@ class ConverterRefCount final : public Converter { const clang::FunctionDecl *lt, const clang::FunctionDecl *cmp) override; - const char *GetComparisonRhs() const override; + std::string GetComparisonTraitSignature(const RecordTrait &trait, + std::string_view lhs, + std::string_view rhs) const override; bool RecordImplementsClone(const clang::RecordDecl *decl) override; From 9d010c0274e0ee9031a49c69ba0c6ec850ef7ec5 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 12:59:16 +0000 Subject: [PATCH 10/18] Update tests --- tests/unit/out/unsafe/class.rs | 4 +- tests/unit/out/unsafe/find.rs | 4 +- tests/unit/out/unsafe/friend.rs | 4 +- tests/unit/out/unsafe/map_key_copy_ctor.rs | 8 +-- tests/unit/out/unsafe/map_key_identity.rs | 8 ++- tests/unit/out/unsafe/max.rs | 8 +-- .../unsafe/operator_comparison_defaulted.rs | 49 ++++++++++----- .../out/unsafe/operator_comparison_free.rs | 27 +++++--- .../out/unsafe/operator_comparison_member.rs | 8 ++- .../out/unsafe/operator_comparison_nonbool.rs | 62 +++++++++++++------ .../unsafe/operator_comparison_noncopyable.rs | 8 ++- tests/unit/out/unsafe/operator_friend.rs | 32 ++++++---- tests/unit/out/unsafe/operator_less_than.rs | 8 +-- tests/unit/out/unsafe/operator_three_way.rs | 6 +- tests/unit/out/unsafe/operator_traits.rs | 26 +++++--- tests/unit/out/unsafe/sort_no_copy.rs | 24 +++---- 16 files changed, 186 insertions(+), 100 deletions(-) diff --git a/tests/unit/out/unsafe/class.rs b/tests/unit/out/unsafe/class.rs index a9e1375d63..ece9c26b13 100644 --- a/tests/unit/out/unsafe/class.rs +++ b/tests/unit/out/unsafe/class.rs @@ -101,7 +101,9 @@ impl WeaklyEqualityComparableWithUnsafe for Counter { } impl std::cmp::PartialEq for Counter { fn eq(&self, other: &Self) -> bool { - unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Counter) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Counter {} diff --git a/tests/unit/out/unsafe/find.rs b/tests/unit/out/unsafe/find.rs index ed78867061..fe2946da88 100644 --- a/tests/unit/out/unsafe/find.rs +++ b/tests/unit/out/unsafe/find.rs @@ -27,7 +27,9 @@ impl WeaklyEqualityComparableWithUnsafe for P { } impl std::cmp::PartialEq for P { fn eq(&self, other: &Self) -> bool { - unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const P) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for P {} diff --git a/tests/unit/out/unsafe/friend.rs b/tests/unit/out/unsafe/friend.rs index f12ece54cb..6291384b01 100644 --- a/tests/unit/out/unsafe/friend.rs +++ b/tests/unit/out/unsafe/friend.rs @@ -36,7 +36,9 @@ pub struct V { } impl std::cmp::PartialEq for V { fn eq(&self, other: &Self) -> bool { - unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const V) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for V {} diff --git a/tests/unit/out/unsafe/map_key_copy_ctor.rs b/tests/unit/out/unsafe/map_key_copy_ctor.rs index 3db77d5c8f..019299a70c 100644 --- a/tests/unit/out/unsafe/map_key_copy_ctor.rs +++ b/tests/unit/out/unsafe/map_key_copy_ctor.rs @@ -40,9 +40,9 @@ impl MoveConstructibleUnsafe for Key { impl std::cmp::Ord for Key { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if Key::operator_lt(self, other as *const Key) { + if Key::operator_lt((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if Key::operator_lt(other, self as *const Key) { + } else if Key::operator_lt((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -58,8 +58,8 @@ impl std::cmp::PartialOrd for Key { impl std::cmp::PartialEq for Key { fn eq(&self, other: &Self) -> bool { unsafe { - !(Key::operator_lt(self, other as *const Key)) - && !(Key::operator_lt(other, self as *const Key)) + !(Key::operator_lt((self as *const Self), (other as *const Self))) + && !(Key::operator_lt((other as *const Self), (self as *const Self))) } } } diff --git a/tests/unit/out/unsafe/map_key_identity.rs b/tests/unit/out/unsafe/map_key_identity.rs index 2b2431c20f..87ffed5547 100644 --- a/tests/unit/out/unsafe/map_key_identity.rs +++ b/tests/unit/out/unsafe/map_key_identity.rs @@ -26,9 +26,9 @@ pub struct Key { impl std::cmp::Ord for Key { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_1(self as *const Key, other as *const Key) { + if operator_lt_1((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_1(other as *const Key, self as *const Key) { + } else if operator_lt_1((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -43,7 +43,9 @@ impl std::cmp::PartialOrd for Key { } impl std::cmp::PartialEq for Key { fn eq(&self, other: &Self) -> bool { - unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Key) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Key {} diff --git a/tests/unit/out/unsafe/max.rs b/tests/unit/out/unsafe/max.rs index 2418d926f2..5576cdc089 100644 --- a/tests/unit/out/unsafe/max.rs +++ b/tests/unit/out/unsafe/max.rs @@ -47,9 +47,9 @@ impl CopyConstructibleUnsafe for Bag { impl std::cmp::Ord for Bag { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_4(self as *const Bag, other as *const Bag) { + if operator_lt_4((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_4(other as *const Bag, self as *const Bag) { + } else if operator_lt_4((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -65,8 +65,8 @@ impl std::cmp::PartialOrd for Bag { impl std::cmp::PartialEq for Bag { fn eq(&self, other: &Self) -> bool { unsafe { - !(operator_lt_4(self as *const Bag, other as *const Bag)) - && !(operator_lt_4(other as *const Bag, self as *const Bag)) + !(operator_lt_4((self as *const Self), (other as *const Self))) + && !(operator_lt_4((other as *const Self), (self as *const Self))) } } } diff --git a/tests/unit/out/unsafe/operator_comparison_defaulted.rs b/tests/unit/out/unsafe/operator_comparison_defaulted.rs index fee2384db5..96f4589540 100644 --- a/tests/unit/out/unsafe/operator_comparison_defaulted.rs +++ b/tests/unit/out/unsafe/operator_comparison_defaulted.rs @@ -28,7 +28,9 @@ impl WeaklyEqualityComparableWithUnsafe for Eq { } impl std::cmp::PartialEq for Eq { fn eq(&self, other: &Self) -> bool { - unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Eq) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Eq {} @@ -71,7 +73,7 @@ impl WeaklyEqualityComparableWithUnsafe for Cmp { } impl std::cmp::Ord for Cmp { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { Cmp::operator_cmp(self, other as *const Cmp) } + unsafe { Cmp::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for Cmp { @@ -81,7 +83,10 @@ impl std::cmp::PartialOrd for Cmp { } impl std::cmp::PartialEq for Cmp { fn eq(&self, other: &Self) -> bool { - unsafe { Cmp::operator_cmp(self, other as *const Cmp) == std::cmp::Ordering::Equal } + unsafe { + Cmp::operator_cmp((self as *const Self), (other as *const Self)) + == std::cmp::Ordering::Equal + } } } impl std::cmp::Eq for Cmp {} @@ -117,7 +122,7 @@ impl WeaklyEqualityComparableWithUnsafe for Both { } impl std::cmp::Ord for Both { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { Both::operator_cmp(self, other as *const Both) } + unsafe { Both::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for Both { @@ -127,7 +132,9 @@ impl std::cmp::PartialOrd for Both { } impl std::cmp::PartialEq for Both { fn eq(&self, other: &Self) -> bool { - unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Both) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Both {} @@ -158,7 +165,7 @@ impl OrdOnly { } impl std::cmp::Ord for OrdOnly { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { OrdOnly::operator_cmp(self, other as *const OrdOnly) } + unsafe { OrdOnly::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for OrdOnly { @@ -168,7 +175,10 @@ impl std::cmp::PartialOrd for OrdOnly { } impl std::cmp::PartialEq for OrdOnly { fn eq(&self, other: &Self) -> bool { - unsafe { OrdOnly::operator_cmp(self, other as *const OrdOnly) == std::cmp::Ordering::Equal } + unsafe { + OrdOnly::operator_cmp((self as *const Self), (other as *const Self)) + == std::cmp::Ordering::Equal + } } } impl std::cmp::Eq for OrdOnly {} @@ -204,7 +214,7 @@ impl WeaklyEqualityComparableWithUnsafe for Inner { } impl std::cmp::Ord for Inner { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { Inner::operator_cmp(self, other as *const Inner) } + unsafe { Inner::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for Inner { @@ -214,7 +224,10 @@ impl std::cmp::PartialOrd for Inner { } impl std::cmp::PartialEq for Inner { fn eq(&self, other: &Self) -> bool { - unsafe { Inner::operator_cmp(self, other as *const Inner) == std::cmp::Ordering::Equal } + unsafe { + Inner::operator_cmp((self as *const Self), (other as *const Self)) + == std::cmp::Ordering::Equal + } } } impl std::cmp::Eq for Inner {} @@ -263,7 +276,7 @@ impl WeaklyEqualityComparableWithUnsafe for Outer { } impl std::cmp::Ord for Outer { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { Outer::operator_cmp(self, other as *const Outer) } + unsafe { Outer::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for Outer { @@ -273,7 +286,10 @@ impl std::cmp::PartialOrd for Outer { } impl std::cmp::PartialEq for Outer { fn eq(&self, other: &Self) -> bool { - unsafe { Outer::operator_cmp(self, other as *const Outer) == std::cmp::Ordering::Equal } + unsafe { + Outer::operator_cmp((self as *const Self), (other as *const Self)) + == std::cmp::Ordering::Equal + } } } impl std::cmp::Eq for Outer {} @@ -320,7 +336,7 @@ impl WeaklyEqualityComparableWithUnsafe for Secondary { } impl std::cmp::Ord for Secondary { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { Secondary::operator_cmp(self, other as *const Secondary) } + unsafe { Secondary::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for Secondary { @@ -330,7 +346,9 @@ impl std::cmp::PartialOrd for Secondary { } impl std::cmp::PartialEq for Secondary { fn eq(&self, other: &Self) -> bool { - unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Secondary) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Secondary {} @@ -366,7 +384,7 @@ impl WeaklyEqualityComparableWithUnsafe for PtrMember { } impl std::cmp::Ord for PtrMember { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { PtrMember::operator_cmp(self, other as *const PtrMember) } + unsafe { PtrMember::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for PtrMember { @@ -377,7 +395,8 @@ impl std::cmp::PartialOrd for PtrMember { impl std::cmp::PartialEq for PtrMember { fn eq(&self, other: &Self) -> bool { unsafe { - PtrMember::operator_cmp(self, other as *const PtrMember) == std::cmp::Ordering::Equal + PtrMember::operator_cmp((self as *const Self), (other as *const Self)) + == std::cmp::Ordering::Equal } } } diff --git a/tests/unit/out/unsafe/operator_comparison_free.rs b/tests/unit/out/unsafe/operator_comparison_free.rs index 2e2e9eb9fd..201d8c1b6a 100644 --- a/tests/unit/out/unsafe/operator_comparison_free.rs +++ b/tests/unit/out/unsafe/operator_comparison_free.rs @@ -23,9 +23,9 @@ pub struct S { impl std::cmp::Ord for S { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_0(self as *const S, other as *const S) { + if operator_lt_0((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_0(other as *const S, self as *const S) { + } else if operator_lt_0((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -40,7 +40,9 @@ impl std::cmp::PartialOrd for S { } impl std::cmp::PartialEq for S { fn eq(&self, other: &Self) -> bool { - unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const S) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for S {} @@ -87,9 +89,15 @@ pub struct V { impl std::cmp::Ord for V { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_7(self.clone(), other.clone()) { + if operator_lt_7( + (*(self as *const Self)).clone(), + (*(other as *const Self)).clone(), + ) { std::cmp::Ordering::Less - } else if operator_lt_7(other.clone(), self.clone()) { + } else if operator_lt_7( + (*(other as *const Self)).clone(), + (*(self as *const Self)).clone(), + ) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -104,13 +112,18 @@ impl std::cmp::PartialOrd for V { } impl std::cmp::PartialEq for V { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_8(self.clone(), other.clone()) } + unsafe { + operator_eq_8( + (*(self as *const Self)).clone(), + (*(other as *const Self)).clone(), + ) + } } } impl std::cmp::Eq for V {} impl WeaklyEqualityComparableWithUnsafe for V { unsafe fn equal(a: *const Self, b: *const Self) -> bool { - operator_eq_8((&*a).clone(), (&*b).clone()) + operator_eq_8((*a).clone(), (*b).clone()) } } pub unsafe fn operator_eq_8(mut a: V, mut b: V) -> bool { diff --git a/tests/unit/out/unsafe/operator_comparison_member.rs b/tests/unit/out/unsafe/operator_comparison_member.rs index e17c1b0739..59be403cde 100644 --- a/tests/unit/out/unsafe/operator_comparison_member.rs +++ b/tests/unit/out/unsafe/operator_comparison_member.rs @@ -48,9 +48,9 @@ impl WeaklyEqualityComparableWithUnsafe for S { impl std::cmp::Ord for S { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if S::operator_lt_3(self, other as *const S) { + if S::operator_lt_3((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if S::operator_lt_3(other, self as *const S) { + } else if S::operator_lt_3((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -65,7 +65,9 @@ impl std::cmp::PartialOrd for S { } impl std::cmp::PartialEq for S { fn eq(&self, other: &Self) -> bool { - unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const S) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for S {} diff --git a/tests/unit/out/unsafe/operator_comparison_nonbool.rs b/tests/unit/out/unsafe/operator_comparison_nonbool.rs index cf9a37ae36..0af4c100c8 100644 --- a/tests/unit/out/unsafe/operator_comparison_nonbool.rs +++ b/tests/unit/out/unsafe/operator_comparison_nonbool.rs @@ -23,9 +23,17 @@ pub struct X { impl std::cmp::Ord for X { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if ((operator_lt_0(self.clone(), other.clone())) != 0) { + if ((operator_lt_0( + (*(self as *const Self)).clone(), + (*(other as *const Self)).clone(), + )) != 0) + { std::cmp::Ordering::Less - } else if ((operator_lt_0(other.clone(), self.clone())) != 0) { + } else if ((operator_lt_0( + (*(other as *const Self)).clone(), + (*(self as *const Self)).clone(), + )) != 0) + { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -40,13 +48,18 @@ impl std::cmp::PartialOrd for X { } impl std::cmp::PartialEq for X { fn eq(&self, other: &Self) -> bool { - unsafe { ((operator_eq_1(self.clone(), other.clone())) != 0) } + unsafe { + ((operator_eq_1( + (*(self as *const Self)).clone(), + (*(other as *const Self)).clone(), + )) != 0) + } } } impl std::cmp::Eq for X {} impl WeaklyEqualityComparableWithUnsafe for X { unsafe fn equal(a: *const Self, b: *const Self) -> bool { - ((operator_eq_1((&*a).clone(), (&*b).clone())) != 0) + ((operator_eq_1((*a).clone(), (*b).clone())) != 0) } } pub unsafe fn operator_eq_1(mut a: X, mut b: X) -> i32 { @@ -132,9 +145,9 @@ impl Mixed { impl std::cmp::Ord for Mixed { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if ((Mixed::operator_lt(self, other as *const Mixed)) != 0) { + if ((Mixed::operator_lt((self as *const Self), (other as *const Self))) != 0) { std::cmp::Ordering::Less - } else if ((Mixed::operator_lt(other, self as *const Mixed)) != 0) { + } else if ((Mixed::operator_lt((other as *const Self), (self as *const Self))) != 0) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -149,13 +162,13 @@ impl std::cmp::PartialOrd for Mixed { } impl std::cmp::PartialEq for Mixed { fn eq(&self, other: &Self) -> bool { - unsafe { ((Mixed::operator_eq(self, other as *const Mixed)) != 0) } + unsafe { ((Mixed::operator_eq((self as *const Self), (other as *const Self))) != 0) } } } impl std::cmp::Eq for Mixed {} impl WeaklyEqualityComparableWithUnsafe for Mixed { unsafe fn equal(this: *const Self, o: *const Self) -> bool { - ((Mixed::operator_eq((&*this), (&*o) as *const Mixed)) != 0) + ((Mixed::operator_eq(this, o)) != 0) } } #[repr(C)] @@ -200,13 +213,19 @@ impl std::cmp::Ord for Boolish { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { if { - let __cmp = operator_lt_6(self.clone(), other.clone()); - MyBool::to_bool(&__cmp) + let __cmp = operator_lt_6( + (*(self as *const Self)).clone(), + (*(other as *const Self)).clone(), + ); + MyBool::to_bool((&raw const __cmp)) } { std::cmp::Ordering::Less } else if { - let __cmp = operator_lt_6(other.clone(), self.clone()); - MyBool::to_bool(&__cmp) + let __cmp = operator_lt_6( + (*(other as *const Self)).clone(), + (*(self as *const Self)).clone(), + ); + MyBool::to_bool((&raw const __cmp)) } { std::cmp::Ordering::Greater } else { @@ -224,8 +243,11 @@ impl std::cmp::PartialEq for Boolish { fn eq(&self, other: &Self) -> bool { unsafe { { - let __cmp = operator_eq_7(self.clone(), other.clone()); - MyBool::to_bool(&__cmp) + let __cmp = operator_eq_7( + (*(self as *const Self)).clone(), + (*(other as *const Self)).clone(), + ); + MyBool::to_bool((&raw const __cmp)) } } } @@ -234,8 +256,8 @@ impl std::cmp::Eq for Boolish {} impl WeaklyEqualityComparableWithUnsafe for Boolish { unsafe fn equal(a: *const Self, b: *const Self) -> bool { { - let __cmp = operator_eq_7((&*a).clone(), (&*b).clone()); - MyBool::to_bool(&__cmp) + let __cmp = operator_eq_7((*a).clone(), (*b).clone()); + MyBool::to_bool((&raw const __cmp)) } } } @@ -306,8 +328,8 @@ impl std::cmp::PartialEq for RefInt { fn eq(&self, other: &Self) -> bool { unsafe { { - let __cmp = RefInt::operator_eq(self, other as *const RefInt); - RefBool::to_bool(&*__cmp) + let __cmp = RefInt::operator_eq((self as *const Self), (other as *const Self)); + RefBool::to_bool((__cmp as *const _)) } } } @@ -316,8 +338,8 @@ impl std::cmp::Eq for RefInt {} impl WeaklyEqualityComparableWithUnsafe for RefInt { unsafe fn equal(this: *const Self, _a0: *const Self) -> bool { { - let __cmp = RefInt::operator_eq((&*this), (&*_a0) as *const RefInt); - RefBool::to_bool(&*__cmp) + let __cmp = RefInt::operator_eq(this, _a0); + RefBool::to_bool((__cmp as *const _)) } } } diff --git a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs index 7f3188b42b..55478842c6 100644 --- a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs +++ b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs @@ -36,9 +36,9 @@ impl S { impl std::cmp::Ord for S { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_0(self as *const S, other as *const S) { + if operator_lt_0((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_0(other as *const S, self as *const S) { + } else if operator_lt_0((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -53,7 +53,9 @@ impl std::cmp::PartialOrd for S { } impl std::cmp::PartialEq for S { fn eq(&self, other: &Self) -> bool { - unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const S) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for S {} diff --git a/tests/unit/out/unsafe/operator_friend.rs b/tests/unit/out/unsafe/operator_friend.rs index cf29633f8d..f647ed7091 100644 --- a/tests/unit/out/unsafe/operator_friend.rs +++ b/tests/unit/out/unsafe/operator_friend.rs @@ -28,7 +28,9 @@ pub struct Defaulted { } impl std::cmp::PartialEq for Defaulted { fn eq(&self, other: &Self) -> bool { - unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Defaulted) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Defaulted {} @@ -65,7 +67,7 @@ pub struct DefaultedOrd { } impl std::cmp::Ord for DefaultedOrd { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { operator_cmp_0(self as *const DefaultedOrd, other as *const DefaultedOrd) } + unsafe { operator_cmp_0((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for DefaultedOrd { @@ -75,7 +77,9 @@ impl std::cmp::PartialOrd for DefaultedOrd { } impl std::cmp::PartialEq for DefaultedOrd { fn eq(&self, other: &Self) -> bool { - unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const DefaultedOrd) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for DefaultedOrd {} @@ -109,9 +113,9 @@ pub struct Inline { impl std::cmp::Ord for Inline { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_1(self as *const Inline, other as *const Inline) { + if operator_lt_1((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_1(other as *const Inline, self as *const Inline) { + } else if operator_lt_1((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -126,7 +130,9 @@ impl std::cmp::PartialOrd for Inline { } impl std::cmp::PartialEq for Inline { fn eq(&self, other: &Self) -> bool { - unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Inline) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Inline {} @@ -146,7 +152,9 @@ pub struct OutOfLine { } impl std::cmp::PartialEq for OutOfLine { fn eq(&self, other: &Self) -> bool { - unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const OutOfLine) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for OutOfLine {} @@ -189,9 +197,9 @@ pub struct Tmpl_int_ { impl std::cmp::Ord for Tmpl_int_ { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_4(self as *const Tmpl_int_, other as *const Tmpl_int_) { + if operator_lt_4((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_4(other as *const Tmpl_int_, self as *const Tmpl_int_) { + } else if operator_lt_4((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -206,7 +214,9 @@ impl std::cmp::PartialOrd for Tmpl_int_ { } impl std::cmp::PartialEq for Tmpl_int_ { fn eq(&self, other: &Self) -> bool { - unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Tmpl_int_) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Tmpl_int_ {} @@ -246,7 +256,7 @@ pub struct TmplDefaulted_int_ { impl std::cmp::PartialEq for TmplDefaulted_int_ { fn eq(&self, other: &Self) -> bool { unsafe { - WeaklyEqualityComparableWithUnsafe::equal(self, other as *const TmplDefaulted_int_) + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) } } } diff --git a/tests/unit/out/unsafe/operator_less_than.rs b/tests/unit/out/unsafe/operator_less_than.rs index 5bf2faffa5..54ee1f8bf2 100644 --- a/tests/unit/out/unsafe/operator_less_than.rs +++ b/tests/unit/out/unsafe/operator_less_than.rs @@ -30,9 +30,9 @@ impl Pair { impl std::cmp::Ord for Pair { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if Pair::operator_lt((&raw const *self).cast_mut(), other as *const Pair) { + if Pair::operator_lt((self as *const Self).cast_mut(), (other as *const Self)) { std::cmp::Ordering::Less - } else if Pair::operator_lt((&raw const *other).cast_mut(), self as *const Pair) { + } else if Pair::operator_lt((other as *const Self).cast_mut(), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -48,8 +48,8 @@ impl std::cmp::PartialOrd for Pair { impl std::cmp::PartialEq for Pair { fn eq(&self, other: &Self) -> bool { unsafe { - !(Pair::operator_lt((&raw const *self).cast_mut(), other as *const Pair)) - && !(Pair::operator_lt((&raw const *other).cast_mut(), self as *const Pair)) + !(Pair::operator_lt((self as *const Self).cast_mut(), (other as *const Self))) + && !(Pair::operator_lt((other as *const Self).cast_mut(), (self as *const Self))) } } } diff --git a/tests/unit/out/unsafe/operator_three_way.rs b/tests/unit/out/unsafe/operator_three_way.rs index 91a9003428..9b05bcb14c 100644 --- a/tests/unit/out/unsafe/operator_three_way.rs +++ b/tests/unit/out/unsafe/operator_three_way.rs @@ -38,7 +38,7 @@ impl WeaklyEqualityComparableWithUnsafe for S { } impl std::cmp::Ord for S { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { S::operator_cmp(self, other as *const S) } + unsafe { S::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for S { @@ -48,7 +48,9 @@ impl std::cmp::PartialOrd for S { } impl std::cmp::PartialEq for S { fn eq(&self, other: &Self) -> bool { - unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const S) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for S {} diff --git a/tests/unit/out/unsafe/operator_traits.rs b/tests/unit/out/unsafe/operator_traits.rs index 9cdd91dc44..a7f1237627 100644 --- a/tests/unit/out/unsafe/operator_traits.rs +++ b/tests/unit/out/unsafe/operator_traits.rs @@ -28,9 +28,9 @@ impl Lt { impl std::cmp::Ord for Lt { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if Lt::operator_lt(self, other as *const Lt) { + if Lt::operator_lt((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if Lt::operator_lt(other, self as *const Lt) { + } else if Lt::operator_lt((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -46,8 +46,8 @@ impl std::cmp::PartialOrd for Lt { impl std::cmp::PartialEq for Lt { fn eq(&self, other: &Self) -> bool { unsafe { - !(Lt::operator_lt(self, other as *const Lt)) - && !(Lt::operator_lt(other, self as *const Lt)) + !(Lt::operator_lt((self as *const Self), (other as *const Self))) + && !(Lt::operator_lt((other as *const Self), (self as *const Self))) } } } @@ -73,7 +73,9 @@ impl WeaklyEqualityComparableWithUnsafe for Eq { } impl std::cmp::PartialEq for Eq { fn eq(&self, other: &Self) -> bool { - unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Eq) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Eq {} @@ -103,7 +105,7 @@ impl WeaklyEqualityComparableWithUnsafe for Cmp { } impl std::cmp::Ord for Cmp { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { Cmp::operator_cmp(self, other as *const Cmp) } + unsafe { Cmp::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for Cmp { @@ -113,7 +115,9 @@ impl std::cmp::PartialOrd for Cmp { } impl std::cmp::PartialEq for Cmp { fn eq(&self, other: &Self) -> bool { - unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Cmp) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Cmp {} @@ -134,9 +138,9 @@ pub struct Free { impl std::cmp::Ord for Free { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_0(self as *const Free, other as *const Free) { + if operator_lt_0((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_0(other as *const Free, self as *const Free) { + } else if operator_lt_0((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -151,7 +155,9 @@ impl std::cmp::PartialOrd for Free { } impl std::cmp::PartialEq for Free { fn eq(&self, other: &Self) -> bool { - unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Free) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Free {} diff --git a/tests/unit/out/unsafe/sort_no_copy.rs b/tests/unit/out/unsafe/sort_no_copy.rs index 34401bf3a7..3e9dfc67a3 100644 --- a/tests/unit/out/unsafe/sort_no_copy.rs +++ b/tests/unit/out/unsafe/sort_no_copy.rs @@ -52,9 +52,9 @@ impl MoveAssignableUnsafe for Tracked { impl std::cmp::Ord for Tracked { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_1(self as *const Tracked, other as *const Tracked) { + if operator_lt_1((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_1(other as *const Tracked, self as *const Tracked) { + } else if operator_lt_1((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -70,8 +70,8 @@ impl std::cmp::PartialOrd for Tracked { impl std::cmp::PartialEq for Tracked { fn eq(&self, other: &Self) -> bool { unsafe { - !(operator_lt_1(self as *const Tracked, other as *const Tracked)) - && !(operator_lt_1(other as *const Tracked, self as *const Tracked)) + !(operator_lt_1((self as *const Self), (other as *const Self))) + && !(operator_lt_1((other as *const Self), (self as *const Self))) } } } @@ -116,9 +116,9 @@ impl MoveOnly { impl std::cmp::Ord for MoveOnly { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_3(self as *const MoveOnly, other as *const MoveOnly) { + if operator_lt_3((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_3(other as *const MoveOnly, self as *const MoveOnly) { + } else if operator_lt_3((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -134,8 +134,8 @@ impl std::cmp::PartialOrd for MoveOnly { impl std::cmp::PartialEq for MoveOnly { fn eq(&self, other: &Self) -> bool { unsafe { - !(operator_lt_3(self as *const MoveOnly, other as *const MoveOnly)) - && !(operator_lt_3(other as *const MoveOnly, self as *const MoveOnly)) + !(operator_lt_3((self as *const Self), (other as *const Self))) + && !(operator_lt_3((other as *const Self), (self as *const Self))) } } } @@ -164,9 +164,9 @@ impl DefaultConstructibleUnsafe for Bag { impl std::cmp::Ord for Bag { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_4(self as *const Bag, other as *const Bag) { + if operator_lt_4((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_4(other as *const Bag, self as *const Bag) { + } else if operator_lt_4((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -181,7 +181,9 @@ impl std::cmp::PartialOrd for Bag { } impl std::cmp::PartialEq for Bag { fn eq(&self, other: &Self) -> bool { - unsafe { WeaklyEqualityComparableWithUnsafe::equal(self, other as *const Bag) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Bag {} From 4f7c7f77a06d9ad1d953475806b26cf94963d7cd Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 13:10:25 +0000 Subject: [PATCH 11/18] Use the equality traits inside rules --- rules/algorithm/tgt_refcount.rs | 74 ++-- rules/algorithm/tgt_unsafe.rs | 16 +- rules/iterator_category/shim.rs | 60 ++- rules/iterator_category/tgt_refcount.rs | 12 +- rules/iterator_category/tgt_unsafe.rs | 12 +- rules/vector/tgt_refcount.rs | 18 +- rules/vector/tgt_unsafe.rs | 4 +- .../refcount/container_element_receiver.rs | 18 +- tests/unit/out/refcount/copy_ctor.rs | 31 +- .../refcount/elidable_iterator_copy_cxx11.rs | 41 +- .../out/refcount/emplace_receiver_alias.rs | 18 +- .../out/refcount/emplace_receiver_order.rs | 40 +- tests/unit/out/refcount/find.rs | 244 +++++++----- tests/unit/out/refcount/map.rs | 363 ++++++++++-------- tests/unit/out/refcount/map_key_identity.rs | 143 ++++--- tests/unit/out/refcount/map_try_emplace.rs | 46 +-- tests/unit/out/refcount/max.rs | 83 ++-- .../refcount/operator_comparison_nonbool.rs | 16 +- tests/unit/out/refcount/operator_traits.rs | 101 ++--- tests/unit/out/refcount/push_emplace_back.rs | 101 ++--- .../refcount/redundant_copy_in_conversion.rs | 33 +- tests/unit/out/refcount/size_t_ssize_t.rs | 236 ++++++------ tests/unit/out/refcount/sort_no_copy.rs | 114 +++--- tests/unit/out/refcount/stdcopy.rs | 54 +-- tests/unit/out/refcount/stdcopy_ostream.rs | 9 +- .../refcount/unboxed_conditional_iterator.rs | 42 +- tests/unit/out/refcount/vector.rs | 185 ++++----- .../out/refcount/vector_iter_range_ctor.rs | 141 +++---- .../out/refcount/vector_with_allocator.rs | 50 +-- .../out/unsafe/container_element_receiver.rs | 2 +- tests/unit/out/unsafe/copy_ctor.rs | 2 +- .../unsafe/elidable_iterator_copy_cxx11.rs | 5 +- .../unit/out/unsafe/emplace_receiver_alias.rs | 2 +- .../unit/out/unsafe/emplace_receiver_order.rs | 4 +- tests/unit/out/unsafe/find.rs | 76 ++-- tests/unit/out/unsafe/map.rs | 37 +- tests/unit/out/unsafe/map_key_identity.rs | 47 ++- tests/unit/out/unsafe/map_try_emplace.rs | 6 +- tests/unit/out/unsafe/max.rs | 4 +- .../out/unsafe/operator_comparison_nonbool.rs | 2 +- tests/unit/out/unsafe/operator_traits.rs | 17 +- tests/unit/out/unsafe/push_emplace_back.rs | 8 +- .../unsafe/redundant_copy_in_conversion.rs | 21 +- tests/unit/out/unsafe/size_t_ssize_t.rs | 22 +- tests/unit/out/unsafe/sort_no_copy.rs | 29 +- tests/unit/out/unsafe/stdcopy.rs | 8 +- tests/unit/out/unsafe/stdcopy_ostream.rs | 2 +- .../unsafe/unboxed_conditional_iterator.rs | 9 +- tests/unit/out/unsafe/vector.rs | 12 +- .../unit/out/unsafe/vector_iter_range_ctor.rs | 18 +- .../unit/out/unsafe/vector_with_allocator.rs | 10 +- 51 files changed, 1531 insertions(+), 1117 deletions(-) diff --git a/rules/algorithm/tgt_refcount.rs b/rules/algorithm/tgt_refcount.rs index 3f52f2b689..67e2ed34c1 100644 --- a/rules/algorithm/tgt_refcount.rs +++ b/rules/algorithm/tgt_refcount.rs @@ -23,22 +23,26 @@ fn f2< a1: T1, a2: T2, ) -> T2 { - let mut __first = a0; + let __first: Value = Rc::new(RefCell::new(a0)); + let __last: Value = Rc::new(RefCell::new(a1)); let mut __out = a2; - while __first != a1 { - __out.iter_deref().write(T4::cpp_from(__first.iter_deref())); - __first.iter_inc(); + while !::equal(__first.as_pointer(), __last.as_pointer()) { + __out.iter_deref().write(T4::cpp_from(__first.borrow().iter_deref())); + __first.borrow_mut().iter_inc(); __out.iter_inc(); } __out } fn f3, T2, T3: WeaklyEqualityComparableWith>(a0: T1, a1: T1, a2: Ptr) -> T1 { - let mut __it = a0; - while __it != a1 && !WeaklyEqualityComparableWith::equal(__it.iter_deref(), a2.clone()) { - __it.iter_inc(); + let __it: Value = Rc::new(RefCell::new(a0)); + let __last: Value = Rc::new(RefCell::new(a1)); + while !::equal(__it.as_pointer(), __last.as_pointer()) + && !WeaklyEqualityComparableWith::equal(__it.borrow().iter_deref(), a2.clone()) + { + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() } fn f6, T2, T3: Clone + ByteRepr>(a0: T1, a1: T1, a2: T2) @@ -62,15 +66,16 @@ where } fn f8, T2: CppLess>(a0: T1, a1: T1) -> T1 { - let mut __best = a0.clone(); - if a0 != a1 { - let mut __it = a0; - __it.iter_inc(); - while __it != a1 { - if CppLess::less(__best.iter_deref(), __it.iter_deref()) { - __best = __it.clone(); + let __it: Value = Rc::new(RefCell::new(a0)); + let __last: Value = Rc::new(RefCell::new(a1)); + let mut __best = __it.borrow().clone(); + if !::equal(__it.as_pointer(), __last.as_pointer()) { + __it.borrow_mut().iter_inc(); + while !::equal(__it.as_pointer(), __last.as_pointer()) { + if CppLess::less(__best.iter_deref(), __it.borrow().iter_deref()) { + __best = __it.borrow().clone(); } - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } } __best @@ -84,18 +89,19 @@ fn f10, T2: WeaklyEqualityComparableWith + Triviall a0: T1, a1: T1, ) -> T1 { - if a0 == a1 { - a1 + let __it: Value = Rc::new(RefCell::new(a0)); + let __last: Value = Rc::new(RefCell::new(a1)); + if ::equal(__it.as_pointer(), __last.as_pointer()) { + __last.borrow().clone() } else { - let mut __write = a0.clone(); - let mut __it = a0; - __it.iter_inc(); - while __it != a1 { - if !WeaklyEqualityComparableWith::equal(__write.iter_deref(), __it.iter_deref()) { + let mut __write = __it.borrow().clone(); + __it.borrow_mut().iter_inc(); + while !::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.iter_deref().read()); + __write.iter_deref().write(__it.borrow().iter_deref().read()); } - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } __write.iter_inc(); __write @@ -103,20 +109,22 @@ fn f10, T2: WeaklyEqualityComparableWith + Triviall } fn f12, T2: Clone + ByteRepr>(a0: T1, a1: T1, a2: T2) { - let mut __it = a0; - while __it != a1 { - __it.iter_deref().write(Clone::clone(&a2)); - __it.iter_inc(); + let __it: Value = Rc::new(RefCell::new(a0)); + let __last: Value = Rc::new(RefCell::new(a1)); + while !::equal(__it.as_pointer(), __last.as_pointer()) { + __it.borrow().iter_deref().write(Clone::clone(&a2)); + __it.borrow_mut().iter_inc(); } } fn f13>(a0: T1, a1: T1, a2: &mut ::std::fs::File) -> ::std::fs::File { - let mut __it = a0; + let __it: Value = Rc::new(RefCell::new(a0)); + let __last: Value = Rc::new(RefCell::new(a1)); let __out = &mut *a2; let mut __bytes: Vec = Vec::new(); - while __it != a1 { - __bytes.push(__it.iter_deref().read() as u8); - __it.iter_inc(); + while !::equal(__it.as_pointer(), __last.as_pointer()) { + __bytes.push(__it.borrow().iter_deref().read() as u8); + __it.borrow_mut().iter_inc(); } __out.write_all(&__bytes); __out.try_clone().unwrap() diff --git a/rules/algorithm/tgt_unsafe.rs b/rules/algorithm/tgt_unsafe.rs index 721baf36e6..ad6d84fced 100644 --- a/rules/algorithm/tgt_unsafe.rs +++ b/rules/algorithm/tgt_unsafe.rs @@ -24,7 +24,7 @@ unsafe fn f2, T2: UnsafeCppIterator, T3, T4: ) -> T2 { let mut __first = a0; let mut __out = a2; - while __first != a1 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__first, &a1) { *__out.iter_deref() = T4::cpp_from(__first.iter_deref()); __first.iter_inc(); __out.iter_inc(); @@ -34,7 +34,7 @@ unsafe fn f2, T2: UnsafeCppIterator, T3, T4: unsafe fn f3, T2, T3: WeaklyEqualityComparableWithUnsafe>(a0: T1, a1: T1, a2: T2) -> T1 { let mut __it = a0; - while __it != a1 && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &a2) { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &a1) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &a2) { __it.iter_inc(); } __it @@ -68,10 +68,10 @@ where unsafe fn f8, T2: PartialOrd>(a0: T1, a1: T1) -> T1 { let mut __best = a0.clone(); - if a0 != a1 { + if !WeaklyEqualityComparableWithUnsafe::equal(&a0, &a1) { let mut __it = a0; __it.iter_inc(); - while __it != a1 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &a1) { if *__best.iter_deref() < *__it.iter_deref() { __best = __it.clone(); } @@ -88,13 +88,13 @@ unsafe fn f9(a0: *mut T1, a1: *mut T1) { } unsafe fn f10, T2: WeaklyEqualityComparableWithUnsafe + Clone>(a0: T1, a1: T1) -> T1 { - if a0 == a1 { + if WeaklyEqualityComparableWithUnsafe::equal(&a0, &a1) { a1 } else { let mut __write = a0.clone(); let mut __it = a0; __it.iter_inc(); - while __it != a1 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &a1) { if !WeaklyEqualityComparableWithUnsafe::equal(&*__write.iter_deref(), __it.iter_deref()) { __write.iter_inc(); *__write.iter_deref() = (*__it.iter_deref()).clone(); @@ -108,7 +108,7 @@ unsafe fn f10, T2: WeaklyEqualityComparableWithUn unsafe fn f12, T2: Clone>(a0: T1, a1: T1, a2: T2) { let mut __it = a0; - while __it != a1 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &a1) { *__it.iter_deref() = Clone::clone(&a2); __it.iter_inc(); } @@ -122,7 +122,7 @@ unsafe fn f13>( let mut __it = a0; let __out = &mut *a2; let mut __bytes: Vec = Vec::new(); - while __it != a1 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &a1) { __bytes.push(*__it.iter_deref() as u8); __it.iter_inc(); } diff --git a/rules/iterator_category/shim.rs b/rules/iterator_category/shim.rs index 65e0ae3b31..99716165b7 100644 --- a/rules/iterator_category/shim.rs +++ b/rules/iterator_category/shim.rs @@ -8,7 +8,8 @@ use std::marker::PhantomData; use std::rc::Rc; use crate::{ - ByteRepr, MapNode, PostfixDec, PostfixInc, PrefixDec, PrefixInc, Ptr, UnsafeMapNode, Value, + ByteRepr, EqualityComparable, EqualityComparableUnsafe, MapNode, PostfixDec, PostfixInc, + PrefixDec, PrefixInc, Ptr, UnsafeMapNode, Value, }; pub trait CppIterator: Clone { @@ -17,7 +18,7 @@ pub trait CppIterator: Clone { fn iter_post_inc(&mut self) -> Self; } -pub trait CppInputIterator: CppIterator + PartialEq {} +pub trait CppInputIterator: CppIterator + PartialEq + EqualityComparable {} pub trait CppBidirectionalIterator: CppInputIterator { fn iter_dec(&mut self) -> &mut Self; @@ -37,7 +38,10 @@ pub trait UnsafeCppIterator: Clone { fn iter_post_inc(&mut self) -> Self; } -pub trait UnsafeCppInputIterator: UnsafeCppIterator + PartialEq {} +pub trait UnsafeCppInputIterator: + UnsafeCppIterator + PartialEq + EqualityComparableUnsafe +{ +} pub trait UnsafeCppBidirectionalIterator: UnsafeCppInputIterator { fn iter_dec(&mut self) -> &mut Self; @@ -174,6 +178,30 @@ macro_rules! uninhabited_iterator { self.never() } } + + impl crate::MoveConstructible for $name { + fn move_constructor(_: Ptr, src: Ptr) { + src.with(|it| it.never()) + } + } + + impl crate::CopyConstructible for $name { + fn copy_constructor(_: Ptr, src: Ptr) { + src.with(|it| it.never()) + } + } + + impl crate::MoveConstructibleUnsafe for $name { + unsafe fn move_constructor(_: *mut Self, src: *mut Self) { + unsafe { (*src).never() } + } + } + + impl crate::CopyConstructibleUnsafe for $name { + unsafe fn copy_constructor(_: *mut Self, src: *const Self) { + unsafe { (*src).never() } + } + } }; } @@ -207,8 +235,8 @@ uninhabited_iterator_ops!(UnsafeInputIterator, UnsafeCppIterator, *mut T); uninhabited_iterator_ops!(UnsafeOutputIterator, UnsafeCppIterator, *mut T); uninhabited_iterator_ops!(UnsafeForwardIterator, UnsafeCppIterator, *mut T); -impl CppInputIterator for InputIterator {} -impl CppInputIterator for ForwardIterator {} +impl CppInputIterator for InputIterator {} +impl CppInputIterator for ForwardIterator {} impl UnsafeCppInputIterator for UnsafeInputIterator {} impl UnsafeCppInputIterator for UnsafeForwardIterator {} @@ -265,9 +293,9 @@ impl CppIterator for BidirectionalIterator { } } -impl CppInputIterator for BidirectionalIterator {} +impl CppInputIterator for BidirectionalIterator {} -impl CppBidirectionalIterator for BidirectionalIterator { +impl CppBidirectionalIterator for BidirectionalIterator { fn iter_dec(&mut self) -> &mut Self { match self { Self::Map(node) => *node = MapNode::prev(node), @@ -343,7 +371,7 @@ impl UnsafeCppBidirectionalIterator for UnsafeBidirectionalIterator { } macro_rules! random_access_iterator { - ($name:ident, $ptr:ty, $iter:ident, $input:ident, $bidi:ident, $random:ident, $null:expr) => { + ($name:ident, $ptr:ty, $iter:ident, $input:ident, $bidi:ident, $random:ident, $eq:ident, $null:expr) => { pub enum $name { Vec($ptr), } @@ -413,11 +441,17 @@ macro_rules! random_access_iterator { } } - impl $input for $name where $ptr: $input {} + impl $input for $name + where + $ptr: $input, + Self: $eq, + { + } impl $bidi for $name where $ptr: $bidi, + Self: $eq, { fn iter_dec(&mut self) -> &mut Self { match self { @@ -437,6 +471,7 @@ macro_rules! random_access_iterator { impl $random for $name where $ptr: $random, + Self: $eq, { fn iter_add(&self, n: isize) -> Self { match self { @@ -469,6 +504,7 @@ random_access_iterator!( CppInputIterator, CppBidirectionalIterator, CppRandomAccessIterator, + EqualityComparable, Ptr::null() ); @@ -487,9 +523,15 @@ random_access_iterator!( UnsafeCppInputIterator, UnsafeCppBidirectionalIterator, UnsafeCppRandomAccessIterator, + EqualityComparableUnsafe, std::ptr::null_mut() ); +crate::constructor::impl_trivial_copy_move!( + BidirectionalIterator, RandomAccessIterator, + UnsafeBidirectionalIterator, UnsafeRandomAccessIterator, +); + crate::cmp::impl_weakly_equality_comparable_with!( InputIterator, OutputIterator, ForwardIterator, BidirectionalIterator, RandomAccessIterator, diff --git a/rules/iterator_category/tgt_refcount.rs b/rules/iterator_category/tgt_refcount.rs index dfe55827ee..732c5299b8 100644 --- a/rules/iterator_category/tgt_refcount.rs +++ b/rules/iterator_category/tgt_refcount.rs @@ -58,12 +58,12 @@ fn f8, T2>(a0: T1) -> Ptr { a0.iter_deref() } -fn f9, T2>(a0: T1, a1: T1) -> bool { - a0 == a1 +fn f9, T2>(a0: Ptr, a1: Ptr) -> bool { + WeaklyEqualityComparableWith::equal(a0, a1) } -fn f10, T2>(a0: T1, a1: T1) -> bool { - a0 != a1 +fn f10, T2>(a0: Ptr, a1: Ptr) -> bool { + !WeaklyEqualityComparableWith::equal(a0, a1) } fn f11, T2>(a0: &mut T1) -> &mut T1 { @@ -135,6 +135,6 @@ fn f26, T2>(a0: &mut T1) -> &mut T1 { a0 } -fn f27 + PartialEq, T2: CppInputIterator, T3>(a0: T1, a1: T2) -> bool { - a0 == a1 +fn f27 + WeaklyEqualityComparableWith, T2: CppInputIterator, 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 c16b316384..24ae84f4f1 100644 --- a/rules/iterator_category/tgt_unsafe.rs +++ b/rules/iterator_category/tgt_unsafe.rs @@ -58,12 +58,12 @@ fn f8, T2>(a0: T1) -> *mut T2 { a0.iter_deref() } -fn f9, T2>(a0: T1, a1: T1) -> bool { - a0 == a1 +unsafe fn f9, T2>(a0: T1, a1: T1) -> bool { + WeaklyEqualityComparableWithUnsafe::equal(&a0, &a1) } -fn f10, T2>(a0: T1, a1: T1) -> bool { - a0 != a1 +unsafe fn f10, T2>(a0: T1, a1: T1) -> bool { + !WeaklyEqualityComparableWithUnsafe::equal(&a0, &a1) } fn f11, T2>(a0: &mut T1) -> &mut T1 { @@ -135,6 +135,6 @@ fn f26, T2>(a0: &mut T1) -> &mut T1 { a0 } -fn f27 + PartialEq, T2: UnsafeCppInputIterator, T3>(a0: T1, a1: T2) -> bool { - a0 == a1 +unsafe fn f27 + WeaklyEqualityComparableWithUnsafe, T2: UnsafeCppInputIterator, T3>(a0: T1, a1: T2) -> bool { + WeaklyEqualityComparableWithUnsafe::equal(&a0, &a1) } diff --git a/rules/vector/tgt_refcount.rs b/rules/vector/tgt_refcount.rs index a931448642..f5fd6514ff 100644 --- a/rules/vector/tgt_refcount.rs +++ b/rules/vector/tgt_refcount.rs @@ -93,10 +93,11 @@ fn f80(a0: Ptr>, fn f92, T2, T3: CppInputIterator, T4: ByteRepr>(a0: T3, a1: T3) -> Vec { let mut __v = Vec::new(); - let mut __it = a0; - while __it != a1 { - __v.push(T1::cpp_from(__it.iter_deref())); - __it.iter_inc(); + let __it: Value = Rc::new(RefCell::new(a0)); + let __last: Value = Rc::new(RefCell::new(a1)); + while !::equal(__it.as_pointer(), __last.as_pointer()) { + __v.push(T1::cpp_from(__it.borrow().iter_deref())); + __it.borrow_mut().iter_inc(); } __v } @@ -137,10 +138,11 @@ fn f101 + ByteRepr, T2, T3: CppInputIterator, T4: ByteRepr>( ) -> RandomAccessIterator { let start_idx = a1.index(); let mut temp_vec: Vec = Vec::new(); - let mut __it = a2; - while __it != a3 { - temp_vec.push(T1::cpp_from(__it.iter_deref())); - __it.iter_inc(); + let __it: Value = Rc::new(RefCell::new(a2)); + let __last: Value = Rc::new(RefCell::new(a3)); + while !::equal(__it.as_pointer(), __last.as_pointer()) { + temp_vec.push(T1::cpp_from(__it.borrow().iter_deref())); + __it.borrow_mut().iter_inc(); } a0.with_mut(|v: &mut Vec| { v.splice(start_idx..start_idx, temp_vec); diff --git a/rules/vector/tgt_unsafe.rs b/rules/vector/tgt_unsafe.rs index c10cb2cb55..f591fb3dd6 100644 --- a/rules/vector/tgt_unsafe.rs +++ b/rules/vector/tgt_unsafe.rs @@ -152,7 +152,7 @@ fn f91(a0: Vec) -> Vec { unsafe fn f92, T2, T3: UnsafeCppInputIterator, T4>(a0: T3, a1: T3) -> Vec { let mut __v = Vec::new(); let mut __it = a0; - while __it != a1 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &a1) { __v.push(T1::cpp_from(__it.iter_deref())); __it.iter_inc(); } @@ -193,7 +193,7 @@ unsafe fn f101, T2, T3: UnsafeCppInputIterator, T4>( let __off = a1.iter_distance(&UnsafeRandomAccessIterator::Vec(a0.as_mut_ptr())) as usize; let mut __tmp = Vec::new(); let mut __it = a2; - while __it != a3 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &a3) { __tmp.push(T1::cpp_from(__it.iter_deref())); __it.iter_inc(); } diff --git a/tests/unit/out/refcount/container_element_receiver.rs b/tests/unit/out/refcount/container_element_receiver.rs index 449d379793..cdd0f9512a 100644 --- a/tests/unit/out/refcount/container_element_receiver.rs +++ b/tests/unit/out/refcount/container_element_receiver.rs @@ -38,7 +38,9 @@ pub fn sum_1(v: Ptr>) -> i32 { let mut total: i32 = 0; { let it: Value> = Rc::new(RefCell::new(v.decay().begin())); - 'loop_: while (*it.borrow()) != v.decay().end() { + 'loop_: while match (Rc::new(RefCell::new(v.decay().end())).as_pointer(),) { + (__tmp_0,) => !WeaklyEqualityComparableWith::equal(it.as_pointer(), (__tmp_0).clone()), + } { 'for_body: { total += (({ (*it.borrow()).iter_deref() }).read()); } @@ -93,34 +95,34 @@ fn main_0() -> i32 { ) }),) { - (__tmp_0,) => __tmp_0.decay(), + (__tmp_1,) => __tmp_1.decay(), } .write(7); assert!(((vec_elem!(h.as_pointer(), vec_, 0_usize).read()) == 7)); let m: Value, Value>)>> = Rc::new(RefCell::new(Map::new())); ({ - let __tmp_2: Value = Rc::new(RefCell::new(8)); + let __tmp_3: Value = Rc::new(RefCell::new(8)); MoveConstructible::push_moved( &match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_1,) => { + (__tmp_2,) => { ({ (*m.borrow_mut()).subscript_move( - __tmp_1, + __tmp_2, |__k| cpp_move!(__k), || Default::default(), ) }) } }, - __tmp_2.as_pointer(), + __tmp_3.as_pointer(), ) }); assert!( ((match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_3,) => { + (__tmp_4,) => { ({ (*m.borrow_mut()).subscript_move( - __tmp_3, + __tmp_4, |__k| cpp_move!(__k), || Default::default(), ) diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index 1c838005ce..55d3fc0169 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -420,13 +420,16 @@ fn main_0() -> i32 { object!(der2, Derived, 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() }; - let mut __tmp_1 = { vec_.decay().end() }; let mut __v = Vec::new(); - let mut __it = (__tmp_0).clone(); - while __it != __tmp_1 { - __v.push(>::cpp_from(__it.iter_deref())); - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(vec_.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(vec_.decay().end())); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __v.push(>::cpp_from( + __it.borrow().iter_deref(), + )); + __it.borrow_mut().iter_inc(); } __v }; @@ -439,13 +442,13 @@ fn main_0() -> i32 { } }); { - let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); match ({ - DefaultConstructible::default_constructor(__tmp_3.as_pointer()); - __tmp_3.as_pointer() + DefaultConstructible::default_constructor(__tmp_1.as_pointer()); + __tmp_1.as_pointer() },) { - (__tmp_2,) => MoveConstructible::push_moved(&selfs.as_pointer(), (__tmp_2).clone()), + (__tmp_0,) => MoveConstructible::push_moved(&selfs.as_pointer(), (__tmp_0).clone()), } }; object!(self_src, SelfPtr); @@ -464,13 +467,13 @@ fn main_0() -> i32 { } }); { - let __tmp_5: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); match ({ - Counted::construct(__tmp_5.as_pointer(), 30); - __tmp_5.as_pointer() + Counted::construct(__tmp_3.as_pointer(), 30); + __tmp_3.as_pointer() },) { - (__tmp_4,) => MoveConstructible::push_moved(&temps.as_pointer(), (__tmp_4).clone()), + (__tmp_2,) => MoveConstructible::push_moved(&temps.as_pointer(), (__tmp_2).clone()), } }; assert!( diff --git a/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs b/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs index 91c0a3793a..6b603f74af 100644 --- a/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs +++ b/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs @@ -22,41 +22,48 @@ fn main_0() -> i32 { }); let it: Value> = Rc::new(RefCell::new( ({ - let __tmp_4: Value = Rc::new(RefCell::new(7)); + let __tmp_2: Value = Rc::new(RefCell::new(7)); { - let mut __tmp_2 = { v.decay().begin() }; - let mut __tmp_3 = { v.decay().end() }; - let mut __it = (__tmp_2).clone(); - while __it != __tmp_3 + let __it: Value> = + Rc::new(RefCell::new(v.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(v.decay().end())); + while !>::equal(__it.as_pointer(), __last.as_pointer()) && !WeaklyEqualityComparableWith::equal( - __it.iter_deref(), - __tmp_4.as_pointer().clone(), + __it.borrow().iter_deref(), + __tmp_2.as_pointer().clone(), ) { - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() } }), )); - assert!((*it.borrow()) != v.decay().end()); + assert!( + match (Rc::new(RefCell::new(v.decay().end())).as_pointer(),) { + (__tmp_3,) => { + !WeaklyEqualityComparableWith::equal(it.as_pointer(), (__tmp_3).clone()) + } + } + ); assert!(((({ (*it.borrow()).iter_deref() }).read()) == 7)); { - let mut __tmp_5 = { v.decay().begin() }; - let __n = v.decay().end().iter_distance(&__tmp_5); + let mut __tmp_4 = { v.decay().begin() }; + let __n = v.decay().end().iter_distance(&__tmp_4); let __random = std::hash::RandomState::new(); for __i in (1..__n).rev() { let __j = (std::hash::BuildHasher::hash_one(&__random, __i) % (__i + 1) as u64) as isize; - Swappable::swap(__tmp_5.iter_at(__i), __tmp_5.iter_at(__j)); + Swappable::swap(__tmp_4.iter_at(__i), __tmp_4.iter_at(__j)); } }; { - let mut __tmp_6 = { v.decay().begin() }; - let __n = v.decay().end().iter_distance(&__tmp_6); + let mut __tmp_5 = { v.decay().begin() }; + let __n = v.decay().end().iter_distance(&__tmp_5); let mut __order: Vec = (0..__n).collect(); - __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_6.iter_at(__x), &__tmp_6.iter_at(__y))); - reorder(__order, |__i| __tmp_6.iter_at(__i)); + __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_5.iter_at(__x), &__tmp_5.iter_at(__y))); + reorder(__order, |__i| __tmp_5.iter_at(__i)); }; assert!(({ (*v.borrow())[0_usize] } == 4) && ({ (*v.borrow())[1_usize] } == 7)); return 0; diff --git a/tests/unit/out/refcount/emplace_receiver_alias.rs b/tests/unit/out/refcount/emplace_receiver_alias.rs index 70a1267555..86ea20ee47 100644 --- a/tests/unit/out/refcount/emplace_receiver_alias.rs +++ b/tests/unit/out/refcount/emplace_receiver_alias.rs @@ -28,20 +28,22 @@ fn main_0() -> i32 { let mut alias: Ptr>> = (rows.as_pointer()); { let mut __tmp_0 = { ({ select_rows_0((alias).clone(), (calls.as_pointer())) }) }; - let mut __tmp_3 = { + let mut __tmp_1 = { { - let mut __tmp_1 = { (alias).decay().offset(0_usize).decay() }; - let mut __tmp_2 = { (alias).decay().offset(0_usize).decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = (__tmp_1).clone(); - while __it != __tmp_2 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new((alias).decay().offset(0_usize).decay())); + let __last: Value> = Rc::new(RefCell::new( + (alias).decay().offset(0_usize).decay().offset((3) as isize), + )); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v } }; - __tmp_0.with_mut(|__v: &mut Vec>| __v.push(__tmp_3)) + __tmp_0.with_mut(|__v: &mut Vec>| __v.push(__tmp_1)) }; printf!( b"calls=%d size=%zu last=%d\n", diff --git a/tests/unit/out/refcount/emplace_receiver_order.rs b/tests/unit/out/refcount/emplace_receiver_order.rs index 1f85e96f87..83ace175ee 100644 --- a/tests/unit/out/refcount/emplace_receiver_order.rs +++ b/tests/unit/out/refcount/emplace_receiver_order.rs @@ -35,41 +35,43 @@ fn main_0() -> i32 { let mut receiver: Ptr>> = ({ select_rows_0((rows.as_pointer()), (calls.as_pointer())) }); { - let mut __tmp_2 = { + let mut __tmp_0 = { { - let mut __tmp_0 = { rows.decay().offset(0_usize).decay() }; - let mut __tmp_1 = - { rows.decay().offset(0_usize).decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = (__tmp_0).clone(); - while __it != __tmp_1 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(rows.decay().offset(0_usize).decay())); + let __last: Value> = Rc::new(RefCell::new( + rows.decay().offset(0_usize).decay().offset((3) as isize), + )); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v } }; - receiver.with_mut(|__v: &mut Vec>| __v.push(__tmp_2)) + receiver.with_mut(|__v: &mut Vec>| __v.push(__tmp_0)) }; } else { { - let mut __tmp_3 = + let mut __tmp_1 = { ({ select_rows_0((rows.as_pointer()), (calls.as_pointer())) }) }; - let mut __tmp_6 = { + let mut __tmp_2 = { { - let mut __tmp_4 = { rows.decay().offset(0_usize).decay() }; - let mut __tmp_5 = - { rows.decay().offset(0_usize).decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = (__tmp_4).clone(); - while __it != __tmp_5 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(rows.decay().offset(0_usize).decay())); + let __last: Value> = Rc::new(RefCell::new( + rows.decay().offset(0_usize).decay().offset((3) as isize), + )); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v } }; - __tmp_3.with_mut(|__v: &mut Vec>| __v.push(__tmp_6)) + __tmp_1.with_mut(|__v: &mut Vec>| __v.push(__tmp_2)) }; } printf!( diff --git a/tests/unit/out/refcount/find.rs b/tests/unit/out/refcount/find.rs index d0c17ab502..8883012306 100644 --- a/tests/unit/out/refcount/find.rs +++ b/tests/unit/out/refcount/find.rs @@ -50,23 +50,27 @@ fn main_0() -> i32 { let v_end: Value> = Rc::new(RefCell::new(v.decay().end())); let it: Value> = Rc::new(RefCell::new( ({ - let __tmp_4: Value = Rc::new(RefCell::new(2)); + let __tmp_3: Value = Rc::new(RefCell::new(2)); { - let mut __tmp_3 = { (*v_end.borrow()).clone() }; - let mut __it = ({ (*v_begin.borrow()).clone() }); - while __it != __tmp_3 + let __it: Value> = + Rc::new(RefCell::new(({ (*v_begin.borrow()).clone() }))); + let __last: Value> = + Rc::new(RefCell::new(({ (*v_end.borrow()).clone() }))); + while !>::equal(__it.as_pointer(), __last.as_pointer()) && !WeaklyEqualityComparableWith::equal( - __it.iter_deref(), - __tmp_4.as_pointer().clone(), + __it.borrow().iter_deref(), + __tmp_3.as_pointer().clone(), ) { - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() } }), )); - let mut v_result_true: bool = (*it.borrow()) != v.decay().end(); + let mut v_result_true: bool = match (Rc::new(RefCell::new(v.decay().end())).as_pointer(),) { + (__tmp_4,) => !WeaklyEqualityComparableWith::equal(it.as_pointer(), (__tmp_4).clone()), + }; let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); match (Rc::new(RefCell::new(1)).as_pointer(),) { (__tmp_5,) => { @@ -94,109 +98,161 @@ fn main_0() -> i32 { m.as_pointer() .with(|__m: &Map, Value)>| __m.end()), )); - let mut m_result_true: bool = (*m_begin.borrow()) != (*m_end.borrow()); + let mut m_result_true: bool = + !WeaklyEqualityComparableWith::equal(m_begin.as_pointer(), m_end.as_pointer()); assert!( ((v_result_true) && (m_result_true)) - && (({ - let __tmp_10: Value = Rc::new(RefCell::new(2)); - { - let mut __tmp_8 = { v.decay().begin() }; - let mut __tmp_9 = { v.decay().begin() }; - let mut __it = (__tmp_8).clone(); - while __it != __tmp_9 - && !WeaklyEqualityComparableWith::equal( - __it.iter_deref(), - __tmp_10.as_pointer().clone(), - ) - { - __it.iter_inc(); - } - __it + && (match ( + Rc::new(RefCell::new( + ({ + let __tmp_9: Value = Rc::new(RefCell::new(2)); + { + let __it: Value> = + Rc::new(RefCell::new(v.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(v.decay().begin())); + while !>::equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_9.as_pointer().clone(), + ) { + __it.borrow_mut().iter_inc(); + } + __it.borrow().clone() + } + }) + )) + .as_pointer(), + Rc::new(RefCell::new(v.decay().begin())).as_pointer(), + ) { + (__tmp_8, __tmp_10) => { + WeaklyEqualityComparableWith::equal((__tmp_8).clone(), (__tmp_10).clone()) } - }) == v.decay().begin()) + }) ); let w: Value> = Rc::new(RefCell::new(Vec::from([1, 2, 3, 4, 5]))); - assert!( - ({ - let __tmp_13: Value = Rc::new(RefCell::new(4)); - { - let mut __tmp_11 = { w.decay().begin().iter_add(2_isize) }; - let mut __tmp_12 = { w.decay().end() }; - let mut __it = (__tmp_11).clone(); - while __it != __tmp_12 - && !WeaklyEqualityComparableWith::equal( - __it.iter_deref(), - __tmp_13.as_pointer().clone(), - ) + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_12: Value = Rc::new(RefCell::new(4)); { - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(w.decay().begin().iter_add(2_isize))); + let __last: Value> = + Rc::new(RefCell::new(w.decay().end())); + while !>::equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_12.as_pointer().clone(), + ) { + __it.borrow_mut().iter_inc(); + } + __it.borrow().clone() } - __it - } - }) == w.decay().begin().iter_add(3_isize) - ); - assert!( - ({ - let __tmp_16: Value = Rc::new(RefCell::new(1)); - { - let mut __tmp_14 = { w.decay().begin().iter_add(2_isize) }; - let mut __tmp_15 = { w.decay().end() }; - let mut __it = (__tmp_14).clone(); - while __it != __tmp_15 - && !WeaklyEqualityComparableWith::equal( - __it.iter_deref(), - __tmp_16.as_pointer().clone(), - ) + }) + )) + .as_pointer(), + Rc::new(RefCell::new(w.decay().begin().iter_add(3_isize))).as_pointer(), + ) { + (__tmp_11, __tmp_13) => { + WeaklyEqualityComparableWith::equal((__tmp_11).clone(), (__tmp_13).clone()) + } + }); + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_15: Value = Rc::new(RefCell::new(1)); { - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(w.decay().begin().iter_add(2_isize))); + let __last: Value> = + Rc::new(RefCell::new(w.decay().end())); + while !>::equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_15.as_pointer().clone(), + ) { + __it.borrow_mut().iter_inc(); + } + __it.borrow().clone() } - __it - } - }) == w.decay().end() - ); - assert!( - ({ - let __tmp_19: Value = Rc::new(RefCell::new(5)); - { - let mut __tmp_17 = { w.decay().begin().iter_add(2_isize) }; - let mut __tmp_18 = { w.decay().begin().iter_add(4_isize) }; - let mut __it = (__tmp_17).clone(); - while __it != __tmp_18 - && !WeaklyEqualityComparableWith::equal( - __it.iter_deref(), - __tmp_19.as_pointer().clone(), - ) + }) + )) + .as_pointer(), + Rc::new(RefCell::new(w.decay().end())).as_pointer(), + ) { + (__tmp_14, __tmp_16) => { + WeaklyEqualityComparableWith::equal((__tmp_14).clone(), (__tmp_16).clone()) + } + }); + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_18: Value = Rc::new(RefCell::new(5)); { - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(w.decay().begin().iter_add(2_isize))); + let __last: Value> = + Rc::new(RefCell::new(w.decay().begin().iter_add(4_isize))); + while !>::equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_18.as_pointer().clone(), + ) { + __it.borrow_mut().iter_inc(); + } + __it.borrow().clone() } - __it - } - }) == w.decay().begin().iter_add(4_isize) - ); + }) + )) + .as_pointer(), + Rc::new(RefCell::new(w.decay().begin().iter_add(4_isize))).as_pointer(), + ) { + (__tmp_17, __tmp_19) => { + WeaklyEqualityComparableWith::equal((__tmp_17).clone(), (__tmp_19).clone()) + } + }); let p: Value> = Rc::new(RefCell::new(Vec::from([ P { x: 0 }, P { x: 1 }, P { x: 2 }, ]))); - assert!( - ({ - let __tmp_22: Value

= Rc::new(RefCell::new(P { x: 1 })); - { - let mut __tmp_20 = { p.decay().begin() }; - let mut __tmp_21 = { p.decay().end() }; - let mut __it = (__tmp_20).clone(); - while __it != __tmp_21 - && !WeaklyEqualityComparableWith::equal( - __it.iter_deref(), - (__tmp_22.as_pointer()).clone(), - ) + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_21: Value

= Rc::new(RefCell::new(P { x: 1 })); { - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(p.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(p.decay().end())); + while !>::equal(__it.as_pointer(), __last.as_pointer()) + && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + (__tmp_21.as_pointer()).clone(), + ) + { + __it.borrow_mut().iter_inc(); + } + __it.borrow().clone() } - __it - } - }) == p.decay().begin().iter_add(1_isize) - ); + }) + )) + .as_pointer(), + Rc::new(RefCell::new(p.decay().begin().iter_add(1_isize))).as_pointer(), + ) { + (__tmp_20, __tmp_22) => { + WeaklyEqualityComparableWith::equal((__tmp_20).clone(), (__tmp_22).clone()) + } + }); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/map.rs b/tests/unit/out/refcount/map.rs index 2ee95d677a..7b728702bb 100644 --- a/tests/unit/out/refcount/map.rs +++ b/tests/unit/out/refcount/map.rs @@ -219,7 +219,7 @@ fn main_0() -> i32 { }), ), )); - let mut x1: u32 = if (*it.borrow()) == (*end.borrow()) { + let mut x1: u32 = if WeaklyEqualityComparableWith::equal(it.as_pointer(), end.as_pointer()) { 0_u32 } else { (*(*({ (*it.borrow()).iter_deref() }).upgrade().deref()) @@ -227,9 +227,16 @@ fn main_0() -> i32 { .borrow()) }; assert!((x1 == 4_u32)); - let mut x2: u32 = if (*const_it.borrow()) - == , Value)>>::from(({ (*end.borrow()).clone() })) + let mut x2: u32 = if match (Rc::new(RefCell::new(, + Value, + )>>::from(({ (*end.borrow()).clone() })))) + .as_pointer(),) { + (__tmp_20,) => { + WeaklyEqualityComparableWith::equal(const_it.as_pointer(), (__tmp_20).clone()) + } + } { 0_u32 } else { (*(*({ (*const_it.borrow()).iter_deref() }).upgrade().deref()) @@ -237,10 +244,14 @@ fn main_0() -> i32 { .borrow()) }; assert!((x2 == 0_u32)); - let mut x3: u32 = if (*it.borrow()) - == m.as_pointer() - .with(|__m: &Map, Value)>| __m.end()) + let mut x3: u32 = if match (Rc::new(RefCell::new( + m.as_pointer() + .with(|__m: &Map, Value)>| __m.end()), + )) + .as_pointer(),) { + (__tmp_21,) => WeaklyEqualityComparableWith::equal(it.as_pointer(), (__tmp_21).clone()), + } { 0_u32 } else { (*(*({ (*it.borrow()).iter_deref() }).upgrade().deref()) @@ -248,11 +259,19 @@ fn main_0() -> i32 { .borrow()) }; assert!((x3 == 4_u32)); - let mut x4: u32 = if (*const_it.borrow()) - == , Value)>>::from( - m.as_pointer() - .with(|__m: &Map, Value)>| __m.end()), - ) { + let mut x4: u32 = if match (Rc::new(RefCell::new(, + Value, + )>>::from( + m.as_pointer() + .with(|__m: &Map, Value)>| __m.end()), + ))) + .as_pointer(),) + { + (__tmp_22,) => { + WeaklyEqualityComparableWith::equal(const_it.as_pointer(), (__tmp_22).clone()) + } + } { 0_u32 } else { (*(*({ (*const_it.borrow()).iter_deref() }).upgrade().deref()) @@ -261,16 +280,16 @@ fn main_0() -> i32 { }; assert!((x4 == 0_u32)); match (Rc::new(RefCell::new(4_i16)).as_pointer(),) { - (__tmp_20,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_20, |__k| cpp_move!(__k), || 0_u32) }) + (__tmp_23,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_23, |__k| cpp_move!(__k), || 0_u32) }) } } .write(5_u32); let it4: Value, Value)>> = Rc::new(RefCell::new( ({ - let __tmp_21: Value = Rc::new(RefCell::new(4_i16)); + let __tmp_24: Value = Rc::new(RefCell::new(4_i16)); m.as_pointer() - .with(|__m: &Map, Value)>| __m.find(&__tmp_21.as_pointer())) + .with(|__m: &Map, Value)>| __m.find(&__tmp_24.as_pointer())) }), )); let mut p: Ptr = ((*({ (*it4.borrow()).iter_deref() }).upgrade().deref()) @@ -279,8 +298,8 @@ fn main_0() -> i32 { let mut x5: u32 = (p.read()); assert!( ((match (Rc::new(RefCell::new(4_i16)).as_pointer(),) { - (__tmp_22,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_22, |__k| cpp_move!(__k), || 0_u32) }) + (__tmp_25,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_25, |__k| cpp_move!(__k), || 0_u32) }) } } .read()) @@ -301,8 +320,8 @@ fn main_0() -> i32 { }); assert!( ((match (Rc::new(RefCell::new(4_i16)).as_pointer(),) { - (__tmp_23,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_23, |__k| cpp_move!(__k), || 0_u32) }) + (__tmp_26,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_26, |__k| cpp_move!(__k), || 0_u32) }) } } .read()) @@ -321,10 +340,10 @@ fn main_0() -> i32 { let const_it4: Value, Value)>> = Rc::new(RefCell::new( , Value)>>::from( ({ - let __tmp_24: Value = Rc::new(RefCell::new(4_i16)); + let __tmp_27: Value = Rc::new(RefCell::new(4_i16)); m.as_pointer() .with(|__m: &Map, Value)>| { - __m.find(&__tmp_24.as_pointer()) + __m.find(&__tmp_27.as_pointer()) }) }), ), @@ -339,66 +358,90 @@ fn main_0() -> i32 { ); let r: Ptr, Value)>> = m.as_pointer(); assert!(({ ((*r.upgrade().deref()).len() == 4_usize) })); - assert!( - ({ - let __tmp_25: Value = Rc::new(RefCell::new(4_i16)); + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_29: Value = Rc::new(RefCell::new(4_i16)); + m.as_pointer() + .with(|__m: &Map, Value)>| { + __m.find(&__tmp_29.as_pointer()) + }) + }) + )) + .as_pointer(), + Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.find(&__tmp_25.as_pointer())) - }) != m - .as_pointer() - .with(|__m: &Map, Value)>| __m.end()) - ); + .with(|__m: &Map, Value)>| __m.end()) + )) + .as_pointer(), + ) { + (__tmp_28, __tmp_30) => { + !WeaklyEqualityComparableWith::equal((__tmp_28).clone(), (__tmp_30).clone()) + } + }); Map::erase((r).clone(), &({ (*it4.borrow()).clone() })); assert!(({ ((*r.upgrade().deref()).len() == 3_usize) })); - assert!( - ({ - let __tmp_26: Value = Rc::new(RefCell::new(4_i16)); + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_32: Value = Rc::new(RefCell::new(4_i16)); + m.as_pointer() + .with(|__m: &Map, Value)>| { + __m.find(&__tmp_32.as_pointer()) + }) + }) + )) + .as_pointer(), + Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.find(&__tmp_26.as_pointer())) - }) == m - .as_pointer() - .with(|__m: &Map, Value)>| __m.end()) - ); + .with(|__m: &Map, Value)>| __m.end()) + )) + .as_pointer(), + ) { + (__tmp_31, __tmp_33) => { + WeaklyEqualityComparableWith::equal((__tmp_31).clone(), (__tmp_33).clone()) + } + }); match (Rc::new(RefCell::new(7_i16)).as_pointer(),) { - (__tmp_27,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_27, |__k| cpp_move!(__k), || 0_u32) }) + (__tmp_34,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_34, |__k| cpp_move!(__k), || 0_u32) }) } } .write(7_u32); match (Rc::new(RefCell::new(8_i16)).as_pointer(),) { - (__tmp_28,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_28, |__k| cpp_move!(__k), || 0_u32) }) + (__tmp_35,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_35, |__k| cpp_move!(__k), || 0_u32) }) } } .write(8_u32); match (Rc::new(RefCell::new(9_i16)).as_pointer(),) { - (__tmp_29,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_29, |__k| cpp_move!(__k), || 0_u32) }) + (__tmp_36,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_36, |__k| cpp_move!(__k), || 0_u32) }) } } .write(9_u32); assert!(({ ((*r.upgrade().deref()).len() == 6_usize) })); assert!( (({ - let __tmp_30: Value = Rc::new(RefCell::new(10_i16)); - Map::erase_key(m.as_pointer(), &__tmp_30.as_pointer()) + let __tmp_37: Value = Rc::new(RefCell::new(10_i16)); + Map::erase_key(m.as_pointer(), &__tmp_37.as_pointer()) }) == 0_usize) ); let mut key9: i32 = 9; assert!( (({ - let __tmp_31: Value = Rc::new(RefCell::new((key9 as i16))); - Map::erase_key(m.as_pointer(), &__tmp_31.as_pointer()) + let __tmp_38: Value = Rc::new(RefCell::new((key9 as i16))); + Map::erase_key(m.as_pointer(), &__tmp_38.as_pointer()) }) == 1_usize) ); assert!(({ ((*r.upgrade().deref()).len() == 5_usize) })); let cit: Value, Value)>> = Rc::new(RefCell::new( , Value)>>::from( ({ - let __tmp_32: Value = Rc::new(RefCell::new(7_i16)); + let __tmp_39: Value = Rc::new(RefCell::new(7_i16)); m.as_pointer() .with(|__m: &Map, Value)>| { - __m.find(&__tmp_32.as_pointer()) + __m.find(&__tmp_39.as_pointer()) }) }), ), @@ -406,34 +449,54 @@ fn main_0() -> i32 { let next: Value, Value)>> = Rc::new(RefCell::new( Map::erase(m.as_pointer(), &({ (*cit.borrow()).clone() })), )); - assert!( - (*next.borrow()) - == ({ - let __tmp_33: Value = Rc::new(RefCell::new(8_i16)); - m.as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&__tmp_33.as_pointer()) - }) - }) - ); + assert!(match (Rc::new(RefCell::new( + ({ + let __tmp_41: Value = Rc::new(RefCell::new(8_i16)); + m.as_pointer() + .with(|__m: &Map, Value)>| __m.find(&__tmp_41.as_pointer())) + }) + )) + .as_pointer(),) + { + (__tmp_40,) => { + WeaklyEqualityComparableWith::equal(next.as_pointer(), (__tmp_40).clone()) + } + }); { (*next.borrow_mut()) = Map::erase(m.as_pointer(), &({ (*next.borrow()).clone() })); }; - assert!( - (*next.borrow()) - == m.as_pointer() - .with(|__m: &Map, Value)>| __m.end()) - ); + assert!(match (Rc::new(RefCell::new( + m.as_pointer() + .with(|__m: &Map, Value)>| __m.end()) + )) + .as_pointer(),) + { + (__tmp_42,) => { + WeaklyEqualityComparableWith::equal(next.as_pointer(), (__tmp_42).clone()) + } + }); assert!(({ ((*r.upgrade().deref()).len() == 3_usize) })); - assert!( - ({ - let __tmp_34: Value = Rc::new(RefCell::new(8_i16)); + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_44: Value = Rc::new(RefCell::new(8_i16)); + m.as_pointer() + .with(|__m: &Map, Value)>| { + __m.find(&__tmp_44.as_pointer()) + }) + }) + )) + .as_pointer(), + Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.find(&__tmp_34.as_pointer())) - }) == m - .as_pointer() - .with(|__m: &Map, Value)>| __m.end()) - ); + .with(|__m: &Map, Value)>| __m.end()) + )) + .as_pointer(), + ) { + (__tmp_43, __tmp_45) => { + WeaklyEqualityComparableWith::equal((__tmp_43).clone(), (__tmp_45).clone()) + } + }); let other_map: Value< Map<(Value, Value), (Value<(Value, Value)>, Value)>, > = Rc::new(RefCell::new(Map::new())); @@ -444,18 +507,18 @@ fn main_0() -> i32 { ))); let mut value: f64 = 2_f64; match (key0.as_pointer(),) { - (__tmp_35,) => ({ (*other_map.borrow_mut()).subscript(__tmp_35, || 0_f64) }), + (__tmp_46,) => ({ (*other_map.borrow_mut()).subscript(__tmp_46, || 0_f64) }), } .write(value); value = (match (key0.as_pointer(),) { - (__tmp_36,) => ({ (*other_map.borrow_mut()).subscript(__tmp_36, || 0_f64) }), + (__tmp_47,) => ({ (*other_map.borrow_mut()).subscript(__tmp_47, || 0_f64) }), } .read()); assert!(({ ((*other_map.borrow()).len() == 1_usize) })); assert!( ((match (key0.as_pointer(),) { - (__tmp_37,) => { - ({ (*other_map.borrow_mut()).subscript(__tmp_37, || 0_f64) }) + (__tmp_48,) => { + ({ (*other_map.borrow_mut()).subscript(__tmp_48, || 0_f64) }) } } .read()) @@ -465,9 +528,9 @@ fn main_0() -> i32 { let mut k: i32 = 0; assert!( ({ - let __tmp_38: Value = Rc::new(RefCell::new((k as i16))); + let __tmp_49: Value = Rc::new(RefCell::new((k as i16))); ((*m.borrow()) - .get(&__tmp_38.as_pointer()) + .get(&__tmp_49.as_pointer()) .expect("out of range!") .borrow() .1 @@ -478,9 +541,9 @@ fn main_0() -> i32 { k.prefix_inc(); assert!( ({ - let __tmp_39: Value = Rc::new(RefCell::new((k as i16))); + let __tmp_50: Value = Rc::new(RefCell::new((k as i16))); ((*m.borrow()) - .get(&__tmp_39.as_pointer()) + .get(&__tmp_50.as_pointer()) .expect("out of range!") .borrow() .1 @@ -491,9 +554,9 @@ fn main_0() -> i32 { k.prefix_inc(); assert!( ({ - let __tmp_40: Value = Rc::new(RefCell::new((k as i16))); + let __tmp_51: Value = Rc::new(RefCell::new((k as i16))); ((*m.borrow()) - .get(&__tmp_40.as_pointer()) + .get(&__tmp_51.as_pointer()) .expect("out of range!") .borrow() .1 @@ -509,8 +572,8 @@ fn main_0() -> i32 { 'loop_: while (i > 30_u32) { 'for_body: { ({ - let __tmp_41: Value = Rc::new(RefCell::new((i as i32))); - MoveConstructible::push_moved(&indexes.as_pointer(), __tmp_41.as_pointer()) + let __tmp_52: Value = Rc::new(RefCell::new((i as i32))); + MoveConstructible::push_moved(&indexes.as_pointer(), __tmp_52.as_pointer()) }); } i.prefix_dec(); @@ -521,8 +584,8 @@ fn main_0() -> i32 { 'loop_: while (i > 60_u32) { 'for_body: { ({ - let __tmp_42: Value = Rc::new(RefCell::new((i as i32))); - MoveConstructible::push_moved(&indexes.as_pointer(), __tmp_42.as_pointer()) + let __tmp_53: Value = Rc::new(RefCell::new((i as i32))); + MoveConstructible::push_moved(&indexes.as_pointer(), __tmp_53.as_pointer()) }); } i.prefix_dec(); @@ -533,8 +596,8 @@ fn main_0() -> i32 { 'loop_: while (i > 0_u32) { 'for_body: { ({ - let __tmp_43: Value = Rc::new(RefCell::new((i as i32))); - MoveConstructible::push_moved(&indexes.as_pointer(), __tmp_43.as_pointer()) + let __tmp_54: Value = Rc::new(RefCell::new((i as i32))); + MoveConstructible::push_moved(&indexes.as_pointer(), __tmp_54.as_pointer()) }); } i.prefix_dec(); @@ -545,7 +608,7 @@ fn main_0() -> i32 { 'loop_: while ((i as usize) < (*indexes.borrow()).len()) { 'for_body: { match (indexes.decay().offset((i as usize)),) { - (__tmp_44,) => ({ (*m2.borrow_mut()).subscript(__tmp_44, || false) }), + (__tmp_55,) => ({ (*m2.borrow_mut()).subscript(__tmp_55, || false) }), } .write(((i).wrapping_rem(2_u32) != 0)); } @@ -576,9 +639,9 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let mut __tmp_45 = { (Rc::new(RefCell::new(1)), Rc::new(RefCell::new(2))) }; + let mut __tmp_56 = { (Rc::new(RefCell::new(1)), Rc::new(RefCell::new(2))) }; let (__it, __inserted) = - Map::emplace(m3.as_pointer(), &__tmp_45.0.as_pointer(), || __tmp_45); + Map::emplace(m3.as_pointer(), &__tmp_56.0.as_pointer(), || __tmp_56); ( Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted)), @@ -599,9 +662,9 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let mut __tmp_46 = { (Rc::new(RefCell::new(1)), Rc::new(RefCell::new(3))) }; + let mut __tmp_57 = { (Rc::new(RefCell::new(1)), Rc::new(RefCell::new(3))) }; let (__it, __inserted) = - Map::emplace(m3.as_pointer(), &__tmp_46.0.as_pointer(), || __tmp_46); + Map::emplace(m3.as_pointer(), &__tmp_57.0.as_pointer(), || __tmp_57); ( Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted)), @@ -619,25 +682,25 @@ fn main_0() -> i32 { }) ); { - let mut __tmp_48 = { + let mut __tmp_59 = { match (Rc::new(RefCell::new(( Rc::new(RefCell::new(4)), Rc::new(RefCell::new(5)), ))) .as_pointer(),) { - (__tmp_47,) => ( + (__tmp_58,) => ( Rc::new(RefCell::new( - ((*__tmp_47.upgrade().deref()).0.as_pointer().read()), + ((*__tmp_58.upgrade().deref()).0.as_pointer().read()), )), Rc::new(RefCell::new( - ((*__tmp_47.upgrade().deref()).1.as_pointer().read()), + ((*__tmp_58.upgrade().deref()).1.as_pointer().read()), )), ), } }; let (__it, __inserted) = - Map::emplace(m3.as_pointer(), &__tmp_48.0.as_pointer(), || __tmp_48); + Map::emplace(m3.as_pointer(), &__tmp_59.0.as_pointer(), || __tmp_59); ( Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted)), @@ -646,8 +709,8 @@ fn main_0() -> i32 { assert!(({ ((*m3.borrow()).len() == 2_usize) })); assert!( ((match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_49,) => { - ({ (*m3.borrow_mut()).subscript_move(__tmp_49, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_60,) => { + ({ (*m3.borrow_mut()).subscript_move(__tmp_60, |__k| cpp_move!(__k), || 0_i32) }) } } .read()) @@ -655,23 +718,23 @@ fn main_0() -> i32 { ); assert!( ((match (Rc::new(RefCell::new(4)).as_pointer(),) { - (__tmp_50,) => { - ({ (*m3.borrow_mut()).subscript_move(__tmp_50, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_61,) => { + ({ (*m3.borrow_mut()).subscript_move(__tmp_61, |__k| cpp_move!(__k), || 0_i32) }) } } .read()) == 5) ); let hinted: Value, Value)>> = Rc::new(RefCell::new({ - let mut __tmp_51 = { + let mut __tmp_62 = { , Value)>>::from( m3.as_pointer() .with(|__m: &Map, Value)>| __m.end()), ) }; - let mut __tmp_52 = { (Rc::new(RefCell::new(6)), Rc::new(RefCell::new(7))) }; - let _ = (__tmp_51).clone(); - Map::emplace(m3.as_pointer(), &__tmp_52.0.as_pointer(), || __tmp_52).0 + let mut __tmp_63 = { (Rc::new(RefCell::new(6)), Rc::new(RefCell::new(7))) }; + let _ = (__tmp_62).clone(); + Map::emplace(m3.as_pointer(), &__tmp_63.0.as_pointer(), || __tmp_63).0 })); assert!( ({ @@ -727,8 +790,8 @@ fn main_0() -> i32 { assert!(({ ((*(*tried_new.borrow()).1.borrow()) as bool) })); assert!( ((match (Rc::new(RefCell::new(8)).as_pointer(),) { - (__tmp_53,) => { - ({ (*m3.borrow_mut()).subscript_move(__tmp_53, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_64,) => { + ({ (*m3.borrow_mut()).subscript_move(__tmp_64, |__k| cpp_move!(__k), || 0_i32) }) } } .read()) @@ -758,10 +821,10 @@ fn main_0() -> i32 { assert!(({ ((*(*point_new.borrow()).1.borrow()) as bool) })); assert!( (match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_54,) => { + (__tmp_65,) => { ({ (*points.borrow_mut()).subscript_move( - __tmp_54, + __tmp_65, |__k| cpp_move!(__k), || ::default(), ) @@ -773,10 +836,10 @@ fn main_0() -> i32 { ); assert!( (match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_55,) => { + (__tmp_66,) => { ({ (*points.borrow_mut()).subscript_move( - __tmp_55, + __tmp_66, |__k| cpp_move!(__k), || ::default(), ) @@ -787,7 +850,7 @@ fn main_0() -> i32 { == 4) ); { - let mut __tmp_56 = { + let mut __tmp_67 = { ( Rc::new(RefCell::new(({ (*key8.borrow()) }))), Rc::new(RefCell::new({ @@ -798,7 +861,7 @@ fn main_0() -> i32 { ) }; let (__it, __inserted) = - Map::emplace(points.as_pointer(), &__tmp_56.0.as_pointer(), || __tmp_56); + Map::emplace(points.as_pointer(), &__tmp_67.0.as_pointer(), || __tmp_67); ( Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted)), @@ -806,10 +869,10 @@ fn main_0() -> i32 { }; assert!( (match (Rc::new(RefCell::new(8)).as_pointer(),) { - (__tmp_57,) => { + (__tmp_68,) => { ({ (*points.borrow_mut()).subscript_move( - __tmp_57, + __tmp_68, |__k| cpp_move!(__k), || ::default(), ) @@ -821,10 +884,10 @@ fn main_0() -> i32 { ); assert!( (match (Rc::new(RefCell::new(8)).as_pointer(),) { - (__tmp_58,) => { + (__tmp_69,) => { ({ (*points.borrow_mut()).subscript_move( - __tmp_58, + __tmp_69, |__k| cpp_move!(__k), || ::default(), ) @@ -867,9 +930,9 @@ fn main_0() -> i32 { ); k = 0; let value_0: Ptr = ({ - let __tmp_59: Value = Rc::new(RefCell::new((k as i16))); + let __tmp_70: Value = Rc::new(RefCell::new((k as i16))); (*m.borrow()) - .get(&__tmp_59.as_pointer()) + .get(&__tmp_70.as_pointer()) .expect("out of range!") .borrow() .1 @@ -908,10 +971,10 @@ fn main_0() -> i32 { ); { match (Rc::new(RefCell::new((pk2.as_pointer()))).as_pointer(),) { - (__tmp_60,) => { + (__tmp_71,) => { ({ (*ptr_counts.borrow_mut()).subscript_move( - __tmp_60, + __tmp_71, |__k| cpp_move!(__k), || 0_i32, ) @@ -922,10 +985,10 @@ fn main_0() -> i32 { }; assert!( ((match (Rc::new(RefCell::new((pk2.as_pointer()))).as_pointer(),) { - (__tmp_61,) => { + (__tmp_72,) => { ({ (*ptr_counts.borrow_mut()).subscript_move( - __tmp_61, + __tmp_72, |__k| cpp_move!(__k), || 0_i32, ) @@ -939,75 +1002,75 @@ fn main_0() -> i32 { { let t: Value, Value)>> = Rc::new(RefCell::new(Map::new())); match (Rc::new(RefCell::new(1_i64)).as_pointer(),) { - (__tmp_62,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_62, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_73,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_73, |__k| cpp_move!(__k), || 0_i32) }) } } .write(5); { match (Rc::new(RefCell::new(2_i64)).as_pointer(),) { - (__tmp_63,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_63, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_74,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_74, |__k| cpp_move!(__k), || 0_i32) }) } } .with_mut(|__v| *__v = *__v + 3) }; match (Rc::new(RefCell::new(3_i64)).as_pointer(),) { - (__tmp_64,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_64, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_75,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_75, |__k| cpp_move!(__k), || 0_i32) }) } } .with_mut(|__v| __v.postfix_inc()); let r: Ptr = match (Rc::new(RefCell::new(1_i64)).as_pointer(),) { - (__tmp_65,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_65, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_76,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_76, |__k| cpp_move!(__k), || 0_i32) }) } }; r.write(6); let mut p: Ptr = (match (Rc::new(RefCell::new(2_i64)).as_pointer(),) { - (__tmp_66,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_66, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_77,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_77, |__k| cpp_move!(__k), || 0_i32) }) } }); p.write(4); ({ inc_2(match (Rc::new(RefCell::new(3_i64)).as_pointer(),) { - (__tmp_67,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_67, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_78,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_78, |__k| cpp_move!(__k), || 0_i32) }) } }) }); Swappable::swap( match (Rc::new(RefCell::new(1_i64)).as_pointer(),) { - (__tmp_68,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_68, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_79,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_79, |__k| cpp_move!(__k), || 0_i32) }) } }, match (Rc::new(RefCell::new(2_i64)).as_pointer(),) { - (__tmp_69,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_69, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_80,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_80, |__k| cpp_move!(__k), || 0_i32) }) } }, ); let mut x: i32 = ((match (Rc::new(RefCell::new(1_i64)).as_pointer(),) { - (__tmp_70,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_70, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_81,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_81, |__k| cpp_move!(__k), || 0_i32) }) } } .read()) + (match (Rc::new(RefCell::new(2_i64)).as_pointer(),) { - (__tmp_71,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_71, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_82,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_82, |__k| cpp_move!(__k), || 0_i32) }) } } .read())); assert!( (((x == 10) && ((match (Rc::new(RefCell::new(1_i64)).as_pointer(),) { - (__tmp_72,) => { + (__tmp_83,) => { ({ (*t.borrow_mut()).subscript_move( - __tmp_72, + __tmp_83, |__k| cpp_move!(__k), || 0_i32, ) @@ -1017,10 +1080,10 @@ fn main_0() -> i32 { .read()) == 4)) && ((match (Rc::new(RefCell::new(2_i64)).as_pointer(),) { - (__tmp_73,) => { + (__tmp_84,) => { ({ (*t.borrow_mut()).subscript_move( - __tmp_73, + __tmp_84, |__k| cpp_move!(__k), || 0_i32, ) @@ -1030,10 +1093,10 @@ fn main_0() -> i32 { .read()) == 6)) && ((match (Rc::new(RefCell::new(3_i64)).as_pointer(),) { - (__tmp_74,) => { + (__tmp_85,) => { ({ (*t.borrow_mut()).subscript_move( - __tmp_74, + __tmp_85, |__k| cpp_move!(__k), || 0_i32, ) diff --git a/tests/unit/out/refcount/map_key_identity.rs b/tests/unit/out/refcount/map_key_identity.rs index 90a0a4f8b7..d7a212a61c 100644 --- a/tests/unit/out/refcount/map_key_identity.rs +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -115,31 +115,43 @@ fn main_0() -> i32 { }; ok = { ((ok as i32) - & (((*a_it.borrow()) - == distinct - .as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&distinct_a.as_pointer()) - })) as i32)) + & ((match (Rc::new(RefCell::new(distinct.as_pointer().with( + |__m: &Map, Value)>| __m.find(&distinct_a.as_pointer()), + ))) + .as_pointer(),) + { + (__tmp_0,) => { + WeaklyEqualityComparableWith::equal(a_it.as_pointer(), (__tmp_0).clone()) + } + }) as i32)) != 0 }; ok = { ((ok as i32) - & (((*b_it.borrow()) - == distinct - .as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&distinct_b.as_pointer()) - })) as i32)) + & ((match (Rc::new(RefCell::new(distinct.as_pointer().with( + |__m: &Map, Value)>| __m.find(&distinct_b.as_pointer()), + ))) + .as_pointer(),) + { + (__tmp_1,) => { + WeaklyEqualityComparableWith::equal(b_it.as_pointer(), (__tmp_1).clone()) + } + }) as i32)) != 0 }; ok = { ((ok as i32) - & (((*b_it.borrow()) - != distinct + & ((match (Rc::new(RefCell::new( + distinct .as_pointer() - .with(|__m: &Map, Value)>| __m.end())) - as i32)) + .with(|__m: &Map, Value)>| __m.end()), + )) + .as_pointer(),) + { + (__tmp_2,) => { + !WeaklyEqualityComparableWith::equal(b_it.as_pointer(), (__tmp_2).clone()) + } + }) as i32)) != 0 }; ok = { @@ -243,32 +255,51 @@ fn main_0() -> i32 { if reused { ok = { ((ok as i32) - & (((*first_it.borrow()) - != equivalent + & ((match (Rc::new(RefCell::new( + equivalent .as_pointer() - .with(|__m: &Map, Value)>| __m.end())) - as i32)) + .with(|__m: &Map, Value)>| __m.end()), + )) + .as_pointer(),) + { + (__tmp_3,) => !WeaklyEqualityComparableWith::equal( + first_it.as_pointer(), + (__tmp_3).clone(), + ), + }) as i32)) != 0 }; ok = { ((ok as i32) & (({ (first).clone() } == { (second).clone() }) as i32)) != 0 }; ok = { ((ok as i32) - & (((*first_it.borrow()) - == equivalent.as_pointer().with( - |__m: &Map, Value)>| { - __m.find(&equivalent_a.as_pointer()) - }, - )) as i32)) + & ((match (Rc::new(RefCell::new(equivalent.as_pointer().with( + |__m: &Map, Value)>| { + __m.find(&equivalent_a.as_pointer()) + }, + ))) + .as_pointer(),) + { + (__tmp_4,) => WeaklyEqualityComparableWith::equal( + first_it.as_pointer(), + (__tmp_4).clone(), + ), + }) as i32)) != 0 }; ok = { ((ok as i32) - & (((*first_it.borrow()) - == equivalent.as_pointer().with( - |__m: &Map, Value)>| { - __m.find(&equivalent_b.as_pointer()) - }, - )) as i32)) + & ((match (Rc::new(RefCell::new(equivalent.as_pointer().with( + |__m: &Map, Value)>| { + __m.find(&equivalent_b.as_pointer()) + }, + ))) + .as_pointer(),) + { + (__tmp_5,) => WeaklyEqualityComparableWith::equal( + first_it.as_pointer(), + (__tmp_5).clone(), + ), + }) as i32)) != 0 }; ok = { @@ -334,12 +365,18 @@ fn main_0() -> i32 { if reused { ok = { ((ok as i32) - & (((*first_it.borrow()) - == equivalent.as_pointer().with( - |__m: &Map, Value)>| { - __m.find(&equivalent_a.as_pointer()) - }, - )) as i32)) + & ((match (Rc::new(RefCell::new(equivalent.as_pointer().with( + |__m: &Map, Value)>| { + __m.find(&equivalent_a.as_pointer()) + }, + ))) + .as_pointer(),) + { + (__tmp_6,) => WeaklyEqualityComparableWith::equal( + first_it.as_pointer(), + (__tmp_6).clone(), + ), + }) as i32)) != 0 }; ok = { @@ -399,12 +436,15 @@ fn main_0() -> i32 { ok = { ((ok as i32) & (({ (matched).clone() } == { (matched_again).clone() }) as i32)) != 0 }; ok = { ((ok as i32) - & (((*matched_it.borrow()) - == matching - .as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&matching_b.as_pointer()) - })) as i32)) + & ((match (Rc::new(RefCell::new(matching.as_pointer().with( + |__m: &Map, Value)>| __m.find(&matching_b.as_pointer()), + ))) + .as_pointer(),) + { + (__tmp_7,) => { + WeaklyEqualityComparableWith::equal(matched_it.as_pointer(), (__tmp_7).clone()) + } + }) as i32)) != 0 }; ok = { @@ -433,12 +473,15 @@ fn main_0() -> i32 { ok = { ((ok as i32) & (((*matching.borrow()).len() == 2_usize) as i32)) != 0 }; ok = { ((ok as i32) - & (((*matched_it.borrow()) - == matching - .as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&matching_a.as_pointer()) - })) as i32)) + & ((match (Rc::new(RefCell::new(matching.as_pointer().with( + |__m: &Map, Value)>| __m.find(&matching_a.as_pointer()), + ))) + .as_pointer(),) + { + (__tmp_8,) => { + WeaklyEqualityComparableWith::equal(matched_it.as_pointer(), (__tmp_8).clone()) + } + }) as i32)) != 0 }; ok = { diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index bd21add8dd..3e3dc3f6cd 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -295,7 +295,7 @@ fn main_0() -> i32 { as i32)) != 0 }; - let mut found : bool = (*(*result.borrow()) .0.borrow()) == m .as_pointer() .with(|__m: &Map, Value)>| __m.find(&key .as_pointer() )) ; + let mut found : bool = match (Rc::new(RefCell::new(m .as_pointer() .with(|__m: &Map, Value)>| __m.find(&key .as_pointer() )) )).as_pointer(),) { (__tmp_6,) => { WeaklyEqualityComparableWith::equal(({ (*result.borrow()) .0 .as_pointer() }), (__tmp_6 ).clone()) } } ; ok = { ((ok as i32) & (found as i32)) != 0 }; ok = { ((ok as i32) @@ -390,14 +390,14 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_6,) => { + (__tmp_7,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), (__tmp_6).clone()); + ConstructFrom::construct_from(__v.as_pointer(), (__tmp_7).clone()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -429,7 +429,7 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_7,) => { + (__tmp_8,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( @@ -438,7 +438,7 @@ fn main_0() -> i32 { let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( __v.as_pointer(), - Moved((__tmp_7).clone()), + Moved((__tmp_8).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -470,14 +470,14 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_8,) => { + (__tmp_9,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), (__tmp_8).clone()); + ConstructFrom::construct_from(__v.as_pointer(), (__tmp_9).clone()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -510,7 +510,7 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_9,) => { + (__tmp_10,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( @@ -519,7 +519,7 @@ fn main_0() -> i32 { let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( __v.as_pointer(), - Moved((__tmp_9).clone()), + Moved((__tmp_10).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -573,13 +573,13 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ reference_5(counter.as_pointer()) }),) { - (__tmp_10,) => { + (__tmp_11,) => { let (__it, __inserted) = Map::emplace(refs.as_pointer(), &key.as_pointer(), || { ( 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_10).clone(), 2); + RefItem::construct_1(__v.as_pointer(), (__tmp_11).clone(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -604,13 +604,13 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ reference_5(counter.as_pointer()) }),) { - (__tmp_11,) => { + (__tmp_12,) => { let (__it, __inserted) = Map::emplace(refs.as_pointer(), &key.as_pointer(), || { ( 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); + RefItem::construct_1(__v.as_pointer(), (__tmp_12).clone(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -655,13 +655,13 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_13: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_14: Value = Rc::new(RefCell::new(::zero_init())); match ({ - Item::construct_1(__tmp_13.as_pointer(), 30); - __tmp_13.as_pointer() + Item::construct_1(__tmp_14.as_pointer(), 30); + __tmp_14.as_pointer() },) { - (__tmp_12,) => { + (__tmp_13,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( @@ -670,7 +670,7 @@ fn main_0() -> i32 { let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( __v.as_pointer(), - Moved((__tmp_12).clone()), + Moved((__tmp_13).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -698,13 +698,13 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_15: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_16: Value = Rc::new(RefCell::new(::zero_init())); match ({ - Item::construct_1(__tmp_15.as_pointer(), 40); - __tmp_15.as_pointer() + Item::construct_1(__tmp_16.as_pointer(), 40); + __tmp_16.as_pointer() },) { - (__tmp_14,) => { + (__tmp_15,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( @@ -713,7 +713,7 @@ fn main_0() -> i32 { let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( __v.as_pointer(), - Moved((__tmp_14).clone()), + Moved((__tmp_15).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 5c273a875b..8a9518c0dc 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -111,17 +111,16 @@ fn main_0() -> i32 { assert!((((((r1 + r2) + r3) + r4) + r5) == 56)); let values: Value> = Rc::new(RefCell::new(Box::new([1, 7, 7, 3]))); let mut max: Ptr = { - let mut __tmp_2 = { values.decay() }; - let mut __tmp_3 = { values.decay().offset((4) as isize) }; - let mut __best = __tmp_2.clone(); - if __tmp_2 != __tmp_3 { - let mut __it = (__tmp_2).clone(); - __it.iter_inc(); - while __it != __tmp_3 { - if CppLess::less(__best.iter_deref(), __it.iter_deref()) { - __best = __it.clone(); + let __it: Value> = Rc::new(RefCell::new(values.decay())); + let __last: Value> = Rc::new(RefCell::new(values.decay().offset((4) as isize))); + let mut __best = __it.borrow().clone(); + if !>::equal(__it.as_pointer(), __last.as_pointer()) { + __it.borrow_mut().iter_inc(); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + if CppLess::less(__best.iter_deref(), __it.borrow().iter_deref()) { + __best = __it.borrow().clone(); } - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } } __best @@ -129,11 +128,11 @@ fn main_0() -> i32 { assert!(({ (max).clone() } == { values.decay().offset((1) as isize) })); assert!( ((match (({ pick_3(0,) }), ({ pick_3(1,) }),) { - (__tmp_4, __tmp_5) => { - if CppLess::less((__tmp_4).clone().clone(), (__tmp_5).clone().clone()) { - (__tmp_5).clone() + (__tmp_2, __tmp_3) => { + if CppLess::less((__tmp_2).clone().clone(), (__tmp_3).clone().clone()) { + (__tmp_3).clone() } else { - (__tmp_4).clone() + (__tmp_2).clone() } } } @@ -143,11 +142,11 @@ fn main_0() -> i32 { ); assert!( ((match (({ pick_3(1,) }), ({ pick_3(0,) }),) { - (__tmp_6, __tmp_7) => { - if CppLess::less((__tmp_7).clone().clone(), (__tmp_6).clone().clone()) { - (__tmp_7).clone() + (__tmp_4, __tmp_5) => { + if CppLess::less((__tmp_5).clone().clone(), (__tmp_4).clone().clone()) { + (__tmp_5).clone() } else { - (__tmp_6).clone() + (__tmp_4).clone() } } } @@ -158,46 +157,46 @@ 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_11: Value = Rc::new(RefCell::new(::zero_init())); (match ( { - ({ make_5(Ptr::clone(&__tmp_9.as_pointer()), 1) }); - __tmp_9.as_pointer() + ({ make_5(Ptr::clone(&__tmp_7.as_pointer()), 1) }); + __tmp_7.as_pointer() }, { - ({ make_5(Ptr::clone(&__tmp_11.as_pointer()), 2) }); - __tmp_11.as_pointer() + ({ make_5(Ptr::clone(&__tmp_9.as_pointer()), 2) }); + __tmp_9.as_pointer() }, ) { - (__tmp_8, __tmp_10) => { - if CppLess::less((__tmp_8).clone().clone(), (__tmp_10).clone().clone()) { - (__tmp_10).clone() - } else { + (__tmp_6, __tmp_8) => { + if CppLess::less((__tmp_6).clone().clone(), (__tmp_8).clone().clone()) { (__tmp_8).clone() + } else { + (__tmp_6).clone() } } } .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_15: Value = Rc::new(RefCell::new(::zero_init())); (match ( { - ({ make_5(Ptr::clone(&__tmp_13.as_pointer()), 1) }); - __tmp_13.as_pointer() + ({ make_5(Ptr::clone(&__tmp_11.as_pointer()), 1) }); + __tmp_11.as_pointer() }, { - ({ make_5(Ptr::clone(&__tmp_15.as_pointer()), 2) }); - __tmp_15.as_pointer() + ({ make_5(Ptr::clone(&__tmp_13.as_pointer()), 2) }); + __tmp_13.as_pointer() }, ) { - (__tmp_12, __tmp_14) => { - if CppLess::less((__tmp_14).clone().clone(), (__tmp_12).clone().clone()) { - (__tmp_14).clone() - } else { + (__tmp_10, __tmp_12) => { + if CppLess::less((__tmp_12).clone().clone(), (__tmp_10).clone().clone()) { (__tmp_12).clone() + } else { + (__tmp_10).clone() } } } @@ -212,16 +211,16 @@ fn main_0() -> i32 { 'loop_: while (i < 3) { 'for_body: { largest = (({ - let __tmp_17: Value = Rc::new(RefCell::new((largest as u64))); + let __tmp_15: Value = Rc::new(RefCell::new((largest as u64))); (match (Rc::new(RefCell::new((({ size_of_2(i) }) as u64))).as_pointer(),) { - (__tmp_16,) => { + (__tmp_14,) => { if CppLess::less( - __tmp_17.as_pointer().clone(), - (__tmp_16).clone().clone(), + __tmp_15.as_pointer().clone(), + (__tmp_14).clone().clone(), ) { - (__tmp_16).clone() + (__tmp_14).clone() } else { - __tmp_17.as_pointer() + __tmp_15.as_pointer() } } } diff --git a/tests/unit/out/refcount/operator_comparison_nonbool.rs b/tests/unit/out/refcount/operator_comparison_nonbool.rs index 2499645a9d..9e15867561 100644 --- a/tests/unit/out/refcount/operator_comparison_nonbool.rs +++ b/tests/unit/out/refcount/operator_comparison_nonbool.rs @@ -368,14 +368,18 @@ fn main_0() -> i32 { Rc::new(RefCell::new(Box::new([RefInt { v: 1 }, RefInt { v: 2 }]))); assert!( ({ - let mut __tmp_3 = { ris.decay().offset((2) as isize) }; - let mut __it = ris.decay(); - while __it != __tmp_3 - && !WeaklyEqualityComparableWith::equal(__it.iter_deref(), ri2.as_pointer().clone()) + let __it: Value> = Rc::new(RefCell::new(ris.decay())); + let __last: Value> = + Rc::new(RefCell::new(ris.decay().offset((2) as isize))); + while !>::equal(__it.as_pointer(), __last.as_pointer()) + && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + ri2.as_pointer().clone(), + ) { - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() } == ris.decay()) ); return 0; diff --git a/tests/unit/out/refcount/operator_traits.rs b/tests/unit/out/refcount/operator_traits.rs index 83368ac2cf..54148f238d 100644 --- a/tests/unit/out/refcount/operator_traits.rs +++ b/tests/unit/out/refcount/operator_traits.rs @@ -166,47 +166,54 @@ fn main_0() -> i32 { let nine: Value = Rc::new(RefCell::new(Eq { v: 9 })); assert!( ({ - let mut __tmp_1 = { eqs.decay().begin() }; - let mut __tmp_2 = { eqs.decay().end() }; - let mut __it = (__tmp_1).clone(); - while __it != __tmp_2 - && !WeaklyEqualityComparableWith::equal(__it.iter_deref(), two.as_pointer().clone()) + let __it: Value> = Rc::new(RefCell::new(eqs.decay().begin())); + let __last: Value> = Rc::new(RefCell::new(eqs.decay().end())); + while !>::equal(__it.as_pointer(), __last.as_pointer()) + && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + two.as_pointer().clone(), + ) { - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() } .iter_deref() .with(|__s| __s.v) == 2) ); - assert!( - { - let mut __tmp_3 = { eqs.decay().begin() }; - let mut __tmp_4 = { eqs.decay().end() }; - let mut __it = (__tmp_3).clone(); - while __it != __tmp_4 + assert!(match ( + Rc::new(RefCell::new({ + let __it: Value> = Rc::new(RefCell::new(eqs.decay().begin())); + let __last: Value> = Rc::new(RefCell::new(eqs.decay().end())); + while !>::equal(__it.as_pointer(), __last.as_pointer()) && !WeaklyEqualityComparableWith::equal( - __it.iter_deref(), + __it.borrow().iter_deref(), nine.as_pointer().clone(), ) { - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } - __it - } == eqs.decay().end() - ); + __it.borrow().clone() + })) + .as_pointer(), + Rc::new(RefCell::new(eqs.decay().end())).as_pointer(), + ) { + (__tmp_1, __tmp_2) => { + WeaklyEqualityComparableWith::equal((__tmp_1).clone(), (__tmp_2).clone()) + } + }); let cmps: Value> = Rc::new(RefCell::new(Vec::from([ Cmp { v: 3 }, Cmp { v: 1 }, Cmp { v: 2 }, ]))); { - let mut __tmp_5 = { cmps.decay().begin() }; - let __n = cmps.decay().end().iter_distance(&__tmp_5); + let mut __tmp_3 = { cmps.decay().begin() }; + let __n = cmps.decay().end().iter_distance(&__tmp_3); let mut __order: Vec = (0..__n).collect(); - __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_5.iter_at(__x), &__tmp_5.iter_at(__y))); - reorder(__order, |__i| __tmp_5.iter_at(__i)); + __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_3.iter_at(__x), &__tmp_3.iter_at(__y))); + reorder(__order, |__i| __tmp_3.iter_at(__i)); }; assert!( ({ { (*cmps.borrow())[0_usize] }.v } == 1) && ({ { (*cmps.borrow())[2_usize] }.v } == 3) @@ -214,18 +221,19 @@ fn main_0() -> i32 { let three: Value = Rc::new(RefCell::new(Cmp { v: 3 })); assert!( ({ - let mut __tmp_6 = { cmps.decay().begin() }; - let mut __tmp_7 = { cmps.decay().end() }; - let mut __it = (__tmp_6).clone(); - while __it != __tmp_7 + let __it: Value> = + Rc::new(RefCell::new(cmps.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(cmps.decay().end())); + while !>::equal(__it.as_pointer(), __last.as_pointer()) && !WeaklyEqualityComparableWith::equal( - __it.iter_deref(), + __it.borrow().iter_deref(), three.as_pointer().clone(), ) { - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() } .iter_deref() .with(|__s| __s.v) @@ -233,28 +241,29 @@ fn main_0() -> i32 { ); let frees: Value> = Rc::new(RefCell::new(Vec::from([Free { v: 2 }, Free { v: 1 }]))); { - let mut __tmp_8 = { frees.decay().begin() }; - let __n = frees.decay().end().iter_distance(&__tmp_8); + let mut __tmp_4 = { frees.decay().begin() }; + let __n = frees.decay().end().iter_distance(&__tmp_4); let mut __order: Vec = (0..__n).collect(); - __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_8.iter_at(__x), &__tmp_8.iter_at(__y))); - reorder(__order, |__i| __tmp_8.iter_at(__i)); + __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_4.iter_at(__x), &__tmp_4.iter_at(__y))); + reorder(__order, |__i| __tmp_4.iter_at(__i)); }; assert!(({ { (*frees.borrow())[0_usize] }.v } == 1)); let ftwo: Value = Rc::new(RefCell::new(Free { v: 2 })); assert!( ({ - let mut __tmp_9 = { frees.decay().begin() }; - let mut __tmp_10 = { frees.decay().end() }; - let mut __it = (__tmp_9).clone(); - while __it != __tmp_10 + let __it: Value> = + Rc::new(RefCell::new(frees.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(frees.decay().end())); + while !>::equal(__it.as_pointer(), __last.as_pointer()) && !WeaklyEqualityComparableWith::equal( - __it.iter_deref(), + __it.borrow().iter_deref(), ftwo.as_pointer().clone(), ) { - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() } .iter_deref() .with(|__s| __s.v) @@ -262,14 +271,14 @@ fn main_0() -> i32 { ); let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); match (Rc::new(RefCell::new(Lt { v: 2 })).as_pointer(),) { - (__tmp_11,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_11, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_5,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_5, |__k| cpp_move!(__k), || 0_i32) }) } } .write(20); match (Rc::new(RefCell::new(Lt { v: 1 })).as_pointer(),) { - (__tmp_12,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_12, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_6,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_6, |__k| cpp_move!(__k), || 0_i32) }) } } .write(10); @@ -286,8 +295,8 @@ fn main_0() -> i32 { ); assert!( ((match (Rc::new(RefCell::new(Lt { v: 2 })).as_pointer(),) { - (__tmp_13,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_13, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_7,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_7, |__k| cpp_move!(__k), || 0_i32) }) } } .read()) diff --git a/tests/unit/out/refcount/push_emplace_back.rs b/tests/unit/out/refcount/push_emplace_back.rs index c049702916..aa3812e294 100644 --- a/tests/unit/out/refcount/push_emplace_back.rs +++ b/tests/unit/out/refcount/push_emplace_back.rs @@ -86,12 +86,12 @@ pub fn push_local_from_field_1(mut jpg: Ptr, mut cond: bool) { dest = (field_ref!(jpg, app_data).as_pointer()); } match (Rc::new(RefCell::new({ - let mut __tmp_2 = { head.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = head.decay(); - while __it != __tmp_2 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(head.decay())); + let __last: Value> = Rc::new(RefCell::new(head.decay().offset((3) as isize))); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v })) @@ -117,12 +117,13 @@ pub fn emplace_local_from_field_4(mut jpg: Ptr, mut cond: bool) { { dest.with_mut(|__v: &mut Vec>| { __v.push({ - let mut __tmp_3 = { head.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = head.decay(); - while __it != __tmp_3 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(head.decay())); + let __last: Value> = + Rc::new(RefCell::new(head.decay().offset((3) as isize))); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v }) @@ -131,9 +132,9 @@ pub fn emplace_local_from_field_4(mut jpg: Ptr, mut cond: bool) { } pub fn nested_emplace_move_5(mut bw: Ptr) { { - let mut __tmp_4 = { bw.with(|__s| __s.output.clone()) }; - let mut __tmp_5 = { bw.with(|__s| __s.chunk) }; - __tmp_4.with_mut(|__v: &mut Vec| __v.push(__tmp_5)); + let mut __tmp_2 = { bw.with(|__s| __s.output.clone()) }; + let mut __tmp_3 = { bw.with(|__s| __s.chunk) }; + __tmp_2.with_mut(|__v: &mut Vec| __v.push(__tmp_3)); }; } pub fn self_ref_push_6(mut comps: Ptr>) { @@ -188,36 +189,36 @@ pub fn emplace_ctor_args_7(mut pairs: Ptr>) { }); }; { - let mut __tmp_6 = { + let mut __tmp_4 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Pair::construct_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_6)); + pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_4)); }; { - let mut __tmp_7 = { + let mut __tmp_5 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Pair::construct_2(__v.as_pointer(), 4, 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_7)); + pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_5)); }; } pub fn emplace_deque_8(mut queue: Ptr>) { { - let mut __tmp_8 = { + let mut __tmp_6 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Pair::construct_2(__v.as_pointer(), 6, 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - queue.with_mut(|__v: &mut Vec| __v.push(__tmp_8)); + queue.with_mut(|__v: &mut Vec| __v.push(__tmp_6)); }; { queue.with_mut(|__v: &mut Vec| { @@ -240,7 +241,7 @@ pub fn emplace_scalar_9(mut values: Ptr>, x: i32) { } pub fn emplace_ref_through_ptr_10(mut pairs: Ptr>) { let p: Ptr = { - let mut __tmp_9 = { + let mut __tmp_7 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Pair::construct_2(__v.as_pointer(), 1, 2); @@ -248,7 +249,7 @@ pub fn emplace_ref_through_ptr_10(mut pairs: Ptr>) { } }; pairs.with_mut(|__b0| { - (*__b0).push(__tmp_9); + (*__b0).push(__tmp_7); let __n = (*__b0).len() - 1; pairs.decay().offset((__n) as isize) }) @@ -257,7 +258,7 @@ pub fn emplace_ref_through_ptr_10(mut pairs: Ptr>) { { field!( { - let mut __tmp_10 = { + let mut __tmp_8 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Pair::construct_1(__v.as_pointer(), 4); @@ -265,7 +266,7 @@ pub fn emplace_ref_through_ptr_10(mut pairs: Ptr>) { } }; pairs.with_mut(|__b0| { - (*__b0).push(__tmp_10); + (*__b0).push(__tmp_8); let __n = (*__b0).len() - 1; pairs.decay().offset((__n) as isize) }) @@ -284,15 +285,15 @@ pub fn emplace_addr_11(values: Ptr>) -> Ptr { } pub fn emplace_self_reads_12(mut values: Ptr>, mut pairs: Ptr>) { { - let mut __tmp_11 = { (((*values.upgrade().deref()).len()) as i64) }; - values.with_mut(|__v: &mut Vec| __v.push(__tmp_11)); + let mut __tmp_9 = { (((*values.upgrade().deref()).len()) as i64) }; + values.with_mut(|__v: &mut Vec| __v.push(__tmp_9)); }; { - let mut __tmp_12 = { index!(pairs, 0_usize).read() }; - pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_12)); + let mut __tmp_10 = { index!(pairs, 0_usize).read() }; + pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_10)); }; { - let mut __tmp_13 = { + let mut __tmp_11 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Pair::construct_2( @@ -313,14 +314,14 @@ pub fn emplace_self_reads_12(mut values: Ptr>, mut pairs: Ptr Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_13)); + pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_11)); }; } pub fn emplace_ref_self_read_13(values: Ptr>) -> Ptr { return { - let mut __tmp_14 = { (values.decay().read()) }; + let mut __tmp_12 = { (values.decay().read()) }; values.with_mut(|__b0| { - (*__b0).push(__tmp_14); + (*__b0).push(__tmp_12); let __n = (*__b0).len() - 1; values.decay().offset((__n) as isize) }) @@ -368,19 +369,20 @@ impl Default for Bytes { pub fn emplace_from_element_14(mut v: Ptr>>) { let p: Value> = Rc::new(RefCell::new((v).decay().offset(0_usize).decay())); { - let mut __tmp_16 = { + let mut __tmp_13 = { { - let mut __tmp_15 = { (*p.borrow()).offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = ({ (*p.borrow()).clone() }); - while __it != __tmp_15 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(({ (*p.borrow()).clone() }))); + let __last: Value> = + Rc::new(RefCell::new((*p.borrow()).offset((3) as isize))); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v } }; - v.with_mut(|__v: &mut Vec>| __v.push(__tmp_16)); + v.with_mut(|__v: &mut Vec>| __v.push(__tmp_13)); }; } #[derive( @@ -455,33 +457,34 @@ impl Counted { impl Counted {} pub fn emplace_counted_17(mut v: Ptr>) { { - let mut __tmp_17 = { + let mut __tmp_14 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Counted::construct(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - v.with_mut(|__v: &mut Vec| __v.push(__tmp_17)); + v.with_mut(|__v: &mut Vec| __v.push(__tmp_14)); }; } pub fn emplace_from_sibling_18(mut s: Ptr) { let p: Value> = Rc::new(RefCell::new(array_field_ptr!(s, b))); let mut v: Ptr>> = (field_ref!(s, v).as_pointer()); { - let mut __tmp_19 = { + let mut __tmp_15 = { { - let mut __tmp_18 = { (*p.borrow()).offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = ({ (*p.borrow()).clone() }); - while __it != __tmp_18 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(({ (*p.borrow()).clone() }))); + let __last: Value> = + Rc::new(RefCell::new((*p.borrow()).offset((3) as isize))); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v } }; - v.with_mut(|__v: &mut Vec>| __v.push(__tmp_19)); + v.with_mut(|__v: &mut Vec>| __v.push(__tmp_15)); }; } pub fn main() { @@ -638,14 +641,14 @@ fn main_0() -> i32 { let self_values: Value> = Rc::new(RefCell::new(Vec::from([7_i64]))); let self_pairs: Value> = Rc::new(RefCell::new(Vec::new())); { - let mut __tmp_20 = { + let mut __tmp_16 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Pair::construct_2(__v.as_pointer(), 1, 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - (*self_pairs.borrow_mut()).push(__tmp_20); + (*self_pairs.borrow_mut()).push(__tmp_16); }; ({ emplace_self_reads_12((self_values.as_pointer()), (self_pairs.as_pointer())) }); { diff --git a/tests/unit/out/refcount/redundant_copy_in_conversion.rs b/tests/unit/out/refcount/redundant_copy_in_conversion.rs index 9a972e2c1e..2d3679ec5b 100644 --- a/tests/unit/out/refcount/redundant_copy_in_conversion.rs +++ b/tests/unit/out/refcount/redundant_copy_in_conversion.rs @@ -11,9 +11,14 @@ pub fn sink_0(it: BidirectionalIterator<(Value, Value)>) -> i32 { let cit: Value, Value)>> = Rc::new(RefCell::new( , Value)>>::from(({ (*it.borrow()).clone() })), )); - return if (*cit.borrow()) - == , Value)>>::from(({ (*it.borrow()).clone() })) + return if match (Rc::new(RefCell::new(, + Value, + )>>::from(({ (*it.borrow()).clone() })))) + .as_pointer(),) { + (__tmp_0,) => WeaklyEqualityComparableWith::equal(cit.as_pointer(), (__tmp_0).clone()), + } { (*(*({ (*it.borrow()).iter_deref() }).upgrade().deref()) .1 .borrow()) @@ -28,8 +33,8 @@ pub fn main() { fn main_0() -> i32 { let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); match (Rc::new(RefCell::new(0)).as_pointer(),) { - (__tmp_0,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_0, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_1,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_1, |__k| cpp_move!(__k), || 0_i32) }) } } .write(1); @@ -39,23 +44,28 @@ fn main_0() -> i32 { )); let it0: Value, Value)>> = Rc::new(RefCell::new( ({ - let __tmp_1: Value = Rc::new(RefCell::new(0)); + let __tmp_2: Value = Rc::new(RefCell::new(0)); m.as_pointer() - .with(|__m: &Map, Value)>| __m.find(&__tmp_1.as_pointer())) + .with(|__m: &Map, Value)>| __m.find(&__tmp_2.as_pointer())) }), )); let const_it: Value, Value)>> = Rc::new(RefCell::new( , Value)>>::from(({ (*it0.borrow()).clone() })), )); - let mut r: i32 = if (*const_it.borrow()) - == , Value)>>::from(({ (*end.borrow()).clone() })) + let mut r: i32 = if match (Rc::new(RefCell::new(, + Value, + )>>::from(({ (*end.borrow()).clone() })))) + .as_pointer(),) { + (__tmp_3,) => WeaklyEqualityComparableWith::equal(const_it.as_pointer(), (__tmp_3).clone()), + } { 0 } else { 1 }; r += ({ sink_0({ (*it0.borrow()).clone() }) }); - r += if (*end.borrow()) == (*end.borrow()) { + r += if WeaklyEqualityComparableWith::equal(end.as_pointer(), end.as_pointer()) { 0 } else { 1 @@ -68,7 +78,10 @@ fn main_0() -> i32 { >::from(({ (*middle.borrow()).clone() })), )); assert!(((({ (*const_middle.borrow()).iter_deref() }).read()) == 8_u32)); - assert!(({ (*const_middle.borrow()) == (*middle.borrow()) })); + assert!(WeaklyEqualityComparableWith::equal( + const_middle.as_pointer(), + middle.as_pointer() + )); return 0; } pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/size_t_ssize_t.rs b/tests/unit/out/refcount/size_t_ssize_t.rs index 1615a0fa56..e4cbf076bc 100644 --- a/tests/unit/out/refcount/size_t_ssize_t.rs +++ b/tests/unit/out/refcount/size_t_ssize_t.rs @@ -33,14 +33,14 @@ pub fn size_t_in_rules_3() { (0..3).map(|_| 0_usize).collect::>(), )); { - let mut __tmp_0 = { src.decay().offset((3) as isize) }; - let mut __first = src.decay(); + let __first: Value> = Rc::new(RefCell::new(src.decay())); + let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); let mut __out = (dst.decay()).reinterpret_cast::(); - while __first != __tmp_0 { + while !>::equal(__first.as_pointer(), __last.as_pointer()) { __out .iter_deref() - .write(((__first.iter_deref().read()) as u64)); - __first.iter_inc(); + .write(((__first.borrow().iter_deref().read()) as u64)); + __first.borrow_mut().iter_inc(); __out.iter_inc(); } __out @@ -80,27 +80,39 @@ pub fn size_t_in_rules_3() { assert!((mx > mn)); let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); match (Rc::new(RefCell::new(1_u64)).as_pointer(),) { - (__tmp_1,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_1, |__k| cpp_move!(__k), || 0_u64) }) + (__tmp_0,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_0, |__k| cpp_move!(__k), || 0_u64) }) } } .write(2_u64); let key: Value = Rc::new(RefCell::new(3_usize)); match ((key.as_pointer()).reinterpret_cast::(),) { - (__tmp_2,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_2, |__k| cpp_move!(__k), || 0_u64) }) + (__tmp_1,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_1, |__k| cpp_move!(__k), || 0_u64) }) } } .write(4_u64); - assert!( - ({ - let __tmp_3: Value = Rc::new(RefCell::new(1_u64)); + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_3: Value = Rc::new(RefCell::new(1_u64)); + m.as_pointer() + .with(|__m: &Map, Value)>| { + __m.find(&__tmp_3.as_pointer()) + }) + }) + )) + .as_pointer(), + Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.find(&__tmp_3.as_pointer())) - }) != m - .as_pointer() - .with(|__m: &Map, Value)>| __m.end()) - ); + .with(|__m: &Map, Value)>| __m.end()) + )) + .as_pointer(), + ) { + (__tmp_2, __tmp_4) => { + !WeaklyEqualityComparableWith::equal((__tmp_2).clone(), (__tmp_4).clone()) + } + }); assert!( ((*(*m .as_pointer() @@ -129,12 +141,12 @@ pub fn size_t_in_rules_3() { ))) .as_pointer(),) { - (__tmp_4,) => ( + (__tmp_5,) => ( Rc::new(RefCell::new( - (((*__tmp_4.upgrade().deref()).0.as_pointer().read()) as u64), + (((*__tmp_5.upgrade().deref()).0.as_pointer().read()) as u64), )), Rc::new(RefCell::new( - (((*__tmp_4.upgrade().deref()).1.as_pointer().read()) as u64), + (((*__tmp_5.upgrade().deref()).1.as_pointer().read()) as u64), )), ), }, @@ -163,9 +175,9 @@ pub fn size_t_in_rules_3() { ))) .as_pointer(),) { - (__tmp_5,) => { - let __first = (((*__tmp_5.upgrade().deref()).0.as_pointer().read()) as u64); - let __second = (((*__tmp_5.upgrade().deref()).1.as_pointer().read()) as u64); + (__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; } @@ -191,18 +203,18 @@ pub fn size_t_in_rules_3() { let v: Value> = Rc::new(RefCell::new(Vec::from_fn(3_usize, |_| 0_u64))); (*v.borrow_mut()).resize_with(5_usize, || 0_u64); { - let mut __tmp_6 = { >::from(v.decay().begin()) }; + let mut __tmp_7 = { >::from(v.decay().begin()) }; v.as_pointer() - .with_mut(|__v: &mut Vec| __v.remove(__tmp_6.index())); - (__tmp_6).clone() + .with_mut(|__v: &mut Vec| __v.remove(__tmp_7.index())); + (__tmp_7).clone() }; let mut v2: Vec = { - let mut __tmp_7 = { src.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = src.decay(); - while __it != __tmp_7 { - __v.push(((__it.iter_deref().read()) as u64)); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src.decay())); + let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __v.push(((__it.borrow().iter_deref().read()) as u64)); + __it.borrow_mut().iter_inc(); } __v }; @@ -216,13 +228,13 @@ pub fn size_t_in_rules_3() { (*v.borrow_mut()).push(((*k.borrow()) as u64)); }; { - let mut __tmp_9 = { v.decay().begin() }; - let mut __tmp_10 = { v.decay().end() }; - let mut __it = (__tmp_9).clone(); - while __it != __tmp_10 { - __it.iter_deref() + let __it: Value> = Rc::new(RefCell::new(v.decay().begin())); + let __last: Value> = Rc::new(RefCell::new(v.decay().end())); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __it.borrow() + .iter_deref() .write(Clone::clone(&({ ((*k.borrow()) as u64) }))); - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } }; Swappable::swap( @@ -230,13 +242,13 @@ pub fn size_t_in_rules_3() { (k.as_pointer()).reinterpret_cast::(), ); let mut big: usize = (({ - let __tmp_12: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); + let __tmp_10: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); (match (v.decay().offset(1_usize),) { - (__tmp_11,) => { - if CppLess::less((__tmp_11).clone().clone(), __tmp_12.as_pointer().clone()) { - __tmp_12.as_pointer() + (__tmp_9,) => { + if CppLess::less((__tmp_9).clone().clone(), __tmp_10.as_pointer().clone()) { + __tmp_10.as_pointer() } else { - (__tmp_11).clone() + (__tmp_9).clone() } } } @@ -252,14 +264,14 @@ pub fn size_t_in_rules_3() { .read()) as usize) }; { - let mut __tmp_13 = { + let mut __tmp_11 = { ( Rc::new(RefCell::new(({ ((*k.borrow()) as u64) }))), Rc::new(RefCell::new(({ ((*k.borrow()) as u64) }))), ) }; let (__it, __inserted) = - Map::emplace(m2.as_pointer(), &__tmp_13.0.as_pointer(), || __tmp_13); + Map::emplace(m2.as_pointer(), &__tmp_11.0.as_pointer(), || __tmp_11); ( Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted)), @@ -267,9 +279,9 @@ pub fn size_t_in_rules_3() { }; assert!( (((*(*({ - let __tmp_14: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); + let __tmp_12: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); m2.as_pointer() - .with(|__m: &Map, Value)>| __m.find(&__tmp_14.as_pointer())) + .with(|__m: &Map, Value)>| __m.find(&__tmp_12.as_pointer())) }) .iter_deref() .upgrade() @@ -279,13 +291,13 @@ pub fn size_t_in_rules_3() { == (*k.borrow())) ); { - let __tmp_15: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); - ({ (*m2.borrow_mut()).subscript(__tmp_15.as_pointer(), || 0_u64) }) + let __tmp_13: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); + ({ (*m2.borrow_mut()).subscript(__tmp_13.as_pointer(), || 0_u64) }) } .write((big as u64)); let mv: Ptr = ({ - let __tmp_16: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); - ({ (*m2.borrow_mut()).subscript(__tmp_16.as_pointer(), || 0_u64) }) + let __tmp_14: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); + ({ (*m2.borrow_mut()).subscript(__tmp_14.as_pointer(), || 0_u64) }) }) .reinterpret_cast::(); mv.write(1_usize); @@ -303,37 +315,47 @@ pub fn size_t_in_rules_3() { ((*k.borrow()) as u64), ]))); ({ - let __tmp_18: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); + let __tmp_16: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); { - let mut __tmp_17 = { >::from(v3.decay().begin()) }; - let __a2 = copy_constructed(__tmp_18.as_pointer()); - (*v3.borrow_mut()).insert(__tmp_17.index(), __a2); - (__tmp_17).clone() + let mut __tmp_15 = { >::from(v3.decay().begin()) }; + let __a2 = copy_constructed(__tmp_16.as_pointer()); + (*v3.borrow_mut()).insert(__tmp_15.index(), __a2); + (__tmp_15).clone() } }); ({ - let __tmp_19: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); - (*v3.borrow_mut()).resize_with(5_usize, || copy_constructed(__tmp_19.as_pointer().clone())) + let __tmp_17: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); + (*v3.borrow_mut()).resize_with(5_usize, || copy_constructed(__tmp_17.as_pointer().clone())) }); - assert!( - ({ - let __tmp_22: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); - { - let mut __tmp_20 = { v3.decay().begin() }; - let mut __tmp_21 = { v3.decay().end() }; - let mut __it = (__tmp_20).clone(); - while __it != __tmp_21 - && !WeaklyEqualityComparableWith::equal( - __it.iter_deref(), - __tmp_22.as_pointer().clone(), - ) + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_19: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); { - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(v3.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(v3.decay().end())); + while !>::equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_19.as_pointer().clone(), + ) { + __it.borrow_mut().iter_inc(); + } + __it.borrow().clone() } - __it - } - }) != v3.decay().end() - ); + }) + )) + .as_pointer(), + Rc::new(RefCell::new(v3.decay().end())).as_pointer(), + ) { + (__tmp_18, __tmp_20) => { + !WeaklyEqualityComparableWith::equal((__tmp_18).clone(), (__tmp_20).clone()) + } + }); assert!( ({ (((*v3.borrow()).len() == 5_usize) && (big >= (*k.borrow()))) @@ -388,37 +410,37 @@ fn main_0() -> i32 { let mut fr2: u64 = ({ take_ulong_1((sz as u64)) }); assert!((fr2 == 21_u64)); let mut lo: usize = (({ - let __tmp_23: Value = Rc::new(RefCell::new( + let __tmp_21: Value = Rc::new(RefCell::new( (::std::mem::size_of::() as u64).wrapping_add((*ul.borrow())), )); - let __tmp_24: Value = Rc::new(RefCell::new((sz as u64))); - (if CppLess::less(__tmp_23.as_pointer().clone(), __tmp_24.as_pointer().clone()) { - __tmp_23.as_pointer() + let __tmp_22: Value = Rc::new(RefCell::new((sz as u64))); + (if CppLess::less(__tmp_21.as_pointer().clone(), __tmp_22.as_pointer().clone()) { + __tmp_21.as_pointer() } else { - __tmp_24.as_pointer() + __tmp_22.as_pointer() } .read()) }) as usize); let mut hi: usize = (({ - let __tmp_25: Value = Rc::new(RefCell::new( + let __tmp_23: Value = Rc::new(RefCell::new( (::std::mem::size_of::() as u64).wrapping_add((sz as u64)), )); - (if CppLess::less(__tmp_25.as_pointer().clone(), ul.as_pointer().clone()) { + (if CppLess::less(__tmp_23.as_pointer().clone(), ul.as_pointer().clone()) { ul.as_pointer() } else { - __tmp_25.as_pointer() + __tmp_23.as_pointer() } .read()) }) as usize); assert!((lo == (::std::mem::size_of::() as usize).wrapping_add(10_usize))); assert!((hi == (::std::mem::size_of::() as usize).wrapping_add(21_usize))); let mut bound: usize = (({ - let __tmp_26: Value = Rc::new(RefCell::new((4_usize as u64))); - let __tmp_27: Value = Rc::new(RefCell::new((sz as u64))); - (if CppLess::less(__tmp_26.as_pointer().clone(), __tmp_27.as_pointer().clone()) { - __tmp_26.as_pointer() + let __tmp_24: Value = Rc::new(RefCell::new((4_usize as u64))); + let __tmp_25: Value = Rc::new(RefCell::new((sz as u64))); + (if CppLess::less(__tmp_24.as_pointer().clone(), __tmp_25.as_pointer().clone()) { + __tmp_24.as_pointer() } else { - __tmp_27.as_pointer() + __tmp_25.as_pointer() } .read()) }) as usize); @@ -469,22 +491,22 @@ fn main_0() -> i32 { assert!((sm == 15_isize)); assert!((sm > (l as isize))); let mut smin: isize = (({ - let __tmp_28: Value = Rc::new(RefCell::new((sm as i64))); - let __tmp_29: Value = Rc::new(RefCell::new((sd as i64))); - (if CppLess::less(__tmp_28.as_pointer().clone(), __tmp_29.as_pointer().clone()) { - __tmp_28.as_pointer() + let __tmp_26: Value = Rc::new(RefCell::new((sm as i64))); + let __tmp_27: Value = Rc::new(RefCell::new((sd as i64))); + (if CppLess::less(__tmp_26.as_pointer().clone(), __tmp_27.as_pointer().clone()) { + __tmp_26.as_pointer() } else { - __tmp_29.as_pointer() + __tmp_27.as_pointer() } .read()) }) as isize); let mut smax: isize = (({ - let __tmp_30: Value = Rc::new(RefCell::new((sd as i64))); - let __tmp_31: Value = Rc::new(RefCell::new((sm as i64))); - (if CppLess::less(__tmp_30.as_pointer().clone(), __tmp_31.as_pointer().clone()) { - __tmp_31.as_pointer() + let __tmp_28: Value = Rc::new(RefCell::new((sd as i64))); + let __tmp_29: Value = Rc::new(RefCell::new((sm as i64))); + (if CppLess::less(__tmp_28.as_pointer().clone(), __tmp_29.as_pointer().clone()) { + __tmp_29.as_pointer() } else { - __tmp_30.as_pointer() + __tmp_28.as_pointer() } .read()) }) as isize); @@ -506,22 +528,22 @@ fn main_0() -> i32 { let mut mins: [usize; 4] = [ 0_usize, (({ - let __tmp_32: Value = Rc::new(RefCell::new((mx as u64))); - let __tmp_33: Value = Rc::new(RefCell::new(1_u64)); - (if CppLess::less(__tmp_32.as_pointer().clone(), __tmp_33.as_pointer().clone()) { - __tmp_32.as_pointer() + let __tmp_30: Value = Rc::new(RefCell::new((mx as u64))); + let __tmp_31: Value = Rc::new(RefCell::new(1_u64)); + (if CppLess::less(__tmp_30.as_pointer().clone(), __tmp_31.as_pointer().clone()) { + __tmp_30.as_pointer() } else { - __tmp_33.as_pointer() + __tmp_31.as_pointer() } .read()) }) as usize), (({ - let __tmp_34: Value = Rc::new(RefCell::new(((mx).wrapping_sub(3_usize) as u64))); - let __tmp_35: Value = Rc::new(RefCell::new((mx as u64))); - (if CppLess::less(__tmp_34.as_pointer().clone(), __tmp_35.as_pointer().clone()) { - __tmp_34.as_pointer() + let __tmp_32: Value = Rc::new(RefCell::new(((mx).wrapping_sub(3_usize) as u64))); + let __tmp_33: Value = Rc::new(RefCell::new((mx as u64))); + (if CppLess::less(__tmp_32.as_pointer().clone(), __tmp_33.as_pointer().clone()) { + __tmp_32.as_pointer() } else { - __tmp_35.as_pointer() + __tmp_33.as_pointer() } .read()) }) as usize), diff --git a/tests/unit/out/refcount/sort_no_copy.rs b/tests/unit/out/refcount/sort_no_copy.rs index 98193c39e2..31ce2fabff 100644 --- a/tests/unit/out/refcount/sort_no_copy.rs +++ b/tests/unit/out/refcount/sort_no_copy.rs @@ -426,40 +426,54 @@ fn main_0() -> i32 { }) ); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); - assert!( - { - let mut __tmp_20 = { bag_vec.decay().begin() }; - let mut __tmp_21 = { bag_vec.decay().end() }; - let mut __it = (__tmp_20).clone(); - while __it != __tmp_21 + assert!(match ( + Rc::new(RefCell::new({ + let __it: Value> = + Rc::new(RefCell::new(bag_vec.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(bag_vec.decay().end())); + while !>::equal(__it.as_pointer(), __last.as_pointer()) && !WeaklyEqualityComparableWith::equal( - __it.iter_deref(), + __it.borrow().iter_deref(), bags.decay().offset(1).clone(), ) { - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } - __it - } == bag_vec.decay().begin().iter_add(1_isize) - ); - assert!( - { - let mut __tmp_22 = { bag_vec.decay().begin() }; - let mut __tmp_23 = { bag_vec.decay().end() }; - let mut __best = __tmp_22.clone(); - if __tmp_22 != __tmp_23 { - let mut __it = (__tmp_22).clone(); - __it.iter_inc(); - while __it != __tmp_23 { - if CppLess::less(__best.iter_deref(), __it.iter_deref()) { - __best = __it.clone(); + __it.borrow().clone() + })) + .as_pointer(), + Rc::new(RefCell::new(bag_vec.decay().begin().iter_add(1_isize))).as_pointer(), + ) { + (__tmp_20, __tmp_21) => { + WeaklyEqualityComparableWith::equal((__tmp_20).clone(), (__tmp_21).clone()) + } + }); + assert!(match ( + Rc::new(RefCell::new({ + let __it: Value> = + Rc::new(RefCell::new(bag_vec.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(bag_vec.decay().end())); + let mut __best = __it.borrow().clone(); + if !>::equal(__it.as_pointer(), __last.as_pointer()) { + __it.borrow_mut().iter_inc(); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + if CppLess::less(__best.iter_deref(), __it.borrow().iter_deref()) { + __best = __it.borrow().clone(); } - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } } __best - } == bag_vec.decay().begin().iter_add(2_isize) - ); + })) + .as_pointer(), + Rc::new(RefCell::new(bag_vec.decay().begin().iter_add(2_isize))).as_pointer(), + ) { + (__tmp_22, __tmp_23) => { + WeaklyEqualityComparableWith::equal((__tmp_22).clone(), (__tmp_23).clone()) + } + }); assert!( ((if CppLess::less( bags.decay().offset(2).clone(), @@ -505,64 +519,72 @@ fn main_0() -> i32 { .borrow()) == 2) ); - assert!( - bag_map - .as_pointer() - .with(|__m: &Map, Value)>| __m.find(&bags.decay().offset(1))) - == bag_map + assert!(match ( + Rc::new(RefCell::new(bag_map.as_pointer().with( + |__m: &Map, Value)>| __m.find(&bags.decay().offset(1)) + ))) + .as_pointer(), + Rc::new(RefCell::new( + bag_map .as_pointer() .with(|__m: &Map, Value)>| __m.end()) - ); + )) + .as_pointer(), + ) { + (__tmp_26, __tmp_27) => { + WeaklyEqualityComparableWith::equal((__tmp_26).clone(), (__tmp_27).clone()) + } + }); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); let moves: Value> = Rc::new(RefCell::new(Vec::new())); { - let mut __tmp_26 = { + let mut __tmp_28 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); MoveOnly::construct(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - (*moves.borrow_mut()).push(__tmp_26); + (*moves.borrow_mut()).push(__tmp_28); }; { - let mut __tmp_27 = { + let mut __tmp_29 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); MoveOnly::construct(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - (*moves.borrow_mut()).push(__tmp_27); + (*moves.borrow_mut()).push(__tmp_29); }; { - let mut __tmp_28 = { + let mut __tmp_30 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); MoveOnly::construct(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - (*moves.borrow_mut()).push(__tmp_28); + (*moves.borrow_mut()).push(__tmp_30); }; { - let mut __tmp_29 = { moves.decay().begin() }; - let __n = moves.decay().end().iter_distance(&__tmp_29); + let mut __tmp_31 = { moves.decay().begin() }; + let __n = moves.decay().end().iter_distance(&__tmp_31); let mut __order: Vec = (0..__n).collect(); - __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_29.iter_at(__x), &__tmp_29.iter_at(__y))); - reorder(__order, |__i| __tmp_29.iter_at(__i)); + __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_31.iter_at(__x), &__tmp_31.iter_at(__y))); + reorder(__order, |__i| __tmp_31.iter_at(__i)); }; assert!( (({ (*moves.borrow())[0_usize].v } == 1) && ({ (*moves.borrow())[1_usize].v } == 2)) && ({ (*moves.borrow())[2_usize].v } == 3) ); { - let mut __tmp_30 = { moves.decay().begin() }; - let __n = moves.decay().end().iter_distance(&__tmp_30); + let mut __tmp_32 = { moves.decay().begin() }; + let __n = moves.decay().end().iter_distance(&__tmp_32); let mut __order: Vec = (0..__n).collect(); __order.sort_by(|&__x, &__y| { - let __a = __tmp_30.iter_at(__x); - let __b = __tmp_30.iter_at(__y); + let __a = __tmp_32.iter_at(__x); + let __b = __tmp_32.iter_at(__y); if FnPtr::, Ptr) -> bool>::new( |a: Ptr, b: Ptr| -> bool { { @@ -587,7 +609,7 @@ fn main_0() -> i32 { std::cmp::Ordering::Equal } }); - reorder(__order, |__i| __tmp_30.iter_at(__i)); + reorder(__order, |__i| __tmp_32.iter_at(__i)); }; assert!( (({ (*moves.borrow())[0_usize].v } == 3) && ({ (*moves.borrow())[1_usize].v } == 2)) diff --git a/tests/unit/out/refcount/stdcopy.rs b/tests/unit/out/refcount/stdcopy.rs index 45fdbba656..b20a77a8af 100644 --- a/tests/unit/out/refcount/stdcopy.rs +++ b/tests/unit/out/refcount/stdcopy.rs @@ -39,12 +39,14 @@ fn main_0() -> i32 { let output: Value> = Rc::new(RefCell::new((0..3).map(|_| 0_i32).collect::>())); { - let mut __tmp_0 = { input.decay().offset((3) as isize) }; - let mut __first = input.decay(); + let __first: Value> = Rc::new(RefCell::new(input.decay())); + let __last: Value> = Rc::new(RefCell::new(input.decay().offset((3) as isize))); let mut __out = output.decay(); - while __first != __tmp_0 { - __out.iter_deref().write((__first.iter_deref().read())); - __first.iter_inc(); + while !>::equal(__first.as_pointer(), __last.as_pointer()) { + __out + .iter_deref() + .write((__first.borrow().iter_deref().read())); + __first.borrow_mut().iter_inc(); __out.iter_inc(); } __out @@ -55,14 +57,14 @@ fn main_0() -> i32 { .collect(), )); { - let mut __tmp_1 = { input.decay().offset((3) as isize) }; - let mut __first = input.decay(); + let __first: Value> = Rc::new(RefCell::new(input.decay())); + let __last: Value> = Rc::new(RefCell::new(input.decay().offset((3) as isize))); let mut __out = widened.decay().begin(); - while __first != __tmp_1 { + while !>::equal(__first.as_pointer(), __last.as_pointer()) { __out .iter_deref() - .write(((__first.iter_deref().read()) as i64)); - __first.iter_inc(); + .write(((__first.borrow().iter_deref().read()) as i64)); + __first.borrow_mut().iter_inc(); __out.iter_inc(); } __out @@ -71,26 +73,28 @@ fn main_0() -> i32 { ({ (*widened.borrow())[0_usize] } == 1_i64) && ({ (*widened.borrow())[2_usize] } == 3_i64) ); let constructed: Value> = Rc::new(RefCell::new({ - let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); match ({ - Degrees::construct(__tmp_3.as_pointer(), 0); - __tmp_3.as_pointer() + Degrees::construct(__tmp_1.as_pointer(), 0); + __tmp_1.as_pointer() },) { - (__tmp_2,) => (0..3_usize) - .map(|_| copy_constructed((__tmp_2).clone().clone())) + (__tmp_0,) => (0..3_usize) + .map(|_| copy_constructed((__tmp_0).clone().clone())) .collect(), } })); { - let mut __tmp_4 = { input.decay().offset((3) as isize) }; - let mut __first = input.decay(); + let __first: Value> = Rc::new(RefCell::new(input.decay())); + let __last: Value> = Rc::new(RefCell::new(input.decay().offset((3) as isize))); let mut __out = constructed.decay().begin(); - while __first != __tmp_4 { + while !>::equal(__first.as_pointer(), __last.as_pointer()) { __out .iter_deref() - .write(>::cpp_from(__first.iter_deref())); - __first.iter_inc(); + .write(>::cpp_from( + __first.borrow().iter_deref(), + )); + __first.borrow_mut().iter_inc(); __out.iter_inc(); } __out @@ -106,14 +110,14 @@ fn main_0() -> i32 { .collect(), )); { - let mut __tmp_5 = { wide.decay().offset((2) as isize) }; - let mut __first = wide.decay(); + let __first: Value> = Rc::new(RefCell::new(wide.decay())); + let __last: Value> = Rc::new(RefCell::new(wide.decay().offset((2) as isize))); let mut __out = floating.decay().begin(); - while __first != __tmp_5 { + while !>::equal(__first.as_pointer(), __last.as_pointer()) { __out .iter_deref() - .write(((__first.iter_deref().read()) as f64)); - __first.iter_inc(); + .write(((__first.borrow().iter_deref().read()) as f64)); + __first.borrow_mut().iter_inc(); __out.iter_inc(); } __out diff --git a/tests/unit/out/refcount/stdcopy_ostream.rs b/tests/unit/out/refcount/stdcopy_ostream.rs index bb899c8f52..c4702a9bcb 100644 --- a/tests/unit/out/refcount/stdcopy_ostream.rs +++ b/tests/unit/out/refcount/stdcopy_ostream.rs @@ -28,12 +28,13 @@ fn main_0() -> i32 { { let mut __tmp_0 = { RandomAccessIterator::Vec(str.decay()) }; let mut __tmp_1 = { RandomAccessIterator::Vec(str.decay().to_last()) }; - let mut __it = (__tmp_0).clone(); + let __it: Value> = Rc::new(RefCell::new(__tmp_0)); + let __last: Value> = Rc::new(RefCell::new(__tmp_1)); let __out = &mut (*ofs.borrow_mut()); let mut __bytes: Vec = Vec::new(); - while __it != __tmp_1 { - __bytes.push(__it.iter_deref().read() as u8); - __it.iter_inc(); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __bytes.push(__it.borrow().iter_deref().read() as u8); + __it.borrow_mut().iter_inc(); } __out.write_all(&__bytes); __out.try_clone().unwrap() diff --git a/tests/unit/out/refcount/unboxed_conditional_iterator.rs b/tests/unit/out/refcount/unboxed_conditional_iterator.rs index 21720c30e4..bced1d3af9 100644 --- a/tests/unit/out/refcount/unboxed_conditional_iterator.rs +++ b/tests/unit/out/refcount/unboxed_conditional_iterator.rs @@ -55,29 +55,37 @@ pub fn lehmer_3(mut sigma: Ptr, mut len: u32, mut code: Ptr) { 'loop_: while (i < len) { 'for_body: { let it: Value> = Rc::new(RefCell::new({ - let mut __tmp_0 = { items.decay().begin() }; - let mut __tmp_1 = { items.decay().end() }; - let mut __it = (__tmp_0).clone(); - while __it != __tmp_1 - && !WeaklyEqualityComparableWith::equal( - __it.iter_deref(), - sigma.offset((i) as isize).clone(), - ) - { - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(items.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(items.decay().end())); + while !>::equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + sigma.offset((i) as isize).clone(), + ) { + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() })); - assert!((*it.borrow()) != items.decay().end()); + assert!( + match (Rc::new(RefCell::new(items.decay().end())).as_pointer(),) { + (__tmp_0,) => { + !WeaklyEqualityComparableWith::equal(it.as_pointer(), (__tmp_0).clone()) + } + } + ); let __rhs = (((*it.borrow()).iter_distance(&items.decay().begin())) as u32); elem!(code, i).write(__rhs); { - let mut __tmp_2 = + let mut __tmp_1 = { >::from(({ (*it.borrow()).clone() })) }; items .as_pointer() - .with_mut(|__v: &mut Vec| __v.remove(__tmp_2.index())); - (__tmp_2).clone() + .with_mut(|__v: &mut Vec| __v.remove(__tmp_1.index())); + (__tmp_1).clone() }; } i.prefix_inc(); @@ -88,7 +96,9 @@ pub fn sum_4(v: Ptr>) -> i32 { let mut s: i32 = 0; { let it: Value> = Rc::new(RefCell::new(v.decay().begin())); - 'loop_: while (*it.borrow()) != v.decay().end() { + 'loop_: while match (Rc::new(RefCell::new(v.decay().end())).as_pointer(),) { + (__tmp_2,) => !WeaklyEqualityComparableWith::equal(it.as_pointer(), (__tmp_2).clone()), + } { 'for_body: { s += (({ (*it.borrow()).iter_deref() }).read()); } diff --git a/tests/unit/out/refcount/vector.rs b/tests/unit/out/refcount/vector.rs index 47f5e85479..247311d0fe 100644 --- a/tests/unit/out/refcount/vector.rs +++ b/tests/unit/out/refcount/vector.rs @@ -182,14 +182,13 @@ fn main_0() -> i32 { let src: Value> = Rc::new(RefCell::new(Vec::from([21, 22]))); { let mut __tmp_10 = { >::from(v2.decay().begin()) }; - let mut __tmp_11 = { src.decay().begin() }; - let mut __tmp_12 = { src.decay().end() }; let start_idx = __tmp_10.index(); let mut temp_vec: Vec = Vec::new(); - let mut __it = (__tmp_11).clone(); - while __it != __tmp_12 { - temp_vec.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src.decay().begin())); + let __last: Value> = Rc::new(RefCell::new(src.decay().end())); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + temp_vec.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } v2.as_pointer().with_mut(|v: &mut Vec| { v.splice(start_idx..start_idx, temp_vec); @@ -201,27 +200,27 @@ fn main_0() -> i32 { assert!(({ (*v2.borrow())[1_usize] } == 22)); assert!(({ (*v2.borrow())[2_usize] } == 100)); { - let mut __tmp_13 = { >::from(v2.decay().begin()) }; + let mut __tmp_11 = { >::from(v2.decay().begin()) }; v2.as_pointer() - .with_mut(|__v: &mut Vec| __v.remove(__tmp_13.index())); - (__tmp_13).clone() + .with_mut(|__v: &mut Vec| __v.remove(__tmp_11.index())); + (__tmp_11).clone() }; { - let mut __tmp_14 = { >::from(v2.decay().begin()) }; + let mut __tmp_12 = { >::from(v2.decay().begin()) }; v2.as_pointer() - .with_mut(|__v: &mut Vec| __v.remove(__tmp_14.index())); - (__tmp_14).clone() + .with_mut(|__v: &mut Vec| __v.remove(__tmp_12.index())); + (__tmp_12).clone() }; { let mut i: i32 = 0; 'loop_: while (i < 4) { 'for_body: { { - let mut __tmp_15 = + let mut __tmp_13 = { >::from(v2.decay().begin().iter_add(1_isize)) }; v2.as_pointer() - .with_mut(|__v: &mut Vec| __v.remove(__tmp_15.index())); - (__tmp_15).clone() + .with_mut(|__v: &mut Vec| __v.remove(__tmp_13.index())); + (__tmp_13).clone() }; } i.prefix_inc(); @@ -436,11 +435,11 @@ fn main_0() -> i32 { assert!( ({ (({ - let mut __tmp_16 = { (idx as usize) }; - if __tmp_16 >= (*v6.borrow()).len() { + let mut __tmp_14 = { (idx as usize) }; + if __tmp_14 >= (*v6.borrow()).len() { panic!("out of bounds access") } - v6.decay().offset((__tmp_16) as isize) + v6.decay().offset((__tmp_14) as isize) } .read()) == 2_f64) @@ -449,22 +448,22 @@ fn main_0() -> i32 { assert!( ({ (({ - let mut __tmp_17 = { (s2).wrapping_sub(1_usize) }; - if __tmp_17 >= (*v6.borrow()).len() { + let mut __tmp_15 = { (s2).wrapping_sub(1_usize) }; + if __tmp_15 >= (*v6.borrow()).len() { panic!("out of bounds access") } - v6.decay().offset((__tmp_17) as isize) + v6.decay().offset((__tmp_15) as isize) } .read()) == 5_f64) }) ); let ref1: Ptr = { - let mut __tmp_18 = { (s2).wrapping_sub(1_usize) }; - if __tmp_18 >= (*v6.borrow()).len() { + let mut __tmp_16 = { (s2).wrapping_sub(1_usize) }; + if __tmp_16 >= (*v6.borrow()).len() { panic!("out of bounds access") } - v6.decay().offset((__tmp_18) as isize) + v6.decay().offset((__tmp_16) as isize) }; { ref1.with_mut(|__v| *__v = *__v + 1.5_f64) @@ -472,22 +471,22 @@ fn main_0() -> i32 { assert!( ({ (({ - let mut __tmp_19 = { (s2).wrapping_sub(1_usize) }; - if __tmp_19 >= (*v6.borrow()).len() { + let mut __tmp_17 = { (s2).wrapping_sub(1_usize) }; + if __tmp_17 >= (*v6.borrow()).len() { panic!("out of bounds access") } - v6.decay().offset((__tmp_19) as isize) + v6.decay().offset((__tmp_17) as isize) } .read()) == 6.5_f64) }) ); let mut x1: f64 = ({ - let mut __tmp_20 = { (s2).wrapping_sub(1_usize) }; - if __tmp_20 >= (*v6.borrow()).len() { + let mut __tmp_18 = { (s2).wrapping_sub(1_usize) }; + if __tmp_18 >= (*v6.borrow()).len() { panic!("out of bounds access") } - v6.decay().offset((__tmp_20) as isize) + v6.decay().offset((__tmp_18) as isize) } .read()); assert!((x1 == 6.5_f64)); @@ -495,11 +494,11 @@ fn main_0() -> i32 { assert!( ({ (({ - let mut __tmp_21 = { (s2).wrapping_sub(1_usize) }; - if __tmp_21 >= (*v6.borrow()).len() { + let mut __tmp_19 = { (s2).wrapping_sub(1_usize) }; + if __tmp_19 >= (*v6.borrow()).len() { panic!("out of bounds access") } - v6.decay().offset((__tmp_21) as isize) + v6.decay().offset((__tmp_19) as isize) } .read()) == 6.5_f64) @@ -522,15 +521,15 @@ fn main_0() -> i32 { let pa: Value> = Rc::new(RefCell::new((a.as_pointer()))); let v8: Value>>> = Rc::new(RefCell::new(Vec::new())); ({ - let __tmp_22: Value>> = Rc::new(RefCell::new((pa.as_pointer()))); - MoveConstructible::push_moved(&v8.as_pointer(), __tmp_22.as_pointer()) + let __tmp_20: Value>> = Rc::new(RefCell::new((pa.as_pointer()))); + MoveConstructible::push_moved(&v8.as_pointer(), __tmp_20.as_pointer()) }); assert!(({ (((*v8.borrow())[0_usize].read()).with(|__s| __s.x) == 1) })); let ppa: Value>> = Rc::new(RefCell::new((pa.as_pointer()))); let v9: Value>>>> = Rc::new(RefCell::new(Vec::new())); ({ - let __tmp_23: Value>>> = Rc::new(RefCell::new((ppa.as_pointer()))); - MoveConstructible::push_moved(&v9.as_pointer(), __tmp_23.as_pointer()) + let __tmp_21: Value>>> = Rc::new(RefCell::new((ppa.as_pointer()))); + MoveConstructible::push_moved(&v9.as_pointer(), __tmp_21.as_pointer()) }); field!((((*v9.borrow())[0_usize].read()).read()), x).write(2); assert!(({ (*a.borrow()).x } == 2)); @@ -547,24 +546,24 @@ fn main_0() -> i32 { ); object!(foo, Foo); ({ - let __tmp_24: Value = Rc::new(RefCell::new(5)); + let __tmp_22: Value = Rc::new(RefCell::new(5)); MoveConstructible::push_moved( &field_ref!(foo.as_pointer(), a).as_pointer(), - __tmp_24.as_pointer(), + __tmp_22.as_pointer(), ) }); ({ - let __tmp_25: Value = Rc::new(RefCell::new(6)); + let __tmp_23: Value = Rc::new(RefCell::new(6)); MoveConstructible::push_moved( &field_ref!(foo.as_pointer(), b).as_pointer(), - __tmp_25.as_pointer(), + __tmp_23.as_pointer(), ) }); ({ - let __tmp_26: Value = Rc::new(RefCell::new(7)); + let __tmp_24: Value = Rc::new(RefCell::new(7)); MoveConstructible::push_moved( &field_ref!(foo.as_pointer(), b).as_pointer(), - __tmp_26.as_pointer(), + __tmp_24.as_pointer(), ) }); field_ref!(foo.as_pointer(), a) @@ -660,21 +659,21 @@ fn main_0() -> i32 { let v16: Value> = Rc::new(RefCell::new(Vec::from([1, 2, 3, 4, 5, 6, 7, 8]))); let mut after_v16: Vec = Vec::from([0]); let inserted: Value> = Rc::new(RefCell::new({ - let mut __tmp_27 = + let mut __tmp_25 = { >::from(v16.decay().begin().iter_add(1_isize)) }; let __a2 = 7; - (*v16.borrow_mut()).insert(__tmp_27.index(), __a2); - (__tmp_27).clone() + (*v16.borrow_mut()).insert(__tmp_25.index(), __a2); + (__tmp_25).clone() })); { ({ (*inserted.borrow()).iter_deref() }).with_mut(|__v| *__v = *__v + 1) }; let nine: Value = Rc::new(RefCell::new(9)); let inserted_copy: Value> = Rc::new(RefCell::new({ - let mut __tmp_28 = { >::from(v16.decay().begin()) }; + let mut __tmp_26 = { >::from(v16.decay().begin()) }; let __a2 = copy_constructed(nine.as_pointer()); - (*v16.borrow_mut()).insert(__tmp_28.index(), __a2); - (__tmp_28).clone() + (*v16.borrow_mut()).insert(__tmp_26.index(), __a2); + (__tmp_26).clone() })); { ({ (*inserted_copy.borrow()).iter_deref() }).with_mut(|__v| *__v = *__v + 1) @@ -687,20 +686,20 @@ fn main_0() -> i32 { let ints: Value> = Rc::new(RefCell::new(Box::new([1, 2, 3]))); let longs: Value> = Rc::new(RefCell::new(Vec::from([10_i64, 20_i64]))); let pos: Value> = Rc::new(RefCell::new({ - let mut __tmp_29 = + let mut __tmp_27 = { >::from(longs.decay().begin().iter_add(1_isize)) }; - let mut __tmp_30 = { ints.decay().offset((3) as isize) }; - let start_idx = __tmp_29.index(); + let start_idx = __tmp_27.index(); let mut temp_vec: Vec = Vec::new(); - let mut __it = ints.decay(); - while __it != __tmp_30 { - temp_vec.push(((__it.iter_deref().read()) as i64)); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(ints.decay())); + let __last: Value> = Rc::new(RefCell::new(ints.decay().offset((3) as isize))); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + temp_vec.push(((__it.borrow().iter_deref().read()) as i64)); + __it.borrow_mut().iter_inc(); } longs.as_pointer().with_mut(|v: &mut Vec| { v.splice(start_idx..start_idx, temp_vec); }); - (__tmp_29).clone() + (__tmp_27).clone() })); assert!( ({ @@ -712,39 +711,40 @@ fn main_0() -> i32 { ); let more: Value> = Rc::new(RefCell::new(Vec::from([4, 5]))); { - let mut __tmp_31 = { >::from(longs.decay().end()) }; - let mut __tmp_32 = { more.decay().begin() }; - let mut __tmp_33 = { more.decay().end() }; - let start_idx = __tmp_31.index(); + let mut __tmp_28 = { >::from(longs.decay().end()) }; + let start_idx = __tmp_28.index(); let mut temp_vec: Vec = Vec::new(); - let mut __it = (__tmp_32).clone(); - while __it != __tmp_33 { - temp_vec.push(((__it.iter_deref().read()) as i64)); - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(more.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(more.decay().end())); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + temp_vec.push(((__it.borrow().iter_deref().read()) as i64)); + __it.borrow_mut().iter_inc(); } longs.as_pointer().with_mut(|v: &mut Vec| { v.splice(start_idx..start_idx, temp_vec); }); - (__tmp_31).clone() + (__tmp_28).clone() }; assert!( ({ ((*longs.borrow()).len() == 7_usize) && ({ (*longs.borrow())[6_usize] } == 5_i64) }) ); let doubles: Value> = Rc::new(RefCell::new(Vec::new())); { - let mut __tmp_34 = { >::from(doubles.decay().begin()) }; - let mut __tmp_35 = { ints.decay().offset((2) as isize) }; - let start_idx = __tmp_34.index(); + let mut __tmp_29 = { >::from(doubles.decay().begin()) }; + let start_idx = __tmp_29.index(); let mut temp_vec: Vec = Vec::new(); - let mut __it = ints.decay(); - while __it != __tmp_35 { - temp_vec.push(((__it.iter_deref().read()) as f64)); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(ints.decay())); + let __last: Value> = Rc::new(RefCell::new(ints.decay().offset((2) as isize))); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + temp_vec.push(((__it.borrow().iter_deref().read()) as f64)); + __it.borrow_mut().iter_inc(); } doubles.as_pointer().with_mut(|v: &mut Vec| { v.splice(start_idx..start_idx, temp_vec); }); - (__tmp_34).clone() + (__tmp_29).clone() }; assert!( ({ @@ -754,19 +754,21 @@ fn main_0() -> i32 { ); let wrapped: Value> = Rc::new(RefCell::new(Vec::new())); { - let mut __tmp_36 = { >::from(wrapped.decay().begin()) }; - let mut __tmp_37 = { ints.decay().offset((3) as isize) }; - let start_idx = __tmp_36.index(); + let mut __tmp_30 = { >::from(wrapped.decay().begin()) }; + let start_idx = __tmp_30.index(); let mut temp_vec: Vec = Vec::new(); - let mut __it = ints.decay(); - while __it != __tmp_37 { - temp_vec.push(>::cpp_from(__it.iter_deref())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(ints.decay())); + let __last: Value> = Rc::new(RefCell::new(ints.decay().offset((3) as isize))); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + temp_vec.push(>::cpp_from( + __it.borrow().iter_deref(), + )); + __it.borrow_mut().iter_inc(); } wrapped.as_pointer().with_mut(|v: &mut Vec| { v.splice(start_idx..start_idx, temp_vec); }); - (__tmp_36).clone() + (__tmp_30).clone() }; assert!( ({ @@ -776,20 +778,21 @@ fn main_0() -> i32 { ); let same: Value> = Rc::new(RefCell::new(Vec::from([7]))); { - let mut __tmp_38 = { >::from(same.decay().begin()) }; - let mut __tmp_39 = { more.decay().begin() }; - let mut __tmp_40 = { more.decay().end() }; - let start_idx = __tmp_38.index(); + let mut __tmp_31 = { >::from(same.decay().begin()) }; + let start_idx = __tmp_31.index(); let mut temp_vec: Vec = Vec::new(); - let mut __it = (__tmp_39).clone(); - while __it != __tmp_40 { - temp_vec.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(more.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(more.decay().end())); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + temp_vec.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } same.as_pointer().with_mut(|v: &mut Vec| { v.splice(start_idx..start_idx, temp_vec); }); - (__tmp_38).clone() + (__tmp_31).clone() }; assert!( ({ diff --git a/tests/unit/out/refcount/vector_iter_range_ctor.rs b/tests/unit/out/refcount/vector_iter_range_ctor.rs index 688722f1c7..0e69e3cfc8 100644 --- a/tests/unit/out/refcount/vector_iter_range_ctor.rs +++ b/tests/unit/out/refcount/vector_iter_range_ctor.rs @@ -61,36 +61,36 @@ pub fn main() { fn main_0() -> i32 { let src: Value> = Rc::new(RefCell::new(Box::new([1_u32, 2_u32, 3_u32]))); let mut v1: Vec = { - let mut __tmp_0 = { src.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = src.decay(); - while __it != __tmp_0 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src.decay())); + let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v }; assert!((v1.len() == 3_usize)); assert!(((v1[0_usize] == 1_u32) && (v1[1_usize] == 2_u32)) && (v1[2_usize] == 3_u32)); let mut v2: Vec = { - let mut __tmp_1 = { src.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = src.decay(); - while __it != __tmp_1 { - __v.push(((__it.iter_deref().read()) as u64)); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src.decay())); + let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __v.push(((__it.borrow().iter_deref().read()) as u64)); + __it.borrow_mut().iter_inc(); } __v }; assert!((v2.len() == 3_usize)); assert!(((v2[0_usize] == 1_u64) && (v2[1_usize] == 2_u64)) && (v2[2_usize] == 3_u64)); let mut v3: Vec = { - let mut __tmp_2 = { src.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = src.decay(); - while __it != __tmp_2 { - __v.push(((__it.iter_deref().read()) as i32)); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src.decay())); + let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __v.push(((__it.borrow().iter_deref().read()) as i32)); + __it.borrow_mut().iter_inc(); } __v }; @@ -98,12 +98,12 @@ fn main_0() -> i32 { assert!(((v3[0_usize] == 1) && (v3[1_usize] == 2)) && (v3[2_usize] == 3)); let src1: Value> = Rc::new(RefCell::new(Box::new([1_u32, 2_u32, 3_u32]))); let mut v4: Vec = { - let mut __tmp_3 = { src1.decay().to_end() }; let mut __v = Vec::new(); - let mut __it = src1.decay(); - while __it != __tmp_3 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src1.decay())); + let __last: Value> = Rc::new(RefCell::new(src1.decay().to_end())); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v }; @@ -117,12 +117,12 @@ fn main_0() -> i32 { let mut start: Ptr = buf.decay(); let mut len: usize = 5_usize; let mut v5: Vec = { - let mut __tmp_4 = { start.offset((len) as isize) }; let mut __v = Vec::new(); - let mut __it = (start).clone(); - while __it != __tmp_4 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new((start).clone())); + let __last: Value> = Rc::new(RefCell::new(start.offset((len) as isize))); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v }; @@ -130,40 +130,42 @@ fn main_0() -> i32 { assert!(((v5[0_usize] as i32) == 10) && ((v5[4_usize] as i32) == 50)); let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_5,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_5, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_0,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_0, |__k| cpp_move!(__k), || 0_i32) }) } } .write(10); match (Rc::new(RefCell::new(2)).as_pointer(),) { - (__tmp_6,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_6, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_1,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_1, |__k| cpp_move!(__k), || 0_i32) }) } } .write(20); match (Rc::new(RefCell::new(3)).as_pointer(),) { - (__tmp_7,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_7, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_2,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_2, |__k| cpp_move!(__k), || 0_i32) }) } } .write(30); let v6: Value, Value)>> = Rc::new(RefCell::new({ - let mut __tmp_8 = { + let mut __v = Vec::new(); + let __it: Value, Value)>> = Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.begin()) - }; - let mut __tmp_9 = { + .with(|__m: &Map, Value)>| __m.begin()), + )); + let __last: Value, Value)>> = Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.end()) - }; - let mut __v = Vec::new(); - let mut __it = (__tmp_8).clone(); - while __it != __tmp_9 { + .with(|__m: &Map, Value)>| __m.end()), + )); + while !, Value)>>::equal( + __it.as_pointer(), + __last.as_pointer(), + ) { __v.push(<(Value, Value) as CppFrom<( Value, Value, - )>>::cpp_from(__it.iter_deref())); - __it.iter_inc(); + )>>::cpp_from(__it.borrow().iter_deref())); + __it.borrow_mut().iter_inc(); } __v })); @@ -181,34 +183,36 @@ fn main_0() -> i32 { }) ); { - let mut __tmp_10 = { + let mut __tmp_3 = { , Value)>>::from( v6.decay().begin().iter_add(1_isize), ) }; - let mut __tmp_11 = { + let start_idx = __tmp_3.index(); + let mut temp_vec: Vec<(Value, Value)> = Vec::new(); + let __it: Value, Value)>> = Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.begin()) - }; - let mut __tmp_12 = { + .with(|__m: &Map, Value)>| __m.begin()), + )); + let __last: Value, Value)>> = Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.end()) - }; - let start_idx = __tmp_10.index(); - let mut temp_vec: Vec<(Value, Value)> = Vec::new(); - let mut __it = (__tmp_11).clone(); - while __it != __tmp_12 { + .with(|__m: &Map, Value)>| __m.end()), + )); + while !, Value)>>::equal( + __it.as_pointer(), + __last.as_pointer(), + ) { temp_vec.push(<(Value, Value) as CppFrom<( Value, Value, - )>>::cpp_from(__it.iter_deref())); - __it.iter_inc(); + )>>::cpp_from(__it.borrow().iter_deref())); + __it.borrow_mut().iter_inc(); } v6.as_pointer() .with_mut(|v: &mut Vec<(Value, Value)>| { v.splice(start_idx..start_idx, temp_vec); }); - (__tmp_10).clone() + (__tmp_3).clone() }; assert!(({ ((*v6.borrow()).len() == 6_usize) })); assert!( @@ -220,12 +224,14 @@ fn main_0() -> i32 { ); let ints: Value> = Rc::new(RefCell::new(Box::new([4, 5, 6]))); let mut v7: Vec = { - let mut __tmp_13 = { ints.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = ints.decay(); - while __it != __tmp_13 { - __v.push(>::cpp_from(__it.iter_deref())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(ints.decay())); + let __last: Value> = Rc::new(RefCell::new(ints.decay().offset((3) as isize))); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __v.push(>::cpp_from( + __it.borrow().iter_deref(), + )); + __it.borrow_mut().iter_inc(); } __v }; @@ -235,12 +241,15 @@ fn main_0() -> i32 { Reading { raw_: 5 }, ]))); let mut v8: Vec = { - let mut __tmp_14 = { readings.decay().offset((2) as isize) }; let mut __v = Vec::new(); - let mut __it = readings.decay(); - while __it != __tmp_14 { - __v.push(>::cpp_from(__it.iter_deref())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(readings.decay())); + let __last: Value> = + Rc::new(RefCell::new(readings.decay().offset((2) as isize))); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __v.push(>::cpp_from( + __it.borrow().iter_deref(), + )); + __it.borrow_mut().iter_inc(); } __v }; diff --git a/tests/unit/out/refcount/vector_with_allocator.rs b/tests/unit/out/refcount/vector_with_allocator.rs index 140a20b210..37193da02a 100644 --- a/tests/unit/out/refcount/vector_with_allocator.rs +++ b/tests/unit/out/refcount/vector_with_allocator.rs @@ -398,36 +398,36 @@ fn main_0() -> i32 { ({ fn_1(v7.as_pointer(), copy_constructed(v8.as_pointer())) }); let src: Value> = Rc::new(RefCell::new(Box::new([1_u32, 2_u32, 3_u32]))); let mut v9: Vec = { - let mut __tmp_22 = { src.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = src.decay(); - while __it != __tmp_22 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src.decay())); + let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v }; assert!((v9.len() == 3_usize)); assert!(((v9[0_usize] == 1_u32) && (v9[1_usize] == 2_u32)) && (v9[2_usize] == 3_u32)); let mut v10: Vec = { - let mut __tmp_23 = { src.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = src.decay(); - while __it != __tmp_23 { - __v.push(((__it.iter_deref().read()) as u64)); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src.decay())); + let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __v.push(((__it.borrow().iter_deref().read()) as u64)); + __it.borrow_mut().iter_inc(); } __v }; assert!((v10.len() == 3_usize)); assert!(((v10[0_usize] == 1_u64) && (v10[1_usize] == 2_u64)) && (v10[2_usize] == 3_u64)); let mut v11: Vec = { - let mut __tmp_24 = { src.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = src.decay(); - while __it != __tmp_24 { - __v.push(((__it.iter_deref().read()) as i32)); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src.decay())); + let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __v.push(((__it.borrow().iter_deref().read()) as i32)); + __it.borrow_mut().iter_inc(); } __v }; @@ -435,12 +435,12 @@ fn main_0() -> i32 { assert!(((v11[0_usize] == 1) && (v11[1_usize] == 2)) && (v11[2_usize] == 3)); let src1: Value> = Rc::new(RefCell::new(Box::new([1_u32, 2_u32, 3_u32]))); let mut v12: Vec = { - let mut __tmp_25 = { src1.decay().to_end() }; let mut __v = Vec::new(); - let mut __it = src1.decay(); - while __it != __tmp_25 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src1.decay())); + let __last: Value> = Rc::new(RefCell::new(src1.decay().to_end())); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v }; @@ -451,12 +451,12 @@ fn main_0() -> i32 { let mut start: Ptr = buf.decay(); let mut len: usize = 5_usize; let mut v13: Vec = { - let mut __tmp_26 = { start.offset((len) as isize) }; let mut __v = Vec::new(); - let mut __it = (start).clone(); - while __it != __tmp_26 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new((start).clone())); + let __last: Value> = Rc::new(RefCell::new(start.offset((len) as isize))); + while !>::equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v }; diff --git a/tests/unit/out/unsafe/container_element_receiver.rs b/tests/unit/out/unsafe/container_element_receiver.rs index 3903828475..d038f9a5eb 100644 --- a/tests/unit/out/unsafe/container_element_receiver.rs +++ b/tests/unit/out/unsafe/container_element_receiver.rs @@ -32,7 +32,7 @@ pub unsafe fn sum_1(v: *const Vec) -> i32 { let mut total: i32 = 0; { let mut it: UnsafeRandomAccessIterator = (*v).begin(); - 'loop_: while it != (*v).end() { + 'loop_: while !WeaklyEqualityComparableWithUnsafe::equal(&it, &(*v).end()) { 'for_body: { total += (*it.iter_deref()); } diff --git a/tests/unit/out/unsafe/copy_ctor.rs b/tests/unit/out/unsafe/copy_ctor.rs index 0c83840e9f..446e50d648 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -384,7 +384,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { vec_.end() }; let mut __v = Vec::new(); let mut __it = (__tmp_0).clone(); - while __it != __tmp_1 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_1) { __v.push(>::cpp_from( __it.iter_deref(), )); diff --git a/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs b/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs index 8c8a829046..9d0fca0560 100644 --- a/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs +++ b/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs @@ -26,13 +26,14 @@ unsafe fn main_0() -> i32 { let mut __tmp_2 = { v.begin() }; let mut __tmp_3 = { v.end() }; let mut __it = (__tmp_2).clone(); - while __it != __tmp_3 && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &7) + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_3) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &7) { __it.iter_inc(); } __it }; - assert!(it != v.end()); + assert!(!WeaklyEqualityComparableWithUnsafe::equal(&it, &v.end())); assert!(((*it.iter_deref()) == (7))); { let mut __tmp_4 = { v.begin() }; diff --git a/tests/unit/out/unsafe/emplace_receiver_alias.rs b/tests/unit/out/unsafe/emplace_receiver_alias.rs index 7151a6602f..f1b13bbd4a 100644 --- a/tests/unit/out/unsafe/emplace_receiver_alias.rs +++ b/tests/unit/out/unsafe/emplace_receiver_alias.rs @@ -32,7 +32,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { (&mut (*alias))[(0_usize)].as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = __tmp_0; - while __it != __tmp_1 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_1) { __v.push((*__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 10824fecc1..b576a60cf0 100644 --- a/tests/unit/out/unsafe/emplace_receiver_order.rs +++ b/tests/unit/out/unsafe/emplace_receiver_order.rs @@ -40,7 +40,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { rows[(0_usize)].as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = __tmp_0; - while __it != __tmp_1 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_1) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -63,7 +63,7 @@ unsafe fn main_0() -> i32 { { rows[(0_usize)].as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = __tmp_3; - while __it != __tmp_4 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_4) { __v.push((*__it.iter_deref())); __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/find.rs b/tests/unit/out/unsafe/find.rs index fe2946da88..57d639a2b8 100644 --- a/tests/unit/out/unsafe/find.rs +++ b/tests/unit/out/unsafe/find.rs @@ -58,13 +58,14 @@ unsafe fn main_0() -> i32 { let mut it: UnsafeRandomAccessIterator = { let mut __tmp_3 = { (v_end).clone() }; let mut __it = (v_begin).clone(); - while __it != __tmp_3 && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &2) + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_3) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &2) { __it.iter_inc(); } __it }; - let mut v_result_true: bool = it != v.end(); + let mut v_result_true: bool = !WeaklyEqualityComparableWithUnsafe::equal(&it, &v.end()); let mut m: UnsafeMap = UnsafeMap::new(); { let mut __tmp_4: i32; @@ -89,75 +90,82 @@ unsafe fn main_0() -> i32 { }; let mut m_begin: UnsafeBidirectionalIterator<(i32, f64)> = m.begin(); let mut m_end: UnsafeBidirectionalIterator<(i32, f64)> = m.end(); - let mut m_result_true: bool = m_begin != m_end; + let mut m_result_true: bool = !WeaklyEqualityComparableWithUnsafe::equal(&m_begin, &m_end); assert!( ((v_result_true) && (m_result_true)) - && ({ - let mut __tmp_7 = { v.begin() }; - let mut __tmp_8 = { v.begin() }; - let mut __it = (__tmp_7).clone(); - while __it != __tmp_8 - && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &2) - { - __it.iter_inc(); - } - __it - } == v.begin()) + && (WeaklyEqualityComparableWithUnsafe::equal( + &{ + let mut __tmp_7 = { v.begin() }; + let mut __tmp_8 = { v.begin() }; + let mut __it = (__tmp_7).clone(); + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_8) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &2) + { + __it.iter_inc(); + } + __it + }, + &v.begin() + )) ); let mut w: Vec = Vec::from([1, 2, 3, 4, 5]); - assert!( - { + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ let mut __tmp_9 = { w.begin().iter_add(2_isize) }; let mut __tmp_10 = { w.end() }; let mut __it = (__tmp_9).clone(); - while __it != __tmp_10 + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_10) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &4) { __it.iter_inc(); } __it - } == w.begin().iter_add(3_isize) - ); - assert!( - { + }, + &w.begin().iter_add(3_isize) + )); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ let mut __tmp_11 = { w.begin().iter_add(2_isize) }; let mut __tmp_12 = { w.end() }; let mut __it = (__tmp_11).clone(); - while __it != __tmp_12 + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_12) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &1) { __it.iter_inc(); } __it - } == w.end() - ); - assert!( - { + }, + &w.end() + )); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ let mut __tmp_13 = { w.begin().iter_add(2_isize) }; let mut __tmp_14 = { w.begin().iter_add(4_isize) }; let mut __it = (__tmp_13).clone(); - while __it != __tmp_14 + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_14) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &5) { __it.iter_inc(); } __it - } == w.begin().iter_add(4_isize) - ); + }, + &w.begin().iter_add(4_isize) + )); let mut p: Vec

= Vec::from([P { x: 0 }, P { x: 1 }, P { x: 2 }]); - assert!( - { + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ let mut __tmp_15 = { p.begin() }; let mut __tmp_16 = { p.end() }; let mut __it = (__tmp_15).clone(); - while __it != __tmp_16 + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_16) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &(P { x: 1 })) { __it.iter_inc(); } __it - } == p.begin().iter_add(1_isize) - ); + }, + &p.begin().iter_add(1_isize) + )); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/map.rs b/tests/unit/out/unsafe/map.rs index b1c75afbca..42942bf71a 100644 --- a/tests/unit/out/unsafe/map.rs +++ b/tests/unit/out/unsafe/map.rs @@ -216,26 +216,31 @@ unsafe fn main_0() -> i32 { let mut it: UnsafeBidirectionalIterator<(i16, u32)> = m.find(&1_i16); let mut const_it: UnsafeBidirectionalIterator<(i16, u32)> = >::from(m.find(&10_i16)); - let mut x1: u32 = if it == end { + let mut x1: u32 = if WeaklyEqualityComparableWithUnsafe::equal(&it, &end) { 0_u32 } else { (*it.iter_deref()).1 }; assert!(((x1) == (4_u32))); - let mut x2: u32 = if const_it == >::from((end).clone()) - { + let mut x2: u32 = if WeaklyEqualityComparableWithUnsafe::equal( + &const_it, + &>::from((end).clone()), + ) { 0_u32 } else { (*const_it.iter_deref()).1 }; assert!(((x2) == (0_u32))); - let mut x3: u32 = if it == m.end() { + let mut x3: u32 = if WeaklyEqualityComparableWithUnsafe::equal(&it, &m.end()) { 0_u32 } else { (*it.iter_deref()).1 }; assert!(((x3) == (4_u32))); - let mut x4: u32 = if const_it == >::from(m.end()) { + let mut x4: u32 = if WeaklyEqualityComparableWithUnsafe::equal( + &const_it, + &>::from(m.end()), + ) { 0_u32 } else { (*const_it.iter_deref()).1 @@ -281,10 +286,16 @@ unsafe fn main_0() -> i32 { assert!((((*const_it4.iter_deref()).1) == (6_u32))); let r: *mut UnsafeMap = &mut m; assert!((((*r).len()) == (4_usize))); - assert!(m.find(&4_i16) != m.end()); + assert!(!WeaklyEqualityComparableWithUnsafe::equal( + &m.find(&4_i16), + &m.end() + )); (*r).erase(&(it4).clone()); assert!((((*r).len()) == (3_usize))); - assert!(m.find(&4_i16) == m.end()); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &m.find(&4_i16), + &m.end() + )); { let mut __tmp_21: i16; (*{ @@ -314,13 +325,19 @@ unsafe fn main_0() -> i32 { let mut cit: UnsafeBidirectionalIterator<(i16, u32)> = >::from(m.find(&7_i16)); let mut next: UnsafeBidirectionalIterator<(i16, u32)> = m.erase(&(cit).clone()); - assert!(next == m.find(&8_i16)); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &next, + &m.find(&8_i16) + )); { next = m.erase(&(next).clone()); }; - assert!(next == m.end()); + assert!(WeaklyEqualityComparableWithUnsafe::equal(&next, &m.end())); assert!((((*r).len()) == (3_usize))); - assert!(m.find(&8_i16) == m.end()); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &m.find(&8_i16), + &m.end() + )); let mut other_map: UnsafeMap<(i32, i64), ((i32, i64), f64)> = UnsafeMap::new(); assert!(((other_map.len()) == (0_usize))); let mut key0: (i32, i64) = (1, (1 as i64)); diff --git a/tests/unit/out/unsafe/map_key_identity.rs b/tests/unit/out/unsafe/map_key_identity.rs index 87ffed5547..5fed994f67 100644 --- a/tests/unit/out/unsafe/map_key_identity.rs +++ b/tests/unit/out/unsafe/map_key_identity.rs @@ -120,9 +120,15 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & (((distinct.len()) == (2_usize)) as i32)) != 0; ok = ((ok as i32) & (((a) != (b)) as i32)) != 0; ok = ((ok as i32) & (((((*a).value) == (11)) && (((*b).value) == (22))) as i32)) != 0; - ok = ((ok as i32) & ((a_it == distinct.find(&distinct_a)) as i32)) != 0; - ok = ((ok as i32) & ((b_it == distinct.find(&distinct_b)) as i32)) != 0; - ok = ((ok as i32) & ((b_it != distinct.end()) as i32)) != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::equal(&a_it, &distinct.find(&distinct_a))) as i32)) + != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::equal(&b_it, &distinct.find(&distinct_b))) as i32)) + != 0; + ok = ((ok as i32) + & ((!WeaklyEqualityComparableWithUnsafe::equal(&b_it, &distinct.end())) as i32)) + != 0; ok = ((ok as i32) & (((&mut (*a_it.iter_deref()).1 as *mut Mapped) == (a_value)) as i32)) != 0; ok = ((ok as i32) & ((((*a_it.iter_deref()).1.value) == (11)) as i32)) != 0; ok = ((ok as i32) @@ -177,10 +183,22 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & (reused as i32)) != 0; ok = ((ok as i32) & (((equivalent.len()) == (1_usize)) as i32)) != 0; if reused { - ok = ((ok as i32) & ((first_it != equivalent.end()) as i32)) != 0; + ok = ((ok as i32) + & ((!WeaklyEqualityComparableWithUnsafe::equal(&first_it, &equivalent.end())) as i32)) + != 0; ok = ((ok as i32) & (((first) == (second)) as i32)) != 0; - ok = ((ok as i32) & ((first_it == equivalent.find(&equivalent_a)) as i32)) != 0; - ok = ((ok as i32) & ((first_it == equivalent.find(&equivalent_b)) as i32)) != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::equal( + &first_it, + &equivalent.find(&equivalent_a), + )) as i32)) + != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::equal( + &first_it, + &equivalent.find(&equivalent_b), + )) as i32)) + != 0; ok = ((ok as i32) & (((&mut (*first_it.iter_deref()).1 as *mut Mapped) == (first_value)) as i32)) != 0; @@ -216,7 +234,12 @@ unsafe fn main_0() -> i32 { != 0; ok = ((ok as i32) & (((equivalent.len()) == (2_usize)) as i32)) != 0; if reused { - ok = ((ok as i32) & ((first_it == equivalent.find(&equivalent_a)) as i32)) != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::equal( + &first_it, + &equivalent.find(&equivalent_a), + )) as i32)) + != 0; ok = ((ok as i32) & (((&mut (*first_it.iter_deref()).1 as *mut Mapped) == (first_value)) as i32)) != 0; @@ -253,7 +276,10 @@ unsafe fn main_0() -> i32 { != 0; ok = ((ok as i32) & (((matching.len()) == (1_usize)) as i32)) != 0; ok = ((ok as i32) & (((matched) == (matched_again)) as i32)) != 0; - ok = ((ok as i32) & ((matched_it == matching.find(&matching_b)) as i32)) != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::equal(&matched_it, &matching.find(&matching_b))) + as i32)) + != 0; ok = ((ok as i32) & (((&mut (*matched_it.iter_deref()).1 as *mut Mapped) == (matched_value)) as i32)) != 0; @@ -265,7 +291,10 @@ unsafe fn main_0() -> i32 { == ((before_matching) + (2))) as i32)) != 0; ok = ((ok as i32) & (((matching.len()) == (2_usize)) as i32)) != 0; - ok = ((ok as i32) & ((matched_it == matching.find(&matching_a)) as i32)) != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::equal(&matched_it, &matching.find(&matching_a))) + as i32)) + != 0; ok = ((ok as i32) & (((&mut (*matched_it.iter_deref()).1 as *mut Mapped) == (matched_value)) as i32)) != 0; diff --git a/tests/unit/out/unsafe/map_try_emplace.rs b/tests/unit/out/unsafe/map_try_emplace.rs index 50b537fdfa..a752caad76 100644 --- a/tests/unit/out/unsafe/map_try_emplace.rs +++ b/tests/unit/out/unsafe/map_try_emplace.rs @@ -209,7 +209,11 @@ unsafe fn main_0() -> i32 { & ((((result.1) as i32) == (!(hit) as i32)) as i32)) != 0; - let mut found: bool = result.0 == m.find(&key); + let mut found: bool = + WeaklyEqualityComparableWithUnsafe::equal( + &result.0, + &m.find(&key), + ); ok = ((ok as i32) & (found as i32)) != 0; ok = ((ok as i32) & ((((*result.0.iter_deref()).0) == (key)) diff --git a/tests/unit/out/unsafe/max.rs b/tests/unit/out/unsafe/max.rs index 5576cdc089..9459428278 100644 --- a/tests/unit/out/unsafe/max.rs +++ b/tests/unit/out/unsafe/max.rs @@ -126,10 +126,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_2 = { values.as_mut_ptr() }; let mut __tmp_3 = { values.as_mut_ptr().offset((4) as isize) }; let mut __best = __tmp_2.clone(); - if __tmp_2 != __tmp_3 { + if !WeaklyEqualityComparableWithUnsafe::equal(&__tmp_2, &__tmp_3) { let mut __it = __tmp_2; __it.iter_inc(); - while __it != __tmp_3 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_3) { if *__best.iter_deref() < *__it.iter_deref() { __best = __it.clone(); } diff --git a/tests/unit/out/unsafe/operator_comparison_nonbool.rs b/tests/unit/out/unsafe/operator_comparison_nonbool.rs index 0af4c100c8..8dff6cb9c0 100644 --- a/tests/unit/out/unsafe/operator_comparison_nonbool.rs +++ b/tests/unit/out/unsafe/operator_comparison_nonbool.rs @@ -502,7 +502,7 @@ unsafe fn main_0() -> i32 { (({ let mut __tmp_3 = { ris.as_mut_ptr().offset((2) as isize) }; let mut __it = ris.as_mut_ptr(); - while __it != __tmp_3 + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_3) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &ri2) { __it.iter_inc(); diff --git a/tests/unit/out/unsafe/operator_traits.rs b/tests/unit/out/unsafe/operator_traits.rs index a7f1237627..99ebd6999e 100644 --- a/tests/unit/out/unsafe/operator_traits.rs +++ b/tests/unit/out/unsafe/operator_traits.rs @@ -217,7 +217,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { eqs.begin() }; let mut __tmp_2 = { eqs.end() }; let mut __it = (__tmp_1).clone(); - while __it != __tmp_2 + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_2) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &two) { __it.iter_inc(); @@ -227,19 +227,20 @@ unsafe fn main_0() -> i32 { .iter_deref()) .v) == (2)) ); - assert!( - { + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ let mut __tmp_3 = { eqs.begin() }; let mut __tmp_4 = { eqs.end() }; let mut __it = (__tmp_3).clone(); - while __it != __tmp_4 + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_4) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &nine) { __it.iter_inc(); } __it - } == eqs.end() - ); + }, + &eqs.end() + )); let mut cmps: Vec = Vec::from([Cmp { v: 3 }, Cmp { v: 1 }, Cmp { v: 2 }]); { let mut __tmp_5 = { cmps.begin() }; @@ -261,7 +262,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_6 = { cmps.begin() }; let mut __tmp_7 = { cmps.end() }; let mut __it = (__tmp_6).clone(); - while __it != __tmp_7 + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_7) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &three) { __it.iter_inc(); @@ -292,7 +293,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_9 = { frees.begin() }; let mut __tmp_10 = { frees.end() }; let mut __it = (__tmp_9).clone(); - while __it != __tmp_10 + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_10) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &ftwo) { __it.iter_inc(); diff --git a/tests/unit/out/unsafe/push_emplace_back.rs b/tests/unit/out/unsafe/push_emplace_back.rs index a95c33594e..9e841e8464 100644 --- a/tests/unit/out/unsafe/push_emplace_back.rs +++ b/tests/unit/out/unsafe/push_emplace_back.rs @@ -75,7 +75,7 @@ pub unsafe fn push_local_from_field_1(mut jpg: *mut JPEGData, mut cond: bool) { let mut __tmp_2 = { head.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = head.as_mut_ptr(); - while __it != __tmp_2 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_2) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -103,7 +103,7 @@ pub unsafe fn emplace_local_from_field_4(mut jpg: *mut JPEGData, mut cond: bool) let mut __tmp_3 = { head.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = head.as_mut_ptr(); - while __it != __tmp_3 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_3) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -251,7 +251,7 @@ pub unsafe fn emplace_from_element_14(mut v: *mut Vec>) { let mut __tmp_4 = { p.offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = p; - while __it != __tmp_4 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_4) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -318,7 +318,7 @@ pub unsafe fn emplace_from_sibling_18(mut s: *mut Bytes) { let mut __tmp_5 = { p.offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = p; - while __it != __tmp_5 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_5) { __v.push((*__it.iter_deref())); __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/redundant_copy_in_conversion.rs b/tests/unit/out/unsafe/redundant_copy_in_conversion.rs index 7b912f27aa..3e97994247 100644 --- a/tests/unit/out/unsafe/redundant_copy_in_conversion.rs +++ b/tests/unit/out/unsafe/redundant_copy_in_conversion.rs @@ -9,7 +9,10 @@ use std::rc::Rc; pub unsafe fn sink_0(mut it: UnsafeBidirectionalIterator<(i32, i32)>) -> i32 { let mut cit: UnsafeBidirectionalIterator<(i32, i32)> = >::from((it).clone()); - return if cit == >::from((it).clone()) { + return if WeaklyEqualityComparableWithUnsafe::equal( + &cit, + &>::from((it).clone()), + ) { (*it.iter_deref()).1 } else { 0 @@ -34,20 +37,30 @@ unsafe fn main_0() -> i32 { let mut it0: UnsafeBidirectionalIterator<(i32, i32)> = m.find(&0); let mut const_it: UnsafeBidirectionalIterator<(i32, i32)> = >::from((it0).clone()); - let mut r: i32 = if const_it == >::from((end).clone()) { + let mut r: i32 = if WeaklyEqualityComparableWithUnsafe::equal( + &const_it, + &>::from((end).clone()), + ) { 0 } else { 1 }; r += (unsafe { sink_0((it0).clone()) }); - r += if end == end { 0 } else { 1 }; + r += if WeaklyEqualityComparableWithUnsafe::equal(&end, &end) { + 0 + } else { + 1 + }; assert!(((r) == (2))); let mut values: Vec = Vec::from([7_u32, 8_u32, 9_u32]); let mut middle: UnsafeRandomAccessIterator = values.begin().iter_add(1_isize); let mut const_middle: UnsafeRandomAccessIterator = >::from((middle).clone()); assert!(((*const_middle.iter_deref()) == (8_u32))); - assert!(const_middle == middle); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &const_middle, + &middle + )); return 0; } pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/size_t_ssize_t.rs b/tests/unit/out/unsafe/size_t_ssize_t.rs index 28b7541040..4ba04c4d0f 100644 --- a/tests/unit/out/unsafe/size_t_ssize_t.rs +++ b/tests/unit/out/unsafe/size_t_ssize_t.rs @@ -36,7 +36,7 @@ pub unsafe fn size_t_in_rules_3() { let mut __tmp_0 = { src.as_mut_ptr().offset((3) as isize) }; let mut __first = src.as_mut_ptr(); let mut __out = (dst.as_mut_ptr() as *mut usize).cast::(); - while __first != __tmp_0 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__first, &__tmp_0) { *__out.iter_deref() = ((*__first.iter_deref()) as u64); __first.iter_inc(); __out.iter_inc(); @@ -75,7 +75,10 @@ pub unsafe fn size_t_in_rules_3() { |__k| cpp_move_unsafe!(__k), || 0_u64, )) = 4_u64; - assert!(m.find(&1_u64) != m.end()); + assert!(!WeaklyEqualityComparableWithUnsafe::equal( + &m.find(&1_u64), + &m.end() + )); assert!((((*m.begin().iter_deref()).0) == (1_u64))); let mut m2: UnsafeMap = std::mem::take(&mut m); assert!(((m2.len()) == (2_usize))); @@ -138,7 +141,7 @@ pub unsafe fn size_t_in_rules_3() { let mut __tmp_5 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while __it != __tmp_5 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_5) { __v.push(((*__it.iter_deref()) as u64)); __it.iter_inc(); } @@ -155,7 +158,7 @@ pub unsafe fn size_t_in_rules_3() { let mut __tmp_7 = { v.begin() }; let mut __tmp_8 = { v.end() }; let mut __it = (__tmp_7).clone(); - while __it != __tmp_8 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_8) { *__it.iter_deref() = Clone::clone(&(k as u64)); __it.iter_inc(); } @@ -217,19 +220,20 @@ pub unsafe fn size_t_in_rules_3() { v3.push(__a2) } }; - assert!( - { + assert!(!WeaklyEqualityComparableWithUnsafe::equal( + &{ let mut __tmp_12 = { v3.begin() }; let mut __tmp_13 = { v3.end() }; let mut __it = (__tmp_12).clone(); - while __it != __tmp_13 + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_13) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &(k as u64)) { __it.iter_inc(); } __it - } != v3.end() - ); + }, + &v3.end() + )); assert!((((v3.len()) == (5_usize)) && ((big) >= (k))) && (((pk.1) as usize) == (k))); let mut ci: UnsafeRandomAccessIterator = >::from(v.begin()); diff --git a/tests/unit/out/unsafe/sort_no_copy.rs b/tests/unit/out/unsafe/sort_no_copy.rs index 3e9dfc67a3..9e6e593b76 100644 --- a/tests/unit/out/unsafe/sort_no_copy.rs +++ b/tests/unit/out/unsafe/sort_no_copy.rs @@ -469,12 +469,12 @@ unsafe fn main_0() -> i32 { && ((bag_vec[(2_usize)].items[(1_usize)].v) == (5)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); - assert!( - { + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ let mut __tmp_7 = { bag_vec.begin() }; let mut __tmp_8 = { bag_vec.end() }; let mut __it = (__tmp_7).clone(); - while __it != __tmp_8 + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_8) && !WeaklyEqualityComparableWithUnsafe::equal( &*__it.iter_deref(), &bags[(1) as usize], @@ -483,17 +483,18 @@ unsafe fn main_0() -> i32 { __it.iter_inc(); } __it - } == bag_vec.begin().iter_add(1_isize) - ); - assert!( - { + }, + &bag_vec.begin().iter_add(1_isize) + )); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ let mut __tmp_9 = { bag_vec.begin() }; let mut __tmp_10 = { bag_vec.end() }; let mut __best = __tmp_9.clone(); - if __tmp_9 != __tmp_10 { + if !WeaklyEqualityComparableWithUnsafe::equal(&__tmp_9, &__tmp_10) { let mut __it = (__tmp_9).clone(); __it.iter_inc(); - while __it != __tmp_10 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_10) { if *__best.iter_deref() < *__it.iter_deref() { __best = __it.clone(); } @@ -501,8 +502,9 @@ unsafe fn main_0() -> i32 { } } __best - } == bag_vec.begin().iter_add(2_isize) - ); + }, + &bag_vec.begin().iter_add(2_isize) + )); assert!( (({ let __a: *const _ = &mut bags[(0) as usize]; @@ -530,7 +532,10 @@ unsafe fn main_0() -> i32 { || 0_i32, )) = 0; assert!((((*bag_map.find(&bags[(2) as usize]).iter_deref()).1) == (2))); - assert!(bag_map.find(&bags[(1) as usize]) == bag_map.end()); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &bag_map.find(&bags[(1) as usize]), + &bag_map.end() + )); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); let mut moves: Vec = Vec::new(); moves.push_mut({ diff --git a/tests/unit/out/unsafe/stdcopy.rs b/tests/unit/out/unsafe/stdcopy.rs index dc8489328d..64af57fda8 100644 --- a/tests/unit/out/unsafe/stdcopy.rs +++ b/tests/unit/out/unsafe/stdcopy.rs @@ -40,7 +40,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_0 = { input.as_mut_ptr().offset((3) as isize) }; let mut __first = input.as_mut_ptr(); let mut __out = output.as_mut_ptr(); - while __first != __tmp_0 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__first, &__tmp_0) { *__out.iter_deref() = (*__first.iter_deref()); __first.iter_inc(); __out.iter_inc(); @@ -52,7 +52,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { input.as_mut_ptr().offset((3) as isize) }; let mut __first = input.as_mut_ptr(); let mut __out = widened.begin(); - while __first != __tmp_1 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__first, &__tmp_1) { *__out.iter_deref() = ((*__first.iter_deref()) as i64); __first.iter_inc(); __out.iter_inc(); @@ -74,7 +74,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_4 = { input.as_mut_ptr().offset((3) as isize) }; let mut __first = input.as_mut_ptr(); let mut __out = constructed.begin(); - while __first != __tmp_4 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__first, &__tmp_4) { *__out.iter_deref() = >::cpp_from(__first.iter_deref()); __first.iter_inc(); __out.iter_inc(); @@ -88,7 +88,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_5 = { wide.as_mut_ptr().offset((2) as isize) }; let mut __first = wide.as_mut_ptr(); let mut __out = floating.begin(); - while __first != __tmp_5 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__first, &__tmp_5) { *__out.iter_deref() = ((*__first.iter_deref()) as f64); __first.iter_inc(); __out.iter_inc(); diff --git a/tests/unit/out/unsafe/stdcopy_ostream.rs b/tests/unit/out/unsafe/stdcopy_ostream.rs index 019a2d0a6c..87b8f8f23b 100644 --- a/tests/unit/out/unsafe/stdcopy_ostream.rs +++ b/tests/unit/out/unsafe/stdcopy_ostream.rs @@ -37,7 +37,7 @@ unsafe fn main_0() -> i32 { let mut __it = (__tmp_0).clone(); let __out = &mut ofs; let mut __bytes: Vec = Vec::new(); - while __it != __tmp_1 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_1) { __bytes.push(*__it.iter_deref() as u8); __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/unboxed_conditional_iterator.rs b/tests/unit/out/unsafe/unboxed_conditional_iterator.rs index 4743c5d503..dc34cb89d6 100644 --- a/tests/unit/out/unsafe/unboxed_conditional_iterator.rs +++ b/tests/unit/out/unsafe/unboxed_conditional_iterator.rs @@ -55,7 +55,7 @@ pub unsafe fn lehmer_3(mut sigma: *const u32, mut len: u32, mut code: *mut u32) let mut __tmp_0 = { items.begin() }; let mut __tmp_1 = { items.end() }; let mut __it = (__tmp_0).clone(); - while __it != __tmp_1 + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_1) && !WeaklyEqualityComparableWithUnsafe::equal( &*__it.iter_deref(), &(*sigma.offset((i) as isize)), @@ -65,7 +65,10 @@ pub unsafe fn lehmer_3(mut sigma: *const u32, mut len: u32, mut code: *mut u32) } __it }; - assert!(it != items.end()); + assert!(!WeaklyEqualityComparableWithUnsafe::equal( + &it, + &items.end() + )); (*code.offset((i) as isize)) = ((it.iter_distance(&items.begin())) as u32); { let mut __tmp_2 = { >::from((it).clone()) }; @@ -84,7 +87,7 @@ pub unsafe fn sum_4(v: *mut Vec) -> i32 { let mut s: i32 = 0; { let mut it: UnsafeRandomAccessIterator = (*v).begin(); - 'loop_: while it != (*v).end() { + 'loop_: while !WeaklyEqualityComparableWithUnsafe::equal(&it, &(*v).end()) { 'for_body: { s += (*it.iter_deref()); } diff --git a/tests/unit/out/unsafe/vector.rs b/tests/unit/out/unsafe/vector.rs index 1e1283e461..cebc891578 100644 --- a/tests/unit/out/unsafe/vector.rs +++ b/tests/unit/out/unsafe/vector.rs @@ -185,7 +185,7 @@ unsafe fn main_0() -> i32 { __tmp_7.iter_distance(&UnsafeRandomAccessIterator::Vec(v2.as_mut_ptr())) as usize; let mut __tmp = Vec::new(); let mut __it = (__tmp_8).clone(); - while __it != __tmp_9 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_9) { __tmp.push((*__it.iter_deref())); __it.iter_inc(); } @@ -509,7 +509,7 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp = Vec::new(); let mut __it = ints.as_mut_ptr(); - while __it != __tmp_20 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_20) { __tmp.push(((*__it.iter_deref()) as i64)); __it.iter_inc(); } @@ -530,7 +530,7 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp = Vec::new(); let mut __it = (__tmp_22).clone(); - while __it != __tmp_23 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_23) { __tmp.push(((*__it.iter_deref()) as i64)); __it.iter_inc(); } @@ -547,7 +547,7 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp = Vec::new(); let mut __it = ints.as_mut_ptr(); - while __it != __tmp_25 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_25) { __tmp.push(((*__it.iter_deref()) as f64)); __it.iter_inc(); } @@ -564,7 +564,7 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp = Vec::new(); let mut __it = ints.as_mut_ptr(); - while __it != __tmp_27 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_27) { __tmp.push(>::cpp_from(__it.iter_deref())); __it.iter_inc(); } @@ -581,7 +581,7 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp = Vec::new(); let mut __it = (__tmp_29).clone(); - while __it != __tmp_30 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_30) { __tmp.push((*__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 02864261d4..bbb1bcf0c3 100644 --- a/tests/unit/out/unsafe/vector_iter_range_ctor.rs +++ b/tests/unit/out/unsafe/vector_iter_range_ctor.rs @@ -60,7 +60,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_0 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while __it != __tmp_0 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_0) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -75,7 +75,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while __it != __tmp_1 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_1) { __v.push(((*__it.iter_deref()) as u64)); __it.iter_inc(); } @@ -90,7 +90,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_2 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while __it != __tmp_2 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_2) { __v.push(((*__it.iter_deref()) as i32)); __it.iter_inc(); } @@ -103,7 +103,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_3 = { src1.as_ptr().add(src1.len()) }; let mut __v = Vec::new(); let mut __it = src1.as_ptr(); - while __it != __tmp_3 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_3) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -127,7 +127,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_5 = { start.offset((len) as isize) }; let mut __v = Vec::new(); let mut __it = start; - while __it != __tmp_5 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_5) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -162,7 +162,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_10 = { m.end() }; let mut __v = Vec::new(); let mut __it = (__tmp_9).clone(); - while __it != __tmp_10 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_10) { __v.push(<(i32, i32) as CppFromUnsafe<(i32, i32)>>::cpp_from( __it.iter_deref(), )); @@ -182,7 +182,7 @@ unsafe fn main_0() -> i32 { __tmp_11.iter_distance(&UnsafeRandomAccessIterator::Vec(v6.as_mut_ptr())) as usize; let mut __tmp = Vec::new(); let mut __it = (__tmp_12).clone(); - while __it != __tmp_13 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_13) { __tmp.push(<(i32, i32) as CppFromUnsafe<(i32, i32)>>::cpp_from( __it.iter_deref(), )); @@ -200,7 +200,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_14 = { ints.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = ints.as_mut_ptr(); - while __it != __tmp_14 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_14) { __v.push(>::cpp_from(__it.iter_deref())); __it.iter_inc(); } @@ -212,7 +212,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_15 = { readings.as_mut_ptr().offset((2) as isize) }; let mut __v = Vec::new(); let mut __it = readings.as_mut_ptr(); - while __it != __tmp_15 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_15) { __v.push(>::cpp_from(__it.iter_deref())); __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/vector_with_allocator.rs b/tests/unit/out/unsafe/vector_with_allocator.rs index 34293aab10..f008a1014a 100644 --- a/tests/unit/out/unsafe/vector_with_allocator.rs +++ b/tests/unit/out/unsafe/vector_with_allocator.rs @@ -317,7 +317,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_16 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while __it != __tmp_16 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_16) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -332,7 +332,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_17 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while __it != __tmp_17 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_17) { __v.push(((*__it.iter_deref()) as u64)); __it.iter_inc(); } @@ -347,7 +347,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_18 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while __it != __tmp_18 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_18) { __v.push(((*__it.iter_deref()) as i32)); __it.iter_inc(); } @@ -360,7 +360,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_19 = { src1.as_ptr().add(src1.len()) }; let mut __v = Vec::new(); let mut __it = src1.as_ptr(); - while __it != __tmp_19 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_19) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -378,7 +378,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_20 = { start.offset((len) as isize) }; let mut __v = Vec::new(); let mut __it = start; - while __it != __tmp_20 { + while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_20) { __v.push((*__it.iter_deref())); __it.iter_inc(); } From fd5ea208d47b3cbad41690b960dcbe51551a2a00 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 13:27:27 +0000 Subject: [PATCH 12/18] Synthesize not_equal --- cpp2rust/converter/converter.cpp | 117 +++++++++++++----- cpp2rust/converter/converter.h | 14 ++- cpp2rust/converter/converter_lib.cpp | 25 +++- cpp2rust/converter/converter_lib.h | 6 + cpp2rust/cpp2rust_lib.cpp | 4 +- libcc2rs/src/cmp.rs | 21 +++- rules/algorithm/tgt_refcount.rs | 14 +-- rules/algorithm/tgt_unsafe.rs | 14 +-- rules/iterator_category/tgt_refcount.rs | 4 +- rules/iterator_category/tgt_unsafe.rs | 4 +- rules/vector/tgt_refcount.rs | 4 +- rules/vector/tgt_unsafe.rs | 4 +- .../out/refcount/friend_operator.rs | 38 +++--- .../out/unsafe/friend_operator.rs | 42 +++---- tests/std/basic/out/refcount/basic.def.odr.rs | 14 +-- tests/std/basic/out/unsafe/basic.def.odr.rs | 14 +-- tests/unit/out/refcount/class.rs | 16 +-- .../refcount/container_element_receiver.rs | 4 +- tests/unit/out/refcount/copy_ctor.rs | 2 +- .../refcount/elidable_iterator_copy_cxx11.rs | 4 +- .../out/refcount/emplace_receiver_alias.rs | 2 +- .../out/refcount/emplace_receiver_order.rs | 6 +- tests/unit/out/refcount/find.rs | 37 +++--- tests/unit/out/refcount/friend.rs | 10 +- tests/unit/out/refcount/map.rs | 2 +- tests/unit/out/refcount/map_key_identity.rs | 14 +-- tests/unit/out/refcount/max.rs | 4 +- .../refcount/operator_comparison_defaulted.rs | 84 ++++++------- .../out/refcount/operator_comparison_free.rs | 59 ++++----- .../refcount/operator_comparison_member.rs | 18 +-- .../refcount/operator_comparison_nonbool.rs | 73 +++++------ .../operator_comparison_noncopyable.rs | 10 +- tests/unit/out/refcount/operator_friend.rs | 82 ++++++------ tests/unit/out/refcount/operator_three_way.rs | 10 +- tests/unit/out/refcount/operator_traits.rs | 38 +++--- tests/unit/out/refcount/push_emplace_back.rs | 8 +- tests/unit/out/refcount/size_t_ssize_t.rs | 12 +- tests/unit/out/refcount/sort_no_copy.rs | 17 +-- tests/unit/out/refcount/stdcopy.rs | 8 +- tests/unit/out/refcount/stdcopy_ostream.rs | 2 +- .../refcount/unboxed_conditional_iterator.rs | 11 +- tests/unit/out/refcount/vector.rs | 12 +- .../out/refcount/vector_iter_range_ctor.rs | 18 +-- .../out/refcount/vector_with_allocator.rs | 10 +- tests/unit/out/unsafe/class.rs | 12 +- .../out/unsafe/container_element_receiver.rs | 2 +- tests/unit/out/unsafe/copy_ctor.rs | 2 +- .../unsafe/elidable_iterator_copy_cxx11.rs | 4 +- .../unit/out/unsafe/emplace_receiver_alias.rs | 2 +- .../unit/out/unsafe/emplace_receiver_order.rs | 5 +- tests/unit/out/unsafe/find.rs | 26 ++-- tests/unit/out/unsafe/friend.rs | 10 +- tests/unit/out/unsafe/map.rs | 2 +- tests/unit/out/unsafe/map_key_identity.rs | 15 +-- tests/unit/out/unsafe/max.rs | 4 +- .../unsafe/operator_comparison_defaulted.rs | 84 ++++++------- .../out/unsafe/operator_comparison_free.rs | 59 ++++----- .../out/unsafe/operator_comparison_member.rs | 18 +-- .../out/unsafe/operator_comparison_nonbool.rs | 77 ++++++------ .../unsafe/operator_comparison_noncopyable.rs | 10 +- tests/unit/out/unsafe/operator_friend.rs | 88 ++++++------- tests/unit/out/unsafe/operator_three_way.rs | 10 +- tests/unit/out/unsafe/operator_traits.rs | 38 +++--- tests/unit/out/unsafe/push_emplace_back.rs | 8 +- tests/unit/out/unsafe/size_t_ssize_t.rs | 12 +- tests/unit/out/unsafe/sort_no_copy.rs | 16 +-- tests/unit/out/unsafe/stdcopy.rs | 8 +- tests/unit/out/unsafe/stdcopy_ostream.rs | 2 +- .../unsafe/unboxed_conditional_iterator.rs | 6 +- tests/unit/out/unsafe/vector.rs | 12 +- .../unit/out/unsafe/vector_iter_range_ctor.rs | 18 +-- .../unit/out/unsafe/vector_with_allocator.rs | 10 +- 72 files changed, 796 insertions(+), 676 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index a9e7c973e4..bc0774d07a 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -33,7 +33,7 @@ std::unordered_set Converter::decl_ids_; std::unordered_set Converter::globals_; std::vector Converter::global_inits_; Converter::RecordIndex Converter::record_decls_; -std::map Converter::virtual_methods_; +std::map Converter::deferred_impls_; std::map> Converter::declared_record_traits_; std::set> @@ -60,12 +60,38 @@ void Converter::EmitDeferredBlock(const DeferredBlock &block, out += "}\n"; } -void Converter::EmitVirtualMethods(std::string &out) { - for (const auto &[name, impl] : virtual_methods_) { +void Converter::EmitDeferredImpls(std::string &out) { + for (const auto &[header, impl] : deferred_impls_) { EmitDeferredBlock(impl, out); } } +Converter::DeferredBlock &Converter::DeferredImpl(std::string header) { + auto [it, inserted] = deferred_impls_.try_emplace(header); + if (inserted) { + it->second.header = std::move(header); + } + return it->second; +} + +void Converter::AddEqualityComparableMethod(const clang::CXXRecordDecl *record, + const RecordTrait &trait, + std::string_view method) { + auto name = GetRecordName(record); + if (&trait == &kWeaklyEqualityComparableWith) { + converted_record_traits_.emplace(name, trait.refcount.name); + } + EqualityComparableImplFor(record).body += method; +} + +Converter::DeferredBlock & +Converter::EqualityComparableImplFor(const clang::CXXRecordDecl *record) { + return DeferredImpl( + std::format("impl {} for {}", + GetRecordTraitSpelling(kWeaklyEqualityComparableWith).name, + GetRecordName(record))); +} + void Converter::EmitUndefinedRecordTraits(Model model, std::string &out) { bool is_unsafe = model == Model::kUnsafe; for (const auto &[record, traits] : declared_record_traits_) { @@ -74,6 +100,13 @@ void Converter::EmitUndefinedRecordTraits(Model model, std::string &out) { continue; } const auto &spelling = is_unsafe ? trait->unsafe : trait->refcount; + if (trait == &kWeaklyEqualityComparableWith) { + DeferredImpl(std::format("impl {} for {}", spelling.name, record)) + .body += + std::format("{} {{ unreachable!(\"{}::{} is never defined\") }}\n", + spelling.signature, record, trait->method); + continue; + } out += std::format( "impl {} for {} {{ {} {{ unreachable!(\"{}::{} is never defined\") " "}} }}\n", @@ -85,8 +118,11 @@ void Converter::EmitUndefinedRecordTraits(Model model, std::string &out) { void Converter::DeclareRecordTraits(const clang::CXXRecordDecl *decl) { auto &traits = declared_record_traits_[GetRecordName(decl)]; for (auto *method : decl->methods()) { - if (auto *trait = GetRecordTrait(method); - trait && !IsDerivedCopyOrMove(method)) { + if (GetComparisonTrait(method)) { + traits.emplace(kWeaklyEqualityComparableWith.refcount.name, + &kWeaklyEqualityComparableWith); + } else if (auto *trait = GetRecordTrait(method); + trait && !IsDerivedCopyOrMove(method)) { traits.emplace(trait->refcount.name, trait); } } @@ -518,19 +554,23 @@ bool Converter::VisitFunctionDecl(clang::FunctionDecl *decl) { void Converter::ConvertComparisonTraitImpl(clang::FunctionDecl *decl, const RecordTrait &trait) { - const auto &spelling = GetRecordTraitSpelling(trait); - auto *record = GetComparisonRecord(decl); - StrCat(keyword::kImpl, spelling.name, "for", GetRecordName(record)); - PushBrace impl_brace(*this); - StrCat(keyword_unsafe_, keyword::kFn, trait.method); + std::string method; { - PushParen paren(*this); - ConvertFunctionParameters(decl); + Buffer buf(*this); + StrCat(keyword_unsafe_, keyword::kFn, trait.method); + { + PushParen paren(*this); + ConvertFunctionParameters(decl); + } + ConvertFunctionReturnType(decl); + { + PushBrace body(*this); + EmitFunctionPreamble(decl); + ConvertFunctionBody(decl); + } + method = std::move(buf).str(); } - ConvertFunctionReturnType(decl); - PushBrace body(*this); - EmitFunctionPreamble(decl); - ConvertFunctionBody(decl); + AddEqualityComparableMethod(GetComparisonRecord(decl), trait, method); } void Converter::EmitHoistedDecls(clang::CompoundStmt *body) { @@ -1155,6 +1195,10 @@ void Converter::ConvertCopyOrMoveTraitImpl(clang::CXXMethodDecl *method, if (body.empty()) { return; } + if (GetComparisonTrait(method)) { + AddEqualityComparableMethod(method->getParent(), trait, body); + return; + } converted_record_traits_.emplace(GetRecordName(method->getParent()), trait.refcount.name); StrCat(keyword::kImpl, GetCopyOrMoveTraitName(trait), "for", @@ -5799,14 +5843,10 @@ void Converter::ConvertCXXMethodDecls( Converter::DeferredBlock & Converter::VirtualMethodsFor(const clang::CXXRecordDecl *decl) { - auto name = GetRecordName(decl); - auto [it, inserted] = virtual_methods_.try_emplace(name); - if (inserted) { - it->second.header = std::format( - "{} impl {} for {}", keyword_unsafe_, - GetUnsafeTypeAsString(decl->bases_begin()->getType()), name); - } - return it->second; + return DeferredImpl( + std::format("{} impl {} for {}", keyword_unsafe_, + GetUnsafeTypeAsString(decl->bases_begin()->getType()), + GetRecordName(decl))); } void Converter::ConvertVirtualMethods(clang::CXXRecordDecl *decl) { @@ -5997,15 +6037,15 @@ Converter::GetComparisonOperandNames(const clang::FunctionDecl *op) { } void Converter::ConvertEqualityComparableImpl(const clang::CXXRecordDecl *decl, - const clang::FunctionDecl *eq) { - const auto &trait = kWeaklyEqualityComparableWith; - auto [lhs, rhs] = GetComparisonOperandNames(eq); - StrCat(keyword::kImpl, GetRecordTraitSpelling(trait).name, "for", - GetRecordName(decl)); - PushBrace impl_brace(*this); - StrCat(GetComparisonTraitSignature(trait, lhs, rhs)); - PushBrace body(*this); - StrCat(GetComparisonBool(eq, decl, lhs, rhs)); + const clang::FunctionDecl *op) { + const auto &trait = op->getOverloadedOperator() == clang::OO_ExclaimEqual + ? kWeaklyEqualityComparableWithNotEqual + : kWeaklyEqualityComparableWith; + auto [lhs, rhs] = GetComparisonOperandNames(op); + AddEqualityComparableMethod( + decl, trait, + std::format("{} {{ {} }}\n", GetComparisonTraitSignature(trait, lhs, rhs), + GetComparisonBool(op, decl, lhs, rhs))); } std::string Converter::GetComparisonTraitSignature(const RecordTrait &trait, @@ -6017,6 +6057,7 @@ std::string Converter::GetComparisonTraitSignature(const RecordTrait &trait, void Converter::AddOrdTrait(const clang::CXXRecordDecl *decl) { const clang::FunctionDecl *eq = nullptr; + const clang::FunctionDecl *ne = nullptr; const clang::FunctionDecl *lt = nullptr; const clang::FunctionDecl *cmp = nullptr; auto consider = [&](const clang::FunctionDecl *fn) { @@ -6032,6 +6073,9 @@ void Converter::AddOrdTrait(const clang::CXXRecordDecl *decl) { case clang::OO_EqualEqual: eq = fn; break; + case clang::OO_ExclaimEqual: + ne = fn; + break; case clang::OO_Less: lt = fn; break; @@ -6055,7 +6099,8 @@ void Converter::AddOrdTrait(const clang::CXXRecordDecl *decl) { for (const auto *method : decl->methods()) { consider(method); } - for (auto op : {clang::OO_EqualEqual, clang::OO_Less, clang::OO_Spaceship}) { + for (auto op : {clang::OO_EqualEqual, clang::OO_ExclaimEqual, clang::OO_Less, + clang::OO_Spaceship}) { auto name = ctx_.DeclarationNames.getCXXOperatorName(op); for (const auto *found : decl->getDeclContext()->lookup(name)) { consider_decl(found); @@ -6067,6 +6112,10 @@ void Converter::AddOrdTrait(const clang::CXXRecordDecl *decl) { } } + if (eq && ne && !GetComparisonTrait(ne)) { + ConvertEqualityComparableImpl(decl, ne); + } + if (!eq && !lt && !cmp) { return; } diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index cebf68db0a..dd8f7cd7ba 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -110,7 +110,7 @@ class Converter : public clang::RecursiveASTVisitor { static void EmitOpaqueRecords(Model model, std::string &out); static void EmitGlobalInits(Model model, std::string &out); - static void EmitVirtualMethods(std::string &out); + static void EmitDeferredImpls(std::string &out); static void EmitUndefinedRecordTraits(Model model, std::string &out); virtual bool VisitBuiltinType(clang::BuiltinType *type); @@ -498,7 +498,7 @@ class Converter : public clang::RecursiveASTVisitor { GetComparisonOperandNames(const clang::FunctionDecl *op); void ConvertEqualityComparableImpl(const clang::CXXRecordDecl *decl, - const clang::FunctionDecl *eq); + const clang::FunctionDecl *op); void ConvertParamTy(clang::QualType param_type, clang::Expr *expr); @@ -1389,7 +1389,15 @@ class Converter : public clang::RecursiveASTVisitor { std::string header; std::string body; }; - static std::map virtual_methods_; + static std::map deferred_impls_; + + static DeferredBlock &DeferredImpl(std::string header); + + DeferredBlock &EqualityComparableImplFor(const clang::CXXRecordDecl *record); + + void AddEqualityComparableMethod(const clang::CXXRecordDecl *record, + const RecordTrait &trait, + std::string_view method); static std::map> declared_record_traits_; static std::set> converted_record_traits_; diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 63b0f1e079..34976632fb 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -673,8 +673,24 @@ const clang::CXXRecordDecl *GetComparisonRecord(const clang::FunctionDecl *fn) { : nullptr; } +static bool HasSameTypeEqualityOperator(const clang::CXXRecordDecl *record) { + auto is_equality = [&](const clang::NamedDecl *found) { + auto *fn = clang::dyn_cast_or_null(found); + return fn && fn->getOverloadedOperator() == clang::OO_EqualEqual && + !fn->isDeleted() && IsSameTypeComparison(fn, record); + }; + auto name = record->getASTContext().DeclarationNames.getCXXOperatorName( + clang::OO_EqualEqual); + return llvm::any_of(record->methods(), is_equality) || + llvm::any_of(record->getDeclContext()->lookup(name), is_equality) || + llvm::any_of(record->friends(), [&](const clang::FriendDecl *decl) { + return is_equality(decl->getFriendDecl()); + }); +} + const RecordTrait *GetComparisonTrait(const clang::FunctionDecl *fn) { - if (fn->getOverloadedOperator() != clang::OO_EqualEqual) { + auto op = fn->getOverloadedOperator(); + if (op != clang::OO_EqualEqual && op != clang::OO_ExclaimEqual) { return nullptr; } auto *record = GetComparisonRecord(fn); @@ -697,7 +713,12 @@ const RecordTrait *GetComparisonTrait(const clang::FunctionDecl *fn) { return nullptr; } } - return &kWeaklyEqualityComparableWith; + if (op == clang::OO_EqualEqual) { + return &kWeaklyEqualityComparableWith; + } + return HasSameTypeEqualityOperator(record) + ? &kWeaklyEqualityComparableWithNotEqual + : nullptr; } const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method) { diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index b62df6f3b1..15348de110 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -170,6 +170,12 @@ inline constexpr RecordTrait kWeaklyEqualityComparableWith{ "fn equal(this: Ptr, _: Ptr) -> bool", "this.clone()"}, {"WeaklyEqualityComparableWithUnsafe", "unsafe fn equal(this: *const Self, _: *const Self) -> bool", "this"}}; +inline constexpr RecordTrait kWeaklyEqualityComparableWithNotEqual{ + "not_equal", + {"WeaklyEqualityComparableWith", + "fn not_equal(this: Ptr, _: Ptr) -> bool", "this.clone()"}, + {"WeaklyEqualityComparableWithUnsafe", + "unsafe fn not_equal(this: *const Self, _: *const Self) -> bool", "this"}}; inline constexpr RecordTrait kTriviallyDefaultConstructible{ nullptr, {"TriviallyDefaultConstructible"}, diff --git a/cpp2rust/cpp2rust_lib.cpp b/cpp2rust/cpp2rust_lib.cpp index 605e46ba59..a71f783d37 100644 --- a/cpp2rust/cpp2rust_lib.cpp +++ b/cpp2rust/cpp2rust_lib.cpp @@ -32,8 +32,8 @@ std::string TranspileSrc(std::string_view cc_code, Model model, cc_code, tool_args, std::filesystem::path(filename).filename().string(), filename.ends_with(".c") ? CLANG_C_COMPILER : CLANG_CXX_COMPILER); Converter::EmitOpaqueRecords(model, rs_code); - Converter::EmitVirtualMethods(rs_code); Converter::EmitUndefinedRecordTraits(model, rs_code); + Converter::EmitDeferredImpls(rs_code); Converter::EmitGlobalInits(model, rs_code); return rs_code; } @@ -75,8 +75,8 @@ std::string TranspileDir(std::string_view build_dir, Model model, FrontendActionFactory factory(rs_code, model, rules_dir); Tool.run(&factory); Converter::EmitOpaqueRecords(model, rs_code); - Converter::EmitVirtualMethods(rs_code); Converter::EmitUndefinedRecordTraits(model, rs_code); + Converter::EmitDeferredImpls(rs_code); Converter::EmitGlobalInits(model, rs_code); return rs_code; } diff --git a/libcc2rs/src/cmp.rs b/libcc2rs/src/cmp.rs index 7ed4da5ead..f7d96a17f5 100644 --- a/libcc2rs/src/cmp.rs +++ b/libcc2rs/src/cmp.rs @@ -16,12 +16,22 @@ pub trait CppLess: Sized { pub trait WeaklyEqualityComparableWith: Sized { fn equal(this: Ptr, rhs: Ptr) -> bool; + + fn not_equal(this: Ptr, rhs: Ptr) -> bool { + !Self::equal(this, rhs) + } } pub trait WeaklyEqualityComparableWithUnsafe: Sized { /// # Safety /// `rhs` must point to a live value. unsafe fn equal(this: *const Self, rhs: *const U) -> bool; + + /// # Safety + /// `this` and `rhs` must point to live values. + unsafe fn not_equal(this: *const Self, rhs: *const U) -> bool { + unsafe { !Self::equal(this, rhs) } + } } pub trait EqualityComparable: WeaklyEqualityComparableWith {} @@ -32,7 +42,7 @@ pub trait EqualityComparableUnsafe: WeaklyEqualityComparableWithUnsafe {} impl> EqualityComparableUnsafe for T {} -pub trait EqualityComparableWith: +pub trait EqualityComparableWith>: EqualityComparable + WeaklyEqualityComparableWith { } @@ -40,19 +50,20 @@ pub trait EqualityComparableWith: impl EqualityComparableWith for T where T: EqualityComparable + WeaklyEqualityComparableWith, - U: EqualityComparable, + U: EqualityComparable + WeaklyEqualityComparableWith, { } -pub trait EqualityComparableWithUnsafe: - EqualityComparableUnsafe + WeaklyEqualityComparableWithUnsafe +pub trait EqualityComparableWithUnsafe< + U: EqualityComparableUnsafe + WeaklyEqualityComparableWithUnsafe, +>: EqualityComparableUnsafe + WeaklyEqualityComparableWithUnsafe { } impl EqualityComparableWithUnsafe for T where T: EqualityComparableUnsafe + WeaklyEqualityComparableWithUnsafe, - U: EqualityComparableUnsafe, + U: EqualityComparableUnsafe + WeaklyEqualityComparableWithUnsafe, { } diff --git a/rules/algorithm/tgt_refcount.rs b/rules/algorithm/tgt_refcount.rs index 67e2ed34c1..9164df44d9 100644 --- a/rules/algorithm/tgt_refcount.rs +++ b/rules/algorithm/tgt_refcount.rs @@ -26,7 +26,7 @@ fn f2< let __first: Value = Rc::new(RefCell::new(a0)); let __last: Value = Rc::new(RefCell::new(a1)); let mut __out = a2; - while !::equal(__first.as_pointer(), __last.as_pointer()) { + while ::not_equal(__first.as_pointer(), __last.as_pointer()) { __out.iter_deref().write(T4::cpp_from(__first.borrow().iter_deref())); __first.borrow_mut().iter_inc(); __out.iter_inc(); @@ -37,7 +37,7 @@ fn f2< fn f3, T2, 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 !::equal(__it.as_pointer(), __last.as_pointer()) + while ::not_equal(__it.as_pointer(), __last.as_pointer()) && !WeaklyEqualityComparableWith::equal(__it.borrow().iter_deref(), a2.clone()) { __it.borrow_mut().iter_inc(); @@ -69,9 +69,9 @@ fn f8, T2: CppLess>(a0: T1, a1: T1) -> T1 { let __it: Value = Rc::new(RefCell::new(a0)); let __last: Value = Rc::new(RefCell::new(a1)); let mut __best = __it.borrow().clone(); - if !::equal(__it.as_pointer(), __last.as_pointer()) { + if ::not_equal(__it.as_pointer(), __last.as_pointer()) { __it.borrow_mut().iter_inc(); - while !::equal(__it.as_pointer(), __last.as_pointer()) { + while ::not_equal(__it.as_pointer(), __last.as_pointer()) { if CppLess::less(__best.iter_deref(), __it.borrow().iter_deref()) { __best = __it.borrow().clone(); } @@ -96,7 +96,7 @@ fn f10, T2: WeaklyEqualityComparableWith + Triviall } else { let mut __write = __it.borrow().clone(); __it.borrow_mut().iter_inc(); - while !::equal(__it.as_pointer(), __last.as_pointer()) { + 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()); @@ -111,7 +111,7 @@ fn f10, T2: WeaklyEqualityComparableWith + Triviall fn f12, T2: Clone + ByteRepr>(a0: T1, a1: T1, a2: T2) { let __it: Value = Rc::new(RefCell::new(a0)); let __last: Value = Rc::new(RefCell::new(a1)); - while !::equal(__it.as_pointer(), __last.as_pointer()) { + while ::not_equal(__it.as_pointer(), __last.as_pointer()) { __it.borrow().iter_deref().write(Clone::clone(&a2)); __it.borrow_mut().iter_inc(); } @@ -122,7 +122,7 @@ fn f13>(a0: T1, a1: T1, a2: &mut ::std::fs::File) -> :: let __last: Value = Rc::new(RefCell::new(a1)); let __out = &mut *a2; let mut __bytes: Vec = Vec::new(); - while !::equal(__it.as_pointer(), __last.as_pointer()) { + while ::not_equal(__it.as_pointer(), __last.as_pointer()) { __bytes.push(__it.borrow().iter_deref().read() as u8); __it.borrow_mut().iter_inc(); } diff --git a/rules/algorithm/tgt_unsafe.rs b/rules/algorithm/tgt_unsafe.rs index ad6d84fced..0038c80ea8 100644 --- a/rules/algorithm/tgt_unsafe.rs +++ b/rules/algorithm/tgt_unsafe.rs @@ -24,7 +24,7 @@ unsafe fn f2, T2: UnsafeCppIterator, T3, T4: ) -> T2 { let mut __first = a0; let mut __out = a2; - while !WeaklyEqualityComparableWithUnsafe::equal(&__first, &a1) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &a1) { *__out.iter_deref() = T4::cpp_from(__first.iter_deref()); __first.iter_inc(); __out.iter_inc(); @@ -34,7 +34,7 @@ unsafe fn f2, T2: UnsafeCppIterator, T3, T4: unsafe fn f3, T2, T3: WeaklyEqualityComparableWithUnsafe>(a0: T1, a1: T1, a2: T2) -> T1 { let mut __it = a0; - while !WeaklyEqualityComparableWithUnsafe::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 @@ -68,10 +68,10 @@ where unsafe fn f8, T2: PartialOrd>(a0: T1, a1: T1) -> T1 { let mut __best = a0.clone(); - if !WeaklyEqualityComparableWithUnsafe::equal(&a0, &a1) { + if WeaklyEqualityComparableWithUnsafe::not_equal(&a0, &a1) { let mut __it = a0; __it.iter_inc(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &a1) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) { if *__best.iter_deref() < *__it.iter_deref() { __best = __it.clone(); } @@ -94,7 +94,7 @@ unsafe fn f10, T2: WeaklyEqualityComparableWithUn let mut __write = a0.clone(); let mut __it = a0; __it.iter_inc(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &a1) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) { if !WeaklyEqualityComparableWithUnsafe::equal(&*__write.iter_deref(), __it.iter_deref()) { __write.iter_inc(); *__write.iter_deref() = (*__it.iter_deref()).clone(); @@ -108,7 +108,7 @@ unsafe fn f10, T2: WeaklyEqualityComparableWithUn unsafe fn f12, T2: Clone>(a0: T1, a1: T1, a2: T2) { let mut __it = a0; - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &a1) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) { *__it.iter_deref() = Clone::clone(&a2); __it.iter_inc(); } @@ -122,7 +122,7 @@ unsafe fn f13>( let mut __it = a0; let __out = &mut *a2; let mut __bytes: Vec = Vec::new(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &a1) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) { __bytes.push(*__it.iter_deref() as u8); __it.iter_inc(); } diff --git a/rules/iterator_category/tgt_refcount.rs b/rules/iterator_category/tgt_refcount.rs index 732c5299b8..153918f166 100644 --- a/rules/iterator_category/tgt_refcount.rs +++ b/rules/iterator_category/tgt_refcount.rs @@ -63,7 +63,7 @@ fn f9, T2>(a0: Ptr, a1: Ptr) -> bool { } fn f10, T2>(a0: Ptr, a1: Ptr) -> bool { - !WeaklyEqualityComparableWith::equal(a0, a1) + WeaklyEqualityComparableWith::not_equal(a0, a1) } fn f11, T2>(a0: &mut T1) -> &mut T1 { @@ -135,6 +135,6 @@ fn f26, T2>(a0: &mut T1) -> &mut T1 { a0 } -fn f27 + WeaklyEqualityComparableWith, T2: CppInputIterator, T3>(a0: Ptr, a1: Ptr) -> bool { +fn f27 + 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 24ae84f4f1..5a9629caf1 100644 --- a/rules/iterator_category/tgt_unsafe.rs +++ b/rules/iterator_category/tgt_unsafe.rs @@ -63,7 +63,7 @@ unsafe fn f9, T2>(a0: T1, a1: T1) -> bool { } unsafe fn f10, T2>(a0: T1, a1: T1) -> bool { - !WeaklyEqualityComparableWithUnsafe::equal(&a0, &a1) + WeaklyEqualityComparableWithUnsafe::not_equal(&a0, &a1) } fn f11, T2>(a0: &mut T1) -> &mut T1 { @@ -135,6 +135,6 @@ fn f26, T2>(a0: &mut T1) -> &mut T1 { a0 } -unsafe fn f27 + WeaklyEqualityComparableWithUnsafe, T2: UnsafeCppInputIterator, T3>(a0: T1, a1: T2) -> bool { +unsafe fn f27 + WeaklyEqualityComparableWithUnsafe, T2: UnsafeCppInputIterator + WeaklyEqualityComparableWithUnsafe, T3>(a0: T1, a1: T2) -> bool { WeaklyEqualityComparableWithUnsafe::equal(&a0, &a1) } diff --git a/rules/vector/tgt_refcount.rs b/rules/vector/tgt_refcount.rs index f5fd6514ff..a374cf2cd8 100644 --- a/rules/vector/tgt_refcount.rs +++ b/rules/vector/tgt_refcount.rs @@ -95,7 +95,7 @@ fn f92, T2, T3: CppInputIterator, T4: ByteRepr>(a0: T3, a1: let mut __v = Vec::new(); let __it: Value = Rc::new(RefCell::new(a0)); let __last: Value = Rc::new(RefCell::new(a1)); - while !::equal(__it.as_pointer(), __last.as_pointer()) { + while ::not_equal(__it.as_pointer(), __last.as_pointer()) { __v.push(T1::cpp_from(__it.borrow().iter_deref())); __it.borrow_mut().iter_inc(); } @@ -140,7 +140,7 @@ fn f101 + ByteRepr, T2, T3: CppInputIterator, T4: ByteRepr>( let mut temp_vec: Vec = Vec::new(); let __it: Value = Rc::new(RefCell::new(a2)); let __last: Value = Rc::new(RefCell::new(a3)); - while !::equal(__it.as_pointer(), __last.as_pointer()) { + while ::not_equal(__it.as_pointer(), __last.as_pointer()) { temp_vec.push(T1::cpp_from(__it.borrow().iter_deref())); __it.borrow_mut().iter_inc(); } diff --git a/rules/vector/tgt_unsafe.rs b/rules/vector/tgt_unsafe.rs index f591fb3dd6..5fc277be99 100644 --- a/rules/vector/tgt_unsafe.rs +++ b/rules/vector/tgt_unsafe.rs @@ -152,7 +152,7 @@ fn f91(a0: Vec) -> Vec { unsafe fn f92, T2, T3: UnsafeCppInputIterator, T4>(a0: T3, a1: T3) -> Vec { let mut __v = Vec::new(); let mut __it = a0; - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &a1) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a1) { __v.push(T1::cpp_from(__it.iter_deref())); __it.iter_inc(); } @@ -193,7 +193,7 @@ unsafe fn f101, T2, T3: UnsafeCppInputIterator, T4>( let __off = a1.iter_distance(&UnsafeRandomAccessIterator::Vec(a0.as_mut_ptr())) as usize; let mut __tmp = Vec::new(); let mut __it = a2; - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &a3) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &a3) { __tmp.push(T1::cpp_from(__it.iter_deref())); __it.iter_inc(); } diff --git a/tests/multi-file/friend_operator/out/refcount/friend_operator.rs b/tests/multi-file/friend_operator/out/refcount/friend_operator.rs index 070a1725f1..51be3124d8 100644 --- a/tests/multi-file/friend_operator/out/refcount/friend_operator.rs +++ b/tests/multi-file/friend_operator/out/refcount/friend_operator.rs @@ -34,36 +34,36 @@ fn main_0() -> i32 { let s2: Value = Rc::new(RefCell::new(S { a: 1, b: 2 })); let s3: Value = Rc::new(RefCell::new(S { a: 1, b: 3 })); assert!(({ WeaklyEqualityComparableWith::equal(s1.as_pointer(), s2.as_pointer(),) })); - assert!(({ operator_ne_0(s1.as_pointer(), s3.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::not_equal(s1.as_pointer(), s3.as_pointer(),) })); assert!(!({ WeaklyEqualityComparableWith::equal(s1.as_pointer(), s3.as_pointer(),) })); - assert!(({ operator_lt_1(s1.as_pointer(), s3.as_pointer(),) })); - assert!(!({ operator_lt_1(s3.as_pointer(), s1.as_pointer(),) })); - assert!((({ compare_2(s1.as_pointer(), s3.as_pointer(),) }) == -1_i32)); - assert!((({ compare_2(s3.as_pointer(), s1.as_pointer(),) }) == 1)); - assert!((({ compare_2(s1.as_pointer(), s2.as_pointer(),) }) == 0)); + assert!(({ operator_lt_0(s1.as_pointer(), s3.as_pointer(),) })); + assert!(!({ operator_lt_0(s3.as_pointer(), s1.as_pointer(),) })); + assert!((({ compare_1(s1.as_pointer(), s3.as_pointer(),) }) == -1_i32)); + assert!((({ compare_1(s3.as_pointer(), s1.as_pointer(),) }) == 1)); + assert!((({ compare_1(s1.as_pointer(), s2.as_pointer(),) }) == 0)); return 0; } -impl WeaklyEqualityComparableWith for S { - fn equal(x: Ptr, y: Ptr) -> bool { - return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }) - && ({ x.with(|__s| __s.b) } == { y.with(|__s| __s.b) }); - } -} -pub fn operator_ne_0(x: Ptr, y: Ptr) -> bool { - return !({ WeaklyEqualityComparableWith::equal((x).clone(), (y).clone()) }); -} -pub fn operator_lt_1(x: Ptr, y: Ptr) -> bool { +pub fn operator_lt_0(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.a) } < { y.with(|__s| __s.a) }) || (({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }) && ({ x.with(|__s| __s.b) } < { y.with(|__s| __s.b) })); } -pub fn compare_2(x: Ptr, y: Ptr) -> i32 { - if ({ operator_lt_1((x).clone(), (y).clone()) }) { +pub fn compare_1(x: Ptr, y: Ptr) -> i32 { + if ({ operator_lt_0((x).clone(), (y).clone()) }) { return -1_i32; } - if ({ operator_lt_1((y).clone(), (x).clone()) }) { + if ({ operator_lt_0((y).clone(), (x).clone()) }) { return 1; } return 0; } +impl WeaklyEqualityComparableWith for S { + fn equal(x: Ptr, y: Ptr) -> bool { + return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }) + && ({ x.with(|__s| __s.b) } == { y.with(|__s| __s.b) }); + } + fn not_equal(x: Ptr, y: Ptr) -> bool { + return !({ WeaklyEqualityComparableWith::equal((x).clone(), (y).clone()) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs b/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs index 572e6c8c57..21e57ddc31 100644 --- a/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs +++ b/tests/multi-file/friend_operator/out/unsafe/friend_operator.rs @@ -40,7 +40,7 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const S = &s1; - operator_ne_0(_x, &s3) + WeaklyEqualityComparableWithUnsafe::not_equal(_x, &s3) }) ); assert!( @@ -52,47 +52,47 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const S = &s1; - operator_lt_1(_x, &s3) + operator_lt_0(_x, &s3) }) ); assert!( !(unsafe { let _x: *const S = &s3; - operator_lt_1(_x, &s1) + operator_lt_0(_x, &s1) }) ); - assert!(((unsafe { compare_2(&s1, &s3,) }) == (-1_i32))); - assert!(((unsafe { compare_2(&s3, &s1,) }) == (1))); - assert!(((unsafe { compare_2(&s1, &s2,) }) == (0))); + assert!(((unsafe { compare_1(&s1, &s3,) }) == (-1_i32))); + assert!(((unsafe { compare_1(&s3, &s1,) }) == (1))); + assert!(((unsafe { compare_1(&s1, &s2,) }) == (0))); return 0; } -impl WeaklyEqualityComparableWithUnsafe for S { - unsafe fn equal(x: *const S, y: *const S) -> bool { - return (((*x).a) == ((*y).a)) && (((*x).b) == ((*y).b)); - } -} -pub unsafe fn operator_ne_0(x: *const S, y: *const S) -> bool { - return !(unsafe { - let _x: *const S = x; - WeaklyEqualityComparableWithUnsafe::equal(_x, y) - }); -} -pub unsafe fn operator_lt_1(x: *const S, y: *const S) -> bool { +pub unsafe fn operator_lt_0(x: *const S, y: *const S) -> bool { return (((*x).a) < ((*y).a)) || ((((*x).a) == ((*y).a)) && (((*x).b) < ((*y).b))); } -pub unsafe fn compare_2(x: *const S, y: *const S) -> i32 { +pub unsafe fn compare_1(x: *const S, y: *const S) -> i32 { if (unsafe { let _x: *const S = x; - operator_lt_1(_x, y) + operator_lt_0(_x, y) }) { return -1_i32; } if (unsafe { let _x: *const S = y; - operator_lt_1(_x, x) + operator_lt_0(_x, x) }) { return 1; } return 0; } +impl WeaklyEqualityComparableWithUnsafe for S { + unsafe fn equal(x: *const S, y: *const S) -> bool { + return (((*x).a) == ((*y).a)) && (((*x).b) == ((*y).b)); + } + unsafe fn not_equal(x: *const S, y: *const S) -> bool { + return !(unsafe { + let _x: *const S = x; + WeaklyEqualityComparableWithUnsafe::equal(_x, y) + }); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index 80212c0812..f98c669f4f 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -848,13 +848,6 @@ fn main_0() -> i32 { #[derive(Clone, Copy, Default, ByteRepr, VaArg, FnPtrArg)] #[byte_size(1)] pub struct p13_pointer_to_incomplete_class_X; -impl p4_1_pure_virtual_without_definition_HasPureVirtual - for p4_1_pure_virtual_without_definition_OverridesPureVirtual -{ - fn f(&mut self) { - (*derived_calls_10.with(Value::clone).borrow_mut()).prefix_inc(); - } -} impl Destructible for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { fn destroy(this: Ptr) { unreachable!( @@ -876,6 +869,13 @@ impl CopyAssignable for p9_unused_implicit_assignment_HasUndefinedCopyAssignment ) } } +impl p4_1_pure_virtual_without_definition_HasPureVirtual + for p4_1_pure_virtual_without_definition_OverridesPureVirtual +{ + fn f(&mut self) { + (*derived_calls_10.with(Value::clone).borrow_mut()).prefix_inc(); + } +} pub fn __cpp2rust_init_globals() { let _ = copyCount_0.with(|_| ()); let _ = ctorCount_1.with(|_| ()); diff --git a/tests/std/basic/out/unsafe/basic.def.odr.rs b/tests/std/basic/out/unsafe/basic.def.odr.rs index 9b239de46c..f1bd018218 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -758,13 +758,6 @@ unsafe fn main_0() -> i32 { } #[derive(Clone, Copy, Default, VaArg, FnPtrArg)] pub struct p13_pointer_to_incomplete_class_X; -unsafe impl p4_1_pure_virtual_without_definition_HasPureVirtual - for p4_1_pure_virtual_without_definition_OverridesPureVirtual -{ - unsafe fn f(&mut self) { - (*std::cell::LazyCell::force_mut(&mut *&raw mut derived_calls_10)).prefix_inc(); - } -} impl DestructibleUnsafe for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { unsafe fn destroy(this: *mut Self) { unreachable!( @@ -786,6 +779,13 @@ impl CopyAssignableUnsafe for p9_unused_implicit_assignment_HasUndefinedCopyAssi ) } } +unsafe impl p4_1_pure_virtual_without_definition_HasPureVirtual + for p4_1_pure_virtual_without_definition_OverridesPureVirtual +{ + unsafe fn f(&mut self) { + (*std::cell::LazyCell::force_mut(&mut *&raw mut derived_calls_10)).prefix_inc(); + } +} pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const copyCount_0); std::cell::LazyCell::force(&*&raw const ctorCount_1); diff --git a/tests/unit/out/refcount/class.rs b/tests/unit/out/refcount/class.rs index 31efb77c4d..d99c5277d1 100644 --- a/tests/unit/out/refcount/class.rs +++ b/tests/unit/out/refcount/class.rs @@ -102,14 +102,6 @@ impl Counter { return this.with(|__s| __s.v); } } -impl WeaklyEqualityComparableWith for Counter { - fn equal(this: Ptr, o: Ptr) -> bool { - field!(this, calls).with_mut(|__v| { - __v.prefix_inc(); - }); - return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } -} #[derive( Copy, Clone, @@ -210,4 +202,12 @@ fn main_0() -> i32 { assert!(({ (*ct.borrow()).calls } == 10)); return 0; } +impl WeaklyEqualityComparableWith for Counter { + fn equal(this: Ptr, o: Ptr) -> bool { + field!(this, calls).with_mut(|__v| { + __v.prefix_inc(); + }); + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/container_element_receiver.rs b/tests/unit/out/refcount/container_element_receiver.rs index cdd0f9512a..0f5a446b89 100644 --- a/tests/unit/out/refcount/container_element_receiver.rs +++ b/tests/unit/out/refcount/container_element_receiver.rs @@ -39,7 +39,9 @@ pub fn sum_1(v: Ptr>) -> i32 { { let it: Value> = Rc::new(RefCell::new(v.decay().begin())); 'loop_: while match (Rc::new(RefCell::new(v.decay().end())).as_pointer(),) { - (__tmp_0,) => !WeaklyEqualityComparableWith::equal(it.as_pointer(), (__tmp_0).clone()), + (__tmp_0,) => { + WeaklyEqualityComparableWith::not_equal(it.as_pointer(), (__tmp_0).clone()) + } } { 'for_body: { total += (({ (*it.borrow()).iter_deref() }).read()); diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index 55d3fc0169..1d75ac83e3 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -425,7 +425,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(vec_.decay().begin())); let __last: Value> = Rc::new(RefCell::new(vec_.decay().end())); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { __v.push(>::cpp_from( __it.borrow().iter_deref(), )); diff --git a/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs b/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs index 6b603f74af..d094221826 100644 --- a/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs +++ b/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs @@ -28,7 +28,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(v.decay().begin())); let __last: Value> = Rc::new(RefCell::new(v.decay().end())); - while !>::equal(__it.as_pointer(), __last.as_pointer()) + while >::not_equal(__it.as_pointer(), __last.as_pointer()) && !WeaklyEqualityComparableWith::equal( __it.borrow().iter_deref(), __tmp_2.as_pointer().clone(), @@ -43,7 +43,7 @@ fn main_0() -> i32 { assert!( match (Rc::new(RefCell::new(v.decay().end())).as_pointer(),) { (__tmp_3,) => { - !WeaklyEqualityComparableWith::equal(it.as_pointer(), (__tmp_3).clone()) + WeaklyEqualityComparableWith::not_equal(it.as_pointer(), (__tmp_3).clone()) } } ); diff --git a/tests/unit/out/refcount/emplace_receiver_alias.rs b/tests/unit/out/refcount/emplace_receiver_alias.rs index 86ea20ee47..8562a87dd6 100644 --- a/tests/unit/out/refcount/emplace_receiver_alias.rs +++ b/tests/unit/out/refcount/emplace_receiver_alias.rs @@ -36,7 +36,7 @@ fn main_0() -> i32 { let __last: Value> = Rc::new(RefCell::new( (alias).decay().offset(0_usize).decay().offset((3) as isize), )); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { __v.push((__it.borrow().iter_deref().read())); __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 83ace175ee..78a71cd0ac 100644 --- a/tests/unit/out/refcount/emplace_receiver_order.rs +++ b/tests/unit/out/refcount/emplace_receiver_order.rs @@ -43,7 +43,8 @@ fn main_0() -> i32 { let __last: Value> = Rc::new(RefCell::new( rows.decay().offset(0_usize).decay().offset((3) as isize), )); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) + { __v.push((__it.borrow().iter_deref().read())); __it.borrow_mut().iter_inc(); } @@ -64,7 +65,8 @@ fn main_0() -> i32 { let __last: Value> = Rc::new(RefCell::new( rows.decay().offset(0_usize).decay().offset((3) as isize), )); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) + { __v.push((__it.borrow().iter_deref().read())); __it.borrow_mut().iter_inc(); } diff --git a/tests/unit/out/refcount/find.rs b/tests/unit/out/refcount/find.rs index 8883012306..e0982d9a88 100644 --- a/tests/unit/out/refcount/find.rs +++ b/tests/unit/out/refcount/find.rs @@ -23,11 +23,6 @@ pub struct P { #[offset(0)] pub x: i32, } -impl WeaklyEqualityComparableWith for P { - fn equal(this: Ptr, o: Ptr

) -> bool { - return ({ this.with(|__s| __s.x) } == { o.with(|__s| __s.x) }); - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -56,7 +51,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(({ (*v_begin.borrow()).clone() }))); let __last: Value> = Rc::new(RefCell::new(({ (*v_end.borrow()).clone() }))); - while !>::equal(__it.as_pointer(), __last.as_pointer()) + while >::not_equal(__it.as_pointer(), __last.as_pointer()) && !WeaklyEqualityComparableWith::equal( __it.borrow().iter_deref(), __tmp_3.as_pointer().clone(), @@ -69,7 +64,7 @@ fn main_0() -> i32 { }), )); let mut v_result_true: bool = match (Rc::new(RefCell::new(v.decay().end())).as_pointer(),) { - (__tmp_4,) => !WeaklyEqualityComparableWith::equal(it.as_pointer(), (__tmp_4).clone()), + (__tmp_4,) => WeaklyEqualityComparableWith::not_equal(it.as_pointer(), (__tmp_4).clone()), }; let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); match (Rc::new(RefCell::new(1)).as_pointer(),) { @@ -99,7 +94,7 @@ fn main_0() -> i32 { .with(|__m: &Map, Value)>| __m.end()), )); let mut m_result_true: bool = - !WeaklyEqualityComparableWith::equal(m_begin.as_pointer(), m_end.as_pointer()); + WeaklyEqualityComparableWith::not_equal(m_begin.as_pointer(), m_end.as_pointer()); assert!( ((v_result_true) && (m_result_true)) && (match ( @@ -111,7 +106,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(v.decay().begin())); let __last: Value> = Rc::new(RefCell::new(v.decay().begin())); - while !>::equal( + while >::not_equal( __it.as_pointer(), __last.as_pointer(), ) && !WeaklyEqualityComparableWith::equal( @@ -142,7 +137,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(w.decay().begin().iter_add(2_isize))); let __last: Value> = Rc::new(RefCell::new(w.decay().end())); - while !>::equal( + while >::not_equal( __it.as_pointer(), __last.as_pointer(), ) && !WeaklyEqualityComparableWith::equal( @@ -171,7 +166,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(w.decay().begin().iter_add(2_isize))); let __last: Value> = Rc::new(RefCell::new(w.decay().end())); - while !>::equal( + while >::not_equal( __it.as_pointer(), __last.as_pointer(), ) && !WeaklyEqualityComparableWith::equal( @@ -200,7 +195,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(w.decay().begin().iter_add(2_isize))); let __last: Value> = Rc::new(RefCell::new(w.decay().begin().iter_add(4_isize))); - while !>::equal( + while >::not_equal( __it.as_pointer(), __last.as_pointer(), ) && !WeaklyEqualityComparableWith::equal( @@ -234,12 +229,13 @@ fn main_0() -> i32 { Rc::new(RefCell::new(p.decay().begin())); let __last: Value> = Rc::new(RefCell::new(p.decay().end())); - while !>::equal(__it.as_pointer(), __last.as_pointer()) - && !WeaklyEqualityComparableWith::equal( - __it.borrow().iter_deref(), - (__tmp_21.as_pointer()).clone(), - ) - { + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + (__tmp_21.as_pointer()).clone(), + ) { __it.borrow_mut().iter_inc(); } __it.borrow().clone() @@ -255,4 +251,9 @@ fn main_0() -> i32 { }); return 0; } +impl WeaklyEqualityComparableWith for P { + fn equal(this: Ptr, o: Ptr

) -> bool { + return ({ this.with(|__s| __s.x) } == { o.with(|__s| __s.x) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/friend.rs b/tests/unit/out/refcount/friend.rs index 11036f9e7e..d4b2be0dee 100644 --- a/tests/unit/out/refcount/friend.rs +++ b/tests/unit/out/refcount/friend.rs @@ -9,11 +9,6 @@ use std::rc::{Rc, Weak}; pub fn get_0(v: Ptr) -> i32 { return v.with(|__s| __s.x); } -impl WeaklyEqualityComparableWith for V { - fn equal(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.x) } == { b.with(|__s| __s.x) }); - } -} pub fn scaled_1(v: Ptr, mut k: i32) -> i32 { return ({ v.with(|__s| __s.x) } * { k }); } @@ -118,4 +113,9 @@ fn main_0() -> i32 { assert!((({ declared_then_defined_5(d.as_pointer(),) }) == 8)); return 0; } +impl WeaklyEqualityComparableWith for V { + fn equal(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.x) } == { b.with(|__s| __s.x) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/map.rs b/tests/unit/out/refcount/map.rs index 7b728702bb..38a0839aa7 100644 --- a/tests/unit/out/refcount/map.rs +++ b/tests/unit/out/refcount/map.rs @@ -376,7 +376,7 @@ fn main_0() -> i32 { .as_pointer(), ) { (__tmp_28, __tmp_30) => { - !WeaklyEqualityComparableWith::equal((__tmp_28).clone(), (__tmp_30).clone()) + WeaklyEqualityComparableWith::not_equal((__tmp_28).clone(), (__tmp_30).clone()) } }); Map::erase((r).clone(), &({ (*it4.borrow()).clone() })); diff --git a/tests/unit/out/refcount/map_key_identity.rs b/tests/unit/out/refcount/map_key_identity.rs index d7a212a61c..d502571423 100644 --- a/tests/unit/out/refcount/map_key_identity.rs +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -36,11 +36,6 @@ impl CppLess for Key { pub fn operator_lt_1(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.order) } < { b.with(|__s| __s.order) }); } -impl WeaklyEqualityComparableWith for Key { - fn equal(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.identity) } == { b.with(|__s| __s.identity) }); - } -} #[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] #[byte_size(4)] pub struct Mapped { @@ -149,7 +144,7 @@ fn main_0() -> i32 { .as_pointer(),) { (__tmp_2,) => { - !WeaklyEqualityComparableWith::equal(b_it.as_pointer(), (__tmp_2).clone()) + WeaklyEqualityComparableWith::not_equal(b_it.as_pointer(), (__tmp_2).clone()) } }) as i32)) != 0 @@ -262,7 +257,7 @@ fn main_0() -> i32 { )) .as_pointer(),) { - (__tmp_3,) => !WeaklyEqualityComparableWith::equal( + (__tmp_3,) => WeaklyEqualityComparableWith::not_equal( first_it.as_pointer(), (__tmp_3).clone(), ), @@ -501,6 +496,11 @@ fn main_0() -> i32 { }; return if ok { 0 } else { 1 }; } +impl WeaklyEqualityComparableWith for Key { + fn equal(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.identity) } == { b.with(|__s| __s.identity) }); + } +} pub fn __cpp2rust_init_globals() { let _ = default_constructions_0.with(|_| ()); } diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index 8a9518c0dc..db0277c11c 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -114,9 +114,9 @@ fn main_0() -> i32 { let __it: Value> = Rc::new(RefCell::new(values.decay())); let __last: Value> = Rc::new(RefCell::new(values.decay().offset((4) as isize))); let mut __best = __it.borrow().clone(); - if !>::equal(__it.as_pointer(), __last.as_pointer()) { + if >::not_equal(__it.as_pointer(), __last.as_pointer()) { __it.borrow_mut().iter_inc(); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { if CppLess::less(__best.iter_deref(), __it.borrow().iter_deref()) { __best = __it.borrow().clone(); } diff --git a/tests/unit/out/refcount/operator_comparison_defaulted.rs b/tests/unit/out/refcount/operator_comparison_defaulted.rs index da9da2a9a3..ecdf2fe32e 100644 --- a/tests/unit/out/refcount/operator_comparison_defaulted.rs +++ b/tests/unit/out/refcount/operator_comparison_defaulted.rs @@ -25,12 +25,6 @@ pub struct Eq { #[offset(4)] pub b: i32, } -impl WeaklyEqualityComparableWith for Eq { - fn equal(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }) - && ({ this.with(|__s| __s.b) } == { _a0.with(|__s| __s.b) }); - } -} #[derive( Copy, Clone, @@ -73,12 +67,6 @@ impl Cmp { return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } } -impl WeaklyEqualityComparableWith for Cmp { - fn equal(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }) - && ({ this.with(|__s| __s.b) } == { _a0.with(|__s| __s.b) }); - } -} impl CppLess for Cmp { fn less(this: Ptr, _a0: Ptr) -> bool { Cmp::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less @@ -115,11 +103,6 @@ impl Both { return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } } -impl WeaklyEqualityComparableWith for Both { - fn equal(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); - } -} impl CppLess for Both { fn less(this: Ptr, _a0: Ptr) -> bool { Both::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less @@ -192,11 +175,6 @@ impl Inner { return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } } -impl WeaklyEqualityComparableWith for Inner { - fn equal(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.x) } == { _a0.with(|__s| __s.x) }); - } -} impl CppLess for Inner { fn less(this: Ptr, _a0: Ptr) -> bool { Inner::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less @@ -244,12 +222,6 @@ impl Outer { return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } } -impl WeaklyEqualityComparableWith for Outer { - fn equal(this: Ptr, _a0: Ptr) -> bool { - return ({ WeaklyEqualityComparableWith::equal(field_ptr!(this, i), field_ptr!(_a0, i)) }) - && ({ this.with(|__s| __s.y) } == { _a0.with(|__s| __s.y) }); - } -} impl CppLess for Outer { fn less(this: Ptr, _a0: Ptr) -> bool { Outer::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less @@ -273,9 +245,6 @@ pub struct Secondary { pub a: i32, } impl Secondary { - pub fn operator_ne(this: Ptr, _a0: Ptr) -> bool { - return !({ WeaklyEqualityComparableWith::equal((this).clone(), (_a0).clone()) }); - } pub fn operator_cmp(this: Ptr, _a0: Ptr) -> std::cmp::Ordering { { let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( @@ -297,11 +266,6 @@ impl Secondary { != std::cmp::Ordering::Less; } } -impl WeaklyEqualityComparableWith for Secondary { - fn equal(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); - } -} impl CppLess for Secondary { fn less(this: Ptr, _a0: Ptr) -> bool { Secondary::operator_lt(this.clone(), _a0.clone()) @@ -338,11 +302,6 @@ impl PtrMember { return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } } -impl WeaklyEqualityComparableWith for PtrMember { - fn equal(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.p.clone()) } == { _a0.with(|__s| __s.p.clone()) }); - } -} impl CppLess for PtrMember { fn less(this: Ptr, _a0: Ptr) -> bool { PtrMember::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less @@ -408,7 +367,7 @@ fn main_0() -> i32 { ); let s1: Value = Rc::new(RefCell::new(Secondary { a: 1 })); let s2: Value = Rc::new(RefCell::new(Secondary { a: 2 })); - assert!(({ Secondary::operator_ne(s1.as_pointer(), s2.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::not_equal(s1.as_pointer(), s2.as_pointer(),) })); assert!(({ Secondary::operator_lt(s1.as_pointer(), s2.as_pointer(),) })); assert!(({ Secondary::operator_ge(s2.as_pointer(), s1.as_pointer(),) })); assert!(!({ Secondary::operator_lt(s2.as_pointer(), s1.as_pointer(),) })); @@ -429,4 +388,45 @@ fn main_0() -> i32 { ); return 0; } +impl WeaklyEqualityComparableWith for Both { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); + } +} +impl WeaklyEqualityComparableWith for Cmp { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }) + && ({ this.with(|__s| __s.b) } == { _a0.with(|__s| __s.b) }); + } +} +impl WeaklyEqualityComparableWith for Eq { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }) + && ({ this.with(|__s| __s.b) } == { _a0.with(|__s| __s.b) }); + } +} +impl WeaklyEqualityComparableWith for Inner { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.x) } == { _a0.with(|__s| __s.x) }); + } +} +impl WeaklyEqualityComparableWith for Outer { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ WeaklyEqualityComparableWith::equal(field_ptr!(this, i), field_ptr!(_a0, i)) }) + && ({ this.with(|__s| __s.y) } == { _a0.with(|__s| __s.y) }); + } +} +impl WeaklyEqualityComparableWith for PtrMember { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.p.clone()) } == { _a0.with(|__s| __s.p.clone()) }); + } +} +impl WeaklyEqualityComparableWith for Secondary { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); + } + fn not_equal(this: Ptr, _a0: Ptr) -> bool { + return !({ WeaklyEqualityComparableWith::equal((this).clone(), (_a0).clone()) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_comparison_free.rs b/tests/unit/out/refcount/operator_comparison_free.rs index 4d00fa46e3..6ebfb63406 100644 --- a/tests/unit/out/refcount/operator_comparison_free.rs +++ b/tests/unit/out/refcount/operator_comparison_free.rs @@ -28,30 +28,22 @@ impl CppLess for S { operator_lt_0(a.clone(), b.clone()) } } -impl WeaklyEqualityComparableWith for S { - fn equal(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); - } -} -pub fn operator_ne_1(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.v) } != { b.with(|__s| __s.v) }); -} pub fn operator_lt_0(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } < { b.with(|__s| __s.v) }); } -pub fn operator_gt_2(a: Ptr, b: Ptr) -> bool { +pub fn operator_gt_1(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } > { b.with(|__s| __s.v) }); } -pub fn operator_le_3(a: Ptr, b: Ptr) -> bool { +pub fn operator_le_2(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } <= { b.with(|__s| __s.v) }); } -pub fn operator_ge_4(a: Ptr, b: Ptr) -> bool { +pub fn operator_ge_3(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } >= { b.with(|__s| __s.v) }); } -pub fn operator_lt_5(a: Ptr, mut b: i32) -> bool { +pub fn operator_lt_4(a: Ptr, mut b: i32) -> bool { return ({ a.with(|__s| __s.v) } < { b }); } -pub fn operator_lt_6(mut a: i32, b: Ptr) -> bool { +pub fn operator_lt_5(mut a: i32, b: Ptr) -> bool { return ({ a } < { b.with(|__s| __s.v) }); } #[derive( @@ -76,21 +68,16 @@ impl CppLess for V { operator_lt_7(a.read(), b.read()) } } -impl WeaklyEqualityComparableWith for V { - fn equal(a: Ptr, b: Ptr) -> bool { - operator_eq_8(a.read(), b.read()) - } -} pub fn operator_eq_8(mut a: V, mut b: V) -> bool { return (a.v == b.v); } -pub fn operator_ne_9(mut a: V, mut b: V) -> bool { +pub fn operator_ne_6(mut a: V, mut b: V) -> bool { return (a.v != b.v); } pub fn operator_lt_7(mut a: V, mut b: V) -> bool { return (a.v < b.v); } -pub fn operator_gt_10(mut a: V, mut b: V) -> bool { +pub fn operator_gt_9(mut a: V, mut b: V) -> bool { return (a.v > b.v); } pub fn main() { @@ -102,22 +89,38 @@ fn main_0() -> i32 { let mut y: V = V { v: 2 }; let mut z: V = V { v: 1 }; assert!(({ operator_eq_8(x, z,) })); - assert!(({ operator_ne_9(x, y,) })); + assert!(({ operator_ne_6(x, y,) })); assert!(({ operator_lt_7(x, y,) })); - assert!(({ operator_gt_10(y, x,) })); + assert!(({ operator_gt_9(y, x,) })); assert!(!({ operator_lt_7(y, x,) })); let a: Value = Rc::new(RefCell::new(S { v: 1 })); let b: Value = Rc::new(RefCell::new(S { v: 2 })); let c: Value = Rc::new(RefCell::new(S { v: 1 })); assert!(({ WeaklyEqualityComparableWith::equal(a.as_pointer(), c.as_pointer(),) })); - assert!(({ operator_ne_1(a.as_pointer(), b.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::not_equal(a.as_pointer(), b.as_pointer(),) })); assert!(({ operator_lt_0(a.as_pointer(), b.as_pointer(),) })); - assert!(({ operator_gt_2(b.as_pointer(), a.as_pointer(),) })); - assert!(({ operator_le_3(a.as_pointer(), c.as_pointer(),) })); - assert!(({ operator_ge_4(a.as_pointer(), c.as_pointer(),) })); + assert!(({ operator_gt_1(b.as_pointer(), a.as_pointer(),) })); + assert!(({ operator_le_2(a.as_pointer(), c.as_pointer(),) })); + assert!(({ operator_ge_3(a.as_pointer(), c.as_pointer(),) })); assert!(!({ operator_lt_0(b.as_pointer(), a.as_pointer(),) })); - assert!(({ operator_lt_5(a.as_pointer(), 5,) })); - assert!(({ operator_lt_6(0, a.as_pointer(),) })); + assert!(({ operator_lt_4(a.as_pointer(), 5,) })); + assert!(({ operator_lt_5(0, a.as_pointer(),) })); return 0; } +impl WeaklyEqualityComparableWith for S { + fn equal(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); + } + fn not_equal(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.v) } != { b.with(|__s| __s.v) }); + } +} +impl WeaklyEqualityComparableWith for V { + fn not_equal(a: Ptr, b: Ptr) -> bool { + operator_ne_6(a.read(), b.read()) + } + fn equal(a: Ptr, b: Ptr) -> bool { + operator_eq_8(a.read(), b.read()) + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_comparison_member.rs b/tests/unit/out/refcount/operator_comparison_member.rs index f6224ca220..d0d5e86497 100644 --- a/tests/unit/out/refcount/operator_comparison_member.rs +++ b/tests/unit/out/refcount/operator_comparison_member.rs @@ -24,9 +24,6 @@ pub struct S { pub v: i32, } impl S { - pub fn operator_ne(this: Ptr, o: Ptr) -> bool { - return ({ this.with(|__s| __s.v) } != { o.with(|__s| __s.v) }); - } pub fn operator_lt_3(this: Ptr, o: Ptr) -> bool { return ({ this.with(|__s| __s.v) } < { o.with(|__s| __s.v) }); } @@ -43,11 +40,6 @@ impl S { return (this.with(|__s| __s.v) < o); } } -impl WeaklyEqualityComparableWith for S { - fn equal(this: Ptr, o: Ptr) -> bool { - return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } -} impl CppLess for S { fn less(this: Ptr, o: Ptr) -> bool { S::operator_lt_3(this.clone(), o.clone()) @@ -62,7 +54,7 @@ fn main_0() -> i32 { let b: Value = Rc::new(RefCell::new(S { v: 2 })); let c: Value = Rc::new(RefCell::new(S { v: 1 })); assert!(({ WeaklyEqualityComparableWith::equal(a.as_pointer(), c.as_pointer(),) })); - assert!(({ S::operator_ne(a.as_pointer(), b.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::not_equal(a.as_pointer(), b.as_pointer(),) })); assert!(({ S::operator_lt_3(a.as_pointer(), b.as_pointer(),) })); assert!(({ S::operator_gt(b.as_pointer(), a.as_pointer(),) })); assert!(({ S::operator_le(a.as_pointer(), c.as_pointer(),) })); @@ -71,4 +63,12 @@ fn main_0() -> i32 { assert!(({ S::operator_lt_7(a.as_pointer(), 5,) })); return 0; } +impl WeaklyEqualityComparableWith for S { + fn equal(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } + fn not_equal(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } != { o.with(|__s| __s.v) }); + } +} 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 9e15867561..e616eb253b 100644 --- a/tests/unit/out/refcount/operator_comparison_nonbool.rs +++ b/tests/unit/out/refcount/operator_comparison_nonbool.rs @@ -25,21 +25,16 @@ pub struct X { } impl CppLess for X { fn less(a: Ptr, b: Ptr) -> bool { - ((operator_lt_0(a.read(), b.read())) != 0) + ((operator_lt_1(a.read(), b.read())) != 0) } } -impl WeaklyEqualityComparableWith for X { - fn equal(a: Ptr, b: Ptr) -> bool { - ((operator_eq_1(a.read(), b.read())) != 0) - } -} -pub fn operator_eq_1(mut a: X, mut b: X) -> i32 { +pub fn operator_eq_2(mut a: X, mut b: X) -> i32 { return if (a.v == b.v) { 2 } else { 0 }; } -pub fn operator_ne_2(mut a: X, mut b: X) -> i32 { +pub fn operator_ne_0(mut a: X, mut b: X) -> i32 { return if (a.v != b.v) { 3 } else { 0 }; } -pub fn operator_lt_0(mut a: X, mut b: X) -> i32 { +pub fn operator_lt_1(mut a: X, mut b: X) -> i32 { return if (a.v < b.v) { 4 } else { 0 }; } pub fn operator_gt_3(mut a: X, mut b: X) -> i32 { @@ -135,11 +130,6 @@ impl CppLess for Mixed { ((Mixed::operator_lt(this.clone(), o.clone())) != 0) } } -impl WeaklyEqualityComparableWith for Mixed { - fn equal(this: Ptr, o: Ptr) -> bool { - ((Mixed::operator_eq(this.clone(), o.clone())) != 0) - } -} #[derive( Copy, Clone, @@ -192,14 +182,6 @@ impl CppLess for Boolish { } } } -impl WeaklyEqualityComparableWith for Boolish { - fn equal(a: Ptr, b: Ptr) -> bool { - { - let __cmp = operator_eq_7(a.read(), b.read()); - MyBool::to_bool(Rc::new(RefCell::new(__cmp)).as_pointer()) - } - } -} pub fn operator_eq_7(mut a: Boolish, mut b: Boolish) -> MyBool { return { let __v: Value = Rc::new(RefCell::new(::zero_init())); @@ -269,14 +251,6 @@ impl RefInt { return ref_true_8.with(|v| v.as_pointer()); } } -impl WeaklyEqualityComparableWith for RefInt { - fn equal(this: Ptr, _a0: Ptr) -> bool { - { - let __cmp = RefInt::operator_eq(this.clone(), _a0.clone()); - RefBool::to_bool(__cmp.clone()) - } - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -285,10 +259,10 @@ fn main_0() -> i32 { let mut a: X = X { v: 1 }; let mut b: X = X { v: 2 }; let mut c: X = X { v: 1 }; - assert!((({ operator_eq_1(a, c,) }) == 2)); - assert!((({ operator_eq_1(a, b,) }) == 0)); - assert!((({ operator_ne_2(a, b,) }) == 3)); - assert!((({ operator_lt_0(a, b,) }) == 4)); + assert!((({ operator_eq_2(a, c,) }) == 2)); + assert!((({ operator_eq_2(a, b,) }) == 0)); + assert!((({ operator_ne_0(a, b,) }) == 3)); + assert!((({ operator_lt_1(a, b,) }) == 4)); assert!((({ operator_gt_3(b, a,) }) == 5)); assert!((({ operator_le_4(a, c,) }) == 6)); assert!((({ operator_ge_5(a, c,) }) == 7)); @@ -371,7 +345,7 @@ fn main_0() -> i32 { let __it: Value> = Rc::new(RefCell::new(ris.decay())); let __last: Value> = Rc::new(RefCell::new(ris.decay().offset((2) as isize))); - while !>::equal(__it.as_pointer(), __last.as_pointer()) + while >::not_equal(__it.as_pointer(), __last.as_pointer()) && !WeaklyEqualityComparableWith::equal( __it.borrow().iter_deref(), ri2.as_pointer().clone(), @@ -384,6 +358,35 @@ fn main_0() -> i32 { ); return 0; } +impl WeaklyEqualityComparableWith for Boolish { + fn equal(a: Ptr, b: Ptr) -> bool { + { + let __cmp = operator_eq_7(a.read(), b.read()); + MyBool::to_bool(Rc::new(RefCell::new(__cmp)).as_pointer()) + } + } +} +impl WeaklyEqualityComparableWith for Mixed { + fn equal(this: Ptr, o: Ptr) -> bool { + ((Mixed::operator_eq(this.clone(), o.clone())) != 0) + } +} +impl WeaklyEqualityComparableWith for RefInt { + fn equal(this: Ptr, _a0: Ptr) -> bool { + { + let __cmp = RefInt::operator_eq(this.clone(), _a0.clone()); + RefBool::to_bool(__cmp.clone()) + } + } +} +impl WeaklyEqualityComparableWith for X { + fn not_equal(a: Ptr, b: Ptr) -> bool { + ((operator_ne_0(a.read(), b.read())) != 0) + } + fn equal(a: Ptr, b: Ptr) -> bool { + ((operator_eq_2(a.read(), b.read())) != 0) + } +} pub fn __cpp2rust_init_globals() { let _ = ref_true_8.with(|_| ()); } diff --git a/tests/unit/out/refcount/operator_comparison_noncopyable.rs b/tests/unit/out/refcount/operator_comparison_noncopyable.rs index f9ed7ab8cb..8d00d4fb59 100644 --- a/tests/unit/out/refcount/operator_comparison_noncopyable.rs +++ b/tests/unit/out/refcount/operator_comparison_noncopyable.rs @@ -6,11 +6,6 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -impl WeaklyEqualityComparableWith for S { - fn equal(x: Ptr, y: Ptr) -> bool { - return ({ x.with(|__s| __s.data_) } == { y.with(|__s| __s.data_) }); - } -} pub fn operator_lt_0(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.data_) } < { y.with(|__s| __s.data_) }); } @@ -54,4 +49,9 @@ fn main_0() -> i32 { assert!(!({ operator_lt_0(b.as_pointer(), a.as_pointer(),) })); return 0; } +impl WeaklyEqualityComparableWith for S { + fn equal(x: Ptr, y: Ptr) -> bool { + return ({ x.with(|__s| __s.data_) } == { y.with(|__s| __s.data_) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_friend.rs b/tests/unit/out/refcount/operator_friend.rs index ad1cebf1da..6d240efaf6 100644 --- a/tests/unit/out/refcount/operator_friend.rs +++ b/tests/unit/out/refcount/operator_friend.rs @@ -6,12 +6,6 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -impl WeaklyEqualityComparableWith for Defaulted { - fn equal(_a0: Ptr, _a1: Ptr) -> bool { - return ({ _a0.with(|__s| __s.a) } == { _a1.with(|__s| __s.a) }) - && ({ _a0.with(|__s| __s.b) } == { _a1.with(|__s| __s.b) }); - } -} #[derive( Copy, Clone, @@ -43,11 +37,6 @@ pub fn operator_cmp_0(_a0: Ptr, _a1: Ptr) -> std::cm } return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } -impl WeaklyEqualityComparableWith for DefaultedOrd { - fn equal(_a0: Ptr, _a1: Ptr) -> bool { - return ({ _a0.with(|__s| __s.a) } == { _a1.with(|__s| __s.a) }); - } -} #[derive( Copy, Clone, @@ -70,11 +59,6 @@ impl CppLess for DefaultedOrd { operator_cmp_0(_a0.clone(), _a1.clone()) == std::cmp::Ordering::Less } } -impl WeaklyEqualityComparableWith for Inline { - fn equal(x: Ptr, y: Ptr) -> bool { - return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }); - } -} pub fn operator_lt_1(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.a) } < { y.with(|__s| __s.a) }); } @@ -122,23 +106,10 @@ pub struct OutOfLine { #[offset(0)] pub a: i32, } -impl WeaklyEqualityComparableWith for OutOfLine { - fn equal(x: Ptr, y: Ptr) -> bool { - return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }); - } -} -pub fn operator_ne_3(x: Ptr, y: Ptr) -> bool { - return !({ WeaklyEqualityComparableWith::equal((x).clone(), (y).clone()) }); -} -impl WeaklyEqualityComparableWith for Tmpl_int_ { - fn equal(x: Ptr, y: Ptr) -> bool { - return ({ x.with(|__s| __s.v) } == { y.with(|__s| __s.v) }); - } -} -pub fn operator_lt_4(x: Ptr, y: Ptr) -> bool { +pub fn operator_lt_3(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.v) } < { y.with(|__s| __s.v) }); } -pub fn operator_eq_5(x: Ptr, y: Ptr) -> bool { +pub fn operator_eq_4(x: Ptr, y: Ptr) -> bool { return ({ (x.with(|__s| __s.v) as i64) } == { y.with(|__s| __s.v) }); } #[derive( @@ -160,7 +131,7 @@ pub struct Tmpl_int_ { } impl CppLess for Tmpl_int_ { fn less(x: Ptr, y: Ptr) -> bool { - operator_lt_4(x.clone(), y.clone()) + operator_lt_3(x.clone(), y.clone()) } } #[derive( @@ -180,11 +151,6 @@ pub struct Tmpl_long_ { #[offset(0)] pub v: i64, } -impl WeaklyEqualityComparableWith for TmplDefaulted_int_ { - fn equal(_a0: Ptr, _a1: Ptr) -> bool { - return ({ _a0.with(|__s| __s.v) } == { _a1.with(|__s| __s.v) }); - } -} #[derive( Copy, Clone, @@ -242,18 +208,18 @@ fn main_0() -> i32 { let f2: Value = Rc::new(RefCell::new(OutOfLine { a: 4 })); let f3: Value = Rc::new(RefCell::new(OutOfLine { a: 5 })); assert!(({ WeaklyEqualityComparableWith::equal(f1.as_pointer(), f2.as_pointer(),) })); - assert!(({ operator_ne_3(f1.as_pointer(), f3.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::not_equal(f1.as_pointer(), f3.as_pointer(),) })); assert!(!({ WeaklyEqualityComparableWith::equal(f1.as_pointer(), f3.as_pointer(),) })); let t1: Value = Rc::new(RefCell::new(Tmpl_int_ { v: 1 })); let t2: Value = Rc::new(RefCell::new(Tmpl_int_ { v: 2 })); let t3: Value = Rc::new(RefCell::new(Tmpl_int_ { v: 1 })); assert!(({ WeaklyEqualityComparableWith::equal(t1.as_pointer(), t3.as_pointer(),) })); assert!(!({ WeaklyEqualityComparableWith::equal(t1.as_pointer(), t2.as_pointer(),) })); - assert!(({ operator_lt_4(t1.as_pointer(), t2.as_pointer(),) })); + assert!(({ operator_lt_3(t1.as_pointer(), t2.as_pointer(),) })); let u1: Value = Rc::new(RefCell::new(Tmpl_long_ { v: 1_i64 })); let u2: Value = Rc::new(RefCell::new(Tmpl_long_ { v: 2_i64 })); - assert!(({ operator_eq_5(t1.as_pointer(), u1.as_pointer(),) })); - assert!(!({ operator_eq_5(t1.as_pointer(), u2.as_pointer(),) })); + assert!(({ operator_eq_4(t1.as_pointer(), u1.as_pointer(),) })); + assert!(!({ operator_eq_4(t1.as_pointer(), u2.as_pointer(),) })); let v1: Value = Rc::new(RefCell::new(TmplDefaulted_int_ { v: 7 })); let v2: Value = Rc::new(RefCell::new(TmplDefaulted_int_ { v: 7 })); let v3: Value = Rc::new(RefCell::new(TmplDefaulted_int_ { v: 8 })); @@ -262,4 +228,38 @@ fn main_0() -> i32 { assert!(!({ WeaklyEqualityComparableWith::equal(v1.as_pointer(), v3.as_pointer(),) })); return 0; } +impl WeaklyEqualityComparableWith for Defaulted { + fn equal(_a0: Ptr, _a1: Ptr) -> bool { + return ({ _a0.with(|__s| __s.a) } == { _a1.with(|__s| __s.a) }) + && ({ _a0.with(|__s| __s.b) } == { _a1.with(|__s| __s.b) }); + } +} +impl WeaklyEqualityComparableWith for DefaultedOrd { + fn equal(_a0: Ptr, _a1: Ptr) -> bool { + return ({ _a0.with(|__s| __s.a) } == { _a1.with(|__s| __s.a) }); + } +} +impl WeaklyEqualityComparableWith for Inline { + fn equal(x: Ptr, y: Ptr) -> bool { + return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }); + } +} +impl WeaklyEqualityComparableWith for OutOfLine { + fn equal(x: Ptr, y: Ptr) -> bool { + return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }); + } + fn not_equal(x: Ptr, y: Ptr) -> bool { + return !({ WeaklyEqualityComparableWith::equal((x).clone(), (y).clone()) }); + } +} +impl WeaklyEqualityComparableWith for TmplDefaulted_int_ { + fn equal(_a0: Ptr, _a1: Ptr) -> bool { + return ({ _a0.with(|__s| __s.v) } == { _a1.with(|__s| __s.v) }); + } +} +impl WeaklyEqualityComparableWith for Tmpl_int_ { + fn equal(x: Ptr, y: Ptr) -> bool { + return ({ x.with(|__s| __s.v) } == { y.with(|__s| __s.v) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_three_way.rs b/tests/unit/out/refcount/operator_three_way.rs index 3924a32fcf..54907d11aa 100644 --- a/tests/unit/out/refcount/operator_three_way.rs +++ b/tests/unit/out/refcount/operator_three_way.rs @@ -34,11 +34,6 @@ impl S { return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } } -impl WeaklyEqualityComparableWith for S { - fn equal(this: Ptr, o: Ptr) -> bool { - return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } -} impl CppLess for S { fn less(this: Ptr, o: Ptr) -> bool { S::operator_cmp(this.clone(), o.clone()) == std::cmp::Ordering::Less @@ -62,4 +57,9 @@ fn main_0() -> i32 { ); return 0; } +impl WeaklyEqualityComparableWith for S { + fn equal(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_traits.rs b/tests/unit/out/refcount/operator_traits.rs index 54148f238d..7d3202e71e 100644 --- a/tests/unit/out/refcount/operator_traits.rs +++ b/tests/unit/out/refcount/operator_traits.rs @@ -50,11 +50,6 @@ pub struct Eq { #[offset(0)] pub v: i32, } -impl WeaklyEqualityComparableWith for Eq { - fn equal(this: Ptr, o: Ptr) -> bool { - return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } -} #[derive( Copy, Clone, @@ -77,11 +72,6 @@ impl Cmp { return std::cmp::Ord::cmp(&(this.with(|__s| __s.v)), &(o.with(|__s| __s.v))); } } -impl WeaklyEqualityComparableWith for Cmp { - fn equal(this: Ptr, o: Ptr) -> bool { - return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } -} impl CppLess for Cmp { fn less(this: Ptr, o: Ptr) -> bool { Cmp::operator_cmp(this.clone(), o.clone()) == std::cmp::Ordering::Less @@ -112,11 +102,6 @@ impl CppLess for Free { pub fn operator_lt_0(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } < { b.with(|__s| __s.v) }); } -impl WeaklyEqualityComparableWith for Free { - fn equal(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); - } -} #[derive( Copy, Clone, @@ -168,7 +153,7 @@ fn main_0() -> i32 { ({ let __it: Value> = Rc::new(RefCell::new(eqs.decay().begin())); let __last: Value> = Rc::new(RefCell::new(eqs.decay().end())); - while !>::equal(__it.as_pointer(), __last.as_pointer()) + while >::not_equal(__it.as_pointer(), __last.as_pointer()) && !WeaklyEqualityComparableWith::equal( __it.borrow().iter_deref(), two.as_pointer().clone(), @@ -186,7 +171,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new({ let __it: Value> = Rc::new(RefCell::new(eqs.decay().begin())); let __last: Value> = Rc::new(RefCell::new(eqs.decay().end())); - while !>::equal(__it.as_pointer(), __last.as_pointer()) + while >::not_equal(__it.as_pointer(), __last.as_pointer()) && !WeaklyEqualityComparableWith::equal( __it.borrow().iter_deref(), nine.as_pointer().clone(), @@ -225,7 +210,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(cmps.decay().begin())); let __last: Value> = Rc::new(RefCell::new(cmps.decay().end())); - while !>::equal(__it.as_pointer(), __last.as_pointer()) + while >::not_equal(__it.as_pointer(), __last.as_pointer()) && !WeaklyEqualityComparableWith::equal( __it.borrow().iter_deref(), three.as_pointer().clone(), @@ -255,7 +240,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(frees.decay().begin())); let __last: Value> = Rc::new(RefCell::new(frees.decay().end())); - while !>::equal(__it.as_pointer(), __last.as_pointer()) + while >::not_equal(__it.as_pointer(), __last.as_pointer()) && !WeaklyEqualityComparableWith::equal( __it.borrow().iter_deref(), ftwo.as_pointer().clone(), @@ -304,4 +289,19 @@ fn main_0() -> i32 { ); return 0; } +impl WeaklyEqualityComparableWith for Cmp { + fn equal(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } +} +impl WeaklyEqualityComparableWith for Eq { + fn equal(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } +} +impl WeaklyEqualityComparableWith for Free { + fn equal(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/push_emplace_back.rs b/tests/unit/out/refcount/push_emplace_back.rs index aa3812e294..d100808c4b 100644 --- a/tests/unit/out/refcount/push_emplace_back.rs +++ b/tests/unit/out/refcount/push_emplace_back.rs @@ -89,7 +89,7 @@ pub fn push_local_from_field_1(mut jpg: Ptr, mut cond: bool) { let mut __v = Vec::new(); let __it: Value> = Rc::new(RefCell::new(head.decay())); let __last: Value> = Rc::new(RefCell::new(head.decay().offset((3) as isize))); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { __v.push((__it.borrow().iter_deref().read())); __it.borrow_mut().iter_inc(); } @@ -121,7 +121,7 @@ pub fn emplace_local_from_field_4(mut jpg: Ptr, mut cond: bool) { let __it: Value> = Rc::new(RefCell::new(head.decay())); let __last: Value> = Rc::new(RefCell::new(head.decay().offset((3) as isize))); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { __v.push((__it.borrow().iter_deref().read())); __it.borrow_mut().iter_inc(); } @@ -375,7 +375,7 @@ pub fn emplace_from_element_14(mut v: Ptr>>) { let __it: Value> = Rc::new(RefCell::new(({ (*p.borrow()).clone() }))); let __last: Value> = Rc::new(RefCell::new((*p.borrow()).offset((3) as isize))); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { __v.push((__it.borrow().iter_deref().read())); __it.borrow_mut().iter_inc(); } @@ -477,7 +477,7 @@ pub fn emplace_from_sibling_18(mut s: Ptr) { let __it: Value> = Rc::new(RefCell::new(({ (*p.borrow()).clone() }))); let __last: Value> = Rc::new(RefCell::new((*p.borrow()).offset((3) as isize))); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { __v.push((__it.borrow().iter_deref().read())); __it.borrow_mut().iter_inc(); } diff --git a/tests/unit/out/refcount/size_t_ssize_t.rs b/tests/unit/out/refcount/size_t_ssize_t.rs index e4cbf076bc..65ec82e18c 100644 --- a/tests/unit/out/refcount/size_t_ssize_t.rs +++ b/tests/unit/out/refcount/size_t_ssize_t.rs @@ -36,7 +36,7 @@ pub fn size_t_in_rules_3() { let __first: Value> = Rc::new(RefCell::new(src.decay())); let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); let mut __out = (dst.decay()).reinterpret_cast::(); - while !>::equal(__first.as_pointer(), __last.as_pointer()) { + while >::not_equal(__first.as_pointer(), __last.as_pointer()) { __out .iter_deref() .write(((__first.borrow().iter_deref().read()) as u64)); @@ -110,7 +110,7 @@ pub fn size_t_in_rules_3() { .as_pointer(), ) { (__tmp_2, __tmp_4) => { - !WeaklyEqualityComparableWith::equal((__tmp_2).clone(), (__tmp_4).clone()) + WeaklyEqualityComparableWith::not_equal((__tmp_2).clone(), (__tmp_4).clone()) } }); assert!( @@ -212,7 +212,7 @@ pub fn size_t_in_rules_3() { let mut __v = 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 !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { __v.push(((__it.borrow().iter_deref().read()) as u64)); __it.borrow_mut().iter_inc(); } @@ -230,7 +230,7 @@ pub fn size_t_in_rules_3() { { let __it: Value> = Rc::new(RefCell::new(v.decay().begin())); let __last: Value> = Rc::new(RefCell::new(v.decay().end())); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { __it.borrow() .iter_deref() .write(Clone::clone(&({ ((*k.borrow()) as u64) }))); @@ -336,7 +336,7 @@ pub fn size_t_in_rules_3() { Rc::new(RefCell::new(v3.decay().begin())); let __last: Value> = Rc::new(RefCell::new(v3.decay().end())); - while !>::equal( + while >::not_equal( __it.as_pointer(), __last.as_pointer(), ) && !WeaklyEqualityComparableWith::equal( @@ -353,7 +353,7 @@ pub fn size_t_in_rules_3() { Rc::new(RefCell::new(v3.decay().end())).as_pointer(), ) { (__tmp_18, __tmp_20) => { - !WeaklyEqualityComparableWith::equal((__tmp_18).clone(), (__tmp_20).clone()) + WeaklyEqualityComparableWith::not_equal((__tmp_18).clone(), (__tmp_20).clone()) } }); assert!( diff --git a/tests/unit/out/refcount/sort_no_copy.rs b/tests/unit/out/refcount/sort_no_copy.rs index 31ce2fabff..0fc9872366 100644 --- a/tests/unit/out/refcount/sort_no_copy.rs +++ b/tests/unit/out/refcount/sort_no_copy.rs @@ -126,11 +126,6 @@ impl CppLess for Bag { pub fn operator_lt_4(a: Ptr, b: Ptr) -> bool { return ({ (*a.upgrade().deref()).items.len() } < { (*b.upgrade().deref()).items.len() }); } -impl WeaklyEqualityComparableWith for Bag { - fn equal(a: Ptr, b: Ptr) -> bool { - return ({ (*a.upgrade().deref()).items.len() } == { (*b.upgrade().deref()).items.len() }); - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -432,7 +427,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(bag_vec.decay().begin())); let __last: Value> = Rc::new(RefCell::new(bag_vec.decay().end())); - while !>::equal(__it.as_pointer(), __last.as_pointer()) + while >::not_equal(__it.as_pointer(), __last.as_pointer()) && !WeaklyEqualityComparableWith::equal( __it.borrow().iter_deref(), bags.decay().offset(1).clone(), @@ -456,9 +451,10 @@ fn main_0() -> i32 { let __last: Value> = Rc::new(RefCell::new(bag_vec.decay().end())); let mut __best = __it.borrow().clone(); - if !>::equal(__it.as_pointer(), __last.as_pointer()) { + if >::not_equal(__it.as_pointer(), __last.as_pointer()) { __it.borrow_mut().iter_inc(); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) + { if CppLess::less(__best.iter_deref(), __it.borrow().iter_deref()) { __best = __it.borrow().clone(); } @@ -617,6 +613,11 @@ fn main_0() -> i32 { ); return copies_0.with(|rc| *rc.borrow()); } +impl WeaklyEqualityComparableWith for Bag { + fn equal(a: Ptr, b: Ptr) -> bool { + return ({ (*a.upgrade().deref()).items.len() } == { (*b.upgrade().deref()).items.len() }); + } +} pub fn __cpp2rust_init_globals() { let _ = copies_0.with(|_| ()); } diff --git a/tests/unit/out/refcount/stdcopy.rs b/tests/unit/out/refcount/stdcopy.rs index b20a77a8af..d27bbf3f5e 100644 --- a/tests/unit/out/refcount/stdcopy.rs +++ b/tests/unit/out/refcount/stdcopy.rs @@ -42,7 +42,7 @@ fn main_0() -> i32 { let __first: Value> = Rc::new(RefCell::new(input.decay())); let __last: Value> = Rc::new(RefCell::new(input.decay().offset((3) as isize))); let mut __out = output.decay(); - while !>::equal(__first.as_pointer(), __last.as_pointer()) { + while >::not_equal(__first.as_pointer(), __last.as_pointer()) { __out .iter_deref() .write((__first.borrow().iter_deref().read())); @@ -60,7 +60,7 @@ fn main_0() -> i32 { let __first: Value> = Rc::new(RefCell::new(input.decay())); let __last: Value> = Rc::new(RefCell::new(input.decay().offset((3) as isize))); let mut __out = widened.decay().begin(); - while !>::equal(__first.as_pointer(), __last.as_pointer()) { + while >::not_equal(__first.as_pointer(), __last.as_pointer()) { __out .iter_deref() .write(((__first.borrow().iter_deref().read()) as i64)); @@ -88,7 +88,7 @@ fn main_0() -> i32 { let __first: Value> = Rc::new(RefCell::new(input.decay())); let __last: Value> = Rc::new(RefCell::new(input.decay().offset((3) as isize))); let mut __out = constructed.decay().begin(); - while !>::equal(__first.as_pointer(), __last.as_pointer()) { + while >::not_equal(__first.as_pointer(), __last.as_pointer()) { __out .iter_deref() .write(>::cpp_from( @@ -113,7 +113,7 @@ fn main_0() -> i32 { let __first: Value> = Rc::new(RefCell::new(wide.decay())); let __last: Value> = Rc::new(RefCell::new(wide.decay().offset((2) as isize))); let mut __out = floating.decay().begin(); - while !>::equal(__first.as_pointer(), __last.as_pointer()) { + while >::not_equal(__first.as_pointer(), __last.as_pointer()) { __out .iter_deref() .write(((__first.borrow().iter_deref().read()) as f64)); diff --git a/tests/unit/out/refcount/stdcopy_ostream.rs b/tests/unit/out/refcount/stdcopy_ostream.rs index c4702a9bcb..125d536561 100644 --- a/tests/unit/out/refcount/stdcopy_ostream.rs +++ b/tests/unit/out/refcount/stdcopy_ostream.rs @@ -32,7 +32,7 @@ fn main_0() -> i32 { let __last: Value> = Rc::new(RefCell::new(__tmp_1)); let __out = &mut (*ofs.borrow_mut()); let mut __bytes: Vec = Vec::new(); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { __bytes.push(__it.borrow().iter_deref().read() as u8); __it.borrow_mut().iter_inc(); } diff --git a/tests/unit/out/refcount/unboxed_conditional_iterator.rs b/tests/unit/out/refcount/unboxed_conditional_iterator.rs index bced1d3af9..393e236257 100644 --- a/tests/unit/out/refcount/unboxed_conditional_iterator.rs +++ b/tests/unit/out/refcount/unboxed_conditional_iterator.rs @@ -59,7 +59,7 @@ pub fn lehmer_3(mut sigma: Ptr, mut len: u32, mut code: Ptr) { Rc::new(RefCell::new(items.decay().begin())); let __last: Value> = Rc::new(RefCell::new(items.decay().end())); - while !>::equal( + while >::not_equal( __it.as_pointer(), __last.as_pointer(), ) && !WeaklyEqualityComparableWith::equal( @@ -73,7 +73,10 @@ pub fn lehmer_3(mut sigma: Ptr, mut len: u32, mut code: Ptr) { assert!( match (Rc::new(RefCell::new(items.decay().end())).as_pointer(),) { (__tmp_0,) => { - !WeaklyEqualityComparableWith::equal(it.as_pointer(), (__tmp_0).clone()) + WeaklyEqualityComparableWith::not_equal( + it.as_pointer(), + (__tmp_0).clone(), + ) } } ); @@ -97,7 +100,9 @@ pub fn sum_4(v: Ptr>) -> i32 { { let it: Value> = Rc::new(RefCell::new(v.decay().begin())); 'loop_: while match (Rc::new(RefCell::new(v.decay().end())).as_pointer(),) { - (__tmp_2,) => !WeaklyEqualityComparableWith::equal(it.as_pointer(), (__tmp_2).clone()), + (__tmp_2,) => { + WeaklyEqualityComparableWith::not_equal(it.as_pointer(), (__tmp_2).clone()) + } } { 'for_body: { s += (({ (*it.borrow()).iter_deref() }).read()); diff --git a/tests/unit/out/refcount/vector.rs b/tests/unit/out/refcount/vector.rs index 247311d0fe..37f11f02c4 100644 --- a/tests/unit/out/refcount/vector.rs +++ b/tests/unit/out/refcount/vector.rs @@ -186,7 +186,7 @@ fn main_0() -> i32 { let mut temp_vec: Vec = Vec::new(); let __it: Value> = Rc::new(RefCell::new(src.decay().begin())); let __last: Value> = Rc::new(RefCell::new(src.decay().end())); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { temp_vec.push((__it.borrow().iter_deref().read())); __it.borrow_mut().iter_inc(); } @@ -692,7 +692,7 @@ fn main_0() -> i32 { let mut temp_vec: Vec = Vec::new(); let __it: Value> = Rc::new(RefCell::new(ints.decay())); let __last: Value> = Rc::new(RefCell::new(ints.decay().offset((3) as isize))); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { temp_vec.push(((__it.borrow().iter_deref().read()) as i64)); __it.borrow_mut().iter_inc(); } @@ -718,7 +718,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(more.decay().begin())); let __last: Value> = Rc::new(RefCell::new(more.decay().end())); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { temp_vec.push(((__it.borrow().iter_deref().read()) as i64)); __it.borrow_mut().iter_inc(); } @@ -737,7 +737,7 @@ fn main_0() -> i32 { let mut temp_vec: Vec = Vec::new(); let __it: Value> = Rc::new(RefCell::new(ints.decay())); let __last: Value> = Rc::new(RefCell::new(ints.decay().offset((2) as isize))); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { temp_vec.push(((__it.borrow().iter_deref().read()) as f64)); __it.borrow_mut().iter_inc(); } @@ -759,7 +759,7 @@ fn main_0() -> i32 { let mut temp_vec: Vec = Vec::new(); let __it: Value> = Rc::new(RefCell::new(ints.decay())); let __last: Value> = Rc::new(RefCell::new(ints.decay().offset((3) as isize))); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { temp_vec.push(>::cpp_from( __it.borrow().iter_deref(), )); @@ -785,7 +785,7 @@ fn main_0() -> i32 { Rc::new(RefCell::new(more.decay().begin())); let __last: Value> = Rc::new(RefCell::new(more.decay().end())); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { temp_vec.push((__it.borrow().iter_deref().read())); __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 0e69e3cfc8..939b203404 100644 --- a/tests/unit/out/refcount/vector_iter_range_ctor.rs +++ b/tests/unit/out/refcount/vector_iter_range_ctor.rs @@ -64,7 +64,7 @@ fn main_0() -> i32 { let mut __v = 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 !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { __v.push((__it.borrow().iter_deref().read())); __it.borrow_mut().iter_inc(); } @@ -76,7 +76,7 @@ fn main_0() -> i32 { let mut __v = 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 !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { __v.push(((__it.borrow().iter_deref().read()) as u64)); __it.borrow_mut().iter_inc(); } @@ -88,7 +88,7 @@ fn main_0() -> i32 { let mut __v = 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 !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { __v.push(((__it.borrow().iter_deref().read()) as i32)); __it.borrow_mut().iter_inc(); } @@ -101,7 +101,7 @@ fn main_0() -> i32 { let mut __v = Vec::new(); let __it: Value> = Rc::new(RefCell::new(src1.decay())); let __last: Value> = Rc::new(RefCell::new(src1.decay().to_end())); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { __v.push((__it.borrow().iter_deref().read())); __it.borrow_mut().iter_inc(); } @@ -120,7 +120,7 @@ fn main_0() -> i32 { let mut __v = Vec::new(); let __it: Value> = Rc::new(RefCell::new((start).clone())); let __last: Value> = Rc::new(RefCell::new(start.offset((len) as isize))); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { __v.push((__it.borrow().iter_deref().read())); __it.borrow_mut().iter_inc(); } @@ -157,7 +157,7 @@ fn main_0() -> i32 { m.as_pointer() .with(|__m: &Map, Value)>| __m.end()), )); - while !, Value)>>::equal( + while , Value)>>::not_equal( __it.as_pointer(), __last.as_pointer(), ) { @@ -198,7 +198,7 @@ fn main_0() -> i32 { m.as_pointer() .with(|__m: &Map, Value)>| __m.end()), )); - while !, Value)>>::equal( + while , Value)>>::not_equal( __it.as_pointer(), __last.as_pointer(), ) { @@ -227,7 +227,7 @@ fn main_0() -> i32 { let mut __v = Vec::new(); let __it: Value> = Rc::new(RefCell::new(ints.decay())); let __last: Value> = Rc::new(RefCell::new(ints.decay().offset((3) as isize))); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { __v.push(>::cpp_from( __it.borrow().iter_deref(), )); @@ -245,7 +245,7 @@ fn main_0() -> i32 { let __it: Value> = Rc::new(RefCell::new(readings.decay())); let __last: Value> = Rc::new(RefCell::new(readings.decay().offset((2) as isize))); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { __v.push(>::cpp_from( __it.borrow().iter_deref(), )); diff --git a/tests/unit/out/refcount/vector_with_allocator.rs b/tests/unit/out/refcount/vector_with_allocator.rs index 37193da02a..6020baa986 100644 --- a/tests/unit/out/refcount/vector_with_allocator.rs +++ b/tests/unit/out/refcount/vector_with_allocator.rs @@ -401,7 +401,7 @@ fn main_0() -> i32 { let mut __v = 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 !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { __v.push((__it.borrow().iter_deref().read())); __it.borrow_mut().iter_inc(); } @@ -413,7 +413,7 @@ fn main_0() -> i32 { let mut __v = 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 !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { __v.push(((__it.borrow().iter_deref().read()) as u64)); __it.borrow_mut().iter_inc(); } @@ -425,7 +425,7 @@ fn main_0() -> i32 { let mut __v = 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 !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { __v.push(((__it.borrow().iter_deref().read()) as i32)); __it.borrow_mut().iter_inc(); } @@ -438,7 +438,7 @@ fn main_0() -> i32 { let mut __v = Vec::new(); let __it: Value> = Rc::new(RefCell::new(src1.decay())); let __last: Value> = Rc::new(RefCell::new(src1.decay().to_end())); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { __v.push((__it.borrow().iter_deref().read())); __it.borrow_mut().iter_inc(); } @@ -454,7 +454,7 @@ fn main_0() -> i32 { let mut __v = Vec::new(); let __it: Value> = Rc::new(RefCell::new((start).clone())); let __last: Value> = Rc::new(RefCell::new(start.offset((len) as isize))); - while !>::equal(__it.as_pointer(), __last.as_pointer()) { + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { __v.push((__it.borrow().iter_deref().read())); __it.borrow_mut().iter_inc(); } diff --git a/tests/unit/out/unsafe/class.rs b/tests/unit/out/unsafe/class.rs index ece9c26b13..0b457cc02d 100644 --- a/tests/unit/out/unsafe/class.rs +++ b/tests/unit/out/unsafe/class.rs @@ -93,12 +93,6 @@ impl Counter { return (*this).v; } } -impl WeaklyEqualityComparableWithUnsafe for Counter { - unsafe fn equal(this: *const Self, o: *const Counter) -> bool { - (*(&raw const (*this).calls).cast_mut()).prefix_inc(); - return (((*this).v) == ((*o).v)); - } -} impl std::cmp::PartialEq for Counter { fn eq(&self, other: &Self) -> bool { unsafe { @@ -198,4 +192,10 @@ unsafe fn main_0() -> i32 { assert!(((ct.calls) == (10))); return 0; } +impl WeaklyEqualityComparableWithUnsafe for Counter { + unsafe fn equal(this: *const Self, o: *const Counter) -> bool { + (*(&raw const (*this).calls).cast_mut()).prefix_inc(); + return (((*this).v) == ((*o).v)); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/container_element_receiver.rs b/tests/unit/out/unsafe/container_element_receiver.rs index d038f9a5eb..313f7890e5 100644 --- a/tests/unit/out/unsafe/container_element_receiver.rs +++ b/tests/unit/out/unsafe/container_element_receiver.rs @@ -32,7 +32,7 @@ pub unsafe fn sum_1(v: *const Vec) -> i32 { let mut total: i32 = 0; { let mut it: UnsafeRandomAccessIterator = (*v).begin(); - 'loop_: while !WeaklyEqualityComparableWithUnsafe::equal(&it, &(*v).end()) { + 'loop_: while WeaklyEqualityComparableWithUnsafe::not_equal(&it, &(*v).end()) { 'for_body: { total += (*it.iter_deref()); } diff --git a/tests/unit/out/unsafe/copy_ctor.rs b/tests/unit/out/unsafe/copy_ctor.rs index 446e50d648..3f21fe6fe3 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -384,7 +384,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { vec_.end() }; let mut __v = Vec::new(); let mut __it = (__tmp_0).clone(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_1) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { __v.push(>::cpp_from( __it.iter_deref(), )); diff --git a/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs b/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs index 9d0fca0560..8c01e80d11 100644 --- a/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs +++ b/tests/unit/out/unsafe/elidable_iterator_copy_cxx11.rs @@ -26,14 +26,14 @@ unsafe fn main_0() -> i32 { let mut __tmp_2 = { v.begin() }; let mut __tmp_3 = { v.end() }; let mut __it = (__tmp_2).clone(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_3) + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &7) { __it.iter_inc(); } __it }; - assert!(!WeaklyEqualityComparableWithUnsafe::equal(&it, &v.end())); + assert!(WeaklyEqualityComparableWithUnsafe::not_equal(&it, &v.end())); assert!(((*it.iter_deref()) == (7))); { let mut __tmp_4 = { v.begin() }; diff --git a/tests/unit/out/unsafe/emplace_receiver_alias.rs b/tests/unit/out/unsafe/emplace_receiver_alias.rs index f1b13bbd4a..6547e096ea 100644 --- a/tests/unit/out/unsafe/emplace_receiver_alias.rs +++ b/tests/unit/out/unsafe/emplace_receiver_alias.rs @@ -32,7 +32,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { (&mut (*alias))[(0_usize)].as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = __tmp_0; - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_1) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { __v.push((*__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 b576a60cf0..d10debc89e 100644 --- a/tests/unit/out/unsafe/emplace_receiver_order.rs +++ b/tests/unit/out/unsafe/emplace_receiver_order.rs @@ -40,7 +40,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { rows[(0_usize)].as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = __tmp_0; - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_1) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -63,7 +63,8 @@ unsafe fn main_0() -> i32 { { rows[(0_usize)].as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = __tmp_3; - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_4) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_4) + { __v.push((*__it.iter_deref())); __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/find.rs b/tests/unit/out/unsafe/find.rs index 57d639a2b8..1c03f0b4ac 100644 --- a/tests/unit/out/unsafe/find.rs +++ b/tests/unit/out/unsafe/find.rs @@ -20,11 +20,6 @@ use std::rc::Rc; pub struct P { pub x: i32, } -impl WeaklyEqualityComparableWithUnsafe for P { - unsafe fn equal(this: *const Self, o: *const P) -> bool { - return (((*this).x) == ((*o).x)); - } -} impl std::cmp::PartialEq for P { fn eq(&self, other: &Self) -> bool { unsafe { @@ -58,14 +53,14 @@ unsafe fn main_0() -> i32 { let mut it: UnsafeRandomAccessIterator = { let mut __tmp_3 = { (v_end).clone() }; let mut __it = (v_begin).clone(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_3) + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &2) { __it.iter_inc(); } __it }; - let mut v_result_true: bool = !WeaklyEqualityComparableWithUnsafe::equal(&it, &v.end()); + let mut v_result_true: bool = WeaklyEqualityComparableWithUnsafe::not_equal(&it, &v.end()); let mut m: UnsafeMap = UnsafeMap::new(); { let mut __tmp_4: i32; @@ -90,7 +85,7 @@ unsafe fn main_0() -> i32 { }; let mut m_begin: UnsafeBidirectionalIterator<(i32, f64)> = m.begin(); let mut m_end: UnsafeBidirectionalIterator<(i32, f64)> = m.end(); - let mut m_result_true: bool = !WeaklyEqualityComparableWithUnsafe::equal(&m_begin, &m_end); + let mut m_result_true: bool = WeaklyEqualityComparableWithUnsafe::not_equal(&m_begin, &m_end); assert!( ((v_result_true) && (m_result_true)) && (WeaklyEqualityComparableWithUnsafe::equal( @@ -98,7 +93,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_7 = { v.begin() }; let mut __tmp_8 = { v.begin() }; let mut __it = (__tmp_7).clone(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_8) + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_8) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &2) { __it.iter_inc(); @@ -114,7 +109,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_9 = { w.begin().iter_add(2_isize) }; let mut __tmp_10 = { w.end() }; let mut __it = (__tmp_9).clone(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_10) + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_10) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &4) { __it.iter_inc(); @@ -128,7 +123,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_11 = { w.begin().iter_add(2_isize) }; let mut __tmp_12 = { w.end() }; let mut __it = (__tmp_11).clone(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_12) + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_12) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &1) { __it.iter_inc(); @@ -142,7 +137,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_13 = { w.begin().iter_add(2_isize) }; let mut __tmp_14 = { w.begin().iter_add(4_isize) }; let mut __it = (__tmp_13).clone(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_14) + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_14) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &5) { __it.iter_inc(); @@ -157,7 +152,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_15 = { p.begin() }; let mut __tmp_16 = { p.end() }; let mut __it = (__tmp_15).clone(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_16) + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_16) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &(P { x: 1 })) { __it.iter_inc(); @@ -168,4 +163,9 @@ unsafe fn main_0() -> i32 { )); return 0; } +impl WeaklyEqualityComparableWithUnsafe for P { + unsafe fn equal(this: *const Self, o: *const P) -> bool { + return (((*this).x) == ((*o).x)); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/friend.rs b/tests/unit/out/unsafe/friend.rs index 6291384b01..9c2281c35d 100644 --- a/tests/unit/out/unsafe/friend.rs +++ b/tests/unit/out/unsafe/friend.rs @@ -9,11 +9,6 @@ use std::rc::Rc; pub unsafe fn get_0(v: *const V) -> i32 { return (*v).x; } -impl WeaklyEqualityComparableWithUnsafe for V { - unsafe fn equal(a: *const V, b: *const V) -> bool { - return (((*a).x) == ((*b).x)); - } -} pub unsafe fn scaled_1(v: *const V, mut k: i32) -> i32 { return (((*v).x) * (k)); } @@ -126,4 +121,9 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { declared_then_defined_5(&d,) }) == (8))); return 0; } +impl WeaklyEqualityComparableWithUnsafe for V { + unsafe fn equal(a: *const V, b: *const V) -> bool { + return (((*a).x) == ((*b).x)); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/map.rs b/tests/unit/out/unsafe/map.rs index 42942bf71a..bafffe08be 100644 --- a/tests/unit/out/unsafe/map.rs +++ b/tests/unit/out/unsafe/map.rs @@ -286,7 +286,7 @@ unsafe fn main_0() -> i32 { assert!((((*const_it4.iter_deref()).1) == (6_u32))); let r: *mut UnsafeMap = &mut m; assert!((((*r).len()) == (4_usize))); - assert!(!WeaklyEqualityComparableWithUnsafe::equal( + assert!(WeaklyEqualityComparableWithUnsafe::not_equal( &m.find(&4_i16), &m.end() )); diff --git a/tests/unit/out/unsafe/map_key_identity.rs b/tests/unit/out/unsafe/map_key_identity.rs index 5fed994f67..8d6e5b77e7 100644 --- a/tests/unit/out/unsafe/map_key_identity.rs +++ b/tests/unit/out/unsafe/map_key_identity.rs @@ -52,11 +52,6 @@ impl std::cmp::Eq for Key {} pub unsafe fn operator_lt_1(a: *const Key, b: *const Key) -> bool { return (((*a).order) < ((*b).order)); } -impl WeaklyEqualityComparableWithUnsafe for Key { - unsafe fn equal(a: *const Key, b: *const Key) -> bool { - return (((*a).identity) == ((*b).identity)); - } -} #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] pub struct Mapped { @@ -127,7 +122,7 @@ unsafe fn main_0() -> i32 { & ((WeaklyEqualityComparableWithUnsafe::equal(&b_it, &distinct.find(&distinct_b))) as i32)) != 0; ok = ((ok as i32) - & ((!WeaklyEqualityComparableWithUnsafe::equal(&b_it, &distinct.end())) as i32)) + & ((WeaklyEqualityComparableWithUnsafe::not_equal(&b_it, &distinct.end())) as i32)) != 0; ok = ((ok as i32) & (((&mut (*a_it.iter_deref()).1 as *mut Mapped) == (a_value)) as i32)) != 0; ok = ((ok as i32) & ((((*a_it.iter_deref()).1.value) == (11)) as i32)) != 0; @@ -184,7 +179,8 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & (((equivalent.len()) == (1_usize)) as i32)) != 0; if reused { ok = ((ok as i32) - & ((!WeaklyEqualityComparableWithUnsafe::equal(&first_it, &equivalent.end())) as i32)) + & ((WeaklyEqualityComparableWithUnsafe::not_equal(&first_it, &equivalent.end())) + as i32)) != 0; ok = ((ok as i32) & (((first) == (second)) as i32)) != 0; ok = ((ok as i32) @@ -301,6 +297,11 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & ((((*matched_it.iter_deref()).1.value) == (51)) as i32)) != 0; return if ok { 0 } else { 1 }; } +impl WeaklyEqualityComparableWithUnsafe for Key { + unsafe fn equal(a: *const Key, b: *const Key) -> bool { + return (((*a).identity) == ((*b).identity)); + } +} pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const default_constructions_0); } diff --git a/tests/unit/out/unsafe/max.rs b/tests/unit/out/unsafe/max.rs index 9459428278..2a504984cd 100644 --- a/tests/unit/out/unsafe/max.rs +++ b/tests/unit/out/unsafe/max.rs @@ -126,10 +126,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_2 = { values.as_mut_ptr() }; let mut __tmp_3 = { values.as_mut_ptr().offset((4) as isize) }; let mut __best = __tmp_2.clone(); - if !WeaklyEqualityComparableWithUnsafe::equal(&__tmp_2, &__tmp_3) { + if WeaklyEqualityComparableWithUnsafe::not_equal(&__tmp_2, &__tmp_3) { let mut __it = __tmp_2; __it.iter_inc(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_3) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) { if *__best.iter_deref() < *__it.iter_deref() { __best = __it.clone(); } diff --git a/tests/unit/out/unsafe/operator_comparison_defaulted.rs b/tests/unit/out/unsafe/operator_comparison_defaulted.rs index 96f4589540..be6434480d 100644 --- a/tests/unit/out/unsafe/operator_comparison_defaulted.rs +++ b/tests/unit/out/unsafe/operator_comparison_defaulted.rs @@ -21,11 +21,6 @@ pub struct Eq { pub a: i32, pub b: i32, } -impl WeaklyEqualityComparableWithUnsafe for Eq { - unsafe fn equal(this: *const Self, _a0: *const Eq) -> bool { - return (((*this).a) == ((*_a0).a)) && (((*this).b) == ((*_a0).b)); - } -} impl std::cmp::PartialEq for Eq { fn eq(&self, other: &Self) -> bool { unsafe { @@ -66,11 +61,6 @@ impl Cmp { return libcc2rs::STRONG_ORDERING_EQUAL; } } -impl WeaklyEqualityComparableWithUnsafe for Cmp { - unsafe fn equal(this: *const Self, _a0: *const Cmp) -> bool { - return (((*this).a) == ((*_a0).a)) && (((*this).b) == ((*_a0).b)); - } -} impl std::cmp::Ord for Cmp { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { Cmp::operator_cmp((self as *const Self), (other as *const Self)) } @@ -115,11 +105,6 @@ impl Both { return libcc2rs::STRONG_ORDERING_EQUAL; } } -impl WeaklyEqualityComparableWithUnsafe for Both { - unsafe fn equal(this: *const Self, _a0: *const Both) -> bool { - return (((*this).a) == ((*_a0).a)); - } -} impl std::cmp::Ord for Both { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { Both::operator_cmp((self as *const Self), (other as *const Self)) } @@ -207,11 +192,6 @@ impl Inner { return libcc2rs::STRONG_ORDERING_EQUAL; } } -impl WeaklyEqualityComparableWithUnsafe for Inner { - unsafe fn equal(this: *const Self, _a0: *const Inner) -> bool { - return (((*this).x) == ((*_a0).x)); - } -} impl std::cmp::Ord for Inner { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { Inner::operator_cmp((self as *const Self), (other as *const Self)) } @@ -266,14 +246,6 @@ impl Outer { return libcc2rs::STRONG_ORDERING_EQUAL; } } -impl WeaklyEqualityComparableWithUnsafe for Outer { - unsafe fn equal(this: *const Self, _a0: *const Outer) -> bool { - return (unsafe { - let _arg0: *const Inner = &(*_a0).i; - WeaklyEqualityComparableWithUnsafe::equal(&raw const (*this).i, _arg0) - }) && (((*this).y) == ((*_a0).y)); - } -} impl std::cmp::Ord for Outer { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { Outer::operator_cmp((self as *const Self), (other as *const Self)) } @@ -308,9 +280,6 @@ pub struct Secondary { pub a: i32, } impl Secondary { - pub unsafe fn operator_ne(this: *const Self, _a0: *const Secondary) -> bool { - return !(unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const (*this), _a0) }); - } pub unsafe fn operator_cmp(this: *const Self, _a0: *const Secondary) -> std::cmp::Ordering { { let mut cmp: std::cmp::Ordering = std::cmp::Ord::cmp(&((*this).a), &((*_a0).a)); @@ -329,11 +298,6 @@ impl Secondary { != std::cmp::Ordering::Less; } } -impl WeaklyEqualityComparableWithUnsafe for Secondary { - unsafe fn equal(this: *const Self, _a0: *const Secondary) -> bool { - return (((*this).a) == ((*_a0).a)); - } -} impl std::cmp::Ord for Secondary { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { Secondary::operator_cmp((self as *const Self), (other as *const Self)) } @@ -377,11 +341,6 @@ impl PtrMember { return libcc2rs::STRONG_ORDERING_EQUAL; } } -impl WeaklyEqualityComparableWithUnsafe for PtrMember { - unsafe fn equal(this: *const Self, _a0: *const PtrMember) -> bool { - return (((*this).p) == ((*_a0).p)); - } -} impl std::cmp::Ord for PtrMember { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { PtrMember::operator_cmp((self as *const Self), (other as *const Self)) } @@ -461,7 +420,7 @@ unsafe fn main_0() -> i32 { ); let mut s1: Secondary = Secondary { a: 1 }; let mut s2: Secondary = Secondary { a: 2 }; - assert!((unsafe { Secondary::operator_ne(&raw const s1, &s2,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::not_equal(&raw const s1, &s2,) })); assert!((unsafe { Secondary::operator_lt(&raw const s1, &s2,) })); assert!((unsafe { Secondary::operator_ge(&raw const s2, &s1,) })); assert!(!(unsafe { Secondary::operator_lt(&raw const s2, &s1,) })); @@ -483,4 +442,45 @@ unsafe fn main_0() -> i32 { ); return 0; } +impl WeaklyEqualityComparableWithUnsafe for Both { + unsafe fn equal(this: *const Self, _a0: *const Both) -> bool { + return (((*this).a) == ((*_a0).a)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Cmp { + unsafe fn equal(this: *const Self, _a0: *const Cmp) -> bool { + return (((*this).a) == ((*_a0).a)) && (((*this).b) == ((*_a0).b)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Eq { + unsafe fn equal(this: *const Self, _a0: *const Eq) -> bool { + return (((*this).a) == ((*_a0).a)) && (((*this).b) == ((*_a0).b)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Inner { + unsafe fn equal(this: *const Self, _a0: *const Inner) -> bool { + return (((*this).x) == ((*_a0).x)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Outer { + unsafe fn equal(this: *const Self, _a0: *const Outer) -> bool { + return (unsafe { + let _arg0: *const Inner = &(*_a0).i; + WeaklyEqualityComparableWithUnsafe::equal(&raw const (*this).i, _arg0) + }) && (((*this).y) == ((*_a0).y)); + } +} +impl WeaklyEqualityComparableWithUnsafe for PtrMember { + unsafe fn equal(this: *const Self, _a0: *const PtrMember) -> bool { + return (((*this).p) == ((*_a0).p)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Secondary { + unsafe fn equal(this: *const Self, _a0: *const Secondary) -> bool { + return (((*this).a) == ((*_a0).a)); + } + unsafe fn not_equal(this: *const Self, _a0: *const Secondary) -> bool { + return !(unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const (*this), _a0) }); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_comparison_free.rs b/tests/unit/out/unsafe/operator_comparison_free.rs index 201d8c1b6a..17fad6efeb 100644 --- a/tests/unit/out/unsafe/operator_comparison_free.rs +++ b/tests/unit/out/unsafe/operator_comparison_free.rs @@ -46,30 +46,22 @@ impl std::cmp::PartialEq for S { } } impl std::cmp::Eq for S {} -impl WeaklyEqualityComparableWithUnsafe for S { - unsafe fn equal(a: *const S, b: *const S) -> bool { - return (((*a).v) == ((*b).v)); - } -} -pub unsafe fn operator_ne_1(a: *const S, b: *const S) -> bool { - return (((*a).v) != ((*b).v)); -} pub unsafe fn operator_lt_0(a: *const S, b: *const S) -> bool { return (((*a).v) < ((*b).v)); } -pub unsafe fn operator_gt_2(a: *const S, b: *const S) -> bool { +pub unsafe fn operator_gt_1(a: *const S, b: *const S) -> bool { return (((*a).v) > ((*b).v)); } -pub unsafe fn operator_le_3(a: *const S, b: *const S) -> bool { +pub unsafe fn operator_le_2(a: *const S, b: *const S) -> bool { return (((*a).v) <= ((*b).v)); } -pub unsafe fn operator_ge_4(a: *const S, b: *const S) -> bool { +pub unsafe fn operator_ge_3(a: *const S, b: *const S) -> bool { return (((*a).v) >= ((*b).v)); } -pub unsafe fn operator_lt_5(a: *const S, mut b: i32) -> bool { +pub unsafe fn operator_lt_4(a: *const S, mut b: i32) -> bool { return (((*a).v) < (b)); } -pub unsafe fn operator_lt_6(mut a: i32, b: *const S) -> bool { +pub unsafe fn operator_lt_5(mut a: i32, b: *const S) -> bool { return ((a) < ((*b).v)); } #[repr(C)] @@ -121,21 +113,16 @@ impl std::cmp::PartialEq for V { } } impl std::cmp::Eq for V {} -impl WeaklyEqualityComparableWithUnsafe for V { - unsafe fn equal(a: *const Self, b: *const Self) -> bool { - operator_eq_8((*a).clone(), (*b).clone()) - } -} pub unsafe fn operator_eq_8(mut a: V, mut b: V) -> bool { return ((a.v) == (b.v)); } -pub unsafe fn operator_ne_9(mut a: V, mut b: V) -> bool { +pub unsafe fn operator_ne_6(mut a: V, mut b: V) -> bool { return ((a.v) != (b.v)); } pub unsafe fn operator_lt_7(mut a: V, mut b: V) -> bool { return ((a.v) < (b.v)); } -pub unsafe fn operator_gt_10(mut a: V, mut b: V) -> bool { +pub unsafe fn operator_gt_9(mut a: V, mut b: V) -> bool { return ((a.v) > (b.v)); } pub fn main() { @@ -157,7 +144,7 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _a: V = x; - operator_ne_9(_a, y) + operator_ne_6(_a, y) }) ); assert!( @@ -169,7 +156,7 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _a: V = y; - operator_gt_10(_a, x) + operator_gt_9(_a, x) }) ); assert!( @@ -190,7 +177,7 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _a: *const S = &a; - operator_ne_1(_a, &b) + WeaklyEqualityComparableWithUnsafe::not_equal(_a, &b) }) ); assert!( @@ -202,19 +189,19 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _a: *const S = &b; - operator_gt_2(_a, &a) + operator_gt_1(_a, &a) }) ); assert!( (unsafe { let _a: *const S = &a; - operator_le_3(_a, &c) + operator_le_2(_a, &c) }) ); assert!( (unsafe { let _a: *const S = &a; - operator_ge_4(_a, &c) + operator_ge_3(_a, &c) }) ); assert!( @@ -226,10 +213,26 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _a: *const S = &a; - operator_lt_5(_a, 5) + operator_lt_4(_a, 5) }) ); - assert!((unsafe { operator_lt_6(0, &a,) })); + assert!((unsafe { operator_lt_5(0, &a,) })); return 0; } +impl WeaklyEqualityComparableWithUnsafe for S { + unsafe fn equal(a: *const S, b: *const S) -> bool { + return (((*a).v) == ((*b).v)); + } + unsafe fn not_equal(a: *const S, b: *const S) -> bool { + return (((*a).v) != ((*b).v)); + } +} +impl WeaklyEqualityComparableWithUnsafe for V { + unsafe fn not_equal(a: *const Self, b: *const Self) -> bool { + operator_ne_6((*a).clone(), (*b).clone()) + } + unsafe fn equal(a: *const Self, b: *const Self) -> bool { + operator_eq_8((*a).clone(), (*b).clone()) + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_comparison_member.rs b/tests/unit/out/unsafe/operator_comparison_member.rs index 59be403cde..7ce9e42ed9 100644 --- a/tests/unit/out/unsafe/operator_comparison_member.rs +++ b/tests/unit/out/unsafe/operator_comparison_member.rs @@ -21,9 +21,6 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn operator_ne(this: *const Self, o: *const S) -> bool { - return (((*this).v) != ((*o).v)); - } pub unsafe fn operator_lt_3(this: *const Self, o: *const S) -> bool { return (((*this).v) < ((*o).v)); } @@ -40,11 +37,6 @@ impl S { return (((*this).v) < (o)); } } -impl WeaklyEqualityComparableWithUnsafe for S { - unsafe fn equal(this: *const Self, o: *const S) -> bool { - return (((*this).v) == ((*o).v)); - } -} impl std::cmp::Ord for S { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { @@ -82,7 +74,7 @@ unsafe fn main_0() -> i32 { let mut b: S = S { v: 2 }; let mut c: S = S { v: 1 }; assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const a, &c,) })); - assert!((unsafe { S::operator_ne(&raw const a, &b,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::not_equal(&raw const a, &b,) })); assert!((unsafe { S::operator_lt_3(&raw const a, &b,) })); assert!((unsafe { S::operator_gt(&raw const b, &a,) })); assert!((unsafe { S::operator_le(&raw const a, &c,) })); @@ -91,4 +83,12 @@ unsafe fn main_0() -> i32 { assert!((unsafe { S::operator_lt_7(&raw const a, 5,) })); return 0; } +impl WeaklyEqualityComparableWithUnsafe for S { + unsafe fn equal(this: *const Self, o: *const S) -> bool { + return (((*this).v) == ((*o).v)); + } + unsafe fn not_equal(this: *const Self, o: *const S) -> bool { + return (((*this).v) != ((*o).v)); + } +} 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 8dff6cb9c0..ec7169d6ed 100644 --- a/tests/unit/out/unsafe/operator_comparison_nonbool.rs +++ b/tests/unit/out/unsafe/operator_comparison_nonbool.rs @@ -23,13 +23,13 @@ pub struct X { impl std::cmp::Ord for X { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if ((operator_lt_0( + if ((operator_lt_1( (*(self as *const Self)).clone(), (*(other as *const Self)).clone(), )) != 0) { std::cmp::Ordering::Less - } else if ((operator_lt_0( + } else if ((operator_lt_1( (*(other as *const Self)).clone(), (*(self as *const Self)).clone(), )) != 0) @@ -49,7 +49,7 @@ impl std::cmp::PartialOrd for X { impl std::cmp::PartialEq for X { fn eq(&self, other: &Self) -> bool { unsafe { - ((operator_eq_1( + ((operator_eq_2( (*(self as *const Self)).clone(), (*(other as *const Self)).clone(), )) != 0) @@ -57,18 +57,13 @@ impl std::cmp::PartialEq for X { } } impl std::cmp::Eq for X {} -impl WeaklyEqualityComparableWithUnsafe for X { - unsafe fn equal(a: *const Self, b: *const Self) -> bool { - ((operator_eq_1((*a).clone(), (*b).clone())) != 0) - } -} -pub unsafe fn operator_eq_1(mut a: X, mut b: X) -> i32 { +pub unsafe fn operator_eq_2(mut a: X, mut b: X) -> i32 { return if ((a.v) == (b.v)) { 2 } else { 0 }; } -pub unsafe fn operator_ne_2(mut a: X, mut b: X) -> i32 { +pub unsafe fn operator_ne_0(mut a: X, mut b: X) -> i32 { return if ((a.v) != (b.v)) { 3 } else { 0 }; } -pub unsafe fn operator_lt_0(mut a: X, mut b: X) -> i32 { +pub unsafe fn operator_lt_1(mut a: X, mut b: X) -> i32 { return if ((a.v) < (b.v)) { 4 } else { 0 }; } pub unsafe fn operator_gt_3(mut a: X, mut b: X) -> i32 { @@ -166,11 +161,6 @@ impl std::cmp::PartialEq for Mixed { } } impl std::cmp::Eq for Mixed {} -impl WeaklyEqualityComparableWithUnsafe for Mixed { - unsafe fn equal(this: *const Self, o: *const Self) -> bool { - ((Mixed::operator_eq(this, o)) != 0) - } -} #[repr(C)] #[derive( Copy, @@ -253,14 +243,6 @@ impl std::cmp::PartialEq for Boolish { } } impl std::cmp::Eq for Boolish {} -impl WeaklyEqualityComparableWithUnsafe for Boolish { - unsafe fn equal(a: *const Self, b: *const Self) -> bool { - { - let __cmp = operator_eq_7((*a).clone(), (*b).clone()); - MyBool::to_bool((&raw const __cmp)) - } - } -} pub unsafe fn operator_eq_7(mut a: Boolish, mut b: Boolish) -> MyBool { return { let mut __v: MyBool = ::zero_init(); @@ -335,14 +317,6 @@ impl std::cmp::PartialEq for RefInt { } } impl std::cmp::Eq for RefInt {} -impl WeaklyEqualityComparableWithUnsafe for RefInt { - unsafe fn equal(this: *const Self, _a0: *const Self) -> bool { - { - let __cmp = RefInt::operator_eq(this, _a0); - RefBool::to_bool((__cmp as *const _)) - } - } -} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -356,25 +330,25 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let _a: X = a; - operator_eq_1(_a, c) + operator_eq_2(_a, c) }) == (2)) ); assert!( ((unsafe { let _a: X = a; - operator_eq_1(_a, b) + operator_eq_2(_a, b) }) == (0)) ); assert!( ((unsafe { let _a: X = a; - operator_ne_2(_a, b) + operator_ne_0(_a, b) }) == (3)) ); assert!( ((unsafe { let _a: X = a; - operator_lt_0(_a, b) + operator_lt_1(_a, b) }) == (4)) ); assert!( @@ -502,7 +476,7 @@ unsafe fn main_0() -> i32 { (({ let mut __tmp_3 = { ris.as_mut_ptr().offset((2) as isize) }; let mut __it = ris.as_mut_ptr(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_3) + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &ri2) { __it.iter_inc(); @@ -512,6 +486,35 @@ unsafe fn main_0() -> i32 { ); return 0; } +impl WeaklyEqualityComparableWithUnsafe for Boolish { + unsafe fn equal(a: *const Self, b: *const Self) -> bool { + { + let __cmp = operator_eq_7((*a).clone(), (*b).clone()); + MyBool::to_bool((&raw const __cmp)) + } + } +} +impl WeaklyEqualityComparableWithUnsafe for Mixed { + unsafe fn equal(this: *const Self, o: *const Self) -> bool { + ((Mixed::operator_eq(this, o)) != 0) + } +} +impl WeaklyEqualityComparableWithUnsafe for RefInt { + unsafe fn equal(this: *const Self, _a0: *const Self) -> bool { + { + let __cmp = RefInt::operator_eq(this, _a0); + RefBool::to_bool((__cmp as *const _)) + } + } +} +impl WeaklyEqualityComparableWithUnsafe for X { + unsafe fn not_equal(a: *const Self, b: *const Self) -> bool { + ((operator_ne_0((*a).clone(), (*b).clone())) != 0) + } + unsafe fn equal(a: *const Self, b: *const Self) -> bool { + ((operator_eq_2((*a).clone(), (*b).clone())) != 0) + } +} pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const ref_true_8); } diff --git a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs index 55478842c6..50da53cb5e 100644 --- a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs +++ b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs @@ -6,11 +6,6 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -impl WeaklyEqualityComparableWithUnsafe for S { - unsafe fn equal(x: *const S, y: *const S) -> bool { - return (((*x).data_) == ((*y).data_)); - } -} pub unsafe fn operator_lt_0(x: *const S, y: *const S) -> bool { return (((*x).data_) < ((*y).data_)); } @@ -89,4 +84,9 @@ unsafe fn main_0() -> i32 { ); return 0; } +impl WeaklyEqualityComparableWithUnsafe for S { + unsafe fn equal(x: *const S, y: *const S) -> bool { + return (((*x).data_) == ((*y).data_)); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_friend.rs b/tests/unit/out/unsafe/operator_friend.rs index f647ed7091..d39340c824 100644 --- a/tests/unit/out/unsafe/operator_friend.rs +++ b/tests/unit/out/unsafe/operator_friend.rs @@ -6,11 +6,6 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -impl WeaklyEqualityComparableWithUnsafe for Defaulted { - unsafe fn equal(_a0: *const Defaulted, _a1: *const Defaulted) -> bool { - return (((*_a0).a) == ((*_a1).a)) && (((*_a0).b) == ((*_a1).b)); - } -} #[repr(C)] #[derive( Copy, @@ -46,11 +41,6 @@ pub unsafe fn operator_cmp_0( } return libcc2rs::STRONG_ORDERING_EQUAL; } -impl WeaklyEqualityComparableWithUnsafe for DefaultedOrd { - unsafe fn equal(_a0: *const DefaultedOrd, _a1: *const DefaultedOrd) -> bool { - return (((*_a0).a) == ((*_a1).a)); - } -} #[repr(C)] #[derive( Copy, @@ -83,11 +73,6 @@ impl std::cmp::PartialEq for DefaultedOrd { } } impl std::cmp::Eq for DefaultedOrd {} -impl WeaklyEqualityComparableWithUnsafe for Inline { - unsafe fn equal(x: *const Inline, y: *const Inline) -> bool { - return (((*x).a) == ((*y).a)); - } -} pub unsafe fn operator_lt_1(x: *const Inline, y: *const Inline) -> bool { return (((*x).a) < ((*y).a)); } @@ -158,26 +143,10 @@ impl std::cmp::PartialEq for OutOfLine { } } impl std::cmp::Eq for OutOfLine {} -impl WeaklyEqualityComparableWithUnsafe for OutOfLine { - unsafe fn equal(x: *const OutOfLine, y: *const OutOfLine) -> bool { - return (((*x).a) == ((*y).a)); - } -} -pub unsafe fn operator_ne_3(x: *const OutOfLine, y: *const OutOfLine) -> bool { - return !(unsafe { - let _x: *const OutOfLine = x; - WeaklyEqualityComparableWithUnsafe::equal(_x, y) - }); -} -impl WeaklyEqualityComparableWithUnsafe for Tmpl_int_ { - unsafe fn equal(x: *const Tmpl_int_, y: *const Tmpl_int_) -> bool { - return (((*x).v) == ((*y).v)); - } -} -pub unsafe fn operator_lt_4(x: *const Tmpl_int_, y: *const Tmpl_int_) -> bool { +pub unsafe fn operator_lt_3(x: *const Tmpl_int_, y: *const Tmpl_int_) -> bool { return (((*x).v) < ((*y).v)); } -pub unsafe fn operator_eq_5(x: *const Tmpl_int_, y: *const Tmpl_long_) -> bool { +pub unsafe fn operator_eq_4(x: *const Tmpl_int_, y: *const Tmpl_long_) -> bool { return (((*x).v as i64) == ((*y).v)); } #[repr(C)] @@ -197,9 +166,9 @@ pub struct Tmpl_int_ { impl std::cmp::Ord for Tmpl_int_ { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_4((self as *const Self), (other as *const Self)) { + if operator_lt_3((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_4((other as *const Self), (self as *const Self)) { + } else if operator_lt_3((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -234,11 +203,6 @@ impl std::cmp::Eq for Tmpl_int_ {} pub struct Tmpl_long_ { pub v: i64, } -impl WeaklyEqualityComparableWithUnsafe for TmplDefaulted_int_ { - unsafe fn equal(_a0: *const TmplDefaulted_int_, _a1: *const TmplDefaulted_int_) -> bool { - return (((*_a0).v) == ((*_a1).v)); - } -} #[repr(C)] #[derive( Copy, @@ -365,7 +329,7 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const OutOfLine = &f1; - operator_ne_3(_x, &f3) + WeaklyEqualityComparableWithUnsafe::not_equal(_x, &f3) }) ); assert!( @@ -392,7 +356,7 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const Tmpl_int_ = &t1; - operator_lt_4(_x, &t2) + operator_lt_3(_x, &t2) }) ); let mut u1: Tmpl_long_ = Tmpl_long_ { v: 1_i64 }; @@ -400,13 +364,13 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const Tmpl_int_ = &t1; - operator_eq_5(_x, &u1) + operator_eq_4(_x, &u1) }) ); assert!( !(unsafe { let _x: *const Tmpl_int_ = &t1; - operator_eq_5(_x, &u2) + operator_eq_4(_x, &u2) }) ); let mut v1: TmplDefaulted_int_ = TmplDefaulted_int_ { v: 7 }; @@ -432,4 +396,40 @@ unsafe fn main_0() -> i32 { ); return 0; } +impl WeaklyEqualityComparableWithUnsafe for Defaulted { + unsafe fn equal(_a0: *const Defaulted, _a1: *const Defaulted) -> bool { + return (((*_a0).a) == ((*_a1).a)) && (((*_a0).b) == ((*_a1).b)); + } +} +impl WeaklyEqualityComparableWithUnsafe for DefaultedOrd { + unsafe fn equal(_a0: *const DefaultedOrd, _a1: *const DefaultedOrd) -> bool { + return (((*_a0).a) == ((*_a1).a)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Inline { + unsafe fn equal(x: *const Inline, y: *const Inline) -> bool { + return (((*x).a) == ((*y).a)); + } +} +impl WeaklyEqualityComparableWithUnsafe for OutOfLine { + unsafe fn equal(x: *const OutOfLine, y: *const OutOfLine) -> bool { + return (((*x).a) == ((*y).a)); + } + unsafe fn not_equal(x: *const OutOfLine, y: *const OutOfLine) -> bool { + return !(unsafe { + let _x: *const OutOfLine = x; + WeaklyEqualityComparableWithUnsafe::equal(_x, y) + }); + } +} +impl WeaklyEqualityComparableWithUnsafe for TmplDefaulted_int_ { + unsafe fn equal(_a0: *const TmplDefaulted_int_, _a1: *const TmplDefaulted_int_) -> bool { + return (((*_a0).v) == ((*_a1).v)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Tmpl_int_ { + unsafe fn equal(x: *const Tmpl_int_, y: *const Tmpl_int_) -> bool { + return (((*x).v) == ((*y).v)); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_three_way.rs b/tests/unit/out/unsafe/operator_three_way.rs index 9b05bcb14c..3511bdd32b 100644 --- a/tests/unit/out/unsafe/operator_three_way.rs +++ b/tests/unit/out/unsafe/operator_three_way.rs @@ -31,11 +31,6 @@ impl S { return libcc2rs::STRONG_ORDERING_EQUAL; } } -impl WeaklyEqualityComparableWithUnsafe for S { - unsafe fn equal(this: *const Self, o: *const S) -> bool { - return (((*this).v) == ((*o).v)); - } -} impl std::cmp::Ord for S { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { S::operator_cmp((self as *const Self), (other as *const Self)) } @@ -71,4 +66,9 @@ unsafe fn main_0() -> i32 { assert!((unsafe { S::operator_cmp(&raw const a, &b,) }) == libcc2rs::STRONG_ORDERING_LESS); return 0; } +impl WeaklyEqualityComparableWithUnsafe for S { + unsafe fn equal(this: *const Self, o: *const S) -> bool { + return (((*this).v) == ((*o).v)); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_traits.rs b/tests/unit/out/unsafe/operator_traits.rs index 99ebd6999e..b5881ec210 100644 --- a/tests/unit/out/unsafe/operator_traits.rs +++ b/tests/unit/out/unsafe/operator_traits.rs @@ -66,11 +66,6 @@ impl std::cmp::Eq for Lt {} pub struct Eq { pub v: i32, } -impl WeaklyEqualityComparableWithUnsafe for Eq { - unsafe fn equal(this: *const Self, o: *const Eq) -> bool { - return (((*this).v) == ((*o).v)); - } -} impl std::cmp::PartialEq for Eq { fn eq(&self, other: &Self) -> bool { unsafe { @@ -98,11 +93,6 @@ impl Cmp { return std::cmp::Ord::cmp(&((*this).v), &((*o).v)); } } -impl WeaklyEqualityComparableWithUnsafe for Cmp { - unsafe fn equal(this: *const Self, o: *const Cmp) -> bool { - return (((*this).v) == ((*o).v)); - } -} impl std::cmp::Ord for Cmp { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { Cmp::operator_cmp((self as *const Self), (other as *const Self)) } @@ -164,11 +154,6 @@ impl std::cmp::Eq for Free {} pub unsafe fn operator_lt_0(a: *const Free, b: *const Free) -> bool { return (((*a).v) < ((*b).v)); } -impl WeaklyEqualityComparableWithUnsafe for Free { - unsafe fn equal(a: *const Free, b: *const Free) -> bool { - return (((*a).v) == ((*b).v)); - } -} #[repr(C)] #[derive( Copy, @@ -217,7 +202,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { eqs.begin() }; let mut __tmp_2 = { eqs.end() }; let mut __it = (__tmp_1).clone(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_2) + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_2) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &two) { __it.iter_inc(); @@ -232,7 +217,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_3 = { eqs.begin() }; let mut __tmp_4 = { eqs.end() }; let mut __it = (__tmp_3).clone(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_4) + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_4) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &nine) { __it.iter_inc(); @@ -262,7 +247,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_6 = { cmps.begin() }; let mut __tmp_7 = { cmps.end() }; let mut __it = (__tmp_6).clone(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_7) + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_7) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &three) { __it.iter_inc(); @@ -293,7 +278,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_9 = { frees.begin() }; let mut __tmp_10 = { frees.end() }; let mut __it = (__tmp_9).clone(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_10) + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_10) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &ftwo) { __it.iter_inc(); @@ -330,4 +315,19 @@ unsafe fn main_0() -> i32 { }; return 0; } +impl WeaklyEqualityComparableWithUnsafe for Cmp { + unsafe fn equal(this: *const Self, o: *const Cmp) -> bool { + return (((*this).v) == ((*o).v)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Eq { + unsafe fn equal(this: *const Self, o: *const Eq) -> bool { + return (((*this).v) == ((*o).v)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Free { + unsafe fn equal(a: *const Free, b: *const Free) -> bool { + return (((*a).v) == ((*b).v)); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/push_emplace_back.rs b/tests/unit/out/unsafe/push_emplace_back.rs index 9e841e8464..9e7ad99b5f 100644 --- a/tests/unit/out/unsafe/push_emplace_back.rs +++ b/tests/unit/out/unsafe/push_emplace_back.rs @@ -75,7 +75,7 @@ pub unsafe fn push_local_from_field_1(mut jpg: *mut JPEGData, mut cond: bool) { let mut __tmp_2 = { head.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = head.as_mut_ptr(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_2) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_2) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -103,7 +103,7 @@ pub unsafe fn emplace_local_from_field_4(mut jpg: *mut JPEGData, mut cond: bool) let mut __tmp_3 = { head.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = head.as_mut_ptr(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_3) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -251,7 +251,7 @@ pub unsafe fn emplace_from_element_14(mut v: *mut Vec>) { let mut __tmp_4 = { p.offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = p; - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_4) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_4) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -318,7 +318,7 @@ pub unsafe fn emplace_from_sibling_18(mut s: *mut Bytes) { let mut __tmp_5 = { p.offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = p; - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_5) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_5) { __v.push((*__it.iter_deref())); __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/size_t_ssize_t.rs b/tests/unit/out/unsafe/size_t_ssize_t.rs index 4ba04c4d0f..766192a706 100644 --- a/tests/unit/out/unsafe/size_t_ssize_t.rs +++ b/tests/unit/out/unsafe/size_t_ssize_t.rs @@ -36,7 +36,7 @@ pub unsafe fn size_t_in_rules_3() { let mut __tmp_0 = { src.as_mut_ptr().offset((3) as isize) }; let mut __first = src.as_mut_ptr(); let mut __out = (dst.as_mut_ptr() as *mut usize).cast::(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__first, &__tmp_0) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &__tmp_0) { *__out.iter_deref() = ((*__first.iter_deref()) as u64); __first.iter_inc(); __out.iter_inc(); @@ -75,7 +75,7 @@ pub unsafe fn size_t_in_rules_3() { |__k| cpp_move_unsafe!(__k), || 0_u64, )) = 4_u64; - assert!(!WeaklyEqualityComparableWithUnsafe::equal( + assert!(WeaklyEqualityComparableWithUnsafe::not_equal( &m.find(&1_u64), &m.end() )); @@ -141,7 +141,7 @@ pub unsafe fn size_t_in_rules_3() { let mut __tmp_5 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_5) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_5) { __v.push(((*__it.iter_deref()) as u64)); __it.iter_inc(); } @@ -158,7 +158,7 @@ pub unsafe fn size_t_in_rules_3() { let mut __tmp_7 = { v.begin() }; let mut __tmp_8 = { v.end() }; let mut __it = (__tmp_7).clone(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_8) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_8) { *__it.iter_deref() = Clone::clone(&(k as u64)); __it.iter_inc(); } @@ -220,12 +220,12 @@ pub unsafe fn size_t_in_rules_3() { v3.push(__a2) } }; - assert!(!WeaklyEqualityComparableWithUnsafe::equal( + assert!(WeaklyEqualityComparableWithUnsafe::not_equal( &{ let mut __tmp_12 = { v3.begin() }; let mut __tmp_13 = { v3.end() }; let mut __it = (__tmp_12).clone(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_13) + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_13) && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &(k as u64)) { __it.iter_inc(); diff --git a/tests/unit/out/unsafe/sort_no_copy.rs b/tests/unit/out/unsafe/sort_no_copy.rs index 9e6e593b76..13a3f86ea0 100644 --- a/tests/unit/out/unsafe/sort_no_copy.rs +++ b/tests/unit/out/unsafe/sort_no_copy.rs @@ -190,11 +190,6 @@ impl std::cmp::Eq for Bag {} pub unsafe fn operator_lt_4(a: *const Bag, b: *const Bag) -> bool { return (((*a).items.len()) < ((*b).items.len())); } -impl WeaklyEqualityComparableWithUnsafe for Bag { - unsafe fn equal(a: *const Bag, b: *const Bag) -> bool { - return (((*a).items.len()) == ((*b).items.len())); - } -} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -474,7 +469,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_7 = { bag_vec.begin() }; let mut __tmp_8 = { bag_vec.end() }; let mut __it = (__tmp_7).clone(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_8) + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_8) && !WeaklyEqualityComparableWithUnsafe::equal( &*__it.iter_deref(), &bags[(1) as usize], @@ -491,10 +486,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_9 = { bag_vec.begin() }; let mut __tmp_10 = { bag_vec.end() }; let mut __best = __tmp_9.clone(); - if !WeaklyEqualityComparableWithUnsafe::equal(&__tmp_9, &__tmp_10) { + if WeaklyEqualityComparableWithUnsafe::not_equal(&__tmp_9, &__tmp_10) { let mut __it = (__tmp_9).clone(); __it.iter_inc(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_10) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_10) { if *__best.iter_deref() < *__it.iter_deref() { __best = __it.clone(); } @@ -615,6 +610,11 @@ unsafe fn main_0() -> i32 { ); return (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)); } +impl WeaklyEqualityComparableWithUnsafe for Bag { + unsafe fn equal(a: *const Bag, b: *const Bag) -> bool { + return (((*a).items.len()) == ((*b).items.len())); + } +} pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const copies_0); } diff --git a/tests/unit/out/unsafe/stdcopy.rs b/tests/unit/out/unsafe/stdcopy.rs index 64af57fda8..1e589a8c48 100644 --- a/tests/unit/out/unsafe/stdcopy.rs +++ b/tests/unit/out/unsafe/stdcopy.rs @@ -40,7 +40,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_0 = { input.as_mut_ptr().offset((3) as isize) }; let mut __first = input.as_mut_ptr(); let mut __out = output.as_mut_ptr(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__first, &__tmp_0) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &__tmp_0) { *__out.iter_deref() = (*__first.iter_deref()); __first.iter_inc(); __out.iter_inc(); @@ -52,7 +52,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { input.as_mut_ptr().offset((3) as isize) }; let mut __first = input.as_mut_ptr(); let mut __out = widened.begin(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__first, &__tmp_1) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &__tmp_1) { *__out.iter_deref() = ((*__first.iter_deref()) as i64); __first.iter_inc(); __out.iter_inc(); @@ -74,7 +74,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_4 = { input.as_mut_ptr().offset((3) as isize) }; let mut __first = input.as_mut_ptr(); let mut __out = constructed.begin(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__first, &__tmp_4) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &__tmp_4) { *__out.iter_deref() = >::cpp_from(__first.iter_deref()); __first.iter_inc(); __out.iter_inc(); @@ -88,7 +88,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_5 = { wide.as_mut_ptr().offset((2) as isize) }; let mut __first = wide.as_mut_ptr(); let mut __out = floating.begin(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__first, &__tmp_5) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &__tmp_5) { *__out.iter_deref() = ((*__first.iter_deref()) as f64); __first.iter_inc(); __out.iter_inc(); diff --git a/tests/unit/out/unsafe/stdcopy_ostream.rs b/tests/unit/out/unsafe/stdcopy_ostream.rs index 87b8f8f23b..de2abdc633 100644 --- a/tests/unit/out/unsafe/stdcopy_ostream.rs +++ b/tests/unit/out/unsafe/stdcopy_ostream.rs @@ -37,7 +37,7 @@ unsafe fn main_0() -> i32 { let mut __it = (__tmp_0).clone(); let __out = &mut ofs; let mut __bytes: Vec = Vec::new(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_1) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { __bytes.push(*__it.iter_deref() as u8); __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/unboxed_conditional_iterator.rs b/tests/unit/out/unsafe/unboxed_conditional_iterator.rs index dc34cb89d6..48dfc6485f 100644 --- a/tests/unit/out/unsafe/unboxed_conditional_iterator.rs +++ b/tests/unit/out/unsafe/unboxed_conditional_iterator.rs @@ -55,7 +55,7 @@ pub unsafe fn lehmer_3(mut sigma: *const u32, mut len: u32, mut code: *mut u32) let mut __tmp_0 = { items.begin() }; let mut __tmp_1 = { items.end() }; let mut __it = (__tmp_0).clone(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_1) + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) && !WeaklyEqualityComparableWithUnsafe::equal( &*__it.iter_deref(), &(*sigma.offset((i) as isize)), @@ -65,7 +65,7 @@ pub unsafe fn lehmer_3(mut sigma: *const u32, mut len: u32, mut code: *mut u32) } __it }; - assert!(!WeaklyEqualityComparableWithUnsafe::equal( + assert!(WeaklyEqualityComparableWithUnsafe::not_equal( &it, &items.end() )); @@ -87,7 +87,7 @@ pub unsafe fn sum_4(v: *mut Vec) -> i32 { let mut s: i32 = 0; { let mut it: UnsafeRandomAccessIterator = (*v).begin(); - 'loop_: while !WeaklyEqualityComparableWithUnsafe::equal(&it, &(*v).end()) { + 'loop_: while WeaklyEqualityComparableWithUnsafe::not_equal(&it, &(*v).end()) { 'for_body: { s += (*it.iter_deref()); } diff --git a/tests/unit/out/unsafe/vector.rs b/tests/unit/out/unsafe/vector.rs index cebc891578..9a5c15a49f 100644 --- a/tests/unit/out/unsafe/vector.rs +++ b/tests/unit/out/unsafe/vector.rs @@ -185,7 +185,7 @@ unsafe fn main_0() -> i32 { __tmp_7.iter_distance(&UnsafeRandomAccessIterator::Vec(v2.as_mut_ptr())) as usize; let mut __tmp = Vec::new(); let mut __it = (__tmp_8).clone(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_9) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_9) { __tmp.push((*__it.iter_deref())); __it.iter_inc(); } @@ -509,7 +509,7 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp = Vec::new(); let mut __it = ints.as_mut_ptr(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_20) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_20) { __tmp.push(((*__it.iter_deref()) as i64)); __it.iter_inc(); } @@ -530,7 +530,7 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp = Vec::new(); let mut __it = (__tmp_22).clone(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_23) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_23) { __tmp.push(((*__it.iter_deref()) as i64)); __it.iter_inc(); } @@ -547,7 +547,7 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp = Vec::new(); let mut __it = ints.as_mut_ptr(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_25) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_25) { __tmp.push(((*__it.iter_deref()) as f64)); __it.iter_inc(); } @@ -564,7 +564,7 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp = Vec::new(); let mut __it = ints.as_mut_ptr(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_27) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_27) { __tmp.push(>::cpp_from(__it.iter_deref())); __it.iter_inc(); } @@ -581,7 +581,7 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp = Vec::new(); let mut __it = (__tmp_29).clone(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_30) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_30) { __tmp.push((*__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 bbb1bcf0c3..70957875b5 100644 --- a/tests/unit/out/unsafe/vector_iter_range_ctor.rs +++ b/tests/unit/out/unsafe/vector_iter_range_ctor.rs @@ -60,7 +60,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_0 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_0) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_0) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -75,7 +75,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_1) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { __v.push(((*__it.iter_deref()) as u64)); __it.iter_inc(); } @@ -90,7 +90,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_2 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_2) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_2) { __v.push(((*__it.iter_deref()) as i32)); __it.iter_inc(); } @@ -103,7 +103,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_3 = { src1.as_ptr().add(src1.len()) }; let mut __v = Vec::new(); let mut __it = src1.as_ptr(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_3) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -127,7 +127,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_5 = { start.offset((len) as isize) }; let mut __v = Vec::new(); let mut __it = start; - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_5) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_5) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -162,7 +162,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_10 = { m.end() }; let mut __v = Vec::new(); let mut __it = (__tmp_9).clone(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_10) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_10) { __v.push(<(i32, i32) as CppFromUnsafe<(i32, i32)>>::cpp_from( __it.iter_deref(), )); @@ -182,7 +182,7 @@ unsafe fn main_0() -> i32 { __tmp_11.iter_distance(&UnsafeRandomAccessIterator::Vec(v6.as_mut_ptr())) as usize; let mut __tmp = Vec::new(); let mut __it = (__tmp_12).clone(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_13) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_13) { __tmp.push(<(i32, i32) as CppFromUnsafe<(i32, i32)>>::cpp_from( __it.iter_deref(), )); @@ -200,7 +200,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_14 = { ints.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = ints.as_mut_ptr(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_14) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_14) { __v.push(>::cpp_from(__it.iter_deref())); __it.iter_inc(); } @@ -212,7 +212,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_15 = { readings.as_mut_ptr().offset((2) as isize) }; let mut __v = Vec::new(); let mut __it = readings.as_mut_ptr(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_15) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_15) { __v.push(>::cpp_from(__it.iter_deref())); __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/vector_with_allocator.rs b/tests/unit/out/unsafe/vector_with_allocator.rs index f008a1014a..fce95b321f 100644 --- a/tests/unit/out/unsafe/vector_with_allocator.rs +++ b/tests/unit/out/unsafe/vector_with_allocator.rs @@ -317,7 +317,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_16 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_16) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_16) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -332,7 +332,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_17 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_17) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_17) { __v.push(((*__it.iter_deref()) as u64)); __it.iter_inc(); } @@ -347,7 +347,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_18 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_18) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_18) { __v.push(((*__it.iter_deref()) as i32)); __it.iter_inc(); } @@ -360,7 +360,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_19 = { src1.as_ptr().add(src1.len()) }; let mut __v = Vec::new(); let mut __it = src1.as_ptr(); - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_19) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_19) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -378,7 +378,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_20 = { start.offset((len) as isize) }; let mut __v = Vec::new(); let mut __it = start; - while !WeaklyEqualityComparableWithUnsafe::equal(&__it, &__tmp_20) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_20) { __v.push((*__it.iter_deref())); __it.iter_inc(); } From 8fbc98bae80130bd00155c80b01224ca2440b279 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 13:41:59 +0000 Subject: [PATCH 13/18] Make WeaklyEqualityComparableWith symmetric --- cpp2rust/converter/converter.cpp | 61 +++-- cpp2rust/converter/converter.h | 12 +- cpp2rust/converter/converter_lib.cpp | 62 +++-- cpp2rust/converter/converter_lib.h | 5 + .../converter/models/converter_refcount.cpp | 11 +- .../converter/models/converter_refcount.h | 7 +- libcc2rs/src/cmp.rs | 10 +- rules/algorithm/tgt_refcount.rs | 2 +- rules/algorithm/tgt_unsafe.rs | 2 +- .../concept.equalitycomparable.cpp | 70 ++++++ .../refcount/concept.equalitycomparable.rs | 212 ++++++++++++++++++ .../out/unsafe/concept.equalitycomparable.rs | 179 +++++++++++++++ tests/unit/out/refcount/operator_friend.rs | 17 +- tests/unit/out/unsafe/operator_friend.rs | 17 +- 14 files changed, 606 insertions(+), 61 deletions(-) create mode 100644 tests/std/concepts/concepts.compare/concept.equalitycomparable.cpp create mode 100644 tests/std/concepts/concepts.compare/out/refcount/concept.equalitycomparable.rs create mode 100644 tests/std/concepts/concepts.compare/out/unsafe/concept.equalitycomparable.rs diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index bc0774d07a..60be4fa1b7 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -74,22 +74,40 @@ Converter::DeferredBlock &Converter::DeferredImpl(std::string header) { return it->second; } -void Converter::AddEqualityComparableMethod(const clang::CXXRecordDecl *record, +void Converter::AddEqualityComparableMethod(const clang::FunctionDecl *op, const RecordTrait &trait, std::string_view method) { + auto *record = GetComparisonRecord(op); auto name = GetRecordName(record); - if (&trait == &kWeaklyEqualityComparableWith) { - converted_record_traits_.emplace(name, trait.refcount.name); + clang::QualType lhs = ctx_.getCanonicalTagType(record); + auto rhs = GetComparisonRhsType(op); + if (lhs == rhs) { + EqualityComparableImpl(name, "").body += method; + if (&trait == &kWeaklyEqualityComparableWith) { + converted_record_traits_.emplace(name, trait.refcount.name); + } + return; + } + auto other = GetUnboxedTypeAsString(rhs); + EqualityComparableImpl(name, other).body += method; + if (&trait != &kWeaklyEqualityComparableWith || + HasEqualityOperator(ctx_, rhs, lhs)) { + return; } - EqualityComparableImplFor(record).body += method; + EqualityComparableImpl(other, name).body += + std::format("{} {{ <{} as {}<{}>>::{}(rhs, lhs) }}\n", + GetComparisonTraitSignature(trait, "lhs", "rhs", name), name, + GetRecordTraitSpelling(trait).name, other, trait.method); } Converter::DeferredBlock & -Converter::EqualityComparableImplFor(const clang::CXXRecordDecl *record) { - return DeferredImpl( - std::format("impl {} for {}", - GetRecordTraitSpelling(kWeaklyEqualityComparableWith).name, - GetRecordName(record))); +Converter::EqualityComparableImpl(std::string_view self, + std::string_view other) { + const char *name = GetRecordTraitSpelling(kWeaklyEqualityComparableWith).name; + if (other.empty()) { + return DeferredImpl(std::format("impl {} for {}", name, self)); + } + return DeferredImpl(std::format("impl {}<{}> for {}", name, other, self)); } void Converter::EmitUndefinedRecordTraits(Model model, std::string &out) { @@ -119,8 +137,10 @@ void Converter::DeclareRecordTraits(const clang::CXXRecordDecl *decl) { auto &traits = declared_record_traits_[GetRecordName(decl)]; for (auto *method : decl->methods()) { if (GetComparisonTrait(method)) { - traits.emplace(kWeaklyEqualityComparableWith.refcount.name, - &kWeaklyEqualityComparableWith); + if (IsSameTypeComparison(method, decl)) { + traits.emplace(kWeaklyEqualityComparableWith.refcount.name, + &kWeaklyEqualityComparableWith); + } } else if (auto *trait = GetRecordTrait(method); trait && !IsDerivedCopyOrMove(method)) { traits.emplace(trait->refcount.name, trait); @@ -570,7 +590,7 @@ void Converter::ConvertComparisonTraitImpl(clang::FunctionDecl *decl, } method = std::move(buf).str(); } - AddEqualityComparableMethod(GetComparisonRecord(decl), trait, method); + AddEqualityComparableMethod(decl, trait, method); } void Converter::EmitHoistedDecls(clang::CompoundStmt *body) { @@ -1196,7 +1216,7 @@ void Converter::ConvertCopyOrMoveTraitImpl(clang::CXXMethodDecl *method, return; } if (GetComparisonTrait(method)) { - AddEqualityComparableMethod(method->getParent(), trait, body); + AddEqualityComparableMethod(method, trait, body); return; } converted_record_traits_.emplace(GetRecordName(method->getParent()), @@ -6043,16 +6063,17 @@ void Converter::ConvertEqualityComparableImpl(const clang::CXXRecordDecl *decl, : kWeaklyEqualityComparableWith; auto [lhs, rhs] = GetComparisonOperandNames(op); AddEqualityComparableMethod( - decl, trait, - std::format("{} {{ {} }}\n", GetComparisonTraitSignature(trait, lhs, rhs), + op, trait, + std::format("{} {{ {} }}\n", + GetComparisonTraitSignature(trait, lhs, rhs, "Self"), GetComparisonBool(op, decl, lhs, rhs))); } -std::string Converter::GetComparisonTraitSignature(const RecordTrait &trait, - std::string_view lhs, - std::string_view rhs) const { - return std::format("unsafe fn {}({}: *const Self, {}: *const Self) -> bool", - trait.method, lhs, rhs); +std::string Converter::GetComparisonTraitSignature( + const RecordTrait &trait, std::string_view lhs, std::string_view rhs, + std::string_view rhs_type) const { + return std::format("unsafe fn {}({}: *const Self, {}: *const {}) -> bool", + trait.method, lhs, rhs, rhs_type); } void Converter::AddOrdTrait(const clang::CXXRecordDecl *decl) { diff --git a/cpp2rust/converter/converter.h b/cpp2rust/converter/converter.h index dd8f7cd7ba..074462a88a 100644 --- a/cpp2rust/converter/converter.h +++ b/cpp2rust/converter/converter.h @@ -490,9 +490,10 @@ class Converter : public clang::RecursiveASTVisitor { void ConvertComparisonTraitImpl(clang::FunctionDecl *decl, const RecordTrait &trait); - virtual std::string GetComparisonTraitSignature(const RecordTrait &trait, - std::string_view lhs, - std::string_view rhs) const; + virtual std::string + GetComparisonTraitSignature(const RecordTrait &trait, std::string_view lhs, + std::string_view rhs, + std::string_view rhs_type) const; std::pair GetComparisonOperandNames(const clang::FunctionDecl *op); @@ -1393,9 +1394,10 @@ class Converter : public clang::RecursiveASTVisitor { static DeferredBlock &DeferredImpl(std::string header); - DeferredBlock &EqualityComparableImplFor(const clang::CXXRecordDecl *record); + DeferredBlock &EqualityComparableImpl(std::string_view self, + std::string_view other); - void AddEqualityComparableMethod(const clang::CXXRecordDecl *record, + void AddEqualityComparableMethod(const clang::FunctionDecl *op, const RecordTrait &trait, std::string_view method); static std::map> diff --git a/cpp2rust/converter/converter_lib.cpp b/cpp2rust/converter/converter_lib.cpp index 34976632fb..eb4f59fef5 100644 --- a/cpp2rust/converter/converter_lib.cpp +++ b/cpp2rust/converter/converter_lib.cpp @@ -673,19 +673,50 @@ const clang::CXXRecordDecl *GetComparisonRecord(const clang::FunctionDecl *fn) { : nullptr; } -static bool HasSameTypeEqualityOperator(const clang::CXXRecordDecl *record) { +clang::QualType GetComparisonRhsType(const clang::FunctionDecl *fn) { + return fn->getParamDecl(fn->getNumParams() - 1) + ->getType() + .getNonReferenceType() + .getUnqualifiedType() + .getCanonicalType(); +} + +bool HasEqualityOperator(clang::ASTContext &ctx, clang::QualType lhs, + clang::QualType rhs) { + auto same = [](clang::QualType type, clang::QualType expected) { + return type.getNonReferenceType().getUnqualifiedType().getCanonicalType() == + expected; + }; auto is_equality = [&](const clang::NamedDecl *found) { auto *fn = clang::dyn_cast_or_null(found); - return fn && fn->getOverloadedOperator() == clang::OO_EqualEqual && - !fn->isDeleted() && IsSameTypeComparison(fn, record); + if (!fn || fn->getOverloadedOperator() != clang::OO_EqualEqual || + fn->isDeleted()) { + return false; + } + if (auto *method = clang::dyn_cast(fn)) { + return method->isInstance() && method->getNumParams() == 1 && + same(ctx.getCanonicalTagType(method->getParent()), lhs) && + same(method->getParamDecl(0)->getType(), rhs); + } + return fn->getNumParams() == 2 && + same(fn->getParamDecl(0)->getType(), lhs) && + same(fn->getParamDecl(1)->getType(), rhs); }; - auto name = record->getASTContext().DeclarationNames.getCXXOperatorName( - clang::OO_EqualEqual); - return llvm::any_of(record->methods(), is_equality) || - llvm::any_of(record->getDeclContext()->lookup(name), is_equality) || - llvm::any_of(record->friends(), [&](const clang::FriendDecl *decl) { - return is_equality(decl->getFriendDecl()); - }); + auto name = ctx.DeclarationNames.getCXXOperatorName(clang::OO_EqualEqual); + for (auto type : {lhs, rhs}) { + auto *record = type->getAsCXXRecordDecl(); + if (!record || !record->hasDefinition()) { + continue; + } + if (llvm::any_of(record->methods(), is_equality) || + llvm::any_of(record->getDeclContext()->lookup(name), is_equality) || + llvm::any_of(record->friends(), [&](const clang::FriendDecl *decl) { + return is_equality(decl->getFriendDecl()); + })) { + return true; + } + } + return false; } const RecordTrait *GetComparisonTrait(const clang::FunctionDecl *fn) { @@ -696,8 +727,11 @@ const RecordTrait *GetComparisonTrait(const clang::FunctionDecl *fn) { auto *record = GetComparisonRecord(fn); if (!record || !IsUserDefinedDecl(record) || fn->isDeleted() || fn->getDescribedFunctionTemplate() || - !fn->getReturnType()->isBooleanType() || - !IsSameTypeComparison(fn, record)) { + !fn->getReturnType()->isBooleanType()) { + return nullptr; + } + if (auto *method = clang::dyn_cast(fn); + method ? method->getNumParams() != 1 : fn->getNumParams() != 2) { return nullptr; } if (auto *method = clang::dyn_cast(fn); @@ -716,7 +750,9 @@ const RecordTrait *GetComparisonTrait(const clang::FunctionDecl *fn) { if (op == clang::OO_EqualEqual) { return &kWeaklyEqualityComparableWith; } - return HasSameTypeEqualityOperator(record) + auto &ctx = fn->getASTContext(); + return HasEqualityOperator(ctx, ctx.getCanonicalTagType(record), + GetComparisonRhsType(fn)) ? &kWeaklyEqualityComparableWithNotEqual : nullptr; } diff --git a/cpp2rust/converter/converter_lib.h b/cpp2rust/converter/converter_lib.h index 15348de110..8570fcd042 100644 --- a/cpp2rust/converter/converter_lib.h +++ b/cpp2rust/converter/converter_lib.h @@ -194,6 +194,11 @@ const RecordTrait *GetRecordTrait(const clang::CXXMethodDecl *method); const RecordTrait *GetComparisonTrait(const clang::FunctionDecl *fn); +clang::QualType GetComparisonRhsType(const clang::FunctionDecl *fn); + +bool HasEqualityOperator(clang::ASTContext &ctx, clang::QualType lhs, + clang::QualType rhs); + const clang::CXXRecordDecl *GetComparisonRecord(const clang::FunctionDecl *fn); // Whether method is a C++ defaulted copy or move member that is translated as diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index acbb6d60fb..9ab287222a 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -688,12 +688,11 @@ void ConverterRefCount::ConvertOrdAndPartialOrdTraits( } } -std::string -ConverterRefCount::GetComparisonTraitSignature(const RecordTrait &trait, - std::string_view lhs, - std::string_view rhs) const { - return std::format("fn {}({}: Ptr, {}: Ptr) -> bool", - trait.method, lhs, rhs); +std::string ConverterRefCount::GetComparisonTraitSignature( + const RecordTrait &trait, std::string_view lhs, std::string_view rhs, + std::string_view rhs_type) const { + return std::format("fn {}({}: Ptr, {}: Ptr<{}>) -> bool", trait.method, + lhs, rhs, rhs_type); } // Whether decl is copied by copying its bytes or the pointers it holds. diff --git a/cpp2rust/converter/models/converter_refcount.h b/cpp2rust/converter/models/converter_refcount.h index a3a1465525..d4446f434a 100644 --- a/cpp2rust/converter/models/converter_refcount.h +++ b/cpp2rust/converter/models/converter_refcount.h @@ -58,9 +58,10 @@ class ConverterRefCount final : public Converter { const clang::FunctionDecl *lt, const clang::FunctionDecl *cmp) override; - std::string GetComparisonTraitSignature(const RecordTrait &trait, - std::string_view lhs, - std::string_view rhs) const override; + std::string + GetComparisonTraitSignature(const RecordTrait &trait, std::string_view lhs, + std::string_view rhs, + std::string_view rhs_type) const override; bool RecordImplementsClone(const clang::RecordDecl *decl) override; diff --git a/libcc2rs/src/cmp.rs b/libcc2rs/src/cmp.rs index f7d96a17f5..0435e70ce9 100644 --- a/libcc2rs/src/cmp.rs +++ b/libcc2rs/src/cmp.rs @@ -14,7 +14,11 @@ pub trait CppLess: Sized { fn less(lhs: Ptr, rhs: Ptr) -> bool; } -pub trait WeaklyEqualityComparableWith: Sized { +// TODO: equal and not_equal return a boolean-testable type in C++ +// ([concept.booleantestable]); replace bool with BooleanTestable. +pub trait WeaklyEqualityComparableWith = Self>: + Sized +{ fn equal(this: Ptr, rhs: Ptr) -> bool; fn not_equal(this: Ptr, rhs: Ptr) -> bool { @@ -22,7 +26,9 @@ pub trait WeaklyEqualityComparableWith: Sized { } } -pub trait WeaklyEqualityComparableWithUnsafe: Sized { +pub trait WeaklyEqualityComparableWithUnsafe = Self>: + Sized +{ /// # Safety /// `rhs` must point to a live value. unsafe fn equal(this: *const Self, rhs: *const U) -> bool; diff --git a/rules/algorithm/tgt_refcount.rs b/rules/algorithm/tgt_refcount.rs index 9164df44d9..1df7cc903f 100644 --- a/rules/algorithm/tgt_refcount.rs +++ b/rules/algorithm/tgt_refcount.rs @@ -34,7 +34,7 @@ fn f2< __out } -fn f3, T2, T3: WeaklyEqualityComparableWith>(a0: T1, a1: T1, a2: Ptr) -> T1 { +fn f3, 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()) diff --git a/rules/algorithm/tgt_unsafe.rs b/rules/algorithm/tgt_unsafe.rs index 0038c80ea8..7a1531f4de 100644 --- a/rules/algorithm/tgt_unsafe.rs +++ b/rules/algorithm/tgt_unsafe.rs @@ -32,7 +32,7 @@ unsafe fn f2, T2: UnsafeCppIterator, T3, T4: __out } -unsafe fn f3, T2, T3: WeaklyEqualityComparableWithUnsafe>(a0: T1, a1: T1, a2: T2) -> T1 { +unsafe fn f3, 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) { __it.iter_inc(); diff --git a/tests/std/concepts/concepts.compare/concept.equalitycomparable.cpp b/tests/std/concepts/concepts.compare/concept.equalitycomparable.cpp new file mode 100644 index 0000000000..308a473718 --- /dev/null +++ b/tests/std/concepts/concepts.compare/concept.equalitycomparable.cpp @@ -0,0 +1,70 @@ +// ADDITIONAL_COMPILE_FLAGS: -std=c++23 +#include +#include +#include + +// N4950 [concept.equalitycomparable]/1.3: t != u is the opposite of t == u, +// also when the type defines both operators. +namespace p1_3_not_equal { +static int not_equal_calls = 0; + +struct Meters { + int value; + bool operator==(const Meters &other) const { return value == other.value; } + bool operator!=(const Meters &other) const { + ++not_equal_calls; + return value != other.value; + } +}; + +void test() { + Meters three{3}; + Meters also_three{3}; + Meters four{4}; + assert(three == also_three); + assert(!(three != also_three)); + assert(three != four); + assert(not_equal_calls == 2); +} +} // namespace p1_3_not_equal + +// N4950 [concept.equalitycomparable]/1.2, /1.4: u == t and u != t give the +// results of t == u and t != u. +namespace p1_2_reversed_operands { +struct Meters { + int value; + bool operator==(const int &other) const { return value == other; } +}; + +void test() { + Meters three{3}; + assert(three == 3); + assert(3 == three); + assert(three != 4); + assert(4 != three); +} +} // namespace p1_2_reversed_operands + +// N4950 [concept.equalitycomparable]/1: the operands may have different +// types. +namespace p1_different_types { +struct Meters { + int value; + bool operator==(const int &other) const { return value == other; } +}; + +void test() { + std::vector lengths{{1}, {2}, {3}}; + auto found = std::find(lengths.begin(), lengths.end(), 2); + assert(found != lengths.end()); + assert(found->value == 2); + assert(std::find(lengths.begin(), lengths.end(), 7) == lengths.end()); +} +} // namespace p1_different_types + +int main() { + p1_3_not_equal::test(); + p1_2_reversed_operands::test(); + p1_different_types::test(); + return 0; +} diff --git a/tests/std/concepts/concepts.compare/out/refcount/concept.equalitycomparable.rs b/tests/std/concepts/concepts.compare/out/refcount/concept.equalitycomparable.rs new file mode 100644 index 0000000000..ac6ac28c57 --- /dev/null +++ b/tests/std/concepts/concepts.compare/out/refcount/concept.equalitycomparable.rs @@ -0,0 +1,212 @@ +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}; +thread_local!( + pub static not_equal_calls_0: Value = Rc::new(RefCell::new(0)); +); +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, +)] +#[byte_size(4)] +pub struct p1_3_not_equal_Meters { + #[offset(0)] + pub value: i32, +} +pub fn test_1() { + let three: Value = + Rc::new(RefCell::new(p1_3_not_equal_Meters { value: 3 })); + let also_three: Value = + Rc::new(RefCell::new(p1_3_not_equal_Meters { value: 3 })); + let four: Value = + Rc::new(RefCell::new(p1_3_not_equal_Meters { value: 4 })); + assert!( + ({ WeaklyEqualityComparableWith::equal(three.as_pointer(), also_three.as_pointer(),) }) + ); + assert!( + !({ + WeaklyEqualityComparableWith::not_equal(three.as_pointer(), also_three.as_pointer()) + }) + ); + assert!(({ WeaklyEqualityComparableWith::not_equal(three.as_pointer(), four.as_pointer(),) })); + assert!((not_equal_calls_0.with(|rc| *rc.borrow()) == 2)); +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, +)] +#[byte_size(4)] +pub struct p1_2_reversed_operands_Meters { + #[offset(0)] + pub value: i32, +} +pub fn test_2() { + let three: Value = + Rc::new(RefCell::new(p1_2_reversed_operands_Meters { value: 3 })); + assert!( + ({ + let _other: Value = Rc::new(RefCell::new(3)); + WeaklyEqualityComparableWith::equal(three.as_pointer(), _other.as_pointer()) + }) + ); + assert!( + ({ + let _other: Value = Rc::new(RefCell::new(3)); + WeaklyEqualityComparableWith::equal(three.as_pointer(), _other.as_pointer()) + }) + ); + assert!( + !({ + let _other: Value = Rc::new(RefCell::new(4)); + WeaklyEqualityComparableWith::equal(three.as_pointer(), _other.as_pointer()) + }) + ); + assert!( + !({ + let _other: Value = Rc::new(RefCell::new(4)); + WeaklyEqualityComparableWith::equal(three.as_pointer(), _other.as_pointer()) + }) + ); +} +#[derive( + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + TriviallyDefaultConstructible, + TriviallyCopyable, + Default, +)] +#[byte_size(4)] +pub struct p1_different_types_Meters { + #[offset(0)] + pub value: i32, +} +pub fn test_3() { + let lengths: Value> = Rc::new(RefCell::new(Vec::from([ + p1_different_types_Meters { value: 1 }, + p1_different_types_Meters { value: 2 }, + p1_different_types_Meters { value: 3 }, + ]))); + let found: Value> = Rc::new(RefCell::new( + ({ + let __tmp_0: Value = Rc::new(RefCell::new(2)); + { + let __it: Value> = + Rc::new(RefCell::new(lengths.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(lengths.decay().end())); + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_0.as_pointer().clone(), + ) { + __it.borrow_mut().iter_inc(); + } + __it.borrow().clone() + } + }), + )); + assert!(WeaklyEqualityComparableWith::not_equal( + found.as_pointer(), + Rc::new(RefCell::new(lengths.decay().end())).as_pointer() + )); + assert!((({ (*found.borrow()).iter_deref() }).with(|__s| __s.value) == 2)); + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_2: Value = Rc::new(RefCell::new(7)); + { + let __it: Value> = + Rc::new(RefCell::new(lengths.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(lengths.decay().end())); + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_2.as_pointer().clone(), + ) { + __it.borrow_mut().iter_inc(); + } + __it.borrow().clone() + } + }) + )) + .as_pointer(), + Rc::new(RefCell::new(lengths.decay().end())).as_pointer(), + ) { + (__tmp_1, __tmp_3) => { + WeaklyEqualityComparableWith::equal((__tmp_1).clone(), (__tmp_3).clone()) + } + }); +} +pub fn main() { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0()); +} +fn main_0() -> i32 { + ({ test_1() }); + ({ test_2() }); + ({ test_3() }); + return 0; +} +impl WeaklyEqualityComparableWith for p1_3_not_equal_Meters { + fn equal(this: Ptr, other: Ptr) -> bool { + return ({ this.with(|__s| __s.value) } == { other.with(|__s| __s.value) }); + } + fn not_equal(this: Ptr, other: Ptr) -> bool { + (*not_equal_calls_0.with(Value::clone).borrow_mut()).prefix_inc(); + return ({ this.with(|__s| __s.value) } != { other.with(|__s| __s.value) }); + } +} +impl WeaklyEqualityComparableWith for p1_2_reversed_operands_Meters { + fn equal(this: Ptr, other: Ptr) -> bool { + return ({ this.with(|__s| __s.value) } == { (other.read()) }); + } +} +impl WeaklyEqualityComparableWith for p1_different_types_Meters { + fn equal(this: Ptr, other: Ptr) -> bool { + return ({ this.with(|__s| __s.value) } == { (other.read()) }); + } +} +impl WeaklyEqualityComparableWith for i32 { + fn equal(lhs: Ptr, rhs: Ptr) -> bool { + >::equal(rhs, lhs) + } +} +impl WeaklyEqualityComparableWith for i32 { + fn equal(lhs: Ptr, rhs: Ptr) -> bool { + >::equal(rhs, lhs) + } +} +pub fn __cpp2rust_init_globals() { + let _ = not_equal_calls_0.with(|_| ()); +} diff --git a/tests/std/concepts/concepts.compare/out/unsafe/concept.equalitycomparable.rs b/tests/std/concepts/concepts.compare/out/unsafe/concept.equalitycomparable.rs new file mode 100644 index 0000000000..cd4e166a0e --- /dev/null +++ b/tests/std/concepts/concepts.compare/out/unsafe/concept.equalitycomparable.rs @@ -0,0 +1,179 @@ +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 static mut not_equal_calls_0: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0 }); +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, +)] +pub struct p1_3_not_equal_Meters { + pub value: i32, +} +impl std::cmp::PartialEq for p1_3_not_equal_Meters { + fn eq(&self, other: &Self) -> bool { + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } + } +} +impl std::cmp::Eq for p1_3_not_equal_Meters {} +pub unsafe fn test_1() { + let mut three: p1_3_not_equal_Meters = p1_3_not_equal_Meters { value: 3 }; + let mut also_three: p1_3_not_equal_Meters = p1_3_not_equal_Meters { value: 3 }; + let mut four: p1_3_not_equal_Meters = p1_3_not_equal_Meters { value: 4 }; + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const three, &also_three,) })); + assert!( + !(unsafe { WeaklyEqualityComparableWithUnsafe::not_equal(&raw const three, &also_three,) }) + ); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::not_equal(&raw const three, &four,) })); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut not_equal_calls_0)) == (2))); +} +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, +)] +pub struct p1_2_reversed_operands_Meters { + pub value: i32, +} +pub unsafe fn test_2() { + let mut three: p1_2_reversed_operands_Meters = p1_2_reversed_operands_Meters { value: 3 }; + assert!( + (unsafe { + let mut _other: i32 = 3; + WeaklyEqualityComparableWithUnsafe::equal(&raw const three, &mut _other) + }) + ); + assert!( + (unsafe { + let mut _other: i32 = 3; + WeaklyEqualityComparableWithUnsafe::equal(&raw const three, &mut _other) + }) + ); + assert!( + !(unsafe { + let mut _other: i32 = 4; + WeaklyEqualityComparableWithUnsafe::equal(&raw const three, &mut _other) + }) + ); + assert!( + !(unsafe { + let mut _other: i32 = 4; + WeaklyEqualityComparableWithUnsafe::equal(&raw const three, &mut _other) + }) + ); +} +#[repr(C)] +#[derive( + Copy, + Clone, + VaArg, + FnPtrArg, + ZeroInitializationUnsafe, + TriviallyDefaultConstructibleUnsafe, + TriviallyCopyableUnsafe, + Default, +)] +pub struct p1_different_types_Meters { + pub value: i32, +} +pub unsafe fn test_3() { + let mut lengths: Vec = Vec::from([ + p1_different_types_Meters { value: 1 }, + p1_different_types_Meters { value: 2 }, + p1_different_types_Meters { value: 3 }, + ]); + let mut found: UnsafeRandomAccessIterator = { + let mut __tmp_0 = { lengths.begin() }; + let mut __tmp_1 = { lengths.end() }; + let mut __it = (__tmp_0).clone(); + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &2) + { + __it.iter_inc(); + } + __it + }; + assert!(WeaklyEqualityComparableWithUnsafe::not_equal( + &found, + &lengths.end() + )); + assert!((((*found.iter_deref()).value) == (2))); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ + let mut __tmp_2 = { lengths.begin() }; + let mut __tmp_3 = { lengths.end() }; + let mut __it = (__tmp_2).clone(); + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &7) + { + __it.iter_inc(); + } + __it + }, + &lengths.end() + )); +} +pub fn main() { + unsafe { + __cpp2rust_init_globals(); + libcc2rs::cpp2rust_exit(main_0() as i32); + } +} +unsafe fn main_0() -> i32 { + (unsafe { test_1() }); + (unsafe { test_2() }); + (unsafe { test_3() }); + return 0; +} +impl WeaklyEqualityComparableWithUnsafe for p1_3_not_equal_Meters { + unsafe fn equal(this: *const Self, other: *const p1_3_not_equal_Meters) -> bool { + return (((*this).value) == ((*other).value)); + } + unsafe fn not_equal(this: *const Self, other: *const p1_3_not_equal_Meters) -> bool { + (*std::cell::LazyCell::force_mut(&mut *&raw mut not_equal_calls_0)).prefix_inc(); + return (((*this).value) != ((*other).value)); + } +} +impl WeaklyEqualityComparableWithUnsafe for p1_2_reversed_operands_Meters { + unsafe fn equal(this: *const Self, other: *const i32) -> bool { + return (((*this).value) == (*other)); + } +} +impl WeaklyEqualityComparableWithUnsafe for p1_different_types_Meters { + unsafe fn equal(this: *const Self, other: *const i32) -> bool { + return (((*this).value) == (*other)); + } +} +impl WeaklyEqualityComparableWithUnsafe for i32 { + unsafe fn equal(lhs: *const Self, rhs: *const p1_2_reversed_operands_Meters) -> bool { + >::equal(rhs, lhs) + } +} +impl WeaklyEqualityComparableWithUnsafe for i32 { + unsafe fn equal(lhs: *const Self, rhs: *const p1_different_types_Meters) -> bool { + >::equal(rhs, lhs) + } +} +pub unsafe fn __cpp2rust_init_globals() { + std::cell::LazyCell::force(&*&raw const not_equal_calls_0); +} diff --git a/tests/unit/out/refcount/operator_friend.rs b/tests/unit/out/refcount/operator_friend.rs index 6d240efaf6..84cd7bd9af 100644 --- a/tests/unit/out/refcount/operator_friend.rs +++ b/tests/unit/out/refcount/operator_friend.rs @@ -109,9 +109,6 @@ pub struct OutOfLine { pub fn operator_lt_3(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.v) } < { y.with(|__s| __s.v) }); } -pub fn operator_eq_4(x: Ptr, y: Ptr) -> bool { - return ({ (x.with(|__s| __s.v) as i64) } == { y.with(|__s| __s.v) }); -} #[derive( Copy, Clone, @@ -218,8 +215,8 @@ fn main_0() -> i32 { assert!(({ operator_lt_3(t1.as_pointer(), t2.as_pointer(),) })); let u1: Value = Rc::new(RefCell::new(Tmpl_long_ { v: 1_i64 })); let u2: Value = Rc::new(RefCell::new(Tmpl_long_ { v: 2_i64 })); - assert!(({ operator_eq_4(t1.as_pointer(), u1.as_pointer(),) })); - assert!(!({ operator_eq_4(t1.as_pointer(), u2.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(t1.as_pointer(), u1.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(t1.as_pointer(), u2.as_pointer(),) })); let v1: Value = Rc::new(RefCell::new(TmplDefaulted_int_ { v: 7 })); let v2: Value = Rc::new(RefCell::new(TmplDefaulted_int_ { v: 7 })); let v3: Value = Rc::new(RefCell::new(TmplDefaulted_int_ { v: 8 })); @@ -262,4 +259,14 @@ impl WeaklyEqualityComparableWith for Tmpl_int_ { return ({ x.with(|__s| __s.v) } == { y.with(|__s| __s.v) }); } } +impl WeaklyEqualityComparableWith for Tmpl_long_ { + fn equal(lhs: Ptr, rhs: Ptr) -> bool { + >::equal(rhs, lhs) + } +} +impl WeaklyEqualityComparableWith for Tmpl_int_ { + fn equal(x: Ptr, y: Ptr) -> bool { + return ({ (x.with(|__s| __s.v) as i64) } == { y.with(|__s| __s.v) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_friend.rs b/tests/unit/out/unsafe/operator_friend.rs index d39340c824..f254b59214 100644 --- a/tests/unit/out/unsafe/operator_friend.rs +++ b/tests/unit/out/unsafe/operator_friend.rs @@ -146,9 +146,6 @@ impl std::cmp::Eq for OutOfLine {} pub unsafe fn operator_lt_3(x: *const Tmpl_int_, y: *const Tmpl_int_) -> bool { return (((*x).v) < ((*y).v)); } -pub unsafe fn operator_eq_4(x: *const Tmpl_int_, y: *const Tmpl_long_) -> bool { - return (((*x).v as i64) == ((*y).v)); -} #[repr(C)] #[derive( Copy, @@ -364,13 +361,13 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const Tmpl_int_ = &t1; - operator_eq_4(_x, &u1) + WeaklyEqualityComparableWithUnsafe::equal(_x, &u1) }) ); assert!( !(unsafe { let _x: *const Tmpl_int_ = &t1; - operator_eq_4(_x, &u2) + WeaklyEqualityComparableWithUnsafe::equal(_x, &u2) }) ); let mut v1: TmplDefaulted_int_ = TmplDefaulted_int_ { v: 7 }; @@ -432,4 +429,14 @@ impl WeaklyEqualityComparableWithUnsafe for Tmpl_int_ { return (((*x).v) == ((*y).v)); } } +impl WeaklyEqualityComparableWithUnsafe for Tmpl_long_ { + unsafe fn equal(lhs: *const Self, rhs: *const Tmpl_int_) -> bool { + >::equal(rhs, lhs) + } +} +impl WeaklyEqualityComparableWithUnsafe for Tmpl_int_ { + unsafe fn equal(x: *const Tmpl_int_, y: *const Tmpl_long_) -> bool { + return (((*x).v as i64) == ((*y).v)); + } +} pub unsafe fn __cpp2rust_init_globals() {} From 449ebef2bde5670a3715bbb2c0f55e44dda78c63 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 13:56:08 +0000 Subject: [PATCH 14/18] Remove PartialEq where possible --- cpp2rust/converter/converter.cpp | 21 ++++++----- libcc2rs/src/cmp.rs | 65 +++++++++++++++++++++++++++++--- rules/iterator_category/shim.rs | 7 +--- 3 files changed, 73 insertions(+), 20 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 60be4fa1b7..4c66e694ed 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -5903,20 +5903,21 @@ bool Converter::ConvertOutOfLineVirtualMethod(clang::CXXMethodDecl *decl) { void Converter::ConvertOrdAndPartialOrdTraitsBase( std::string_view cmp_body, std::string_view eq_body, std::string_view record_name) { - if (!cmp_body.empty()) { - StrCat(keyword::kImpl, "std::cmp::Ord for ", record_name, '{'); - StrCat("fn cmp(&self, other: &Self) -> std::cmp::Ordering {"); - StrCat(std::format("{} {{", keyword_unsafe_)); - StrCat(cmp_body); - StrCat("}}}"); - - StrCat(keyword::kImpl, "std::cmp::PartialOrd for", record_name, '{'); - StrCat(R"( + if (cmp_body.empty()) { + return; + } + StrCat(keyword::kImpl, "std::cmp::Ord for ", record_name, '{'); + StrCat("fn cmp(&self, other: &Self) -> std::cmp::Ordering {"); + StrCat(std::format("{} {{", keyword_unsafe_)); + StrCat(cmp_body); + StrCat("}}}"); + + StrCat(keyword::kImpl, "std::cmp::PartialOrd for", record_name, '{'); + StrCat(R"( fn partial_cmp(&self, other: &Self) -> Option { Some(self.cmp(other)) } })"); - } StrCat(keyword::kImpl, "std::cmp::PartialEq for", record_name, '{'); StrCat("fn eq(&self, other: &Self) -> bool {"); diff --git a/libcc2rs/src/cmp.rs b/libcc2rs/src/cmp.rs index 0435e70ce9..dfaae69cdd 100644 --- a/libcc2rs/src/cmp.rs +++ b/libcc2rs/src/cmp.rs @@ -6,7 +6,7 @@ use std::cmp::Ordering; -use crate::rc::Ptr; +use crate::rc::{AsPointer, Ptr, Value}; use crate::reinterpret::ByteRepr; // operator<. Records implement it with their comparison operators. @@ -111,19 +111,74 @@ impl_weakly_equality_comparable_with!( <> bool, <> i8, <> i16, <> i32, <> i64, <> i128, <> isize, <> u8, <> u16, <> u32, <> u64, <> u128, <> usize, <> f32, <> f64, Ptr, <> crate::AnyPtr, crate::FnPtr, - Vec, Box<[T]>, Option, (A, B), + Option, ); +impl WeaklyEqualityComparableWith for Vec { + fn equal(this: Ptr, rhs: Ptr) -> bool { + let len = this.with(Vec::len); + let (a, b) = (this.decay(), rhs.decay()); + len == rhs.with(Vec::len) && (0..len).all(|i| T::equal(a.offset(i), b.offset(i))) + } +} + +impl WeaklyEqualityComparableWith for Box<[T]> { + fn equal(this: Ptr, rhs: Ptr) -> bool { + let len = this.with(|elems| elems.len()); + let (a, b) = (this.decay(), rhs.decay()); + len == rhs.with(|elems| elems.len()) && (0..len).all(|i| T::equal(a.offset(i), b.offset(i))) + } +} + +impl WeaklyEqualityComparableWith + for (Value, Value) +where + Self: ByteRepr, +{ + fn equal(this: Ptr, rhs: Ptr) -> bool { + let pointers = |pair: &Self| { + ( + AsPointer::::as_pointer(&pair.0), + AsPointer::::as_pointer(&pair.1), + ) + }; + let (a0, a1) = this.with(pointers); + let (b0, b1) = rhs.with(pointers); + A::equal(a0, b0) && B::equal(a1, b1) + } +} + impl_weakly_equality_comparable_with_unsafe!( <> bool, <> i8, <> i16, <> i32, <> i64, <> i128, <> isize, <> u8, <> u16, <> u32, <> u64, <> u128, <> usize, <> f32, <> f64, *mut T, *const T, crate::FnPtr, - Vec, Option, (A, B), + Option, ); -impl WeaklyEqualityComparableWithUnsafe for [T; N] { +impl WeaklyEqualityComparableWithUnsafe for Vec { unsafe fn equal(this: *const Self, rhs: *const Self) -> bool { - unsafe { *this == *rhs } + unsafe { + let (len, a, b) = ((*this).len(), (*this).as_ptr(), (*rhs).as_ptr()); + len == (*rhs).len() && (0..len).all(|i| T::equal(a.add(i), b.add(i))) + } + } +} + +impl WeaklyEqualityComparableWithUnsafe for [T; N] { + unsafe fn equal(this: *const Self, rhs: *const Self) -> bool { + let (a, b) = (this as *const T, rhs as *const T); + (0..N).all(|i| unsafe { T::equal(a.add(i), b.add(i)) }) + } +} + +impl WeaklyEqualityComparableWithUnsafe + for (A, B) +{ + unsafe fn equal(this: *const Self, rhs: *const Self) -> bool { + unsafe { + A::equal(&raw const (*this).0, &raw const (*rhs).0) + && B::equal(&raw const (*this).1, &raw const (*rhs).1) + } } } diff --git a/rules/iterator_category/shim.rs b/rules/iterator_category/shim.rs index 99716165b7..1b6e93a23d 100644 --- a/rules/iterator_category/shim.rs +++ b/rules/iterator_category/shim.rs @@ -18,7 +18,7 @@ pub trait CppIterator: Clone { fn iter_post_inc(&mut self) -> Self; } -pub trait CppInputIterator: CppIterator + PartialEq + EqualityComparable {} +pub trait CppInputIterator: CppIterator + EqualityComparable {} pub trait CppBidirectionalIterator: CppInputIterator { fn iter_dec(&mut self) -> &mut Self; @@ -38,10 +38,7 @@ pub trait UnsafeCppIterator: Clone { fn iter_post_inc(&mut self) -> Self; } -pub trait UnsafeCppInputIterator: - UnsafeCppIterator + PartialEq + EqualityComparableUnsafe -{ -} +pub trait UnsafeCppInputIterator: UnsafeCppIterator + EqualityComparableUnsafe {} pub trait UnsafeCppBidirectionalIterator: UnsafeCppInputIterator { fn iter_dec(&mut self) -> &mut Self; From 030786f1c8817fa73bada8db741be291082edd6b Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 13:58:08 +0000 Subject: [PATCH 15/18] Update tests --- .../out/unsafe/concept.equalitycomparable.rs | 8 ------- tests/unit/out/unsafe/class.rs | 8 ------- tests/unit/out/unsafe/find.rs | 8 ------- tests/unit/out/unsafe/friend.rs | 8 ------- .../unsafe/operator_comparison_defaulted.rs | 8 ------- .../out/unsafe/operator_comparison_nonbool.rs | 11 --------- tests/unit/out/unsafe/operator_friend.rs | 24 ------------------- tests/unit/out/unsafe/operator_traits.rs | 8 ------- 8 files changed, 83 deletions(-) diff --git a/tests/std/concepts/concepts.compare/out/unsafe/concept.equalitycomparable.rs b/tests/std/concepts/concepts.compare/out/unsafe/concept.equalitycomparable.rs index cd4e166a0e..527546e493 100644 --- a/tests/std/concepts/concepts.compare/out/unsafe/concept.equalitycomparable.rs +++ b/tests/std/concepts/concepts.compare/out/unsafe/concept.equalitycomparable.rs @@ -22,14 +22,6 @@ pub static mut not_equal_calls_0: std::cell::LazyCell = pub struct p1_3_not_equal_Meters { pub value: i32, } -impl std::cmp::PartialEq for p1_3_not_equal_Meters { - fn eq(&self, other: &Self) -> bool { - unsafe { - WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) - } - } -} -impl std::cmp::Eq for p1_3_not_equal_Meters {} pub unsafe fn test_1() { let mut three: p1_3_not_equal_Meters = p1_3_not_equal_Meters { value: 3 }; let mut also_three: p1_3_not_equal_Meters = p1_3_not_equal_Meters { value: 3 }; diff --git a/tests/unit/out/unsafe/class.rs b/tests/unit/out/unsafe/class.rs index 0b457cc02d..a1be7efaff 100644 --- a/tests/unit/out/unsafe/class.rs +++ b/tests/unit/out/unsafe/class.rs @@ -93,14 +93,6 @@ impl Counter { return (*this).v; } } -impl std::cmp::PartialEq for Counter { - fn eq(&self, other: &Self) -> bool { - unsafe { - WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) - } - } -} -impl std::cmp::Eq for Counter {} #[repr(C)] #[derive( Copy, diff --git a/tests/unit/out/unsafe/find.rs b/tests/unit/out/unsafe/find.rs index 1c03f0b4ac..3861d5282c 100644 --- a/tests/unit/out/unsafe/find.rs +++ b/tests/unit/out/unsafe/find.rs @@ -20,14 +20,6 @@ use std::rc::Rc; pub struct P { pub x: i32, } -impl std::cmp::PartialEq for P { - fn eq(&self, other: &Self) -> bool { - unsafe { - WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) - } - } -} -impl std::cmp::Eq for P {} pub fn main() { unsafe { __cpp2rust_init_globals(); diff --git a/tests/unit/out/unsafe/friend.rs b/tests/unit/out/unsafe/friend.rs index 9c2281c35d..54853b5c19 100644 --- a/tests/unit/out/unsafe/friend.rs +++ b/tests/unit/out/unsafe/friend.rs @@ -29,14 +29,6 @@ pub unsafe fn scaled_2(v: *const V, mut k: f64) -> f64 { pub struct V { pub x: i32, } -impl std::cmp::PartialEq for V { - fn eq(&self, other: &Self) -> bool { - unsafe { - WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) - } - } -} -impl std::cmp::Eq for V {} pub unsafe fn get_3(w: *const W_int_) -> i32 { return (*w).x; } diff --git a/tests/unit/out/unsafe/operator_comparison_defaulted.rs b/tests/unit/out/unsafe/operator_comparison_defaulted.rs index be6434480d..466114ab9f 100644 --- a/tests/unit/out/unsafe/operator_comparison_defaulted.rs +++ b/tests/unit/out/unsafe/operator_comparison_defaulted.rs @@ -21,14 +21,6 @@ pub struct Eq { pub a: i32, pub b: i32, } -impl std::cmp::PartialEq for Eq { - fn eq(&self, other: &Self) -> bool { - unsafe { - WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) - } - } -} -impl std::cmp::Eq for Eq {} #[repr(C)] #[derive( Copy, diff --git a/tests/unit/out/unsafe/operator_comparison_nonbool.rs b/tests/unit/out/unsafe/operator_comparison_nonbool.rs index ec7169d6ed..215a3e07c6 100644 --- a/tests/unit/out/unsafe/operator_comparison_nonbool.rs +++ b/tests/unit/out/unsafe/operator_comparison_nonbool.rs @@ -306,17 +306,6 @@ impl RefInt { return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut ref_true_8)); } } -impl std::cmp::PartialEq for RefInt { - fn eq(&self, other: &Self) -> bool { - unsafe { - { - let __cmp = RefInt::operator_eq((self as *const Self), (other as *const Self)); - RefBool::to_bool((__cmp as *const _)) - } - } - } -} -impl std::cmp::Eq for RefInt {} pub fn main() { unsafe { __cpp2rust_init_globals(); diff --git a/tests/unit/out/unsafe/operator_friend.rs b/tests/unit/out/unsafe/operator_friend.rs index f254b59214..d8a6e88031 100644 --- a/tests/unit/out/unsafe/operator_friend.rs +++ b/tests/unit/out/unsafe/operator_friend.rs @@ -21,14 +21,6 @@ pub struct Defaulted { pub a: i32, pub b: i32, } -impl std::cmp::PartialEq for Defaulted { - fn eq(&self, other: &Self) -> bool { - unsafe { - WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) - } - } -} -impl std::cmp::Eq for Defaulted {} pub unsafe fn operator_cmp_0( _a0: *const DefaultedOrd, _a1: *const DefaultedOrd, @@ -135,14 +127,6 @@ impl std::cmp::Eq for Inline {} pub struct OutOfLine { pub a: i32, } -impl std::cmp::PartialEq for OutOfLine { - fn eq(&self, other: &Self) -> bool { - unsafe { - WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) - } - } -} -impl std::cmp::Eq for OutOfLine {} pub unsafe fn operator_lt_3(x: *const Tmpl_int_, y: *const Tmpl_int_) -> bool { return (((*x).v) < ((*y).v)); } @@ -214,14 +198,6 @@ pub struct Tmpl_long_ { pub struct TmplDefaulted_int_ { pub v: i32, } -impl std::cmp::PartialEq for TmplDefaulted_int_ { - fn eq(&self, other: &Self) -> bool { - unsafe { - WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) - } - } -} -impl std::cmp::Eq for TmplDefaulted_int_ {} pub fn main() { unsafe { __cpp2rust_init_globals(); diff --git a/tests/unit/out/unsafe/operator_traits.rs b/tests/unit/out/unsafe/operator_traits.rs index b5881ec210..da0b07ce0f 100644 --- a/tests/unit/out/unsafe/operator_traits.rs +++ b/tests/unit/out/unsafe/operator_traits.rs @@ -66,14 +66,6 @@ impl std::cmp::Eq for Lt {} pub struct Eq { pub v: i32, } -impl std::cmp::PartialEq for Eq { - fn eq(&self, other: &Self) -> bool { - unsafe { - WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) - } - } -} -impl std::cmp::Eq for Eq {} #[repr(C)] #[derive( Copy, From 548778a189ed87b117e0d23bead8305adccfdb77 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 14:08:06 +0000 Subject: [PATCH 16/18] Add WeaklyEqualityComparableWith for refcount pointers --- libcc2rs/src/cmp.rs | 6 ++---- libcc2rs/src/fn_ptr.rs | 12 ++++++++++++ libcc2rs/src/void.rs | 6 ++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/libcc2rs/src/cmp.rs b/libcc2rs/src/cmp.rs index dfaae69cdd..92c6b8d0d4 100644 --- a/libcc2rs/src/cmp.rs +++ b/libcc2rs/src/cmp.rs @@ -110,8 +110,7 @@ pub(crate) use impl_weakly_equality_comparable_with_unsafe; impl_weakly_equality_comparable_with!( <> bool, <> i8, <> i16, <> i32, <> i64, <> i128, <> isize, <> u8, <> u16, <> u32, <> u64, <> u128, <> usize, <> f32, <> f64, - Ptr, <> crate::AnyPtr, crate::FnPtr, - Option, + Ptr, Option, ); impl WeaklyEqualityComparableWith for Vec { @@ -151,8 +150,7 @@ where impl_weakly_equality_comparable_with_unsafe!( <> bool, <> i8, <> i16, <> i32, <> i64, <> i128, <> isize, <> u8, <> u16, <> u32, <> u64, <> u128, <> usize, <> f32, <> f64, - *mut T, *const T, crate::FnPtr, - Option, + *mut T, *const T, Option, ); impl WeaklyEqualityComparableWithUnsafe for Vec { diff --git a/libcc2rs/src/fn_ptr.rs b/libcc2rs/src/fn_ptr.rs index aa5c2dbb0d..c149582224 100644 --- a/libcc2rs/src/fn_ptr.rs +++ b/libcc2rs/src/fn_ptr.rs @@ -493,6 +493,18 @@ impl PartialEq for FnPtr { impl Eq for FnPtr {} +impl crate::WeaklyEqualityComparableWith for FnPtr { + fn equal(this: crate::Ptr, rhs: crate::Ptr) -> bool { + this.with(|a| rhs.with(|b| a.addr == b.addr)) + } +} + +impl crate::WeaklyEqualityComparableWithUnsafe for FnPtr { + unsafe fn equal(this: *const Self, rhs: *const Self) -> bool { + unsafe { (*this).addr == (*rhs).addr } + } +} + impl ByteRepr for FnPtr {} impl crate::ZeroInitialization for FnPtr { diff --git a/libcc2rs/src/void.rs b/libcc2rs/src/void.rs index 9b8d672467..6a737d9af9 100644 --- a/libcc2rs/src/void.rs +++ b/libcc2rs/src/void.rs @@ -140,6 +140,12 @@ impl PartialEq for AnyPtr { } } +impl crate::WeaklyEqualityComparableWith for AnyPtr { + fn equal(this: crate::Ptr, rhs: crate::Ptr) -> bool { + this.with(|a| rhs.with(|b| *a.ptr == *b.ptr)) + } +} + impl std::fmt::Debug for AnyPtr { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { std::fmt::Debug::fmt(&self.ptr.as_bytes(), f) From 80545e14c7b207a011fc87663bd9043bf748e24f Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 18:17:03 +0000 Subject: [PATCH 17/18] Trigger CI From 82a245abfd793a69e43a9bf538359ee14fcc87b5 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Thu, 3 Dec 2026 19:16:12 +0000 Subject: [PATCH 18/18] Update tests --- tests/unit/out/refcount/class.rs | 23 +- tests/unit/out/refcount/copy_ctor.rs | 31 +- .../refcount/elidable_iterator_copy_cxx11.rs | 42 +- tests/unit/out/refcount/find.rs | 246 +++++++----- tests/unit/out/refcount/friend.rs | 37 +- tests/unit/out/refcount/map.rs | 363 ++++++++++-------- tests/unit/out/refcount/map_key_copy_ctor.rs | 10 +- tests/unit/out/refcount/map_key_identity.rs | 186 ++++++--- tests/unit/out/refcount/map_try_emplace.rs | 46 +-- tests/unit/out/refcount/max.rs | 93 +++-- .../refcount/operator_comparison_defaulted.rs | 152 +++----- .../out/refcount/operator_comparison_free.rs | 82 ++-- .../refcount/operator_comparison_member.rs | 27 +- .../refcount/operator_comparison_nonbool.rs | 97 ++--- .../operator_comparison_noncopyable.rs | 25 +- tests/unit/out/refcount/operator_friend.rs | 167 ++++---- tests/unit/out/refcount/operator_less_than.rs | 10 +- tests/unit/out/refcount/operator_three_way.rs | 19 +- tests/unit/out/refcount/operator_traits.rs | 169 ++++---- tests/unit/out/refcount/push_emplace_back.rs | 101 ++--- tests/unit/out/refcount/size_t_ssize_t.rs | 233 ++++++----- tests/unit/out/refcount/sort_no_copy.rs | 155 ++++---- tests/unit/out/refcount/stdcopy.rs | 54 +-- .../refcount/unboxed_conditional_iterator.rs | 44 ++- tests/unit/out/refcount/vector.rs | 185 ++++----- .../out/refcount/vector_iter_range_ctor.rs | 141 +++---- .../out/refcount/vector_with_allocator.rs | 50 +-- tests/unit/out/unsafe/class.rs | 20 +- tests/unit/out/unsafe/copy_ctor.rs | 2 +- tests/unit/out/unsafe/find.rs | 99 ++--- tests/unit/out/unsafe/map.rs | 37 +- tests/unit/out/unsafe/map_key_copy_ctor.rs | 8 +- tests/unit/out/unsafe/map_key_identity.rs | 72 +++- tests/unit/out/unsafe/map_try_emplace.rs | 6 +- tests/unit/out/unsafe/max.rs | 12 +- .../unsafe/operator_comparison_defaulted.rs | 135 ++++--- .../out/unsafe/operator_comparison_member.rs | 26 +- .../out/unsafe/operator_comparison_nonbool.rs | 104 +++-- .../unsafe/operator_comparison_noncopyable.rs | 24 +- tests/unit/out/unsafe/operator_less_than.rs | 8 +- tests/unit/out/unsafe/operator_three_way.rs | 16 +- tests/unit/out/unsafe/operator_traits.rs | 79 ++-- tests/unit/out/unsafe/push_emplace_back.rs | 8 +- tests/unit/out/unsafe/sort_no_copy.rs | 66 ++-- tests/unit/out/unsafe/stdcopy.rs | 8 +- tests/unit/out/unsafe/vector.rs | 12 +- .../unit/out/unsafe/vector_iter_range_ctor.rs | 18 +- .../unit/out/unsafe/vector_with_allocator.rs | 10 +- 48 files changed, 1973 insertions(+), 1585 deletions(-) diff --git a/tests/unit/out/refcount/class.rs b/tests/unit/out/refcount/class.rs index b74e57284a..d99c5277d1 100644 --- a/tests/unit/out/refcount/class.rs +++ b/tests/unit/out/refcount/class.rs @@ -101,17 +101,6 @@ impl Counter { }); return this.with(|__s| __s.v); } - pub fn operator_eq(this: Ptr, o: Ptr) -> bool { - field!(this, calls).with_mut(|__v| { - __v.prefix_inc(); - }); - return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } -} -impl CppEq for Counter { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Counter::operator_eq(__lhs.clone(), __rhs.clone()) - } } #[derive( Copy, @@ -199,8 +188,8 @@ fn main_0() -> i32 { assert!((({ Counter::Get(c1.as_pointer(),) }) == 3)); assert!((({ Counter::Get(c2.as_pointer(),) }) == 3)); assert!((({ Counter::Get((pc).clone(),) }) == 3)); - assert!(({ Counter::operator_eq(c1.as_pointer(), c2.as_pointer(),) })); - assert!(({ Counter::operator_eq(c2.as_pointer(), c1.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(c1.as_pointer(), c2.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(c2.as_pointer(), c1.as_pointer(),) })); assert!(({ (*c1.borrow()).calls } == 3)); assert!(({ (*c2.borrow()).calls } == 2)); let t: Value = Rc::new(RefCell::new(Tally { calls: 0 })); @@ -213,4 +202,12 @@ fn main_0() -> i32 { assert!(({ (*ct.borrow()).calls } == 10)); return 0; } +impl WeaklyEqualityComparableWith for Counter { + fn equal(this: Ptr, o: Ptr) -> bool { + field!(this, calls).with_mut(|__v| { + __v.prefix_inc(); + }); + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index 1c838005ce..1d75ac83e3 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -420,13 +420,16 @@ fn main_0() -> i32 { object!(der2, Derived, 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() }; - let mut __tmp_1 = { vec_.decay().end() }; let mut __v = Vec::new(); - let mut __it = (__tmp_0).clone(); - while __it != __tmp_1 { - __v.push(>::cpp_from(__it.iter_deref())); - __it.iter_inc(); + 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(), + )); + __it.borrow_mut().iter_inc(); } __v }; @@ -439,13 +442,13 @@ fn main_0() -> i32 { } }); { - let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); match ({ - DefaultConstructible::default_constructor(__tmp_3.as_pointer()); - __tmp_3.as_pointer() + DefaultConstructible::default_constructor(__tmp_1.as_pointer()); + __tmp_1.as_pointer() },) { - (__tmp_2,) => MoveConstructible::push_moved(&selfs.as_pointer(), (__tmp_2).clone()), + (__tmp_0,) => MoveConstructible::push_moved(&selfs.as_pointer(), (__tmp_0).clone()), } }; object!(self_src, SelfPtr); @@ -464,13 +467,13 @@ fn main_0() -> i32 { } }); { - let __tmp_5: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); match ({ - Counted::construct(__tmp_5.as_pointer(), 30); - __tmp_5.as_pointer() + Counted::construct(__tmp_3.as_pointer(), 30); + __tmp_3.as_pointer() },) { - (__tmp_4,) => MoveConstructible::push_moved(&temps.as_pointer(), (__tmp_4).clone()), + (__tmp_2,) => MoveConstructible::push_moved(&temps.as_pointer(), (__tmp_2).clone()), } }; assert!( diff --git a/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs b/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs index 8eb3283d6f..d094221826 100644 --- a/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs +++ b/tests/unit/out/refcount/elidable_iterator_copy_cxx11.rs @@ -22,38 +22,48 @@ fn main_0() -> i32 { }); let it: Value> = Rc::new(RefCell::new( ({ - let __tmp_4: Value = Rc::new(RefCell::new(7)); + let __tmp_2: Value = Rc::new(RefCell::new(7)); { - let mut __tmp_2 = { v.decay().begin() }; - let mut __tmp_3 = { v.decay().end() }; - let mut __it = (__tmp_2).clone(); - while __it != __tmp_3 - && !CppEq::equal(__it.iter_deref(), __tmp_4.as_pointer().clone()) + let __it: Value> = + Rc::new(RefCell::new(v.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(v.decay().end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) + && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_2.as_pointer().clone(), + ) { - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() } }), )); - assert!((*it.borrow()) != v.decay().end()); + assert!( + match (Rc::new(RefCell::new(v.decay().end())).as_pointer(),) { + (__tmp_3,) => { + WeaklyEqualityComparableWith::not_equal(it.as_pointer(), (__tmp_3).clone()) + } + } + ); assert!(((({ (*it.borrow()).iter_deref() }).read()) == 7)); { - let mut __tmp_5 = { v.decay().begin() }; - let __n = v.decay().end().iter_distance(&__tmp_5); + let mut __tmp_4 = { v.decay().begin() }; + let __n = v.decay().end().iter_distance(&__tmp_4); let __random = std::hash::RandomState::new(); for __i in (1..__n).rev() { let __j = (std::hash::BuildHasher::hash_one(&__random, __i) % (__i + 1) as u64) as isize; - Swappable::swap(__tmp_5.iter_at(__i), __tmp_5.iter_at(__j)); + Swappable::swap(__tmp_4.iter_at(__i), __tmp_4.iter_at(__j)); } }; { - let mut __tmp_6 = { v.decay().begin() }; - let __n = v.decay().end().iter_distance(&__tmp_6); + let mut __tmp_5 = { v.decay().begin() }; + let __n = v.decay().end().iter_distance(&__tmp_5); let mut __order: Vec = (0..__n).collect(); - __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_6.iter_at(__x), &__tmp_6.iter_at(__y))); - reorder(__order, |__i| __tmp_6.iter_at(__i)); + __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_5.iter_at(__x), &__tmp_5.iter_at(__y))); + reorder(__order, |__i| __tmp_5.iter_at(__i)); }; assert!(({ (*v.borrow())[0_usize] } == 4) && ({ (*v.borrow())[1_usize] } == 7)); return 0; diff --git a/tests/unit/out/refcount/find.rs b/tests/unit/out/refcount/find.rs index 504af54ae4..e0982d9a88 100644 --- a/tests/unit/out/refcount/find.rs +++ b/tests/unit/out/refcount/find.rs @@ -23,16 +23,6 @@ pub struct P { #[offset(0)] pub x: i32, } -impl P { - pub fn operator_eq(this: Ptr, o: Ptr

) -> bool { - return ({ this.with(|__s| __s.x) } == { o.with(|__s| __s.x) }); - } -} -impl CppEq for P { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - P::operator_eq(__lhs.clone(), __rhs.clone()) - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -55,20 +45,27 @@ fn main_0() -> i32 { let v_end: Value> = Rc::new(RefCell::new(v.decay().end())); let it: Value> = Rc::new(RefCell::new( ({ - let __tmp_4: Value = Rc::new(RefCell::new(2)); + let __tmp_3: Value = Rc::new(RefCell::new(2)); { - let mut __tmp_3 = { (*v_end.borrow()).clone() }; - let mut __it = ({ (*v_begin.borrow()).clone() }); - while __it != __tmp_3 - && !CppEq::equal(__it.iter_deref(), __tmp_4.as_pointer().clone()) + let __it: Value> = + Rc::new(RefCell::new(({ (*v_begin.borrow()).clone() }))); + let __last: Value> = + Rc::new(RefCell::new(({ (*v_end.borrow()).clone() }))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) + && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_3.as_pointer().clone(), + ) { - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() } }), )); - let mut v_result_true: bool = (*it.borrow()) != v.decay().end(); + let mut v_result_true: bool = match (Rc::new(RefCell::new(v.decay().end())).as_pointer(),) { + (__tmp_4,) => WeaklyEqualityComparableWith::not_equal(it.as_pointer(), (__tmp_4).clone()), + }; let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); match (Rc::new(RefCell::new(1)).as_pointer(),) { (__tmp_5,) => { @@ -96,94 +93,167 @@ fn main_0() -> i32 { m.as_pointer() .with(|__m: &Map, Value)>| __m.end()), )); - let mut m_result_true: bool = (*m_begin.borrow()) != (*m_end.borrow()); + let mut m_result_true: bool = + WeaklyEqualityComparableWith::not_equal(m_begin.as_pointer(), m_end.as_pointer()); assert!( ((v_result_true) && (m_result_true)) - && (({ - let __tmp_10: Value = Rc::new(RefCell::new(2)); - { - let mut __tmp_8 = { v.decay().begin() }; - let mut __tmp_9 = { v.decay().begin() }; - let mut __it = (__tmp_8).clone(); - while __it != __tmp_9 - && !CppEq::equal(__it.iter_deref(), __tmp_10.as_pointer().clone()) - { - __it.iter_inc(); - } - __it + && (match ( + Rc::new(RefCell::new( + ({ + let __tmp_9: Value = Rc::new(RefCell::new(2)); + { + let __it: Value> = + Rc::new(RefCell::new(v.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(v.decay().begin())); + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_9.as_pointer().clone(), + ) { + __it.borrow_mut().iter_inc(); + } + __it.borrow().clone() + } + }) + )) + .as_pointer(), + Rc::new(RefCell::new(v.decay().begin())).as_pointer(), + ) { + (__tmp_8, __tmp_10) => { + WeaklyEqualityComparableWith::equal((__tmp_8).clone(), (__tmp_10).clone()) } - }) == v.decay().begin()) + }) ); let w: Value> = Rc::new(RefCell::new(Vec::from([1, 2, 3, 4, 5]))); - assert!( - ({ - let __tmp_13: Value = Rc::new(RefCell::new(4)); - { - let mut __tmp_11 = { w.decay().begin().iter_add(2_isize) }; - let mut __tmp_12 = { w.decay().end() }; - let mut __it = (__tmp_11).clone(); - while __it != __tmp_12 - && !CppEq::equal(__it.iter_deref(), __tmp_13.as_pointer().clone()) + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_12: Value = Rc::new(RefCell::new(4)); { - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(w.decay().begin().iter_add(2_isize))); + let __last: Value> = + Rc::new(RefCell::new(w.decay().end())); + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_12.as_pointer().clone(), + ) { + __it.borrow_mut().iter_inc(); + } + __it.borrow().clone() } - __it - } - }) == w.decay().begin().iter_add(3_isize) - ); - assert!( - ({ - let __tmp_16: Value = Rc::new(RefCell::new(1)); - { - let mut __tmp_14 = { w.decay().begin().iter_add(2_isize) }; - let mut __tmp_15 = { w.decay().end() }; - let mut __it = (__tmp_14).clone(); - while __it != __tmp_15 - && !CppEq::equal(__it.iter_deref(), __tmp_16.as_pointer().clone()) + }) + )) + .as_pointer(), + Rc::new(RefCell::new(w.decay().begin().iter_add(3_isize))).as_pointer(), + ) { + (__tmp_11, __tmp_13) => { + WeaklyEqualityComparableWith::equal((__tmp_11).clone(), (__tmp_13).clone()) + } + }); + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_15: Value = Rc::new(RefCell::new(1)); { - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(w.decay().begin().iter_add(2_isize))); + let __last: Value> = + Rc::new(RefCell::new(w.decay().end())); + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_15.as_pointer().clone(), + ) { + __it.borrow_mut().iter_inc(); + } + __it.borrow().clone() } - __it - } - }) == w.decay().end() - ); - assert!( - ({ - let __tmp_19: Value = Rc::new(RefCell::new(5)); - { - let mut __tmp_17 = { w.decay().begin().iter_add(2_isize) }; - let mut __tmp_18 = { w.decay().begin().iter_add(4_isize) }; - let mut __it = (__tmp_17).clone(); - while __it != __tmp_18 - && !CppEq::equal(__it.iter_deref(), __tmp_19.as_pointer().clone()) + }) + )) + .as_pointer(), + Rc::new(RefCell::new(w.decay().end())).as_pointer(), + ) { + (__tmp_14, __tmp_16) => { + WeaklyEqualityComparableWith::equal((__tmp_14).clone(), (__tmp_16).clone()) + } + }); + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_18: Value = Rc::new(RefCell::new(5)); { - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(w.decay().begin().iter_add(2_isize))); + let __last: Value> = + Rc::new(RefCell::new(w.decay().begin().iter_add(4_isize))); + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_18.as_pointer().clone(), + ) { + __it.borrow_mut().iter_inc(); + } + __it.borrow().clone() } - __it - } - }) == w.decay().begin().iter_add(4_isize) - ); + }) + )) + .as_pointer(), + Rc::new(RefCell::new(w.decay().begin().iter_add(4_isize))).as_pointer(), + ) { + (__tmp_17, __tmp_19) => { + WeaklyEqualityComparableWith::equal((__tmp_17).clone(), (__tmp_19).clone()) + } + }); let p: Value> = Rc::new(RefCell::new(Vec::from([ P { x: 0 }, P { x: 1 }, P { x: 2 }, ]))); - assert!( - ({ - let __tmp_22: Value

= Rc::new(RefCell::new(P { x: 1 })); - { - let mut __tmp_20 = { p.decay().begin() }; - let mut __tmp_21 = { p.decay().end() }; - let mut __it = (__tmp_20).clone(); - while __it != __tmp_21 - && !CppEq::equal(__it.iter_deref(), (__tmp_22.as_pointer()).clone()) + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_21: Value

= Rc::new(RefCell::new(P { x: 1 })); { - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(p.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(p.decay().end())); + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + (__tmp_21.as_pointer()).clone(), + ) { + __it.borrow_mut().iter_inc(); + } + __it.borrow().clone() } - __it - } - }) == p.decay().begin().iter_add(1_isize) - ); + }) + )) + .as_pointer(), + Rc::new(RefCell::new(p.decay().begin().iter_add(1_isize))).as_pointer(), + ) { + (__tmp_20, __tmp_22) => { + WeaklyEqualityComparableWith::equal((__tmp_20).clone(), (__tmp_22).clone()) + } + }); return 0; } +impl WeaklyEqualityComparableWith for P { + fn equal(this: Ptr, o: Ptr

) -> bool { + return ({ this.with(|__s| __s.x) } == { o.with(|__s| __s.x) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/friend.rs b/tests/unit/out/refcount/friend.rs index c9e3cff5e4..d4b2be0dee 100644 --- a/tests/unit/out/refcount/friend.rs +++ b/tests/unit/out/refcount/friend.rs @@ -9,13 +9,10 @@ use std::rc::{Rc, Weak}; pub fn get_0(v: Ptr) -> i32 { return v.with(|__s| __s.x); } -pub fn operator_eq_1(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.x) } == { b.with(|__s| __s.x) }); -} -pub fn scaled_2(v: Ptr, mut k: i32) -> i32 { +pub fn scaled_1(v: Ptr, mut k: i32) -> i32 { return ({ v.with(|__s| __s.x) } * { k }); } -pub fn scaled_3(v: Ptr, mut k: f64) -> f64 { +pub fn scaled_2(v: Ptr, mut k: f64) -> f64 { return ({ (v.with(|__s| __s.x) as f64) } * { k }); } #[derive( @@ -35,12 +32,7 @@ pub struct V { #[offset(0)] pub x: i32, } -impl CppEq for V { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_1(__lhs.clone(), __rhs.clone()) - } -} -pub fn get_4(w: Ptr) -> i32 { +pub fn get_3(w: Ptr) -> i32 { return w.with(|__s| __s.x); } #[derive( @@ -60,7 +52,7 @@ pub struct W_int_ { #[offset(0)] pub x: i32, } -pub fn get_5(w: Ptr) -> i64 { +pub fn get_4(w: Ptr) -> i64 { return w.with(|__s| __s.x); } #[derive( @@ -97,7 +89,7 @@ pub struct D { #[offset(0)] pub x: i32, } -pub fn declared_then_defined_6(d: Ptr) -> i32 { +pub fn declared_then_defined_5(d: Ptr) -> i32 { return (d.with(|__s| __s.x) + 1); } pub fn main() { @@ -109,16 +101,21 @@ fn main_0() -> i32 { let b: Value = Rc::new(RefCell::new(V { x: 3 })); let c: Value = Rc::new(RefCell::new(V { x: 4 })); assert!((({ get_0(a.as_pointer(),) }) == 3)); - assert!(({ operator_eq_1(a.as_pointer(), b.as_pointer(),) })); - assert!(!({ operator_eq_1(a.as_pointer(), c.as_pointer(),) })); - assert!((({ scaled_2(c.as_pointer(), 2,) }) == 8)); - assert!((({ scaled_3(c.as_pointer(), 1.5_f64,) }) == 6_f64)); + assert!(({ WeaklyEqualityComparableWith::equal(a.as_pointer(), b.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(a.as_pointer(), c.as_pointer(),) })); + assert!((({ scaled_1(c.as_pointer(), 2,) }) == 8)); + assert!((({ scaled_2(c.as_pointer(), 1.5_f64,) }) == 6_f64)); let wi: Value = Rc::new(RefCell::new(W_int_ { x: 5 })); let wl: Value = Rc::new(RefCell::new(W_long_ { x: 6_i64 })); - assert!((({ get_4(wi.as_pointer(),) }) == 5)); - assert!((({ get_5(wl.as_pointer(),) }) == 6_i64)); + assert!((({ get_3(wi.as_pointer(),) }) == 5)); + assert!((({ get_4(wl.as_pointer(),) }) == 6_i64)); let d: Value = Rc::new(RefCell::new(D { x: 7 })); - assert!((({ declared_then_defined_6(d.as_pointer(),) }) == 8)); + assert!((({ declared_then_defined_5(d.as_pointer(),) }) == 8)); return 0; } +impl WeaklyEqualityComparableWith for V { + fn equal(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.x) } == { b.with(|__s| __s.x) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/map.rs b/tests/unit/out/refcount/map.rs index 2ee95d677a..38a0839aa7 100644 --- a/tests/unit/out/refcount/map.rs +++ b/tests/unit/out/refcount/map.rs @@ -219,7 +219,7 @@ fn main_0() -> i32 { }), ), )); - let mut x1: u32 = if (*it.borrow()) == (*end.borrow()) { + let mut x1: u32 = if WeaklyEqualityComparableWith::equal(it.as_pointer(), end.as_pointer()) { 0_u32 } else { (*(*({ (*it.borrow()).iter_deref() }).upgrade().deref()) @@ -227,9 +227,16 @@ fn main_0() -> i32 { .borrow()) }; assert!((x1 == 4_u32)); - let mut x2: u32 = if (*const_it.borrow()) - == , Value)>>::from(({ (*end.borrow()).clone() })) + let mut x2: u32 = if match (Rc::new(RefCell::new(, + Value, + )>>::from(({ (*end.borrow()).clone() })))) + .as_pointer(),) { + (__tmp_20,) => { + WeaklyEqualityComparableWith::equal(const_it.as_pointer(), (__tmp_20).clone()) + } + } { 0_u32 } else { (*(*({ (*const_it.borrow()).iter_deref() }).upgrade().deref()) @@ -237,10 +244,14 @@ fn main_0() -> i32 { .borrow()) }; assert!((x2 == 0_u32)); - let mut x3: u32 = if (*it.borrow()) - == m.as_pointer() - .with(|__m: &Map, Value)>| __m.end()) + let mut x3: u32 = if match (Rc::new(RefCell::new( + m.as_pointer() + .with(|__m: &Map, Value)>| __m.end()), + )) + .as_pointer(),) { + (__tmp_21,) => WeaklyEqualityComparableWith::equal(it.as_pointer(), (__tmp_21).clone()), + } { 0_u32 } else { (*(*({ (*it.borrow()).iter_deref() }).upgrade().deref()) @@ -248,11 +259,19 @@ fn main_0() -> i32 { .borrow()) }; assert!((x3 == 4_u32)); - let mut x4: u32 = if (*const_it.borrow()) - == , Value)>>::from( - m.as_pointer() - .with(|__m: &Map, Value)>| __m.end()), - ) { + let mut x4: u32 = if match (Rc::new(RefCell::new(, + Value, + )>>::from( + m.as_pointer() + .with(|__m: &Map, Value)>| __m.end()), + ))) + .as_pointer(),) + { + (__tmp_22,) => { + WeaklyEqualityComparableWith::equal(const_it.as_pointer(), (__tmp_22).clone()) + } + } { 0_u32 } else { (*(*({ (*const_it.borrow()).iter_deref() }).upgrade().deref()) @@ -261,16 +280,16 @@ fn main_0() -> i32 { }; assert!((x4 == 0_u32)); match (Rc::new(RefCell::new(4_i16)).as_pointer(),) { - (__tmp_20,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_20, |__k| cpp_move!(__k), || 0_u32) }) + (__tmp_23,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_23, |__k| cpp_move!(__k), || 0_u32) }) } } .write(5_u32); let it4: Value, Value)>> = Rc::new(RefCell::new( ({ - let __tmp_21: Value = Rc::new(RefCell::new(4_i16)); + let __tmp_24: Value = Rc::new(RefCell::new(4_i16)); m.as_pointer() - .with(|__m: &Map, Value)>| __m.find(&__tmp_21.as_pointer())) + .with(|__m: &Map, Value)>| __m.find(&__tmp_24.as_pointer())) }), )); let mut p: Ptr = ((*({ (*it4.borrow()).iter_deref() }).upgrade().deref()) @@ -279,8 +298,8 @@ fn main_0() -> i32 { let mut x5: u32 = (p.read()); assert!( ((match (Rc::new(RefCell::new(4_i16)).as_pointer(),) { - (__tmp_22,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_22, |__k| cpp_move!(__k), || 0_u32) }) + (__tmp_25,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_25, |__k| cpp_move!(__k), || 0_u32) }) } } .read()) @@ -301,8 +320,8 @@ fn main_0() -> i32 { }); assert!( ((match (Rc::new(RefCell::new(4_i16)).as_pointer(),) { - (__tmp_23,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_23, |__k| cpp_move!(__k), || 0_u32) }) + (__tmp_26,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_26, |__k| cpp_move!(__k), || 0_u32) }) } } .read()) @@ -321,10 +340,10 @@ fn main_0() -> i32 { let const_it4: Value, Value)>> = Rc::new(RefCell::new( , Value)>>::from( ({ - let __tmp_24: Value = Rc::new(RefCell::new(4_i16)); + let __tmp_27: Value = Rc::new(RefCell::new(4_i16)); m.as_pointer() .with(|__m: &Map, Value)>| { - __m.find(&__tmp_24.as_pointer()) + __m.find(&__tmp_27.as_pointer()) }) }), ), @@ -339,66 +358,90 @@ fn main_0() -> i32 { ); let r: Ptr, Value)>> = m.as_pointer(); assert!(({ ((*r.upgrade().deref()).len() == 4_usize) })); - assert!( - ({ - let __tmp_25: Value = Rc::new(RefCell::new(4_i16)); + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_29: Value = Rc::new(RefCell::new(4_i16)); + m.as_pointer() + .with(|__m: &Map, Value)>| { + __m.find(&__tmp_29.as_pointer()) + }) + }) + )) + .as_pointer(), + Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.find(&__tmp_25.as_pointer())) - }) != m - .as_pointer() - .with(|__m: &Map, Value)>| __m.end()) - ); + .with(|__m: &Map, Value)>| __m.end()) + )) + .as_pointer(), + ) { + (__tmp_28, __tmp_30) => { + WeaklyEqualityComparableWith::not_equal((__tmp_28).clone(), (__tmp_30).clone()) + } + }); Map::erase((r).clone(), &({ (*it4.borrow()).clone() })); assert!(({ ((*r.upgrade().deref()).len() == 3_usize) })); - assert!( - ({ - let __tmp_26: Value = Rc::new(RefCell::new(4_i16)); + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_32: Value = Rc::new(RefCell::new(4_i16)); + m.as_pointer() + .with(|__m: &Map, Value)>| { + __m.find(&__tmp_32.as_pointer()) + }) + }) + )) + .as_pointer(), + Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.find(&__tmp_26.as_pointer())) - }) == m - .as_pointer() - .with(|__m: &Map, Value)>| __m.end()) - ); + .with(|__m: &Map, Value)>| __m.end()) + )) + .as_pointer(), + ) { + (__tmp_31, __tmp_33) => { + WeaklyEqualityComparableWith::equal((__tmp_31).clone(), (__tmp_33).clone()) + } + }); match (Rc::new(RefCell::new(7_i16)).as_pointer(),) { - (__tmp_27,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_27, |__k| cpp_move!(__k), || 0_u32) }) + (__tmp_34,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_34, |__k| cpp_move!(__k), || 0_u32) }) } } .write(7_u32); match (Rc::new(RefCell::new(8_i16)).as_pointer(),) { - (__tmp_28,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_28, |__k| cpp_move!(__k), || 0_u32) }) + (__tmp_35,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_35, |__k| cpp_move!(__k), || 0_u32) }) } } .write(8_u32); match (Rc::new(RefCell::new(9_i16)).as_pointer(),) { - (__tmp_29,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_29, |__k| cpp_move!(__k), || 0_u32) }) + (__tmp_36,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_36, |__k| cpp_move!(__k), || 0_u32) }) } } .write(9_u32); assert!(({ ((*r.upgrade().deref()).len() == 6_usize) })); assert!( (({ - let __tmp_30: Value = Rc::new(RefCell::new(10_i16)); - Map::erase_key(m.as_pointer(), &__tmp_30.as_pointer()) + let __tmp_37: Value = Rc::new(RefCell::new(10_i16)); + Map::erase_key(m.as_pointer(), &__tmp_37.as_pointer()) }) == 0_usize) ); let mut key9: i32 = 9; assert!( (({ - let __tmp_31: Value = Rc::new(RefCell::new((key9 as i16))); - Map::erase_key(m.as_pointer(), &__tmp_31.as_pointer()) + let __tmp_38: Value = Rc::new(RefCell::new((key9 as i16))); + Map::erase_key(m.as_pointer(), &__tmp_38.as_pointer()) }) == 1_usize) ); assert!(({ ((*r.upgrade().deref()).len() == 5_usize) })); let cit: Value, Value)>> = Rc::new(RefCell::new( , Value)>>::from( ({ - let __tmp_32: Value = Rc::new(RefCell::new(7_i16)); + let __tmp_39: Value = Rc::new(RefCell::new(7_i16)); m.as_pointer() .with(|__m: &Map, Value)>| { - __m.find(&__tmp_32.as_pointer()) + __m.find(&__tmp_39.as_pointer()) }) }), ), @@ -406,34 +449,54 @@ fn main_0() -> i32 { let next: Value, Value)>> = Rc::new(RefCell::new( Map::erase(m.as_pointer(), &({ (*cit.borrow()).clone() })), )); - assert!( - (*next.borrow()) - == ({ - let __tmp_33: Value = Rc::new(RefCell::new(8_i16)); - m.as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&__tmp_33.as_pointer()) - }) - }) - ); + assert!(match (Rc::new(RefCell::new( + ({ + let __tmp_41: Value = Rc::new(RefCell::new(8_i16)); + m.as_pointer() + .with(|__m: &Map, Value)>| __m.find(&__tmp_41.as_pointer())) + }) + )) + .as_pointer(),) + { + (__tmp_40,) => { + WeaklyEqualityComparableWith::equal(next.as_pointer(), (__tmp_40).clone()) + } + }); { (*next.borrow_mut()) = Map::erase(m.as_pointer(), &({ (*next.borrow()).clone() })); }; - assert!( - (*next.borrow()) - == m.as_pointer() - .with(|__m: &Map, Value)>| __m.end()) - ); + assert!(match (Rc::new(RefCell::new( + m.as_pointer() + .with(|__m: &Map, Value)>| __m.end()) + )) + .as_pointer(),) + { + (__tmp_42,) => { + WeaklyEqualityComparableWith::equal(next.as_pointer(), (__tmp_42).clone()) + } + }); assert!(({ ((*r.upgrade().deref()).len() == 3_usize) })); - assert!( - ({ - let __tmp_34: Value = Rc::new(RefCell::new(8_i16)); + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_44: Value = Rc::new(RefCell::new(8_i16)); + m.as_pointer() + .with(|__m: &Map, Value)>| { + __m.find(&__tmp_44.as_pointer()) + }) + }) + )) + .as_pointer(), + Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.find(&__tmp_34.as_pointer())) - }) == m - .as_pointer() - .with(|__m: &Map, Value)>| __m.end()) - ); + .with(|__m: &Map, Value)>| __m.end()) + )) + .as_pointer(), + ) { + (__tmp_43, __tmp_45) => { + WeaklyEqualityComparableWith::equal((__tmp_43).clone(), (__tmp_45).clone()) + } + }); let other_map: Value< Map<(Value, Value), (Value<(Value, Value)>, Value)>, > = Rc::new(RefCell::new(Map::new())); @@ -444,18 +507,18 @@ fn main_0() -> i32 { ))); let mut value: f64 = 2_f64; match (key0.as_pointer(),) { - (__tmp_35,) => ({ (*other_map.borrow_mut()).subscript(__tmp_35, || 0_f64) }), + (__tmp_46,) => ({ (*other_map.borrow_mut()).subscript(__tmp_46, || 0_f64) }), } .write(value); value = (match (key0.as_pointer(),) { - (__tmp_36,) => ({ (*other_map.borrow_mut()).subscript(__tmp_36, || 0_f64) }), + (__tmp_47,) => ({ (*other_map.borrow_mut()).subscript(__tmp_47, || 0_f64) }), } .read()); assert!(({ ((*other_map.borrow()).len() == 1_usize) })); assert!( ((match (key0.as_pointer(),) { - (__tmp_37,) => { - ({ (*other_map.borrow_mut()).subscript(__tmp_37, || 0_f64) }) + (__tmp_48,) => { + ({ (*other_map.borrow_mut()).subscript(__tmp_48, || 0_f64) }) } } .read()) @@ -465,9 +528,9 @@ fn main_0() -> i32 { let mut k: i32 = 0; assert!( ({ - let __tmp_38: Value = Rc::new(RefCell::new((k as i16))); + let __tmp_49: Value = Rc::new(RefCell::new((k as i16))); ((*m.borrow()) - .get(&__tmp_38.as_pointer()) + .get(&__tmp_49.as_pointer()) .expect("out of range!") .borrow() .1 @@ -478,9 +541,9 @@ fn main_0() -> i32 { k.prefix_inc(); assert!( ({ - let __tmp_39: Value = Rc::new(RefCell::new((k as i16))); + let __tmp_50: Value = Rc::new(RefCell::new((k as i16))); ((*m.borrow()) - .get(&__tmp_39.as_pointer()) + .get(&__tmp_50.as_pointer()) .expect("out of range!") .borrow() .1 @@ -491,9 +554,9 @@ fn main_0() -> i32 { k.prefix_inc(); assert!( ({ - let __tmp_40: Value = Rc::new(RefCell::new((k as i16))); + let __tmp_51: Value = Rc::new(RefCell::new((k as i16))); ((*m.borrow()) - .get(&__tmp_40.as_pointer()) + .get(&__tmp_51.as_pointer()) .expect("out of range!") .borrow() .1 @@ -509,8 +572,8 @@ fn main_0() -> i32 { 'loop_: while (i > 30_u32) { 'for_body: { ({ - let __tmp_41: Value = Rc::new(RefCell::new((i as i32))); - MoveConstructible::push_moved(&indexes.as_pointer(), __tmp_41.as_pointer()) + let __tmp_52: Value = Rc::new(RefCell::new((i as i32))); + MoveConstructible::push_moved(&indexes.as_pointer(), __tmp_52.as_pointer()) }); } i.prefix_dec(); @@ -521,8 +584,8 @@ fn main_0() -> i32 { 'loop_: while (i > 60_u32) { 'for_body: { ({ - let __tmp_42: Value = Rc::new(RefCell::new((i as i32))); - MoveConstructible::push_moved(&indexes.as_pointer(), __tmp_42.as_pointer()) + let __tmp_53: Value = Rc::new(RefCell::new((i as i32))); + MoveConstructible::push_moved(&indexes.as_pointer(), __tmp_53.as_pointer()) }); } i.prefix_dec(); @@ -533,8 +596,8 @@ fn main_0() -> i32 { 'loop_: while (i > 0_u32) { 'for_body: { ({ - let __tmp_43: Value = Rc::new(RefCell::new((i as i32))); - MoveConstructible::push_moved(&indexes.as_pointer(), __tmp_43.as_pointer()) + let __tmp_54: Value = Rc::new(RefCell::new((i as i32))); + MoveConstructible::push_moved(&indexes.as_pointer(), __tmp_54.as_pointer()) }); } i.prefix_dec(); @@ -545,7 +608,7 @@ fn main_0() -> i32 { 'loop_: while ((i as usize) < (*indexes.borrow()).len()) { 'for_body: { match (indexes.decay().offset((i as usize)),) { - (__tmp_44,) => ({ (*m2.borrow_mut()).subscript(__tmp_44, || false) }), + (__tmp_55,) => ({ (*m2.borrow_mut()).subscript(__tmp_55, || false) }), } .write(((i).wrapping_rem(2_u32) != 0)); } @@ -576,9 +639,9 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let mut __tmp_45 = { (Rc::new(RefCell::new(1)), Rc::new(RefCell::new(2))) }; + let mut __tmp_56 = { (Rc::new(RefCell::new(1)), Rc::new(RefCell::new(2))) }; let (__it, __inserted) = - Map::emplace(m3.as_pointer(), &__tmp_45.0.as_pointer(), || __tmp_45); + Map::emplace(m3.as_pointer(), &__tmp_56.0.as_pointer(), || __tmp_56); ( Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted)), @@ -599,9 +662,9 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let mut __tmp_46 = { (Rc::new(RefCell::new(1)), Rc::new(RefCell::new(3))) }; + let mut __tmp_57 = { (Rc::new(RefCell::new(1)), Rc::new(RefCell::new(3))) }; let (__it, __inserted) = - Map::emplace(m3.as_pointer(), &__tmp_46.0.as_pointer(), || __tmp_46); + Map::emplace(m3.as_pointer(), &__tmp_57.0.as_pointer(), || __tmp_57); ( Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted)), @@ -619,25 +682,25 @@ fn main_0() -> i32 { }) ); { - let mut __tmp_48 = { + let mut __tmp_59 = { match (Rc::new(RefCell::new(( Rc::new(RefCell::new(4)), Rc::new(RefCell::new(5)), ))) .as_pointer(),) { - (__tmp_47,) => ( + (__tmp_58,) => ( Rc::new(RefCell::new( - ((*__tmp_47.upgrade().deref()).0.as_pointer().read()), + ((*__tmp_58.upgrade().deref()).0.as_pointer().read()), )), Rc::new(RefCell::new( - ((*__tmp_47.upgrade().deref()).1.as_pointer().read()), + ((*__tmp_58.upgrade().deref()).1.as_pointer().read()), )), ), } }; let (__it, __inserted) = - Map::emplace(m3.as_pointer(), &__tmp_48.0.as_pointer(), || __tmp_48); + Map::emplace(m3.as_pointer(), &__tmp_59.0.as_pointer(), || __tmp_59); ( Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted)), @@ -646,8 +709,8 @@ fn main_0() -> i32 { assert!(({ ((*m3.borrow()).len() == 2_usize) })); assert!( ((match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_49,) => { - ({ (*m3.borrow_mut()).subscript_move(__tmp_49, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_60,) => { + ({ (*m3.borrow_mut()).subscript_move(__tmp_60, |__k| cpp_move!(__k), || 0_i32) }) } } .read()) @@ -655,23 +718,23 @@ fn main_0() -> i32 { ); assert!( ((match (Rc::new(RefCell::new(4)).as_pointer(),) { - (__tmp_50,) => { - ({ (*m3.borrow_mut()).subscript_move(__tmp_50, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_61,) => { + ({ (*m3.borrow_mut()).subscript_move(__tmp_61, |__k| cpp_move!(__k), || 0_i32) }) } } .read()) == 5) ); let hinted: Value, Value)>> = Rc::new(RefCell::new({ - let mut __tmp_51 = { + let mut __tmp_62 = { , Value)>>::from( m3.as_pointer() .with(|__m: &Map, Value)>| __m.end()), ) }; - let mut __tmp_52 = { (Rc::new(RefCell::new(6)), Rc::new(RefCell::new(7))) }; - let _ = (__tmp_51).clone(); - Map::emplace(m3.as_pointer(), &__tmp_52.0.as_pointer(), || __tmp_52).0 + let mut __tmp_63 = { (Rc::new(RefCell::new(6)), Rc::new(RefCell::new(7))) }; + let _ = (__tmp_62).clone(); + Map::emplace(m3.as_pointer(), &__tmp_63.0.as_pointer(), || __tmp_63).0 })); assert!( ({ @@ -727,8 +790,8 @@ fn main_0() -> i32 { assert!(({ ((*(*tried_new.borrow()).1.borrow()) as bool) })); assert!( ((match (Rc::new(RefCell::new(8)).as_pointer(),) { - (__tmp_53,) => { - ({ (*m3.borrow_mut()).subscript_move(__tmp_53, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_64,) => { + ({ (*m3.borrow_mut()).subscript_move(__tmp_64, |__k| cpp_move!(__k), || 0_i32) }) } } .read()) @@ -758,10 +821,10 @@ fn main_0() -> i32 { assert!(({ ((*(*point_new.borrow()).1.borrow()) as bool) })); assert!( (match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_54,) => { + (__tmp_65,) => { ({ (*points.borrow_mut()).subscript_move( - __tmp_54, + __tmp_65, |__k| cpp_move!(__k), || ::default(), ) @@ -773,10 +836,10 @@ fn main_0() -> i32 { ); assert!( (match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_55,) => { + (__tmp_66,) => { ({ (*points.borrow_mut()).subscript_move( - __tmp_55, + __tmp_66, |__k| cpp_move!(__k), || ::default(), ) @@ -787,7 +850,7 @@ fn main_0() -> i32 { == 4) ); { - let mut __tmp_56 = { + let mut __tmp_67 = { ( Rc::new(RefCell::new(({ (*key8.borrow()) }))), Rc::new(RefCell::new({ @@ -798,7 +861,7 @@ fn main_0() -> i32 { ) }; let (__it, __inserted) = - Map::emplace(points.as_pointer(), &__tmp_56.0.as_pointer(), || __tmp_56); + Map::emplace(points.as_pointer(), &__tmp_67.0.as_pointer(), || __tmp_67); ( Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted)), @@ -806,10 +869,10 @@ fn main_0() -> i32 { }; assert!( (match (Rc::new(RefCell::new(8)).as_pointer(),) { - (__tmp_57,) => { + (__tmp_68,) => { ({ (*points.borrow_mut()).subscript_move( - __tmp_57, + __tmp_68, |__k| cpp_move!(__k), || ::default(), ) @@ -821,10 +884,10 @@ fn main_0() -> i32 { ); assert!( (match (Rc::new(RefCell::new(8)).as_pointer(),) { - (__tmp_58,) => { + (__tmp_69,) => { ({ (*points.borrow_mut()).subscript_move( - __tmp_58, + __tmp_69, |__k| cpp_move!(__k), || ::default(), ) @@ -867,9 +930,9 @@ fn main_0() -> i32 { ); k = 0; let value_0: Ptr = ({ - let __tmp_59: Value = Rc::new(RefCell::new((k as i16))); + let __tmp_70: Value = Rc::new(RefCell::new((k as i16))); (*m.borrow()) - .get(&__tmp_59.as_pointer()) + .get(&__tmp_70.as_pointer()) .expect("out of range!") .borrow() .1 @@ -908,10 +971,10 @@ fn main_0() -> i32 { ); { match (Rc::new(RefCell::new((pk2.as_pointer()))).as_pointer(),) { - (__tmp_60,) => { + (__tmp_71,) => { ({ (*ptr_counts.borrow_mut()).subscript_move( - __tmp_60, + __tmp_71, |__k| cpp_move!(__k), || 0_i32, ) @@ -922,10 +985,10 @@ fn main_0() -> i32 { }; assert!( ((match (Rc::new(RefCell::new((pk2.as_pointer()))).as_pointer(),) { - (__tmp_61,) => { + (__tmp_72,) => { ({ (*ptr_counts.borrow_mut()).subscript_move( - __tmp_61, + __tmp_72, |__k| cpp_move!(__k), || 0_i32, ) @@ -939,75 +1002,75 @@ fn main_0() -> i32 { { let t: Value, Value)>> = Rc::new(RefCell::new(Map::new())); match (Rc::new(RefCell::new(1_i64)).as_pointer(),) { - (__tmp_62,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_62, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_73,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_73, |__k| cpp_move!(__k), || 0_i32) }) } } .write(5); { match (Rc::new(RefCell::new(2_i64)).as_pointer(),) { - (__tmp_63,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_63, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_74,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_74, |__k| cpp_move!(__k), || 0_i32) }) } } .with_mut(|__v| *__v = *__v + 3) }; match (Rc::new(RefCell::new(3_i64)).as_pointer(),) { - (__tmp_64,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_64, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_75,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_75, |__k| cpp_move!(__k), || 0_i32) }) } } .with_mut(|__v| __v.postfix_inc()); let r: Ptr = match (Rc::new(RefCell::new(1_i64)).as_pointer(),) { - (__tmp_65,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_65, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_76,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_76, |__k| cpp_move!(__k), || 0_i32) }) } }; r.write(6); let mut p: Ptr = (match (Rc::new(RefCell::new(2_i64)).as_pointer(),) { - (__tmp_66,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_66, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_77,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_77, |__k| cpp_move!(__k), || 0_i32) }) } }); p.write(4); ({ inc_2(match (Rc::new(RefCell::new(3_i64)).as_pointer(),) { - (__tmp_67,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_67, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_78,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_78, |__k| cpp_move!(__k), || 0_i32) }) } }) }); Swappable::swap( match (Rc::new(RefCell::new(1_i64)).as_pointer(),) { - (__tmp_68,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_68, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_79,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_79, |__k| cpp_move!(__k), || 0_i32) }) } }, match (Rc::new(RefCell::new(2_i64)).as_pointer(),) { - (__tmp_69,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_69, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_80,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_80, |__k| cpp_move!(__k), || 0_i32) }) } }, ); let mut x: i32 = ((match (Rc::new(RefCell::new(1_i64)).as_pointer(),) { - (__tmp_70,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_70, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_81,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_81, |__k| cpp_move!(__k), || 0_i32) }) } } .read()) + (match (Rc::new(RefCell::new(2_i64)).as_pointer(),) { - (__tmp_71,) => { - ({ (*t.borrow_mut()).subscript_move(__tmp_71, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_82,) => { + ({ (*t.borrow_mut()).subscript_move(__tmp_82, |__k| cpp_move!(__k), || 0_i32) }) } } .read())); assert!( (((x == 10) && ((match (Rc::new(RefCell::new(1_i64)).as_pointer(),) { - (__tmp_72,) => { + (__tmp_83,) => { ({ (*t.borrow_mut()).subscript_move( - __tmp_72, + __tmp_83, |__k| cpp_move!(__k), || 0_i32, ) @@ -1017,10 +1080,10 @@ fn main_0() -> i32 { .read()) == 4)) && ((match (Rc::new(RefCell::new(2_i64)).as_pointer(),) { - (__tmp_73,) => { + (__tmp_84,) => { ({ (*t.borrow_mut()).subscript_move( - __tmp_73, + __tmp_84, |__k| cpp_move!(__k), || 0_i32, ) @@ -1030,10 +1093,10 @@ fn main_0() -> i32 { .read()) == 6)) && ((match (Rc::new(RefCell::new(3_i64)).as_pointer(),) { - (__tmp_74,) => { + (__tmp_85,) => { ({ (*t.borrow_mut()).subscript_move( - __tmp_74, + __tmp_85, |__k| cpp_move!(__k), || 0_i32, ) diff --git a/tests/unit/out/refcount/map_key_copy_ctor.rs b/tests/unit/out/refcount/map_key_copy_ctor.rs index 23a1742f03..6b30fb39c0 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -45,14 +45,8 @@ impl MoveConstructible for Key { } } impl CppLess for Key { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Key::operator_lt(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Key { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - !(Key::operator_lt(__lhs.clone(), __rhs.clone())) - && !(Key::operator_lt(__rhs.clone(), __lhs.clone())) + fn less(this: Ptr, o: Ptr) -> bool { + Key::operator_lt(this.clone(), o.clone()) } } pub fn make_key_3(__return: Ptr, mut k: i32) { diff --git a/tests/unit/out/refcount/map_key_identity.rs b/tests/unit/out/refcount/map_key_identity.rs index 6576af11ae..d502571423 100644 --- a/tests/unit/out/refcount/map_key_identity.rs +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -29,21 +29,13 @@ pub struct Key { pub identity: i32, } impl CppLess for Key { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_1(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Key { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_2(__lhs.clone(), __rhs.clone()) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_1(a.clone(), b.clone()) } } pub fn operator_lt_1(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.order) } < { b.with(|__s| __s.order) }); } -pub fn operator_eq_2(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.identity) } == { b.with(|__s| __s.identity) }); -} #[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, TriviallyCopyable)] #[byte_size(4)] pub struct Mapped { @@ -82,7 +74,11 @@ fn main_0() -> i32 { identity: 7, })); ok = { - ((ok as i32) & ((operator_eq_2(distinct_a.as_pointer(), distinct_b.as_pointer())) as i32)) + ((ok as i32) + & ((WeaklyEqualityComparableWith::equal( + distinct_a.as_pointer(), + distinct_b.as_pointer(), + )) as i32)) != 0 }; let distinct: Value, Value)>> = Rc::new(RefCell::new(Map::new())); @@ -114,31 +110,43 @@ fn main_0() -> i32 { }; ok = { ((ok as i32) - & (((*a_it.borrow()) - == distinct - .as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&distinct_a.as_pointer()) - })) as i32)) + & ((match (Rc::new(RefCell::new(distinct.as_pointer().with( + |__m: &Map, Value)>| __m.find(&distinct_a.as_pointer()), + ))) + .as_pointer(),) + { + (__tmp_0,) => { + WeaklyEqualityComparableWith::equal(a_it.as_pointer(), (__tmp_0).clone()) + } + }) as i32)) != 0 }; ok = { ((ok as i32) - & (((*b_it.borrow()) - == distinct - .as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&distinct_b.as_pointer()) - })) as i32)) + & ((match (Rc::new(RefCell::new(distinct.as_pointer().with( + |__m: &Map, Value)>| __m.find(&distinct_b.as_pointer()), + ))) + .as_pointer(),) + { + (__tmp_1,) => { + WeaklyEqualityComparableWith::equal(b_it.as_pointer(), (__tmp_1).clone()) + } + }) as i32)) != 0 }; ok = { ((ok as i32) - & (((*b_it.borrow()) - != distinct + & ((match (Rc::new(RefCell::new( + distinct .as_pointer() - .with(|__m: &Map, Value)>| __m.end())) - as i32)) + .with(|__m: &Map, Value)>| __m.end()), + )) + .as_pointer(),) + { + (__tmp_2,) => { + WeaklyEqualityComparableWith::not_equal(b_it.as_pointer(), (__tmp_2).clone()) + } + }) as i32)) != 0 }; ok = { @@ -157,7 +165,11 @@ fn main_0() -> i32 { != 0 }; ok = { - ((ok as i32) & ((operator_eq_2(distinct_a.as_pointer(), distinct_b.as_pointer())) as i32)) + ((ok as i32) + & ((WeaklyEqualityComparableWith::equal( + distinct_a.as_pointer(), + distinct_b.as_pointer(), + )) as i32)) != 0 }; let mut distinct_count: usize = 0_usize; @@ -200,7 +212,12 @@ fn main_0() -> i32 { })); ok = { ((ok as i32) - & (!({ operator_eq_2(equivalent_a.as_pointer(), equivalent_b.as_pointer()) }) as i32)) + & (!({ + WeaklyEqualityComparableWith::equal( + equivalent_a.as_pointer(), + equivalent_b.as_pointer(), + ) + }) as i32)) != 0 }; let equivalent: Value, Value)>> = @@ -233,32 +250,51 @@ fn main_0() -> i32 { if reused { ok = { ((ok as i32) - & (((*first_it.borrow()) - != equivalent + & ((match (Rc::new(RefCell::new( + equivalent .as_pointer() - .with(|__m: &Map, Value)>| __m.end())) - as i32)) + .with(|__m: &Map, Value)>| __m.end()), + )) + .as_pointer(),) + { + (__tmp_3,) => WeaklyEqualityComparableWith::not_equal( + first_it.as_pointer(), + (__tmp_3).clone(), + ), + }) as i32)) != 0 }; ok = { ((ok as i32) & (({ (first).clone() } == { (second).clone() }) as i32)) != 0 }; ok = { ((ok as i32) - & (((*first_it.borrow()) - == equivalent.as_pointer().with( - |__m: &Map, Value)>| { - __m.find(&equivalent_a.as_pointer()) - }, - )) as i32)) + & ((match (Rc::new(RefCell::new(equivalent.as_pointer().with( + |__m: &Map, Value)>| { + __m.find(&equivalent_a.as_pointer()) + }, + ))) + .as_pointer(),) + { + (__tmp_4,) => WeaklyEqualityComparableWith::equal( + first_it.as_pointer(), + (__tmp_4).clone(), + ), + }) as i32)) != 0 }; ok = { ((ok as i32) - & (((*first_it.borrow()) - == equivalent.as_pointer().with( - |__m: &Map, Value)>| { - __m.find(&equivalent_b.as_pointer()) - }, - )) as i32)) + & ((match (Rc::new(RefCell::new(equivalent.as_pointer().with( + |__m: &Map, Value)>| { + __m.find(&equivalent_b.as_pointer()) + }, + ))) + .as_pointer(),) + { + (__tmp_5,) => WeaklyEqualityComparableWith::equal( + first_it.as_pointer(), + (__tmp_5).clone(), + ), + }) as i32)) != 0 }; ok = { @@ -300,7 +336,12 @@ fn main_0() -> i32 { } ok = { ((ok as i32) - & (!({ operator_eq_2(equivalent_a.as_pointer(), equivalent_b.as_pointer()) }) as i32)) + & (!({ + WeaklyEqualityComparableWith::equal( + equivalent_a.as_pointer(), + equivalent_b.as_pointer(), + ) + }) as i32)) != 0 }; let later_key: Value = Rc::new(RefCell::new(Key { @@ -319,12 +360,18 @@ fn main_0() -> i32 { if reused { ok = { ((ok as i32) - & (((*first_it.borrow()) - == equivalent.as_pointer().with( - |__m: &Map, Value)>| { - __m.find(&equivalent_a.as_pointer()) - }, - )) as i32)) + & ((match (Rc::new(RefCell::new(equivalent.as_pointer().with( + |__m: &Map, Value)>| { + __m.find(&equivalent_a.as_pointer()) + }, + ))) + .as_pointer(),) + { + (__tmp_6,) => WeaklyEqualityComparableWith::equal( + first_it.as_pointer(), + (__tmp_6).clone(), + ), + }) as i32)) != 0 }; ok = { @@ -384,12 +431,15 @@ fn main_0() -> i32 { ok = { ((ok as i32) & (({ (matched).clone() } == { (matched_again).clone() }) as i32)) != 0 }; ok = { ((ok as i32) - & (((*matched_it.borrow()) - == matching - .as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&matching_b.as_pointer()) - })) as i32)) + & ((match (Rc::new(RefCell::new(matching.as_pointer().with( + |__m: &Map, Value)>| __m.find(&matching_b.as_pointer()), + ))) + .as_pointer(),) + { + (__tmp_7,) => { + WeaklyEqualityComparableWith::equal(matched_it.as_pointer(), (__tmp_7).clone()) + } + }) as i32)) != 0 }; ok = { @@ -418,12 +468,15 @@ fn main_0() -> i32 { ok = { ((ok as i32) & (((*matching.borrow()).len() == 2_usize) as i32)) != 0 }; ok = { ((ok as i32) - & (((*matched_it.borrow()) - == matching - .as_pointer() - .with(|__m: &Map, Value)>| { - __m.find(&matching_a.as_pointer()) - })) as i32)) + & ((match (Rc::new(RefCell::new(matching.as_pointer().with( + |__m: &Map, Value)>| __m.find(&matching_a.as_pointer()), + ))) + .as_pointer(),) + { + (__tmp_8,) => { + WeaklyEqualityComparableWith::equal(matched_it.as_pointer(), (__tmp_8).clone()) + } + }) as i32)) != 0 }; ok = { @@ -443,6 +496,11 @@ fn main_0() -> i32 { }; return if ok { 0 } else { 1 }; } +impl WeaklyEqualityComparableWith for Key { + fn equal(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.identity) } == { b.with(|__s| __s.identity) }); + } +} pub fn __cpp2rust_init_globals() { let _ = default_constructions_0.with(|_| ()); } diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index bd21add8dd..3e3dc3f6cd 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -295,7 +295,7 @@ fn main_0() -> i32 { as i32)) != 0 }; - let mut found : bool = (*(*result.borrow()) .0.borrow()) == m .as_pointer() .with(|__m: &Map, Value)>| __m.find(&key .as_pointer() )) ; + let mut found : bool = match (Rc::new(RefCell::new(m .as_pointer() .with(|__m: &Map, Value)>| __m.find(&key .as_pointer() )) )).as_pointer(),) { (__tmp_6,) => { WeaklyEqualityComparableWith::equal(({ (*result.borrow()) .0 .as_pointer() }), (__tmp_6 ).clone()) } } ; ok = { ((ok as i32) & (found as i32)) != 0 }; ok = { ((ok as i32) @@ -390,14 +390,14 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_6,) => { + (__tmp_7,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), (__tmp_6).clone()); + ConstructFrom::construct_from(__v.as_pointer(), (__tmp_7).clone()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -429,7 +429,7 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_7,) => { + (__tmp_8,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( @@ -438,7 +438,7 @@ fn main_0() -> i32 { let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( __v.as_pointer(), - Moved((__tmp_7).clone()), + Moved((__tmp_8).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -470,14 +470,14 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_8,) => { + (__tmp_9,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(copy_constructed(key.as_pointer().clone()))), Rc::new(RefCell::new({ let __v: Value = Rc::new(RefCell::new(::zero_init())); - ConstructFrom::construct_from(__v.as_pointer(), (__tmp_8).clone()); + ConstructFrom::construct_from(__v.as_pointer(), (__tmp_9).clone()); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -510,7 +510,7 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ argument_4(source.as_pointer()) }),) { - (__tmp_9,) => { + (__tmp_10,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( @@ -519,7 +519,7 @@ fn main_0() -> i32 { let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( __v.as_pointer(), - Moved((__tmp_9).clone()), + Moved((__tmp_10).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -573,13 +573,13 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ reference_5(counter.as_pointer()) }),) { - (__tmp_10,) => { + (__tmp_11,) => { let (__it, __inserted) = Map::emplace(refs.as_pointer(), &key.as_pointer(), || { ( 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_10).clone(), 2); + RefItem::construct_1(__v.as_pointer(), (__tmp_11).clone(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -604,13 +604,13 @@ fn main_0() -> i32 { Value, )> = Rc::new(RefCell::new( match (({ reference_5(counter.as_pointer()) }),) { - (__tmp_11,) => { + (__tmp_12,) => { let (__it, __inserted) = Map::emplace(refs.as_pointer(), &key.as_pointer(), || { ( 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); + RefItem::construct_1(__v.as_pointer(), (__tmp_12).clone(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), ) @@ -655,13 +655,13 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_13: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_14: Value = Rc::new(RefCell::new(::zero_init())); match ({ - Item::construct_1(__tmp_13.as_pointer(), 30); - __tmp_13.as_pointer() + Item::construct_1(__tmp_14.as_pointer(), 30); + __tmp_14.as_pointer() },) { - (__tmp_12,) => { + (__tmp_13,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( @@ -670,7 +670,7 @@ fn main_0() -> i32 { let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( __v.as_pointer(), - Moved((__tmp_12).clone()), + Moved((__tmp_13).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), @@ -698,13 +698,13 @@ fn main_0() -> i32 { Value, Value)>>, Value, )> = Rc::new(RefCell::new({ - let __tmp_15: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_16: Value = Rc::new(RefCell::new(::zero_init())); match ({ - Item::construct_1(__tmp_15.as_pointer(), 40); - __tmp_15.as_pointer() + Item::construct_1(__tmp_16.as_pointer(), 40); + __tmp_16.as_pointer() },) { - (__tmp_14,) => { + (__tmp_15,) => { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( @@ -713,7 +713,7 @@ fn main_0() -> i32 { let __v: Value = Rc::new(RefCell::new(::zero_init())); ConstructFrom::construct_from( __v.as_pointer(), - Moved((__tmp_14).clone()), + Moved((__tmp_15).clone()), ); Rc::try_unwrap(__v).ok().unwrap().into_inner() })), diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index fdd9e50724..db0277c11c 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -52,14 +52,8 @@ impl CopyConstructible for Bag { } } impl CppLess for Bag { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_4(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Bag { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - !(operator_lt_4(__lhs.clone(), __rhs.clone())) - && !(operator_lt_4(__rhs.clone(), __lhs.clone())) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_4(a.clone(), b.clone()) } } pub fn operator_lt_4(a: Ptr, b: Ptr) -> bool { @@ -117,17 +111,16 @@ fn main_0() -> i32 { assert!((((((r1 + r2) + r3) + r4) + r5) == 56)); let values: Value> = Rc::new(RefCell::new(Box::new([1, 7, 7, 3]))); let mut max: Ptr = { - let mut __tmp_2 = { values.decay() }; - let mut __tmp_3 = { values.decay().offset((4) as isize) }; - let mut __best = __tmp_2.clone(); - if __tmp_2 != __tmp_3 { - let mut __it = (__tmp_2).clone(); - __it.iter_inc(); - while __it != __tmp_3 { - if CppLess::less(__best.iter_deref(), __it.iter_deref()) { - __best = __it.clone(); + let __it: Value> = Rc::new(RefCell::new(values.decay())); + let __last: Value> = Rc::new(RefCell::new(values.decay().offset((4) as isize))); + 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()) { + if CppLess::less(__best.iter_deref(), __it.borrow().iter_deref()) { + __best = __it.borrow().clone(); } - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } } __best @@ -135,11 +128,11 @@ fn main_0() -> i32 { assert!(({ (max).clone() } == { values.decay().offset((1) as isize) })); assert!( ((match (({ pick_3(0,) }), ({ pick_3(1,) }),) { - (__tmp_4, __tmp_5) => { - if CppLess::less((__tmp_4).clone().clone(), (__tmp_5).clone().clone()) { - (__tmp_5).clone() + (__tmp_2, __tmp_3) => { + if CppLess::less((__tmp_2).clone().clone(), (__tmp_3).clone().clone()) { + (__tmp_3).clone() } else { - (__tmp_4).clone() + (__tmp_2).clone() } } } @@ -149,11 +142,11 @@ fn main_0() -> i32 { ); assert!( ((match (({ pick_3(1,) }), ({ pick_3(0,) }),) { - (__tmp_6, __tmp_7) => { - if CppLess::less((__tmp_7).clone().clone(), (__tmp_6).clone().clone()) { - (__tmp_7).clone() + (__tmp_4, __tmp_5) => { + if CppLess::less((__tmp_5).clone().clone(), (__tmp_4).clone().clone()) { + (__tmp_5).clone() } else { - (__tmp_6).clone() + (__tmp_4).clone() } } } @@ -164,46 +157,46 @@ 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_11: Value = Rc::new(RefCell::new(::zero_init())); (match ( { - ({ make_5(Ptr::clone(&__tmp_9.as_pointer()), 1) }); - __tmp_9.as_pointer() + ({ make_5(Ptr::clone(&__tmp_7.as_pointer()), 1) }); + __tmp_7.as_pointer() }, { - ({ make_5(Ptr::clone(&__tmp_11.as_pointer()), 2) }); - __tmp_11.as_pointer() + ({ make_5(Ptr::clone(&__tmp_9.as_pointer()), 2) }); + __tmp_9.as_pointer() }, ) { - (__tmp_8, __tmp_10) => { - if CppLess::less((__tmp_8).clone().clone(), (__tmp_10).clone().clone()) { - (__tmp_10).clone() - } else { + (__tmp_6, __tmp_8) => { + if CppLess::less((__tmp_6).clone().clone(), (__tmp_8).clone().clone()) { (__tmp_8).clone() + } else { + (__tmp_6).clone() } } } .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_15: Value = Rc::new(RefCell::new(::zero_init())); (match ( { - ({ make_5(Ptr::clone(&__tmp_13.as_pointer()), 1) }); - __tmp_13.as_pointer() + ({ make_5(Ptr::clone(&__tmp_11.as_pointer()), 1) }); + __tmp_11.as_pointer() }, { - ({ make_5(Ptr::clone(&__tmp_15.as_pointer()), 2) }); - __tmp_15.as_pointer() + ({ make_5(Ptr::clone(&__tmp_13.as_pointer()), 2) }); + __tmp_13.as_pointer() }, ) { - (__tmp_12, __tmp_14) => { - if CppLess::less((__tmp_14).clone().clone(), (__tmp_12).clone().clone()) { - (__tmp_14).clone() - } else { + (__tmp_10, __tmp_12) => { + if CppLess::less((__tmp_12).clone().clone(), (__tmp_10).clone().clone()) { (__tmp_12).clone() + } else { + (__tmp_10).clone() } } } @@ -218,16 +211,16 @@ fn main_0() -> i32 { 'loop_: while (i < 3) { 'for_body: { largest = (({ - let __tmp_17: Value = Rc::new(RefCell::new((largest as u64))); + let __tmp_15: Value = Rc::new(RefCell::new((largest as u64))); (match (Rc::new(RefCell::new((({ size_of_2(i) }) as u64))).as_pointer(),) { - (__tmp_16,) => { + (__tmp_14,) => { if CppLess::less( - __tmp_17.as_pointer().clone(), - (__tmp_16).clone().clone(), + __tmp_15.as_pointer().clone(), + (__tmp_14).clone().clone(), ) { - (__tmp_16).clone() + (__tmp_14).clone() } else { - __tmp_17.as_pointer() + __tmp_15.as_pointer() } } } diff --git a/tests/unit/out/refcount/operator_comparison_defaulted.rs b/tests/unit/out/refcount/operator_comparison_defaulted.rs index 35144fd896..ecdf2fe32e 100644 --- a/tests/unit/out/refcount/operator_comparison_defaulted.rs +++ b/tests/unit/out/refcount/operator_comparison_defaulted.rs @@ -25,17 +25,6 @@ pub struct Eq { #[offset(4)] pub b: i32, } -impl Eq { - pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }) - && ({ this.with(|__s| __s.b) } == { _a0.with(|__s| __s.b) }); - } -} -impl CppEq for Eq { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Eq::operator_eq(__lhs.clone(), __rhs.clone()) - } -} #[derive( Copy, Clone, @@ -77,19 +66,10 @@ impl Cmp { } return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } - pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }) - && ({ this.with(|__s| __s.b) } == { _a0.with(|__s| __s.b) }); - } } impl CppLess for Cmp { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Cmp::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less - } -} -impl CppEq for Cmp { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Cmp::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal + fn less(this: Ptr, _a0: Ptr) -> bool { + Cmp::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less } } #[derive( @@ -110,9 +90,6 @@ pub struct Both { pub a: i32, } impl Both { - pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); - } pub fn operator_cmp(this: Ptr, _a0: Ptr) -> std::cmp::Ordering { { let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( @@ -127,13 +104,8 @@ impl Both { } } impl CppLess for Both { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Both::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less - } -} -impl CppEq for Both { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Both::operator_eq(__lhs.clone(), __rhs.clone()) + fn less(this: Ptr, _a0: Ptr) -> bool { + Both::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less } } #[derive( @@ -168,13 +140,8 @@ impl OrdOnly { } } impl CppLess for OrdOnly { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - OrdOnly::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less - } -} -impl CppEq for OrdOnly { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - OrdOnly::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal + fn less(this: Ptr, _a0: Ptr) -> bool { + OrdOnly::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less } } #[derive( @@ -207,18 +174,10 @@ impl Inner { } return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } - pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.x) } == { _a0.with(|__s| __s.x) }); - } } impl CppLess for Inner { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Inner::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less - } -} -impl CppEq for Inner { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Inner::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal + fn less(this: Ptr, _a0: Ptr) -> bool { + Inner::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less } } #[derive( @@ -262,19 +221,10 @@ impl Outer { } return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } - pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { - return ({ Inner::operator_eq(field_ptr!(this, i), field_ptr!(_a0, i)) }) - && ({ this.with(|__s| __s.y) } == { _a0.with(|__s| __s.y) }); - } } impl CppLess for Outer { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Outer::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less - } -} -impl CppEq for Outer { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Outer::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal + fn less(this: Ptr, _a0: Ptr) -> bool { + Outer::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less } } #[derive( @@ -295,12 +245,6 @@ pub struct Secondary { pub a: i32, } impl Secondary { - pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); - } - pub fn operator_ne(this: Ptr, _a0: Ptr) -> bool { - return !({ Secondary::operator_eq((this).clone(), (_a0).clone()) }); - } pub fn operator_cmp(this: Ptr, _a0: Ptr) -> std::cmp::Ordering { { let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( @@ -323,13 +267,8 @@ impl Secondary { } } impl CppLess for Secondary { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Secondary::operator_lt(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Secondary { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Secondary::operator_eq(__lhs.clone(), __rhs.clone()) + fn less(this: Ptr, _a0: Ptr) -> bool { + Secondary::operator_lt(this.clone(), _a0.clone()) } } #[derive( @@ -362,18 +301,10 @@ impl PtrMember { } return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } - pub fn operator_eq(this: Ptr, _a0: Ptr) -> bool { - return ({ this.with(|__s| __s.p.clone()) } == { _a0.with(|__s| __s.p.clone()) }); - } } impl CppLess for PtrMember { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - PtrMember::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less - } -} -impl CppEq for PtrMember { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - PtrMember::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Equal + fn less(this: Ptr, _a0: Ptr) -> bool { + PtrMember::operator_cmp(this.clone(), _a0.clone()) == std::cmp::Ordering::Less } } pub fn main() { @@ -384,8 +315,8 @@ fn main_0() -> i32 { let e1: Value = Rc::new(RefCell::new(Eq { a: 1, b: 2 })); let e2: Value = Rc::new(RefCell::new(Eq { a: 1, b: 2 })); let e3: Value = Rc::new(RefCell::new(Eq { a: 1, b: 3 })); - assert!(({ Eq::operator_eq(e1.as_pointer(), e2.as_pointer(),) })); - assert!(!({ Eq::operator_eq(e1.as_pointer(), e3.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(e1.as_pointer(), e2.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(e1.as_pointer(), e3.as_pointer(),) })); let c1: Value = Rc::new(RefCell::new(Cmp { a: 1, b: 2 })); let c2: Value = Rc::new(RefCell::new(Cmp { a: 1, b: 3 })); let c3: Value = Rc::new(RefCell::new(Cmp { a: 2, b: 0 })); @@ -394,7 +325,7 @@ fn main_0() -> i32 { assert!( ({ Cmp::operator_cmp(c3.as_pointer(), c4.as_pointer(),) }) == std::cmp::Ordering::Greater ); - assert!(({ Cmp::operator_eq(c1.as_pointer(), c1.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(c1.as_pointer(), c1.as_pointer(),) })); assert!( ({ Cmp::operator_cmp(c1.as_pointer(), c2.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_less().upgrade().deref()) }) @@ -404,7 +335,7 @@ fn main_0() -> i32 { assert!( ({ Both::operator_cmp(b1.as_pointer(), b2.as_pointer(),) }) == std::cmp::Ordering::Less ); - assert!(({ Both::operator_eq(b2.as_pointer(), b2.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(b2.as_pointer(), b2.as_pointer(),) })); let o1: Value = Rc::new(RefCell::new(OrdOnly { a: 1 })); let o2: Value = Rc::new(RefCell::new(OrdOnly { a: 2 })); assert!( @@ -429,14 +360,14 @@ fn main_0() -> i32 { assert!( ({ Outer::operator_cmp(x1.as_pointer(), x2.as_pointer(),) }) == std::cmp::Ordering::Less ); - assert!(({ Outer::operator_eq(x1.as_pointer(), x3.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(x1.as_pointer(), x3.as_pointer(),) })); assert!( ({ Outer::operator_cmp(x2.as_pointer(), x1.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_greater().upgrade().deref()) }) ); let s1: Value = Rc::new(RefCell::new(Secondary { a: 1 })); let s2: Value = Rc::new(RefCell::new(Secondary { a: 2 })); - assert!(({ Secondary::operator_ne(s1.as_pointer(), s2.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::not_equal(s1.as_pointer(), s2.as_pointer(),) })); assert!(({ Secondary::operator_lt(s1.as_pointer(), s2.as_pointer(),) })); assert!(({ Secondary::operator_ge(s2.as_pointer(), s1.as_pointer(),) })); assert!(!({ Secondary::operator_lt(s2.as_pointer(), s1.as_pointer(),) })); @@ -450,11 +381,52 @@ fn main_0() -> i32 { ({ PtrMember::operator_cmp(p1.as_pointer(), p2.as_pointer(),) }) == std::cmp::Ordering::Less ); - assert!(({ PtrMember::operator_eq(p1.as_pointer(), p3.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(p1.as_pointer(), p3.as_pointer(),) })); assert!( ({ PtrMember::operator_cmp(p2.as_pointer(), p1.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_greater().upgrade().deref()) }) ); return 0; } +impl WeaklyEqualityComparableWith for Both { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); + } +} +impl WeaklyEqualityComparableWith for Cmp { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }) + && ({ this.with(|__s| __s.b) } == { _a0.with(|__s| __s.b) }); + } +} +impl WeaklyEqualityComparableWith for Eq { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }) + && ({ this.with(|__s| __s.b) } == { _a0.with(|__s| __s.b) }); + } +} +impl WeaklyEqualityComparableWith for Inner { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.x) } == { _a0.with(|__s| __s.x) }); + } +} +impl WeaklyEqualityComparableWith for Outer { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ WeaklyEqualityComparableWith::equal(field_ptr!(this, i), field_ptr!(_a0, i)) }) + && ({ this.with(|__s| __s.y) } == { _a0.with(|__s| __s.y) }); + } +} +impl WeaklyEqualityComparableWith for PtrMember { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.p.clone()) } == { _a0.with(|__s| __s.p.clone()) }); + } +} +impl WeaklyEqualityComparableWith for Secondary { + fn equal(this: Ptr, _a0: Ptr) -> bool { + return ({ this.with(|__s| __s.a) } == { _a0.with(|__s| __s.a) }); + } + fn not_equal(this: Ptr, _a0: Ptr) -> bool { + return !({ WeaklyEqualityComparableWith::equal((this).clone(), (_a0).clone()) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_comparison_free.rs b/tests/unit/out/refcount/operator_comparison_free.rs index a3cce0c780..6ebfb63406 100644 --- a/tests/unit/out/refcount/operator_comparison_free.rs +++ b/tests/unit/out/refcount/operator_comparison_free.rs @@ -24,37 +24,26 @@ pub struct S { pub v: i32, } impl CppLess for S { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_0(__lhs.clone(), __rhs.clone()) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_0(a.clone(), b.clone()) } } -impl CppEq for S { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_1(__lhs.clone(), __rhs.clone()) - } -} -pub fn operator_eq_1(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); -} -pub fn operator_ne_2(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.v) } != { b.with(|__s| __s.v) }); -} pub fn operator_lt_0(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } < { b.with(|__s| __s.v) }); } -pub fn operator_gt_3(a: Ptr, b: Ptr) -> bool { +pub fn operator_gt_1(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } > { b.with(|__s| __s.v) }); } -pub fn operator_le_4(a: Ptr, b: Ptr) -> bool { +pub fn operator_le_2(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } <= { b.with(|__s| __s.v) }); } -pub fn operator_ge_5(a: Ptr, b: Ptr) -> bool { +pub fn operator_ge_3(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } >= { b.with(|__s| __s.v) }); } -pub fn operator_lt_6(a: Ptr, mut b: i32) -> bool { +pub fn operator_lt_4(a: Ptr, mut b: i32) -> bool { return ({ a.with(|__s| __s.v) } < { b }); } -pub fn operator_lt_7(mut a: i32, b: Ptr) -> bool { +pub fn operator_lt_5(mut a: i32, b: Ptr) -> bool { return ({ a } < { b.with(|__s| __s.v) }); } #[derive( @@ -75,25 +64,20 @@ pub struct V { pub v: i32, } impl CppLess for V { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_8(__lhs.read(), __rhs.read()) - } -} -impl CppEq for V { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_9(__lhs.read(), __rhs.read()) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_7(a.read(), b.read()) } } -pub fn operator_eq_9(mut a: V, mut b: V) -> bool { +pub fn operator_eq_8(mut a: V, mut b: V) -> bool { return (a.v == b.v); } -pub fn operator_ne_10(mut a: V, mut b: V) -> bool { +pub fn operator_ne_6(mut a: V, mut b: V) -> bool { return (a.v != b.v); } -pub fn operator_lt_8(mut a: V, mut b: V) -> bool { +pub fn operator_lt_7(mut a: V, mut b: V) -> bool { return (a.v < b.v); } -pub fn operator_gt_11(mut a: V, mut b: V) -> bool { +pub fn operator_gt_9(mut a: V, mut b: V) -> bool { return (a.v > b.v); } pub fn main() { @@ -104,23 +88,39 @@ fn main_0() -> i32 { let mut x: V = V { v: 1 }; let mut y: V = V { v: 2 }; let mut z: V = V { v: 1 }; - assert!(({ operator_eq_9(x, z,) })); - assert!(({ operator_ne_10(x, y,) })); - assert!(({ operator_lt_8(x, y,) })); - assert!(({ operator_gt_11(y, x,) })); - assert!(!({ operator_lt_8(y, x,) })); + assert!(({ operator_eq_8(x, z,) })); + assert!(({ operator_ne_6(x, y,) })); + assert!(({ operator_lt_7(x, y,) })); + assert!(({ operator_gt_9(y, x,) })); + assert!(!({ operator_lt_7(y, x,) })); let a: Value = Rc::new(RefCell::new(S { v: 1 })); let b: Value = Rc::new(RefCell::new(S { v: 2 })); let c: Value = Rc::new(RefCell::new(S { v: 1 })); - assert!(({ operator_eq_1(a.as_pointer(), c.as_pointer(),) })); - assert!(({ operator_ne_2(a.as_pointer(), b.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(a.as_pointer(), c.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::not_equal(a.as_pointer(), b.as_pointer(),) })); assert!(({ operator_lt_0(a.as_pointer(), b.as_pointer(),) })); - assert!(({ operator_gt_3(b.as_pointer(), a.as_pointer(),) })); - assert!(({ operator_le_4(a.as_pointer(), c.as_pointer(),) })); - assert!(({ operator_ge_5(a.as_pointer(), c.as_pointer(),) })); + assert!(({ operator_gt_1(b.as_pointer(), a.as_pointer(),) })); + assert!(({ operator_le_2(a.as_pointer(), c.as_pointer(),) })); + assert!(({ operator_ge_3(a.as_pointer(), c.as_pointer(),) })); assert!(!({ operator_lt_0(b.as_pointer(), a.as_pointer(),) })); - assert!(({ operator_lt_6(a.as_pointer(), 5,) })); - assert!(({ operator_lt_7(0, a.as_pointer(),) })); + assert!(({ operator_lt_4(a.as_pointer(), 5,) })); + assert!(({ operator_lt_5(0, a.as_pointer(),) })); return 0; } +impl WeaklyEqualityComparableWith for S { + fn equal(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); + } + fn not_equal(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.v) } != { b.with(|__s| __s.v) }); + } +} +impl WeaklyEqualityComparableWith for V { + fn not_equal(a: Ptr, b: Ptr) -> bool { + operator_ne_6(a.read(), b.read()) + } + fn equal(a: Ptr, b: Ptr) -> bool { + operator_eq_8(a.read(), b.read()) + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_comparison_member.rs b/tests/unit/out/refcount/operator_comparison_member.rs index a0088dd538..d0d5e86497 100644 --- a/tests/unit/out/refcount/operator_comparison_member.rs +++ b/tests/unit/out/refcount/operator_comparison_member.rs @@ -24,12 +24,6 @@ pub struct S { pub v: i32, } impl S { - pub fn operator_eq(this: Ptr, o: Ptr) -> bool { - return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } - pub fn operator_ne(this: Ptr, o: Ptr) -> bool { - return ({ this.with(|__s| __s.v) } != { o.with(|__s| __s.v) }); - } pub fn operator_lt_3(this: Ptr, o: Ptr) -> bool { return ({ this.with(|__s| __s.v) } < { o.with(|__s| __s.v) }); } @@ -47,13 +41,8 @@ impl S { } } impl CppLess for S { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - S::operator_lt_3(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for S { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - S::operator_eq(__lhs.clone(), __rhs.clone()) + fn less(this: Ptr, o: Ptr) -> bool { + S::operator_lt_3(this.clone(), o.clone()) } } pub fn main() { @@ -64,8 +53,8 @@ fn main_0() -> i32 { let a: Value = Rc::new(RefCell::new(S { v: 1 })); let b: Value = Rc::new(RefCell::new(S { v: 2 })); let c: Value = Rc::new(RefCell::new(S { v: 1 })); - assert!(({ S::operator_eq(a.as_pointer(), c.as_pointer(),) })); - assert!(({ S::operator_ne(a.as_pointer(), b.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(a.as_pointer(), c.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::not_equal(a.as_pointer(), b.as_pointer(),) })); assert!(({ S::operator_lt_3(a.as_pointer(), b.as_pointer(),) })); assert!(({ S::operator_gt(b.as_pointer(), a.as_pointer(),) })); assert!(({ S::operator_le(a.as_pointer(), c.as_pointer(),) })); @@ -74,4 +63,12 @@ fn main_0() -> i32 { assert!(({ S::operator_lt_7(a.as_pointer(), 5,) })); return 0; } +impl WeaklyEqualityComparableWith for S { + fn equal(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } + fn not_equal(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } != { o.with(|__s| __s.v) }); + } +} 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 1229dd8525..e616eb253b 100644 --- a/tests/unit/out/refcount/operator_comparison_nonbool.rs +++ b/tests/unit/out/refcount/operator_comparison_nonbool.rs @@ -24,22 +24,17 @@ pub struct X { pub v: i32, } impl CppLess for X { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - ((operator_lt_0(__lhs.read(), __rhs.read())) != 0) + fn less(a: Ptr, b: Ptr) -> bool { + ((operator_lt_1(a.read(), b.read())) != 0) } } -impl CppEq for X { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - ((operator_eq_1(__lhs.read(), __rhs.read())) != 0) - } -} -pub fn operator_eq_1(mut a: X, mut b: X) -> i32 { +pub fn operator_eq_2(mut a: X, mut b: X) -> i32 { return if (a.v == b.v) { 2 } else { 0 }; } -pub fn operator_ne_2(mut a: X, mut b: X) -> i32 { +pub fn operator_ne_0(mut a: X, mut b: X) -> i32 { return if (a.v != b.v) { 3 } else { 0 }; } -pub fn operator_lt_0(mut a: X, mut b: X) -> i32 { +pub fn operator_lt_1(mut a: X, mut b: X) -> i32 { return if (a.v < b.v) { 4 } else { 0 }; } pub fn operator_gt_3(mut a: X, mut b: X) -> i32 { @@ -131,13 +126,8 @@ impl Mixed { } } impl CppLess for Mixed { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - ((Mixed::operator_lt(__lhs.clone(), __rhs.clone())) != 0) - } -} -impl CppEq for Mixed { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - ((Mixed::operator_eq(__lhs.clone(), __rhs.clone())) != 0) + fn less(this: Ptr, o: Ptr) -> bool { + ((Mixed::operator_lt(this.clone(), o.clone())) != 0) } } #[derive( @@ -185,17 +175,9 @@ pub struct Boolish { pub v: i32, } impl CppLess for Boolish { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { + fn less(a: Ptr, b: Ptr) -> bool { { - let __cmp = operator_lt_6(__lhs.read(), __rhs.read()); - MyBool::to_bool(Rc::new(RefCell::new(__cmp)).as_pointer()) - } - } -} -impl CppEq for Boolish { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - { - let __cmp = operator_eq_7(__lhs.read(), __rhs.read()); + let __cmp = operator_lt_6(a.read(), b.read()); MyBool::to_bool(Rc::new(RefCell::new(__cmp)).as_pointer()) } } @@ -269,14 +251,6 @@ impl RefInt { return ref_true_8.with(|v| v.as_pointer()); } } -impl CppEq for RefInt { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - { - let __cmp = RefInt::operator_eq(__lhs.clone(), __rhs.clone()); - RefBool::to_bool(__cmp.clone()) - } - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -285,10 +259,10 @@ fn main_0() -> i32 { let mut a: X = X { v: 1 }; let mut b: X = X { v: 2 }; let mut c: X = X { v: 1 }; - assert!((({ operator_eq_1(a, c,) }) == 2)); - assert!((({ operator_eq_1(a, b,) }) == 0)); - assert!((({ operator_ne_2(a, b,) }) == 3)); - assert!((({ operator_lt_0(a, b,) }) == 4)); + assert!((({ operator_eq_2(a, c,) }) == 2)); + assert!((({ operator_eq_2(a, b,) }) == 0)); + assert!((({ operator_ne_0(a, b,) }) == 3)); + assert!((({ operator_lt_1(a, b,) }) == 4)); assert!((({ operator_gt_3(b, a,) }) == 5)); assert!((({ operator_le_4(a, c,) }) == 6)); assert!((({ operator_ge_5(a, c,) }) == 7)); @@ -368,16 +342,51 @@ fn main_0() -> i32 { Rc::new(RefCell::new(Box::new([RefInt { v: 1 }, RefInt { v: 2 }]))); assert!( ({ - let mut __tmp_3 = { ris.decay().offset((2) as isize) }; - let mut __it = ris.decay(); - while __it != __tmp_3 && !CppEq::equal(__it.iter_deref(), ri2.as_pointer().clone()) { - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(ris.decay())); + let __last: Value> = + Rc::new(RefCell::new(ris.decay().offset((2) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) + && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + ri2.as_pointer().clone(), + ) + { + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() } == ris.decay()) ); return 0; } +impl WeaklyEqualityComparableWith for Boolish { + fn equal(a: Ptr, b: Ptr) -> bool { + { + let __cmp = operator_eq_7(a.read(), b.read()); + MyBool::to_bool(Rc::new(RefCell::new(__cmp)).as_pointer()) + } + } +} +impl WeaklyEqualityComparableWith for Mixed { + fn equal(this: Ptr, o: Ptr) -> bool { + ((Mixed::operator_eq(this.clone(), o.clone())) != 0) + } +} +impl WeaklyEqualityComparableWith for RefInt { + fn equal(this: Ptr, _a0: Ptr) -> bool { + { + let __cmp = RefInt::operator_eq(this.clone(), _a0.clone()); + RefBool::to_bool(__cmp.clone()) + } + } +} +impl WeaklyEqualityComparableWith for X { + fn not_equal(a: Ptr, b: Ptr) -> bool { + ((operator_ne_0(a.read(), b.read())) != 0) + } + fn equal(a: Ptr, b: Ptr) -> bool { + ((operator_eq_2(a.read(), b.read())) != 0) + } +} pub fn __cpp2rust_init_globals() { let _ = ref_true_8.with(|_| ()); } diff --git a/tests/unit/out/refcount/operator_comparison_noncopyable.rs b/tests/unit/out/refcount/operator_comparison_noncopyable.rs index 7edce8d200..8d00d4fb59 100644 --- a/tests/unit/out/refcount/operator_comparison_noncopyable.rs +++ b/tests/unit/out/refcount/operator_comparison_noncopyable.rs @@ -6,10 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn operator_eq_0(x: Ptr, y: Ptr) -> bool { - return ({ x.with(|__s| __s.data_) } == { y.with(|__s| __s.data_) }); -} -pub fn operator_lt_1(x: Ptr, y: Ptr) -> bool { +pub fn operator_lt_0(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.data_) } < { y.with(|__s| __s.data_) }); } #[derive( @@ -35,13 +32,8 @@ impl S { } } impl CppLess for S { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_1(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for S { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_0(__lhs.clone(), __rhs.clone()) + fn less(x: Ptr, y: Ptr) -> bool { + operator_lt_0(x.clone(), y.clone()) } } pub fn main() { @@ -52,9 +44,14 @@ fn main_0() -> i32 { object!(a, S(1)); object!(b, S(2)); object!(c, S(1)); - assert!(({ operator_eq_0(a.as_pointer(), c.as_pointer(),) })); - assert!(({ operator_lt_1(a.as_pointer(), b.as_pointer(),) })); - assert!(!({ operator_lt_1(b.as_pointer(), a.as_pointer(),) })); + 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(),) })); return 0; } +impl WeaklyEqualityComparableWith for S { + fn equal(x: Ptr, y: Ptr) -> bool { + return ({ x.with(|__s| __s.data_) } == { y.with(|__s| __s.data_) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_friend.rs b/tests/unit/out/refcount/operator_friend.rs index 7355fb70d4..84cd7bd9af 100644 --- a/tests/unit/out/refcount/operator_friend.rs +++ b/tests/unit/out/refcount/operator_friend.rs @@ -6,10 +6,6 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -pub fn operator_eq_0(_a0: Ptr, _a1: Ptr) -> bool { - return ({ _a0.with(|__s| __s.a) } == { _a1.with(|__s| __s.a) }) - && ({ _a0.with(|__s| __s.b) } == { _a1.with(|__s| __s.b) }); -} #[derive( Copy, Clone, @@ -29,12 +25,7 @@ pub struct Defaulted { #[offset(4)] pub b: i32, } -impl CppEq for Defaulted { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_0(__lhs.clone(), __rhs.clone()) - } -} -pub fn operator_cmp_1(_a0: Ptr, _a1: Ptr) -> std::cmp::Ordering { +pub fn operator_cmp_0(_a0: Ptr, _a1: Ptr) -> std::cmp::Ordering { { let cmp: Value = Rc::new(RefCell::new(std::cmp::Ord::cmp( &(_a0.with(|__s| __s.a)), @@ -46,9 +37,6 @@ pub fn operator_cmp_1(_a0: Ptr, _a1: Ptr) -> std::cm } return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } -pub fn operator_eq_2(_a0: Ptr, _a1: Ptr) -> bool { - return ({ _a0.with(|__s| __s.a) } == { _a1.with(|__s| __s.a) }); -} #[derive( Copy, Clone, @@ -67,22 +55,14 @@ pub struct DefaultedOrd { pub a: i32, } impl CppLess for DefaultedOrd { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_cmp_1(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less - } -} -impl CppEq for DefaultedOrd { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_2(__lhs.clone(), __rhs.clone()) + fn less(_a0: Ptr, _a1: Ptr) -> bool { + operator_cmp_0(_a0.clone(), _a1.clone()) == std::cmp::Ordering::Less } } -pub fn operator_eq_3(x: Ptr, y: Ptr) -> bool { - return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }); -} -pub fn operator_lt_4(x: Ptr, y: Ptr) -> bool { +pub fn operator_lt_1(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.a) } < { y.with(|__s| __s.a) }); } -pub fn operator_add_5(x: Ptr, y: Ptr) -> Inline { +pub fn operator_add_2(x: Ptr, y: Ptr) -> Inline { return Inline { a: ({ x.with(|__s| __s.a) } + { y.with(|__s| __s.a) }), }; @@ -105,13 +85,8 @@ pub struct Inline { pub a: i32, } impl CppLess for Inline { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_4(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Inline { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_3(__lhs.clone(), __rhs.clone()) + fn less(x: Ptr, y: Ptr) -> bool { + operator_lt_1(x.clone(), y.clone()) } } #[derive( @@ -131,26 +106,9 @@ pub struct OutOfLine { #[offset(0)] pub a: i32, } -impl CppEq for OutOfLine { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_6(__lhs.clone(), __rhs.clone()) - } -} -pub fn operator_eq_6(x: Ptr, y: Ptr) -> bool { - return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }); -} -pub fn operator_ne_7(x: Ptr, y: Ptr) -> bool { - return !({ operator_eq_6((x).clone(), (y).clone()) }); -} -pub fn operator_eq_8(x: Ptr, y: Ptr) -> bool { - return ({ x.with(|__s| __s.v) } == { y.with(|__s| __s.v) }); -} -pub fn operator_lt_9(x: Ptr, y: Ptr) -> bool { +pub fn operator_lt_3(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.v) } < { y.with(|__s| __s.v) }); } -pub fn operator_eq_10(x: Ptr, y: Ptr) -> bool { - return ({ (x.with(|__s| __s.v) as i64) } == { y.with(|__s| __s.v) }); -} #[derive( Copy, Clone, @@ -169,13 +127,8 @@ pub struct Tmpl_int_ { pub v: i32, } impl CppLess for Tmpl_int_ { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_9(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Tmpl_int_ { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_8(__lhs.clone(), __rhs.clone()) + fn less(x: Ptr, y: Ptr) -> bool { + operator_lt_3(x.clone(), y.clone()) } } #[derive( @@ -195,9 +148,6 @@ pub struct Tmpl_long_ { #[offset(0)] pub v: i64, } -pub fn operator_eq_11(_a0: Ptr, _a1: Ptr) -> bool { - return ({ _a0.with(|__s| __s.v) } == { _a1.with(|__s| __s.v) }); -} #[derive( Copy, Clone, @@ -215,11 +165,6 @@ pub struct TmplDefaulted_int_ { #[offset(0)] pub v: i32, } -impl CppEq for TmplDefaulted_int_ { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_11(__lhs.clone(), __rhs.clone()) - } -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -228,56 +173,100 @@ fn main_0() -> i32 { let d1: Value = Rc::new(RefCell::new(Defaulted { a: 1, b: 2 })); let d2: Value = Rc::new(RefCell::new(Defaulted { a: 1, b: 2 })); let d3: Value = Rc::new(RefCell::new(Defaulted { a: 1, b: 3 })); - assert!(({ operator_eq_0(d1.as_pointer(), d2.as_pointer(),) })); - assert!(!({ operator_eq_0(d1.as_pointer(), d3.as_pointer(),) })); - assert!(!({ operator_eq_0(d1.as_pointer(), d3.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(d1.as_pointer(), d2.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(d1.as_pointer(), d3.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(d1.as_pointer(), d3.as_pointer(),) })); let o1: Value = Rc::new(RefCell::new(DefaultedOrd { a: 1 })); let o2: Value = Rc::new(RefCell::new(DefaultedOrd { a: 2 })); - assert!(({ operator_cmp_1(o1.as_pointer(), o2.as_pointer(),) }) == std::cmp::Ordering::Less); - assert!(({ operator_cmp_1(o2.as_pointer(), o1.as_pointer(),) }) == std::cmp::Ordering::Greater); - assert!(({ operator_eq_2(o1.as_pointer(), o1.as_pointer(),) })); + assert!(({ operator_cmp_0(o1.as_pointer(), o2.as_pointer(),) }) == std::cmp::Ordering::Less); + assert!(({ operator_cmp_0(o2.as_pointer(), o1.as_pointer(),) }) == std::cmp::Ordering::Greater); + assert!(({ WeaklyEqualityComparableWith::equal(o1.as_pointer(), o1.as_pointer(),) })); assert!( - ({ operator_cmp_1(o1.as_pointer(), o2.as_pointer(),) }) + ({ operator_cmp_0(o1.as_pointer(), o2.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_less().upgrade().deref()) }) ); let i1: Value = Rc::new(RefCell::new(Inline { a: 1 })); let i2: Value = Rc::new(RefCell::new(Inline { a: 2 })); let i3: Value = Rc::new(RefCell::new(Inline { a: 1 })); - assert!(({ operator_eq_3(i1.as_pointer(), i3.as_pointer(),) })); - assert!(!({ operator_eq_3(i1.as_pointer(), i2.as_pointer(),) })); - assert!(({ operator_lt_4(i1.as_pointer(), i2.as_pointer(),) })); - assert!(!({ operator_lt_4(i2.as_pointer(), i1.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(i1.as_pointer(), i3.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(i1.as_pointer(), i2.as_pointer(),) })); + assert!(({ operator_lt_1(i1.as_pointer(), i2.as_pointer(),) })); + assert!(!({ operator_lt_1(i2.as_pointer(), i1.as_pointer(),) })); assert!( ({ let _x: Value = Rc::new(RefCell::new( - ({ operator_add_5(i1.as_pointer(), i2.as_pointer()) }), + ({ operator_add_2(i1.as_pointer(), i2.as_pointer()) }), )); let _y: Value = Rc::new(RefCell::new(Inline { a: 3 })); - operator_eq_3(_x.as_pointer(), _y.as_pointer()) + WeaklyEqualityComparableWith::equal(_x.as_pointer(), _y.as_pointer()) }) ); let f1: Value = Rc::new(RefCell::new(OutOfLine { a: 4 })); let f2: Value = Rc::new(RefCell::new(OutOfLine { a: 4 })); let f3: Value = Rc::new(RefCell::new(OutOfLine { a: 5 })); - assert!(({ operator_eq_6(f1.as_pointer(), f2.as_pointer(),) })); - assert!(({ operator_ne_7(f1.as_pointer(), f3.as_pointer(),) })); - assert!(!({ operator_eq_6(f1.as_pointer(), f3.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(f1.as_pointer(), f2.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::not_equal(f1.as_pointer(), f3.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(f1.as_pointer(), f3.as_pointer(),) })); let t1: Value = Rc::new(RefCell::new(Tmpl_int_ { v: 1 })); let t2: Value = Rc::new(RefCell::new(Tmpl_int_ { v: 2 })); let t3: Value = Rc::new(RefCell::new(Tmpl_int_ { v: 1 })); - assert!(({ operator_eq_8(t1.as_pointer(), t3.as_pointer(),) })); - assert!(!({ operator_eq_8(t1.as_pointer(), t2.as_pointer(),) })); - assert!(({ operator_lt_9(t1.as_pointer(), t2.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(t1.as_pointer(), t3.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(t1.as_pointer(), t2.as_pointer(),) })); + assert!(({ operator_lt_3(t1.as_pointer(), t2.as_pointer(),) })); let u1: Value = Rc::new(RefCell::new(Tmpl_long_ { v: 1_i64 })); let u2: Value = Rc::new(RefCell::new(Tmpl_long_ { v: 2_i64 })); - assert!(({ operator_eq_10(t1.as_pointer(), u1.as_pointer(),) })); - assert!(!({ operator_eq_10(t1.as_pointer(), u2.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(t1.as_pointer(), u1.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(t1.as_pointer(), u2.as_pointer(),) })); let v1: Value = Rc::new(RefCell::new(TmplDefaulted_int_ { v: 7 })); let v2: Value = Rc::new(RefCell::new(TmplDefaulted_int_ { v: 7 })); let v3: Value = Rc::new(RefCell::new(TmplDefaulted_int_ { v: 8 })); - assert!(({ operator_eq_11(v1.as_pointer(), v2.as_pointer(),) })); - assert!(!({ operator_eq_11(v1.as_pointer(), v3.as_pointer(),) })); - assert!(!({ operator_eq_11(v1.as_pointer(), v3.as_pointer(),) })); + assert!(({ WeaklyEqualityComparableWith::equal(v1.as_pointer(), v2.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(v1.as_pointer(), v3.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(v1.as_pointer(), v3.as_pointer(),) })); return 0; } +impl WeaklyEqualityComparableWith for Defaulted { + fn equal(_a0: Ptr, _a1: Ptr) -> bool { + return ({ _a0.with(|__s| __s.a) } == { _a1.with(|__s| __s.a) }) + && ({ _a0.with(|__s| __s.b) } == { _a1.with(|__s| __s.b) }); + } +} +impl WeaklyEqualityComparableWith for DefaultedOrd { + fn equal(_a0: Ptr, _a1: Ptr) -> bool { + return ({ _a0.with(|__s| __s.a) } == { _a1.with(|__s| __s.a) }); + } +} +impl WeaklyEqualityComparableWith for Inline { + fn equal(x: Ptr, y: Ptr) -> bool { + return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }); + } +} +impl WeaklyEqualityComparableWith for OutOfLine { + fn equal(x: Ptr, y: Ptr) -> bool { + return ({ x.with(|__s| __s.a) } == { y.with(|__s| __s.a) }); + } + fn not_equal(x: Ptr, y: Ptr) -> bool { + return !({ WeaklyEqualityComparableWith::equal((x).clone(), (y).clone()) }); + } +} +impl WeaklyEqualityComparableWith for TmplDefaulted_int_ { + fn equal(_a0: Ptr, _a1: Ptr) -> bool { + return ({ _a0.with(|__s| __s.v) } == { _a1.with(|__s| __s.v) }); + } +} +impl WeaklyEqualityComparableWith for Tmpl_int_ { + fn equal(x: Ptr, y: Ptr) -> bool { + return ({ x.with(|__s| __s.v) } == { y.with(|__s| __s.v) }); + } +} +impl WeaklyEqualityComparableWith for Tmpl_long_ { + fn equal(lhs: Ptr, rhs: Ptr) -> bool { + >::equal(rhs, lhs) + } +} +impl WeaklyEqualityComparableWith for Tmpl_int_ { + fn equal(x: Ptr, y: Ptr) -> bool { + return ({ (x.with(|__s| __s.v) as i64) } == { y.with(|__s| __s.v) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_less_than.rs b/tests/unit/out/refcount/operator_less_than.rs index e62ec942fc..47bb4adc05 100644 --- a/tests/unit/out/refcount/operator_less_than.rs +++ b/tests/unit/out/refcount/operator_less_than.rs @@ -33,14 +33,8 @@ impl Pair { } } impl CppLess for Pair { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Pair::operator_lt(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Pair { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - !(Pair::operator_lt(__lhs.clone(), __rhs.clone())) - && !(Pair::operator_lt(__rhs.clone(), __lhs.clone())) + fn less(this: Ptr, other: Ptr) -> bool { + Pair::operator_lt(this.clone(), other.clone()) } } pub fn main() { diff --git a/tests/unit/out/refcount/operator_three_way.rs b/tests/unit/out/refcount/operator_three_way.rs index 993d253862..54907d11aa 100644 --- a/tests/unit/out/refcount/operator_three_way.rs +++ b/tests/unit/out/refcount/operator_three_way.rs @@ -33,18 +33,10 @@ impl S { } return (*libcc2rs::strong_ordering_equal().upgrade().deref()); } - pub fn operator_eq(this: Ptr, o: Ptr) -> bool { - return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } } impl CppLess for S { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - S::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less - } -} -impl CppEq for S { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - S::operator_eq(__lhs.clone(), __rhs.clone()) + fn less(this: Ptr, o: Ptr) -> bool { + S::operator_cmp(this.clone(), o.clone()) == std::cmp::Ordering::Less } } pub fn main() { @@ -58,11 +50,16 @@ fn main_0() -> i32 { assert!(({ S::operator_cmp(b.as_pointer(), a.as_pointer(),) }) == std::cmp::Ordering::Greater); assert!(({ S::operator_cmp(a.as_pointer(), b.as_pointer(),) }) != std::cmp::Ordering::Greater); assert!(({ S::operator_cmp(b.as_pointer(), a.as_pointer(),) }) != std::cmp::Ordering::Less); - assert!(!({ S::operator_eq(a.as_pointer(), b.as_pointer(),) })); + assert!(!({ WeaklyEqualityComparableWith::equal(a.as_pointer(), b.as_pointer(),) })); assert!( ({ S::operator_cmp(a.as_pointer(), b.as_pointer(),) }) == ({ (*libcc2rs::strong_ordering_less().upgrade().deref()) }) ); return 0; } +impl WeaklyEqualityComparableWith for S { + fn equal(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/operator_traits.rs b/tests/unit/out/refcount/operator_traits.rs index 8aa303c76d..7d3202e71e 100644 --- a/tests/unit/out/refcount/operator_traits.rs +++ b/tests/unit/out/refcount/operator_traits.rs @@ -29,14 +29,8 @@ impl Lt { } } impl CppLess for Lt { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Lt::operator_lt(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Lt { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - !(Lt::operator_lt(__lhs.clone(), __rhs.clone())) - && !(Lt::operator_lt(__rhs.clone(), __lhs.clone())) + fn less(this: Ptr, o: Ptr) -> bool { + Lt::operator_lt(this.clone(), o.clone()) } } #[derive( @@ -56,16 +50,6 @@ pub struct Eq { #[offset(0)] pub v: i32, } -impl Eq { - pub fn operator_eq(this: Ptr, o: Ptr) -> bool { - return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } -} -impl CppEq for Eq { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Eq::operator_eq(__lhs.clone(), __rhs.clone()) - } -} #[derive( Copy, Clone, @@ -87,18 +71,10 @@ impl Cmp { pub fn operator_cmp(this: Ptr, o: Ptr) -> std::cmp::Ordering { return std::cmp::Ord::cmp(&(this.with(|__s| __s.v)), &(o.with(|__s| __s.v))); } - pub fn operator_eq(this: Ptr, o: Ptr) -> bool { - return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); - } } impl CppLess for Cmp { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - Cmp::operator_cmp(__lhs.clone(), __rhs.clone()) == std::cmp::Ordering::Less - } -} -impl CppEq for Cmp { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - Cmp::operator_eq(__lhs.clone(), __rhs.clone()) + fn less(this: Ptr, o: Ptr) -> bool { + Cmp::operator_cmp(this.clone(), o.clone()) == std::cmp::Ordering::Less } } #[derive( @@ -119,21 +95,13 @@ pub struct Free { pub v: i32, } impl CppLess for Free { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_0(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Free { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_1(__lhs.clone(), __rhs.clone()) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_0(a.clone(), b.clone()) } } pub fn operator_lt_0(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } < { b.with(|__s| __s.v) }); } -pub fn operator_eq_1(a: Ptr, b: Ptr) -> bool { - return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); -} #[derive( Copy, Clone, @@ -183,40 +151,54 @@ fn main_0() -> i32 { let nine: Value = Rc::new(RefCell::new(Eq { v: 9 })); assert!( ({ - let mut __tmp_1 = { eqs.decay().begin() }; - let mut __tmp_2 = { eqs.decay().end() }; - let mut __it = (__tmp_1).clone(); - while __it != __tmp_2 && !CppEq::equal(__it.iter_deref(), two.as_pointer().clone()) { - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(eqs.decay().begin())); + let __last: Value> = Rc::new(RefCell::new(eqs.decay().end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) + && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + two.as_pointer().clone(), + ) + { + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() } .iter_deref() .with(|__s| __s.v) == 2) ); - assert!( - { - let mut __tmp_3 = { eqs.decay().begin() }; - let mut __tmp_4 = { eqs.decay().end() }; - let mut __it = (__tmp_3).clone(); - while __it != __tmp_4 && !CppEq::equal(__it.iter_deref(), nine.as_pointer().clone()) { - __it.iter_inc(); + assert!(match ( + Rc::new(RefCell::new({ + let __it: Value> = Rc::new(RefCell::new(eqs.decay().begin())); + let __last: Value> = Rc::new(RefCell::new(eqs.decay().end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) + && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + nine.as_pointer().clone(), + ) + { + __it.borrow_mut().iter_inc(); } - __it - } == eqs.decay().end() - ); + __it.borrow().clone() + })) + .as_pointer(), + Rc::new(RefCell::new(eqs.decay().end())).as_pointer(), + ) { + (__tmp_1, __tmp_2) => { + WeaklyEqualityComparableWith::equal((__tmp_1).clone(), (__tmp_2).clone()) + } + }); let cmps: Value> = Rc::new(RefCell::new(Vec::from([ Cmp { v: 3 }, Cmp { v: 1 }, Cmp { v: 2 }, ]))); { - let mut __tmp_5 = { cmps.decay().begin() }; - let __n = cmps.decay().end().iter_distance(&__tmp_5); + let mut __tmp_3 = { cmps.decay().begin() }; + let __n = cmps.decay().end().iter_distance(&__tmp_3); let mut __order: Vec = (0..__n).collect(); - __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_5.iter_at(__x), &__tmp_5.iter_at(__y))); - reorder(__order, |__i| __tmp_5.iter_at(__i)); + __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_3.iter_at(__x), &__tmp_3.iter_at(__y))); + reorder(__order, |__i| __tmp_3.iter_at(__i)); }; assert!( ({ { (*cmps.borrow())[0_usize] }.v } == 1) && ({ { (*cmps.borrow())[2_usize] }.v } == 3) @@ -224,13 +206,19 @@ fn main_0() -> i32 { let three: Value = Rc::new(RefCell::new(Cmp { v: 3 })); assert!( ({ - let mut __tmp_6 = { cmps.decay().begin() }; - let mut __tmp_7 = { cmps.decay().end() }; - let mut __it = (__tmp_6).clone(); - while __it != __tmp_7 && !CppEq::equal(__it.iter_deref(), three.as_pointer().clone()) { - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(cmps.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(cmps.decay().end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) + && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + three.as_pointer().clone(), + ) + { + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() } .iter_deref() .with(|__s| __s.v) @@ -238,23 +226,29 @@ fn main_0() -> i32 { ); let frees: Value> = Rc::new(RefCell::new(Vec::from([Free { v: 2 }, Free { v: 1 }]))); { - let mut __tmp_8 = { frees.decay().begin() }; - let __n = frees.decay().end().iter_distance(&__tmp_8); + let mut __tmp_4 = { frees.decay().begin() }; + let __n = frees.decay().end().iter_distance(&__tmp_4); let mut __order: Vec = (0..__n).collect(); - __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_8.iter_at(__x), &__tmp_8.iter_at(__y))); - reorder(__order, |__i| __tmp_8.iter_at(__i)); + __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_4.iter_at(__x), &__tmp_4.iter_at(__y))); + reorder(__order, |__i| __tmp_4.iter_at(__i)); }; assert!(({ { (*frees.borrow())[0_usize] }.v } == 1)); let ftwo: Value = Rc::new(RefCell::new(Free { v: 2 })); assert!( ({ - let mut __tmp_9 = { frees.decay().begin() }; - let mut __tmp_10 = { frees.decay().end() }; - let mut __it = (__tmp_9).clone(); - while __it != __tmp_10 && !CppEq::equal(__it.iter_deref(), ftwo.as_pointer().clone()) { - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(frees.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(frees.decay().end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) + && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + ftwo.as_pointer().clone(), + ) + { + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() } .iter_deref() .with(|__s| __s.v) @@ -262,14 +256,14 @@ fn main_0() -> i32 { ); let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); match (Rc::new(RefCell::new(Lt { v: 2 })).as_pointer(),) { - (__tmp_11,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_11, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_5,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_5, |__k| cpp_move!(__k), || 0_i32) }) } } .write(20); match (Rc::new(RefCell::new(Lt { v: 1 })).as_pointer(),) { - (__tmp_12,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_12, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_6,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_6, |__k| cpp_move!(__k), || 0_i32) }) } } .write(10); @@ -286,8 +280,8 @@ fn main_0() -> i32 { ); assert!( ((match (Rc::new(RefCell::new(Lt { v: 2 })).as_pointer(),) { - (__tmp_13,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_13, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_7,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_7, |__k| cpp_move!(__k), || 0_i32) }) } } .read()) @@ -295,4 +289,19 @@ fn main_0() -> i32 { ); return 0; } +impl WeaklyEqualityComparableWith for Cmp { + fn equal(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } +} +impl WeaklyEqualityComparableWith for Eq { + fn equal(this: Ptr, o: Ptr) -> bool { + return ({ this.with(|__s| __s.v) } == { o.with(|__s| __s.v) }); + } +} +impl WeaklyEqualityComparableWith for Free { + fn equal(a: Ptr, b: Ptr) -> bool { + return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); + } +} pub fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/refcount/push_emplace_back.rs b/tests/unit/out/refcount/push_emplace_back.rs index c049702916..d100808c4b 100644 --- a/tests/unit/out/refcount/push_emplace_back.rs +++ b/tests/unit/out/refcount/push_emplace_back.rs @@ -86,12 +86,12 @@ pub fn push_local_from_field_1(mut jpg: Ptr, mut cond: bool) { dest = (field_ref!(jpg, app_data).as_pointer()); } match (Rc::new(RefCell::new({ - let mut __tmp_2 = { head.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = head.decay(); - while __it != __tmp_2 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(head.decay())); + let __last: Value> = Rc::new(RefCell::new(head.decay().offset((3) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v })) @@ -117,12 +117,13 @@ pub fn emplace_local_from_field_4(mut jpg: Ptr, mut cond: bool) { { dest.with_mut(|__v: &mut Vec>| { __v.push({ - let mut __tmp_3 = { head.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = head.decay(); - while __it != __tmp_3 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(head.decay())); + let __last: Value> = + Rc::new(RefCell::new(head.decay().offset((3) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v }) @@ -131,9 +132,9 @@ pub fn emplace_local_from_field_4(mut jpg: Ptr, mut cond: bool) { } pub fn nested_emplace_move_5(mut bw: Ptr) { { - let mut __tmp_4 = { bw.with(|__s| __s.output.clone()) }; - let mut __tmp_5 = { bw.with(|__s| __s.chunk) }; - __tmp_4.with_mut(|__v: &mut Vec| __v.push(__tmp_5)); + let mut __tmp_2 = { bw.with(|__s| __s.output.clone()) }; + let mut __tmp_3 = { bw.with(|__s| __s.chunk) }; + __tmp_2.with_mut(|__v: &mut Vec| __v.push(__tmp_3)); }; } pub fn self_ref_push_6(mut comps: Ptr>) { @@ -188,36 +189,36 @@ pub fn emplace_ctor_args_7(mut pairs: Ptr>) { }); }; { - let mut __tmp_6 = { + let mut __tmp_4 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Pair::construct_1(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_6)); + pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_4)); }; { - let mut __tmp_7 = { + let mut __tmp_5 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Pair::construct_2(__v.as_pointer(), 4, 5); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_7)); + pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_5)); }; } pub fn emplace_deque_8(mut queue: Ptr>) { { - let mut __tmp_8 = { + let mut __tmp_6 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Pair::construct_2(__v.as_pointer(), 6, 7); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - queue.with_mut(|__v: &mut Vec| __v.push(__tmp_8)); + queue.with_mut(|__v: &mut Vec| __v.push(__tmp_6)); }; { queue.with_mut(|__v: &mut Vec| { @@ -240,7 +241,7 @@ pub fn emplace_scalar_9(mut values: Ptr>, x: i32) { } pub fn emplace_ref_through_ptr_10(mut pairs: Ptr>) { let p: Ptr = { - let mut __tmp_9 = { + let mut __tmp_7 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Pair::construct_2(__v.as_pointer(), 1, 2); @@ -248,7 +249,7 @@ pub fn emplace_ref_through_ptr_10(mut pairs: Ptr>) { } }; pairs.with_mut(|__b0| { - (*__b0).push(__tmp_9); + (*__b0).push(__tmp_7); let __n = (*__b0).len() - 1; pairs.decay().offset((__n) as isize) }) @@ -257,7 +258,7 @@ pub fn emplace_ref_through_ptr_10(mut pairs: Ptr>) { { field!( { - let mut __tmp_10 = { + let mut __tmp_8 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Pair::construct_1(__v.as_pointer(), 4); @@ -265,7 +266,7 @@ pub fn emplace_ref_through_ptr_10(mut pairs: Ptr>) { } }; pairs.with_mut(|__b0| { - (*__b0).push(__tmp_10); + (*__b0).push(__tmp_8); let __n = (*__b0).len() - 1; pairs.decay().offset((__n) as isize) }) @@ -284,15 +285,15 @@ pub fn emplace_addr_11(values: Ptr>) -> Ptr { } pub fn emplace_self_reads_12(mut values: Ptr>, mut pairs: Ptr>) { { - let mut __tmp_11 = { (((*values.upgrade().deref()).len()) as i64) }; - values.with_mut(|__v: &mut Vec| __v.push(__tmp_11)); + let mut __tmp_9 = { (((*values.upgrade().deref()).len()) as i64) }; + values.with_mut(|__v: &mut Vec| __v.push(__tmp_9)); }; { - let mut __tmp_12 = { index!(pairs, 0_usize).read() }; - pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_12)); + let mut __tmp_10 = { index!(pairs, 0_usize).read() }; + pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_10)); }; { - let mut __tmp_13 = { + let mut __tmp_11 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Pair::construct_2( @@ -313,14 +314,14 @@ pub fn emplace_self_reads_12(mut values: Ptr>, mut pairs: Ptr Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_13)); + pairs.with_mut(|__v: &mut Vec| __v.push(__tmp_11)); }; } pub fn emplace_ref_self_read_13(values: Ptr>) -> Ptr { return { - let mut __tmp_14 = { (values.decay().read()) }; + let mut __tmp_12 = { (values.decay().read()) }; values.with_mut(|__b0| { - (*__b0).push(__tmp_14); + (*__b0).push(__tmp_12); let __n = (*__b0).len() - 1; values.decay().offset((__n) as isize) }) @@ -368,19 +369,20 @@ impl Default for Bytes { pub fn emplace_from_element_14(mut v: Ptr>>) { let p: Value> = Rc::new(RefCell::new((v).decay().offset(0_usize).decay())); { - let mut __tmp_16 = { + let mut __tmp_13 = { { - let mut __tmp_15 = { (*p.borrow()).offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = ({ (*p.borrow()).clone() }); - while __it != __tmp_15 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(({ (*p.borrow()).clone() }))); + let __last: Value> = + Rc::new(RefCell::new((*p.borrow()).offset((3) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v } }; - v.with_mut(|__v: &mut Vec>| __v.push(__tmp_16)); + v.with_mut(|__v: &mut Vec>| __v.push(__tmp_13)); }; } #[derive( @@ -455,33 +457,34 @@ impl Counted { impl Counted {} pub fn emplace_counted_17(mut v: Ptr>) { { - let mut __tmp_17 = { + let mut __tmp_14 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Counted::construct(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - v.with_mut(|__v: &mut Vec| __v.push(__tmp_17)); + v.with_mut(|__v: &mut Vec| __v.push(__tmp_14)); }; } pub fn emplace_from_sibling_18(mut s: Ptr) { let p: Value> = Rc::new(RefCell::new(array_field_ptr!(s, b))); let mut v: Ptr>> = (field_ref!(s, v).as_pointer()); { - let mut __tmp_19 = { + let mut __tmp_15 = { { - let mut __tmp_18 = { (*p.borrow()).offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = ({ (*p.borrow()).clone() }); - while __it != __tmp_18 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(({ (*p.borrow()).clone() }))); + let __last: Value> = + Rc::new(RefCell::new((*p.borrow()).offset((3) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v } }; - v.with_mut(|__v: &mut Vec>| __v.push(__tmp_19)); + v.with_mut(|__v: &mut Vec>| __v.push(__tmp_15)); }; } pub fn main() { @@ -638,14 +641,14 @@ fn main_0() -> i32 { let self_values: Value> = Rc::new(RefCell::new(Vec::from([7_i64]))); let self_pairs: Value> = Rc::new(RefCell::new(Vec::new())); { - let mut __tmp_20 = { + let mut __tmp_16 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); Pair::construct_2(__v.as_pointer(), 1, 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - (*self_pairs.borrow_mut()).push(__tmp_20); + (*self_pairs.borrow_mut()).push(__tmp_16); }; ({ emplace_self_reads_12((self_values.as_pointer()), (self_pairs.as_pointer())) }); { diff --git a/tests/unit/out/refcount/size_t_ssize_t.rs b/tests/unit/out/refcount/size_t_ssize_t.rs index 28168bbd87..65ec82e18c 100644 --- a/tests/unit/out/refcount/size_t_ssize_t.rs +++ b/tests/unit/out/refcount/size_t_ssize_t.rs @@ -33,14 +33,14 @@ pub fn size_t_in_rules_3() { (0..3).map(|_| 0_usize).collect::>(), )); { - let mut __tmp_0 = { src.decay().offset((3) as isize) }; - let mut __first = src.decay(); + let __first: Value> = Rc::new(RefCell::new(src.decay())); + let __last: Value> = Rc::new(RefCell::new(src.decay().offset((3) as isize))); let mut __out = (dst.decay()).reinterpret_cast::(); - while __first != __tmp_0 { + while >::not_equal(__first.as_pointer(), __last.as_pointer()) { __out .iter_deref() - .write(((__first.iter_deref().read()) as u64)); - __first.iter_inc(); + .write(((__first.borrow().iter_deref().read()) as u64)); + __first.borrow_mut().iter_inc(); __out.iter_inc(); } __out @@ -80,27 +80,39 @@ pub fn size_t_in_rules_3() { assert!((mx > mn)); let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); match (Rc::new(RefCell::new(1_u64)).as_pointer(),) { - (__tmp_1,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_1, |__k| cpp_move!(__k), || 0_u64) }) + (__tmp_0,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_0, |__k| cpp_move!(__k), || 0_u64) }) } } .write(2_u64); let key: Value = Rc::new(RefCell::new(3_usize)); match ((key.as_pointer()).reinterpret_cast::(),) { - (__tmp_2,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_2, |__k| cpp_move!(__k), || 0_u64) }) + (__tmp_1,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_1, |__k| cpp_move!(__k), || 0_u64) }) } } .write(4_u64); - assert!( - ({ - let __tmp_3: Value = Rc::new(RefCell::new(1_u64)); + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_3: Value = Rc::new(RefCell::new(1_u64)); + m.as_pointer() + .with(|__m: &Map, Value)>| { + __m.find(&__tmp_3.as_pointer()) + }) + }) + )) + .as_pointer(), + Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.find(&__tmp_3.as_pointer())) - }) != m - .as_pointer() - .with(|__m: &Map, Value)>| __m.end()) - ); + .with(|__m: &Map, Value)>| __m.end()) + )) + .as_pointer(), + ) { + (__tmp_2, __tmp_4) => { + WeaklyEqualityComparableWith::not_equal((__tmp_2).clone(), (__tmp_4).clone()) + } + }); assert!( ((*(*m .as_pointer() @@ -129,12 +141,12 @@ pub fn size_t_in_rules_3() { ))) .as_pointer(),) { - (__tmp_4,) => ( + (__tmp_5,) => ( Rc::new(RefCell::new( - (((*__tmp_4.upgrade().deref()).0.as_pointer().read()) as u64), + (((*__tmp_5.upgrade().deref()).0.as_pointer().read()) as u64), )), Rc::new(RefCell::new( - (((*__tmp_4.upgrade().deref()).1.as_pointer().read()) as u64), + (((*__tmp_5.upgrade().deref()).1.as_pointer().read()) as u64), )), ), }, @@ -163,9 +175,9 @@ pub fn size_t_in_rules_3() { ))) .as_pointer(),) { - (__tmp_5,) => { - let __first = (((*__tmp_5.upgrade().deref()).0.as_pointer().read()) as u64); - let __second = (((*__tmp_5.upgrade().deref()).1.as_pointer().read()) as u64); + (__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; } @@ -191,18 +203,18 @@ pub fn size_t_in_rules_3() { let v: Value> = Rc::new(RefCell::new(Vec::from_fn(3_usize, |_| 0_u64))); (*v.borrow_mut()).resize_with(5_usize, || 0_u64); { - let mut __tmp_6 = { >::from(v.decay().begin()) }; + let mut __tmp_7 = { >::from(v.decay().begin()) }; v.as_pointer() - .with_mut(|__v: &mut Vec| __v.remove(__tmp_6.index())); - (__tmp_6).clone() + .with_mut(|__v: &mut Vec| __v.remove(__tmp_7.index())); + (__tmp_7).clone() }; let mut v2: Vec = { - let mut __tmp_7 = { src.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = src.decay(); - while __it != __tmp_7 { - __v.push(((__it.iter_deref().read()) as u64)); - __it.iter_inc(); + 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)); + __it.borrow_mut().iter_inc(); } __v }; @@ -216,13 +228,13 @@ pub fn size_t_in_rules_3() { (*v.borrow_mut()).push(((*k.borrow()) as u64)); }; { - let mut __tmp_9 = { v.decay().begin() }; - let mut __tmp_10 = { v.decay().end() }; - let mut __it = (__tmp_9).clone(); - while __it != __tmp_10 { - __it.iter_deref() + let __it: Value> = Rc::new(RefCell::new(v.decay().begin())); + let __last: Value> = Rc::new(RefCell::new(v.decay().end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __it.borrow() + .iter_deref() .write(Clone::clone(&({ ((*k.borrow()) as u64) }))); - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } }; Swappable::swap( @@ -230,13 +242,13 @@ pub fn size_t_in_rules_3() { (k.as_pointer()).reinterpret_cast::(), ); let mut big: usize = (({ - let __tmp_12: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); + let __tmp_10: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); (match (v.decay().offset(1_usize),) { - (__tmp_11,) => { - if CppLess::less((__tmp_11).clone().clone(), __tmp_12.as_pointer().clone()) { - __tmp_12.as_pointer() + (__tmp_9,) => { + if CppLess::less((__tmp_9).clone().clone(), __tmp_10.as_pointer().clone()) { + __tmp_10.as_pointer() } else { - (__tmp_11).clone() + (__tmp_9).clone() } } } @@ -252,14 +264,14 @@ pub fn size_t_in_rules_3() { .read()) as usize) }; { - let mut __tmp_13 = { + let mut __tmp_11 = { ( Rc::new(RefCell::new(({ ((*k.borrow()) as u64) }))), Rc::new(RefCell::new(({ ((*k.borrow()) as u64) }))), ) }; let (__it, __inserted) = - Map::emplace(m2.as_pointer(), &__tmp_13.0.as_pointer(), || __tmp_13); + Map::emplace(m2.as_pointer(), &__tmp_11.0.as_pointer(), || __tmp_11); ( Rc::new(RefCell::new(__it)), Rc::new(RefCell::new(__inserted)), @@ -267,9 +279,9 @@ pub fn size_t_in_rules_3() { }; assert!( (((*(*({ - let __tmp_14: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); + let __tmp_12: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); m2.as_pointer() - .with(|__m: &Map, Value)>| __m.find(&__tmp_14.as_pointer())) + .with(|__m: &Map, Value)>| __m.find(&__tmp_12.as_pointer())) }) .iter_deref() .upgrade() @@ -279,13 +291,13 @@ pub fn size_t_in_rules_3() { == (*k.borrow())) ); { - let __tmp_15: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); - ({ (*m2.borrow_mut()).subscript(__tmp_15.as_pointer(), || 0_u64) }) + let __tmp_13: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); + ({ (*m2.borrow_mut()).subscript(__tmp_13.as_pointer(), || 0_u64) }) } .write((big as u64)); let mv: Ptr = ({ - let __tmp_16: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); - ({ (*m2.borrow_mut()).subscript(__tmp_16.as_pointer(), || 0_u64) }) + let __tmp_14: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); + ({ (*m2.borrow_mut()).subscript(__tmp_14.as_pointer(), || 0_u64) }) }) .reinterpret_cast::(); mv.write(1_usize); @@ -303,34 +315,47 @@ pub fn size_t_in_rules_3() { ((*k.borrow()) as u64), ]))); ({ - let __tmp_18: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); + let __tmp_16: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); { - let mut __tmp_17 = { >::from(v3.decay().begin()) }; - let __a2 = copy_constructed(__tmp_18.as_pointer()); - (*v3.borrow_mut()).insert(__tmp_17.index(), __a2); - (__tmp_17).clone() + let mut __tmp_15 = { >::from(v3.decay().begin()) }; + let __a2 = copy_constructed(__tmp_16.as_pointer()); + (*v3.borrow_mut()).insert(__tmp_15.index(), __a2); + (__tmp_15).clone() } }); ({ - let __tmp_19: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); - (*v3.borrow_mut()).resize_with(5_usize, || copy_constructed(__tmp_19.as_pointer().clone())) + let __tmp_17: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); + (*v3.borrow_mut()).resize_with(5_usize, || copy_constructed(__tmp_17.as_pointer().clone())) }); - assert!( - ({ - let __tmp_22: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); - { - let mut __tmp_20 = { v3.decay().begin() }; - let mut __tmp_21 = { v3.decay().end() }; - let mut __it = (__tmp_20).clone(); - while __it != __tmp_21 - && !CppEq::equal(__it.iter_deref(), __tmp_22.as_pointer().clone()) + assert!(match ( + Rc::new(RefCell::new( + ({ + let __tmp_19: Value = Rc::new(RefCell::new(((*k.borrow()) as u64))); { - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(v3.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(v3.decay().end())); + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + __tmp_19.as_pointer().clone(), + ) { + __it.borrow_mut().iter_inc(); + } + __it.borrow().clone() } - __it - } - }) != v3.decay().end() - ); + }) + )) + .as_pointer(), + Rc::new(RefCell::new(v3.decay().end())).as_pointer(), + ) { + (__tmp_18, __tmp_20) => { + WeaklyEqualityComparableWith::not_equal((__tmp_18).clone(), (__tmp_20).clone()) + } + }); assert!( ({ (((*v3.borrow()).len() == 5_usize) && (big >= (*k.borrow()))) @@ -385,37 +410,37 @@ fn main_0() -> i32 { let mut fr2: u64 = ({ take_ulong_1((sz as u64)) }); assert!((fr2 == 21_u64)); let mut lo: usize = (({ - let __tmp_23: Value = Rc::new(RefCell::new( + let __tmp_21: Value = Rc::new(RefCell::new( (::std::mem::size_of::() as u64).wrapping_add((*ul.borrow())), )); - let __tmp_24: Value = Rc::new(RefCell::new((sz as u64))); - (if CppLess::less(__tmp_23.as_pointer().clone(), __tmp_24.as_pointer().clone()) { - __tmp_23.as_pointer() + let __tmp_22: Value = Rc::new(RefCell::new((sz as u64))); + (if CppLess::less(__tmp_21.as_pointer().clone(), __tmp_22.as_pointer().clone()) { + __tmp_21.as_pointer() } else { - __tmp_24.as_pointer() + __tmp_22.as_pointer() } .read()) }) as usize); let mut hi: usize = (({ - let __tmp_25: Value = Rc::new(RefCell::new( + let __tmp_23: Value = Rc::new(RefCell::new( (::std::mem::size_of::() as u64).wrapping_add((sz as u64)), )); - (if CppLess::less(__tmp_25.as_pointer().clone(), ul.as_pointer().clone()) { + (if CppLess::less(__tmp_23.as_pointer().clone(), ul.as_pointer().clone()) { ul.as_pointer() } else { - __tmp_25.as_pointer() + __tmp_23.as_pointer() } .read()) }) as usize); assert!((lo == (::std::mem::size_of::() as usize).wrapping_add(10_usize))); assert!((hi == (::std::mem::size_of::() as usize).wrapping_add(21_usize))); let mut bound: usize = (({ - let __tmp_26: Value = Rc::new(RefCell::new((4_usize as u64))); - let __tmp_27: Value = Rc::new(RefCell::new((sz as u64))); - (if CppLess::less(__tmp_26.as_pointer().clone(), __tmp_27.as_pointer().clone()) { - __tmp_26.as_pointer() + let __tmp_24: Value = Rc::new(RefCell::new((4_usize as u64))); + let __tmp_25: Value = Rc::new(RefCell::new((sz as u64))); + (if CppLess::less(__tmp_24.as_pointer().clone(), __tmp_25.as_pointer().clone()) { + __tmp_24.as_pointer() } else { - __tmp_27.as_pointer() + __tmp_25.as_pointer() } .read()) }) as usize); @@ -466,22 +491,22 @@ fn main_0() -> i32 { assert!((sm == 15_isize)); assert!((sm > (l as isize))); let mut smin: isize = (({ - let __tmp_28: Value = Rc::new(RefCell::new((sm as i64))); - let __tmp_29: Value = Rc::new(RefCell::new((sd as i64))); - (if CppLess::less(__tmp_28.as_pointer().clone(), __tmp_29.as_pointer().clone()) { - __tmp_28.as_pointer() + let __tmp_26: Value = Rc::new(RefCell::new((sm as i64))); + let __tmp_27: Value = Rc::new(RefCell::new((sd as i64))); + (if CppLess::less(__tmp_26.as_pointer().clone(), __tmp_27.as_pointer().clone()) { + __tmp_26.as_pointer() } else { - __tmp_29.as_pointer() + __tmp_27.as_pointer() } .read()) }) as isize); let mut smax: isize = (({ - let __tmp_30: Value = Rc::new(RefCell::new((sd as i64))); - let __tmp_31: Value = Rc::new(RefCell::new((sm as i64))); - (if CppLess::less(__tmp_30.as_pointer().clone(), __tmp_31.as_pointer().clone()) { - __tmp_31.as_pointer() + let __tmp_28: Value = Rc::new(RefCell::new((sd as i64))); + let __tmp_29: Value = Rc::new(RefCell::new((sm as i64))); + (if CppLess::less(__tmp_28.as_pointer().clone(), __tmp_29.as_pointer().clone()) { + __tmp_29.as_pointer() } else { - __tmp_30.as_pointer() + __tmp_28.as_pointer() } .read()) }) as isize); @@ -503,22 +528,22 @@ fn main_0() -> i32 { let mut mins: [usize; 4] = [ 0_usize, (({ - let __tmp_32: Value = Rc::new(RefCell::new((mx as u64))); - let __tmp_33: Value = Rc::new(RefCell::new(1_u64)); - (if CppLess::less(__tmp_32.as_pointer().clone(), __tmp_33.as_pointer().clone()) { - __tmp_32.as_pointer() + let __tmp_30: Value = Rc::new(RefCell::new((mx as u64))); + let __tmp_31: Value = Rc::new(RefCell::new(1_u64)); + (if CppLess::less(__tmp_30.as_pointer().clone(), __tmp_31.as_pointer().clone()) { + __tmp_30.as_pointer() } else { - __tmp_33.as_pointer() + __tmp_31.as_pointer() } .read()) }) as usize), (({ - let __tmp_34: Value = Rc::new(RefCell::new(((mx).wrapping_sub(3_usize) as u64))); - let __tmp_35: Value = Rc::new(RefCell::new((mx as u64))); - (if CppLess::less(__tmp_34.as_pointer().clone(), __tmp_35.as_pointer().clone()) { - __tmp_34.as_pointer() + let __tmp_32: Value = Rc::new(RefCell::new(((mx).wrapping_sub(3_usize) as u64))); + let __tmp_33: Value = Rc::new(RefCell::new((mx as u64))); + (if CppLess::less(__tmp_32.as_pointer().clone(), __tmp_33.as_pointer().clone()) { + __tmp_32.as_pointer() } else { - __tmp_35.as_pointer() + __tmp_33.as_pointer() } .read()) }) as usize), diff --git a/tests/unit/out/refcount/sort_no_copy.rs b/tests/unit/out/refcount/sort_no_copy.rs index 27aee2afb1..0fc9872366 100644 --- a/tests/unit/out/refcount/sort_no_copy.rs +++ b/tests/unit/out/refcount/sort_no_copy.rs @@ -51,14 +51,8 @@ impl MoveAssignable for Tracked { } } impl CppLess for Tracked { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_1(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Tracked { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - !(operator_lt_1(__lhs.clone(), __rhs.clone())) - && !(operator_lt_1(__rhs.clone(), __lhs.clone())) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_1(a.clone(), b.clone()) } } impl Default for Tracked { @@ -102,14 +96,8 @@ impl MoveOnly { } } impl CppLess for MoveOnly { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_3(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for MoveOnly { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - !(operator_lt_3(__lhs.clone(), __rhs.clone())) - && !(operator_lt_3(__rhs.clone(), __lhs.clone())) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_3(a.clone(), b.clone()) } } pub fn operator_lt_3(a: Ptr, b: Ptr) -> bool { @@ -131,21 +119,13 @@ impl DefaultConstructible for Bag { } } impl CppLess for Bag { - fn less(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_lt_4(__lhs.clone(), __rhs.clone()) - } -} -impl CppEq for Bag { - fn equal(__lhs: Ptr, __rhs: Ptr) -> bool { - operator_eq_5(__lhs.clone(), __rhs.clone()) + fn less(a: Ptr, b: Ptr) -> bool { + operator_lt_4(a.clone(), b.clone()) } } pub fn operator_lt_4(a: Ptr, b: Ptr) -> bool { return ({ (*a.upgrade().deref()).items.len() } < { (*b.upgrade().deref()).items.len() }); } -pub fn operator_eq_5(a: Ptr, b: Ptr) -> bool { - return ({ (*a.upgrade().deref()).items.len() } == { (*b.upgrade().deref()).items.len() }); -} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); @@ -441,37 +421,55 @@ fn main_0() -> i32 { }) ); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); - assert!( - { - let mut __tmp_20 = { bag_vec.decay().begin() }; - let mut __tmp_21 = { bag_vec.decay().end() }; - let mut __it = (__tmp_20).clone(); - while __it != __tmp_21 - && !CppEq::equal(__it.iter_deref(), bags.decay().offset(1).clone()) + assert!(match ( + Rc::new(RefCell::new({ + let __it: Value> = + Rc::new(RefCell::new(bag_vec.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(bag_vec.decay().end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) + && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + bags.decay().offset(1).clone(), + ) { - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } - __it - } == bag_vec.decay().begin().iter_add(1_isize) - ); - assert!( - { - let mut __tmp_22 = { bag_vec.decay().begin() }; - let mut __tmp_23 = { bag_vec.decay().end() }; - let mut __best = __tmp_22.clone(); - if __tmp_22 != __tmp_23 { - let mut __it = (__tmp_22).clone(); - __it.iter_inc(); - while __it != __tmp_23 { - if CppLess::less(__best.iter_deref(), __it.iter_deref()) { - __best = __it.clone(); + __it.borrow().clone() + })) + .as_pointer(), + Rc::new(RefCell::new(bag_vec.decay().begin().iter_add(1_isize))).as_pointer(), + ) { + (__tmp_20, __tmp_21) => { + WeaklyEqualityComparableWith::equal((__tmp_20).clone(), (__tmp_21).clone()) + } + }); + assert!(match ( + Rc::new(RefCell::new({ + let __it: Value> = + Rc::new(RefCell::new(bag_vec.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(bag_vec.decay().end())); + 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()) + { + if CppLess::less(__best.iter_deref(), __it.borrow().iter_deref()) { + __best = __it.borrow().clone(); } - __it.iter_inc(); + __it.borrow_mut().iter_inc(); } } __best - } == bag_vec.decay().begin().iter_add(2_isize) - ); + })) + .as_pointer(), + Rc::new(RefCell::new(bag_vec.decay().begin().iter_add(2_isize))).as_pointer(), + ) { + (__tmp_22, __tmp_23) => { + WeaklyEqualityComparableWith::equal((__tmp_22).clone(), (__tmp_23).clone()) + } + }); assert!( ((if CppLess::less( bags.decay().offset(2).clone(), @@ -517,64 +515,72 @@ fn main_0() -> i32 { .borrow()) == 2) ); - assert!( - bag_map - .as_pointer() - .with(|__m: &Map, Value)>| __m.find(&bags.decay().offset(1))) - == bag_map + assert!(match ( + Rc::new(RefCell::new(bag_map.as_pointer().with( + |__m: &Map, Value)>| __m.find(&bags.decay().offset(1)) + ))) + .as_pointer(), + Rc::new(RefCell::new( + bag_map .as_pointer() .with(|__m: &Map, Value)>| __m.end()) - ); + )) + .as_pointer(), + ) { + (__tmp_26, __tmp_27) => { + WeaklyEqualityComparableWith::equal((__tmp_26).clone(), (__tmp_27).clone()) + } + }); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); let moves: Value> = Rc::new(RefCell::new(Vec::new())); { - let mut __tmp_26 = { + let mut __tmp_28 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); MoveOnly::construct(__v.as_pointer(), 3); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - (*moves.borrow_mut()).push(__tmp_26); + (*moves.borrow_mut()).push(__tmp_28); }; { - let mut __tmp_27 = { + let mut __tmp_29 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); MoveOnly::construct(__v.as_pointer(), 1); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - (*moves.borrow_mut()).push(__tmp_27); + (*moves.borrow_mut()).push(__tmp_29); }; { - let mut __tmp_28 = { + let mut __tmp_30 = { { let __v: Value = Rc::new(RefCell::new(::zero_init())); MoveOnly::construct(__v.as_pointer(), 2); Rc::try_unwrap(__v).ok().unwrap().into_inner() } }; - (*moves.borrow_mut()).push(__tmp_28); + (*moves.borrow_mut()).push(__tmp_30); }; { - let mut __tmp_29 = { moves.decay().begin() }; - let __n = moves.decay().end().iter_distance(&__tmp_29); + let mut __tmp_31 = { moves.decay().begin() }; + let __n = moves.decay().end().iter_distance(&__tmp_31); let mut __order: Vec = (0..__n).collect(); - __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_29.iter_at(__x), &__tmp_29.iter_at(__y))); - reorder(__order, |__i| __tmp_29.iter_at(__i)); + __order.sort_by(|&__x, &__y| cpp_cmp(&__tmp_31.iter_at(__x), &__tmp_31.iter_at(__y))); + reorder(__order, |__i| __tmp_31.iter_at(__i)); }; assert!( (({ (*moves.borrow())[0_usize].v } == 1) && ({ (*moves.borrow())[1_usize].v } == 2)) && ({ (*moves.borrow())[2_usize].v } == 3) ); { - let mut __tmp_30 = { moves.decay().begin() }; - let __n = moves.decay().end().iter_distance(&__tmp_30); + let mut __tmp_32 = { moves.decay().begin() }; + let __n = moves.decay().end().iter_distance(&__tmp_32); let mut __order: Vec = (0..__n).collect(); __order.sort_by(|&__x, &__y| { - let __a = __tmp_30.iter_at(__x); - let __b = __tmp_30.iter_at(__y); + let __a = __tmp_32.iter_at(__x); + let __b = __tmp_32.iter_at(__y); if FnPtr::, Ptr) -> bool>::new( |a: Ptr, b: Ptr| -> bool { { @@ -599,7 +605,7 @@ fn main_0() -> i32 { std::cmp::Ordering::Equal } }); - reorder(__order, |__i| __tmp_30.iter_at(__i)); + reorder(__order, |__i| __tmp_32.iter_at(__i)); }; assert!( (({ (*moves.borrow())[0_usize].v } == 3) && ({ (*moves.borrow())[1_usize].v } == 2)) @@ -607,6 +613,11 @@ fn main_0() -> i32 { ); return copies_0.with(|rc| *rc.borrow()); } +impl WeaklyEqualityComparableWith for Bag { + fn equal(a: Ptr, b: Ptr) -> bool { + return ({ (*a.upgrade().deref()).items.len() } == { (*b.upgrade().deref()).items.len() }); + } +} pub fn __cpp2rust_init_globals() { let _ = copies_0.with(|_| ()); } diff --git a/tests/unit/out/refcount/stdcopy.rs b/tests/unit/out/refcount/stdcopy.rs index 45fdbba656..d27bbf3f5e 100644 --- a/tests/unit/out/refcount/stdcopy.rs +++ b/tests/unit/out/refcount/stdcopy.rs @@ -39,12 +39,14 @@ fn main_0() -> i32 { let output: Value> = Rc::new(RefCell::new((0..3).map(|_| 0_i32).collect::>())); { - let mut __tmp_0 = { input.decay().offset((3) as isize) }; - let mut __first = input.decay(); + let __first: Value> = Rc::new(RefCell::new(input.decay())); + let __last: Value> = Rc::new(RefCell::new(input.decay().offset((3) as isize))); let mut __out = output.decay(); - while __first != __tmp_0 { - __out.iter_deref().write((__first.iter_deref().read())); - __first.iter_inc(); + while >::not_equal(__first.as_pointer(), __last.as_pointer()) { + __out + .iter_deref() + .write((__first.borrow().iter_deref().read())); + __first.borrow_mut().iter_inc(); __out.iter_inc(); } __out @@ -55,14 +57,14 @@ fn main_0() -> i32 { .collect(), )); { - let mut __tmp_1 = { input.decay().offset((3) as isize) }; - let mut __first = input.decay(); + let __first: Value> = Rc::new(RefCell::new(input.decay())); + let __last: Value> = Rc::new(RefCell::new(input.decay().offset((3) as isize))); let mut __out = widened.decay().begin(); - while __first != __tmp_1 { + while >::not_equal(__first.as_pointer(), __last.as_pointer()) { __out .iter_deref() - .write(((__first.iter_deref().read()) as i64)); - __first.iter_inc(); + .write(((__first.borrow().iter_deref().read()) as i64)); + __first.borrow_mut().iter_inc(); __out.iter_inc(); } __out @@ -71,26 +73,28 @@ fn main_0() -> i32 { ({ (*widened.borrow())[0_usize] } == 1_i64) && ({ (*widened.borrow())[2_usize] } == 3_i64) ); let constructed: Value> = Rc::new(RefCell::new({ - let __tmp_3: Value = Rc::new(RefCell::new(::zero_init())); + let __tmp_1: Value = Rc::new(RefCell::new(::zero_init())); match ({ - Degrees::construct(__tmp_3.as_pointer(), 0); - __tmp_3.as_pointer() + Degrees::construct(__tmp_1.as_pointer(), 0); + __tmp_1.as_pointer() },) { - (__tmp_2,) => (0..3_usize) - .map(|_| copy_constructed((__tmp_2).clone().clone())) + (__tmp_0,) => (0..3_usize) + .map(|_| copy_constructed((__tmp_0).clone().clone())) .collect(), } })); { - let mut __tmp_4 = { input.decay().offset((3) as isize) }; - let mut __first = input.decay(); + let __first: Value> = Rc::new(RefCell::new(input.decay())); + let __last: Value> = Rc::new(RefCell::new(input.decay().offset((3) as isize))); let mut __out = constructed.decay().begin(); - while __first != __tmp_4 { + while >::not_equal(__first.as_pointer(), __last.as_pointer()) { __out .iter_deref() - .write(>::cpp_from(__first.iter_deref())); - __first.iter_inc(); + .write(>::cpp_from( + __first.borrow().iter_deref(), + )); + __first.borrow_mut().iter_inc(); __out.iter_inc(); } __out @@ -106,14 +110,14 @@ fn main_0() -> i32 { .collect(), )); { - let mut __tmp_5 = { wide.decay().offset((2) as isize) }; - let mut __first = wide.decay(); + let __first: Value> = Rc::new(RefCell::new(wide.decay())); + let __last: Value> = Rc::new(RefCell::new(wide.decay().offset((2) as isize))); let mut __out = floating.decay().begin(); - while __first != __tmp_5 { + while >::not_equal(__first.as_pointer(), __last.as_pointer()) { __out .iter_deref() - .write(((__first.iter_deref().read()) as f64)); - __first.iter_inc(); + .write(((__first.borrow().iter_deref().read()) as f64)); + __first.borrow_mut().iter_inc(); __out.iter_inc(); } __out diff --git a/tests/unit/out/refcount/unboxed_conditional_iterator.rs b/tests/unit/out/refcount/unboxed_conditional_iterator.rs index 2f66920724..393e236257 100644 --- a/tests/unit/out/refcount/unboxed_conditional_iterator.rs +++ b/tests/unit/out/refcount/unboxed_conditional_iterator.rs @@ -55,26 +55,40 @@ pub fn lehmer_3(mut sigma: Ptr, mut len: u32, mut code: Ptr) { 'loop_: while (i < len) { 'for_body: { let it: Value> = Rc::new(RefCell::new({ - let mut __tmp_0 = { items.decay().begin() }; - let mut __tmp_1 = { items.decay().end() }; - let mut __it = (__tmp_0).clone(); - while __it != __tmp_1 - && !CppEq::equal(__it.iter_deref(), sigma.offset((i) as isize).clone()) - { - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(items.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(items.decay().end())); + while >::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) && !WeaklyEqualityComparableWith::equal( + __it.borrow().iter_deref(), + sigma.offset((i) as isize).clone(), + ) { + __it.borrow_mut().iter_inc(); } - __it + __it.borrow().clone() })); - assert!((*it.borrow()) != items.decay().end()); + assert!( + match (Rc::new(RefCell::new(items.decay().end())).as_pointer(),) { + (__tmp_0,) => { + WeaklyEqualityComparableWith::not_equal( + it.as_pointer(), + (__tmp_0).clone(), + ) + } + } + ); let __rhs = (((*it.borrow()).iter_distance(&items.decay().begin())) as u32); elem!(code, i).write(__rhs); { - let mut __tmp_2 = + let mut __tmp_1 = { >::from(({ (*it.borrow()).clone() })) }; items .as_pointer() - .with_mut(|__v: &mut Vec| __v.remove(__tmp_2.index())); - (__tmp_2).clone() + .with_mut(|__v: &mut Vec| __v.remove(__tmp_1.index())); + (__tmp_1).clone() }; } i.prefix_inc(); @@ -85,7 +99,11 @@ pub fn sum_4(v: Ptr>) -> i32 { let mut s: i32 = 0; { let it: Value> = Rc::new(RefCell::new(v.decay().begin())); - 'loop_: while (*it.borrow()) != v.decay().end() { + 'loop_: while match (Rc::new(RefCell::new(v.decay().end())).as_pointer(),) { + (__tmp_2,) => { + WeaklyEqualityComparableWith::not_equal(it.as_pointer(), (__tmp_2).clone()) + } + } { 'for_body: { s += (({ (*it.borrow()).iter_deref() }).read()); } diff --git a/tests/unit/out/refcount/vector.rs b/tests/unit/out/refcount/vector.rs index 47f5e85479..37f11f02c4 100644 --- a/tests/unit/out/refcount/vector.rs +++ b/tests/unit/out/refcount/vector.rs @@ -182,14 +182,13 @@ fn main_0() -> i32 { let src: Value> = Rc::new(RefCell::new(Vec::from([21, 22]))); { let mut __tmp_10 = { >::from(v2.decay().begin()) }; - let mut __tmp_11 = { src.decay().begin() }; - let mut __tmp_12 = { src.decay().end() }; let start_idx = __tmp_10.index(); let mut temp_vec: Vec = Vec::new(); - let mut __it = (__tmp_11).clone(); - while __it != __tmp_12 { - temp_vec.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src.decay().begin())); + let __last: Value> = Rc::new(RefCell::new(src.decay().end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + temp_vec.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } v2.as_pointer().with_mut(|v: &mut Vec| { v.splice(start_idx..start_idx, temp_vec); @@ -201,27 +200,27 @@ fn main_0() -> i32 { assert!(({ (*v2.borrow())[1_usize] } == 22)); assert!(({ (*v2.borrow())[2_usize] } == 100)); { - let mut __tmp_13 = { >::from(v2.decay().begin()) }; + let mut __tmp_11 = { >::from(v2.decay().begin()) }; v2.as_pointer() - .with_mut(|__v: &mut Vec| __v.remove(__tmp_13.index())); - (__tmp_13).clone() + .with_mut(|__v: &mut Vec| __v.remove(__tmp_11.index())); + (__tmp_11).clone() }; { - let mut __tmp_14 = { >::from(v2.decay().begin()) }; + let mut __tmp_12 = { >::from(v2.decay().begin()) }; v2.as_pointer() - .with_mut(|__v: &mut Vec| __v.remove(__tmp_14.index())); - (__tmp_14).clone() + .with_mut(|__v: &mut Vec| __v.remove(__tmp_12.index())); + (__tmp_12).clone() }; { let mut i: i32 = 0; 'loop_: while (i < 4) { 'for_body: { { - let mut __tmp_15 = + let mut __tmp_13 = { >::from(v2.decay().begin().iter_add(1_isize)) }; v2.as_pointer() - .with_mut(|__v: &mut Vec| __v.remove(__tmp_15.index())); - (__tmp_15).clone() + .with_mut(|__v: &mut Vec| __v.remove(__tmp_13.index())); + (__tmp_13).clone() }; } i.prefix_inc(); @@ -436,11 +435,11 @@ fn main_0() -> i32 { assert!( ({ (({ - let mut __tmp_16 = { (idx as usize) }; - if __tmp_16 >= (*v6.borrow()).len() { + let mut __tmp_14 = { (idx as usize) }; + if __tmp_14 >= (*v6.borrow()).len() { panic!("out of bounds access") } - v6.decay().offset((__tmp_16) as isize) + v6.decay().offset((__tmp_14) as isize) } .read()) == 2_f64) @@ -449,22 +448,22 @@ fn main_0() -> i32 { assert!( ({ (({ - let mut __tmp_17 = { (s2).wrapping_sub(1_usize) }; - if __tmp_17 >= (*v6.borrow()).len() { + let mut __tmp_15 = { (s2).wrapping_sub(1_usize) }; + if __tmp_15 >= (*v6.borrow()).len() { panic!("out of bounds access") } - v6.decay().offset((__tmp_17) as isize) + v6.decay().offset((__tmp_15) as isize) } .read()) == 5_f64) }) ); let ref1: Ptr = { - let mut __tmp_18 = { (s2).wrapping_sub(1_usize) }; - if __tmp_18 >= (*v6.borrow()).len() { + let mut __tmp_16 = { (s2).wrapping_sub(1_usize) }; + if __tmp_16 >= (*v6.borrow()).len() { panic!("out of bounds access") } - v6.decay().offset((__tmp_18) as isize) + v6.decay().offset((__tmp_16) as isize) }; { ref1.with_mut(|__v| *__v = *__v + 1.5_f64) @@ -472,22 +471,22 @@ fn main_0() -> i32 { assert!( ({ (({ - let mut __tmp_19 = { (s2).wrapping_sub(1_usize) }; - if __tmp_19 >= (*v6.borrow()).len() { + let mut __tmp_17 = { (s2).wrapping_sub(1_usize) }; + if __tmp_17 >= (*v6.borrow()).len() { panic!("out of bounds access") } - v6.decay().offset((__tmp_19) as isize) + v6.decay().offset((__tmp_17) as isize) } .read()) == 6.5_f64) }) ); let mut x1: f64 = ({ - let mut __tmp_20 = { (s2).wrapping_sub(1_usize) }; - if __tmp_20 >= (*v6.borrow()).len() { + let mut __tmp_18 = { (s2).wrapping_sub(1_usize) }; + if __tmp_18 >= (*v6.borrow()).len() { panic!("out of bounds access") } - v6.decay().offset((__tmp_20) as isize) + v6.decay().offset((__tmp_18) as isize) } .read()); assert!((x1 == 6.5_f64)); @@ -495,11 +494,11 @@ fn main_0() -> i32 { assert!( ({ (({ - let mut __tmp_21 = { (s2).wrapping_sub(1_usize) }; - if __tmp_21 >= (*v6.borrow()).len() { + let mut __tmp_19 = { (s2).wrapping_sub(1_usize) }; + if __tmp_19 >= (*v6.borrow()).len() { panic!("out of bounds access") } - v6.decay().offset((__tmp_21) as isize) + v6.decay().offset((__tmp_19) as isize) } .read()) == 6.5_f64) @@ -522,15 +521,15 @@ fn main_0() -> i32 { let pa: Value> = Rc::new(RefCell::new((a.as_pointer()))); let v8: Value>>> = Rc::new(RefCell::new(Vec::new())); ({ - let __tmp_22: Value>> = Rc::new(RefCell::new((pa.as_pointer()))); - MoveConstructible::push_moved(&v8.as_pointer(), __tmp_22.as_pointer()) + let __tmp_20: Value>> = Rc::new(RefCell::new((pa.as_pointer()))); + MoveConstructible::push_moved(&v8.as_pointer(), __tmp_20.as_pointer()) }); assert!(({ (((*v8.borrow())[0_usize].read()).with(|__s| __s.x) == 1) })); let ppa: Value>> = Rc::new(RefCell::new((pa.as_pointer()))); let v9: Value>>>> = Rc::new(RefCell::new(Vec::new())); ({ - let __tmp_23: Value>>> = Rc::new(RefCell::new((ppa.as_pointer()))); - MoveConstructible::push_moved(&v9.as_pointer(), __tmp_23.as_pointer()) + let __tmp_21: Value>>> = Rc::new(RefCell::new((ppa.as_pointer()))); + MoveConstructible::push_moved(&v9.as_pointer(), __tmp_21.as_pointer()) }); field!((((*v9.borrow())[0_usize].read()).read()), x).write(2); assert!(({ (*a.borrow()).x } == 2)); @@ -547,24 +546,24 @@ fn main_0() -> i32 { ); object!(foo, Foo); ({ - let __tmp_24: Value = Rc::new(RefCell::new(5)); + let __tmp_22: Value = Rc::new(RefCell::new(5)); MoveConstructible::push_moved( &field_ref!(foo.as_pointer(), a).as_pointer(), - __tmp_24.as_pointer(), + __tmp_22.as_pointer(), ) }); ({ - let __tmp_25: Value = Rc::new(RefCell::new(6)); + let __tmp_23: Value = Rc::new(RefCell::new(6)); MoveConstructible::push_moved( &field_ref!(foo.as_pointer(), b).as_pointer(), - __tmp_25.as_pointer(), + __tmp_23.as_pointer(), ) }); ({ - let __tmp_26: Value = Rc::new(RefCell::new(7)); + let __tmp_24: Value = Rc::new(RefCell::new(7)); MoveConstructible::push_moved( &field_ref!(foo.as_pointer(), b).as_pointer(), - __tmp_26.as_pointer(), + __tmp_24.as_pointer(), ) }); field_ref!(foo.as_pointer(), a) @@ -660,21 +659,21 @@ fn main_0() -> i32 { let v16: Value> = Rc::new(RefCell::new(Vec::from([1, 2, 3, 4, 5, 6, 7, 8]))); let mut after_v16: Vec = Vec::from([0]); let inserted: Value> = Rc::new(RefCell::new({ - let mut __tmp_27 = + let mut __tmp_25 = { >::from(v16.decay().begin().iter_add(1_isize)) }; let __a2 = 7; - (*v16.borrow_mut()).insert(__tmp_27.index(), __a2); - (__tmp_27).clone() + (*v16.borrow_mut()).insert(__tmp_25.index(), __a2); + (__tmp_25).clone() })); { ({ (*inserted.borrow()).iter_deref() }).with_mut(|__v| *__v = *__v + 1) }; let nine: Value = Rc::new(RefCell::new(9)); let inserted_copy: Value> = Rc::new(RefCell::new({ - let mut __tmp_28 = { >::from(v16.decay().begin()) }; + let mut __tmp_26 = { >::from(v16.decay().begin()) }; let __a2 = copy_constructed(nine.as_pointer()); - (*v16.borrow_mut()).insert(__tmp_28.index(), __a2); - (__tmp_28).clone() + (*v16.borrow_mut()).insert(__tmp_26.index(), __a2); + (__tmp_26).clone() })); { ({ (*inserted_copy.borrow()).iter_deref() }).with_mut(|__v| *__v = *__v + 1) @@ -687,20 +686,20 @@ fn main_0() -> i32 { let ints: Value> = Rc::new(RefCell::new(Box::new([1, 2, 3]))); let longs: Value> = Rc::new(RefCell::new(Vec::from([10_i64, 20_i64]))); let pos: Value> = Rc::new(RefCell::new({ - let mut __tmp_29 = + let mut __tmp_27 = { >::from(longs.decay().begin().iter_add(1_isize)) }; - let mut __tmp_30 = { ints.decay().offset((3) as isize) }; - let start_idx = __tmp_29.index(); + let start_idx = __tmp_27.index(); let mut temp_vec: Vec = Vec::new(); - let mut __it = ints.decay(); - while __it != __tmp_30 { - temp_vec.push(((__it.iter_deref().read()) as i64)); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(ints.decay())); + let __last: Value> = Rc::new(RefCell::new(ints.decay().offset((3) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + temp_vec.push(((__it.borrow().iter_deref().read()) as i64)); + __it.borrow_mut().iter_inc(); } longs.as_pointer().with_mut(|v: &mut Vec| { v.splice(start_idx..start_idx, temp_vec); }); - (__tmp_29).clone() + (__tmp_27).clone() })); assert!( ({ @@ -712,39 +711,40 @@ fn main_0() -> i32 { ); let more: Value> = Rc::new(RefCell::new(Vec::from([4, 5]))); { - let mut __tmp_31 = { >::from(longs.decay().end()) }; - let mut __tmp_32 = { more.decay().begin() }; - let mut __tmp_33 = { more.decay().end() }; - let start_idx = __tmp_31.index(); + let mut __tmp_28 = { >::from(longs.decay().end()) }; + let start_idx = __tmp_28.index(); let mut temp_vec: Vec = Vec::new(); - let mut __it = (__tmp_32).clone(); - while __it != __tmp_33 { - temp_vec.push(((__it.iter_deref().read()) as i64)); - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(more.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(more.decay().end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + temp_vec.push(((__it.borrow().iter_deref().read()) as i64)); + __it.borrow_mut().iter_inc(); } longs.as_pointer().with_mut(|v: &mut Vec| { v.splice(start_idx..start_idx, temp_vec); }); - (__tmp_31).clone() + (__tmp_28).clone() }; assert!( ({ ((*longs.borrow()).len() == 7_usize) && ({ (*longs.borrow())[6_usize] } == 5_i64) }) ); let doubles: Value> = Rc::new(RefCell::new(Vec::new())); { - let mut __tmp_34 = { >::from(doubles.decay().begin()) }; - let mut __tmp_35 = { ints.decay().offset((2) as isize) }; - let start_idx = __tmp_34.index(); + let mut __tmp_29 = { >::from(doubles.decay().begin()) }; + let start_idx = __tmp_29.index(); let mut temp_vec: Vec = Vec::new(); - let mut __it = ints.decay(); - while __it != __tmp_35 { - temp_vec.push(((__it.iter_deref().read()) as f64)); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(ints.decay())); + let __last: Value> = Rc::new(RefCell::new(ints.decay().offset((2) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + temp_vec.push(((__it.borrow().iter_deref().read()) as f64)); + __it.borrow_mut().iter_inc(); } doubles.as_pointer().with_mut(|v: &mut Vec| { v.splice(start_idx..start_idx, temp_vec); }); - (__tmp_34).clone() + (__tmp_29).clone() }; assert!( ({ @@ -754,19 +754,21 @@ fn main_0() -> i32 { ); let wrapped: Value> = Rc::new(RefCell::new(Vec::new())); { - let mut __tmp_36 = { >::from(wrapped.decay().begin()) }; - let mut __tmp_37 = { ints.decay().offset((3) as isize) }; - let start_idx = __tmp_36.index(); + let mut __tmp_30 = { >::from(wrapped.decay().begin()) }; + let start_idx = __tmp_30.index(); let mut temp_vec: Vec = Vec::new(); - let mut __it = ints.decay(); - while __it != __tmp_37 { - temp_vec.push(>::cpp_from(__it.iter_deref())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(ints.decay())); + let __last: Value> = Rc::new(RefCell::new(ints.decay().offset((3) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + temp_vec.push(>::cpp_from( + __it.borrow().iter_deref(), + )); + __it.borrow_mut().iter_inc(); } wrapped.as_pointer().with_mut(|v: &mut Vec| { v.splice(start_idx..start_idx, temp_vec); }); - (__tmp_36).clone() + (__tmp_30).clone() }; assert!( ({ @@ -776,20 +778,21 @@ fn main_0() -> i32 { ); let same: Value> = Rc::new(RefCell::new(Vec::from([7]))); { - let mut __tmp_38 = { >::from(same.decay().begin()) }; - let mut __tmp_39 = { more.decay().begin() }; - let mut __tmp_40 = { more.decay().end() }; - let start_idx = __tmp_38.index(); + let mut __tmp_31 = { >::from(same.decay().begin()) }; + let start_idx = __tmp_31.index(); let mut temp_vec: Vec = Vec::new(); - let mut __it = (__tmp_39).clone(); - while __it != __tmp_40 { - temp_vec.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = + Rc::new(RefCell::new(more.decay().begin())); + let __last: Value> = + Rc::new(RefCell::new(more.decay().end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + temp_vec.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } same.as_pointer().with_mut(|v: &mut Vec| { v.splice(start_idx..start_idx, temp_vec); }); - (__tmp_38).clone() + (__tmp_31).clone() }; assert!( ({ diff --git a/tests/unit/out/refcount/vector_iter_range_ctor.rs b/tests/unit/out/refcount/vector_iter_range_ctor.rs index 688722f1c7..939b203404 100644 --- a/tests/unit/out/refcount/vector_iter_range_ctor.rs +++ b/tests/unit/out/refcount/vector_iter_range_ctor.rs @@ -61,36 +61,36 @@ pub fn main() { fn main_0() -> i32 { let src: Value> = Rc::new(RefCell::new(Box::new([1_u32, 2_u32, 3_u32]))); let mut v1: Vec = { - let mut __tmp_0 = { src.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = src.decay(); - while __it != __tmp_0 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + 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())); + __it.borrow_mut().iter_inc(); } __v }; assert!((v1.len() == 3_usize)); assert!(((v1[0_usize] == 1_u32) && (v1[1_usize] == 2_u32)) && (v1[2_usize] == 3_u32)); let mut v2: Vec = { - let mut __tmp_1 = { src.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = src.decay(); - while __it != __tmp_1 { - __v.push(((__it.iter_deref().read()) as u64)); - __it.iter_inc(); + 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)); + __it.borrow_mut().iter_inc(); } __v }; assert!((v2.len() == 3_usize)); assert!(((v2[0_usize] == 1_u64) && (v2[1_usize] == 2_u64)) && (v2[2_usize] == 3_u64)); let mut v3: Vec = { - let mut __tmp_2 = { src.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = src.decay(); - while __it != __tmp_2 { - __v.push(((__it.iter_deref().read()) as i32)); - __it.iter_inc(); + 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 i32)); + __it.borrow_mut().iter_inc(); } __v }; @@ -98,12 +98,12 @@ fn main_0() -> i32 { assert!(((v3[0_usize] == 1) && (v3[1_usize] == 2)) && (v3[2_usize] == 3)); let src1: Value> = Rc::new(RefCell::new(Box::new([1_u32, 2_u32, 3_u32]))); let mut v4: Vec = { - let mut __tmp_3 = { src1.decay().to_end() }; let mut __v = Vec::new(); - let mut __it = src1.decay(); - while __it != __tmp_3 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src1.decay())); + let __last: Value> = Rc::new(RefCell::new(src1.decay().to_end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v }; @@ -117,12 +117,12 @@ fn main_0() -> i32 { let mut start: Ptr = buf.decay(); let mut len: usize = 5_usize; let mut v5: Vec = { - let mut __tmp_4 = { start.offset((len) as isize) }; let mut __v = Vec::new(); - let mut __it = (start).clone(); - while __it != __tmp_4 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new((start).clone())); + let __last: Value> = Rc::new(RefCell::new(start.offset((len) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v }; @@ -130,40 +130,42 @@ fn main_0() -> i32 { assert!(((v5[0_usize] as i32) == 10) && ((v5[4_usize] as i32) == 50)); let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); match (Rc::new(RefCell::new(1)).as_pointer(),) { - (__tmp_5,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_5, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_0,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_0, |__k| cpp_move!(__k), || 0_i32) }) } } .write(10); match (Rc::new(RefCell::new(2)).as_pointer(),) { - (__tmp_6,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_6, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_1,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_1, |__k| cpp_move!(__k), || 0_i32) }) } } .write(20); match (Rc::new(RefCell::new(3)).as_pointer(),) { - (__tmp_7,) => { - ({ (*m.borrow_mut()).subscript_move(__tmp_7, |__k| cpp_move!(__k), || 0_i32) }) + (__tmp_2,) => { + ({ (*m.borrow_mut()).subscript_move(__tmp_2, |__k| cpp_move!(__k), || 0_i32) }) } } .write(30); let v6: Value, Value)>> = Rc::new(RefCell::new({ - let mut __tmp_8 = { + let mut __v = Vec::new(); + let __it: Value, Value)>> = Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.begin()) - }; - let mut __tmp_9 = { + .with(|__m: &Map, Value)>| __m.begin()), + )); + let __last: Value, Value)>> = Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.end()) - }; - let mut __v = Vec::new(); - let mut __it = (__tmp_8).clone(); - while __it != __tmp_9 { + .with(|__m: &Map, Value)>| __m.end()), + )); + while , Value)>>::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) { __v.push(<(Value, Value) as CppFrom<( Value, Value, - )>>::cpp_from(__it.iter_deref())); - __it.iter_inc(); + )>>::cpp_from(__it.borrow().iter_deref())); + __it.borrow_mut().iter_inc(); } __v })); @@ -181,34 +183,36 @@ fn main_0() -> i32 { }) ); { - let mut __tmp_10 = { + let mut __tmp_3 = { , Value)>>::from( v6.decay().begin().iter_add(1_isize), ) }; - let mut __tmp_11 = { + let start_idx = __tmp_3.index(); + let mut temp_vec: Vec<(Value, Value)> = Vec::new(); + let __it: Value, Value)>> = Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.begin()) - }; - let mut __tmp_12 = { + .with(|__m: &Map, Value)>| __m.begin()), + )); + let __last: Value, Value)>> = Rc::new(RefCell::new( m.as_pointer() - .with(|__m: &Map, Value)>| __m.end()) - }; - let start_idx = __tmp_10.index(); - let mut temp_vec: Vec<(Value, Value)> = Vec::new(); - let mut __it = (__tmp_11).clone(); - while __it != __tmp_12 { + .with(|__m: &Map, Value)>| __m.end()), + )); + while , Value)>>::not_equal( + __it.as_pointer(), + __last.as_pointer(), + ) { temp_vec.push(<(Value, Value) as CppFrom<( Value, Value, - )>>::cpp_from(__it.iter_deref())); - __it.iter_inc(); + )>>::cpp_from(__it.borrow().iter_deref())); + __it.borrow_mut().iter_inc(); } v6.as_pointer() .with_mut(|v: &mut Vec<(Value, Value)>| { v.splice(start_idx..start_idx, temp_vec); }); - (__tmp_10).clone() + (__tmp_3).clone() }; assert!(({ ((*v6.borrow()).len() == 6_usize) })); assert!( @@ -220,12 +224,14 @@ fn main_0() -> i32 { ); let ints: Value> = Rc::new(RefCell::new(Box::new([4, 5, 6]))); let mut v7: Vec = { - let mut __tmp_13 = { ints.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = ints.decay(); - while __it != __tmp_13 { - __v.push(>::cpp_from(__it.iter_deref())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(ints.decay())); + let __last: Value> = Rc::new(RefCell::new(ints.decay().offset((3) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push(>::cpp_from( + __it.borrow().iter_deref(), + )); + __it.borrow_mut().iter_inc(); } __v }; @@ -235,12 +241,15 @@ fn main_0() -> i32 { Reading { raw_: 5 }, ]))); let mut v8: Vec = { - let mut __tmp_14 = { readings.decay().offset((2) as isize) }; let mut __v = Vec::new(); - let mut __it = readings.decay(); - while __it != __tmp_14 { - __v.push(>::cpp_from(__it.iter_deref())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(readings.decay())); + let __last: Value> = + Rc::new(RefCell::new(readings.decay().offset((2) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push(>::cpp_from( + __it.borrow().iter_deref(), + )); + __it.borrow_mut().iter_inc(); } __v }; diff --git a/tests/unit/out/refcount/vector_with_allocator.rs b/tests/unit/out/refcount/vector_with_allocator.rs index 140a20b210..6020baa986 100644 --- a/tests/unit/out/refcount/vector_with_allocator.rs +++ b/tests/unit/out/refcount/vector_with_allocator.rs @@ -398,36 +398,36 @@ fn main_0() -> i32 { ({ fn_1(v7.as_pointer(), copy_constructed(v8.as_pointer())) }); let src: Value> = Rc::new(RefCell::new(Box::new([1_u32, 2_u32, 3_u32]))); let mut v9: Vec = { - let mut __tmp_22 = { src.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = src.decay(); - while __it != __tmp_22 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + 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())); + __it.borrow_mut().iter_inc(); } __v }; assert!((v9.len() == 3_usize)); assert!(((v9[0_usize] == 1_u32) && (v9[1_usize] == 2_u32)) && (v9[2_usize] == 3_u32)); let mut v10: Vec = { - let mut __tmp_23 = { src.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = src.decay(); - while __it != __tmp_23 { - __v.push(((__it.iter_deref().read()) as u64)); - __it.iter_inc(); + 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)); + __it.borrow_mut().iter_inc(); } __v }; assert!((v10.len() == 3_usize)); assert!(((v10[0_usize] == 1_u64) && (v10[1_usize] == 2_u64)) && (v10[2_usize] == 3_u64)); let mut v11: Vec = { - let mut __tmp_24 = { src.decay().offset((3) as isize) }; let mut __v = Vec::new(); - let mut __it = src.decay(); - while __it != __tmp_24 { - __v.push(((__it.iter_deref().read()) as i32)); - __it.iter_inc(); + 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 i32)); + __it.borrow_mut().iter_inc(); } __v }; @@ -435,12 +435,12 @@ fn main_0() -> i32 { assert!(((v11[0_usize] == 1) && (v11[1_usize] == 2)) && (v11[2_usize] == 3)); let src1: Value> = Rc::new(RefCell::new(Box::new([1_u32, 2_u32, 3_u32]))); let mut v12: Vec = { - let mut __tmp_25 = { src1.decay().to_end() }; let mut __v = Vec::new(); - let mut __it = src1.decay(); - while __it != __tmp_25 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new(src1.decay())); + let __last: Value> = Rc::new(RefCell::new(src1.decay().to_end())); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v }; @@ -451,12 +451,12 @@ fn main_0() -> i32 { let mut start: Ptr = buf.decay(); let mut len: usize = 5_usize; let mut v13: Vec = { - let mut __tmp_26 = { start.offset((len) as isize) }; let mut __v = Vec::new(); - let mut __it = (start).clone(); - while __it != __tmp_26 { - __v.push((__it.iter_deref().read())); - __it.iter_inc(); + let __it: Value> = Rc::new(RefCell::new((start).clone())); + let __last: Value> = Rc::new(RefCell::new(start.offset((len) as isize))); + while >::not_equal(__it.as_pointer(), __last.as_pointer()) { + __v.push((__it.borrow().iter_deref().read())); + __it.borrow_mut().iter_inc(); } __v }; diff --git a/tests/unit/out/unsafe/class.rs b/tests/unit/out/unsafe/class.rs index 8bb913f0e5..a1be7efaff 100644 --- a/tests/unit/out/unsafe/class.rs +++ b/tests/unit/out/unsafe/class.rs @@ -92,17 +92,7 @@ impl Counter { (*(&raw const (*this).calls).cast_mut()).prefix_inc(); return (*this).v; } - pub unsafe fn operator_eq(this: *const Self, o: *const Counter) -> bool { - (*(&raw const (*this).calls).cast_mut()).prefix_inc(); - return (((*this).v) == ((*o).v)); - } -} -impl std::cmp::PartialEq for Counter { - fn eq(&self, other: &Self) -> bool { - unsafe { Counter::operator_eq(self, other as *const Counter) } - } } -impl std::cmp::Eq for Counter {} #[repr(C)] #[derive( Copy, @@ -180,8 +170,8 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { Counter::Get(&raw const c1,) }) == (3))); assert!(((unsafe { Counter::Get(&raw const c2,) }) == (3))); assert!(((unsafe { Counter::Get(&raw const (*pc),) }) == (3))); - assert!((unsafe { Counter::operator_eq(&raw const c1, &c2,) })); - assert!((unsafe { Counter::operator_eq(&raw const c2, &c1,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const c1, &c2,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const c2, &c1,) })); assert!(((c1.calls) == (3))); assert!(((c2.calls) == (2))); let mut t: Tally = Tally { calls: 0 }; @@ -194,4 +184,10 @@ unsafe fn main_0() -> i32 { assert!(((ct.calls) == (10))); return 0; } +impl WeaklyEqualityComparableWithUnsafe for Counter { + unsafe fn equal(this: *const Self, o: *const Counter) -> bool { + (*(&raw const (*this).calls).cast_mut()).prefix_inc(); + return (((*this).v) == ((*o).v)); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/copy_ctor.rs b/tests/unit/out/unsafe/copy_ctor.rs index 0c83840e9f..3f21fe6fe3 100644 --- a/tests/unit/out/unsafe/copy_ctor.rs +++ b/tests/unit/out/unsafe/copy_ctor.rs @@ -384,7 +384,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { vec_.end() }; let mut __v = Vec::new(); let mut __it = (__tmp_0).clone(); - while __it != __tmp_1 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { __v.push(>::cpp_from( __it.iter_deref(), )); diff --git a/tests/unit/out/unsafe/find.rs b/tests/unit/out/unsafe/find.rs index 62eb6c3e8c..3861d5282c 100644 --- a/tests/unit/out/unsafe/find.rs +++ b/tests/unit/out/unsafe/find.rs @@ -20,17 +20,6 @@ use std::rc::Rc; pub struct P { pub x: i32, } -impl P { - pub unsafe fn operator_eq(this: *const Self, o: *const P) -> bool { - return (((*this).x) == ((*o).x)); - } -} -impl std::cmp::PartialEq for P { - fn eq(&self, other: &Self) -> bool { - unsafe { P::operator_eq(self, other as *const P) } - } -} -impl std::cmp::Eq for P {} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -56,12 +45,14 @@ unsafe fn main_0() -> i32 { let mut it: UnsafeRandomAccessIterator = { let mut __tmp_3 = { (v_end).clone() }; let mut __it = (v_begin).clone(); - while __it != __tmp_3 && *__it.iter_deref() != 2 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &2) + { __it.iter_inc(); } __it }; - let mut v_result_true: bool = it != v.end(); + let mut v_result_true: bool = WeaklyEqualityComparableWithUnsafe::not_equal(&it, &v.end()); let mut m: UnsafeMap = UnsafeMap::new(); { let mut __tmp_4: i32; @@ -86,65 +77,87 @@ unsafe fn main_0() -> i32 { }; let mut m_begin: UnsafeBidirectionalIterator<(i32, f64)> = m.begin(); let mut m_end: UnsafeBidirectionalIterator<(i32, f64)> = m.end(); - let mut m_result_true: bool = m_begin != m_end; + let mut m_result_true: bool = WeaklyEqualityComparableWithUnsafe::not_equal(&m_begin, &m_end); assert!( ((v_result_true) && (m_result_true)) - && ({ - let mut __tmp_7 = { v.begin() }; - let mut __tmp_8 = { v.begin() }; - let mut __it = (__tmp_7).clone(); - while __it != __tmp_8 && *__it.iter_deref() != 2 { - __it.iter_inc(); - } - __it - } == v.begin()) + && (WeaklyEqualityComparableWithUnsafe::equal( + &{ + let mut __tmp_7 = { v.begin() }; + let mut __tmp_8 = { v.begin() }; + let mut __it = (__tmp_7).clone(); + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_8) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &2) + { + __it.iter_inc(); + } + __it + }, + &v.begin() + )) ); let mut w: Vec = Vec::from([1, 2, 3, 4, 5]); - assert!( - { + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ let mut __tmp_9 = { w.begin().iter_add(2_isize) }; let mut __tmp_10 = { w.end() }; let mut __it = (__tmp_9).clone(); - while __it != __tmp_10 && *__it.iter_deref() != 4 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_10) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &4) + { __it.iter_inc(); } __it - } == w.begin().iter_add(3_isize) - ); - assert!( - { + }, + &w.begin().iter_add(3_isize) + )); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ let mut __tmp_11 = { w.begin().iter_add(2_isize) }; let mut __tmp_12 = { w.end() }; let mut __it = (__tmp_11).clone(); - while __it != __tmp_12 && *__it.iter_deref() != 1 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_12) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &1) + { __it.iter_inc(); } __it - } == w.end() - ); - assert!( - { + }, + &w.end() + )); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ let mut __tmp_13 = { w.begin().iter_add(2_isize) }; let mut __tmp_14 = { w.begin().iter_add(4_isize) }; let mut __it = (__tmp_13).clone(); - while __it != __tmp_14 && *__it.iter_deref() != 5 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_14) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &5) + { __it.iter_inc(); } __it - } == w.begin().iter_add(4_isize) - ); + }, + &w.begin().iter_add(4_isize) + )); let mut p: Vec

= Vec::from([P { x: 0 }, P { x: 1 }, P { x: 2 }]); - assert!( - { + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ let mut __tmp_15 = { p.begin() }; let mut __tmp_16 = { p.end() }; let mut __it = (__tmp_15).clone(); - while __it != __tmp_16 && *__it.iter_deref() != (P { x: 1 }) { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_16) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &(P { x: 1 })) + { __it.iter_inc(); } __it - } == p.begin().iter_add(1_isize) - ); + }, + &p.begin().iter_add(1_isize) + )); return 0; } +impl WeaklyEqualityComparableWithUnsafe for P { + unsafe fn equal(this: *const Self, o: *const P) -> bool { + return (((*this).x) == ((*o).x)); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/map.rs b/tests/unit/out/unsafe/map.rs index b1c75afbca..bafffe08be 100644 --- a/tests/unit/out/unsafe/map.rs +++ b/tests/unit/out/unsafe/map.rs @@ -216,26 +216,31 @@ unsafe fn main_0() -> i32 { let mut it: UnsafeBidirectionalIterator<(i16, u32)> = m.find(&1_i16); let mut const_it: UnsafeBidirectionalIterator<(i16, u32)> = >::from(m.find(&10_i16)); - let mut x1: u32 = if it == end { + let mut x1: u32 = if WeaklyEqualityComparableWithUnsafe::equal(&it, &end) { 0_u32 } else { (*it.iter_deref()).1 }; assert!(((x1) == (4_u32))); - let mut x2: u32 = if const_it == >::from((end).clone()) - { + let mut x2: u32 = if WeaklyEqualityComparableWithUnsafe::equal( + &const_it, + &>::from((end).clone()), + ) { 0_u32 } else { (*const_it.iter_deref()).1 }; assert!(((x2) == (0_u32))); - let mut x3: u32 = if it == m.end() { + let mut x3: u32 = if WeaklyEqualityComparableWithUnsafe::equal(&it, &m.end()) { 0_u32 } else { (*it.iter_deref()).1 }; assert!(((x3) == (4_u32))); - let mut x4: u32 = if const_it == >::from(m.end()) { + let mut x4: u32 = if WeaklyEqualityComparableWithUnsafe::equal( + &const_it, + &>::from(m.end()), + ) { 0_u32 } else { (*const_it.iter_deref()).1 @@ -281,10 +286,16 @@ unsafe fn main_0() -> i32 { assert!((((*const_it4.iter_deref()).1) == (6_u32))); let r: *mut UnsafeMap = &mut m; assert!((((*r).len()) == (4_usize))); - assert!(m.find(&4_i16) != m.end()); + assert!(WeaklyEqualityComparableWithUnsafe::not_equal( + &m.find(&4_i16), + &m.end() + )); (*r).erase(&(it4).clone()); assert!((((*r).len()) == (3_usize))); - assert!(m.find(&4_i16) == m.end()); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &m.find(&4_i16), + &m.end() + )); { let mut __tmp_21: i16; (*{ @@ -314,13 +325,19 @@ unsafe fn main_0() -> i32 { let mut cit: UnsafeBidirectionalIterator<(i16, u32)> = >::from(m.find(&7_i16)); let mut next: UnsafeBidirectionalIterator<(i16, u32)> = m.erase(&(cit).clone()); - assert!(next == m.find(&8_i16)); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &next, + &m.find(&8_i16) + )); { next = m.erase(&(next).clone()); }; - assert!(next == m.end()); + assert!(WeaklyEqualityComparableWithUnsafe::equal(&next, &m.end())); assert!((((*r).len()) == (3_usize))); - assert!(m.find(&8_i16) == m.end()); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &m.find(&8_i16), + &m.end() + )); let mut other_map: UnsafeMap<(i32, i64), ((i32, i64), f64)> = UnsafeMap::new(); assert!(((other_map.len()) == (0_usize))); let mut key0: (i32, i64) = (1, (1 as i64)); diff --git a/tests/unit/out/unsafe/map_key_copy_ctor.rs b/tests/unit/out/unsafe/map_key_copy_ctor.rs index 3db77d5c8f..019299a70c 100644 --- a/tests/unit/out/unsafe/map_key_copy_ctor.rs +++ b/tests/unit/out/unsafe/map_key_copy_ctor.rs @@ -40,9 +40,9 @@ impl MoveConstructibleUnsafe for Key { impl std::cmp::Ord for Key { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if Key::operator_lt(self, other as *const Key) { + if Key::operator_lt((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if Key::operator_lt(other, self as *const Key) { + } else if Key::operator_lt((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -58,8 +58,8 @@ impl std::cmp::PartialOrd for Key { impl std::cmp::PartialEq for Key { fn eq(&self, other: &Self) -> bool { unsafe { - !(Key::operator_lt(self, other as *const Key)) - && !(Key::operator_lt(other, self as *const Key)) + !(Key::operator_lt((self as *const Self), (other as *const Self))) + && !(Key::operator_lt((other as *const Self), (self as *const Self))) } } } diff --git a/tests/unit/out/unsafe/map_key_identity.rs b/tests/unit/out/unsafe/map_key_identity.rs index 62f5ce6810..8d6e5b77e7 100644 --- a/tests/unit/out/unsafe/map_key_identity.rs +++ b/tests/unit/out/unsafe/map_key_identity.rs @@ -26,9 +26,9 @@ pub struct Key { impl std::cmp::Ord for Key { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_1(self as *const Key, other as *const Key) { + if operator_lt_1((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_1(other as *const Key, self as *const Key) { + } else if operator_lt_1((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -43,16 +43,15 @@ impl std::cmp::PartialOrd for Key { } impl std::cmp::PartialEq for Key { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_2(self as *const Key, other as *const Key) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Key {} pub unsafe fn operator_lt_1(a: *const Key, b: *const Key) -> bool { return (((*a).order) < ((*b).order)); } -pub unsafe fn operator_eq_2(a: *const Key, b: *const Key) -> bool { - return (((*a).identity) == ((*b).identity)); -} #[repr(C)] #[derive(Copy, Clone, VaArg, FnPtrArg, ZeroInitializationUnsafe, TriviallyCopyableUnsafe)] pub struct Mapped { @@ -94,7 +93,7 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & ((unsafe { let _a: *const Key = &distinct_a; - operator_eq_2(_a, &distinct_b) + WeaklyEqualityComparableWithUnsafe::equal(_a, &distinct_b) }) as i32)) != 0; let mut distinct: UnsafeMap = UnsafeMap::new(); @@ -116,15 +115,21 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & (((distinct.len()) == (2_usize)) as i32)) != 0; ok = ((ok as i32) & (((a) != (b)) as i32)) != 0; ok = ((ok as i32) & (((((*a).value) == (11)) && (((*b).value) == (22))) as i32)) != 0; - ok = ((ok as i32) & ((a_it == distinct.find(&distinct_a)) as i32)) != 0; - ok = ((ok as i32) & ((b_it == distinct.find(&distinct_b)) as i32)) != 0; - ok = ((ok as i32) & ((b_it != distinct.end()) as i32)) != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::equal(&a_it, &distinct.find(&distinct_a))) as i32)) + != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::equal(&b_it, &distinct.find(&distinct_b))) as i32)) + != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::not_equal(&b_it, &distinct.end())) as i32)) + != 0; ok = ((ok as i32) & (((&mut (*a_it.iter_deref()).1 as *mut Mapped) == (a_value)) as i32)) != 0; ok = ((ok as i32) & ((((*a_it.iter_deref()).1.value) == (11)) as i32)) != 0; ok = ((ok as i32) & ((unsafe { let _a: *const Key = &distinct_a; - operator_eq_2(_a, &distinct_b) + WeaklyEqualityComparableWithUnsafe::equal(_a, &distinct_b) }) as i32)) != 0; let mut distinct_count: usize = 0_usize; @@ -153,7 +158,7 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & (!(unsafe { let _a: *const Key = &equivalent_a; - operator_eq_2(_a, &equivalent_b) + WeaklyEqualityComparableWithUnsafe::equal(_a, &equivalent_b) }) as i32)) != 0; let mut equivalent: UnsafeMap = UnsafeMap::new(); @@ -173,10 +178,23 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & (reused as i32)) != 0; ok = ((ok as i32) & (((equivalent.len()) == (1_usize)) as i32)) != 0; if reused { - ok = ((ok as i32) & ((first_it != equivalent.end()) as i32)) != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::not_equal(&first_it, &equivalent.end())) + as i32)) + != 0; ok = ((ok as i32) & (((first) == (second)) as i32)) != 0; - ok = ((ok as i32) & ((first_it == equivalent.find(&equivalent_a)) as i32)) != 0; - ok = ((ok as i32) & ((first_it == equivalent.find(&equivalent_b)) as i32)) != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::equal( + &first_it, + &equivalent.find(&equivalent_a), + )) as i32)) + != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::equal( + &first_it, + &equivalent.find(&equivalent_b), + )) as i32)) + != 0; ok = ((ok as i32) & (((&mut (*first_it.iter_deref()).1 as *mut Mapped) == (first_value)) as i32)) != 0; @@ -197,7 +215,7 @@ unsafe fn main_0() -> i32 { ok = ((ok as i32) & (!(unsafe { let _a: *const Key = &equivalent_a; - operator_eq_2(_a, &equivalent_b) + WeaklyEqualityComparableWithUnsafe::equal(_a, &equivalent_b) }) as i32)) != 0; let later_key: Key = Key { @@ -212,7 +230,12 @@ unsafe fn main_0() -> i32 { != 0; ok = ((ok as i32) & (((equivalent.len()) == (2_usize)) as i32)) != 0; if reused { - ok = ((ok as i32) & ((first_it == equivalent.find(&equivalent_a)) as i32)) != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::equal( + &first_it, + &equivalent.find(&equivalent_a), + )) as i32)) + != 0; ok = ((ok as i32) & (((&mut (*first_it.iter_deref()).1 as *mut Mapped) == (first_value)) as i32)) != 0; @@ -249,7 +272,10 @@ unsafe fn main_0() -> i32 { != 0; ok = ((ok as i32) & (((matching.len()) == (1_usize)) as i32)) != 0; ok = ((ok as i32) & (((matched) == (matched_again)) as i32)) != 0; - ok = ((ok as i32) & ((matched_it == matching.find(&matching_b)) as i32)) != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::equal(&matched_it, &matching.find(&matching_b))) + as i32)) + != 0; ok = ((ok as i32) & (((&mut (*matched_it.iter_deref()).1 as *mut Mapped) == (matched_value)) as i32)) != 0; @@ -261,13 +287,21 @@ unsafe fn main_0() -> i32 { == ((before_matching) + (2))) as i32)) != 0; ok = ((ok as i32) & (((matching.len()) == (2_usize)) as i32)) != 0; - ok = ((ok as i32) & ((matched_it == matching.find(&matching_a)) as i32)) != 0; + ok = ((ok as i32) + & ((WeaklyEqualityComparableWithUnsafe::equal(&matched_it, &matching.find(&matching_a))) + as i32)) + != 0; ok = ((ok as i32) & (((&mut (*matched_it.iter_deref()).1 as *mut Mapped) == (matched_value)) as i32)) != 0; ok = ((ok as i32) & ((((*matched_it.iter_deref()).1.value) == (51)) as i32)) != 0; return if ok { 0 } else { 1 }; } +impl WeaklyEqualityComparableWithUnsafe for Key { + unsafe fn equal(a: *const Key, b: *const Key) -> bool { + return (((*a).identity) == ((*b).identity)); + } +} pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const default_constructions_0); } diff --git a/tests/unit/out/unsafe/map_try_emplace.rs b/tests/unit/out/unsafe/map_try_emplace.rs index 50b537fdfa..a752caad76 100644 --- a/tests/unit/out/unsafe/map_try_emplace.rs +++ b/tests/unit/out/unsafe/map_try_emplace.rs @@ -209,7 +209,11 @@ unsafe fn main_0() -> i32 { & ((((result.1) as i32) == (!(hit) as i32)) as i32)) != 0; - let mut found: bool = result.0 == m.find(&key); + let mut found: bool = + WeaklyEqualityComparableWithUnsafe::equal( + &result.0, + &m.find(&key), + ); ok = ((ok as i32) & (found as i32)) != 0; ok = ((ok as i32) & ((((*result.0.iter_deref()).0) == (key)) diff --git a/tests/unit/out/unsafe/max.rs b/tests/unit/out/unsafe/max.rs index 2418d926f2..2a504984cd 100644 --- a/tests/unit/out/unsafe/max.rs +++ b/tests/unit/out/unsafe/max.rs @@ -47,9 +47,9 @@ impl CopyConstructibleUnsafe for Bag { impl std::cmp::Ord for Bag { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_4(self as *const Bag, other as *const Bag) { + if operator_lt_4((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_4(other as *const Bag, self as *const Bag) { + } else if operator_lt_4((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -65,8 +65,8 @@ impl std::cmp::PartialOrd for Bag { impl std::cmp::PartialEq for Bag { fn eq(&self, other: &Self) -> bool { unsafe { - !(operator_lt_4(self as *const Bag, other as *const Bag)) - && !(operator_lt_4(other as *const Bag, self as *const Bag)) + !(operator_lt_4((self as *const Self), (other as *const Self))) + && !(operator_lt_4((other as *const Self), (self as *const Self))) } } } @@ -126,10 +126,10 @@ unsafe fn main_0() -> i32 { let mut __tmp_2 = { values.as_mut_ptr() }; let mut __tmp_3 = { values.as_mut_ptr().offset((4) as isize) }; let mut __best = __tmp_2.clone(); - if __tmp_2 != __tmp_3 { + if WeaklyEqualityComparableWithUnsafe::not_equal(&__tmp_2, &__tmp_3) { let mut __it = __tmp_2; __it.iter_inc(); - while __it != __tmp_3 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) { if *__best.iter_deref() < *__it.iter_deref() { __best = __it.clone(); } diff --git a/tests/unit/out/unsafe/operator_comparison_defaulted.rs b/tests/unit/out/unsafe/operator_comparison_defaulted.rs index 3ed17b1d67..466114ab9f 100644 --- a/tests/unit/out/unsafe/operator_comparison_defaulted.rs +++ b/tests/unit/out/unsafe/operator_comparison_defaulted.rs @@ -21,17 +21,6 @@ pub struct Eq { pub a: i32, pub b: i32, } -impl Eq { - pub unsafe fn operator_eq(this: *const Self, _a0: *const Eq) -> bool { - return (((*this).a) == ((*_a0).a)) && (((*this).b) == ((*_a0).b)); - } -} -impl std::cmp::PartialEq for Eq { - fn eq(&self, other: &Self) -> bool { - unsafe { Eq::operator_eq(self, other as *const Eq) } - } -} -impl std::cmp::Eq for Eq {} #[repr(C)] #[derive( Copy, @@ -63,13 +52,10 @@ impl Cmp { } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(this: *const Self, _a0: *const Cmp) -> bool { - return (((*this).a) == ((*_a0).a)) && (((*this).b) == ((*_a0).b)); - } } impl std::cmp::Ord for Cmp { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { Cmp::operator_cmp(self, other as *const Cmp) } + unsafe { Cmp::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for Cmp { @@ -79,7 +65,10 @@ impl std::cmp::PartialOrd for Cmp { } impl std::cmp::PartialEq for Cmp { fn eq(&self, other: &Self) -> bool { - unsafe { Cmp::operator_cmp(self, other as *const Cmp) == std::cmp::Ordering::Equal } + unsafe { + Cmp::operator_cmp((self as *const Self), (other as *const Self)) + == std::cmp::Ordering::Equal + } } } impl std::cmp::Eq for Cmp {} @@ -98,9 +87,6 @@ pub struct Both { pub a: i32, } impl Both { - pub unsafe fn operator_eq(this: *const Self, _a0: *const Both) -> bool { - return (((*this).a) == ((*_a0).a)); - } pub unsafe fn operator_cmp(this: *const Self, _a0: *const Both) -> std::cmp::Ordering { { let mut cmp: std::cmp::Ordering = std::cmp::Ord::cmp(&((*this).a), &((*_a0).a)); @@ -113,7 +99,7 @@ impl Both { } impl std::cmp::Ord for Both { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { Both::operator_cmp(self, other as *const Both) } + unsafe { Both::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for Both { @@ -123,7 +109,9 @@ impl std::cmp::PartialOrd for Both { } impl std::cmp::PartialEq for Both { fn eq(&self, other: &Self) -> bool { - unsafe { Both::operator_eq(self, other as *const Both) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Both {} @@ -154,7 +142,7 @@ impl OrdOnly { } impl std::cmp::Ord for OrdOnly { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { OrdOnly::operator_cmp(self, other as *const OrdOnly) } + unsafe { OrdOnly::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for OrdOnly { @@ -164,7 +152,10 @@ impl std::cmp::PartialOrd for OrdOnly { } impl std::cmp::PartialEq for OrdOnly { fn eq(&self, other: &Self) -> bool { - unsafe { OrdOnly::operator_cmp(self, other as *const OrdOnly) == std::cmp::Ordering::Equal } + unsafe { + OrdOnly::operator_cmp((self as *const Self), (other as *const Self)) + == std::cmp::Ordering::Equal + } } } impl std::cmp::Eq for OrdOnly {} @@ -192,13 +183,10 @@ impl Inner { } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(this: *const Self, _a0: *const Inner) -> bool { - return (((*this).x) == ((*_a0).x)); - } } impl std::cmp::Ord for Inner { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { Inner::operator_cmp(self, other as *const Inner) } + unsafe { Inner::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for Inner { @@ -208,7 +196,10 @@ impl std::cmp::PartialOrd for Inner { } impl std::cmp::PartialEq for Inner { fn eq(&self, other: &Self) -> bool { - unsafe { Inner::operator_cmp(self, other as *const Inner) == std::cmp::Ordering::Equal } + unsafe { + Inner::operator_cmp((self as *const Self), (other as *const Self)) + == std::cmp::Ordering::Equal + } } } impl std::cmp::Eq for Inner {} @@ -246,16 +237,10 @@ impl Outer { } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(this: *const Self, _a0: *const Outer) -> bool { - return (unsafe { - let _arg0: *const Inner = &(*_a0).i; - Inner::operator_eq(&raw const (*this).i, _arg0) - }) && (((*this).y) == ((*_a0).y)); - } } impl std::cmp::Ord for Outer { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { Outer::operator_cmp(self, other as *const Outer) } + unsafe { Outer::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for Outer { @@ -265,7 +250,10 @@ impl std::cmp::PartialOrd for Outer { } impl std::cmp::PartialEq for Outer { fn eq(&self, other: &Self) -> bool { - unsafe { Outer::operator_cmp(self, other as *const Outer) == std::cmp::Ordering::Equal } + unsafe { + Outer::operator_cmp((self as *const Self), (other as *const Self)) + == std::cmp::Ordering::Equal + } } } impl std::cmp::Eq for Outer {} @@ -284,12 +272,6 @@ pub struct Secondary { pub a: i32, } impl Secondary { - pub unsafe fn operator_eq(this: *const Self, _a0: *const Secondary) -> bool { - return (((*this).a) == ((*_a0).a)); - } - pub unsafe fn operator_ne(this: *const Self, _a0: *const Secondary) -> bool { - return !(unsafe { Secondary::operator_eq(&raw const (*this), _a0) }); - } pub unsafe fn operator_cmp(this: *const Self, _a0: *const Secondary) -> std::cmp::Ordering { { let mut cmp: std::cmp::Ordering = std::cmp::Ord::cmp(&((*this).a), &((*_a0).a)); @@ -310,7 +292,7 @@ impl Secondary { } impl std::cmp::Ord for Secondary { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { Secondary::operator_cmp(self, other as *const Secondary) } + unsafe { Secondary::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for Secondary { @@ -320,7 +302,9 @@ impl std::cmp::PartialOrd for Secondary { } impl std::cmp::PartialEq for Secondary { fn eq(&self, other: &Self) -> bool { - unsafe { Secondary::operator_eq(self, other as *const Secondary) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Secondary {} @@ -348,13 +332,10 @@ impl PtrMember { } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(this: *const Self, _a0: *const PtrMember) -> bool { - return (((*this).p) == ((*_a0).p)); - } } impl std::cmp::Ord for PtrMember { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { PtrMember::operator_cmp(self, other as *const PtrMember) } + unsafe { PtrMember::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for PtrMember { @@ -365,7 +346,8 @@ impl std::cmp::PartialOrd for PtrMember { impl std::cmp::PartialEq for PtrMember { fn eq(&self, other: &Self) -> bool { unsafe { - PtrMember::operator_cmp(self, other as *const PtrMember) == std::cmp::Ordering::Equal + PtrMember::operator_cmp((self as *const Self), (other as *const Self)) + == std::cmp::Ordering::Equal } } } @@ -380,8 +362,8 @@ unsafe fn main_0() -> i32 { let mut e1: Eq = Eq { a: 1, b: 2 }; let mut e2: Eq = Eq { a: 1, b: 2 }; let mut e3: Eq = Eq { a: 1, b: 3 }; - assert!((unsafe { Eq::operator_eq(&raw const e1, &e2,) })); - assert!(!(unsafe { Eq::operator_eq(&raw const e1, &e3,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const e1, &e2,) })); + assert!(!(unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const e1, &e3,) })); let mut c1: Cmp = Cmp { a: 1, b: 2 }; let mut c2: Cmp = Cmp { a: 1, b: 3 }; let mut c3: Cmp = Cmp { a: 2, b: 0 }; @@ -391,7 +373,7 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _arg0: *const Cmp = &c1; - Cmp::operator_eq(&raw const c1, _arg0) + WeaklyEqualityComparableWithUnsafe::equal(&raw const c1, _arg0) }) ); assert!((unsafe { Cmp::operator_cmp(&raw const c1, &c2,) }) == libcc2rs::STRONG_ORDERING_LESS); @@ -401,7 +383,7 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _arg0: *const Both = &b2; - Both::operator_eq(&raw const b2, _arg0) + WeaklyEqualityComparableWithUnsafe::equal(&raw const b2, _arg0) }) ); let mut o1: OrdOnly = OrdOnly { a: 1 }; @@ -424,13 +406,13 @@ unsafe fn main_0() -> i32 { y: 9, }; assert!((unsafe { Outer::operator_cmp(&raw const x1, &x2,) }) == std::cmp::Ordering::Less); - assert!((unsafe { Outer::operator_eq(&raw const x1, &x3,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const x1, &x3,) })); assert!( (unsafe { Outer::operator_cmp(&raw const x2, &x1,) }) == libcc2rs::STRONG_ORDERING_GREATER ); let mut s1: Secondary = Secondary { a: 1 }; let mut s2: Secondary = Secondary { a: 2 }; - assert!((unsafe { Secondary::operator_ne(&raw const s1, &s2,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::not_equal(&raw const s1, &s2,) })); assert!((unsafe { Secondary::operator_lt(&raw const s1, &s2,) })); assert!((unsafe { Secondary::operator_ge(&raw const s2, &s1,) })); assert!(!(unsafe { Secondary::operator_lt(&raw const s2, &s1,) })); @@ -445,11 +427,52 @@ unsafe fn main_0() -> i32 { p: arr.as_mut_ptr(), }; assert!((unsafe { PtrMember::operator_cmp(&raw const p1, &p2,) }) == std::cmp::Ordering::Less); - assert!((unsafe { PtrMember::operator_eq(&raw const p1, &p3,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const p1, &p3,) })); assert!( (unsafe { PtrMember::operator_cmp(&raw const p2, &p1,) }) == libcc2rs::STRONG_ORDERING_GREATER ); return 0; } +impl WeaklyEqualityComparableWithUnsafe for Both { + unsafe fn equal(this: *const Self, _a0: *const Both) -> bool { + return (((*this).a) == ((*_a0).a)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Cmp { + unsafe fn equal(this: *const Self, _a0: *const Cmp) -> bool { + return (((*this).a) == ((*_a0).a)) && (((*this).b) == ((*_a0).b)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Eq { + unsafe fn equal(this: *const Self, _a0: *const Eq) -> bool { + return (((*this).a) == ((*_a0).a)) && (((*this).b) == ((*_a0).b)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Inner { + unsafe fn equal(this: *const Self, _a0: *const Inner) -> bool { + return (((*this).x) == ((*_a0).x)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Outer { + unsafe fn equal(this: *const Self, _a0: *const Outer) -> bool { + return (unsafe { + let _arg0: *const Inner = &(*_a0).i; + WeaklyEqualityComparableWithUnsafe::equal(&raw const (*this).i, _arg0) + }) && (((*this).y) == ((*_a0).y)); + } +} +impl WeaklyEqualityComparableWithUnsafe for PtrMember { + unsafe fn equal(this: *const Self, _a0: *const PtrMember) -> bool { + return (((*this).p) == ((*_a0).p)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Secondary { + unsafe fn equal(this: *const Self, _a0: *const Secondary) -> bool { + return (((*this).a) == ((*_a0).a)); + } + unsafe fn not_equal(this: *const Self, _a0: *const Secondary) -> bool { + return !(unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const (*this), _a0) }); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_comparison_member.rs b/tests/unit/out/unsafe/operator_comparison_member.rs index 8901e9a173..7ce9e42ed9 100644 --- a/tests/unit/out/unsafe/operator_comparison_member.rs +++ b/tests/unit/out/unsafe/operator_comparison_member.rs @@ -21,12 +21,6 @@ pub struct S { pub v: i32, } impl S { - pub unsafe fn operator_eq(this: *const Self, o: *const S) -> bool { - return (((*this).v) == ((*o).v)); - } - pub unsafe fn operator_ne(this: *const Self, o: *const S) -> bool { - return (((*this).v) != ((*o).v)); - } pub unsafe fn operator_lt_3(this: *const Self, o: *const S) -> bool { return (((*this).v) < ((*o).v)); } @@ -46,9 +40,9 @@ impl S { impl std::cmp::Ord for S { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if S::operator_lt_3(self, other as *const S) { + if S::operator_lt_3((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if S::operator_lt_3(other, self as *const S) { + } else if S::operator_lt_3((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -63,7 +57,9 @@ impl std::cmp::PartialOrd for S { } impl std::cmp::PartialEq for S { fn eq(&self, other: &Self) -> bool { - unsafe { S::operator_eq(self, other as *const S) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for S {} @@ -77,8 +73,8 @@ unsafe fn main_0() -> i32 { let mut a: S = S { v: 1 }; let mut b: S = S { v: 2 }; let mut c: S = S { v: 1 }; - assert!((unsafe { S::operator_eq(&raw const a, &c,) })); - assert!((unsafe { S::operator_ne(&raw const a, &b,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const a, &c,) })); + assert!((unsafe { WeaklyEqualityComparableWithUnsafe::not_equal(&raw const a, &b,) })); assert!((unsafe { S::operator_lt_3(&raw const a, &b,) })); assert!((unsafe { S::operator_gt(&raw const b, &a,) })); assert!((unsafe { S::operator_le(&raw const a, &c,) })); @@ -87,4 +83,12 @@ unsafe fn main_0() -> i32 { assert!((unsafe { S::operator_lt_7(&raw const a, 5,) })); return 0; } +impl WeaklyEqualityComparableWithUnsafe for S { + unsafe fn equal(this: *const Self, o: *const S) -> bool { + return (((*this).v) == ((*o).v)); + } + unsafe fn not_equal(this: *const Self, o: *const S) -> bool { + return (((*this).v) != ((*o).v)); + } +} 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 dec785d640..215a3e07c6 100644 --- a/tests/unit/out/unsafe/operator_comparison_nonbool.rs +++ b/tests/unit/out/unsafe/operator_comparison_nonbool.rs @@ -23,9 +23,17 @@ pub struct X { impl std::cmp::Ord for X { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if ((operator_lt_0(self.clone(), other.clone())) != 0) { + if ((operator_lt_1( + (*(self as *const Self)).clone(), + (*(other as *const Self)).clone(), + )) != 0) + { std::cmp::Ordering::Less - } else if ((operator_lt_0(other.clone(), self.clone())) != 0) { + } else if ((operator_lt_1( + (*(other as *const Self)).clone(), + (*(self as *const Self)).clone(), + )) != 0) + { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -40,17 +48,22 @@ impl std::cmp::PartialOrd for X { } impl std::cmp::PartialEq for X { fn eq(&self, other: &Self) -> bool { - unsafe { ((operator_eq_1(self.clone(), other.clone())) != 0) } + unsafe { + ((operator_eq_2( + (*(self as *const Self)).clone(), + (*(other as *const Self)).clone(), + )) != 0) + } } } impl std::cmp::Eq for X {} -pub unsafe fn operator_eq_1(mut a: X, mut b: X) -> i32 { +pub unsafe fn operator_eq_2(mut a: X, mut b: X) -> i32 { return if ((a.v) == (b.v)) { 2 } else { 0 }; } -pub unsafe fn operator_ne_2(mut a: X, mut b: X) -> i32 { +pub unsafe fn operator_ne_0(mut a: X, mut b: X) -> i32 { return if ((a.v) != (b.v)) { 3 } else { 0 }; } -pub unsafe fn operator_lt_0(mut a: X, mut b: X) -> i32 { +pub unsafe fn operator_lt_1(mut a: X, mut b: X) -> i32 { return if ((a.v) < (b.v)) { 4 } else { 0 }; } pub unsafe fn operator_gt_3(mut a: X, mut b: X) -> i32 { @@ -127,9 +140,9 @@ impl Mixed { impl std::cmp::Ord for Mixed { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if ((Mixed::operator_lt(self, other as *const Mixed)) != 0) { + if ((Mixed::operator_lt((self as *const Self), (other as *const Self))) != 0) { std::cmp::Ordering::Less - } else if ((Mixed::operator_lt(other, self as *const Mixed)) != 0) { + } else if ((Mixed::operator_lt((other as *const Self), (self as *const Self))) != 0) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -144,7 +157,7 @@ impl std::cmp::PartialOrd for Mixed { } impl std::cmp::PartialEq for Mixed { fn eq(&self, other: &Self) -> bool { - unsafe { ((Mixed::operator_eq(self, other as *const Mixed)) != 0) } + unsafe { ((Mixed::operator_eq((self as *const Self), (other as *const Self))) != 0) } } } impl std::cmp::Eq for Mixed {} @@ -190,13 +203,19 @@ impl std::cmp::Ord for Boolish { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { if { - let __cmp = operator_lt_6(self.clone(), other.clone()); - MyBool::to_bool(&__cmp) + let __cmp = operator_lt_6( + (*(self as *const Self)).clone(), + (*(other as *const Self)).clone(), + ); + MyBool::to_bool((&raw const __cmp)) } { std::cmp::Ordering::Less } else if { - let __cmp = operator_lt_6(other.clone(), self.clone()); - MyBool::to_bool(&__cmp) + let __cmp = operator_lt_6( + (*(other as *const Self)).clone(), + (*(self as *const Self)).clone(), + ); + MyBool::to_bool((&raw const __cmp)) } { std::cmp::Ordering::Greater } else { @@ -214,8 +233,11 @@ impl std::cmp::PartialEq for Boolish { fn eq(&self, other: &Self) -> bool { unsafe { { - let __cmp = operator_eq_7(self.clone(), other.clone()); - MyBool::to_bool(&__cmp) + let __cmp = operator_eq_7( + (*(self as *const Self)).clone(), + (*(other as *const Self)).clone(), + ); + MyBool::to_bool((&raw const __cmp)) } } } @@ -284,17 +306,6 @@ impl RefInt { return &mut (*std::cell::LazyCell::force_mut(&mut *&raw mut ref_true_8)); } } -impl std::cmp::PartialEq for RefInt { - fn eq(&self, other: &Self) -> bool { - unsafe { - { - let __cmp = RefInt::operator_eq(self, other as *const RefInt); - RefBool::to_bool(&*__cmp) - } - } - } -} -impl std::cmp::Eq for RefInt {} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -308,25 +319,25 @@ unsafe fn main_0() -> i32 { assert!( ((unsafe { let _a: X = a; - operator_eq_1(_a, c) + operator_eq_2(_a, c) }) == (2)) ); assert!( ((unsafe { let _a: X = a; - operator_eq_1(_a, b) + operator_eq_2(_a, b) }) == (0)) ); assert!( ((unsafe { let _a: X = a; - operator_ne_2(_a, b) + operator_ne_0(_a, b) }) == (3)) ); assert!( ((unsafe { let _a: X = a; - operator_lt_0(_a, b) + operator_lt_1(_a, b) }) == (4)) ); assert!( @@ -454,7 +465,9 @@ unsafe fn main_0() -> i32 { (({ let mut __tmp_3 = { ris.as_mut_ptr().offset((2) as isize) }; let mut __it = ris.as_mut_ptr(); - while __it != __tmp_3 && *__it.iter_deref() != ri2 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &ri2) + { __it.iter_inc(); } __it @@ -462,6 +475,35 @@ unsafe fn main_0() -> i32 { ); return 0; } +impl WeaklyEqualityComparableWithUnsafe for Boolish { + unsafe fn equal(a: *const Self, b: *const Self) -> bool { + { + let __cmp = operator_eq_7((*a).clone(), (*b).clone()); + MyBool::to_bool((&raw const __cmp)) + } + } +} +impl WeaklyEqualityComparableWithUnsafe for Mixed { + unsafe fn equal(this: *const Self, o: *const Self) -> bool { + ((Mixed::operator_eq(this, o)) != 0) + } +} +impl WeaklyEqualityComparableWithUnsafe for RefInt { + unsafe fn equal(this: *const Self, _a0: *const Self) -> bool { + { + let __cmp = RefInt::operator_eq(this, _a0); + RefBool::to_bool((__cmp as *const _)) + } + } +} +impl WeaklyEqualityComparableWithUnsafe for X { + unsafe fn not_equal(a: *const Self, b: *const Self) -> bool { + ((operator_ne_0((*a).clone(), (*b).clone())) != 0) + } + unsafe fn equal(a: *const Self, b: *const Self) -> bool { + ((operator_eq_2((*a).clone(), (*b).clone())) != 0) + } +} pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const ref_true_8); } diff --git a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs index 8da1438508..50da53cb5e 100644 --- a/tests/unit/out/unsafe/operator_comparison_noncopyable.rs +++ b/tests/unit/out/unsafe/operator_comparison_noncopyable.rs @@ -6,10 +6,7 @@ use std::collections::BTreeMap; use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; -pub unsafe fn operator_eq_0(x: *const S, y: *const S) -> bool { - return (((*x).data_) == ((*y).data_)); -} -pub unsafe fn operator_lt_1(x: *const S, y: *const S) -> bool { +pub unsafe fn operator_lt_0(x: *const S, y: *const S) -> bool { return (((*x).data_) < ((*y).data_)); } #[repr(C)] @@ -34,9 +31,9 @@ impl S { impl std::cmp::Ord for S { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_1(self as *const S, other as *const S) { + if operator_lt_0((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_1(other as *const S, self as *const S) { + } else if operator_lt_0((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -51,7 +48,9 @@ impl std::cmp::PartialOrd for S { } impl std::cmp::PartialEq for S { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_0(self as *const S, other as *const S) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for S {} @@ -68,21 +67,26 @@ unsafe fn main_0() -> i32 { assert!( (unsafe { let _x: *const S = &a; - operator_eq_0(_x, &c) + WeaklyEqualityComparableWithUnsafe::equal(_x, &c) }) ); assert!( (unsafe { let _x: *const S = &a; - operator_lt_1(_x, &b) + operator_lt_0(_x, &b) }) ); assert!( !(unsafe { let _x: *const S = &b; - operator_lt_1(_x, &a) + operator_lt_0(_x, &a) }) ); return 0; } +impl WeaklyEqualityComparableWithUnsafe for S { + unsafe fn equal(x: *const S, y: *const S) -> bool { + return (((*x).data_) == ((*y).data_)); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_less_than.rs b/tests/unit/out/unsafe/operator_less_than.rs index 5bf2faffa5..54ee1f8bf2 100644 --- a/tests/unit/out/unsafe/operator_less_than.rs +++ b/tests/unit/out/unsafe/operator_less_than.rs @@ -30,9 +30,9 @@ impl Pair { impl std::cmp::Ord for Pair { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if Pair::operator_lt((&raw const *self).cast_mut(), other as *const Pair) { + if Pair::operator_lt((self as *const Self).cast_mut(), (other as *const Self)) { std::cmp::Ordering::Less - } else if Pair::operator_lt((&raw const *other).cast_mut(), self as *const Pair) { + } else if Pair::operator_lt((other as *const Self).cast_mut(), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -48,8 +48,8 @@ impl std::cmp::PartialOrd for Pair { impl std::cmp::PartialEq for Pair { fn eq(&self, other: &Self) -> bool { unsafe { - !(Pair::operator_lt((&raw const *self).cast_mut(), other as *const Pair)) - && !(Pair::operator_lt((&raw const *other).cast_mut(), self as *const Pair)) + !(Pair::operator_lt((self as *const Self).cast_mut(), (other as *const Self))) + && !(Pair::operator_lt((other as *const Self).cast_mut(), (self as *const Self))) } } } diff --git a/tests/unit/out/unsafe/operator_three_way.rs b/tests/unit/out/unsafe/operator_three_way.rs index 001ceea13f..3511bdd32b 100644 --- a/tests/unit/out/unsafe/operator_three_way.rs +++ b/tests/unit/out/unsafe/operator_three_way.rs @@ -30,13 +30,10 @@ impl S { } return libcc2rs::STRONG_ORDERING_EQUAL; } - pub unsafe fn operator_eq(this: *const Self, o: *const S) -> bool { - return (((*this).v) == ((*o).v)); - } } impl std::cmp::Ord for S { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { S::operator_cmp(self, other as *const S) } + unsafe { S::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for S { @@ -46,7 +43,9 @@ impl std::cmp::PartialOrd for S { } impl std::cmp::PartialEq for S { fn eq(&self, other: &Self) -> bool { - unsafe { S::operator_eq(self, other as *const S) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for S {} @@ -63,8 +62,13 @@ unsafe fn main_0() -> i32 { assert!((unsafe { S::operator_cmp(&raw const b, &a,) }) == std::cmp::Ordering::Greater); assert!((unsafe { S::operator_cmp(&raw const a, &b,) }) != std::cmp::Ordering::Greater); assert!((unsafe { S::operator_cmp(&raw const b, &a,) }) != std::cmp::Ordering::Less); - assert!(!(unsafe { S::operator_eq(&raw const a, &b,) })); + assert!(!(unsafe { WeaklyEqualityComparableWithUnsafe::equal(&raw const a, &b,) })); assert!((unsafe { S::operator_cmp(&raw const a, &b,) }) == libcc2rs::STRONG_ORDERING_LESS); return 0; } +impl WeaklyEqualityComparableWithUnsafe for S { + unsafe fn equal(this: *const Self, o: *const S) -> bool { + return (((*this).v) == ((*o).v)); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/operator_traits.rs b/tests/unit/out/unsafe/operator_traits.rs index c5e3127926..da0b07ce0f 100644 --- a/tests/unit/out/unsafe/operator_traits.rs +++ b/tests/unit/out/unsafe/operator_traits.rs @@ -28,9 +28,9 @@ impl Lt { impl std::cmp::Ord for Lt { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if Lt::operator_lt(self, other as *const Lt) { + if Lt::operator_lt((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if Lt::operator_lt(other, self as *const Lt) { + } else if Lt::operator_lt((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -46,8 +46,8 @@ impl std::cmp::PartialOrd for Lt { impl std::cmp::PartialEq for Lt { fn eq(&self, other: &Self) -> bool { unsafe { - !(Lt::operator_lt(self, other as *const Lt)) - && !(Lt::operator_lt(other, self as *const Lt)) + !(Lt::operator_lt((self as *const Self), (other as *const Self))) + && !(Lt::operator_lt((other as *const Self), (self as *const Self))) } } } @@ -66,17 +66,6 @@ impl std::cmp::Eq for Lt {} pub struct Eq { pub v: i32, } -impl Eq { - pub unsafe fn operator_eq(this: *const Self, o: *const Eq) -> bool { - return (((*this).v) == ((*o).v)); - } -} -impl std::cmp::PartialEq for Eq { - fn eq(&self, other: &Self) -> bool { - unsafe { Eq::operator_eq(self, other as *const Eq) } - } -} -impl std::cmp::Eq for Eq {} #[repr(C)] #[derive( Copy, @@ -95,13 +84,10 @@ impl Cmp { pub unsafe fn operator_cmp(this: *const Self, o: *const Cmp) -> std::cmp::Ordering { return std::cmp::Ord::cmp(&((*this).v), &((*o).v)); } - pub unsafe fn operator_eq(this: *const Self, o: *const Cmp) -> bool { - return (((*this).v) == ((*o).v)); - } } impl std::cmp::Ord for Cmp { fn cmp(&self, other: &Self) -> std::cmp::Ordering { - unsafe { Cmp::operator_cmp(self, other as *const Cmp) } + unsafe { Cmp::operator_cmp((self as *const Self), (other as *const Self)) } } } impl std::cmp::PartialOrd for Cmp { @@ -111,7 +97,9 @@ impl std::cmp::PartialOrd for Cmp { } impl std::cmp::PartialEq for Cmp { fn eq(&self, other: &Self) -> bool { - unsafe { Cmp::operator_eq(self, other as *const Cmp) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Cmp {} @@ -132,9 +120,9 @@ pub struct Free { impl std::cmp::Ord for Free { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_0(self as *const Free, other as *const Free) { + if operator_lt_0((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_0(other as *const Free, self as *const Free) { + } else if operator_lt_0((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -149,16 +137,15 @@ impl std::cmp::PartialOrd for Free { } impl std::cmp::PartialEq for Free { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_1(self as *const Free, other as *const Free) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Free {} pub unsafe fn operator_lt_0(a: *const Free, b: *const Free) -> bool { return (((*a).v) < ((*b).v)); } -pub unsafe fn operator_eq_1(a: *const Free, b: *const Free) -> bool { - return (((*a).v) == ((*b).v)); -} #[repr(C)] #[derive( Copy, @@ -207,7 +194,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { eqs.begin() }; let mut __tmp_2 = { eqs.end() }; let mut __it = (__tmp_1).clone(); - while __it != __tmp_2 && *__it.iter_deref() != two { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_2) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &two) + { __it.iter_inc(); } __it @@ -215,17 +204,20 @@ unsafe fn main_0() -> i32 { .iter_deref()) .v) == (2)) ); - assert!( - { + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ let mut __tmp_3 = { eqs.begin() }; let mut __tmp_4 = { eqs.end() }; let mut __it = (__tmp_3).clone(); - while __it != __tmp_4 && *__it.iter_deref() != nine { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_4) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &nine) + { __it.iter_inc(); } __it - } == eqs.end() - ); + }, + &eqs.end() + )); let mut cmps: Vec = Vec::from([Cmp { v: 3 }, Cmp { v: 1 }, Cmp { v: 2 }]); { let mut __tmp_5 = { cmps.begin() }; @@ -247,7 +239,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_6 = { cmps.begin() }; let mut __tmp_7 = { cmps.end() }; let mut __it = (__tmp_6).clone(); - while __it != __tmp_7 && *__it.iter_deref() != three { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_7) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &three) + { __it.iter_inc(); } __it @@ -276,7 +270,9 @@ unsafe fn main_0() -> i32 { let mut __tmp_9 = { frees.begin() }; let mut __tmp_10 = { frees.end() }; let mut __it = (__tmp_9).clone(); - while __it != __tmp_10 && *__it.iter_deref() != ftwo { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_10) + && !WeaklyEqualityComparableWithUnsafe::equal(&*__it.iter_deref(), &ftwo) + { __it.iter_inc(); } __it @@ -311,4 +307,19 @@ unsafe fn main_0() -> i32 { }; return 0; } +impl WeaklyEqualityComparableWithUnsafe for Cmp { + unsafe fn equal(this: *const Self, o: *const Cmp) -> bool { + return (((*this).v) == ((*o).v)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Eq { + unsafe fn equal(this: *const Self, o: *const Eq) -> bool { + return (((*this).v) == ((*o).v)); + } +} +impl WeaklyEqualityComparableWithUnsafe for Free { + unsafe fn equal(a: *const Free, b: *const Free) -> bool { + return (((*a).v) == ((*b).v)); + } +} pub unsafe fn __cpp2rust_init_globals() {} diff --git a/tests/unit/out/unsafe/push_emplace_back.rs b/tests/unit/out/unsafe/push_emplace_back.rs index a95c33594e..9e7ad99b5f 100644 --- a/tests/unit/out/unsafe/push_emplace_back.rs +++ b/tests/unit/out/unsafe/push_emplace_back.rs @@ -75,7 +75,7 @@ pub unsafe fn push_local_from_field_1(mut jpg: *mut JPEGData, mut cond: bool) { let mut __tmp_2 = { head.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = head.as_mut_ptr(); - while __it != __tmp_2 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_2) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -103,7 +103,7 @@ pub unsafe fn emplace_local_from_field_4(mut jpg: *mut JPEGData, mut cond: bool) let mut __tmp_3 = { head.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = head.as_mut_ptr(); - while __it != __tmp_3 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -251,7 +251,7 @@ pub unsafe fn emplace_from_element_14(mut v: *mut Vec>) { let mut __tmp_4 = { p.offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = p; - while __it != __tmp_4 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_4) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -318,7 +318,7 @@ pub unsafe fn emplace_from_sibling_18(mut s: *mut Bytes) { let mut __tmp_5 = { p.offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = p; - while __it != __tmp_5 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_5) { __v.push((*__it.iter_deref())); __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/sort_no_copy.rs b/tests/unit/out/unsafe/sort_no_copy.rs index 3ec644d0cc..13a3f86ea0 100644 --- a/tests/unit/out/unsafe/sort_no_copy.rs +++ b/tests/unit/out/unsafe/sort_no_copy.rs @@ -52,9 +52,9 @@ impl MoveAssignableUnsafe for Tracked { impl std::cmp::Ord for Tracked { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_1(self as *const Tracked, other as *const Tracked) { + if operator_lt_1((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_1(other as *const Tracked, self as *const Tracked) { + } else if operator_lt_1((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -70,8 +70,8 @@ impl std::cmp::PartialOrd for Tracked { impl std::cmp::PartialEq for Tracked { fn eq(&self, other: &Self) -> bool { unsafe { - !(operator_lt_1(self as *const Tracked, other as *const Tracked)) - && !(operator_lt_1(other as *const Tracked, self as *const Tracked)) + !(operator_lt_1((self as *const Self), (other as *const Self))) + && !(operator_lt_1((other as *const Self), (self as *const Self))) } } } @@ -116,9 +116,9 @@ impl MoveOnly { impl std::cmp::Ord for MoveOnly { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_3(self as *const MoveOnly, other as *const MoveOnly) { + if operator_lt_3((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_3(other as *const MoveOnly, self as *const MoveOnly) { + } else if operator_lt_3((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -134,8 +134,8 @@ impl std::cmp::PartialOrd for MoveOnly { impl std::cmp::PartialEq for MoveOnly { fn eq(&self, other: &Self) -> bool { unsafe { - !(operator_lt_3(self as *const MoveOnly, other as *const MoveOnly)) - && !(operator_lt_3(other as *const MoveOnly, self as *const MoveOnly)) + !(operator_lt_3((self as *const Self), (other as *const Self))) + && !(operator_lt_3((other as *const Self), (self as *const Self))) } } } @@ -164,9 +164,9 @@ impl DefaultConstructibleUnsafe for Bag { impl std::cmp::Ord for Bag { fn cmp(&self, other: &Self) -> std::cmp::Ordering { unsafe { - if operator_lt_4(self as *const Bag, other as *const Bag) { + if operator_lt_4((self as *const Self), (other as *const Self)) { std::cmp::Ordering::Less - } else if operator_lt_4(other as *const Bag, self as *const Bag) { + } else if operator_lt_4((other as *const Self), (self as *const Self)) { std::cmp::Ordering::Greater } else { std::cmp::Ordering::Equal @@ -181,16 +181,15 @@ impl std::cmp::PartialOrd for Bag { } impl std::cmp::PartialEq for Bag { fn eq(&self, other: &Self) -> bool { - unsafe { operator_eq_5(self as *const Bag, other as *const Bag) } + unsafe { + WeaklyEqualityComparableWithUnsafe::equal((self as *const Self), (other as *const Self)) + } } } impl std::cmp::Eq for Bag {} pub unsafe fn operator_lt_4(a: *const Bag, b: *const Bag) -> bool { return (((*a).items.len()) < ((*b).items.len())); } -pub unsafe fn operator_eq_5(a: *const Bag, b: *const Bag) -> bool { - return (((*a).items.len()) == ((*b).items.len())); -} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -465,26 +464,32 @@ unsafe fn main_0() -> i32 { && ((bag_vec[(2_usize)].items[(1_usize)].v) == (5)) ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); - assert!( - { + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ let mut __tmp_7 = { bag_vec.begin() }; let mut __tmp_8 = { bag_vec.end() }; let mut __it = (__tmp_7).clone(); - while __it != __tmp_8 && *__it.iter_deref() != bags[(1) as usize] { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_8) + && !WeaklyEqualityComparableWithUnsafe::equal( + &*__it.iter_deref(), + &bags[(1) as usize], + ) + { __it.iter_inc(); } __it - } == bag_vec.begin().iter_add(1_isize) - ); - assert!( - { + }, + &bag_vec.begin().iter_add(1_isize) + )); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &{ let mut __tmp_9 = { bag_vec.begin() }; let mut __tmp_10 = { bag_vec.end() }; let mut __best = __tmp_9.clone(); - if __tmp_9 != __tmp_10 { + if WeaklyEqualityComparableWithUnsafe::not_equal(&__tmp_9, &__tmp_10) { let mut __it = (__tmp_9).clone(); __it.iter_inc(); - while __it != __tmp_10 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_10) { if *__best.iter_deref() < *__it.iter_deref() { __best = __it.clone(); } @@ -492,8 +497,9 @@ unsafe fn main_0() -> i32 { } } __best - } == bag_vec.begin().iter_add(2_isize) - ); + }, + &bag_vec.begin().iter_add(2_isize) + )); assert!( (({ let __a: *const _ = &mut bags[(0) as usize]; @@ -521,7 +527,10 @@ unsafe fn main_0() -> i32 { || 0_i32, )) = 0; assert!((((*bag_map.find(&bags[(2) as usize]).iter_deref()).1) == (2))); - assert!(bag_map.find(&bags[(1) as usize]) == bag_map.end()); + assert!(WeaklyEqualityComparableWithUnsafe::equal( + &bag_map.find(&bags[(1) as usize]), + &bag_map.end() + )); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); let mut moves: Vec = Vec::new(); moves.push_mut({ @@ -601,6 +610,11 @@ unsafe fn main_0() -> i32 { ); return (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)); } +impl WeaklyEqualityComparableWithUnsafe for Bag { + unsafe fn equal(a: *const Bag, b: *const Bag) -> bool { + return (((*a).items.len()) == ((*b).items.len())); + } +} pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const copies_0); } diff --git a/tests/unit/out/unsafe/stdcopy.rs b/tests/unit/out/unsafe/stdcopy.rs index dc8489328d..1e589a8c48 100644 --- a/tests/unit/out/unsafe/stdcopy.rs +++ b/tests/unit/out/unsafe/stdcopy.rs @@ -40,7 +40,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_0 = { input.as_mut_ptr().offset((3) as isize) }; let mut __first = input.as_mut_ptr(); let mut __out = output.as_mut_ptr(); - while __first != __tmp_0 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &__tmp_0) { *__out.iter_deref() = (*__first.iter_deref()); __first.iter_inc(); __out.iter_inc(); @@ -52,7 +52,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { input.as_mut_ptr().offset((3) as isize) }; let mut __first = input.as_mut_ptr(); let mut __out = widened.begin(); - while __first != __tmp_1 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &__tmp_1) { *__out.iter_deref() = ((*__first.iter_deref()) as i64); __first.iter_inc(); __out.iter_inc(); @@ -74,7 +74,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_4 = { input.as_mut_ptr().offset((3) as isize) }; let mut __first = input.as_mut_ptr(); let mut __out = constructed.begin(); - while __first != __tmp_4 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &__tmp_4) { *__out.iter_deref() = >::cpp_from(__first.iter_deref()); __first.iter_inc(); __out.iter_inc(); @@ -88,7 +88,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_5 = { wide.as_mut_ptr().offset((2) as isize) }; let mut __first = wide.as_mut_ptr(); let mut __out = floating.begin(); - while __first != __tmp_5 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__first, &__tmp_5) { *__out.iter_deref() = ((*__first.iter_deref()) as f64); __first.iter_inc(); __out.iter_inc(); diff --git a/tests/unit/out/unsafe/vector.rs b/tests/unit/out/unsafe/vector.rs index 1e1283e461..9a5c15a49f 100644 --- a/tests/unit/out/unsafe/vector.rs +++ b/tests/unit/out/unsafe/vector.rs @@ -185,7 +185,7 @@ unsafe fn main_0() -> i32 { __tmp_7.iter_distance(&UnsafeRandomAccessIterator::Vec(v2.as_mut_ptr())) as usize; let mut __tmp = Vec::new(); let mut __it = (__tmp_8).clone(); - while __it != __tmp_9 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_9) { __tmp.push((*__it.iter_deref())); __it.iter_inc(); } @@ -509,7 +509,7 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp = Vec::new(); let mut __it = ints.as_mut_ptr(); - while __it != __tmp_20 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_20) { __tmp.push(((*__it.iter_deref()) as i64)); __it.iter_inc(); } @@ -530,7 +530,7 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp = Vec::new(); let mut __it = (__tmp_22).clone(); - while __it != __tmp_23 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_23) { __tmp.push(((*__it.iter_deref()) as i64)); __it.iter_inc(); } @@ -547,7 +547,7 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp = Vec::new(); let mut __it = ints.as_mut_ptr(); - while __it != __tmp_25 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_25) { __tmp.push(((*__it.iter_deref()) as f64)); __it.iter_inc(); } @@ -564,7 +564,7 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp = Vec::new(); let mut __it = ints.as_mut_ptr(); - while __it != __tmp_27 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_27) { __tmp.push(>::cpp_from(__it.iter_deref())); __it.iter_inc(); } @@ -581,7 +581,7 @@ unsafe fn main_0() -> i32 { as usize; let mut __tmp = Vec::new(); let mut __it = (__tmp_29).clone(); - while __it != __tmp_30 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_30) { __tmp.push((*__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 02864261d4..70957875b5 100644 --- a/tests/unit/out/unsafe/vector_iter_range_ctor.rs +++ b/tests/unit/out/unsafe/vector_iter_range_ctor.rs @@ -60,7 +60,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_0 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while __it != __tmp_0 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_0) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -75,7 +75,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_1 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while __it != __tmp_1 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_1) { __v.push(((*__it.iter_deref()) as u64)); __it.iter_inc(); } @@ -90,7 +90,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_2 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while __it != __tmp_2 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_2) { __v.push(((*__it.iter_deref()) as i32)); __it.iter_inc(); } @@ -103,7 +103,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_3 = { src1.as_ptr().add(src1.len()) }; let mut __v = Vec::new(); let mut __it = src1.as_ptr(); - while __it != __tmp_3 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_3) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -127,7 +127,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_5 = { start.offset((len) as isize) }; let mut __v = Vec::new(); let mut __it = start; - while __it != __tmp_5 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_5) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -162,7 +162,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_10 = { m.end() }; let mut __v = Vec::new(); let mut __it = (__tmp_9).clone(); - while __it != __tmp_10 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_10) { __v.push(<(i32, i32) as CppFromUnsafe<(i32, i32)>>::cpp_from( __it.iter_deref(), )); @@ -182,7 +182,7 @@ unsafe fn main_0() -> i32 { __tmp_11.iter_distance(&UnsafeRandomAccessIterator::Vec(v6.as_mut_ptr())) as usize; let mut __tmp = Vec::new(); let mut __it = (__tmp_12).clone(); - while __it != __tmp_13 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_13) { __tmp.push(<(i32, i32) as CppFromUnsafe<(i32, i32)>>::cpp_from( __it.iter_deref(), )); @@ -200,7 +200,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_14 = { ints.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = ints.as_mut_ptr(); - while __it != __tmp_14 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_14) { __v.push(>::cpp_from(__it.iter_deref())); __it.iter_inc(); } @@ -212,7 +212,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_15 = { readings.as_mut_ptr().offset((2) as isize) }; let mut __v = Vec::new(); let mut __it = readings.as_mut_ptr(); - while __it != __tmp_15 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_15) { __v.push(>::cpp_from(__it.iter_deref())); __it.iter_inc(); } diff --git a/tests/unit/out/unsafe/vector_with_allocator.rs b/tests/unit/out/unsafe/vector_with_allocator.rs index 34293aab10..fce95b321f 100644 --- a/tests/unit/out/unsafe/vector_with_allocator.rs +++ b/tests/unit/out/unsafe/vector_with_allocator.rs @@ -317,7 +317,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_16 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while __it != __tmp_16 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_16) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -332,7 +332,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_17 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while __it != __tmp_17 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_17) { __v.push(((*__it.iter_deref()) as u64)); __it.iter_inc(); } @@ -347,7 +347,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_18 = { src.as_mut_ptr().offset((3) as isize) }; let mut __v = Vec::new(); let mut __it = src.as_mut_ptr(); - while __it != __tmp_18 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_18) { __v.push(((*__it.iter_deref()) as i32)); __it.iter_inc(); } @@ -360,7 +360,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_19 = { src1.as_ptr().add(src1.len()) }; let mut __v = Vec::new(); let mut __it = src1.as_ptr(); - while __it != __tmp_19 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_19) { __v.push((*__it.iter_deref())); __it.iter_inc(); } @@ -378,7 +378,7 @@ unsafe fn main_0() -> i32 { let mut __tmp_20 = { start.offset((len) as isize) }; let mut __v = Vec::new(); let mut __it = start; - while __it != __tmp_20 { + while WeaklyEqualityComparableWithUnsafe::not_equal(&__it, &__tmp_20) { __v.push((*__it.iter_deref())); __it.iter_inc(); }