@@ -449,11 +449,38 @@ pub fn unsafe_gc_impl(input: proc_macro::TokenStream) -> proc_macro::TokenStream
449
449
res. into ( )
450
450
}
451
451
452
+ #[ proc_macro_derive( NullTrace , attributes( zerogc) ) ]
453
+ pub fn derive_null_trace ( input : proc_macro:: TokenStream ) -> proc_macro:: TokenStream {
454
+ let input = parse_macro_input ! ( input as DeriveInput ) ;
455
+ let mut info = match GcTypeInfo :: parse ( & input) {
456
+ Ok ( info) => info,
457
+ Err ( e) => return e. to_compile_error ( ) . into ( )
458
+ } ;
459
+ if info. config . nop_trace {
460
+ return quote_spanned ! { input. ident. span( ) =>
461
+ compile_error!( "derive(NullTrace): Can't explicitly specify #[zerogc(nop_trace)] as it's already implied" )
462
+ } . into ( ) ;
463
+ }
464
+ info. config . nop_trace = true ;
465
+ let res = From :: from ( impl_derive_trace ( & input, & info)
466
+ . unwrap_or_else ( |e| e. to_compile_error ( ) ) ) ;
467
+ debug_derive (
468
+ "derive(NullTrace)" ,
469
+ & input. ident . to_string ( ) ,
470
+ & format_args ! ( "#[derive(NullTrace) for {}" , input. ident) ,
471
+ & res
472
+ ) ;
473
+ res
474
+ }
452
475
453
476
#[ proc_macro_derive( Trace , attributes( zerogc) ) ]
454
477
pub fn derive_trace ( input : proc_macro:: TokenStream ) -> proc_macro:: TokenStream {
455
478
let input = parse_macro_input ! ( input as DeriveInput ) ;
456
- let res = From :: from ( impl_derive_trace ( & input)
479
+ let info = match GcTypeInfo :: parse ( & input) {
480
+ Ok ( info) => info,
481
+ Err ( e) => return e. to_compile_error ( ) . into ( )
482
+ } ;
483
+ let res = From :: from ( impl_derive_trace ( & input, & info)
457
484
. unwrap_or_else ( |e| e. to_compile_error ( ) ) ) ;
458
485
debug_derive (
459
486
"derive(Trace)" ,
@@ -464,8 +491,7 @@ pub fn derive_trace(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
464
491
res
465
492
}
466
493
467
- fn impl_derive_trace ( input : & DeriveInput ) -> Result < TokenStream , syn:: Error > {
468
- let info = GcTypeInfo :: parse ( input) ?;
494
+ fn impl_derive_trace ( input : & DeriveInput , info : & GcTypeInfo ) -> Result < TokenStream , syn:: Error > {
469
495
let trace_impl = if info. config . nop_trace {
470
496
impl_nop_trace ( & input, & info) ?
471
497
} else {
0 commit comments