diff --git a/gc/src/trace.rs b/gc/src/trace.rs index 6780ae7..ce02f1d 100644 --- a/gc/src/trace.rs +++ b/gc/src/trace.rs @@ -5,6 +5,7 @@ use std::num::{ NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize, }; use std::path::{Path, PathBuf}; +use std::rc::Rc; use std::sync::atomic::{ AtomicBool, AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicIsize, AtomicU16, AtomicU32, AtomicU64, AtomicU8, AtomicUsize, @@ -141,6 +142,7 @@ simple_empty_finalize_trace![ char, String, Box, + Rc, Path, PathBuf, NonZeroIsize, @@ -256,6 +258,13 @@ type_arg_tuple_based_finalized_trace_impls![ (A, B, C, D, E, F, G, H, I, J, K, L); ]; +impl Finalize for Rc {} +unsafe impl Trace for Rc { + custom_trace!(this, { + mark(&**this); + }); +} + impl Finalize for Box {} unsafe impl Trace for Box { custom_trace!(this, { diff --git a/gc/tests/trace_impl.rs b/gc/tests/trace_impl.rs index 1040f48..da492bd 100644 --- a/gc/tests/trace_impl.rs +++ b/gc/tests/trace_impl.rs @@ -2,6 +2,7 @@ use gc_derive::{Finalize, Trace}; use std::cell::RefCell; +use std::rc::Rc; thread_local!(static X: RefCell = RefCell::new(0)); @@ -37,6 +38,21 @@ struct InnerBoxStr { inner: Box, } +#[derive(Trace, Clone, Finalize)] +struct InnerRcSlice { + inner: Box<[u32]>, +} + +#[derive(Trace, Clone, Finalize)] +struct InnerRcStr { + inner: Rc, +} + +#[derive(Trace, Clone, Finalize)] +struct InnerRcStruct { + inner: Rc, +} + #[derive(Trace, Finalize)] struct Baz { a: Bar,