Skip to content

Commit fe4fea0

Browse files
committed
refactor: remove TriviallyDrop trait
Signed-off-by: Yaroslav Bolyukin <iam@lach.pw>
1 parent aa4e896 commit fe4fea0

File tree

3 files changed

+6
-18
lines changed

3 files changed

+6
-18
lines changed

gc/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub use gc_derive::{Finalize, Trace};
3535
// We re-export the Trace method, as well as some useful internal methods for
3636
// managing collections or configuring the garbage collector.
3737
pub use crate::gc::{finalizer_safe, force_collect};
38-
pub use crate::trace::{Finalize, Trace, TriviallyDrop};
38+
pub use crate::trace::{Finalize, Trace};
3939

4040
////////
4141
// Gc //

gc/src/trace.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,6 @@ pub trait Finalize {
1717
fn finalize(&self) {}
1818
}
1919

20-
/// Ensures type has no custom Drop implementation, without implementing it itself
21-
/// In case of Drop implementation present, obscure compilation error will be raised
22-
pub unsafe trait TriviallyDrop {
23-
unsafe fn guard(self);
24-
}
25-
2620
#[cfg(feature = "nightly")]
2721
impl<T: ?Sized> Finalize for T {
2822
// XXX: Should this function somehow tell its caller (which is presumably

gc_derive/src/lib.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,25 +76,19 @@ fn derive_trace(mut s: Structure<'_>) -> proc_macro2::TokenStream {
7676
#drop_impl
7777
}
7878
} else {
79-
let finalize_impl = derive_finalize(s.clone());
80-
8179
s.bind_with(|_| BindStyle::Move);
82-
let trivially_drop_body = s.each(|bi| quote!(drop(#bi)));
83-
84-
let trivially_drop_impl = s.unsafe_bound_impl(
85-
quote!(::gc::TriviallyDrop),
80+
let trivially_drop_body = s.each(|_| quote! {});
81+
let finalize_impl = s.bound_impl(
82+
quote!(::gc::Finalize),
8683
quote!(
87-
unsafe fn guard(self) {
88-
match self {
89-
#trivially_drop_body
90-
}
84+
fn finalize(&self) {
85+
let _trivially_drop = |t: Self| match t { #trivially_drop_body };
9186
}
9287
),
9388
);
9489

9590
quote! {
9691
#trace_impl
97-
#trivially_drop_impl
9892
#finalize_impl
9993
}
10094
}

0 commit comments

Comments
 (0)