Skip to content

Commit a8f7acd

Browse files
authoredOct 26, 2023
Rollup merge of #117114 - nnethercote:improve-stringify-test, r=petrochenkov
Improve `stringify.rs` test Best reviewed one commit at a time. r? `@petrochenkov`
·
1.87.01.75.0
2 parents d09c988 + c1800fb commit a8f7acd

File tree

2 files changed

+482
-559
lines changed

2 files changed

+482
-559
lines changed
 

‎compiler/rustc_ast/src/ast.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -734,6 +734,8 @@ pub enum RangeSyntax {
734734
}
735735

736736
/// All the different flavors of pattern that Rust recognizes.
737+
//
738+
// Adding a new variant? Please update `test_pat` in `tests/ui/macros/stringify.rs`.
737739
#[derive(Clone, Encodable, Decodable, Debug)]
738740
pub enum PatKind {
739741
/// Represents a wildcard pattern (`_`).
@@ -967,6 +969,7 @@ impl Stmt {
967969
}
968970
}
969971

972+
// Adding a new variant? Please update `test_stmt` in `tests/ui/macros/stringify.rs`.
970973
#[derive(Clone, Encodable, Decodable, Debug)]
971974
pub enum StmtKind {
972975
/// A local (let) binding.
@@ -1345,6 +1348,7 @@ pub struct StructExpr {
13451348
pub rest: StructRest,
13461349
}
13471350

1351+
// Adding a new variant? Please update `test_expr` in `tests/ui/macros/stringify.rs`.
13481352
#[derive(Clone, Encodable, Decodable, Debug)]
13491353
pub enum ExprKind {
13501354
/// An array (`[a, b, c, d]`)
@@ -2015,6 +2019,8 @@ pub struct BareFnTy {
20152019
}
20162020

20172021
/// The various kinds of type recognized by the compiler.
2022+
//
2023+
// Adding a new variant? Please update `test_ty` in `tests/ui/macros/stringify.rs`.
20182024
#[derive(Clone, Encodable, Decodable, Debug)]
20192025
pub enum TyKind {
20202026
/// A variable-length slice (`[T]`).
@@ -2880,6 +2886,7 @@ pub struct ConstItem {
28802886
pub expr: Option<P<Expr>>,
28812887
}
28822888

2889+
// Adding a new variant? Please update `test_item` in `tests/ui/macros/stringify.rs`.
28832890
#[derive(Clone, Encodable, Decodable, Debug)]
28842891
pub enum ItemKind {
28852892
/// An `extern crate` item, with the optional *original* crate name if the crate was renamed.

‎tests/ui/macros/stringify.rs

Lines changed: 475 additions & 559 deletions
Original file line numberDiff line numberDiff line change
@@ -2,496 +2,441 @@
22
// edition:2021
33
// compile-flags: --test
44

5+
#![allow(incomplete_features)]
56
#![feature(async_closure)]
67
#![feature(auto_traits)]
78
#![feature(box_patterns)]
89
#![feature(const_trait_impl)]
9-
#![feature(decl_macro)]
1010
#![feature(coroutines)]
11+
#![feature(decl_macro)]
12+
#![feature(explicit_tail_calls)]
1113
#![feature(more_qualified_paths)]
1214
#![feature(raw_ref_op)]
1315
#![feature(trait_alias)]
1416
#![feature(try_blocks)]
1517
#![feature(type_ascription)]
18+
#![feature(yeet_expr)]
1619
#![deny(unused_macros)]
1720

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);
6339
};
6440
}
6541

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);
6953
};
7054
}
7155

7256
#[test]
7357
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, [ {
7962
return;
80-
}),
63+
} ],
8164
"{ return; }",
65+
"{ return ; }"
8266
);
83-
assert_eq!(
84-
stringify_block!({
67+
c2!(block,
68+
[ {
8569
let _;
8670
true
87-
}),
71+
} ],
8872
"{ let _; true }",
73+
"{ let _ ; true }"
8974
);
9075
}
9176

9277
#[test]
9378
fn test_expr() {
9479
// 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
9987

10088
// 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, [ ()() ], "()()", "() ()");
10896

10997
// 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 < _ >> ()");
112101

113102
// 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,)");
118107

119108
// 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+
);
122118

123119
// 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");
127123

128124
// 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");
132128

133129
// 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 >");
136132

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 }");
139137

140138
// 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 {
156148
} else if false {
157-
}),
158-
"if true {} else if false {}",
149+
} ],
150+
"if true {} else if false {}"
159151
);
160-
assert_eq!(
161-
stringify_expr!(if true {
152+
c1!(expr,
153+
[ if true {
162154
} else if false {
163155
} else {
164-
}),
165-
"if true {} else if false {} else {}",
156+
} ],
157+
"if true {} else if false {} else {}"
166158
);
167-
assert_eq!(
168-
stringify_expr!(if true {
159+
c2!(expr,
160+
[ if true {
169161
return;
170162
} else if false {
171163
0
172164
} else {
173165
0
174-
}),
166+
} ],
175167
"if true { return; } else if false { 0 } else { 0 }",
168+
"if true { return ; } else if false { 0 } else { 0 }"
176169
);
177170

178171
// 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 {}");
182175

183176
// 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 {}");
186179

187180
// 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 {}");
190183

191184
// 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 {
195188
Ok => 1,
196-
}),
197-
"match self { Ok => 1, }",
189+
} ],
190+
"match self { Ok => 1, }"
198191
);
199-
assert_eq!(
200-
stringify_expr!(match self {
192+
c1!(expr,
193+
[ match self {
201194
Ok => 1,
202195
Err => 0,
203-
}),
204-
"match self { Ok => 1, Err => 0, }",
196+
} ],
197+
"match self { Ok => 1, Err => 0, }"
205198
);
206199

207200
// 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??
229214

230215
// 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+
[
243222
{
244223
#![attr]
245224
}
246-
),
225+
],
247226
"{\n\
248227
\x20 #![attr]\n\
249228
}",
229+
"{ #! [attr] }"
250230
);
251231

252232
// 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 {}");
255235

256236
// ExprKind::Await
257-
assert_eq!(stringify_expr!(expr.await), "expr.await");
237+
c1!(expr, [ expr.await ], "expr.await");
258238

259239
// ExprKind::TryBlock
260-
assert_eq!(stringify_expr!(try {}), "try {}");
240+
c1!(expr, [ try {} ], "try {}");
261241

262242
// ExprKind::Assign
263-
assert_eq!(stringify_expr!(expr = true), "expr = true");
243+
c1!(expr, [ expr = true ], "expr = true");
264244

265245
// ExprKind::AssignOp
266-
assert_eq!(stringify_expr!(expr += true), "expr += true");
246+
c1!(expr, [ expr += true ], "expr += true");
267247

268248
// 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");
271251

272252
// ExprKind::Index
273-
assert_eq!(stringify_expr!(expr[true]), "expr[true]");
253+
c2!(expr, [ expr[true] ], "expr[true]", "expr [true]");
274254

275255
// 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
283266

284267
// 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 >");
292275

293276
// 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");
298281

299282
// 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");
304287

305288
// 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");
308291

309292
// 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.
312299

313300
// 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! { ... }");
317304

318305
// 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+
);
330324

331325
// ExprKind::Repeat
332-
assert_eq!(stringify_expr!([(); 0]), "[(); 0]");
326+
c2!(expr, [ [(); 0] ], "[(); 0]", "[() ; 0]");
333327

334328
// ExprKind::Paren
335-
assert_eq!(stringify_expr!((expr)), "(expr)");
329+
c1!(expr, [ (expr) ], "(expr)");
336330

337331
// ExprKind::Try
338-
assert_eq!(stringify_expr!(expr?), "expr?");
332+
c2!(expr, [ expr? ], "expr?", "expr ?");
339333

340334
// 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.
343351
}
344352

345353
#[test]
346354
fn test_item() {
347355
// 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; ],
358359
"pub extern crate self as std;",
360+
"pub extern crate self as std ;"
359361
);
360362

361363
// 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}; ],
366366
"pub use crate::{a, b::c};",
367+
"pub use crate :: { a, b :: c } ;"
367368
);
369+
c2!(item, [ pub use A::*; ], "pub use A::*;", "pub use A :: * ;");
368370

369371
// 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 : () ;");
394376

395377
// 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 : () ;");
408380

409381
// 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 >>) {}"
415395
);
416396

417397
// 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 {}");
442402

443403
// 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\" {}"
462409
);
410+
c1!(item, [ unsafe extern "C++" {} ], "unsafe extern \"C++\" {}");
411+
412+
// ItemKind::GlobalAsm: untestable because this test works pre-expansion.
463413

464414
// ItemKind::TyAlias
465-
#[rustfmt::skip]
466-
assert_eq!(
467-
stringify_item!(
415+
c2!(item,
416+
[
468417
pub default type Type<'a>: Bound
469418
where
470419
Self: 'a,
471420
= T;
472-
),
421+
],
473422
"pub default type Type<'a>: Bound where Self: 'a = T;",
423+
"pub default type Type < 'a > : Bound where Self : 'a, = T ;"
474424
);
475425

476426
// 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+
[
485430
enum Empty {
486431
Unit,
487432
Tuple(),
488433
Struct {},
489434
}
490-
),
491-
"enum Empty { Unit, Tuple(), Struct {}, }",
435+
],
436+
"enum Empty { Unit, Tuple(), Struct {}, }"
492437
);
493-
assert_eq!(
494-
stringify_item!(
438+
c2!(item,
439+
[
495440
enum Enum<T>
496441
where
497442
T: 'a,
@@ -500,386 +445,357 @@ fn test_item() {
500445
Tuple(T),
501446
Struct { t: T },
502447
}
503-
),
448+
],
504449
"enum Enum<T> where T: 'a {\n\
505450
\x20 Unit,\n\
506451
\x20 Tuple(T),\n\
507452
\x20 Struct {\n\
508453
\x20 t: T,\n\
509454
\x20 },\n\
510455
}",
456+
"enum Enum < T > where T : 'a, { Unit, Tuple(T), Struct { t : T }, }"
511457
);
512458

513459
// 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+
[
540466
struct Struct<T>
541467
where
542468
T: 'a,
543469
{
544470
t: T,
545471
}
546-
),
472+
],
547473
"struct Struct<T> where T: 'a {\n\
548474
\x20 t: T,\n\
549475
}",
476+
"struct Struct < T > where T : 'a, { t : T, }"
550477
);
551478

552479
// 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+
[
561483
union Union<T> where T: 'a {
562484
t: T,
563485
}
564-
),
486+
],
565487
"union Union<T> where T: 'a {\n\
566488
\x20 t: T,\n\
567489
}",
490+
"union Union < T > where T : 'a { t : T, }"
568491
);
569492

570493
// 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+
[
579497
trait Trait<'a>: Sized
580498
where
581499
Self: 'a,
582500
{
583501
}
584-
),
502+
],
585503
"trait Trait<'a>: Sized where Self: 'a {}",
504+
"trait Trait < 'a > : Sized where Self : 'a, {}"
586505
);
587506

588507
// 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; ],
593510
"pub trait Trait<T> = Sized where T: 'a;",
511+
"pub trait Trait < T > = Sized where T : 'a ;"
594512
);
595513

596514
// 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 {} ],
619520
"impl<T> const Trait for T {}",
521+
"impl < T > const Trait for T {}"
620522
);
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 {}");
627524

628525
// 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! { ... }");
632529

633530
// ItemKind::MacroDef
634-
assert_eq!(
635-
stringify_item!(
531+
c1!(item,
532+
[
636533
macro_rules! stringify {
637534
() => {};
638535
}
639-
),
640-
"macro_rules! stringify { () => {} ; }", // FIXME
536+
],
537+
"macro_rules! stringify { () => {} ; }"
641538
);
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() {}"
647543
);
648544
}
649545

650546
#[test]
651547
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");
656552
}
657553

658554
#[test]
659555
fn test_pat() {
660556
// PatKind::Wild
661-
assert_eq!(stringify_pat!(_), "_");
557+
c1!(pat, [ _ ], "_");
662558

663559
// 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 @ _");
669565

670566
// 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 {} ],
682577
"<Struct as Trait>::Type {}",
578+
"< Struct as Trait > :: Type {}"
683579
);
684580

685581
// 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+
);
693593

694594
// 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");
698598

699599
// 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");
704604

705605
// 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)");
709609

710610
// PatKind::Box
711-
assert_eq!(stringify_pat!(box pat), "box pat");
611+
c1!(pat, [ box pat ], "box pat");
712612

713613
// 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");
716616

717617
// PatKind::Lit
718-
assert_eq!(stringify_pat!(1_000_i8), "1_000_i8");
618+
c1!(pat, [ 1_000_i8 ], "1_000_i8");
719619

720620
// 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");
726626

727627
// 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]");
732632

733633
// PatKind::Rest
734-
assert_eq!(stringify_pat!(..), "..");
634+
c1!(pat, [ .. ], "..");
735635

736636
// PatKind::Paren
737-
assert_eq!(stringify_pat!((pat)), "(pat)");
637+
c1!(pat, [ (pat) ], "(pat)");
738638

739639
// 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! { ... }");
743643
}
744644

745645
#[test]
746646
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() -> ()");
756656
}
757657

758658
#[test]
759659
fn test_stmt() {
760660
// 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+
);
764670

765671
// 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 {}");
772674

773675
// StmtKind::Expr
774-
assert_eq!(stringify_stmt!(loop {}), "loop {}");
676+
c1!(stmt, [ loop {} ], "loop {}");
775677

776678
// StmtKind::Semi
777-
assert_eq!(stringify_stmt!(1 + 1), "1 + 1;");
679+
c2!(stmt, [ 1 + 1 ], "1 + 1;", "1 + 1");
778680

779681
// StmtKind::Empty
780-
assert_eq!(stringify_stmt!(;), ";");
682+
c1!(stmt, [ ; ], ";");
781683

782684
// 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! { ... }");
786688
}
787689

788690
#[test]
789691
fn test_ty() {
790692
// TyKind::Slice
791-
assert_eq!(stringify_ty!([T]), "[T]");
693+
c1!(ty, [ [T] ], "[T]");
792694

793695
// TyKind::Array
794-
assert_eq!(stringify_ty!([T; 0]), "[T; 0]");
696+
c2!(ty, [ [T; 0] ], "[T; 0]", "[T ; 0]");
795697

796698
// 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");
799701

800702
// 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 >> >>");
805708

806709
// 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()");
814716

815717
// TyKind::Never
816-
assert_eq!(stringify_ty!(!), "!");
718+
c1!(ty, [ ! ], "!");
817719

818720
// 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.
822728

823729
// 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");
831737

832738
// 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");
839745

840746
// 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");
847753

848754
// TyKind::Paren
849-
assert_eq!(stringify_ty!((T)), "(T)");
755+
c1!(ty, [ (T) ], "(T)");
756+
757+
// TyKind::Typeof: unused for now.
850758

851759
// TyKind::Infer
852-
assert_eq!(stringify_ty!(_), "_");
760+
c1!(ty, [ _ ], "_");
761+
762+
// TyKind::ImplicitSelf: there is no syntax for this.
853763

854764
// 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
858773
}
859774

860775
#[test]
861776
fn test_vis() {
862777
// VisibilityKind::Public
863-
assert_eq!(stringify_vis!(pub), "pub ");
778+
c2!(vis, [ pub ], "pub ", "pub");
864779

865780
// 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+
);
876795

877796
// 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!(), "");
885801
}

0 commit comments

Comments
 (0)
Please sign in to comment.