Skip to content

Commit ebcd405

Browse files
committed
No space before ; when pretty-printing token streams.
1 parent 315b3d6 commit ebcd405

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+137
-148
lines changed

compiler/rustc_ast_pretty/src/pprust/state.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,13 +171,14 @@ fn space_between(tt1: &TokenTree, tt2: &TokenTree) -> bool {
171171
(Tok(Token { kind: Dot | Dollar, .. }, _), _) => false,
172172

173173
// ANYTHING + `,`: `foo,`
174+
// ANYTHING + `;`: `x = 3;`, `[T; 3]`
174175
// ANYTHING + `.`: `x.y`, `tup.0`
175176
// ANYTHING + `!`: `foo! { ... }`
176177
//
177178
// FIXME: Incorrect cases:
178179
// - Logical not: `x =! y`, `if! x { f(); }`
179180
// - Never type: `Fn() ->!`
180-
(_, Tok(Token { kind: Comma | Dot | Not, .. }, _)) => false,
181+
(_, Tok(Token { kind: Comma | Semi | Dot | Not, .. }, _)) => false,
181182

182183
// IDENT + `(`: `f(3)`
183184
//

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/run-make/rustc-macro-dep-files/foo.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ use proc_macro::TokenStream;
77
#[proc_macro_derive(A)]
88
pub fn derive(input: TokenStream) -> TokenStream {
99
let input = input.to_string();
10-
assert!(input.contains("struct A ;"));
10+
assert!(input.contains("struct A;"));
1111
"struct B;".parse().unwrap()
1212
}

tests/ui/infinite/issue-41731-infinite-macro-print.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ LL | stack!("overflow");
1414
| ^^^^^^^^^^^^^^^^^^
1515
|
1616
= note: expanding `stack! { "overflow" }`
17-
= note: to `print! (stack! ("overflow")) ;`
17+
= note: to `print! (stack! ("overflow"));`
1818
= note: expanding `print! { stack! ("overflow") }`
19-
= note: to `{ $crate :: io :: _print($crate :: format_args! (stack! ("overflow"))) ; }`
19+
= note: to `{ $crate :: io :: _print($crate :: format_args! (stack! ("overflow"))); }`
2020
= note: expanding `stack! { "overflow" }`
21-
= note: to `print! (stack! ("overflow")) ;`
21+
= note: to `print! (stack! ("overflow"));`
2222
= note: expanding `print! { stack! ("overflow") }`
23-
= note: to `{ $crate :: io :: _print($crate :: format_args! (stack! ("overflow"))) ; }`
23+
= note: to `{ $crate :: io :: _print($crate :: format_args! (stack! ("overflow"))); }`
2424

2525
error: format argument must be a string literal
2626
--> $DIR/issue-41731-infinite-macro-print.rs:14:5

tests/ui/infinite/issue-41731-infinite-macro-println.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ LL | stack!("overflow");
1414
| ^^^^^^^^^^^^^^^^^^
1515
|
1616
= note: expanding `stack! { "overflow" }`
17-
= note: to `println! (stack! ("overflow")) ;`
17+
= note: to `println! (stack! ("overflow"));`
1818
= note: expanding `println! { stack! ("overflow") }`
19-
= note: to `{ $crate :: io :: _print($crate :: format_args_nl! (stack! ("overflow"))) ; }`
19+
= note: to `{ $crate :: io :: _print($crate :: format_args_nl! (stack! ("overflow"))); }`
2020
= note: expanding `stack! { "overflow" }`
21-
= note: to `println! (stack! ("overflow")) ;`
21+
= note: to `println! (stack! ("overflow"));`
2222
= note: expanding `println! { stack! ("overflow") }`
23-
= note: to `{ $crate :: io :: _print($crate :: format_args_nl! (stack! ("overflow"))) ; }`
23+
= note: to `{ $crate :: io :: _print($crate :: format_args_nl! (stack! ("overflow"))); }`
2424

2525
error: format argument must be a string literal
2626
--> $DIR/issue-41731-infinite-macro-println.rs:14:5

tests/ui/macros/stringify.rs

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,13 @@ fn test_block() {
5858
c1!(block, [ {} ], "{}");
5959
c1!(block, [ { true } ], "{ true }");
6060
c1!(block, [ { return } ], "{ return }");
61-
c2!(block, [ {
62-
return;
63-
} ],
64-
"{ return; }",
65-
"{ return ; }"
66-
);
67-
c2!(block,
61+
c1!(block, [ { return; } ], "{ return; }");
62+
c1!(block,
6863
[ {
6964
let _;
7065
true
7166
} ],
72-
"{ let _; true }",
73-
"{ let _ ; true }"
67+
"{ let _; true }"
7468
);
7569
}
7670

@@ -158,16 +152,15 @@ fn test_expr() {
158152
} ],
159153
"if true {} else if false {} else {}"
160154
);
161-
c2!(expr,
155+
c1!(expr,
162156
[ if true {
163157
return;
164158
} else if false {
165159
0
166160
} else {
167161
0
168162
} ],
169-
"if true { return; } else if false { 0 } else { 0 }",
170-
"if true { return ; } else if false { 0 } else { 0 }"
163+
"if true { return; } else if false { 0 } else { 0 }"
171164
);
172165

173166
// ExprKind::While
@@ -325,7 +318,7 @@ fn test_expr() {
325318
);
326319

327320
// ExprKind::Repeat
328-
c2!(expr, [ [(); 0] ], "[(); 0]", "[() ; 0]");
321+
c1!(expr, [ [(); 0] ], "[(); 0]");
329322

330323
// ExprKind::Paren
331324
c1!(expr, [ (expr) ], "(expr)");
@@ -355,30 +348,29 @@ fn test_expr() {
355348
#[test]
356349
fn test_item() {
357350
// ItemKind::ExternCrate
358-
c2!(item, [ extern crate std; ], "extern crate std;", "extern crate std ;");
359-
c2!(item,
351+
c1!(item, [ extern crate std; ], "extern crate std;");
352+
c1!(item,
360353
[ pub extern crate self as std; ],
361-
"pub extern crate self as std;",
362-
"pub extern crate self as std ;"
354+
"pub extern crate self as std;"
363355
);
364356

365357
// ItemKind::Use
366358
c2!(item,
367359
[ pub use crate::{a, b::c}; ],
368360
"pub use crate::{a, b::c};",
369-
"pub use crate :: { a, b :: c } ;"
361+
"pub use crate :: { a, b :: c };"
370362
);
371-
c2!(item, [ pub use A::*; ], "pub use A::*;", "pub use A :: * ;");
363+
c2!(item, [ pub use A::*; ], "pub use A::*;", "pub use A :: *;");
372364

373365
// ItemKind::Static
374-
c2!(item, [ pub static S: () = {}; ], "pub static S: () = {};", "pub static S : () = {} ;");
375-
c2!(item, [ static mut S: () = {}; ], "static mut S: () = {};", "static mut S : () = {} ;");
376-
c2!(item, [ static S: (); ], "static S: ();", "static S : () ;");
377-
c2!(item, [ static mut S: (); ], "static mut S: ();", "static mut S : () ;");
366+
c2!(item, [ pub static S: () = {}; ], "pub static S: () = {};", "pub static S : () = {};");
367+
c2!(item, [ static mut S: () = {}; ], "static mut S: () = {};", "static mut S : () = {};");
368+
c2!(item, [ static S: (); ], "static S: ();", "static S : ();");
369+
c2!(item, [ static mut S: (); ], "static mut S: ();", "static mut S : ();");
378370

379371
// ItemKind::Const
380-
c2!(item, [ pub const S: () = {}; ], "pub const S: () = {};", "pub const S : () = {} ;");
381-
c2!(item, [ const S: (); ], "const S: ();", "const S : () ;");
372+
c2!(item, [ pub const S: () = {}; ], "pub const S: () = {};", "pub const S : () = {};");
373+
c2!(item, [ const S: (); ], "const S: ();", "const S : ();");
382374

383375
// ItemKind::Fn
384376
c1!(item,
@@ -397,9 +389,9 @@ fn test_item() {
397389
);
398390

399391
// ItemKind::Mod
400-
c2!(item, [ pub mod m; ], "pub mod m;", "pub mod m ;");
392+
c1!(item, [ pub mod m; ], "pub mod m;");
401393
c1!(item, [ mod m {} ], "mod m {}");
402-
c2!(item, [ unsafe mod m; ], "unsafe mod m;", "unsafe mod m ;");
394+
c1!(item, [ unsafe mod m; ], "unsafe mod m;");
403395
c1!(item, [ unsafe mod m {} ], "unsafe mod m {}");
404396

405397
// ItemKind::ForeignMod
@@ -422,7 +414,7 @@ fn test_item() {
422414
= T;
423415
],
424416
"pub default type Type<'a>: Bound where Self: 'a = T;",
425-
"pub default type Type < 'a > : Bound where Self : 'a, = T ;"
417+
"pub default type Type < 'a > : Bound where Self : 'a, = T;"
426418
);
427419

428420
// ItemKind::Enum
@@ -459,9 +451,9 @@ fn test_item() {
459451
);
460452

461453
// ItemKind::Struct
462-
c2!(item, [ pub struct Unit; ], "pub struct Unit;", "pub struct Unit ;");
463-
c2!(item, [ struct Tuple(); ], "struct Tuple();", "struct Tuple() ;");
464-
c2!(item, [ struct Tuple(T); ], "struct Tuple(T);", "struct Tuple(T) ;");
454+
c1!(item, [ pub struct Unit; ], "pub struct Unit;");
455+
c1!(item, [ struct Tuple(); ], "struct Tuple();");
456+
c1!(item, [ struct Tuple(T); ], "struct Tuple(T);");
465457
c1!(item, [ struct Struct {} ], "struct Struct {}");
466458
c2!(item,
467459
[
@@ -510,7 +502,7 @@ fn test_item() {
510502
c2!(item,
511503
[ pub trait Trait<T> = Sized where T: 'a; ],
512504
"pub trait Trait<T> = Sized where T: 'a;",
513-
"pub trait Trait < T > = Sized where T : 'a ;"
505+
"pub trait Trait < T > = Sized where T : 'a;"
514506
);
515507

516508
// ItemKind::Impl
@@ -525,8 +517,8 @@ fn test_item() {
525517
c2!(item, [ impl ~const Struct {} ], "impl ~const Struct {}", "impl ~ const Struct {}");
526518

527519
// ItemKind::MacCall
528-
c2!(item, [ mac!(...); ], "mac!(...);", "mac! (...) ;");
529-
c2!(item, [ mac![...]; ], "mac![...];", "mac! [...] ;");
520+
c2!(item, [ mac!(...); ], "mac!(...);", "mac! (...);");
521+
c2!(item, [ mac![...]; ], "mac![...];", "mac! [...];");
530522
c1!(item, [ mac! { ... } ], "mac! { ... }");
531523

532524
// ItemKind::MacroDef
@@ -536,7 +528,7 @@ fn test_item() {
536528
() => {};
537529
}
538530
],
539-
"macro_rules! stringify { () => {} ; }"
531+
"macro_rules! stringify { () => {}; }"
540532
);
541533
c2!(item,
542534
[ pub macro stringify() {} ],
@@ -671,7 +663,7 @@ fn test_stmt() {
671663
);
672664

673665
// StmtKind::Item
674-
c2!(stmt, [ struct S; ], "struct S;", "struct S ;");
666+
c1!(stmt, [ struct S; ], "struct S;");
675667
c1!(stmt, [ struct S {} ], "struct S {}");
676668

677669
// StmtKind::Expr
@@ -695,7 +687,7 @@ fn test_ty() {
695687
c1!(ty, [ [T] ], "[T]");
696688

697689
// TyKind::Array
698-
c2!(ty, [ [T; 0] ], "[T; 0]", "[T ; 0]");
690+
c1!(ty, [ [T; 0] ], "[T; 0]");
699691

700692
// TyKind::Ptr
701693
c2!(ty, [ *const T ], "*const T", "* const T");

tests/ui/macros/trace-macro.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ LL | println!("Hello, World!");
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: expanding `println! { "Hello, World!" }`
8-
= note: to `{ $crate :: io :: _print($crate :: format_args_nl! ("Hello, World!")) ; }`
8+
= note: to `{ $crate :: io :: _print($crate :: format_args_nl! ("Hello, World!")); }`
99

tests/ui/macros/trace_faulty_macros.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ LL | my_faulty_macro!();
2020
| ^^^^^^^^^^^^^^^^^^
2121
|
2222
= note: expanding `my_faulty_macro! { }`
23-
= note: to `my_faulty_macro! (bcd) ;`
23+
= note: to `my_faulty_macro! (bcd);`
2424
= note: expanding `my_faulty_macro! { bcd }`
2525

2626
error: recursion limit reached while expanding `my_recursive_macro!`
@@ -42,13 +42,13 @@ LL | my_recursive_macro!();
4242
| ^^^^^^^^^^^^^^^^^^^^^
4343
|
4444
= note: expanding `my_recursive_macro! { }`
45-
= note: to `my_recursive_macro! () ;`
45+
= note: to `my_recursive_macro! ();`
4646
= note: expanding `my_recursive_macro! { }`
47-
= note: to `my_recursive_macro! () ;`
47+
= note: to `my_recursive_macro! ();`
4848
= note: expanding `my_recursive_macro! { }`
49-
= note: to `my_recursive_macro! () ;`
49+
= note: to `my_recursive_macro! ();`
5050
= note: expanding `my_recursive_macro! { }`
51-
= note: to `my_recursive_macro! () ;`
51+
= note: to `my_recursive_macro! ();`
5252

5353
error: expected expression, found `A { a: a, b: 0, c: _, .. }`
5454
--> $DIR/trace_faulty_macros.rs:16:9
@@ -76,7 +76,7 @@ LL | let a = pat_macro!();
7676
| ^^^^^^^^^^^^
7777
|
7878
= note: expanding `pat_macro! { }`
79-
= note: to `pat_macro! (A { a : a, b : 0, c : _, .. }) ;`
79+
= note: to `pat_macro! (A { a : a, b : 0, c : _, .. });`
8080
= note: expanding `pat_macro! { A { a : a, b : 0, c : _, .. } }`
8181
= note: to `A { a: a, b: 0, c: _, .. }`
8282

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
PRINT-ATTR INPUT (DISPLAY): struct ItemWithSemi ;
1+
PRINT-ATTR INPUT (DISPLAY): struct ItemWithSemi;
22
PRINT-ATTR INPUT (DEBUG): TokenStream [
33
Ident {
44
ident: "struct",
@@ -45,7 +45,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
4545
span: $DIR/allowed-attr-stmt-expr.rs:53:27: 53:29 (#0),
4646
},
4747
]
48-
PRINT-ATTR INPUT (DISPLAY): #[expect_let] let string = "Hello, world!" ;
48+
PRINT-ATTR INPUT (DISPLAY): #[expect_let] let string = "Hello, world!";
4949
PRINT-ATTR INPUT (DEBUG): TokenStream [
5050
Punct {
5151
ch: '#',
@@ -87,7 +87,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
8787
span: $DIR/allowed-attr-stmt-expr.rs:57:33: 57:34 (#0),
8888
},
8989
]
90-
PRINT-ATTR INPUT (DISPLAY): #[expect_my_macro_stmt] my_macro! ("{}", string) ;
90+
PRINT-ATTR INPUT (DISPLAY): #[expect_my_macro_stmt] my_macro! ("{}", string);
9191
PRINT-ATTR INPUT (DEBUG): TokenStream [
9292
Punct {
9393
ch: '#',
@@ -140,7 +140,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
140140
span: $DIR/allowed-attr-stmt-expr.rs:61:28: 61:29 (#0),
141141
},
142142
]
143-
PRINT-ATTR INPUT (DISPLAY): second_make_stmt! (#[allow(dead_code)] struct Bar {}) ;
143+
PRINT-ATTR INPUT (DISPLAY): second_make_stmt! (#[allow(dead_code)] struct Bar {});
144144
PRINT-ATTR INPUT (DEBUG): TokenStream [
145145
Ident {
146146
ident: "second_make_stmt",
@@ -288,7 +288,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
288288
span: $DIR/allowed-attr-stmt-expr.rs:68:18: 68:20 (#0),
289289
},
290290
]
291-
PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct NonBracedStruct ;
291+
PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct NonBracedStruct;
292292
PRINT-ATTR INPUT (DEBUG): TokenStream [
293293
Punct {
294294
ch: '#',

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
2929
span: $DIR/attr-stmt-expr.rs:45:27: 45:29 (#0),
3030
},
3131
]
32-
PRINT-ATTR INPUT (DISPLAY): #[expect_let] let string = "Hello, world!" ;
32+
PRINT-ATTR INPUT (DISPLAY): #[expect_let] let string = "Hello, world!";
3333
PRINT-ATTR INPUT (DEBUG): TokenStream [
3434
Punct {
3535
ch: '#',
@@ -71,7 +71,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
7171
span: $DIR/attr-stmt-expr.rs:49:33: 49:34 (#0),
7272
},
7373
]
74-
PRINT-ATTR INPUT (DISPLAY): #[expect_my_macro_stmt] my_macro! ("{}", string) ;
74+
PRINT-ATTR INPUT (DISPLAY): #[expect_my_macro_stmt] my_macro! ("{}", string);
7575
PRINT-ATTR INPUT (DEBUG): TokenStream [
7676
Punct {
7777
ch: '#',
@@ -124,7 +124,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
124124
span: $DIR/attr-stmt-expr.rs:53:28: 53:29 (#0),
125125
},
126126
]
127-
PRINT-ATTR INPUT (DISPLAY): second_make_stmt! (#[allow(dead_code)] struct Bar {}) ;
127+
PRINT-ATTR INPUT (DISPLAY): second_make_stmt! (#[allow(dead_code)] struct Bar {});
128128
PRINT-ATTR INPUT (DEBUG): TokenStream [
129129
Ident {
130130
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"; } }

0 commit comments

Comments
 (0)