Skip to content

Commit dcfdd14

Browse files
committed
Make non-Trace types work with unsafe_skip_trace
1 parent d63b971 commit dcfdd14

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

libs/derive/src/derive.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,11 @@ impl TraceDeriveInput {
753753
let traced_field_types = self.determine_field_types(false);
754754
let all_field_types = self.determine_field_types(true);
755755
let needs_trace = traced_field_types.iter().map(|ty| quote_spanned!(ty.span() => <#ty as zerogc::Trace>::NEEDS_TRACE));
756-
let needs_drop = all_field_types.iter().map(|ty| quote_spanned!(ty.span() => <#ty as zerogc::Trace>::NEEDS_DROP));
756+
let needs_drop = all_field_types.iter().map(|ty| if traced_field_types.contains(ty) {
757+
quote_spanned!(ty.span() => <#ty as zerogc::Trace>::NEEDS_DROP)
758+
} else {
759+
quote_spanned!(ty.span() => core::mem::needs_drop::<#ty>())
760+
});
757761
let assoc_constants = if !immutable {
758762
Some(quote! {
759763
const NEEDS_TRACE: bool = #(#needs_trace || )* false /* NOTE: Default to *false* if we have no GC types inside */;

libs/derive/tests/basic.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,15 @@ struct UnsafeSkipped<'gc> {
9999
s: &'static str,
100100
i: i32,
101101
#[zerogc(unsafe_skip_trace)]
102-
wow: Gc<'gc, i32, EpsilonCollectorId>
102+
wow: Gc<'gc, i32, EpsilonCollectorId>,
103+
#[zerogc(unsafe_skip_trace)]
104+
not_impld: NotImplTrace
103105
}
104106

107+
108+
/// A type that doesn't implement `Trace`
109+
struct NotImplTrace;
110+
105111
#[derive(Trace)]
106112
#[zerogc(ignore_lifetimes("'a"), immutable, collector_ids(EpsilonCollectorId))]
107113
#[allow(unused)]

0 commit comments

Comments
 (0)