Skip to content

Commit a2a1cd1

Browse files
committed
pprust: Fix formatting regressions from the previous commits
Fix some remaining cases of bad formatting Update some failing tests
1 parent 7589601 commit a2a1cd1

File tree

11 files changed

+100
-50
lines changed

11 files changed

+100
-50
lines changed

src/libsyntax/mut_visit.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1328,7 +1328,7 @@ mod tests {
13281328
matches_codepattern,
13291329
"matches_codepattern",
13301330
pprust::to_string(|s| fake_print_crate(s, &krate)),
1331-
"macro_rules! zz((zz$zz:zz$(zz $zz:zz)zz+=>(zz$(zz$zz$zz)+)));".to_string());
1331+
"macro_rules! zz{(zz$zz:zz$(zz $zz:zz)zz+=>(zz$(zz$zz$zz)+))}".to_string());
13321332
})
13331333
}
13341334
}

src/libsyntax/print/pprust.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -714,34 +714,37 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
714714
convert_dollar_crate: bool,
715715
span: Span,
716716
) {
717+
if delim == DelimToken::Brace {
718+
self.cbox(INDENT_UNIT);
719+
}
717720
if let Some(path) = path {
718721
self.print_path(path, false, 0);
719722
}
720723
if has_bang {
721724
self.word("!");
722725
}
723726
if let Some(ident) = ident {
724-
self.space();
727+
self.nbsp();
725728
self.print_ident(ident);
726-
self.space();
727729
}
728730
match delim {
729-
DelimToken::Paren => self.popen(),
730-
DelimToken::Bracket => self.word("["),
731-
DelimToken::NoDelim => self.word(" "),
732731
DelimToken::Brace => {
733-
self.head("");
734-
self.bopen();
732+
if path.is_some() || has_bang || ident.is_some() {
733+
self.nbsp();
734+
}
735+
self.word("{");
736+
if !tts.is_empty() {
737+
self.space();
738+
}
735739
}
740+
_ => self.word(token_kind_to_string(&token::OpenDelim(delim))),
736741
}
737742
self.ibox(0);
738743
self.print_tts(tts, convert_dollar_crate);
739744
self.end();
740745
match delim {
741-
DelimToken::Paren => self.pclose(),
742-
DelimToken::Bracket => self.word("]"),
743-
DelimToken::NoDelim => self.word(" "),
744746
DelimToken::Brace => self.bclose(span),
747+
_ => self.word(token_kind_to_string(&token::CloseDelim(delim))),
745748
}
746749
}
747750

src/test/pretty/cast-lt.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
// pretty-mode:expanded
99
// pp-exact:cast-lt.pp
1010

11-
macro_rules! negative {($ e : expr) => {$ e < 0 } }
11+
macro_rules! negative { ($ e : expr) => { $ e < 0 } }
1212

1313
fn main() { (1 as i32) < 0; }
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// pp-exact
2+
3+
#![feature(rustc_attrs)]
4+
5+
macro_rules! mac { ($ ($ tt : tt) *) => () }
6+
7+
mac! {
8+
struct S { field1 : u8 , field2 : u16 , } impl Clone for S
9+
{
10+
fn clone () -> S
11+
{
12+
panic ! () ;
13+
14+
}
15+
}
16+
}
17+
18+
mac! {
19+
a
20+
(aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
21+
aaaaaaaa aaaaaaaa) a
22+
[aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
23+
aaaaaaaa aaaaaaaa] a
24+
{
25+
aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
26+
aaaaaaaa aaaaaaaa aaaaaaaa
27+
} a
28+
}
29+
30+
mac!(aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
31+
aaaaaaaa aaaaaaaa);
32+
mac![aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
33+
aaaaaaaa aaaaaaaa];
34+
mac! {
35+
aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
36+
aaaaaaaa aaaaaaaa
37+
}
38+
39+
#[rustc_dummy(aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
40+
aaaaaaaa aaaaaaaa aaaaaaaa)]
41+
#[rustc_dummy[aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
42+
aaaaaaaa aaaaaaaa aaaaaaaa]]
43+
#[rustc_dummy {
44+
aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
45+
aaaaaaaa aaaaaaaa
46+
}]
47+
#[rustc_dummy =
48+
"aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa"]
49+
fn main() { }

src/test/pretty/issue-30731.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
// pretty-compare-only
66
// pp-exact
77

8-
fn main() { b!{ } c }
8+
fn main() { b! { } c }

src/test/pretty/stmt_expr_attributes.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -111,31 +111,29 @@ fn _8() {
111111
}
112112

113113
fn _9() {
114-
macro_rules!
115-
stmt_mac
116-
{() => {let _ = () ; } }
114+
macro_rules! stmt_mac { () => { let _ = () ; } }
117115

118116
#[rustc_dummy]
119117
stmt_mac!();
120118

121119
#[rustc_dummy]
122-
stmt_mac!{ };
120+
stmt_mac! { };
123121

124122
#[rustc_dummy]
125123
stmt_mac![];
126124

127125
#[rustc_dummy]
128-
stmt_mac!{ }
126+
stmt_mac! { }
129127

130128
let _ = ();
131129
}
132130

133-
macro_rules! expr_mac {() => {() } }
131+
macro_rules! expr_mac { () => { () } }
134132

135133
fn _10() {
136134
let _ = #[rustc_dummy] expr_mac!();
137135
let _ = #[rustc_dummy] expr_mac![];
138-
let _ = #[rustc_dummy] expr_mac!{ };
136+
let _ = #[rustc_dummy] expr_mac! { };
139137
}
140138

141139
fn _11() {
@@ -238,7 +236,7 @@ fn _11() {
238236
|| #[rustc_dummy] return;
239237
let _ = #[rustc_dummy] expr_mac!();
240238
let _ = #[rustc_dummy] expr_mac![];
241-
let _ = #[rustc_dummy] expr_mac!{ };
239+
let _ = #[rustc_dummy] expr_mac! { };
242240
let _ = #[rustc_dummy] Foo{#![rustc_dummy] data: (),};
243241
let _ = #[rustc_dummy] Foo{#![rustc_dummy] ..s};
244242
let _ = #[rustc_dummy] Foo{#![rustc_dummy] data: (), ..s};
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// minimal junk
2-
#![feature(no_core)]
3-
#![no_core]
2+
#![feature /* 0#0 */(no_core)]
3+
#![no_core /* 0#0 */]
44

5-
macro_rules! foo /* 60#0 */(( $ x : ident ) => { y + $ x });
5+
macro_rules /* 0#0 */! foo /* 0#0 */ { ($ x : ident) => { y + $ x } }
66

7-
fn bar /* 62#0 */() { let x /* 59#2 */ = 1; y /* 61#4 */ + x /* 59#5 */ }
7+
fn bar /* 0#0 */() { let x /* 0#0 */ = 1; y /* 0#1 */ + x /* 0#0 */ }
88

9-
fn y /* 61#0 */() { }
9+
fn y /* 0#0 */() { }

src/test/run-pass/macros/syntax-extension-source-utils.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub fn main() {
1818
assert_eq!(column!(), 16);
1919
assert_eq!(indirect_line!(), 19);
2020
assert!((file!().ends_with("syntax-extension-source-utils.rs")));
21-
assert_eq!(stringify!((2*3) + 5).to_string(), "( 2 * 3 ) + 5".to_string());
21+
assert_eq!(stringify!((2*3) + 5).to_string(), "(2 * 3) + 5".to_string());
2222
assert!(include!("syntax-extension-source-utils-files/includeme.\
2323
fragment").to_string()
2424
== "victory robot 6".to_string());
@@ -33,5 +33,5 @@ pub fn main() {
3333
// The Windows tests are wrapped in an extra module for some reason
3434
assert!((m1::m2::where_am_i().ends_with("m1::m2")));
3535

36-
assert_eq!((36, "( 2 * 3 ) + 5"), (line!(), stringify!((2*3) + 5)));
36+
assert_eq!((36, "(2 * 3) + 5"), (line!(), stringify!((2*3) + 5)));
3737
}

src/test/ui/macro_backtrace/main.stderr

+20-20
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ LL | ping!();
2424
|
2525
::: <::ping::ping macros>:1:1
2626
|
27-
LL | () => {pong ! () ; }
28-
| --------------------
29-
| | |
30-
| | in this macro invocation
27+
LL | () => { pong ! () ; }
28+
| ---------------------
29+
| | |
30+
| | in this macro invocation
3131
| in this expansion of `ping!`
3232

3333
error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `error`
@@ -44,34 +44,34 @@ LL | deep!();
4444
|
4545
::: <::ping::deep macros>:1:1
4646
|
47-
LL | () => {foo ! () ; }
48-
| -------------------
49-
| | |
50-
| | in this macro invocation (#2)
47+
LL | () => { foo ! () ; }
48+
| --------------------
49+
| | |
50+
| | in this macro invocation (#2)
5151
| in this expansion of `deep!` (#1)
5252
|
5353
::: <::ping::foo macros>:1:1
5454
|
55-
LL | () => {bar ! () ; }
56-
| -------------------
57-
| | |
58-
| | in this macro invocation (#3)
55+
LL | () => { bar ! () ; }
56+
| --------------------
57+
| | |
58+
| | in this macro invocation (#3)
5959
| in this expansion of `foo!` (#2)
6060
|
6161
::: <::ping::bar macros>:1:1
6262
|
63-
LL | () => {ping ! () ; }
64-
| --------------------
65-
| | |
66-
| | in this macro invocation (#4)
63+
LL | () => { ping ! () ; }
64+
| ---------------------
65+
| | |
66+
| | in this macro invocation (#4)
6767
| in this expansion of `bar!` (#3)
6868
|
6969
::: <::ping::ping macros>:1:1
7070
|
71-
LL | () => {pong ! () ; }
72-
| --------------------
73-
| | |
74-
| | in this macro invocation (#5)
71+
LL | () => { pong ! () ; }
72+
| ---------------------
73+
| | |
74+
| | in this macro invocation (#5)
7575
| in this expansion of `ping!` (#4)
7676

7777
error: aborting due to 3 previous errors

src/test/ui/macros/trace-macro.stderr

+1-1
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 (format_args_nl ! ("Hello, World!")) ; }`
8+
= note: to `{ $crate :: io :: _print (format_args_nl ! ("Hello, World!")) ; }`
99

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)