From 0131dd5f3c3f3510e3e8a2be13aa29df4e40074e Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sun, 29 Nov 2026 20:59:28 +0000 Subject: [PATCH 1/4] Unify destruction for lambdas and user-defined classes --- cpp2rust/converter/converter.cpp | 34 ++++++----------- .../converter/models/converter_refcount.cpp | 38 ++++++++----------- libcc2rs-macros/src/destructor.rs | 4 +- libcc2rs-macros/src/lib.rs | 14 +++---- libcc2rs/src/capture.rs | 22 +++++------ libcc2rs/src/lib.rs | 8 ++-- libcc2rs/src/swap.rs | 12 +++--- 7 files changed, 56 insertions(+), 76 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index eb0231c9f0..52b4ca2574 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -752,21 +752,19 @@ bool Converter::VarTypeNeedsDestructor(clang::QualType type) const { } std::string Converter::StaticDestructorCall(const clang::VarDecl *decl) { - auto destroy = AsLambdaClass(decl->getType()) ? "destroy" : kDestructorName; - return std::format( - "(*std::cell::LazyCell::force_mut(&mut *&raw mut {})).{}()", - GetNamedDeclAsString(decl), destroy); + return std::format("DestructibleUnsafe::destroy(&raw mut " + "*std::cell::LazyCell::force_mut(&mut *&raw mut {}))", + GetNamedDeclAsString(decl)); } void Converter::EmitScopedDestructor(const clang::VarDecl *decl) { if (!NeedsScopedDestructor(decl)) { return; } - auto destroy = AsLambdaClass(decl->getType()) ? "destroy" : kDestructorName; StrCat(token::kSemiColon, std::format("let _dtor_{0} = std::mem::DropGuard::new(&raw mut {0}, " - "|__p| unsafe {{ (*__p).{1}() }})", - GetNamedDeclAsString(decl), destroy)); + "|__p| unsafe {{ DestructibleUnsafe::destroy(__p) }})", + GetNamedDeclAsString(decl))); } bool Converter::RecordDerivesDefault(const clang::RecordDecl *decl) { @@ -1027,17 +1025,8 @@ std::string Converter::DestroyMembers(const clang::CXXRecordDecl *decl) { for (auto *field : FieldsToDestroy(decl)) { auto name = GetNamedDeclAsString(field); auto type = field->getType(); - if (type->isArrayType()) { - auto *elem = type->getBaseElementTypeUnsafe()->getAsCXXRecordDecl(); - assert(elem); - out += - std::format("for __e in self.{0}.iter_mut() {{ {1}::{2}(__e); }}\n", - name, GetRecordName(elem), kDestructorName); - } else { - out += std::format("{1}::{2}(&mut self.{0});\n", name, - GetRecordName(type->getAsCXXRecordDecl()), - kDestructorName); - } + out += std::format("DestructibleUnsafe::destroy(&raw mut self.{});\n", + name); } return out; } @@ -4164,11 +4153,10 @@ bool Converter::VisitCXXDeleteExpr(clang::CXXDeleteExpr *expr) { StrCat( std::format("for __i in (0..libcc2rs::malloc_usable_size(__p as *mut " "::libc::c_void) / ::std::mem::size_of::<{0}>()).rev() {{ " - "{0}::{1}(&mut *__p.add(__i)); }}", - record_name, kDestructorName)); + "DestructibleUnsafe::destroy(__p.add(__i)); }}", + record_name)); } else { - StrCat(std::format("{}::{}(&mut *__p)", record_name, kDestructorName), - token::kSemiColon); + StrCat("DestructibleUnsafe::destroy(__p)", token::kSemiColon); } EmitDeallocation(expr, "__p"); return false; @@ -4775,7 +4763,7 @@ Converter::GetStructAttributes(const clang::RecordDecl *decl) { if (auto *cxx = clang::dyn_cast(decl); cxx && RecordNeedsDestruction(cxx)) { - struct_attrs.emplace_back("DestructorUnsafe"); + struct_attrs.emplace_back("DestructibleUnsafe"); } if (RecordDerivesDefault(decl)) { diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index bcb26c3f41..36c89e13f5 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -935,22 +935,17 @@ void ConverterRefCount::EmitScopedDestructor(const clang::VarDecl *decl) { if (!NeedsScopedDestructor(decl)) { return; } - auto destroy = AsLambdaClass(decl->getType()) - ? std::string("with(|__f| __f.destroy())") - : std::format("{}()", kDestructorName); StrCat(token::kSemiColon, std::format("let _dtor_{0} = std::mem::DropGuard::new({0}.clone(), " - "|__p| __p.as_pointer().{1})", - GetNamedDeclAsString(decl), destroy)); + "|__p| Destructible::destroy(__p.as_pointer()))", + GetNamedDeclAsString(decl))); } std::string ConverterRefCount::StaticDestructorCall(const clang::VarDecl *decl) { - auto destroy = AsLambdaClass(decl->getType()) - ? std::string("with(|__f| __f.destroy())") - : std::format("{}()", kDestructorName); - return std::format("{}.with(Value::clone).as_pointer().{}", - GetNamedDeclAsString(decl), destroy); + return std::format( + "Destructible::destroy({}.with(Value::clone).as_pointer())", + GetNamedDeclAsString(decl)); } bool ConverterRefCount::ConvertIncAndDec(clang::UnaryOperator *expr) { @@ -2025,11 +2020,10 @@ bool ConverterRefCount::VisitCXXDeleteExpr(clang::CXXDeleteExpr *expr) { StrCat(keyword::kLet, "__p", token::kAssign, ToString(expr->getArgument()), token::kSemiColon); if (expr->isArrayForm()) { - StrCat(std::format("for __i in (0..__p.len()).rev() {{ __p.offset(__i as " - "isize).{}(); }}", - kDestructorName)); + StrCat("for __i in (0..__p.len()).rev() { " + "Destructible::destroy(__p.offset(__i as isize)); }"); } else { - StrCat(std::format("__p.{}();", kDestructorName)); + StrCat("Destructible::destroy(__p.clone());"); } StrCat("__p.delete();"); return false; @@ -2309,7 +2303,7 @@ ConverterRefCount::GetStructAttributes(const clang::RecordDecl *decl) { if (auto *cxx = clang::dyn_cast(decl); cxx && RecordNeedsDestruction(cxx)) { - attrs.emplace_back("Destructor"); + attrs.emplace_back("Destructible"); } if (RecordDerivesDefault(decl)) { @@ -3645,16 +3639,14 @@ ConverterRefCount::DestroyMembers(const clang::CXXRecordDecl *decl) { for (auto *field : FieldsToDestroy(decl)) { auto name = GetNamedDeclAsString(field); if (field->getType()->isArrayType()) { - auto *elem = - field->getType()->getBaseElementTypeUnsafe()->getAsCXXRecordDecl(); - assert(elem); out += std::format( - "{{ let __p = array_field_ptr!(self, {0}); for __i in " - "0..__p.len() {{ {2}::{1}(&__p.offset(__i as isize)); }} }}\n", - name, kDestructorName, TraitName(elem)); + "{{ let __p = array_field_ptr!(self, {}); for __i in " + "(0..__p.len()).rev() {{ Destructible::destroy(__p.offset(__i as " + "isize)); }} }}\n", + name); } else { - out += - std::format("field_ptr!(self, {0}).{1}();\n", name, kDestructorName); + out += std::format("Destructible::destroy(field_ptr!(self, {}));\n", + name); } } return out; diff --git a/libcc2rs-macros/src/destructor.rs b/libcc2rs-macros/src/destructor.rs index cbbe5b8947..a7a0ddbe42 100644 --- a/libcc2rs-macros/src/destructor.rs +++ b/libcc2rs-macros/src/destructor.rs @@ -11,7 +11,7 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { let (impl_generics, ty_generics, where_clause) = input.generics.split_for_impl(); if is_unsafe { quote! { - impl #impl_generics ::libcc2rs::DestructorUnsafe for #name #ty_generics #where_clause { + impl #impl_generics ::libcc2rs::DestructibleUnsafe for #name #ty_generics #where_clause { unsafe fn destroy(p: *mut Self) { unsafe { (*p).destructor() } } @@ -19,7 +19,7 @@ pub fn expand(input: TokenStream, is_unsafe: bool) -> TokenStream { } } else { quote! { - impl #impl_generics ::libcc2rs::Destructor for #name #ty_generics #where_clause { + impl #impl_generics ::libcc2rs::Destructible for #name #ty_generics #where_clause { fn destroy(p: ::libcc2rs::Ptr) { p.destructor() } diff --git a/libcc2rs-macros/src/lib.rs b/libcc2rs-macros/src/lib.rs index 96783b6ab2..846b24c7d2 100644 --- a/libcc2rs-macros/src/lib.rs +++ b/libcc2rs-macros/src/lib.rs @@ -200,23 +200,23 @@ pub fn derive_move_assign_unsafe(input: TokenStream) -> TokenStream { assign::expand(input, "move", true) } -// #[derive(Destructor)] +// #[derive(Destructible)] // pub struct S { ... } // impl SImpl for Ptr { // fn destructor(&self) { ... } // } // -// Implements libcc2rs::Destructor for S with its destructor, such that -// lambda! destroys the captures of type S with it. DestructorUnsafe is the +// Implements libcc2rs::Destructible for S with its destructor, through which +// the translation destroys every object of type S. DestructibleUnsafe is the // same for the unsafe model, whose destructor is a method of S. -#[proc_macro_derive(Destructor)] -pub fn derive_destructor(input: TokenStream) -> TokenStream { +#[proc_macro_derive(Destructible)] +pub fn derive_destructible(input: TokenStream) -> TokenStream { destructor::expand(input, false) } -#[proc_macro_derive(DestructorUnsafe)] -pub fn derive_destructor_unsafe(input: TokenStream) -> TokenStream { +#[proc_macro_derive(DestructibleUnsafe)] +pub fn derive_destructible_unsafe(input: TokenStream) -> TokenStream { destructor::expand(input, true) } diff --git a/libcc2rs/src/capture.rs b/libcc2rs/src/capture.rs index 8aec8825c1..8b9891daa3 100644 --- a/libcc2rs/src/capture.rs +++ b/libcc2rs/src/capture.rs @@ -13,7 +13,7 @@ // - a type that is not Clone is not copyable, and neither is the lambda, // so its copy constructor is unreachable. // Likewise, the destructor of the lambda (`destroy_capture()`) destroys the -// captures that have a C++ destructor (Destructor), in reverse order. +// captures that have a C++ destructor (Destructible), in reverse order. // In the refcount model, a capture by value is a Value, which is copied // into a new Value, and a capture by reference is a Ptr, which is copied. @@ -135,32 +135,32 @@ impl MoveCtorUnsafe for [T; N] { } // The C++ destructor of a type, in the refcount model, for the types that -// have one. Records implement it with #[derive(Destructor)]. -pub trait Destructor: Sized { +// have one. Records implement it with #[derive(Destructible)]. +pub trait Destructible: Sized { fn destroy(p: Ptr); } // The C++ destructor of a type, in the unsafe model. Records implement it -// with #[derive(DestructorUnsafe)]. -pub trait DestructorUnsafe: Sized { +// with #[derive(DestructibleUnsafe)]. +pub trait DestructibleUnsafe: Sized { /// # Safety /// `p` must point to a live value. unsafe fn destroy(p: *mut Self); } -impl Destructor for FnPtr { +impl Destructible for FnPtr { fn destroy(p: Ptr) { p.with(|f| f.destroy()) } } -impl DestructorUnsafe for FnPtr { +impl DestructibleUnsafe for FnPtr { unsafe fn destroy(p: *mut Self) { unsafe { (*p).destroy() } } } -impl DestructorUnsafe for [T; N] { +impl DestructibleUnsafe for [T; N] { unsafe fn destroy(p: *mut Self) { let p = p as *mut T; for i in (0..N).rev() { @@ -264,7 +264,7 @@ pub trait DestroyElems { fn destroy_capture(&self); } -impl DestroyElems for &&Capture<'_, Value>> { +impl DestroyElems for &&Capture<'_, Value>> { fn destroy_capture(&self) { let p: Ptr = self.0.decay(); for i in (0..self.0.borrow().len()).rev() { @@ -277,7 +277,7 @@ pub trait DestroyWithDtor { fn destroy_capture(&self); } -impl DestroyWithDtor for &Capture<'_, Value> { +impl DestroyWithDtor for &Capture<'_, Value> { fn destroy_capture(&self) { T::destroy(AsPointer::::as_pointer(self.0)) } @@ -359,7 +359,7 @@ pub trait DestroyWithDtorUnsafe { unsafe fn destroy_capture(&self); } -impl DestroyWithDtorUnsafe for &CaptureUnsafe { +impl DestroyWithDtorUnsafe for &CaptureUnsafe { unsafe fn destroy_capture(&self) { unsafe { T::destroy(self.0) } } diff --git a/libcc2rs/src/lib.rs b/libcc2rs/src/lib.rs index b74661d9ea..3b4c692a15 100644 --- a/libcc2rs/src/lib.rs +++ b/libcc2rs/src/lib.rs @@ -43,7 +43,7 @@ pub use fn_ptr::{FnPtr, Generic}; mod capture; pub use capture::{ - CopyAssign, CopyAssignUnsafe, Destructor, DestructorUnsafe, MoveAssign, MoveAssignUnsafe, + CopyAssign, CopyAssignUnsafe, Destructible, DestructibleUnsafe, MoveAssign, MoveAssignUnsafe, MoveCtor, MoveCtorUnsafe, }; @@ -104,7 +104,7 @@ mod format; 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, + ByteRepr, CopyAssign, CopyAssignUnsafe, CppFrom, CppFromUnsafe, Destructible, + DestructibleUnsafe, FnPtrArg, MoveAssign, MoveAssignUnsafe, MoveCtor, MoveCtorUnsafe, Record, + VaArg, goto, goto_block, lambda, lambda_unsafe, switch, }; diff --git a/libcc2rs/src/swap.rs b/libcc2rs/src/swap.rs index eb25244d99..bd7eeb4ef7 100644 --- a/libcc2rs/src/swap.rs +++ b/libcc2rs/src/swap.rs @@ -17,7 +17,7 @@ // types without one; the other types are assigned as a whole, by moving // the value with the move constructor (MoveCtor), or else by copying it // (Clone); -// - the temporary is destroyed with the destructor, if any (Destructor). +// - the temporary is destroyed with the destructor, if any (Destructible). // The values are accessed one at a time, so they may be in the same // allocation, e.g., two fields of a struct. // @@ -32,7 +32,7 @@ use std::cell::RefCell; use std::rc::Rc; use crate::capture::{ - CopyAssign, CopyAssignUnsafe, Destructor, DestructorUnsafe, MoveAssign, MoveAssignUnsafe, + CopyAssign, CopyAssignUnsafe, Destructible, DestructibleUnsafe, MoveAssign, MoveAssignUnsafe, MoveCtor, MoveCtorUnsafe, }; use crate::rc::{AsPointer, Ptr, Value}; @@ -138,14 +138,14 @@ trivial!(Trivial, Ptr, HasNone, HasMoveCtor: MoveCtor for &&&&&Trivial<'_, T>, HasMoveAssign: MoveAssign for &&&&Trivial<'_, T>, HasCopyAssign: CopyAssign for &&&Trivial<'_, T>, - HasDestructor: Destructor for &&Trivial<'_, T> + HasDestructor: Destructible for &&Trivial<'_, T> ); trivial!(TrivialUnsafe, *mut T, HasNoneUnsafe, HasMoveCtorUnsafe: MoveCtorUnsafe for &&&&&TrivialUnsafe<'_, T>, HasMoveAssignUnsafe: MoveAssignUnsafe for &&&&TrivialUnsafe<'_, T>, HasCopyAssignUnsafe: CopyAssignUnsafe for &&&TrivialUnsafe<'_, T>, - HasDestructorUnsafe: DestructorUnsafe for &&TrivialUnsafe<'_, T> + HasDestructorUnsafe: DestructibleUnsafe for &&TrivialUnsafe<'_, T> ); #[cold] @@ -282,7 +282,7 @@ pub trait DestroyNone { fn destroy(self); } -impl DestroyWithDtor for &&Destroy<'_, T> { +impl DestroyWithDtor for &&Destroy<'_, T> { fn destroy(self) { T::destroy(self.0.clone()) } @@ -386,7 +386,7 @@ pub trait DestroyNoneUnsafe { unsafe fn destroy(self); } -impl DestroyWithDtorUnsafe for &&DestroyUnsafe { +impl DestroyWithDtorUnsafe for &&DestroyUnsafe { unsafe fn destroy(self) { unsafe { T::destroy(self.0) } } From 84074e925a7209347d062e29f3b5e075b77e67bd Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sun, 29 Nov 2026 21:10:20 +0000 Subject: [PATCH 2/4] Update tests --- cpp2rust/converter/converter.cpp | 1 - .../out/refcount/p14-class-in-two-files.rs | 10 +-- .../out/unsafe/p14-class-in-two-files.rs | 16 ++-- .../p15-class-template-static-member.rs | 6 +- .../p15-class-template-static-member.rs | 10 ++- .../out/refcount/p15-function-template.rs | 22 +++-- .../out/unsafe/p15-function-template.rs | 24 +++-- .../out/refcount/p15-inline-function.rs | 10 ++- .../out/unsafe/p15-inline-function.rs | 12 ++- .../out/refcount/p15-inline-variable.rs | 8 +- .../out/unsafe/p15-inline-variable.rs | 12 ++- .../p16-default-argument-lambda-in-class.rs | 8 +- .../p16-default-argument-lambda-in-class.rs | 12 ++- .../refcount/p16-lambda-in-inline-function.rs | 8 +- .../unsafe/p16-lambda-in-inline-function.rs | 12 ++- .../out/refcount/basic.scope.block.rs | 44 ++++++---- .../out/unsafe/basic.scope.block.rs | 44 ++++++---- .../out/refcount/basic.start.term-p1-exit.rs | 11 +-- .../out/refcount/basic.start.term.rs | 30 +++---- .../out/unsafe/basic.start.term-p1-exit.rs | 15 ++-- .../out/unsafe/basic.start.term.rs | 42 ++++++--- tests/std/basic/out/refcount/basic.def.odr.rs | 32 ++++--- tests/std/basic/out/unsafe/basic.def.odr.rs | 40 ++++++--- .../stmt.iter/out/refcount/stmt.while.rs | 14 +-- .../stmt.iter/out/unsafe/stmt.while.rs | 14 +-- .../stmt.select/out/refcount/stmt.if.rs | 6 +- .../stmt.select/out/refcount/stmt.switch.rs | 11 +-- .../stmt.select/out/unsafe/stmt.if.rs | 12 +-- .../stmt.select/out/unsafe/stmt.switch.rs | 14 +-- tests/unit/out/refcount/constructor.rs | 5 +- .../unit/out/refcount/copy_move_defaulted.rs | 36 +++++--- tests/unit/out/refcount/delete_array_order.rs | 4 +- tests/unit/out/refcount/destructor.rs | 76 +++++++++------- tests/unit/out/refcount/destructor_params.rs | 5 +- .../out/refcount/destructor_temporaries.rs | 9 +- .../unit/out/refcount/for_body_destructor.rs | 55 +++++++----- tests/unit/out/refcount/lambda_as_field.rs | 10 ++- .../out/refcount/lambda_capture_copy_ctor.rs | 20 ++--- .../out/refcount/lambda_move_only_capture.rs | 16 ++-- tests/unit/out/refcount/rule_of_five.rs | 17 ++-- tests/unit/out/refcount/rule_of_three.rs | 14 +-- tests/unit/out/refcount/swap_map_no_copy.rs | 43 ++++++--- tests/unit/out/refcount/va_list_field.rs | 5 +- tests/unit/out/unsafe/constructor.rs | 6 +- tests/unit/out/unsafe/copy_move_defaulted.rs | 48 +++++++--- tests/unit/out/unsafe/delete_array_order.rs | 4 +- tests/unit/out/unsafe/destructor.rs | 88 ++++++++++++------- tests/unit/out/unsafe/destructor_params.rs | 6 +- .../unit/out/unsafe/destructor_temporaries.rs | 10 ++- tests/unit/out/unsafe/for_body_destructor.rs | 60 +++++++------ tests/unit/out/unsafe/lambda_as_field.rs | 12 ++- .../out/unsafe/lambda_capture_copy_ctor.rs | 28 ++++-- .../out/unsafe/lambda_move_only_capture.rs | 27 ++++-- tests/unit/out/unsafe/rule_of_five.rs | 22 +++-- tests/unit/out/unsafe/rule_of_three.rs | 18 ++-- tests/unit/out/unsafe/swap_map_no_copy.rs | 40 ++++++--- tests/unit/out/unsafe/va_list_field.rs | 7 +- 57 files changed, 736 insertions(+), 455 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index 52b4ca2574..cdcab90596 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -1024,7 +1024,6 @@ std::string Converter::DestroyMembers(const clang::CXXRecordDecl *decl) { std::string out; for (auto *field : FieldsToDestroy(decl)) { auto name = GetNamedDeclAsString(field); - auto type = field->getType(); out += std::format("DestructibleUnsafe::destroy(&raw mut self.{});\n", name); } 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..37b7baaf37 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, VaArg, FnPtrArg, CopyAssign, Destructible)] #[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, VaArg, FnPtrArg, Destructible, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -77,7 +77,7 @@ thread_local!( pub static check_4: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 2 })); libcc2rs::register_static_destructor(|| { - check_4.with(Value::clone).as_pointer().destructor() + Destructible::destroy(check_4.with(Value::clone).as_pointer()) }); __static }; @@ -86,7 +86,7 @@ thread_local!( pub static shared_5: Value = { let __static = Rc::new(RefCell::new(LifetimeTracked::new())); libcc2rs::register_static_destructor(|| { - shared_5.with(Value::clone).as_pointer().destructor() + Destructible::destroy(shared_5.with(Value::clone).as_pointer()) }); __static }; @@ -103,7 +103,7 @@ thread_local!( static local_6: Value = { let __static = Rc::new(RefCell::new(LifetimeTracked::new())); libcc2rs::register_static_destructor(|| { - local_6.with(Value::clone).as_pointer().destructor() + Destructible::destroy(local_6.with(Value::clone).as_pointer()) }); __static }; 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..5fa5dc515f 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 @@ -11,7 +11,7 @@ pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructibleUnsafe)] pub struct LifetimeTracked { pub uses: i32, } @@ -61,7 +61,7 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -75,7 +75,9 @@ pub static mut check_4: std::cell::LazyCell = { let __static = AssertsDtorCountAtExit { expected: 2 }; libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut check_4)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut check_4, + )) }); __static } @@ -85,7 +87,9 @@ pub static mut shared_5: std::cell::LazyCell = { let __static = LifetimeTracked::new(); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut shared_5, + )) }); __static } @@ -102,7 +106,9 @@ static mut local_6: std::cell::LazyCell = std::cell::LazyCell:: { let __static = LifetimeTracked::new(); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut local_6)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut local_6, + )) }); __static } 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..8984e13533 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, VaArg, FnPtrArg, CopyAssign, Destructible)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -71,7 +71,7 @@ thread_local!( pub static member_4: Value = { let __static = Rc::new(RefCell::new(LifetimeTracked::new())); libcc2rs::register_static_destructor(|| { - member_4.with(Value::clone).as_pointer().destructor() + Destructible::destroy(member_4.with(Value::clone).as_pointer()) }); __static }; @@ -83,7 +83,7 @@ thread_local!( pub static member_5: Value = { let __static = Rc::new(RefCell::new(LifetimeTracked::new())); libcc2rs::register_static_destructor(|| { - member_5.with(Value::clone).as_pointer().destructor() + Destructible::destroy(member_5.with(Value::clone).as_pointer()) }); __static }; 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..3bb6868cbe 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 @@ -11,7 +11,7 @@ pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructibleUnsafe)] pub struct LifetimeTracked { pub uses: i32, } @@ -65,7 +65,9 @@ pub static mut member_4: std::cell::LazyCell = { let __static = LifetimeTracked::new(); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut member_4)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut member_4, + )) }); __static } @@ -78,7 +80,9 @@ pub static mut member_5: std::cell::LazyCell = { let __static = LifetimeTracked::new(); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut member_5)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut member_5, + )) }); __static } 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..0934af5384 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, VaArg, FnPtrArg, CopyAssign, Destructible)] #[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, VaArg, FnPtrArg, Destructible, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -85,7 +85,9 @@ pub fn count_10() -> i32 { thread_local!( static t_5: Value = { let __static = Rc::new(RefCell::new(LifetimeTracked::new())); - libcc2rs::register_static_destructor(|| t_5.with(Value::clone).as_pointer().destructor()); + libcc2rs::register_static_destructor(|| { + Destructible::destroy(t_5.with(Value::clone).as_pointer()) + }); __static }; ); @@ -95,7 +97,9 @@ thread_local!( thread_local!( static t_8: Value = { let __static = Rc::new(RefCell::new(LifetimeTracked::new())); - libcc2rs::register_static_destructor(|| t_8.with(Value::clone).as_pointer().destructor()); + libcc2rs::register_static_destructor(|| { + Destructible::destroy(t_8.with(Value::clone).as_pointer()) + }); __static }; ); @@ -105,7 +109,9 @@ thread_local!( thread_local!( static t_11: Value = { let __static = Rc::new(RefCell::new(LifetimeTracked::new())); - libcc2rs::register_static_destructor(|| t_11.with(Value::clone).as_pointer().destructor()); + libcc2rs::register_static_destructor(|| { + Destructible::destroy(t_11.with(Value::clone).as_pointer()) + }); __static }; ); @@ -116,7 +122,7 @@ thread_local!( pub static check_13: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 4 })); libcc2rs::register_static_destructor(|| { - check_13.with(Value::clone).as_pointer().destructor() + Destructible::destroy(check_13.with(Value::clone).as_pointer()) }); __static }; @@ -148,7 +154,9 @@ pub fn count_18() -> i32 { thread_local!( static t_19: Value = { let __static = Rc::new(RefCell::new(LifetimeTracked::new())); - libcc2rs::register_static_destructor(|| t_19.with(Value::clone).as_pointer().destructor()); + libcc2rs::register_static_destructor(|| { + Destructible::destroy(t_19.with(Value::clone).as_pointer()) + }); __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..e334d9be49 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 @@ -11,7 +11,7 @@ pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructibleUnsafe)] pub struct LifetimeTracked { pub uses: i32, } @@ -61,7 +61,7 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -83,7 +83,9 @@ static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new( { let __static = LifetimeTracked::new(); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut t_5)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut t_5, + )) }); __static } @@ -93,7 +95,9 @@ static mut t_8: std::cell::LazyCell = std::cell::LazyCell::new( { let __static = LifetimeTracked::new(); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut t_8)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut t_8, + )) }); __static } @@ -103,7 +107,9 @@ static mut t_11: std::cell::LazyCell = std::cell::LazyCell::new { let __static = LifetimeTracked::new(); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut t_11)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut t_11, + )) }); __static } @@ -114,7 +120,9 @@ pub static mut check_13: std::cell::LazyCell = { let __static = AssertsDtorCountAtExit { expected: 4 }; libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut check_13)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut check_13, + )) }); __static } @@ -149,7 +157,9 @@ static mut t_19: std::cell::LazyCell = std::cell::LazyCell::new { let __static = LifetimeTracked::new(); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut t_19)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut t_19, + )) }); __static } 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..49296abffb 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, VaArg, FnPtrArg, CopyAssign, Destructible)] #[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, VaArg, FnPtrArg, Destructible, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -79,7 +79,9 @@ pub fn instance_4() -> Ptr { thread_local!( static t_5: Value = { let __static = Rc::new(RefCell::new(LifetimeTracked::new())); - libcc2rs::register_static_destructor(|| t_5.with(Value::clone).as_pointer().destructor()); + libcc2rs::register_static_destructor(|| { + Destructible::destroy(t_5.with(Value::clone).as_pointer()) + }); __static }; ); @@ -87,7 +89,7 @@ thread_local!( pub static check_6: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); libcc2rs::register_static_destructor(|| { - check_6.with(Value::clone).as_pointer().destructor() + Destructible::destroy(check_6.with(Value::clone).as_pointer()) }); __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..692ba3aea6 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 @@ -11,7 +11,7 @@ pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructibleUnsafe)] pub struct LifetimeTracked { pub uses: i32, } @@ -61,7 +61,7 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -77,7 +77,9 @@ static mut t_5: std::cell::LazyCell = std::cell::LazyCell::new( { let __static = LifetimeTracked::new(); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut t_5)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut t_5, + )) }); __static } @@ -87,7 +89,9 @@ pub static mut check_6: std::cell::LazyCell = { let __static = AssertsDtorCountAtExit { expected: 1 }; libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut check_6)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut check_6, + )) }); __static } 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..7cf4760235 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, VaArg, FnPtrArg, CopyAssign, Destructible)] #[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, VaArg, FnPtrArg, Destructible, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -77,7 +77,7 @@ thread_local!( pub static check_4: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); libcc2rs::register_static_destructor(|| { - check_4.with(Value::clone).as_pointer().destructor() + Destructible::destroy(check_4.with(Value::clone).as_pointer()) }); __static }; @@ -86,7 +86,7 @@ thread_local!( pub static shared_5: Value = { let __static = Rc::new(RefCell::new(LifetimeTracked::new())); libcc2rs::register_static_destructor(|| { - shared_5.with(Value::clone).as_pointer().destructor() + Destructible::destroy(shared_5.with(Value::clone).as_pointer()) }); __static }; 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..d3ccd895f0 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 @@ -11,7 +11,7 @@ pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructibleUnsafe)] pub struct LifetimeTracked { pub uses: i32, } @@ -61,7 +61,7 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -75,7 +75,9 @@ pub static mut check_4: std::cell::LazyCell = { let __static = AssertsDtorCountAtExit { expected: 1 }; libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut check_4)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut check_4, + )) }); __static } @@ -85,7 +87,9 @@ pub static mut shared_5: std::cell::LazyCell = { let __static = LifetimeTracked::new(); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut shared_5)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut shared_5, + )) }); __static } 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..1ce9adcf23 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, VaArg, FnPtrArg, CopyAssign, Destructible)] #[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, VaArg, FnPtrArg, Destructible, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -80,7 +80,7 @@ thread_local!( static local_4: Value = { let __static = Rc::new(RefCell::new(LifetimeTracked::new())); libcc2rs::register_static_destructor(|| { - local_4.with(Value::clone).as_pointer().destructor() + Destructible::destroy(local_4.with(Value::clone).as_pointer()) }); __static }; @@ -89,7 +89,7 @@ thread_local!( pub static check_5: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); libcc2rs::register_static_destructor(|| { - check_5.with(Value::clone).as_pointer().destructor() + Destructible::destroy(check_5.with(Value::clone).as_pointer()) }); __static }; 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..131a0dbf5b 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 @@ -11,7 +11,7 @@ pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructibleUnsafe)] pub struct LifetimeTracked { pub uses: i32, } @@ -61,7 +61,7 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -98,7 +98,9 @@ static mut local_4: std::cell::LazyCell = std::cell::LazyCell:: { let __static = LifetimeTracked::new(); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut local_4)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut local_4, + )) }); __static } @@ -108,7 +110,9 @@ pub static mut check_5: std::cell::LazyCell = { let __static = AssertsDtorCountAtExit { expected: 1 }; libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut check_5)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut check_5, + )) }); __static } 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..31175d4301 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, VaArg, FnPtrArg, CopyAssign, Destructible)] #[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, VaArg, FnPtrArg, Destructible, Default)] #[byte_size(4)] pub struct AssertsDtorCountAtExit { #[offset(0)] @@ -91,7 +91,7 @@ thread_local!( static local_5: Value = { let __static = Rc::new(RefCell::new(LifetimeTracked::new())); libcc2rs::register_static_destructor(|| { - local_5.with(Value::clone).as_pointer().destructor() + Destructible::destroy(local_5.with(Value::clone).as_pointer()) }); __static }; @@ -100,7 +100,7 @@ thread_local!( pub static check_6: Value = { let __static = Rc::new(RefCell::new(AssertsDtorCountAtExit { expected: 1 })); libcc2rs::register_static_destructor(|| { - check_6.with(Value::clone).as_pointer().destructor() + Destructible::destroy(check_6.with(Value::clone).as_pointer()) }); __static }; 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..b1e530e52c 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 @@ -11,7 +11,7 @@ pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructibleUnsafe)] pub struct LifetimeTracked { pub uses: i32, } @@ -61,7 +61,7 @@ impl Default for LifetimeTracked { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct AssertsDtorCountAtExit { pub expected: i32, } @@ -92,7 +92,9 @@ static mut local_5: std::cell::LazyCell = std::cell::LazyCell:: { let __static = LifetimeTracked::new(); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut local_5)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut local_5, + )) }); __static } @@ -102,7 +104,9 @@ pub static mut check_6: std::cell::LazyCell = { let __static = AssertsDtorCountAtExit { expected: 1 }; libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut check_6)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut check_6, + )) }); __static } 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..29c195878e 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, VaArg, FnPtrArg, CopyAssign, Destructible)] #[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, VaArg, FnPtrArg, Destructible, Default)] #[byte_size(4)] pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { #[offset(0)] @@ -87,8 +87,9 @@ pub fn test_7() { let condition: Value = Rc::new( RefCell::new(p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 0 }), ); - let _dtor_condition = - std::mem::DropGuard::new(condition.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| { + Destructible::destroy(__p.as_pointer()) + }); if ({ p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl::to_bool( &condition.as_pointer(), @@ -108,8 +109,9 @@ pub fn test_7() { let condition: Value = Rc::new( RefCell::new(p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 6 }), ); - let _dtor_condition = - std::mem::DropGuard::new(condition.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| { + Destructible::destroy(__p.as_pointer()) + }); if ({ p1_1_condition_variable_visible_in_else_ConvertsToBoolImpl::to_bool( &condition.as_pointer(), @@ -147,16 +149,18 @@ pub fn test_8() { pub fn test_9() { ({ LifetimeTracked::reset() }); let scoped: Value = Rc::new(RefCell::new(LifetimeTracked::new())); - let _dtor_scoped = - std::mem::DropGuard::new(scoped.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_scoped = std::mem::DropGuard::new(scoped.clone(), |__p| { + Destructible::destroy(__p.as_pointer()) + }); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 1)); { let mut index: i32 = 0; 'loop_: while (index < 3) { 'for_body: { let scoped: Value = Rc::new(RefCell::new(LifetimeTracked::new())); - let _dtor_scoped = - std::mem::DropGuard::new(scoped.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_scoped = std::mem::DropGuard::new(scoped.clone(), |__p| { + Destructible::destroy(__p.as_pointer()) + }); } index.prefix_inc(); } @@ -165,16 +169,18 @@ pub fn test_9() { 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 _dtor_scoped = - std::mem::DropGuard::new(scoped.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_scoped = std::mem::DropGuard::new(scoped.clone(), |__p| { + Destructible::destroy(__p.as_pointer()) + }); } assert!((ctorCount_0.with(|rc| *rc.borrow()) == 5)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 4)); if (ctorCount_0.with(|rc| *rc.borrow()) == 0) { } else { let scoped: Value = Rc::new(RefCell::new(LifetimeTracked::new())); - let _dtor_scoped = - std::mem::DropGuard::new(scoped.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_scoped = std::mem::DropGuard::new(scoped.clone(), |__p| { + Destructible::destroy(__p.as_pointer()) + }); } assert!((ctorCount_0.with(|rc| *rc.borrow()) == 6)); assert!((dtorCount_2.with(|rc| *rc.borrow()) == 5)); @@ -204,12 +210,14 @@ pub fn test_10() { pub fn test_11() { ({ LifetimeTracked::reset() }); let tracked: Value = Rc::new(RefCell::new(LifetimeTracked::new())); - let _dtor_tracked = - std::mem::DropGuard::new(tracked.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_tracked = std::mem::DropGuard::new(tracked.clone(), |__p| { + Destructible::destroy(__p.as_pointer()) + }); { let tracked: Value = Rc::new(RefCell::new(LifetimeTracked::new())); - let _dtor_tracked = - std::mem::DropGuard::new(tracked.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_tracked = std::mem::DropGuard::new(tracked.clone(), |__p| { + Destructible::destroy(__p.as_pointer()) + }); assert!((ctorCount_0.with(|rc| *rc.borrow()) == 2)); ({ LifetimeTrackedImpl::use_(&tracked.as_pointer()) }); assert!(({ ({ (*tracked.borrow()).uses } == 1) })); 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..bad4677654 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 @@ -11,7 +11,7 @@ pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructibleUnsafe)] pub struct LifetimeTracked { pub uses: i32, } @@ -66,7 +66,7 @@ pub static mut else_runs_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); pub static mut dtorCount_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct p1_1_condition_variable_visible_in_else_ConvertsToBool { pub value: i32, } @@ -82,8 +82,9 @@ pub unsafe fn test_7() { { let mut condition: p1_1_condition_variable_visible_in_else_ConvertsToBool = p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 0 }; - let _dtor_condition = - std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { (*__p).destructor() }); + let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); if (unsafe { p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(&condition) }) { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); @@ -99,8 +100,9 @@ pub unsafe fn test_7() { { let mut condition: p1_1_condition_variable_visible_in_else_ConvertsToBool = p1_1_condition_variable_visible_in_else_ConvertsToBool { value: 6 }; - let _dtor_condition = - std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { (*__p).destructor() }); + let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); if (unsafe { p1_1_condition_variable_visible_in_else_ConvertsToBool::to_bool(&condition) }) { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); @@ -135,16 +137,18 @@ pub unsafe fn test_8() { pub unsafe fn test_9() { (unsafe { LifetimeTracked::reset() }); let mut scoped: LifetimeTracked = LifetimeTracked::new(); - let _dtor_scoped = - std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { (*__p).destructor() }); + let _dtor_scoped = std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (1))); { let mut index: i32 = 0; 'loop_: while ((index) < (3)) { 'for_body: { let mut scoped: LifetimeTracked = LifetimeTracked::new(); - let _dtor_scoped = - std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { (*__p).destructor() }); + let _dtor_scoped = std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); } index.prefix_inc(); } @@ -153,16 +157,18 @@ pub unsafe fn test_9() { 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 _dtor_scoped = - std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { (*__p).destructor() }); + let _dtor_scoped = std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (5))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (4))); if ((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (0)) { } else { let mut scoped: LifetimeTracked = LifetimeTracked::new(); - let _dtor_scoped = - std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { (*__p).destructor() }); + let _dtor_scoped = std::mem::DropGuard::new(&raw mut scoped, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (6))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (5))); @@ -188,12 +194,14 @@ pub unsafe fn test_10() { pub unsafe fn test_11() { (unsafe { LifetimeTracked::reset() }); let mut tracked: LifetimeTracked = LifetimeTracked::new(); - let _dtor_tracked = - std::mem::DropGuard::new(&raw mut tracked, |__p| unsafe { (*__p).destructor() }); + let _dtor_tracked = std::mem::DropGuard::new(&raw mut tracked, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); { let mut tracked: LifetimeTracked = LifetimeTracked::new(); - let _dtor_tracked = - std::mem::DropGuard::new(&raw mut tracked, |__p| unsafe { (*__p).destructor() }); + let _dtor_tracked = std::mem::DropGuard::new(&raw mut tracked, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut ctorCount_0)) == (2))); (unsafe { LifetimeTracked::use_(&tracked) }); assert!(((tracked.uses) == (1))); 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..a2e0eea9a4 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, VaArg, FnPtrArg, Destructible, Default)] #[byte_size(4)] pub struct Tracker { #[offset(0)] @@ -23,7 +23,7 @@ thread_local!( pub static global_0: Value = { let __static = Rc::new(RefCell::new(Tracker::new({ 1 }))); libcc2rs::register_static_destructor(|| { - global_0.with(Value::clone).as_pointer().destructor() + Destructible::destroy(global_0.with(Value::clone).as_pointer()) }); __static }; @@ -33,15 +33,16 @@ pub fn exit_from_nested_call_1() { (*local_static_2.with(Value::clone).borrow()).tag }); let automatic: Value = Rc::new(RefCell::new(Tracker::new({ 3 }))); - let _dtor_automatic = - std::mem::DropGuard::new(automatic.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_automatic = std::mem::DropGuard::new(automatic.clone(), |__p| { + Destructible::destroy(__p.as_pointer()) + }); libcc2rs::cpp2rust_exit(0); } thread_local!( static local_static_2: Value = { let __static = Rc::new(RefCell::new(Tracker::new({ 2 }))); libcc2rs::register_static_destructor(|| { - local_static_2.with(Value::clone).as_pointer().destructor() + Destructible::destroy(local_static_2.with(Value::clone).as_pointer()) }); __static }; 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..e33aa6afc7 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, VaArg, FnPtrArg, Destructible, Default)] #[byte_size(4)] pub struct Tracker { #[offset(0)] @@ -19,7 +19,7 @@ impl Tracker { __this } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructible, Default)] #[byte_size(4)] pub struct HoldsTracker { #[offset(0)] @@ -36,7 +36,7 @@ thread_local!( pub static global_0: Value = { let __static = Rc::new(RefCell::new(Tracker::new({ 1 }))); libcc2rs::register_static_destructor(|| { - global_0.with(Value::clone).as_pointer().destructor() + Destructible::destroy(global_0.with(Value::clone).as_pointer()) }); __static }; @@ -51,10 +51,7 @@ thread_local!( static never_constructed_2: Value = { let __static = Rc::new(RefCell::new(Tracker::new({ 100 }))); libcc2rs::register_static_destructor(|| { - never_constructed_2 - .with(Value::clone) - .as_pointer() - .destructor() + Destructible::destroy(never_constructed_2.with(Value::clone).as_pointer()) }); __static }; @@ -66,7 +63,7 @@ thread_local!( pub static before_6: Value = { let __static = Rc::new(RefCell::new(Tracker::new({ 2 }))); libcc2rs::register_static_destructor(|| { - before_6.with(Value::clone).as_pointer().destructor() + Destructible::destroy(before_6.with(Value::clone).as_pointer()) }); __static }; @@ -77,7 +74,7 @@ thread_local!( (({ local_static_during_global_init_4() }).with(|__s| __s.tag) + 1) }))); libcc2rs::register_static_destructor(|| { - after_7.with(Value::clone).as_pointer().destructor() + Destructible::destroy(after_7.with(Value::clone).as_pointer()) }); __static }; @@ -88,7 +85,7 @@ thread_local!( member: Tracker::new({ 5 }), })); libcc2rs::register_static_destructor(|| { - holder_8.with(Value::clone).as_pointer().destructor() + Destructible::destroy(holder_8.with(Value::clone).as_pointer()) }); __static }; @@ -104,7 +101,7 @@ thread_local!( pub static member_10: Value = { let __static = Rc::new(RefCell::new(Tracker::new({ 7 }))); libcc2rs::register_static_destructor(|| { - member_10.with(Value::clone).as_pointer().destructor() + Destructible::destroy(member_10.with(Value::clone).as_pointer()) }); __static }; @@ -120,10 +117,7 @@ thread_local!( } ))); libcc2rs::register_static_destructor(|| { - capturing_11 - .with(Value::clone) - .as_pointer() - .with(|__f| __f.destroy()) + Destructible::destroy(capturing_11.with(Value::clone).as_pointer()) }); __static }; @@ -146,7 +140,7 @@ thread_local!( static during_init_5: Value = { let __static = Rc::new(RefCell::new(Tracker::new({ 3 }))); libcc2rs::register_static_destructor(|| { - during_init_5.with(Value::clone).as_pointer().destructor() + Destructible::destroy(during_init_5.with(Value::clone).as_pointer()) }); __static }; @@ -155,7 +149,7 @@ thread_local!( static during_main_13: Value = { let __static = Rc::new(RefCell::new(Tracker::new({ 9 }))); libcc2rs::register_static_destructor(|| { - during_main_13.with(Value::clone).as_pointer().destructor() + Destructible::destroy(during_main_13.with(Value::clone).as_pointer()) }); __static }; @@ -175,7 +169,7 @@ pub trait HoldsTrackerImpl { } impl HoldsTrackerImpl for Ptr { fn destructor(&self) { - field_ptr!(self, member).destructor(); + Destructible::destroy(field_ptr!(self, member)); } } pub trait TrackerImpl { 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..8a7322ec46 100644 --- a/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs +++ b/tests/std/basic/basic.start/out/unsafe/basic.start.term-p1-exit.rs @@ -7,7 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct Tracker { pub tag: i32, } @@ -25,7 +25,9 @@ pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new { let __static = Tracker::new({ 1 }); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut global_0, + )) }); __static } @@ -38,15 +40,18 @@ pub unsafe fn exit_from_nested_call_1() { ) }); let mut automatic: Tracker = Tracker::new({ 3 }); - let _dtor_automatic = - std::mem::DropGuard::new(&raw mut automatic, |__p| unsafe { (*__p).destructor() }); + let _dtor_automatic = std::mem::DropGuard::new(&raw mut automatic, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); libcc2rs::cpp2rust_exit(0); } static mut local_static_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { { let __static = Tracker::new({ 2 }); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut local_static_2)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut local_static_2, + )) }); __static } 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..a663ccf35a 100644 --- a/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs +++ b/tests/std/basic/basic.start/out/unsafe/basic.start.term.rs @@ -7,7 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct Tracker { pub tag: i32, } @@ -25,13 +25,13 @@ impl Tracker { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct HoldsTracker { pub member: Tracker, } impl HoldsTracker { pub unsafe fn destructor(&mut self) { - Tracker::destructor(&mut self.member); + DestructibleUnsafe::destroy(&raw mut self.member); } } #[repr(C)] @@ -43,7 +43,9 @@ pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new { let __static = Tracker::new({ 1 }); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut global_0, + )) }); __static } @@ -61,7 +63,9 @@ static mut never_constructed_2: std::cell::LazyCell = { let __static = Tracker::new({ 100 }); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut never_constructed_2)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut never_constructed_2, + )) }); __static } @@ -73,7 +77,9 @@ pub static mut before_6: std::cell::LazyCell = std::cell::LazyCell::new { let __static = Tracker::new({ 2 }); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut before_6)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut before_6, + )) }); __static } @@ -83,7 +89,9 @@ pub static mut after_7: std::cell::LazyCell = std::cell::LazyCell::new( let __static = Tracker::new({ (((*(unsafe { local_static_during_global_init_4() })).tag) + (1)) }); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut after_7)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut after_7, + )) }); __static } @@ -94,7 +102,9 @@ pub static mut holder_8: std::cell::LazyCell = std::cell::LazyCell member: Tracker::new({ 5 }), }; libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut holder_8)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut holder_8, + )) }); __static } @@ -108,7 +118,9 @@ pub static mut member_10: std::cell::LazyCell = std::cell::LazyCell::ne { let __static = Tracker::new({ 7 }); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut member_10)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut member_10, + )) }); __static } @@ -125,7 +137,9 @@ pub static mut capturing_11: std::cell::LazyCell i32>> = } ); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut capturing_11)).destroy() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut capturing_11, + )) }); __static } @@ -155,7 +169,9 @@ static mut during_init_5: std::cell::LazyCell = std::cell::LazyCell::ne { let __static = Tracker::new({ 3 }); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut during_init_5)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut during_init_5, + )) }); __static } @@ -164,7 +180,9 @@ static mut during_main_13: std::cell::LazyCell = std::cell::LazyCell::n { let __static = Tracker::new({ 9 }); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut during_main_13)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut during_main_13, + )) }); __static } diff --git a/tests/std/basic/out/refcount/basic.def.odr.rs b/tests/std/basic/out/refcount/basic.def.odr.rs index 66705328fd..e932e3ccb1 100644 --- a/tests/std/basic/out/refcount/basic.def.odr.rs +++ b/tests/std/basic/out/refcount/basic.def.odr.rs @@ -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, VaArg, FnPtrArg, CopyAssign, Destructible)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -196,7 +196,7 @@ thread_local!( pub static global_12: Value = { let __static = Rc::new(RefCell::new(LifetimeTracked::new())); libcc2rs::register_static_destructor(|| { - global_12.with(Value::clone).as_pointer().destructor() + Destructible::destroy(global_12.with(Value::clone).as_pointer()) }); __static }; @@ -216,7 +216,8 @@ pub fn test_13() { pub fn test_14() { ({ LifetimeTracked::reset() }); let t: Value = Rc::new(RefCell::new(LifetimeTracked::new())); - let _dtor_t = std::mem::DropGuard::new(t.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_t = + std::mem::DropGuard::new(t.clone(), |__p| Destructible::destroy(__p.as_pointer())); let r: Ptr = t.as_pointer(); let f: Value> = Rc::new(RefCell::new(lambda!( { @@ -228,7 +229,7 @@ pub fn test_14() { } ))); let _dtor_f = - std::mem::DropGuard::new(f.clone(), |__p| __p.as_pointer().with(|__f| __f.destroy())); + std::mem::DropGuard::new(f.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!((copyCount_2.with(|rc| *rc.borrow()) == 1)); ({ (*f.borrow()).call() }); assert!((copyCount_2.with(|rc| *rc.borrow()) == 1)); @@ -336,7 +337,7 @@ 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, VaArg, FnPtrArg, CopyAssign, Destructible, Default)] #[byte_size(8)] pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { #[offset(0)] @@ -354,7 +355,8 @@ pub fn test_20() { b: LifetimeTracked::new(), }, )); - let _dtor_p = std::mem::DropGuard::new(p.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_p = + std::mem::DropGuard::new(p.clone(), |__p| Destructible::destroy(__p.as_pointer())); let __decomp_21: Ptr = p.as_pointer(); let f: Value usize>> = Rc::new(RefCell::new(FnPtr:: usize>::new(|| -> usize { @@ -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, VaArg, FnPtrArg, CopyAssign, Destructible)] #[byte_size(8)] pub struct p7_member_access_captures_this_HasMemberUsedInLambda { #[offset(0)] @@ -391,7 +393,8 @@ pub fn test_22() { let c: Value = Rc::new(RefCell::new( ::default(), )); - let _dtor_c = std::mem::DropGuard::new(c.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_c = + std::mem::DropGuard::new(c.clone(), |__p| Destructible::destroy(__p.as_pointer())); let f: Value i32>> = Rc::new(RefCell::new( ({ p7_member_access_captures_this_HasMemberUsedInLambdaImpl::makeLambda(&c.as_pointer()) }), )); @@ -403,7 +406,7 @@ 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, VaArg, FnPtrArg, CopyAssign, Destructible, Default)] #[byte_size(4)] pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { #[offset(0)] @@ -415,7 +418,8 @@ pub fn test_23() { let c: Value = Rc::new( RefCell::new(::default()), ); - let _dtor_c = std::mem::DropGuard::new(c.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_c = + std::mem::DropGuard::new(c.clone(), |__p| Destructible::destroy(__p.as_pointer())); let f: Value usize>> = Rc::new(RefCell::new( ({ p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl::sizer(&c.as_pointer()) @@ -735,8 +739,8 @@ impl p6_unevaluated_binding_needs_no_capture_HasTwoMembersImpl return (*self).clone(); } fn destructor(&self) { - field_ptr!(self, b).destructor(); - field_ptr!(self, a).destructor(); + Destructible::destroy(field_ptr!(self, b)); + Destructible::destroy(field_ptr!(self, a)); } } pub trait p7_member_access_captures_this_HasMemberUsedInLambdaImpl { @@ -774,7 +778,7 @@ impl p7_member_access_captures_this_HasMemberUsedInLambdaImpl return (*self).clone(); } fn destructor(&self) { - field_ptr!(self, x).destructor(); + Destructible::destroy(field_ptr!(self, x)); } } pub trait p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl { @@ -806,7 +810,7 @@ impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambdaImpl return (*self).clone(); } fn destructor(&self) { - field_ptr!(self, x).destructor(); + Destructible::destroy(field_ptr!(self, x)); } } pub trait p9_destructor_not_potentially_invoked_HasUndefinedDestructorImpl { diff --git a/tests/std/basic/out/unsafe/basic.def.odr.rs b/tests/std/basic/out/unsafe/basic.def.odr.rs index d482309b05..c404f4c1f8 100644 --- a/tests/std/basic/out/unsafe/basic.def.odr.rs +++ b/tests/std/basic/out/unsafe/basic.def.odr.rs @@ -41,7 +41,7 @@ pub static mut copyCount_2: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut useCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructibleUnsafe)] pub struct LifetimeTracked { pub uses: i32, } @@ -173,7 +173,9 @@ pub static mut global_12: std::cell::LazyCell = { let __static = LifetimeTracked::new(); libcc2rs::register_static_destructor(|| { - (*std::cell::LazyCell::force_mut(&mut *&raw mut global_12)).destructor() + DestructibleUnsafe::destroy(&raw mut *std::cell::LazyCell::force_mut( + &mut *&raw mut global_12, + )) }); __static } @@ -195,7 +197,9 @@ pub unsafe fn test_13() { pub unsafe fn test_14() { (unsafe { LifetimeTracked::reset() }); let mut t: LifetimeTracked = LifetimeTracked::new(); - let _dtor_t = std::mem::DropGuard::new(&raw mut t, |__p| unsafe { (*__p).destructor() }); + let _dtor_t = std::mem::DropGuard::new(&raw mut t, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let r: *mut LifetimeTracked = &mut t; let mut f: FnPtr = lambda_unsafe!( { @@ -205,7 +209,9 @@ pub unsafe fn test_14() { (unsafe { LifetimeTracked::use_(&r) }); } ); - let _dtor_f = std::mem::DropGuard::new(&raw mut f, |__p| unsafe { (*__p).destroy() }); + let _dtor_f = std::mem::DropGuard::new(&raw mut f, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (1))); (unsafe { f.call() }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (1))); @@ -309,7 +315,7 @@ pub unsafe fn test_19() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_18)) == (1))); } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, CopyAssignUnsafe, DestructibleUnsafe, Default)] pub struct p6_unevaluated_binding_needs_no_capture_HasTwoMembers { pub a: LifetimeTracked, pub b: LifetimeTracked, @@ -332,8 +338,8 @@ impl p6_unevaluated_binding_needs_no_capture_HasTwoMembers { } impl p6_unevaluated_binding_needs_no_capture_HasTwoMembers { pub unsafe fn destructor(&mut self) { - LifetimeTracked::destructor(&mut self.b); - LifetimeTracked::destructor(&mut self.a); + DestructibleUnsafe::destroy(&raw mut self.b); + DestructibleUnsafe::destroy(&raw mut self.a); } } pub unsafe fn test_20() { @@ -343,7 +349,9 @@ pub unsafe fn test_20() { a: LifetimeTracked::new(), b: LifetimeTracked::new(), }; - let _dtor_p = std::mem::DropGuard::new(&raw mut p, |__p| unsafe { (*__p).destructor() }); + let _dtor_p = std::mem::DropGuard::new(&raw mut p, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let __decomp_21: *mut p6_unevaluated_binding_needs_no_capture_HasTwoMembers = &mut p; let mut f: FnPtr usize> = FnPtr:: usize>::new(|| -> usize { unsafe { @@ -356,7 +364,7 @@ pub unsafe fn test_20() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut useCount_4)) == (0))); } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +#[derive(Clone, VaArg, FnPtrArg, CopyAssignUnsafe, DestructibleUnsafe)] pub struct p7_member_access_captures_this_HasMemberUsedInLambda { pub x: LifetimeTracked, pub n: i32, @@ -388,7 +396,7 @@ impl p7_member_access_captures_this_HasMemberUsedInLambda { } impl p7_member_access_captures_this_HasMemberUsedInLambda { pub unsafe fn destructor(&mut self) { - LifetimeTracked::destructor(&mut self.x); + DestructibleUnsafe::destroy(&raw mut self.x); } } impl Default for p7_member_access_captures_this_HasMemberUsedInLambda { @@ -405,7 +413,9 @@ pub unsafe fn test_22() { (unsafe { LifetimeTracked::reset() }); let mut c: p7_member_access_captures_this_HasMemberUsedInLambda = ::default(); - let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { (*__p).destructor() }); + let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut f: FnPtr i32> = (unsafe { p7_member_access_captures_this_HasMemberUsedInLambda::makeLambda(&mut c) }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (0))); @@ -417,7 +427,7 @@ pub unsafe fn test_22() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copyCount_2)) == (0))); } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, CopyAssignUnsafe, DestructibleUnsafe, Default)] pub struct p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { pub x: LifetimeTracked, } @@ -442,14 +452,16 @@ impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { } impl p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda { pub unsafe fn destructor(&mut self) { - LifetimeTracked::destructor(&mut self.x); + DestructibleUnsafe::destroy(&raw mut self.x); } } pub unsafe fn test_23() { (unsafe { LifetimeTracked::reset() }); let mut c: p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda = ::default(); - let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { (*__p).destructor() }); + let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut f: FnPtr usize> = (unsafe { p7_unevaluated_this_needs_no_capture_HasMemberUsedInLambda::sizer(&mut c) }); assert!(((unsafe { f.call() }) == (::std::mem::size_of::()))); 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..8737b7d0f7 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,7 @@ 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, VaArg, FnPtrArg, CppFrom, Destructible, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct p2_condition_variable_created_each_iteration_ConvertsToBool { @@ -35,8 +35,9 @@ pub fn test_2() { Rc::new(RefCell::new( p2_condition_variable_created_each_iteration_ConvertsToBool::new({ remaining }), )); - let _dtor_condition = - std::mem::DropGuard::new(condition.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| { + Destructible::destroy(__p.as_pointer()) + }); if !({ p2_condition_variable_created_each_iteration_ConvertsToBoolImpl::to_bool( &condition.as_pointer(), @@ -60,7 +61,7 @@ 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, VaArg, FnPtrArg, CppFrom, Destructible, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct p2_continue_destroys_condition_variable_ConvertsToBool { @@ -83,8 +84,9 @@ pub fn test_5() { Rc::new(RefCell::new( p2_continue_destroys_condition_variable_ConvertsToBool::new({ remaining }), )); - let _dtor_condition = - std::mem::DropGuard::new(condition.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| { + Destructible::destroy(__p.as_pointer()) + }); if !({ p2_continue_destroys_condition_variable_ConvertsToBoolImpl::to_bool( &condition.as_pointer(), diff --git a/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs b/tests/std/stmt.stmt/stmt.iter/out/unsafe/stmt.while.rs index 4a08f01147..2ffbe798dc 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 @@ -9,7 +9,7 @@ use std::rc::Rc; pub static mut ctorCount_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut dtorCount_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, CppFromUnsafe, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, CppFromUnsafe, DestructibleUnsafe, Default)] #[cpp_from(i32, new, value)] pub struct p2_condition_variable_created_each_iteration_ConvertsToBool { pub value: i32, @@ -33,8 +33,9 @@ pub unsafe fn test_2() { 'loop_: loop { let mut condition: p2_condition_variable_created_each_iteration_ConvertsToBool = p2_condition_variable_created_each_iteration_ConvertsToBool::new({ remaining }); - let _dtor_condition = - std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { (*__p).destructor() }); + let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); if !(unsafe { p2_condition_variable_created_each_iteration_ConvertsToBool::to_bool(&condition) }) { @@ -55,7 +56,7 @@ pub unsafe fn test_2() { pub static mut ctorCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut dtorCount_4: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, CppFromUnsafe, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, CppFromUnsafe, DestructibleUnsafe, Default)] #[cpp_from(i32, new, value)] pub struct p2_continue_destroys_condition_variable_ConvertsToBool { pub value: i32, @@ -80,8 +81,9 @@ pub unsafe fn test_5() { 'loop_: loop { let mut condition: p2_continue_destroys_condition_variable_ConvertsToBool = p2_continue_destroys_condition_variable_ConvertsToBool::new({ remaining }); - let _dtor_condition = - std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { (*__p).destructor() }); + let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); if !(unsafe { p2_continue_destroys_condition_variable_ConvertsToBool::to_bool(&condition) }) { break; diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.if.rs index 6f94c793f0..81f4a3616c 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, VaArg, FnPtrArg, CopyAssign, Destructible)] #[byte_size(4)] pub struct LifetimeTracked { #[offset(0)] @@ -79,7 +79,7 @@ pub fn test_6() { { let guard: Value = Rc::new(RefCell::new(LifetimeTracked::new())); let _dtor_guard = - std::mem::DropGuard::new(guard.clone(), |__p| __p.as_pointer().destructor()); + std::mem::DropGuard::new(guard.clone(), |__p| Destructible::destroy(__p.as_pointer())); let mut choice: i32 = 0; if (choice != 0) { (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); @@ -97,7 +97,7 @@ pub fn test_6() { { let guard: Value = Rc::new(RefCell::new(LifetimeTracked::new())); let _dtor_guard = - std::mem::DropGuard::new(guard.clone(), |__p| __p.as_pointer().destructor()); + std::mem::DropGuard::new(guard.clone(), |__p| Destructible::destroy(__p.as_pointer())); let mut choice: i32 = 4; if (choice != 0) { (*then_runs_4.with(Value::clone).borrow_mut()).prefix_inc(); diff --git a/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/refcount/stmt.switch.rs index 0935da1fb3..1131d3d79f 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, VaArg, FnPtrArg, CopyAssign, Destructible)] #[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, CppFrom, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Destructible, Default)] #[cpp_into(i32, to_i32)] #[byte_size(4)] pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { @@ -89,8 +89,9 @@ pub fn test_7() { Rc::new(RefCell::new( p2_condition_variable_lives_for_whole_statement_ConvertsToInt { value: 2 }, )); - let _dtor_selector = - std::mem::DropGuard::new(selector.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_selector = std::mem::DropGuard::new(selector.clone(), |__p| { + Destructible::destroy(__p.as_pointer()) + }); 'switch: { match { ({ @@ -128,7 +129,7 @@ pub fn test_10() { { let guard: Value = Rc::new(RefCell::new(LifetimeTracked::new())); let _dtor_guard = - std::mem::DropGuard::new(guard.clone(), |__p| __p.as_pointer().destructor()); + std::mem::DropGuard::new(guard.clone(), |__p| Destructible::destroy(__p.as_pointer())); let mut selector: i32 = 2; 'switch: { match { selector } { diff --git a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.if.rs index fd22be5aba..c80037a107 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 @@ -11,7 +11,7 @@ pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructibleUnsafe)] pub struct LifetimeTracked { pub uses: i32, } @@ -69,8 +69,9 @@ pub unsafe fn test_6() { let mut choice: i32 = 9; { let mut guard: LifetimeTracked = LifetimeTracked::new(); - let _dtor_guard = - std::mem::DropGuard::new(&raw mut guard, |__p| unsafe { (*__p).destructor() }); + let _dtor_guard = std::mem::DropGuard::new(&raw mut guard, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut choice: i32 = 0; if (choice != 0) { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); @@ -87,8 +88,9 @@ pub unsafe fn test_6() { assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut dtorCount_2)) == (1))); { let mut guard: LifetimeTracked = LifetimeTracked::new(); - let _dtor_guard = - std::mem::DropGuard::new(&raw mut guard, |__p| unsafe { (*__p).destructor() }); + let _dtor_guard = std::mem::DropGuard::new(&raw mut guard, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut choice: i32 = 4; if (choice != 0) { (*std::cell::LazyCell::force_mut(&mut *&raw mut then_runs_4)).prefix_inc(); diff --git a/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs b/tests/std/stmt.stmt/stmt.select/out/unsafe/stmt.switch.rs index 177fa848ed..7fb1b86497 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 @@ -11,7 +11,7 @@ pub static mut copyCount_1: std::cell::LazyCell = std::cell::LazyCell::new( pub static mut dtorCount_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut useCount_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe)] +#[derive(VaArg, FnPtrArg, CopyAssignUnsafe, DestructibleUnsafe)] pub struct LifetimeTracked { pub uses: i32, } @@ -66,7 +66,7 @@ pub static mut other_case_runs_5: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0_i32 }); pub static mut dtorCount_6: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, CppFromUnsafe, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, CppFromUnsafe, DestructibleUnsafe, Default)] #[cpp_into(i32, to_i32)] pub struct p2_condition_variable_lives_for_whole_statement_ConvertsToInt { pub value: i32, @@ -83,8 +83,9 @@ pub unsafe fn test_7() { { let mut selector: p2_condition_variable_lives_for_whole_statement_ConvertsToInt = p2_condition_variable_lives_for_whole_statement_ConvertsToInt { value: 2 }; - let _dtor_selector = - std::mem::DropGuard::new(&raw mut selector, |__p| unsafe { (*__p).destructor() }); + let _dtor_selector = std::mem::DropGuard::new(&raw mut selector, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); 'switch: { match { (unsafe { @@ -119,8 +120,9 @@ pub unsafe fn test_10() { let mut selector: i32 = 9; { let mut guard: LifetimeTracked = LifetimeTracked::new(); - let _dtor_guard = - std::mem::DropGuard::new(&raw mut guard, |__p| unsafe { (*__p).destructor() }); + let _dtor_guard = std::mem::DropGuard::new(&raw mut guard, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut selector: i32 = 2; 'switch: { match { selector } { diff --git a/tests/unit/out/refcount/constructor.rs b/tests/unit/out/refcount/constructor.rs index 5ef50fef7a..d37dd52e25 100644 --- a/tests/unit/out/refcount/constructor.rs +++ b/tests/unit/out/refcount/constructor.rs @@ -9,7 +9,7 @@ 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, VaArg, FnPtrArg, CppFrom, Destructible, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct S { @@ -67,7 +67,8 @@ pub fn main() { fn main_0() -> i32 { { let s: Value = Rc::new(RefCell::new(S::new({ 3 }))); - let _dtor_s = std::mem::DropGuard::new(s.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_s = + std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!(({ ({ (*s.borrow()).v } == 4) })); assert!((total_0.with(|rc| *rc.borrow()) == 8)); } diff --git a/tests/unit/out/refcount/copy_move_defaulted.rs b/tests/unit/out/refcount/copy_move_defaulted.rs index fc5ac5d32c..9e54aa4024 100644 --- a/tests/unit/out/refcount/copy_move_defaulted.rs +++ b/tests/unit/out/refcount/copy_move_defaulted.rs @@ -12,7 +12,7 @@ pub struct Inner { #[offset(0)] pub x: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Destructor)] +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CppFrom, Destructible)] #[cpp_from(i32, new, value)] #[byte_size(16)] pub struct Explicit { @@ -225,7 +225,7 @@ impl Copyable { } } } -#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, CppFrom, MoveAssign, Destructor, Default)] +#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, CppFrom, MoveAssign, Destructible, Default)] #[cpp_from(i32, new, value)] #[byte_size(32)] pub struct Holder { @@ -267,22 +267,28 @@ pub fn main() { } fn main_0() -> i32 { let a: Value = Rc::new(RefCell::new(Explicit::new({ 1 }))); - let _dtor_a = std::mem::DropGuard::new(a.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_a = + std::mem::DropGuard::new(a.clone(), |__p| Destructible::destroy(__p.as_pointer())); let b: Value = Rc::new(RefCell::new((*a.borrow()).clone())); - let _dtor_b = std::mem::DropGuard::new(b.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_b = + std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(__p.as_pointer())); let c: Value = Rc::new(RefCell::new((*a.borrow()).clone())); - let _dtor_c = std::mem::DropGuard::new(c.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_c = + std::mem::DropGuard::new(c.clone(), |__p| Destructible::destroy(__p.as_pointer())); let d: Value = Rc::new(RefCell::new((*a.borrow()).clone())); - let _dtor_d = std::mem::DropGuard::new(d.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_d = + std::mem::DropGuard::new(d.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!( (({ same_0(b.as_pointer(), a.as_pointer(),) }) && ({ same_0(c.as_pointer(), a.as_pointer(),) })) && ({ same_0(d.as_pointer(), a.as_pointer(),) }) ); let e: Value = Rc::new(RefCell::new(Explicit::new({ 2 }))); - let _dtor_e = std::mem::DropGuard::new(e.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_e = + std::mem::DropGuard::new(e.clone(), |__p| Destructible::destroy(__p.as_pointer())); let f: Value = Rc::new(RefCell::new(Explicit::new({ 3 }))); - let _dtor_f = std::mem::DropGuard::new(f.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_f = + std::mem::DropGuard::new(f.clone(), |__p| Destructible::destroy(__p.as_pointer())); (*e.borrow_mut()) = (*b.borrow()).clone(); (*f.borrow_mut()) = (*c.borrow()).clone(); assert!( @@ -290,7 +296,8 @@ fn main_0() -> i32 { && ({ same_0(f.as_pointer(), c.as_pointer(),) }) ); let g: Value = Rc::new(RefCell::new(Explicit::new({ 4 }))); - let _dtor_g = std::mem::DropGuard::new(g.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_g = + std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(__p.as_pointer())); (*g.borrow_mut()) = { (*e.borrow_mut()) = (*f.borrow()).clone(); (*e.borrow()).clone() @@ -450,13 +457,15 @@ fn main_0() -> i32 { }) ); let h1: Value = Rc::new(RefCell::new(Holder::new({ 4 }))); - let _dtor_h1 = std::mem::DropGuard::new(h1.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_h1 = + std::mem::DropGuard::new(h1.clone(), |__p| Destructible::destroy(__p.as_pointer())); { 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 _dtor_h2 = std::mem::DropGuard::new(h2.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_h2 = + std::mem::DropGuard::new(h2.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!( ({ ((({ (*h2.borrow()).inner.x } == 4) && ({ (*h2.borrow()).e.v } == 4)) @@ -465,7 +474,8 @@ fn main_0() -> i32 { }) ); let h3: Value = Rc::new(RefCell::new(Holder::new({ 1 }))); - let _dtor_h3 = std::mem::DropGuard::new(h3.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_h3 = + std::mem::DropGuard::new(h3.clone(), |__p| Destructible::destroy(__p.as_pointer())); ({ HolderImpl::move_assign(&h3.as_pointer(), h2.as_pointer()) }); assert!( ({ @@ -538,7 +548,7 @@ impl HolderImpl for Ptr { return (*self).clone(); } fn destructor(&self) { - field_ptr!(self, e).destructor(); + Destructible::destroy(field_ptr!(self, e)); } } pub trait OwnerImpl { diff --git a/tests/unit/out/refcount/delete_array_order.rs b/tests/unit/out/refcount/delete_array_order.rs index cc8b8f29db..9af4979079 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, VaArg, FnPtrArg, Destructible, Default)] #[byte_size(16)] pub struct Element { #[offset(0)] @@ -36,7 +36,7 @@ fn main_0() -> i32 { { let __p = a; for __i in (0..__p.len()).rev() { - __p.offset(__i as isize).destructor(); + Destructible::destroy(__p.offset(__i as isize)); } __p.delete(); }; diff --git a/tests/unit/out/refcount/destructor.rs b/tests/unit/out/refcount/destructor.rs index 034b8813ec..1aab63b9ee 100644 --- a/tests/unit/out/refcount/destructor.rs +++ b/tests/unit/out/refcount/destructor.rs @@ -9,31 +9,31 @@ 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, VaArg, FnPtrArg, Destructible, Default)] #[byte_size(1)] pub struct S {} -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructible, 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, VaArg, FnPtrArg, Destructible, 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, VaArg, FnPtrArg, Destructible, 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, VaArg, FnPtrArg, Destructible)] #[byte_size(3)] pub struct ArrayMember { #[offset(0)] @@ -49,26 +49,26 @@ impl Default for ArrayMember { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructible, 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, VaArg, FnPtrArg, Destructible, 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, VaArg, FnPtrArg, Destructible, 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, VaArg, FnPtrArg, Destructible, Default)] #[byte_size(4)] pub struct Copied { #[offset(0)] @@ -81,13 +81,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, VaArg, FnPtrArg, Destructible, Default)] #[byte_size(4)] pub struct Tagged { #[offset(0)] pub tag: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructible, Default)] #[byte_size(20)] pub struct Ordered { #[offset(0)] @@ -111,46 +111,56 @@ pub fn main() { fn main_0() -> i32 { { let s: Value = Rc::new(RefCell::new(::default())); - let _dtor_s = std::mem::DropGuard::new(s.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_s = + std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 1)); { let s: Value = Rc::new(RefCell::new(::default())); - let _dtor_s = std::mem::DropGuard::new(s.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_s = + std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 2)); { let d: Value = Rc::new(RefCell::new(::default())); - let _dtor_d = std::mem::DropGuard::new(d.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_d = + std::mem::DropGuard::new(d.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 3)); { let o: Value = Rc::new(RefCell::new(::default())); - let _dtor_o = std::mem::DropGuard::new(o.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_o = + std::mem::DropGuard::new(o.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 4)); { let am: Value = Rc::new(RefCell::new(::default())); - let _dtor_am = std::mem::DropGuard::new(am.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_am = + std::mem::DropGuard::new(am.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 7)); { let e: Value = Rc::new(RefCell::new(::default())); - let _dtor_e = std::mem::DropGuard::new(e.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_e = + std::mem::DropGuard::new(e.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 8)); { let tc: Value = Rc::new(RefCell::new(::default())); - let _dtor_tc = std::mem::DropGuard::new(tc.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_tc = + std::mem::DropGuard::new(tc.clone(), |__p| Destructible::destroy(__p.as_pointer())); let ti: Value = Rc::new(RefCell::new(::default())); - let _dtor_ti = std::mem::DropGuard::new(ti.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_ti = + std::mem::DropGuard::new(ti.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == 13)); { let a: Value = Rc::new(RefCell::new(Copied { v: 5 })); - let _dtor_a = std::mem::DropGuard::new(a.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_a = + std::mem::DropGuard::new(a.clone(), |__p| Destructible::destroy(__p.as_pointer())); let b: Value = Rc::new(RefCell::new((*a.borrow()).clone())); - let _dtor_b = std::mem::DropGuard::new(b.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_b = + std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!(({ ({ (*b.borrow()).v } == 5) })); } assert!((global_0.with(|rc| *rc.borrow()) == 15)); @@ -162,7 +172,8 @@ fn main_0() -> i32 { dummy2: 0, third: Tagged { tag: 3 }, })); - let _dtor_o = std::mem::DropGuard::new(o.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_o = + std::mem::DropGuard::new(o.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((order_count_2.with(|rc| *rc.borrow()) == 3)); assert!( @@ -186,7 +197,8 @@ fn main_0() -> i32 { let mut before: i32 = global_0.with(|rc| *rc.borrow()); { let cs: Value = Rc::new(RefCell::new(::default())); - let _dtor_cs = std::mem::DropGuard::new(cs.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_cs = + std::mem::DropGuard::new(cs.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((global_0.with(|rc| *rc.borrow()) == (before + 1))); return 0; @@ -198,8 +210,8 @@ impl ArrayMemberImpl for Ptr { fn destructor(&self) { { let __p = array_field_ptr!(self, items); - for __i in 0..__p.len() { - SImpl::destructor(&__p.offset(__i as isize)); + for __i in (0..__p.len()).rev() { + Destructible::destroy(__p.offset(__i as isize)); } } } @@ -217,7 +229,7 @@ pub trait DefaultedImpl { } impl DefaultedImpl for Ptr { fn destructor(&self) { - field_ptr!(self, s).destructor(); + Destructible::destroy(field_ptr!(self, s)); } } pub trait EmptyBodyImpl { @@ -225,7 +237,7 @@ pub trait EmptyBodyImpl { } impl EmptyBodyImpl for Ptr { fn destructor(&self) { - field_ptr!(self, s).destructor(); + Destructible::destroy(field_ptr!(self, s)); } } pub trait MiddleImpl { @@ -233,7 +245,7 @@ pub trait MiddleImpl { } impl MiddleImpl for Ptr { fn destructor(&self) { - field_ptr!(self, s).destructor(); + Destructible::destroy(field_ptr!(self, s)); } } pub trait OrderedImpl { @@ -241,9 +253,9 @@ pub trait OrderedImpl { } impl OrderedImpl for Ptr { fn destructor(&self) { - field_ptr!(self, third).destructor(); - field_ptr!(self, second).destructor(); - field_ptr!(self, first).destructor(); + Destructible::destroy(field_ptr!(self, third)); + Destructible::destroy(field_ptr!(self, second)); + Destructible::destroy(field_ptr!(self, first)); } } pub trait OuterImpl { @@ -251,7 +263,7 @@ pub trait OuterImpl { } impl OuterImpl for Ptr { fn destructor(&self) { - field_ptr!(self, m).destructor(); + Destructible::destroy(field_ptr!(self, m)); } } pub trait SImpl { diff --git a/tests/unit/out/refcount/destructor_params.rs b/tests/unit/out/refcount/destructor_params.rs index 567c521862..17b00faad5 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, VaArg, FnPtrArg, Destructible, Default)] #[byte_size(4)] pub struct S { #[offset(0)] @@ -48,7 +48,8 @@ pub fn main() { fn main_0() -> i32 { { let s: Value = Rc::new(RefCell::new(S { v: 1 })); - let _dtor_s = std::mem::DropGuard::new(s.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_s = + std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!(({ (({ by_value_2((*s.borrow()).clone(),) }) == 1) })); assert!( (destroyed_0.with(|rc| *rc.borrow()) == 1) && (last_1.with(|rc| *rc.borrow()) == 1) diff --git a/tests/unit/out/refcount/destructor_temporaries.rs b/tests/unit/out/refcount/destructor_temporaries.rs index 79555ab888..e6bca59162 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, VaArg, FnPtrArg, Destructible, Default)] #[byte_size(4)] pub struct S { #[offset(0)] pub v: i32, } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructible, Default)] #[byte_size(8)] pub struct Outer { #[offset(0)] @@ -116,7 +116,8 @@ fn main_0() -> i32 { destroyed_0.with(|rc| *rc.borrow_mut() = 0); { let s: Value = Rc::new(RefCell::new(S { v: 12 })); - let _dtor_s = std::mem::DropGuard::new(s.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_s = + std::mem::DropGuard::new(s.clone(), |__p| Destructible::destroy(__p.as_pointer())); (*s.borrow_mut()) = ({ make_2(13) }); assert!( ({ @@ -134,7 +135,7 @@ pub trait OuterImpl { } impl OuterImpl for Ptr { fn destructor(&self) { - field_ptr!(self, inner).destructor(); + Destructible::destroy(field_ptr!(self, inner)); } } pub trait SImpl { diff --git a/tests/unit/out/refcount/for_body_destructor.rs b/tests/unit/out/refcount/for_body_destructor.rs index 60ff9056a1..55ab0488a4 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, VaArg, FnPtrArg, Destructible, Default)] #[byte_size(4)] pub struct Guard { #[offset(0)] @@ -29,11 +29,13 @@ fn main_0() -> i32 { 'loop_: while ((*i.borrow()) < 2) { 'for_body: { let first: Value = Rc::new(RefCell::new(Guard { digit: 1 })); - let _dtor_first = - std::mem::DropGuard::new(first.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_first = std::mem::DropGuard::new(first.clone(), |__p| { + Destructible::destroy(__p.as_pointer()) + }); let second: Value = Rc::new(RefCell::new(Guard { digit: 2 })); - let _dtor_second = - std::mem::DropGuard::new(second.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_second = std::mem::DropGuard::new(second.clone(), |__p| { + Destructible::destroy(__p.as_pointer()) + }); if ((*i.borrow()) == 0) { break 'for_body; } @@ -47,8 +49,9 @@ fn main_0() -> i32 { 'loop_: while ((*i.borrow()) < 2) { 'for_body: { let g: Value = Rc::new(RefCell::new(Guard { digit: 3 })); - let _dtor_g = - std::mem::DropGuard::new(g.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_g = std::mem::DropGuard::new(g.clone(), |__p| { + Destructible::destroy(__p.as_pointer()) + }); break 'loop_; } ({ step_0(i.as_pointer()) }); @@ -60,15 +63,16 @@ fn main_0() -> i32 { 'loop_: while ((*i.borrow()) < 1) { 'for_body: { let outer: Value = Rc::new(RefCell::new(Guard { digit: 4 })); - let _dtor_outer = - std::mem::DropGuard::new(outer.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_outer = std::mem::DropGuard::new(outer.clone(), |__p| { + Destructible::destroy(__p.as_pointer()) + }); { let j: Value = Rc::new(RefCell::new(0)); 'loop_: while ((*j.borrow()) < 2) { 'for_body: { let inner: Value = Rc::new(RefCell::new(Guard { digit: 5 })); let _dtor_inner = std::mem::DropGuard::new(inner.clone(), |__p| { - __p.as_pointer().destructor() + Destructible::destroy(__p.as_pointer()) }); if ((*j.borrow()) == 0) { break 'for_body; @@ -89,13 +93,14 @@ fn main_0() -> i32 { 'loop_: while ((*i.borrow()) < 1) { 'for_body: { let outer: Value = Rc::new(RefCell::new(Guard { digit: 4 })); - let _dtor_outer = - std::mem::DropGuard::new(outer.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_outer = std::mem::DropGuard::new(outer.clone(), |__p| { + Destructible::destroy(__p.as_pointer()) + }); let mut j: i32 = 0; 'loop_: while ((*j.prefix_inc()) < 3) { let inner: Value = Rc::new(RefCell::new(Guard { digit: 5 })); let _dtor_inner = std::mem::DropGuard::new(inner.clone(), |__p| { - __p.as_pointer().destructor() + Destructible::destroy(__p.as_pointer()) }); if (j == 1) { continue 'loop_; @@ -107,7 +112,7 @@ fn main_0() -> i32 { __do_while = false; let inner: Value = Rc::new(RefCell::new(Guard { digit: 6 })); let _dtor_inner = std::mem::DropGuard::new(inner.clone(), |__p| { - __p.as_pointer().destructor() + Destructible::destroy(__p.as_pointer()) }); continue 'loop_; } @@ -118,7 +123,7 @@ fn main_0() -> i32 { let mut value: i32 = (value.read()); let inner: Value = Rc::new(RefCell::new(Guard { digit: value })); let _dtor_inner = std::mem::DropGuard::new(inner.clone(), |__p| { - __p.as_pointer().destructor() + Destructible::destroy(__p.as_pointer()) }); if (value == 1) { continue 'loop_; @@ -135,15 +140,17 @@ fn main_0() -> i32 { let mut i: i32 = 2; 'loop_: loop { let condition: Value = Rc::new(RefCell::new(Guard { digit: i })); - let _dtor_condition = - std::mem::DropGuard::new(condition.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_condition = std::mem::DropGuard::new(condition.clone(), |__p| { + Destructible::destroy(__p.as_pointer()) + }); if !({ GuardImpl::to_bool(&condition.as_pointer()) }) { break; } 'for_body: { let body: Value = Rc::new(RefCell::new(Guard { digit: 4 })); - let _dtor_body = - std::mem::DropGuard::new(body.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_body = std::mem::DropGuard::new(body.clone(), |__p| { + Destructible::destroy(__p.as_pointer()) + }); if (i == 2) { break 'for_body; } @@ -159,12 +166,13 @@ fn main_0() -> i32 { { let init: Value = Rc::new(RefCell::new(Guard { digit: 5 })); let _dtor_init = - std::mem::DropGuard::new(init.clone(), |__p| __p.as_pointer().destructor()); + std::mem::DropGuard::new(init.clone(), |__p| Destructible::destroy(__p.as_pointer())); 'loop_: while ((*i.borrow()) < 2) { 'for_body: { let body: Value = Rc::new(RefCell::new(Guard { digit: 6 })); - let _dtor_body = - std::mem::DropGuard::new(body.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_body = std::mem::DropGuard::new(body.clone(), |__p| { + Destructible::destroy(__p.as_pointer()) + }); } ({ step_0(i.as_pointer()) }); } @@ -176,7 +184,8 @@ fn main_0() -> i32 { let g: Value = Rc::new(RefCell::new(Guard { digit: (*j.prefix_inc()), })); - let _dtor_g = std::mem::DropGuard::new(g.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_g = + std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(__p.as_pointer())); continue 'loop_; } } diff --git a/tests/unit/out/refcount/lambda_as_field.rs b/tests/unit/out/refcount/lambda_as_field.rs index 3287edcb88..5fef9b2947 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, VaArg, FnPtrArg, Destructible)] #[byte_size(1)] pub struct Guard__lambda_at_lambda_as_field_cpp_34_13__ { #[offset(0)] @@ -24,7 +24,7 @@ impl Default for Guard__lambda_at_lambda_as_field_cpp_34_13__ { } } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, Destructible, Default)] #[byte_size(8)] pub struct Guard__lambda_at_lambda_as_field_cpp_45_13__ { #[offset(0)] @@ -141,7 +141,8 @@ fn main_0() -> i32 { (*count_0.with(Value::clone).borrow_mut()).postfix_inc(); }), })); - let _dtor_g = std::mem::DropGuard::new(g.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_g = + std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!((count_0.with(|rc| *rc.borrow()) == 0)); } assert!((count_0.with(|rc| *rc.borrow()) == 1)); @@ -172,7 +173,8 @@ fn main_0() -> i32 { } ), })); - let _dtor_g = std::mem::DropGuard::new(g.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_g = + std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!(({ ((*cleaned.borrow()) == 0) })); } assert!(({ ((*cleaned.borrow()) == 1) })); diff --git a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs index daf1e89e2e..2ac27630c5 100644 --- a/tests/unit/out/refcount/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/refcount/lambda_capture_copy_ctor.rs @@ -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, VaArg, FnPtrArg, MoveCtor, Destructible)] #[byte_size(1)] pub struct Dropped {} impl Dropped { @@ -141,10 +141,10 @@ fn main_0() -> i32 { || {} ))); let _dtor_m = - std::mem::DropGuard::new(m.clone(), |__p| __p.as_pointer().with(|__f| __f.destroy())); + std::mem::DropGuard::new(m.clone(), |__p| Destructible::destroy(__p.as_pointer())); let m2: Value> = Rc::new(RefCell::new((*m.borrow()).move_from())); let _dtor_m2 = - std::mem::DropGuard::new(m2.clone(), |__p| __p.as_pointer().with(|__f| __f.destroy())); + std::mem::DropGuard::new(m2.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((drops_0.with(|rc| *rc.borrow()) == 2)); { @@ -155,10 +155,10 @@ fn main_0() -> i32 { || {} ))); let _dtor_k = - std::mem::DropGuard::new(k.clone(), |__p| __p.as_pointer().with(|__f| __f.destroy())); + std::mem::DropGuard::new(k.clone(), |__p| Destructible::destroy(__p.as_pointer())); let k2: Value> = Rc::new(RefCell::new((*k.borrow()).copy_from())); let _dtor_k2 = - std::mem::DropGuard::new(k2.clone(), |__p| __p.as_pointer().with(|__f| __f.destroy())); + std::mem::DropGuard::new(k2.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((drops_0.with(|rc| *rc.borrow()) == 4)); { @@ -168,9 +168,8 @@ fn main_0() -> i32 { }, || {} ))); - let _dtor_inner = std::mem::DropGuard::new(inner.clone(), |__p| { - __p.as_pointer().with(|__f| __f.destroy()) - }); + let _dtor_inner = + std::mem::DropGuard::new(inner.clone(), |__p| Destructible::destroy(__p.as_pointer())); let outer: Value> = Rc::new(RefCell::new(lambda!( { let inner: Value> = @@ -178,9 +177,8 @@ fn main_0() -> i32 { }, || {} ))); - let _dtor_outer = std::mem::DropGuard::new(outer.clone(), |__p| { - __p.as_pointer().with(|__f| __f.destroy()) - }); + let _dtor_outer = + std::mem::DropGuard::new(outer.clone(), |__p| Destructible::destroy(__p.as_pointer())); } assert!((drops_0.with(|rc| *rc.borrow()) == 6)); return 0; diff --git a/tests/unit/out/refcount/lambda_move_only_capture.rs b/tests/unit/out/refcount/lambda_move_only_capture.rs index f04a28cdcb..8e6c2a7282 100644 --- a/tests/unit/out/refcount/lambda_move_only_capture.rs +++ b/tests/unit/out/refcount/lambda_move_only_capture.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, Destructor, Default)] +#[derive(Record, ByteRepr, FnPtrArg, MoveCtor, CppFrom, Destructible, Default)] #[cpp_from(i32, new, value)] #[byte_size(8)] pub struct Owner { @@ -32,7 +32,8 @@ pub fn main() { } fn main_0() -> i32 { let o: Value = Rc::new(RefCell::new(Owner::new({ 5 }))); - let _dtor_o = std::mem::DropGuard::new(o.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_o = + std::mem::DropGuard::new(o.clone(), |__p| Destructible::destroy(__p.as_pointer())); let f: Value i32>> = Rc::new(RefCell::new(lambda!( { let h: Value = Rc::new(RefCell::new(Owner::move_from({ o.as_pointer() }))); @@ -42,12 +43,12 @@ fn main_0() -> i32 { } ))); let _dtor_f = - std::mem::DropGuard::new(f.clone(), |__p| __p.as_pointer().with(|__f| __f.destroy())); + std::mem::DropGuard::new(f.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!(({ ({ (*o.borrow()).p.clone() }).is_null() })); assert!(({ (({ (*f.borrow()).call() }) == 5) })); let g: Value i32>> = Rc::new(RefCell::new((*f.borrow()).move_from())); let _dtor_g = - std::mem::DropGuard::new(g.clone(), |__p| __p.as_pointer().with(|__f| __f.destroy())); + std::mem::DropGuard::new(g.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!(({ (({ (*g.borrow()).call() }) == 5) })); let total: Value = Rc::new(RefCell::new(0)); let consume: Value> = Rc::new(RefCell::new(lambda!( @@ -64,17 +65,18 @@ fn main_0() -> i32 { } ))); let _dtor_consume = std::mem::DropGuard::new(consume.clone(), |__p| { - __p.as_pointer().with(|__f| __f.destroy()) + Destructible::destroy(__p.as_pointer()) }); ({ (*consume.borrow()).call() }); ({ (*consume.borrow()).call() }); assert!(({ ((*total.borrow()) == 7) })); let o2: Value = Rc::new(RefCell::new(Owner::new({ 9 }))); - let _dtor_o2 = std::mem::DropGuard::new(o2.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_o2 = + std::mem::DropGuard::new(o2.clone(), |__p| Destructible::destroy(__p.as_pointer())); let t: Value i32>> = Rc::new(RefCell::new(({ OwnerImpl::take(&o2.as_pointer()) }))); let _dtor_t = - std::mem::DropGuard::new(t.clone(), |__p| __p.as_pointer().with(|__f| __f.destroy())); + std::mem::DropGuard::new(t.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!(({ ({ (*o2.borrow()).p.clone() }).is_null() })); assert!(({ (({ (*t.borrow()).call() }) == 9) })); return 0; diff --git a/tests/unit/out/refcount/rule_of_five.rs b/tests/unit/out/refcount/rule_of_five.rs index fd16015e5d..528459a260 100644 --- a/tests/unit/out/refcount/rule_of_five.rs +++ b/tests/unit/out/refcount/rule_of_five.rs @@ -16,7 +16,7 @@ thread_local!( pub static moves_2: Value = Rc::new(RefCell::new(0)); ); #[derive( - Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom, CopyAssign, MoveAssign, Destructor, + Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CppFrom, CopyAssign, MoveAssign, Destructible, )] #[cpp_from(i32, new, value)] #[byte_size(20)] @@ -108,7 +108,8 @@ impl Default for Buffer { } pub fn make_3(mut size: i32) -> Buffer { let b: Value = Rc::new(RefCell::new(Buffer::new({ size }))); - let _dtor_b = std::mem::DropGuard::new(b.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_b = + std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(__p.as_pointer())); return Buffer::move_from({ b.as_pointer() }); } pub fn main() { @@ -118,9 +119,11 @@ pub fn main() { fn main_0() -> i32 { { let a: Value = Rc::new(RefCell::new(Buffer::new({ 4 }))); - let _dtor_a = std::mem::DropGuard::new(a.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_a = + std::mem::DropGuard::new(a.clone(), |__p| Destructible::destroy(__p.as_pointer())); let b: Value = Rc::new(RefCell::new(Buffer::copy_from({ a.as_pointer() }))); - let _dtor_b = std::mem::DropGuard::new(b.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_b = + std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!( ((alive_0.with(|rc| *rc.borrow()) == 2) && (copies_1.with(|rc| *rc.borrow()) == 1)) && (moves_2.with(|rc| *rc.borrow()) == 0) @@ -128,7 +131,8 @@ fn main_0() -> i32 { array_elem!(b.as_pointer(), data, 0).write(100); assert!(((array_elem!(a.as_pointer(), data, 0).read()) == 0)); let c: Value = Rc::new(RefCell::new(Buffer::move_from({ a.as_pointer() }))); - let _dtor_c = std::mem::DropGuard::new(c.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_c = + std::mem::DropGuard::new(c.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!((alive_0.with(|rc| *rc.borrow()) == 3) && (moves_2.with(|rc| *rc.borrow()) == 1)); assert!( ({ @@ -143,7 +147,8 @@ fn main_0() -> i32 { }) ); let d: Value = Rc::new(RefCell::new(({ make_3(2) }))); - let _dtor_d = std::mem::DropGuard::new(d.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_d = + std::mem::DropGuard::new(d.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!(({ ({ (*d.borrow()).size } == 2) && (moves_2.with(|rc| *rc.borrow()) == 2) })); ({ BufferImpl::copy_assign(&d.as_pointer(), b.as_pointer()) }); assert!( diff --git a/tests/unit/out/refcount/rule_of_three.rs b/tests/unit/out/refcount/rule_of_three.rs index b1bdcc7384..eefc62e17c 100644 --- a/tests/unit/out/refcount/rule_of_three.rs +++ b/tests/unit/out/refcount/rule_of_three.rs @@ -12,7 +12,7 @@ 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, VaArg, FnPtrArg, CppFrom, CopyAssign, Destructible)] #[cpp_from(i32, new, value)] #[byte_size(20)] pub struct Buffer { @@ -100,14 +100,17 @@ pub fn main() { fn main_0() -> i32 { { let a: Value = Rc::new(RefCell::new(Buffer::new({ 4 }))); - let _dtor_a = std::mem::DropGuard::new(a.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_a = + std::mem::DropGuard::new(a.clone(), |__p| Destructible::destroy(__p.as_pointer())); let b: Value = Rc::new(RefCell::new(Buffer::copy_from({ a.as_pointer() }))); - let _dtor_b = std::mem::DropGuard::new(b.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_b = + std::mem::DropGuard::new(b.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!((alive_0.with(|rc| *rc.borrow()) == 2) && (copies_1.with(|rc| *rc.borrow()) == 1)); array_elem!(b.as_pointer(), data, 0).write(100); assert!(((array_elem!(a.as_pointer(), data, 0).read()) == 0)); let c: Value = Rc::new(RefCell::new(Buffer::new({ 2 }))); - let _dtor_c = std::mem::DropGuard::new(c.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_c = + std::mem::DropGuard::new(c.clone(), |__p| Destructible::destroy(__p.as_pointer())); ({ BufferImpl::copy_assign(&c.as_pointer(), a.as_pointer()) }); assert!( ({ @@ -124,7 +127,8 @@ fn main_0() -> i32 { assert!((({ sum_2(a.as_pointer(),) }) == 6)); assert!((({ sum_2(b.as_pointer(),) }) == 106)); let d: Value = Rc::new(RefCell::new(Buffer::copy_from({ a.as_pointer() }))); - let _dtor_d = std::mem::DropGuard::new(d.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_d = + std::mem::DropGuard::new(d.clone(), |__p| Destructible::destroy(__p.as_pointer())); assert!((alive_0.with(|rc| *rc.borrow()) == 4) && (copies_1.with(|rc| *rc.borrow()) == 3)); assert!( ({ diff --git a/tests/unit/out/refcount/swap_map_no_copy.rs b/tests/unit/out/refcount/swap_map_no_copy.rs index 1e6b008c52..2f32b9e7f1 100644 --- a/tests/unit/out/refcount/swap_map_no_copy.rs +++ b/tests/unit/out/refcount/swap_map_no_copy.rs @@ -107,7 +107,7 @@ 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, VaArg, FnPtrArg, CppFrom, CopyAssign, Destructible, Default)] #[cpp_from(i32, new, value)] #[byte_size(4)] pub struct CopyOnly { @@ -132,7 +132,7 @@ impl Clone for CopyOnly { CopyOnly::copy_from(__src.as_pointer()) } } -#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructor, Default)] +#[derive(Clone, Record, ByteRepr, VaArg, FnPtrArg, CopyAssign, Destructible, Default)] #[byte_size(8)] pub struct CopyOnlyPair { #[offset(0)] @@ -160,7 +160,7 @@ thread_local!( CppFrom, CopyAssign, MoveAssign, - Destructor, + Destructible, Default, )] #[cpp_from(i32, new, value)] @@ -196,7 +196,16 @@ impl Clone for Moved { } } #[derive( - Clone, Record, ByteRepr, VaArg, FnPtrArg, MoveCtor, CopyAssign, MoveAssign, Destructor, Default, + Clone, + Record, + ByteRepr, + VaArg, + FnPtrArg, + MoveCtor, + CopyAssign, + MoveAssign, + Destructible, + Default, )] #[byte_size(8)] pub struct MovedPair { @@ -603,9 +612,11 @@ fn main_0() -> i32 { ); assert!((copies_0.with(|rc| *rc.borrow()) == 0)); let c1: Value = Rc::new(RefCell::new(CopyOnly::new({ 1 }))); - let _dtor_c1 = std::mem::DropGuard::new(c1.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_c1 = + std::mem::DropGuard::new(c1.clone(), |__p| Destructible::destroy(__p.as_pointer())); let c2: Value = Rc::new(RefCell::new(CopyOnly::new({ 2 }))); - let _dtor_c2 = std::mem::DropGuard::new(c2.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_c2 = + std::mem::DropGuard::new(c2.clone(), |__p| Destructible::destroy(__p.as_pointer())); cpp_swap!(c1.as_pointer(), c2.as_pointer()); assert!(({ ({ (*c1.borrow()).v } == 2) && ({ (*c2.borrow()).v } == 1) })); assert!( @@ -616,7 +627,8 @@ fn main_0() -> i32 { x: CopyOnly::new({ 3 }), y: CopyOnly::new({ 4 }), })); - let _dtor_cp = std::mem::DropGuard::new(cp.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_cp = + std::mem::DropGuard::new(cp.clone(), |__p| Destructible::destroy(__p.as_pointer())); cpp_swap!( field_ptr!(cp.as_pointer(), x), field_ptr!(cp.as_pointer(), y) @@ -642,9 +654,11 @@ fn main_0() -> i32 { && (copy_only_dtors_2.with(|rc| *rc.borrow()) == 3) ); let mv1: Value = Rc::new(RefCell::new(Moved::new({ 1 }))); - let _dtor_mv1 = std::mem::DropGuard::new(mv1.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_mv1 = + std::mem::DropGuard::new(mv1.clone(), |__p| Destructible::destroy(__p.as_pointer())); let mv2: Value = Rc::new(RefCell::new(Moved::new({ 2 }))); - let _dtor_mv2 = std::mem::DropGuard::new(mv2.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_mv2 = + std::mem::DropGuard::new(mv2.clone(), |__p| Destructible::destroy(__p.as_pointer())); cpp_swap!(mv1.as_pointer(), mv2.as_pointer()); assert!(({ ({ (*mv1.borrow()).v } == 2) && ({ (*mv2.borrow()).v } == 1) })); assert!(({ swapped_once_6() })); @@ -652,7 +666,8 @@ fn main_0() -> i32 { x: Moved::new({ 3 }), y: Moved::new({ 4 }), })); - let _dtor_mp = std::mem::DropGuard::new(mp.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_mp = + std::mem::DropGuard::new(mp.clone(), |__p| Destructible::destroy(__p.as_pointer())); cpp_swap!( field_ptr!(mp.as_pointer(), x), field_ptr!(mp.as_pointer(), y) @@ -791,8 +806,8 @@ impl CopyOnlyPairImpl for Ptr { return (*self).clone(); } fn destructor(&self) { - field_ptr!(self, y).destructor(); - field_ptr!(self, x).destructor(); + Destructible::destroy(field_ptr!(self, y)); + Destructible::destroy(field_ptr!(self, x)); } } pub trait MovedImpl { @@ -845,8 +860,8 @@ impl MovedPairImpl for Ptr { return (*self).clone(); } fn destructor(&self) { - field_ptr!(self, y).destructor(); - field_ptr!(self, x).destructor(); + Destructible::destroy(field_ptr!(self, y)); + Destructible::destroy(field_ptr!(self, x)); } } pub trait OwnerImpl { diff --git a/tests/unit/out/refcount/va_list_field.rs b/tests/unit/out/refcount/va_list_field.rs index 5dd7dfeb52..52c3e0da4c 100644 --- a/tests/unit/out/refcount/va_list_field.rs +++ b/tests/unit/out/refcount/va_list_field.rs @@ -12,7 +12,8 @@ pub fn sum_0(n: i32, __args: Box<[VaArg]>) -> i32 { let ap: Value> = Rc::new(RefCell::new(Ptr::::default())); (*ap.borrow_mut()) = __args.decay(); let guard: Value = Rc::new(RefCell::new(Guard_1::new({ ap.as_pointer() }))); - let _dtor_guard = std::mem::DropGuard::new(guard.clone(), |__p| __p.as_pointer().destructor()); + let _dtor_guard = + std::mem::DropGuard::new(guard.clone(), |__p| Destructible::destroy(__p.as_pointer())); let mut total: i32 = 0; { let mut i: i32 = 0; @@ -25,7 +26,7 @@ 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, VaArg, FnPtrArg, CppFrom, Destructible, Default)] #[cpp_from(Ptr , new, mut_ptr)] #[byte_size(16)] pub struct Guard_1 { diff --git a/tests/unit/out/unsafe/constructor.rs b/tests/unit/out/unsafe/constructor.rs index c9c9a6dfaf..980507093f 100644 --- a/tests/unit/out/unsafe/constructor.rs +++ b/tests/unit/out/unsafe/constructor.rs @@ -8,7 +8,7 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub static mut total_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, CppFromUnsafe, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, CppFromUnsafe, DestructibleUnsafe, Default)] #[cpp_from(i32, new, value)] pub struct S { pub v: i32, @@ -70,7 +70,9 @@ pub fn main() { unsafe fn main_0() -> i32 { { let mut s: S = S::new({ 3 }); - let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { (*__p).destructor() }); + let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); assert!(((s.v) == (4))); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut total_0)) == (8))); } diff --git a/tests/unit/out/unsafe/copy_move_defaulted.rs b/tests/unit/out/unsafe/copy_move_defaulted.rs index 88fb268944..4e83cdebb6 100644 --- a/tests/unit/out/unsafe/copy_move_defaulted.rs +++ b/tests/unit/out/unsafe/copy_move_defaulted.rs @@ -12,7 +12,7 @@ pub struct Inner { pub x: i32, } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, CppFromUnsafe, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, CppFromUnsafe, DestructibleUnsafe, Default)] #[cpp_from(i32, new, value)] pub struct Explicit { pub v: i32, @@ -212,7 +212,9 @@ impl Copyable { } } #[repr(C)] -#[derive(FnPtrArg, MoveCtorUnsafe, CppFromUnsafe, MoveAssignUnsafe, DestructorUnsafe, Default)] +#[derive( + FnPtrArg, MoveCtorUnsafe, CppFromUnsafe, MoveAssignUnsafe, DestructibleUnsafe, Default, +)] #[cpp_from(i32, new, value)] pub struct Holder { pub inner: Inner, @@ -247,7 +249,7 @@ impl Holder { } impl Holder { pub unsafe fn destructor(&mut self) { - Explicit::destructor(&mut self.e); + DestructibleUnsafe::destroy(&raw mut self.e); } } pub unsafe fn same_0(a: *const Explicit, b: *const Explicit) -> bool { @@ -263,26 +265,40 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut a: Explicit = Explicit::new({ 1 }); - let _dtor_a = std::mem::DropGuard::new(&raw mut a, |__p| unsafe { (*__p).destructor() }); + let _dtor_a = std::mem::DropGuard::new(&raw mut a, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut b: Explicit = a.clone(); - let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { (*__p).destructor() }); + let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut c: Explicit = a.clone(); - let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { (*__p).destructor() }); + let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut d: Explicit = a.clone(); - let _dtor_d = std::mem::DropGuard::new(&raw mut d, |__p| unsafe { (*__p).destructor() }); + let _dtor_d = std::mem::DropGuard::new(&raw mut d, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); assert!( ((unsafe { same_0(&b, &a,) }) && (unsafe { same_0(&c, &a,) })) && (unsafe { same_0(&d, &a,) }) ); let mut e: Explicit = Explicit::new({ 2 }); - let _dtor_e = std::mem::DropGuard::new(&raw mut e, |__p| unsafe { (*__p).destructor() }); + let _dtor_e = std::mem::DropGuard::new(&raw mut e, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut f: Explicit = Explicit::new({ 3 }); - let _dtor_f = std::mem::DropGuard::new(&raw mut f, |__p| unsafe { (*__p).destructor() }); + let _dtor_f = std::mem::DropGuard::new(&raw mut f, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); e = (b).clone(); f = (c).clone(); assert!((unsafe { same_0(&e, &b,) }) && (unsafe { same_0(&f, &c,) })); let mut g: Explicit = Explicit::new({ 4 }); - let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { (*__p).destructor() }); + let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); g = { e = (f).clone(); (e).clone() @@ -423,7 +439,9 @@ unsafe fn main_0() -> i32 { (unsafe { Copyable::move_assign(&mut c4, &mut c3) }); assert!(((c4.data[(1_usize)]) == (2)) && (c3.data.is_empty())); let mut h1: Holder = Holder::new({ 4 }); - let _dtor_h1 = std::mem::DropGuard::new(&raw mut h1, |__p| unsafe { (*__p).destructor() }); + let _dtor_h1 = std::mem::DropGuard::new(&raw mut h1, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); { let _a0: *mut i32 = (Box::leak(Box::new(9)) as *mut i32); h1.p = if _a0.is_null() { @@ -433,7 +451,9 @@ unsafe fn main_0() -> i32 { } }; let mut h2: Holder = Holder::move_from({ &mut h1 }); - let _dtor_h2 = std::mem::DropGuard::new(&raw mut h2, |__p| unsafe { (*__p).destructor() }); + let _dtor_h2 = std::mem::DropGuard::new(&raw mut h2, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); assert!( ((((h2.inner.x) == (4)) && ((h2.e.v) == (4))) && ((*h2 @@ -448,7 +468,9 @@ unsafe fn main_0() -> i32 { .is_null()) ); let mut h3: Holder = Holder::new({ 1 }); - let _dtor_h3 = std::mem::DropGuard::new(&raw mut h3, |__p| unsafe { (*__p).destructor() }); + let _dtor_h3 = std::mem::DropGuard::new(&raw mut h3, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); (unsafe { Holder::move_assign(&mut h3, &mut h2) }); assert!( ((((h3.inner.x) == (4)) && ((h3.e.arr[(1) as usize]) == (5))) diff --git a/tests/unit/out/unsafe/delete_array_order.rs b/tests/unit/out/unsafe/delete_array_order.rs index 01e8e0284f..74b823e8b9 100644 --- a/tests/unit/out/unsafe/delete_array_order.rs +++ b/tests/unit/out/unsafe/delete_array_order.rs @@ -7,7 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct Element { pub id: i64, pub value: i64, @@ -52,7 +52,7 @@ unsafe fn main_0() -> i32 { / ::std::mem::size_of::()) .rev() { - Element::destructor(&mut *__p.add(__i)); + DestructibleUnsafe::destroy(__p.add(__i)); } ::std::mem::drop(Box::from_raw(::std::slice::from_raw_parts_mut( __p, diff --git a/tests/unit/out/unsafe/destructor.rs b/tests/unit/out/unsafe/destructor.rs index 7779f7c8f6..1f8caead60 100644 --- a/tests/unit/out/unsafe/destructor.rs +++ b/tests/unit/out/unsafe/destructor.rs @@ -8,7 +8,7 @@ use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; pub static mut global_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct S {} impl S { pub unsafe fn destructor(&mut self) { @@ -16,59 +16,57 @@ impl S { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct Defaulted { pub s: S, } impl Defaulted { pub unsafe fn destructor(&mut self) { - S::destructor(&mut self.s); + DestructibleUnsafe::destroy(&raw mut self.s); } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct Middle { pub s: S, } impl Middle { pub unsafe fn destructor(&mut self) { - S::destructor(&mut self.s); + DestructibleUnsafe::destroy(&raw mut self.s); } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct Outer { pub m: Middle, } impl Outer { pub unsafe fn destructor(&mut self) { - Middle::destructor(&mut self.m); + DestructibleUnsafe::destroy(&raw mut self.m); } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct ArrayMember { pub items: [S; 3], } impl ArrayMember { pub unsafe fn destructor(&mut self) { - for __e in self.items.iter_mut() { - S::destructor(__e); - } + DestructibleUnsafe::destroy(&raw mut self.items); } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct EmptyBody { pub s: S, } impl EmptyBody { pub unsafe fn destructor(&mut self) { - S::destructor(&mut self.s); + DestructibleUnsafe::destroy(&raw mut self.s); } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct Templated_char_ { pub v: libc::c_char, } @@ -80,7 +78,7 @@ impl Templated_char_ { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct Templated_int_ { pub v: i32, } @@ -92,7 +90,7 @@ impl Templated_int_ { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct Copied { pub v: i32, } @@ -105,7 +103,7 @@ pub static mut order_1: std::cell::LazyCell<[i32; 3]> = std::cell::LazyCell::new(|| unsafe { [0_i32; 3] }); pub static mut order_count_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct Tagged { pub tag: i32, } @@ -117,7 +115,7 @@ impl Tagged { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct Ordered { pub first: Tagged, pub dummy1: i32, @@ -127,9 +125,9 @@ pub struct Ordered { } impl Ordered { pub unsafe fn destructor(&mut self) { - Tagged::destructor(&mut self.third); - Tagged::destructor(&mut self.second); - Tagged::destructor(&mut self.first); + DestructibleUnsafe::destroy(&raw mut self.third); + DestructibleUnsafe::destroy(&raw mut self.second); + DestructibleUnsafe::destroy(&raw mut self.first); } } pub fn main() { @@ -141,46 +139,66 @@ pub fn main() { unsafe fn main_0() -> i32 { { let mut s: S = ::default(); - let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { (*__p).destructor() }); + let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (1))); { let mut s: S = ::default(); - let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { (*__p).destructor() }); + let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (2))); { let mut d: Defaulted = ::default(); - let _dtor_d = std::mem::DropGuard::new(&raw mut d, |__p| unsafe { (*__p).destructor() }); + let _dtor_d = std::mem::DropGuard::new(&raw mut d, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (3))); { let mut o: Outer = ::default(); - let _dtor_o = std::mem::DropGuard::new(&raw mut o, |__p| unsafe { (*__p).destructor() }); + let _dtor_o = std::mem::DropGuard::new(&raw mut o, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (4))); { let mut am: ArrayMember = ::default(); - let _dtor_am = std::mem::DropGuard::new(&raw mut am, |__p| unsafe { (*__p).destructor() }); + let _dtor_am = std::mem::DropGuard::new(&raw mut am, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (7))); { let mut e: EmptyBody = ::default(); - let _dtor_e = std::mem::DropGuard::new(&raw mut e, |__p| unsafe { (*__p).destructor() }); + let _dtor_e = std::mem::DropGuard::new(&raw mut e, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (8))); { let mut tc: Templated_char_ = ::default(); - let _dtor_tc = std::mem::DropGuard::new(&raw mut tc, |__p| unsafe { (*__p).destructor() }); + let _dtor_tc = std::mem::DropGuard::new(&raw mut tc, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut ti: Templated_int_ = ::default(); - let _dtor_ti = std::mem::DropGuard::new(&raw mut ti, |__p| unsafe { (*__p).destructor() }); + let _dtor_ti = std::mem::DropGuard::new(&raw mut ti, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (13))); { let mut a: Copied = Copied { v: 5 }; - let _dtor_a = std::mem::DropGuard::new(&raw mut a, |__p| unsafe { (*__p).destructor() }); + let _dtor_a = std::mem::DropGuard::new(&raw mut a, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut b: Copied = a.clone(); - let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { (*__p).destructor() }); + let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); assert!(((b.v) == (5))); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == (15))); @@ -192,7 +210,9 @@ unsafe fn main_0() -> i32 { dummy2: 0, third: Tagged { tag: 3 }, }; - let _dtor_o = std::mem::DropGuard::new(&raw mut o, |__p| unsafe { (*__p).destructor() }); + let _dtor_o = std::mem::DropGuard::new(&raw mut o, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut order_count_2)) == (3))); assert!((((*std::cell::LazyCell::force_mut(&mut *&raw mut order_1))[(0) as usize]) == (3))); @@ -201,7 +221,9 @@ unsafe fn main_0() -> i32 { let mut before: i32 = (*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)); { let mut cs: S = ::default(); - let _dtor_cs = std::mem::DropGuard::new(&raw mut cs, |__p| unsafe { (*__p).destructor() }); + let _dtor_cs = std::mem::DropGuard::new(&raw mut cs, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut global_0)) == ((before) + (1)))); return 0; diff --git a/tests/unit/out/unsafe/destructor_params.rs b/tests/unit/out/unsafe/destructor_params.rs index cb15112e1e..b2066769fc 100644 --- a/tests/unit/out/unsafe/destructor_params.rs +++ b/tests/unit/out/unsafe/destructor_params.rs @@ -9,7 +9,7 @@ use std::rc::Rc; pub static mut destroyed_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut last_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct S { pub v: i32, } @@ -49,7 +49,9 @@ pub fn main() { unsafe fn main_0() -> i32 { { let mut s: S = S { v: 1 }; - let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { (*__p).destructor() }); + let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); assert!(((unsafe { by_value_2(s.clone(),) }) == (1))); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1)) diff --git a/tests/unit/out/unsafe/destructor_temporaries.rs b/tests/unit/out/unsafe/destructor_temporaries.rs index 171874cf7d..3ddbf3b727 100644 --- a/tests/unit/out/unsafe/destructor_temporaries.rs +++ b/tests/unit/out/unsafe/destructor_temporaries.rs @@ -9,7 +9,7 @@ use std::rc::Rc; pub static mut destroyed_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut last_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct S { pub v: i32, } @@ -23,14 +23,14 @@ impl S { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct Outer { pub inner: S, pub w: i32, } impl Outer { pub unsafe fn destructor(&mut self) { - S::destructor(&mut self.inner); + DestructibleUnsafe::destroy(&raw mut self.inner); } } pub unsafe fn make_2(mut v: i32) -> S { @@ -133,7 +133,9 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) = 0; { let mut s: S = S { v: 12 }; - let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { (*__p).destructor() }); + let _dtor_s = std::mem::DropGuard::new(&raw mut s, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); s = (unsafe { make_2(13) }); assert!( (((*std::cell::LazyCell::force_mut(&mut *&raw mut destroyed_0)) == (1)) diff --git a/tests/unit/out/unsafe/for_body_destructor.rs b/tests/unit/out/unsafe/for_body_destructor.rs index c20ee7e57c..0ab2ec2e2e 100644 --- a/tests/unit/out/unsafe/for_body_destructor.rs +++ b/tests/unit/out/unsafe/for_body_destructor.rs @@ -7,7 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct Guard { pub digit: i32, } @@ -36,11 +36,13 @@ unsafe fn main_0() -> i32 { 'loop_: while ((i) < (2)) { 'for_body: { let mut first: Guard = Guard { digit: 1 }; - let _dtor_first = - std::mem::DropGuard::new(&raw mut first, |__p| unsafe { (*__p).destructor() }); + let _dtor_first = std::mem::DropGuard::new(&raw mut first, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut second: Guard = Guard { digit: 2 }; - let _dtor_second = - std::mem::DropGuard::new(&raw mut second, |__p| unsafe { (*__p).destructor() }); + let _dtor_second = std::mem::DropGuard::new(&raw mut second, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); if ((i) == (0)) { break 'for_body; } @@ -54,8 +56,9 @@ unsafe fn main_0() -> i32 { 'loop_: while ((i) < (2)) { 'for_body: { let mut g: Guard = Guard { digit: 3 }; - let _dtor_g = - std::mem::DropGuard::new(&raw mut g, |__p| unsafe { (*__p).destructor() }); + let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); break 'loop_; } (unsafe { step_0(&mut i) }); @@ -67,8 +70,9 @@ unsafe fn main_0() -> i32 { 'loop_: while ((i) < (1)) { 'for_body: { let mut outer: Guard = Guard { digit: 4 }; - let _dtor_outer = - std::mem::DropGuard::new(&raw mut outer, |__p| unsafe { (*__p).destructor() }); + let _dtor_outer = std::mem::DropGuard::new(&raw mut outer, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); { let mut j: i32 = 0; 'loop_: while ((j) < (2)) { @@ -76,7 +80,7 @@ unsafe fn main_0() -> i32 { let mut inner: Guard = Guard { digit: 5 }; let _dtor_inner = std::mem::DropGuard::new(&raw mut inner, |__p| unsafe { - (*__p).destructor() + DestructibleUnsafe::destroy(__p) }); if ((j) == (0)) { break 'for_body; @@ -97,13 +101,14 @@ unsafe fn main_0() -> i32 { 'loop_: while ((i) < (1)) { 'for_body: { let mut outer: Guard = Guard { digit: 4 }; - let _dtor_outer = - std::mem::DropGuard::new(&raw mut outer, |__p| unsafe { (*__p).destructor() }); + let _dtor_outer = std::mem::DropGuard::new(&raw mut outer, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut j: i32 = 0; 'loop_: while ((*j.prefix_inc()) < (3)) { let mut inner: Guard = Guard { digit: 5 }; let _dtor_inner = std::mem::DropGuard::new(&raw mut inner, |__p| unsafe { - (*__p).destructor() + DestructibleUnsafe::destroy(__p) }); if ((j) == (1)) { continue 'loop_; @@ -115,7 +120,7 @@ unsafe fn main_0() -> i32 { __do_while = false; let mut inner: Guard = Guard { digit: 6 }; let _dtor_inner = std::mem::DropGuard::new(&raw mut inner, |__p| unsafe { - (*__p).destructor() + DestructibleUnsafe::destroy(__p) }); continue 'loop_; } @@ -127,7 +132,7 @@ unsafe fn main_0() -> i32 { let mut value: i32 = (*value); let mut inner: Guard = Guard { digit: value }; let _dtor_inner = std::mem::DropGuard::new(&raw mut inner, |__p| unsafe { - (*__p).destructor() + DestructibleUnsafe::destroy(__p) }); if ((value) == (1)) { continue 'loop_; @@ -144,15 +149,17 @@ unsafe fn main_0() -> i32 { let mut i: i32 = 2; 'loop_: loop { let mut condition: Guard = Guard { digit: i }; - let _dtor_condition = - std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { (*__p).destructor() }); + let _dtor_condition = std::mem::DropGuard::new(&raw mut condition, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); if !(unsafe { Guard::to_bool(&condition) }) { break; } 'for_body: { let mut body: Guard = Guard { digit: 4 }; - let _dtor_body = - std::mem::DropGuard::new(&raw mut body, |__p| unsafe { (*__p).destructor() }); + let _dtor_body = std::mem::DropGuard::new(&raw mut body, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); if ((i) == (2)) { break 'for_body; } @@ -169,13 +176,15 @@ unsafe fn main_0() -> i32 { let mut i: i32 = 0; { let mut init: Guard = Guard { digit: 5 }; - let _dtor_init = - std::mem::DropGuard::new(&raw mut init, |__p| unsafe { (*__p).destructor() }); + let _dtor_init = std::mem::DropGuard::new(&raw mut init, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); 'loop_: while ((i) < (2)) { 'for_body: { let mut body: Guard = Guard { digit: 6 }; - let _dtor_body = - std::mem::DropGuard::new(&raw mut body, |__p| unsafe { (*__p).destructor() }); + let _dtor_body = std::mem::DropGuard::new(&raw mut body, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); } (unsafe { step_0(&mut i) }); } @@ -187,8 +196,9 @@ unsafe fn main_0() -> i32 { let mut g: Guard = Guard { digit: (*j.prefix_inc()), }; - let _dtor_g = - std::mem::DropGuard::new(&raw mut g, |__p| unsafe { (*__p).destructor() }); + let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); continue 'loop_; } } diff --git a/tests/unit/out/unsafe/lambda_as_field.rs b/tests/unit/out/unsafe/lambda_as_field.rs index cf0ec94877..f35fca53fa 100644 --- a/tests/unit/out/unsafe/lambda_as_field.rs +++ b/tests/unit/out/unsafe/lambda_as_field.rs @@ -7,7 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe)] pub struct Guard__lambda_at_lambda_as_field_cpp_34_13__ { pub f: FnPtr, } @@ -28,7 +28,7 @@ impl Default for Guard__lambda_at_lambda_as_field_cpp_34_13__ { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, DestructibleUnsafe, Default)] pub struct Guard__lambda_at_lambda_as_field_cpp_45_13__ { pub f: FnPtr, } @@ -147,7 +147,9 @@ unsafe fn main_0() -> i32 { (*std::cell::LazyCell::force_mut(&mut *&raw mut count_0)).postfix_inc(); }), }; - let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { (*__p).destructor() }); + let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut count_0)) == (0))); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut count_0)) == (1))); @@ -175,7 +177,9 @@ unsafe fn main_0() -> i32 { } ), }; - let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { (*__p).destructor() }); + let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); assert!(((cleaned) == (0))); } assert!(((cleaned) == (1))); diff --git a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs index 8ba53c613c..7e5694fddf 100644 --- a/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs +++ b/tests/unit/out/unsafe/lambda_capture_copy_ctor.rs @@ -47,7 +47,7 @@ impl Default for Counted { } pub static mut drops_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, MoveCtorUnsafe, DestructorUnsafe)] +#[derive(VaArg, FnPtrArg, MoveCtorUnsafe, DestructibleUnsafe)] pub struct Dropped {} impl Dropped { pub unsafe fn new() -> Self { @@ -133,9 +133,13 @@ unsafe fn main_0() -> i32 { }, || {} ); - let _dtor_m = std::mem::DropGuard::new(&raw mut m, |__p| unsafe { (*__p).destroy() }); + let _dtor_m = std::mem::DropGuard::new(&raw mut m, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut m2: FnPtr = m.move_from(); - let _dtor_m2 = std::mem::DropGuard::new(&raw mut m2, |__p| unsafe { (*__p).destroy() }); + let _dtor_m2 = std::mem::DropGuard::new(&raw mut m2, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut drops_0)) == (2))); { @@ -145,9 +149,13 @@ unsafe fn main_0() -> i32 { }, || {} ); - let _dtor_k = std::mem::DropGuard::new(&raw mut k, |__p| unsafe { (*__p).destroy() }); + let _dtor_k = std::mem::DropGuard::new(&raw mut k, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut k2: FnPtr = k.copy_from(); - let _dtor_k2 = std::mem::DropGuard::new(&raw mut k2, |__p| unsafe { (*__p).destroy() }); + let _dtor_k2 = std::mem::DropGuard::new(&raw mut k2, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut drops_0)) == (4))); { @@ -157,16 +165,18 @@ unsafe fn main_0() -> i32 { }, || {} ); - let _dtor_inner = - std::mem::DropGuard::new(&raw mut inner, |__p| unsafe { (*__p).destroy() }); + let _dtor_inner = std::mem::DropGuard::new(&raw mut inner, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut outer: FnPtr = lambda_unsafe!( { let inner: FnPtr = inner.copy_from(); }, || {} ); - let _dtor_outer = - std::mem::DropGuard::new(&raw mut outer, |__p| unsafe { (*__p).destroy() }); + let _dtor_outer = std::mem::DropGuard::new(&raw mut outer, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); } assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut drops_0)) == (6))); return 0; diff --git a/tests/unit/out/unsafe/lambda_move_only_capture.rs b/tests/unit/out/unsafe/lambda_move_only_capture.rs index 3d1915c605..8237c225f4 100644 --- a/tests/unit/out/unsafe/lambda_move_only_capture.rs +++ b/tests/unit/out/unsafe/lambda_move_only_capture.rs @@ -7,7 +7,7 @@ use std::io::{Read, Seek, Write}; use std::os::fd::{AsFd, FromRawFd, IntoRawFd}; use std::rc::Rc; #[repr(C)] -#[derive(FnPtrArg, MoveCtorUnsafe, CppFromUnsafe, DestructorUnsafe, Default)] +#[derive(FnPtrArg, MoveCtorUnsafe, CppFromUnsafe, DestructibleUnsafe, Default)] #[cpp_from(i32, new, value)] pub struct Owner { pub p: *mut i32, @@ -51,7 +51,9 @@ pub fn main() { } unsafe fn main_0() -> i32 { let mut o: Owner = Owner::new({ 5 }); - let _dtor_o = std::mem::DropGuard::new(&raw mut o, |__p| unsafe { (*__p).destructor() }); + let _dtor_o = std::mem::DropGuard::new(&raw mut o, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut f: FnPtr i32> = lambda_unsafe!( { let h: Owner = Owner::move_from({ &mut o }); @@ -60,11 +62,15 @@ unsafe fn main_0() -> i32 { return (*h.p); } ); - let _dtor_f = std::mem::DropGuard::new(&raw mut f, |__p| unsafe { (*__p).destroy() }); + let _dtor_f = std::mem::DropGuard::new(&raw mut f, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); assert!((o.p).is_null()); assert!(((unsafe { f.call() }) == (5))); let mut g: FnPtr i32> = f.move_from(); - let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { (*__p).destroy() }); + let _dtor_g = std::mem::DropGuard::new(&raw mut g, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); assert!(((unsafe { g.call() }) == (5))); let mut total: i32 = 0; let mut consume: FnPtr = lambda_unsafe!( @@ -77,15 +83,20 @@ unsafe fn main_0() -> i32 { (*h.p) = 0; } ); - let _dtor_consume = - std::mem::DropGuard::new(&raw mut consume, |__p| unsafe { (*__p).destroy() }); + let _dtor_consume = std::mem::DropGuard::new(&raw mut consume, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); (unsafe { consume.call() }); (unsafe { consume.call() }); assert!(((total) == (7))); let mut o2: Owner = Owner::new({ 9 }); - let _dtor_o2 = std::mem::DropGuard::new(&raw mut o2, |__p| unsafe { (*__p).destructor() }); + let _dtor_o2 = std::mem::DropGuard::new(&raw mut o2, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut t: FnPtr i32> = (unsafe { Owner::take(&mut o2) }); - let _dtor_t = std::mem::DropGuard::new(&raw mut t, |__p| unsafe { (*__p).destroy() }); + let _dtor_t = std::mem::DropGuard::new(&raw mut t, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); assert!((o2.p).is_null()); assert!(((unsafe { t.call() }) == (9))); return 0; diff --git a/tests/unit/out/unsafe/rule_of_five.rs b/tests/unit/out/unsafe/rule_of_five.rs index 296f86ad4a..10e00c0c94 100644 --- a/tests/unit/out/unsafe/rule_of_five.rs +++ b/tests/unit/out/unsafe/rule_of_five.rs @@ -17,7 +17,7 @@ pub static mut moves_2: std::cell::LazyCell = std::cell::LazyCell::new(|| u CppFromUnsafe, CopyAssignUnsafe, MoveAssignUnsafe, - DestructorUnsafe, + DestructibleUnsafe, Default, )] #[cpp_from(i32, new, value)] @@ -128,7 +128,9 @@ impl Clone for Buffer { } pub unsafe fn make_3(mut size: i32) -> Buffer { let mut b: Buffer = Buffer::new({ size }); - let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { (*__p).destructor() }); + let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); return Buffer::move_from({ &mut b }); } pub fn main() { @@ -140,9 +142,13 @@ pub fn main() { unsafe fn main_0() -> i32 { { let mut a: Buffer = Buffer::new({ 4 }); - let _dtor_a = std::mem::DropGuard::new(&raw mut a, |__p| unsafe { (*__p).destructor() }); + let _dtor_a = std::mem::DropGuard::new(&raw mut a, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut b: Buffer = Buffer::copy_from({ &a }); - let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { (*__p).destructor() }); + let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); assert!( (((*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)) == (2)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (1))) @@ -151,7 +157,9 @@ unsafe fn main_0() -> i32 { b.data[(0) as usize] = 100; assert!(((a.data[(0) as usize]) == (0))); let mut c: Buffer = Buffer::move_from({ &mut a }); - let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { (*__p).destructor() }); + let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)) == (3)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_2)) == (1)) @@ -159,7 +167,9 @@ unsafe fn main_0() -> i32 { assert!(((a.size) == (0)) && ((a.data[(0) as usize]) == (-1_i32))); assert!(((c.size) == (4)) && ((c.data[(3) as usize]) == (3))); let mut d: Buffer = (unsafe { make_3(2) }); - let _dtor_d = std::mem::DropGuard::new(&raw mut d, |__p| unsafe { (*__p).destructor() }); + let _dtor_d = std::mem::DropGuard::new(&raw mut d, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); assert!( ((d.size) == (2)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut moves_2)) == (2)) ); diff --git a/tests/unit/out/unsafe/rule_of_three.rs b/tests/unit/out/unsafe/rule_of_three.rs index 855560681d..b5e5cbd46a 100644 --- a/tests/unit/out/unsafe/rule_of_three.rs +++ b/tests/unit/out/unsafe/rule_of_three.rs @@ -9,7 +9,7 @@ use std::rc::Rc; pub static mut alive_0: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); pub static mut copies_1: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, DestructorUnsafe, Default)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, DestructibleUnsafe, Default)] #[cpp_from(i32, new, value)] pub struct Buffer { pub data: [i32; 4], @@ -99,9 +99,13 @@ pub fn main() { unsafe fn main_0() -> i32 { { let mut a: Buffer = Buffer::new({ 4 }); - let _dtor_a = std::mem::DropGuard::new(&raw mut a, |__p| unsafe { (*__p).destructor() }); + let _dtor_a = std::mem::DropGuard::new(&raw mut a, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut b: Buffer = Buffer::copy_from({ &a }); - let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { (*__p).destructor() }); + let _dtor_b = std::mem::DropGuard::new(&raw mut b, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)) == (2)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (1)) @@ -109,7 +113,9 @@ unsafe fn main_0() -> i32 { b.data[(0) as usize] = 100; assert!(((a.data[(0) as usize]) == (0))); let mut c: Buffer = Buffer::new({ 2 }); - let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { (*__p).destructor() }); + let _dtor_c = std::mem::DropGuard::new(&raw mut c, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); (unsafe { Buffer::copy_assign(&mut c, &a) }); assert!(((c.size) == (4)) && ((c.data[(3) as usize]) == (3))); assert!( @@ -124,7 +130,9 @@ unsafe fn main_0() -> i32 { assert!(((unsafe { sum_2(&a,) }) == (6))); assert!(((unsafe { sum_2(&b,) }) == (106))); let mut d: Buffer = Buffer::copy_from({ &a }); - let _dtor_d = std::mem::DropGuard::new(&raw mut d, |__p| unsafe { (*__p).destructor() }); + let _dtor_d = std::mem::DropGuard::new(&raw mut d, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); assert!( ((*std::cell::LazyCell::force_mut(&mut *&raw mut alive_0)) == (4)) && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_1)) == (3)) diff --git a/tests/unit/out/unsafe/swap_map_no_copy.rs b/tests/unit/out/unsafe/swap_map_no_copy.rs index 11750e8377..fa1c59705b 100644 --- a/tests/unit/out/unsafe/swap_map_no_copy.rs +++ b/tests/unit/out/unsafe/swap_map_no_copy.rs @@ -166,7 +166,7 @@ pub static mut copy_only_copies_1: std::cell::LazyCell = pub static mut copy_only_dtors_2: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); #[repr(C)] -#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, DestructorUnsafe, Default)] +#[derive(VaArg, FnPtrArg, CppFromUnsafe, CopyAssignUnsafe, DestructibleUnsafe, Default)] #[cpp_from(i32, new, value)] pub struct CopyOnly { pub v: i32, @@ -196,7 +196,7 @@ impl Clone for CopyOnly { } } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, CopyAssignUnsafe, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, CopyAssignUnsafe, DestructibleUnsafe, Default)] pub struct CopyOnlyPair { pub x: CopyOnly, pub y: CopyOnly, @@ -216,8 +216,8 @@ impl CopyOnlyPair { } impl CopyOnlyPair { pub unsafe fn destructor(&mut self) { - CopyOnly::destructor(&mut self.y); - CopyOnly::destructor(&mut self.x); + DestructibleUnsafe::destroy(&raw mut self.y); + DestructibleUnsafe::destroy(&raw mut self.x); } } pub static mut moves_3: std::cell::LazyCell = std::cell::LazyCell::new(|| unsafe { 0 }); @@ -231,7 +231,7 @@ pub static mut moved_dtors_5: std::cell::LazyCell = std::cell::LazyCell::ne CppFromUnsafe, CopyAssignUnsafe, MoveAssignUnsafe, - DestructorUnsafe, + DestructibleUnsafe, Default, )] #[cpp_from(i32, new, value)] @@ -282,7 +282,7 @@ impl Clone for Moved { MoveCtorUnsafe, CopyAssignUnsafe, MoveAssignUnsafe, - DestructorUnsafe, + DestructibleUnsafe, Default, )] pub struct MovedPair { @@ -322,8 +322,8 @@ impl MovedPair { } impl MovedPair { pub unsafe fn destructor(&mut self) { - Moved::destructor(&mut self.y); - Moved::destructor(&mut self.x); + DestructibleUnsafe::destroy(&raw mut self.y); + DestructibleUnsafe::destroy(&raw mut self.x); } } pub unsafe fn swapped_once_6() -> bool { @@ -538,9 +538,13 @@ unsafe fn main_0() -> i32 { ); assert!(((*std::cell::LazyCell::force_mut(&mut *&raw mut copies_0)) == (0))); let mut c1: CopyOnly = CopyOnly::new({ 1 }); - let _dtor_c1 = std::mem::DropGuard::new(&raw mut c1, |__p| unsafe { (*__p).destructor() }); + let _dtor_c1 = std::mem::DropGuard::new(&raw mut c1, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut c2: CopyOnly = CopyOnly::new({ 2 }); - let _dtor_c2 = std::mem::DropGuard::new(&raw mut c2, |__p| unsafe { (*__p).destructor() }); + let _dtor_c2 = std::mem::DropGuard::new(&raw mut c2, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); cpp_swap_unsafe!(&mut c1, &mut c2); assert!(((c1.v) == (2)) && ((c2.v) == (1))); assert!( @@ -551,7 +555,9 @@ unsafe fn main_0() -> i32 { x: CopyOnly::new({ 3 }), y: CopyOnly::new({ 4 }), }; - let _dtor_cp = std::mem::DropGuard::new(&raw mut cp, |__p| unsafe { (*__p).destructor() }); + let _dtor_cp = std::mem::DropGuard::new(&raw mut cp, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); cpp_swap_unsafe!(&mut cp.x, &mut cp.y); assert!(((cp.x.v) == (4)) && ((cp.y.v) == (3))); assert!( @@ -566,9 +572,13 @@ unsafe fn main_0() -> i32 { && ((*std::cell::LazyCell::force_mut(&mut *&raw mut copy_only_dtors_2)) == (3)) ); let mut mv1: Moved = Moved::new({ 1 }); - let _dtor_mv1 = std::mem::DropGuard::new(&raw mut mv1, |__p| unsafe { (*__p).destructor() }); + let _dtor_mv1 = std::mem::DropGuard::new(&raw mut mv1, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut mv2: Moved = Moved::new({ 2 }); - let _dtor_mv2 = std::mem::DropGuard::new(&raw mut mv2, |__p| unsafe { (*__p).destructor() }); + let _dtor_mv2 = std::mem::DropGuard::new(&raw mut mv2, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); cpp_swap_unsafe!(&mut mv1, &mut mv2); assert!(((mv1.v) == (2)) && ((mv2.v) == (1))); assert!((unsafe { swapped_once_6() })); @@ -576,7 +586,9 @@ unsafe fn main_0() -> i32 { x: Moved::new({ 3 }), y: Moved::new({ 4 }), }; - let _dtor_mp = std::mem::DropGuard::new(&raw mut mp, |__p| unsafe { (*__p).destructor() }); + let _dtor_mp = std::mem::DropGuard::new(&raw mut mp, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); cpp_swap_unsafe!(&mut mp.x, &mut mp.y); assert!(((mp.x.v) == (4)) && ((mp.y.v) == (3))); assert!((unsafe { swapped_once_6() })); diff --git a/tests/unit/out/unsafe/va_list_field.rs b/tests/unit/out/unsafe/va_list_field.rs index 823d387731..b0e7c35fe0 100644 --- a/tests/unit/out/unsafe/va_list_field.rs +++ b/tests/unit/out/unsafe/va_list_field.rs @@ -10,8 +10,9 @@ pub unsafe fn sum_0(mut n: i32, __args: Box<[VaArg]>) -> i32 { let mut ap: *const VaArg = ::std::ptr::null(); ap = __args.as_ptr(); let mut guard: Guard_1 = Guard_1::new({ &mut ap }); - let _dtor_guard = - std::mem::DropGuard::new(&raw mut guard, |__p| unsafe { (*__p).destructor() }); + let _dtor_guard = std::mem::DropGuard::new(&raw mut guard, |__p| unsafe { + DestructibleUnsafe::destroy(__p) + }); let mut total: i32 = 0; { let mut i: i32 = 0; @@ -25,7 +26,7 @@ pub unsafe fn sum_0(mut n: i32, __args: Box<[VaArg]>) -> i32 { return total; } #[repr(C)] -#[derive(Clone, VaArg, FnPtrArg, CppFromUnsafe, DestructorUnsafe, Default)] +#[derive(Clone, VaArg, FnPtrArg, CppFromUnsafe, DestructibleUnsafe, Default)] #[cpp_from(*const VaArg , new, mut_ptr)] pub struct Guard_1 { pub ap: *mut *const VaArg, From df5061568fee47b980c3bb8e461368a73a9abd5d Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sun, 29 Nov 2026 21:16:41 +0000 Subject: [PATCH 3/4] Add Destructible for refcount array --- cpp2rust/converter/models/converter_refcount.cpp | 13 ++----------- libcc2rs/src/capture.rs | 9 +++++++++ tests/unit/out/refcount/destructor.rs | 7 +------ 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/cpp2rust/converter/models/converter_refcount.cpp b/cpp2rust/converter/models/converter_refcount.cpp index 36c89e13f5..3aa1326ebc 100644 --- a/cpp2rust/converter/models/converter_refcount.cpp +++ b/cpp2rust/converter/models/converter_refcount.cpp @@ -3637,17 +3637,8 @@ std::string ConverterRefCount::DestroyMembers(const clang::CXXRecordDecl *decl) { std::string out; for (auto *field : FieldsToDestroy(decl)) { - auto name = GetNamedDeclAsString(field); - if (field->getType()->isArrayType()) { - out += std::format( - "{{ let __p = array_field_ptr!(self, {}); for __i in " - "(0..__p.len()).rev() {{ Destructible::destroy(__p.offset(__i as " - "isize)); }} }}\n", - name); - } else { - out += std::format("Destructible::destroy(field_ptr!(self, {}));\n", - name); - } + out += std::format("Destructible::destroy(field_ptr!(self, {}));\n", + GetNamedDeclAsString(field)); } return out; } diff --git a/libcc2rs/src/capture.rs b/libcc2rs/src/capture.rs index 8b9891daa3..e0eca957fd 100644 --- a/libcc2rs/src/capture.rs +++ b/libcc2rs/src/capture.rs @@ -160,6 +160,15 @@ impl DestructibleUnsafe for FnPtr { } } +impl Destructible for Box<[T]> { + fn destroy(p: Ptr) { + let elems = p.decay(); + for i in (0..elems.len()).rev() { + T::destroy(elems.offset(i)); + } + } +} + impl DestructibleUnsafe for [T; N] { unsafe fn destroy(p: *mut Self) { let p = p as *mut T; diff --git a/tests/unit/out/refcount/destructor.rs b/tests/unit/out/refcount/destructor.rs index 1aab63b9ee..b200bb8276 100644 --- a/tests/unit/out/refcount/destructor.rs +++ b/tests/unit/out/refcount/destructor.rs @@ -208,12 +208,7 @@ pub trait ArrayMemberImpl { } impl ArrayMemberImpl for Ptr { fn destructor(&self) { - { - let __p = array_field_ptr!(self, items); - for __i in (0..__p.len()).rev() { - Destructible::destroy(__p.offset(__i as isize)); - } - } + Destructible::destroy(field_ptr!(self, items)); } } pub trait CopiedImpl { From 83c40d9edb94f4f06b7c6482ede91516b0179b07 Mon Sep 17 00:00:00 2001 From: Lucian Popescu Date: Sun, 29 Nov 2026 21:23:08 +0000 Subject: [PATCH 4/4] Format --- cpp2rust/converter/converter.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cpp2rust/converter/converter.cpp b/cpp2rust/converter/converter.cpp index cdcab90596..fb017e4c97 100644 --- a/cpp2rust/converter/converter.cpp +++ b/cpp2rust/converter/converter.cpp @@ -1024,8 +1024,8 @@ std::string Converter::DestroyMembers(const clang::CXXRecordDecl *decl) { std::string out; for (auto *field : FieldsToDestroy(decl)) { auto name = GetNamedDeclAsString(field); - out += std::format("DestructibleUnsafe::destroy(&raw mut self.{});\n", - name); + out += + std::format("DestructibleUnsafe::destroy(&raw mut self.{});\n", name); } return out; }