Skip to content

Commit

Permalink
Make non-Trace types work with unsafe_skip_trace
Browse files Browse the repository at this point in the history
  • Loading branch information
Techcable committed Sep 3, 2021
1 parent d63b971 commit dcfdd14
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
6 changes: 5 additions & 1 deletion libs/derive/src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,11 @@ impl TraceDeriveInput {
let traced_field_types = self.determine_field_types(false);
let all_field_types = self.determine_field_types(true);
let needs_trace = traced_field_types.iter().map(|ty| quote_spanned!(ty.span() => <#ty as zerogc::Trace>::NEEDS_TRACE));
let needs_drop = all_field_types.iter().map(|ty| quote_spanned!(ty.span() => <#ty as zerogc::Trace>::NEEDS_DROP));
let needs_drop = all_field_types.iter().map(|ty| if traced_field_types.contains(ty) {
quote_spanned!(ty.span() => <#ty as zerogc::Trace>::NEEDS_DROP)
} else {
quote_spanned!(ty.span() => core::mem::needs_drop::<#ty>())
});
let assoc_constants = if !immutable {
Some(quote! {
const NEEDS_TRACE: bool = #(#needs_trace || )* false /* NOTE: Default to *false* if we have no GC types inside */;
Expand Down
8 changes: 7 additions & 1 deletion libs/derive/tests/basic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,15 @@ struct UnsafeSkipped<'gc> {
s: &'static str,
i: i32,
#[zerogc(unsafe_skip_trace)]
wow: Gc<'gc, i32, EpsilonCollectorId>
wow: Gc<'gc, i32, EpsilonCollectorId>,
#[zerogc(unsafe_skip_trace)]
not_impld: NotImplTrace
}


/// A type that doesn't implement `Trace`
struct NotImplTrace;

#[derive(Trace)]
#[zerogc(ignore_lifetimes("'a"), immutable, collector_ids(EpsilonCollectorId))]
#[allow(unused)]
Expand Down

0 comments on commit dcfdd14

Please sign in to comment.