From 096cb9f5891f796aa487cb201479c074e1c0fdc3 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sun, 29 Nov 2026 18:44:05 +0000 Subject: [PATCH 01/18] Update tests --- .../out/refcount/cross_tu_tag_collision.rs | 2 +- .../out/refcount/defaulted_move_cross_tu.rs | 7 +- .../out/refcount/friend_operator.rs | 2 +- .../out/refcount/opaque_forward_decl.rs | 2 +- .../refcount/out_of_line_methods_cross_tu.rs | 6 +- .../template_method_late_instantiation.rs | 2 +- .../out/refcount/p14-class-in-two-files.rs | 6 +- .../p15-class-template-static-member.rs | 6 +- .../out/refcount/p15-function-template.rs | 8 +- .../out/refcount/p15-inline-function.rs | 4 +- .../out/refcount/p15-inline-variable.rs | 4 +- .../p16-default-argument-lambda-in-class.rs | 6 +- .../refcount/p16-lambda-in-inline-function.rs | 4 +- .../basic.link/out/refcount/basic.link.rs | 22 +- .../out/refcount/basic.scope.block.rs | 4 +- .../out/refcount/basic.scope.class.rs | 4 +- .../out/refcount/basic.scope.param.rs | 2 +- .../out/refcount/basic.scope.pdecl.rs | 4 +- .../out/refcount/basic.scope.scope.rs | 33 +- .../out/refcount/basic.start.term-p1-exit.rs | 2 +- .../out/refcount/basic.start.term.rs | 8 +- .../out/refcount/basic.types.general.rs | 4 +- tests/std/basic/out/refcount/basic.def.odr.rs | 26 +- .../out/refcount/class.conv.ctor.rs | 2 +- .../class.conv/out/refcount/class.conv.fct.rs | 2 +- .../out/refcount/class.copy.ctor.rs | 2 +- .../class.mem/out/refcount/class.free.rs | 4 +- .../out/refcount/class.mem.general.rs | 4 +- .../dcl.decl/dcl.init/dcl.init.general.cpp | 201 +++++++++ .../dcl.init/out/refcount/dcl.init.general.rs | 394 +++++++++++++++++- .../dcl.init/out/unsafe/dcl.init.general.rs | 343 +++++++++++++++ .../dcl.meaning/out/refcount/dcl.array.rs | 2 +- .../out/refcount/dcl.fct.default.rs | 8 +- .../dcl.meaning/out/refcount/dcl.mptr.rs | 11 +- tests/std/expr/conv/out/refcount/conv.mem.rs | 2 +- .../expr.post/out/refcount/expr.const.cast.rs | 2 +- ...nterpret.cast-p10-result-is-unspecified.rs | 4 +- .../out/refcount/expr.reinterpret.cast.rs | 8 +- .../expr.unary/out/refcount/expr.pre.incr.rs | 2 +- .../expr.unary/out/refcount/expr.unary.op.rs | 6 +- .../expr.compound/out/refcount/expr.cond.rs | 2 +- .../expr.compound/out/refcount/expr.eq.rs | 9 +- ...ptr.oper-p6-null-pointer-to-data-member.rs | 2 +- .../out/refcount/expr.mptr.oper.rs | 10 +- .../allocator.requirements.general.rs | 6 +- .../stmt.iter/out/refcount/stmt.while.rs | 8 +- .../stmt.select/out/refcount/stmt.if.rs | 2 +- .../stmt.select/out/refcount/stmt.switch.rs | 6 +- tests/std/temp/out/refcount/temp.type.rs | 8 +- .../temp/temp.spec/out/refcount/temp.inst.rs | 4 +- .../utility/out/refcount/forward-helpers.rs | 12 +- .../utilities/utility/out/refcount/forward.rs | 4 +- .../utility/out/refcount/utility.as.const.rs | 2 +- tests/ub/out/refcount/ctor_ref_member.rs | 2 +- .../refcount/self_referencing_initializer.rs | 2 +- tests/ub/out/refcount/ub6.rs | 2 +- tests/unit/out/refcount/05_new.rs | 4 +- tests/unit/out/refcount/10_struct.rs | 10 +- tests/unit/out/refcount/addr_of_global.rs | 4 +- tests/unit/out/refcount/anonymous-struct.rs | 18 +- tests/unit/out/refcount/anonymous-struct_c.rs | 18 +- tests/unit/out/refcount/anonymous_enum.rs | 4 +- tests/unit/out/refcount/anonymous_enum_c.rs | 4 +- tests/unit/out/refcount/any.rs | 2 +- tests/unit/out/refcount/array_const_init.rs | 6 +- tests/unit/out/refcount/array_field_addr.rs | 3 +- .../out/refcount/array_of_noncopy_struct.rs | 2 +- tests/unit/out/refcount/array_reference.rs | 2 +- tests/unit/out/refcount/as_const.rs | 2 +- tests/unit/out/refcount/assign_rhs_first.rs | 2 +- tests/unit/out/refcount/bounded_struct_ptr.rs | 2 +- tests/unit/out/refcount/bst.rs | 2 +- tests/unit/out/refcount/c_struct.rs | 10 +- tests/unit/out/refcount/cast.rs | 12 +- .../refcount/cast_array_to_pointer_decay.rs | 3 +- tests/unit/out/refcount/class.rs | 8 +- .../refcount/class_template_lazy_member.rs | 10 +- tests/unit/out/refcount/class_templates.rs | 30 +- tests/unit/out/refcount/clone_vs_move.rs | 7 +- tests/unit/out/refcount/comma_operator.rs | 2 +- tests/unit/out/refcount/complex_function.rs | 8 +- .../out/refcount/compound_assign_paren.rs | 2 +- tests/unit/out/refcount/concepts.rs | 2 +- tests/unit/out/refcount/constexpr_function.rs | 4 +- tests/unit/out/refcount/constructor.rs | 6 +- .../refcount/container_element_receiver.rs | 2 +- .../unit/out/refcount/container_field_addr.rs | 4 +- .../conversion_operator_same_translation.rs | 4 +- tests/unit/out/refcount/copy_assign.rs | 14 +- tests/unit/out/refcount/copy_ctor.rs | 17 +- .../unit/out/refcount/copy_move_defaulted.rs | 55 ++- tests/unit/out/refcount/copy_move_deleted.rs | 12 +- tests/unit/out/refcount/default.rs | 12 +- .../refcount/default_function_arguments.rs | 4 +- tests/unit/out/refcount/default_in_statics.rs | 7 +- tests/unit/out/refcount/delete_array_order.rs | 2 +- tests/unit/out/refcount/destructor.rs | 23 +- tests/unit/out/refcount/destructor_params.rs | 4 +- .../out/refcount/destructor_temporaries.rs | 4 +- tests/unit/out/refcount/doubly_linked_list.rs | 2 +- .../out/refcount/enum_default_in_static.rs | 2 +- tests/unit/out/refcount/enum_int_interop.rs | 2 +- tests/unit/out/refcount/enum_int_interop_c.rs | 2 +- .../unit/out/refcount/enum_underlying_type.rs | 2 +- tests/unit/out/refcount/exprs.rs | 4 +- tests/unit/out/refcount/fft.rs | 2 +- tests/unit/out/refcount/field_aliasing.rs | 7 +- .../unit/out/refcount/field_array_elem_ptr.rs | 6 +- .../out/refcount/field_method_receiver.rs | 5 +- tests/unit/out/refcount/field_pointers.rs | 9 +- .../field_pointers_malloced_struct.rs | 2 +- .../field_reinterpret_write_through.rs | 6 +- tests/unit/out/refcount/find.rs | 2 +- .../refcount/first_field_ptr_covers_struct.rs | 4 +- .../out/refcount/first_member_downcast.rs | 4 +- .../refcount/flex_array_member_incomplete.rs | 3 +- .../flex_array_member_sibling_write.rs | 8 +- tests/unit/out/refcount/fn_ptr.rs | 2 +- tests/unit/out/refcount/fn_ptr_cast.rs | 2 +- tests/unit/out/refcount/fn_ptr_stable_sort.rs | 2 +- tests/unit/out/refcount/fn_ptr_struct.rs | 6 +- .../unit/out/refcount/fn_ptr_typedef_cast.rs | 2 +- tests/unit/out/refcount/fn_ptr_vtable.rs | 2 +- tests/unit/out/refcount/fn_ref.rs | 2 +- .../unit/out/refcount/for_body_destructor.rs | 2 +- .../refcount/foreach_disjoint_field_borrow.rs | 4 +- tests/unit/out/refcount/forward_basic.rs | 6 +- tests/unit/out/refcount/forward_decltype.rs | 2 +- tests/unit/out/refcount/forward_explicit.rs | 2 +- tests/unit/out/refcount/forward_pack.rs | 4 +- tests/unit/out/refcount/friend.rs | 8 +- .../unit/out/refcount/function_overloading.rs | 2 +- .../out/refcount/global_call_temporaries.rs | 2 +- .../out/refcount/global_init_side_effect.rs | 2 +- .../out/refcount/global_non_const_init.rs | 6 +- tests/unit/out/refcount/global_pointers.rs | 2 +- .../refcount/global_without_initializer.rs | 2 +- .../out/refcount/goto_aggregate_default.rs | 2 +- tests/unit/out/refcount/goto_cleanup.rs | 2 +- tests/unit/out/refcount/huffman.rs | 4 +- .../refcount/immutable-deref-on-func-call.rs | 2 +- tests/unit/out/refcount/implicit_autoref.rs | 4 +- .../refcount/in_class_field_initializer.rs | 6 +- tests/unit/out/refcount/init.rs | 2 +- tests/unit/out/refcount/init_list.rs | 6 +- .../out/refcount/inline_container_fields.rs | 11 +- tests/unit/out/refcount/kruskal.rs | 6 +- tests/unit/out/refcount/lambda_as_field.rs | 10 +- .../out/refcount/lambda_capture_copy_ctor.rs | 4 +- tests/unit/out/refcount/lambda_capture_ref.rs | 2 +- .../out/refcount/lambda_capture_star_this.rs | 2 +- .../unit/out/refcount/lambda_capture_this.rs | 2 +- .../unit/out/refcount/lambda_capture_value.rs | 2 +- .../unit/out/refcount/lambda_decltype_type.rs | 6 +- .../refcount/lambda_generic_explicit_args.rs | 2 +- .../out/refcount/lambda_immediate_init.rs | 2 +- .../out/refcount/lambda_move_only_capture.rs | 4 +- tests/unit/out/refcount/lambda_nested.rs | 2 +- .../unit/out/refcount/lambda_static_local.rs | 2 +- .../refcount/libc_struct_without_default.rs | 5 +- tests/unit/out/refcount/linked_list.rs | 2 +- .../refcount/local_anon_struct_collision.rs | 4 +- .../out/refcount/local_record_template.rs | 8 +- tests/unit/out/refcount/map.rs | 2 +- tests/unit/out/refcount/map_key_copy_ctor.rs | 2 +- tests/unit/out/refcount/map_key_identity.rs | 4 +- tests/unit/out/refcount/map_try_emplace.rs | 4 +- .../out/refcount/map_try_emplace_lvalues.rs | 13 +- tests/unit/out/refcount/max.rs | 2 +- .../unit/out/refcount/memcpy_struct_bytes.rs | 2 +- .../out/refcount/memcpy_struct_layouts.rs | 11 +- .../unit/out/refcount/memcpy_struct_struct.rs | 2 +- tests/unit/out/refcount/memset_struct_tail.rs | 3 +- tests/unit/out/refcount/move_assign.rs | 6 +- tests/unit/out/refcount/move_ctor.rs | 8 +- tests/unit/out/refcount/move_this.rs | 2 +- tests/unit/out/refcount/nested_structs.rs | 12 +- tests/unit/out/refcount/new.rs | 2 +- tests/unit/out/refcount/new_bst.rs | 2 +- tests/unit/out/refcount/new_struct.rs | 4 +- .../refcount/nttp_distinct_specializations.rs | 6 +- tests/unit/out/refcount/offsetof.rs | 5 +- .../unit/out/refcount/opaque_forward_decl.rs | 2 +- tests/unit/out/refcount/opaque_record_copy.rs | 4 +- .../unit/out/refcount/opaque_then_defined.rs | 4 +- .../out/refcount/operator_arithmetic_free.rs | 2 +- .../refcount/operator_arithmetic_member.rs | 2 +- .../out/refcount/operator_bitwise_free.rs | 2 +- .../out/refcount/operator_bitwise_member.rs | 2 +- .../refcount/operator_comparison_defaulted.rs | 16 +- .../out/refcount/operator_comparison_free.rs | 4 +- .../refcount/operator_comparison_member.rs | 2 +- .../out/refcount/operator_comparison_mixed.rs | 2 +- .../refcount/operator_comparison_nonbool.rs | 16 +- .../operator_comparison_noncopyable.rs | 2 +- .../operator_compound_assignment_free.rs | 2 +- .../operator_compound_assignment_member.rs | 2 +- tests/unit/out/refcount/operator_friend.rs | 14 +- tests/unit/out/refcount/operator_less_than.rs | 2 +- .../out/refcount/operator_logical_free.rs | 2 +- .../out/refcount/operator_logical_member.rs | 2 +- .../refcount/operator_member_pointer_free.rs | 5 +- .../operator_member_pointer_member.rs | 7 +- .../unit/out/refcount/operator_other_free.rs | 2 +- .../out/refcount/operator_other_member.rs | 4 +- tests/unit/out/refcount/operator_overloads.rs | 2 +- .../unit/out/refcount/operator_qualifiers.rs | 2 +- tests/unit/out/refcount/operator_three_way.rs | 2 +- tests/unit/out/refcount/operator_traits.rs | 10 +- tests/unit/out/refcount/overload_mangling.rs | 6 +- .../refcount/pair_converting_construction.rs | 20 +- tests/unit/out/refcount/pod.rs | 2 +- tests/unit/out/refcount/pointer_array.rs | 3 +- tests/unit/out/refcount/pointers.rs | 2 +- tests/unit/out/refcount/polymorphism.rs | 4 +- tests/unit/out/refcount/ptr_cast_init.rs | 4 +- tests/unit/out/refcount/push_emplace_back.rs | 18 +- tests/unit/out/refcount/random.rs | 6 +- tests/unit/out/refcount/reference_wrapper.rs | 2 +- tests/unit/out/refcount/references.rs | 5 +- tests/unit/out/refcount/refs_as_args.rs | 2 +- .../out/refcount/reinterpret_cast_ptr_cmp.rs | 8 +- .../out/refcount/reinterpret_cast_struct.rs | 2 +- .../reinterpret_cast_struct_to_struct.rs | 4 +- tests/unit/out/refcount/reserved_keywords.rs | 6 +- tests/unit/out/refcount/return_move.rs | 4 +- tests/unit/out/refcount/rule_of_five.rs | 12 +- tests/unit/out/refcount/rule_of_three.rs | 5 +- .../unit/out/refcount/rvalue_rule_arg_move.rs | 4 +- tests/unit/out/refcount/rvalue_struct.rs | 2 +- .../scalar_builtin_construct_destruct.rs | 2 +- .../refcount/self_referencing_initializer.rs | 6 +- .../unit/out/refcount/size_t_static_member.rs | 4 +- .../out/refcount/size_t_template_param.rs | 4 +- tests/unit/out/refcount/sort_no_copy.rs | 12 +- tests/unit/out/refcount/static_local.rs | 2 +- .../unit/out/refcount/static_var_in_class.rs | 4 +- tests/unit/out/refcount/stdcopy.rs | 2 +- tests/unit/out/refcount/strdup.rs | 2 +- .../out/refcount/string_literal_ptr_init.rs | 2 +- tests/unit/out/refcount/string_substr.rs | 2 +- .../out/refcount/struct_2d_array_field.rs | 3 +- tests/unit/out/refcount/struct_ctor.rs | 6 +- .../unit/out/refcount/struct_default_ctor.rs | 9 +- .../refcount/struct_member_array_adjacency.rs | 4 +- tests/unit/out/refcount/struct_ptr.rs | 2 +- .../refcount/structured_binding_copy_ctor.rs | 2 +- .../structured_binding_element_ctor.rs | 4 +- .../refcount/structured_binding_move_ctor.rs | 6 +- .../refcount/structured_binding_range_for.rs | 2 +- .../out/refcount/structured_binding_ref.rs | 2 +- .../refcount/structured_binding_trivial.rs | 2 +- tests/unit/out/refcount/swap_map_no_copy.rs | 46 +- .../refcount/tag_vs_identifier_collision.rs | 16 +- .../unit/out/refcount/template_default_arg.rs | 8 +- .../out/refcount/template_static_member.rs | 10 +- .../unit/out/refcount/temporary_field_addr.rs | 7 +- .../out/refcount/temporary_field_ctor_arg.rs | 6 +- .../out/refcount/temporary_field_two_args.rs | 8 +- tests/unit/out/refcount/this.rs | 4 +- .../unit/out/refcount/typedef-anon-struct.rs | 6 +- .../out/refcount/unary_expr_or_type_trait.rs | 2 +- tests/unit/out/refcount/unboxed_locals.rs | 4 +- tests/unit/out/refcount/unboxed_records.rs | 7 +- .../out/refcount/union_addrof_external.rs | 8 +- tests/unit/out/refcount/union_basic.rs | 12 +- .../unit/out/refcount/union_cross_arm_cast.rs | 11 +- .../out/refcount/union_field_alignment.rs | 5 +- .../out/refcount/union_flex_array_member.rs | 5 +- .../unit/out/refcount/union_memset_memcpy.rs | 11 +- tests/unit/out/refcount/union_nested.rs | 13 +- .../out/refcount/union_pointer_pun_address.rs | 7 +- .../union_pointer_pun_writethrough.rs | 3 +- .../out/refcount/union_struct_dual_use.rs | 7 +- .../out/refcount/union_tagged_many_arms.rs | 5 +- .../unit/out/refcount/union_tagged_simple.rs | 5 +- .../out/refcount/union_tagged_struct_arms.rs | 11 +- .../refcount/union_void_ptr_sized_deref.rs | 5 +- tests/unit/out/refcount/unique_ptr.rs | 4 +- .../out/refcount/unique_ptr_const_deref.rs | 2 +- .../out/refcount/unique_ptr_field_reset.rs | 4 +- tests/unit/out/refcount/unique_ptr_nested.rs | 4 +- tests/unit/out/refcount/unique_ptr_struct.rs | 2 +- tests/unit/out/refcount/va_arg_mixed_types.rs | 2 +- .../out/refcount/va_arg_non_primitive_ptrs.rs | 2 +- tests/unit/out/refcount/va_arg_struct_ctx.rs | 5 +- tests/unit/out/refcount/va_arg_void_ptr.rs | 2 +- tests/unit/out/refcount/va_list_field.rs | 6 +- tests/unit/out/refcount/vector.rs | 6 +- .../out/refcount/vector_iter_range_ctor.rs | 4 +- .../out/refcount/vector_subscript_direct.rs | 6 +- .../out/refcount/vector_with_allocator.rs | 4 +- tests/unit/out/refcount/void_cast.rs | 8 +- 293 files changed, 1860 insertions(+), 685 deletions(-) diff --git a/tests/multi-file/cross_tu_tag_collision/out/refcount/cross_tu_tag_collision.rs b/tests/multi-file/cross_tu_tag_collision/out/refcount/cross_tu_tag_collision.rs index 9201e1a89c..e1598f3b78 100644 --- a/tests/multi-file/cross_tu_tag_collision/out/refcount/cross_tu_tag_collision.rs +++ b/tests/multi-file/cross_tu_tag_collision/out/refcount/cross_tu_tag_collision.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct widget { #[offset(0)] 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 d1300b878b..8e99a88e15 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 @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, CppFrom, MoveAssign)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom, MoveAssign)] #[cpp_from(i32, new, value)] #[byte_size(32)] pub struct S { @@ -15,6 +15,7 @@ pub struct S { pub v: Vec, #[offset(24)] #[byte_size(8)] + #[array_len(2)] pub n: Box<[i32]>, } impl S { @@ -43,7 +44,9 @@ impl Default for S { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, +)] #[byte_size(24)] pub struct T { #[offset(0)] 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 81b539028a..b463624f0b 100644 --- a/tests/multi-file/friend_operator/out/refcount/friend_operator.rs +++ b/tests/multi-file/friend_operator/out/refcount/friend_operator.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct S { #[offset(0)] diff --git a/tests/multi-file/opaque_forward_decl/out/refcount/opaque_forward_decl.rs b/tests/multi-file/opaque_forward_decl/out/refcount/opaque_forward_decl.rs index 00e8b7f8bd..d0dba51dc5 100644 --- a/tests/multi-file/opaque_forward_decl/out/refcount/opaque_forward_decl.rs +++ b/tests/multi-file/opaque_forward_decl/out/refcount/opaque_forward_decl.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct container { #[offset(0)] diff --git a/tests/multi-file/out_of_line_methods_cross_tu/out/refcount/out_of_line_methods_cross_tu.rs b/tests/multi-file/out_of_line_methods_cross_tu/out/refcount/out_of_line_methods_cross_tu.rs index 5ebfc5a606..3d37d8acd3 100644 --- a/tests/multi-file/out_of_line_methods_cross_tu/out/refcount/out_of_line_methods_cross_tu.rs +++ b/tests/multi-file/out_of_line_methods_cross_tu/out/refcount/out_of_line_methods_cross_tu.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -16,14 +16,14 @@ impl S {} pub trait Base { fn apply(&mut self, x: i32) -> i32; } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Derived { #[offset(8)] pub factor: i32, } impl Derived {} -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Pair { #[offset(0)] 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 d7c1724f96..a43e8c01ad 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 @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct S_int_ { #[offset(0)] diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/refcount/p14-class-in-two-files.rs index 34f713292b..668fe631fa 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 @@ -18,7 +18,7 @@ thread_local!( thread_local!( pub static useCount_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructor)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -67,7 +67,7 @@ impl Default for LifetimeTracked { { LifetimeTracked::new() } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -91,7 +91,7 @@ thread_local!( __static }; ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct HasInlineMembers {} impl HasInlineMembers { 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 d2ffb7060e..a0f11971f3 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 @@ -18,7 +18,7 @@ thread_local!( thread_local!( pub static useCount_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructor)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -76,7 +76,7 @@ thread_local!( __static }; ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct HasStaticMember_int_ {} thread_local!( @@ -88,7 +88,7 @@ thread_local!( __static }; ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct HasStaticMember_long_ {} pub fn main() { 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 dd6c90c7ef..4d567cb70d 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 @@ -18,7 +18,7 @@ thread_local!( thread_local!( pub static useCount_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructor)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -67,7 +67,7 @@ impl Default for LifetimeTracked { { LifetimeTracked::new() } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -139,7 +139,7 @@ fn main_0() -> i32 { assert!((ctorCount_0.with(|rc| *rc.borrow()) == 4)); return 0; } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct S_14 {} pub fn count_18() -> i32 { @@ -164,7 +164,7 @@ pub fn b_count_long_17() -> i32 { pub fn b_count_local_15() -> i32 { return ({ count_18() }); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct S_21 {} pub trait AssertsDtorCountAtExitImpl { 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 01e84bfcb3..b006b15296 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 @@ -18,7 +18,7 @@ thread_local!( thread_local!( pub static useCount_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructor)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -67,7 +67,7 @@ impl Default for LifetimeTracked { { LifetimeTracked::new() } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] 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 21b612eed3..4afe7c452a 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 @@ -18,7 +18,7 @@ thread_local!( thread_local!( pub static useCount_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructor)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -67,7 +67,7 @@ impl Default for LifetimeTracked { { LifetimeTracked::new() } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] 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 da9dce2d90..3a717d7f1d 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 @@ -18,7 +18,7 @@ thread_local!( thread_local!( pub static useCount_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructor)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -67,13 +67,13 @@ impl Default for LifetimeTracked { { LifetimeTracked::new() } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] pub expected: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct X {} thread_local!( 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 98847588b6..604938b021 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 @@ -18,7 +18,7 @@ thread_local!( thread_local!( pub static useCount_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructor)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -67,7 +67,7 @@ impl Default for LifetimeTracked { { LifetimeTracked::new() } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] 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 4209c9f144..41793dcac4 100644 --- a/tests/std/basic/basic.link/out/refcount/basic.link.rs +++ b/tests/std/basic/basic.link/out/refcount/basic.link.rs @@ -29,11 +29,12 @@ pub fn test_11() { assert!((ceiling_10.with(|rc| *rc.borrow()) == 40)); assert!(((ceiling_10.with(|v| v.as_pointer())) == ({ ceiling_address_in_b_12() }))); } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(4)] pub struct anon_13 { #[offset(0)] #[byte_size(4)] + #[array_len(4)] __bytes: Box<[u8]>, } impl anon_13 { @@ -66,7 +67,7 @@ thread_local!( pub fn bump_18() -> i32 { return (*(*counter_17.with(Value::clone).borrow_mut()).prefix_inc()); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct Record_19 { #[offset(0)] @@ -102,7 +103,7 @@ pub fn test_29() { level_28.with(|rc| *rc.borrow_mut() = 10); assert!((({ raise_30(1,) }) == 11)); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct Tally_31 {} thread_local!( @@ -114,7 +115,7 @@ pub fn test_33() { assert!((({ add_in_b_34(1,) }) == 102)); assert!((total_32.with(|rc| *rc.borrow()) == 11)); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct p5_members_of_class_with_external_linkage_Ledger {} pub fn test_36() { @@ -182,7 +183,7 @@ pub fn test_55() { assert!((({ second_key_plus_value_53() }) == 32)); assert!((({ key_in_b_56() }) == 400)); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct Entry_52 { #[offset(0)] @@ -193,7 +194,7 @@ impl Default for Entry_52 { { Entry_52 { key: 1 } } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(8)] pub struct Entry_54 { #[offset(0)] @@ -265,11 +266,12 @@ thread_local!( pub fn ceiling_address_in_b_12() -> Ptr { return (ceiling_10.with(|v| v.as_pointer())); } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(4)] pub struct anon_62 { #[offset(0)] #[byte_size(4)] + #[array_len(4)] __bytes: Box<[u8]>, } impl anon_62 { @@ -302,7 +304,7 @@ thread_local!( pub fn bump_64() -> i32 { return (*(*counter_63.with(Value::clone).borrow_mut()).prefix_inc()); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(16)] pub struct Record_65 { #[offset(0)] @@ -346,7 +348,7 @@ pub fn raise_30(mut by: i32) -> i32 { level_28.with(|rc| *rc.borrow_mut() += by); return level_28.with(|rc| *rc.borrow()); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct Tally_67 {} thread_local!( @@ -388,7 +390,7 @@ pub fn key_in_b_56() -> i32 { let mut entry: Entry_71 = ::default(); return (entry.key as i32); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(8)] pub struct Entry_71 { #[offset(0)] 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 fbd6e1813e..2265d0824a 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 @@ -18,7 +18,7 @@ thread_local!( thread_local!( pub static useCount_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructor)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -76,7 +76,7 @@ thread_local!( thread_local!( pub static dtorCount_6: Value = Rc::new(RefCell::new(0)); ); -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(4)] pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { #[offset(0)] 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 0295466ed9..dd3976bde2 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 @@ -9,7 +9,7 @@ use std::rc::{Rc, Weak}; thread_local!( pub static balance_0: Value = Rc::new(RefCell::new(50)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct p1_member_hides_namespace_variable_HasBalance { #[offset(0)] @@ -45,7 +45,7 @@ pub fn test_1() { thread_local!( pub static initial_2: Value = Rc::new(RefCell::new(100)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct p1_out_of_class_definition_is_in_class_scope_HasStaticTotal { #[offset(0)] diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.param.rs index d8f5431317..3b3a3849d2 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 @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { 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 f8e290e42e..fced9b524c 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 @@ -18,7 +18,7 @@ pub fn test_0() { } assert!((level == 5)); } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct p1_own_address_in_initializer_SelfLinked { #[offset(0)] @@ -73,7 +73,7 @@ pub fn test_3() { pub type anon_4 = u32; pub const anon_4_limit: anon_4 = 13; pub const anon_4_above: anon_4 = 14; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(8)] pub struct p9_func_declared_before_function_body_RecordsConstructorName { #[offset(0)] diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.scope.rs index 12fdc93cd7..20120f1ead 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 @@ -44,7 +44,7 @@ pub const p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_small: p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size = 3; pub const p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size_large: p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum_Size = 8; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct p2_11_unscoped_enumerator_in_both_scopes_HasUnscopedEnum {} pub fn test_5() { @@ -72,7 +72,7 @@ pub fn test_5() { thread_local!( pub static count_6: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct p2_12_class_name_in_own_scope_HasStaticCounter {} impl p2_12_class_name_in_own_scope_HasStaticCounter { @@ -88,11 +88,12 @@ pub fn test_7() { count_6.with(|rc| *rc.borrow_mut() = 6); assert!((count_6.with(|rc| *rc.borrow()) == 6)); } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_8 { #[offset(0)] #[byte_size(8)] + #[array_len(8)] __bytes: Box<[u8]>, } impl anon_8 { @@ -113,11 +114,12 @@ impl Default for anon_8 { thread_local!( pub static anon_8: Value = Rc::new(RefCell::new(::default())); ); -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_9 { #[offset(0)] #[byte_size(8)] + #[array_len(8)] __bytes: Box<[u8]>, } impl anon_9 { @@ -135,7 +137,7 @@ impl Default for anon_9 { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct p2_13_anonymous_union_members_in_parent_scope_HasAnonymousUnion { #[offset(0)] @@ -171,11 +173,12 @@ pub fn test_10() { anon_11::block_ratio(anon_11.as_pointer()).write(0.75_f64); assert!(((anon_11::block_ratio(anon_11.as_pointer()).read()) == 0.75_f64)); } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_11 { #[offset(0)] #[byte_size(8)] + #[array_len(8)] __bytes: Box<[u8]>, } impl anon_11 { @@ -193,7 +196,7 @@ impl Default for anon_11 { } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(8)] pub struct p3_2_const_qualified_member_is_distinct_HasConstOverload { #[offset(0)] @@ -237,7 +240,7 @@ thread_local!( thread_local!( pub static rvalue_calls_14: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct p3_2_explicit_object_and_rvalue_members_are_distinct_HasExplicitObjectOverload { #[offset(0)] @@ -279,7 +282,7 @@ thread_local!( thread_local!( pub static rvalue_calls_17: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct p3_2_ref_qualified_members_are_distinct_HasRefQualifiedOverloads {} pub fn test_18() { @@ -317,7 +320,7 @@ pub fn test_18() { assert!((lvalue_calls_16.with(|rc| *rc.borrow()) == 1)); assert!((rvalue_calls_17.with(|rc| *rc.borrow()) == 2)); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(8)] pub struct p3_4_const_qualified_member_templates_are_distinct_HasConstTemplateOverload { #[offset(0)] @@ -364,7 +367,7 @@ thread_local!( thread_local!( pub static rvalue_calls_21: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct p3_4_ref_qualified_member_templates_are_distinct_HasRefQualifiedTemplateOverloads {} pub fn test_22() { @@ -394,14 +397,14 @@ pub fn test_22() { thread_local!( pub static friend_calls_23: Value = Rc::new(RefCell::new(0_i32)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct p4_friend_definition_defines_earlier_friend_declaration_DeclaresFriend {} pub fn shared_friend_24() -> i32 { (*friend_calls_23.with(Value::clone).borrow_mut()).prefix_inc(); return 7; } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct p4_friend_definition_defines_earlier_friend_declaration_DefinesFriend {} pub fn test_25() { @@ -433,7 +436,7 @@ pub fn test_30() { thread_local!( pub static function_calls_31: Value = Rc::new(RefCell::new(0_i32)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct p4_2_class_and_function_share_name_Reading { #[offset(0)] @@ -451,7 +454,7 @@ pub fn test_33() { assert!((({ Reading_32(reading.value,) }) == 5)); assert!((function_calls_31.with(|rc| *rc.borrow()) == 1)); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct p4_2_class_and_variable_share_name_Limit { #[offset(0)] 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 5a113e0ba4..49ea73f73e 100644 --- a/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs +++ b/tests/std/basic/basic.start/out/refcount/basic.start.term-p1-exit.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(4)] pub struct Tracker { #[offset(0)] diff --git a/tests/std/basic/basic.start/out/refcount/basic.start.term.rs b/tests/std/basic/basic.start/out/refcount/basic.start.term.rs index 20053fe17b..e02f70ba85 100644 --- a/tests/std/basic/basic.start/out/refcount/basic.start.term.rs +++ b/tests/std/basic/basic.start/out/refcount/basic.start.term.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(4)] pub struct Tracker { #[offset(0)] @@ -19,14 +19,14 @@ impl Tracker { __this } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(4)] pub struct HoldsTracker { #[offset(0)] #[byte_size(4)] pub member: Tracker, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct TriviallyDestructible { #[offset(0)] @@ -97,7 +97,7 @@ thread_local!( pub static trivial_9: Value = Rc::new(RefCell::new(TriviallyDestructible { value: 6 })); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct p3_reverse_completion_order_WithStaticMember {} thread_local!( diff --git a/tests/std/basic/basic.types/out/refcount/basic.types.general.rs b/tests/std/basic/basic.types/out/refcount/basic.types.general.rs index 14d1147933..d50e4c91c2 100644 --- a/tests/std/basic/basic.types/out/refcount/basic.types.general.rs +++ b/tests/std/basic/basic.types/out/refcount/basic.types.general.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct p2_pointer_to_data_member_bytes_round_trip_HasTwoInts { #[offset(0)] @@ -69,7 +69,7 @@ pub fn test_0() { }; assert!(({ ((*null_pm.borrow()) == -1_isize) })); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct p3_pointer_to_data_member_bytes_copied_to_other_object_HasTwoInts { #[offset(0)] diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index 66705328fd..d9a5246510 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -9,7 +9,7 @@ use std::rc::{Rc, Weak}; thread_local!( pub static copyCount_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct HasConstexprCtor { @@ -50,7 +50,7 @@ thread_local!( thread_local!( pub static useCount_4: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructor)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -180,7 +180,7 @@ thread_local!( pub trait p4_1_pure_virtual_without_definition_HasPureVirtual { fn f(&mut self); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct p4_1_pure_virtual_without_definition_OverridesPureVirtual {} pub fn test_11() { @@ -279,7 +279,7 @@ pub fn test_17() { thread_local!( pub static copies_18: Value = Rc::new(RefCell::new(0_i32)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] #[cpp_from(i32, new, value)] #[byte_size(8)] pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { @@ -336,7 +336,9 @@ pub fn test_19() { assert!(({ (({ (*f.borrow()).call() }) == 5) })); assert!((copies_18.with(|rc| *rc.borrow()) == 1)); } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructor, Default, +)] #[byte_size(8)] pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { #[offset(0)] @@ -367,7 +369,7 @@ pub fn test_20() { assert!((copyCount_2.with(|rc| *rc.borrow()) == 0)); assert!((useCount_4.with(|rc| *rc.borrow()) == 0)); } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructor)] #[byte_size(8)] pub struct p7_member_access_captures_this_HasMemberUsedInLambda { #[offset(0)] @@ -403,7 +405,9 @@ pub fn test_22() { assert!(({ ({ (*c.borrow()).x.uses } == 2) })); assert!((copyCount_2.with(|rc| *rc.borrow()) == 0)); } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructor, Default, +)] #[byte_size(4)] pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { #[offset(0)] @@ -448,7 +452,7 @@ pub fn test_26() { thread_local!( pub static t_ctors_27: Value = Rc::new(RefCell::new(0_i32)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(1)] pub struct p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} impl p9_destructor_not_potentially_invoked_HasUndefinedDestructor { @@ -472,7 +476,7 @@ pub fn test_28() { thread_local!( pub static ctor_calls_29: Value = Rc::new(RefCell::new(0_i32)); ); -#[derive(Record, ByteRepr, FnPtrArg)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg)] #[byte_size(4)] pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { #[offset(0)] @@ -503,7 +507,7 @@ pub fn test_31() { thread_local!( pub static m_ctors_32: Value = Rc::new(RefCell::new(0_i32)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(1)] pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} impl p9_unused_implicit_assignment_HasUndefinedCopyAssignment { @@ -518,7 +522,7 @@ impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { { p9_unused_implicit_assignment_HasUndefinedCopyAssignment::new() } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct p9_unused_implicit_assignment_HasMemberWithUndefinedCopyAssignment { #[offset(0)] 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 31f7517e61..6653a1bce1 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 @@ -13,7 +13,7 @@ impl p1_template_constructor_from_own_type_Probe { } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_from(i32, new_2, value)] #[byte_size(4)] pub struct p1_template_constructor_from_own_type_Probe { 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 fa4515f198..18e1484f24 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 @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_into(i64, to_i64, mut_ptr)] #[byte_size(8)] pub struct p2_non_const_conversion_function_Gauge { 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 aea6ffabe1..a5f9afd63d 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 @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct p11_defaulted_move_constructor_is_trivial_MoveOnly { diff --git a/tests/std/class/class.mem/out/refcount/class.free.rs b/tests/std/class/class.mem/out/refcount/class.free.rs index 051e0ab616..f79f771bc7 100644 --- a/tests/std/class/class.mem/out/refcount/class.free.rs +++ b/tests/std/class/class.mem/out/refcount/class.free.rs @@ -9,7 +9,7 @@ use std::rc::{Rc, Weak}; thread_local!( pub static allocations_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct p1_allocation_function_is_static_Allocates {} impl p1_allocation_function_is_static_Allocates { @@ -46,7 +46,7 @@ pub fn test_1() { thread_local!( pub static deallocations_2: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct p3_deallocation_function_is_static_Deallocates {} impl p3_deallocation_function_is_static_Deallocates { 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 75cee7d659..20c68c54ed 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 @@ -14,7 +14,7 @@ pub fn minimum_1() -> i32 { } pub type anon_2 = u32; pub const anon_2_reserve: anon_2 = 30; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct p7_1_function_body_names_later_member_HasLaterMembers { #[offset(0)] @@ -43,7 +43,7 @@ thread_local!( thread_local!( pub static step_5: Value = Rc::new(RefCell::new(4)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct p7_2_default_argument_names_later_member_HasLaterStaticStep { #[offset(0)] diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.init/dcl.init.general.cpp b/tests/std/dcl.dcl/dcl.decl/dcl.init/dcl.init.general.cpp index ff328142c6..4319ff89b1 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.init/dcl.init.general.cpp +++ b/tests/std/dcl.dcl/dcl.decl/dcl.init/dcl.init.general.cpp @@ -28,7 +28,208 @@ void test() { } } // namespace p6_1_zero_initialized_pointer_to_member +// N4950 [dcl.init.general]/6.1: a zero-initialized scalar is the integer +// literal 0 converted to its type. +namespace p6_1_zero_initialized_scalars { +enum class Color { red = 1, green }; + +static int static_int; +static double static_double; +static bool static_bool; +static char static_char; +static int *static_pointer; +static Color static_enum; +static void (*static_function_pointer)(); +thread_local long thread_local_long; + +int next_count() { + static int counter; + return ++counter; +} + +void test() { + assert(static_int == 0); + assert(static_double == 0.0); + assert(!static_bool); + assert(static_char == '\0'); + assert(static_pointer == nullptr); + assert(static_enum == Color(0)); + assert(static_enum != Color::red); + assert(static_function_pointer == nullptr); + assert(thread_local_long == 0); + assert(next_count() == 1); + assert(next_count() == 2); + + int value_int{}; + double value_double = double(); + int *value_pointer{}; + assert(value_int == 0); + assert(value_double == 0.0); + assert(value_pointer == nullptr); + + int *heap_int = new int(); + assert(*heap_int == 0); + delete heap_int; +} +} // namespace p6_1_zero_initialized_scalars + +// N4950 [dcl.init.general]/6.2: zero-initializing a class zero-initializes +// each non-static data member. +namespace p6_2_zero_initialized_class { +struct Inner { + int number; + double real; + int *pointer; +}; + +struct Outer { + char letter; + Inner inner; + int numbers[3]; + Inner inners[2]; +}; + +static Outer static_outer; + +void check(const Outer &outer) { + assert(outer.letter == '\0'); + assert(outer.inner.number == 0); + assert(outer.inner.real == 0.0); + assert(outer.inner.pointer == nullptr); + for (int i = 0; i < 3; ++i) { + assert(outer.numbers[i] == 0); + } + for (int i = 0; i < 2; ++i) { + assert(outer.inners[i].number == 0); + assert(outer.inners[i].real == 0.0); + assert(outer.inners[i].pointer == nullptr); + } +} + +void test() { + check(static_outer); + Outer value_outer = Outer(); + check(value_outer); + Outer *heap_outer = new Outer(); + check(*heap_outer); + delete heap_outer; +} +} // namespace p6_2_zero_initialized_class + +// N4950 [dcl.init.general]/6.2: the padding bits of a zero-initialized class +// are zero bits. +namespace p6_2_zero_initialized_padding { +struct Padded { + char letter; + int number; +}; + +static Padded static_padded; + +void test() { + const unsigned char *bytes = + reinterpret_cast(&static_padded); + for (unsigned long i = 0; i < sizeof(Padded); ++i) { + assert(bytes[i] == 0); + } +} +} // namespace p6_2_zero_initialized_padding + +// N4950 [dcl.init.general]/6.3: zero-initializing a union zero-initializes its +// first non-static named data member. +namespace p6_3_zero_initialized_union { +union Number { + int integer; + char bytes[8]; +}; + +static Number static_number; + +void test() { + assert(static_number.integer == 0); + Number value_number = Number(); + assert(value_number.integer == 0); +} +} // namespace p6_3_zero_initialized_union + +// N4950 [dcl.init.general]/6.4: zero-initializing an array zero-initializes +// each element. +namespace p6_4_zero_initialized_array { +struct Pair { + int first; + int second; +}; + +static int static_numbers[4]; +static int static_matrix[2][3]; +static Pair static_pairs[2]; + +void test() { + for (int i = 0; i < 4; ++i) { + assert(static_numbers[i] == 0); + } + for (int i = 0; i < 2; ++i) { + for (int j = 0; j < 3; ++j) { + assert(static_matrix[i][j] == 0); + } + } + for (int i = 0; i < 2; ++i) { + assert(static_pairs[i].first == 0); + assert(static_pairs[i].second == 0); + } + int *heap_numbers = new int[3](); + for (int i = 0; i < 3; ++i) { + assert(heap_numbers[i] == 0); + } + delete[] heap_numbers; +} +} // namespace p6_4_zero_initialized_array + +// N4950 [dcl.init.general]/9.1.2: value-initializing a class whose default +// constructor is not user-provided zero-initializes the object, then +// default-initializes it if the default constructor is non-trivial. +namespace p9_1_2_zero_then_default_initialized { +struct WithDefaultMember { + int zeroed; + int five = 5; +}; + +struct LeavesMemberAlone { + LeavesMemberAlone() {} + int untouched; +}; + +struct HoldsLeavesMemberAlone { + int number; + LeavesMemberAlone member; +}; + +void test() { + WithDefaultMember value = WithDefaultMember(); + assert(value.zeroed == 0); + assert(value.five == 5); + WithDefaultMember *heap = new WithDefaultMember(); + assert(heap->zeroed == 0); + assert(heap->five == 5); + delete heap; + + HoldsLeavesMemberAlone holder = HoldsLeavesMemberAlone(); + assert(holder.number == 0); + assert(holder.member.untouched == 0); + HoldsLeavesMemberAlone *heap_holder = new HoldsLeavesMemberAlone(); + assert(heap_holder->number == 0); + assert(heap_holder->member.untouched == 0); + delete heap_holder; +} +} // namespace p9_1_2_zero_then_default_initialized + int main() { p6_1_zero_initialized_pointer_to_member::test(); + p6_1_zero_initialized_scalars::test(); + p6_2_zero_initialized_class::test(); + p6_2_zero_initialized_padding::test(); + p6_3_zero_initialized_union::test(); + p6_4_zero_initialized_array::test(); + p9_1_2_zero_then_default_initialized::test(); return 0; } 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 822d9f3f1f..a01c52b611 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 @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct p6_1_zero_initialized_pointer_to_member_HasTwoInts { #[offset(0)] @@ -14,7 +14,7 @@ pub struct p6_1_zero_initialized_pointer_to_member_HasTwoInts { #[offset(4)] pub second: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(8)] pub struct p6_1_zero_initialized_pointer_to_member_HoldsSelector { #[offset(0)] @@ -52,14 +52,404 @@ pub fn test_1() { as isize)) ); } +pub type p6_1_zero_initialized_scalars_Color = i32; +pub const p6_1_zero_initialized_scalars_Color_red: p6_1_zero_initialized_scalars_Color = 1; +pub const p6_1_zero_initialized_scalars_Color_green: p6_1_zero_initialized_scalars_Color = 2; +thread_local!( + pub static static_int_2: Value = Rc::new(RefCell::new(0_i32)); +); +thread_local!( + pub static static_double_3: Value = Rc::new(RefCell::new(0_f64)); +); +thread_local!( + pub static static_bool_4: Value = Rc::new(RefCell::new(false)); +); +thread_local!( + pub static static_char_5: Value = Rc::new(RefCell::new(0_i8)); +); +thread_local!( + pub static static_pointer_6: Value> = Rc::new(RefCell::new(Ptr::::null())); +); +thread_local!( + pub static static_enum_7: Value = + >::default(); +); +thread_local!( + pub static static_function_pointer_8: Value> = + Rc::new(RefCell::new(FnPtr::::null())); +); +thread_local!( + pub static thread_local_long_9: Value = Rc::new(RefCell::new(0_i64)); +); +pub fn next_count_10() -> i32 { + return (*(*counter_11.with(Value::clone).borrow_mut()).prefix_inc()); +} +pub fn test_12() { + assert!((static_int_2.with(|rc| *rc.borrow()) == 0)); + assert!((static_double_3.with(|rc| *rc.borrow()) == 0_f64)); + assert!(!(static_bool_4.with(|rc| *rc.borrow()))); + assert!(((static_char_5.with(|rc| *rc.borrow()) as i32) == (('\0' as i8) as i32))); + assert!(({ (*static_pointer_6.with(Value::clone).borrow()).is_null() })); + assert!( + (static_enum_7.with(|rc| *rc.borrow()) == ((0) as p6_1_zero_initialized_scalars_Color)) + ); + assert!((static_enum_7.with(|rc| *rc.borrow()) != p6_1_zero_initialized_scalars_Color_red)); + assert!(({ (*static_function_pointer_8.with(Value::clone).borrow()).is_null() })); + assert!((thread_local_long_9.with(|rc| *rc.borrow()) == 0_i64)); + assert!((({ next_count_10() }) == 1)); + assert!((({ next_count_10() }) == 2)); + let mut value_int: i32 = 0_i32; + let mut value_double: f64 = 0_f64; + let mut value_pointer: Ptr = Ptr::::null(); + assert!((value_int == 0)); + assert!((value_double == 0_f64)); + assert!((value_pointer).is_null()); + let mut heap_int: Ptr = Ptr::alloc(0_i32); + assert!(((heap_int.read()) == 0)); + heap_int.delete(); +} +thread_local!( + static counter_11: Value = Rc::new(RefCell::new(0_i32)); +); +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[byte_size(24)] +pub struct p6_2_zero_initialized_class_Inner { + #[offset(0)] + pub number: i32, + #[offset(8)] + pub real: f64, + #[offset(16)] + #[byte_size(8)] + pub pointer: Ptr, +} +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[byte_size(96)] +pub struct p6_2_zero_initialized_class_Outer { + #[offset(0)] + pub letter: i8, + #[offset(8)] + #[byte_size(24)] + pub inner: p6_2_zero_initialized_class_Inner, + #[offset(32)] + #[byte_size(12)] + #[array_len(3)] + pub numbers: Box<[i32]>, + #[offset(48)] + #[byte_size(48)] + #[array_len(2)] + pub inners: Box<[p6_2_zero_initialized_class_Inner]>, +} +impl Default for p6_2_zero_initialized_class_Outer { + fn default() -> Self { + { + p6_2_zero_initialized_class_Outer { + letter: 0_i8, + inner: ::default(), + numbers: (0..3).map(|_| 0_i32).collect::>(), + inners: (0..2) + .map(|_| ::default()) + .collect::>(), + } + } + } +} +thread_local!( + pub static static_outer_13: Value = + Rc::new(RefCell::new(::default())); +); +pub fn check_14(outer: Ptr) { + assert!(((outer.with(|__s| __s.letter) as i32) == (('\0' as i8) as i32))); + assert!((outer.with(|__s| __s.inner.number) == 0)); + assert!((outer.with(|__s| __s.inner.real) == 0_f64)); + assert!((outer.with(|__s| __s.inner.pointer.clone())).is_null()); + { + let mut i: i32 = 0; + 'loop_: while (i < 3) { + 'for_body: { + assert!(((array_elem!(outer, numbers, i).read()) == 0)); + } + i.prefix_inc(); + } + } + { + let mut i: i32 = 0; + 'loop_: while (i < 2) { + 'for_body: { + assert!((array_elem!(outer, inners, i).with(|__s| __s.number) == 0)); + assert!((array_elem!(outer, inners, i).with(|__s| __s.real) == 0_f64)); + assert!((array_elem!(outer, inners, i).with(|__s| __s.pointer.clone())).is_null()); + } + i.prefix_inc(); + } + } +} +pub fn test_15() { + ({ check_14(static_outer_13.with(|v| v.as_pointer())) }); + let value_outer: Value = + Rc::new(RefCell::new(::default())); + ({ check_14(value_outer.as_pointer()) }); + let mut heap_outer: Ptr = + Ptr::alloc(::default()); + ({ check_14((heap_outer).clone()) }); + heap_outer.delete(); +} +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[byte_size(8)] +pub struct p6_2_zero_initialized_padding_Padded { + #[offset(0)] + pub letter: i8, + #[offset(4)] + pub number: i32, +} +thread_local!( + pub static static_padded_16: Value = Rc::new( + RefCell::new(::default()), + ); +); +pub fn test_17() { + let mut bytes: Ptr = (static_padded_16.with(|v| v.as_pointer())).reinterpret_cast::(); + { + let mut i: u64 = 0_u64; + 'loop_: while ((i as usize) < 8usize) { + 'for_body: { + assert!((((elem!(bytes, i).read()) as i32) == 0)); + } + i.prefix_inc(); + } + } +} +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] +#[byte_size(8)] +pub struct p6_3_zero_initialized_union_Number { + #[offset(0)] + #[byte_size(8)] + #[array_len(8)] + __bytes: Box<[u8]>, +} +impl p6_3_zero_initialized_union_Number { + pub fn integer(this: Ptr) -> Ptr { + this.reinterpret_cast() + } + pub fn bytes(this: Ptr) -> Ptr { + this.reinterpret_cast() + } +} +impl Default for p6_3_zero_initialized_union_Number { + fn default() -> Self { + p6_3_zero_initialized_union_Number { + __bytes: Box::from([0u8; 8]), + } + } +} +thread_local!( + pub static static_number_18: Value = + Rc::new(RefCell::new(::default())); +); +pub fn test_19() { + assert!( + ((p6_3_zero_initialized_union_Number::integer(static_number_18.with(|v| v.as_pointer())) + .read()) + == 0) + ); + let value_number: Value = + Rc::new(RefCell::new(::default())); + assert!(((p6_3_zero_initialized_union_Number::integer(value_number.as_pointer()).read()) == 0)); +} +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[byte_size(8)] +pub struct p6_4_zero_initialized_array_Pair { + #[offset(0)] + pub first: i32, + #[offset(4)] + pub second: i32, +} +thread_local!( + pub static static_numbers_20: Value> = + Rc::new(RefCell::new((0..4).map(|_| 0_i32).collect::>())); +); +thread_local!( + pub static static_matrix_21: Value]>> = Rc::new(RefCell::new( + (0..2) + .map(|_| (0..3).map(|_| 0_i32).collect::>()) + .collect::]>>(), + )); +); +thread_local!( + pub static static_pairs_22: Value> = + Rc::new(RefCell::new( + (0..2) + .map(|_| ::default()) + .collect::>(), + )); +); +pub fn test_23() { + { + let mut i: i32 = 0; + 'loop_: while (i < 4) { + 'for_body: { + assert!( + (({ + let __idx0 = (i) as usize; + static_numbers_20.with(|rc| rc.borrow()[__idx0]) + }) == 0) + ); + } + i.prefix_inc(); + } + } + { + let mut i: i32 = 0; + 'loop_: while (i < 2) { + 'for_body: { + { + let mut j: i32 = 0; + 'loop_: while (j < 3) { + 'for_body: { + assert!( + (({ + let __idx0 = (i) as usize; + let __idx1 = (j) as usize; + static_matrix_21.with(|rc| rc.borrow()[__idx0][__idx1]) + }) == 0) + ); + } + j.prefix_inc(); + } + } + } + i.prefix_inc(); + } + } + { + let mut i: i32 = 0; + 'loop_: while (i < 2) { + 'for_body: { + assert!( + ({ + ({ + let __idx0 = (i) as usize; + static_pairs_22.with(|rc| rc.borrow()[__idx0]) + }) + .first + } == 0) + ); + assert!( + ({ + ({ + let __idx0 = (i) as usize; + static_pairs_22.with(|rc| rc.borrow()[__idx0]) + }) + .second + } == 0) + ); + } + i.prefix_inc(); + } + } + let mut heap_numbers: Ptr = + Ptr::alloc_array((0..3_usize).map(|_| 0_i32).collect::>()); + { + let mut i: i32 = 0; + 'loop_: while (i < 3) { + 'for_body: { + assert!(((elem!(heap_numbers, i).read()) == 0)); + } + i.prefix_inc(); + } + } + heap_numbers.delete(); +} +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[byte_size(8)] +pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { + #[offset(0)] + pub zeroed: i32, + #[offset(4)] + pub five: i32, +} +impl Default for p9_1_2_zero_then_default_initialized_WithDefaultMember { + fn default() -> Self { + { + p9_1_2_zero_then_default_initialized_WithDefaultMember { + zeroed: 0_i32, + five: 5, + } + } + } +} +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] +#[byte_size(4)] +pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { + #[offset(0)] + pub untouched: i32, +} +impl p9_1_2_zero_then_default_initialized_LeavesMemberAlone { + pub fn new() -> Self { + Self { untouched: 0_i32 } + } +} +impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { + fn default() -> Self { + { p9_1_2_zero_then_default_initialized_LeavesMemberAlone::new() } + } +} +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] +#[byte_size(8)] +pub struct p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { + #[offset(0)] + pub number: i32, + #[offset(4)] + #[byte_size(4)] + pub member: p9_1_2_zero_then_default_initialized_LeavesMemberAlone, +} +pub fn test_24() { + let mut value: p9_1_2_zero_then_default_initialized_WithDefaultMember = + ::default(); + assert!((value.zeroed == 0)); + assert!((value.five == 5)); + let mut heap: Ptr = + Ptr::alloc(::default()); + assert!((heap.with(|__s| __s.zeroed) == 0)); + assert!((heap.with(|__s| __s.five) == 5)); + heap.delete(); + let mut holder: p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone = + ::default(); + assert!((holder.number == 0)); + assert!((holder.member.untouched == 0)); + let mut heap_holder: Ptr = + Ptr::alloc(::default()); + assert!((heap_holder.with(|__s| __s.number) == 0)); + assert!((heap_holder.with(|__s| __s.member.untouched) == 0)); + heap_holder.delete(); +} pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { ({ test_1() }); + ({ test_12() }); + ({ test_15() }); + ({ test_17() }); + ({ test_19() }); + ({ test_23() }); + ({ test_24() }); return 0; } pub fn __cpp2rust_init_globals() { let _ = static_pm_0.with(|_| ()); + let _ = static_int_2.with(|_| ()); + let _ = static_double_3.with(|_| ()); + let _ = static_bool_4.with(|_| ()); + let _ = static_char_5.with(|_| ()); + let _ = static_pointer_6.with(|_| ()); + let _ = static_enum_7.with(|_| ()); + let _ = static_function_pointer_8.with(|_| ()); + let _ = thread_local_long_9.with(|_| ()); + let _ = static_outer_13.with(|_| ()); + let _ = static_padded_16.with(|_| ()); + let _ = static_number_18.with(|_| ()); + let _ = static_numbers_20.with(|_| ()); + let _ = static_matrix_21.with(|_| ()); + let _ = static_pairs_22.with(|_| ()); } 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 9d73394598..0b08fcdd20 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 @@ -47,6 +47,329 @@ pub unsafe fn test_1() { as isize)) ); } +pub type p6_1_zero_initialized_scalars_Color = i32; +pub const p6_1_zero_initialized_scalars_Color_red: p6_1_zero_initialized_scalars_Color = 1; +pub const p6_1_zero_initialized_scalars_Color_green: p6_1_zero_initialized_scalars_Color = 2; +pub static mut static_int_2: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i32 }); +pub static mut static_double_3: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_f64 }); +pub static mut static_bool_4: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { false }); +pub static mut static_char_5: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { (0 as libc::c_char) }); +pub static mut static_pointer_6: std::cell::LazyCell<*mut i32> = + std::cell::LazyCell::new(|| unsafe { std::ptr::null_mut() }); +pub static mut static_enum_7: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { p6_1_zero_initialized_scalars_Color_red }); +pub static mut static_function_pointer_8: std::cell::LazyCell> = + std::cell::LazyCell::new(|| unsafe { None }); +pub static mut thread_local_long_9: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { 0_i64 }); +pub unsafe fn next_count_10() -> i32 { + return (*(*std::cell::LazyCell::force_mut(&mut *&raw mut counter_11)).prefix_inc()); +} +pub unsafe fn test_12() { + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut static_int_2)) == (0))); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut static_double_3)) == (0_f64))); + assert!(!(*std::cell::LazyCell::force_mut(&mut *&raw mut static_bool_4))); + assert!( + (((*std::cell::LazyCell::force_mut(&mut *&raw mut static_char_5)) as i32) + == (('\0' as libc::c_char) as i32)) + ); + assert!((*std::cell::LazyCell::force_mut(&mut *&raw mut static_pointer_6)).is_null()); + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut static_enum_7)) + == ((0) as p6_1_zero_initialized_scalars_Color)) + ); + assert!( + ((*std::cell::LazyCell::force_mut(&mut *&raw mut static_enum_7)) + != (p6_1_zero_initialized_scalars_Color_red)) + ); + assert!((*std::cell::LazyCell::force_mut(&mut *&raw mut static_function_pointer_8)).is_none()); + assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut thread_local_long_9)) == (0_i64))); + assert!(((unsafe { next_count_10() }) == (1))); + assert!(((unsafe { next_count_10() }) == (2))); + let mut value_int: i32 = 0_i32; + let mut value_double: f64 = 0_f64; + let mut value_pointer: *mut i32 = std::ptr::null_mut(); + assert!(((value_int) == (0))); + assert!(((value_double) == (0_f64))); + assert!((value_pointer).is_null()); + let mut heap_int: *mut i32 = (Box::leak(Box::new(0_i32)) as *mut i32); + assert!(((*heap_int) == (0))); + { + let __p = heap_int; + if !__p.is_null() { + ::std::mem::drop(Box::from_raw(__p)) + } + }; +} +static mut counter_11: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct p6_2_zero_initialized_class_Inner { + pub number: i32, + pub real: f64, + pub pointer: *mut i32, +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct p6_2_zero_initialized_class_Outer { + pub letter: libc::c_char, + pub inner: p6_2_zero_initialized_class_Inner, + pub numbers: [i32; 3], + pub inners: [p6_2_zero_initialized_class_Inner; 2], +} +pub static mut static_outer_13: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { ::default() }); +pub unsafe fn check_14(outer: *const p6_2_zero_initialized_class_Outer) { + assert!((((*outer).letter as i32) == (('\0' as libc::c_char) as i32))); + assert!((((*outer).inner.number) == (0))); + assert!((((*outer).inner.real) == (0_f64))); + assert!(((*outer).inner.pointer).is_null()); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (3)) { + 'for_body: { + assert!((((*outer).numbers[(i) as usize]) == (0))); + } + i.prefix_inc(); + } + } + { + let mut i: i32 = 0; + 'loop_: while ((i) < (2)) { + 'for_body: { + assert!((((*outer).inners[(i) as usize].number) == (0))); + assert!((((*outer).inners[(i) as usize].real) == (0_f64))); + assert!(((*outer).inners[(i) as usize].pointer).is_null()); + } + i.prefix_inc(); + } + } +} +pub unsafe fn test_15() { + (unsafe { check_14(&(*std::cell::LazyCell::force_mut(&mut *&raw mut static_outer_13))) }); + let mut value_outer: p6_2_zero_initialized_class_Outer = + ::default(); + (unsafe { check_14(&value_outer) }); + let mut heap_outer: *mut p6_2_zero_initialized_class_Outer = + (Box::leak(Box::new(::default())) + as *mut p6_2_zero_initialized_class_Outer); + (unsafe { check_14(&(*heap_outer)) }); + { + let __p = heap_outer; + if !__p.is_null() { + ::std::mem::drop(Box::from_raw(__p)) + } + }; +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct p6_2_zero_initialized_padding_Padded { + pub letter: libc::c_char, + pub number: i32, +} +pub static mut static_padded_16: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { ::default() }); +pub unsafe fn test_17() { + let mut bytes: *const u8 = + ((&raw mut (*std::cell::LazyCell::force_mut(&mut *&raw mut static_padded_16)) + as *mut p6_2_zero_initialized_padding_Padded) as *const u8); + { + let mut i: u64 = 0_u64; + 'loop_: while ((i as usize) + < (::std::mem::size_of::())) + { + 'for_body: { + assert!((((*bytes.offset((i) as isize)) as i32) == (0))); + } + i.prefix_inc(); + } + } +} +#[repr(C)] +#[derive(Copy, Clone, FnPtrArg, VaArg)] +pub union p6_3_zero_initialized_union_Number { + pub integer: i32, + pub bytes: [libc::c_char; 8], +} +impl Default for p6_3_zero_initialized_union_Number { + fn default() -> Self { + unsafe { std::mem::zeroed() } + } +} +pub static mut static_number_18: std::cell::LazyCell = + std::cell::LazyCell::new(|| unsafe { ::default() }); +pub unsafe fn test_19() { + assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut static_number_18)).integer) == (0))); + let mut value_number: p6_3_zero_initialized_union_Number = + ::default(); + assert!(((value_number.integer) == (0))); +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct p6_4_zero_initialized_array_Pair { + pub first: i32, + pub second: i32, +} +pub static mut static_numbers_20: std::cell::LazyCell<[i32; 4]> = + std::cell::LazyCell::new(|| unsafe { [0_i32; 4] }); +pub static mut static_matrix_21: std::cell::LazyCell<[[i32; 3]; 2]> = + std::cell::LazyCell::new(|| unsafe { [[0_i32; 3]; 2] }); +pub static mut static_pairs_22: std::cell::LazyCell<[p6_4_zero_initialized_array_Pair; 2]> = + std::cell::LazyCell::new(|| unsafe { [::default(); 2] }); +pub unsafe fn test_23() { + { + let mut i: i32 = 0; + 'loop_: while ((i) < (4)) { + 'for_body: { + assert!( + (((*std::cell::LazyCell::force_mut(&mut *&raw mut static_numbers_20)) + [(i) as usize]) + == (0)) + ); + } + i.prefix_inc(); + } + } + { + let mut i: i32 = 0; + 'loop_: while ((i) < (2)) { + 'for_body: { + { + let mut j: i32 = 0; + 'loop_: while ((j) < (3)) { + 'for_body: { + assert!( + (((*std::cell::LazyCell::force_mut( + &mut *&raw mut static_matrix_21 + ))[(i) as usize][(j) as usize]) + == (0)) + ); + } + j.prefix_inc(); + } + } + } + i.prefix_inc(); + } + } + { + let mut i: i32 = 0; + 'loop_: while ((i) < (2)) { + 'for_body: { + assert!( + (((*std::cell::LazyCell::force_mut(&mut *&raw mut static_pairs_22)) + [(i) as usize] + .first) + == (0)) + ); + assert!( + (((*std::cell::LazyCell::force_mut(&mut *&raw mut static_pairs_22)) + [(i) as usize] + .second) + == (0)) + ); + } + i.prefix_inc(); + } + } + let mut heap_numbers: *mut i32 = + Box::leak((0..3_usize).map(|_| 0_i32).collect::>()).as_mut_ptr(); + { + let mut i: i32 = 0; + 'loop_: while ((i) < (3)) { + 'for_body: { + assert!(((*heap_numbers.offset((i) as isize)) == (0))); + } + i.prefix_inc(); + } + } + { + let __p = heap_numbers; + if !__p.is_null() { + ::std::mem::drop(Box::from_raw(::std::slice::from_raw_parts_mut( + __p, + libcc2rs::malloc_usable_size(__p as *mut ::libc::c_void) + / ::std::mem::size_of::(), + ))) + } + }; +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg)] +pub struct p9_1_2_zero_then_default_initialized_WithDefaultMember { + pub zeroed: i32, + pub five: i32, +} +impl Default for p9_1_2_zero_then_default_initialized_WithDefaultMember { + fn default() -> Self { + unsafe { + p9_1_2_zero_then_default_initialized_WithDefaultMember { + zeroed: 0_i32, + five: 5, + } + } + } +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg)] +pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { + pub untouched: i32, +} +impl p9_1_2_zero_then_default_initialized_LeavesMemberAlone { + pub unsafe fn new() -> Self { + let mut this = Self { untouched: 0_i32 }; + this + } +} +impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { + fn default() -> Self { + unsafe { p9_1_2_zero_then_default_initialized_LeavesMemberAlone::new() } + } +} +#[repr(C)] +#[derive(Copy, Clone, VaArg, FnPtrArg, Default)] +pub struct p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone { + pub number: i32, + pub member: p9_1_2_zero_then_default_initialized_LeavesMemberAlone, +} +pub unsafe fn test_24() { + let mut value: p9_1_2_zero_then_default_initialized_WithDefaultMember = + ::default(); + assert!(((value.zeroed) == (0))); + assert!(((value.five) == (5))); + let mut heap: *mut p9_1_2_zero_then_default_initialized_WithDefaultMember = (Box::leak( + Box::new(::default()), + ) + as *mut p9_1_2_zero_then_default_initialized_WithDefaultMember); + assert!((((*heap).zeroed) == (0))); + assert!((((*heap).five) == (5))); + { + let __p = heap; + if !__p.is_null() { + ::std::mem::drop(Box::from_raw(__p)) + } + }; + let mut holder: p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone = + ::default(); + assert!(((holder.number) == (0))); + assert!(((holder.member.untouched) == (0))); + let mut heap_holder: *mut p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone = + (Box::leak(Box::new( + ::default(), + )) as *mut p9_1_2_zero_then_default_initialized_HoldsLeavesMemberAlone); + assert!((((*heap_holder).number) == (0))); + assert!((((*heap_holder).member.untouched) == (0))); + { + let __p = heap_holder; + if !__p.is_null() { + ::std::mem::drop(Box::from_raw(__p)) + } + }; +} pub fn main() { unsafe { __cpp2rust_init_globals(); @@ -55,8 +378,28 @@ pub fn main() { } unsafe fn main_0() -> i32 { (unsafe { test_1() }); + (unsafe { test_12() }); + (unsafe { test_15() }); + (unsafe { test_17() }); + (unsafe { test_19() }); + (unsafe { test_23() }); + (unsafe { test_24() }); return 0; } pub unsafe fn __cpp2rust_init_globals() { std::cell::LazyCell::force(&*&raw const static_pm_0); + std::cell::LazyCell::force(&*&raw const static_int_2); + std::cell::LazyCell::force(&*&raw const static_double_3); + std::cell::LazyCell::force(&*&raw const static_bool_4); + std::cell::LazyCell::force(&*&raw const static_char_5); + std::cell::LazyCell::force(&*&raw const static_pointer_6); + std::cell::LazyCell::force(&*&raw const static_enum_7); + std::cell::LazyCell::force(&*&raw const static_function_pointer_8); + std::cell::LazyCell::force(&*&raw const thread_local_long_9); + std::cell::LazyCell::force(&*&raw const static_outer_13); + std::cell::LazyCell::force(&*&raw const static_padded_16); + std::cell::LazyCell::force(&*&raw const static_number_18); + std::cell::LazyCell::force(&*&raw const static_numbers_20); + std::cell::LazyCell::force(&*&raw const static_matrix_21); + std::cell::LazyCell::force(&*&raw const static_pairs_22); } diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.array.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.array.rs index 03dc37b6c1..f7875ca5e8 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.array.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.array.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(12)] pub struct p6_array_of_pointers_to_data_members_HasThreeInts { #[offset(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 d05aeba93d..6855cf3296 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 @@ -54,7 +54,7 @@ thread_local!( thread_local!( pub static step_10: Value = Rc::new(RefCell::new(4)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct p9_static_member_hides_namespace_variable_HasStaticStep { #[offset(0)] @@ -105,7 +105,7 @@ pub fn count_default_13() -> i32 { pub fn combine_14(mut first: i32, mut second: i32) -> i32 { return ((first * 100) + second); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct p9_evaluated_each_time_called_Widget { @@ -127,7 +127,7 @@ thread_local!( ); pub type anon_16 = u32; pub const anon_16_kBonus: anon_16 = 5; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct p9_evaluated_each_time_called_Account { #[offset(0)] @@ -197,7 +197,7 @@ pub fn test_17() { pub fn add_18(mut a: i32, mut b: i32) -> i32 { return (a + b); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct p9_not_part_of_the_type_Scale {} impl p9_not_part_of_the_type_Scale { diff --git a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.mptr.rs b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.mptr.rs index d81ee72927..0b77ba09a5 100644 --- a/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.mptr.rs +++ b/tests/std/dcl.dcl/dcl.decl/dcl.meaning/out/refcount/dcl.mptr.rs @@ -6,13 +6,14 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(16)] pub struct p2_pointer_to_array_member_HasIntArray { #[offset(0)] pub before: i32, #[offset(4)] #[byte_size(12)] + #[array_len(3)] pub elements: Box<[i32]>, } impl Default for p2_pointer_to_array_member_HasIntArray { @@ -39,7 +40,7 @@ pub fn test_0() { assert!(((array_elem!(obj.as_pointer(), elements, 1).read()) == 7)); assert!(({ ({ (*obj.borrow()).before } == 1) })); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct p2_pointer_to_data_member_HasTwoInts { #[offset(0)] @@ -67,7 +68,7 @@ pub fn test_1() { thread_local!( pub static pm_2: Value = Rc::new(RefCell::new(-1_isize)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct p2_pointer_to_member_of_incomplete_class_CompletedLater { #[offset(0)] @@ -96,7 +97,7 @@ pub fn test_3() { == 4) ); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct p2_pointer_to_member_of_pointer_to_member_type_HasTwoInts { #[offset(0)] @@ -104,7 +105,7 @@ pub struct p2_pointer_to_member_of_pointer_to_member_type_HasTwoInts { #[offset(4)] pub second: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(8)] pub struct p2_pointer_to_member_of_pointer_to_member_type_HoldsSelector { #[offset(0)] diff --git a/tests/std/expr/conv/out/refcount/conv.mem.rs b/tests/std/expr/conv/out/refcount/conv.mem.rs index 93c47a391f..74a595f022 100644 --- a/tests/std/expr/conv/out/refcount/conv.mem.rs +++ b/tests/std/expr/conv/out/refcount/conv.mem.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct p1_null_distinct_from_first_member_HasTwoInts { #[offset(0)] diff --git a/tests/std/expr/expr.compound/expr.post/out/refcount/expr.const.cast.rs b/tests/std/expr/expr.compound/expr.post/out/refcount/expr.const.cast.rs index 4c53d43eb2..dafe769296 100644 --- a/tests/std/expr/expr.compound/expr.post/out/refcount/expr.const.cast.rs +++ b/tests/std/expr/expr.compound/expr.post/out/refcount/expr.const.cast.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct p4_reference_const_cast_Pair { #[offset(0)] diff --git a/tests/std/expr/expr.compound/expr.post/out/refcount/expr.reinterpret.cast-p10-result-is-unspecified.rs b/tests/std/expr/expr.compound/expr.post/out/refcount/expr.reinterpret.cast-p10-result-is-unspecified.rs index 1d2579260d..36e1b8a0b8 100644 --- a/tests/std/expr/expr.compound/expr.post/out/refcount/expr.reinterpret.cast-p10-result-is-unspecified.rs +++ b/tests/std/expr/expr.compound/expr.post/out/refcount/expr.reinterpret.cast-p10-result-is-unspecified.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct HasTwoInts { #[offset(0)] @@ -14,7 +14,7 @@ pub struct HasTwoInts { #[offset(4)] pub second: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct AlsoHasTwoInts { #[offset(0)] diff --git a/tests/std/expr/expr.compound/expr.post/out/refcount/expr.reinterpret.cast.rs b/tests/std/expr/expr.compound/expr.post/out/refcount/expr.reinterpret.cast.rs index b73e3efec8..e0ee6af6db 100644 --- a/tests/std/expr/expr.compound/expr.post/out/refcount/expr.reinterpret.cast.rs +++ b/tests/std/expr/expr.compound/expr.post/out/refcount/expr.reinterpret.cast.rs @@ -16,7 +16,7 @@ pub fn test_0() { (*value.borrow_mut()) = 7; assert!((((converted.read()).read()) == 7)); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct p10_null_converts_to_null_HasTwoInts { #[offset(0)] @@ -24,7 +24,7 @@ pub struct p10_null_converts_to_null_HasTwoInts { #[offset(4)] pub second: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct p10_null_converts_to_null_HasChar { #[offset(0)] @@ -35,7 +35,7 @@ pub fn test_1() { let mut converted: isize = pm; assert!(((converted) == -1_isize)); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct p10_2_data_member_round_trip_HasTwoInts { #[offset(0)] @@ -43,7 +43,7 @@ pub struct p10_2_data_member_round_trip_HasTwoInts { #[offset(4)] pub second: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct p10_2_data_member_round_trip_HasChar { #[offset(0)] diff --git a/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.pre.incr.rs b/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.pre.incr.rs index 900ddec18a..5abe461cf4 100644 --- a/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.pre.incr.rs +++ b/tests/std/expr/expr.compound/expr.unary/out/refcount/expr.pre.incr.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct p1_result_is_updated_operand_Counter { #[offset(0)] 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 7f1fe5924f..74c09bb17a 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 @@ -12,7 +12,7 @@ thread_local!( thread_local!( pub static calls_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct p3_2_static_member_is_ordinary_pointer_HasStaticMembers {} impl p3_2_static_member_is_ordinary_pointer_HasStaticMembers { @@ -30,7 +30,7 @@ pub fn test_2() { ({ function_pointer.call() }); assert!((calls_1.with(|rc| *rc.borrow()) == 1)); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct p3_2_explicit_object_member_is_ordinary_pointer_HasExplicitObjectMember { #[offset(0)] @@ -46,7 +46,7 @@ pub fn test_3() { (*object.borrow_mut()).base = 5; assert!((({ function_pointer.call(object.as_pointer(), 1,) }) == 6)); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct p4_parenthesized_qualified_id_is_object_pointer_TakesAddressOfOwnMember { #[offset(0)] diff --git a/tests/std/expr/expr.compound/out/refcount/expr.cond.rs b/tests/std/expr/expr.compound/out/refcount/expr.cond.rs index 6b8daeef1d..d0cf7c81d8 100644 --- a/tests/std/expr/expr.compound/out/refcount/expr.cond.rs +++ b/tests/std/expr/expr.compound/out/refcount/expr.cond.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct p7_4_pointer_to_member_and_null_HasTwoInts { #[offset(0)] diff --git a/tests/std/expr/expr.compound/out/refcount/expr.eq.rs b/tests/std/expr/expr.compound/out/refcount/expr.eq.rs index 60e6b1423d..2e7cca7b6a 100644 --- a/tests/std/expr/expr.compound/out/refcount/expr.eq.rs +++ b/tests/std/expr/expr.compound/out/refcount/expr.eq.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct p4_1_both_null_HasTwoInts { #[offset(0)] @@ -20,7 +20,7 @@ pub fn test_0() { assert!((first_null == second_null)); assert!(!(first_null != second_null)); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct p4_2_one_null_HasTwoInts { #[offset(0)] @@ -36,11 +36,12 @@ pub fn test_1() { assert!((null_pm != first_pm)); assert!(!(null_pm == first_pm)); } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(4)] pub struct p4_5_members_of_same_union_HasTwoIntMembers { #[offset(0)] #[byte_size(4)] + #[array_len(4)] __bytes: Box<[u8]>, } impl p4_5_members_of_same_union_HasTwoIntMembers { @@ -64,7 +65,7 @@ pub fn test_2() { assert!((first_pm == second_pm)); assert!(!(first_pm != second_pm)); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct p4_6_data_members_HasTwoInts { #[offset(0)] diff --git a/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper-p6-null-pointer-to-data-member.rs b/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper-p6-null-pointer-to-data-member.rs index c655f24343..58dba1bf76 100644 --- a/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper-p6-null-pointer-to-data-member.rs +++ b/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper-p6-null-pointer-to-data-member.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct HasTwoInts { #[offset(0)] diff --git a/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs b/tests/std/expr/expr.compound/out/refcount/expr.mptr.oper.rs index 52e93545fb..e02106a63e 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 @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct p3_arrow_star_HasTwoInts { #[offset(0)] @@ -27,7 +27,7 @@ pub fn test_0() { assert!(({ ({ (*obj.borrow()).first } == 3) })); assert!((((p).member::(pm)) == ((p).member::(pm)))); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct p4_object_expression_sequenced_first_HasValue { #[offset(0)] @@ -69,7 +69,7 @@ pub fn test_7() { assert!((object_stamp_2.with(|rc| *rc.borrow()) == 1)); assert!((member_stamp_3.with(|rc| *rc.borrow()) == 2)); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct p6_data_member_of_lvalue_is_lvalue_HasTwoInts { #[offset(0)] @@ -98,7 +98,7 @@ thread_local!( thread_local!( pub static moveCount_10: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, Default)] #[byte_size(1)] pub struct p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} impl p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { @@ -121,7 +121,7 @@ impl Clone for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::copy_from(__src.as_pointer()) } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, Default)] #[byte_size(1)] pub struct p6_data_member_of_rvalue_is_xvalue_HoldsCounted { #[offset(0)] 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 bf8e8701f0..25d3d46062 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 @@ -6,10 +6,10 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct p16_rebind_member_Alloc_std_pair_const_int__int___rebind_std_pair_const_int__int__ {} -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct p16_rebind_member_Alloc_std_pair_const_int__int__ { #[offset(0)] @@ -43,7 +43,7 @@ pub fn test_0() { ); assert!(({ ((*n.borrow()).len() == 1_usize) })); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct p18_rebind_to_container_node_Alloc_std_pair_const_int__int__ {} pub fn test_1() { 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 48740610a7..03c4cfdeab 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 @@ -12,7 +12,9 @@ thread_local!( thread_local!( pub static dtorCount_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Destructor, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructor, Default, +)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct p2_condition_variable_created_each_iteration_ConvertsToBool { @@ -60,7 +62,9 @@ thread_local!( thread_local!( pub static dtorCount_4: Value = Rc::new(RefCell::new(0)); ); -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Destructor, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructor, Default, +)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct p2_continue_destroys_condition_variable_ConvertsToBool { 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 6f94c793f0..276c98201a 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 @@ -18,7 +18,7 @@ thread_local!( thread_local!( pub static useCount_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructor)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] 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 0935da1fb3..9253fb3b98 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 @@ -18,7 +18,7 @@ thread_local!( thread_local!( pub static useCount_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructor)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -76,7 +76,9 @@ thread_local!( thread_local!( pub static dtorCount_6: Value = Rc::new(RefCell::new(0)); ); -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Destructor, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructor, Default, +)] #[cpp_into(i32, to_i32)] #[byte_size(4)] pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { diff --git a/tests/std/temp/out/refcount/temp.type.rs b/tests/std/temp/out/refcount/temp.type.rs index b693e8574d..ea929ef43c 100644 --- a/tests/std/temp/out/refcount/temp.type.rs +++ b/tests/std/temp/out/refcount/temp.type.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct p2_6_pointer_to_member_argument_HasTwoInts { #[offset(0)] @@ -17,21 +17,21 @@ pub struct p2_6_pointer_to_member_argument_HasTwoInts { thread_local!( pub static count_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct p2_6_pointer_to_member_argument_CountsPerMember_refp2_6_pointer_to_member_argument_HasTwoInts_first_ {} thread_local!( pub static count_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct p2_6_pointer_to_member_argument_CountsPerMember_refp2_6_pointer_to_member_argument_HasTwoInts_second_ {} thread_local!( pub static count_2: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct p2_6_pointer_to_member_argument_CountsPerMember_nullptr_ {} pub fn test_3() { 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 f534995783..7a91cf2945 100644 --- a/tests/std/temp/temp.spec/out/refcount/temp.inst.rs +++ b/tests/std/temp/temp.spec/out/refcount/temp.inst.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct p2_reference_does_not_instantiate_Member { #[offset(0)] @@ -22,7 +22,7 @@ impl Default for p2_reference_does_not_instantiate_Member { { p2_reference_does_not_instantiate_Member { value: 1 } } } } -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, Default)] #[byte_size(4)] pub struct p2_reference_does_not_instantiate_Holder { #[offset(0)] diff --git a/tests/std/utilities/utility/out/refcount/forward-helpers.rs b/tests/std/utilities/utility/out/refcount/forward-helpers.rs index b84bd79545..df3a371cef 100644 --- a/tests/std/utilities/utility/out/refcount/forward-helpers.rs +++ b/tests/std/utilities/utility/out/refcount/forward-helpers.rs @@ -14,7 +14,7 @@ pub fn test_0() { lvalue.write(2); assert!(({ ((*value.borrow()) == 2) })); } -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct p6_forward_like_Movable { @@ -47,7 +47,7 @@ impl Clone for p6_forward_like_Movable { p6_forward_like_Movable::copy_from(__src.as_pointer()) } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor)] #[byte_size(4)] pub struct p6_forward_like_Holder { #[offset(0)] @@ -84,7 +84,7 @@ pub fn test_3() { let mut moved: p6_forward_like_Movable = ({ take_2(holder.as_pointer()) }); assert!(({ (moved.value == 1) && ({ (*holder.borrow()).member.value } == 0) })); } -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct p9_move_Movable { @@ -139,7 +139,7 @@ pub fn test_4() { }) ); } -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom)] #[cpp_from(i32, new, value)] #[byte_size(12)] pub struct p10_forward_in_template_A { @@ -213,7 +213,7 @@ pub fn test_7() { assert!(((moved.value == 1) && (moved.copies == 0)) && (moved.moves == 1)); assert!(({ ({ (*a.borrow()).value } == 0) })); } -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct p11_move_if_noexcept_NoexceptMove { @@ -246,7 +246,7 @@ impl Clone for p11_move_if_noexcept_NoexceptMove { p11_move_if_noexcept_NoexceptMove::copy_from(__src.as_pointer()) } } -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct p11_move_if_noexcept_ThrowingMove { diff --git a/tests/std/utilities/utility/out/refcount/forward.rs b/tests/std/utilities/utility/out/refcount/forward.rs index 9c707282a9..386c913920 100644 --- a/tests/std/utilities/utility/out/refcount/forward.rs +++ b/tests/std/utilities/utility/out/refcount/forward.rs @@ -12,7 +12,7 @@ pub fn test_0() { assert!((target == 1)); assert!((source == 1)); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct p9_move_trivially_copyable_Point { #[offset(0)] @@ -43,7 +43,7 @@ pub fn test_1() { assert!((points[0_usize].x == 5) && (points[0_usize].y == 6)); assert!((element.x == 5) && (element.y == 6)); } -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct p10_move_constructor_A { 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 ba50eed01d..3d11aa6791 100644 --- a/tests/std/utilities/utility/out/refcount/utility.as.const.rs +++ b/tests/std/utilities/utility/out/refcount/utility.as.const.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct p1_as_const_Counter { #[offset(0)] diff --git a/tests/ub/out/refcount/ctor_ref_member.rs b/tests/ub/out/refcount/ctor_ref_member.rs index 18c0b0763b..4c91ad922e 100644 --- a/tests/ub/out/refcount/ctor_ref_member.rs +++ b/tests/ub/out/refcount/ctor_ref_member.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_from(i32, new, ptr)] #[byte_size(8)] pub struct S { diff --git a/tests/ub/out/refcount/self_referencing_initializer.rs b/tests/ub/out/refcount/self_referencing_initializer.rs index f4a75cddc6..4dd36b221f 100644 --- a/tests/ub/out/refcount/self_referencing_initializer.rs +++ b/tests/ub/out/refcount/self_referencing_initializer.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct pair { #[offset(0)] diff --git a/tests/ub/out/refcount/ub6.rs b/tests/ub/out/refcount/ub6.rs index d02ed6221a..316eddb87a 100644 --- a/tests/ub/out/refcount/ub6.rs +++ b/tests/ub/out/refcount/ub6.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Pair { #[offset(0)] diff --git a/tests/unit/out/refcount/05_new.rs b/tests/unit/out/refcount/05_new.rs index bacef4215d..bc5e4eb072 100644 --- a/tests/unit/out/refcount/05_new.rs +++ b/tests/unit/out/refcount/05_new.rs @@ -6,10 +6,10 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct A {} -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct D {} pub fn main() { diff --git a/tests/unit/out/refcount/10_struct.rs b/tests/unit/out/refcount/10_struct.rs index ceb82b4637..0649747310 100644 --- a/tests/unit/out/refcount/10_struct.rs +++ b/tests/unit/out/refcount/10_struct.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct GraphNode { #[offset(0)] @@ -15,7 +15,7 @@ pub struct GraphNode { #[byte_size(8)] pub next: Ptr, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Graph { #[offset(0)] @@ -24,7 +24,7 @@ pub struct Graph { #[byte_size(8)] pub adj: Ptr>, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(8)] pub struct Partial { #[offset(0)] @@ -45,11 +45,11 @@ impl Default for Partial { } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct Declared {} impl Declared {} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/addr_of_global.rs b/tests/unit/out/refcount/addr_of_global.rs index bf12d9d302..85298e8823 100644 --- a/tests/unit/out/refcount/addr_of_global.rs +++ b/tests/unit/out/refcount/addr_of_global.rs @@ -6,13 +6,13 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Inner { #[offset(0)] pub value: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Outer { #[offset(0)] diff --git a/tests/unit/out/refcount/anonymous-struct.rs b/tests/unit/out/refcount/anonymous-struct.rs index d8b0921f4d..eda0623019 100644 --- a/tests/unit/out/refcount/anonymous-struct.rs +++ b/tests/unit/out/refcount/anonymous-struct.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Outer_Named { #[offset(0)] @@ -14,7 +14,7 @@ pub struct Outer_Named { #[offset(4)] pub b: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] @@ -22,7 +22,7 @@ pub struct anon_0 { #[offset(4)] pub d: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct anon_1 { #[offset(0)] @@ -30,7 +30,7 @@ pub struct anon_1 { #[offset(4)] pub h: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct anon_2 { #[offset(0)] @@ -38,19 +38,19 @@ pub struct anon_2 { #[offset(4)] pub f: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct anon_4 { #[offset(0)] pub j: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct anon_5 { #[offset(0)] pub k: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(12)] pub struct anon_3 { #[offset(0)] @@ -62,7 +62,7 @@ pub struct anon_3 { #[byte_size(4)] pub anon_5: anon_5, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(44)] pub struct Outer { #[offset(0)] @@ -126,7 +126,7 @@ fn main_0() -> i32 { ); return 0; } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct anon_6 { #[offset(0)] diff --git a/tests/unit/out/refcount/anonymous-struct_c.rs b/tests/unit/out/refcount/anonymous-struct_c.rs index c903903369..4dde61ed84 100644 --- a/tests/unit/out/refcount/anonymous-struct_c.rs +++ b/tests/unit/out/refcount/anonymous-struct_c.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Named { #[offset(0)] @@ -14,7 +14,7 @@ pub struct Named { #[offset(4)] pub b: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] @@ -22,7 +22,7 @@ pub struct anon_0 { #[offset(4)] pub d: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct anon_1 { #[offset(0)] @@ -30,7 +30,7 @@ pub struct anon_1 { #[offset(4)] pub h: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct anon_2 { #[offset(0)] @@ -38,19 +38,19 @@ pub struct anon_2 { #[offset(4)] pub f: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct anon_4 { #[offset(0)] pub j: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct anon_5 { #[offset(0)] pub k: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(12)] pub struct anon_3 { #[offset(0)] @@ -62,7 +62,7 @@ pub struct anon_3 { #[byte_size(4)] pub anon_5: anon_5, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(44)] pub struct Outer { #[offset(0)] @@ -132,7 +132,7 @@ fn main_0() -> i32 { ); return 0; } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct anon_6 { #[offset(0)] diff --git a/tests/unit/out/refcount/anonymous_enum.rs b/tests/unit/out/refcount/anonymous_enum.rs index 28c889c8bc..e2778966b9 100644 --- a/tests/unit/out/refcount/anonymous_enum.rs +++ b/tests/unit/out/refcount/anonymous_enum.rs @@ -12,7 +12,7 @@ pub const anon_0_FIRST_B: anon_0 = 1; pub type anon_1 = u32; pub const anon_1_SECOND_A: anon_1 = 0; pub const anon_1_SECOND_B: anon_1 = 1; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -24,7 +24,7 @@ pub const TdEnum_TD_B: TdEnum = 1; pub type anon_2 = u32; pub const anon_2_FIELD_A: anon_2 = 0; pub const anon_2_FIELD_B: anon_2 = 1; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct WithAnonField { #[offset(0)] diff --git a/tests/unit/out/refcount/anonymous_enum_c.rs b/tests/unit/out/refcount/anonymous_enum_c.rs index 14fae2c717..5b19cd0c46 100644 --- a/tests/unit/out/refcount/anonymous_enum_c.rs +++ b/tests/unit/out/refcount/anonymous_enum_c.rs @@ -12,7 +12,7 @@ pub const anon_0_FIRST_B: anon_0 = 1; pub type anon_1 = u32; pub const anon_1_SECOND_A: anon_1 = 0; pub const anon_1_SECOND_B: anon_1 = 1; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -24,7 +24,7 @@ pub const TdEnum_enum_TD_B: TdEnum_enum = 1; pub type anon_2 = u32; pub const anon_2_FIELD_A: anon_2 = 0; pub const anon_2_FIELD_B: anon_2 = 1; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct WithAnonField { #[offset(0)] diff --git a/tests/unit/out/refcount/any.rs b/tests/unit/out/refcount/any.rs index 53670a2197..1e91846425 100644 --- a/tests/unit/out/refcount/any.rs +++ b/tests/unit/out/refcount/any.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Point { #[offset(0)] diff --git a/tests/unit/out/refcount/array_const_init.rs b/tests/unit/out/refcount/array_const_init.rs index f593dd57a7..b931ea843a 100644 --- a/tests/unit/out/refcount/array_const_init.rs +++ b/tests/unit/out/refcount/array_const_init.rs @@ -6,16 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(20)] pub struct S { #[offset(0)] pub head: i32, #[offset(4)] #[byte_size(12)] + #[array_len(3)] pub tail: Box<[i32]>, #[offset(16)] #[byte_size(4)] + #[array_len(4)] pub buf: Box<[i8]>, } impl Default for S { @@ -36,7 +38,7 @@ thread_local!( buf: Box::new([0; 4]), })); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct P { #[offset(0)] diff --git a/tests/unit/out/refcount/array_field_addr.rs b/tests/unit/out/refcount/array_field_addr.rs index faa1b9117f..26cbd4303f 100644 --- a/tests/unit/out/refcount/array_field_addr.rs +++ b/tests/unit/out/refcount/array_field_addr.rs @@ -6,13 +6,14 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(12)] pub struct S { #[offset(0)] pub before: i32, #[offset(4)] #[byte_size(4)] + #[array_len(4)] pub mask: Box<[u8]>, #[offset(8)] pub after: i32, diff --git a/tests/unit/out/refcount/array_of_noncopy_struct.rs b/tests/unit/out/refcount/array_of_noncopy_struct.rs index 457a5fec52..983eee4889 100644 --- a/tests/unit/out/refcount/array_of_noncopy_struct.rs +++ b/tests/unit/out/refcount/array_of_noncopy_struct.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign)] #[byte_size(32)] pub struct NonCopy { #[offset(0)] diff --git a/tests/unit/out/refcount/array_reference.rs b/tests/unit/out/refcount/array_reference.rs index d7908a749c..50c15cc696 100644 --- a/tests/unit/out/refcount/array_reference.rs +++ b/tests/unit/out/refcount/array_reference.rs @@ -63,7 +63,7 @@ pub fn fill_and_sum_9(a: Ptr, mut v: i32, out: Ptr) { pub fn pick_10(s: Ptr) -> Ptr { return (s).clone(); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Point { #[offset(0)] diff --git a/tests/unit/out/refcount/as_const.rs b/tests/unit/out/refcount/as_const.rs index f172530f34..5ce42cb5bd 100644 --- a/tests/unit/out/refcount/as_const.rs +++ b/tests/unit/out/refcount/as_const.rs @@ -9,7 +9,7 @@ use std::rc::{Rc, Weak}; pub type Overload = u32; pub const Overload_kMutableOverload: Overload = 1; pub const Overload_kConstOverload: Overload = 2; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/assign_rhs_first.rs b/tests/unit/out/refcount/assign_rhs_first.rs index 44e750a1f5..36b9ea5db5 100644 --- a/tests/unit/out/refcount/assign_rhs_first.rs +++ b/tests/unit/out/refcount/assign_rhs_first.rs @@ -15,7 +15,7 @@ pub fn advance_1() -> i32 { }); return 10; } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/bounded_struct_ptr.rs b/tests/unit/out/refcount/bounded_struct_ptr.rs index a4bf73b4c3..1504753273 100644 --- a/tests/unit/out/refcount/bounded_struct_ptr.rs +++ b/tests/unit/out/refcount/bounded_struct_ptr.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Foo { #[offset(0)] diff --git a/tests/unit/out/refcount/bst.rs b/tests/unit/out/refcount/bst.rs index be28c9dd0b..cc168f3f21 100644 --- a/tests/unit/out/refcount/bst.rs +++ b/tests/unit/out/refcount/bst.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(24)] pub struct node_t { #[offset(0)] diff --git a/tests/unit/out/refcount/c_struct.rs b/tests/unit/out/refcount/c_struct.rs index 5decad14dc..3ca4cf031e 100644 --- a/tests/unit/out/refcount/c_struct.rs +++ b/tests/unit/out/refcount/c_struct.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Point { #[offset(0)] @@ -14,7 +14,7 @@ pub struct Point { #[offset(4)] pub y: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Line { #[offset(0)] @@ -24,7 +24,7 @@ pub struct Line { #[byte_size(8)] pub end: Point, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Node { #[offset(0)] @@ -37,7 +37,7 @@ pub type Color = u32; pub const Color_RED: Color = 0; pub const Color_GREEN: Color = 1; pub const Color_BLUE: Color = 2; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Inner { #[offset(0)] @@ -45,7 +45,7 @@ pub struct Inner { #[offset(4)] pub b: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Container { #[offset(0)] diff --git a/tests/unit/out/refcount/cast.rs b/tests/unit/out/refcount/cast.rs index e248572b18..a58c8d5bd9 100644 --- a/tests/unit/out/refcount/cast.rs +++ b/tests/unit/out/refcount/cast.rs @@ -10,7 +10,7 @@ pub type E = u32; pub const E_A: E = 0; pub const E_B: E = 1; pub const E_C: E = 2; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -18,23 +18,25 @@ pub struct Pair { #[offset(4)] pub y: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(64)] #[byte_align(64)] pub struct Wide { #[offset(0)] pub c: i8, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(40)] pub struct Grid { #[offset(0)] pub h: i32, #[offset(4)] #[byte_size(12)] + #[array_len(3)] pub row: Box<[i32]>, #[offset(16)] #[byte_size(24)] + #[array_len(2, 3)] pub cells: Box<[Box<[i32]>]>, } impl Default for Grid { @@ -50,7 +52,9 @@ impl Default for Grid { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, +)] #[byte_size(32)] pub struct Bag { #[offset(0)] diff --git a/tests/unit/out/refcount/cast_array_to_pointer_decay.rs b/tests/unit/out/refcount/cast_array_to_pointer_decay.rs index a8966503b1..4c176fcd8b 100644 --- a/tests/unit/out/refcount/cast_array_to_pointer_decay.rs +++ b/tests/unit/out/refcount/cast_array_to_pointer_decay.rs @@ -16,11 +16,12 @@ pub fn strlen_1(mut s: Ptr) -> i32 { } return c; } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(12)] pub struct Row { #[offset(0)] #[byte_size(12)] + #[array_len(3)] pub a: Box<[i32]>, } impl Default for Row { diff --git a/tests/unit/out/refcount/class.rs b/tests/unit/out/refcount/class.rs index 133f23325f..a124c94927 100644 --- a/tests/unit/out/refcount/class.rs +++ b/tests/unit/out/refcount/class.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -14,7 +14,7 @@ pub struct Pair { #[offset(4)] pub second: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Route { #[offset(0)] @@ -23,7 +23,7 @@ pub struct Route { #[offset(8)] pub cost: f64, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Counter { #[offset(0)] @@ -36,7 +36,7 @@ impl CppEq for Counter { CounterImpl::operator_eq(__lhs, __rhs.clone()) } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Tally { #[offset(0)] diff --git a/tests/unit/out/refcount/class_template_lazy_member.rs b/tests/unit/out/refcount/class_template_lazy_member.rs index 0f4f8b70ab..0cd2514117 100644 --- a/tests/unit/out/refcount/class_template_lazy_member.rs +++ b/tests/unit/out/refcount/class_template_lazy_member.rs @@ -6,32 +6,32 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Point { #[offset(0)] pub x: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Box_int_ { #[offset(0)] pub val: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Box_Point_ { #[offset(0)] #[byte_size(4)] pub val: Point, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Deduced_int_ { #[offset(0)] pub val: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Deduced_Point_ { #[offset(0)] diff --git a/tests/unit/out/refcount/class_templates.rs b/tests/unit/out/refcount/class_templates.rs index c5497d3369..f491170971 100644 --- a/tests/unit/out/refcount/class_templates.rs +++ b/tests/unit/out/refcount/class_templates.rs @@ -6,7 +6,9 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, +)] #[byte_size(24)] pub struct MyContainer_int_ { #[offset(0)] @@ -20,7 +22,9 @@ impl MyContainer_int_ { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, +)] #[byte_size(24)] pub struct MyContainer_char_ { #[offset(0)] @@ -34,7 +38,9 @@ impl MyContainer_char_ { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, +)] #[byte_size(24)] pub struct MyContainer_float_ { #[offset(0)] @@ -48,7 +54,7 @@ impl MyContainer_float_ { } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(2)] pub struct Boxed_short_ { #[offset(0)] @@ -59,7 +65,7 @@ impl Boxed_short_ { return (((v as i32) + (v as i32)) as i16); } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Boxed_int_ { #[offset(0)] @@ -70,7 +76,7 @@ impl Boxed_int_ { return (v + v); } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Boxed_long_ { #[offset(0)] @@ -81,7 +87,7 @@ impl Boxed_long_ { return (v + v); } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Outer_int__Inner_int_ { #[offset(0)] @@ -89,13 +95,13 @@ pub struct Outer_int__Inner_int_ { #[offset(4)] pub u: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Outer_int_ { #[offset(0)] pub v: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Outer_long__Inner_int_ { #[offset(0)] @@ -103,7 +109,7 @@ pub struct Outer_long__Inner_int_ { #[offset(8)] pub u: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Outer_long__Inner_char_ { #[offset(0)] @@ -111,13 +117,13 @@ pub struct Outer_long__Inner_char_ { #[offset(8)] pub u: i8, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Outer_long_ { #[offset(0)] pub v: i64, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Elem { #[offset(0)] diff --git a/tests/unit/out/refcount/clone_vs_move.rs b/tests/unit/out/refcount/clone_vs_move.rs index aa79d410b1..e039b96e3b 100644 --- a/tests/unit/out/refcount/clone_vs_move.rs +++ b/tests/unit/out/refcount/clone_vs_move.rs @@ -6,13 +6,13 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Bar { #[offset(0)] pub w: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(40)] pub struct Foo { #[offset(0)] @@ -25,6 +25,7 @@ pub struct Foo { pub z: Ptr, #[offset(24)] #[byte_size(12)] + #[array_len(3)] pub a: Box<[i32]>, #[offset(36)] #[byte_size(4)] @@ -43,7 +44,7 @@ impl Default for Foo { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Refs { #[offset(0)] diff --git a/tests/unit/out/refcount/comma_operator.rs b/tests/unit/out/refcount/comma_operator.rs index 1d63aa58e6..47e0ef07af 100644 --- a/tests/unit/out/refcount/comma_operator.rs +++ b/tests/unit/out/refcount/comma_operator.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Pair { #[offset(0)] diff --git a/tests/unit/out/refcount/complex_function.rs b/tests/unit/out/refcount/complex_function.rs index 8b53364fc4..0f8d8e2180 100644 --- a/tests/unit/out/refcount/complex_function.rs +++ b/tests/unit/out/refcount/complex_function.rs @@ -15,27 +15,27 @@ pub fn ptr_1(mut x: Ptr) -> Ptr { pub fn bar_2(x: Ptr) -> Ptr { return (x).clone(); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct X1 { #[offset(0)] pub v: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct X2 { #[offset(0)] #[byte_size(8)] pub v: Ptr, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct X3 { #[offset(0)] #[byte_size(8)] pub v: Ptr, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct X4 { #[offset(0)] diff --git a/tests/unit/out/refcount/compound_assign_paren.rs b/tests/unit/out/refcount/compound_assign_paren.rs index eba87b7b6c..d0915965f7 100644 --- a/tests/unit/out/refcount/compound_assign_paren.rs +++ b/tests/unit/out/refcount/compound_assign_paren.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct Item { #[offset(0)] diff --git a/tests/unit/out/refcount/concepts.rs b/tests/unit/out/refcount/concepts.rs index fe8b126282..2f2400e07d 100644 --- a/tests/unit/out/refcount/concepts.rs +++ b/tests/unit/out/refcount/concepts.rs @@ -11,7 +11,7 @@ const _: () = assert!( (::std::mem::size_of::() == 4_usize), "sizeof(int) == 4" ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct Sized {} pub fn is_small_0() -> bool { diff --git a/tests/unit/out/refcount/constexpr_function.rs b/tests/unit/out/refcount/constexpr_function.rs index 30a83c6b04..fc933ae67d 100644 --- a/tests/unit/out/refcount/constexpr_function.rs +++ b/tests/unit/out/refcount/constexpr_function.rs @@ -21,7 +21,7 @@ pub fn scaled_2(mut x: i32) -> i32 { pub fn half_3(mut x: f64) -> f64 { return (x / 2_f64); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Flag { #[offset(0)] @@ -44,7 +44,7 @@ const _: () = assert!(true, "in_constant_context()"); pub fn imm_7(mut b: bool) -> bool { return b; } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct P { #[offset(0)] diff --git a/tests/unit/out/refcount/constructor.rs b/tests/unit/out/refcount/constructor.rs index 5ef50fef7a..7cdc4b8e32 100644 --- a/tests/unit/out/refcount/constructor.rs +++ b/tests/unit/out/refcount/constructor.rs @@ -9,7 +9,9 @@ use std::rc::{Rc, Weak}; thread_local!( pub static total_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Destructor, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructor, Default, +)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct S { @@ -25,7 +27,7 @@ impl S { Rc::try_unwrap(__this).ok().unwrap().into_inner() } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom)] #[cpp_from(i32, new_1, value)] #[byte_size(8)] pub struct Point { diff --git a/tests/unit/out/refcount/container_element_receiver.rs b/tests/unit/out/refcount/container_element_receiver.rs index ebc969fe48..bf53df83e0 100644 --- a/tests/unit/out/refcount/container_element_receiver.rs +++ b/tests/unit/out/refcount/container_element_receiver.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, Default)] #[byte_size(32)] pub struct Holder { #[offset(0)] diff --git a/tests/unit/out/refcount/container_field_addr.rs b/tests/unit/out/refcount/container_field_addr.rs index d1903c8968..1d3099efee 100644 --- a/tests/unit/out/refcount/container_field_addr.rs +++ b/tests/unit/out/refcount/container_field_addr.rs @@ -6,7 +6,9 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, +)] #[byte_size(32)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/conversion_operator_same_translation.rs b/tests/unit/out/refcount/conversion_operator_same_translation.rs index ea9205554a..bad76bd5f0 100644 --- a/tests/unit/out/refcount/conversion_operator_same_translation.rs +++ b/tests/unit/out/refcount/conversion_operator_same_translation.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_into(i8, to_i8)] #[cpp_into(u8, to_u8)] #[byte_size(4)] @@ -14,7 +14,7 @@ pub struct S { #[offset(0)] pub v: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_into(i64, to_i64_1)] #[byte_size(4)] pub struct T { diff --git a/tests/unit/out/refcount/copy_assign.rs b/tests/unit/out/refcount/copy_assign.rs index 22f1365481..0de866275c 100644 --- a/tests/unit/out/refcount/copy_assign.rs +++ b/tests/unit/out/refcount/copy_assign.rs @@ -9,7 +9,7 @@ use std::rc::{Rc, Weak}; thread_local!( pub static assigns_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Default)] #[byte_size(8)] pub struct Partial { #[offset(0)] @@ -37,7 +37,7 @@ impl Clone for Partial { Partial::copy_from(__src.as_pointer()) } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct NonConstAssign { #[offset(0)] @@ -53,7 +53,7 @@ impl Default for NonConstAssign { { NonConstAssign::new() } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign)] #[byte_size(4)] pub struct RefQualified { #[offset(0)] @@ -69,7 +69,7 @@ impl Default for RefQualified { { RefQualified::new() } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign)] #[byte_size(24)] pub struct Holder { #[offset(0)] @@ -77,6 +77,7 @@ pub struct Holder { pub p: Partial, #[offset(8)] #[byte_size(16)] + #[array_len(2)] pub arr: Box<[Partial]>, } impl Default for Holder { @@ -94,7 +95,7 @@ impl Default for Holder { thread_local!( pub static copies_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct CopyCounted { @@ -119,7 +120,7 @@ impl Clone for CopyCounted { CopyCounted::copy_from(__src.as_pointer()) } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign)] #[byte_size(12)] pub struct HasCopyCounted { #[offset(0)] @@ -127,6 +128,7 @@ pub struct HasCopyCounted { pub c: CopyCounted, #[offset(4)] #[byte_size(8)] + #[array_len(2)] pub arr: Box<[CopyCounted]>, } impl Default for HasCopyCounted { diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index bd1cd20c38..5ed6ba9b64 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -9,7 +9,7 @@ use std::rc::{Rc, Weak}; thread_local!( pub static copies_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct Counted { @@ -34,7 +34,7 @@ impl Clone for Counted { Counted::copy_from(__src.as_pointer()) } } -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign)] #[byte_size(4)] pub struct NonConst { #[offset(0)] @@ -68,7 +68,7 @@ impl Default for NonConst { { NonConst::new() } } } -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct Ignored { @@ -91,7 +91,7 @@ impl Clone for Ignored { Ignored::copy_from(__src.as_pointer()) } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign)] #[byte_size(12)] pub struct Holder { #[offset(0)] @@ -99,6 +99,7 @@ pub struct Holder { pub c: Counted, #[offset(4)] #[byte_size(8)] + #[array_len(2)] pub arr: Box<[Counted]>, } impl Default for Holder { @@ -113,7 +114,7 @@ impl Default for Holder { } } } -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct Box_int_ { @@ -143,7 +144,7 @@ impl Clone for Box_int_ { Box_int_::copy_from(__src.as_pointer()) } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, Default)] #[byte_size(4)] pub struct Owner { #[offset(0)] @@ -157,7 +158,7 @@ impl Owner { } } } -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct OutOfLine { @@ -183,7 +184,7 @@ impl Clone for OutOfLine { } } impl OutOfLine {} -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign)] #[byte_size(4)] pub struct Tracked { #[offset(0)] diff --git a/tests/unit/out/refcount/copy_move_defaulted.rs b/tests/unit/out/refcount/copy_move_defaulted.rs index fc5ac5d32c..28c91729c1 100644 --- a/tests/unit/out/refcount/copy_move_defaulted.rs +++ b/tests/unit/out/refcount/copy_move_defaulted.rs @@ -6,13 +6,13 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Inner { #[offset(0)] pub x: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Destructor)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructor)] #[cpp_from(i32, new, value)] #[byte_size(16)] pub struct Explicit { @@ -23,6 +23,7 @@ pub struct Explicit { pub inner: Inner, #[offset(8)] #[byte_size(8)] + #[array_len(2)] pub arr: Box<[i32]>, } impl Explicit { @@ -45,7 +46,7 @@ impl Default for Explicit { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(16)] pub struct Implicit { #[offset(0)] @@ -55,6 +56,7 @@ pub struct Implicit { pub inner: Inner, #[offset(8)] #[byte_size(8)] + #[array_len(2)] pub arr: Box<[i32]>, } impl Default for Implicit { @@ -69,7 +71,17 @@ impl Default for Implicit { } } #[derive( - Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom, MoveAssign, Default, + Copy, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + MoveCtor, + CppFrom, + MoveAssign, + Default, )] #[cpp_from(i32, new, value)] #[byte_size(4)] @@ -89,7 +101,18 @@ impl DefaultCopyUserMove { __this } } -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom, CopyAssign, MoveAssign, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + MoveCtor, + CppFrom, + CopyAssign, + MoveAssign, + Default, +)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct UserCopyDefaultMove { @@ -118,7 +141,7 @@ impl Clone for UserCopyDefaultMove { UserCopyDefaultMove::copy_from(__src.as_pointer()) } } -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, CppFrom, MoveAssign)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom, MoveAssign)] #[cpp_from(i32, new, value)] #[byte_size(64)] pub struct Buffer { @@ -132,6 +155,7 @@ pub struct Buffer { pub n: i32, #[offset(52)] #[byte_size(8)] + #[array_len(2)] pub arr: Box<[i32]>, } impl Buffer { @@ -172,7 +196,7 @@ impl Default for Buffer { } } } -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, MoveAssign)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign)] #[byte_size(48)] pub struct Owner { #[offset(0)] @@ -182,6 +206,7 @@ pub struct Owner { pub n: i32, #[offset(28)] #[byte_size(8)] + #[array_len(2)] pub arr: Box<[i32]>, #[offset(40)] #[byte_size(8)] @@ -211,7 +236,9 @@ impl Default for Owner { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, +)] #[byte_size(24)] pub struct Copyable { #[offset(0)] @@ -225,7 +252,17 @@ impl Copyable { } } } -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, CppFrom, MoveAssign, Destructor, Default)] +#[derive( + Record, + ByteRepr, + ZeroInitialization, + FnPtrArg, + MoveCtor, + CppFrom, + MoveAssign, + Destructor, + Default, +)] #[cpp_from(i32, new, value)] #[byte_size(32)] pub struct Holder { diff --git a/tests/unit/out/refcount/copy_move_deleted.rs b/tests/unit/out/refcount/copy_move_deleted.rs index a99124452a..d6f0fa08fb 100644 --- a/tests/unit/out/refcount/copy_move_deleted.rs +++ b/tests/unit/out/refcount/copy_move_deleted.rs @@ -6,7 +6,9 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, CppFrom, MoveAssign, Default)] +#[derive( + Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom, MoveAssign, Default, +)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct NoCopy { @@ -25,7 +27,7 @@ impl NoCopy { __this } } -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, MoveAssign)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign)] #[byte_size(4)] pub struct PrivateCopy { #[offset(0)] @@ -48,7 +50,7 @@ impl Default for PrivateCopy { { PrivateCopy::new() } } } -#[derive(Record, ByteRepr, FnPtrArg)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg)] #[byte_size(4)] pub struct Immovable { #[offset(0)] @@ -64,7 +66,7 @@ impl Default for Immovable { { Immovable::new() } } } -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] #[byte_size(8)] pub struct Container { #[offset(0)] @@ -81,7 +83,7 @@ impl Container { } } } -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] #[byte_size(24)] pub struct VecHolder { #[offset(0)] diff --git a/tests/unit/out/refcount/default.rs b/tests/unit/out/refcount/default.rs index 1568ba56c3..907c89f632 100644 --- a/tests/unit/out/refcount/default.rs +++ b/tests/unit/out/refcount/default.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(144)] pub struct Pointers { #[offset(0)] @@ -17,9 +17,11 @@ pub struct Pointers { pub x2: Ptr, #[offset(16)] #[byte_size(40)] + #[array_len(5)] pub x3: Box<[Ptr]>, #[offset(56)] #[byte_size(80)] + #[array_len(10)] pub x4: Box<[Ptr]>, #[offset(136)] pub x5: i32, @@ -41,20 +43,23 @@ impl Default for Pointers { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(440)] pub struct SmallArrays { #[offset(0)] #[byte_size(128)] + #[array_len(32)] pub a: Box<[i32]>, #[offset(128)] #[byte_size(8)] pub f: FnPtr i32>, #[offset(136)] #[byte_size(16)] + #[array_len(2)] pub fs: Box<[FnPtr i32>]>, #[offset(152)] #[byte_size(288)] + #[array_len(2)] pub p: Box<[Pointers]>, } impl Default for SmallArrays { @@ -73,11 +78,12 @@ impl Default for SmallArrays { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(132)] pub struct BigArray { #[offset(0)] #[byte_size(132)] + #[array_len(33)] pub a: Box<[i32]>, } impl Default for BigArray { diff --git a/tests/unit/out/refcount/default_function_arguments.rs b/tests/unit/out/refcount/default_function_arguments.rs index 0b6a8cd322..d7ccc2e6cd 100644 --- a/tests/unit/out/refcount/default_function_arguments.rs +++ b/tests/unit/out/refcount/default_function_arguments.rs @@ -12,7 +12,7 @@ pub fn foo_0(mut a: i32, mut b: i32) -> i32 { pub fn baz_1(mut a: Ptr, mut b: Ptr) -> bool { return ({ a } == { b }); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct Bar { @@ -53,7 +53,7 @@ pub fn shifted_8(mut x: i32, mut y: i32) -> i32 { pub fn first_9(r: Ptr) -> i32 { return (elem!(r, 0).read()); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Holder_int_ { #[offset(0)] diff --git a/tests/unit/out/refcount/default_in_statics.rs b/tests/unit/out/refcount/default_in_statics.rs index 688ca32c59..0ea967a62d 100644 --- a/tests/unit/out/refcount/default_in_statics.rs +++ b/tests/unit/out/refcount/default_in_statics.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Inner { #[offset(0)] @@ -15,7 +15,7 @@ pub struct Inner { #[byte_size(8)] pub name: Ptr, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(88)] pub struct Outer { #[offset(0)] @@ -26,6 +26,7 @@ pub struct Outer { pub p2: Ptr, #[offset(16)] #[byte_size(24)] + #[array_len(3)] pub arr: Box<[Ptr]>, #[offset(40)] #[byte_size(8)] @@ -60,7 +61,7 @@ impl Default for Outer { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(40)] pub struct Foo { #[offset(0)] diff --git a/tests/unit/out/refcount/delete_array_order.rs b/tests/unit/out/refcount/delete_array_order.rs index cc8b8f29db..ca011a00bc 100644 --- a/tests/unit/out/refcount/delete_array_order.rs +++ b/tests/unit/out/refcount/delete_array_order.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(16)] pub struct Element { #[offset(0)] diff --git a/tests/unit/out/refcount/destructor.rs b/tests/unit/out/refcount/destructor.rs index 034b8813ec..9c6ca0d377 100644 --- a/tests/unit/out/refcount/destructor.rs +++ b/tests/unit/out/refcount/destructor.rs @@ -9,35 +9,36 @@ use std::rc::{Rc, Weak}; thread_local!( pub static global_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(1)] pub struct S {} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(1)] pub struct Defaulted { #[offset(0)] #[byte_size(1)] pub s: S, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(1)] pub struct Middle { #[offset(0)] #[byte_size(1)] pub s: S, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(1)] pub struct Outer { #[offset(0)] #[byte_size(1)] pub m: Middle, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor)] #[byte_size(3)] pub struct ArrayMember { #[offset(0)] #[byte_size(3)] + #[array_len(3)] pub items: Box<[S]>, } impl Default for ArrayMember { @@ -49,26 +50,26 @@ impl Default for ArrayMember { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(1)] pub struct EmptyBody { #[offset(0)] #[byte_size(1)] pub s: S, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(1)] pub struct Templated_char_ { #[offset(0)] pub v: i8, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(4)] pub struct Templated_int_ { #[offset(0)] pub v: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(4)] pub struct Copied { #[offset(0)] @@ -81,13 +82,13 @@ thread_local!( thread_local!( pub static order_count_2: Value = Rc::new(RefCell::new(0)); ); -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(4)] pub struct Tagged { #[offset(0)] pub tag: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(20)] pub struct Ordered { #[offset(0)] diff --git a/tests/unit/out/refcount/destructor_params.rs b/tests/unit/out/refcount/destructor_params.rs index 567c521862..b8deb4a55a 100644 --- a/tests/unit/out/refcount/destructor_params.rs +++ b/tests/unit/out/refcount/destructor_params.rs @@ -12,7 +12,7 @@ thread_local!( thread_local!( pub static last_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -27,7 +27,7 @@ pub fn with_default_3(s: S) -> i32 { let s: Value = Rc::new(RefCell::new(s)); return { (*s.borrow()).v }; } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Holder { #[offset(0)] diff --git a/tests/unit/out/refcount/destructor_temporaries.rs b/tests/unit/out/refcount/destructor_temporaries.rs index 79555ab888..808cd33023 100644 --- a/tests/unit/out/refcount/destructor_temporaries.rs +++ b/tests/unit/out/refcount/destructor_temporaries.rs @@ -12,13 +12,13 @@ thread_local!( thread_local!( pub static last_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(4)] pub struct S { #[offset(0)] pub v: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(8)] pub struct Outer { #[offset(0)] diff --git a/tests/unit/out/refcount/doubly_linked_list.rs b/tests/unit/out/refcount/doubly_linked_list.rs index d2e519c04b..b14c953f84 100644 --- a/tests/unit/out/refcount/doubly_linked_list.rs +++ b/tests/unit/out/refcount/doubly_linked_list.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(24)] pub struct Node { #[offset(0)] diff --git a/tests/unit/out/refcount/enum_default_in_static.rs b/tests/unit/out/refcount/enum_default_in_static.rs index dfef000e05..bbfeeb0727 100644 --- a/tests/unit/out/refcount/enum_default_in_static.rs +++ b/tests/unit/out/refcount/enum_default_in_static.rs @@ -10,7 +10,7 @@ pub type Mode = u32; pub const Mode_MODE_NONE: Mode = 0; pub const Mode_MODE_ONE: Mode = 1; pub const Mode_MODE_TWO: Mode = 2; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Config { #[offset(0)] diff --git a/tests/unit/out/refcount/enum_int_interop.rs b/tests/unit/out/refcount/enum_int_interop.rs index b8e78da257..d01d8fe2c3 100644 --- a/tests/unit/out/refcount/enum_int_interop.rs +++ b/tests/unit/out/refcount/enum_int_interop.rs @@ -19,7 +19,7 @@ pub type Tag = u32; pub const Tag_TAG_ZERO: Tag = 0; pub const Tag_TAG_ONE: Tag = 1; pub const Tag_TAG_TWO: Tag = 2; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Entry { #[offset(0)] diff --git a/tests/unit/out/refcount/enum_int_interop_c.rs b/tests/unit/out/refcount/enum_int_interop_c.rs index 09c258402e..fdba30d553 100644 --- a/tests/unit/out/refcount/enum_int_interop_c.rs +++ b/tests/unit/out/refcount/enum_int_interop_c.rs @@ -19,7 +19,7 @@ pub type Tag_enum = u32; pub const Tag_enum_TAG_ZERO: Tag_enum = 0; pub const Tag_enum_TAG_ONE: Tag_enum = 1; pub const Tag_enum_TAG_TWO: Tag_enum = 2; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Entry { #[offset(0)] diff --git a/tests/unit/out/refcount/enum_underlying_type.rs b/tests/unit/out/refcount/enum_underlying_type.rs index 1bd07e6977..b7f3132c3c 100644 --- a/tests/unit/out/refcount/enum_underlying_type.rs +++ b/tests/unit/out/refcount/enum_underlying_type.rs @@ -25,7 +25,7 @@ pub type Scoped = i8; pub const Scoped_NEG: Scoped = -2; pub const Scoped_POS: Scoped = 2; pub type Empty = bool; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(1)] pub struct HoldsEmpty { #[offset(0)] diff --git a/tests/unit/out/refcount/exprs.rs b/tests/unit/out/refcount/exprs.rs index e183797f18..5072945418 100644 --- a/tests/unit/out/refcount/exprs.rs +++ b/tests/unit/out/refcount/exprs.rs @@ -6,13 +6,13 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct X { #[offset(0)] pub x: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Y { #[offset(0)] diff --git a/tests/unit/out/refcount/fft.rs b/tests/unit/out/refcount/fft.rs index 4cabd16d64..f2c3321109 100644 --- a/tests/unit/out/refcount/fft.rs +++ b/tests/unit/out/refcount/fft.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Complex { #[offset(0)] diff --git a/tests/unit/out/refcount/field_aliasing.rs b/tests/unit/out/refcount/field_aliasing.rs index 313688bec9..5d5cd52e68 100644 --- a/tests/unit/out/refcount/field_aliasing.rs +++ b/tests/unit/out/refcount/field_aliasing.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct In { #[offset(0)] @@ -14,7 +14,7 @@ pub struct In { #[offset(4)] pub y: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(32)] pub struct S { #[offset(0)] @@ -26,6 +26,7 @@ pub struct S { pub n: i32, #[offset(16)] #[byte_size(16)] + #[array_len(4)] pub arr: Box<[i32]>, } impl Default for S { @@ -40,7 +41,7 @@ impl Default for S { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Node { #[offset(0)] diff --git a/tests/unit/out/refcount/field_array_elem_ptr.rs b/tests/unit/out/refcount/field_array_elem_ptr.rs index 72015b408c..ec95ed28e5 100644 --- a/tests/unit/out/refcount/field_array_elem_ptr.rs +++ b/tests/unit/out/refcount/field_array_elem_ptr.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Point { #[offset(0)] @@ -14,16 +14,18 @@ pub struct Point { #[offset(4)] pub y: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(48)] pub struct Shape { #[offset(0)] pub id: i32, #[offset(4)] #[byte_size(16)] + #[array_len(4)] pub coords: Box<[i32]>, #[offset(20)] #[byte_size(24)] + #[array_len(3)] pub points: Box<[Point]>, #[offset(44)] pub tail: i32, diff --git a/tests/unit/out/refcount/field_method_receiver.rs b/tests/unit/out/refcount/field_method_receiver.rs index 4180da7a85..54c0fb8dd8 100644 --- a/tests/unit/out/refcount/field_method_receiver.rs +++ b/tests/unit/out/refcount/field_method_receiver.rs @@ -6,13 +6,13 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Counter { #[offset(0)] pub n: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign)] #[byte_size(40)] pub struct S { #[offset(0)] @@ -22,6 +22,7 @@ pub struct S { pub c: Counter, #[offset(8)] #[byte_size(8)] + #[array_len(2)] pub arr: Box<[Counter]>, #[offset(16)] #[byte_size(24)] diff --git a/tests/unit/out/refcount/field_pointers.rs b/tests/unit/out/refcount/field_pointers.rs index 22fb971951..35fb9a34c2 100644 --- a/tests/unit/out/refcount/field_pointers.rs +++ b/tests/unit/out/refcount/field_pointers.rs @@ -6,13 +6,14 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(12)] pub struct Inner { #[offset(0)] pub a: i32, #[offset(4)] #[byte_size(8)] + #[array_len(8)] pub name: Box<[i8]>, } impl Default for Inner { @@ -25,7 +26,7 @@ impl Default for Inner { } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Header { #[offset(0)] @@ -33,7 +34,7 @@ pub struct Header { #[offset(4)] pub size: i16, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign)] #[byte_size(104)] pub struct Outer { #[offset(0)] @@ -43,6 +44,7 @@ pub struct Outer { pub inner: Inner, #[offset(16)] #[byte_size(36)] + #[array_len(3)] pub items: Box<[Inner]>, #[offset(56)] #[byte_size(24)] @@ -52,6 +54,7 @@ pub struct Outer { pub cursor: Ptr, #[offset(88)] #[byte_size(16)] + #[array_len(4)] pub buf: Box<[i32]>, } impl Outer { diff --git a/tests/unit/out/refcount/field_pointers_malloced_struct.rs b/tests/unit/out/refcount/field_pointers_malloced_struct.rs index dc4b1b0639..d74abec99b 100644 --- a/tests/unit/out/refcount/field_pointers_malloced_struct.rs +++ b/tests/unit/out/refcount/field_pointers_malloced_struct.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(12)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/field_reinterpret_write_through.rs b/tests/unit/out/refcount/field_reinterpret_write_through.rs index 5fe2ac720d..53c8f2326a 100644 --- a/tests/unit/out/refcount/field_reinterpret_write_through.rs +++ b/tests/unit/out/refcount/field_reinterpret_write_through.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct In { #[offset(0)] @@ -14,7 +14,7 @@ pub struct In { #[offset(4)] pub b: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(40)] pub struct S { #[offset(0)] @@ -24,9 +24,11 @@ pub struct S { pub in_: In, #[offset(12)] #[byte_size(4)] + #[array_len(4)] pub bytes: Box<[u8]>, #[offset(16)] #[byte_size(12)] + #[array_len(3)] pub arr: Box<[i32]>, #[offset(32)] pub tail: i64, diff --git a/tests/unit/out/refcount/find.rs b/tests/unit/out/refcount/find.rs index abe4b00636..b1b2b36bdb 100644 --- a/tests/unit/out/refcount/find.rs +++ b/tests/unit/out/refcount/find.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct P { #[offset(0)] diff --git a/tests/unit/out/refcount/first_field_ptr_covers_struct.rs b/tests/unit/out/refcount/first_field_ptr_covers_struct.rs index cf6b7a8bc4..81358273ee 100644 --- a/tests/unit/out/refcount/first_field_ptr_covers_struct.rs +++ b/tests/unit/out/refcount/first_field_ptr_covers_struct.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct In { #[offset(0)] @@ -14,7 +14,7 @@ pub struct In { #[offset(2)] pub b: i16, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(12)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/first_member_downcast.rs b/tests/unit/out/refcount/first_member_downcast.rs index f0b38972a0..0e766a79e7 100644 --- a/tests/unit/out/refcount/first_member_downcast.rs +++ b/tests/unit/out/refcount/first_member_downcast.rs @@ -6,13 +6,13 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct base { #[offset(0)] pub kind: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct derived { #[offset(0)] diff --git a/tests/unit/out/refcount/flex_array_member_incomplete.rs b/tests/unit/out/refcount/flex_array_member_incomplete.rs index d3e63edf9d..1be33956bd 100644 --- a/tests/unit/out/refcount/flex_array_member_incomplete.rs +++ b/tests/unit/out/refcount/flex_array_member_incomplete.rs @@ -6,13 +6,14 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct F { #[offset(0)] pub n: i32, #[offset(4)] #[byte_size(0)] + #[array_len(0)] pub tail: Box<[i8]>, } impl Default for F { diff --git a/tests/unit/out/refcount/flex_array_member_sibling_write.rs b/tests/unit/out/refcount/flex_array_member_sibling_write.rs index cea9803196..443107535a 100644 --- a/tests/unit/out/refcount/flex_array_member_sibling_write.rs +++ b/tests/unit/out/refcount/flex_array_member_sibling_write.rs @@ -6,13 +6,14 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(8)] pub struct S { #[offset(0)] pub n: i32, #[offset(4)] #[byte_size(1)] + #[array_len(1)] pub name: Box<[i8]>, } impl Default for S { @@ -25,7 +26,7 @@ impl Default for S { } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct E { #[offset(0)] @@ -33,7 +34,7 @@ pub struct E { #[offset(4)] pub w: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(16)] pub struct T { #[offset(0)] @@ -42,6 +43,7 @@ pub struct T { pub cap: i32, #[offset(8)] #[byte_size(8)] + #[array_len(1)] pub a: Box<[E]>, } impl Default for T { diff --git a/tests/unit/out/refcount/fn_ptr.rs b/tests/unit/out/refcount/fn_ptr.rs index 6d2d59afd4..150c149f61 100644 --- a/tests/unit/out/refcount/fn_ptr.rs +++ b/tests/unit/out/refcount/fn_ptr.rs @@ -28,7 +28,7 @@ pub fn call_fn_5(mut f: FnPtr usize>, mut v: i32) -> usize { pub fn identity_hash_6(mut v: bool) -> usize { return (v as usize); } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_from(FnPtr u64 > , new, ptr)] #[byte_size(8)] pub struct HashHolder_unsigned_long__ptr__bool__ { diff --git a/tests/unit/out/refcount/fn_ptr_cast.rs b/tests/unit/out/refcount/fn_ptr_cast.rs index 8c612fa1eb..72fe1d2075 100644 --- a/tests/unit/out/refcount/fn_ptr_cast.rs +++ b/tests/unit/out/refcount/fn_ptr_cast.rs @@ -24,7 +24,7 @@ pub fn test_double_cast_2() { assert!((({ fn2.call(5,) }) == 10)); assert!(({ (fn2).clone() } == { (fn_).clone() })); } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Command { #[offset(0)] diff --git a/tests/unit/out/refcount/fn_ptr_stable_sort.rs b/tests/unit/out/refcount/fn_ptr_stable_sort.rs index 52678d12ad..9702cd4443 100644 --- a/tests/unit/out/refcount/fn_ptr_stable_sort.rs +++ b/tests/unit/out/refcount/fn_ptr_stable_sort.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Item { #[offset(0)] diff --git a/tests/unit/out/refcount/fn_ptr_struct.rs b/tests/unit/out/refcount/fn_ptr_struct.rs index 87f3498422..aaf75497a7 100644 --- a/tests/unit/out/refcount/fn_ptr_struct.rs +++ b/tests/unit/out/refcount/fn_ptr_struct.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Handler { #[offset(0)] @@ -21,7 +21,7 @@ pub fn double_it_0(mut x: i32) -> i32 { pub fn negate_1(mut x: i32) -> i32 { return -x; } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct S {} impl S { @@ -35,7 +35,7 @@ impl S { return (x + 3); } } -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct MoveOnly { diff --git a/tests/unit/out/refcount/fn_ptr_typedef_cast.rs b/tests/unit/out/refcount/fn_ptr_typedef_cast.rs index 1a4f43a4a2..a72c15adba 100644 --- a/tests/unit/out/refcount/fn_ptr_typedef_cast.rs +++ b/tests/unit/out/refcount/fn_ptr_typedef_cast.rs @@ -18,7 +18,7 @@ pub fn via_size_t_param_2(mut b: usize) -> u64 { pub fn via_size_t_return_3(mut b: u64) -> usize { return (b as usize); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct pair { #[offset(0)] diff --git a/tests/unit/out/refcount/fn_ptr_vtable.rs b/tests/unit/out/refcount/fn_ptr_vtable.rs index 81aec298e7..b9281b2847 100644 --- a/tests/unit/out/refcount/fn_ptr_vtable.rs +++ b/tests/unit/out/refcount/fn_ptr_vtable.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(24)] pub struct Vtable { #[offset(0)] diff --git a/tests/unit/out/refcount/fn_ref.rs b/tests/unit/out/refcount/fn_ref.rs index ae78ca2d93..e00efd7f20 100644 --- a/tests/unit/out/refcount/fn_ref.rs +++ b/tests/unit/out/refcount/fn_ref.rs @@ -21,7 +21,7 @@ pub fn call_deduced_3(f: FnPtr i32>, mut x: i32) -> i32 { pub fn call_forwarded_4(f: FnPtr i32>, mut x: i32) -> i32 { return ({ f.call(x) }); } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Holder { #[offset(0)] diff --git a/tests/unit/out/refcount/for_body_destructor.rs b/tests/unit/out/refcount/for_body_destructor.rs index 60ff9056a1..c150844a4f 100644 --- a/tests/unit/out/refcount/for_body_destructor.rs +++ b/tests/unit/out/refcount/for_body_destructor.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(4)] pub struct Guard { #[offset(0)] diff --git a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs index 0d7a42161e..eb39f2478d 100644 --- a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs @@ -6,7 +6,9 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, +)] #[byte_size(32)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/forward_basic.rs b/tests/unit/out/refcount/forward_basic.rs index a6ffefe6dd..13dc21e01f 100644 --- a/tests/unit/out/refcount/forward_basic.rs +++ b/tests/unit/out/refcount/forward_basic.rs @@ -9,7 +9,7 @@ use std::rc::{Rc, Weak}; pub type Overload = u32; pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(12)] pub struct Tracked { @@ -75,7 +75,9 @@ impl Holder { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default, +)] #[cpp_from(Tracked, new_1, mut_ptr)] #[cpp_from_move(Tracked, new_2, ptr)] #[byte_size(12)] diff --git a/tests/unit/out/refcount/forward_decltype.rs b/tests/unit/out/refcount/forward_decltype.rs index 5b0bee3a98..ab2b722c0c 100644 --- a/tests/unit/out/refcount/forward_decltype.rs +++ b/tests/unit/out/refcount/forward_decltype.rs @@ -9,7 +9,7 @@ use std::rc::{Rc, Weak}; pub type Overload = u32; pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(12)] pub struct Tracked { diff --git a/tests/unit/out/refcount/forward_explicit.rs b/tests/unit/out/refcount/forward_explicit.rs index 8e6dcf4673..68f171717b 100644 --- a/tests/unit/out/refcount/forward_explicit.rs +++ b/tests/unit/out/refcount/forward_explicit.rs @@ -11,7 +11,7 @@ pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; pub const Overload_kIntLvalueOverload: Overload = 3; pub const Overload_kIntRvalueOverload: Overload = 4; -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(12)] pub struct Tracked { diff --git a/tests/unit/out/refcount/forward_pack.rs b/tests/unit/out/refcount/forward_pack.rs index a251532466..0bf4058417 100644 --- a/tests/unit/out/refcount/forward_pack.rs +++ b/tests/unit/out/refcount/forward_pack.rs @@ -11,7 +11,7 @@ pub const Overload_kLvalueOverload: Overload = 1; pub const Overload_kRvalueOverload: Overload = 2; pub const Overload_kIntLvalueOverload: Overload = 3; pub const Overload_kIntRvalueOverload: Overload = 4; -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(12)] pub struct Tracked { @@ -120,7 +120,7 @@ impl Pair { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, Default)] #[byte_size(24)] pub struct Pair { #[offset(0)] diff --git a/tests/unit/out/refcount/friend.rs b/tests/unit/out/refcount/friend.rs index 747600f712..243527c9e9 100644 --- a/tests/unit/out/refcount/friend.rs +++ b/tests/unit/out/refcount/friend.rs @@ -18,7 +18,7 @@ pub fn scaled_2(v: Ptr, mut k: i32) -> i32 { pub fn scaled_3(v: Ptr, mut k: f64) -> f64 { return ({ (v.with(|__s| __s.x) as f64) } * { k }); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct V { #[offset(0)] @@ -32,7 +32,7 @@ impl CppEq for V { pub fn get_4(w: Ptr) -> i32 { return w.with(|__s| __s.x); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct W_int_ { #[offset(0)] @@ -41,13 +41,13 @@ pub struct W_int_ { pub fn get_5(w: Ptr) -> i64 { return w.with(|__s| __s.x); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct W_long_ { #[offset(0)] pub x: i64, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct D { #[offset(0)] diff --git a/tests/unit/out/refcount/function_overloading.rs b/tests/unit/out/refcount/function_overloading.rs index 7c2f6875ad..71ceb664e8 100644 --- a/tests/unit/out/refcount/function_overloading.rs +++ b/tests/unit/out/refcount/function_overloading.rs @@ -21,7 +21,7 @@ pub fn foo_3(mut x: Ptr, mut y: Ptr, z: Ptr) -> i32 { pub fn bar_4(x: Ptr) -> i32 { return (x.read()); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct Foo {} pub fn func_5(mut x: i32) -> i32 { diff --git a/tests/unit/out/refcount/global_call_temporaries.rs b/tests/unit/out/refcount/global_call_temporaries.rs index 6beec818a6..37e88e9bdc 100644 --- a/tests/unit/out/refcount/global_call_temporaries.rs +++ b/tests/unit/out/refcount/global_call_temporaries.rs @@ -93,7 +93,7 @@ thread_local!( }) })); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Item { #[offset(0)] diff --git a/tests/unit/out/refcount/global_init_side_effect.rs b/tests/unit/out/refcount/global_init_side_effect.rs index 457879c99c..fcf0162e8a 100644 --- a/tests/unit/out/refcount/global_init_side_effect.rs +++ b/tests/unit/out/refcount/global_init_side_effect.rs @@ -9,7 +9,7 @@ use std::rc::{Rc, Weak}; thread_local!( pub static total_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(1)] pub struct S {} diff --git a/tests/unit/out/refcount/global_non_const_init.rs b/tests/unit/out/refcount/global_non_const_init.rs index bbb65e63d8..5edef0f578 100644 --- a/tests/unit/out/refcount/global_non_const_init.rs +++ b/tests/unit/out/refcount/global_non_const_init.rs @@ -32,7 +32,7 @@ thread_local!( pub static depends_on_call_6: Value = Rc::new(RefCell::new((from_call_5.with(|rc| *rc.borrow()) + 1))); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct Ctor { #[offset(0)] @@ -67,7 +67,7 @@ thread_local!( thread_local!( pub static inline_member_11: Value = Rc::new(RefCell::new(Ctor::new_2({ 5 }))); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct Holder {} thread_local!( @@ -82,7 +82,7 @@ thread_local!( thread_local!( static local_ctor_14: Value = Rc::new(RefCell::new(Ctor::new_2({ 3 }))); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct Singleton { #[offset(0)] diff --git a/tests/unit/out/refcount/global_pointers.rs b/tests/unit/out/refcount/global_pointers.rs index d8c3c88775..bc212fab16 100644 --- a/tests/unit/out/refcount/global_pointers.rs +++ b/tests/unit/out/refcount/global_pointers.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Entry { #[offset(0)] diff --git a/tests/unit/out/refcount/global_without_initializer.rs b/tests/unit/out/refcount/global_without_initializer.rs index a6fab960df..1990136dff 100644 --- a/tests/unit/out/refcount/global_without_initializer.rs +++ b/tests/unit/out/refcount/global_without_initializer.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/goto_aggregate_default.rs b/tests/unit/out/refcount/goto_aggregate_default.rs index b5af3228dc..0449ac8471 100644 --- a/tests/unit/out/refcount/goto_aggregate_default.rs +++ b/tests/unit/out/refcount/goto_aggregate_default.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Point { #[offset(0)] diff --git a/tests/unit/out/refcount/goto_cleanup.rs b/tests/unit/out/refcount/goto_cleanup.rs index 85ba2ab652..4afb08cad2 100644 --- a/tests/unit/out/refcount/goto_cleanup.rs +++ b/tests/unit/out/refcount/goto_cleanup.rs @@ -76,7 +76,7 @@ pub fn from_switch_2(mut n: i32) -> i32 { }); panic!("ub: non-void function does not return a value") } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct wrapper { #[offset(0)] diff --git a/tests/unit/out/refcount/huffman.rs b/tests/unit/out/refcount/huffman.rs index 47ef40b9c5..a41b1ade17 100644 --- a/tests/unit/out/refcount/huffman.rs +++ b/tests/unit/out/refcount/huffman.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(24)] pub struct MinHeapNode { #[offset(0)] @@ -44,7 +44,7 @@ pub fn Swap_0(a: Ptr, b: Ptr) { } }); } -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] #[byte_size(32)] pub struct MinHeap { #[offset(0)] 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 ef204e1c16..db4781d98d 100644 --- a/tests/unit/out/refcount/immutable-deref-on-func-call.rs +++ b/tests/unit/out/refcount/immutable-deref-on-func-call.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Item { #[offset(0)] diff --git a/tests/unit/out/refcount/implicit_autoref.rs b/tests/unit/out/refcount/implicit_autoref.rs index bf8a1d6c85..978f439507 100644 --- a/tests/unit/out/refcount/implicit_autoref.rs +++ b/tests/unit/out/refcount/implicit_autoref.rs @@ -6,7 +6,9 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, +)] #[byte_size(24)] pub struct Holder { #[offset(0)] diff --git a/tests/unit/out/refcount/in_class_field_initializer.rs b/tests/unit/out/refcount/in_class_field_initializer.rs index 2fe6413521..876d3d0b04 100644 --- a/tests/unit/out/refcount/in_class_field_initializer.rs +++ b/tests/unit/out/refcount/in_class_field_initializer.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(8)] pub struct Inner { #[offset(0)] @@ -19,7 +19,7 @@ impl Default for Inner { { Inner { x: 3, y: 4 } } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(24)] pub struct S { #[offset(0)] @@ -45,7 +45,7 @@ impl Default for S { } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(8)] pub struct Boxed_int_ { #[offset(0)] diff --git a/tests/unit/out/refcount/init.rs b/tests/unit/out/refcount/init.rs index f52ddd1f4a..f9b6d67e5a 100644 --- a/tests/unit/out/refcount/init.rs +++ b/tests/unit/out/refcount/init.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct X { #[offset(0)] diff --git a/tests/unit/out/refcount/init_list.rs b/tests/unit/out/refcount/init_list.rs index f161ecffc0..22e7b80b0b 100644 --- a/tests/unit/out/refcount/init_list.rs +++ b/tests/unit/out/refcount/init_list.rs @@ -9,7 +9,7 @@ use std::rc::{Rc, Weak}; pub fn f_0(list: Vec) { let list: Value> = Rc::new(RefCell::new(list)); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -17,7 +17,7 @@ pub struct Pair { #[offset(4)] pub b: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(8)] pub struct Holder { #[offset(0)] @@ -36,7 +36,7 @@ impl Default for Holder { pub fn sum_1(p: Ptr) -> i32 { return ({ p.with(|__s| __s.a) } + { p.with(|__s| __s.b) }); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct Seven { #[offset(0)] diff --git a/tests/unit/out/refcount/inline_container_fields.rs b/tests/unit/out/refcount/inline_container_fields.rs index 6f97f26588..b357458ad3 100644 --- a/tests/unit/out/refcount/inline_container_fields.rs +++ b/tests/unit/out/refcount/inline_container_fields.rs @@ -6,13 +6,14 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign)] #[byte_size(48)] pub struct Elem { #[offset(0)] pub id: i32, #[offset(4)] #[byte_size(16)] + #[array_len(4)] pub hist: Box<[i32]>, #[offset(24)] #[byte_size(24)] @@ -40,16 +41,18 @@ impl Default for Elem { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign)] #[byte_size(88)] pub struct State { #[offset(0)] pub count: i32, #[offset(4)] #[byte_size(24)] + #[array_len(2, 3)] pub grid: Box<[Box<[i32]>]>, #[offset(28)] #[byte_size(12)] + #[array_len(3)] pub arr: Box<[i32]>, #[offset(40)] #[byte_size(24)] @@ -154,7 +157,9 @@ thread_local!( thread_local!( pub static move_assigns_5: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CopyAssign, MoveAssign)] +#[derive( + Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CopyAssign, MoveAssign, +)] #[byte_size(4)] pub struct Counted { #[offset(0)] diff --git a/tests/unit/out/refcount/kruskal.rs b/tests/unit/out/refcount/kruskal.rs index 94fb576e50..a0dc746fd8 100644 --- a/tests/unit/out/refcount/kruskal.rs +++ b/tests/unit/out/refcount/kruskal.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Edge { #[offset(0)] @@ -116,7 +116,7 @@ pub fn quicksort_1(arr: Ptr>>>, mut start: i32, mut end quicksort_1(_arr, _start, _end) }); } -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] #[byte_size(24)] pub struct DisjointSet { #[offset(0)] @@ -137,7 +137,7 @@ impl DisjointSet { } } } -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] #[byte_size(16)] pub struct Graph { #[offset(0)] diff --git a/tests/unit/out/refcount/lambda_as_field.rs b/tests/unit/out/refcount/lambda_as_field.rs index 3287edcb88..784a89b5ab 100644 --- a/tests/unit/out/refcount/lambda_as_field.rs +++ b/tests/unit/out/refcount/lambda_as_field.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor)] #[byte_size(1)] pub struct Guard__lambda_at_lambda_as_field_cpp_34_13__ { #[offset(0)] @@ -24,14 +24,14 @@ impl Default for Guard__lambda_at_lambda_as_field_cpp_34_13__ { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] #[byte_size(8)] pub struct Guard__lambda_at_lambda_as_field_cpp_45_13__ { #[offset(0)] #[byte_size(8)] pub f: FnPtr, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(8)] pub struct Holder__lambda_at_lambda_as_field_cpp_39_12__ { #[offset(0)] @@ -54,7 +54,7 @@ impl Default for Holder__lambda_at_lambda_as_field_cpp_39_12__ { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Holder__lambda_at_lambda_as_field_cpp_51_12__ { #[offset(0)] @@ -63,7 +63,7 @@ pub struct Holder__lambda_at_lambda_as_field_cpp_51_12__ { #[offset(4)] pub calls: i32, } -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, CppFrom)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom)] #[cpp_from(FnPtr i32 > , new, value)] #[byte_size(8)] pub struct Moving__lambda_at_lambda_as_field_cpp_64_12__ { diff --git a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs index daf1e89e2e..956e7a8c7b 100644 --- a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor)] #[byte_size(8)] pub struct Counted { #[offset(0)] @@ -51,7 +51,7 @@ impl Default for Counted { thread_local!( pub static drops_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, Destructor)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, Destructor)] #[byte_size(1)] pub struct Dropped {} impl Dropped { diff --git a/tests/unit/out/refcount/lambda_capture_ref.rs b/tests/unit/out/refcount/lambda_capture_ref.rs index ba60856059..2321c38781 100644 --- a/tests/unit/out/refcount/lambda_capture_ref.rs +++ b/tests/unit/out/refcount/lambda_capture_ref.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/lambda_capture_star_this.rs b/tests/unit/out/refcount/lambda_capture_star_this.rs index 0c69a772e6..28fbaaf607 100644 --- a/tests/unit/out/refcount/lambda_capture_star_this.rs +++ b/tests/unit/out/refcount/lambda_capture_star_this.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/lambda_capture_this.rs b/tests/unit/out/refcount/lambda_capture_this.rs index 383d321597..b95e001bd5 100644 --- a/tests/unit/out/refcount/lambda_capture_this.rs +++ b/tests/unit/out/refcount/lambda_capture_this.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/lambda_capture_value.rs b/tests/unit/out/refcount/lambda_capture_value.rs index 08ad9d928b..4fa6b5688b 100644 --- a/tests/unit/out/refcount/lambda_capture_value.rs +++ b/tests/unit/out/refcount/lambda_capture_value.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/lambda_decltype_type.rs b/tests/unit/out/refcount/lambda_decltype_type.rs index 58a8a26dc4..cf2ee98ce5 100644 --- a/tests/unit/out/refcount/lambda_decltype_type.rs +++ b/tests/unit/out/refcount/lambda_decltype_type.rs @@ -6,11 +6,12 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(24)] pub struct Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { #[offset(0)] #[byte_size(16)] + #[array_len(4)] pub items: Box<[i32]>, #[offset(16)] pub size: i32, @@ -33,11 +34,12 @@ impl Default for Sorted__lambda_at_lambda_decltype_type_cpp_22_18__ { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(24)] pub struct Sorted__lambda_at_lambda_decltype_type_cpp_19_23__ { #[offset(0)] #[byte_size(16)] + #[array_len(4)] pub items: Box<[i32]>, #[offset(16)] pub size: i32, diff --git a/tests/unit/out/refcount/lambda_generic_explicit_args.rs b/tests/unit/out/refcount/lambda_generic_explicit_args.rs index 0933e93300..1102aa786f 100644 --- a/tests/unit/out/refcount/lambda_generic_explicit_args.rs +++ b/tests/unit/out/refcount/lambda_generic_explicit_args.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Val { #[offset(0)] diff --git a/tests/unit/out/refcount/lambda_immediate_init.rs b/tests/unit/out/refcount/lambda_immediate_init.rs index b8c8d87ea3..6aeb494e2e 100644 --- a/tests/unit/out/refcount/lambda_immediate_init.rs +++ b/tests/unit/out/refcount/lambda_immediate_init.rs @@ -9,7 +9,7 @@ use std::rc::{Rc, Weak}; pub fn pick_0(mut x: i32) -> i32 { return x; } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(8)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/lambda_move_only_capture.rs b/tests/unit/out/refcount/lambda_move_only_capture.rs index f04a28cdcb..3d0fa6b821 100644 --- a/tests/unit/out/refcount/lambda_move_only_capture.rs +++ b/tests/unit/out/refcount/lambda_move_only_capture.rs @@ -6,7 +6,9 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, CppFrom, Destructor, Default)] +#[derive( + Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom, Destructor, Default, +)] #[cpp_from(i32, new, value)] #[byte_size(8)] pub struct Owner { diff --git a/tests/unit/out/refcount/lambda_nested.rs b/tests/unit/out/refcount/lambda_nested.rs index c0842b1f29..ba8bf59b16 100644 --- a/tests/unit/out/refcount/lambda_nested.rs +++ b/tests/unit/out/refcount/lambda_nested.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/lambda_static_local.rs b/tests/unit/out/refcount/lambda_static_local.rs index cc78231f56..7015e7960a 100644 --- a/tests/unit/out/refcount/lambda_static_local.rs +++ b/tests/unit/out/refcount/lambda_static_local.rs @@ -78,7 +78,7 @@ thread_local!( thread_local!( static calls_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct P_4 { #[offset(0)] diff --git a/tests/unit/out/refcount/libc_struct_without_default.rs b/tests/unit/out/refcount/libc_struct_without_default.rs index 790d94b34b..8deaec11ea 100644 --- a/tests/unit/out/refcount/libc_struct_without_default.rs +++ b/tests/unit/out/refcount/libc_struct_without_default.rs @@ -6,11 +6,12 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign)] #[byte_size(32)] pub struct UserDefined { #[offset(0)] #[byte_size(4)] + #[array_len(1)] pub a: Box<[i32]>, #[offset(8)] #[byte_size(24)] @@ -36,7 +37,7 @@ impl Default for UserDefined { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(16)] pub struct FieldIsLibcType { #[offset(0)] diff --git a/tests/unit/out/refcount/linked_list.rs b/tests/unit/out/refcount/linked_list.rs index 70e04b4246..77b67a330e 100644 --- a/tests/unit/out/refcount/linked_list.rs +++ b/tests/unit/out/refcount/linked_list.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Node { #[offset(0)] diff --git a/tests/unit/out/refcount/local_anon_struct_collision.rs b/tests/unit/out/refcount/local_anon_struct_collision.rs index 5bf56af28a..c00fcb21b3 100644 --- a/tests/unit/out/refcount/local_anon_struct_collision.rs +++ b/tests/unit/out/refcount/local_anon_struct_collision.rs @@ -12,7 +12,7 @@ pub fn first_0() -> i32 { p.y = 2; return (p.x + p.y); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct anon_1 { #[offset(0)] @@ -26,7 +26,7 @@ pub fn second_2() -> i32 { q.b = 20_i64; return ((q.a + q.b) as i32); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct anon_3 { #[offset(0)] diff --git a/tests/unit/out/refcount/local_record_template.rs b/tests/unit/out/refcount/local_record_template.rs index 7b9a25a7ed..a8902e358c 100644 --- a/tests/unit/out/refcount/local_record_template.rs +++ b/tests/unit/out/refcount/local_record_template.rs @@ -29,13 +29,13 @@ pub fn wrap_10(mut v: i64) -> i32 { let mut l: Local_7 = Local_7 { x: v }; return ({ get_6(l) }); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Local_5 { #[offset(0)] pub x: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Local_7 { #[offset(0)] @@ -45,7 +45,7 @@ pub fn other_11() -> i32 { let mut l: Local_1 = Local_1 { x: 3_i64, y: 4_i64 }; return (({ get_0(l) }) + (l.y as i32)); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Local_1 { #[offset(0)] @@ -66,7 +66,7 @@ fn main_0() -> i32 { assert!((({ wrap_10(6_i64,) }) == 6)); return 0; } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Local_3 { #[offset(0)] diff --git a/tests/unit/out/refcount/map.rs b/tests/unit/out/refcount/map.rs index 73ceea07ab..d3e353e73f 100644 --- a/tests/unit/out/refcount/map.rs +++ b/tests/unit/out/refcount/map.rs @@ -12,7 +12,7 @@ pub fn foo_0(mut x: u32) { pub fn bar_1(x: Ptr) { x.write({ (x.read()).wrapping_add(1_u32) }); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(8)] pub struct Point { #[offset(0)] diff --git a/tests/unit/out/refcount/map_key_copy_ctor.rs b/tests/unit/out/refcount/map_key_copy_ctor.rs index 2e7f91d5b6..d1f4d84c5a 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -15,7 +15,7 @@ thread_local!( thread_local!( pub static made_2: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct Key { diff --git a/tests/unit/out/refcount/map_key_identity.rs b/tests/unit/out/refcount/map_key_identity.rs index 8d9695dd17..7241cd10fe 100644 --- a/tests/unit/out/refcount/map_key_identity.rs +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -9,7 +9,7 @@ use std::rc::{Rc, Weak}; thread_local!( pub static default_constructions_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Key { #[offset(0)] @@ -33,7 +33,7 @@ pub fn operator_lt_1(a: Ptr, b: Ptr) -> bool { 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, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct Mapped { #[offset(0)] diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index f64adfeced..afb5dda8ab 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -18,7 +18,7 @@ thread_local!( thread_local!( pub static moves_3: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom)] #[cpp_from(i32, new_1, value)] #[byte_size(4)] pub struct Item { @@ -67,7 +67,7 @@ pub fn argument_4(item: Ptr) -> Ptr { (*calls_0.with(Value::clone).borrow_mut()).prefix_inc(); return (item).clone(); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct RefItem { #[offset(0)] diff --git a/tests/unit/out/refcount/map_try_emplace_lvalues.rs b/tests/unit/out/refcount/map_try_emplace_lvalues.rs index 906db21ba5..154a5c06e5 100644 --- a/tests/unit/out/refcount/map_try_emplace_lvalues.rs +++ b/tests/unit/out/refcount/map_try_emplace_lvalues.rs @@ -12,7 +12,7 @@ thread_local!( thread_local!( pub static visits_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct Item { #[offset(0)] @@ -54,13 +54,14 @@ pub fn place_3(n: Ptr) -> Ptr { thread_local!( pub static temporary_calls_4: Value = Rc::new(RefCell::new(0)); ); -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(12)] pub struct Temporary { #[offset(0)] pub n: i32, #[offset(4)] #[byte_size(8)] + #[array_len(2)] pub data: Box<[i32]>, } impl Temporary { @@ -78,7 +79,7 @@ impl Default for Temporary { { Temporary::new() } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(12)] pub struct Nested { #[offset(0)] @@ -91,7 +92,7 @@ pub fn make_temporary_5() -> Temporary { pub fn make_nested_6() -> Nested { return ::default(); } -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, MoveAssign)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign)] #[byte_size(8)] pub struct Owner { #[offset(0)] @@ -115,7 +116,7 @@ impl Default for Owner { { Owner::new() } } } -#[derive(Record, ByteRepr, FnPtrArg)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg)] #[byte_size(4)] pub struct Noncopy { #[offset(0)] @@ -126,7 +127,7 @@ impl Default for Noncopy { { Noncopy { n: 5 } } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom)] #[cpp_from(i32, new_1, ptr)] #[byte_size(8)] pub struct Held { diff --git a/tests/unit/out/refcount/max.rs b/tests/unit/out/refcount/max.rs index 607f43cdfe..1cff9e31c3 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -20,7 +20,7 @@ pub fn pick_3(mut i: i32) -> Ptr { (*calls_0.with(Value::clone).borrow_mut()).prefix_inc(); return xs_1.with(|v| v.decay()).offset(i); } -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct Bag { diff --git a/tests/unit/out/refcount/memcpy_struct_bytes.rs b/tests/unit/out/refcount/memcpy_struct_bytes.rs index fedfd47c7e..2a5219ef4f 100644 --- a/tests/unit/out/refcount/memcpy_struct_bytes.rs +++ b/tests/unit/out/refcount/memcpy_struct_bytes.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct point { #[offset(0)] diff --git a/tests/unit/out/refcount/memcpy_struct_layouts.rs b/tests/unit/out/refcount/memcpy_struct_layouts.rs index 7530f72e27..f385cc95ad 100644 --- a/tests/unit/out/refcount/memcpy_struct_layouts.rs +++ b/tests/unit/out/refcount/memcpy_struct_layouts.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct packed { #[offset(0)] @@ -18,7 +18,7 @@ pub struct packed { #[offset(6)] pub d: i16, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(12)] pub struct reordered { #[offset(0)] @@ -28,7 +28,7 @@ pub struct reordered { #[offset(8)] pub c: i8, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct tail { #[offset(0)] @@ -36,7 +36,7 @@ pub struct tail { #[offset(8)] pub b: f64, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(24)] pub struct nested { #[offset(0)] @@ -45,11 +45,12 @@ pub struct nested { #[offset(16)] pub c: i8, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(8)] pub struct array { #[offset(0)] #[byte_size(3)] + #[array_len(3)] pub name: Box<[i8]>, #[offset(4)] pub x: i32, diff --git a/tests/unit/out/refcount/memcpy_struct_struct.rs b/tests/unit/out/refcount/memcpy_struct_struct.rs index 3b08e55cf9..17ad89855b 100644 --- a/tests/unit/out/refcount/memcpy_struct_struct.rs +++ b/tests/unit/out/refcount/memcpy_struct_struct.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Entry { #[offset(0)] diff --git a/tests/unit/out/refcount/memset_struct_tail.rs b/tests/unit/out/refcount/memset_struct_tail.rs index b670037ca5..eca67abf50 100644 --- a/tests/unit/out/refcount/memset_struct_tail.rs +++ b/tests/unit/out/refcount/memset_struct_tail.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(32)] pub struct S { #[offset(0)] @@ -17,6 +17,7 @@ pub struct S { pub b: i64, #[offset(16)] #[byte_size(5)] + #[array_len(5)] pub c: Box<[i8]>, #[offset(24)] pub last: i32, diff --git a/tests/unit/out/refcount/move_assign.rs b/tests/unit/out/refcount/move_assign.rs index 8481437538..d1d8511b83 100644 --- a/tests/unit/out/refcount/move_assign.rs +++ b/tests/unit/out/refcount/move_assign.rs @@ -6,7 +6,9 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, CppFrom, MoveAssign, Default)] +#[derive( + Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom, MoveAssign, Default, +)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct MoveOnly { @@ -25,7 +27,7 @@ impl MoveOnly { __this } } -#[derive(Record, ByteRepr, FnPtrArg)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg)] #[byte_size(4)] pub struct ConstMoveAssign { #[offset(0)] diff --git a/tests/unit/out/refcount/move_ctor.rs b/tests/unit/out/refcount/move_ctor.rs index a61e8b580e..9b938215cd 100644 --- a/tests/unit/out/refcount/move_ctor.rs +++ b/tests/unit/out/refcount/move_ctor.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct MoveOnly { @@ -25,7 +25,7 @@ impl MoveOnly { __this } } -#[derive(Record, ByteRepr, FnPtrArg)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg)] #[byte_size(4)] pub struct ConstMove { #[offset(0)] @@ -51,7 +51,7 @@ impl Default for ConstMove { { ConstMove::new() } } } -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(12)] pub struct ThrowingMove { @@ -97,7 +97,7 @@ impl Clone for ThrowingMove { ThrowingMove::copy_from(__src.as_pointer()) } } -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(12)] pub struct NoexceptMove { diff --git a/tests/unit/out/refcount/move_this.rs b/tests/unit/out/refcount/move_this.rs index 9d06aa1438..8781a89b51 100644 --- a/tests/unit/out/refcount/move_this.rs +++ b/tests/unit/out/refcount/move_this.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct Chain { diff --git a/tests/unit/out/refcount/nested_structs.rs b/tests/unit/out/refcount/nested_structs.rs index c2968d3c29..92ff0d5cc2 100644 --- a/tests/unit/out/refcount/nested_structs.rs +++ b/tests/unit/out/refcount/nested_structs.rs @@ -6,13 +6,13 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Level0_Level1_1_Level2_1_Level3_1 { #[offset(0)] pub x1: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Level0_Level1_1_Level2_1_Level3_2 { #[offset(0)] @@ -20,19 +20,19 @@ pub struct Level0_Level1_1_Level2_1_Level3_2 { #[offset(4)] pub x2: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Level0_Level1_1_Level2_1 { #[offset(0)] pub x1: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Level0_Level1_1 { #[offset(0)] pub x1: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Level0_Level1_2 { #[offset(0)] @@ -40,7 +40,7 @@ pub struct Level0_Level1_2 { #[offset(4)] pub x2: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct Level0 {} pub fn main() { diff --git a/tests/unit/out/refcount/new.rs b/tests/unit/out/refcount/new.rs index cea2db9812..0bf358cc6a 100644 --- a/tests/unit/out/refcount/new.rs +++ b/tests/unit/out/refcount/new.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Pair { #[offset(0)] diff --git a/tests/unit/out/refcount/new_bst.rs b/tests/unit/out/refcount/new_bst.rs index 4f8295c431..1485b5947e 100644 --- a/tests/unit/out/refcount/new_bst.rs +++ b/tests/unit/out/refcount/new_bst.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(24)] pub struct node_t { #[offset(0)] diff --git a/tests/unit/out/refcount/new_struct.rs b/tests/unit/out/refcount/new_struct.rs index 74478f932b..0431d6d7d1 100644 --- a/tests/unit/out/refcount/new_struct.rs +++ b/tests/unit/out/refcount/new_struct.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -14,7 +14,7 @@ pub struct Pair { #[offset(4)] pub y: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Triple { #[offset(0)] diff --git a/tests/unit/out/refcount/nttp_distinct_specializations.rs b/tests/unit/out/refcount/nttp_distinct_specializations.rs index 081ae9bb7b..7c5fb3ec65 100644 --- a/tests/unit/out/refcount/nttp_distinct_specializations.rs +++ b/tests/unit/out/refcount/nttp_distinct_specializations.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct S_2_ { #[offset(0)] @@ -14,13 +14,13 @@ pub struct S_2_ { #[offset(4)] pub w: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S_1_ { #[offset(0)] pub v: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S_3_ { #[offset(0)] diff --git a/tests/unit/out/refcount/offsetof.rs b/tests/unit/out/refcount/offsetof.rs index a394fe50e6..69c0b7985d 100644 --- a/tests/unit/out/refcount/offsetof.rs +++ b/tests/unit/out/refcount/offsetof.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(12)] pub struct Layout { #[offset(0)] @@ -16,13 +16,14 @@ pub struct Layout { #[offset(8)] pub c: u16, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(66)] pub struct Frame { #[offset(0)] pub tag: u16, #[offset(2)] #[byte_size(64)] + #[array_len(64)] pub body: Box<[i8]>, } impl Default for Frame { diff --git a/tests/unit/out/refcount/opaque_forward_decl.rs b/tests/unit/out/refcount/opaque_forward_decl.rs index ca0809ff5d..68b7285f7f 100644 --- a/tests/unit/out/refcount/opaque_forward_decl.rs +++ b/tests/unit/out/refcount/opaque_forward_decl.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct container { #[offset(0)] diff --git a/tests/unit/out/refcount/opaque_record_copy.rs b/tests/unit/out/refcount/opaque_record_copy.rs index 91e97fa397..52f209175c 100644 --- a/tests/unit/out/refcount/opaque_record_copy.rs +++ b/tests/unit/out/refcount/opaque_record_copy.rs @@ -6,10 +6,10 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct Probe {} -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Wrapper_Probe_ { #[offset(0)] diff --git a/tests/unit/out/refcount/opaque_then_defined.rs b/tests/unit/out/refcount/opaque_then_defined.rs index f9d4c8ee08..c848e68b1a 100644 --- a/tests/unit/out/refcount/opaque_then_defined.rs +++ b/tests/unit/out/refcount/opaque_then_defined.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct list { #[offset(0)] @@ -15,7 +15,7 @@ pub struct list { #[offset(8)] pub size: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct node { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_arithmetic_free.rs b/tests/unit/out/refcount/operator_arithmetic_free.rs index b0bb4c08eb..5b62ce1e9a 100644 --- a/tests/unit/out/refcount/operator_arithmetic_free.rs +++ b/tests/unit/out/refcount/operator_arithmetic_free.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_arithmetic_member.rs b/tests/unit/out/refcount/operator_arithmetic_member.rs index 913a6447e9..aa36fe7c32 100644 --- a/tests/unit/out/refcount/operator_arithmetic_member.rs +++ b/tests/unit/out/refcount/operator_arithmetic_member.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_bitwise_free.rs b/tests/unit/out/refcount/operator_bitwise_free.rs index fa5eee3f8c..3df83ca166 100644 --- a/tests/unit/out/refcount/operator_bitwise_free.rs +++ b/tests/unit/out/refcount/operator_bitwise_free.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_bitwise_member.rs b/tests/unit/out/refcount/operator_bitwise_member.rs index f2919e3cb6..45aba391cb 100644 --- a/tests/unit/out/refcount/operator_bitwise_member.rs +++ b/tests/unit/out/refcount/operator_bitwise_member.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_comparison_defaulted.rs b/tests/unit/out/refcount/operator_comparison_defaulted.rs index 7fa4f9dd49..7cce6fff1c 100644 --- a/tests/unit/out/refcount/operator_comparison_defaulted.rs +++ b/tests/unit/out/refcount/operator_comparison_defaulted.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Eq { #[offset(0)] @@ -19,7 +19,7 @@ impl CppEq for Eq { EqImpl::operator_eq(__lhs, __rhs.clone()) } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Cmp { #[offset(0)] @@ -37,7 +37,7 @@ impl CppEq for Cmp { CmpImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Equal } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Both { #[offset(0)] @@ -53,7 +53,7 @@ impl CppEq for Both { BothImpl::operator_eq(__lhs, __rhs.clone()) } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct OrdOnly { #[offset(0)] @@ -69,7 +69,7 @@ impl CppEq for OrdOnly { OrdOnlyImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Equal } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Inner { #[offset(0)] @@ -85,7 +85,7 @@ impl CppEq for Inner { InnerImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Equal } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Outer { #[offset(0)] @@ -104,7 +104,7 @@ impl CppEq for Outer { OuterImpl::operator_cmp(__lhs, __rhs.clone()) == std::cmp::Ordering::Equal } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Secondary { #[offset(0)] @@ -120,7 +120,7 @@ impl CppEq for Secondary { SecondaryImpl::operator_eq(__lhs, __rhs.clone()) } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct PtrMember { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_comparison_free.rs b/tests/unit/out/refcount/operator_comparison_free.rs index 7c2b962ce5..7cfb037462 100644 --- a/tests/unit/out/refcount/operator_comparison_free.rs +++ b/tests/unit/out/refcount/operator_comparison_free.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -46,7 +46,7 @@ pub fn operator_lt_6(a: Ptr, mut b: i32) -> bool { pub fn operator_lt_7(mut a: i32, b: Ptr) -> bool { return ({ a } < { b.with(|__s| __s.v) }); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct V { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_comparison_member.rs b/tests/unit/out/refcount/operator_comparison_member.rs index 0caa1e8284..c6316b011c 100644 --- a/tests/unit/out/refcount/operator_comparison_member.rs +++ b/tests/unit/out/refcount/operator_comparison_member.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_comparison_mixed.rs b/tests/unit/out/refcount/operator_comparison_mixed.rs index 3291ba33e4..d2d1cf43bf 100644 --- a/tests/unit/out/refcount/operator_comparison_mixed.rs +++ b/tests/unit/out/refcount/operator_comparison_mixed.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_comparison_nonbool.rs b/tests/unit/out/refcount/operator_comparison_nonbool.rs index 41b0c2e8a0..b4307e2bc5 100644 --- a/tests/unit/out/refcount/operator_comparison_nonbool.rs +++ b/tests/unit/out/refcount/operator_comparison_nonbool.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct X { #[offset(0)] @@ -40,19 +40,19 @@ pub fn operator_le_4(mut a: X, mut b: X) -> i32 { pub fn operator_ge_5(mut a: X, mut b: X) -> i32 { return if (a.v >= b.v) { 7 } else { 0 }; } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Result { #[offset(0)] pub r: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Custom { #[offset(0)] pub v: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Mixed { #[offset(0)] @@ -68,7 +68,7 @@ impl CppEq for Mixed { ((MixedImpl::operator_eq(__lhs, __rhs.clone())) != 0) } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_into(bool, to_bool)] #[byte_size(1)] pub struct MyBool { @@ -80,7 +80,7 @@ impl MyBool { Self { value: v } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Boolish { #[offset(0)] @@ -108,7 +108,7 @@ pub fn operator_eq_7(mut a: Boolish, mut b: Boolish) -> MyBool { pub fn operator_lt_6(mut a: Boolish, mut b: Boolish) -> MyBool { return MyBool::new({ (a.v < b.v) }); } -#[derive(Record, ByteRepr, FnPtrArg, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Default)] #[cpp_into(bool, to_bool)] #[byte_size(1)] pub struct RefBool { @@ -123,7 +123,7 @@ impl RefBool { thread_local!( pub static ref_true_8: Value = Rc::new(RefCell::new(RefBool::new({ true }))); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct RefInt { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_comparison_noncopyable.rs b/tests/unit/out/refcount/operator_comparison_noncopyable.rs index 300ff4225f..729adfa5ee 100644 --- a/tests/unit/out/refcount/operator_comparison_noncopyable.rs +++ b/tests/unit/out/refcount/operator_comparison_noncopyable.rs @@ -12,7 +12,7 @@ pub fn operator_eq_0(x: Ptr, y: Ptr) -> bool { pub fn operator_lt_1(x: Ptr, y: Ptr) -> bool { return ({ x.with(|__s| __s.data_) } < { y.with(|__s| __s.data_) }); } -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct S { diff --git a/tests/unit/out/refcount/operator_compound_assignment_free.rs b/tests/unit/out/refcount/operator_compound_assignment_free.rs index 4d7df98b39..a2e785ba51 100644 --- a/tests/unit/out/refcount/operator_compound_assignment_free.rs +++ b/tests/unit/out/refcount/operator_compound_assignment_free.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_compound_assignment_member.rs b/tests/unit/out/refcount/operator_compound_assignment_member.rs index 4452be00d5..e6acfcd60c 100644 --- a/tests/unit/out/refcount/operator_compound_assignment_member.rs +++ b/tests/unit/out/refcount/operator_compound_assignment_member.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_friend.rs b/tests/unit/out/refcount/operator_friend.rs index b3997e1177..645f6a93d0 100644 --- a/tests/unit/out/refcount/operator_friend.rs +++ b/tests/unit/out/refcount/operator_friend.rs @@ -10,7 +10,7 @@ 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, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Defaulted { #[offset(0)] @@ -38,7 +38,7 @@ pub fn operator_cmp_1(_a0: Ptr, _a1: Ptr) -> std::cm pub fn operator_eq_2(_a0: Ptr, _a1: Ptr) -> bool { return ({ _a0.with(|__s| __s.a) } == { _a1.with(|__s| __s.a) }); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct DefaultedOrd { #[offset(0)] @@ -65,7 +65,7 @@ pub fn operator_add_5(x: Ptr, y: Ptr) -> Inline { a: ({ x.with(|__s| __s.a) } + { y.with(|__s| __s.a) }), }; } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Inline { #[offset(0)] @@ -81,7 +81,7 @@ impl CppEq for Inline { operator_eq_3(__lhs.clone(), __rhs.clone()) } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct OutOfLine { #[offset(0)] @@ -111,7 +111,7 @@ pub fn operator_lt_9(x: Ptr, y: Ptr) -> bool { 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, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Tmpl_int_ { #[offset(0)] @@ -127,7 +127,7 @@ impl CppEq for Tmpl_int_ { operator_eq_8(__lhs.clone(), __rhs.clone()) } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Tmpl_long_ { #[offset(0)] @@ -136,7 +136,7 @@ pub struct Tmpl_long_ { pub fn operator_eq_11(_a0: Ptr, _a1: Ptr) -> bool { return ({ _a0.with(|__s| __s.v) } == { _a1.with(|__s| __s.v) }); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct TmplDefaulted_int_ { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_less_than.rs b/tests/unit/out/refcount/operator_less_than.rs index b33a1934a9..7785126728 100644 --- a/tests/unit/out/refcount/operator_less_than.rs +++ b/tests/unit/out/refcount/operator_less_than.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Pair { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_logical_free.rs b/tests/unit/out/refcount/operator_logical_free.rs index 96e7aefabc..817f423018 100644 --- a/tests/unit/out/refcount/operator_logical_free.rs +++ b/tests/unit/out/refcount/operator_logical_free.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_logical_member.rs b/tests/unit/out/refcount/operator_logical_member.rs index 302d9506ec..4b722e25b3 100644 --- a/tests/unit/out/refcount/operator_logical_member.rs +++ b/tests/unit/out/refcount/operator_logical_member.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_member_pointer_free.rs b/tests/unit/out/refcount/operator_member_pointer_free.rs index 4e428f670c..3d3ceefcd9 100644 --- a/tests/unit/out/refcount/operator_member_pointer_free.rs +++ b/tests/unit/out/refcount/operator_member_pointer_free.rs @@ -6,17 +6,18 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Inner { #[offset(0)] pub x: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(16)] pub struct S { #[offset(0)] #[byte_size(12)] + #[array_len(3)] pub data: Box<[i32]>, #[offset(12)] #[byte_size(4)] diff --git a/tests/unit/out/refcount/operator_member_pointer_member.rs b/tests/unit/out/refcount/operator_member_pointer_member.rs index 940b113fd9..5251a58a80 100644 --- a/tests/unit/out/refcount/operator_member_pointer_member.rs +++ b/tests/unit/out/refcount/operator_member_pointer_member.rs @@ -6,13 +6,13 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Inner { #[offset(0)] pub x: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct Table {} impl Table { @@ -23,11 +23,12 @@ impl Table { thread_local!( pub static table_0: Value> = Rc::new(RefCell::new(Box::new([7, 8, 9]))); ); -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(16)] pub struct S { #[offset(0)] #[byte_size(12)] + #[array_len(3)] pub data: Box<[i32]>, #[offset(12)] #[byte_size(4)] diff --git a/tests/unit/out/refcount/operator_other_free.rs b/tests/unit/out/refcount/operator_other_free.rs index 969f4933b3..9abe997bb4 100644 --- a/tests/unit/out/refcount/operator_other_free.rs +++ b/tests/unit/out/refcount/operator_other_free.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_other_member.rs b/tests/unit/out/refcount/operator_other_member.rs index 62a11f97bb..3b627eea25 100644 --- a/tests/unit/out/refcount/operator_other_member.rs +++ b/tests/unit/out/refcount/operator_other_member.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct Static {} impl Static { @@ -14,7 +14,7 @@ impl Static { return (a * b); } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_into(i32, to_i32)] #[byte_size(4)] pub struct S { diff --git a/tests/unit/out/refcount/operator_overloads.rs b/tests/unit/out/refcount/operator_overloads.rs index 6de5824a0f..600c902ba7 100644 --- a/tests/unit/out/refcount/operator_overloads.rs +++ b/tests/unit/out/refcount/operator_overloads.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_qualifiers.rs b/tests/unit/out/refcount/operator_qualifiers.rs index a3140eb65a..6bf6f81a61 100644 --- a/tests/unit/out/refcount/operator_qualifiers.rs +++ b/tests/unit/out/refcount/operator_qualifiers.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_three_way.rs b/tests/unit/out/refcount/operator_three_way.rs index 5677bec797..9298036a09 100644 --- a/tests/unit/out/refcount/operator_three_way.rs +++ b/tests/unit/out/refcount/operator_three_way.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/operator_traits.rs b/tests/unit/out/refcount/operator_traits.rs index 41dc06aa98..a6e01f8f27 100644 --- a/tests/unit/out/refcount/operator_traits.rs +++ b/tests/unit/out/refcount/operator_traits.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Lt { #[offset(0)] @@ -22,7 +22,7 @@ impl CppEq for Lt { !(LtImpl::operator_lt(__lhs, __rhs.clone())) && !(LtImpl::operator_lt(__rhs, __lhs.clone())) } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Eq { #[offset(0)] @@ -33,7 +33,7 @@ impl CppEq for Eq { EqImpl::operator_eq(__lhs, __rhs.clone()) } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Cmp { #[offset(0)] @@ -49,7 +49,7 @@ impl CppEq for Cmp { CmpImpl::operator_eq(__lhs, __rhs.clone()) } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Free { #[offset(0)] @@ -71,7 +71,7 @@ pub fn operator_lt_0(a: Ptr, b: Ptr) -> bool { pub fn operator_eq_1(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } == { b.with(|__s| __s.v) }); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Wrapped_int_ { #[offset(0)] diff --git a/tests/unit/out/refcount/overload_mangling.rs b/tests/unit/out/refcount/overload_mangling.rs index b9fcc91f3b..7538eae3a0 100644 --- a/tests/unit/out/refcount/overload_mangling.rs +++ b/tests/unit/out/refcount/overload_mangling.rs @@ -20,16 +20,16 @@ pub fn add_1(mut p: Ptr, mut n: i32) { pub fn twice_2(mut n: i32) -> i32 { return (n * 2); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct Access_S_ {} -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] pub base: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Box_ { #[offset(0)] diff --git a/tests/unit/out/refcount/pair_converting_construction.rs b/tests/unit/out/refcount/pair_converting_construction.rs index 023301cd94..6ee4d35353 100644 --- a/tests/unit/out/refcount/pair_converting_construction.rs +++ b/tests/unit/out/refcount/pair_converting_construction.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct Celsius { @@ -18,14 +18,14 @@ impl Celsius { Self { degrees: d } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_into(i32, to_i32)] #[byte_size(4)] pub struct Meters { #[offset(0)] pub value: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_from(Celsius, new, ptr)] #[byte_size(4)] pub struct Label { @@ -39,7 +39,7 @@ impl Label { } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_from(Celsius, new_1, ptr)] #[cpp_from_move(Celsius, new_2, ptr)] #[byte_size(8)] @@ -63,7 +63,7 @@ impl Owner { } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_from(Celsius, new, value)] #[byte_size(4)] pub struct Holder { @@ -75,7 +75,7 @@ impl Holder { Self { value: c.degrees } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct Fallback { @@ -92,13 +92,13 @@ impl Default for Fallback { { Fallback::new({ -1_i32 }) } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Counter { #[offset(0)] pub hits: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_from(Counter, new, mut_ptr)] #[byte_size(4)] pub struct Observer { @@ -121,14 +121,14 @@ impl Tag { } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_from(Celsius, new, ptr)] #[byte_size(4)] pub struct Tag { #[offset(0)] pub code: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_from(Ptr< i8 > , new, value)] #[byte_size(4)] pub struct Name { diff --git a/tests/unit/out/refcount/pod.rs b/tests/unit/out/refcount/pod.rs index c266b7d2f1..5543d2bf2b 100644 --- a/tests/unit/out/refcount/pod.rs +++ b/tests/unit/out/refcount/pod.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(12)] pub struct POD { #[offset(0)] diff --git a/tests/unit/out/refcount/pointer_array.rs b/tests/unit/out/refcount/pointer_array.rs index 99d3db82ff..266a5c06da 100644 --- a/tests/unit/out/refcount/pointer_array.rs +++ b/tests/unit/out/refcount/pointer_array.rs @@ -6,11 +6,12 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(24)] pub struct StackArray { #[offset(0)] #[byte_size(24)] + #[array_len(3)] pub arr: Box<[Ptr]>, } impl Default for StackArray { diff --git a/tests/unit/out/refcount/pointers.rs b/tests/unit/out/refcount/pointers.rs index 65a2d41b8a..7b1a92545c 100644 --- a/tests/unit/out/refcount/pointers.rs +++ b/tests/unit/out/refcount/pointers.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Test { #[offset(0)] diff --git a/tests/unit/out/refcount/polymorphism.rs b/tests/unit/out/refcount/polymorphism.rs index 39c8124707..4d5ad299ef 100644 --- a/tests/unit/out/refcount/polymorphism.rs +++ b/tests/unit/out/refcount/polymorphism.rs @@ -9,10 +9,10 @@ use std::rc::{Rc, Weak}; pub trait Animal { fn bark(&self) -> bool; } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Dog {} -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Cat {} pub fn main() { diff --git a/tests/unit/out/refcount/ptr_cast_init.rs b/tests/unit/out/refcount/ptr_cast_init.rs index 33607ffd43..c46b52bef4 100644 --- a/tests/unit/out/refcount/ptr_cast_init.rs +++ b/tests/unit/out/refcount/ptr_cast_init.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct header { #[offset(0)] @@ -14,7 +14,7 @@ pub struct header { #[offset(4)] pub size: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct view { #[offset(0)] diff --git a/tests/unit/out/refcount/push_emplace_back.rs b/tests/unit/out/refcount/push_emplace_back.rs index 11794508d4..1174af6771 100644 --- a/tests/unit/out/refcount/push_emplace_back.rs +++ b/tests/unit/out/refcount/push_emplace_back.rs @@ -6,13 +6,13 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Chunk { #[offset(0)] pub data: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Writer { #[offset(0)] @@ -22,7 +22,9 @@ pub struct Writer { #[byte_size(4)] pub chunk: Chunk, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, +)] #[byte_size(48)] pub struct JPEGData { #[offset(0)] @@ -114,7 +116,7 @@ pub fn self_ref_push_6(mut comps: Ptr>) { comps.with_mut(|__v: &mut Vec| __v.push(a0_clone)) }; } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom)] #[cpp_from(i32, new_1, value)] #[byte_size(8)] pub struct Pair { @@ -250,7 +252,7 @@ pub fn emplace_ref_self_read_13(values: Ptr>) -> Ptr { }) }; } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign)] #[byte_size(32)] pub struct Bytes { #[offset(0)] @@ -258,6 +260,7 @@ pub struct Bytes { pub v: Vec>, #[offset(24)] #[byte_size(3)] + #[array_len(3)] pub b: Box<[u8]>, } impl Bytes { @@ -298,13 +301,14 @@ pub fn emplace_from_element_14(mut v: Ptr>>) { v.with_mut(|__v: &mut Vec>| __v.push(__tmp_15)); }; } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(24)] pub struct Plain { #[offset(0)] pub a: i32, #[offset(8)] #[byte_size(16)] + #[array_len(2)] pub b: Box<[f64]>, } impl Default for Plain { @@ -330,7 +334,7 @@ thread_local!( pub static all_counted_16: Value>> = Rc::new(RefCell::new(Ptr::>::null())); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Counted { #[offset(0)] diff --git a/tests/unit/out/refcount/random.rs b/tests/unit/out/refcount/random.rs index 7b2c189993..62e7accb5f 100644 --- a/tests/unit/out/refcount/random.rs +++ b/tests/unit/out/refcount/random.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(72)] pub struct Pair { #[offset(0)] @@ -15,6 +15,7 @@ pub struct Pair { pub y: i32, #[offset(8)] #[byte_size(20)] + #[array_len(5)] pub a: Box<[i32]>, #[offset(32)] #[byte_size(8)] @@ -27,6 +28,7 @@ pub struct Pair { pub pair: Ptr, #[offset(56)] #[byte_size(16)] + #[array_len(2)] pub ap: Box<[Ptr]>, } impl Default for Pair { @@ -49,7 +51,7 @@ impl Default for Pair { pub fn zero_0() -> i32 { return 0; } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct X1 {} pub fn foo_1(mut x1: i32, x2: Ptr, mut x3: Ptr, p2: Ptr, mut p3: Ptr) {} diff --git a/tests/unit/out/refcount/reference_wrapper.rs b/tests/unit/out/refcount/reference_wrapper.rs index 5aaa57abd8..2126013a08 100644 --- a/tests/unit/out/refcount/reference_wrapper.rs +++ b/tests/unit/out/refcount/reference_wrapper.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Point { #[offset(0)] diff --git a/tests/unit/out/refcount/references.rs b/tests/unit/out/refcount/references.rs index 1a5c4c28a6..af7cbe7a47 100644 --- a/tests/unit/out/refcount/references.rs +++ b/tests/unit/out/refcount/references.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(16)] pub struct Pair { #[offset(0)] @@ -15,6 +15,7 @@ pub struct Pair { pub y: i32, #[offset(8)] #[byte_size(8)] + #[array_len(2)] pub arr: Box<[i32]>, } impl Default for Pair { @@ -28,7 +29,7 @@ impl Default for Pair { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Nested { #[offset(0)] diff --git a/tests/unit/out/refcount/refs_as_args.rs b/tests/unit/out/refcount/refs_as_args.rs index 85919354eb..e0c0f4f169 100644 --- a/tests/unit/out/refcount/refs_as_args.rs +++ b/tests/unit/out/refcount/refs_as_args.rs @@ -31,7 +31,7 @@ pub fn more_refs_0(x1: i32, x2: i32, r1: Ptr, r2: Ptr) { }; r1.write({ (rx2.read()) }); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Val { #[offset(0)] diff --git a/tests/unit/out/refcount/reinterpret_cast_ptr_cmp.rs b/tests/unit/out/refcount/reinterpret_cast_ptr_cmp.rs index 61adb0bd0b..16a49ba0ec 100644 --- a/tests/unit/out/refcount/reinterpret_cast_ptr_cmp.rs +++ b/tests/unit/out/refcount/reinterpret_cast_ptr_cmp.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct S { #[offset(0)] @@ -14,13 +14,14 @@ pub struct S { #[offset(4)] pub y: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(28)] pub struct W { #[offset(0)] pub h: i32, #[offset(4)] #[byte_size(24)] + #[array_len(3)] pub arr: Box<[S]>, } impl Default for W { @@ -33,7 +34,7 @@ impl Default for W { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(32)] pub struct P { #[offset(0)] @@ -41,6 +42,7 @@ pub struct P { pub a: Ptr, #[offset(8)] #[byte_size(24)] + #[array_len(3)] pub arr: Box<[Ptr]>, } impl Default for P { diff --git a/tests/unit/out/refcount/reinterpret_cast_struct.rs b/tests/unit/out/refcount/reinterpret_cast_struct.rs index b8113a7060..e823d6b293 100644 --- a/tests/unit/out/refcount/reinterpret_cast_struct.rs +++ b/tests/unit/out/refcount/reinterpret_cast_struct.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Point { #[offset(0)] diff --git a/tests/unit/out/refcount/reinterpret_cast_struct_to_struct.rs b/tests/unit/out/refcount/reinterpret_cast_struct_to_struct.rs index 377deb6da3..9c0325d69b 100644 --- a/tests/unit/out/refcount/reinterpret_cast_struct_to_struct.rs +++ b/tests/unit/out/refcount/reinterpret_cast_struct_to_struct.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Point { #[offset(0)] @@ -14,7 +14,7 @@ pub struct Point { #[offset(4)] pub y: u32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Pair { #[offset(0)] diff --git a/tests/unit/out/refcount/reserved_keywords.rs b/tests/unit/out/refcount/reserved_keywords.rs index d18cb4477a..93b8d77d2a 100644 --- a/tests/unit/out/refcount/reserved_keywords.rs +++ b/tests/unit/out/refcount/reserved_keywords.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(152)] pub struct S { #[offset(0)] @@ -86,13 +86,13 @@ pub struct S { #[offset(148)] pub vec_: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct type_ { #[offset(0)] pub v: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct loop_ { #[offset(0)] diff --git a/tests/unit/out/refcount/return_move.rs b/tests/unit/out/refcount/return_move.rs index 304d172cfb..6ad2276c38 100644 --- a/tests/unit/out/refcount/return_move.rs +++ b/tests/unit/out/refcount/return_move.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct node { #[offset(0)] @@ -15,7 +15,7 @@ pub struct node { #[byte_size(8)] pub next: Ptr, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct pair_t { #[offset(0)] diff --git a/tests/unit/out/refcount/rule_of_five.rs b/tests/unit/out/refcount/rule_of_five.rs index fd16015e5d..31033592f5 100644 --- a/tests/unit/out/refcount/rule_of_five.rs +++ b/tests/unit/out/refcount/rule_of_five.rs @@ -16,13 +16,23 @@ thread_local!( pub static moves_2: Value = Rc::new(RefCell::new(0)); ); #[derive( - Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom, CopyAssign, MoveAssign, Destructor, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + MoveCtor, + CppFrom, + CopyAssign, + MoveAssign, + Destructor, )] #[cpp_from(i32, new, value)] #[byte_size(20)] pub struct Buffer { #[offset(0)] #[byte_size(16)] + #[array_len(4)] pub data: Box<[i32]>, #[offset(16)] pub size: i32, diff --git a/tests/unit/out/refcount/rule_of_three.rs b/tests/unit/out/refcount/rule_of_three.rs index b1bdcc7384..5675f6b2c9 100644 --- a/tests/unit/out/refcount/rule_of_three.rs +++ b/tests/unit/out/refcount/rule_of_three.rs @@ -12,12 +12,15 @@ thread_local!( thread_local!( pub static copies_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Destructor)] +#[derive( + Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, CopyAssign, Destructor, +)] #[cpp_from(i32, new, value)] #[byte_size(20)] pub struct Buffer { #[offset(0)] #[byte_size(16)] + #[array_len(4)] pub data: Box<[i32]>, #[offset(16)] pub size: i32, diff --git a/tests/unit/out/refcount/rvalue_rule_arg_move.rs b/tests/unit/out/refcount/rvalue_rule_arg_move.rs index 747eae3fc8..0b5ad54a61 100644 --- a/tests/unit/out/refcount/rvalue_rule_arg_move.rs +++ b/tests/unit/out/refcount/rvalue_rule_arg_move.rs @@ -12,7 +12,9 @@ thread_local!( thread_local!( pub static moves_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom, CopyAssign, Default)] +#[derive( + Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, CopyAssign, Default, +)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct Elem { diff --git a/tests/unit/out/refcount/rvalue_struct.rs b/tests/unit/out/refcount/rvalue_struct.rs index e1f2be267e..ee273801e7 100644 --- a/tests/unit/out/refcount/rvalue_struct.rs +++ b/tests/unit/out/refcount/rvalue_struct.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/scalar_builtin_construct_destruct.rs b/tests/unit/out/refcount/scalar_builtin_construct_destruct.rs index 10fe629994..0c291e81a8 100644 --- a/tests/unit/out/refcount/scalar_builtin_construct_destruct.rs +++ b/tests/unit/out/refcount/scalar_builtin_construct_destruct.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Pod { #[offset(0)] diff --git a/tests/unit/out/refcount/self_referencing_initializer.rs b/tests/unit/out/refcount/self_referencing_initializer.rs index 958de1fa8d..099d491ace 100644 --- a/tests/unit/out/refcount/self_referencing_initializer.rs +++ b/tests/unit/out/refcount/self_referencing_initializer.rs @@ -6,14 +6,14 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct list_head { #[offset(0)] #[byte_size(8)] pub next: Ptr, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct node { #[offset(0)] @@ -22,7 +22,7 @@ pub struct node { #[byte_size(8)] pub value_ptr: Ptr, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(16)] pub struct node_with_defaults { #[offset(0)] diff --git a/tests/unit/out/refcount/size_t_static_member.rs b/tests/unit/out/refcount/size_t_static_member.rs index 84688bdd1d..10d3177ae3 100644 --- a/tests/unit/out/refcount/size_t_static_member.rs +++ b/tests/unit/out/refcount/size_t_static_member.rs @@ -9,13 +9,13 @@ use std::rc::{Rc, Weak}; thread_local!( pub static c_0: Value = Rc::new(RefCell::new(5_usize)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct S {} thread_local!( pub static table_size_1: Value = Rc::new(RefCell::new(256_usize)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct Table_char_ {} pub fn main() { diff --git a/tests/unit/out/refcount/size_t_template_param.rs b/tests/unit/out/refcount/size_t_template_param.rs index 51b7557e55..2a50553606 100644 --- a/tests/unit/out/refcount/size_t_template_param.rs +++ b/tests/unit/out/refcount/size_t_template_param.rs @@ -10,7 +10,7 @@ pub fn array_ref_0(a: Ptr) -> u64 { elem!(a, 0).write({ (elem!(a, 0).read()).wrapping_add(1_u64) }); return (elem!(a, (3_u64 as u64).wrapping_sub(1_u64)).read()); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_from(Ptr< u64 > , new, value)] #[byte_size(8)] pub struct PtrCtor_unsigned_long_ { @@ -24,7 +24,7 @@ impl PtrCtor_unsigned_long_ { } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_from(u64, new, ptr)] #[byte_size(8)] pub struct RefCtor_unsigned_long_ { diff --git a/tests/unit/out/refcount/sort_no_copy.rs b/tests/unit/out/refcount/sort_no_copy.rs index d4bb1b88bb..fc97618cae 100644 --- a/tests/unit/out/refcount/sort_no_copy.rs +++ b/tests/unit/out/refcount/sort_no_copy.rs @@ -9,7 +9,9 @@ use std::rc::{Rc, Weak}; thread_local!( pub static copies_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom, CopyAssign, MoveAssign)] +#[derive( + Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, CopyAssign, MoveAssign, +)] #[cpp_from(i32, new_1, value)] #[byte_size(4)] pub struct Tracked { @@ -64,7 +66,9 @@ pub fn operator_lt_1(a: Ptr, b: Ptr) -> bool { pub fn greater_2(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } > { b.with(|__s| __s.v) }); } -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, CppFrom, MoveAssign, Default)] +#[derive( + Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom, MoveAssign, Default, +)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct MoveOnly { @@ -95,7 +99,9 @@ impl CppEq for MoveOnly { pub fn operator_lt_3(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.v) } < { b.with(|__s| __s.v) }); } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, +)] #[byte_size(24)] pub struct Bag { #[offset(0)] diff --git a/tests/unit/out/refcount/static_local.rs b/tests/unit/out/refcount/static_local.rs index 3a5055fbcb..388d6c7496 100644 --- a/tests/unit/out/refcount/static_local.rs +++ b/tests/unit/out/refcount/static_local.rs @@ -33,7 +33,7 @@ pub fn from_local_class_6() -> i32 { thread_local!( static x_7: Value = Rc::new(RefCell::new(3)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct S_8 {} pub fn main() { diff --git a/tests/unit/out/refcount/static_var_in_class.rs b/tests/unit/out/refcount/static_var_in_class.rs index 99ea3f43a3..ccae0ec716 100644 --- a/tests/unit/out/refcount/static_var_in_class.rs +++ b/tests/unit/out/refcount/static_var_in_class.rs @@ -9,7 +9,7 @@ use std::rc::{Rc, Weak}; thread_local!( static inner_const_0: Value = Rc::new(RefCell::new(1)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct C {} thread_local!( @@ -17,7 +17,7 @@ thread_local!( ); pub type anon_3 = u32; pub const anon_3_kValue: anon_3 = 3; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct S {} impl S { diff --git a/tests/unit/out/refcount/stdcopy.rs b/tests/unit/out/refcount/stdcopy.rs index ab8da5fba7..6edc939c74 100644 --- a/tests/unit/out/refcount/stdcopy.rs +++ b/tests/unit/out/refcount/stdcopy.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct Degrees { diff --git a/tests/unit/out/refcount/strdup.rs b/tests/unit/out/refcount/strdup.rs index ea668ab934..11e6da6767 100644 --- a/tests/unit/out/refcount/strdup.rs +++ b/tests/unit/out/refcount/strdup.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct record { #[offset(0)] diff --git a/tests/unit/out/refcount/string_literal_ptr_init.rs b/tests/unit/out/refcount/string_literal_ptr_init.rs index 3feed7109f..3597ba4ba7 100644 --- a/tests/unit/out/refcount/string_literal_ptr_init.rs +++ b/tests/unit/out/refcount/string_literal_ptr_init.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(24)] pub struct label { #[offset(0)] diff --git a/tests/unit/out/refcount/string_substr.rs b/tests/unit/out/refcount/string_substr.rs index ab830e4fab..7ccd20b510 100644 --- a/tests/unit/out/refcount/string_substr.rs +++ b/tests/unit/out/refcount/string_substr.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Text { #[offset(0)] diff --git a/tests/unit/out/refcount/struct_2d_array_field.rs b/tests/unit/out/refcount/struct_2d_array_field.rs index ea50bd897f..1610af3378 100644 --- a/tests/unit/out/refcount/struct_2d_array_field.rs +++ b/tests/unit/out/refcount/struct_2d_array_field.rs @@ -6,11 +6,12 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(40)] pub struct table { #[offset(0)] #[byte_size(30)] + #[array_len(3, 10)] pub rows: Box<[Box<[i8]>]>, #[offset(32)] pub count: usize, diff --git a/tests/unit/out/refcount/struct_ctor.rs b/tests/unit/out/refcount/struct_ctor.rs index 8f69b3cd62..cb9b3c7544 100644 --- a/tests/unit/out/refcount/struct_ctor.rs +++ b/tests/unit/out/refcount/struct_ctor.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct StructWithCtor { #[offset(0)] @@ -30,7 +30,7 @@ impl StructWithCtor { pub fn foo_0(x: Ptr) -> Ptr { return (x).clone(); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct Value_ { @@ -42,7 +42,7 @@ impl Value_ { Self { v: u } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(8)] pub struct Ptr_ { #[offset(0)] diff --git a/tests/unit/out/refcount/struct_default_ctor.rs b/tests/unit/out/refcount/struct_default_ctor.rs index 95aea6b047..af311b381a 100644 --- a/tests/unit/out/refcount/struct_default_ctor.rs +++ b/tests/unit/out/refcount/struct_default_ctor.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(8)] pub struct S { #[offset(0)] @@ -24,18 +24,19 @@ impl Default for S { { S::new() } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Declared { #[offset(0)] pub v: i32, } impl Declared {} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(16)] pub struct Holder { #[offset(0)] #[byte_size(16)] + #[array_len(2)] pub items: Box<[S]>, } impl Default for Holder { @@ -50,7 +51,7 @@ impl Default for Holder { thread_local!( pub static kInit_0: Value = Rc::new(RefCell::new(3)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct FromStatic { #[offset(0)] diff --git a/tests/unit/out/refcount/struct_member_array_adjacency.rs b/tests/unit/out/refcount/struct_member_array_adjacency.rs index ae3f88eedb..9392526a17 100644 --- a/tests/unit/out/refcount/struct_member_array_adjacency.rs +++ b/tests/unit/out/refcount/struct_member_array_adjacency.rs @@ -6,14 +6,16 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(32)] pub struct pair { #[offset(0)] #[byte_size(16)] + #[array_len(4)] pub a: Box<[i32]>, #[offset(16)] #[byte_size(16)] + #[array_len(4)] pub b: Box<[i32]>, } impl Default for pair { diff --git a/tests/unit/out/refcount/struct_ptr.rs b/tests/unit/out/refcount/struct_ptr.rs index ace6344e93..c34fbc8c35 100644 --- a/tests/unit/out/refcount/struct_ptr.rs +++ b/tests/unit/out/refcount/struct_ptr.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct XX { #[offset(0)] diff --git a/tests/unit/out/refcount/structured_binding_copy_ctor.rs b/tests/unit/out/refcount/structured_binding_copy_ctor.rs index 86f8d3c315..ad694163f4 100644 --- a/tests/unit/out/refcount/structured_binding_copy_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_copy_ctor.rs @@ -9,7 +9,7 @@ use std::rc::{Rc, Weak}; thread_local!( pub static copies_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Default)] #[byte_size(8)] pub struct Counted { #[offset(0)] diff --git a/tests/unit/out/refcount/structured_binding_element_ctor.rs b/tests/unit/out/refcount/structured_binding_element_ctor.rs index d08feed964..c9aac1a793 100644 --- a/tests/unit/out/refcount/structured_binding_element_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_element_ctor.rs @@ -12,7 +12,7 @@ thread_local!( thread_local!( pub static moves_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct Elem { @@ -45,7 +45,7 @@ impl Clone for Elem { Elem::copy_from(__src.as_pointer()) } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, Default)] #[byte_size(8)] pub struct Two { #[offset(0)] diff --git a/tests/unit/out/refcount/structured_binding_move_ctor.rs b/tests/unit/out/refcount/structured_binding_move_ctor.rs index 96b44b3978..75067ce3f9 100644 --- a/tests/unit/out/refcount/structured_binding_move_ctor.rs +++ b/tests/unit/out/refcount/structured_binding_move_ctor.rs @@ -12,7 +12,7 @@ thread_local!( thread_local!( pub static moves_1: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, Default)] #[byte_size(8)] pub struct Movable { #[offset(0)] @@ -52,7 +52,9 @@ impl Clone for Movable { Movable::copy_from(__src.as_pointer()) } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, +)] #[byte_size(48)] pub struct Holder { #[offset(0)] diff --git a/tests/unit/out/refcount/structured_binding_range_for.rs b/tests/unit/out/refcount/structured_binding_range_for.rs index 36f76d9c61..1d0447a13e 100644 --- a/tests/unit/out/refcount/structured_binding_range_for.rs +++ b/tests/unit/out/refcount/structured_binding_range_for.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Pair { #[offset(0)] diff --git a/tests/unit/out/refcount/structured_binding_ref.rs b/tests/unit/out/refcount/structured_binding_ref.rs index 622192311a..d35f932e4d 100644 --- a/tests/unit/out/refcount/structured_binding_ref.rs +++ b/tests/unit/out/refcount/structured_binding_ref.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(12)] pub struct Triple { #[offset(0)] diff --git a/tests/unit/out/refcount/structured_binding_trivial.rs b/tests/unit/out/refcount/structured_binding_trivial.rs index ae782778da..cdc4393f6e 100644 --- a/tests/unit/out/refcount/structured_binding_trivial.rs +++ b/tests/unit/out/refcount/structured_binding_trivial.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Pair { #[offset(0)] diff --git a/tests/unit/out/refcount/swap_map_no_copy.rs b/tests/unit/out/refcount/swap_map_no_copy.rs index 1e6b008c52..f31211f7c8 100644 --- a/tests/unit/out/refcount/swap_map_no_copy.rs +++ b/tests/unit/out/refcount/swap_map_no_copy.rs @@ -9,7 +9,9 @@ use std::rc::{Rc, Weak}; thread_local!( pub static copies_0: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom, CopyAssign, MoveAssign)] +#[derive( + Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, CopyAssign, MoveAssign, +)] #[cpp_from(i32, new_1, value)] #[byte_size(4)] pub struct Tracked { @@ -47,7 +49,18 @@ impl Default for Tracked { { Tracked::new_2() } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CopyAssign, MoveAssign, Default)] +#[derive( + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + MoveCtor, + CopyAssign, + MoveAssign, + Default, +)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -65,14 +78,18 @@ impl Pair { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CopyAssign, MoveAssign)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CopyAssign, MoveAssign, +)] #[byte_size(16)] pub struct Arrays { #[offset(0)] #[byte_size(8)] + #[array_len(2)] pub a: Box<[Tracked]>, #[offset(8)] #[byte_size(8)] + #[array_len(2)] pub b: Box<[Tracked]>, } impl Arrays { @@ -107,7 +124,9 @@ thread_local!( thread_local!( pub static copy_only_dtors_2: Value = Rc::new(RefCell::new(0)); ); -#[derive(Record, ByteRepr, VaArg, FnPtrArg, CppFrom, CopyAssign, Destructor, Default)] +#[derive( + Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, CopyAssign, Destructor, Default, +)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct CopyOnly { @@ -132,7 +151,9 @@ impl Clone for CopyOnly { CopyOnly::copy_from(__src.as_pointer()) } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign, Destructor, Default, +)] #[byte_size(8)] pub struct CopyOnlyPair { #[offset(0)] @@ -154,6 +175,7 @@ thread_local!( #[derive( Record, ByteRepr, + ZeroInitialization, VaArg, FnPtrArg, MoveCtor, @@ -196,7 +218,17 @@ impl Clone for Moved { } } #[derive( - Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CopyAssign, MoveAssign, Destructor, Default, + Clone, + Record, + ByteRepr, + ZeroInitialization, + VaArg, + FnPtrArg, + MoveCtor, + CopyAssign, + MoveAssign, + Destructor, + Default, )] #[byte_size(8)] pub struct MovedPair { @@ -232,7 +264,7 @@ pub fn swapped_once_6() -> bool { }); return ok; } -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] #[byte_size(8)] pub struct Owner { #[offset(0)] diff --git a/tests/unit/out/refcount/tag_vs_identifier_collision.rs b/tests/unit/out/refcount/tag_vs_identifier_collision.rs index c76fe5fdd2..a4c1e9f70f 100644 --- a/tests/unit/out/refcount/tag_vs_identifier_collision.rs +++ b/tests/unit/out/refcount/tag_vs_identifier_collision.rs @@ -10,7 +10,7 @@ pub type widget_enum = u32; pub const widget_enum_MODE_IDLE: widget_enum = 0; pub const widget_enum_MODE_ACTIVE: widget_enum = 1; pub const widget_enum_MODE_DONE: widget_enum = 2; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct widget { #[offset(0)] @@ -18,7 +18,7 @@ pub struct widget { #[offset(4)] pub mode: widget_enum, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct point_struct { #[offset(0)] @@ -26,11 +26,12 @@ pub struct point_struct { #[offset(4)] pub y: i32, } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(4)] pub struct point { #[offset(0)] #[byte_size(4)] + #[array_len(4)] __bytes: Box<[u8]>, } impl point { @@ -48,11 +49,12 @@ impl Default for point { } } } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(4)] pub struct slot_union { #[offset(0)] #[byte_size(4)] + #[array_len(4)] __bytes: Box<[u8]>, } impl slot_union { @@ -73,20 +75,20 @@ impl Default for slot_union { pub type slot = u32; pub const slot_SLOT_A: slot = 0; pub const slot_SLOT_B: slot = 1; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Inner { #[offset(0)] pub tag_field: i32, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Outer { #[offset(0)] #[byte_size(4)] pub field: Inner, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Inner_struct { #[offset(0)] diff --git a/tests/unit/out/refcount/template_default_arg.rs b/tests/unit/out/refcount/template_default_arg.rs index 04b034ea12..4e8839d822 100644 --- a/tests/unit/out/refcount/template_default_arg.rs +++ b/tests/unit/out/refcount/template_default_arg.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom)] #[cpp_from(i32, new_1, value)] #[byte_size(4)] pub struct A { @@ -26,7 +26,7 @@ impl Default for A { { A::new_2() } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct B { #[offset(0)] @@ -42,7 +42,7 @@ impl Default for B { { B::new() } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct NoDefault { @@ -66,7 +66,7 @@ pub fn scaled_2(mut x: A, mut n: i32) -> i32 { pub fn always_given_3(mut x: NoDefault) -> i32 { return x.v; } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct S_NoDefault_ { diff --git a/tests/unit/out/refcount/template_static_member.rs b/tests/unit/out/refcount/template_static_member.rs index a4e3dc84aa..5af9536c09 100644 --- a/tests/unit/out/refcount/template_static_member.rs +++ b/tests/unit/out/refcount/template_static_member.rs @@ -9,19 +9,19 @@ use std::rc::{Rc, Weak}; thread_local!( pub static s_0: Value = Rc::new(RefCell::new(55)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct Static_int_ {} thread_local!( pub static s_1: Value = Rc::new(RefCell::new(55_i8)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct Static_char_ {} thread_local!( pub static s_2: Value = Rc::new(RefCell::new(55_i64)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct Static_long_ {} thread_local!( @@ -30,7 +30,7 @@ thread_local!( thread_local!( pub static hi_4: Value = Rc::new(RefCell::new(1)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct Range_int_ {} thread_local!( @@ -39,7 +39,7 @@ thread_local!( thread_local!( pub static hi_6: Value = Rc::new(RefCell::new(2_i64)); ); -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct Range_long_ {} pub fn main() { diff --git a/tests/unit/out/refcount/temporary_field_addr.rs b/tests/unit/out/refcount/temporary_field_addr.rs index d6c1d3cd11..32d3cde098 100644 --- a/tests/unit/out/refcount/temporary_field_addr.rs +++ b/tests/unit/out/refcount/temporary_field_addr.rs @@ -6,7 +6,9 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, +)] #[byte_size(24)] pub struct Inner { #[offset(0)] @@ -20,7 +22,7 @@ impl Inner { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign)] #[byte_size(56)] pub struct Outer { #[offset(0)] @@ -31,6 +33,7 @@ pub struct Outer { pub inner: Inner, #[offset(48)] #[byte_size(8)] + #[array_len(8)] pub name: Box<[i8]>, } impl Outer { diff --git a/tests/unit/out/refcount/temporary_field_ctor_arg.rs b/tests/unit/out/refcount/temporary_field_ctor_arg.rs index ffd8febf48..bf99357b12 100644 --- a/tests/unit/out/refcount/temporary_field_ctor_arg.rs +++ b/tests/unit/out/refcount/temporary_field_ctor_arg.rs @@ -6,7 +6,9 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, +)] #[byte_size(24)] pub struct Outer { #[offset(0)] @@ -25,7 +27,7 @@ pub fn make_0() -> Outer { values: Vec::from([1, 2, 3, 4]), }; } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_from(Vec , new, ptr)] #[byte_size(4)] pub struct H { diff --git a/tests/unit/out/refcount/temporary_field_two_args.rs b/tests/unit/out/refcount/temporary_field_two_args.rs index be85304730..9cf4e0914b 100644 --- a/tests/unit/out/refcount/temporary_field_two_args.rs +++ b/tests/unit/out/refcount/temporary_field_two_args.rs @@ -6,7 +6,9 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, +)] #[byte_size(24)] pub struct Inner { #[offset(0)] @@ -20,7 +22,9 @@ impl Inner { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, +)] #[byte_size(48)] pub struct Outer { #[offset(0)] diff --git a/tests/unit/out/refcount/this.rs b/tests/unit/out/refcount/this.rs index f0cf148043..56b069fa92 100644 --- a/tests/unit/out/refcount/this.rs +++ b/tests/unit/out/refcount/this.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_from(i32, new_1, value)] #[byte_size(16)] pub struct S { @@ -51,7 +51,7 @@ impl S { pub fn bump_0(mut p: Ptr) { field!(p, a_).with_mut(|__v| __v.postfix_inc()); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct D { diff --git a/tests/unit/out/refcount/typedef-anon-struct.rs b/tests/unit/out/refcount/typedef-anon-struct.rs index f864e519d0..8d5d3f03d0 100644 --- a/tests/unit/out/refcount/typedef-anon-struct.rs +++ b/tests/unit/out/refcount/typedef-anon-struct.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Outer_RunInfo { #[offset(0)] @@ -14,7 +14,9 @@ pub struct Outer_RunInfo { #[offset(4)] pub num_extra_zero_runs: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, +)] #[byte_size(24)] pub struct Outer { #[offset(0)] diff --git a/tests/unit/out/refcount/unary_expr_or_type_trait.rs b/tests/unit/out/refcount/unary_expr_or_type_trait.rs index 8deadb5d6d..11cde1b667 100644 --- a/tests/unit/out/refcount/unary_expr_or_type_trait.rs +++ b/tests/unit/out/refcount/unary_expr_or_type_trait.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct S { #[offset(0)] diff --git a/tests/unit/out/refcount/unboxed_locals.rs b/tests/unit/out/refcount/unboxed_locals.rs index 5202abfa9d..ad81da32be 100644 --- a/tests/unit/out/refcount/unboxed_locals.rs +++ b/tests/unit/out/refcount/unboxed_locals.rs @@ -14,7 +14,7 @@ pub fn inc_1(r: Ptr) { __v.prefix_inc(); }); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Pair { #[offset(0)] @@ -54,7 +54,7 @@ pub fn countdown_4(mut n: i32, mut step: i32) -> i32 { pub trait Shape { fn scale(&mut self, factor: i32) -> i32; } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(16)] pub struct Square { #[offset(8)] diff --git a/tests/unit/out/refcount/unboxed_records.rs b/tests/unit/out/refcount/unboxed_records.rs index c9ce989825..dd511e1697 100644 --- a/tests/unit/out/refcount/unboxed_records.rs +++ b/tests/unit/out/refcount/unboxed_records.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Inner { #[offset(0)] @@ -14,7 +14,7 @@ pub struct Inner { #[offset(4)] pub b: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(48)] pub struct Cookie { #[offset(0)] @@ -30,6 +30,7 @@ pub struct Cookie { pub inner: Inner, #[offset(32)] #[byte_size(16)] + #[array_len(4)] pub arr: Box<[i32]>, } impl Default for Cookie { @@ -45,7 +46,7 @@ impl Default for Cookie { } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] pub struct Counter { #[offset(0)] diff --git a/tests/unit/out/refcount/union_addrof_external.rs b/tests/unit/out/refcount/union_addrof_external.rs index 95d15532e3..7a4f25160f 100644 --- a/tests/unit/out/refcount/union_addrof_external.rs +++ b/tests/unit/out/refcount/union_addrof_external.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(16)] pub struct record { #[offset(0)] @@ -17,6 +17,7 @@ pub struct record { pub hi: u32, #[offset(8)] #[byte_size(8)] + #[array_len(8)] pub pad: Box<[i8]>, } impl Default for record { @@ -31,11 +32,12 @@ impl Default for record { } } } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(128)] pub struct anon_0 { #[offset(0)] #[byte_size(128)] + #[array_len(128)] __bytes: Box<[u8]>, } impl anon_0 { @@ -53,7 +55,7 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(128)] pub struct Container { #[offset(0)] diff --git a/tests/unit/out/refcount/union_basic.rs b/tests/unit/out/refcount/union_basic.rs index 8bdd16de0f..be25047476 100644 --- a/tests/unit/out/refcount/union_basic.rs +++ b/tests/unit/out/refcount/union_basic.rs @@ -6,11 +6,12 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(4)] pub struct basic { #[offset(0)] #[byte_size(4)] + #[array_len(4)] __bytes: Box<[u8]>, } impl basic { @@ -28,11 +29,12 @@ impl Default for basic { } } } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(1)] pub struct empty { #[offset(0)] #[byte_size(1)] + #[array_len(1)] __bytes: Box<[u8]>, } impl empty {} @@ -43,11 +45,12 @@ impl Default for empty { } } } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct underscores { #[offset(0)] #[byte_size(8)] + #[array_len(8)] __bytes: Box<[u8]>, } impl underscores { @@ -120,11 +123,12 @@ fn main_0() -> i32 { assert!(((__ + ___) == 3)); return 0; } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(4)] pub struct anon_0 { #[offset(0)] #[byte_size(4)] + #[array_len(4)] __bytes: Box<[u8]>, } impl anon_0 { diff --git a/tests/unit/out/refcount/union_cross_arm_cast.rs b/tests/unit/out/refcount/union_cross_arm_cast.rs index 60ad86f7fa..a9d1479a1e 100644 --- a/tests/unit/out/refcount/union_cross_arm_cast.rs +++ b/tests/unit/out/refcount/union_cross_arm_cast.rs @@ -6,13 +6,14 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(16)] pub struct shape_a { #[offset(0)] pub code: u16, #[offset(2)] #[byte_size(14)] + #[array_len(14)] pub pad: Box<[i8]>, } impl Default for shape_a { @@ -25,7 +26,7 @@ impl Default for shape_a { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(28)] pub struct shape_b { #[offset(0)] @@ -36,6 +37,7 @@ pub struct shape_b { pub mid: u32, #[offset(8)] #[byte_size(16)] + #[array_len(16)] pub fill: Box<[u8]>, #[offset(24)] pub tail: u32, @@ -53,11 +55,12 @@ impl Default for shape_b { } } } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(64)] pub struct anon_0 { #[offset(0)] #[byte_size(64)] + #[array_len(64)] __bytes: Box<[u8]>, } impl anon_0 { @@ -78,7 +81,7 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(68)] pub struct Container { #[offset(0)] diff --git a/tests/unit/out/refcount/union_field_alignment.rs b/tests/unit/out/refcount/union_field_alignment.rs index 59a9b7f077..57809017f9 100644 --- a/tests/unit/out/refcount/union_field_alignment.rs +++ b/tests/unit/out/refcount/union_field_alignment.rs @@ -6,11 +6,12 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] #[byte_size(8)] + #[array_len(8)] __bytes: Box<[u8]>, } impl anon_0 { @@ -28,7 +29,7 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct node { #[offset(0)] diff --git a/tests/unit/out/refcount/union_flex_array_member.rs b/tests/unit/out/refcount/union_flex_array_member.rs index 240ef06b64..9175cf2729 100644 --- a/tests/unit/out/refcount/union_flex_array_member.rs +++ b/tests/unit/out/refcount/union_flex_array_member.rs @@ -6,11 +6,12 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] #[byte_size(8)] + #[array_len(8)] __bytes: Box<[u8]>, } impl anon_0 { @@ -28,7 +29,7 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(24)] pub struct node { #[offset(0)] diff --git a/tests/unit/out/refcount/union_memset_memcpy.rs b/tests/unit/out/refcount/union_memset_memcpy.rs index 9190bd8958..517b8b726f 100644 --- a/tests/unit/out/refcount/union_memset_memcpy.rs +++ b/tests/unit/out/refcount/union_memset_memcpy.rs @@ -6,13 +6,14 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(16)] pub struct shape_a { #[offset(0)] pub code: u16, #[offset(2)] #[byte_size(14)] + #[array_len(14)] pub pad: Box<[i8]>, } impl Default for shape_a { @@ -25,7 +26,7 @@ impl Default for shape_a { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(16)] pub struct shape_b { #[offset(0)] @@ -36,6 +37,7 @@ pub struct shape_b { pub hi: u32, #[offset(8)] #[byte_size(8)] + #[array_len(8)] pub fill: Box<[i8]>, } impl Default for shape_b { @@ -50,11 +52,12 @@ impl Default for shape_b { } } } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(256)] pub struct anon_0 { #[offset(0)] #[byte_size(256)] + #[array_len(256)] __bytes: Box<[u8]>, } impl anon_0 { @@ -75,7 +78,7 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(256)] pub struct Container { #[offset(0)] diff --git a/tests/unit/out/refcount/union_nested.rs b/tests/unit/out/refcount/union_nested.rs index 9b9a9f9491..7ef5b75524 100644 --- a/tests/unit/out/refcount/union_nested.rs +++ b/tests/unit/out/refcount/union_nested.rs @@ -6,13 +6,14 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(16)] pub struct record { #[offset(0)] pub code: u16, #[offset(2)] #[byte_size(14)] + #[array_len(14)] pub pad: Box<[i8]>, } impl Default for record { @@ -25,11 +26,12 @@ impl Default for record { } } } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(128)] pub struct anon_0 { #[offset(0)] #[byte_size(128)] + #[array_len(128)] __bytes: Box<[u8]>, } impl anon_0 { @@ -47,18 +49,19 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(128)] pub struct inner { #[offset(0)] #[byte_size(128)] pub view: anon_0, } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(128)] pub struct anon_1 { #[offset(0)] #[byte_size(128)] + #[array_len(128)] __bytes: Box<[u8]>, } impl anon_1 { @@ -76,7 +79,7 @@ impl Default for anon_1 { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(144)] pub struct Outer { #[offset(0)] diff --git a/tests/unit/out/refcount/union_pointer_pun_address.rs b/tests/unit/out/refcount/union_pointer_pun_address.rs index 73fcdce7e3..39eebeea38 100644 --- a/tests/unit/out/refcount/union_pointer_pun_address.rs +++ b/tests/unit/out/refcount/union_pointer_pun_address.rs @@ -6,13 +6,13 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct node_a { #[offset(0)] pub n: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct node_b { #[offset(0)] @@ -34,11 +34,12 @@ fn main_0() -> i32 { assert!(({ (out).to_any() } == { (a.as_pointer()).to_any() })); return 0; } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] #[byte_size(8)] + #[array_len(8)] __bytes: Box<[u8]>, } impl anon_0 { diff --git a/tests/unit/out/refcount/union_pointer_pun_writethrough.rs b/tests/unit/out/refcount/union_pointer_pun_writethrough.rs index 23d5a6c1d4..c16a0a1c70 100644 --- a/tests/unit/out/refcount/union_pointer_pun_writethrough.rs +++ b/tests/unit/out/refcount/union_pointer_pun_writethrough.rs @@ -18,11 +18,12 @@ fn main_0() -> i32 { assert!(({ ((*x.borrow()) == 42_i64) })); return 0; } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] #[byte_size(8)] + #[array_len(8)] __bytes: Box<[u8]>, } impl anon_0 { diff --git a/tests/unit/out/refcount/union_struct_dual_use.rs b/tests/unit/out/refcount/union_struct_dual_use.rs index 5220df13ba..9a272dd59f 100644 --- a/tests/unit/out/refcount/union_struct_dual_use.rs +++ b/tests/unit/out/refcount/union_struct_dual_use.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Inner { #[offset(0)] @@ -17,11 +17,12 @@ pub struct Inner { pub fn sum_inner_0(mut i: Ptr) -> i32 { return ({ i.with(|__s| __s.a) } + { i.with(|__s| __s.b) }); } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(16)] pub struct anon_1 { #[offset(0)] #[byte_size(16)] + #[array_len(16)] __bytes: Box<[u8]>, } impl anon_1 { @@ -39,7 +40,7 @@ impl Default for anon_1 { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Outer { #[offset(0)] diff --git a/tests/unit/out/refcount/union_tagged_many_arms.rs b/tests/unit/out/refcount/union_tagged_many_arms.rs index 15327cd089..e6015b90dc 100644 --- a/tests/unit/out/refcount/union_tagged_many_arms.rs +++ b/tests/unit/out/refcount/union_tagged_many_arms.rs @@ -12,11 +12,12 @@ pub const Tag_enum_T_NUM_U: Tag_enum = 1; pub const Tag_enum_T_TEXT: Tag_enum = 2; pub const Tag_enum_T_FLOAT: Tag_enum = 3; pub const Tag_enum_T_REF: Tag_enum = 4; -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] #[byte_size(8)] + #[array_len(8)] __bytes: Box<[u8]>, } impl anon_0 { @@ -43,7 +44,7 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Slot { #[offset(0)] diff --git a/tests/unit/out/refcount/union_tagged_simple.rs b/tests/unit/out/refcount/union_tagged_simple.rs index 3198866474..830d7c1d8a 100644 --- a/tests/unit/out/refcount/union_tagged_simple.rs +++ b/tests/unit/out/refcount/union_tagged_simple.rs @@ -9,11 +9,12 @@ use std::rc::{Rc, Weak}; pub type Kind_enum = u32; pub const Kind_enum_KIND_NONE: Kind_enum = 0; pub const Kind_enum_KIND_DONE: Kind_enum = 1; -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] #[byte_size(8)] + #[array_len(8)] __bytes: Box<[u8]>, } impl anon_0 { @@ -31,7 +32,7 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(24)] pub struct Event { #[offset(0)] diff --git a/tests/unit/out/refcount/union_tagged_struct_arms.rs b/tests/unit/out/refcount/union_tagged_struct_arms.rs index 594363d299..db388b5ac6 100644 --- a/tests/unit/out/refcount/union_tagged_struct_arms.rs +++ b/tests/unit/out/refcount/union_tagged_struct_arms.rs @@ -10,7 +10,7 @@ pub type Choice_enum = u32; pub const Choice_enum_C_LIST: Choice_enum = 1; pub const Choice_enum_C_LETTERS: Choice_enum = 2; pub const Choice_enum_C_INTEGERS: Choice_enum = 3; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(24)] pub struct anon_1 { #[offset(0)] @@ -21,7 +21,7 @@ pub struct anon_1 { #[offset(16)] pub cursor: i64, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct anon_2 { #[offset(0)] @@ -33,7 +33,7 @@ pub struct anon_2 { #[offset(12)] pub step: u8, } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(40)] pub struct anon_3 { #[offset(0)] @@ -47,11 +47,12 @@ pub struct anon_3 { #[offset(32)] pub width: i32, } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(40)] pub struct anon_0 { #[offset(0)] #[byte_size(40)] + #[array_len(40)] __bytes: Box<[u8]>, } impl anon_0 { @@ -72,7 +73,7 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(48)] pub struct Branch { #[offset(0)] diff --git a/tests/unit/out/refcount/union_void_ptr_sized_deref.rs b/tests/unit/out/refcount/union_void_ptr_sized_deref.rs index 1b34ddf1a8..271b2b7121 100644 --- a/tests/unit/out/refcount/union_void_ptr_sized_deref.rs +++ b/tests/unit/out/refcount/union_void_ptr_sized_deref.rs @@ -10,11 +10,12 @@ pub type Width_enum = u32; pub const Width_enum_W_64: Width_enum = 0; pub const Width_enum_W_32: Width_enum = 1; pub const Width_enum_W_16: Width_enum = 2; -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct anon_0 { #[offset(0)] #[byte_size(8)] + #[array_len(8)] __bytes: Box<[u8]>, } impl anon_0 { @@ -38,7 +39,7 @@ impl Default for anon_0 { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct Sink { #[offset(0)] diff --git a/tests/unit/out/refcount/unique_ptr.rs b/tests/unit/out/refcount/unique_ptr.rs index b76b57bdb1..b928095edd 100644 --- a/tests/unit/out/refcount/unique_ptr.rs +++ b/tests/unit/out/refcount/unique_ptr.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] #[byte_size(8)] pub struct SafePointer { #[offset(0)] @@ -20,7 +20,7 @@ impl SafePointer { } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Pair { #[offset(0)] diff --git a/tests/unit/out/refcount/unique_ptr_const_deref.rs b/tests/unit/out/refcount/unique_ptr_const_deref.rs index 2a71c1dc23..c29e3d7338 100644 --- a/tests/unit/out/refcount/unique_ptr_const_deref.rs +++ b/tests/unit/out/refcount/unique_ptr_const_deref.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] #[byte_size(8)] pub struct Holder { #[offset(0)] diff --git a/tests/unit/out/refcount/unique_ptr_field_reset.rs b/tests/unit/out/refcount/unique_ptr_field_reset.rs index 9b3fe9c6ff..ee36217eea 100644 --- a/tests/unit/out/refcount/unique_ptr_field_reset.rs +++ b/tests/unit/out/refcount/unique_ptr_field_reset.rs @@ -6,13 +6,13 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Data { #[offset(0)] pub v: i32, } -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] #[byte_size(16)] pub struct Holder { #[offset(0)] diff --git a/tests/unit/out/refcount/unique_ptr_nested.rs b/tests/unit/out/refcount/unique_ptr_nested.rs index aba8b6b507..9d6bab6be2 100644 --- a/tests/unit/out/refcount/unique_ptr_nested.rs +++ b/tests/unit/out/refcount/unique_ptr_nested.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Inner { #[offset(0)] @@ -14,7 +14,7 @@ pub struct Inner { #[offset(4)] pub y: i32, } -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] #[byte_size(8)] pub struct Outer { #[offset(0)] diff --git a/tests/unit/out/refcount/unique_ptr_struct.rs b/tests/unit/out/refcount/unique_ptr_struct.rs index d65e042875..a4b69191dd 100644 --- a/tests/unit/out/refcount/unique_ptr_struct.rs +++ b/tests/unit/out/refcount/unique_ptr_struct.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Point { #[offset(0)] diff --git a/tests/unit/out/refcount/va_arg_mixed_types.rs b/tests/unit/out/refcount/va_arg_mixed_types.rs index 51d25a87de..2dd7e4c91d 100644 --- a/tests/unit/out/refcount/va_arg_mixed_types.rs +++ b/tests/unit/out/refcount/va_arg_mixed_types.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct pair { #[offset(0)] diff --git a/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs b/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs index da8474fd56..7d5b5f9630 100644 --- a/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs +++ b/tests/unit/out/refcount/va_arg_non_primitive_ptrs.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct node { #[offset(0)] diff --git a/tests/unit/out/refcount/va_arg_struct_ctx.rs b/tests/unit/out/refcount/va_arg_struct_ctx.rs index b594487d18..ca01b26811 100644 --- a/tests/unit/out/refcount/va_arg_struct_ctx.rs +++ b/tests/unit/out/refcount/va_arg_struct_ctx.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct context { #[offset(0)] @@ -24,11 +24,12 @@ pub fn set_error_0(mut ctx: Ptr, fmt: Ptr, __args: Box<[VaArg]>) { field!(ctx, last_error).write(__rhs); } } -#[derive(VaArg, FnPtrArg, ByteRepr, Clone)] +#[derive(VaArg, FnPtrArg, ByteRepr, Clone, ZeroInitialization)] #[byte_size(8)] pub struct value { #[offset(0)] #[byte_size(8)] + #[array_len(8)] __bytes: Box<[u8]>, } impl value { diff --git a/tests/unit/out/refcount/va_arg_void_ptr.rs b/tests/unit/out/refcount/va_arg_void_ptr.rs index 5dfdb884e5..432e2b742a 100644 --- a/tests/unit/out/refcount/va_arg_void_ptr.rs +++ b/tests/unit/out/refcount/va_arg_void_ptr.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(16)] pub struct registry { #[offset(0)] diff --git a/tests/unit/out/refcount/va_list_field.rs b/tests/unit/out/refcount/va_list_field.rs index 5dd7dfeb52..6f5a7396b8 100644 --- a/tests/unit/out/refcount/va_list_field.rs +++ b/tests/unit/out/refcount/va_list_field.rs @@ -25,7 +25,9 @@ pub fn sum_0(n: i32, __args: Box<[VaArg]>) -> i32 { } return total; } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Destructor, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Destructor, Default, +)] #[cpp_from(Ptr , new, mut_ptr)] #[byte_size(16)] pub struct Guard_1 { @@ -63,7 +65,7 @@ pub fn sum_ptr_2(n: i32, __args: Box<[VaArg]>) -> i32 { }; return total; } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Cursor_3 { #[offset(0)] diff --git a/tests/unit/out/refcount/vector.rs b/tests/unit/out/refcount/vector.rs index e1468ef8c3..8ecbf7f350 100644 --- a/tests/unit/out/refcount/vector.rs +++ b/tests/unit/out/refcount/vector.rs @@ -6,14 +6,16 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct S { #[offset(0)] pub x: i32, } pub fn copy_0(mut copy_vector: Vec) {} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, +)] #[byte_size(48)] pub struct Foo { #[offset(0)] diff --git a/tests/unit/out/refcount/vector_iter_range_ctor.rs b/tests/unit/out/refcount/vector_iter_range_ctor.rs index 9eb433d954..801cee5414 100644 --- a/tests/unit/out/refcount/vector_iter_range_ctor.rs +++ b/tests/unit/out/refcount/vector_iter_range_ctor.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct Degrees { @@ -18,7 +18,7 @@ impl Degrees { Self { value: v } } } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] #[cpp_into(i64, to_i64)] #[byte_size(4)] pub struct Reading { diff --git a/tests/unit/out/refcount/vector_subscript_direct.rs b/tests/unit/out/refcount/vector_subscript_direct.rs index 556ff5a363..73b19794df 100644 --- a/tests/unit/out/refcount/vector_subscript_direct.rs +++ b/tests/unit/out/refcount/vector_subscript_direct.rs @@ -6,7 +6,7 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(8)] pub struct Point { #[offset(0)] @@ -14,7 +14,9 @@ pub struct Point { #[offset(4)] pub y: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, +)] #[byte_size(48)] pub struct Holder { #[offset(0)] diff --git a/tests/unit/out/refcount/vector_with_allocator.rs b/tests/unit/out/refcount/vector_with_allocator.rs index 9d167eddcb..aaa75bf506 100644 --- a/tests/unit/out/refcount/vector_with_allocator.rs +++ b/tests/unit/out/refcount/vector_with_allocator.rs @@ -6,10 +6,10 @@ use std::io::prelude::*; use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct TestAllocator_int_ {} -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] pub struct TestAllocator_double_ {} pub fn copy_0(mut copy_vector: Vec) {} diff --git a/tests/unit/out/refcount/void_cast.rs b/tests/unit/out/refcount/void_cast.rs index 6fed81259f..a74374adb5 100644 --- a/tests/unit/out/refcount/void_cast.rs +++ b/tests/unit/out/refcount/void_cast.rs @@ -7,7 +7,9 @@ use std::io::{Read, Seek, Write}; use std::os::fd::AsFd; use std::rc::{Rc, Weak}; pub fn unused_param_0(mut x: i32) {} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive( + Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, MoveAssign, Default, +)] #[byte_size(24)] pub struct NonTrivial { #[offset(0)] @@ -30,13 +32,13 @@ pub fn bump_and_return_4() -> i32 { (*side_effect_counter_3.with(Value::clone).borrow_mut()).prefix_inc(); return side_effect_counter_3.with(|rc| *rc.borrow()); } -#[derive(Copy, Clone, Record, ByteRepr, VaArg, FnPtrArg, Default)] +#[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] pub struct Holder { #[offset(0)] pub field: i32, } -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, MoveAssign, Default)] +#[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] #[byte_size(8)] pub struct NonCopyable { #[offset(0)] From 931e173ada812824ec66e9d443a09ff537d07cc6 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sun, 29 Nov 2026 18:44:30 +0000 Subject: [PATCH 02/18] Update rules --- rules/brotli/shim.rs | 6 ++++++ rules/dirent/shim.rs | 5 +++-- rules/ifaddrs/shim.rs | 6 ++++-- rules/ip/shim.rs | 7 ++++--- rules/iterator_category/shim.rs | 12 ++++++++++++ rules/map/shim.rs | 6 ++++++ rules/netdb/shim.rs | 4 ++-- rules/poll/shim.rs | 4 ++-- rules/pwd/shim.rs | 4 ++-- rules/select/shim.rs | 6 ++++++ rules/socket/shim.rs | 16 ++++++++++------ rules/stat/shim.rs | 4 ++-- rules/termios/shim.rs | 7 ++++--- rules/time/shim.rs | 8 ++++---- 14 files changed, 67 insertions(+), 28 deletions(-) diff --git a/rules/brotli/shim.rs b/rules/brotli/shim.rs index 942dfb21ae..51fd14e2c6 100644 --- a/rules/brotli/shim.rs +++ b/rules/brotli/shim.rs @@ -50,6 +50,12 @@ pub struct BrotliDecoderState { impl ByteRepr for BrotliDecoderState {} +impl crate::ZeroInitialization for BrotliDecoderState { + fn zero_init() -> Self { + Self::default() + } +} + impl Default for BrotliDecoderState { fn default() -> Self { Self { diff --git a/rules/dirent/shim.rs b/rules/dirent/shim.rs index 90c77ada5e..1d738cf2cc 100644 --- a/rules/dirent/shim.rs +++ b/rules/dirent/shim.rs @@ -1,11 +1,11 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -use crate::{ByteRepr, Record, size_of_field}; +use crate::{ByteRepr, Record, ZeroInitialization, size_of_field}; use std::cell::Cell; use std::mem::{offset_of, size_of}; -#[derive(Clone, Record, ByteRepr)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization)] #[byte_size(size_of::<::libc::dirent>())] pub struct Dirent { #[offset(offset_of!(::libc::dirent, d_ino))] @@ -19,6 +19,7 @@ pub struct Dirent { pub d_type: u8, #[offset(offset_of!(::libc::dirent, d_name))] #[byte_size(size_of_field!(::libc::dirent, d_name))] + #[array_len(size_of_field!(::libc::dirent, d_name))] pub d_name: Box<[i8]>, } diff --git a/rules/ifaddrs/shim.rs b/rules/ifaddrs/shim.rs index 9189609094..eff408a936 100644 --- a/rules/ifaddrs/shim.rs +++ b/rules/ifaddrs/shim.rs @@ -1,10 +1,12 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -use crate::{ByteRepr, Ptr, Record, Sockaddr, SockaddrIn, SockaddrIn6, SockaddrStorage}; +use crate::{ + ByteRepr, Ptr, Record, Sockaddr, SockaddrIn, SockaddrIn6, SockaddrStorage, ZeroInitialization, +}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record, ByteRepr)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] #[byte_size(size_of::<::libc::ifaddrs>())] pub struct Ifaddrs { #[offset(offset_of!(::libc::ifaddrs, ifa_next))] diff --git a/rules/ip/shim.rs b/rules/ip/shim.rs index 38b96f86a8..842f81350e 100644 --- a/rules/ip/shim.rs +++ b/rules/ip/shim.rs @@ -1,20 +1,21 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -use crate::{ByteRepr, Ptr, Record}; +use crate::{ByteRepr, Ptr, Record, ZeroInitialization}; -#[derive(Clone, Default, Record, ByteRepr)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] #[byte_size(4)] pub struct InAddr { #[offset(0)] pub s_addr: u32, } -#[derive(Clone, Record, ByteRepr)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization)] #[byte_size(16)] pub struct In6Addr { #[offset(0)] #[byte_size(16)] + #[array_len(16)] pub s6_addr: Box<[u8]>, } diff --git a/rules/iterator_category/shim.rs b/rules/iterator_category/shim.rs index 59b078ce6c..7fcaaeedd4 100644 --- a/rules/iterator_category/shim.rs +++ b/rules/iterator_category/shim.rs @@ -216,6 +216,12 @@ pub enum BidirectionalIterator { Map(Value>), } +impl crate::ZeroInitialization for BidirectionalIterator { + fn zero_init() -> Self { + Self::default() + } +} + impl Default for BidirectionalIterator { fn default() -> Self { Self::Map(MapNode::header()) @@ -348,6 +354,12 @@ macro_rules! random_access_iterator { } } + impl crate::ZeroInitialization for $name { + fn zero_init() -> Self { + Self::default() + } + } + impl Clone for $name { fn clone(&self) -> Self { match self { diff --git a/rules/map/shim.rs b/rules/map/shim.rs index e2f3551375..caaf12d995 100644 --- a/rules/map/shim.rs +++ b/rules/map/shim.rs @@ -89,6 +89,12 @@ pub struct Map { header: Value>, } +impl crate::ZeroInitialization for Map { + fn zero_init() -> Self { + Self::default() + } +} + impl Default for Map { fn default() -> Self { Self { diff --git a/rules/netdb/shim.rs b/rules/netdb/shim.rs index 526a3e23b8..9432b2adcf 100644 --- a/rules/netdb/shim.rs +++ b/rules/netdb/shim.rs @@ -1,10 +1,10 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -use crate::{ByteRepr, Ptr, Record, Sockaddr}; +use crate::{ByteRepr, Ptr, Record, Sockaddr, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record, ByteRepr)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] #[byte_size(size_of::<::libc::addrinfo>())] pub struct Addrinfo { #[offset(offset_of!(::libc::addrinfo, ai_flags))] diff --git a/rules/poll/shim.rs b/rules/poll/shim.rs index 6ad3807f9f..06f6daa720 100644 --- a/rules/poll/shim.rs +++ b/rules/poll/shim.rs @@ -1,10 +1,10 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -use crate::{ByteRepr, Record}; +use crate::{ByteRepr, Record, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record, ByteRepr)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] #[byte_size(size_of::<::libc::pollfd>())] pub struct Pollfd { #[offset(offset_of!(::libc::pollfd, fd))] diff --git a/rules/pwd/shim.rs b/rules/pwd/shim.rs index 724e508de3..01229b236f 100644 --- a/rules/pwd/shim.rs +++ b/rules/pwd/shim.rs @@ -1,10 +1,10 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -use crate::{ByteRepr, Ptr, Record}; +use crate::{ByteRepr, Ptr, Record, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record, ByteRepr)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] #[byte_size(size_of::<::libc::passwd>())] pub struct Passwd { #[offset(offset_of!(::libc::passwd, pw_name))] diff --git a/rules/select/shim.rs b/rules/select/shim.rs index 2be99981e0..7a108b2223 100644 --- a/rules/select/shim.rs +++ b/rules/select/shim.rs @@ -10,6 +10,12 @@ pub struct CFdSet { impl crate::ByteRepr for CFdSet {} +impl crate::ZeroInitialization for CFdSet { + fn zero_init() -> Self { + Self::default() + } +} + impl CFdSet { pub fn zero(&mut self) { self.fds.clear(); diff --git a/rules/socket/shim.rs b/rules/socket/shim.rs index 6d8009b0e8..47ef06c5f9 100644 --- a/rules/socket/shim.rs +++ b/rules/socket/shim.rs @@ -1,20 +1,21 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -use crate::{ByteRepr, CChar, In6Addr, InAddr, Ptr, Record}; +use crate::{ByteRepr, CChar, In6Addr, InAddr, Ptr, Record, ZeroInitialization}; // The fields are at the offsets of the byte representation below. -#[derive(Clone, Record, ByteRepr)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization)] #[byte_size(16)] pub struct Sockaddr { #[offset(0)] pub sa_family: u16, #[offset(2)] #[byte_size(14)] + #[array_len(14)] pub sa_data: Box<[i8]>, } -#[derive(Clone, Record, ByteRepr)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization)] #[byte_size(16)] pub struct SockaddrIn { #[offset(0)] @@ -25,10 +26,11 @@ pub struct SockaddrIn { pub sin_addr: InAddr, #[offset(8)] #[byte_size(8)] + #[array_len(8)] pub sin_zero: Box<[u8]>, } -#[derive(Clone, Default, Record, ByteRepr)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] #[byte_size(28)] pub struct SockaddrIn6 { #[offset(0)] @@ -43,23 +45,25 @@ pub struct SockaddrIn6 { pub sin6_scope_id: u32, } -#[derive(Clone, Record, ByteRepr)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization)] #[byte_size(110)] pub struct SockaddrUn { #[offset(0)] pub sun_family: u16, #[offset(2)] #[byte_size(108)] + #[array_len(108)] pub sun_path: Box<[i8]>, } -#[derive(Clone, Record, ByteRepr)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization)] #[byte_size(128)] pub struct SockaddrStorage { #[offset(0)] pub ss_family: u16, #[offset(2)] #[byte_size(126)] + #[array_len(126)] pub __pad: Box<[u8]>, } diff --git a/rules/stat/shim.rs b/rules/stat/shim.rs index bad11db7ab..423b6bbdd6 100644 --- a/rules/stat/shim.rs +++ b/rules/stat/shim.rs @@ -1,10 +1,10 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -use crate::{ByteRepr, Record}; +use crate::{ByteRepr, Record, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record)] +#[derive(Clone, Default, Record, ZeroInitialization)] // The fields have the sizes of those of libc::stat only in x86-64 Linux. #[cfg_attr( all(target_os = "linux", target_arch = "x86_64"), diff --git a/rules/termios/shim.rs b/rules/termios/shim.rs index 2155a01bd2..2a4ea03734 100644 --- a/rules/termios/shim.rs +++ b/rules/termios/shim.rs @@ -1,10 +1,10 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -use crate::{ByteRepr, Record}; +use crate::{ByteRepr, Record, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Record, ByteRepr)] +#[derive(Clone, Record, ByteRepr, ZeroInitialization)] #[byte_size(size_of::<::libc::termios>())] pub struct Termios { #[offset(offset_of!(::libc::termios, c_iflag))] @@ -20,6 +20,7 @@ pub struct Termios { pub c_line: u8, #[offset(offset_of!(::libc::termios, c_cc))] #[byte_size(::libc::NCCS)] + #[array_len(32)] pub c_cc: Box<[u8]>, #[offset(offset_of!(::libc::termios, c_ispeed))] pub c_ispeed: u32, @@ -104,7 +105,7 @@ impl Termios { } } -#[derive(Clone, Default, Record, ByteRepr)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] #[byte_size(size_of::<::libc::winsize>())] pub struct Winsize { #[offset(offset_of!(::libc::winsize, ws_row))] diff --git a/rules/time/shim.rs b/rules/time/shim.rs index 431e66da43..2c9066f65c 100644 --- a/rules/time/shim.rs +++ b/rules/time/shim.rs @@ -1,10 +1,10 @@ // Copyright (c) 2022-present INESC-ID. // Distributed under the MIT license that can be found in the LICENSE file. -use crate::{ByteRepr, Ptr, Record}; +use crate::{ByteRepr, Ptr, Record, ZeroInitialization}; use std::mem::{offset_of, size_of}; -#[derive(Clone, Default, Record, ByteRepr)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] #[byte_size(size_of::<::libc::tm>())] pub struct Tm { #[offset(offset_of!(::libc::tm, tm_sec))] @@ -65,7 +65,7 @@ impl Tm { } } -#[derive(Clone, Default, Record, ByteRepr)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] #[byte_size(size_of::<::libc::timeval>())] pub struct Timeval { #[offset(offset_of!(::libc::timeval, tv_sec))] @@ -74,7 +74,7 @@ pub struct Timeval { pub tv_usec: i64, } -#[derive(Clone, Default, Record, ByteRepr)] +#[derive(Clone, Default, Record, ByteRepr, ZeroInitialization)] #[byte_size(size_of::<::libc::timespec>())] pub struct Timespec { #[offset(offset_of!(::libc::timespec, tv_sec))] From b72cd1884ca222feb436256b2c3c5c1fb4bf125a Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sun, 29 Nov 2026 18:44:47 +0000 Subject: [PATCH 03/18] Fiz zero initialization of enums --- cpp2rust/converter/converter.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index eb0231c9f0..9b8dd174dc 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -4674,11 +4674,8 @@ std::string Converter::GetDefaultAsStringFallback(clang::QualType qual_type) { } if (qual_type->isEnumeralType()) { - auto enum_decl = qual_type->castAs()->getDecl(); - if (enum_decl->enumerators().empty()) { - return GetDefaultAsString(enum_decl->getIntegerType()); - } - return EnumeratorName(*enum_decl->enumerator_begin()); + return GetDefaultAsString( + qual_type->castAs()->getDecl()->getIntegerType()); } return std::format("<{}>::default()", ToString(qual_type)); From 0723df1cf15a3997f084cb68eb7074c99405e4b5 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sun, 29 Nov 2026 18:47:42 +0000 Subject: [PATCH 04/18] Add ZeroInitialization in libcc2rs and converter --- .../converter/models/converter_refcount.cpp | 38 ++++++++- libcc2rs-macros/src/initialization.rs | 56 +++++++++++++ libcc2rs-macros/src/lib.rs | 17 ++++ libcc2rs/src/fn_ptr.rs | 7 ++ libcc2rs/src/initialization.rs | 78 +++++++++++++++++++ libcc2rs/src/lib.rs | 7 +- libcc2rs/src/rc.rs | 7 ++ libcc2rs/src/void.rs | 7 ++ .../dcl.init/out/unsafe/dcl.init.general.rs | 2 +- 9 files changed, 214 insertions(+), 5 deletions(-) create mode 100644 libcc2rs-macros/src/initialization.rs create mode 100644 libcc2rs/src/initialization.rs diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index bcb26c3f41..5f0af0d282 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -797,8 +797,9 @@ void ConverterRefCount::EmitRustUnion(clang::RecordDecl *decl) { auto size = ctx_.getTypeSizeInChars(ctx_.getCanonicalTagType(decl)); StrCat(std::format( - "#[derive(ByteRepr, Clone)] #[byte_size({0})] pub struct {1} {{ " - "#[offset(0)] #[byte_size({0})] __bytes: Box<[u8]> }}", + "#[derive(ByteRepr, Clone, ZeroInitialization)] #[byte_size({0})] pub " + "struct {1} {{ " + "#[offset(0)] #[byte_size({0})] #[array_len({0})] __bytes: Box<[u8]> }}", size.getQuantity(), name)); StrCat("impl", name); @@ -845,6 +846,31 @@ bool ConverterRefCount::VisitCXXConstructorDecl( return Converter::VisitCXXConstructorDecl(decl); } +static std::vector GetArrayLengths(const clang::ASTContext &ctx, + clang::QualType type) { + std::vector lengths; + while (true) { + if (auto *array = ctx.getAsConstantArrayType(type)) { + lengths.push_back(array->getSize().getZExtValue()); + type = array->getElementType(); + continue; + } + if (ctx.getAsIncompleteArrayType(type)) { + lengths.push_back(0); + return lengths; + } + auto *array = + llvm::dyn_cast_or_null( + type->getAsCXXRecordDecl()); + if (!IsStdDecl(array, "array")) { + return lengths; + } + auto &args = array->getTemplateArgs(); + lengths.push_back(args[1].getAsIntegral().getZExtValue()); + type = args[0].getAsType(); + } +} + bool ConverterRefCount::VisitFieldDecl(clang::FieldDecl *decl) { // The C offset of the field, which locates it for pointers to it. const auto &layout = ctx_.getASTRecordLayout(decl->getParent()); @@ -858,6 +884,13 @@ bool ConverterRefCount::VisitFieldDecl(clang::FieldDecl *decl) { StrCat(std::format("#[byte_size({})]", ctx_.getTypeSizeInChars(decl->getType()).getQuantity())); } + if (auto lengths = GetArrayLengths(ctx_, decl->getType()); !lengths.empty()) { + std::string args; + for (auto length : lengths) { + args += std::format("{}{}", args.empty() ? "" : ", ", length); + } + StrCat(std::format("#[array_len({})]", args)); + } PushConversionKind push(*this, ConversionKind::Pointee); return Converter::VisitFieldDecl(decl); } @@ -2285,6 +2318,7 @@ ConverterRefCount::GetStructAttributes(const clang::RecordDecl *decl) { attrs.emplace_back("Record"); // Gives access to the bytes of the struct, at the offsets of its fields. attrs.emplace_back("ByteRepr"); + attrs.emplace_back("ZeroInitialization"); if (RecordImplementsClone(decl)) { attrs.emplace_back("VaArg"); diff --git a/libcc2rs-macros/src/initialization.rs b/libcc2rs-macros/src/initialization.rs new file mode 100644 index 0000000000..34a80ea98c --- /dev/null +++ b/libcc2rs-macros/src/initialization.rs @@ -0,0 +1,56 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +use proc_macro::TokenStream; +use proc_macro2::TokenStream as TokenStream2; +use quote::quote; +use syn::punctuated::Punctuated; +use syn::{Data, DeriveInput, Expr, Field, Fields, Index, Token, parse_macro_input}; + +// The zero-initialized value of `field`. An array, whose length is +// not part of its type, has one array_len argument per dimension. +fn zero_init(field: &Field) -> TokenStream2 { + let lens = field + .attrs + .iter() + .find(|attr| attr.path().is_ident("array_len")) + .map(|attr| { + attr.parse_args_with(Punctuated::::parse_terminated) + .unwrap() + }); + let mut value = quote!(::libcc2rs::ZeroInitialization::zero_init()); + for len in lens.iter().flatten().rev() { + value = quote!((0..#len).map(|_| #value).collect()); + } + value +} + +pub fn expand(input: TokenStream) -> TokenStream { + let input = parse_macro_input!(input as DeriveInput); + let name = &input.ident; + let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); + let Data::Struct(data) = &input.data else { + panic!("derive(ZeroInitialization) is only supported on structs, `{name}` is not one"); + }; + let fields = match &data.fields { + Fields::Named(fields) => { + let idents = fields.named.iter().map(|field| &field.ident); + let values = fields.named.iter().map(zero_init); + quote!({ #(#idents: #values,)* }) + } + Fields::Unnamed(fields) => { + let indices = (0..fields.unnamed.len()).map(Index::from); + let values = fields.unnamed.iter().map(zero_init); + quote!({ #(#indices: #values,)* }) + } + Fields::Unit => quote!({}), + }; + quote! { + impl #impl_generics ::libcc2rs::ZeroInitialization for #name #ty_generics #where_clause { + fn zero_init() -> Self { + Self #fields + } + } + } + .into() +} diff --git a/libcc2rs-macros/src/lib.rs b/libcc2rs-macros/src/lib.rs index 96783b6ab2..eee23a4ad1 100644 --- a/libcc2rs-macros/src/lib.rs +++ b/libcc2rs-macros/src/lib.rs @@ -9,6 +9,7 @@ mod cpp_from; mod destructor; mod fn_ptr_arg; mod goto; +mod initialization; mod lambda; mod move_ctor; mod record; @@ -148,6 +149,22 @@ pub fn derive_record(input: TokenStream) -> TokenStream { record::expand(input) } +// #[derive(ZeroInitialization)] +// pub struct S { +// pub a: i32, +// #[array_len(2, 3)] +// pub b: Box<[Box<[i32]>]>, +// } +// +// Implements libcc2rs::ZeroInitialization for S, whose zero_init is the +// zero_init of each of its fields. The arguments of the array_len attribute are the lengths of +// the dimensions of a field that is an array, outermost first. + +#[proc_macro_derive(ZeroInitialization, attributes(array_len))] +pub fn derive_zero_initialization(input: TokenStream) -> TokenStream { + initialization::expand(input) +} + // #[derive(MoveCtor)] // pub struct S { ... } // impl S { diff --git a/libcc2rs/src/fn_ptr.rs b/libcc2rs/src/fn_ptr.rs index d6fe3d8d82..aa5c2dbb0d 100644 --- a/libcc2rs/src/fn_ptr.rs +++ b/libcc2rs/src/fn_ptr.rs @@ -495,6 +495,13 @@ impl Eq for FnPtr {} impl ByteRepr for FnPtr {} +impl crate::ZeroInitialization for FnPtr { + #[inline] + fn zero_init() -> Self { + FnPtr::null() + } +} + impl FnPtrArg for FnPtr { #[inline] fn to_repr(self) -> ArgRepr { diff --git a/libcc2rs/src/initialization.rs b/libcc2rs/src/initialization.rs new file mode 100644 index 0000000000..509222cd18 --- /dev/null +++ b/libcc2rs/src/initialization.rs @@ -0,0 +1,78 @@ +// Copyright (c) 2022-present INESC-ID. +// Distributed under the MIT license that can be found in the LICENSE file. + +use std::cell::RefCell; +use std::rc::Rc; + +// Zero-initialization ([dcl.init.general]/6): scalars are zero, pointers are +// null. It is also the storage of an object before its constructor runs, so +// creating it has no side effects. +pub trait ZeroInitialization { + fn zero_init() -> Self; +} + +macro_rules! impl_zero_init { + ($($ty:ty => $value:expr),* $(,)?) => {$( + impl ZeroInitialization for $ty { + #[inline] + fn zero_init() -> Self { + $value + } + } + )*}; +} + +impl_zero_init!( + () => (), + bool => false, + u8 => 0, + i8 => 0, + u16 => 0, + i16 => 0, + u32 => 0, + i32 => 0, + u64 => 0, + i64 => 0, + u128 => 0, + i128 => 0, + usize => 0, + isize => 0, + f32 => 0.0, + f64 => 0.0, + std::cmp::Ordering => std::cmp::Ordering::Equal, +); + +impl ZeroInitialization for Option { + #[inline] + fn zero_init() -> Self { + None + } +} + +impl ZeroInitialization for Vec { + #[inline] + fn zero_init() -> Self { + Vec::new() + } +} + +impl ZeroInitialization for Rc> { + #[inline] + fn zero_init() -> Self { + Rc::new(RefCell::new(T::zero_init())) + } +} + +impl ZeroInitialization for [T; N] { + #[inline] + fn zero_init() -> Self { + std::array::from_fn(|_| T::zero_init()) + } +} + +impl ZeroInitialization for (A, B) { + #[inline] + fn zero_init() -> Self { + (A::zero_init(), B::zero_init()) + } +} diff --git a/libcc2rs/src/lib.rs b/libcc2rs/src/lib.rs index b74661d9ea..bd7b99b695 100644 --- a/libcc2rs/src/lib.rs +++ b/libcc2rs/src/lib.rs @@ -53,6 +53,9 @@ pub use cmp::*; mod conversion; pub use conversion::{CppFrom, CppFromUnsafe}; +mod initialization; +pub use initialization::ZeroInitialization; + mod swap; // Used by cpp_swap! and cpp_swap_unsafe!. #[doc(hidden)] @@ -105,6 +108,6 @@ pub use format::*; pub use libcc2rs_macros::{ ByteRepr, CopyAssign, CopyAssignUnsafe, CppFrom, CppFromUnsafe, Destructor, DestructorUnsafe, - FnPtrArg, MoveAssign, MoveAssignUnsafe, MoveCtor, MoveCtorUnsafe, Record, VaArg, goto, - goto_block, lambda, lambda_unsafe, switch, + FnPtrArg, MoveAssign, MoveAssignUnsafe, MoveCtor, MoveCtorUnsafe, Record, VaArg, + ZeroInitialization, goto, goto_block, lambda, lambda_unsafe, switch, }; diff --git a/libcc2rs/src/rc.rs b/libcc2rs/src/rc.rs index 248e89a7cd..bbaf6b8341 100644 --- a/libcc2rs/src/rc.rs +++ b/libcc2rs/src/rc.rs @@ -477,6 +477,13 @@ impl Default for Ptr { } } +impl crate::ZeroInitialization for Ptr { + #[inline] + fn zero_init() -> Self { + Ptr::null() + } +} + impl Clone for Ptr { #[inline] fn clone(&self) -> Self { diff --git a/libcc2rs/src/void.rs b/libcc2rs/src/void.rs index 014a5d1fb7..9b8d672467 100644 --- a/libcc2rs/src/void.rs +++ b/libcc2rs/src/void.rs @@ -105,6 +105,13 @@ impl Ptr { } } +impl crate::ZeroInitialization for AnyPtr { + #[inline] + fn zero_init() -> Self { + AnyPtr::default() + } +} + impl Default for AnyPtr { fn default() -> Self { Ptr::<()>::null().to_any() 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 0b08fcdd20..fba43bafdc 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 @@ -61,7 +61,7 @@ pub static mut static_char_5: std::cell::LazyCell = pub static mut static_pointer_6: std::cell::LazyCell<*mut i32> = std::cell::LazyCell::new(|| unsafe { std::ptr::null_mut() }); pub static mut static_enum_7: std::cell::LazyCell = - std::cell::LazyCell::new(|| unsafe { p6_1_zero_initialized_scalars_Color_red }); + std::cell::LazyCell::new(|| unsafe { 0_i32 }); pub static mut static_function_pointer_8: std::cell::LazyCell> = std::cell::LazyCell::new(|| unsafe { None }); pub static mut thread_local_long_9: std::cell::LazyCell = From dbf54138cfef43994404307005f6566e53b104b5 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sun, 29 Nov 2026 18:59:22 +0000 Subject: [PATCH 05/18] Update tests --- .../out/refcount/defaulted_move_cross_tu.rs | 48 ++- .../out/unsafe/defaulted_move_cross_tu.rs | 51 ++- .../refcount/out_of_line_methods_cross_tu.rs | 20 +- .../unsafe/out_of_line_methods_cross_tu.rs | 22 +- .../out/refcount/p14-class-in-two-files.rs | 35 +- .../out/unsafe/p14-class-in-two-files.rs | 36 +- .../p15-class-template-static-member.rs | 35 +- .../p15-class-template-static-member.rs | 36 +- .../out/refcount/p15-function-template.rs | 47 ++- .../out/unsafe/p15-function-template.rs | 48 ++- .../out/refcount/p15-inline-function.rs | 29 +- .../out/unsafe/p15-inline-function.rs | 30 +- .../out/refcount/p15-inline-variable.rs | 29 +- .../out/unsafe/p15-inline-variable.rs | 30 +- .../p16-default-argument-lambda-in-class.rs | 29 +- .../p16-default-argument-lambda-in-class.rs | 30 +- .../refcount/p16-lambda-in-inline-function.rs | 29 +- .../unsafe/p16-lambda-in-inline-function.rs | 30 +- .../out/refcount/basic.scope.block.rs | 60 ++- .../out/refcount/basic.scope.param.rs | 23 +- .../out/refcount/basic.scope.pdecl.rs | 33 +- .../out/unsafe/basic.scope.block.rs | 60 ++- .../out/unsafe/basic.scope.param.rs | 21 +- .../out/unsafe/basic.scope.pdecl.rs | 28 +- .../out/refcount/basic.start.term-p1-exit.rs | 23 +- .../out/refcount/basic.start.term.rs | 63 ++- .../out/unsafe/basic.start.term-p1-exit.rs | 23 +- .../out/unsafe/basic.start.term.rs | 62 ++- tests/std/basic/out/refcount/basic.def.odr.rs | 293 ++++++++++---- tests/std/basic/out/unsafe/basic.def.odr.rs | 273 ++++++++++--- .../out/refcount/class.conv.ctor.rs | 31 +- .../class.conv/out/unsafe/class.conv.ctor.rs | 28 +- .../out/refcount/class.copy.ctor.rs | 33 +- .../class.ctor/out/unsafe/class.copy.ctor.rs | 34 +- .../dcl.init/out/refcount/dcl.init.general.rs | 15 +- .../dcl.init/out/unsafe/dcl.init.general.rs | 15 +- .../out/refcount/dcl.fct.default.rs | 43 +- .../dcl.meaning/out/unsafe/dcl.fct.default.rs | 41 +- .../out/refcount/expr.mptr.oper.rs | 63 ++- .../out/unsafe/expr.mptr.oper.rs | 60 ++- .../stmt.iter/out/refcount/stmt.while.rs | 38 +- .../stmt.iter/out/unsafe/stmt.while.rs | 32 +- .../stmt.select/out/refcount/stmt.if.rs | 35 +- .../stmt.select/out/refcount/stmt.switch.rs | 29 +- .../stmt.select/out/unsafe/stmt.if.rs | 36 +- .../stmt.select/out/unsafe/stmt.switch.rs | 30 +- .../temp/temp.spec/out/refcount/temp.inst.rs | 10 +- .../temp/temp.spec/out/unsafe/temp.inst.rs | 15 +- .../utility/out/refcount/forward-helpers.rs | 209 ++++++---- .../utilities/utility/out/refcount/forward.rs | 42 +- .../utility/out/unsafe/forward-helpers.rs | 207 ++++++---- .../utilities/utility/out/unsafe/forward.rs | 36 +- tests/ub/out/refcount/ctor_ref_member.rs | 10 +- tests/ub/out/unsafe/ctor_ref_member.rs | 11 +- tests/unit/out/refcount/10_struct.rs | 10 +- tests/unit/out/refcount/any.rs | 21 +- .../out/refcount/array_of_noncopy_struct.rs | 6 +- tests/unit/out/refcount/cast.rs | 6 +- tests/unit/out/refcount/class_templates.rs | 18 +- tests/unit/out/refcount/constructor.rs | 48 ++- .../refcount/container_element_receiver.rs | 6 +- .../unit/out/refcount/container_field_addr.rs | 6 +- tests/unit/out/refcount/copy_assign.rs | 202 ++++++++-- tests/unit/out/refcount/copy_ctor.rs | 267 +++++++++---- .../unit/out/refcount/copy_move_defaulted.rs | 239 ++++++++--- tests/unit/out/refcount/copy_move_deleted.rs | 108 +++-- .../refcount/default_function_arguments.rs | 81 +++- tests/unit/out/refcount/destructor_params.rs | 12 +- .../out/refcount/field_method_receiver.rs | 6 +- tests/unit/out/refcount/field_pointers.rs | 6 +- tests/unit/out/refcount/fn_ptr.rs | 12 +- tests/unit/out/refcount/fn_ptr_struct.rs | 33 +- .../refcount/foreach_disjoint_field_borrow.rs | 6 +- tests/unit/out/refcount/forward_basic.rs | 107 +++-- tests/unit/out/refcount/forward_decltype.rs | 59 ++- tests/unit/out/refcount/forward_explicit.rs | 65 ++- tests/unit/out/refcount/forward_pack.rs | 95 +++-- .../out/refcount/global_init_side_effect.rs | 17 +- .../out/refcount/global_non_const_init.rs | 58 ++- tests/unit/out/refcount/huffman.rs | 6 +- tests/unit/out/refcount/implicit_autoref.rs | 6 +- .../refcount/in_class_field_initializer.rs | 10 +- .../out/refcount/inline_container_fields.rs | 36 +- tests/unit/out/refcount/kruskal.rs | 12 +- tests/unit/out/refcount/lambda_as_field.rs | 36 +- .../out/refcount/lambda_capture_copy_ctor.rs | 114 ++++-- .../out/refcount/lambda_move_only_capture.rs | 42 +- .../refcount/libc_struct_without_default.rs | 6 +- tests/unit/out/refcount/map.rs | 28 +- tests/unit/out/refcount/map_key_copy_ctor.rs | 54 ++- tests/unit/out/refcount/map_key_identity.rs | 13 +- tests/unit/out/refcount/map_try_emplace.rs | 134 +++++-- .../out/refcount/map_try_emplace_lvalues.rs | 375 ++++++++++++++---- tests/unit/out/refcount/max.rs | 21 +- tests/unit/out/refcount/move_assign.rs | 102 ++++- tests/unit/out/refcount/move_ctor.rs | 215 +++++++--- tests/unit/out/refcount/move_this.rs | 88 ++-- .../refcount/operator_comparison_nonbool.rs | 26 +- .../operator_comparison_noncopyable.rs | 28 +- .../refcount/pair_converting_construction.rs | 157 +++++--- tests/unit/out/refcount/push_emplace_back.rs | 149 +++++-- tests/unit/out/refcount/rule_of_five.rs | 58 ++- tests/unit/out/refcount/rule_of_three.rs | 44 +- .../unit/out/refcount/rvalue_rule_arg_move.rs | 40 +- tests/unit/out/refcount/rvalue_struct.rs | 10 +- .../out/refcount/size_t_template_param.rs | 30 +- tests/unit/out/refcount/sort_no_copy.rs | 183 +++++++-- tests/unit/out/refcount/stdcopy.rs | 14 +- tests/unit/out/refcount/struct_ctor.rs | 49 ++- .../unit/out/refcount/struct_default_ctor.rs | 18 +- .../refcount/structured_binding_copy_ctor.rs | 33 +- .../structured_binding_element_ctor.rs | 82 ++-- .../refcount/structured_binding_move_ctor.rs | 40 +- tests/unit/out/refcount/swap_map_no_copy.rs | 334 ++++++++++++---- .../unit/out/refcount/template_default_arg.rs | 118 +++++- .../unit/out/refcount/temporary_field_addr.rs | 18 +- .../out/refcount/temporary_field_ctor_arg.rs | 26 +- .../out/refcount/temporary_field_two_args.rs | 18 +- tests/unit/out/refcount/this.rs | 88 ++-- .../unit/out/refcount/typedef-anon-struct.rs | 6 +- tests/unit/out/refcount/unique_ptr.rs | 6 +- .../out/refcount/unique_ptr_const_deref.rs | 6 +- .../out/refcount/unique_ptr_field_reset.rs | 6 +- tests/unit/out/refcount/unique_ptr_nested.rs | 6 +- tests/unit/out/refcount/va_list_field.rs | 12 +- tests/unit/out/refcount/vector.rs | 6 +- .../out/refcount/vector_iter_range_ctor.rs | 4 +- .../out/refcount/vector_subscript_direct.rs | 6 +- tests/unit/out/refcount/void_cast.rs | 12 +- tests/unit/out/unsafe/10_struct.rs | 11 +- tests/unit/out/unsafe/any.rs | 17 +- .../out/unsafe/array_of_noncopy_struct.rs | 7 +- tests/unit/out/unsafe/cast.rs | 7 +- tests/unit/out/unsafe/class_templates.rs | 21 +- tests/unit/out/unsafe/constructor.rs | 54 ++- .../out/unsafe/container_element_receiver.rs | 7 +- tests/unit/out/unsafe/container_field_addr.rs | 7 +- tests/unit/out/unsafe/copy_assign.rs | 208 ++++++++-- tests/unit/out/unsafe/copy_ctor.rs | 283 +++++++++---- tests/unit/out/unsafe/copy_move_defaulted.rs | 238 +++++++---- tests/unit/out/unsafe/copy_move_deleted.rs | 109 +++-- .../out/unsafe/default_function_arguments.rs | 84 +++- tests/unit/out/unsafe/destructor_params.rs | 11 +- .../unit/out/unsafe/field_method_receiver.rs | 7 +- tests/unit/out/unsafe/field_pointers.rs | 7 +- tests/unit/out/unsafe/fn_ptr.rs | 12 +- tests/unit/out/unsafe/fn_ptr_struct.rs | 32 +- .../unsafe/foreach_disjoint_field_borrow.rs | 7 +- tests/unit/out/unsafe/forward_basic.rs | 114 ++++-- tests/unit/out/unsafe/forward_decltype.rs | 63 ++- tests/unit/out/unsafe/forward_explicit.rs | 67 +++- tests/unit/out/unsafe/forward_pack.rs | 101 +++-- .../out/unsafe/global_init_side_effect.rs | 21 +- .../unit/out/unsafe/global_non_const_init.rs | 78 +++- tests/unit/out/unsafe/huffman.rs | 7 +- tests/unit/out/unsafe/implicit_autoref.rs | 7 +- .../out/unsafe/in_class_field_initializer.rs | 11 +- .../out/unsafe/inline_container_fields.rs | 36 +- tests/unit/out/unsafe/kruskal.rs | 14 +- tests/unit/out/unsafe/lambda_as_field.rs | 33 +- .../out/unsafe/lambda_capture_copy_ctor.rs | 119 ++++-- .../out/unsafe/lambda_move_only_capture.rs | 42 +- .../out/unsafe/libc_struct_without_default.rs | 7 +- tests/unit/out/unsafe/map.rs | 30 +- tests/unit/out/unsafe/map_key_copy_ctor.rs | 55 ++- tests/unit/out/unsafe/map_key_identity.rs | 13 +- tests/unit/out/unsafe/map_try_emplace.rs | 136 +++++-- .../out/unsafe/map_try_emplace_lvalues.rs | 274 +++++++++---- tests/unit/out/unsafe/max.rs | 22 +- tests/unit/out/unsafe/move_assign.rs | 101 +++-- tests/unit/out/unsafe/move_ctor.rs | 225 ++++++++--- tests/unit/out/unsafe/move_this.rs | 88 ++-- .../out/unsafe/operator_comparison_nonbool.rs | 31 +- .../unsafe/operator_comparison_noncopyable.rs | 30 +- .../unsafe/pair_converting_construction.rs | 190 ++++++--- tests/unit/out/unsafe/push_emplace_back.rs | 130 ++++-- tests/unit/out/unsafe/rule_of_five.rs | 63 ++- tests/unit/out/unsafe/rule_of_three.rs | 48 ++- tests/unit/out/unsafe/rvalue_rule_arg_move.rs | 39 +- tests/unit/out/unsafe/rvalue_struct.rs | 11 +- .../unit/out/unsafe/size_t_template_param.rs | 31 +- tests/unit/out/unsafe/sort_no_copy.rs | 159 ++++++-- tests/unit/out/unsafe/stdcopy.rs | 14 +- tests/unit/out/unsafe/struct_ctor.rs | 53 ++- tests/unit/out/unsafe/struct_default_ctor.rs | 19 +- .../unsafe/structured_binding_copy_ctor.rs | 36 +- .../unsafe/structured_binding_element_ctor.rs | 87 ++-- .../unsafe/structured_binding_move_ctor.rs | 44 +- tests/unit/out/unsafe/swap_map_no_copy.rs | 329 +++++++++++---- tests/unit/out/unsafe/template_default_arg.rs | 122 ++++-- tests/unit/out/unsafe/temporary_field_addr.rs | 20 +- .../out/unsafe/temporary_field_ctor_arg.rs | 20 +- .../out/unsafe/temporary_field_two_args.rs | 20 +- tests/unit/out/unsafe/this.rs | 98 +++-- tests/unit/out/unsafe/typedef-anon-struct.rs | 7 +- tests/unit/out/unsafe/unique_ptr.rs | 7 +- .../unit/out/unsafe/unique_ptr_const_deref.rs | 7 +- .../unit/out/unsafe/unique_ptr_field_reset.rs | 7 +- tests/unit/out/unsafe/unique_ptr_nested.rs | 7 +- tests/unit/out/unsafe/va_list_field.rs | 13 +- tests/unit/out/unsafe/vector.rs | 7 +- .../unit/out/unsafe/vector_iter_range_ctor.rs | 5 +- .../out/unsafe/vector_subscript_direct.rs | 7 +- tests/unit/out/unsafe/void_cast.rs | 14 +- 204 files changed, 8246 insertions(+), 3326 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 8e99a88e15..0938d49f04 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 @@ -19,19 +19,19 @@ pub struct S { pub n: Box<[i32]>, } impl S { - pub fn new(mut x: i32) -> Self { - Self { + pub fn new(this: Ptr, mut x: i32) { + this.write(Self { v: vec![x; (x as usize)], n: Box::new([x, (x + 1)]), - } + }); } - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { v: field!(_a0, v).with_mut(std::mem::take), n: Box::new(std::array::from_fn::<_, 2, _>(|__i: usize| { (*_a0.upgrade().deref()).n[(__i) as usize] })), - } + }); } } impl Default for S { @@ -54,10 +54,10 @@ pub struct T { pub v: Vec, } impl T { - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { v: field!(_a0, v).with_mut(std::mem::take), - } + }); } } pub fn sum_0(s: Ptr) -> i32 { @@ -70,7 +70,11 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let s: Value = Rc::new(RefCell::new(S::new({ 2 }))); + let s: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + S::new(__v.as_pointer(), { 2 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!((({ sum_0(s.as_pointer(),) }) == 7)); assert!((({ shuffle_1(3,) }) == 10)); let t: Value = Rc::new(RefCell::new(T { @@ -80,14 +84,30 @@ fn main_0() -> i32 { return 0; } pub fn shuffle_1(mut x: i32) -> i32 { - let a: Value = Rc::new(RefCell::new(S::new({ x }))); - let b: Value = Rc::new(RefCell::new(S::move_from({ a.as_pointer() }))); + let a: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + S::new(__v.as_pointer(), { x }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let b: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + S::move_from(__v.as_pointer(), { a.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!(({ (*a.borrow()).v.is_empty() })); - let c: Value = Rc::new(RefCell::new(S::new({ 1 }))); + let c: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + S::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); ({ SImpl::move_assign(&c.as_pointer(), b.as_pointer()) }); assert!(({ (*b.borrow()).v.is_empty() })); let t: Value = Rc::new(RefCell::new(T { v: Vec::from([1]) })); - let u: Value = Rc::new(RefCell::new(T::move_from({ t.as_pointer() }))); + let u: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + T::move_from(__v.as_pointer(), { t.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let w: Value = Rc::new(RefCell::new(::default())); ({ TImpl::move_assign(&w.as_pointer(), u.as_pointer()) }); assert!( 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 f910a40800..1790921b2b 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 @@ -14,19 +14,17 @@ pub struct S { pub n: [i32; 2], } impl S { - pub unsafe fn new(mut x: i32) -> Self { - let mut this = Self { + pub unsafe fn new(this: *mut Self, mut x: i32) { + this.write(Self { v: vec![x; (x as usize)], n: [x, ((x) + (1))], - }; - this + }); } - pub unsafe fn move_from(_a0: *mut S) -> Self { - let mut this = Self { + pub unsafe fn move_from(this: *mut Self, _a0: *mut S) { + this.write(Self { v: std::mem::take(&mut (*_a0).v), n: std::array::from_fn::<_, 2, _>(|__i: usize| (*_a0).n[(__i)]), - }; - this + }); } pub unsafe fn move_assign(&mut self, _a0: *mut S) -> *mut S { { @@ -52,11 +50,10 @@ impl T { pub unsafe fn size(&self) -> i32 { return ((self.v.len()) as i32); } - pub unsafe fn move_from(_a0: *mut T) -> Self { - let mut this = Self { + pub unsafe fn move_from(this: *mut Self, _a0: *mut T) { + this.write(Self { v: std::mem::take(&mut (*_a0).v), - }; - this + }); } pub unsafe fn move_assign(&mut self, _a0: *mut T) -> *mut T { { @@ -75,7 +72,11 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut s: S = S::new({ 2 }); + let mut s: S = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + S::new(__v.as_mut_ptr(), { 2 }); + __v.assume_init() + }; assert!(((unsafe { sum_0(&s,) }) == (7))); assert!(((unsafe { shuffle_1(3,) }) == (10))); let mut t: T = T { @@ -85,14 +86,30 @@ unsafe fn main_0() -> i32 { return 0; } pub unsafe fn shuffle_1(mut x: i32) -> i32 { - let mut a: S = S::new({ x }); - let mut b: S = S::move_from({ &mut a }); + let mut a: S = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + S::new(__v.as_mut_ptr(), { x }); + __v.assume_init() + }; + let mut b: S = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + S::move_from(__v.as_mut_ptr(), { &mut a }); + __v.assume_init() + }; assert!(a.v.is_empty()); - let mut c: S = S::new({ 1 }); + let mut c: S = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + S::new(__v.as_mut_ptr(), { 1 }); + __v.assume_init() + }; (unsafe { S::move_assign(&mut c, &mut b) }); assert!(b.v.is_empty()); let mut t: T = T { v: Vec::from([1]) }; - let mut u: T = T::move_from({ &mut t }); + let mut u: T = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + T::move_from(__v.as_mut_ptr(), { &mut t }); + __v.assume_init() + }; let mut w: T = ::default(); (unsafe { T::move_assign(&mut w, &mut u) }); assert!( 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 3d37d8acd3..01c200d145 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 @@ -39,12 +39,20 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let s: Value = Rc::new(RefCell::new(S::new({ 1 }))); + let s: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + S::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); 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)); - let derived: Value = Rc::new(RefCell::new(Derived::new({ 3 }))); + let derived: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Derived::new(__v.as_pointer(), { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let mut base: PtrDyn = (derived.as_pointer()).to_dyn::(|w| w); assert!((({ (*base.upgrade().deref_mut()).apply(5,) }) == 15)); let pair: Value = Rc::new(RefCell::new(Pair { @@ -56,13 +64,13 @@ fn main_0() -> i32 { return 0; } impl S { - pub fn new(mut x: i32) -> Self { - Self { v: x } + pub fn new(this: Ptr, mut x: i32) { + this.write(Self { v: x }); } } impl Derived { - pub fn new(mut factor: i32) -> Self { - Self { factor: factor } + pub fn new(this: Ptr, mut factor: i32) { + this.write(Self { factor: factor }); } } impl S {} 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 6e78a3941e..7c1a87c7a6 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 @@ -41,12 +41,20 @@ pub fn main() { } } unsafe fn main_0() -> i32 { - let mut s: S = S::new({ 1 }); + let mut s: S = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + S::new(__v.as_mut_ptr(), { 1 }); + __v.assume_init() + }; 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))); - let mut derived: Derived = Derived::new({ 3 }); + let mut derived: Derived = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + Derived::new(__v.as_mut_ptr(), { 3 }); + __v.assume_init() + }; let mut base: *mut dyn Base = (&mut derived as *mut Derived); assert!(((unsafe { (*base).apply(5,) }) == (15))); let mut pair: Pair = Pair { @@ -58,15 +66,13 @@ unsafe fn main_0() -> i32 { return 0; } impl S { - pub unsafe fn new(mut x: i32) -> Self { - let mut this = Self { v: x }; - this + pub unsafe fn new(this: *mut Self, mut x: i32) { + this.write(Self { v: x }); } } impl Derived { - pub unsafe fn new(mut factor: i32) -> Self { - let mut this = Self { factor: factor }; - this + pub unsafe fn new(this: *mut Self, mut factor: i32) { + this.write(Self { factor: factor }); } } impl S {} 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 668fe631fa..4e4910045f 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 @@ -43,15 +43,13 @@ impl LifetimeTracked { } }); } - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; + pub fn new(this: Ptr) { + this.write(Self { uses: 0 }); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; + pub fn copy_from(this: Ptr, _a0: Ptr) { + this.write(Self { uses: 0 }); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Clone for LifetimeTracked { @@ -59,12 +57,21 @@ impl Clone for LifetimeTracked { let __src: Value = Rc::new(RefCell::new(LifetimeTracked { uses: self.uses.clone(), })); - LifetimeTracked::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } impl Default for LifetimeTracked { fn default() -> Self { - { LifetimeTracked::new() } + { + { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } #[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] @@ -84,7 +91,11 @@ thread_local!( ); thread_local!( pub static shared_5: Value = { - let __static = Rc::new(RefCell::new(LifetimeTracked::new())); + let __static = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); libcc2rs::register_static_destructor(|| { shared_5.with(Value::clone).as_pointer().destructor() }); @@ -101,7 +112,11 @@ impl HasInlineMembers { } thread_local!( static local_6: Value = { - let __static = Rc::new(RefCell::new(LifetimeTracked::new())); + let __static = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); libcc2rs::register_static_destructor(|| { local_6.with(Value::clone).as_pointer().destructor() }); diff --git a/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs b/tests/std/basic/basic.def.odr/p14-class-in-two-files/out/unsafe/p14-class-in-two-files.rs index 5309797a65..81578cdb3c 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 @@ -28,15 +28,13 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; + pub unsafe fn new(this: *mut Self) { + this.write(Self { uses: 0 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; + pub unsafe fn copy_from(this: *mut Self, _a0: *const LifetimeTracked) { + this.write(Self { uses: 0 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -52,12 +50,22 @@ impl LifetimeTracked { } impl Clone for LifetimeTracked { fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + unsafe { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::copy_from(__v.as_mut_ptr(), self as *const LifetimeTracked); + __v.assume_init() + } } } impl Default for LifetimeTracked { fn default() -> Self { - unsafe { LifetimeTracked::new() } + unsafe { + { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + } + } } } #[repr(C)] @@ -83,7 +91,11 @@ pub static mut check_4: std::cell::LazyCell = pub static mut shared_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let __static = LifetimeTracked::new(); + let __static = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5)).destructor() }); @@ -100,7 +112,11 @@ impl HasInlineMembers { } static mut local_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let __static = LifetimeTracked::new(); + let __static = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut local_6)).destructor() }); diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/refcount/p15-class-template-static-member.rs index a0f11971f3..096f41a71d 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 @@ -43,15 +43,13 @@ impl LifetimeTracked { } }); } - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; + pub fn new(this: Ptr) { + this.write(Self { uses: 0 }); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; + pub fn copy_from(this: Ptr, _a0: Ptr) { + this.write(Self { uses: 0 }); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Clone for LifetimeTracked { @@ -59,17 +57,30 @@ impl Clone for LifetimeTracked { let __src: Value = Rc::new(RefCell::new(LifetimeTracked { uses: self.uses.clone(), })); - LifetimeTracked::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } impl Default for LifetimeTracked { fn default() -> Self { - { LifetimeTracked::new() } + { + { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } thread_local!( pub static member_4: Value = { - let __static = Rc::new(RefCell::new(LifetimeTracked::new())); + let __static = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); libcc2rs::register_static_destructor(|| { member_4.with(Value::clone).as_pointer().destructor() }); @@ -81,7 +92,11 @@ thread_local!( pub struct HasStaticMember_int_ {} thread_local!( pub static member_5: Value = { - let __static = Rc::new(RefCell::new(LifetimeTracked::new())); + let __static = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); libcc2rs::register_static_destructor(|| { member_5.with(Value::clone).as_pointer().destructor() }); diff --git a/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs b/tests/std/basic/basic.def.odr/p15-class-template-static-member/out/unsafe/p15-class-template-static-member.rs index f366dd2b83..2d8965dff8 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 @@ -28,15 +28,13 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; + pub unsafe fn new(this: *mut Self) { + this.write(Self { uses: 0 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; + pub unsafe fn copy_from(this: *mut Self, _a0: *const LifetimeTracked) { + this.write(Self { uses: 0 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -52,18 +50,32 @@ impl LifetimeTracked { } impl Clone for LifetimeTracked { fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + unsafe { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::copy_from(__v.as_mut_ptr(), self as *const LifetimeTracked); + __v.assume_init() + } } } impl Default for LifetimeTracked { fn default() -> Self { - unsafe { LifetimeTracked::new() } + unsafe { + { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + } + } } } pub static mut member_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let __static = LifetimeTracked::new(); + let __static = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut member_4)).destructor() }); @@ -76,7 +88,11 @@ pub struct HasStaticMember_int_ {} pub static mut member_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let __static = LifetimeTracked::new(); + let __static = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut member_5)).destructor() }); diff --git a/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs b/tests/std/basic/basic.def.odr/p15-function-template/out/refcount/p15-function-template.rs index 4d567cb70d..a5de623eac 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 @@ -43,15 +43,13 @@ impl LifetimeTracked { } }); } - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; + pub fn new(this: Ptr) { + this.write(Self { uses: 0 }); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; + pub fn copy_from(this: Ptr, _a0: Ptr) { + this.write(Self { uses: 0 }); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Clone for LifetimeTracked { @@ -59,12 +57,21 @@ impl Clone for LifetimeTracked { let __src: Value = Rc::new(RefCell::new(LifetimeTracked { uses: self.uses.clone(), })); - LifetimeTracked::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } impl Default for LifetimeTracked { fn default() -> Self { - { LifetimeTracked::new() } + { + { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } #[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] @@ -84,7 +91,11 @@ pub fn count_10() -> i32 { } thread_local!( static t_5: Value = { - let __static = Rc::new(RefCell::new(LifetimeTracked::new())); + let __static = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); libcc2rs::register_static_destructor(|| t_5.with(Value::clone).as_pointer().destructor()); __static }; @@ -94,7 +105,11 @@ thread_local!( ); thread_local!( static t_8: Value = { - let __static = Rc::new(RefCell::new(LifetimeTracked::new())); + let __static = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); libcc2rs::register_static_destructor(|| t_8.with(Value::clone).as_pointer().destructor()); __static }; @@ -104,7 +119,11 @@ thread_local!( ); thread_local!( static t_11: Value = { - let __static = Rc::new(RefCell::new(LifetimeTracked::new())); + let __static = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); libcc2rs::register_static_destructor(|| t_11.with(Value::clone).as_pointer().destructor()); __static }; @@ -147,7 +166,11 @@ pub fn count_18() -> i32 { } thread_local!( static t_19: Value = { - let __static = Rc::new(RefCell::new(LifetimeTracked::new())); + let __static = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); libcc2rs::register_static_destructor(|| t_19.with(Value::clone).as_pointer().destructor()); __static }; 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 e822da1ad5..7c9cb60297 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 @@ -28,15 +28,13 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; + pub unsafe fn new(this: *mut Self) { + this.write(Self { uses: 0 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; + pub unsafe fn copy_from(this: *mut Self, _a0: *const LifetimeTracked) { + this.write(Self { uses: 0 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -52,12 +50,22 @@ impl LifetimeTracked { } impl Clone for LifetimeTracked { fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + unsafe { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::copy_from(__v.as_mut_ptr(), self as *const LifetimeTracked); + __v.assume_init() + } } } impl Default for LifetimeTracked { fn default() -> Self { - unsafe { LifetimeTracked::new() } + unsafe { + { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + } + } } } #[repr(C)] @@ -81,7 +89,11 @@ pub unsafe fn count_10() -> i32 { } static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let __static = LifetimeTracked::new(); + let __static = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut t_5)).destructor() }); @@ -91,7 +103,11 @@ static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new( static mut n_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); static mut t_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let __static = LifetimeTracked::new(); + let __static = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut t_8)).destructor() }); @@ -101,7 +117,11 @@ static mut t_8: std::cell::LazyCell = std::cell::LazyCell::new( static mut n_9: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); static mut t_11: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let __static = LifetimeTracked::new(); + let __static = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut t_11)).destructor() }); @@ -147,7 +167,11 @@ pub unsafe fn count_18() -> i32 { } static mut t_19: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let __static = LifetimeTracked::new(); + let __static = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut t_19)).destructor() }); diff --git a/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs b/tests/std/basic/basic.def.odr/p15-inline-function/out/refcount/p15-inline-function.rs index b006b15296..710b5484cc 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 @@ -43,15 +43,13 @@ impl LifetimeTracked { } }); } - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; + pub fn new(this: Ptr) { + this.write(Self { uses: 0 }); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; + pub fn copy_from(this: Ptr, _a0: Ptr) { + this.write(Self { uses: 0 }); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Clone for LifetimeTracked { @@ -59,12 +57,21 @@ impl Clone for LifetimeTracked { let __src: Value = Rc::new(RefCell::new(LifetimeTracked { uses: self.uses.clone(), })); - LifetimeTracked::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } impl Default for LifetimeTracked { fn default() -> Self { - { LifetimeTracked::new() } + { + { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } #[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] @@ -78,7 +85,11 @@ pub fn instance_4() -> Ptr { } thread_local!( static t_5: Value = { - let __static = Rc::new(RefCell::new(LifetimeTracked::new())); + let __static = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); libcc2rs::register_static_destructor(|| t_5.with(Value::clone).as_pointer().destructor()); __static }; 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 d71518db48..6075b2823f 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 @@ -28,15 +28,13 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; + pub unsafe fn new(this: *mut Self) { + this.write(Self { uses: 0 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; + pub unsafe fn copy_from(this: *mut Self, _a0: *const LifetimeTracked) { + this.write(Self { uses: 0 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -52,12 +50,22 @@ impl LifetimeTracked { } impl Clone for LifetimeTracked { fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + unsafe { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::copy_from(__v.as_mut_ptr(), self as *const LifetimeTracked); + __v.assume_init() + } } } impl Default for LifetimeTracked { fn default() -> Self { - unsafe { LifetimeTracked::new() } + unsafe { + { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + } + } } } #[repr(C)] @@ -75,7 +83,11 @@ pub unsafe fn instance_4() -> *mut LifetimeTracked { } static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let __static = LifetimeTracked::new(); + let __static = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut t_5)).destructor() }); diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/refcount/p15-inline-variable.rs index 4afe7c452a..956420e6f5 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 @@ -43,15 +43,13 @@ impl LifetimeTracked { } }); } - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; + pub fn new(this: Ptr) { + this.write(Self { uses: 0 }); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; + pub fn copy_from(this: Ptr, _a0: Ptr) { + this.write(Self { uses: 0 }); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Clone for LifetimeTracked { @@ -59,12 +57,21 @@ impl Clone for LifetimeTracked { let __src: Value = Rc::new(RefCell::new(LifetimeTracked { uses: self.uses.clone(), })); - LifetimeTracked::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } impl Default for LifetimeTracked { fn default() -> Self { - { LifetimeTracked::new() } + { + { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } #[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] @@ -84,7 +91,11 @@ thread_local!( ); thread_local!( pub static shared_5: Value = { - let __static = Rc::new(RefCell::new(LifetimeTracked::new())); + let __static = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); libcc2rs::register_static_destructor(|| { shared_5.with(Value::clone).as_pointer().destructor() }); diff --git a/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs b/tests/std/basic/basic.def.odr/p15-inline-variable/out/unsafe/p15-inline-variable.rs index c7006c1478..268be94cc1 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 @@ -28,15 +28,13 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; + pub unsafe fn new(this: *mut Self) { + this.write(Self { uses: 0 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; + pub unsafe fn copy_from(this: *mut Self, _a0: *const LifetimeTracked) { + this.write(Self { uses: 0 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -52,12 +50,22 @@ impl LifetimeTracked { } impl Clone for LifetimeTracked { fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + unsafe { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::copy_from(__v.as_mut_ptr(), self as *const LifetimeTracked); + __v.assume_init() + } } } impl Default for LifetimeTracked { fn default() -> Self { - unsafe { LifetimeTracked::new() } + unsafe { + { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + } + } } } #[repr(C)] @@ -83,7 +91,11 @@ pub static mut check_4: std::cell::LazyCell = pub static mut shared_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let __static = LifetimeTracked::new(); + let __static = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5)).destructor() }); diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/refcount/p16-default-argument-lambda-in-class.rs index 3a717d7f1d..b39a038b28 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 @@ -43,15 +43,13 @@ impl LifetimeTracked { } }); } - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; + pub fn new(this: Ptr) { + this.write(Self { uses: 0 }); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; + pub fn copy_from(this: Ptr, _a0: Ptr) { + this.write(Self { uses: 0 }); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Clone for LifetimeTracked { @@ -59,12 +57,21 @@ impl Clone for LifetimeTracked { let __src: Value = Rc::new(RefCell::new(LifetimeTracked { uses: self.uses.clone(), })); - LifetimeTracked::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } impl Default for LifetimeTracked { fn default() -> Self { - { LifetimeTracked::new() } + { + { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } #[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] @@ -78,7 +85,11 @@ pub struct AssertsDtorCountAtExit { pub struct X {} thread_local!( static local_4: Value = { - let __static = Rc::new(RefCell::new(LifetimeTracked::new())); + let __static = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); libcc2rs::register_static_destructor(|| { local_4.with(Value::clone).as_pointer().destructor() }); diff --git a/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs b/tests/std/basic/basic.def.odr/p16-default-argument-lambda-in-class/out/unsafe/p16-default-argument-lambda-in-class.rs index ad5d698cef..041c5269db 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 @@ -28,15 +28,13 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; + pub unsafe fn new(this: *mut Self) { + this.write(Self { uses: 0 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; + pub unsafe fn copy_from(this: *mut Self, _a0: *const LifetimeTracked) { + this.write(Self { uses: 0 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -52,12 +50,22 @@ impl LifetimeTracked { } impl Clone for LifetimeTracked { fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + unsafe { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::copy_from(__v.as_mut_ptr(), self as *const LifetimeTracked); + __v.assume_init() + } } } impl Default for LifetimeTracked { fn default() -> Self { - unsafe { LifetimeTracked::new() } + unsafe { + { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + } + } } } #[repr(C)] @@ -96,7 +104,11 @@ impl X { } static mut local_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let __static = LifetimeTracked::new(); + let __static = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut local_4)).destructor() }); diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/refcount/p16-lambda-in-inline-function.rs index 604938b021..0837c4bb5b 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 @@ -43,15 +43,13 @@ impl LifetimeTracked { } }); } - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; + pub fn new(this: Ptr) { + this.write(Self { uses: 0 }); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; + pub fn copy_from(this: Ptr, _a0: Ptr) { + this.write(Self { uses: 0 }); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Clone for LifetimeTracked { @@ -59,12 +57,21 @@ impl Clone for LifetimeTracked { let __src: Value = Rc::new(RefCell::new(LifetimeTracked { uses: self.uses.clone(), })); - LifetimeTracked::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } impl Default for LifetimeTracked { fn default() -> Self { - { LifetimeTracked::new() } + { + { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } #[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] @@ -89,7 +96,11 @@ pub fn f_4(mut cond: bool, mut p: FnPtr) { } thread_local!( static local_5: Value = { - let __static = Rc::new(RefCell::new(LifetimeTracked::new())); + let __static = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); libcc2rs::register_static_destructor(|| { local_5.with(Value::clone).as_pointer().destructor() }); diff --git a/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs b/tests/std/basic/basic.def.odr/p16-lambda-in-inline-function/out/unsafe/p16-lambda-in-inline-function.rs index fe1766c880..2668df5c05 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 @@ -28,15 +28,13 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; + pub unsafe fn new(this: *mut Self) { + this.write(Self { uses: 0 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; + pub unsafe fn copy_from(this: *mut Self, _a0: *const LifetimeTracked) { + this.write(Self { uses: 0 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -52,12 +50,22 @@ impl LifetimeTracked { } impl Clone for LifetimeTracked { fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + unsafe { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::copy_from(__v.as_mut_ptr(), self as *const LifetimeTracked); + __v.assume_init() + } } } impl Default for LifetimeTracked { fn default() -> Self { - unsafe { LifetimeTracked::new() } + unsafe { + { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + } + } } } #[repr(C)] @@ -90,7 +98,11 @@ pub unsafe fn f_4(mut cond: bool, mut p: Option) { } static mut local_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let __static = LifetimeTracked::new(); + let __static = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut local_5)).destructor() }); diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.block.rs index 2265d0824a..7685d59703 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 @@ -43,15 +43,13 @@ impl LifetimeTracked { } }); } - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; + pub fn new(this: Ptr) { + this.write(Self { uses: 0 }); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; + pub fn copy_from(this: Ptr, _a0: Ptr) { + this.write(Self { uses: 0 }); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Clone for LifetimeTracked { @@ -59,12 +57,21 @@ impl Clone for LifetimeTracked { let __src: Value = Rc::new(RefCell::new(LifetimeTracked { uses: self.uses.clone(), })); - LifetimeTracked::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } impl Default for LifetimeTracked { fn default() -> Self { - { LifetimeTracked::new() } + { + { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } thread_local!( @@ -146,7 +153,11 @@ pub fn test_8() { } pub fn test_9() { ({ LifetimeTracked::reset() }); - let scoped: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + let scoped: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_scoped = std::mem::DropGuard::new(scoped.clone(), |__p| __p.as_pointer().destructor()); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); @@ -154,7 +165,12 @@ pub fn test_9() { let mut index: i32 = 0; 'loop_: while (index < 3) { 'for_body: { - let scoped: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + let scoped: Value = Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_scoped = std::mem::DropGuard::new(scoped.clone(), |__p| __p.as_pointer().destructor()); } @@ -164,7 +180,11 @@ pub fn test_9() { assert!((ctorCount_0.with(|rc| *rc.borrow()) == 4)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 3)); if (ctorCount_0.with(|rc| *rc.borrow()) == 4) { - let scoped: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + let scoped: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_scoped = std::mem::DropGuard::new(scoped.clone(), |__p| __p.as_pointer().destructor()); } @@ -172,7 +192,11 @@ pub fn test_9() { assert!((dtorCount_2.with(|rc| *rc.borrow()) == 4)); if (ctorCount_0.with(|rc| *rc.borrow()) == 0) { } else { - let scoped: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + let scoped: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_scoped = std::mem::DropGuard::new(scoped.clone(), |__p| __p.as_pointer().destructor()); } @@ -203,11 +227,19 @@ pub fn test_10() { } pub fn test_11() { ({ LifetimeTracked::reset() }); - let tracked: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + let tracked: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_tracked = std::mem::DropGuard::new(tracked.clone(), |__p| __p.as_pointer().destructor()); { - let tracked: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + let tracked: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_tracked = std::mem::DropGuard::new(tracked.clone(), |__p| __p.as_pointer().destructor()); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2)); 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 3b3a3849d2..4a66cdf41d 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 @@ -14,24 +14,25 @@ pub struct p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParamete pub amount: i32, } impl p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter { - pub fn new(mut amount: i32) -> Self { - let __this: Value = - Rc::new(RefCell::new(Self { - amount: (amount + 1), - })); - let this: Ptr = - __this.as_pointer(); + pub fn new(this: Ptr, mut amount: i32) { + this.write(Self { + amount: (amount + 1), + }); amount += 10; assert!((amount == 14)); assert!((this.with(|__s| __s.amount) == 5)); - Rc::try_unwrap(__this).ok().unwrap().into_inner() } } pub fn test_0() { let object: Value = - Rc::new(RefCell::new( - p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter::new({ 4 }), - )); + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter::new( + __v.as_pointer(), + { 4 }, + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!(({ ({ (*object.borrow()).amount } == 5) })); assert!( (({ diff --git a/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs b/tests/std/basic/basic.scope/out/refcount/basic.scope.pdecl.rs index fced9b524c..014ef64b81 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 @@ -81,23 +81,28 @@ pub struct p9_func_declared_before_function_body_RecordsConstructorName { pub name: Ptr, } impl p9_func_declared_before_function_body_RecordsConstructorName { - pub fn new() -> Self { - let __this: Value = - Rc::new(RefCell::new(Self { - name: Ptr::::from_string_literal(b"RecordsConstructorName"), - })); - let this: Ptr = - __this.as_pointer(); + pub fn new(this: Ptr) { + this.write(Self { + name: Ptr::::from_string_literal(b"RecordsConstructorName"), + }); assert!( (this.with(|__s| __s.name.clone()) == Ptr::::from_string_literal(b"RecordsConstructorName")) ); - Rc::try_unwrap(__this).ok().unwrap().into_inner() } } impl Default for p9_func_declared_before_function_body_RecordsConstructorName { fn default() -> Self { - { p9_func_declared_before_function_body_RecordsConstructorName::new() } + { + { + let __v: Value = + Rc::new(RefCell::new( + ::zero_init(), + )); + p9_func_declared_before_function_body_RecordsConstructorName::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } pub fn plain_function_5() -> Ptr { @@ -122,8 +127,14 @@ pub fn test_6() { } == 0) ); assert!((({ plain_function_5() }) == ({ plain_function_5() }))); - let mut object: p9_func_declared_before_function_body_RecordsConstructorName = - p9_func_declared_before_function_body_RecordsConstructorName::new(); + let mut object: p9_func_declared_before_function_body_RecordsConstructorName = { + let __v: Value = + Rc::new(RefCell::new( + ::zero_init(), + )); + p9_func_declared_before_function_body_RecordsConstructorName::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!( ({ let mut __it1 = object.name.to_c_string_iterator(); 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 cfaf288d6e..4a3a15e7f9 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 @@ -28,15 +28,13 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; + pub unsafe fn new(this: *mut Self) { + this.write(Self { uses: 0 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; + pub unsafe fn copy_from(this: *mut Self, _a0: *const LifetimeTracked) { + this.write(Self { uses: 0 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -52,12 +50,22 @@ impl LifetimeTracked { } impl Clone for LifetimeTracked { fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + unsafe { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::copy_from(__v.as_mut_ptr(), self as *const LifetimeTracked); + __v.assume_init() + } } } impl Default for LifetimeTracked { fn default() -> Self { - unsafe { LifetimeTracked::new() } + unsafe { + { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + } + } } } pub static mut then_runs_4: std::cell::LazyCell = @@ -134,7 +142,11 @@ pub unsafe fn test_8() { } pub unsafe fn test_9() { (unsafe { LifetimeTracked::reset() }); - let mut scoped: LifetimeTracked = LifetimeTracked::new(); + let mut scoped: LifetimeTracked = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; let _dtor_scoped = std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { (*__p).destructor() }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); @@ -142,7 +154,11 @@ pub unsafe fn test_9() { let mut index: i32 = 0; 'loop_: while ((index) < (3)) { 'for_body: { - let mut scoped: LifetimeTracked = LifetimeTracked::new(); + let mut scoped: LifetimeTracked = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; let _dtor_scoped = std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { (*__p).destructor() }); } @@ -152,7 +168,11 @@ pub unsafe fn test_9() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (4))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (3))); if ((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (4)) { - let mut scoped: LifetimeTracked = LifetimeTracked::new(); + let mut scoped: LifetimeTracked = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; let _dtor_scoped = std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { (*__p).destructor() }); } @@ -160,7 +180,11 @@ pub unsafe fn test_9() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (4))); if ((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0)) { } else { - let mut scoped: LifetimeTracked = LifetimeTracked::new(); + let mut scoped: LifetimeTracked = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; let _dtor_scoped = std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { (*__p).destructor() }); } @@ -187,11 +211,19 @@ pub unsafe fn test_10() { } pub unsafe fn test_11() { (unsafe { LifetimeTracked::reset() }); - let mut tracked: LifetimeTracked = LifetimeTracked::new(); + let mut tracked: LifetimeTracked = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; let _dtor_tracked = std::mem::DropGuard::new(&raw mut tracked, |__p| unsafe { (*__p).destructor() }); { - let mut tracked: LifetimeTracked = LifetimeTracked::new(); + let mut tracked: LifetimeTracked = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; let _dtor_tracked = std::mem::DropGuard::new(&raw mut tracked, |__p| unsafe { (*__p).destructor() }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2))); 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 d7efc2d115..1c70881a41 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 @@ -13,22 +13,29 @@ 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 new(mut amount: i32) -> Self { - let mut this = Self { + pub unsafe fn new(this: *mut Self, mut amount: i32) { + this.write(Self { amount: ((amount) + (1)), - }; + }); amount += 10; assert!(((amount) == (14))); - assert!(((this.amount) == (5))); - this + assert!((((*this).amount) == (5))); } pub unsafe fn add(&self, mut amount: i32) -> i32 { return ((self.amount) + (amount)); } } pub unsafe fn test_0() { - let mut object: p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter = - p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter::new({ 4 }); + let mut object: p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter = { + let mut __v = ::std::mem::MaybeUninit::< + p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter, + >::uninit(); + p1_1_parameter_hides_member_in_constructor_HasMemberNamedLikeParameter::new( + __v.as_mut_ptr(), + { 4 }, + ); + __v.assume_init() + }; assert!(((object.amount) == (5))); assert!( ((unsafe { 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 3d10a2c1f5..dc43f62861 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 @@ -77,17 +77,24 @@ pub struct p9_func_declared_before_function_body_RecordsConstructorName { pub name: *const libc::c_char, } impl p9_func_declared_before_function_body_RecordsConstructorName { - pub unsafe fn new() -> Self { - let mut this = Self { + pub unsafe fn new(this: *mut Self) { + this.write(Self { name: c"RecordsConstructorName".as_ptr(), - }; - assert!(((this.name) == (c"RecordsConstructorName".as_ptr()))); - this + }); + assert!((((*this).name) == (c"RecordsConstructorName".as_ptr()))); } } impl Default for p9_func_declared_before_function_body_RecordsConstructorName { fn default() -> Self { - unsafe { p9_func_declared_before_function_body_RecordsConstructorName::new() } + unsafe { + { + let mut __v = ::std::mem::MaybeUninit::< + p9_func_declared_before_function_body_RecordsConstructorName, + >::uninit(); + p9_func_declared_before_function_body_RecordsConstructorName::new(__v.as_mut_ptr()); + __v.assume_init() + } + } } } pub unsafe fn plain_function_5() -> *const libc::c_char { @@ -96,8 +103,13 @@ pub unsafe fn plain_function_5() -> *const libc::c_char { pub unsafe fn test_6() { assert!(((libc::strcmp((unsafe { plain_function_5() }), c"plain_function".as_ptr())) == (0))); assert!(((unsafe { plain_function_5() }) == (unsafe { plain_function_5() }))); - let mut object: p9_func_declared_before_function_body_RecordsConstructorName = - p9_func_declared_before_function_body_RecordsConstructorName::new(); + let mut object: p9_func_declared_before_function_body_RecordsConstructorName = { + let mut __v = ::std::mem::MaybeUninit::< + p9_func_declared_before_function_body_RecordsConstructorName, + >::uninit(); + p9_func_declared_before_function_body_RecordsConstructorName::new(__v.as_mut_ptr()); + __v.assume_init() + }; assert!(((libc::strcmp(object.name, c"RecordsConstructorName".as_ptr())) == (0))); let mut enclosing: *const libc::c_char = c"test".as_ptr(); let mut lambda: FnPtr *const libc::c_char> = 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 49ea73f73e..e807bae782 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 @@ -13,15 +13,18 @@ pub struct Tracker { pub tag: i32, } impl Tracker { - pub fn new(mut tag: i32) -> Self { - let __this: Tracker = Self { tag: tag }; + pub fn new(this: Ptr, mut tag: i32) { + this.write(Self { tag: tag }); printf!(b"construct %d\n", tag); - __this } } thread_local!( pub static global_0: Value = { - let __static = Rc::new(RefCell::new(Tracker::new({ 1 }))); + let __static = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracker::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); libcc2rs::register_static_destructor(|| { global_0.with(Value::clone).as_pointer().destructor() }); @@ -32,14 +35,22 @@ pub fn exit_from_nested_call_1() { printf!(b"local static %d\n", { (*local_static_2.with(Value::clone).borrow()).tag }); - let automatic: Value = Rc::new(RefCell::new(Tracker::new({ 3 }))); + let automatic: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracker::new(__v.as_pointer(), { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_automatic = std::mem::DropGuard::new(automatic.clone(), |__p| __p.as_pointer().destructor()); libcc2rs::cpp2rust_exit(0); } thread_local!( static local_static_2: Value = { - let __static = Rc::new(RefCell::new(Tracker::new({ 2 }))); + let __static = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracker::new(__v.as_pointer(), { 2 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); libcc2rs::register_static_destructor(|| { local_static_2.with(Value::clone).as_pointer().destructor() }); diff --git a/tests/std/basic/basic.start/out/refcount/basic.start.term.rs b/tests/std/basic/basic.start/out/refcount/basic.start.term.rs index e02f70ba85..1e09ca0c8a 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 @@ -13,10 +13,9 @@ pub struct Tracker { pub tag: i32, } impl Tracker { - pub fn new(mut tag: i32) -> Self { - let __this: Tracker = Self { tag: tag }; + pub fn new(this: Ptr, mut tag: i32) { + this.write(Self { tag: tag }); printf!(b"construct %d\n", tag); - __this } } #[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Destructor, Default)] @@ -34,7 +33,11 @@ pub struct TriviallyDestructible { } thread_local!( pub static global_0: Value = { - let __static = Rc::new(RefCell::new(Tracker::new({ 1 }))); + let __static = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracker::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); libcc2rs::register_static_destructor(|| { global_0.with(Value::clone).as_pointer().destructor() }); @@ -49,7 +52,11 @@ pub fn test_3() { } thread_local!( static never_constructed_2: Value = { - let __static = Rc::new(RefCell::new(Tracker::new({ 100 }))); + let __static = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracker::new(__v.as_pointer(), { 100 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); libcc2rs::register_static_destructor(|| { never_constructed_2 .with(Value::clone) @@ -64,7 +71,11 @@ pub fn local_static_during_global_init_4() -> Ptr { } thread_local!( pub static before_6: Value = { - let __static = Rc::new(RefCell::new(Tracker::new({ 2 }))); + let __static = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracker::new(__v.as_pointer(), { 2 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); libcc2rs::register_static_destructor(|| { before_6.with(Value::clone).as_pointer().destructor() }); @@ -73,9 +84,13 @@ thread_local!( ); thread_local!( pub static after_7: Value = { - let __static = Rc::new(RefCell::new(Tracker::new({ - (({ local_static_during_global_init_4() }).with(|__s| __s.tag) + 1) - }))); + let __static = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracker::new(__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(|| { after_7.with(Value::clone).as_pointer().destructor() }); @@ -85,7 +100,11 @@ thread_local!( thread_local!( pub static holder_8: Value = { let __static = Rc::new(RefCell::new(HoldsTracker { - member: Tracker::new({ 5 }), + member: { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracker::new(__v.as_pointer(), { 5 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, })); libcc2rs::register_static_destructor(|| { holder_8.with(Value::clone).as_pointer().destructor() @@ -102,7 +121,11 @@ thread_local!( pub struct p3_reverse_completion_order_WithStaticMember {} thread_local!( pub static member_10: Value = { - let __static = Rc::new(RefCell::new(Tracker::new({ 7 }))); + let __static = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracker::new(__v.as_pointer(), { 7 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); libcc2rs::register_static_destructor(|| { member_10.with(Value::clone).as_pointer().destructor() }); @@ -113,7 +136,11 @@ thread_local!( pub static capturing_11: Value i32>> = { let __static = Rc::new(RefCell::new(lambda!( { - let captured: Value = Rc::new(RefCell::new(Tracker::new({ 8 }))); + let captured: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracker::new(__v.as_pointer(), { 8 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); }, || -> i32 { return { (*captured.borrow()).tag }; @@ -144,7 +171,11 @@ pub fn test_14() { } thread_local!( static during_init_5: Value = { - let __static = Rc::new(RefCell::new(Tracker::new({ 3 }))); + let __static = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracker::new(__v.as_pointer(), { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); libcc2rs::register_static_destructor(|| { during_init_5.with(Value::clone).as_pointer().destructor() }); @@ -153,7 +184,11 @@ thread_local!( ); thread_local!( static during_main_13: Value = { - let __static = Rc::new(RefCell::new(Tracker::new({ 9 }))); + let __static = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracker::new(__v.as_pointer(), { 9 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); libcc2rs::register_static_destructor(|| { during_main_13.with(Value::clone).as_pointer().destructor() }); diff --git a/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs b/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs index 6b7fe95719..b8747ded8f 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 @@ -12,10 +12,9 @@ pub struct Tracker { pub tag: i32, } impl Tracker { - pub unsafe fn new(mut tag: i32) -> Self { - let mut this = Self { tag: tag }; + pub unsafe fn new(this: *mut Self, mut tag: i32) { + this.write(Self { tag: tag }); (unsafe { libc::printf(c"construct %d\n".as_ptr() as *const libc::c_char, (tag)) }); - this } pub unsafe fn destructor(&mut self) { (unsafe { libc::printf(c"destroy %d\n".as_ptr() as *const libc::c_char, (self.tag)) }); @@ -23,7 +22,11 @@ impl Tracker { } pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let __static = Tracker::new({ 1 }); + let __static = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + Tracker::new(__v.as_mut_ptr(), { 1 }); + __v.assume_init() + }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)).destructor() }); @@ -37,14 +40,22 @@ pub unsafe fn exit_from_nested_call_1() { ((*std::cell::LazyCell::force_mut(&mut *&raw mut local_static_2)).tag), ) }); - let mut automatic: Tracker = Tracker::new({ 3 }); + let mut automatic: Tracker = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + Tracker::new(__v.as_mut_ptr(), { 3 }); + __v.assume_init() + }; let _dtor_automatic = std::mem::DropGuard::new(&raw mut automatic, |__p| unsafe { (*__p).destructor() }); libcc2rs::cpp2rust_exit(0); } static mut local_static_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let __static = Tracker::new({ 2 }); + let __static = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + Tracker::new(__v.as_mut_ptr(), { 2 }); + __v.assume_init() + }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut local_static_2)).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 e39d136a78..6deed86ea7 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 @@ -12,10 +12,9 @@ pub struct Tracker { pub tag: i32, } impl Tracker { - pub unsafe fn new(mut tag: i32) -> Self { - let mut this = Self { tag: tag }; + pub unsafe fn new(this: *mut Self, mut tag: i32) { + this.write(Self { tag: tag }); (unsafe { libc::printf(c"construct %d\n".as_ptr() as *const libc::c_char, (tag)) }); - this } pub unsafe fn destructor(&mut self) { (unsafe { libc::printf(c"destroy %d\n".as_ptr() as *const libc::c_char, (self.tag)) }); @@ -41,7 +40,11 @@ pub struct TriviallyDestructible { } pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let __static = Tracker::new({ 1 }); + let __static = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + Tracker::new(__v.as_mut_ptr(), { 1 }); + __v.assume_init() + }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)).destructor() }); @@ -59,7 +62,11 @@ pub unsafe fn test_3() { static mut never_constructed_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let __static = Tracker::new({ 100 }); + let __static = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + Tracker::new(__v.as_mut_ptr(), { 100 }); + __v.assume_init() + }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut never_constructed_2)).destructor() }); @@ -71,7 +78,11 @@ pub unsafe fn local_static_during_global_init_4() -> *const Tracker { } pub static mut before_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let __static = Tracker::new({ 2 }); + let __static = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + Tracker::new(__v.as_mut_ptr(), { 2 }); + __v.assume_init() + }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut before_6)).destructor() }); @@ -80,8 +91,13 @@ pub static mut before_6: std::cell::LazyCell = std::cell::LazyCell::new }); pub static mut after_7: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let __static = - Tracker::new({ (((*(unsafe { local_static_during_global_init_4() })).tag) + (1)) }); + let __static = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + Tracker::new(__v.as_mut_ptr(), { + (((*(unsafe { local_static_during_global_init_4() })).tag) + (1)) + }); + __v.assume_init() + }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut after_7)).destructor() }); @@ -91,7 +107,11 @@ pub static mut after_7: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut holder_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = HoldsTracker { - member: Tracker::new({ 5 }), + member: { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + Tracker::new(__v.as_mut_ptr(), { 5 }); + __v.assume_init() + }, }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut holder_8)).destructor() @@ -106,7 +126,11 @@ pub static mut trivial_9: std::cell::LazyCell = pub struct p3_reverse_completion_order_WithStaticMember {} pub static mut member_10: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let __static = Tracker::new({ 7 }); + let __static = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + Tracker::new(__v.as_mut_ptr(), { 7 }); + __v.assume_init() + }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut member_10)).destructor() }); @@ -118,7 +142,11 @@ pub static mut capturing_11: std::cell::LazyCell i32>> = { let __static = lambda_unsafe!( { - let captured: Tracker = Tracker::new({ 8 }); + let captured: Tracker = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + Tracker::new(__v.as_mut_ptr(), { 8 }); + __v.assume_init() + }; }, || -> i32 { return captured.tag; @@ -153,7 +181,11 @@ pub unsafe fn test_14() { } static mut during_init_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let __static = Tracker::new({ 3 }); + let __static = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + Tracker::new(__v.as_mut_ptr(), { 3 }); + __v.assume_init() + }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut during_init_5)).destructor() }); @@ -162,7 +194,11 @@ static mut during_init_5: std::cell::LazyCell = std::cell::LazyCell::ne }); static mut during_main_13: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let __static = Tracker::new({ 9 }); + let __static = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + Tracker::new(__v.as_mut_ptr(), { 9 }); + __v.assume_init() + }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut during_main_13)).destructor() }); diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index d9a5246510..429ffc0bfe 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -20,22 +20,23 @@ impl HasConstexprCtor { pub fn reset() { copyCount_0.with(|rc| *rc.borrow_mut() = 0); } - pub fn new(mut v: i32) -> Self { - Self { m: v } + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { m: v }); } - pub fn copy_from(o: Ptr) -> Self { - let __this: HasConstexprCtor = Self { + pub fn copy_from(this: Ptr, o: Ptr) { + this.write(Self { m: o.with(|__s| __s.m), - }; + }); (*copyCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Clone for HasConstexprCtor { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(HasConstexprCtor { m: self.m.clone() })); - HasConstexprCtor::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + HasConstexprCtor::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } thread_local!( @@ -75,15 +76,13 @@ impl LifetimeTracked { } }); } - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; + pub fn new(this: Ptr) { + this.write(Self { uses: 0 }); (*ctorCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; + pub fn copy_from(this: Ptr, _a0: Ptr) { + this.write(Self { uses: 0 }); (*copyCount_2.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Clone for LifetimeTracked { @@ -91,22 +90,56 @@ impl Clone for LifetimeTracked { let __src: Value = Rc::new(RefCell::new(LifetimeTracked { uses: self.uses.clone(), })); - LifetimeTracked::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } impl Default for LifetimeTracked { fn default() -> Self { - { LifetimeTracked::new() } + { + { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } pub fn test_5() { ({ HasConstexprCtor::reset() }); - let mut arr: [HasConstexprCtor; 2] = - [HasConstexprCtor::new({ 3 }), HasConstexprCtor::new({ 4 })]; + let mut arr: [HasConstexprCtor; 2] = [ + { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + HasConstexprCtor::new(__v.as_pointer(), { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + HasConstexprCtor::new(__v.as_pointer(), { 4 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + ]; let f: Value i32>> = Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { { - return [HasConstexprCtor::new({ 3 }), HasConstexprCtor::new({ 4 })][(1) as usize] + return [ + { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + HasConstexprCtor::new(__v.as_pointer(), { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + HasConstexprCtor::new(__v.as_pointer(), { 4 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + ][(1) as usize] .m; } }))); @@ -116,11 +149,21 @@ pub fn test_5() { } pub fn test_6() { ({ HasConstexprCtor::reset() }); - let mut k: HasConstexprCtor = HasConstexprCtor::new({ 5 }); + let mut k: HasConstexprCtor = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + HasConstexprCtor::new(__v.as_pointer(), { 5 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; let f: Value i32>> = Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { { - return HasConstexprCtor::new({ 5 }).m; + return { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + HasConstexprCtor::new(__v.as_pointer(), { 5 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + .m; } }))); assert!((copyCount_0.with(|rc| *rc.borrow()) == 0)); @@ -129,16 +172,34 @@ pub fn test_6() { } pub fn test_7() { ({ HasConstexprCtor::reset() }); - let mut k1: HasConstexprCtor = HasConstexprCtor::new({ 7 }); - let mut k2: HasConstexprCtor = HasConstexprCtor::new({ 9 }); + let mut k1: HasConstexprCtor = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + HasConstexprCtor::new(__v.as_pointer(), { 7 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; + let mut k2: HasConstexprCtor = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + HasConstexprCtor::new(__v.as_pointer(), { 9 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; let f: Value i32>> = Rc::new(RefCell::new(FnPtr:: i32>::new( |mut b: bool| -> i32 { { return { (if b { - HasConstexprCtor::new({ 7 }) + { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + HasConstexprCtor::new(__v.as_pointer(), { 7 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } } else { - HasConstexprCtor::new({ 9 }) + { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + HasConstexprCtor::new(__v.as_pointer(), { 9 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } }) .m }; @@ -155,14 +216,23 @@ thread_local!( ); pub fn test_9() { ({ HasConstexprCtor::reset() }); - let k: Value = Rc::new(RefCell::new(HasConstexprCtor::new({ 5 }))); + let k: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + HasConstexprCtor::new(__v.as_pointer(), { 5 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let f: Value i32>> = Rc::new(RefCell::new(FnPtr:: i32>::new(|| -> i32 { { return { { (*left_8.with(Value::clone).borrow_mut()).prefix_inc(); - HasConstexprCtor::new({ 5 }) + { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + HasConstexprCtor::new(__v.as_pointer(), { 5 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } } .m }; @@ -194,7 +264,11 @@ pub fn test_11() { } thread_local!( pub static global_12: Value = { - let __static = Rc::new(RefCell::new(LifetimeTracked::new())); + let __static = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); libcc2rs::register_static_destructor(|| { global_12.with(Value::clone).as_pointer().destructor() }); @@ -215,13 +289,21 @@ pub fn test_13() { } pub fn test_14() { ({ LifetimeTracked::reset() }); - let t: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + let t: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_t = std::mem::DropGuard::new(t.clone(), |__p| __p.as_pointer().destructor()); let r: Ptr = t.as_pointer(); let f: Value> = Rc::new(RefCell::new(lambda!( { - let r: Value = - Rc::new(RefCell::new(LifetimeTracked::copy_from({ (r).clone() }))); + let r: Value = Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::copy_from(__v.as_pointer(), { (r).clone() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); }, || { ({ LifetimeTrackedImpl::use_(&r.as_pointer()) }); @@ -250,15 +332,27 @@ pub fn test_15() { } pub fn test_16() { ({ HasConstexprCtor::reset() }); - let k: Value = Rc::new(RefCell::new(HasConstexprCtor::new({ 5 }))); + let k: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + HasConstexprCtor::new(__v.as_pointer(), { 5 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let f: Value i32>> = Rc::new(RefCell::new(lambda!( { - let k: Value = Rc::new(RefCell::new(HasConstexprCtor::copy_from({ - k.as_pointer() - }))); + let k: Value = Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + HasConstexprCtor::copy_from(__v.as_pointer(), { k.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); }, || -> i32 { - let mut c: HasConstexprCtor = HasConstexprCtor::copy_from({ k.as_pointer() }); + let mut c: HasConstexprCtor = { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + HasConstexprCtor::copy_from(__v.as_pointer(), { k.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; return c.m; } ))); @@ -289,19 +383,18 @@ pub struct p5_2_mutable_subobject_is_odr_used_HasMutableMember { pub scratch: i32, } impl p5_2_mutable_subobject_is_odr_used_HasMutableMember { - pub fn new(mut v: i32) -> Self { - Self { + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { value: v, scratch: 0, - } + }); } - pub fn copy_from(o: Ptr) -> Self { - let __this: p5_2_mutable_subobject_is_odr_used_HasMutableMember = Self { + pub fn copy_from(this: Ptr, o: Ptr) { + this.write(Self { value: o.with(|__s| __s.value), scratch: o.with(|__s| __s.scratch), - }; + }); (*copies_18.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Clone for p5_2_mutable_subobject_is_odr_used_HasMutableMember { @@ -312,21 +405,38 @@ impl Clone for p5_2_mutable_subobject_is_odr_used_HasMutableMember { scratch: self.scratch.clone(), }), ); - p5_2_mutable_subobject_is_odr_used_HasMutableMember::copy_from(__src.as_pointer()) + let __v: Value = Rc::new( + RefCell::new(::zero_init()), + ); + p5_2_mutable_subobject_is_odr_used_HasMutableMember::copy_from( + __v.as_pointer(), + __src.as_pointer(), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } pub fn test_19() { - let k: Value = Rc::new(RefCell::new( - p5_2_mutable_subobject_is_odr_used_HasMutableMember::new({ 5 }), - )); + let k: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new( + RefCell::new(::zero_init()), + ); + p5_2_mutable_subobject_is_odr_used_HasMutableMember::new(__v.as_pointer(), { 5 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let f: Value i32>> = Rc::new(RefCell::new(lambda!( { let k: Value = - Rc::new(RefCell::new( - p5_2_mutable_subobject_is_odr_used_HasMutableMember::copy_from({ - k.as_pointer() - }), - )); + Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new( + ::zero_init(), + )); + p5_2_mutable_subobject_is_odr_used_HasMutableMember::copy_from( + __v.as_pointer(), + { k.as_pointer() }, + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); }, || -> i32 { return { (*k.borrow()).value }; @@ -352,8 +462,18 @@ pub fn test_20() { ({ LifetimeTracked::reset() }); let p: Value = Rc::new(RefCell::new( p6_unevaluated_binding_needs_no_capture_HasTwoMembers { - a: LifetimeTracked::new(), - b: LifetimeTracked::new(), + a: { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + b: { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, }, )); let _dtor_p = std::mem::DropGuard::new(p.clone(), |__p| __p.as_pointer().destructor()); @@ -456,20 +576,34 @@ thread_local!( #[byte_size(1)] pub struct p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} impl p9_destructor_not_potentially_invoked_HasUndefinedDestructor { - pub fn new() -> Self { - let __this: p9_destructor_not_potentially_invoked_HasUndefinedDestructor = Self {}; + pub fn new(this: Ptr) { + this.write(Self {}); (*t_ctors_27.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Default for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { fn default() -> Self { - { p9_destructor_not_potentially_invoked_HasUndefinedDestructor::new() } + { + { + let __v: Value = + Rc::new(RefCell::new( + ::zero_init(), + )); + p9_destructor_not_potentially_invoked_HasUndefinedDestructor::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } pub fn test_28() { - let mut p: Ptr = - Ptr::alloc(p9_destructor_not_potentially_invoked_HasUndefinedDestructor::new()); + let mut p: Ptr = Ptr::alloc({ + let __v: Value = + Rc::new(RefCell::new( + ::zero_init(), + )); + p9_destructor_not_potentially_invoked_HasUndefinedDestructor::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }); assert!(!((p).is_null())); assert!((t_ctors_27.with(|rc| *rc.borrow()) == 1)); } @@ -483,24 +617,35 @@ pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { pub value: i32, } impl p9_unused_copy_constructor_HasUndefinedCopyCtor { - pub fn new() -> Self { - let __this: p9_unused_copy_constructor_HasUndefinedCopyCtor = Self { value: 3 }; + pub fn new(this: Ptr) { + this.write(Self { value: 3 }); (*ctor_calls_29.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { fn default() -> Self { - { p9_unused_copy_constructor_HasUndefinedCopyCtor::new() } + { + { + let __v: Value = Rc::new( + RefCell::new(::zero_init()), + ); + p9_unused_copy_constructor_HasUndefinedCopyCtor::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } pub fn read_30(object: Ptr) -> i32 { return object.with(|__s| __s.value); } pub fn test_31() { - let a: Value = Rc::new(RefCell::new( - p9_unused_copy_constructor_HasUndefinedCopyCtor::new(), - )); + let a: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new( + ::zero_init(), + )); + p9_unused_copy_constructor_HasUndefinedCopyCtor::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!((({ read_30(a.as_pointer(),) }) == 3)); assert!((ctor_calls_29.with(|rc| *rc.borrow()) == 1)); } @@ -511,15 +656,23 @@ thread_local!( #[byte_size(1)] pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} impl p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - pub fn new() -> Self { - let __this: p9_unused_implicit_assignment_HasUndefinedCopyAssignment = Self {}; + pub fn new(this: Ptr) { + this.write(Self {}); (*m_ctors_32.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { fn default() -> Self { - { p9_unused_implicit_assignment_HasUndefinedCopyAssignment::new() } + { + { + let __v: Value = + Rc::new(RefCell::new( + ::zero_init(), + )); + p9_unused_implicit_assignment_HasUndefinedCopyAssignment::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } #[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] diff --git a/tests/std/basic/out/unsafe/basic.def.odr.rs b/tests/std/basic/out/unsafe/basic.def.odr.rs index d482309b05..09d14344db 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -17,14 +17,12 @@ impl HasConstexprCtor { pub unsafe fn reset() { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) = 0; } - pub unsafe fn new(mut v: i32) -> Self { - let mut this = Self { m: v }; - this + pub unsafe fn new(this: *mut Self, mut v: i32) { + this.write(Self { m: v }); } - pub unsafe fn copy_from(o: *const HasConstexprCtor) -> Self { - let mut this = Self { m: (*o).m }; + pub unsafe fn copy_from(this: *mut Self, o: *const HasConstexprCtor) { + this.write(Self { m: (*o).m }); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)).prefix_inc(); - this } pub unsafe fn copy_assign(&mut self, _a0: *const HasConstexprCtor) -> *mut HasConstexprCtor { self.m = (*_a0).m; @@ -33,7 +31,11 @@ impl HasConstexprCtor { } impl Clone for HasConstexprCtor { fn clone(&self) -> Self { - unsafe { HasConstexprCtor::copy_from(self as *const HasConstexprCtor) } + unsafe { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + HasConstexprCtor::copy_from(__v.as_mut_ptr(), self as *const HasConstexprCtor); + __v.assume_init() + } } } pub static mut ctorCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); @@ -58,15 +60,13 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) }; } - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; + pub unsafe fn new(this: *mut Self) { + this.write(Self { uses: 0 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_1)).prefix_inc(); - this } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; + pub unsafe fn copy_from(this: *mut Self, _a0: *const LifetimeTracked) { + this.write(Self { uses: 0 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)).prefix_inc(); - this } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_3)).prefix_inc(); @@ -82,20 +82,53 @@ impl LifetimeTracked { } impl Clone for LifetimeTracked { fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + unsafe { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::copy_from(__v.as_mut_ptr(), self as *const LifetimeTracked); + __v.assume_init() + } } } impl Default for LifetimeTracked { fn default() -> Self { - unsafe { LifetimeTracked::new() } + unsafe { + { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + } + } } } pub unsafe fn test_5() { (unsafe { HasConstexprCtor::reset() }); - let arr: [HasConstexprCtor; 2] = [HasConstexprCtor::new({ 3 }), HasConstexprCtor::new({ 4 })]; + let arr: [HasConstexprCtor; 2] = [ + { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + HasConstexprCtor::new(__v.as_mut_ptr(), { 3 }); + __v.assume_init() + }, + { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + HasConstexprCtor::new(__v.as_mut_ptr(), { 4 }); + __v.assume_init() + }, + ]; let mut f: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { unsafe { - return [HasConstexprCtor::new({ 3 }), HasConstexprCtor::new({ 4 })][(1) as usize].m; + return [ + { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + HasConstexprCtor::new(__v.as_mut_ptr(), { 3 }); + __v.assume_init() + }, + { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + HasConstexprCtor::new(__v.as_mut_ptr(), { 4 }); + __v.assume_init() + }, + ][(1) as usize] + .m; } }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); @@ -104,10 +137,19 @@ pub unsafe fn test_5() { } pub unsafe fn test_6() { (unsafe { HasConstexprCtor::reset() }); - let k: HasConstexprCtor = HasConstexprCtor::new({ 5 }); + let k: HasConstexprCtor = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + HasConstexprCtor::new(__v.as_mut_ptr(), { 5 }); + __v.assume_init() + }; let mut f: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { unsafe { - return HasConstexprCtor::new({ 5 }).m; + return { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + HasConstexprCtor::new(__v.as_mut_ptr(), { 5 }); + __v.assume_init() + } + .m; } }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_0)) == (0))); @@ -116,14 +158,30 @@ pub unsafe fn test_6() { } pub unsafe fn test_7() { (unsafe { HasConstexprCtor::reset() }); - let k1: HasConstexprCtor = HasConstexprCtor::new({ 7 }); - let k2: HasConstexprCtor = HasConstexprCtor::new({ 9 }); + let k1: HasConstexprCtor = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + HasConstexprCtor::new(__v.as_mut_ptr(), { 7 }); + __v.assume_init() + }; + let k2: HasConstexprCtor = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + HasConstexprCtor::new(__v.as_mut_ptr(), { 9 }); + __v.assume_init() + }; let mut f: FnPtr i32> = FnPtr:: i32>::new(|mut b: bool| -> i32 { unsafe { return (if b { - HasConstexprCtor::new({ 7 }) + { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + HasConstexprCtor::new(__v.as_mut_ptr(), { 7 }); + __v.assume_init() + } } else { - HasConstexprCtor::new({ 9 }) + { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + HasConstexprCtor::new(__v.as_mut_ptr(), { 9 }); + __v.assume_init() + } }) .m; } @@ -136,12 +194,20 @@ pub unsafe fn test_7() { pub static mut left_8: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); pub unsafe fn test_9() { (unsafe { HasConstexprCtor::reset() }); - let k: HasConstexprCtor = HasConstexprCtor::new({ 5 }); + let k: HasConstexprCtor = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + HasConstexprCtor::new(__v.as_mut_ptr(), { 5 }); + __v.assume_init() + }; let mut f: FnPtr i32> = FnPtr:: i32>::new(|| -> i32 { unsafe { return { (*std::cell::LazyCell::force_mut(&mut *&raw mut left_8)).prefix_inc(); - HasConstexprCtor::new({ 5 }) + { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + HasConstexprCtor::new(__v.as_mut_ptr(), { 5 }); + __v.assume_init() + } } .m; } @@ -171,7 +237,11 @@ pub unsafe fn test_11() { pub static mut global_12: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { - let __static = LifetimeTracked::new(); + let __static = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; libcc2rs::register_static_destructor(|| { (*std::cell::LazyCell::force_mut(&mut *&raw mut global_12)).destructor() }); @@ -194,12 +264,20 @@ pub unsafe fn test_13() { } pub unsafe fn test_14() { (unsafe { LifetimeTracked::reset() }); - let mut t: LifetimeTracked = LifetimeTracked::new(); + let mut t: LifetimeTracked = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; let _dtor_t = std::mem::DropGuard::new(&raw mut t, |__p| unsafe { (*__p).destructor() }); let r: *mut LifetimeTracked = &mut t; let mut f: FnPtr = lambda_unsafe!( { - let r: LifetimeTracked = LifetimeTracked::copy_from({ r }); + let r: LifetimeTracked = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::copy_from(__v.as_mut_ptr(), { r }); + __v.assume_init() + }; }, || { (unsafe { LifetimeTracked::use_(&r) }); @@ -227,13 +305,25 @@ pub unsafe fn test_15() { } pub unsafe fn test_16() { (unsafe { HasConstexprCtor::reset() }); - let k: HasConstexprCtor = HasConstexprCtor::new({ 5 }); + let k: HasConstexprCtor = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + HasConstexprCtor::new(__v.as_mut_ptr(), { 5 }); + __v.assume_init() + }; let mut f: FnPtr i32> = lambda_unsafe!( { - let k: HasConstexprCtor = HasConstexprCtor::copy_from({ &k }); + let k: HasConstexprCtor = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + HasConstexprCtor::copy_from(__v.as_mut_ptr(), { &k }); + __v.assume_init() + }; }, || -> i32 { - let mut c: HasConstexprCtor = HasConstexprCtor::copy_from({ &k }); + let mut c: HasConstexprCtor = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + HasConstexprCtor::copy_from(__v.as_mut_ptr(), { &k }); + __v.assume_init() + }; return c.m; } ); @@ -259,20 +349,21 @@ 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 new(mut v: i32) -> Self { - let mut this = Self { + pub unsafe fn new(this: *mut Self, mut v: i32) { + this.write(Self { value: v, scratch: 0, - }; - this + }); } - pub unsafe fn copy_from(o: *const p5_2_mutable_subobject_is_odr_used_HasMutableMember) -> Self { - let mut this = Self { + pub unsafe fn copy_from( + this: *mut Self, + o: *const p5_2_mutable_subobject_is_odr_used_HasMutableMember, + ) { + this.write(Self { value: (*o).value, scratch: (*o).scratch, - }; + }); (*std::cell::LazyCell::force_mut(&mut *&raw mut copies_18)).prefix_inc(); - this } pub unsafe fn copy_assign( &mut self, @@ -286,19 +377,36 @@ impl p5_2_mutable_subobject_is_odr_used_HasMutableMember { impl Clone for p5_2_mutable_subobject_is_odr_used_HasMutableMember { fn clone(&self) -> Self { unsafe { + let mut __v = ::std::mem::MaybeUninit::< + p5_2_mutable_subobject_is_odr_used_HasMutableMember, + >::uninit(); p5_2_mutable_subobject_is_odr_used_HasMutableMember::copy_from( + __v.as_mut_ptr(), self as *const p5_2_mutable_subobject_is_odr_used_HasMutableMember, - ) + ); + __v.assume_init() } } } pub unsafe fn test_19() { - let k: p5_2_mutable_subobject_is_odr_used_HasMutableMember = - p5_2_mutable_subobject_is_odr_used_HasMutableMember::new({ 5 }); + let k: p5_2_mutable_subobject_is_odr_used_HasMutableMember = { + let mut __v = + ::std::mem::MaybeUninit::::uninit( + ); + p5_2_mutable_subobject_is_odr_used_HasMutableMember::new(__v.as_mut_ptr(), { 5 }); + __v.assume_init() + }; let mut f: FnPtr i32> = lambda_unsafe!( { - let k: p5_2_mutable_subobject_is_odr_used_HasMutableMember = - p5_2_mutable_subobject_is_odr_used_HasMutableMember::copy_from({ &k }); + let k: p5_2_mutable_subobject_is_odr_used_HasMutableMember = { + let mut __v = ::std::mem::MaybeUninit::< + p5_2_mutable_subobject_is_odr_used_HasMutableMember, + >::uninit(); + p5_2_mutable_subobject_is_odr_used_HasMutableMember::copy_from(__v.as_mut_ptr(), { + &k + }); + __v.assume_init() + }; }, || -> i32 { return k.value; @@ -340,8 +448,16 @@ pub unsafe fn test_20() { (unsafe { LifetimeTracked::reset() }); let mut p: p6_unevaluated_binding_needs_no_capture_HasTwoMembers = p6_unevaluated_binding_needs_no_capture_HasTwoMembers { - a: LifetimeTracked::new(), - b: LifetimeTracked::new(), + a: { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }, + b: { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }, }; let _dtor_p = std::mem::DropGuard::new(&raw mut p, |__p| unsafe { (*__p).destructor() }); let __decomp_21: *mut p6_unevaluated_binding_needs_no_capture_HasTwoMembers = &mut p; @@ -482,22 +598,33 @@ pub static mut t_ctors_27: std::cell::LazyCell = std::cell::LazyCell::new(| #[derive(Copy, Clone, VaArg, FnPtrArg)] pub struct p9_destructor_not_potentially_invoked_HasUndefinedDestructor {} impl p9_destructor_not_potentially_invoked_HasUndefinedDestructor { - pub unsafe fn new() -> Self { - let mut this = Self {}; + pub unsafe fn new(this: *mut Self) { + this.write(Self {}); (*std::cell::LazyCell::force_mut(&mut *&raw mut t_ctors_27)).prefix_inc(); - this } } impl Default for p9_destructor_not_potentially_invoked_HasUndefinedDestructor { fn default() -> Self { - unsafe { p9_destructor_not_potentially_invoked_HasUndefinedDestructor::new() } + unsafe { + { + let mut __v = ::std::mem::MaybeUninit::< + p9_destructor_not_potentially_invoked_HasUndefinedDestructor, + >::uninit(); + p9_destructor_not_potentially_invoked_HasUndefinedDestructor::new(__v.as_mut_ptr()); + __v.assume_init() + } + } } } pub unsafe fn test_28() { - let mut p: *mut p9_destructor_not_potentially_invoked_HasUndefinedDestructor = (Box::leak( - Box::new(p9_destructor_not_potentially_invoked_HasUndefinedDestructor::new()), - ) - as *mut p9_destructor_not_potentially_invoked_HasUndefinedDestructor); + let mut p: *mut p9_destructor_not_potentially_invoked_HasUndefinedDestructor = + (Box::leak(Box::new({ + let mut __v = ::std::mem::MaybeUninit::< + p9_destructor_not_potentially_invoked_HasUndefinedDestructor, + >::uninit(); + p9_destructor_not_potentially_invoked_HasUndefinedDestructor::new(__v.as_mut_ptr()); + __v.assume_init() + })) as *mut p9_destructor_not_potentially_invoked_HasUndefinedDestructor); assert!(!((p).is_null())); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut t_ctors_27)) == (1))); } @@ -509,23 +636,34 @@ pub struct p9_unused_copy_constructor_HasUndefinedCopyCtor { pub value: i32, } impl p9_unused_copy_constructor_HasUndefinedCopyCtor { - pub unsafe fn new() -> Self { - let mut this = Self { value: 3 }; + pub unsafe fn new(this: *mut Self) { + this.write(Self { value: 3 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctor_calls_29)).prefix_inc(); - this } } impl Default for p9_unused_copy_constructor_HasUndefinedCopyCtor { fn default() -> Self { - unsafe { p9_unused_copy_constructor_HasUndefinedCopyCtor::new() } + unsafe { + { + let mut __v = ::std::mem::MaybeUninit::< + p9_unused_copy_constructor_HasUndefinedCopyCtor, + >::uninit(); + p9_unused_copy_constructor_HasUndefinedCopyCtor::new(__v.as_mut_ptr()); + __v.assume_init() + } + } } } pub unsafe fn read_30(object: *const p9_unused_copy_constructor_HasUndefinedCopyCtor) -> i32 { return (*object).value; } pub unsafe fn test_31() { - let mut a: p9_unused_copy_constructor_HasUndefinedCopyCtor = - p9_unused_copy_constructor_HasUndefinedCopyCtor::new(); + let mut a: p9_unused_copy_constructor_HasUndefinedCopyCtor = { + let mut __v = + ::std::mem::MaybeUninit::::uninit(); + p9_unused_copy_constructor_HasUndefinedCopyCtor::new(__v.as_mut_ptr()); + __v.assume_init() + }; assert!(((unsafe { read_30(&a,) }) == (3))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctor_calls_29)) == (1))); } @@ -534,15 +672,22 @@ pub static mut m_ctors_32: std::cell::LazyCell = std::cell::LazyCell::new(| #[derive(Copy, Clone, VaArg, FnPtrArg)] pub struct p9_unused_implicit_assignment_HasUndefinedCopyAssignment {} impl p9_unused_implicit_assignment_HasUndefinedCopyAssignment { - pub unsafe fn new() -> Self { - let mut this = Self {}; + pub unsafe fn new(this: *mut Self) { + this.write(Self {}); (*std::cell::LazyCell::force_mut(&mut *&raw mut m_ctors_32)).prefix_inc(); - this } } impl Default for p9_unused_implicit_assignment_HasUndefinedCopyAssignment { fn default() -> Self { - unsafe { p9_unused_implicit_assignment_HasUndefinedCopyAssignment::new() } + unsafe { + { + let mut __v = ::std::mem::MaybeUninit::< + p9_unused_implicit_assignment_HasUndefinedCopyAssignment, + >::uninit(); + p9_unused_implicit_assignment_HasUndefinedCopyAssignment::new(__v.as_mut_ptr()); + __v.assume_init() + } + } } } #[repr(C)] 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 6653a1bce1..5337054eef 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 @@ -7,10 +7,10 @@ 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 new_1(u: Ptr) -> Self { - Self { + pub fn new_1(this: Ptr, u: Ptr) { + this.write(Self { value: (u.with(|__s| __s.value) + 1), - } + }); } } #[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] @@ -21,16 +21,27 @@ pub struct p1_template_constructor_from_own_type_Probe { pub value: i32, } impl p1_template_constructor_from_own_type_Probe { - pub fn new_2(mut v: i32) -> Self { - Self { value: v } + pub fn new_2(this: Ptr, mut v: i32) { + this.write(Self { value: v }); } } pub fn test_0() { - let probe: Value = Rc::new(RefCell::new( - p1_template_constructor_from_own_type_Probe::new_2({ 22 }), - )); - let mut converted: p1_template_constructor_from_own_type_Probe = - p1_template_constructor_from_own_type_Probe::new_1({ probe.as_pointer() }); + let probe: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new( + ::zero_init(), + )); + p1_template_constructor_from_own_type_Probe::new_2(__v.as_pointer(), { 22 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let mut converted: p1_template_constructor_from_own_type_Probe = { + let __v: Value = Rc::new(RefCell::new( + ::zero_init(), + )); + p1_template_constructor_from_own_type_Probe::new_1(__v.as_pointer(), { + probe.as_pointer() + }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((converted.value == 23)); } pub fn main() { 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 e31347631e..a1d90e41a7 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,11 +7,10 @@ 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 new_1(u: *mut p1_template_constructor_from_own_type_Probe) -> Self { - let mut this = Self { + pub unsafe fn new_1(this: *mut Self, u: *mut p1_template_constructor_from_own_type_Probe) { + this.write(Self { value: (((*u).value) + (1)), - }; - this + }); } } #[repr(C)] @@ -21,16 +20,23 @@ pub struct p1_template_constructor_from_own_type_Probe { pub value: i32, } impl p1_template_constructor_from_own_type_Probe { - pub unsafe fn new_2(mut v: i32) -> Self { - let mut this = Self { value: v }; - this + pub unsafe fn new_2(this: *mut Self, mut v: i32) { + this.write(Self { value: v }); } } pub unsafe fn test_0() { - let mut probe: p1_template_constructor_from_own_type_Probe = - p1_template_constructor_from_own_type_Probe::new_2({ 22 }); - let mut converted: p1_template_constructor_from_own_type_Probe = - p1_template_constructor_from_own_type_Probe::new_1({ &mut probe }); + let mut probe: p1_template_constructor_from_own_type_Probe = { + let mut __v = + ::std::mem::MaybeUninit::::uninit(); + p1_template_constructor_from_own_type_Probe::new_2(__v.as_mut_ptr(), { 22 }); + __v.assume_init() + }; + let mut converted: p1_template_constructor_from_own_type_Probe = { + let mut __v = + ::std::mem::MaybeUninit::::uninit(); + p1_template_constructor_from_own_type_Probe::new_1(__v.as_mut_ptr(), { &mut probe }); + __v.assume_init() + }; assert!(((converted.value) == (23))); } pub fn main() { 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 a5f9afd63d..1de51aac6b 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 @@ -14,13 +14,16 @@ pub struct p11_defaulted_move_constructor_is_trivial_MoveOnly { pub value: i32, } impl p11_defaulted_move_constructor_is_trivial_MoveOnly { - pub fn new(mut value: i32) -> Self { - Self { value: value } + pub fn new(this: Ptr, mut value: i32) { + this.write(Self { value: value }); } - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from( + this: Ptr, + _a0: Ptr, + ) { + this.write(Self { value: { (*_a0.upgrade().deref()).value }, - } + }); } } pub fn pass_0( @@ -28,13 +31,25 @@ pub fn pass_0( ) -> p11_defaulted_move_constructor_is_trivial_MoveOnly { let object: Value = Rc::new(RefCell::new(object)); - return p11_defaulted_move_constructor_is_trivial_MoveOnly::move_from({ object.as_pointer() }); + return { + let __v: Value = Rc::new(RefCell::new( + ::zero_init(), + )); + p11_defaulted_move_constructor_is_trivial_MoveOnly::move_from(__v.as_pointer(), { + object.as_pointer() + }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; } pub fn test_1() { let mut result: p11_defaulted_move_constructor_is_trivial_MoveOnly = ({ - pass_0(p11_defaulted_move_constructor_is_trivial_MoveOnly::new({ - 7 - })) + pass_0({ + let __v: Value = Rc::new( + RefCell::new(::zero_init()), + ); + p11_defaulted_move_constructor_is_trivial_MoveOnly::new(__v.as_pointer(), { 7 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }) }); assert!((result.value == 7)); } 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 1ec416a739..1b2e16d9ee 100644 --- a/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs +++ b/tests/std/class/class.mem/class.ctor/out/unsafe/class.copy.ctor.rs @@ -13,27 +13,39 @@ pub struct p11_defaulted_move_constructor_is_trivial_MoveOnly { pub value: i32, } impl p11_defaulted_move_constructor_is_trivial_MoveOnly { - pub unsafe fn new(mut value: i32) -> Self { - let mut this = Self { value: value }; - this + pub unsafe fn new(this: *mut Self, mut value: i32) { + this.write(Self { value: value }); } - pub unsafe fn move_from(_a0: *mut p11_defaulted_move_constructor_is_trivial_MoveOnly) -> Self { - let mut this = Self { + pub unsafe fn move_from( + this: *mut Self, + _a0: *mut p11_defaulted_move_constructor_is_trivial_MoveOnly, + ) { + this.write(Self { value: (*_a0).value, - }; - this + }); } } pub unsafe fn pass_0( mut object: p11_defaulted_move_constructor_is_trivial_MoveOnly, ) -> p11_defaulted_move_constructor_is_trivial_MoveOnly { - return p11_defaulted_move_constructor_is_trivial_MoveOnly::move_from({ &mut object }); + return { + let mut __v = + ::std::mem::MaybeUninit::::uninit(); + p11_defaulted_move_constructor_is_trivial_MoveOnly::move_from(__v.as_mut_ptr(), { + &mut object + }); + __v.assume_init() + }; } pub unsafe fn test_1() { let mut result: p11_defaulted_move_constructor_is_trivial_MoveOnly = (unsafe { - pass_0(p11_defaulted_move_constructor_is_trivial_MoveOnly::new({ - 7 - })) + pass_0({ + let mut __v = ::std::mem::MaybeUninit::< + p11_defaulted_move_constructor_is_trivial_MoveOnly, + >::uninit(); + p11_defaulted_move_constructor_is_trivial_MoveOnly::new(__v.as_mut_ptr(), { 7 }); + __v.assume_init() + }) }); assert!(((result.value) == (7))); } 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 a01c52b611..9cfe2a8f73 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 @@ -384,13 +384,22 @@ pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { pub untouched: i32, } impl p9_1_2_zero_then_default_initialized_LeavesMemberAlone { - pub fn new() -> Self { - Self { untouched: 0_i32 } + pub fn new(this: Ptr) { + this.write(Self { untouched: 0_i32 }); } } impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { fn default() -> Self { - { p9_1_2_zero_then_default_initialized_LeavesMemberAlone::new() } + { + { + let __v: Value = + Rc::new(RefCell::new( + ::zero_init(), + )); + p9_1_2_zero_then_default_initialized_LeavesMemberAlone::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } #[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] 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 fba43bafdc..dc49ecefdd 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 @@ -320,14 +320,21 @@ pub struct p9_1_2_zero_then_default_initialized_LeavesMemberAlone { pub untouched: i32, } impl p9_1_2_zero_then_default_initialized_LeavesMemberAlone { - pub unsafe fn new() -> Self { - let mut this = Self { untouched: 0_i32 }; - this + pub unsafe fn new(this: *mut Self) { + this.write(Self { untouched: 0_i32 }); } } impl Default for p9_1_2_zero_then_default_initialized_LeavesMemberAlone { fn default() -> Self { - unsafe { p9_1_2_zero_then_default_initialized_LeavesMemberAlone::new() } + unsafe { + { + let mut __v = ::std::mem::MaybeUninit::< + p9_1_2_zero_then_default_initialized_LeavesMemberAlone, + >::uninit(); + p9_1_2_zero_then_default_initialized_LeavesMemberAlone::new(__v.as_mut_ptr()); + __v.assume_init() + } + } } } #[repr(C)] 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 6855cf3296..b398328d6f 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 @@ -113,13 +113,23 @@ pub struct p9_evaluated_each_time_called_Widget { pub id: i32, } impl p9_evaluated_each_time_called_Widget { - pub fn new(mut id: i32) -> Self { - Self { id: id } + pub fn new(this: Ptr, mut id: i32) { + this.write(Self { id: id }); } } impl Default for p9_evaluated_each_time_called_Widget { fn default() -> Self { - { p9_evaluated_each_time_called_Widget::new({ ({ count_default_13() }) }) } + { + { + let __v: Value = Rc::new(RefCell::new( + ::zero_init(), + )); + p9_evaluated_each_time_called_Widget::new(__v.as_pointer(), { + ({ count_default_13() }) + }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } thread_local!( @@ -156,12 +166,27 @@ pub fn test_17() { assert!((({ combine_14((*first.prefix_inc()), ({ count_default_13() }),) }) == 103)); assert!((first == 1)); assert!((defaults_evaluated_12.with(|rc| *rc.borrow()) == 3)); - let mut a: p9_evaluated_each_time_called_Widget = - p9_evaluated_each_time_called_Widget::new({ ({ count_default_13() }) }); - let mut b: p9_evaluated_each_time_called_Widget = - p9_evaluated_each_time_called_Widget::new({ 40 }); - let mut c: p9_evaluated_each_time_called_Widget = - p9_evaluated_each_time_called_Widget::new({ ({ count_default_13() }) }); + let mut a: p9_evaluated_each_time_called_Widget = { + let __v: Value = Rc::new(RefCell::new( + ::zero_init(), + )); + p9_evaluated_each_time_called_Widget::new(__v.as_pointer(), { ({ count_default_13() }) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; + let mut b: p9_evaluated_each_time_called_Widget = { + let __v: Value = Rc::new(RefCell::new( + ::zero_init(), + )); + p9_evaluated_each_time_called_Widget::new(__v.as_pointer(), { 40 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; + let mut c: p9_evaluated_each_time_called_Widget = { + let __v: Value = Rc::new(RefCell::new( + ::zero_init(), + )); + p9_evaluated_each_time_called_Widget::new(__v.as_pointer(), { ({ count_default_13() }) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((a.id == 4)); assert!((b.id == 40)); assert!((c.id == 5)); 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 ae65178472..be35a175ce 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 @@ -111,14 +111,22 @@ pub struct p9_evaluated_each_time_called_Widget { pub id: i32, } impl p9_evaluated_each_time_called_Widget { - pub unsafe fn new(mut id: i32) -> Self { - let mut this = Self { id: id }; - this + pub unsafe fn new(this: *mut Self, mut id: i32) { + this.write(Self { id: id }); } } impl Default for p9_evaluated_each_time_called_Widget { fn default() -> Self { - unsafe { p9_evaluated_each_time_called_Widget::new({ (unsafe { count_default_13() }) }) } + unsafe { + { + let mut __v = + ::std::mem::MaybeUninit::::uninit(); + p9_evaluated_each_time_called_Widget::new(__v.as_mut_ptr(), { + (unsafe { count_default_13() }) + }); + __v.assume_init() + } + } } } static mut base_15: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 10 }); @@ -158,12 +166,25 @@ pub unsafe fn test_17() { ); assert!(((first) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut defaults_evaluated_12)) == (3))); - let mut a: p9_evaluated_each_time_called_Widget = - p9_evaluated_each_time_called_Widget::new({ (unsafe { count_default_13() }) }); - let mut b: p9_evaluated_each_time_called_Widget = - p9_evaluated_each_time_called_Widget::new({ 40 }); - let mut c: p9_evaluated_each_time_called_Widget = - p9_evaluated_each_time_called_Widget::new({ (unsafe { count_default_13() }) }); + let mut a: p9_evaluated_each_time_called_Widget = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + p9_evaluated_each_time_called_Widget::new(__v.as_mut_ptr(), { + (unsafe { count_default_13() }) + }); + __v.assume_init() + }; + let mut b: p9_evaluated_each_time_called_Widget = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + p9_evaluated_each_time_called_Widget::new(__v.as_mut_ptr(), { 40 }); + __v.assume_init() + }; + let mut c: p9_evaluated_each_time_called_Widget = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + p9_evaluated_each_time_called_Widget::new(__v.as_mut_ptr(), { + (unsafe { count_default_13() }) + }); + __v.assume_init() + }; assert!(((a.id) == (4))); assert!(((b.id) == (40))); assert!(((c.id) == (5))); 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 e02106a63e..8e220409fb 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 @@ -102,15 +102,19 @@ thread_local!( #[byte_size(1)] pub struct p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} impl p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { - pub fn copy_from(_a0: Ptr) -> Self { - let __this: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves = Self {}; + pub fn copy_from( + this: Ptr, + _a0: Ptr, + ) { + this.write(Self {}); (*copyCount_9.with(Value::clone).borrow_mut()).prefix_inc(); - __this } - pub fn move_from(_a0: Ptr) -> Self { - let __this: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves = Self {}; + pub fn move_from( + this: Ptr, + _a0: Ptr, + ) { + this.write(Self {}); (*moveCount_10.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Clone for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { @@ -118,7 +122,14 @@ impl Clone for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { let __src: Value = Rc::new( RefCell::new(p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {}), ); - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::copy_from(__src.as_pointer()) + let __v: Value = Rc::new( + RefCell::new(::zero_init()), + ); + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::copy_from( + __v.as_pointer(), + __src.as_pointer(), + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } #[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, Default)] @@ -129,12 +140,20 @@ pub struct p6_data_member_of_rvalue_is_xvalue_HoldsCounted { pub member: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, } impl p6_data_member_of_rvalue_is_xvalue_HoldsCounted { - pub fn move_from(_a0: Ptr) -> Self { - Self { - member: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::move_from({ - field_ptr!(_a0, member) - }), - } + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { + member: { + let __v: Value = + Rc::new(RefCell::new( + ::zero_init(), + )); + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::move_from( + __v.as_pointer(), + { field_ptr!(_a0, member) }, + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + }); } } pub fn test_11() { @@ -143,18 +162,28 @@ pub fn test_11() { let holder: Value = Rc::new(RefCell::new( ::default(), )); - let mut from_lvalue: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves = - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::copy_from({ + let mut from_lvalue: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves = { + let __v: Value = Rc::new( + RefCell::new(::zero_init()), + ); + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::copy_from(__v.as_pointer(), { (holder.as_pointer()) .member::(pm) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((copyCount_9.with(|rc| *rc.borrow()) == 1)); assert!((moveCount_10.with(|rc| *rc.borrow()) == 0)); - let mut from_xvalue: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves = - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::move_from({ + let mut from_xvalue: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves = { + let __v: Value = Rc::new( + RefCell::new(::zero_init()), + ); + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::move_from(__v.as_pointer(), { (holder.as_pointer()) .member::(pm) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((copyCount_9.with(|rc| *rc.borrow()) == 1)); assert!((moveCount_10.with(|rc| *rc.borrow()) == 1)); } diff --git a/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs b/tests/std/expr/expr.compound/out/unsafe/expr.mptr.oper.rs index 9630283178..7532395d2e 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 @@ -98,26 +98,31 @@ pub static mut moveCount_10: std::cell::LazyCell = std::cell::LazyCell::new pub struct p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves {} impl p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { pub unsafe fn copy_from( + this: *mut Self, _a0: *const p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, - ) -> Self { - let mut this = Self {}; + ) { + this.write(Self {}); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_9)).prefix_inc(); - this } pub unsafe fn move_from( + this: *mut Self, _a0: *mut p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, - ) -> Self { - let mut this = Self {}; + ) { + this.write(Self {}); (*std::cell::LazyCell::force_mut(&mut *&raw mut moveCount_10)).prefix_inc(); - this } } impl Clone for p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves { fn clone(&self) -> Self { unsafe { + let mut __v = ::std::mem::MaybeUninit::< + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, + >::uninit(); p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::copy_from( + __v.as_mut_ptr(), self as *const p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, - ) + ); + __v.assume_init() } } } @@ -127,13 +132,22 @@ pub struct p6_data_member_of_rvalue_is_xvalue_HoldsCounted { pub member: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, } impl p6_data_member_of_rvalue_is_xvalue_HoldsCounted { - pub unsafe fn move_from(_a0: *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted) -> Self { - let mut this = Self { - member: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::move_from({ - &mut (*_a0).member - }), - }; - this + pub unsafe fn move_from( + this: *mut Self, + _a0: *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted, + ) { + this.write(Self { + member: { + let mut __v = ::std::mem::MaybeUninit::< + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, + >::uninit(); + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::move_from( + __v.as_mut_ptr(), + { &mut (*_a0).member }, + ); + __v.assume_init() + }, + }); } } pub unsafe fn test_11() { @@ -141,20 +155,30 @@ pub unsafe fn test_11() { (::std::mem::offset_of!(p6_data_member_of_rvalue_is_xvalue_HoldsCounted, member) as isize); let mut holder: p6_data_member_of_rvalue_is_xvalue_HoldsCounted = ::default(); - let mut from_lvalue: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves = - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::copy_from({ + let mut from_lvalue: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves = { + let mut __v = ::std::mem::MaybeUninit::< + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, + >::uninit(); + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::copy_from(__v.as_mut_ptr(), { &(*(&mut holder as *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted) .wrapping_byte_offset(pm) .cast::()) }); + __v.assume_init() + }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_9)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut moveCount_10)) == (0))); - let mut from_xvalue: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves = - p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::move_from({ + let mut from_xvalue: p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves = { + let mut __v = ::std::mem::MaybeUninit::< + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves, + >::uninit(); + p6_data_member_of_rvalue_is_xvalue_CountsCopiesAndMoves::move_from(__v.as_mut_ptr(), { &mut (*(&mut holder as *mut p6_data_member_of_rvalue_is_xvalue_HoldsCounted) .wrapping_byte_offset(pm) .cast::()) }); + __v.assume_init() + }; assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_9)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut moveCount_10)) == (1))); } diff --git a/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs b/tests/std/stmt.stmt/stmt.iter/out/refcount/stmt.while.rs index 03c4cfdeab..ebaa920f5a 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 @@ -22,11 +22,9 @@ pub struct p2_condition_variable_created_each_iteration_ConvertsToBool { pub value: i32, } impl p2_condition_variable_created_each_iteration_ConvertsToBool { - pub fn new(mut value: i32) -> Self { - let __this: p2_condition_variable_created_each_iteration_ConvertsToBool = - Self { value: value }; + pub fn new(this: Ptr, mut value: i32) { + this.write(Self { value: value }); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } pub fn test_2() { @@ -34,9 +32,17 @@ pub fn test_2() { let mut iterations: i32 = 0; 'loop_: loop { let condition: Value = - Rc::new(RefCell::new( - p2_condition_variable_created_each_iteration_ConvertsToBool::new({ remaining }), - )); + Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new( + ::zero_init(), + )); + p2_condition_variable_created_each_iteration_ConvertsToBool::new( + __v.as_pointer(), + { remaining }, + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| __p.as_pointer().destructor()); if !({ @@ -72,10 +78,9 @@ pub struct p2_continue_destroys_condition_variable_ConvertsToBool { pub value: i32, } impl p2_continue_destroys_condition_variable_ConvertsToBool { - pub fn new(mut value: i32) -> Self { - let __this: p2_continue_destroys_condition_variable_ConvertsToBool = Self { value: value }; + pub fn new(this: Ptr, mut value: i32) { + this.write(Self { value: value }); (*ctorCount_3.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } pub fn test_5() { @@ -84,9 +89,16 @@ pub fn test_5() { let mut completed: i32 = 0; 'loop_: loop { let condition: Value = - Rc::new(RefCell::new( - p2_continue_destroys_condition_variable_ConvertsToBool::new({ remaining }), - )); + Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new( + ::zero_init(), + )); + p2_continue_destroys_condition_variable_ConvertsToBool::new(__v.as_pointer(), { + remaining + }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| __p.as_pointer().destructor()); if !({ 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 4a08f01147..135d60aa6c 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 @@ -15,10 +15,9 @@ pub struct p2_condition_variable_created_each_iteration_ConvertsToBool { pub value: i32, } impl p2_condition_variable_created_each_iteration_ConvertsToBool { - pub unsafe fn new(mut value: i32) -> Self { - let mut this = Self { value: value }; + pub unsafe fn new(this: *mut Self, mut value: i32) { + this.write(Self { value: value }); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_1)).prefix_inc(); @@ -31,8 +30,15 @@ pub unsafe fn test_2() { let mut remaining: i32 = 2; let mut iterations: i32 = 0; 'loop_: loop { - let mut condition: p2_condition_variable_created_each_iteration_ConvertsToBool = - p2_condition_variable_created_each_iteration_ConvertsToBool::new({ remaining }); + let mut condition: p2_condition_variable_created_each_iteration_ConvertsToBool = { + let mut __v = ::std::mem::MaybeUninit::< + p2_condition_variable_created_each_iteration_ConvertsToBool, + >::uninit(); + p2_condition_variable_created_each_iteration_ConvertsToBool::new(__v.as_mut_ptr(), { + remaining + }); + __v.assume_init() + }; let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { (*__p).destructor() }); if !(unsafe { @@ -61,10 +67,9 @@ pub struct p2_continue_destroys_condition_variable_ConvertsToBool { pub value: i32, } impl p2_continue_destroys_condition_variable_ConvertsToBool { - pub unsafe fn new(mut value: i32) -> Self { - let mut this = Self { value: value }; + pub unsafe fn new(this: *mut Self, mut value: i32) { + this.write(Self { value: value }); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_3)).prefix_inc(); - this } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_4)).prefix_inc(); @@ -78,8 +83,15 @@ pub unsafe fn test_5() { let mut continued: i32 = 0; let mut completed: i32 = 0; 'loop_: loop { - let mut condition: p2_continue_destroys_condition_variable_ConvertsToBool = - p2_continue_destroys_condition_variable_ConvertsToBool::new({ remaining }); + let mut condition: p2_continue_destroys_condition_variable_ConvertsToBool = { + let mut __v = ::std::mem::MaybeUninit::< + p2_continue_destroys_condition_variable_ConvertsToBool, + >::uninit(); + p2_continue_destroys_condition_variable_ConvertsToBool::new(__v.as_mut_ptr(), { + remaining + }); + __v.assume_init() + }; let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { (*__p).destructor() }); if !(unsafe { p2_continue_destroys_condition_variable_ConvertsToBool::to_bool(&condition) }) 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 276c98201a..9e16b9d7a8 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 @@ -43,15 +43,13 @@ impl LifetimeTracked { } }); } - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; + pub fn new(this: Ptr) { + this.write(Self { uses: 0 }); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; + pub fn copy_from(this: Ptr, _a0: Ptr) { + this.write(Self { uses: 0 }); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Clone for LifetimeTracked { @@ -59,12 +57,21 @@ impl Clone for LifetimeTracked { let __src: Value = Rc::new(RefCell::new(LifetimeTracked { uses: self.uses.clone(), })); - LifetimeTracked::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } impl Default for LifetimeTracked { fn default() -> Self { - { LifetimeTracked::new() } + { + { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } thread_local!( @@ -77,7 +84,11 @@ pub fn test_6() { ({ LifetimeTracked::reset() }); let mut choice: i32 = 9; { - let guard: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + let guard: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_guard = std::mem::DropGuard::new(guard.clone(), |__p| __p.as_pointer().destructor()); let mut choice: i32 = 0; @@ -95,7 +106,11 @@ pub fn test_6() { assert!((else_runs_5.with(|rc| *rc.borrow()) == 1)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 1)); { - let guard: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + let guard: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_guard = std::mem::DropGuard::new(guard.clone(), |__p| __p.as_pointer().destructor()); let mut choice: i32 = 4; 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 9253fb3b98..1001395d8f 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 @@ -43,15 +43,13 @@ impl LifetimeTracked { } }); } - pub fn new() -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; + pub fn new(this: Ptr) { + this.write(Self { uses: 0 }); (*ctorCount_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: LifetimeTracked = Self { uses: 0 }; + pub fn copy_from(this: Ptr, _a0: Ptr) { + this.write(Self { uses: 0 }); (*copyCount_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Clone for LifetimeTracked { @@ -59,12 +57,21 @@ impl Clone for LifetimeTracked { let __src: Value = Rc::new(RefCell::new(LifetimeTracked { uses: self.uses.clone(), })); - LifetimeTracked::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } impl Default for LifetimeTracked { fn default() -> Self { - { LifetimeTracked::new() } + { + { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } thread_local!( @@ -128,7 +135,11 @@ pub fn test_10() { ({ LifetimeTracked::reset() }); let mut selector: i32 = 9; { - let guard: Value = Rc::new(RefCell::new(LifetimeTracked::new())); + let guard: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + LifetimeTracked::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_guard = std::mem::DropGuard::new(guard.clone(), |__p| __p.as_pointer().destructor()); let mut selector: i32 = 2; 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 fd22be5aba..4b6521145d 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 @@ -28,15 +28,13 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; + pub unsafe fn new(this: *mut Self) { + this.write(Self { uses: 0 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; + pub unsafe fn copy_from(this: *mut Self, _a0: *const LifetimeTracked) { + this.write(Self { uses: 0 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -52,12 +50,22 @@ impl LifetimeTracked { } impl Clone for LifetimeTracked { fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + unsafe { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::copy_from(__v.as_mut_ptr(), self as *const LifetimeTracked); + __v.assume_init() + } } } impl Default for LifetimeTracked { fn default() -> Self { - unsafe { LifetimeTracked::new() } + unsafe { + { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + } + } } } pub static mut then_runs_4: std::cell::LazyCell = @@ -68,7 +76,11 @@ pub unsafe fn test_6() { (unsafe { LifetimeTracked::reset() }); let mut choice: i32 = 9; { - let mut guard: LifetimeTracked = LifetimeTracked::new(); + let mut guard: LifetimeTracked = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; let _dtor_guard = std::mem::DropGuard::new(&raw mut guard, |__p| unsafe { (*__p).destructor() }); let mut choice: i32 = 0; @@ -86,7 +98,11 @@ pub unsafe fn test_6() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut else_runs_5)) == (1))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (1))); { - let mut guard: LifetimeTracked = LifetimeTracked::new(); + let mut guard: LifetimeTracked = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; let _dtor_guard = std::mem::DropGuard::new(&raw mut guard, |__p| unsafe { (*__p).destructor() }); let mut choice: i32 = 4; 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 177fa848ed..cf9c993bcb 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 @@ -28,15 +28,13 @@ impl LifetimeTracked { (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)) }; } - pub unsafe fn new() -> Self { - let mut this = Self { uses: 0 }; + pub unsafe fn new(this: *mut Self) { + this.write(Self { uses: 0 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)).prefix_inc(); - this } - pub unsafe fn copy_from(_a0: *const LifetimeTracked) -> Self { - let mut this = Self { uses: 0 }; + pub unsafe fn copy_from(this: *mut Self, _a0: *const LifetimeTracked) { + this.write(Self { uses: 0 }); (*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_1)).prefix_inc(); - this } pub unsafe fn destructor(&mut self) { (*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)).prefix_inc(); @@ -52,12 +50,22 @@ impl LifetimeTracked { } impl Clone for LifetimeTracked { fn clone(&self) -> Self { - unsafe { LifetimeTracked::copy_from(self as *const LifetimeTracked) } + unsafe { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::copy_from(__v.as_mut_ptr(), self as *const LifetimeTracked); + __v.assume_init() + } } } impl Default for LifetimeTracked { fn default() -> Self { - unsafe { LifetimeTracked::new() } + unsafe { + { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + } + } } } pub static mut matching_case_runs_4: std::cell::LazyCell = @@ -118,7 +126,11 @@ pub unsafe fn test_10() { (unsafe { LifetimeTracked::reset() }); let mut selector: i32 = 9; { - let mut guard: LifetimeTracked = LifetimeTracked::new(); + let mut guard: LifetimeTracked = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + LifetimeTracked::new(__v.as_mut_ptr()); + __v.assume_init() + }; let _dtor_guard = std::mem::DropGuard::new(&raw mut guard, |__p| unsafe { (*__p).destructor() }); let mut selector: i32 = 2; 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 7a91cf2945..bfa1709f33 100644 --- a/tests/std/temp/temp.spec/out/refcount/temp.inst.rs +++ b/tests/std/temp/temp.spec/out/refcount/temp.inst.rs @@ -13,8 +13,8 @@ pub struct p2_reference_does_not_instantiate_Member { pub value: i32, } impl p2_reference_does_not_instantiate_Member { - pub fn new_1(_a0: Ptr) -> Self { - Self { value: 2 } + pub fn new_1(this: Ptr, _a0: Ptr) { + this.write(Self { value: 2 }); } } impl Default for p2_reference_does_not_instantiate_Member { @@ -30,10 +30,10 @@ pub struct p2_reference_does_not_instantiate_Holder { pub member: p2_reference_does_not_instantiate_Member, } impl p2_reference_does_not_instantiate_Holder { - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { member: { (*_a0.upgrade().deref()).member }, - } + }); } } pub fn test_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 07ecd3fa3a..8655725321 100644 --- a/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs +++ b/tests/std/temp/temp.spec/out/unsafe/temp.inst.rs @@ -12,9 +12,11 @@ pub struct p2_reference_does_not_instantiate_Member { pub value: i32, } impl p2_reference_does_not_instantiate_Member { - pub unsafe fn new_1(_a0: *const p2_reference_does_not_instantiate_Wrapper_int_) -> Self { - let mut this = Self { value: 2 }; - this + pub unsafe fn new_1( + this: *mut Self, + _a0: *const p2_reference_does_not_instantiate_Wrapper_int_, + ) { + this.write(Self { value: 2 }); } } impl Default for p2_reference_does_not_instantiate_Member { @@ -28,11 +30,10 @@ pub struct p2_reference_does_not_instantiate_Holder { pub member: p2_reference_does_not_instantiate_Member, } impl p2_reference_does_not_instantiate_Holder { - pub unsafe fn move_from(_a0: *mut p2_reference_does_not_instantiate_Holder) -> Self { - let mut this = Self { + pub unsafe fn move_from(this: *mut Self, _a0: *mut p2_reference_does_not_instantiate_Holder) { + this.write(Self { member: (*_a0).member, - }; - this + }); } } pub unsafe fn test_0() { diff --git a/tests/std/utilities/utility/out/refcount/forward-helpers.rs b/tests/std/utilities/utility/out/refcount/forward-helpers.rs index df3a371cef..a134cb75a0 100644 --- a/tests/std/utilities/utility/out/refcount/forward-helpers.rs +++ b/tests/std/utilities/utility/out/refcount/forward-helpers.rs @@ -22,20 +22,19 @@ pub struct p6_forward_like_Movable { pub value: i32, } impl p6_forward_like_Movable { - pub fn new(mut value: i32) -> Self { - Self { value: value } + pub fn new(this: Ptr, mut value: i32) { + this.write(Self { value: value }); } - pub fn copy_from(other: Ptr) -> Self { - Self { + pub fn copy_from(this: Ptr, other: Ptr) { + this.write(Self { value: other.with(|__s| __s.value), - } + }); } - pub fn move_from(other: Ptr) -> Self { - let __this: p6_forward_like_Movable = Self { + pub fn move_from(this: Ptr, other: Ptr) { + this.write(Self { value: other.with(|__s| __s.value), - }; + }); field!(other, value).write(0); - __this } } impl Clone for p6_forward_like_Movable { @@ -44,7 +43,10 @@ impl Clone for p6_forward_like_Movable { Rc::new(RefCell::new(p6_forward_like_Movable { value: self.value.clone(), })); - p6_forward_like_Movable::copy_from(__src.as_pointer()) + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + p6_forward_like_Movable::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } #[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor)] @@ -55,26 +57,46 @@ pub struct p6_forward_like_Holder { pub member: p6_forward_like_Movable, } impl p6_forward_like_Holder { - pub fn move_from(_a0: Ptr) -> Self { - Self { - member: p6_forward_like_Movable::move_from({ field_ptr!(_a0, member) }), - } + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { + member: { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + p6_forward_like_Movable::move_from(__v.as_pointer(), { field_ptr!(_a0, member) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + }); } } impl Default for p6_forward_like_Holder { fn default() -> Self { { p6_forward_like_Holder { - member: p6_forward_like_Movable::new({ 1 }), + member: { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + p6_forward_like_Movable::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, } } } } pub fn take_1(self_: Ptr) -> p6_forward_like_Movable { - return p6_forward_like_Movable::copy_from({ field_ptr!(self_, member) }); + return { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + p6_forward_like_Movable::copy_from(__v.as_pointer(), { field_ptr!(self_, member) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; } pub fn take_2(self_: Ptr) -> p6_forward_like_Movable { - return p6_forward_like_Movable::move_from({ field_ptr!(self_, member) }); + return { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + p6_forward_like_Movable::move_from(__v.as_pointer(), { field_ptr!(self_, member) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; } pub fn test_3() { let holder: Value = @@ -92,15 +114,14 @@ pub struct p9_move_Movable { pub value: i32, } impl p9_move_Movable { - pub fn new(mut value: i32) -> Self { - Self { value: value } + pub fn new(this: Ptr, mut value: i32) { + this.write(Self { value: value }); } - pub fn move_from(other: Ptr) -> Self { - let __this: p9_move_Movable = Self { + pub fn move_from(this: Ptr, other: Ptr) { + this.write(Self { value: other.with(|__s| __s.value), - }; + }); field!(other, value).write(0); - __this } } pub fn test_4() { @@ -114,8 +135,16 @@ pub fn test_4() { ({ (moved_pointer).clone() } == { (target.as_pointer()) }) && ({ (pointer).clone() } == { (target.as_pointer()) }) ); - let source: Value = Rc::new(RefCell::new(p9_move_Movable::new({ 3 }))); - let mut destination: p9_move_Movable = p9_move_Movable::move_from({ source.as_pointer() }); + let source: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + p9_move_Movable::new(__v.as_pointer(), { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let mut destination: p9_move_Movable = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + p9_move_Movable::move_from(__v.as_pointer(), { source.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!(({ (destination.value == 3) && ({ (*source.borrow()).value } == 0) })); let strings: Value>> = Rc::new(RefCell::new(Vec::new())); let mut text: Vec = { @@ -151,28 +180,27 @@ pub struct p10_forward_in_template_A { pub moves: i32, } impl p10_forward_in_template_A { - pub fn new(mut value: i32) -> Self { - Self { + pub fn new(this: Ptr, mut value: i32) { + this.write(Self { value: value, copies: 0, moves: 0, - } + }); } - pub fn copy_from(other: Ptr) -> Self { - Self { + pub fn copy_from(this: Ptr, other: Ptr) { + this.write(Self { value: other.with(|__s| __s.value), copies: (other.with(|__s| __s.copies) + 1), moves: 0, - } + }); } - pub fn move_from(other: Ptr) -> Self { - let __this: p10_forward_in_template_A = Self { + pub fn move_from(this: Ptr, other: Ptr) { + this.write(Self { value: other.with(|__s| __s.value), copies: 0, moves: (other.with(|__s| __s.moves) + 1), - }; + }); field!(other, value).write(0); - __this } } impl Clone for p10_forward_in_template_A { @@ -183,7 +211,10 @@ impl Clone for p10_forward_in_template_A { copies: self.copies.clone(), moves: self.moves.clone(), })); - p10_forward_in_template_A::copy_from(__src.as_pointer()) + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + p10_forward_in_template_A::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } impl Default for p10_forward_in_template_A { @@ -198,14 +229,28 @@ impl Default for p10_forward_in_template_A { } } pub fn make_5(source: Ptr) -> p10_forward_in_template_A { - return p10_forward_in_template_A::copy_from({ (source).clone() }); + return { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + p10_forward_in_template_A::copy_from(__v.as_pointer(), { (source).clone() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; } pub fn make_6(source: Ptr) -> p10_forward_in_template_A { - return p10_forward_in_template_A::move_from({ (source).clone() }); + return { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + p10_forward_in_template_A::move_from(__v.as_pointer(), { (source).clone() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; } pub fn test_7() { - let a: Value = - Rc::new(RefCell::new(p10_forward_in_template_A::new({ 1 }))); + let a: Value = Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + p10_forward_in_template_A::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let mut copied: p10_forward_in_template_A = ({ make_5(a.as_pointer()) }); assert!(((copied.value == 1) && (copied.copies == 1)) && (copied.moves == 0)); assert!(({ ({ (*a.borrow()).value } == 1) })); @@ -221,20 +266,19 @@ pub struct p11_move_if_noexcept_NoexceptMove { pub value: i32, } impl p11_move_if_noexcept_NoexceptMove { - pub fn new(mut value: i32) -> Self { - Self { value: value } + pub fn new(this: Ptr, mut value: i32) { + this.write(Self { value: value }); } - pub fn copy_from(other: Ptr) -> Self { - Self { + pub fn copy_from(this: Ptr, other: Ptr) { + this.write(Self { value: other.with(|__s| __s.value), - } + }); } - pub fn move_from(other: Ptr) -> Self { - let __this: p11_move_if_noexcept_NoexceptMove = Self { + pub fn move_from(this: Ptr, other: Ptr) { + this.write(Self { value: other.with(|__s| __s.value), - }; + }); field!(other, value).write(0); - __this } } impl Clone for p11_move_if_noexcept_NoexceptMove { @@ -243,7 +287,11 @@ impl Clone for p11_move_if_noexcept_NoexceptMove { Rc::new(RefCell::new(p11_move_if_noexcept_NoexceptMove { value: self.value.clone(), })); - p11_move_if_noexcept_NoexceptMove::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new( + ::zero_init(), + )); + p11_move_if_noexcept_NoexceptMove::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } #[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] @@ -254,20 +302,19 @@ pub struct p11_move_if_noexcept_ThrowingMove { pub value: i32, } impl p11_move_if_noexcept_ThrowingMove { - pub fn new(mut value: i32) -> Self { - Self { value: value } + pub fn new(this: Ptr, mut value: i32) { + this.write(Self { value: value }); } - pub fn copy_from(other: Ptr) -> Self { - Self { + pub fn copy_from(this: Ptr, other: Ptr) { + this.write(Self { value: other.with(|__s| __s.value), - } + }); } - pub fn move_from(other: Ptr) -> Self { - let __this: p11_move_if_noexcept_ThrowingMove = Self { + pub fn move_from(this: Ptr, other: Ptr) { + this.write(Self { value: other.with(|__s| __s.value), - }; + }); field!(other, value).write(0); - __this } } impl Clone for p11_move_if_noexcept_ThrowingMove { @@ -276,19 +323,45 @@ impl Clone for p11_move_if_noexcept_ThrowingMove { Rc::new(RefCell::new(p11_move_if_noexcept_ThrowingMove { value: self.value.clone(), })); - p11_move_if_noexcept_ThrowingMove::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new( + ::zero_init(), + )); + p11_move_if_noexcept_ThrowingMove::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } pub fn test_8() { - let moved_from: Value = - Rc::new(RefCell::new(p11_move_if_noexcept_NoexceptMove::new({ 1 }))); - let mut moved: p11_move_if_noexcept_NoexceptMove = - p11_move_if_noexcept_NoexceptMove::move_from({ moved_from.as_pointer() }); + let moved_from: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new( + ::zero_init(), + )); + p11_move_if_noexcept_NoexceptMove::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let mut moved: p11_move_if_noexcept_NoexceptMove = { + let __v: Value = Rc::new(RefCell::new( + ::zero_init(), + )); + p11_move_if_noexcept_NoexceptMove::move_from(__v.as_pointer(), { moved_from.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!(({ (moved.value == 1) && ({ (*moved_from.borrow()).value } == 0) })); - let copied_from: Value = - Rc::new(RefCell::new(p11_move_if_noexcept_ThrowingMove::new({ 2 }))); - let mut copied: p11_move_if_noexcept_ThrowingMove = - p11_move_if_noexcept_ThrowingMove::copy_from({ copied_from.as_pointer() }); + let copied_from: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new( + ::zero_init(), + )); + p11_move_if_noexcept_ThrowingMove::new(__v.as_pointer(), { 2 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let mut copied: p11_move_if_noexcept_ThrowingMove = { + let __v: Value = Rc::new(RefCell::new( + ::zero_init(), + )); + p11_move_if_noexcept_ThrowingMove::copy_from(__v.as_pointer(), { + copied_from.as_pointer() + }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!(({ (copied.value == 2) && ({ (*copied_from.borrow()).value } == 2) })); } pub fn main() { diff --git a/tests/std/utilities/utility/out/refcount/forward.rs b/tests/std/utilities/utility/out/refcount/forward.rs index 386c913920..1edadbf2a1 100644 --- a/tests/std/utilities/utility/out/refcount/forward.rs +++ b/tests/std/utilities/utility/out/refcount/forward.rs @@ -51,29 +51,45 @@ pub struct p10_move_constructor_A { pub value: i32, } impl p10_move_constructor_A { - pub fn new(mut value: i32) -> Self { - Self { value: value } + pub fn new(this: Ptr, mut value: i32) { + this.write(Self { value: value }); } - pub fn move_from(other: Ptr) -> Self { - let __this: p10_move_constructor_A = Self { + pub fn move_from(this: Ptr, other: Ptr) { + this.write(Self { value: other.with(|__s| __s.value), - }; + }); field!(other, value).write(0); - __this } } pub fn test_2() { - let source: Value = - Rc::new(RefCell::new(p10_move_constructor_A::new({ 1 }))); - let mut target: p10_move_constructor_A = - p10_move_constructor_A::move_from({ source.as_pointer() }); + let source: Value = Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + p10_move_constructor_A::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let mut target: p10_move_constructor_A = { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + p10_move_constructor_A::move_from(__v.as_pointer(), { source.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((target.value == 1)); assert!(({ ({ (*source.borrow()).value } == 0) })); let mut values: Vec = Vec::new(); - let element: Value = - Rc::new(RefCell::new(p10_move_constructor_A::new({ 2 }))); + let element: Value = Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + p10_move_constructor_A::new(__v.as_pointer(), { 2 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); { - let __a1 = p10_move_constructor_A::move_from({ element.as_pointer() }); + let __a1 = { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + p10_move_constructor_A::move_from(__v.as_pointer(), { element.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; values.push(__a1) }; assert!((values[0_usize].value == 2)); diff --git a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs index 80928ab390..3b64697b8e 100644 --- a/tests/std/utilities/utility/out/unsafe/forward-helpers.rs +++ b/tests/std/utilities/utility/out/unsafe/forward-helpers.rs @@ -21,27 +21,31 @@ pub struct p6_forward_like_Movable { pub value: i32, } impl p6_forward_like_Movable { - pub unsafe fn new(mut value: i32) -> Self { - let mut this = Self { value: value }; - this + pub unsafe fn new(this: *mut Self, mut value: i32) { + this.write(Self { value: value }); } - pub unsafe fn copy_from(other: *const p6_forward_like_Movable) -> Self { - let mut this = Self { + pub unsafe fn copy_from(this: *mut Self, other: *const p6_forward_like_Movable) { + this.write(Self { value: (*other).value, - }; - this + }); } - pub unsafe fn move_from(other: *mut p6_forward_like_Movable) -> Self { - let mut this = Self { + pub unsafe fn move_from(this: *mut Self, other: *mut p6_forward_like_Movable) { + this.write(Self { value: (*other).value, - }; + }); (*other).value = 0; - this } } impl Clone for p6_forward_like_Movable { fn clone(&self) -> Self { - unsafe { p6_forward_like_Movable::copy_from(self as *const p6_forward_like_Movable) } + unsafe { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + p6_forward_like_Movable::copy_from( + __v.as_mut_ptr(), + self as *const p6_forward_like_Movable, + ); + __v.assume_init() + } } } #[repr(C)] @@ -50,27 +54,42 @@ pub struct p6_forward_like_Holder { pub member: p6_forward_like_Movable, } impl p6_forward_like_Holder { - pub unsafe fn move_from(_a0: *mut p6_forward_like_Holder) -> Self { - let mut this = Self { - member: p6_forward_like_Movable::move_from({ &mut (*_a0).member }), - }; - this + pub unsafe fn move_from(this: *mut Self, _a0: *mut p6_forward_like_Holder) { + this.write(Self { + member: { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + p6_forward_like_Movable::move_from(__v.as_mut_ptr(), { &mut (*_a0).member }); + __v.assume_init() + }, + }); } } impl Default for p6_forward_like_Holder { fn default() -> Self { unsafe { p6_forward_like_Holder { - member: p6_forward_like_Movable::new({ 1 }), + member: { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + p6_forward_like_Movable::new(__v.as_mut_ptr(), { 1 }); + __v.assume_init() + }, } } } } pub unsafe fn take_1(self_: *mut p6_forward_like_Holder) -> p6_forward_like_Movable { - return p6_forward_like_Movable::copy_from({ &(*self_).member }); + return { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + p6_forward_like_Movable::copy_from(__v.as_mut_ptr(), { &(*self_).member }); + __v.assume_init() + }; } pub unsafe fn take_2(self_: *mut p6_forward_like_Holder) -> p6_forward_like_Movable { - return p6_forward_like_Movable::move_from({ &mut (*self_).member }); + return { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + p6_forward_like_Movable::move_from(__v.as_mut_ptr(), { &mut (*self_).member }); + __v.assume_init() + }; } pub unsafe fn test_3() { let mut holder: p6_forward_like_Holder = ::default(); @@ -86,16 +105,14 @@ pub struct p9_move_Movable { pub value: i32, } impl p9_move_Movable { - pub unsafe fn new(mut value: i32) -> Self { - let mut this = Self { value: value }; - this + pub unsafe fn new(this: *mut Self, mut value: i32) { + this.write(Self { value: value }); } - pub unsafe fn move_from(other: *mut p9_move_Movable) -> Self { - let mut this = Self { + pub unsafe fn move_from(this: *mut Self, other: *mut p9_move_Movable) { + this.write(Self { value: (*other).value, - }; + }); (*other).value = 0; - this } } pub unsafe fn test_4() { @@ -108,8 +125,16 @@ pub unsafe fn test_4() { assert!( ((moved_pointer) == (&mut target as *mut i32)) && ((pointer) == (&mut target as *mut i32)) ); - let mut source: p9_move_Movable = p9_move_Movable::new({ 3 }); - let mut destination: p9_move_Movable = p9_move_Movable::move_from({ &mut source }); + let mut source: p9_move_Movable = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + p9_move_Movable::new(__v.as_mut_ptr(), { 3 }); + __v.assume_init() + }; + let mut destination: p9_move_Movable = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + p9_move_Movable::move_from(__v.as_mut_ptr(), { &mut source }); + __v.assume_init() + }; assert!(((destination.value) == (3)) && ((source.value) == (0))); let mut strings: Vec> = Vec::new(); let mut text: Vec = std::slice::from_raw_parts( @@ -140,35 +165,39 @@ pub struct p10_forward_in_template_A { pub moves: i32, } impl p10_forward_in_template_A { - pub unsafe fn new(mut value: i32) -> Self { - let mut this = Self { + pub unsafe fn new(this: *mut Self, mut value: i32) { + this.write(Self { value: value, copies: 0, moves: 0, - }; - this + }); } - pub unsafe fn copy_from(other: *const p10_forward_in_template_A) -> Self { - let mut this = Self { + pub unsafe fn copy_from(this: *mut Self, other: *const p10_forward_in_template_A) { + this.write(Self { value: (*other).value, copies: (((*other).copies) + (1)), moves: 0, - }; - this + }); } - pub unsafe fn move_from(other: *mut p10_forward_in_template_A) -> Self { - let mut this = Self { + pub unsafe fn move_from(this: *mut Self, other: *mut p10_forward_in_template_A) { + this.write(Self { value: (*other).value, copies: 0, moves: (((*other).moves) + (1)), - }; + }); (*other).value = 0; - this } } impl Clone for p10_forward_in_template_A { fn clone(&self) -> Self { - unsafe { p10_forward_in_template_A::copy_from(self as *const p10_forward_in_template_A) } + unsafe { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + p10_forward_in_template_A::copy_from( + __v.as_mut_ptr(), + self as *const p10_forward_in_template_A, + ); + __v.assume_init() + } } } impl Default for p10_forward_in_template_A { @@ -183,13 +212,25 @@ impl Default for p10_forward_in_template_A { } } pub unsafe fn make_5(source: *mut p10_forward_in_template_A) -> p10_forward_in_template_A { - return p10_forward_in_template_A::copy_from({ source }); + return { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + p10_forward_in_template_A::copy_from(__v.as_mut_ptr(), { source }); + __v.assume_init() + }; } pub unsafe fn make_6(source: *mut p10_forward_in_template_A) -> p10_forward_in_template_A { - return p10_forward_in_template_A::move_from({ source }); + return { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + p10_forward_in_template_A::move_from(__v.as_mut_ptr(), { source }); + __v.assume_init() + }; } pub unsafe fn test_7() { - let mut a: p10_forward_in_template_A = p10_forward_in_template_A::new({ 1 }); + let mut a: p10_forward_in_template_A = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + p10_forward_in_template_A::new(__v.as_mut_ptr(), { 1 }); + __v.assume_init() + }; let mut copied: p10_forward_in_template_A = (unsafe { make_5(&mut a) }); assert!((((copied.value) == (1)) && ((copied.copies) == (1))) && ((copied.moves) == (0))); assert!(((a.value) == (1))); @@ -204,30 +245,30 @@ pub struct p11_move_if_noexcept_NoexceptMove { pub value: i32, } impl p11_move_if_noexcept_NoexceptMove { - pub unsafe fn new(mut value: i32) -> Self { - let mut this = Self { value: value }; - this + pub unsafe fn new(this: *mut Self, mut value: i32) { + this.write(Self { value: value }); } - pub unsafe fn copy_from(other: *const p11_move_if_noexcept_NoexceptMove) -> Self { - let mut this = Self { + pub unsafe fn copy_from(this: *mut Self, other: *const p11_move_if_noexcept_NoexceptMove) { + this.write(Self { value: (*other).value, - }; - this + }); } - pub unsafe fn move_from(other: *mut p11_move_if_noexcept_NoexceptMove) -> Self { - let mut this = Self { + pub unsafe fn move_from(this: *mut Self, other: *mut p11_move_if_noexcept_NoexceptMove) { + this.write(Self { value: (*other).value, - }; + }); (*other).value = 0; - this } } impl Clone for p11_move_if_noexcept_NoexceptMove { fn clone(&self) -> Self { unsafe { + let mut __v = ::std::mem::MaybeUninit::::uninit(); p11_move_if_noexcept_NoexceptMove::copy_from( + __v.as_mut_ptr(), self as *const p11_move_if_noexcept_NoexceptMove, - ) + ); + __v.assume_init() } } } @@ -238,43 +279,55 @@ pub struct p11_move_if_noexcept_ThrowingMove { pub value: i32, } impl p11_move_if_noexcept_ThrowingMove { - pub unsafe fn new(mut value: i32) -> Self { - let mut this = Self { value: value }; - this + pub unsafe fn new(this: *mut Self, mut value: i32) { + this.write(Self { value: value }); } - pub unsafe fn copy_from(other: *const p11_move_if_noexcept_ThrowingMove) -> Self { - let mut this = Self { + pub unsafe fn copy_from(this: *mut Self, other: *const p11_move_if_noexcept_ThrowingMove) { + this.write(Self { value: (*other).value, - }; - this + }); } - pub unsafe fn move_from(other: *mut p11_move_if_noexcept_ThrowingMove) -> Self { - let mut this = Self { + pub unsafe fn move_from(this: *mut Self, other: *mut p11_move_if_noexcept_ThrowingMove) { + this.write(Self { value: (*other).value, - }; + }); (*other).value = 0; - this } } impl Clone for p11_move_if_noexcept_ThrowingMove { fn clone(&self) -> Self { unsafe { + let mut __v = ::std::mem::MaybeUninit::::uninit(); p11_move_if_noexcept_ThrowingMove::copy_from( + __v.as_mut_ptr(), self as *const p11_move_if_noexcept_ThrowingMove, - ) + ); + __v.assume_init() } } } pub unsafe fn test_8() { - let mut moved_from: p11_move_if_noexcept_NoexceptMove = - p11_move_if_noexcept_NoexceptMove::new({ 1 }); - let mut moved: p11_move_if_noexcept_NoexceptMove = - p11_move_if_noexcept_NoexceptMove::move_from({ &mut moved_from }); + let mut moved_from: p11_move_if_noexcept_NoexceptMove = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + p11_move_if_noexcept_NoexceptMove::new(__v.as_mut_ptr(), { 1 }); + __v.assume_init() + }; + let mut moved: p11_move_if_noexcept_NoexceptMove = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + p11_move_if_noexcept_NoexceptMove::move_from(__v.as_mut_ptr(), { &mut moved_from }); + __v.assume_init() + }; assert!(((moved.value) == (1)) && ((moved_from.value) == (0))); - let mut copied_from: p11_move_if_noexcept_ThrowingMove = - p11_move_if_noexcept_ThrowingMove::new({ 2 }); - let mut copied: p11_move_if_noexcept_ThrowingMove = - p11_move_if_noexcept_ThrowingMove::copy_from({ &copied_from }); + let mut copied_from: p11_move_if_noexcept_ThrowingMove = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + p11_move_if_noexcept_ThrowingMove::new(__v.as_mut_ptr(), { 2 }); + __v.assume_init() + }; + let mut copied: p11_move_if_noexcept_ThrowingMove = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + p11_move_if_noexcept_ThrowingMove::copy_from(__v.as_mut_ptr(), { &copied_from }); + __v.assume_init() + }; assert!(((copied.value) == (2)) && ((copied_from.value) == (2))); } pub fn main() { diff --git a/tests/std/utilities/utility/out/unsafe/forward.rs b/tests/std/utilities/utility/out/unsafe/forward.rs index 09f48ecad5..9e95d2bc98 100644 --- a/tests/std/utilities/utility/out/unsafe/forward.rs +++ b/tests/std/utilities/utility/out/unsafe/forward.rs @@ -48,27 +48,41 @@ pub struct p10_move_constructor_A { pub value: i32, } impl p10_move_constructor_A { - pub unsafe fn new(mut value: i32) -> Self { - let mut this = Self { value: value }; - this + pub unsafe fn new(this: *mut Self, mut value: i32) { + this.write(Self { value: value }); } - pub unsafe fn move_from(other: *mut p10_move_constructor_A) -> Self { - let mut this = Self { + pub unsafe fn move_from(this: *mut Self, other: *mut p10_move_constructor_A) { + this.write(Self { value: (*other).value, - }; + }); (*other).value = 0; - this } } pub unsafe fn test_2() { - let mut source: p10_move_constructor_A = p10_move_constructor_A::new({ 1 }); - let mut target: p10_move_constructor_A = p10_move_constructor_A::move_from({ &mut source }); + let mut source: p10_move_constructor_A = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + p10_move_constructor_A::new(__v.as_mut_ptr(), { 1 }); + __v.assume_init() + }; + let mut target: p10_move_constructor_A = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + p10_move_constructor_A::move_from(__v.as_mut_ptr(), { &mut source }); + __v.assume_init() + }; assert!(((target.value) == (1))); assert!(((source.value) == (0))); let mut values: Vec = Vec::new(); - let mut element: p10_move_constructor_A = p10_move_constructor_A::new({ 2 }); + let mut element: p10_move_constructor_A = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + p10_move_constructor_A::new(__v.as_mut_ptr(), { 2 }); + __v.assume_init() + }; { - let __a1 = p10_move_constructor_A::move_from({ &mut element }); + let __a1 = { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + p10_move_constructor_A::move_from(__v.as_mut_ptr(), { &mut element }); + __v.assume_init() + }; values.push(__a1) }; assert!(((values[(0_usize)].value) == (2))); diff --git a/tests/ub/out/refcount/ctor_ref_member.rs b/tests/ub/out/refcount/ctor_ref_member.rs index 4c91ad922e..005a280a81 100644 --- a/tests/ub/out/refcount/ctor_ref_member.rs +++ b/tests/ub/out/refcount/ctor_ref_member.rs @@ -15,8 +15,8 @@ pub struct S { pub r: Ptr, } impl S { - pub fn new(x: Ptr) -> Self { - Self { r: (x).clone() } + pub fn new(this: Ptr, x: Ptr) { + this.write(Self { r: (x).clone() }); } } pub fn main() { @@ -26,7 +26,11 @@ pub fn main() { fn main_0() -> i32 { let mut s: S = { let __tmp_0: Value = Rc::new(RefCell::new(5)); - S::new({ __tmp_0.as_pointer() }) + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + S::new(__v.as_pointer(), { __tmp_0.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } }; assert!(((s.r.read()) == 5)); return 0; diff --git a/tests/ub/out/unsafe/ctor_ref_member.rs b/tests/ub/out/unsafe/ctor_ref_member.rs index 19a18e0932..25781947f6 100644 --- a/tests/ub/out/unsafe/ctor_ref_member.rs +++ b/tests/ub/out/unsafe/ctor_ref_member.rs @@ -13,9 +13,8 @@ pub struct S { pub r: *const i32, } impl S { - pub unsafe fn new(x: *const i32) -> Self { - let mut this = Self { r: x }; - this + pub unsafe fn new(this: *mut Self, x: *const i32) { + this.write(Self { r: x }); } } pub fn main() { @@ -27,7 +26,11 @@ pub fn main() { unsafe fn main_0() -> i32 { let mut s: S = { let mut __tmp_0: i32 = 5; - S::new({ &mut __tmp_0 }) + { + let mut __v = ::std::mem::MaybeUninit::::uninit(); + S::new(__v.as_mut_ptr(), { &mut __tmp_0 }); + __v.assume_init() + } }; assert!(((*s.r) == (5))); return 0; diff --git a/tests/unit/out/refcount/10_struct.rs b/tests/unit/out/refcount/10_struct.rs index 0649747310..ccf6f40eea 100644 --- a/tests/unit/out/refcount/10_struct.rs +++ b/tests/unit/out/refcount/10_struct.rs @@ -32,8 +32,8 @@ pub struct Partial { pub p: Ptr, } impl Partial { - pub fn new_1(mut q: Ptr) -> Self { - Self { p: (q).clone() } + pub fn new_1(this: Ptr, mut q: Ptr) { + this.write(Self { p: (q).clone() }); } } impl Default for Partial { @@ -68,7 +68,11 @@ fn main_0() -> i32 { adj: Ptr::>::null(), }; let arr: Value> = Rc::new(RefCell::new(Box::new([3, 1, 4]))); - let mut it: Partial = Partial::new_1({ arr.decay() }); + let mut it: Partial = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Partial::new_1(__v.as_pointer(), { arr.decay() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; if ({ (it.p).clone() } != { arr.decay() }) { return 1; } diff --git a/tests/unit/out/refcount/any.rs b/tests/unit/out/refcount/any.rs index 1e91846425..fcf37d07be 100644 --- a/tests/unit/out/refcount/any.rs +++ b/tests/unit/out/refcount/any.rs @@ -15,8 +15,8 @@ pub struct Point { pub y: i32, } impl Point { - pub fn new(mut x: i32, mut y: i32) -> Self { - Self { x: x, y: y } + pub fn new(this: Ptr, mut x: i32, mut y: i32) { + this.write(Self { x: x, y: y }); } } pub fn main() { @@ -24,9 +24,12 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let a: Value>> = Rc::new(RefCell::new(Some(Rc::new( - RefCell::new(Point::new({ 3 }, { 4 })), - )))); + let a: Value>> = + Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Point::new(__v.as_pointer(), { 3 }, { 4 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }))))); assert!(({ (*a.borrow()).is_some() })); let mut p: Ptr = { let mut __tmp_0 = { (a.as_pointer()) }; @@ -61,7 +64,13 @@ fn main_0() -> i32 { .is_null() ); let q: Ptr = { - let mut __tmp_2 = { Point::new({ 5 }, { 6 }) }; + let mut __tmp_2 = { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Point::new(__v.as_pointer(), { 5 }, { 6 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + }; let __value: Value = Rc::new(RefCell::new(__tmp_2)); let __ptr = __value.as_pointer(); (*a.borrow_mut()) = Some(__value); diff --git a/tests/unit/out/refcount/array_of_noncopy_struct.rs b/tests/unit/out/refcount/array_of_noncopy_struct.rs index 983eee4889..45764f45c8 100644 --- a/tests/unit/out/refcount/array_of_noncopy_struct.rs +++ b/tests/unit/out/refcount/array_of_noncopy_struct.rs @@ -16,11 +16,11 @@ pub struct NonCopy { pub tag: i32, } impl NonCopy { - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { data: field!(_a0, data).with_mut(std::mem::take), tag: { (*_a0.upgrade().deref()).tag }, - } + }); } } impl Default for NonCopy { diff --git a/tests/unit/out/refcount/cast.rs b/tests/unit/out/refcount/cast.rs index a58c8d5bd9..64cdbefd45 100644 --- a/tests/unit/out/refcount/cast.rs +++ b/tests/unit/out/refcount/cast.rs @@ -64,11 +64,11 @@ pub struct Bag { pub items: Vec, } impl Bag { - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { n: { (*_a0.upgrade().deref()).n }, items: field!(_a0, items).with_mut(std::mem::take), - } + }); } } pub fn adjacent_arrays_0() { diff --git a/tests/unit/out/refcount/class_templates.rs b/tests/unit/out/refcount/class_templates.rs index f491170971..31e490dc2b 100644 --- a/tests/unit/out/refcount/class_templates.rs +++ b/tests/unit/out/refcount/class_templates.rs @@ -16,10 +16,10 @@ pub struct MyContainer_int_ { vec_: Vec, } impl MyContainer_int_ { - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { vec_: field!(_a0, vec_).with_mut(std::mem::take), - } + }); } } #[derive( @@ -32,10 +32,10 @@ pub struct MyContainer_char_ { vec_: Vec, } impl MyContainer_char_ { - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { vec_: field!(_a0, vec_).with_mut(std::mem::take), - } + }); } } #[derive( @@ -48,10 +48,10 @@ pub struct MyContainer_float_ { vec_: Vec, } impl MyContainer_float_ { - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { vec_: field!(_a0, vec_).with_mut(std::mem::take), - } + }); } } #[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] diff --git a/tests/unit/out/refcount/constructor.rs b/tests/unit/out/refcount/constructor.rs index 7cdc4b8e32..e16286d62f 100644 --- a/tests/unit/out/refcount/constructor.rs +++ b/tests/unit/out/refcount/constructor.rs @@ -19,12 +19,10 @@ pub struct S { pub v: i32, } impl S { - pub fn new(mut init: i32) -> Self { - let __this: Value = Rc::new(RefCell::new(Self { v: init })); - let this: Ptr = __this.as_pointer(); + pub fn new(this: Ptr, mut init: i32) { + this.write(Self { v: init }); ({ SImpl::mut_method(&this) }); total_0.with(|rc| *rc.borrow_mut() += ({ SImpl::const_method(&this) })); - Rc::try_unwrap(__this).ok().unwrap().into_inner() } } #[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom)] @@ -37,29 +35,31 @@ pub struct Point { pub y: i32, } impl Point { - pub fn new_2(mut x: i32, mut y: i32) -> Self { - Self { x: x, y: y } + pub fn new_2(this: Ptr, mut x: i32, mut y: i32) { + this.write(Self { x: x, y: y }); } - pub fn new_1(mut v: i32) -> Self { - let __this: Value = Rc::new(RefCell::new(Point::new_2({ v }, { (v + 1) }))); - let this: Ptr = __this.as_pointer(); + pub fn new_1(this: Ptr, mut v: i32) { + Point::new_2(this, { v }, { (v + 1) }); { field!(this, y).with_mut(|__v| *__v = *__v * 10) }; - Rc::try_unwrap(__this).ok().unwrap().into_inner() } - pub fn new_3() -> Self { - let __this: Value = Rc::new(RefCell::new(Point::new_1({ 4 }))); - let this: Ptr = __this.as_pointer(); + pub fn new_3(this: Ptr) { + Point::new_1(this, { 4 }); { field!(this, x).with_mut(|__v| *__v = *__v + 100) }; - Rc::try_unwrap(__this).ok().unwrap().into_inner() } } impl Default for Point { fn default() -> Self { - { Point::new_3() } + { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Point::new_3(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } pub fn main() { @@ -68,16 +68,28 @@ pub fn main() { } fn main_0() -> i32 { { - let s: Value = Rc::new(RefCell::new(S::new({ 3 }))); + let s: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + S::new(__v.as_pointer(), { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_s = std::mem::DropGuard::new(s.clone(), |__p| __p.as_pointer().destructor()); assert!(({ ({ (*s.borrow()).v } == 4) })); assert!((total_0.with(|rc| *rc.borrow()) == 8)); } assert!((total_0.with(|rc| *rc.borrow()) == 18)); - let mut p: Point = Point::new_3(); + let mut p: Point = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Point::new_3(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((p.x == 104)); assert!((p.y == 50)); - let mut q: Point = Point::new_1({ 7 }); + let mut q: Point = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Point::new_1(__v.as_pointer(), { 7 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((q.x == 7)); assert!((q.y == 80)); return 0; diff --git a/tests/unit/out/refcount/container_element_receiver.rs b/tests/unit/out/refcount/container_element_receiver.rs index bf53df83e0..28d82b9eaa 100644 --- a/tests/unit/out/refcount/container_element_receiver.rs +++ b/tests/unit/out/refcount/container_element_receiver.rs @@ -17,11 +17,11 @@ pub struct Holder { pub vec_: Vec, } impl Holder { - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { ref_: ({ (*_a0.upgrade().deref()).ref_.clone() }).clone(), vec_: field!(_a0, vec_).with_mut(std::mem::take), - } + }); } } pub fn pick_0(a: Ptr>, b: Ptr>, mut first: bool) -> Ptr> { diff --git a/tests/unit/out/refcount/container_field_addr.rs b/tests/unit/out/refcount/container_field_addr.rs index 1d3099efee..0ca55b5cd8 100644 --- a/tests/unit/out/refcount/container_field_addr.rs +++ b/tests/unit/out/refcount/container_field_addr.rs @@ -18,11 +18,11 @@ pub struct S { pub v: Vec, } impl S { - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { tag: { (*_a0.upgrade().deref()).tag }, v: field!(_a0, v).with_mut(std::mem::take), - } + }); } } pub fn add_0(mut v: Ptr>, mut k: i32) { diff --git a/tests/unit/out/refcount/copy_assign.rs b/tests/unit/out/refcount/copy_assign.rs index 0de866275c..d5f040f0c3 100644 --- a/tests/unit/out/refcount/copy_assign.rs +++ b/tests/unit/out/refcount/copy_assign.rs @@ -18,14 +18,14 @@ pub struct Partial { pub keep: i32, } impl Partial { - pub fn new(mut v: i32, mut keep: i32) -> Self { - Self { v: v, keep: keep } + pub fn new(this: Ptr, mut v: i32, mut keep: i32) { + this.write(Self { v: v, keep: keep }); } - pub fn copy_from(o: Ptr) -> Self { - Self { + pub fn copy_from(this: Ptr, o: Ptr) { + this.write(Self { v: o.with(|__s| __s.v), keep: o.with(|__s| __s.keep), - } + }); } } impl Clone for Partial { @@ -34,7 +34,9 @@ impl Clone for Partial { v: self.v.clone(), keep: self.keep.clone(), })); - Partial::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Partial::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } #[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] @@ -44,13 +46,20 @@ pub struct NonConstAssign { pub mark: i32, } impl NonConstAssign { - pub fn new() -> Self { - Self { mark: 0 } + pub fn new(this: Ptr) { + this.write(Self { mark: 0 }); } } impl Default for NonConstAssign { fn default() -> Self { - { NonConstAssign::new() } + { + { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + NonConstAssign::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } #[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign)] @@ -60,13 +69,19 @@ pub struct RefQualified { pub mark: i32, } impl RefQualified { - pub fn new() -> Self { - Self { mark: 0 } + pub fn new(this: Ptr) { + this.write(Self { mark: 0 }); } } impl Default for RefQualified { fn default() -> Self { - { RefQualified::new() } + { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + RefQualified::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } #[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign)] @@ -103,21 +118,22 @@ pub struct CopyCounted { pub v: i32, } impl CopyCounted { - pub fn new(mut v: i32) -> Self { - Self { v: v } + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { v: v }); } - pub fn copy_from(o: Ptr) -> Self { - let __this: CopyCounted = Self { + pub fn copy_from(this: Ptr, o: Ptr) { + this.write(Self { v: o.with(|__s| __s.v), - }; + }); (*copies_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Clone for CopyCounted { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(CopyCounted { v: self.v.clone() })); - CopyCounted::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + CopyCounted::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } #[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign)] @@ -148,9 +164,21 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let a: Value = Rc::new(RefCell::new(Partial::new({ 1 }, { 100 }))); - let b: Value = Rc::new(RefCell::new(Partial::new({ 2 }, { 200 }))); - let c: Value = Rc::new(RefCell::new(Partial::new({ 3 }, { 300 }))); + let a: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Partial::new(__v.as_pointer(), { 1 }, { 100 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let b: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Partial::new(__v.as_pointer(), { 2 }, { 200 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let c: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Partial::new(__v.as_pointer(), { 3 }, { 300 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); ({ PartialImpl::copy_assign(&a.as_pointer(), b.as_pointer()) }); assert!(({ ({ (*a.borrow()).v } == 2) && ({ (*a.borrow()).keep } == 100) })); assert!((assigns_0.with(|rc| *rc.borrow()) == 1)); @@ -168,7 +196,11 @@ fn main_0() -> i32 { }); assert!((assigns_0.with(|rc| *rc.borrow()) == 3)); ({ - let _o: Value = Rc::new(RefCell::new(Partial::new({ 9 }, { 900 }))); + let _o: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Partial::new(__v.as_pointer(), { 9 }, { 900 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); PartialImpl::copy_assign(&a.as_pointer(), _o.as_pointer()) }); assert!(({ ({ (*a.borrow()).v } == 9) && ({ (*a.borrow()).keep } == 100) })); @@ -187,8 +219,23 @@ fn main_0() -> i32 { assert!(({ ({ (*a.borrow()).v } == 2) })); assert!((assigns_0.with(|rc| *rc.borrow()) == 6)); let h: Value = Rc::new(RefCell::new(Holder { - p: Partial::new({ 4 }, { 40 }), - arr: Box::new([Partial::new({ 5 }, { 50 }), Partial::new({ 6 }, { 60 })]), + p: { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Partial::new(__v.as_pointer(), { 4 }, { 40 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + arr: Box::new([ + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Partial::new(__v.as_pointer(), { 5 }, { 50 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Partial::new(__v.as_pointer(), { 6 }, { 60 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + ]), })); ({ PartialImpl::copy_assign(&field_ptr!(h.as_pointer(), p), b.as_pointer()) }); ({ @@ -203,21 +250,60 @@ fn main_0() -> i32 { && (array_elem!(h.as_pointer(), arr, 1).with(|__s| __s.keep) == 60) ); assert!((assigns_0.with(|rc| *rc.borrow()) == 8)); - let n: Value = Rc::new(RefCell::new(NonConstAssign::new())); - let n1: Value = Rc::new(RefCell::new(NonConstAssign::new())); - let n2: Value = Rc::new(RefCell::new(NonConstAssign::new())); - let cn: Value = Rc::new(RefCell::new(NonConstAssign::new())); + let n: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + NonConstAssign::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let n1: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + NonConstAssign::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let n2: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + NonConstAssign::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let cn: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + NonConstAssign::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); ({ NonConstAssignImpl::operator_assign_2(&n1.as_pointer(), n.as_pointer()) }); ({ NonConstAssignImpl::operator_assign_3(&n2.as_pointer(), cn.as_pointer()) }); assert!(({ ({ (*n1.borrow()).mark } == 1) })); assert!(({ ({ (*n2.borrow()).mark } == 10) })); - let r: Value = Rc::new(RefCell::new(RefQualified::new())); - let r1: Value = Rc::new(RefCell::new(RefQualified::new())); + let r: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + RefQualified::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let r1: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + RefQualified::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); ({ RefQualifiedImpl::copy_assign(&r1.as_pointer(), r.as_pointer()) }); assert!(({ ({ (*r1.borrow()).mark } == 1) })); let h2: Value = Rc::new(RefCell::new(Holder { - p: Partial::new({ 7 }, { 70 }), - arr: Box::new([Partial::new({ 8 }, { 80 }), Partial::new({ 9 }, { 90 })]), + p: { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Partial::new(__v.as_pointer(), { 7 }, { 70 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + arr: Box::new([ + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Partial::new(__v.as_pointer(), { 8 }, { 80 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Partial::new(__v.as_pointer(), { 9 }, { 90 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + ]), })); ({ HolderImpl::copy_assign(&h2.as_pointer(), h.as_pointer()) }); assert!(({ ({ (*h2.borrow()).p.v } == 2) && ({ (*h2.borrow()).p.keep } == 70) })); @@ -226,17 +312,55 @@ fn main_0() -> i32 { && (array_elem!(h2.as_pointer(), arr, 1).with(|__s| __s.keep) == 90) ); assert!((assigns_0.with(|rc| *rc.borrow()) == 11)); - let cc1: Value = Rc::new(RefCell::new(CopyCounted::new({ 1 }))); - let cc2: Value = Rc::new(RefCell::new(CopyCounted::new({ 2 }))); + let cc1: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + CopyCounted::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let cc2: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + CopyCounted::new(__v.as_pointer(), { 2 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); ({ CopyCountedImpl::copy_assign(&cc1.as_pointer(), cc2.as_pointer()) }); assert!(({ ({ (*cc1.borrow()).v } == 2) })); let hc1: Value = Rc::new(RefCell::new(HasCopyCounted { - c: CopyCounted::new({ 1 }), - arr: Box::new([CopyCounted::new({ 2 }), CopyCounted::new({ 3 })]), + c: { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + CopyCounted::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + arr: Box::new([ + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + CopyCounted::new(__v.as_pointer(), { 2 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + CopyCounted::new(__v.as_pointer(), { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + ]), })); let hc2: Value = Rc::new(RefCell::new(HasCopyCounted { - c: CopyCounted::new({ 4 }), - arr: Box::new([CopyCounted::new({ 5 }), CopyCounted::new({ 6 })]), + c: { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + CopyCounted::new(__v.as_pointer(), { 4 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + arr: Box::new([ + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + CopyCounted::new(__v.as_pointer(), { 5 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + CopyCounted::new(__v.as_pointer(), { 6 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + ]), })); ({ HasCopyCountedImpl::copy_assign(&hc1.as_pointer(), hc2.as_pointer()) }); assert!( diff --git a/tests/unit/out/refcount/copy_ctor.rs b/tests/unit/out/refcount/copy_ctor.rs index 5ed6ba9b64..dbd2031117 100644 --- a/tests/unit/out/refcount/copy_ctor.rs +++ b/tests/unit/out/refcount/copy_ctor.rs @@ -17,21 +17,22 @@ pub struct Counted { pub v: i32, } impl Counted { - pub fn new(mut v: i32) -> Self { - Self { v: v } + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { v: v }); } - pub fn copy_from(o: Ptr) -> Self { - let __this: Counted = Self { + pub fn copy_from(this: Ptr, o: Ptr) { + this.write(Self { v: o.with(|__s| __s.v), - }; + }); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Clone for Counted { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Counted { v: self.v.clone() })); - Counted::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Counted::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } #[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign)] @@ -41,18 +42,18 @@ pub struct NonConst { pub mark: i32, } impl NonConst { - pub fn new() -> Self { - Self { mark: 0 } + pub fn new(this: Ptr) { + this.write(Self { mark: 0 }); } - pub fn new_1(o: Ptr) -> Self { - Self { + pub fn new_1(this: Ptr, o: Ptr) { + this.write(Self { mark: (o.with(|__s| __s.mark) + 1), - } + }); } - pub fn new_2(o: Ptr) -> Self { - Self { + pub fn new_2(this: Ptr, o: Ptr) { + this.write(Self { mark: (o.with(|__s| __s.mark) + 10), - } + }); } } impl Clone for NonConst { @@ -60,12 +61,20 @@ impl Clone for NonConst { let __src: Value = Rc::new(RefCell::new(NonConst { mark: self.mark.clone(), })); - NonConst::new_1(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + NonConst::new_1(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } impl Default for NonConst { fn default() -> Self { - { NonConst::new() } + { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + NonConst::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } #[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] @@ -76,19 +85,20 @@ pub struct Ignored { pub v: i32, } impl Ignored { - pub fn new(mut v: i32) -> Self { - Self { v: v } + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { v: v }); } - pub fn copy_from(_a0: Ptr) -> Self { - let __this: Ignored = Self { v: -1_i32 }; + pub fn copy_from(this: Ptr, _a0: Ptr) { + this.write(Self { v: -1_i32 }); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Clone for Ignored { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Ignored { v: self.v.clone() })); - Ignored::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Ignored::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } #[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CopyAssign)] @@ -122,18 +132,18 @@ pub struct Box_int_ { pub val: i32, } impl Box_int_ { - pub fn new(mut v: i32) -> Self { - Self { val: v } + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { val: v }); } - pub fn copy_from(o: Ptr) -> Self { - Self { + pub fn copy_from(this: Ptr, o: Ptr) { + this.write(Self { val: o.with(|__s| __s.val), - } + }); } - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { val: { (*_a0.upgrade().deref()).val }, - } + }); } } impl Clone for Box_int_ { @@ -141,7 +151,9 @@ impl Clone for Box_int_ { let __src: Value = Rc::new(RefCell::new(Box_int_ { val: self.val.clone(), })); - Box_int_::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Box_int_::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } #[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, Default)] @@ -152,10 +164,14 @@ pub struct Owner { pub box_: Box_int_, } impl Owner { - pub fn move_from(_a0: Ptr) -> Self { - Self { - box_: Box_int_::move_from({ field_ptr!(_a0, box_) }), - } + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { + box_: { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Box_int_::move_from(__v.as_pointer(), { field_ptr!(_a0, box_) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + }); } } #[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, CopyAssign, Default)] @@ -166,21 +182,22 @@ pub struct OutOfLine { pub v: i32, } impl OutOfLine { - pub fn new(mut v: i32) -> Self { - Self { v: v } + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { v: v }); } - pub fn copy_from(o: Ptr) -> Self { - let __this: OutOfLine = Self { + pub fn copy_from(this: Ptr, o: Ptr) { + this.write(Self { v: (o.with(|__s| __s.v) + 100), - }; + }); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Clone for OutOfLine { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(OutOfLine { v: self.v.clone() })); - OutOfLine::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + OutOfLine::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } impl OutOfLine {} @@ -191,12 +208,11 @@ pub struct Tracked { pub copied_from: i32, } impl Tracked { - pub fn copy_from(o: Ptr) -> Self { - let __this: Tracked = Self { copied_from: 0 }; + pub fn copy_from(this: Ptr, o: Ptr) { + this.write(Self { copied_from: 0 }); field!(o, copied_from).with_mut(|__v| { __v.prefix_inc(); }); - __this } } impl Clone for Tracked { @@ -204,7 +220,9 @@ impl Clone for Tracked { let __src: Value = Rc::new(RefCell::new(Tracked { copied_from: self.copied_from.clone(), })); - Tracked::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } impl Default for Tracked { @@ -221,35 +239,94 @@ pub fn by_value_2(mut c: Counted) -> i32 { return c.v; } pub fn make_3(mut v: i32) -> Counted { - let c: Value = Rc::new(RefCell::new(Counted::new({ v }))); - return Counted::copy_from({ c.as_pointer() }); + let c: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Counted::new(__v.as_pointer(), { v }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + return { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Counted::copy_from(__v.as_pointer(), { c.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; } pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let a: Value = Rc::new(RefCell::new(Counted::new({ 1 }))); - let mut b: Counted = Counted::copy_from({ a.as_pointer() }); - let mut c: Counted = Counted::copy_from({ a.as_pointer() }); - let mut d: Counted = Counted::copy_from({ a.as_pointer() }); + let a: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Counted::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let mut b: Counted = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Counted::copy_from(__v.as_pointer(), { a.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; + let mut c: Counted = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Counted::copy_from(__v.as_pointer(), { a.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; + let mut d: Counted = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Counted::copy_from(__v.as_pointer(), { a.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((copies_0.with(|rc| *rc.borrow()) == 3)); assert!(((b.v == 1) && (c.v == 1)) && (d.v == 1)); - assert!((({ by_value_2(Counted::copy_from({ a.as_pointer() },),) }) == 1)); + assert!( + (({ + by_value_2({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Counted::copy_from(__v.as_pointer(), { a.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }) + }) == 1) + ); assert!((copies_0.with(|rc| *rc.borrow()) == 4)); let mut e: Counted = ({ make_3(5) }); assert!((e.v == 5)); assert!((copies_0.with(|rc| *rc.borrow()) == 5)); - let mut f: Counted = Counted::new({ 6 }); + let mut f: Counted = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Counted::new(__v.as_pointer(), { 6 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((f.v == 6)); assert!((copies_0.with(|rc| *rc.borrow()) == 5)); - let g: Value = Rc::new(RefCell::new(Counted::new({ 7 }))); - let mut h: Counted = Counted::copy_from({ g.as_pointer() }); + let g: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Counted::new(__v.as_pointer(), { 7 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let mut h: Counted = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Counted::copy_from(__v.as_pointer(), { g.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((h.v == 7)); assert!((copies_0.with(|rc| *rc.borrow()) == 6)); let hold: Value = Rc::new(RefCell::new(Holder { - c: Counted::new({ 8 }), - arr: Box::new([Counted::new({ 9 }), Counted::new({ 10 })]), + c: { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Counted::new(__v.as_pointer(), { 8 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + arr: Box::new([ + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Counted::new(__v.as_pointer(), { 9 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Counted::new(__v.as_pointer(), { 10 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + ]), })); let mut hold2: Holder = (*hold.borrow()).clone(); assert!( @@ -263,31 +340,79 @@ fn main_0() -> i32 { }; assert!((vec_[0_usize].v == 1)); assert!((copies_0.with(|rc| *rc.borrow()) == 10)); - let i1: Value = Rc::new(RefCell::new(Ignored::new({ 1 }))); - let mut i2: Ignored = Ignored::copy_from({ i1.as_pointer() }); + let i1: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Ignored::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let mut i2: Ignored = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Ignored::copy_from(__v.as_pointer(), { i1.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!(({ ({ (*i1.borrow()).v } == 1) && (i2.v == -1_i32) })); assert!((copies_0.with(|rc| *rc.borrow()) == 11)); let o: Value = Rc::new(RefCell::new(Owner { - box_: Box_int_::new({ 3 }), + box_: { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Box_int_::new(__v.as_pointer(), { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, })); - let mut o2: Owner = Owner::move_from({ o.as_pointer() }); + let mut o2: Owner = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Owner::move_from(__v.as_pointer(), { o.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((o2.box_.val == 3)); - let ol1: Value = Rc::new(RefCell::new(OutOfLine::new({ 5 }))); - let mut ol2: OutOfLine = OutOfLine::copy_from({ ol1.as_pointer() }); + let ol1: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + OutOfLine::new(__v.as_pointer(), { 5 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let mut ol2: OutOfLine = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + OutOfLine::copy_from(__v.as_pointer(), { ol1.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((ol2.v == 105)); assert!((copies_0.with(|rc| *rc.borrow()) == 12)); - let n: Value = Rc::new(RefCell::new(NonConst::new())); - let mut n1: NonConst = NonConst::new_1({ n.as_pointer() }); - let cn: Value = Rc::new(RefCell::new(NonConst::new())); - let mut n2: NonConst = NonConst::new_2({ cn.as_pointer() }); + let n: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + NonConst::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let mut n1: NonConst = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + NonConst::new_1(__v.as_pointer(), { n.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; + let cn: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + NonConst::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let mut n2: NonConst = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + NonConst::new_2(__v.as_pointer(), { cn.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((n1.mark == 1)); assert!((n2.mark == 10)); let t1: Value = Rc::new(RefCell::new(::default())); - let t2: Value = Rc::new(RefCell::new(Tracked::copy_from({ t1.as_pointer() }))); + let t2: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::copy_from(__v.as_pointer(), { t1.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); ({ TrackedImpl::copy_assign(&t2.as_pointer(), t1.as_pointer()) }); assert!(({ ({ (*t1.borrow()).copied_from } == 2) })); let ct: Value = Rc::new(RefCell::new(::default())); - let mut t3: Tracked = Tracked::copy_from({ ct.as_pointer() }); + let mut t3: Tracked = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::copy_from(__v.as_pointer(), { ct.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; ({ touch_1((ct.as_pointer())) }); assert!(({ ({ (*ct.borrow()).copied_from } == 2) })); return 0; diff --git a/tests/unit/out/refcount/copy_move_defaulted.rs b/tests/unit/out/refcount/copy_move_defaulted.rs index 28c91729c1..12e920914c 100644 --- a/tests/unit/out/refcount/copy_move_defaulted.rs +++ b/tests/unit/out/refcount/copy_move_defaulted.rs @@ -27,12 +27,12 @@ pub struct Explicit { pub arr: Box<[i32]>, } impl Explicit { - pub fn new(mut v: i32) -> Self { - Self { + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { v: v, inner: Inner { x: (v * 10) }, arr: Box::new([v, (v + 1)]), - } + }); } } impl Default for Explicit { @@ -90,15 +90,14 @@ pub struct DefaultCopyUserMove { pub v: i32, } impl DefaultCopyUserMove { - pub fn new(mut v: i32) -> Self { - Self { v: v } + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { v: v }); } - pub fn move_from(o: Ptr) -> Self { - let __this: DefaultCopyUserMove = Self { + pub fn move_from(this: Ptr, o: Ptr) { + this.write(Self { v: o.with(|__s| __s.v), - }; + }); field!(o, v).write(0); - __this } } #[derive( @@ -120,25 +119,28 @@ pub struct UserCopyDefaultMove { pub v: i32, } impl UserCopyDefaultMove { - pub fn new(mut v: i32) -> Self { - Self { v: v } + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { v: v }); } - pub fn copy_from(o: Ptr) -> Self { - Self { + pub fn copy_from(this: Ptr, o: Ptr) { + this.write(Self { v: (o.with(|__s| __s.v) + 100), - } + }); } - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { v: { (*_a0.upgrade().deref()).v }, - } + }); } } impl Clone for UserCopyDefaultMove { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(UserCopyDefaultMove { v: self.v.clone() })); - UserCopyDefaultMove::copy_from(__src.as_pointer()) + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + UserCopyDefaultMove::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, CppFrom, MoveAssign)] @@ -159,29 +161,27 @@ pub struct Buffer { pub arr: Box<[i32]>, } impl Buffer { - pub fn new(mut n: i32) -> Self { - let __this: Value = Rc::new(RefCell::new(Self { + pub fn new(this: Ptr, mut n: i32) { + this.write(Self { data: vec![n; (n as usize)], rows: Vec::new(), n: n, arr: Box::new([n, (n + 1)]), - })); - let this: Ptr = __this.as_pointer(); + }); { let a0_clone = (*this.upgrade().deref()).data.clone(); field!(this, rows).with_mut(|__v: &mut Vec>| __v.push(a0_clone)) }; - Rc::try_unwrap(__this).ok().unwrap().into_inner() } - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { data: field!(_a0, data).with_mut(std::mem::take), rows: field!(_a0, rows).with_mut(std::mem::take), n: { (*_a0.upgrade().deref()).n }, arr: Box::new(std::array::from_fn::<_, 2, _>(|__i: usize| { (*_a0.upgrade().deref()).arr[(__i) as usize] })), - } + }); } } impl Default for Buffer { @@ -213,15 +213,15 @@ pub struct Owner { pub p: Option>, } impl Owner { - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { data: field!(_a0, data).with_mut(std::mem::take), n: { (*_a0.upgrade().deref()).n }, arr: Box::new(std::array::from_fn::<_, 2, _>(|__i: usize| { (*_a0.upgrade().deref()).arr[(__i) as usize] })), p: field!(_a0, p).with_mut(|__v: &mut Option>| __v.take()), - } + }); } } impl Default for Owner { @@ -246,10 +246,10 @@ pub struct Copyable { pub data: Vec, } impl Copyable { - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { data: field!(_a0, data).with_mut(std::mem::take), - } + }); } } #[derive( @@ -277,19 +277,23 @@ pub struct Holder { pub p: Option>, } impl Holder { - pub fn new(mut v: i32) -> Self { - Self { + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { inner: Inner { x: v }, - e: Explicit::new({ v }), + e: { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Explicit::new(__v.as_pointer(), { v }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, p: None, - } + }); } - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { inner: { (*_a0.upgrade().deref()).inner }, e: { (*_a0.upgrade().deref()).e.clone() }, p: field!(_a0, p).with_mut(|__v: &mut Option>| __v.take()), - } + }); } } pub fn same_0(a: Ptr, b: Ptr) -> bool { @@ -303,7 +307,11 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let a: Value = Rc::new(RefCell::new(Explicit::new({ 1 }))); + let a: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Explicit::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_a = std::mem::DropGuard::new(a.clone(), |__p| __p.as_pointer().destructor()); let b: Value = Rc::new(RefCell::new((*a.borrow()).clone())); let _dtor_b = std::mem::DropGuard::new(b.clone(), |__p| __p.as_pointer().destructor()); @@ -316,9 +324,17 @@ fn main_0() -> i32 { && ({ same_0(c.as_pointer(), a.as_pointer(),) })) && ({ same_0(d.as_pointer(), a.as_pointer(),) }) ); - let e: Value = Rc::new(RefCell::new(Explicit::new({ 2 }))); + let e: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Explicit::new(__v.as_pointer(), { 2 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_e = std::mem::DropGuard::new(e.clone(), |__p| __p.as_pointer().destructor()); - let f: Value = Rc::new(RefCell::new(Explicit::new({ 3 }))); + let f: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Explicit::new(__v.as_pointer(), { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_f = std::mem::DropGuard::new(f.clone(), |__p| __p.as_pointer().destructor()); (*e.borrow_mut()) = (*b.borrow()).clone(); (*f.borrow_mut()) = (*c.borrow()).clone(); @@ -326,7 +342,11 @@ fn main_0() -> i32 { ({ same_0(e.as_pointer(), b.as_pointer(),) }) && ({ same_0(f.as_pointer(), c.as_pointer(),) }) ); - let g: Value = Rc::new(RefCell::new(Explicit::new({ 4 }))); + let g: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Explicit::new(__v.as_pointer(), { 4 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_g = std::mem::DropGuard::new(g.clone(), |__p| __p.as_pointer().destructor()); (*g.borrow_mut()) = { (*e.borrow_mut()) = (*f.borrow()).clone(); @@ -358,32 +378,87 @@ fn main_0() -> i32 { vec_.push(a0_clone) }; { - let __a1 = Explicit::new({ 9 }); + let __a1 = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Explicit::new(__v.as_pointer(), { 9 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; vec_.push(__a1) }; assert!((vec_[0_usize].v == 1) && (vec_[1_usize].v == 9)); - let m: Value = Rc::new(RefCell::new(DefaultCopyUserMove::new({ 7 }))); + let m: Value = Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + DefaultCopyUserMove::new(__v.as_pointer(), { 7 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let m1: Value = Rc::new(RefCell::new((*m.borrow()))); - let mut m2: DefaultCopyUserMove = DefaultCopyUserMove::move_from({ m.as_pointer() }); + let mut m2: DefaultCopyUserMove = { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + DefaultCopyUserMove::move_from(__v.as_pointer(), { m.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!(({ (({ (*m1.borrow()).v } == 7) && (m2.v == 7)) && ({ (*m.borrow()).v } == 0) })); - let mut m3: DefaultCopyUserMove = DefaultCopyUserMove::new({ 1 }); - let m4: Value = Rc::new(RefCell::new(DefaultCopyUserMove::new({ 1 }))); + let mut m3: DefaultCopyUserMove = { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + DefaultCopyUserMove::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; + let m4: Value = Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + DefaultCopyUserMove::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); m3 = (*m1.borrow()); ({ DefaultCopyUserMoveImpl::move_assign(&m4.as_pointer(), m1.as_pointer()) }); assert!(({ ((m3.v == 7) && ({ (*m4.borrow()).v } == 7)) && ({ (*m1.borrow()).v } == 0) })); - let u: Value = Rc::new(RefCell::new(UserCopyDefaultMove::new({ 8 }))); - let mut u1: UserCopyDefaultMove = UserCopyDefaultMove::copy_from({ u.as_pointer() }); - let u2: Value = Rc::new(RefCell::new(UserCopyDefaultMove::move_from({ - u.as_pointer() - }))); + let u: Value = Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + UserCopyDefaultMove::new(__v.as_pointer(), { 8 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let mut u1: UserCopyDefaultMove = { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + UserCopyDefaultMove::copy_from(__v.as_pointer(), { u.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; + let u2: Value = Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + UserCopyDefaultMove::move_from(__v.as_pointer(), { u.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!(({ ((u1.v == 108) && ({ (*u2.borrow()).v } == 8)) && ({ (*u.borrow()).v } == 8) })); - let u3: Value = Rc::new(RefCell::new(UserCopyDefaultMove::new({ 1 }))); - let u4: Value = Rc::new(RefCell::new(UserCopyDefaultMove::new({ 1 }))); + let u3: Value = Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + UserCopyDefaultMove::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let u4: Value = Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + UserCopyDefaultMove::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); ({ UserCopyDefaultMoveImpl::copy_assign(&u3.as_pointer(), u2.as_pointer()) }); ({ UserCopyDefaultMoveImpl::move_assign(&u4.as_pointer(), u2.as_pointer()) }); assert!(({ ({ (*u3.borrow()).v } == 108) && ({ (*u4.borrow()).v } == 8) })); - let p: Value = Rc::new(RefCell::new(Buffer::new({ 3 }))); - let q: Value = Rc::new(RefCell::new(Buffer::move_from({ p.as_pointer() }))); + let p: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Buffer::new(__v.as_pointer(), { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let q: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Buffer::move_from(__v.as_pointer(), { p.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!( ({ ((({ (*q.borrow()).n } == 3) && ((*q.borrow()).data.len() == 3_usize)) @@ -391,7 +466,11 @@ fn main_0() -> i32 { && ((*p.borrow()).data.is_empty()) }) ); - let r: Value = Rc::new(RefCell::new(Buffer::new({ 1 }))); + let r: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Buffer::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); ({ BufferImpl::move_assign(&r.as_pointer(), q.as_pointer()) }); assert!( ({ @@ -415,11 +494,21 @@ fn main_0() -> i32 { ); let bufs: Value> = Rc::new(RefCell::new(Vec::new())); { - let __a1 = Buffer::move_from({ r.as_pointer() }); + let __a1 = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Buffer::move_from(__v.as_pointer(), { r.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; (*bufs.borrow_mut()).push(__a1) }; { - let mut __tmp_2 = { Buffer::move_from({ bufs.decay().offset(0_usize) }) }; + let mut __tmp_2 = { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Buffer::move_from(__v.as_pointer(), { bufs.decay().offset(0_usize) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + }; (*bufs.borrow_mut()).push(__tmp_2); }; assert!( @@ -441,7 +530,11 @@ fn main_0() -> i32 { let _p: Ptr<_> = Ptr::alloc(7); field_ptr!(o1.as_pointer(), p).write(_p.to_owned_opt()) }; - let o2: Value = Rc::new(RefCell::new(Owner::move_from({ o1.as_pointer() }))); + let o2: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Owner::move_from(__v.as_pointer(), { o1.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!( ({ ((({ (*o2.borrow()).n } == 5) && ((*o2.borrow()).data.len() == 1_usize)) @@ -475,7 +568,11 @@ fn main_0() -> i32 { data: Vec::from([1, 2]), })); let mut c2: Copyable = (*c1.borrow()).clone(); - let c3: Value = Rc::new(RefCell::new(Copyable::move_from({ c1.as_pointer() }))); + let c3: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Copyable::move_from(__v.as_pointer(), { c1.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!(({ (c2.data.len() == 2_usize) && ((*c3.borrow()).data.len() == 2_usize) })); assert!(({ (*c1.borrow()).data.is_empty() })); let c4: Value = Rc::new(RefCell::new(::default())); @@ -486,13 +583,21 @@ fn main_0() -> i32 { && ((*c3.borrow()).data.is_empty()) }) ); - let h1: Value = Rc::new(RefCell::new(Holder::new({ 4 }))); + let h1: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Holder::new(__v.as_pointer(), { 4 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_h1 = std::mem::DropGuard::new(h1.clone(), |__p| __p.as_pointer().destructor()); { let _p: Ptr<_> = Ptr::alloc(9); field_ptr!(h1.as_pointer(), p).write(_p.to_owned_opt()) }; - let h2: Value = Rc::new(RefCell::new(Holder::move_from({ h1.as_pointer() }))); + let h2: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Holder::move_from(__v.as_pointer(), { h1.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_h2 = std::mem::DropGuard::new(h2.clone(), |__p| __p.as_pointer().destructor()); assert!( ({ @@ -501,7 +606,11 @@ fn main_0() -> i32 { && ((({ { (*h1.borrow()).p.clone() } }).as_pointer()).is_null()) }) ); - let h3: Value = Rc::new(RefCell::new(Holder::new({ 1 }))); + let h3: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Holder::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_h3 = std::mem::DropGuard::new(h3.clone(), |__p| __p.as_pointer().destructor()); ({ HolderImpl::move_assign(&h3.as_pointer(), h2.as_pointer()) }); assert!( diff --git a/tests/unit/out/refcount/copy_move_deleted.rs b/tests/unit/out/refcount/copy_move_deleted.rs index d6f0fa08fb..5ad948f4e6 100644 --- a/tests/unit/out/refcount/copy_move_deleted.rs +++ b/tests/unit/out/refcount/copy_move_deleted.rs @@ -16,15 +16,14 @@ pub struct NoCopy { pub v: i32, } impl NoCopy { - pub fn new(mut v: i32) -> Self { - Self { v: v } + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { v: v }); } - pub fn move_from(o: Ptr) -> Self { - let __this: NoCopy = Self { + pub fn move_from(this: Ptr, o: Ptr) { + this.write(Self { v: o.with(|__s| __s.v), - }; + }); field!(o, v).write(0); - __this } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign)] @@ -34,20 +33,25 @@ pub struct PrivateCopy { pub v: i32, } impl PrivateCopy { - pub fn new() -> Self { - Self { v: 0 } + pub fn new(this: Ptr) { + this.write(Self { v: 0 }); } - pub fn move_from(o: Ptr) -> Self { - let __this: PrivateCopy = Self { + pub fn move_from(this: Ptr, o: Ptr) { + this.write(Self { v: o.with(|__s| __s.v), - }; + }); field!(o, v).write(0); - __this } } impl Default for PrivateCopy { fn default() -> Self { - { PrivateCopy::new() } + { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + PrivateCopy::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg)] @@ -57,13 +61,19 @@ pub struct Immovable { pub v: i32, } impl Immovable { - pub fn new() -> Self { - Self { v: 0 } + pub fn new(this: Ptr) { + this.write(Self { v: 0 }); } } impl Default for Immovable { fn default() -> Self { - { Immovable::new() } + { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Immovable::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] @@ -76,11 +86,15 @@ pub struct Container { pub tag: i32, } impl Container { - pub fn move_from(_a0: Ptr) -> Self { - Self { - inner: NoCopy::move_from({ field_ptr!(_a0, inner) }), + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { + inner: { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + NoCopy::move_from(__v.as_pointer(), { field_ptr!(_a0, inner) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, tag: { (*_a0.upgrade().deref()).tag }, - } + }); } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] @@ -91,10 +105,10 @@ pub struct VecHolder { pub items: Vec, } impl VecHolder { - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { items: field!(_a0, items).with_mut(std::mem::take), - } + }); } } pub fn bump_0(mut p: Ptr) { @@ -108,32 +122,64 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let a: Value = Rc::new(RefCell::new(NoCopy::new({ 1 }))); - let b: Value = Rc::new(RefCell::new(NoCopy::move_from({ a.as_pointer() }))); + let a: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + NoCopy::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let b: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + NoCopy::move_from(__v.as_pointer(), { a.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!(({ ({ (*b.borrow()).v } == 1) && ({ (*a.borrow()).v } == 0) })); ({ NoCopyImpl::move_assign(&a.as_pointer(), b.as_pointer()) }); assert!(({ ({ (*a.borrow()).v } == 1) && ({ (*b.borrow()).v } == 0) })); ({ bump_0((a.as_pointer())) }); assert!(({ ({ (*a.borrow()).v } == 2) })); - let p: Value = Rc::new(RefCell::new(PrivateCopy::new())); + let p: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + PrivateCopy::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); (*p.borrow_mut()).v = 3; - let q: Value = Rc::new(RefCell::new(PrivateCopy::move_from({ p.as_pointer() }))); + let q: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + PrivateCopy::move_from(__v.as_pointer(), { p.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!(({ ({ (*q.borrow()).v } == 3) && ({ (*p.borrow()).v } == 0) })); ({ PrivateCopyImpl::move_assign(&p.as_pointer(), q.as_pointer()) }); assert!(({ ({ (*p.borrow()).v } == 3) && ({ (*q.borrow()).v } == 0) })); - let im: Value = Rc::new(RefCell::new(Immovable::new())); + let im: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Immovable::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); (*im.borrow_mut()).v = 4; ({ bump_ref_1(im.as_pointer()) }); let mut pim: Ptr = (im.as_pointer()); assert!((pim.with(|__s| __s.v) == 5)); let c: Value = Rc::new(RefCell::new(Container { - inner: NoCopy::new({ 6 }), + inner: { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + NoCopy::new(__v.as_pointer(), { 6 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, tag: 7, })); - let mut d: Container = Container::move_from({ c.as_pointer() }); + let mut d: Container = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Container::move_from(__v.as_pointer(), { c.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!(({ ((d.inner.v == 6) && (d.tag == 7)) && ({ (*c.borrow()).inner.v } == 0) })); let h: Value = Rc::new(RefCell::new(::default())); - let mut h2: VecHolder = VecHolder::move_from({ h.as_pointer() }); + let mut h2: VecHolder = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + VecHolder::move_from(__v.as_pointer(), { h.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((h2.items.len() == 0_usize)); return 0; } diff --git a/tests/unit/out/refcount/default_function_arguments.rs b/tests/unit/out/refcount/default_function_arguments.rs index d7ccc2e6cd..561375a26d 100644 --- a/tests/unit/out/refcount/default_function_arguments.rs +++ b/tests/unit/out/refcount/default_function_arguments.rs @@ -20,13 +20,19 @@ pub struct Bar { pub v: i32, } impl Bar { - pub fn new(mut v: i32) -> Self { - Self { v: v } + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { v: v }); } } impl Default for Bar { fn default() -> Self { - { Bar::new({ 1 }) } + { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Bar::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } thread_local!( @@ -42,7 +48,11 @@ pub fn by_ref_5(b: Ptr) -> i32 { return b.with(|__s| __s.v); } thread_local!( - pub static global_bar_6: Value = Rc::new(RefCell::new(Bar::new({ 9 }))); + pub static global_bar_6: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Bar::new(__v.as_pointer(), { 9 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); ); pub fn by_global_ref_7(b: Ptr) -> i32 { return b.with(|__s| __s.v); @@ -60,8 +70,8 @@ pub struct Holder_int_ { pub v: i32, } impl Holder_int_ { - pub fn new(mut v: i32) -> Self { - Self { v: v } + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { v: v }); } } pub fn main() { @@ -81,10 +91,39 @@ fn main_0() -> i32 { }) as i32) == (true as i32)) ); - let mut b: Bar = Bar::new({ 1 }); + let mut b: Bar = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Bar::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((b.v == 1)); - assert!(({ Bar::new({ 2 },).v } == 2)); - let mut arr: [Bar; 3] = [Bar::new({ 1 }), Bar::new({ 1 }), Bar::new({ 1 })]; + assert!( + ({ + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Bar::new(__v.as_pointer(), { 2 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + .v + } == 2) + ); + let mut arr: [Bar; 3] = [ + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Bar::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Bar::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Bar::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + ]; assert!((arr[(0) as usize].v == 1)); assert!((arr[(2) as usize].v == 1)); assert!((({ lazy_4(5,) }) == 5)); @@ -93,24 +132,40 @@ fn main_0() -> i32 { assert!((counter_2.with(|rc| *rc.borrow()) == 1)); assert!( (({ - let _b: Value = Rc::new(RefCell::new(Bar::new({ 7 }))); + let _b: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Bar::new(__v.as_pointer(), { 7 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); by_ref_5(_b.as_pointer()) }) == 7) ); assert!( (({ - let _b: Value = Rc::new(RefCell::new(Bar::new({ 3 }))); + let _b: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Bar::new(__v.as_pointer(), { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); by_ref_5(_b.as_pointer()) }) == 3) ); assert!((({ by_global_ref_7(global_bar_6.with(|v| v.as_pointer()),) }) == 9)); assert!( (({ - let _b: Value = Rc::new(RefCell::new(Bar::new({ 4 }))); + let _b: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Bar::new(__v.as_pointer(), { 4 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); by_global_ref_7(_b.as_pointer()) }) == 4) ); - let mut h: Holder_int_ = Holder_int_::new({ 4 }); + let mut h: Holder_int_ = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Holder_int_::new(__v.as_pointer(), { 4 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((h.v == 4)); assert!((({ shifted_8(3, -1_i32,) }) == 2)); assert!((({ shifted_8(3, 4,) }) == 7)); diff --git a/tests/unit/out/refcount/destructor_params.rs b/tests/unit/out/refcount/destructor_params.rs index b8deb4a55a..59eaca4d9b 100644 --- a/tests/unit/out/refcount/destructor_params.rs +++ b/tests/unit/out/refcount/destructor_params.rs @@ -34,11 +34,11 @@ pub struct Holder { pub v: i32, } impl Holder { - pub fn new(s: S) -> Self { + pub fn new(this: Ptr, s: S) { let s: Value = Rc::new(RefCell::new(s)); - Self { + this.write(Self { v: { (*s.borrow()).v }, - } + }); } } pub fn main() { @@ -63,7 +63,11 @@ fn main_0() -> i32 { assert!((destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 5)); destroyed_0.with(|rc| *rc.borrow_mut() = 0); { - let h: Value = Rc::new(RefCell::new(Holder::new({ S { v: 3 } }))); + let h: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Holder::new(__v.as_pointer(), { S { v: 3 } }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!( (destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 3) ); diff --git a/tests/unit/out/refcount/field_method_receiver.rs b/tests/unit/out/refcount/field_method_receiver.rs index 54c0fb8dd8..7e4e8bed96 100644 --- a/tests/unit/out/refcount/field_method_receiver.rs +++ b/tests/unit/out/refcount/field_method_receiver.rs @@ -29,15 +29,15 @@ pub struct S { pub v: Vec, } impl S { - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { tag: { (*_a0.upgrade().deref()).tag }, c: { (*_a0.upgrade().deref()).c }, arr: Box::new(std::array::from_fn::<_, 2, _>(|__i: usize| { (*_a0.upgrade().deref()).arr[(__i) as usize] })), v: field!(_a0, v).with_mut(std::mem::take), - } + }); } } impl Default for S { diff --git a/tests/unit/out/refcount/field_pointers.rs b/tests/unit/out/refcount/field_pointers.rs index 35fb9a34c2..d465403b29 100644 --- a/tests/unit/out/refcount/field_pointers.rs +++ b/tests/unit/out/refcount/field_pointers.rs @@ -58,8 +58,8 @@ pub struct Outer { pub buf: Box<[i32]>, } impl Outer { - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { x: { (*_a0.upgrade().deref()).x }, inner: { (*_a0.upgrade().deref()).inner.clone() }, items: Box::new(std::array::from_fn::<_, 3, _>(|__i: usize| { @@ -70,7 +70,7 @@ impl Outer { buf: Box::new(std::array::from_fn::<_, 4, _>(|__i: usize| { (*_a0.upgrade().deref()).buf[(__i) as usize] })), - } + }); } } impl Default for Outer { diff --git a/tests/unit/out/refcount/fn_ptr.rs b/tests/unit/out/refcount/fn_ptr.rs index 150c149f61..70e4326f38 100644 --- a/tests/unit/out/refcount/fn_ptr.rs +++ b/tests/unit/out/refcount/fn_ptr.rs @@ -37,8 +37,8 @@ pub struct HashHolder_unsigned_long__ptr__bool__ { pub h: FnPtr u64>, } impl HashHolder_unsigned_long__ptr__bool__ { - pub fn new(h: Ptr u64>>) -> Self { - Self { h: (h.read()) } + pub fn new(this: Ptr, h: Ptr u64>>) { + this.write(Self { h: (h.read()) }); } } thread_local!( @@ -89,7 +89,13 @@ 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__::new({ __tmp_0.as_pointer() }) + { + let __v: Value = Rc::new(RefCell::new( + ::zero_init(), + )); + HashHolder_unsigned_long__ptr__bool__::new(__v.as_pointer(), { __tmp_0.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } }; assert!((({ hh.h.call(true,) }) == 1_u64)); let mut handler: FnPtr = FnPtr::::new(add_to_total_8); diff --git a/tests/unit/out/refcount/fn_ptr_struct.rs b/tests/unit/out/refcount/fn_ptr_struct.rs index aaf75497a7..7fa6eea0ae 100644 --- a/tests/unit/out/refcount/fn_ptr_struct.rs +++ b/tests/unit/out/refcount/fn_ptr_struct.rs @@ -43,23 +43,32 @@ pub struct MoveOnly { pub data_: i32, } impl MoveOnly { - pub fn new(mut data: i32) -> Self { - Self { data_: data } + pub fn new(this: Ptr, mut data: i32) { + this.write(Self { data_: data }); } - pub fn move_from(x: Ptr) -> Self { - let __this: MoveOnly = Self { + pub fn move_from(this: Ptr, x: Ptr) { + this.write(Self { data_: x.with(|__s| __s.data_), - }; + }); field!(x, data_).write(0); - __this } } pub fn make_move_only_2() -> MoveOnly { - return MoveOnly::new({ 4 }); + return { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::new(__v.as_pointer(), { 4 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; } pub fn scale_move_only_3(x: MoveOnly) -> MoveOnly { let x: Value = Rc::new(RefCell::new(x)); - return MoveOnly::new({ (({ MoveOnlyImpl::get(&x.as_pointer()) }) * 10) }); + return { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::new(__v.as_pointer(), { + (({ MoveOnlyImpl::get(&x.as_pointer()) }) * 10) + }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; } pub fn main() { __cpp2rust_init_globals(); @@ -96,7 +105,13 @@ fn main_0() -> i32 { let mut sc: FnPtr MoveOnly> = FnPtr:: MoveOnly>::new(scale_move_only_3); let n: Value = Rc::new(RefCell::new( - ({ sc.call(MoveOnly::move_from({ m.as_pointer() })) }), + ({ + sc.call({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::move_from(__v.as_pointer(), { m.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }) + }), )); assert!((({ MoveOnlyImpl::get(&n.as_pointer(),) }) == 40)); assert!((({ MoveOnlyImpl::get(&m.as_pointer(),) }) == 0)); diff --git a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs index eb39f2478d..627445a11c 100644 --- a/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs +++ b/tests/unit/out/refcount/foreach_disjoint_field_borrow.rs @@ -18,11 +18,11 @@ pub struct S { pub a: i32, } impl S { - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { v: field!(_a0, v).with_mut(std::mem::take), a: { (*_a0.upgrade().deref()).a }, - } + }); } } pub fn main() { diff --git a/tests/unit/out/refcount/forward_basic.rs b/tests/unit/out/refcount/forward_basic.rs index 13dc21e01f..e85315ccb2 100644 --- a/tests/unit/out/refcount/forward_basic.rs +++ b/tests/unit/out/refcount/forward_basic.rs @@ -21,28 +21,27 @@ pub struct Tracked { pub moves: i32, } impl Tracked { - pub fn new(mut v: i32) -> Self { - Self { + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { v: v, copies: 0, moves: 0, - } + }); } - pub fn copy_from(o: Ptr) -> Self { - Self { + pub fn copy_from(this: Ptr, o: Ptr) { + this.write(Self { v: o.with(|__s| __s.v), copies: (o.with(|__s| __s.copies) + 1), moves: o.with(|__s| __s.moves), - } + }); } - pub fn move_from(o: Ptr) -> Self { - let __this: Tracked = Self { + pub fn move_from(this: Ptr, o: Ptr) { + this.write(Self { v: o.with(|__s| __s.v), copies: o.with(|__s| __s.copies), moves: (o.with(|__s| __s.moves) + 1), - }; + }); field!(o, v).write(0); - __this } } impl Clone for Tracked { @@ -52,7 +51,9 @@ impl Clone for Tracked { copies: self.copies.clone(), moves: self.moves.clone(), })); - Tracked::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } pub fn chosen_overload_0(_a0: Ptr) -> Overload { @@ -62,17 +63,25 @@ pub fn chosen_overload_1(_a0: Ptr) -> Overload { return Overload_kRvalueOverload; } impl Holder { - pub fn new_1(x: Ptr) -> Self { - Self { - t: Tracked::copy_from({ (x).clone() }), - } + pub fn new_1(this: Ptr, x: Ptr) { + this.write(Self { + t: { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::copy_from(__v.as_pointer(), { (x).clone() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + }); } } impl Holder { - pub fn new_2(x: Ptr) -> Self { - Self { - t: Tracked::move_from({ (x).clone() }), - } + pub fn new_2(this: Ptr, x: Ptr) { + this.write(Self { + t: { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::move_from(__v.as_pointer(), { (x).clone() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + }); } } #[derive( @@ -87,10 +96,14 @@ pub struct Holder { pub t: Tracked, } impl Holder { - pub fn move_from(_a0: Ptr) -> Self { - Self { - t: Tracked::move_from({ field_ptr!(_a0, t) }), - } + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { + t: { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::move_from(__v.as_pointer(), { field_ptr!(_a0, t) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + }); } } pub fn forward_once_2(x: Ptr) -> Overload { @@ -106,29 +119,49 @@ pub fn forward_twice_5(x: Ptr) -> Overload { return ({ forward_once_3((x).clone()) }); } pub fn forward_into_ctor_6(x: Ptr) -> Holder { - return Holder::new_1({ (x).clone() }); + return { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Holder::new_1(__v.as_pointer(), { (x).clone() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; } pub fn forward_into_ctor_7(x: Ptr) -> Holder { - return Holder::new_2({ (x).clone() }); + return { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Holder::new_2(__v.as_pointer(), { (x).clone() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; } pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let lvalue: Value = Rc::new(RefCell::new(Tracked::new({ 7 }))); + let lvalue: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::new(__v.as_pointer(), { 7 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!( ((({ forward_once_2(lvalue.as_pointer(),) }) as i32) == (Overload_kLvalueOverload as i32)) ); assert!(({ ({ (*lvalue.borrow()).v } == 7) })); assert!( ((({ - let _x: Value = Rc::new(RefCell::new(Tracked::new({ 8 }))); + let _x: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::new(__v.as_pointer(), { 8 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); forward_once_3(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) ); - let relayed: Value = Rc::new(RefCell::new(Tracked::new({ 9 }))); + let relayed: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::new(__v.as_pointer(), { 9 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!( ((({ forward_twice_4(relayed.as_pointer(),) }) as i32) == (Overload_kLvalueOverload as i32)) @@ -136,19 +169,31 @@ fn main_0() -> i32 { assert!(({ ({ (*relayed.borrow()).v } == 9) })); assert!( ((({ - let _x: Value = Rc::new(RefCell::new(Tracked::new({ 10 }))); + let _x: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::new(__v.as_pointer(), { 10 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); forward_twice_5(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) ); - let kept: Value = Rc::new(RefCell::new(Tracked::new({ 11 }))); + let kept: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::new(__v.as_pointer(), { 11 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let mut from_lvalue: Holder = ({ forward_into_ctor_6(kept.as_pointer()) }); assert!((from_lvalue.t.v == 11)); assert!((from_lvalue.t.copies == 1)); assert!((from_lvalue.t.moves == 0)); assert!(({ ({ (*kept.borrow()).v } == 11) })); let mut from_rvalue: Holder = ({ - let _x: Value = Rc::new(RefCell::new(Tracked::new({ 12 }))); + let _x: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::new(__v.as_pointer(), { 12 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); forward_into_ctor_7(_x.as_pointer()) }); assert!((from_rvalue.t.v == 12)); diff --git a/tests/unit/out/refcount/forward_decltype.rs b/tests/unit/out/refcount/forward_decltype.rs index ab2b722c0c..bc3175b73d 100644 --- a/tests/unit/out/refcount/forward_decltype.rs +++ b/tests/unit/out/refcount/forward_decltype.rs @@ -21,28 +21,27 @@ pub struct Tracked { pub moves: i32, } impl Tracked { - pub fn new(mut v: i32) -> Self { - Self { + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { v: v, copies: 0, moves: 0, - } + }); } - pub fn copy_from(o: Ptr) -> Self { - Self { + pub fn copy_from(this: Ptr, o: Ptr) { + this.write(Self { v: o.with(|__s| __s.v), copies: (o.with(|__s| __s.copies) + 1), moves: o.with(|__s| __s.moves), - } + }); } - pub fn move_from(o: Ptr) -> Self { - let __this: Tracked = Self { + pub fn move_from(this: Ptr, o: Ptr) { + this.write(Self { v: o.with(|__s| __s.v), copies: o.with(|__s| __s.copies), moves: (o.with(|__s| __s.moves) + 1), - }; + }); field!(o, v).write(0); - __this } } impl Clone for Tracked { @@ -52,7 +51,9 @@ impl Clone for Tracked { copies: self.copies.clone(), moves: self.moves.clone(), })); - Tracked::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } pub fn chosen_overload_0(_a0: Ptr) -> Overload { @@ -83,7 +84,11 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let a: Value = Rc::new(RefCell::new(Tracked::new({ 3 }))); + let a: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::new(__v.as_pointer(), { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!( ((({ forward_by_decltype_2(a.as_pointer(),) }) as i32) == (Overload_kLvalueOverload as i32)) @@ -91,12 +96,20 @@ fn main_0() -> i32 { assert!(({ ({ (*a.borrow()).v } == 3) })); assert!( ((({ - let _x: Value = Rc::new(RefCell::new(Tracked::new({ 4 }))); + let _x: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::new(__v.as_pointer(), { 4 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); forward_by_decltype_3(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) ); - let b: Value = Rc::new(RefCell::new(Tracked::new({ 5 }))); + let b: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::new(__v.as_pointer(), { 5 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!( ((({ forward_abbreviated_4(b.as_pointer(),) }) as i32) == (Overload_kLvalueOverload as i32)) @@ -104,15 +117,27 @@ fn main_0() -> i32 { assert!(({ ({ (*b.borrow()).v } == 5) })); assert!( ((({ - let _x: Value = Rc::new(RefCell::new(Tracked::new({ 6 }))); + let _x: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::new(__v.as_pointer(), { 6 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); forward_abbreviated_5(_x.as_pointer()) }) as i32) == (Overload_kRvalueOverload as i32)) ); - let c: Value = Rc::new(RefCell::new(Tracked::new({ 7 }))); + let c: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::new(__v.as_pointer(), { 7 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!( (({ - let _args_1: Value = Rc::new(RefCell::new(Tracked::new({ 8 }))); + let _args_1: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::new(__v.as_pointer(), { 8 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); forward_abbreviated_pack_6(c.as_pointer(), _args_1.as_pointer()) }) == ((Overload_kLvalueOverload as i32) + (Overload_kRvalueOverload as i32))) ); diff --git a/tests/unit/out/refcount/forward_explicit.rs b/tests/unit/out/refcount/forward_explicit.rs index 68f171717b..d7de41a6af 100644 --- a/tests/unit/out/refcount/forward_explicit.rs +++ b/tests/unit/out/refcount/forward_explicit.rs @@ -23,28 +23,27 @@ pub struct Tracked { pub moves: i32, } impl Tracked { - pub fn new(mut v: i32) -> Self { - Self { + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { v: v, copies: 0, moves: 0, - } + }); } - pub fn copy_from(o: Ptr) -> Self { - Self { + pub fn copy_from(this: Ptr, o: Ptr) { + this.write(Self { v: o.with(|__s| __s.v), copies: (o.with(|__s| __s.copies) + 1), moves: o.with(|__s| __s.moves), - } + }); } - pub fn move_from(o: Ptr) -> Self { - let __this: Tracked = Self { + pub fn move_from(this: Ptr, o: Ptr) { + this.write(Self { v: o.with(|__s| __s.v), copies: o.with(|__s| __s.copies), moves: (o.with(|__s| __s.moves) + 1), - }; + }); field!(o, v).write(0); - __this } } impl Clone for Tracked { @@ -54,7 +53,9 @@ impl Clone for Tracked { copies: self.copies.clone(), moves: self.moves.clone(), })); - Tracked::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } pub fn chosen_overload_0(_a0: Ptr) -> Overload { @@ -71,14 +72,22 @@ pub fn chosen_overload_3(_a0: Ptr) -> Overload { } pub fn copy_or_move_into_param_4(t: Tracked) -> Tracked { let t: Value = Rc::new(RefCell::new(t)); - return Tracked::move_from({ t.as_pointer() }); + return { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::move_from(__v.as_pointer(), { t.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; } pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let a: Value = Rc::new(RefCell::new(Tracked::new({ 5 }))); + let a: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::new(__v.as_pointer(), { 5 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!( ((({ chosen_overload_0(a.as_pointer(),) }) as i32) == (Overload_kLvalueOverload as i32)) ); @@ -87,16 +96,34 @@ fn main_0() -> i32 { ((({ chosen_overload_1(a.as_pointer(),) }) as i32) == (Overload_kRvalueOverload as i32)) ); assert!(({ ({ (*a.borrow()).v } == 5) })); - let b: Value = Rc::new(RefCell::new(Tracked::new({ 6 }))); - let mut moved: Tracked = - ({ copy_or_move_into_param_4(Tracked::move_from({ b.as_pointer() })) }); + let b: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::new(__v.as_pointer(), { 6 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let mut moved: Tracked = ({ + copy_or_move_into_param_4({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::move_from(__v.as_pointer(), { b.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }) + }); assert!((moved.v == 6)); assert!((moved.copies == 0)); assert!((moved.moves == 2)); assert!(({ ({ (*b.borrow()).v } == 0) })); - let c: Value = Rc::new(RefCell::new(Tracked::new({ 7 }))); - let mut copied: Tracked = - ({ copy_or_move_into_param_4(Tracked::copy_from({ c.as_pointer() })) }); + let c: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::new(__v.as_pointer(), { 7 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let mut copied: Tracked = ({ + copy_or_move_into_param_4({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::copy_from(__v.as_pointer(), { c.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }) + }); assert!((copied.v == 7)); assert!((copied.copies == 1)); assert!((copied.moves == 1)); diff --git a/tests/unit/out/refcount/forward_pack.rs b/tests/unit/out/refcount/forward_pack.rs index 0bf4058417..1d0dbbf162 100644 --- a/tests/unit/out/refcount/forward_pack.rs +++ b/tests/unit/out/refcount/forward_pack.rs @@ -23,28 +23,27 @@ pub struct Tracked { pub moves: i32, } impl Tracked { - pub fn new(mut v: i32) -> Self { - Self { + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { v: v, copies: 0, moves: 0, - } + }); } - pub fn copy_from(o: Ptr) -> Self { - Self { + pub fn copy_from(this: Ptr, o: Ptr) { + this.write(Self { v: o.with(|__s| __s.v), copies: (o.with(|__s| __s.copies) + 1), moves: o.with(|__s| __s.moves), - } + }); } - pub fn move_from(o: Ptr) -> Self { - let __this: Tracked = Self { + pub fn move_from(this: Ptr, o: Ptr) { + this.write(Self { v: o.with(|__s| __s.v), copies: o.with(|__s| __s.copies), moves: (o.with(|__s| __s.moves) + 1), - }; + }); field!(o, v).write(0); - __this } } impl Clone for Tracked { @@ -54,7 +53,9 @@ impl Clone for Tracked { copies: self.copies.clone(), moves: self.moves.clone(), })); - Tracked::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } pub fn chosen_overload_0(_a0: Ptr) -> Overload { @@ -113,11 +114,19 @@ pub fn forward_pack_7( return digits; } impl Pair { - pub fn new(x: Ptr, y: Ptr) -> Self { - Self { - a: Tracked::copy_from({ (x).clone() }), - b: Tracked::move_from({ (y).clone() }), - } + pub fn new(this: Ptr, x: Ptr, y: Ptr) { + this.write(Self { + a: { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::copy_from(__v.as_pointer(), { (x).clone() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + b: { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::move_from(__v.as_pointer(), { (y).clone() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + }); } } #[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, Default)] @@ -131,15 +140,27 @@ pub struct Pair { pub b: Tracked, } impl Pair { - pub fn move_from(_a0: Ptr) -> Self { - Self { - a: Tracked::move_from({ field_ptr!(_a0, a) }), - b: Tracked::move_from({ field_ptr!(_a0, b) }), - } + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { + a: { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::move_from(__v.as_pointer(), { field_ptr!(_a0, a) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + b: { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::move_from(__v.as_pointer(), { field_ptr!(_a0, b) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }, + }); } } pub fn forward_pack_into_ctor_8(args_0: Ptr, args_1: Ptr) -> Pair { - return Pair::new({ (args_0).clone() }, { (args_1).clone() }); + return { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Pair::new(__v.as_pointer(), { (args_0).clone() }, { (args_1).clone() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; } pub fn main() { __cpp2rust_init_globals(); @@ -147,19 +168,31 @@ pub fn main() { } fn main_0() -> i32 { assert!((({ forward_pack_4() }) == 0)); - let a: Value = Rc::new(RefCell::new(Tracked::new({ 1 }))); + let a: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!((({ forward_pack_5(a.as_pointer(),) }) == (Overload_kLvalueOverload as i32))); assert!(({ ({ (*a.borrow()).v } == 1) })); assert!( (({ - let _args: Value = Rc::new(RefCell::new(Tracked::new({ 2 }))); + let _args: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::new(__v.as_pointer(), { 2 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); forward_pack_6(_args.as_pointer()) }) == (Overload_kRvalueOverload as i32)) ); let i: Value = Rc::new(RefCell::new(3)); assert!( (({ - let _args_1: Value = Rc::new(RefCell::new(Tracked::new({ 4 }))); + let _args_1: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::new(__v.as_pointer(), { 4 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _args_3: Value = Rc::new(RefCell::new(5)); forward_pack_7( a.as_pointer(), @@ -171,9 +204,17 @@ fn main_0() -> i32 { ); assert!(({ ({ (*a.borrow()).v } == 1) })); assert!(({ ((*i.borrow()) == 3) })); - let lhs: Value = Rc::new(RefCell::new(Tracked::new({ 6 }))); + let lhs: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::new(__v.as_pointer(), { 6 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let mut p: Pair = ({ - let _args_1: Value = Rc::new(RefCell::new(Tracked::new({ 7 }))); + let _args_1: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Tracked::new(__v.as_pointer(), { 7 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); forward_pack_into_ctor_8(lhs.as_pointer(), _args_1.as_pointer()) }); assert!((p.a.v == 6)); diff --git a/tests/unit/out/refcount/global_init_side_effect.rs b/tests/unit/out/refcount/global_init_side_effect.rs index fcf0162e8a..2db02f2386 100644 --- a/tests/unit/out/refcount/global_init_side_effect.rs +++ b/tests/unit/out/refcount/global_init_side_effect.rs @@ -14,17 +14,24 @@ thread_local!( #[byte_size(1)] pub struct S {} impl S { - pub fn new(mut x: i32) -> Self { - let __this: S = Self {}; + pub fn new(this: Ptr, mut x: i32) { + this.write(Self {}); total_0.with(|rc| *rc.borrow_mut() += x); - __this } } thread_local!( - pub static a_1: Value = Rc::new(RefCell::new(S::new({ 1 }))); + pub static a_1: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + S::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); ); thread_local!( - pub static b_2: Value = Rc::new(RefCell::new(S::new({ 10 }))); + pub static b_2: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + S::new(__v.as_pointer(), { 10 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); ); pub fn main() { __cpp2rust_init_globals(); diff --git a/tests/unit/out/refcount/global_non_const_init.rs b/tests/unit/out/refcount/global_non_const_init.rs index 5edef0f578..7d916f1c09 100644 --- a/tests/unit/out/refcount/global_non_const_init.rs +++ b/tests/unit/out/refcount/global_non_const_init.rs @@ -39,23 +39,37 @@ pub struct Ctor { pub v: i32, } impl Ctor { - pub fn new_1() -> Self { - Self { v: ({ next_0() }) } + pub fn new_1(this: Ptr) { + this.write(Self { v: ({ next_0() }) }); } - pub fn new_2(mut x: i32) -> Self { - Self { v: x } + pub fn new_2(this: Ptr, mut x: i32) { + this.write(Self { v: x }); } } impl Default for Ctor { fn default() -> Self { - { Ctor::new_1() } + { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Ctor::new_1(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } thread_local!( - pub static default_ctor_7: Value = Rc::new(RefCell::new(Ctor::new_1())); + pub static default_ctor_7: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Ctor::new_1(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); ); thread_local!( - pub static arg_ctor_8: Value = Rc::new(RefCell::new(Ctor::new_2({ 7 }))); + pub static arg_ctor_8: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Ctor::new_2(__v.as_pointer(), { 7 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); ); thread_local!( pub static str_9: Value> = Rc::new(RefCell::new({ @@ -65,7 +79,11 @@ thread_local!( })); ); thread_local!( - pub static inline_member_11: Value = Rc::new(RefCell::new(Ctor::new_2({ 5 }))); + pub static inline_member_11: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Ctor::new_2(__v.as_pointer(), { 5 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); ); #[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(1)] @@ -80,7 +98,11 @@ thread_local!( static once_13: Value = Rc::new(RefCell::new(({ next_0() }))); ); thread_local!( - static local_ctor_14: Value = Rc::new(RefCell::new(Ctor::new_2({ 3 }))); + static local_ctor_14: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Ctor::new_2(__v.as_pointer(), { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); ); #[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg)] #[byte_size(4)] @@ -89,8 +111,8 @@ pub struct Singleton { pub hits: i32, } impl Singleton { - pub fn new() -> Self { - Self { hits: 0 } + pub fn new(this: Ptr) { + this.write(Self { hits: 0 }); } pub fn instance() -> Ptr { return s_15.with(|v| v.as_pointer()); @@ -98,11 +120,21 @@ impl Singleton { } impl Default for Singleton { fn default() -> Self { - { Singleton::new() } + { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Singleton::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } thread_local!( - static s_15: Value = Rc::new(RefCell::new(Singleton::new())); + static s_15: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Singleton::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); ); pub fn main() { __cpp2rust_init_globals(); diff --git a/tests/unit/out/refcount/huffman.rs b/tests/unit/out/refcount/huffman.rs index a41b1ade17..2dabeb5476 100644 --- a/tests/unit/out/refcount/huffman.rs +++ b/tests/unit/out/refcount/huffman.rs @@ -61,8 +61,8 @@ pub struct MinHeap { pub alloc: Option>>, } impl MinHeap { - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { size: { (*_a0.upgrade().deref()).size }, capacity: { (*_a0.upgrade().deref()).capacity }, arr: field!(_a0, arr) @@ -70,7 +70,7 @@ impl MinHeap { next: { (*_a0.upgrade().deref()).next }, alloc: field!(_a0, alloc) .with_mut(|__v: &mut Option>>| __v.take()), - } + }); } } pub fn AllocMinHeap_1(mut capacity: i32) -> Option> { diff --git a/tests/unit/out/refcount/implicit_autoref.rs b/tests/unit/out/refcount/implicit_autoref.rs index 978f439507..b15fbb27c3 100644 --- a/tests/unit/out/refcount/implicit_autoref.rs +++ b/tests/unit/out/refcount/implicit_autoref.rs @@ -16,10 +16,10 @@ pub struct Holder { pub v: Vec, } impl Holder { - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { v: field!(_a0, v).with_mut(std::mem::take), - } + }); } } 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 876d3d0b04..046aca1062 100644 --- a/tests/unit/out/refcount/in_class_field_initializer.rs +++ b/tests/unit/out/refcount/in_class_field_initializer.rs @@ -54,8 +54,8 @@ pub struct Boxed_int_ { pub tag: i32, } impl Boxed_int_ { - pub fn new(mut x: i32, mut t: i32) -> Self { - Self { v: x, tag: t } + pub fn new(this: Ptr, mut x: i32, mut t: i32) { + this.write(Self { v: x, tag: t }); } } impl Default for Boxed_int_ { @@ -75,7 +75,11 @@ fn main_0() -> i32 { assert!((s.c.y == 4)); assert!((s.d.x == 3)); assert!((s.d.y == 4)); - let mut boxed: Boxed_int_ = Boxed_int_::new({ 5 }, { 9 }); + let mut boxed: Boxed_int_ = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Boxed_int_::new(__v.as_pointer(), { 5 }, { 9 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((boxed.v == 5)); assert!((boxed.tag == 9)); return 0; diff --git a/tests/unit/out/refcount/inline_container_fields.rs b/tests/unit/out/refcount/inline_container_fields.rs index b357458ad3..a7964ee755 100644 --- a/tests/unit/out/refcount/inline_container_fields.rs +++ b/tests/unit/out/refcount/inline_container_fields.rs @@ -20,14 +20,14 @@ pub struct Elem { pub coeffs: Vec, } impl Elem { - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { id: { (*_a0.upgrade().deref()).id }, hist: Box::new(std::array::from_fn::<_, 4, _>(|__i: usize| { (*_a0.upgrade().deref()).hist[(__i) as usize] })), coeffs: field!(_a0, coeffs).with_mut(std::mem::take), - } + }); } } impl Default for Elem { @@ -62,8 +62,8 @@ pub struct State { pub rows: Vec>, } impl State { - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { count: { (*_a0.upgrade().deref()).count }, grid: Box::new(std::array::from_fn::<_, 2, _>(|__i: usize| { Box::<[_]>::from(std::array::from_fn::<_, 3, _>(|__i2: usize| { @@ -75,7 +75,7 @@ impl State { .collect(), elems: field!(_a0, elems).with_mut(std::mem::take), rows: field!(_a0, rows).with_mut(std::mem::take), - } + }); } } impl Default for State { @@ -166,26 +166,26 @@ pub struct Counted { pub v: i32, } impl Counted { - pub fn copy_from(o: Ptr) -> Self { - let __this: Counted = Self { + pub fn copy_from(this: Ptr, o: Ptr) { + this.write(Self { v: o.with(|__s| __s.v), - }; + }); (*copies_2.with(Value::clone).borrow_mut()).prefix_inc(); - __this } - pub fn move_from(o: Ptr) -> Self { - let __this: Counted = Self { + pub fn move_from(this: Ptr, o: Ptr) { + this.write(Self { v: o.with(|__s| __s.v), - }; + }); field!(o, v).write(-1_i32); (*moves_3.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Clone for Counted { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Counted { v: self.v.clone() })); - Counted::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Counted::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } impl Default for Counted { @@ -311,7 +311,11 @@ fn main_0() -> i32 { ((array_elem!(elems.decay().offset(1_usize), hist, 2).read()) == 5) && ((array_elem!(first, hist, 2).read()) == 0) ); - let moved: Value = Rc::new(RefCell::new(State::move_from({ t.as_pointer() }))); + let moved: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + State::move_from(__v.as_pointer(), { t.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!( ({ ((*moved.borrow()).grid[(0) as usize][(0) as usize] == 100) diff --git a/tests/unit/out/refcount/kruskal.rs b/tests/unit/out/refcount/kruskal.rs index a0dc746fd8..9d6c82f05e 100644 --- a/tests/unit/out/refcount/kruskal.rs +++ b/tests/unit/out/refcount/kruskal.rs @@ -129,12 +129,12 @@ pub struct DisjointSet { pub n: i32, } impl DisjointSet { - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { rank: field!(_a0, rank).with_mut(|__v: &mut Option>>| __v.take()), parent: field!(_a0, parent).with_mut(|__v: &mut Option>>| __v.take()), n: { (*_a0.upgrade().deref()).n }, - } + }); } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, MoveCtor, MoveAssign, Default)] @@ -149,12 +149,12 @@ pub struct Graph { pub E: i32, } impl Graph { - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { edges: field!(_a0, edges).with_mut(|__v: &mut Option>>| __v.take()), V: { (*_a0.upgrade().deref()).V }, E: { (*_a0.upgrade().deref()).E }, - } + }); } } pub fn MSTKruskal_2(graph: Ptr) -> f64 { diff --git a/tests/unit/out/refcount/lambda_as_field.rs b/tests/unit/out/refcount/lambda_as_field.rs index 784a89b5ab..7504a76347 100644 --- a/tests/unit/out/refcount/lambda_as_field.rs +++ b/tests/unit/out/refcount/lambda_as_field.rs @@ -74,18 +74,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 fn new(f: FnPtr i32>) -> Self { + pub fn new(this: Ptr, f: FnPtr i32>) { let f: Value i32>> = Rc::new(RefCell::new(f)); - Self { + this.write(Self { f: (*f.borrow()).copy_from(), moves: 0, - } + }); } - pub fn move_from(o: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, o: Ptr) { + this.write(Self { f: (*o.upgrade().deref()).f.move_from(), moves: (o.with(|__s| __s.moves) + 1), - } + }); } } impl Default for Moving__lambda_at_lambda_as_field_cpp_64_12__ { @@ -215,18 +215,28 @@ fn main_0() -> i32 { let ww: Value i32>> = Rc::new(RefCell::new(({ wrap_2((*w.borrow()).copy_from()) }))); assert!(({ (({ (*ww.borrow()).call(2,) }) == 202) })); - let m: Value = Rc::new(RefCell::new( - Moving__lambda_at_lambda_as_field_cpp_64_12__::new({ + let m: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new( + ::zero_init(), + )); + Moving__lambda_at_lambda_as_field_cpp_64_12__::new(__v.as_pointer(), { FnPtr:: i32>::new(|mut x: i32| -> i32 { { return (x * 2); } }) - }), - )); - let m2: Value = Rc::new(RefCell::new( - Moving__lambda_at_lambda_as_field_cpp_64_12__::move_from({ m.as_pointer() }), - )); + }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let m2: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new( + ::zero_init(), + )); + Moving__lambda_at_lambda_as_field_cpp_64_12__::move_from(__v.as_pointer(), { + m.as_pointer() + }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!(({ (({ (*m2.borrow()).f.call(3,) }) == 6) })); assert!(({ ({ (*m2.borrow()).moves } == 1) })); return 0; diff --git a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs index 956e7a8c7b..f80721834c 100644 --- a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs @@ -15,23 +15,23 @@ pub struct Counted { pub moves: i32, } impl Counted { - pub fn new() -> Self { - Self { + pub fn new(this: Ptr) { + this.write(Self { copies: 0, moves: 0, - } + }); } - pub fn copy_from(o: Ptr) -> Self { - Self { + pub fn copy_from(this: Ptr, o: Ptr) { + this.write(Self { copies: (o.with(|__s| __s.copies) + 1), moves: o.with(|__s| __s.moves), - } + }); } - pub fn move_from(o: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, o: Ptr) { + this.write(Self { copies: o.with(|__s| __s.copies), moves: (o.with(|__s| __s.moves) + 1), - } + }); } } impl Clone for Counted { @@ -40,12 +40,20 @@ impl Clone for Counted { copies: self.copies.clone(), moves: self.moves.clone(), })); - Counted::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Counted::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } impl Default for Counted { fn default() -> Self { - { Counted::new() } + { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Counted::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } thread_local!( @@ -55,25 +63,33 @@ thread_local!( #[byte_size(1)] pub struct Dropped {} impl Dropped { - pub fn new() -> Self { - Self {} + pub fn new(this: Ptr) { + this.write(Self {}); } - pub fn copy_from(_a0: Ptr) -> Self { - Self {} + pub fn copy_from(this: Ptr, _a0: Ptr) { + this.write(Self {}); } - pub fn move_from(_a0: Ptr) -> Self { - Self {} + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self {}); } } impl Clone for Dropped { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Dropped {})); - Dropped::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Dropped::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } impl Default for Dropped { fn default() -> Self { - { Dropped::new() } + { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Dropped::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } pub fn main() { @@ -81,10 +97,18 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let c: Value = Rc::new(RefCell::new(Counted::new())); + let c: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Counted::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let f: Value i32>> = Rc::new(RefCell::new(lambda!( { - let c: Value = Rc::new(RefCell::new(Counted::copy_from({ c.as_pointer() }))); + let c: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Counted::copy_from(__v.as_pointer(), { c.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); }, || -> i32 { return (({ (*c.borrow()).copies } * 10) + { (*c.borrow()).moves }); @@ -100,11 +124,18 @@ fn main_0() -> i32 { ({ lambda!( { - let c: Value = - Rc::new(RefCell::new(Counted::copy_from({ c.as_pointer() }))); + let c: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Counted::copy_from(__v.as_pointer(), { c.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); }, || -> Counted { - return Counted::copy_from({ c.as_pointer() }); + return { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Counted::copy_from(__v.as_pointer(), { c.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; } ) .call() @@ -113,14 +144,21 @@ fn main_0() -> i32 { }; assert!((returned == 2)); let arr: Value> = Rc::new(RefCell::new(Box::new( - std::array::from_fn::<_, 2, _>(|_| Counted::new()), + std::array::from_fn::<_, 2, _>(|_| { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Counted::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }), ))); let a: Value i32>> = Rc::new(RefCell::new(lambda!( { - let arr: Value> = - Rc::new(RefCell::new(Box::new(std::array::from_fn::<_, 2, _>( - |__i: usize| Counted::copy_from({ arr.decay().offset(__i) }), - )))); + 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())); + Counted::copy_from(__v.as_pointer(), { arr.decay().offset(__i) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }), + ))); }, || -> i32 { return ({ (*arr.borrow())[(0) as usize].copies } + { @@ -136,7 +174,11 @@ fn main_0() -> i32 { { let m: Value> = Rc::new(RefCell::new(lambda!( { - let d: Value = Rc::new(RefCell::new(Dropped::new())); + let d: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Dropped::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); }, || {} ))); @@ -150,7 +192,11 @@ fn main_0() -> i32 { { let k: Value> = Rc::new(RefCell::new(lambda!( { - let d: Value = Rc::new(RefCell::new(Dropped::new())); + let d: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Dropped::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); }, || {} ))); @@ -164,7 +210,11 @@ fn main_0() -> i32 { { let inner: Value> = Rc::new(RefCell::new(lambda!( { - let d: Value = Rc::new(RefCell::new(Dropped::new())); + let d: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Dropped::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); }, || {} ))); diff --git a/tests/unit/out/refcount/lambda_move_only_capture.rs b/tests/unit/out/refcount/lambda_move_only_capture.rs index 3d0fa6b821..4e20999216 100644 --- a/tests/unit/out/refcount/lambda_move_only_capture.rs +++ b/tests/unit/out/refcount/lambda_move_only_capture.rs @@ -17,15 +17,14 @@ pub struct Owner { pub p: Ptr, } impl Owner { - pub fn new(mut v: i32) -> Self { - Self { p: Ptr::alloc(v) } + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { p: Ptr::alloc(v) }); } - pub fn move_from(o: Ptr) -> Self { - let __this: Owner = Self { + pub fn move_from(this: Ptr, o: Ptr) { + this.write(Self { p: o.with(|__s| __s.p.clone()), - }; + }); field!(o, p).write(Ptr::::null()); - __this } } pub fn main() { @@ -33,11 +32,19 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let o: Value = Rc::new(RefCell::new(Owner::new({ 5 }))); + let o: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Owner::new(__v.as_pointer(), { 5 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_o = std::mem::DropGuard::new(o.clone(), |__p| __p.as_pointer().destructor()); let f: Value i32>> = Rc::new(RefCell::new(lambda!( { - let h: Value = Rc::new(RefCell::new(Owner::move_from({ o.as_pointer() }))); + let h: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Owner::move_from(__v.as_pointer(), { o.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); }, || -> i32 { return ({ (*h.borrow()).p.clone() }.read()); @@ -54,7 +61,11 @@ fn main_0() -> i32 { let total: Value = Rc::new(RefCell::new(0)); let consume: Value> = Rc::new(RefCell::new(lambda!( { - let h: Value = Rc::new(RefCell::new(Owner::new({ 7 }))); + let h: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Owner::new(__v.as_pointer(), { 7 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let total: Ptr = total.as_pointer(); }, || { @@ -71,7 +82,11 @@ fn main_0() -> i32 { ({ (*consume.borrow()).call() }); ({ (*consume.borrow()).call() }); assert!(({ ((*total.borrow()) == 7) })); - let o2: Value = Rc::new(RefCell::new(Owner::new({ 9 }))); + let o2: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Owner::new(__v.as_pointer(), { 9 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let _dtor_o2 = std::mem::DropGuard::new(o2.clone(), |__p| __p.as_pointer().destructor()); let t: Value i32>> = Rc::new(RefCell::new(({ OwnerImpl::take(&o2.as_pointer()) }))); @@ -92,8 +107,11 @@ impl OwnerImpl for Ptr { fn take(&self) -> FnPtr i32> { return lambda!( { - let self_: Value = - Rc::new(RefCell::new(Owner::move_from({ (*self).clone() }))); + let self_: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Owner::move_from(__v.as_pointer(), { (*self).clone() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); }, || -> i32 { return ({ (*self_.borrow()).p.clone() }.read()); diff --git a/tests/unit/out/refcount/libc_struct_without_default.rs b/tests/unit/out/refcount/libc_struct_without_default.rs index 8deaec11ea..0890521fa7 100644 --- a/tests/unit/out/refcount/libc_struct_without_default.rs +++ b/tests/unit/out/refcount/libc_struct_without_default.rs @@ -18,13 +18,13 @@ pub struct UserDefined { pub v: Vec, } impl UserDefined { - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { a: (0..1) .map(|__i| field_ref!(_a0, a).decay().offset(__i).read()) .collect(), v: field!(_a0, v).with_mut(std::mem::take), - } + }); } } impl Default for UserDefined { diff --git a/tests/unit/out/refcount/map.rs b/tests/unit/out/refcount/map.rs index d3e353e73f..0a58171e8d 100644 --- a/tests/unit/out/refcount/map.rs +++ b/tests/unit/out/refcount/map.rs @@ -21,16 +21,22 @@ pub struct Point { pub y: i32, } impl Point { - pub fn new_1() -> Self { - Self { x: 0, y: 0 } + pub fn new_1(this: Ptr) { + this.write(Self { x: 0, y: 0 }); } - pub fn new_2(mut x: i32, mut y: i32) -> Self { - Self { x: x, y: y } + pub fn new_2(this: Ptr, mut x: i32, mut y: i32) { + this.write(Self { x: x, y: y }); } } impl Default for Point { fn default() -> Self { - { Point::new_1() } + { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Point::new_1(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } pub fn main() { @@ -731,7 +737,11 @@ fn main_0() -> i32 { let (__it, __inserted) = Map::emplace(points.as_pointer(), &key1.as_pointer(), || { ( Rc::new(RefCell::new(key1.as_pointer().read())), - Rc::new(RefCell::new(Point::new_2({ 3 }, { 4 }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Point::new_2(__v.as_pointer(), { 3 }, { 4 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }); ( @@ -774,7 +784,11 @@ fn main_0() -> i32 { let mut __tmp_53 = { ( Rc::new(RefCell::new(({ (*key8.borrow()) }))), - Rc::new(RefCell::new(Point::new_2({ 5 }, { 6 }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Point::new_2(__v.as_pointer(), { 5 }, { 6 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }; let (__it, __inserted) = diff --git a/tests/unit/out/refcount/map_key_copy_ctor.rs b/tests/unit/out/refcount/map_key_copy_ctor.rs index d1f4d84c5a..3c431ee431 100644 --- a/tests/unit/out/refcount/map_key_copy_ctor.rs +++ b/tests/unit/out/refcount/map_key_copy_ctor.rs @@ -23,22 +23,20 @@ pub struct Key { pub k: i32, } impl Key { - pub fn new(mut k: i32) -> Self { - Self { k: k } + pub fn new(this: Ptr, mut k: i32) { + this.write(Self { k: k }); } - pub fn copy_from(o: Ptr) -> Self { - let __this: Key = Self { + pub fn copy_from(this: Ptr, o: Ptr) { + this.write(Self { k: o.with(|__s| __s.k), - }; + }); (*copies_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this } - pub fn move_from(o: Ptr) -> Self { - let __this: Key = Self { + pub fn move_from(this: Ptr, o: Ptr) { + this.write(Self { k: o.with(|__s| __s.k), - }; + }); (*moves_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl CppLess for Key { @@ -55,12 +53,18 @@ impl CppEq for Key { impl Clone for Key { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Key { k: self.k.clone() })); - Key::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Key::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } pub fn make_key_3(mut k: i32) -> Key { (*made_2.with(Value::clone).borrow_mut()).prefix_inc(); - return Key::new({ k }); + return { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Key::new(__v.as_pointer(), { k }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; } pub fn main() { __cpp2rust_init_globals(); @@ -69,9 +73,21 @@ pub fn main() { fn main_0() -> i32 { let mut ok: bool = true; let m: Value, Value)>> = Rc::new(RefCell::new(Map::new())); - let a: Value = Rc::new(RefCell::new(Key::new({ 1 }))); - let b: Value = Rc::new(RefCell::new(Key::new({ 2 }))); - let c: Value = Rc::new(RefCell::new(Key::new({ 3 }))); + let a: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Key::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let b: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Key::new(__v.as_pointer(), { 2 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let c: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Key::new(__v.as_pointer(), { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); match (a.as_pointer(),) { (__tmp_0,) => ({ (*m.borrow_mut()).subscript(__tmp_0, || 0_i32) }), } @@ -190,7 +206,13 @@ fn main_0() -> i32 { .deref()) .0 .as_pointer()); - match (Rc::new(RefCell::new(Key::new({ 0 }))).as_pointer(),) { + match (Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Key::new(__v.as_pointer(), { 0 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })) + .as_pointer(),) + { (__tmp_9,) => { ({ (*m.borrow_mut()).subscript_move(__tmp_9, |__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 7241cd10fe..8668f09878 100644 --- a/tests/unit/out/refcount/map_key_identity.rs +++ b/tests/unit/out/refcount/map_key_identity.rs @@ -40,15 +40,20 @@ pub struct Mapped { pub value: i32, } impl Mapped { - pub fn new() -> Self { - let __this: Mapped = Self { value: 0 }; + pub fn new(this: Ptr) { + this.write(Self { value: 0 }); (*default_constructions_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Default for Mapped { fn default() -> Self { - { Mapped::new() } + { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Mapped::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } pub fn main() { diff --git a/tests/unit/out/refcount/map_try_emplace.rs b/tests/unit/out/refcount/map_try_emplace.rs index afb5dda8ab..fdac3cb861 100644 --- a/tests/unit/out/refcount/map_try_emplace.rs +++ b/tests/unit/out/refcount/map_try_emplace.rs @@ -26,28 +26,25 @@ pub struct Item { pub value: i32, } impl Item { - pub fn new_2() -> Self { - Self { value: 0 } + pub fn new_2(this: Ptr) { + this.write(Self { value: 0 }); } - pub fn new_1(mut value: i32) -> Self { - let __this: Item = Self { value: value }; + pub fn new_1(this: Ptr, mut value: i32) { + this.write(Self { value: value }); (*made_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this } - pub fn copy_from(other: Ptr) -> Self { - let __this: Item = Self { + pub fn copy_from(this: Ptr, other: Ptr) { + this.write(Self { value: other.with(|__s| __s.value), - }; + }); (*copies_2.with(Value::clone).borrow_mut()).prefix_inc(); - __this } - pub fn move_from(other: Ptr) -> Self { - let __this: Item = Self { + pub fn move_from(this: Ptr, other: Ptr) { + this.write(Self { value: other.with(|__s| __s.value), - }; + }); (*moves_3.with(Value::clone).borrow_mut()).prefix_inc(); field!(other, value).write(-1_i32); - __this } } impl Clone for Item { @@ -55,12 +52,20 @@ impl Clone for Item { let __src: Value = Rc::new(RefCell::new(Item { value: self.value.clone(), })); - Item::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } impl Default for Item { fn default() -> Self { - { Item::new_2() } + { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::new_2(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } pub fn argument_4(item: Ptr) -> Ptr { @@ -74,11 +79,11 @@ pub struct RefItem { pub value: i32, } impl RefItem { - pub fn new_1() -> Self { - Self { value: 0 } + pub fn new_1(this: Ptr) { + this.write(Self { value: 0 }); } - pub fn new_2(counter: Ptr, mut amount: i32) -> Self { - let __this: RefItem = Self { + pub fn new_2(this: Ptr, counter: Ptr, mut amount: i32) { + this.write(Self { value: { { let __rhs = { amount }; @@ -86,14 +91,19 @@ impl RefItem { }; (counter.read()) }, - }; + }); (*made_1.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Default for RefItem { fn default() -> Self { - { RefItem::new_1() } + { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + RefItem::new_1(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } pub fn reference_5(counter: Ptr) -> Ptr { @@ -361,7 +371,11 @@ fn main_0() -> i32 { let (__it, __inserted) = Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_1({ 10 }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::new_1(__v.as_pointer(), { 10 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }); ( @@ -369,7 +383,11 @@ fn main_0() -> i32 { Rc::new(RefCell::new(__inserted)), ) }; - let source: Value = Rc::new(RefCell::new(Item::new_1({ 20 }))); + let source: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::new_1(__v.as_pointer(), { 20 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); made_1.with(|rc| { *rc.borrow_mut() = { copies_2.with(|rc| { @@ -391,7 +409,11 @@ fn main_0() -> i32 { Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::copy_from({ (__tmp_6).clone() }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::copy_from(__v.as_pointer(), { (__tmp_6).clone() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }); ( @@ -427,7 +449,11 @@ fn main_0() -> i32 { Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::move_from({ (__tmp_7).clone() }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::move_from(__v.as_pointer(), { (__tmp_7).clone() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }); ( @@ -461,7 +487,11 @@ fn main_0() -> i32 { Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::copy_from({ (__tmp_8).clone() }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::copy_from(__v.as_pointer(), { (__tmp_8).clone() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }); ( @@ -498,7 +528,11 @@ fn main_0() -> i32 { Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::move_from({ (__tmp_9).clone() }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::move_from(__v.as_pointer(), { (__tmp_9).clone() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }); ( @@ -532,9 +566,11 @@ fn main_0() -> i32 { let (__it, __inserted) = Map::emplace(refs.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(RefItem::new_2({ counter.as_pointer() }, { - 5 - }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + RefItem::new_2(__v.as_pointer(), { counter.as_pointer() }, { 5 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }); ( @@ -552,7 +588,11 @@ fn main_0() -> i32 { let (__it, __inserted) = Map::emplace(refs.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(RefItem::new_2({ (__tmp_10).clone() }, { 2 }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + RefItem::new_2(__v.as_pointer(), { (__tmp_10).clone() }, { 2 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }); ( @@ -579,7 +619,11 @@ fn main_0() -> i32 { let (__it, __inserted) = Map::emplace(refs.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(RefItem::new_2({ (__tmp_11).clone() }, { 2 }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + RefItem::new_2(__v.as_pointer(), { (__tmp_11).clone() }, { 2 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }); ( @@ -625,7 +669,11 @@ fn main_0() -> i32 { )> = Rc::new(RefCell::new({ let __tmp_13: Value; match ({ - __tmp_13 = Rc::new(RefCell::new(Item::new_1({ 30 }))); + __tmp_13 = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::new_1(__v.as_pointer(), { 30 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); __tmp_13.as_pointer() },) { @@ -634,7 +682,11 @@ fn main_0() -> i32 { Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::move_from({ (__tmp_12).clone() }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::move_from(__v.as_pointer(), { (__tmp_12).clone() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }); ( @@ -661,7 +713,11 @@ fn main_0() -> i32 { )> = Rc::new(RefCell::new({ let __tmp_15: Value; match ({ - __tmp_15 = Rc::new(RefCell::new(Item::new_1({ 40 }))); + __tmp_15 = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::new_1(__v.as_pointer(), { 40 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); __tmp_15.as_pointer() },) { @@ -670,7 +726,11 @@ fn main_0() -> i32 { Map::emplace(items.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::move_from({ (__tmp_14).clone() }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::move_from(__v.as_pointer(), { (__tmp_14).clone() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }); ( diff --git a/tests/unit/out/refcount/map_try_emplace_lvalues.rs b/tests/unit/out/refcount/map_try_emplace_lvalues.rs index 154a5c06e5..c952cb3c35 100644 --- a/tests/unit/out/refcount/map_try_emplace_lvalues.rs +++ b/tests/unit/out/refcount/map_try_emplace_lvalues.rs @@ -19,11 +19,11 @@ pub struct Item { pub value: i32, } impl Item { - pub fn new_1() -> Self { - Self { value: 0 } + pub fn new_1(this: Ptr) { + this.write(Self { value: 0 }); } - pub fn new_2(counter: Ptr, mut amount: i32) -> Self { - let __this: Item = Self { + pub fn new_2(this: Ptr, counter: Ptr, mut amount: i32) { + this.write(Self { value: { { let __rhs = { amount }; @@ -31,14 +31,19 @@ impl Item { }; (counter.read()) }, - }; + }); (*made_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Default for Item { fn default() -> Self { - { Item::new_1() } + { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::new_1(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } pub fn receiver_2( @@ -65,18 +70,23 @@ pub struct Temporary { pub data: Box<[i32]>, } impl Temporary { - pub fn new() -> Self { - let __this: Temporary = Self { + pub fn new(this: Ptr) { + this.write(Self { n: 5, data: Box::new([6, 7]), - }; + }); (*temporary_calls_4.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl Default for Temporary { fn default() -> Self { - { Temporary::new() } + { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Temporary::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } #[derive(Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] @@ -87,7 +97,11 @@ pub struct Nested { pub inner: Temporary, } pub fn make_temporary_5() -> Temporary { - return Temporary::new(); + return { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Temporary::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; } pub fn make_nested_6() -> Nested { return ::default(); @@ -100,20 +114,30 @@ pub struct Owner { pub ptr: Option>, } impl Owner { - pub fn new() -> Self { - Self { - ptr: Some(Rc::new(RefCell::new(Temporary::new()))), - } + pub fn new(this: Ptr) { + this.write(Self { + ptr: Some(Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Temporary::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }))), + }); } - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { ptr: field!(_a0, ptr).with_mut(|__v: &mut Option>| __v.take()), - } + }); } } impl Default for Owner { fn default() -> Self { - { Owner::new() } + { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Owner::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg)] @@ -136,21 +160,27 @@ pub struct Held { pub ptr: Ptr, } impl Held { - pub fn new_2() -> Self { - Self { + pub fn new_2(this: Ptr) { + this.write(Self { ptr: Ptr::::null(), - } + }); } - pub fn new_1(n: Ptr) -> Self { - Self { ptr: (n).clone() } + pub fn new_1(this: Ptr, n: Ptr) { + this.write(Self { ptr: (n).clone() }); } - pub fn new_3(n: Ptr, mut _a1: i32) -> Self { - Self { ptr: (n).clone() } + pub fn new_3(this: Ptr, n: Ptr, mut _a1: i32) { + this.write(Self { ptr: (n).clone() }); } } impl Default for Held { fn default() -> Self { - { Held::new_2() } + { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Held::new_2(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } thread_local!( @@ -259,7 +289,11 @@ thread_local!( let mut __tmp_7: Option>; match (field_ptr!( (*{ - __tmp_7 = Some(Rc::new(RefCell::new(Temporary::new()))); + __tmp_7 = Some(Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Temporary::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }))); &mut __tmp_7 }) .as_pointer(), @@ -348,7 +382,11 @@ fn main_0() -> i32 { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ counter.as_pointer() }, { 3 }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::new_2(__v.as_pointer(), { counter.as_pointer() }, { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }); ( @@ -372,7 +410,11 @@ fn main_0() -> i32 { let (__it, __inserted) = Map::emplace((__tmp_8).clone(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_9).clone() }, { 2 }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::new_2(__v.as_pointer(), { (__tmp_9).clone() }, { 2 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }); ( @@ -406,7 +448,11 @@ fn main_0() -> i32 { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_11).clone() }, { 2 }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::new_2(__v.as_pointer(), { (__tmp_11).clone() }, { 2 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }); ( @@ -437,7 +483,11 @@ fn main_0() -> i32 { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_13).clone() }, { 2 }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::new_2(__v.as_pointer(), { (__tmp_13).clone() }, { 2 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }); ( @@ -469,7 +519,11 @@ fn main_0() -> i32 { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_16).clone() }, { 2 }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::new_2(__v.as_pointer(), { (__tmp_16).clone() }, { 2 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }); ( @@ -510,7 +564,11 @@ fn main_0() -> i32 { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_19).clone() }, { 3 }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::new_2(__v.as_pointer(), { (__tmp_19).clone() }, { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }); ( @@ -537,7 +595,11 @@ fn main_0() -> i32 { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_21).clone() }, { 3 }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::new_2(__v.as_pointer(), { (__tmp_21).clone() }, { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }); ( @@ -564,7 +626,11 @@ fn main_0() -> i32 { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_24).clone() }, { 3 }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::new_2(__v.as_pointer(), { (__tmp_24).clone() }, { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }); ( @@ -599,7 +665,11 @@ fn main_0() -> i32 { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_27).clone() }, { 3 }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::new_2(__v.as_pointer(), { (__tmp_27).clone() }, { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }); ( @@ -636,7 +706,11 @@ fn main_0() -> i32 { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_30).clone() }, { 3 }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::new_2(__v.as_pointer(), { (__tmp_30).clone() }, { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }); ( @@ -659,7 +733,11 @@ fn main_0() -> i32 { let (__it, __inserted) = Map::emplace(m.as_pointer(), &key.as_pointer(), || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Item::new_2({ (__tmp_33).clone() }, { 3 }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Item::new_2(__v.as_pointer(), { (__tmp_33).clone() }, { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }); ( @@ -1165,10 +1243,20 @@ fn main_0() -> i32 { Rc::new(RefCell::new( keys.decay().offset(0).read(), )), - Rc::new(RefCell::new(Item::new_2( - { (__tmp_61).clone() }, - { 2 }, - ))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new( + RefCell::new(::zero_init()), + ); + Item::new_2( + __v.as_pointer(), + { (__tmp_61).clone() }, + { 2 }, + ); + Rc::try_unwrap(__v) + .ok() + .unwrap() + .into_inner() + })), ) }, ); @@ -1208,10 +1296,20 @@ fn main_0() -> i32 { Rc::new(RefCell::new( keys.decay().offset(1).read(), )), - Rc::new(RefCell::new(Item::new_2( - { (__tmp_64).clone() }, - { 2 }, - ))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new( + RefCell::new(::zero_init()), + ); + Item::new_2( + __v.as_pointer(), + { (__tmp_64).clone() }, + { 2 }, + ); + Rc::try_unwrap(__v) + .ok() + .unwrap() + .into_inner() + })), ) }, ); @@ -1255,10 +1353,20 @@ fn main_0() -> i32 { Rc::new(RefCell::new( keys.decay().offset(2).read(), )), - Rc::new(RefCell::new(Item::new_2( - { (__tmp_69).clone() }, - { 2 }, - ))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new( + RefCell::new(::zero_init()), + ); + Item::new_2( + __v.as_pointer(), + { (__tmp_69).clone() }, + { 2 }, + ); + Rc::try_unwrap(__v) + .ok() + .unwrap() + .into_inner() + })), ) }, ); @@ -1502,9 +1610,14 @@ fn main_0() -> i32 { || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Held::new_1({ - ordinary.as_pointer() - }))), + Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + Held::new_1(__v.as_pointer(), { + ordinary.as_pointer() + }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }, ); @@ -1548,9 +1661,18 @@ fn main_0() -> i32 { Rc::new(RefCell::new( key.as_pointer().read(), )), - Rc::new(RefCell::new(Held::new_1({ - (__tmp_83).clone() - }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new( + RefCell::new(::zero_init()), + ); + Held::new_1(__v.as_pointer(), { + (__tmp_83).clone() + }); + Rc::try_unwrap(__v) + .ok() + .unwrap() + .into_inner() + })), ) }, ); @@ -1593,10 +1715,16 @@ fn main_0() -> i32 { || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Held::new_3( - { ordinary_array.decay() }, - { 0 }, - ))), + Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + Held::new_3( + __v.as_pointer(), + { ordinary_array.decay() }, + { 0 }, + ); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }, ); @@ -1639,10 +1767,20 @@ fn main_0() -> i32 { Rc::new(RefCell::new( key.as_pointer().read(), )), - Rc::new(RefCell::new(Held::new_3( - { (__tmp_88).clone() }, - { 0 }, - ))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new( + RefCell::new(::zero_init()), + ); + Held::new_3( + __v.as_pointer(), + { (__tmp_88).clone() }, + { 0 }, + ); + Rc::try_unwrap(__v) + .ok() + .unwrap() + .into_inner() + })), ) }, ); @@ -1700,7 +1838,12 @@ fn main_0() -> i32 { let mut __tmp_94: Option>; match (field_ptr!( (*{ - __tmp_94 = Some(Rc::new(RefCell::new(Temporary::new()))); + __tmp_94 = Some(Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + Temporary::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }))); &mut __tmp_94 }) .as_pointer(), @@ -1761,7 +1904,12 @@ fn main_0() -> i32 { let mut __tmp_98: Option>; match (array_field_ptr!( (*{ - __tmp_98 = Some(Rc::new(RefCell::new(Temporary::new()))); + __tmp_98 = Some(Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + Temporary::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }))); &mut __tmp_98 }) .as_pointer(), @@ -1791,7 +1939,12 @@ fn main_0() -> i32 { let mut __tmp_100: Option>; match (field_ptr!( (*{ - __tmp_100 = Some(Rc::new(RefCell::new(Temporary::new()))); + __tmp_100 = Some(Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + Temporary::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }))); &mut __tmp_100 }) .as_pointer(), @@ -1820,7 +1973,12 @@ fn main_0() -> i32 { let mut __tmp_102: Option>; match (field_ptr!( ((*{ - __tmp_102 = Some(Rc::new(RefCell::new(Temporary::new()))); + __tmp_102 = Some(Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + Temporary::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }))); &mut __tmp_102 }) .as_pointer()), @@ -1849,9 +2007,12 @@ fn main_0() -> i32 { let mut __tmp_104: Option>>>; match (field_ptr!( ((*(*{ - __tmp_104 = Some(Rc::new(RefCell::new(Some(Rc::new(RefCell::new( - Temporary::new(), - )))))); + __tmp_104 = Some(Rc::new(RefCell::new(Some(Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + Temporary::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })))))); &mut __tmp_104 }) .as_pointer() @@ -1921,9 +2082,14 @@ fn main_0() -> i32 { || { ( Rc::new(RefCell::new(key.as_pointer().read())), - Rc::new(RefCell::new(Held::new_1({ - ordinary.as_pointer() - }))), + Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + Held::new_1(__v.as_pointer(), { + ordinary.as_pointer() + }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ) }, ); @@ -1943,8 +2109,13 @@ fn main_0() -> i32 { match (if (choose != 0) { field_ptr!( (*{ - __tmp_106 = - Some(Rc::new(RefCell::new(Temporary::new()))); + __tmp_106 = Some(Rc::new(RefCell::new({ + let __v: Value = Rc::new( + RefCell::new(::zero_init()), + ); + Temporary::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }))); &mut __tmp_106 }) .as_pointer(), @@ -1953,8 +2124,13 @@ fn main_0() -> i32 { } else { array_field_ptr!( (*{ - __tmp_107 = - Some(Rc::new(RefCell::new(Temporary::new()))); + __tmp_107 = Some(Rc::new(RefCell::new({ + let __v: Value = Rc::new( + RefCell::new(::zero_init()), + ); + Temporary::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }))); &mut __tmp_107 }) .as_pointer(), @@ -1972,9 +2148,18 @@ fn main_0() -> i32 { Rc::new(RefCell::new( key.as_pointer().read(), )), - Rc::new(RefCell::new(Held::new_1({ - (__tmp_105).clone() - }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new( + RefCell::new(::zero_init()), + ); + Held::new_1(__v.as_pointer(), { + (__tmp_105).clone() + }); + Rc::try_unwrap(__v) + .ok() + .unwrap() + .into_inner() + })), ) }, ); @@ -2012,7 +2197,12 @@ fn main_0() -> i32 { { match (({ OwnerImpl::value(&{ - __tmp_109 = Rc::new(RefCell::new(Owner::new())); + __tmp_109 = Rc::new(RefCell::new({ + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + Owner::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); __tmp_109.as_pointer() }) }),) @@ -2026,9 +2216,18 @@ fn main_0() -> i32 { Rc::new(RefCell::new( key.as_pointer().read(), )), - Rc::new(RefCell::new(Held::new_1({ - (__tmp_108).clone() - }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new( + RefCell::new(::zero_init()), + ); + Held::new_1(__v.as_pointer(), { + (__tmp_108).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 1cff9e31c3..bd0b9f698f 100644 --- a/tests/unit/out/refcount/max.rs +++ b/tests/unit/out/refcount/max.rs @@ -28,15 +28,14 @@ pub struct Bag { pub n: i32, } impl Bag { - pub fn new(mut n: i32) -> Self { - Self { n: n } + pub fn new(this: Ptr, mut n: i32) { + this.write(Self { n: n }); } - pub fn copy_from(o: Ptr) -> Self { - let __this: Bag = Self { + pub fn copy_from(this: Ptr, o: Ptr) { + this.write(Self { n: o.with(|__s| __s.n), - }; + }); (*calls_0.with(Value::clone).borrow_mut()).prefix_inc(); - __this } } impl CppLess for Bag { @@ -53,14 +52,20 @@ impl CppEq for Bag { impl Clone for Bag { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Bag { n: self.n.clone() })); - Bag::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Bag::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } pub fn operator_lt_4(a: Ptr, b: Ptr) -> bool { return ({ a.with(|__s| __s.n) } < { b.with(|__s| __s.n) }); } pub fn make_5(mut n: i32) -> Bag { - return Bag::new({ n }); + return { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Bag::new(__v.as_pointer(), { n }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; } pub fn main() { __cpp2rust_init_globals(); diff --git a/tests/unit/out/refcount/move_assign.rs b/tests/unit/out/refcount/move_assign.rs index d1d8511b83..692b3b9a6c 100644 --- a/tests/unit/out/refcount/move_assign.rs +++ b/tests/unit/out/refcount/move_assign.rs @@ -16,15 +16,14 @@ pub struct MoveOnly { pub v: i32, } impl MoveOnly { - pub fn new(mut v: i32) -> Self { - Self { v: v } + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { v: v }); } - pub fn move_from(o: Ptr) -> Self { - let __this: MoveOnly = Self { + pub fn move_from(this: Ptr, o: Ptr) { + this.write(Self { v: o.with(|__s| __s.v), - }; + }); field!(o, v).write(0); - __this } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg)] @@ -34,32 +33,63 @@ pub struct ConstMoveAssign { pub mark: i32, } impl ConstMoveAssign { - pub fn new() -> Self { - Self { mark: 0 } + pub fn new(this: Ptr) { + this.write(Self { mark: 0 }); } } impl Default for ConstMoveAssign { fn default() -> Self { - { ConstMoveAssign::new() } + { + { + let __v: Value = + Rc::new(RefCell::new(::zero_init())); + ConstMoveAssign::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } pub fn make_0(mut v: i32) -> MoveOnly { - let m: Value = Rc::new(RefCell::new(MoveOnly::new({ v }))); - return MoveOnly::move_from({ m.as_pointer() }); + let m: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::new(__v.as_pointer(), { v }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + return { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::move_from(__v.as_pointer(), { m.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; } pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let a: Value = Rc::new(RefCell::new(MoveOnly::new({ 1 }))); - let b: Value = Rc::new(RefCell::new(MoveOnly::new({ 2 }))); - let c: Value = Rc::new(RefCell::new(MoveOnly::new({ 3 }))); + let a: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let b: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::new(__v.as_pointer(), { 2 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let c: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::new(__v.as_pointer(), { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); ({ MoveOnlyImpl::move_assign(&a.as_pointer(), b.as_pointer()) }); assert!(({ ({ (*a.borrow()).v } == 2) })); assert!(({ ({ (*b.borrow()).v } == 0) })); ({ - let _o: Value = Rc::new(RefCell::new(MoveOnly::new({ 3 }))); + let _o: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::new(__v.as_pointer(), { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); MoveOnlyImpl::move_assign(&b.as_pointer(), _o.as_pointer()) }); ({ @@ -74,7 +104,11 @@ fn main_0() -> i32 { }) ); ({ - let _o: Value = Rc::new(RefCell::new(MoveOnly::new({ 5 }))); + let _o: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::new(__v.as_pointer(), { 5 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); MoveOnlyImpl::move_assign(&a.as_pointer(), _o.as_pointer()) }); assert!(({ ({ (*a.borrow()).v } == 5) })); @@ -90,17 +124,41 @@ fn main_0() -> i32 { assert!(({ ({ (*a.borrow()).v } == 6) })); let vec_: Value> = Rc::new(RefCell::new(Vec::new())); { - let __a1 = MoveOnly::new({ 7 }); + let __a1 = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::new(__v.as_pointer(), { 7 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; (*vec_.borrow_mut()).push(__a1) }; - let d: Value = Rc::new(RefCell::new(MoveOnly::new({ 8 }))); + let d: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::new(__v.as_pointer(), { 8 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); ({ MoveOnlyImpl::move_assign(&vec_.decay().offset(0_usize), d.as_pointer()) }); assert!(({ ({ (*vec_.borrow())[0_usize].v } == 8) })); assert!(({ ({ (*d.borrow()).v } == 0) })); - let m: Value = Rc::new(RefCell::new(ConstMoveAssign::new())); - let m1: Value = Rc::new(RefCell::new(ConstMoveAssign::new())); - let m2: Value = Rc::new(RefCell::new(ConstMoveAssign::new())); - let cm: Value = Rc::new(RefCell::new(ConstMoveAssign::new())); + let m: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ConstMoveAssign::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let m1: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ConstMoveAssign::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let m2: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ConstMoveAssign::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let cm: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ConstMoveAssign::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); ({ ConstMoveAssignImpl::operator_assign_2(&m1.as_pointer(), m.as_pointer()) }); ({ ConstMoveAssignImpl::operator_assign_3(&m2.as_pointer(), cm.as_pointer()) }); assert!(({ ({ (*m1.borrow()).mark } == 1) })); diff --git a/tests/unit/out/refcount/move_ctor.rs b/tests/unit/out/refcount/move_ctor.rs index 9b938215cd..36cf747b26 100644 --- a/tests/unit/out/refcount/move_ctor.rs +++ b/tests/unit/out/refcount/move_ctor.rs @@ -14,15 +14,14 @@ pub struct MoveOnly { pub v: i32, } impl MoveOnly { - pub fn new(mut v: i32) -> Self { - Self { v: v } + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { v: v }); } - pub fn move_from(o: Ptr) -> Self { - let __this: MoveOnly = Self { + pub fn move_from(this: Ptr, o: Ptr) { + this.write(Self { v: o.with(|__s| __s.v), - }; + }); field!(o, v).write(0); - __this } } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg)] @@ -32,23 +31,29 @@ pub struct ConstMove { pub mark: i32, } impl ConstMove { - pub fn new() -> Self { - Self { mark: 0 } + pub fn new(this: Ptr) { + this.write(Self { mark: 0 }); } - pub fn new_1(o: Ptr) -> Self { - Self { + pub fn new_1(this: Ptr, o: Ptr) { + this.write(Self { mark: (o.with(|__s| __s.mark) + 1), - } + }); } - pub fn new_2(o: Ptr) -> Self { - Self { + pub fn new_2(this: Ptr, o: Ptr) { + this.write(Self { mark: (o.with(|__s| __s.mark) + 10), - } + }); } } impl Default for ConstMove { fn default() -> Self { - { ConstMove::new() } + { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ConstMove::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } #[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] @@ -63,28 +68,27 @@ pub struct ThrowingMove { pub moves: i32, } impl ThrowingMove { - pub fn new(mut v: i32) -> Self { - Self { + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { v: v, copies: 0, moves: 0, - } + }); } - pub fn copy_from(o: Ptr) -> Self { - Self { + pub fn copy_from(this: Ptr, o: Ptr) { + this.write(Self { v: o.with(|__s| __s.v), copies: (o.with(|__s| __s.copies) + 1), moves: o.with(|__s| __s.moves), - } + }); } - pub fn move_from(o: Ptr) -> Self { - let __this: ThrowingMove = Self { + pub fn move_from(this: Ptr, o: Ptr) { + this.write(Self { v: o.with(|__s| __s.v), copies: o.with(|__s| __s.copies), moves: (o.with(|__s| __s.moves) + 1), - }; + }); field!(o, v).write(0); - __this } } impl Clone for ThrowingMove { @@ -94,7 +98,9 @@ impl Clone for ThrowingMove { copies: self.copies.clone(), moves: self.moves.clone(), })); - ThrowingMove::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ThrowingMove::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } #[derive(Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, MoveCtor, CppFrom, Default)] @@ -109,28 +115,27 @@ pub struct NoexceptMove { pub moves: i32, } impl NoexceptMove { - pub fn new(mut v: i32) -> Self { - Self { + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { v: v, copies: 0, moves: 0, - } + }); } - pub fn copy_from(o: Ptr) -> Self { - Self { + pub fn copy_from(this: Ptr, o: Ptr) { + this.write(Self { v: o.with(|__s| __s.v), copies: (o.with(|__s| __s.copies) + 1), moves: o.with(|__s| __s.moves), - } + }); } - pub fn move_from(o: Ptr) -> Self { - let __this: NoexceptMove = Self { + pub fn move_from(this: Ptr, o: Ptr) { + this.write(Self { v: o.with(|__s| __s.v), copies: o.with(|__s| __s.copies), moves: (o.with(|__s| __s.moves) + 1), - }; + }); field!(o, v).write(0); - __this } } impl Clone for NoexceptMove { @@ -140,68 +145,162 @@ impl Clone for NoexceptMove { copies: self.copies.clone(), moves: self.moves.clone(), })); - NoexceptMove::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + NoexceptMove::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } pub fn by_value_0(mut m: MoveOnly) -> i32 { return m.v; } pub fn make_1(mut v: i32) -> MoveOnly { - let m: Value = Rc::new(RefCell::new(MoveOnly::new({ v }))); - return MoveOnly::move_from({ m.as_pointer() }); + let m: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::new(__v.as_pointer(), { v }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + return { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::move_from(__v.as_pointer(), { m.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; } pub fn main() { __cpp2rust_init_globals(); libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let a: Value = Rc::new(RefCell::new(MoveOnly::new({ 1 }))); - let b: Value = Rc::new(RefCell::new(MoveOnly::move_from({ a.as_pointer() }))); + let a: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let b: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::move_from(__v.as_pointer(), { a.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!(({ ({ (*b.borrow()).v } == 1) })); assert!(({ ({ (*a.borrow()).v } == 0) })); - let c: Value = Rc::new(RefCell::new(MoveOnly::move_from({ b.as_pointer() }))); + let c: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::move_from(__v.as_pointer(), { b.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!(({ ({ (*c.borrow()).v } == 1) })); assert!(({ ({ (*b.borrow()).v } == 0) })); - let mut d: MoveOnly = MoveOnly::move_from({ c.as_pointer() }); + let mut d: MoveOnly = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::move_from(__v.as_pointer(), { c.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((d.v == 1)); assert!(({ ({ (*c.borrow()).v } == 0) })); let e: Value = Rc::new(RefCell::new(({ make_1(5) }))); assert!(({ ({ (*e.borrow()).v } == 5) })); - assert!((({ by_value_0(MoveOnly::new({ 6 },),) }) == 6)); - assert!((({ by_value_0(MoveOnly::move_from({ e.as_pointer() },),) }) == 5)); + assert!( + (({ + by_value_0({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::new(__v.as_pointer(), { 6 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }) + }) == 6) + ); + assert!( + (({ + by_value_0({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::move_from(__v.as_pointer(), { e.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }) + }) == 5) + ); assert!(({ ({ (*e.borrow()).v } == 0) })); let mut vec_: Vec = Vec::new(); { - let __a1 = MoveOnly::new({ 7 }); + let __a1 = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::new(__v.as_pointer(), { 7 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; vec_.push(__a1) }; - let f: Value = Rc::new(RefCell::new(MoveOnly::new({ 8 }))); + let f: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::new(__v.as_pointer(), { 8 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); { - let __a1 = MoveOnly::move_from({ f.as_pointer() }); + let __a1 = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::move_from(__v.as_pointer(), { f.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; vec_.push(__a1) }; assert!((vec_[0_usize].v == 7) && (vec_[1_usize].v == 8)); assert!(({ ({ (*f.borrow()).v } == 0) })); - let m: Value = Rc::new(RefCell::new(ConstMove::new())); - let mut m1: ConstMove = ConstMove::new_1({ m.as_pointer() }); - let cm: Value = Rc::new(RefCell::new(ConstMove::new())); - let mut m2: ConstMove = ConstMove::new_2({ cm.as_pointer() }); + let m: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ConstMove::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let mut m1: ConstMove = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ConstMove::new_1(__v.as_pointer(), { m.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; + let cm: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ConstMove::new(__v.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let mut m2: ConstMove = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ConstMove::new_2(__v.as_pointer(), { cm.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((m1.mark == 1)); assert!((m2.mark == 10)); - let t: Value = Rc::new(RefCell::new(ThrowingMove::new({ 1 }))); - let mut t1: ThrowingMove = ThrowingMove::copy_from({ t.as_pointer() }); + let t: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ThrowingMove::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let mut t1: ThrowingMove = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + ThrowingMove::copy_from(__v.as_pointer(), { t.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((t1.v == 1)); assert!((t1.copies == 1)); assert!((t1.moves == 0)); assert!(({ ({ (*t.borrow()).v } == 1) })); - let n: Value = Rc::new(RefCell::new(NoexceptMove::new({ 2 }))); - let mut n1: NoexceptMove = NoexceptMove::move_from({ n.as_pointer() }); + let n: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + NoexceptMove::new(__v.as_pointer(), { 2 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let mut n1: NoexceptMove = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + NoexceptMove::move_from(__v.as_pointer(), { n.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((n1.v == 2)); assert!((n1.copies == 0)); assert!((n1.moves == 1)); assert!(({ ({ (*n.borrow()).v } == 0) })); - let g: Value = Rc::new(RefCell::new(MoveOnly::new({ 3 }))); - let mut g1: MoveOnly = MoveOnly::move_from({ g.as_pointer() }); + let g: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::new(__v.as_pointer(), { 3 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let mut g1: MoveOnly = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MoveOnly::move_from(__v.as_pointer(), { g.as_pointer() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!((g1.v == 3)); assert!(({ ({ (*g.borrow()).v } == 0) })); return 0; diff --git a/tests/unit/out/refcount/move_this.rs b/tests/unit/out/refcount/move_this.rs index 8781a89b51..95ee1092e1 100644 --- a/tests/unit/out/refcount/move_this.rs +++ b/tests/unit/out/refcount/move_this.rs @@ -14,26 +14,27 @@ pub struct Chain { pub v: i32, } impl Chain { - pub fn new(mut v: i32) -> Self { - Self { v: v } + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { v: v }); } - pub fn copy_from(o: Ptr) -> Self { - Self { + pub fn copy_from(this: Ptr, o: Ptr) { + this.write(Self { v: (o.with(|__s| __s.v) + 100), - } + }); } - pub fn move_from(o: Ptr) -> Self { - let __this: Chain = Self { + pub fn move_from(this: Ptr, o: Ptr) { + this.write(Self { v: (o.with(|__s| __s.v) + 1), - }; + }); field!(o, v).write(0); - __this } } impl Clone for Chain { fn clone(&self) -> Self { let __src: Value = Rc::new(RefCell::new(Chain { v: self.v.clone() })); - Chain::copy_from(__src.as_pointer()) + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Chain::copy_from(__v.as_pointer(), __src.as_pointer()); + Rc::try_unwrap(__v).ok().unwrap().into_inner() } } pub fn consume_0(mut c: Chain) -> i32 { @@ -44,29 +45,62 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let a: Value = Rc::new(RefCell::new(Chain::new({ 1 }))); + let a: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Chain::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); ({ ChainImpl::add_4(&({ ChainImpl::add_4(&a.as_pointer(), 1) }), 1) }); assert!(({ ({ (*a.borrow()).v } == 3) })); - let b0: Value = Rc::new(RefCell::new(Chain::new({ 5 }))); - let mut b: Chain = Chain::move_from({ - ({ ChainImpl::add_5(&({ ChainImpl::add_5(&b0.as_pointer(), 1) }), 1) }) - }); + let b0: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Chain::new(__v.as_pointer(), { 5 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let mut b: Chain = { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Chain::move_from(__v.as_pointer(), { + ({ ChainImpl::add_5(&({ ChainImpl::add_5(&b0.as_pointer(), 1) }), 1) }) + }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; assert!(({ (b.v == 8) && ({ (*b0.borrow()).v } == 0) })); let c: Value = Rc::new(RefCell::new( - ({ ChainImpl::take(&Rc::new(RefCell::new(Chain::new({ 10 }))).as_pointer()) }), + ({ + ChainImpl::take( + &Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Chain::new(__v.as_pointer(), { 10 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })) + .as_pointer(), + ) + }), )); assert!(({ ({ (*c.borrow()).v } == 11) })); let mut d: Chain = ({ ChainImpl::copy(&c.as_pointer()) }); assert!(({ (d.v == 111) && ({ (*c.borrow()).v } == 11) })); - let g: Value = Rc::new(RefCell::new(Chain::new({ 20 }))); + let g: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Chain::new(__v.as_pointer(), { 20 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!( (({ - consume_0(Chain::move_from({ - ({ ChainImpl::self_(&g.as_pointer()) }) - })) + consume_0({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Chain::move_from(__v.as_pointer(), { + ({ ChainImpl::self_(&g.as_pointer()) }) + }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }) }) == 21) ); - let e: Value = Rc::new(RefCell::new(Chain::new({ 30 }))); + let e: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Chain::new(__v.as_pointer(), { 30 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); let mut f: Chain = ({ ChainImpl::take(&e.as_pointer()) }); assert!(({ (f.v == 31) && ({ (*e.borrow()).v } == 0) })); return 0; @@ -94,10 +128,18 @@ impl ChainImpl for Ptr { return (*self).clone(); } fn take(&self) -> Chain { - return Chain::move_from({ (*self).clone() }); + return { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Chain::move_from(__v.as_pointer(), { (*self).clone() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; } fn copy(&self) -> Chain { - return Chain::copy_from({ (*self).clone() }); + return { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Chain::copy_from(__v.as_pointer(), { (*self).clone() }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; } fn self_(&self) -> Ptr { return (*self).clone(); diff --git a/tests/unit/out/refcount/operator_comparison_nonbool.rs b/tests/unit/out/refcount/operator_comparison_nonbool.rs index b4307e2bc5..9fb2c686b0 100644 --- a/tests/unit/out/refcount/operator_comparison_nonbool.rs +++ b/tests/unit/out/refcount/operator_comparison_nonbool.rs @@ -76,8 +76,8 @@ pub struct MyBool { pub value: bool, } impl MyBool { - pub fn new(mut v: bool) -> Self { - Self { value: v } + pub fn new(this: Ptr, mut v: bool) { + this.write(Self { value: v }); } } #[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] @@ -103,10 +103,18 @@ impl CppEq for Boolish { } } pub fn operator_eq_7(mut a: Boolish, mut b: Boolish) -> MyBool { - return MyBool::new({ (a.v == b.v) }); + return { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MyBool::new(__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 MyBool::new({ (a.v < b.v) }); + return { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + MyBool::new(__v.as_pointer(), { (a.v < b.v) }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + }; } #[derive(Record, ByteRepr, ZeroInitialization, FnPtrArg, CppFrom, Default)] #[cpp_into(bool, to_bool)] @@ -116,12 +124,16 @@ pub struct RefBool { pub value: bool, } impl RefBool { - pub fn new(mut v: bool) -> Self { - Self { value: v } + pub fn new(this: Ptr, mut v: bool) { + this.write(Self { value: v }); } } thread_local!( - pub static ref_true_8: Value = Rc::new(RefCell::new(RefBool::new({ true }))); + pub static ref_true_8: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + RefBool::new(__v.as_pointer(), { true }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); ); #[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] #[byte_size(4)] diff --git a/tests/unit/out/refcount/operator_comparison_noncopyable.rs b/tests/unit/out/refcount/operator_comparison_noncopyable.rs index 729adfa5ee..21f9850377 100644 --- a/tests/unit/out/refcount/operator_comparison_noncopyable.rs +++ b/tests/unit/out/refcount/operator_comparison_noncopyable.rs @@ -20,13 +20,13 @@ pub struct S { data_: i32, } impl S { - pub fn new(mut data: i32) -> Self { - Self { data_: data } + pub fn new(this: Ptr, mut data: i32) { + this.write(Self { data_: data }); } - pub fn move_from(_a0: Ptr) -> Self { - Self { + pub fn move_from(this: Ptr, _a0: Ptr) { + this.write(Self { data_: { (*_a0.upgrade().deref()).data_ }, - } + }); } } impl CppLess for S { @@ -44,9 +44,21 @@ pub fn main() { libcc2rs::cpp2rust_exit(main_0()); } fn main_0() -> i32 { - let a: Value = Rc::new(RefCell::new(S::new({ 1 }))); - let b: Value = Rc::new(RefCell::new(S::new({ 2 }))); - let c: Value = Rc::new(RefCell::new(S::new({ 1 }))); + let a: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + S::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let b: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + S::new(__v.as_pointer(), { 2 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); + let c: Value = Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + S::new(__v.as_pointer(), { 1 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })); assert!( ({ let _x: Ptr = a.as_pointer(); diff --git a/tests/unit/out/refcount/pair_converting_construction.rs b/tests/unit/out/refcount/pair_converting_construction.rs index 6ee4d35353..51e828aa57 100644 --- a/tests/unit/out/refcount/pair_converting_construction.rs +++ b/tests/unit/out/refcount/pair_converting_construction.rs @@ -14,8 +14,8 @@ pub struct Celsius { pub degrees: i32, } impl Celsius { - pub fn new(mut d: i32) -> Self { - Self { degrees: d } + pub fn new(this: Ptr, mut d: i32) { + this.write(Self { degrees: d }); } } #[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] @@ -33,10 +33,10 @@ pub struct Label { pub id: i32, } impl Label { - pub fn new(c: Ptr) -> Self { - Self { + pub fn new(this: Ptr, c: Ptr) { + this.write(Self { id: c.with(|__s| __s.degrees), - } + }); } } #[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] @@ -50,17 +50,17 @@ pub struct Owner { pub copied: i32, } impl Owner { - pub fn new_1(c: Ptr) -> Self { - Self { + pub fn new_1(this: Ptr, c: Ptr) { + this.write(Self { taken: 0, copied: c.with(|__s| __s.degrees), - } + }); } - pub fn new_2(c: Ptr) -> Self { - Self { + pub fn new_2(this: Ptr, c: Ptr) { + this.write(Self { taken: c.with(|__s| __s.degrees), copied: 0, - } + }); } } #[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] @@ -71,8 +71,8 @@ pub struct Holder { pub value: i32, } impl Holder { - pub fn new(mut c: Celsius) -> Self { - Self { value: c.degrees } + pub fn new(this: Ptr, mut c: Celsius) { + this.write(Self { value: c.degrees }); } } #[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom)] @@ -83,13 +83,19 @@ pub struct Fallback { pub value: i32, } impl Fallback { - pub fn new(mut v: i32) -> Self { - Self { value: v } + pub fn new(this: Ptr, mut v: i32) { + this.write(Self { value: v }); } } impl Default for Fallback { fn default() -> Self { - { Fallback::new({ -1_i32 }) } + { + { + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Fallback::new(__v.as_pointer(), { -1_i32 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + } + } } } #[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, Default)] @@ -106,19 +112,18 @@ pub struct Observer { pub seen: i32, } impl Observer { - pub fn new(c: Ptr) -> Self { - let __this: Observer = Self { + pub fn new(this: Ptr, c: Ptr) { + this.write(Self { seen: c.with(|__s| __s.hits), - }; + }); field!(c, hits).with_mut(|__v| __v.postfix_inc()); - __this } } impl Tag { - pub fn new(u: Ptr) -> Self { - Self { + pub fn new(this: Ptr, u: Ptr) { + this.write(Self { code: (u.with(|__s| __s.degrees) + 100), - } + }); } } #[derive(Copy, Clone, Record, ByteRepr, ZeroInitialization, VaArg, FnPtrArg, CppFrom, Default)] @@ -136,15 +141,13 @@ pub struct Name { pub len: i32, } impl Name { - pub fn new(mut s: Ptr) -> Self { - let __this: Value = Rc::new(RefCell::new(Self { len: 0 })); - let this: Ptr = __this.as_pointer(); + pub fn new(this: Ptr, mut s: Ptr) { + this.write(Self { len: 0 }); 'loop_: while ((elem!(s, this.with(|__s| __s.len)).read()) != 0) { field!(this, len).with_mut(|__v| { __v.prefix_inc(); }); } - Rc::try_unwrap(__this).ok().unwrap().into_inner() } } pub fn main() { @@ -159,8 +162,16 @@ fn main_0() -> i32 { assert!(({ ((*(*widened.borrow()).0.borrow()) == -1_i64) })); assert!(({ ((*(*widened.borrow()).1.borrow()) == 2_u32) })); let from_ints: Value<(Value, Value)> = Rc::new(RefCell::new(( - Rc::new(RefCell::new(Celsius::new({ 1 }))), - Rc::new(RefCell::new(Celsius::new({ 2 }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Celsius::new(__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())); + Celsius::new(__v.as_pointer(), { 2 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ))); assert!(({ ({ (*(*from_ints.borrow()).0.borrow()).degrees } == 1) })); assert!(({ ({ (*(*from_ints.borrow()).1.borrow()).degrees } == 2) })); @@ -221,8 +232,16 @@ fn main_0() -> i32 { assert!(({ ((*(*from_operator_pair.borrow()).0.borrow()) == 8) })); assert!(({ ((*(*from_operator_pair.borrow()).1.borrow()) == 9) })); let celsius: Value<(Value, Value)> = Rc::new(RefCell::new(( - Rc::new(RefCell::new(Celsius::new({ 10 }))), - Rc::new(RefCell::new(Celsius::new({ 11 }))), + Rc::new(RefCell::new({ + let __v: Value = Rc::new(RefCell::new(::zero_init())); + Celsius::new(__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())); + Celsius::new(__v.as_pointer(), { 11 }); + Rc::try_unwrap(__v).ok().unwrap().into_inner() + })), ))); let from_record_pair: Value<(Value