Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 80deabd

Browse files
committedJan 31, 2024
Auto merge of #120227 - nnethercote:further-improve-space_between, r=petrochenkov
Further improve `space_between` `space_between` is used by `print_tts` to decide when spaces should be put between tokens. This PR improves it in two ways: - avoid unnecessary spaces before semicolons, and - don't omit some necessary spaces before/after some punctuation symbols. r? `@petrochenkov`
2 parents cb4d9a1 + 1fbabee commit 80deabd

28 files changed

+102
-109
lines changed
 

‎compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -160,31 +160,46 @@ fn space_between(tt1: &TokenTree, tt2: &TokenTree) -> bool {
160160
use TokenTree::Delimited as Del;
161161
use TokenTree::Token as Tok;
162162

163+
fn is_punct(tt: &TokenTree) -> bool {
164+
matches!(tt, TokenTree::Token(tok, _) if tok.is_punct())
165+
}
166+
163167
// Each match arm has one or more examples in comments. The default is to
164168
// insert space between adjacent tokens, except for the cases listed in
165169
// this match.
166170
match (tt1, tt2) {
167171
// No space after line doc comments.
168172
(Tok(Token { kind: DocComment(CommentKind::Line, ..), .. }, _), _) => false,
169173

170-
// `.` + ANYTHING: `x.y`, `tup.0`
171-
// `$` + ANYTHING: `$e`
172-
(Tok(Token { kind: Dot | Dollar, .. }, _), _) => false,
173-
174-
// ANYTHING + `,`: `foo,`
175-
// ANYTHING + `.`: `x.y`, `tup.0`
176-
// ANYTHING + `!`: `foo! { ... }`
177-
//
178-
// FIXME: Incorrect cases:
179-
// - Logical not: `x =! y`, `if! x { f(); }`
180-
// - Never type: `Fn() ->!`
181-
(_, Tok(Token { kind: Comma | Dot | Not, .. }, _)) => false,
182-
183-
// IDENT + `(`: `f(3)`
184-
//
185-
// FIXME: Incorrect cases:
186-
// - Let: `let(a, b) = (1, 2)`
187-
(Tok(Token { kind: Ident(..), .. }, _), Del(_, _, Parenthesis, _)) => false,
174+
// `.` + NON-PUNCT: `x.y`, `tup.0`
175+
(Tok(Token { kind: Dot, .. }, _), tt2) if !is_punct(tt2) => false,
176+
177+
// `$` + IDENT: `$e`
178+
(Tok(Token { kind: Dollar, .. }, _), Tok(Token { kind: Ident(..), .. }, _)) => false,
179+
180+
// NON-PUNCT + `,`: `foo,`
181+
// NON-PUNCT + `;`: `x = 3;`, `[T; 3]`
182+
// NON-PUNCT + `.`: `x.y`, `tup.0`
183+
(tt1, Tok(Token { kind: Comma | Semi | Dot, .. }, _)) if !is_punct(tt1) => false,
184+
185+
// IDENT + `!`: `println!()`, but `if !x { ... }` needs a space after the `if`
186+
(Tok(Token { kind: Ident(sym, is_raw), span }, _), Tok(Token { kind: Not, .. }, _))
187+
if !Ident::new(*sym, *span).is_reserved() || *is_raw =>
188+
{
189+
false
190+
}
191+
192+
// IDENT|`fn`|`Self`|`pub` + `(`: `f(3)`, `fn(x: u8)`, `Self()`, `pub(crate)`,
193+
// but `let (a, b) = (1, 2)` needs a space after the `let`
194+
(Tok(Token { kind: Ident(sym, is_raw), span }, _), Del(_, _, Parenthesis, _))
195+
if !Ident::new(*sym, *span).is_reserved()
196+
|| *sym == kw::Fn
197+
|| *sym == kw::SelfUpper
198+
|| *sym == kw::Pub
199+
|| *is_raw =>
200+
{
201+
false
202+
}
188203

189204
// `#` + `[`: `#[attr]`
190205
(Tok(Token { kind: Pound, .. }, _), Del(_, _, Bracket, _)) => false,

‎tests/pretty/delimited-token-groups.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ mac! {
99
{
1010
fn clone() -> S
1111
{
12-
panic! () ;
12+
panic! ();
1313

1414
}
1515
}

‎tests/pretty/macro_rules.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
// pp-exact
22

3-
macro_rules! brace { () => {} ; }
3+
macro_rules! brace { () => {}; }
44

5-
macro_rules! bracket[() => {} ;];
5+
macro_rules! bracket[() => {};];
66

7-
macro_rules! paren(() => {} ;);
7+
macro_rules! paren(() => {};);
88

99
macro_rules! matcher_brackets {
10-
(paren) => {} ; (bracket) => {} ; (brace) => {} ;
10+
(paren) => {}; (bracket) => {}; (brace) => {};
1111
}
1212

1313
macro_rules! all_fragments {
1414
($b : block, $e : expr, $i : ident, $it : item, $l : lifetime, $lit :
1515
literal, $m : meta, $p : pat, $pth : path, $s : stmt, $tt : tt, $ty : ty,
16-
$vis : vis) => {} ;
16+
$vis : vis) => {};
1717
}
1818

1919
fn main() {}

‎tests/pretty/stmt_expr_attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ fn _8() {
113113
}
114114

115115
fn _9() {
116-
macro_rules! stmt_mac { () => { let _ = () ; } }
116+
macro_rules! stmt_mac { () => { let _ = (); } }
117117

118118
#[rustc_dummy]
119119
stmt_mac!();

‎tests/ui/macros/stringify.rs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,9 @@ fn test_expr() {
107107
c1!(expr, [ true || false ], "true || false");
108108
c1!(expr, [ true || false && false ], "true || false && false");
109109
c1!(expr, [ a < 1 && 2 < b && c > 3 && 4 > d ], "a < 1 && 2 < b && c > 3 && 4 > d");
110-
c2!(expr, [ a & b & !c ], "a & b & !c", "a & b &!c"); // FIXME
110+
c1!(expr, [ a & b & !c ], "a & b & !c");
111111
c1!(expr, [ a + b * c - d + -1 * -2 - -3], "a + b * c - d + -1 * -2 - -3");
112-
c2!(expr, [ x = !y ], "x = !y", "x =!y"); // FIXME
112+
c1!(expr, [ x = !y ], "x = !y");
113113

114114
// ExprKind::Unary
115115
c1!(expr, [ *expr ], "*expr");
@@ -141,15 +141,14 @@ fn test_expr() {
141141
"if let _ = (true && false) {}",
142142
"if let _ = true && false {}",
143143
);
144-
c2!(expr,
144+
c1!(expr,
145145
[ match () { _ if let _ = Struct {} => {} } ],
146-
"match () { _ if let _ = Struct {} => {} }",
147-
"match() { _ if let _ = Struct {} => {} }",
146+
"match () { _ if let _ = Struct {} => {} }"
148147
);
149148

150149
// ExprKind::If
151150
c1!(expr, [ if true {} ], "if true {}");
152-
c2!(expr, [ if !true {} ], "if !true {}", "if!true {}"); // FIXME
151+
c1!(expr, [ if !true {} ], "if !true {}");
153152
c1!(expr, [ if ::std::blah() { } else { } ], "if ::std::blah() {} else {}");
154153
c1!(expr, [ if let true = true {} else {} ], "if let true = true {} else {}");
155154
c1!(expr,
@@ -212,7 +211,7 @@ fn test_expr() {
212211
c2_match_arm!(
213212
[ { 1 } - 1 ],
214213
"match () { _ => ({ 1 }) - 1, }",
215-
"match() { _ => { 1 } - 1 }",
214+
"match () { _ => { 1 } - 1 }",
216215
);
217216

218217
// ExprKind::Closure
@@ -655,11 +654,11 @@ fn test_stmt() {
655654
c2!(stmt, [ let _ ], "let _;", "let _");
656655
c2!(stmt, [ let x = true ], "let x = true;", "let x = true");
657656
c2!(stmt, [ let x: bool = true ], "let x: bool = true;", "let x: bool = true");
658-
c2!(stmt, [ let (a, b) = (1, 2) ], "let (a, b) = (1, 2);", "let(a, b) = (1, 2)"); // FIXME
657+
c2!(stmt, [ let (a, b) = (1, 2) ], "let (a, b) = (1, 2);", "let (a, b) = (1, 2)");
659658
c2!(stmt,
660659
[ let (a, b): (u32, u32) = (1, 2) ],
661660
"let (a, b): (u32, u32) = (1, 2);",
662-
"let(a, b): (u32, u32) = (1, 2)" // FIXME
661+
"let (a, b): (u32, u32) = (1, 2)"
663662
);
664663
macro_rules! c2_let_expr_minus_one {
665664
([ $expr:expr ], $stmt_expected:expr, $tokens_expected:expr $(,)?) => {
@@ -776,8 +775,8 @@ fn test_ty() {
776775
c1!(ty, [ Ref<'a> ], "Ref<'a>");
777776
c1!(ty, [ PhantomData<T> ], "PhantomData<T>");
778777
c2!(ty, [ PhantomData::<T> ], "PhantomData<T>", "PhantomData::<T>");
779-
c2!(ty, [ Fn() -> ! ], "Fn() -> !", "Fn() ->!");
780-
c2!(ty, [ Fn(u8) -> ! ], "Fn(u8) -> !", "Fn(u8) ->!"); // FIXME
778+
c1!(ty, [ Fn() -> ! ], "Fn() -> !");
779+
c1!(ty, [ Fn(u8) -> ! ], "Fn(u8) -> !");
781780
c1!(ty, [ <Struct as Trait>::Type ], "<Struct as Trait>::Type");
782781

783782
// TyKind::TraitObject
@@ -857,16 +856,16 @@ fn test_punct() {
857856
// Otherwise, any old proc macro that parses pretty-printed code might glue
858857
// together tokens that shouldn't be glued.
859858
p!([ = = < < <= <= == == != != >= >= > > ], "= = < < <= <= == == != != >= >= > >");
860-
p!([ && && & & || || | | ! ! ], "&& && & & || || | |!!"); // FIXME
859+
p!([ && && & & || || | | ! ! ], "&& && & & || || | | ! !");
861860
p!([ ~ ~ @ @ # # ], "~ ~ @ @ # #");
862-
p!([ . . .. .. ... ... ..= ..=], ".... .. ... ... ..= ..="); // FIXME
863-
p!([ , , ; ; : : :: :: ], ",, ; ; : : :: ::"); // FIXME
861+
p!([ . . .. .. ... ... ..= ..=], ". . .. .. ... ... ..= ..=");
862+
p!([ , , ; ; : : :: :: ], ", , ; ; : : :: ::");
864863
p!([ -> -> <- <- => =>], "-> -> <- <- => =>");
865-
p!([ $ $ ? ? ' ' ], "$$? ? ' '"); // FIXME
864+
p!([ $ $ ? ? ' ' ], "$ $ ? ? ' '");
866865
p!([ + + += += - - -= -= * * *= *= / / /= /= ], "+ + += += - - -= -= * * *= *= / / /= /=");
867866
p!([ % % %= %= ^ ^ ^= ^= << << <<= <<= >> >> >>= >>= ],
868867
"% % %= %= ^ ^ ^= ^= << << <<= <<= >> >> >>= >>=");
869-
p!([ +! ?= |> >>@ --> <-- $$ =====> ], "+! ?= |> >>@ --> <-- $$=====>");
870-
p!([ ,; ;, ** @@ $+$ >< <> ?? +== ], ",; ;, ** @@ $+$>< <> ?? +=="); // FIXME: `$ >` -> `$>`
868+
p!([ +! ?= |> >>@ --> <-- $$ =====> ], "+! ?= |> >>@ --> <-- $$ =====>");
869+
p!([ ,; ;, ** @@ $+$ >< <> ?? +== ], ",; ;, ** @@ $+$ >< <> ?? +==");
871870
p!([ :#!@|$=&*,+;*~? ], ":#!@|$=&*,+;*~?");
872871
}

‎tests/ui/macros/trace_faulty_macros.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ LL | test!(let x = 1+1);
111111
= note: expanding `test! { let x = 1+1 }`
112112
= note: to `test! ((x, 1 + 1))`
113113
= note: expanding `test! { (x, 1 + 1) }`
114-
= note: to `let x = 1 + 1 ;`
114+
= note: to `let x = 1 + 1;`
115115

116116
error: aborting due to 5 previous errors
117117

‎tests/ui/proc-macro/allowed-attr-stmt-expr.stdout

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
PRINT-ATTR INPUT (DISPLAY): struct ItemWithSemi;
2-
PRINT-ATTR RE-COLLECTED (DISPLAY): struct ItemWithSemi ;
32
PRINT-ATTR INPUT (DEBUG): TokenStream [
43
Ident {
54
ident: "struct",
@@ -47,7 +46,6 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
4746
},
4847
]
4948
PRINT-ATTR INPUT (DISPLAY): #[expect_let] let string = "Hello, world!";
50-
PRINT-ATTR RE-COLLECTED (DISPLAY): #[expect_let] let string = "Hello, world!" ;
5149
PRINT-ATTR INPUT (DEBUG): TokenStream [
5250
Punct {
5351
ch: '#',
@@ -90,7 +88,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
9088
},
9189
]
9290
PRINT-ATTR INPUT (DISPLAY): #[expect_my_macro_stmt] my_macro!("{}", string);
93-
PRINT-ATTR RE-COLLECTED (DISPLAY): #[expect_my_macro_stmt] my_macro! ("{}", string) ;
91+
PRINT-ATTR RE-COLLECTED (DISPLAY): #[expect_my_macro_stmt] my_macro! ("{}", string);
9492
PRINT-ATTR INPUT (DEBUG): TokenStream [
9593
Punct {
9694
ch: '#',
@@ -144,7 +142,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
144142
},
145143
]
146144
PRINT-ATTR INPUT (DISPLAY): second_make_stmt!(#[allow(dead_code)] struct Bar {});
147-
PRINT-ATTR RE-COLLECTED (DISPLAY): second_make_stmt! (#[allow(dead_code)] struct Bar {}) ;
145+
PRINT-ATTR RE-COLLECTED (DISPLAY): second_make_stmt! (#[allow(dead_code)] struct Bar {});
148146
PRINT-ATTR INPUT (DEBUG): TokenStream [
149147
Ident {
150148
ident: "second_make_stmt",
@@ -293,7 +291,6 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
293291
},
294292
]
295293
PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct NonBracedStruct;
296-
PRINT-ATTR RE-COLLECTED (DISPLAY): #[rustc_dummy] struct NonBracedStruct ;
297294
PRINT-ATTR INPUT (DEBUG): TokenStream [
298295
Punct {
299296
ch: '#',

‎tests/ui/proc-macro/attr-stmt-expr.stdout

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
3030
},
3131
]
3232
PRINT-ATTR INPUT (DISPLAY): #[expect_let] let string = "Hello, world!";
33-
PRINT-ATTR RE-COLLECTED (DISPLAY): #[expect_let] let string = "Hello, world!" ;
3433
PRINT-ATTR INPUT (DEBUG): TokenStream [
3534
Punct {
3635
ch: '#',
@@ -73,7 +72,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
7372
},
7473
]
7574
PRINT-ATTR INPUT (DISPLAY): #[expect_my_macro_stmt] my_macro!("{}", string);
76-
PRINT-ATTR RE-COLLECTED (DISPLAY): #[expect_my_macro_stmt] my_macro! ("{}", string) ;
75+
PRINT-ATTR RE-COLLECTED (DISPLAY): #[expect_my_macro_stmt] my_macro! ("{}", string);
7776
PRINT-ATTR INPUT (DEBUG): TokenStream [
7877
Punct {
7978
ch: '#',
@@ -127,7 +126,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
127126
},
128127
]
129128
PRINT-ATTR INPUT (DISPLAY): second_make_stmt!(#[allow(dead_code)] struct Bar {});
130-
PRINT-ATTR RE-COLLECTED (DISPLAY): second_make_stmt! (#[allow(dead_code)] struct Bar {}) ;
129+
PRINT-ATTR RE-COLLECTED (DISPLAY): second_make_stmt! (#[allow(dead_code)] struct Bar {});
131130
PRINT-ATTR INPUT (DEBUG): TokenStream [
132131
Ident {
133132
ident: "second_make_stmt",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
fn main() { let y : u32 = "z" ; { let x: u32 = "y"; } }
1+
fn main() { let y : u32 = "z"; { let x: u32 = "y"; } }

‎tests/ui/proc-macro/auxiliary/attr-stmt-expr.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ use proc_macro::TokenStream;
1010
#[proc_macro_attribute]
1111
pub fn expect_let(attr: TokenStream, item: TokenStream) -> TokenStream {
1212
assert!(attr.to_string().is_empty());
13-
assert_eq!(item.to_string(), "let string = \"Hello, world!\" ;");
13+
assert_eq!(item.to_string(), "let string = \"Hello, world!\";");
1414
item
1515
}
1616

1717
#[proc_macro_attribute]
1818
pub fn expect_my_macro_stmt(attr: TokenStream, item: TokenStream) -> TokenStream {
1919
assert!(attr.to_string().is_empty());
20-
assert_eq!(item.to_string(), "my_macro! (\"{}\", string) ;");
20+
assert_eq!(item.to_string(), "my_macro! (\"{}\", string);");
2121
item
2222
}
2323

‎tests/ui/proc-macro/cfg-eval-inner.stdout

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ PRINT-ATTR RE-COLLECTED (DISPLAY): impl Foo <
1111
{ field: [u8; { #![rustc_dummy(another_cursed_inner)] 1 }] } 0
1212
}] > { #![rustc_dummy(evaluated_attr)] fn bar() {} }
1313
PRINT-ATTR DEEP-RE-COLLECTED (DISPLAY): impl Foo <
14-
[u8 ;
14+
[u8;
1515
{
1616
#! [rustc_dummy(cursed_inner)] #! [allow(unused)] struct Inner
17-
{ field : [u8 ; { #! [rustc_dummy(another_cursed_inner)] 1 }] } 0
17+
{ field : [u8; { #! [rustc_dummy(another_cursed_inner)] 1 }] } 0
1818
}] > { #! [rustc_dummy(evaluated_attr)] fn bar() {} }
1919
PRINT-ATTR INPUT (DEBUG): TokenStream [
2020
Ident {

‎tests/ui/proc-macro/doc-comment-preserved.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ PRINT-BANG INPUT (DISPLAY): /**
66
*******
77
*/
88
pub struct S;
9-
PRINT-BANG RE-COLLECTED (DISPLAY): #[doc = "\n*******\n* DOC *\n* DOC *\n* DOC *\n*******\n"] pub struct S ;
9+
PRINT-BANG RE-COLLECTED (DISPLAY): #[doc = "\n*******\n* DOC *\n* DOC *\n* DOC *\n*******\n"] pub struct S;
1010
PRINT-BANG INPUT (DEBUG): TokenStream [
1111
Punct {
1212
ch: '#',

‎tests/ui/proc-macro/dollar-crate-issue-57089.stdout

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
PRINT-BANG INPUT (DISPLAY): struct M($crate :: S);
2-
PRINT-BANG RE-COLLECTED (DISPLAY): struct M($crate :: S) ;
32
PRINT-BANG INPUT (DEBUG): TokenStream [
43
Ident {
54
ident: "struct",
@@ -40,7 +39,6 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
4039
},
4140
]
4241
PRINT-ATTR INPUT (DISPLAY): struct A($crate :: S);
43-
PRINT-ATTR RE-COLLECTED (DISPLAY): struct A($crate :: S) ;
4442
PRINT-ATTR INPUT (DEBUG): TokenStream [
4543
Ident {
4644
ident: "struct",

‎tests/ui/proc-macro/dollar-crate-issue-62325.stdout

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
PRINT-ATTR INPUT (DISPLAY): struct A(identity! ($crate :: S));
2-
PRINT-ATTR RE-COLLECTED (DISPLAY): struct A(identity! ($crate :: S)) ;
32
PRINT-ATTR INPUT (DEBUG): TokenStream [
43
Ident {
54
ident: "struct",
@@ -55,7 +54,6 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
5554
},
5655
]
5756
PRINT-ATTR INPUT (DISPLAY): struct B(identity! ($crate :: S));
58-
PRINT-ATTR RE-COLLECTED (DISPLAY): struct B(identity! ($crate :: S)) ;
5957
PRINT-ATTR INPUT (DEBUG): TokenStream [
6058
Ident {
6159
ident: "struct",

‎tests/ui/proc-macro/dollar-crate.stdout

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
PRINT-BANG INPUT (DISPLAY): struct M($crate :: S);
2-
PRINT-BANG RE-COLLECTED (DISPLAY): struct M($crate :: S) ;
32
PRINT-BANG INPUT (DEBUG): TokenStream [
43
Ident {
54
ident: "struct",
@@ -40,7 +39,6 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
4039
},
4140
]
4241
PRINT-ATTR INPUT (DISPLAY): struct A($crate :: S);
43-
PRINT-ATTR RE-COLLECTED (DISPLAY): struct A($crate :: S) ;
4442
PRINT-ATTR INPUT (DEBUG): TokenStream [
4543
Ident {
4644
ident: "struct",
@@ -81,7 +79,6 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
8179
},
8280
]
8381
PRINT-DERIVE INPUT (DISPLAY): struct D($crate :: S);
84-
PRINT-DERIVE RE-COLLECTED (DISPLAY): struct D($crate :: S) ;
8582
PRINT-DERIVE INPUT (DEBUG): TokenStream [
8683
Ident {
8784
ident: "struct",
@@ -122,7 +119,6 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
122119
},
123120
]
124121
PRINT-BANG INPUT (DISPLAY): struct M($crate :: S);
125-
PRINT-BANG RE-COLLECTED (DISPLAY): struct M($crate :: S) ;
126122
PRINT-BANG INPUT (DEBUG): TokenStream [
127123
Ident {
128124
ident: "struct",
@@ -163,7 +159,6 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
163159
},
164160
]
165161
PRINT-ATTR INPUT (DISPLAY): struct A($crate :: S);
166-
PRINT-ATTR RE-COLLECTED (DISPLAY): struct A($crate :: S) ;
167162
PRINT-ATTR INPUT (DEBUG): TokenStream [
168163
Ident {
169164
ident: "struct",
@@ -204,7 +199,6 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
204199
},
205200
]
206201
PRINT-DERIVE INPUT (DISPLAY): struct D($crate :: S);
207-
PRINT-DERIVE RE-COLLECTED (DISPLAY): struct D($crate :: S) ;
208202
PRINT-DERIVE INPUT (DEBUG): TokenStream [
209203
Ident {
210204
ident: "struct",

‎tests/ui/proc-macro/expand-to-derive.stdout

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
PRINT-DERIVE INPUT (DISPLAY): struct Foo
22
{
33
field :
4-
[bool ; { #[rustc_dummy] struct Inner { other_inner_field: u8, } 0 }]
4+
[bool; { #[rustc_dummy] struct Inner { other_inner_field: u8, } 0 }]
55
}
66
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): struct Foo
77
{
88
field :
9-
[bool ; { #[rustc_dummy] struct Inner { other_inner_field : u8, } 0 }]
9+
[bool; { #[rustc_dummy] struct Inner { other_inner_field : u8, } 0 }]
1010
}
1111
PRINT-DERIVE INPUT (DEBUG): TokenStream [
1212
Ident {

‎tests/ui/proc-macro/expr-stmt-nonterminal-tokens.stdout

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = #[allow(warnings)] 0 ; 0 }, }
2-
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): enum E { V = { let _ = #[allow(warnings)] #[allow(warnings)] 0 ; 0 }, }
1+
PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = #[allow(warnings)] 0; 0 }, }
2+
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): enum E { V = { let _ = #[allow(warnings)] #[allow(warnings)] 0; 0 }, }
33
PRINT-DERIVE INPUT (DEBUG): TokenStream [
44
Ident {
55
ident: "enum",
@@ -123,7 +123,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
123123
},
124124
]
125125
PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = { 0; }; 0 }, }
126-
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): enum E { V = { let _ = { 0 } ; 0 }, }
126+
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): enum E { V = { let _ = { 0 }; 0 }, }
127127
PRINT-DERIVE INPUT (DEBUG): TokenStream [
128128
Ident {
129129
ident: "enum",
@@ -203,7 +203,6 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
203203
},
204204
]
205205
PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = { {} }; 0 }, }
206-
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): enum E { V = { let _ = { {} } ; 0 }, }
207206
PRINT-DERIVE INPUT (DEBUG): TokenStream [
208207
Ident {
209208
ident: "enum",
@@ -282,7 +281,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
282281
},
283282
]
284283
PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = { PATH; }; 0 }, }
285-
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): enum E { V = { let _ = { PATH } ; 0 }, }
284+
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): enum E { V = { let _ = { PATH }; 0 }, }
286285
PRINT-DERIVE INPUT (DEBUG): TokenStream [
287286
Ident {
288287
ident: "enum",
@@ -360,7 +359,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
360359
},
361360
]
362361
PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = { 0 + 1; }; 0 }, }
363-
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): enum E { V = { let _ = { 0 + 1 } ; 0 }, }
362+
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): enum E { V = { let _ = { 0 + 1 }; 0 }, }
364363
PRINT-DERIVE INPUT (DEBUG): TokenStream [
365364
Ident {
366365
ident: "enum",
@@ -451,7 +450,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
451450
},
452451
]
453452
PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = { PATH + 1; }; 0 }, }
454-
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): enum E { V = { let _ = { PATH + 1 } ; 0 }, }
453+
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): enum E { V = { let _ = { PATH + 1 }; 0 }, }
455454
PRINT-DERIVE INPUT (DEBUG): TokenStream [
456455
Ident {
457456
ident: "enum",

‎tests/ui/proc-macro/inert-attribute-order.stdout

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ PRINT-ATTR INPUT (DISPLAY): /// 1
22
#[rustfmt::attr2] #[doc = "3"] #[doc = "4"] #[rustfmt::attr5] /// 6
33
#[print_attr(nodebug)] struct S;
44
PRINT-ATTR RE-COLLECTED (DISPLAY): #[doc = " 1"] #[rustfmt::attr2] #[doc = "3"] #[doc = "4"] #[rustfmt::attr5]
5-
#[doc = " 6"] #[print_attr(nodebug)] struct S ;
5+
#[doc = " 6"] #[print_attr(nodebug)] struct S;
66
PRINT-ATTR DEEP-RE-COLLECTED (DISPLAY): #[doc = " 1"] #[rustfmt :: attr2] #[doc = "3"] #[doc = "4"]
7-
#[rustfmt :: attr5] #[doc = " 6"] #[print_attr(nodebug)] struct S ;
7+
#[rustfmt :: attr5] #[doc = " 6"] #[print_attr(nodebug)] struct S;
88
PRINT-ATTR INPUT (DISPLAY): #[doc = " 1"] #[rustfmt::attr2] #[doc = "3"] #[doc = "4"] #[rustfmt::attr5]
9-
#[doc = " 6"] struct S ;
9+
#[doc = " 6"] struct S;
1010
PRINT-ATTR DEEP-RE-COLLECTED (DISPLAY): #[doc = " 1"] #[rustfmt :: attr2] #[doc = "3"] #[doc = "4"]
11-
#[rustfmt :: attr5] #[doc = " 6"] struct S ;
11+
#[rustfmt :: attr5] #[doc = " 6"] struct S;

‎tests/ui/proc-macro/inner-attrs.stdout

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -581,10 +581,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
581581
PRINT-DERIVE INPUT (DISPLAY): struct MyDerivePrint
582582
{ field: [u8; { match true { _ => { #![rustc_dummy(third)] true } }; 0 }] }
583583
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): struct MyDerivePrint
584-
{
585-
field :
586-
[u8 ; { match true { _ => { #! [rustc_dummy(third)] true } } ; 0 }]
587-
}
584+
{ field : [u8; { match true { _ => { #! [rustc_dummy(third)] true } }; 0 }] }
588585
PRINT-DERIVE INPUT (DEBUG): TokenStream [
589586
Ident {
590587
ident: "struct",
@@ -718,8 +715,7 @@ PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
718715
},
719716
]
720717
PRINT-ATTR INPUT (DISPLAY): (3, 4, { #![cfg_attr(not(FALSE), rustc_dummy(innermost))] 5 });
721-
PRINT-ATTR RE-COLLECTED (DISPLAY): (3, 4, { #![cfg_attr(not(FALSE), rustc_dummy(innermost))] 5 }) ;
722-
PRINT-ATTR DEEP-RE-COLLECTED (DISPLAY): (3, 4, { #! [cfg_attr(not(FALSE), rustc_dummy(innermost))] 5 }) ;
718+
PRINT-ATTR DEEP-RE-COLLECTED (DISPLAY): (3, 4, { #! [cfg_attr(not(FALSE), rustc_dummy(innermost))] 5 });
723719
PRINT-ATTR INPUT (DEBUG): TokenStream [
724720
Group {
725721
delimiter: Parenthesis,
@@ -834,8 +830,7 @@ PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
834830
},
835831
]
836832
PRINT-ATTR INPUT (DISPLAY): (3, 4, { #![cfg_attr(not(FALSE), rustc_dummy(innermost))] 5 });
837-
PRINT-ATTR RE-COLLECTED (DISPLAY): (3, 4, { #![cfg_attr(not(FALSE), rustc_dummy(innermost))] 5 }) ;
838-
PRINT-ATTR DEEP-RE-COLLECTED (DISPLAY): (3, 4, { #! [cfg_attr(not(FALSE), rustc_dummy(innermost))] 5 }) ;
833+
PRINT-ATTR DEEP-RE-COLLECTED (DISPLAY): (3, 4, { #! [cfg_attr(not(FALSE), rustc_dummy(innermost))] 5 });
839834
PRINT-ATTR INPUT (DEBUG): TokenStream [
840835
Group {
841836
delimiter: Parenthesis,

‎tests/ui/proc-macro/input-interpolated.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
55
span: #0 bytes(503..504),
66
},
77
]
8-
PRINT-ATTR INPUT (DISPLAY): const A : u8 = 0 ;
8+
PRINT-ATTR INPUT (DISPLAY): const A : u8 = 0;
99
PRINT-ATTR INPUT (DEBUG): TokenStream [
1010
Ident {
1111
ident: "const",

‎tests/ui/proc-macro/issue-75734-pp-paren.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PRINT-ATTR INPUT (DISPLAY): fn main() { &|_: u8| {}; mul_2!(1 + 1); }
2-
PRINT-ATTR DEEP-RE-COLLECTED (DISPLAY): fn main() { &| _ : u8 | {} ; mul_2! (1 + 1) ; }
2+
PRINT-ATTR DEEP-RE-COLLECTED (DISPLAY): fn main() { &| _ : u8 | {}; mul_2! (1 + 1); }
33
PRINT-ATTR INPUT (DEBUG): TokenStream [
44
Ident {
55
ident: "fn",

‎tests/ui/proc-macro/issue-75930-derive-cfg.stdout

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,22 +51,22 @@ struct Foo <#[cfg(FALSE)] A, B >
5151
{
5252
#[cfg(FALSE)] first : String, #[cfg_attr(FALSE, deny(warnings))] second :
5353
bool, third :
54-
[u8 ;
54+
[u8;
5555
{
56-
#[cfg(FALSE)] struct Bar ; #[cfg(not(FALSE))] struct Inner ;
57-
#[cfg(FALSE)] let a = 25 ; match true
56+
#[cfg(FALSE)] struct Bar; #[cfg(not(FALSE))] struct Inner;
57+
#[cfg(FALSE)] let a = 25; match true
5858
{
5959
#[cfg(FALSE)] true => {}, #[cfg_attr(not(FALSE), allow(warnings))]
6060
false => {}, _ => {}
61-
} ; #[print_helper(should_be_removed)] fn removed_fn()
61+
}; #[print_helper(should_be_removed)] fn removed_fn()
6262
{ #! [cfg(FALSE)] } #[print_helper(c)] #[cfg(not(FALSE))] fn kept_fn()
63-
{ #! [cfg(not(FALSE))] let my_val = true ; } enum TupleEnum
63+
{ #! [cfg(not(FALSE))] let my_val = true; } enum TupleEnum
6464
{
6565
Foo(#[cfg(FALSE)] u8, #[cfg(FALSE)] bool, #[cfg(not(FALSE))] i32,
6666
#[cfg(FALSE)] String, u8)
6767
} struct
6868
TupleStruct(#[cfg(FALSE)] String, #[cfg(not(FALSE))] i32,
69-
#[cfg(FALSE)] bool, u8) ; fn plain_removed_fn()
69+
#[cfg(FALSE)] bool, u8); fn plain_removed_fn()
7070
{ #! [cfg_attr(not(FALSE), cfg(FALSE))] } 0
7171
}], #[print_helper(d)] fourth : B
7272
}
@@ -1336,14 +1336,14 @@ PRINT-DERIVE INPUT (DISPLAY): #[print_helper(a)] #[allow(dead_code)] #[print_hel
13361336
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): #[print_helper(a)] #[allow(dead_code)] #[print_helper(b)] struct Foo <B >
13371337
{
13381338
second : bool, third :
1339-
[u8 ;
1339+
[u8;
13401340
{
1341-
#[cfg(not(FALSE))] struct Inner ; match true
1342-
{ #[allow(warnings)] false => {}, _ => {} } ; #[print_helper(c)]
1341+
#[cfg(not(FALSE))] struct Inner; match true
1342+
{ #[allow(warnings)] false => {}, _ => {} }; #[print_helper(c)]
13431343
#[cfg(not(FALSE))] fn kept_fn()
1344-
{ #! [cfg(not(FALSE))] let my_val = true ; } enum TupleEnum
1344+
{ #! [cfg(not(FALSE))] let my_val = true; } enum TupleEnum
13451345
{ Foo(#[cfg(not(FALSE))] i32, u8) } struct
1346-
TupleStruct(#[cfg(not(FALSE))] i32, u8) ; 0
1346+
TupleStruct(#[cfg(not(FALSE))] i32, u8); 0
13471347
}], #[print_helper(d)] fourth : B
13481348
}
13491349
PRINT-DERIVE INPUT (DEBUG): TokenStream [

‎tests/ui/proc-macro/issue-76182-leading-vert-pat.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PRINT-ATTR INPUT (DISPLAY): fn main() { match() { | () => () } }
1+
PRINT-ATTR INPUT (DISPLAY): fn main() { match () { | () => () } }
22
PRINT-ATTR INPUT (DEBUG): TokenStream [
33
Ident {
44
ident: "fn",

‎tests/ui/proc-macro/keep-expr-tokens.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] { 1 +1; }
2-
PRINT-ATTR DEEP-RE-COLLECTED (DISPLAY): #[rustc_dummy] { 1 + 1 ; }
2+
PRINT-ATTR DEEP-RE-COLLECTED (DISPLAY): #[rustc_dummy] { 1 + 1; }
33
PRINT-ATTR INPUT (DEBUG): TokenStream [
44
Punct {
55
ch: '#',

‎tests/ui/proc-macro/macro-rules-derive-cfg.stdout

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PRINT-DERIVE INPUT (DISPLAY): struct Foo
22
{
33
val :
4-
[bool ;
4+
[bool;
55
{
66
let a = #[rustc_dummy(first)] #[rustc_dummy(second)]
77
{ #![allow(unused)] 30 }; 0
@@ -10,10 +10,10 @@ PRINT-DERIVE INPUT (DISPLAY): struct Foo
1010
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): struct Foo
1111
{
1212
val :
13-
[bool ;
13+
[bool;
1414
{
1515
let a = #[rustc_dummy(first)] #[rustc_dummy(second)]
16-
{ #! [allow(unused)] 30 } ; 0
16+
{ #! [allow(unused)] 30 }; 0
1717
}]
1818
}
1919
PRINT-DERIVE INPUT (DEBUG): TokenStream [

‎tests/ui/proc-macro/nested-derive-cfg.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
PRINT-DERIVE INPUT (DISPLAY): struct Foo
22
{ my_array: [bool; { struct Inner { non_removed_inner_field: usize } 0 }] }
33
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): struct Foo
4-
{ my_array : [bool ; { struct Inner { non_removed_inner_field : usize } 0 }] }
4+
{ my_array : [bool; { struct Inner { non_removed_inner_field : usize } 0 }] }
55
PRINT-DERIVE INPUT (DEBUG): TokenStream [
66
Ident {
77
ident: "struct",

‎tests/ui/proc-macro/nonterminal-token-hygiene.stdout

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
PRINT-BANG INPUT (DISPLAY): struct S;
2-
PRINT-BANG DEEP-RE-COLLECTED (DISPLAY): struct S ;
32
PRINT-BANG INPUT (DEBUG): TokenStream [
43
Group {
54
delimiter: None,

‎tests/ui/proc-macro/pretty-print-tts.stdout

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PRINT-BANG INPUT (DISPLAY): { #![rustc_dummy] let a = "hello".len(); matches!(a, 5); }
2-
PRINT-BANG DEEP-RE-COLLECTED (DISPLAY): { #! [rustc_dummy] let a = "hello".len() ; matches! (a, 5) ; }
2+
PRINT-BANG DEEP-RE-COLLECTED (DISPLAY): { #! [rustc_dummy] let a = "hello".len(); matches! (a, 5); }
33
PRINT-BANG INPUT (DEBUG): TokenStream [
44
Group {
55
delimiter: Brace,

0 commit comments

Comments
 (0)
Please sign in to comment.