7
7
use core:: num:: Wrapping ;
8
8
9
9
use crate :: prelude:: * ;
10
- use crate :: { GcDirectBarrier , CollectorId } ;
10
+ use crate :: GcDirectBarrier ;
11
11
12
12
use zerogc_derive:: unsafe_gc_impl;
13
13
14
- macro_rules! __rec_trace_tuple {
15
- ( $ ( $param : ident) , * ) => {
16
- // Nothing remaining
14
+ macro_rules! trace_tuple {
15
+ { $single_param : ident } => {
16
+ trace_tuple_impl! ( $single_param ) ;
17
17
} ;
18
- ( $first_param: ident, $( $param: ident) ,+) => {
19
- trace_tuple!( $( $param) ,* ) ;
18
+ { $first_param: ident, $( $param: ident) ,* } => {
19
+ trace_tuple! { $( $param) ,* }
20
+ trace_tuple_impl!( $first_param, $( $param) ,* ) ;
20
21
} ;
21
22
}
22
- macro_rules! trace_tuple {
23
- { $ ( $param : ident ) , * } => {
24
- __rec_trace_tuple! ( $( $param) ,* ) ;
23
+
24
+ macro_rules! trace_tuple_impl {
25
+ { $( $param: ident ) ,* } => {
25
26
unsafe_gc_impl! {
26
27
target => ( $( $param, ) * ) ,
27
28
params => [ $( $param) ,* ] ,
29
+ bounds => {
30
+ GcRebrand => { where $( $param: GcRebrand <' new_gc, Id >) ,* } ,
31
+ GcErase => { where $( $param: GcErase <' min, Id >) ,* } ,
32
+ }
28
33
null_trace => { where $( $param: NullTrace , ) * i32 : Sized } ,
29
34
/*
30
35
* HACK: Macros don't allow using `||` as separator,
@@ -276,4 +281,30 @@ unsafe_gc_impl! {
276
281
// We can trace `Wrapping` by simply tracing its interior
277
282
visitor. #visit_func( #b self . 0 )
278
283
}
284
+ }
285
+
286
+ #[ cfg( test) ]
287
+ mod test {
288
+ use crate :: dummy_impl:: Gc ;
289
+ use zerogc_derive:: Trace ;
290
+ use crate :: prelude:: * ;
291
+ #[ test]
292
+ fn test_null_trace ( ) {
293
+ assert ! ( !<Option <i32 > as Trace >:: NEEDS_TRACE ) ;
294
+ assert ! ( !<Option <( i32 , char ) > as Trace >:: NEEDS_TRACE )
295
+ }
296
+ #[ derive( Trace ) ]
297
+ struct Rec < ' gc > {
298
+ inner : Gc < ' gc , Rec < ' gc > > ,
299
+ inner_tuple : ( Gc < ' gc , Rec < ' gc > > , Gc < ' gc , Option < i32 > > ) ,
300
+ inner_opt : Option < Gc < ' gc , Rec < ' gc > > > ,
301
+ inner_opt_tuple : Option < ( Gc < ' gc , Rec < ' gc > > , Gc < ' gc , char > ) > ,
302
+ }
303
+ #[ test]
304
+ fn test_trace < ' gc > ( ) {
305
+ assert ! ( <Option <Gc <' gc, i32 >> as Trace >:: NEEDS_TRACE ) ;
306
+ assert ! ( <Option <( Gc <' gc, i32 >, char ) > as Trace >:: NEEDS_TRACE ) ;
307
+ assert ! ( <Rec <' gc> as Trace >:: NEEDS_TRACE ) ;
308
+ assert ! ( <Gc <' gc, Rec <' gc>> as Trace >:: NEEDS_TRACE ) ;
309
+ }
279
310
}
0 commit comments