@@ -33,8 +33,6 @@ macro_rules! stmt { ($stmt:stmt) => { stringify!($stmt) }; }
33
33
macro_rules! ty { ( $ty: ty) => { stringify!( $ty) } ; }
34
34
macro_rules! vis { ( $vis: vis) => { stringify!( $vis) } ; }
35
35
36
- // Use this when AST pretty-printing and TokenStream pretty-printing give
37
- // the same result (which is preferable.)
38
36
macro_rules! c1 {
39
37
( $frag: ident, [ $( $tt: tt) * ] , $s: literal) => {
40
38
// Prior to #125174:
@@ -53,6 +51,14 @@ macro_rules! c1 {
53
51
} ;
54
52
}
55
53
54
+ // FIXME: temporary
55
+ macro_rules! c2 {
56
+ ( $frag: ident, [ $( $tt: tt) * ] , $s1: literal, $s2: literal) => {
57
+ assert_eq!( $frag!( $( $tt) * ) , $s1) ;
58
+ assert_eq!( stringify!( $( $tt) * ) , $s2) ;
59
+ } ;
60
+ }
61
+
56
62
#[ test]
57
63
fn test_block ( ) {
58
64
c1 ! ( block, [ { } ] , "{}" ) ;
@@ -66,6 +72,8 @@ fn test_block() {
66
72
} ] ,
67
73
"{ let _; true }"
68
74
) ;
75
+
76
+ // Attributes are not allowed on vanilla blocks.
69
77
}
70
78
71
79
#[ test]
@@ -332,6 +340,20 @@ fn test_expr() {
332
340
// ExprKind::FormatArgs: untestable because this test works pre-expansion.
333
341
334
342
// ExprKind::Err: untestable.
343
+
344
+ // Ones involving attributes.
345
+ c1 ! ( expr, [ #[ aa] 1 ] , "#[aa] 1" ) ;
346
+ c1 ! ( expr, [ #[ aa] #[ bb] x ] , "#[aa] #[bb] x" ) ;
347
+ c2 ! ( expr, [ #[ aa] 1 + 2 ] , "1 + 2" , "#[aa] 1 + 2" ) ; // FIXME
348
+ c2 ! ( expr, [ #[ aa] x + 2 ] , "x + 2" , "#[aa] x + 2" ) ; // FIXME
349
+ c2 ! ( expr, [ #[ aa] 1 / #[ bb] 2 ] , "1 / #[bb] 2" , "#[aa] 1 / #[bb] 2" ) ; // FIXME
350
+ c2 ! ( expr, [ #[ aa] x / #[ bb] 2 ] , "x / #[bb] 2" , "#[aa] x / #[bb] 2" ) ; // FIXME
351
+ c1 ! ( expr, [ 1 << #[ bb] 2 ] , "1 << #[bb] 2" ) ;
352
+ c1 ! ( expr, [ x << #[ bb] 2 ] , "x << #[bb] 2" ) ;
353
+ c1 ! ( expr, [ #[ aa] ( 1 + 2 ) ] , "#[aa] (1 + 2)" ) ;
354
+ c1 ! ( expr, [ #[ aa] #[ bb] ( x + 2 ) ] , "#[aa] #[bb] (x + 2)" ) ;
355
+ c1 ! ( expr, [ #[ aa] x[ 0 ] . p ] , "#[aa] x[0].p" ) ;
356
+ c1 ! ( expr, [ #[ aa] { #![ bb] 0 } ] , "#[aa] { #![bb] 0 }" ) ;
335
357
}
336
358
337
359
#[ test]
@@ -484,6 +506,11 @@ fn test_item() {
484
506
"macro_rules! stringify { () => {}; }"
485
507
) ;
486
508
c1 ! ( item, [ pub macro stringify( ) { } ] , "pub macro stringify() {}" ) ;
509
+
510
+ // Ones involving attributes.
511
+ c1 ! ( item, [ #[ aa] mod m; ] , "#[aa] mod m;" ) ;
512
+ c1 ! ( item, [ mod m { #![ bb] } ] , "mod m { #![bb] }" ) ;
513
+ c1 ! ( item, [ #[ aa] mod m { #![ bb] } ] , "#[aa] mod m { #![bb] }" ) ;
487
514
}
488
515
489
516
#[ test]
@@ -492,6 +519,8 @@ fn test_meta() {
492
519
c1 ! ( meta, [ k = "v" ] , "k = \" v\" " ) ;
493
520
c1 ! ( meta, [ list( k1, k2 = "v" ) ] , "list(k1, k2 = \" v\" )" ) ;
494
521
c1 ! ( meta, [ serde:: k ] , "serde::k" ) ;
522
+
523
+ // Attributes are not allowed on metas.
495
524
}
496
525
497
526
#[ test]
@@ -580,6 +609,8 @@ fn test_pat() {
580
609
c1 ! ( pat, [ mac!( ...) ] , "mac!(...)" ) ;
581
610
c1 ! ( pat, [ mac![ ...] ] , "mac![...]" ) ;
582
611
c1 ! ( pat, [ mac! { ... } ] , "mac! { ... }" ) ;
612
+
613
+ // Attributes are not allowed on patterns.
583
614
}
584
615
585
616
#[ test]
@@ -593,6 +624,8 @@ fn test_path() {
593
624
c1 ! ( path, [ Self :: <' static > ] , "Self::<'static>" ) ;
594
625
c1 ! ( path, [ Self ( ) ] , "Self()" ) ;
595
626
c1 ! ( path, [ Self ( ) -> ( ) ] , "Self() -> ()" ) ;
627
+
628
+ // Attributes are not allowed on paths.
596
629
}
597
630
598
631
#[ test]
@@ -622,6 +655,20 @@ fn test_stmt() {
622
655
c1 ! ( stmt, [ mac!( ...) ] , "mac!(...)" ) ;
623
656
c1 ! ( stmt, [ mac![ ...] ] , "mac![...]" ) ;
624
657
c1 ! ( stmt, [ mac! { ... } ] , "mac! { ... }" ) ;
658
+
659
+ // Ones involving attributes.
660
+ c1 ! ( stmt, [ #[ aa] 1 ] , "#[aa] 1" ) ;
661
+ c1 ! ( stmt, [ #[ aa] #[ bb] x ] , "#[aa] #[bb] x" ) ;
662
+ c2 ! ( stmt, [ #[ aa] 1 as u32 ] , "1 as u32" , "#[aa] 1 as u32" ) ; // FIXME
663
+ c2 ! ( stmt, [ #[ aa] x as u32 ] , "x as u32" , "#[aa] x as u32" ) ; // FIXME
664
+ c2 ! ( stmt, [ #[ aa] 1 .. #[ bb] 2 ] , "1 .. #[bb] 2" , "#[aa] 1 .. #[bb] 2" ) ; // FIXME
665
+ c2 ! ( stmt, [ #[ aa] x .. #[ bb] 2 ] , "x .. #[bb] 2" , "#[aa] x .. #[bb] 2" ) ; // FIXME
666
+ c1 ! ( stmt, [ 1 || #[ bb] 2 ] , "1 || #[bb] 2" ) ;
667
+ c1 ! ( stmt, [ x || #[ bb] 2 ] , "x || #[bb] 2" ) ;
668
+ c1 ! ( stmt, [ #[ aa] ( 1 + 2 ) ] , "#[aa] (1 + 2)" ) ;
669
+ c1 ! ( stmt, [ #[ aa] #[ bb] ( x + 2 ) ] , "#[aa] #[bb] (x + 2)" ) ;
670
+ c1 ! ( stmt, [ #[ aa] x[ 0 ] . p ] , "#[aa] x[0].p" ) ;
671
+ c1 ! ( stmt, [ #[ aa] { #![ bb] 0 } ] , "#[aa] { #![bb] 0 }" ) ;
625
672
}
626
673
627
674
#[ test]
@@ -708,6 +755,8 @@ fn test_ty() {
708
755
709
756
// TyKind::CVarArgs
710
757
// FIXME: todo
758
+
759
+ // Attributes are not allowed on types.
711
760
}
712
761
713
762
#[ test]
@@ -732,6 +781,8 @@ fn test_vis() {
732
781
macro_rules! inherited_vis { ( $vis: vis struct ) => { vis!( $vis) } ; }
733
782
assert_eq ! ( inherited_vis!( struct ) , "" ) ;
734
783
assert_eq ! ( stringify!( ) , "" ) ;
784
+
785
+ // Attributes are not allowed on visibilities.
735
786
}
736
787
737
788
macro_rules! p {
0 commit comments