2
2
// edition:2021
3
3
// compile-flags: --test
4
4
5
+ #![ allow( incomplete_features) ]
5
6
#![ feature( async_closure) ]
6
7
#![ feature( auto_traits) ]
7
8
#![ feature( box_patterns) ]
8
9
#![ feature( const_trait_impl) ]
9
- #![ feature( decl_macro) ]
10
10
#![ feature( coroutines) ]
11
+ #![ feature( decl_macro) ]
12
+ #![ feature( explicit_tail_calls) ]
11
13
#![ feature( more_qualified_paths) ]
12
14
#![ feature( raw_ref_op) ]
13
15
#![ feature( trait_alias) ]
14
16
#![ feature( try_blocks) ]
15
17
#![ feature( type_ascription) ]
18
+ #![ feature( yeet_expr) ]
16
19
#![ deny( unused_macros) ]
17
20
18
- macro_rules! stringify_block {
19
- ( $block: block) => {
20
- stringify!( $block)
21
- } ;
22
- }
23
-
24
- macro_rules! stringify_expr {
25
- ( $expr: expr) => {
26
- stringify!( $expr)
27
- } ;
28
- }
29
-
30
- macro_rules! stringify_item {
31
- ( $item: item) => {
32
- stringify!( $item)
33
- } ;
34
- }
35
-
36
- macro_rules! stringify_meta {
37
- ( $meta: meta) => {
38
- stringify!( $meta)
39
- } ;
40
- }
41
-
42
- macro_rules! stringify_pat {
43
- ( $pat: pat) => {
44
- stringify!( $pat)
45
- } ;
46
- }
47
-
48
- macro_rules! stringify_path {
49
- ( $path: path) => {
50
- stringify!( $path)
51
- } ;
52
- }
53
-
54
- macro_rules! stringify_stmt {
55
- ( $stmt: stmt) => {
56
- stringify!( $stmt)
57
- } ;
58
- }
59
-
60
- macro_rules! stringify_ty {
61
- ( $ty: ty) => {
62
- stringify!( $ty)
21
+ // These macros force the use of AST pretty-printing by converting the input to
22
+ // a particular fragment specifier.
23
+ macro_rules! block { ( $block: block) => { stringify!( $block) } ; }
24
+ macro_rules! expr { ( $expr: expr) => { stringify!( $expr) } ; }
25
+ macro_rules! item { ( $item: item) => { stringify!( $item) } ; }
26
+ macro_rules! meta { ( $meta: meta) => { stringify!( $meta) } ; }
27
+ macro_rules! pat { ( $pat: pat) => { stringify!( $pat) } ; }
28
+ macro_rules! path { ( $path: path) => { stringify!( $path) } ; }
29
+ macro_rules! stmt { ( $stmt: stmt) => { stringify!( $stmt) } ; }
30
+ macro_rules! ty { ( $ty: ty) => { stringify!( $ty) } ; }
31
+ macro_rules! vis { ( $vis: vis) => { stringify!( $vis) } ; }
32
+
33
+ // Use this when AST pretty-printing and TokenStream pretty-printing give
34
+ // the same result (which is preferable.)
35
+ macro_rules! c1 {
36
+ ( $frag: ident, [ $( $tt: tt) * ] , $s: literal) => {
37
+ assert_eq!( $frag!( $( $tt) * ) , $s) ;
38
+ assert_eq!( stringify!( $( $tt) * ) , $s) ;
63
39
} ;
64
40
}
65
41
66
- macro_rules! stringify_vis {
67
- ( $vis: vis) => {
68
- stringify!( $vis)
42
+ // Use this when AST pretty-printing and TokenStream pretty-printing give
43
+ // different results.
44
+ //
45
+ // `c1` and `c2` could be in a single macro, but having them separate makes it
46
+ // easy to find the cases where the two pretty-printing approaches give
47
+ // different results.
48
+ macro_rules! c2 {
49
+ ( $frag: ident, [ $( $tt: tt) * ] , $s1: literal, $s2: literal) => {
50
+ assert_ne!( $s1, $s2, "should use `c1!` instead" ) ;
51
+ assert_eq!( $frag!( $( $tt) * ) , $s1) ;
52
+ assert_eq!( stringify!( $( $tt) * ) , $s2) ;
69
53
} ;
70
54
}
71
55
72
56
#[ test]
73
57
fn test_block ( ) {
74
- assert_eq ! ( stringify_block!( { } ) , "{}" ) ;
75
- assert_eq ! ( stringify_block!( { true } ) , "{ true }" ) ;
76
- assert_eq ! ( stringify_block!( { return } ) , "{ return }" ) ;
77
- assert_eq ! (
78
- stringify_block!( {
58
+ c1 ! ( block, [ { } ] , "{}" ) ;
59
+ c1 ! ( block, [ { true } ] , "{ true }" ) ;
60
+ c1 ! ( block, [ { return } ] , "{ return }" ) ;
61
+ c2 ! ( block, [ {
79
62
return ;
80
- } ) ,
63
+ } ] ,
81
64
"{ return; }" ,
65
+ "{ return ; }"
82
66
) ;
83
- assert_eq ! (
84
- stringify_block! ( {
67
+ c2 ! ( block ,
68
+ [ {
85
69
let _;
86
70
true
87
- } ) ,
71
+ } ] ,
88
72
"{ let _; true }" ,
73
+ "{ let _ ; true }"
89
74
) ;
90
75
}
91
76
92
77
#[ test]
93
78
fn test_expr ( ) {
94
79
// ExprKind::Array
95
- assert_eq ! ( stringify_expr!( [ ] ) , "[]" ) ;
96
- assert_eq ! ( stringify_expr!( [ true ] ) , "[true]" ) ;
97
- assert_eq ! ( stringify_expr!( [ true , ] ) , "[true]" ) ;
98
- assert_eq ! ( stringify_expr!( [ true , true ] ) , "[true, true]" ) ;
80
+ c1 ! ( expr, [ [ ] ] , "[]" ) ;
81
+ c1 ! ( expr, [ [ true ] ] , "[true]" ) ;
82
+ c2 ! ( expr, [ [ true , ] ] , "[true]" , "[true,]" ) ;
83
+ c1 ! ( expr, [ [ true , true ] ] , "[true, true]" ) ;
84
+
85
+ // ExprKind::ConstBlock
86
+ // FIXME: todo
99
87
100
88
// ExprKind::Call
101
- assert_eq ! ( stringify_expr! ( f( ) ) , "f()" ) ;
102
- assert_eq ! ( stringify_expr! ( f:: <u8 >( ) ) , "f::<u8> ()" ) ;
103
- assert_eq ! ( stringify_expr! ( f:: <1 >( ) ) , "f::<1> ()" ) ;
104
- assert_eq ! ( stringify_expr! ( f:: <' a, u8 , 1 >( ) ) , "f::< 'a, u8, 1> ()" ) ;
105
- assert_eq ! ( stringify_expr! ( f( true ) ) , "f(true)" ) ;
106
- assert_eq ! ( stringify_expr! ( f( true , ) ) , "f(true)" ) ;
107
- assert_eq ! ( stringify_expr! ( ( ) ( ) ) , "()()" ) ;
89
+ c1 ! ( expr , [ f( ) ] , "f()" ) ;
90
+ c2 ! ( expr , [ f :: < u8 > ( ) ] , " f::<u8>()" , "f :: < u8 > ()" ) ;
91
+ c2 ! ( expr , [ f :: < 1 > ( ) ] , " f::<1>()" , "f :: < 1 > ()" ) ;
92
+ c2 ! ( expr , [ f :: < ' a , u8 , 1 > ( ) ] , " f::<'a, u8, 1>()" , "f :: < 'a, u8, 1 > ()" ) ;
93
+ c1 ! ( expr , [ f( true ) ] , "f(true)" ) ;
94
+ c2 ! ( expr , [ f( true , ) ] , "f(true)" , "f(true, )" ) ;
95
+ c2 ! ( expr , [ ( ) ( ) ] , "()()" , "() ()" ) ;
108
96
109
97
// ExprKind::MethodCall
110
- assert_eq ! ( stringify_expr!( x. f( ) ) , "x.f()" ) ;
111
- assert_eq ! ( stringify_expr!( x. f:: <u8 >( ) ) , "x.f::<u8>()" ) ;
98
+ c1 ! ( expr, [ x. f( ) ] , "x.f()" ) ;
99
+ c2 ! ( expr, [ x. f:: <u8 >( ) ] , "x.f::<u8>()" , "x.f :: < u8 > ()" ) ;
100
+ c2 ! ( expr, [ x. collect:: <Vec <_>>( ) ] , "x.collect::<Vec<_>>()" , "x.collect :: < Vec < _ >> ()" ) ;
112
101
113
102
// ExprKind::Tup
114
- assert_eq ! ( stringify_expr! ( ( ) ) , "()" ) ;
115
- assert_eq ! ( stringify_expr! ( ( true , ) ) , "(true,)" ) ;
116
- assert_eq ! ( stringify_expr! ( ( true , false ) ) , "(true, false)" ) ;
117
- assert_eq ! ( stringify_expr! ( ( true , false , ) ) , "(true, false)" ) ;
103
+ c1 ! ( expr , [ ( ) ] , "()" ) ;
104
+ c1 ! ( expr , [ ( true , ) ] , "(true,)" ) ;
105
+ c1 ! ( expr , [ ( true , false ) ] , "(true, false)" ) ;
106
+ c2 ! ( expr , [ ( true , false , ) ] , "(true, false)" , "(true, false, )" ) ;
118
107
119
108
// ExprKind::Binary
120
- assert_eq ! ( stringify_expr!( true || false ) , "true || false" ) ;
121
- assert_eq ! ( stringify_expr!( true || false && false ) , "true || false && false" ) ;
109
+ c1 ! ( expr, [ true || false ] , "true || false" ) ;
110
+ c1 ! ( expr, [ true || false && false ] , "true || false && false" ) ;
111
+ c1 ! ( expr, [ a < 1 && 2 < b && c > 3 && 4 > d ] , "a < 1 && 2 < b && c > 3 && 4 > d" ) ;
112
+ c2 ! ( expr, [ a & b & !c ] , "a & b & !c" , "a & b &! c" ) ; // FIXME
113
+ c2 ! ( expr,
114
+ [ a + b * c - d + -1 * -2 - -3 ] ,
115
+ "a + b * c - d + -1 * -2 - -3" ,
116
+ "a + b * c - d + - 1 * - 2 - - 3"
117
+ ) ;
122
118
123
119
// ExprKind::Unary
124
- assert_eq ! ( stringify_expr! ( * expr) , "*expr" ) ;
125
- assert_eq ! ( stringify_expr! ( !expr) , "!expr" ) ;
126
- assert_eq ! ( stringify_expr! ( -expr) , "-expr" ) ;
120
+ c2 ! ( expr , [ * expr ] , "*expr" , "* expr") ;
121
+ c2 ! ( expr , [ !expr ] , " !expr" , "! expr" ) ;
122
+ c2 ! ( expr , [ -expr ] , "-expr" , "- expr") ;
127
123
128
124
// ExprKind::Lit
129
- assert_eq ! ( stringify_expr! ( 'x' ) , "'x'" ) ;
130
- assert_eq ! ( stringify_expr! ( 1_000_i8 ) , "1_000_i8" ) ;
131
- assert_eq ! ( stringify_expr! ( 1.00000000000000001 ) , "1.00000000000000001" ) ;
125
+ c1 ! ( expr , [ 'x' ] , "'x'" ) ;
126
+ c1 ! ( expr , [ 1_000_i8 ] , "1_000_i8" ) ;
127
+ c1 ! ( expr , [ 1.00000000000000001 ] , "1.00000000000000001" ) ;
132
128
133
129
// ExprKind::Cast
134
- assert_eq ! ( stringify_expr! ( expr as T ) , "expr as T" ) ;
135
- assert_eq ! ( stringify_expr! ( expr as T <u8 >) , "expr as T<u8>" ) ;
130
+ c1 ! ( expr, [ expr as T ] , "expr as T" ) ;
131
+ c2 ! ( expr, [ expr as T <u8 > ] , "expr as T<u8>" , "expr as T < u8 >") ;
136
132
137
- // ExprKind::Type
138
- // There is no syntax for type ascription.
133
+ // ExprKind::Type: there is no syntax for type ascription.
134
+
135
+ // ExprKind::Let
136
+ c1 ! ( expr, [ if let Some ( a) = b { c } else { d } ] , "if let Some(a) = b { c } else { d }" ) ;
139
137
140
138
// ExprKind::If
141
- assert_eq ! ( stringify_expr!( if true { } ) , "if true {}" ) ;
142
- assert_eq ! (
143
- stringify_expr!( if true {
144
- } else {
145
- } ) ,
146
- "if true {} else {}" ,
147
- ) ;
148
- assert_eq ! (
149
- stringify_expr!( if let true = true {
150
- } else {
151
- } ) ,
152
- "if let true = true {} else {}" ,
153
- ) ;
154
- assert_eq ! (
155
- stringify_expr!( if true {
139
+ c1 ! ( expr, [ if true { } ] , "if true {}" ) ;
140
+ c2 ! ( expr,
141
+ [ if :: std:: blah( ) { } else { } ] ,
142
+ "if ::std::blah() {} else {}" ,
143
+ "if :: std :: blah() {} else {}"
144
+ ) ;
145
+ c1 ! ( expr, [ if let true = true { } else { } ] , "if let true = true {} else {}" ) ;
146
+ c1 ! ( expr,
147
+ [ if true {
156
148
} else if false {
157
- } ) ,
158
- "if true {} else if false {}" ,
149
+ } ] ,
150
+ "if true {} else if false {}"
159
151
) ;
160
- assert_eq ! (
161
- stringify_expr! ( if true {
152
+ c1 ! ( expr ,
153
+ [ if true {
162
154
} else if false {
163
155
} else {
164
- } ) ,
165
- "if true {} else if false {} else {}" ,
156
+ } ] ,
157
+ "if true {} else if false {} else {}"
166
158
) ;
167
- assert_eq ! (
168
- stringify_expr! ( if true {
159
+ c2 ! ( expr ,
160
+ [ if true {
169
161
return ;
170
162
} else if false {
171
163
0
172
164
} else {
173
165
0
174
- } ) ,
166
+ } ] ,
175
167
"if true { return; } else if false { 0 } else { 0 }" ,
168
+ "if true { return ; } else if false { 0 } else { 0 }"
176
169
) ;
177
170
178
171
// ExprKind::While
179
- assert_eq ! ( stringify_expr! ( while true { } ) , "while true {}" ) ;
180
- assert_eq ! ( stringify_expr! ( ' a: while true { } ) , "'a: while true {}" ) ;
181
- assert_eq ! ( stringify_expr! ( while let true = true { } ) , "while let true = true {}" ) ;
172
+ c1 ! ( expr , [ while true { } ] , "while true {}" ) ;
173
+ c2 ! ( expr , [ ' a: while true { } ] , "'a: while true {}" , "'a : while true {}") ;
174
+ c1 ! ( expr , [ while let true = true { } ] , "while let true = true {}" ) ;
182
175
183
176
// ExprKind::ForLoop
184
- assert_eq ! ( stringify_expr! ( for _ in x { } ) , "for _ in x {}" ) ;
185
- assert_eq ! ( stringify_expr! ( ' a: for _ in x { } ) , "'a: for _ in x {}" ) ;
177
+ c1 ! ( expr , [ for _ in x { } ] , "for _ in x {}" ) ;
178
+ c2 ! ( expr , [ ' a: for _ in x { } ] , "'a: for _ in x {}" , "'a : for _ in x {}") ;
186
179
187
180
// ExprKind::Loop
188
- assert_eq ! ( stringify_expr! ( loop { } ) , "loop {}" ) ;
189
- assert_eq ! ( stringify_expr! ( ' a: loop { } ) , "'a: loop {}" ) ;
181
+ c1 ! ( expr , [ loop { } ] , "loop {}" ) ;
182
+ c2 ! ( expr , [ ' a: loop { } ] , "'a: loop {}" , "'a : loop {}") ;
190
183
191
184
// ExprKind::Match
192
- assert_eq ! ( stringify_expr! ( match self { } ) , "match self {}" ) ;
193
- assert_eq ! (
194
- stringify_expr! ( match self {
185
+ c1 ! ( expr , [ match self { } ] , "match self {}" ) ;
186
+ c1 ! ( expr ,
187
+ [ match self {
195
188
Ok => 1 ,
196
- } ) ,
197
- "match self { Ok => 1, }" ,
189
+ } ] ,
190
+ "match self { Ok => 1, }"
198
191
) ;
199
- assert_eq ! (
200
- stringify_expr! ( match self {
192
+ c1 ! ( expr ,
193
+ [ match self {
201
194
Ok => 1 ,
202
195
Err => 0 ,
203
- } ) ,
204
- "match self { Ok => 1, Err => 0, }" ,
196
+ } ] ,
197
+ "match self { Ok => 1, Err => 0, }"
205
198
) ;
206
199
207
200
// ExprKind::Closure
208
- assert_eq ! ( stringify_expr!( || { } ) , "|| {}" ) ;
209
- assert_eq ! ( stringify_expr!( |x| { } ) , "|x| {}" ) ;
210
- assert_eq ! ( stringify_expr!( |x: u8 | { } ) , "|x: u8| {}" ) ;
211
- assert_eq ! ( stringify_expr!( || ( ) ) , "|| ()" ) ;
212
- assert_eq ! ( stringify_expr!( move || self ) , "move || self" ) ;
213
- assert_eq ! ( stringify_expr!( async || self ) , "async || self" ) ;
214
- assert_eq ! ( stringify_expr!( async move || self ) , "async move || self" ) ;
215
- assert_eq ! ( stringify_expr!( static || self ) , "static || self" ) ;
216
- assert_eq ! ( stringify_expr!( static move || self ) , "static move || self" ) ;
217
- #[ rustfmt:: skip] // https://github.com/rust-lang/rustfmt/issues/5149
218
- assert_eq ! (
219
- stringify_expr!( static async || self ) ,
220
- "static async || self" ,
221
- ) ;
222
- #[ rustfmt:: skip] // https://github.com/rust-lang/rustfmt/issues/5149
223
- assert_eq ! (
224
- stringify_expr!( static async move || self ) ,
225
- "static async move || self" ,
226
- ) ;
227
- assert_eq ! ( stringify_expr!( || -> u8 { self } ) , "|| -> u8 { self }" ) ;
228
- assert_eq ! ( stringify_expr!( 1 + || { } ) , "1 + (|| {})" ) ; // ??
201
+ c1 ! ( expr, [ || { } ] , "|| {}" ) ;
202
+ c2 ! ( expr, [ |x| { } ] , "|x| {}" , "| x | {}" ) ;
203
+ c2 ! ( expr, [ |x: u8 | { } ] , "|x: u8| {}" , "| x : u8 | {}" ) ;
204
+ c1 ! ( expr, [ || ( ) ] , "|| ()" ) ;
205
+ c1 ! ( expr, [ move || self ] , "move || self" ) ;
206
+ c1 ! ( expr, [ async || self ] , "async || self" ) ;
207
+ c1 ! ( expr, [ async move || self ] , "async move || self" ) ;
208
+ c1 ! ( expr, [ static || self ] , "static || self" ) ;
209
+ c1 ! ( expr, [ static move || self ] , "static move || self" ) ;
210
+ c1 ! ( expr, [ static async || self ] , "static async || self" ) ;
211
+ c1 ! ( expr, [ static async move || self ] , "static async move || self" ) ;
212
+ c1 ! ( expr, [ || -> u8 { self } ] , "|| -> u8 { self }" ) ;
213
+ c2 ! ( expr, [ 1 + || { } ] , "1 + (|| {})" , "1 + || {}" ) ; // AST??
229
214
230
215
// ExprKind::Block
231
- assert_eq ! ( stringify_expr!( { } ) , "{}" ) ;
232
- assert_eq ! ( stringify_expr!( unsafe { } ) , "unsafe {}" ) ;
233
- assert_eq ! ( stringify_expr!( ' a: { } ) , "'a: {}" ) ;
234
- assert_eq ! (
235
- stringify_expr!(
236
- #[ attr]
237
- { }
238
- ) ,
239
- "#[attr] {}" ,
240
- ) ;
241
- assert_eq ! (
242
- stringify_expr!(
216
+ c1 ! ( expr, [ { } ] , "{}" ) ;
217
+ c1 ! ( expr, [ unsafe { } ] , "unsafe {}" ) ;
218
+ c2 ! ( expr, [ ' a: { } ] , "'a: {}" , "'a : {}" ) ;
219
+ c1 ! ( expr, [ #[ attr] { } ] , "#[attr] {}" ) ;
220
+ c2 ! ( expr,
221
+ [
243
222
{
244
223
#![ attr]
245
224
}
246
- ) ,
225
+ ] ,
247
226
"{\n \
248
227
\x20 #![attr]\n \
249
228
}",
229
+ "{ #! [attr] }"
250
230
) ;
251
231
252
232
// ExprKind::Async
253
- assert_eq ! ( stringify_expr! ( async { } ) , "async {}" ) ;
254
- assert_eq ! ( stringify_expr! ( async move { } ) , "async move {}" ) ;
233
+ c1 ! ( expr , [ async { } ] , "async {}" ) ;
234
+ c1 ! ( expr , [ async move { } ] , "async move {}" ) ;
255
235
256
236
// ExprKind::Await
257
- assert_eq ! ( stringify_expr! ( expr. await ) , "expr.await" ) ;
237
+ c1 ! ( expr, [ expr . await ] , "expr.await" ) ;
258
238
259
239
// ExprKind::TryBlock
260
- assert_eq ! ( stringify_expr! ( try { } ) , "try {}" ) ;
240
+ c1 ! ( expr , [ try { } ] , "try {}" ) ;
261
241
262
242
// ExprKind::Assign
263
- assert_eq ! ( stringify_expr! ( expr = true ) , "expr = true" ) ;
243
+ c1 ! ( expr, [ expr = true ] , "expr = true" ) ;
264
244
265
245
// ExprKind::AssignOp
266
- assert_eq ! ( stringify_expr! ( expr += true ) , "expr += true" ) ;
246
+ c1 ! ( expr, [ expr += true ] , "expr += true" ) ;
267
247
268
248
// ExprKind::Field
269
- assert_eq ! ( stringify_expr! ( expr. field) , "expr.field" ) ;
270
- assert_eq ! ( stringify_expr! ( expr. 0 ) , "expr.0" ) ;
249
+ c1 ! ( expr, [ expr . field ] , "expr.field" ) ;
250
+ c1 ! ( expr, [ expr . 0 ] , "expr.0" ) ;
271
251
272
252
// ExprKind::Index
273
- assert_eq ! ( stringify_expr! ( expr[ true ] ) , "expr[true]" ) ;
253
+ c2 ! ( expr, [ expr [ true ] ] , "expr[true]" , "expr [true]") ;
274
254
275
255
// ExprKind::Range
276
- assert_eq ! ( stringify_expr!( ..) , ".." ) ;
277
- assert_eq ! ( stringify_expr!( ..hi) , "..hi" ) ;
278
- assert_eq ! ( stringify_expr!( lo..) , "lo.." ) ;
279
- assert_eq ! ( stringify_expr!( lo..hi) , "lo..hi" ) ;
280
- assert_eq ! ( stringify_expr!( ..=hi) , "..=hi" ) ;
281
- assert_eq ! ( stringify_expr!( lo..=hi) , "lo..=hi" ) ;
282
- assert_eq ! ( stringify_expr!( -2 ..=-1 ) , "-2..=-1" ) ;
256
+ c1 ! ( expr, [ .. ] , ".." ) ;
257
+ c2 ! ( expr, [ ..hi ] , "..hi" , ".. hi" ) ;
258
+ c2 ! ( expr, [ lo.. ] , "lo.." , "lo .." ) ;
259
+ c2 ! ( expr, [ lo..hi ] , "lo..hi" , "lo .. hi" ) ;
260
+ c2 ! ( expr, [ ..=hi ] , "..=hi" , "..= hi" ) ;
261
+ c2 ! ( expr, [ lo..=hi ] , "lo..=hi" , "lo ..= hi" ) ;
262
+ c2 ! ( expr, [ -2 ..=-1 ] , "-2..=-1" , "- 2 ..= - 1" ) ;
263
+
264
+ // ExprKind::Underscore
265
+ // FIXME: todo
283
266
284
267
// ExprKind::Path
285
- assert_eq ! ( stringify_expr! ( thing) , "thing" ) ;
286
- assert_eq ! ( stringify_expr! ( m:: thing) , "m::thing" ) ;
287
- assert_eq ! ( stringify_expr! ( self :: thing) , "self::thing" ) ;
288
- assert_eq ! ( stringify_expr! ( crate :: thing) , "crate::thing" ) ;
289
- assert_eq ! ( stringify_expr! ( Self :: thing) , "Self::thing" ) ;
290
- assert_eq ! ( stringify_expr! ( <Self as T >:: thing) , "<Self as T>::thing" ) ;
291
- assert_eq ! ( stringify_expr! ( Self :: <' static >) , "Self::<'static>" ) ;
268
+ c1 ! ( expr , [ thing ] , "thing" ) ;
269
+ c2 ! ( expr , [ m:: thing ] , "m::thing" , "m :: thing") ;
270
+ c2 ! ( expr , [ self :: thing ] , "self::thing" , "self :: thing") ;
271
+ c2 ! ( expr , [ crate :: thing ] , "crate::thing" , "crate :: thing") ;
272
+ c2 ! ( expr , [ Self :: thing ] , "Self::thing" , "Self :: thing") ;
273
+ c2 ! ( expr , [ <Self as T >:: thing ] , "<Self as T>::thing" , "< Self as T > :: thing") ;
274
+ c2 ! ( expr , [ Self :: <' static > ] , "Self::<'static>" , "Self :: < 'static >") ;
292
275
293
276
// ExprKind::AddrOf
294
- assert_eq ! ( stringify_expr! ( & expr) , "&expr" ) ;
295
- assert_eq ! ( stringify_expr! ( & mut expr) , "&mut expr" ) ;
296
- assert_eq ! ( stringify_expr! ( & raw const expr) , "&raw const expr" ) ;
297
- assert_eq ! ( stringify_expr! ( & raw mut expr) , "&raw mut expr" ) ;
277
+ c2 ! ( expr , [ & expr ] , "&expr" , "& expr") ;
278
+ c2 ! ( expr , [ & mut expr ] , "&mut expr" , "& mut expr") ;
279
+ c2 ! ( expr , [ & raw const expr ] , "&raw const expr" , "& raw const expr") ;
280
+ c2 ! ( expr , [ & raw mut expr ] , "&raw mut expr" , "& raw mut expr") ;
298
281
299
282
// ExprKind::Break
300
- assert_eq ! ( stringify_expr! ( break ) , "break" ) ;
301
- assert_eq ! ( stringify_expr! ( break ' a) , "break 'a" ) ;
302
- assert_eq ! ( stringify_expr! ( break true ) , "break true" ) ;
303
- assert_eq ! ( stringify_expr! ( break ' a true ) , "break 'a true" ) ;
283
+ c1 ! ( expr , [ break ] , "break" ) ;
284
+ c1 ! ( expr , [ break ' a ] , "break 'a" ) ;
285
+ c1 ! ( expr , [ break true ] , "break true" ) ;
286
+ c1 ! ( expr , [ break ' a true ] , "break 'a true" ) ;
304
287
305
288
// ExprKind::Continue
306
- assert_eq ! ( stringify_expr! ( continue ) , "continue" ) ;
307
- assert_eq ! ( stringify_expr! ( continue ' a) , "continue 'a" ) ;
289
+ c1 ! ( expr , [ continue ] , "continue" ) ;
290
+ c1 ! ( expr , [ continue ' a ] , "continue 'a" ) ;
308
291
309
292
// ExprKind::Ret
310
- assert_eq ! ( stringify_expr!( return ) , "return" ) ;
311
- assert_eq ! ( stringify_expr!( return true ) , "return true" ) ;
293
+ c1 ! ( expr, [ return ] , "return" ) ;
294
+ c1 ! ( expr, [ return true ] , "return true" ) ;
295
+
296
+ // ExprKind::InlineAsm: untestable because this test works pre-expansion.
297
+
298
+ // ExprKind::OffsetOf: untestable because this test works pre-expansion.
312
299
313
300
// ExprKind::MacCall
314
- assert_eq ! ( stringify_expr! ( mac!( ...) ) , "mac!(...)" ) ;
315
- assert_eq ! ( stringify_expr! ( mac![ ...] ) , "mac![...]" ) ;
316
- assert_eq ! ( stringify_expr! ( mac! { ... } ) , "mac! { ... }" ) ;
301
+ c2 ! ( expr , [ mac! ( ... ) ] , " mac!(...)" , "mac! (...)" ) ;
302
+ c2 ! ( expr , [ mac! [ ... ] ] , " mac![...]" , "mac! [...]" ) ;
303
+ c1 ! ( expr , [ mac! { ... } ] , "mac! { ... }" ) ;
317
304
318
305
// ExprKind::Struct
319
- assert_eq ! ( stringify_expr!( Struct { } ) , "Struct {}" ) ;
320
- #[ rustfmt:: skip] // https://github.com/rust-lang/rustfmt/issues/5151
321
- assert_eq ! ( stringify_expr!( <Struct as Trait >:: Type { } ) , "<Struct as Trait>::Type {}" ) ;
322
- assert_eq ! ( stringify_expr!( Struct { .. } ) , "Struct { .. }" ) ;
323
- assert_eq ! ( stringify_expr!( Struct { ..base } ) , "Struct { ..base }" ) ;
324
- assert_eq ! ( stringify_expr!( Struct { x } ) , "Struct { x }" ) ;
325
- assert_eq ! ( stringify_expr!( Struct { x, .. } ) , "Struct { x, .. }" ) ;
326
- assert_eq ! ( stringify_expr!( Struct { x, ..base } ) , "Struct { x, ..base }" ) ;
327
- assert_eq ! ( stringify_expr!( Struct { x: true } ) , "Struct { x: true }" ) ;
328
- assert_eq ! ( stringify_expr!( Struct { x: true , .. } ) , "Struct { x: true, .. }" ) ;
329
- assert_eq ! ( stringify_expr!( Struct { x: true , ..base } ) , "Struct { x: true, ..base }" ) ;
306
+ c1 ! ( expr, [ Struct { } ] , "Struct {}" ) ;
307
+ c2 ! ( expr,
308
+ [ <Struct as Trait >:: Type { } ] ,
309
+ "<Struct as Trait>::Type {}" ,
310
+ "< Struct as Trait > :: Type {}"
311
+ ) ;
312
+ c1 ! ( expr, [ Struct { .. } ] , "Struct { .. }" ) ;
313
+ c2 ! ( expr, [ Struct { ..base } ] , "Struct { ..base }" , "Struct { .. base }" ) ;
314
+ c1 ! ( expr, [ Struct { x } ] , "Struct { x }" ) ;
315
+ c1 ! ( expr, [ Struct { x, .. } ] , "Struct { x, .. }" ) ;
316
+ c2 ! ( expr, [ Struct { x, ..base } ] , "Struct { x, ..base }" , "Struct { x, .. base }" ) ;
317
+ c2 ! ( expr, [ Struct { x: true } ] , "Struct { x: true }" , "Struct { x : true }" ) ;
318
+ c2 ! ( expr, [ Struct { x: true , .. } ] , "Struct { x: true, .. }" , "Struct { x : true, .. }" ) ;
319
+ c2 ! ( expr,
320
+ [ Struct { x: true , ..base } ] ,
321
+ "Struct { x: true, ..base }" ,
322
+ "Struct { x : true, .. base }"
323
+ ) ;
330
324
331
325
// ExprKind::Repeat
332
- assert_eq ! ( stringify_expr! ( [ ( ) ; 0 ] ) , "[(); 0]" ) ;
326
+ c2 ! ( expr , [ [ ( ) ; 0 ] ] , "[(); 0]" , "[() ; 0]" ) ;
333
327
334
328
// ExprKind::Paren
335
- assert_eq ! ( stringify_expr! ( ( expr) ) , "(expr)" ) ;
329
+ c1 ! ( expr , [ ( expr) ] , "(expr)" ) ;
336
330
337
331
// ExprKind::Try
338
- assert_eq ! ( stringify_expr! ( expr? ) , "expr?" ) ;
332
+ c2 ! ( expr, [ expr? ] , "expr?" , "expr ?") ;
339
333
340
334
// ExprKind::Yield
341
- assert_eq ! ( stringify_expr!( yield) , "yield" ) ;
342
- assert_eq ! ( stringify_expr!( yield true ) , "yield true" ) ;
335
+ c1 ! ( expr, [ yield ] , "yield" ) ;
336
+ c1 ! ( expr, [ yield true ] , "yield true" ) ;
337
+
338
+ // ExprKind::Yeet
339
+ c1 ! ( expr, [ do yeet ] , "do yeet" ) ;
340
+ c1 ! ( expr, [ do yeet 0 ] , "do yeet 0" ) ;
341
+
342
+ // ExprKind::Become
343
+ // FIXME: todo
344
+
345
+ // ExprKind::IncludedBytes
346
+ // FIXME: todo
347
+
348
+ // ExprKind::FormatArgs: untestable because this test works pre-expansion.
349
+
350
+ // ExprKind::Err: untestable.
343
351
}
344
352
345
353
#[ test]
346
354
fn test_item ( ) {
347
355
// ItemKind::ExternCrate
348
- assert_eq ! (
349
- stringify_item!(
350
- extern crate std;
351
- ) ,
352
- "extern crate std;" ,
353
- ) ;
354
- assert_eq ! (
355
- stringify_item!(
356
- pub extern crate self as std;
357
- ) ,
356
+ c2 ! ( item, [ extern crate std; ] , "extern crate std;" , "extern crate std ;" ) ;
357
+ c2 ! ( item,
358
+ [ pub extern crate self as std; ] ,
358
359
"pub extern crate self as std;" ,
360
+ "pub extern crate self as std ;"
359
361
) ;
360
362
361
363
// ItemKind::Use
362
- assert_eq ! (
363
- stringify_item!(
364
- pub use crate :: { a, b:: c} ;
365
- ) ,
364
+ c2 ! ( item,
365
+ [ pub use crate :: { a, b:: c} ; ] ,
366
366
"pub use crate::{a, b::c};" ,
367
+ "pub use crate :: { a, b :: c } ;"
367
368
) ;
369
+ c2 ! ( item, [ pub use A :: * ; ] , "pub use A::*;" , "pub use A :: * ;" ) ;
368
370
369
371
// ItemKind::Static
370
- assert_eq ! (
371
- stringify_item!(
372
- pub static S : ( ) = { } ;
373
- ) ,
374
- "pub static S: () = {};" ,
375
- ) ;
376
- assert_eq ! (
377
- stringify_item!(
378
- static mut S : ( ) = { } ;
379
- ) ,
380
- "static mut S: () = {};" ,
381
- ) ;
382
- assert_eq ! (
383
- stringify_item!(
384
- static S : ( ) ;
385
- ) ,
386
- "static S: ();" ,
387
- ) ;
388
- assert_eq ! (
389
- stringify_item!(
390
- static mut S : ( ) ;
391
- ) ,
392
- "static mut S: ();" ,
393
- ) ;
372
+ c2 ! ( item, [ pub static S : ( ) = { } ; ] , "pub static S: () = {};" , "pub static S : () = {} ;" ) ;
373
+ c2 ! ( item, [ static mut S : ( ) = { } ; ] , "static mut S: () = {};" , "static mut S : () = {} ;" ) ;
374
+ c2 ! ( item, [ static S : ( ) ; ] , "static S: ();" , "static S : () ;" ) ;
375
+ c2 ! ( item, [ static mut S : ( ) ; ] , "static mut S: ();" , "static mut S : () ;" ) ;
394
376
395
377
// ItemKind::Const
396
- assert_eq ! (
397
- stringify_item!(
398
- pub const S : ( ) = { } ;
399
- ) ,
400
- "pub const S: () = {};" ,
401
- ) ;
402
- assert_eq ! (
403
- stringify_item!(
404
- const S : ( ) ;
405
- ) ,
406
- "const S: ();" ,
407
- ) ;
378
+ c2 ! ( item, [ pub const S : ( ) = { } ; ] , "pub const S: () = {};" , "pub const S : () = {} ;" ) ;
379
+ c2 ! ( item, [ const S : ( ) ; ] , "const S: ();" , "const S : () ;" ) ;
408
380
409
381
// ItemKind::Fn
410
- assert_eq ! (
411
- stringify_item!(
412
- pub default const async unsafe extern "C" fn f( ) { }
413
- ) ,
414
- "pub default const async unsafe extern \" C\" fn f() {}" ,
382
+ c1 ! ( item,
383
+ [ pub default const async unsafe extern "C" fn f( ) { } ] ,
384
+ "pub default const async unsafe extern \" C\" fn f() {}"
385
+ ) ;
386
+ c2 ! ( item,
387
+ [ fn g<T >( t: Vec <Vec <Vec <T >>>) { } ] ,
388
+ "fn g<T>(t: Vec<Vec<Vec<T>>>) {}" ,
389
+ "fn g < T > (t : Vec < Vec < Vec < T >> >) {}"
390
+ ) ;
391
+ c2 ! ( item,
392
+ [ fn h<' a>( t: & ' a Vec <Cell <dyn D >>) { } ] ,
393
+ "fn h<'a>(t: &'a Vec<Cell<dyn D>>) {}" ,
394
+ "fn h < 'a > (t : & 'a Vec < Cell < dyn D >>) {}"
415
395
) ;
416
396
417
397
// ItemKind::Mod
418
- assert_eq ! (
419
- stringify_item!(
420
- pub mod m;
421
- ) ,
422
- "pub mod m;" ,
423
- ) ;
424
- assert_eq ! (
425
- stringify_item!(
426
- mod m { }
427
- ) ,
428
- "mod m {}" ,
429
- ) ;
430
- assert_eq ! (
431
- stringify_item!(
432
- unsafe mod m;
433
- ) ,
434
- "unsafe mod m;" ,
435
- ) ;
436
- assert_eq ! (
437
- stringify_item!(
438
- unsafe mod m { }
439
- ) ,
440
- "unsafe mod m {}" ,
441
- ) ;
398
+ c2 ! ( item, [ pub mod m; ] , "pub mod m;" , "pub mod m ;" ) ;
399
+ c1 ! ( item, [ mod m { } ] , "mod m {}" ) ;
400
+ c2 ! ( item, [ unsafe mod m; ] , "unsafe mod m;" , "unsafe mod m ;" ) ;
401
+ c1 ! ( item, [ unsafe mod m { } ] , "unsafe mod m {}" ) ;
442
402
443
403
// ItemKind::ForeignMod
444
- assert_eq ! (
445
- stringify_item!(
446
- extern "C" { }
447
- ) ,
448
- "extern \" C\" {}" ,
449
- ) ;
450
- #[ rustfmt:: skip]
451
- assert_eq ! (
452
- stringify_item!(
453
- pub extern "C" { }
454
- ) ,
455
- "extern \" C\" {}" ,
456
- ) ;
457
- assert_eq ! (
458
- stringify_item!(
459
- unsafe extern "C++" { }
460
- ) ,
461
- "unsafe extern \" C++\" {}" ,
404
+ c1 ! ( item, [ extern "C" { } ] , "extern \" C\" {}" ) ;
405
+ c2 ! ( item,
406
+ [ pub extern "C" { } ] ,
407
+ "extern \" C\" {}" , // ??
408
+ "pub extern \" C\" {}"
462
409
) ;
410
+ c1 ! ( item, [ unsafe extern "C++" { } ] , "unsafe extern \" C++\" {}" ) ;
411
+
412
+ // ItemKind::GlobalAsm: untestable because this test works pre-expansion.
463
413
464
414
// ItemKind::TyAlias
465
- #[ rustfmt:: skip]
466
- assert_eq ! (
467
- stringify_item!(
415
+ c2 ! ( item,
416
+ [
468
417
pub default type Type <' a>: Bound
469
418
where
470
419
Self : ' a,
471
420
= T ;
472
- ) ,
421
+ ] ,
473
422
"pub default type Type<'a>: Bound where Self: 'a = T;" ,
423
+ "pub default type Type < 'a > : Bound where Self : 'a, = T ;"
474
424
) ;
475
425
476
426
// ItemKind::Enum
477
- assert_eq ! (
478
- stringify_item!(
479
- pub enum Void { }
480
- ) ,
481
- "pub enum Void {}" ,
482
- ) ;
483
- assert_eq ! (
484
- stringify_item!(
427
+ c1 ! ( item, [ pub enum Void { } ] , "pub enum Void {}" ) ;
428
+ c1 ! ( item,
429
+ [
485
430
enum Empty {
486
431
Unit ,
487
432
Tuple ( ) ,
488
433
Struct { } ,
489
434
}
490
- ) ,
491
- "enum Empty { Unit, Tuple(), Struct {}, }" ,
435
+ ] ,
436
+ "enum Empty { Unit, Tuple(), Struct {}, }"
492
437
) ;
493
- assert_eq ! (
494
- stringify_item! (
438
+ c2 ! ( item ,
439
+ [
495
440
enum Enum <T >
496
441
where
497
442
T : ' a,
@@ -500,386 +445,357 @@ fn test_item() {
500
445
Tuple ( T ) ,
501
446
Struct { t: T } ,
502
447
}
503
- ) ,
448
+ ] ,
504
449
"enum Enum<T> where T: 'a {\n \
505
450
\x20 Unit,\n \
506
451
\x20 Tuple(T),\n \
507
452
\x20 Struct {\n \
508
453
\x20 t: T,\n \
509
454
\x20 },\n \
510
455
}",
456
+ "enum Enum < T > where T : 'a, { Unit, Tuple(T), Struct { t : T }, }"
511
457
) ;
512
458
513
459
// ItemKind::Struct
514
- assert_eq ! (
515
- stringify_item!(
516
- pub struct Unit ;
517
- ) ,
518
- "pub struct Unit;" ,
519
- ) ;
520
- assert_eq ! (
521
- stringify_item!(
522
- struct Tuple ( ) ;
523
- ) ,
524
- "struct Tuple();" ,
525
- ) ;
526
- assert_eq ! (
527
- stringify_item!(
528
- struct Tuple ( T ) ;
529
- ) ,
530
- "struct Tuple(T);" ,
531
- ) ;
532
- assert_eq ! (
533
- stringify_item!(
534
- struct Struct { }
535
- ) ,
536
- "struct Struct {}" ,
537
- ) ;
538
- assert_eq ! (
539
- stringify_item!(
460
+ c2 ! ( item, [ pub struct Unit ; ] , "pub struct Unit;" , "pub struct Unit ;" ) ;
461
+ c2 ! ( item, [ struct Tuple ( ) ; ] , "struct Tuple();" , "struct Tuple() ;" ) ;
462
+ c2 ! ( item, [ struct Tuple ( T ) ; ] , "struct Tuple(T);" , "struct Tuple(T) ;" ) ;
463
+ c1 ! ( item, [ struct Struct { } ] , "struct Struct {}" ) ;
464
+ c2 ! ( item,
465
+ [
540
466
struct Struct <T >
541
467
where
542
468
T : ' a,
543
469
{
544
470
t: T ,
545
471
}
546
- ) ,
472
+ ] ,
547
473
"struct Struct<T> where T: 'a {\n \
548
474
\x20 t: T,\n \
549
475
}",
476
+ "struct Struct < T > where T : 'a, { t : T, }"
550
477
) ;
551
478
552
479
// ItemKind::Union
553
- assert_eq ! (
554
- stringify_item!(
555
- pub union Union { }
556
- ) ,
557
- "pub union Union {}" ,
558
- ) ;
559
- assert_eq ! (
560
- stringify_item!(
480
+ c1 ! ( item, [ pub union Union { } ] , "pub union Union {}" ) ;
481
+ c2 ! ( item,
482
+ [
561
483
union Union <T > where T : ' a {
562
484
t: T ,
563
485
}
564
- ) ,
486
+ ] ,
565
487
"union Union<T> where T: 'a {\n \
566
488
\x20 t: T,\n \
567
489
}",
490
+ "union Union < T > where T : 'a { t : T, }"
568
491
) ;
569
492
570
493
// ItemKind::Trait
571
- assert_eq ! (
572
- stringify_item!(
573
- pub unsafe auto trait Send { }
574
- ) ,
575
- "pub unsafe auto trait Send {}" ,
576
- ) ;
577
- assert_eq ! (
578
- stringify_item!(
494
+ c1 ! ( item, [ pub unsafe auto trait Send { } ] , "pub unsafe auto trait Send {}" ) ;
495
+ c2 ! ( item,
496
+ [
579
497
trait Trait <' a>: Sized
580
498
where
581
499
Self : ' a,
582
500
{
583
501
}
584
- ) ,
502
+ ] ,
585
503
"trait Trait<'a>: Sized where Self: 'a {}" ,
504
+ "trait Trait < 'a > : Sized where Self : 'a, {}"
586
505
) ;
587
506
588
507
// ItemKind::TraitAlias
589
- assert_eq ! (
590
- stringify_item!(
591
- pub trait Trait <T > = Sized where T : ' a;
592
- ) ,
508
+ c2 ! ( item,
509
+ [ pub trait Trait <T > = Sized where T : ' a; ] ,
593
510
"pub trait Trait<T> = Sized where T: 'a;" ,
511
+ "pub trait Trait < T > = Sized where T : 'a ;"
594
512
) ;
595
513
596
514
// ItemKind::Impl
597
- assert_eq ! (
598
- stringify_item!(
599
- pub impl Struct { }
600
- ) ,
601
- "pub impl Struct {}" ,
602
- ) ;
603
- assert_eq ! (
604
- stringify_item!(
605
- impl <T > Struct <T > { }
606
- ) ,
607
- "impl<T> Struct<T> {}" ,
608
- ) ;
609
- assert_eq ! (
610
- stringify_item!(
611
- pub impl Trait for Struct { }
612
- ) ,
613
- "pub impl Trait for Struct {}" ,
614
- ) ;
615
- assert_eq ! (
616
- stringify_item!(
617
- impl <T > const Trait for T { }
618
- ) ,
515
+ c1 ! ( item, [ pub impl Struct { } ] , "pub impl Struct {}" ) ;
516
+ c2 ! ( item, [ impl <T > Struct <T > { } ] , "impl<T> Struct<T> {}" , "impl < T > Struct < T > {}" ) ;
517
+ c1 ! ( item, [ pub impl Trait for Struct { } ] , "pub impl Trait for Struct {}" ) ;
518
+ c2 ! ( item,
519
+ [ impl <T > const Trait for T { } ] ,
619
520
"impl<T> const Trait for T {}" ,
521
+ "impl < T > const Trait for T {}"
620
522
) ;
621
- assert_eq ! (
622
- stringify_item!(
623
- impl ~const Struct { }
624
- ) ,
625
- "impl ~const Struct {}" ,
626
- ) ;
523
+ c2 ! ( item, [ impl ~const Struct { } ] , "impl ~const Struct {}" , "impl ~ const Struct {}" ) ;
627
524
628
525
// ItemKind::MacCall
629
- assert_eq ! ( stringify_item! ( mac!( ...) ; ) , "mac!(...);" ) ;
630
- assert_eq ! ( stringify_item! ( mac![ ...] ; ) , "mac![...];" ) ;
631
- assert_eq ! ( stringify_item! ( mac! { ... } ) , "mac! { ... }" ) ;
526
+ c2 ! ( item , [ mac! ( ... ) ; ] , " mac!(...);" , "mac! (...) ;" ) ;
527
+ c2 ! ( item , [ mac! [ ... ] ; ] , " mac![...];" , "mac! [...] ;" ) ;
528
+ c1 ! ( item , [ mac! { ... } ] , "mac! { ... }" ) ;
632
529
633
530
// ItemKind::MacroDef
634
- assert_eq ! (
635
- stringify_item! (
531
+ c1 ! ( item ,
532
+ [
636
533
macro_rules! stringify {
637
534
( ) => { } ;
638
535
}
639
- ) ,
640
- "macro_rules! stringify { () => {} ; }" , // FIXME
536
+ ] ,
537
+ "macro_rules! stringify { () => {} ; }"
641
538
) ;
642
- assert_eq ! (
643
- stringify_item!(
644
- pub macro stringify( ) { }
645
- ) ,
646
- "pub macro stringify { () => {} }" ,
539
+ c2 ! ( item,
540
+ [ pub macro stringify( ) { } ] ,
541
+ "pub macro stringify { () => {} }" , // ??
542
+ "pub macro stringify() {}"
647
543
) ;
648
544
}
649
545
650
546
#[ test]
651
547
fn test_meta ( ) {
652
- assert_eq ! ( stringify_meta! ( k ) , "k" ) ;
653
- assert_eq ! ( stringify_meta! ( k = "v" ) , "k = \" v\" " ) ;
654
- assert_eq ! ( stringify_meta! ( list( k1, k2 = "v" ) ) , "list(k1, k2 = \" v\" )" ) ;
655
- assert_eq ! ( stringify_meta! ( serde:: k) , "serde::k" ) ;
548
+ c1 ! ( meta , [ k ] , "k" ) ;
549
+ c1 ! ( meta , [ k = "v" ] , "k = \" v\" " ) ;
550
+ c1 ! ( meta , [ list( k1, k2 = "v" ) ] , "list(k1, k2 = \" v\" )" ) ;
551
+ c2 ! ( meta , [ serde:: k ] , "serde::k" , "serde :: k") ;
656
552
}
657
553
658
554
#[ test]
659
555
fn test_pat ( ) {
660
556
// PatKind::Wild
661
- assert_eq ! ( stringify_pat! ( _ ) , "_" ) ;
557
+ c1 ! ( pat , [ _ ] , "_" ) ;
662
558
663
559
// PatKind::Ident
664
- assert_eq ! ( stringify_pat! ( _x ) , "_x" ) ;
665
- assert_eq ! ( stringify_pat! ( ref _x) , "ref _x" ) ;
666
- assert_eq ! ( stringify_pat! ( mut _x) , "mut _x" ) ;
667
- assert_eq ! ( stringify_pat! ( ref mut _x) , "ref mut _x" ) ;
668
- assert_eq ! ( stringify_pat! ( ref mut _x @ _) , "ref mut _x @ _" ) ;
560
+ c1 ! ( pat , [ _x ] , "_x" ) ;
561
+ c1 ! ( pat , [ ref _x ] , "ref _x" ) ;
562
+ c1 ! ( pat , [ mut _x ] , "mut _x" ) ;
563
+ c1 ! ( pat , [ ref mut _x ] , "ref mut _x" ) ;
564
+ c1 ! ( pat , [ ref mut _x @ _ ] , "ref mut _x @ _" ) ;
669
565
670
566
// PatKind::Struct
671
- assert_eq ! ( stringify_pat!( Struct { } ) , "Struct {}" ) ;
672
- assert_eq ! ( stringify_pat!( Struct :: <u8 > { } ) , "Struct::<u8> {}" ) ;
673
- assert_eq ! ( stringify_pat!( Struct :: <' static > { } ) , "Struct::<'static> {}" ) ;
674
- assert_eq ! ( stringify_pat!( Struct { x } ) , "Struct { x }" ) ;
675
- assert_eq ! ( stringify_pat!( Struct { x: _x } ) , "Struct { x: _x }" ) ;
676
- assert_eq ! ( stringify_pat!( Struct { .. } ) , "Struct { .. }" ) ;
677
- assert_eq ! ( stringify_pat!( Struct { x, .. } ) , "Struct { x, .. }" ) ;
678
- assert_eq ! ( stringify_pat!( Struct { x: _x, .. } ) , "Struct { x: _x, .. }" ) ;
679
- #[ rustfmt:: skip] // https://github.com/rust-lang/rustfmt/issues/5151
680
- assert_eq ! (
681
- stringify_pat!( <Struct as Trait >:: Type { } ) ,
567
+ c1 ! ( pat, [ Struct { } ] , "Struct {}" ) ;
568
+ c2 ! ( pat, [ Struct :: <u8 > { } ] , "Struct::<u8> {}" , "Struct :: < u8 > {}" ) ;
569
+ c2 ! ( pat, [ Struct :: <' static > { } ] , "Struct::<'static> {}" , "Struct :: < 'static > {}" ) ;
570
+ c1 ! ( pat, [ Struct { x } ] , "Struct { x }" ) ;
571
+ c2 ! ( pat, [ Struct { x: _x } ] , "Struct { x: _x }" , "Struct { x : _x }" ) ;
572
+ c1 ! ( pat, [ Struct { .. } ] , "Struct { .. }" ) ;
573
+ c1 ! ( pat, [ Struct { x, .. } ] , "Struct { x, .. }" ) ;
574
+ c2 ! ( pat, [ Struct { x: _x, .. } ] , "Struct { x: _x, .. }" , "Struct { x : _x, .. }" ) ;
575
+ c2 ! ( pat,
576
+ [ <Struct as Trait >:: Type { } ] ,
682
577
"<Struct as Trait>::Type {}" ,
578
+ "< Struct as Trait > :: Type {}"
683
579
) ;
684
580
685
581
// PatKind::TupleStruct
686
- assert_eq ! ( stringify_pat!( Tuple ( ) ) , "Tuple()" ) ;
687
- assert_eq ! ( stringify_pat!( Tuple :: <u8 >( ) ) , "Tuple::<u8>()" ) ;
688
- assert_eq ! ( stringify_pat!( Tuple :: <' static >( ) ) , "Tuple::<'static>()" ) ;
689
- assert_eq ! ( stringify_pat!( Tuple ( x) ) , "Tuple(x)" ) ;
690
- assert_eq ! ( stringify_pat!( Tuple ( ..) ) , "Tuple(..)" ) ;
691
- assert_eq ! ( stringify_pat!( Tuple ( x, ..) ) , "Tuple(x, ..)" ) ;
692
- assert_eq ! ( stringify_pat!( <Struct as Trait >:: Type ( ) ) , "<Struct as Trait>::Type()" ) ;
582
+ c1 ! ( pat, [ Tuple ( ) ] , "Tuple()" ) ;
583
+ c2 ! ( pat, [ Tuple :: <u8 >( ) ] , "Tuple::<u8>()" , "Tuple :: < u8 > ()" ) ;
584
+ c2 ! ( pat, [ Tuple :: <' static >( ) ] , "Tuple::<'static>()" , "Tuple :: < 'static > ()" ) ;
585
+ c1 ! ( pat, [ Tuple ( x) ] , "Tuple(x)" ) ;
586
+ c1 ! ( pat, [ Tuple ( ..) ] , "Tuple(..)" ) ;
587
+ c1 ! ( pat, [ Tuple ( x, ..) ] , "Tuple(x, ..)" ) ;
588
+ c2 ! ( pat,
589
+ [ <Struct as Trait >:: Type ( ) ] ,
590
+ "<Struct as Trait>::Type()" ,
591
+ "< Struct as Trait > :: Type()"
592
+ ) ;
693
593
694
594
// PatKind::Or
695
- assert_eq ! ( stringify_pat! ( true | false ) , "true | false" ) ;
696
- assert_eq ! ( stringify_pat! ( | true ) , "true" ) ;
697
- assert_eq ! ( stringify_pat! ( |true | false ) , "true | false" ) ;
595
+ c1 ! ( pat , [ true | false ] , "true | false" ) ;
596
+ c2 ! ( pat , [ | true ] , "true" , "| true") ;
597
+ c2 ! ( pat , [ |true | false ] , "true | false" , "| true | false") ;
698
598
699
599
// PatKind::Path
700
- assert_eq ! ( stringify_pat! ( crate :: Path ) , "crate::Path" ) ;
701
- assert_eq ! ( stringify_pat! ( Path :: <u8 >) , "Path::<u8>" ) ;
702
- assert_eq ! ( stringify_pat! ( Path :: <' static >) , "Path::<'static>" ) ;
703
- assert_eq ! ( stringify_pat! ( <Struct as Trait >:: Type ) , "<Struct as Trait>::Type" ) ;
600
+ c2 ! ( pat , [ crate :: Path ] , "crate::Path" , "crate :: Path") ;
601
+ c2 ! ( pat , [ Path :: <u8 > ] , "Path::<u8>" , "Path :: < u8 >") ;
602
+ c2 ! ( pat , [ Path :: <' static > ] , "Path::<'static>" , "Path :: < 'static >") ;
603
+ c2 ! ( pat , [ <Struct as Trait >:: Type ] , "<Struct as Trait>::Type" , "< Struct as Trait > :: Type") ;
704
604
705
605
// PatKind::Tuple
706
- assert_eq ! ( stringify_pat! ( ( ) ) , "()" ) ;
707
- assert_eq ! ( stringify_pat! ( ( true , ) ) , "(true,)" ) ;
708
- assert_eq ! ( stringify_pat! ( ( true , false ) ) , "(true, false)" ) ;
606
+ c1 ! ( pat , [ ( ) ] , "()" ) ;
607
+ c1 ! ( pat , [ ( true , ) ] , "(true,)" ) ;
608
+ c1 ! ( pat , [ ( true , false ) ] , "(true, false)" ) ;
709
609
710
610
// PatKind::Box
711
- assert_eq ! ( stringify_pat! ( box pat) , "box pat" ) ;
611
+ c1 ! ( pat , [ box pat ] , "box pat" ) ;
712
612
713
613
// PatKind::Ref
714
- assert_eq ! ( stringify_pat! ( & pat) , "&pat" ) ;
715
- assert_eq ! ( stringify_pat! ( & mut pat) , "&mut pat" ) ;
614
+ c2 ! ( pat , [ & pat ] , "&pat" , "& pat") ;
615
+ c2 ! ( pat , [ & mut pat ] , "&mut pat" , "& mut pat") ;
716
616
717
617
// PatKind::Lit
718
- assert_eq ! ( stringify_pat! ( 1_000_i8 ) , "1_000_i8" ) ;
618
+ c1 ! ( pat , [ 1_000_i8 ] , "1_000_i8" ) ;
719
619
720
620
// PatKind::Range
721
- assert_eq ! ( stringify_pat! ( ..1 ) , "..1" ) ;
722
- assert_eq ! ( stringify_pat! ( 0 ..) , "0.." ) ;
723
- assert_eq ! ( stringify_pat! ( 0 ..1 ) , "0..1" ) ;
724
- assert_eq ! ( stringify_pat! ( 0 ..=1 ) , "0..=1" ) ;
725
- assert_eq ! ( stringify_pat! ( -2 ..=-1 ) , "-2..=-1" ) ;
621
+ c2 ! ( pat , [ ..1 ] , "..1" , ".. 1") ;
622
+ c2 ! ( pat , [ 0 .. ] , "0.." , "0 ..") ;
623
+ c2 ! ( pat , [ 0 ..1 ] , "0..1" , "0 .. 1") ;
624
+ c2 ! ( pat , [ 0 ..=1 ] , "0..=1" , "0 ..= 1") ;
625
+ c2 ! ( pat , [ -2 ..=-1 ] , "-2..=-1" , "- 2 ..= - 1") ;
726
626
727
627
// PatKind::Slice
728
- assert_eq ! ( stringify_pat! ( [ ] ) , "[]" ) ;
729
- assert_eq ! ( stringify_pat! ( [ true ] ) , "[true]" ) ;
730
- assert_eq ! ( stringify_pat! ( [ true , ] ) , "[true]" ) ;
731
- assert_eq ! ( stringify_pat! ( [ true , false ] ) , "[true, false]" ) ;
628
+ c1 ! ( pat , [ [ ] ] , "[]" ) ;
629
+ c1 ! ( pat , [ [ true ] ] , "[true]" ) ;
630
+ c2 ! ( pat , [ [ true , ] ] , "[true]" , "[true, ]") ;
631
+ c1 ! ( pat , [ [ true , false ] ] , "[true, false]" ) ;
732
632
733
633
// PatKind::Rest
734
- assert_eq ! ( stringify_pat! ( .. ) , ".." ) ;
634
+ c1 ! ( pat , [ .. ] , ".." ) ;
735
635
736
636
// PatKind::Paren
737
- assert_eq ! ( stringify_pat! ( ( pat) ) , "(pat)" ) ;
637
+ c1 ! ( pat , [ ( pat) ] , "(pat)" ) ;
738
638
739
639
// PatKind::MacCall
740
- assert_eq ! ( stringify_pat! ( mac!( ...) ) , "mac!(...)" ) ;
741
- assert_eq ! ( stringify_pat! ( mac![ ...] ) , "mac![...]" ) ;
742
- assert_eq ! ( stringify_pat! ( mac! { ... } ) , "mac! { ... }" ) ;
640
+ c2 ! ( pat , [ mac! ( ... ) ] , " mac!(...)" , "mac! (...)" ) ;
641
+ c2 ! ( pat , [ mac! [ ... ] ] , " mac![...]" , "mac! [...]" ) ;
642
+ c1 ! ( pat , [ mac! { ... } ] , "mac! { ... }" ) ;
743
643
}
744
644
745
645
#[ test]
746
646
fn test_path ( ) {
747
- assert_eq ! ( stringify_path! ( thing) , "thing" ) ;
748
- assert_eq ! ( stringify_path! ( m:: thing) , "m::thing" ) ;
749
- assert_eq ! ( stringify_path! ( self :: thing) , "self::thing" ) ;
750
- assert_eq ! ( stringify_path! ( crate :: thing) , "crate::thing" ) ;
751
- assert_eq ! ( stringify_path! ( Self :: thing) , "Self::thing" ) ;
752
- assert_eq ! ( stringify_path! ( Self <' static >) , "Self<'static>" ) ;
753
- assert_eq ! ( stringify_path! ( Self :: <' static >) , "Self<'static>" ) ;
754
- assert_eq ! ( stringify_path! ( Self ( ) ) , "Self()" ) ;
755
- assert_eq ! ( stringify_path! ( Self ( ) -> ( ) ) , "Self() -> ()" ) ;
647
+ c1 ! ( path , [ thing ] , "thing" ) ;
648
+ c2 ! ( path , [ m:: thing ] , "m::thing" , "m :: thing") ;
649
+ c2 ! ( path , [ self :: thing ] , "self::thing" , "self :: thing") ;
650
+ c2 ! ( path , [ crate :: thing ] , "crate::thing" , "crate :: thing") ;
651
+ c2 ! ( path , [ Self :: thing ] , "Self::thing" , "Self :: thing") ;
652
+ c2 ! ( path , [ Self <' static > ] , "Self<'static>" , "Self < 'static >") ;
653
+ c2 ! ( path , [ Self :: <' static > ] , "Self<'static>" , "Self :: < 'static >") ;
654
+ c1 ! ( path , [ Self ( ) ] , "Self()" ) ;
655
+ c1 ! ( path , [ Self ( ) -> ( ) ] , "Self() -> ()" ) ;
756
656
}
757
657
758
658
#[ test]
759
659
fn test_stmt ( ) {
760
660
// StmtKind::Local
761
- assert_eq ! ( stringify_stmt!( let _) , "let _;" ) ;
762
- assert_eq ! ( stringify_stmt!( let x = true ) , "let x = true;" ) ;
763
- assert_eq ! ( stringify_stmt!( let x: bool = true ) , "let x: bool = true;" ) ;
661
+ c2 ! ( stmt, [ let _ ] , "let _;" , "let _" ) ;
662
+ c2 ! ( stmt, [ let x = true ] , "let x = true;" , "let x = true" ) ;
663
+ c2 ! ( stmt, [ let x: bool = true ] , "let x: bool = true;" , "let x : bool = true" ) ;
664
+ c2 ! ( stmt, [ let ( a, b) = ( 1 , 2 ) ] , "let (a, b) = (1, 2);" , "let(a, b) = (1, 2)" ) ; // FIXME
665
+ c2 ! ( stmt,
666
+ [ let ( a, b) : ( u32 , u32 ) = ( 1 , 2 ) ] ,
667
+ "let (a, b): (u32, u32) = (1, 2);" ,
668
+ "let(a, b) : (u32, u32) = (1, 2)"
669
+ ) ;
764
670
765
671
// StmtKind::Item
766
- assert_eq ! (
767
- stringify_stmt!(
768
- struct S ;
769
- ) ,
770
- "struct S;" ,
771
- ) ;
672
+ c2 ! ( stmt, [ struct S ; ] , "struct S;" , "struct S ;" ) ;
673
+ c1 ! ( stmt, [ struct S { } ] , "struct S {}" ) ;
772
674
773
675
// StmtKind::Expr
774
- assert_eq ! ( stringify_stmt! ( loop { } ) , "loop {}" ) ;
676
+ c1 ! ( stmt , [ loop { } ] , "loop {}" ) ;
775
677
776
678
// StmtKind::Semi
777
- assert_eq ! ( stringify_stmt! ( 1 + 1 ) , "1 + 1;" ) ;
679
+ c2 ! ( stmt , [ 1 + 1 ] , "1 + 1;" , "1 + 1 ") ;
778
680
779
681
// StmtKind::Empty
780
- assert_eq ! ( stringify_stmt! ( ; ) , ";" ) ;
682
+ c1 ! ( stmt , [ ; ] , ";" ) ;
781
683
782
684
// StmtKind::MacCall
783
- assert_eq ! ( stringify_stmt! ( mac!( ...) ) , "mac!(...)" ) ;
784
- assert_eq ! ( stringify_stmt! ( mac![ ...] ) , "mac![...]" ) ;
785
- assert_eq ! ( stringify_stmt! ( mac! { ... } ) , "mac! { ... }" ) ;
685
+ c2 ! ( stmt , [ mac! ( ... ) ] , " mac!(...)" , "mac! (...)" ) ;
686
+ c2 ! ( stmt , [ mac! [ ... ] ] , " mac![...]" , "mac! [...]" ) ;
687
+ c1 ! ( stmt , [ mac! { ... } ] , "mac! { ... }" ) ;
786
688
}
787
689
788
690
#[ test]
789
691
fn test_ty ( ) {
790
692
// TyKind::Slice
791
- assert_eq ! ( stringify_ty! ( [ T ] ) , "[T]" ) ;
693
+ c1 ! ( ty , [ [ T ] ] , "[T]" ) ;
792
694
793
695
// TyKind::Array
794
- assert_eq ! ( stringify_ty! ( [ T ; 0 ] ) , "[T; 0]" ) ;
696
+ c2 ! ( ty , [ [ T ; 0 ] ] , "[T; 0]" , "[T ; 0]") ;
795
697
796
698
// TyKind::Ptr
797
- assert_eq ! ( stringify_ty! ( * const T ) , "*const T" ) ;
798
- assert_eq ! ( stringify_ty! ( * mut T ) , "*mut T" ) ;
699
+ c2 ! ( ty , [ * const T ] , "*const T" , "* const T") ;
700
+ c2 ! ( ty , [ * mut T ] , "*mut T" , "* mut T") ;
799
701
800
702
// TyKind::Ref
801
- assert_eq ! ( stringify_ty!( & T ) , "&T" ) ;
802
- assert_eq ! ( stringify_ty!( & mut T ) , "&mut T" ) ;
803
- assert_eq ! ( stringify_ty!( & ' a T ) , "&'a T" ) ;
804
- assert_eq ! ( stringify_ty!( & ' a mut T ) , "&'a mut T" ) ;
703
+ c2 ! ( ty, [ & T ] , "&T" , "& T" ) ;
704
+ c2 ! ( ty, [ & mut T ] , "&mut T" , "& mut T" ) ;
705
+ c2 ! ( ty, [ & ' a T ] , "&'a T" , "& 'a T" ) ;
706
+ c2 ! ( ty, [ & ' a mut [ T ] ] , "&'a mut [T]" , "& 'a mut [T]" ) ;
707
+ c2 ! ( ty, [ & A <B <C <D <E >>>> ] , "&A<B<C<D<E>>>>" , "& A < B < C < D < E >> >>" ) ;
805
708
806
709
// TyKind::BareFn
807
- assert_eq ! ( stringify_ty!( fn ( ) ) , "fn()" ) ;
808
- assert_eq ! ( stringify_ty!( fn ( ) -> ( ) ) , "fn() -> ()" ) ;
809
- assert_eq ! ( stringify_ty!( fn ( u8 ) ) , "fn(u8)" ) ;
810
- assert_eq ! ( stringify_ty!( fn ( x: u8 ) ) , "fn(x: u8)" ) ;
811
- #[ rustfmt:: skip]
812
- assert_eq ! ( stringify_ty!( for <> fn ( ) ) , "fn()" ) ;
813
- assert_eq ! ( stringify_ty!( for <' a> fn ( ) ) , "for<'a> fn()" ) ;
710
+ c1 ! ( ty, [ fn ( ) ] , "fn()" ) ;
711
+ c1 ! ( ty, [ fn ( ) -> ( ) ] , "fn() -> ()" ) ;
712
+ c1 ! ( ty, [ fn ( u8 ) ] , "fn(u8)" ) ;
713
+ c2 ! ( ty, [ fn ( x: u8 ) ] , "fn(x: u8)" , "fn(x : u8)" ) ;
714
+ c2 ! ( ty, [ for <> fn ( ) ] , "fn()" , "for < > fn()" ) ;
715
+ c2 ! ( ty, [ for <' a> fn ( ) ] , "for<'a> fn()" , "for < 'a > fn()" ) ;
814
716
815
717
// TyKind::Never
816
- assert_eq ! ( stringify_ty! ( ! ) , "!" ) ;
718
+ c1 ! ( ty , [ ! ] , "!" ) ;
817
719
818
720
// TyKind::Tup
819
- assert_eq ! ( stringify_ty!( ( ) ) , "()" ) ;
820
- assert_eq ! ( stringify_ty!( ( T , ) ) , "(T,)" ) ;
821
- assert_eq ! ( stringify_ty!( ( T , U ) ) , "(T, U)" ) ;
721
+ c1 ! ( ty, [ ( ) ] , "()" ) ;
722
+ c1 ! ( ty, [ ( T , ) ] , "(T,)" ) ;
723
+ c1 ! ( ty, [ ( T , U ) ] , "(T, U)" ) ;
724
+
725
+ // TyKind::AnonStruct: untestable in isolation.
726
+
727
+ // TyKind::AnonUnion: untestable in isolation.
822
728
823
729
// TyKind::Path
824
- assert_eq ! ( stringify_ty! ( T ) , "T" ) ;
825
- assert_eq ! ( stringify_ty! ( Ref <' a>) , "Ref<'a>" ) ;
826
- assert_eq ! ( stringify_ty! ( PhantomData <T >) , "PhantomData<T>" ) ;
827
- assert_eq ! ( stringify_ty! ( PhantomData :: <T >) , "PhantomData<T>" ) ;
828
- assert_eq ! ( stringify_ty! ( Fn ( ) -> !) , "Fn() -> !" ) ;
829
- assert_eq ! ( stringify_ty! ( Fn ( u8 ) -> !) , "Fn(u8) -> !" ) ;
830
- assert_eq ! ( stringify_ty! ( <Struct as Trait >:: Type ) , "<Struct as Trait>::Type" ) ;
730
+ c1 ! ( ty , [ T ] , "T" ) ;
731
+ c2 ! ( ty , [ Ref <' a> ] , "Ref<'a>" , "Ref < 'a >") ;
732
+ c2 ! ( ty , [ PhantomData <T > ] , "PhantomData<T>" , "PhantomData < T >") ;
733
+ c2 ! ( ty , [ PhantomData :: <T > ] , "PhantomData<T>" , "PhantomData :: < T >") ;
734
+ c2 ! ( ty , [ Fn ( ) -> ! ] , "Fn() -> !" , "Fn() -> !") ;
735
+ c2 ! ( ty , [ Fn ( u8 ) -> ! ] , "Fn(u8) -> !" , "Fn(u8) ->!" ) ; // FIXME
736
+ c2 ! ( ty , [ <Struct as Trait >:: Type ] , "<Struct as Trait>::Type" , "< Struct as Trait > :: Type") ;
831
737
832
738
// TyKind::TraitObject
833
- assert_eq ! ( stringify_ty! ( dyn Send ) , "dyn Send" ) ;
834
- assert_eq ! ( stringify_ty! ( dyn Send + ' a) , "dyn Send + 'a" ) ;
835
- assert_eq ! ( stringify_ty! ( dyn ' a + Send ) , "dyn 'a + Send" ) ;
836
- assert_eq ! ( stringify_ty! ( dyn ?Sized ) , "dyn ?Sized" ) ;
837
- assert_eq ! ( stringify_ty! ( dyn ~const Clone ) , "dyn ~const Clone" ) ;
838
- assert_eq ! ( stringify_ty! ( dyn for <' a> Send ) , "dyn for<'a> Send" ) ;
739
+ c1 ! ( ty , [ dyn Send ] , "dyn Send" ) ;
740
+ c1 ! ( ty , [ dyn Send + ' a ] , "dyn Send + 'a" ) ;
741
+ c1 ! ( ty , [ dyn ' a + Send ] , "dyn 'a + Send" ) ;
742
+ c2 ! ( ty , [ dyn ?Sized ] , "dyn ?Sized" , "dyn ? Sized") ;
743
+ c2 ! ( ty , [ dyn ~const Clone ] , "dyn ~const Clone" , "dyn ~ const Clone") ;
744
+ c2 ! ( ty , [ dyn for <' a> Send ] , "dyn for<'a> Send" , "dyn for < 'a > Send") ;
839
745
840
746
// TyKind::ImplTrait
841
- assert_eq ! ( stringify_ty! ( impl Send ) , "impl Send" ) ;
842
- assert_eq ! ( stringify_ty! ( impl Send + ' a) , "impl Send + 'a" ) ;
843
- assert_eq ! ( stringify_ty! ( impl ' a + Send ) , "impl 'a + Send" ) ;
844
- assert_eq ! ( stringify_ty! ( impl ?Sized ) , "impl ?Sized" ) ;
845
- assert_eq ! ( stringify_ty! ( impl ~const Clone ) , "impl ~const Clone" ) ;
846
- assert_eq ! ( stringify_ty! ( impl for <' a> Send ) , "impl for<'a> Send" ) ;
747
+ c1 ! ( ty , [ impl Send ] , "impl Send" ) ;
748
+ c1 ! ( ty , [ impl Send + ' a ] , "impl Send + 'a" ) ;
749
+ c1 ! ( ty , [ impl ' a + Send ] , "impl 'a + Send" ) ;
750
+ c2 ! ( ty , [ impl ?Sized ] , "impl ?Sized" , "impl ? Sized") ;
751
+ c2 ! ( ty , [ impl ~const Clone ] , "impl ~const Clone" , "impl ~ const Clone") ;
752
+ c2 ! ( ty , [ impl for <' a> Send ] , "impl for<'a> Send" , "impl for < 'a > Send") ;
847
753
848
754
// TyKind::Paren
849
- assert_eq ! ( stringify_ty!( ( T ) ) , "(T)" ) ;
755
+ c1 ! ( ty, [ ( T ) ] , "(T)" ) ;
756
+
757
+ // TyKind::Typeof: unused for now.
850
758
851
759
// TyKind::Infer
852
- assert_eq ! ( stringify_ty!( _) , "_" ) ;
760
+ c1 ! ( ty, [ _ ] , "_" ) ;
761
+
762
+ // TyKind::ImplicitSelf: there is no syntax for this.
853
763
854
764
// TyKind::MacCall
855
- assert_eq ! ( stringify_ty!( mac!( ...) ) , "mac!(...)" ) ;
856
- assert_eq ! ( stringify_ty!( mac![ ...] ) , "mac![...]" ) ;
857
- assert_eq ! ( stringify_ty!( mac! { ... } ) , "mac! { ... }" ) ;
765
+ c2 ! ( ty, [ mac!( ...) ] , "mac!(...)" , "mac! (...)" ) ;
766
+ c2 ! ( ty, [ mac![ ...] ] , "mac![...]" , "mac! [...]" ) ;
767
+ c1 ! ( ty, [ mac! { ... } ] , "mac! { ... }" ) ;
768
+
769
+ // TyKind::Err: untestable.
770
+
771
+ // TyKind::CVarArgs
772
+ // FIXME: todo
858
773
}
859
774
860
775
#[ test]
861
776
fn test_vis ( ) {
862
777
// VisibilityKind::Public
863
- assert_eq ! ( stringify_vis! ( pub ) , "pub " ) ;
778
+ c2 ! ( vis , [ pub ] , "pub " , "pub ") ;
864
779
865
780
// VisibilityKind::Restricted
866
- assert_eq ! ( stringify_vis!( pub ( crate ) ) , "pub(crate) " ) ;
867
- assert_eq ! ( stringify_vis!( pub ( self ) ) , "pub(self) " ) ;
868
- assert_eq ! ( stringify_vis!( pub ( super ) ) , "pub(super) " ) ;
869
- assert_eq ! ( stringify_vis!( pub ( in crate ) ) , "pub(in crate) " ) ;
870
- assert_eq ! ( stringify_vis!( pub ( in self ) ) , "pub(in self) " ) ;
871
- assert_eq ! ( stringify_vis!( pub ( in super ) ) , "pub(in super) " ) ;
872
- assert_eq ! ( stringify_vis!( pub ( in path:: to) ) , "pub(in path::to) " ) ;
873
- assert_eq ! ( stringify_vis!( pub ( in :: path:: to) ) , "pub(in ::path::to) " ) ;
874
- assert_eq ! ( stringify_vis!( pub ( in self :: path:: to) ) , "pub(in self::path::to) " ) ;
875
- assert_eq ! ( stringify_vis!( pub ( in super :: path:: to) ) , "pub(in super::path::to) " ) ;
781
+ c2 ! ( vis, [ pub ( crate ) ] , "pub(crate) " , "pub(crate)" ) ;
782
+ c2 ! ( vis, [ pub ( self ) ] , "pub(self) " , "pub(self)" ) ;
783
+ c2 ! ( vis, [ pub ( super ) ] , "pub(super) " , "pub(super)" ) ;
784
+ c2 ! ( vis, [ pub ( in crate ) ] , "pub(in crate) " , "pub(in crate)" ) ;
785
+ c2 ! ( vis, [ pub ( in self ) ] , "pub(in self) " , "pub(in self)" ) ;
786
+ c2 ! ( vis, [ pub ( in super ) ] , "pub(in super) " , "pub(in super)" ) ;
787
+ c2 ! ( vis, [ pub ( in path:: to) ] , "pub(in path::to) " , "pub(in path :: to)" ) ;
788
+ c2 ! ( vis, [ pub ( in :: path:: to) ] , "pub(in ::path::to) " , "pub(in :: path :: to)" ) ;
789
+ c2 ! ( vis, [ pub ( in self :: path:: to) ] , "pub(in self::path::to) " , "pub(in self :: path :: to)" ) ;
790
+ c2 ! ( vis,
791
+ [ pub ( in super :: path:: to) ] ,
792
+ "pub(in super::path::to) " ,
793
+ "pub(in super :: path :: to)"
794
+ ) ;
876
795
877
796
// VisibilityKind::Inherited
878
- // Directly calling `stringify_vis!()` does not work.
879
- macro_rules! stringify_inherited_vis {
880
- ( $vis: vis struct ) => {
881
- stringify_vis!( $vis)
882
- } ;
883
- }
884
- assert_eq ! ( stringify_inherited_vis!( struct ) , "" ) ;
797
+ // This one is different because directly calling `vis!` does not work.
798
+ macro_rules! inherited_vis { ( $vis: vis struct ) => { vis!( $vis) } ; }
799
+ assert_eq ! ( inherited_vis!( struct ) , "" ) ;
800
+ assert_eq ! ( stringify!( ) , "" ) ;
885
801
}
0 commit comments