Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
pprust: Fix formatting regressions from the previous commits
Fix some remaining cases of bad formatting
Update some failing tests
  • Loading branch information
petrochenkov committed Jul 15, 2019
1 parent 7589601 commit a2a1cd1
Show file tree
Hide file tree
Showing 11 changed files with 100 additions and 50 deletions.
2 changes: 1 addition & 1 deletion src/libsyntax/mut_visit.rs
Expand Up @@ -1328,7 +1328,7 @@ mod tests {
matches_codepattern,
"matches_codepattern",
pprust::to_string(|s| fake_print_crate(s, &krate)),
"macro_rules! zz((zz$zz:zz$(zz $zz:zz)zz+=>(zz$(zz$zz$zz)+)));".to_string());
"macro_rules! zz{(zz$zz:zz$(zz $zz:zz)zz+=>(zz$(zz$zz$zz)+))}".to_string());
})
}
}
23 changes: 13 additions & 10 deletions src/libsyntax/print/pprust.rs
Expand Up @@ -714,34 +714,37 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
convert_dollar_crate: bool,
span: Span,
) {
if delim == DelimToken::Brace {
self.cbox(INDENT_UNIT);
}
if let Some(path) = path {
self.print_path(path, false, 0);
}
if has_bang {
self.word("!");
}
if let Some(ident) = ident {
self.space();
self.nbsp();
self.print_ident(ident);
self.space();
}
match delim {
DelimToken::Paren => self.popen(),
DelimToken::Bracket => self.word("["),
DelimToken::NoDelim => self.word(" "),
DelimToken::Brace => {
self.head("");
self.bopen();
if path.is_some() || has_bang || ident.is_some() {
self.nbsp();
}
self.word("{");
if !tts.is_empty() {
self.space();
}
}
_ => self.word(token_kind_to_string(&token::OpenDelim(delim))),
}
self.ibox(0);
self.print_tts(tts, convert_dollar_crate);
self.end();
match delim {
DelimToken::Paren => self.pclose(),
DelimToken::Bracket => self.word("]"),
DelimToken::NoDelim => self.word(" "),
DelimToken::Brace => self.bclose(span),
_ => self.word(token_kind_to_string(&token::CloseDelim(delim))),
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/pretty/cast-lt.pp
Expand Up @@ -8,6 +8,6 @@
// pretty-mode:expanded
// pp-exact:cast-lt.pp

macro_rules! negative {($ e : expr) => {$ e < 0 } }
macro_rules! negative { ($ e : expr) => { $ e < 0 } }

fn main() { (1 as i32) < 0; }
49 changes: 49 additions & 0 deletions src/test/pretty/delimited-token-groups.rs
@@ -0,0 +1,49 @@
// pp-exact

#![feature(rustc_attrs)]

macro_rules! mac { ($ ($ tt : tt) *) => () }

mac! {
struct S { field1 : u8 , field2 : u16 , } impl Clone for S
{
fn clone () -> S
{
panic ! () ;

}
}
}

mac! {
a
(aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
aaaaaaaa aaaaaaaa) a
[aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
aaaaaaaa aaaaaaaa] a
{
aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
aaaaaaaa aaaaaaaa aaaaaaaa
} a
}

mac!(aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
aaaaaaaa aaaaaaaa);
mac![aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
aaaaaaaa aaaaaaaa];
mac! {
aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
aaaaaaaa aaaaaaaa
}

#[rustc_dummy(aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
aaaaaaaa aaaaaaaa aaaaaaaa)]
#[rustc_dummy[aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
aaaaaaaa aaaaaaaa aaaaaaaa]]
#[rustc_dummy {
aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
aaaaaaaa aaaaaaaa
}]
#[rustc_dummy =
"aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa"]
fn main() { }
2 changes: 1 addition & 1 deletion src/test/pretty/issue-30731.rs
Expand Up @@ -5,4 +5,4 @@
// pretty-compare-only
// pp-exact

fn main() { b!{ } c }
fn main() { b! { } c }
14 changes: 6 additions & 8 deletions src/test/pretty/stmt_expr_attributes.rs
Expand Up @@ -111,31 +111,29 @@ fn _8() {
}

fn _9() {
macro_rules!
stmt_mac
{() => {let _ = () ; } }
macro_rules! stmt_mac { () => { let _ = () ; } }

#[rustc_dummy]
stmt_mac!();

#[rustc_dummy]
stmt_mac!{ };
stmt_mac! { };

#[rustc_dummy]
stmt_mac![];

#[rustc_dummy]
stmt_mac!{ }
stmt_mac! { }

let _ = ();
}

macro_rules! expr_mac {() => {() } }
macro_rules! expr_mac { () => { () } }

fn _10() {
let _ = #[rustc_dummy] expr_mac!();
let _ = #[rustc_dummy] expr_mac![];
let _ = #[rustc_dummy] expr_mac!{ };
let _ = #[rustc_dummy] expr_mac! { };
}

fn _11() {
Expand Down Expand Up @@ -238,7 +236,7 @@ fn _11() {
|| #[rustc_dummy] return;
let _ = #[rustc_dummy] expr_mac!();
let _ = #[rustc_dummy] expr_mac![];
let _ = #[rustc_dummy] expr_mac!{ };
let _ = #[rustc_dummy] expr_mac! { };
let _ = #[rustc_dummy] Foo{#![rustc_dummy] data: (),};
let _ = #[rustc_dummy] Foo{#![rustc_dummy] ..s};
let _ = #[rustc_dummy] Foo{#![rustc_dummy] data: (), ..s};
Expand Down
10 changes: 5 additions & 5 deletions src/test/run-make-fulldeps/pretty-expanded-hygiene/input.pp.rs
@@ -1,9 +1,9 @@
// minimal junk
#![feature(no_core)]
#![no_core]
#![feature /* 0#0 */(no_core)]
#![no_core /* 0#0 */]

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

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

fn y /* 61#0 */() { }
fn y /* 0#0 */() { }
4 changes: 2 additions & 2 deletions src/test/run-pass/macros/syntax-extension-source-utils.rs
Expand Up @@ -18,7 +18,7 @@ pub fn main() {
assert_eq!(column!(), 16);
assert_eq!(indirect_line!(), 19);
assert!((file!().ends_with("syntax-extension-source-utils.rs")));
assert_eq!(stringify!((2*3) + 5).to_string(), "( 2 * 3 ) + 5".to_string());
assert_eq!(stringify!((2*3) + 5).to_string(), "(2 * 3) + 5".to_string());
assert!(include!("syntax-extension-source-utils-files/includeme.\
fragment").to_string()
== "victory robot 6".to_string());
Expand All @@ -33,5 +33,5 @@ pub fn main() {
// The Windows tests are wrapped in an extra module for some reason
assert!((m1::m2::where_am_i().ends_with("m1::m2")));

assert_eq!((36, "( 2 * 3 ) + 5"), (line!(), stringify!((2*3) + 5)));
assert_eq!((36, "(2 * 3) + 5"), (line!(), stringify!((2*3) + 5)));
}
40 changes: 20 additions & 20 deletions src/test/ui/macro_backtrace/main.stderr
Expand Up @@ -24,10 +24,10 @@ LL | ping!();
|
::: <::ping::ping macros>:1:1
|
LL | () => {pong ! () ; }
| --------------------
| | |
| | in this macro invocation
LL | () => { pong ! () ; }
| ---------------------
| | |
| | in this macro invocation
| in this expansion of `ping!`

error: expected one of `!`, `.`, `::`, `;`, `?`, `{`, `}`, or an operator, found `error`
Expand All @@ -44,34 +44,34 @@ LL | deep!();
|
::: <::ping::deep macros>:1:1
|
LL | () => {foo ! () ; }
| -------------------
| | |
| | in this macro invocation (#2)
LL | () => { foo ! () ; }
| --------------------
| | |
| | in this macro invocation (#2)
| in this expansion of `deep!` (#1)
|
::: <::ping::foo macros>:1:1
|
LL | () => {bar ! () ; }
| -------------------
| | |
| | in this macro invocation (#3)
LL | () => { bar ! () ; }
| --------------------
| | |
| | in this macro invocation (#3)
| in this expansion of `foo!` (#2)
|
::: <::ping::bar macros>:1:1
|
LL | () => {ping ! () ; }
| --------------------
| | |
| | in this macro invocation (#4)
LL | () => { ping ! () ; }
| ---------------------
| | |
| | in this macro invocation (#4)
| in this expansion of `bar!` (#3)
|
::: <::ping::ping macros>:1:1
|
LL | () => {pong ! () ; }
| --------------------
| | |
| | in this macro invocation (#5)
LL | () => { pong ! () ; }
| ---------------------
| | |
| | in this macro invocation (#5)
| in this expansion of `ping!` (#4)

error: aborting due to 3 previous errors
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/macros/trace-macro.stderr
Expand Up @@ -5,5 +5,5 @@ LL | println!("Hello, World!");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expanding `println! { "Hello, World!" }`
= note: to `{$crate :: io :: _print (format_args_nl ! ("Hello, World!")) ; }`
= note: to `{ $crate :: io :: _print (format_args_nl ! ("Hello, World!")) ; }`

2 changes: 1 addition & 1 deletion src/test/ui/proc-macro/attribute-spans-preserved.stdout
@@ -1 +1 @@
fn main () {let y : u32 = "z" ; {let x : u32 = "y" ; } }
fn main () { let y : u32 = "z" ; { let x : u32 = "y" ; } }

0 comments on commit a2a1cd1

Please sign in to comment.