diff --git a/gc/src/lib.rs b/gc/src/lib.rs index b38e4ba..957d12f 100644 --- a/gc/src/lib.rs +++ b/gc/src/lib.rs @@ -141,12 +141,12 @@ impl Gc { #[inline] fn inner_ptr(&self) -> *mut GcBox { // If we are currently in the dropping phase of garbage collection, - // it would be undefined behavior to dereference this pointer. + // it would be undefined behavior to dereference an unrooted Gc. // By opting into `Trace` you agree to not dereference this pointer // within your drop method, meaning that it should be safe. // // This assert exists just in case. - assert!(finalizer_safe()); + assert!(finalizer_safe() || self.rooted()); unsafe { clear_root_bit(self.ptr_root.get()).as_ptr() } } diff --git a/gc/tests/ignore_trace.rs b/gc/tests/ignore_trace.rs new file mode 100644 index 0000000..5fe0e69 --- /dev/null +++ b/gc/tests/ignore_trace.rs @@ -0,0 +1,12 @@ +use gc::{force_collect, Finalize, Gc, Trace}; + +#[derive(Finalize, Trace)] +struct S(#[unsafe_ignore_trace] Gc<()>); + +/// Using `#[unsafe_ignore_trace]` on a `Gc` may inhibit collection of +/// cycles through that `Gc`, but it should not result in panics. +#[test] +fn ignore_trace_gc() { + Gc::new(S(Gc::new(()))); + force_collect(); +}