Skip to content

Commit

Permalink
refactor: remove TriviallyDrop trait
Browse files Browse the repository at this point in the history
Signed-off-by: Yaroslav Bolyukin <[email protected]>
  • Loading branch information
CertainLach committed Jan 3, 2021
1 parent aa4e896 commit 456c8e9
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 17 deletions.
2 changes: 1 addition & 1 deletion gc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub use gc_derive::{Finalize, Trace};
// We re-export the Trace method, as well as some useful internal methods for
// managing collections or configuring the garbage collector.
pub use crate::gc::{finalizer_safe, force_collect};
pub use crate::trace::{Finalize, Trace, TriviallyDrop};
pub use crate::trace::{Finalize, Trace};

////////
// Gc //
Expand Down
6 changes: 0 additions & 6 deletions gc/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,6 @@ pub trait Finalize {
fn finalize(&self) {}
}

/// Ensures type has no custom Drop implementation, without implementing it itself
/// In case of Drop implementation present, obscure compilation error will be raised
pub unsafe trait TriviallyDrop {
unsafe fn guard(self);
}

#[cfg(feature = "nightly")]
impl<T: ?Sized> Finalize for T {
// XXX: Should this function somehow tell its caller (which is presumably
Expand Down
14 changes: 4 additions & 10 deletions gc_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,25 +76,19 @@ fn derive_trace(mut s: Structure<'_>) -> proc_macro2::TokenStream {
#drop_impl
}
} else {
let finalize_impl = derive_finalize(s.clone());

s.bind_with(|_| BindStyle::Move);
let trivially_drop_body = s.each(|bi| quote!(drop(#bi)));

let trivially_drop_impl = s.unsafe_bound_impl(
quote!(::gc::TriviallyDrop),
let finalize_impl = s.unsafe_bound_impl(
quote!(::gc::Finalize),
quote!(
unsafe fn guard(self) {
match self {
#trivially_drop_body
}
fn finalize(self) {
const _TRIVVIALLY_DROP: fn(Self) = |t| match t { #trivially_drop_body }
}
),
);

quote! {
#trace_impl
#trivially_drop_impl
#finalize_impl
}
}
Expand Down

0 comments on commit 456c8e9

Please sign in to comment.