kyren / gc-arena

Incremental garbage collection from safe Rust
Creative Commons Zero v1.0 Universal
438 stars 36 forks source link

Allow using `#[collect(require_static)]` on fields #6

Closed Aaron1011 closed 3 years ago

Aaron1011 commented 3 years ago

Currently, #[collect(require_static)] can be used on an entire struct/enum. This commit allows #[collect(require_static)] to be applied to individual fields or field bindings of a struct/enum.

When applied, we generate a where-clause bound ensuring that the type of the field binding outlives 'static. This allows us to ignore the field in needs_trace and trace.

As a result, it's now possible to use #[derive(Collect)] on a struct/enum containing foreign types, as long as those foreign types are 'static.

Aaron1011 commented 3 years ago

Based on https://github.com/kyren/gc-arena/pull/5

kyren commented 3 years ago

Sorry for leaving these PRs for so long, this is a great idea, thank you!