@@ -139,7 +139,10 @@ struct TypeAttrs {
139
139
gc_lifetime : Option < Lifetime > ,
140
140
collector_id : Option < Ident > ,
141
141
ignore_params : HashSet < Ident > ,
142
- ignored_lifetimes : HashSet < Lifetime >
142
+ ignored_lifetimes : HashSet < Lifetime > ,
143
+ /// Unsafely assume the type is safe to [drop]
144
+ /// from a GC, as consistent with the requirements of [GcSafe]
145
+ unsafe_drop_safe : bool
143
146
}
144
147
impl TypeAttrs {
145
148
fn gc_lifetime ( & self ) -> Lifetime {
@@ -205,6 +208,20 @@ impl Parse for TypeAttrs {
205
208
) )
206
209
}
207
210
result. is_copy = true ;
211
+ } else if meta. path ( ) . is_ident ( "unsafe_drop_safe" ) {
212
+ if !matches ! ( meta, Meta :: Path ( _) ) {
213
+ return Err ( Error :: new (
214
+ meta. span ( ) ,
215
+ "Malformed attribute for #[zerogc(unsafe_drop_safe)]"
216
+ ) )
217
+ }
218
+ if result. unsafe_drop_safe {
219
+ return Err ( Error :: new (
220
+ meta. span ( ) ,
221
+ "Duplicate flags: #[zerogc(unsafe_drop_safe)]"
222
+ ) )
223
+ }
224
+ result. unsafe_drop_safe = true ;
208
225
} else if meta. path ( ) . is_ident ( "nop_trace" ) {
209
226
if !matches ! ( meta, Meta :: Path ( _) ) {
210
227
return Err ( Error :: new (
@@ -973,7 +990,7 @@ fn impl_gc_safe(target: &DeriveInput, info: &GcTypeInfo) -> Result<TokenStream,
973
990
* in the first place.
974
991
*/
975
992
quote ! ( )
976
- } else {
993
+ } else if !info . config . unsafe_drop_safe {
977
994
quote ! ( impl #impl_generics Drop for #name #ty_generics #where_clause {
978
995
#[ inline]
979
996
fn drop( & mut self ) {
0 commit comments