about summary refs log tree commit diff
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-07-14 00:11:59 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-07-15 12:42:07 +0300
commita2a1cd186481c49d1cde611e4f3f2a707e77eab9 (patch)
tree233f58e59461cf478984f1139af72f2a31598793
parent75896011dc2a137d96a4941f5c415c2c108f5cf9 (diff)
downloadrust-a2a1cd186481c49d1cde611e4f3f2a707e77eab9.tar.gz
rust-a2a1cd186481c49d1cde611e4f3f2a707e77eab9.zip
pprust: Fix formatting regressions from the previous commits
Fix some remaining cases of bad formatting
Update some failing tests
-rw-r--r--src/libsyntax/mut_visit.rs2
-rw-r--r--src/libsyntax/print/pprust.rs23
-rw-r--r--src/test/pretty/cast-lt.pp2
-rw-r--r--src/test/pretty/delimited-token-groups.rs49
-rw-r--r--src/test/pretty/issue-30731.rs2
-rw-r--r--src/test/pretty/stmt_expr_attributes.rs14
-rw-r--r--src/test/run-make-fulldeps/pretty-expanded-hygiene/input.pp.rs10
-rw-r--r--src/test/run-pass/macros/syntax-extension-source-utils.rs4
-rw-r--r--src/test/ui/macro_backtrace/main.stderr40
-rw-r--r--src/test/ui/macros/trace-macro.stderr2
-rw-r--r--src/test/ui/proc-macro/attribute-spans-preserved.stdout2
11 files changed, 100 insertions, 50 deletions
diff --git a/src/libsyntax/mut_visit.rs b/src/libsyntax/mut_visit.rs
index 11a1de13fc2..dc656222fbc 100644
--- a/src/libsyntax/mut_visit.rs
+++ b/src/libsyntax/mut_visit.rs
@@ -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());
         })
     }
 }
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index a07bba04489..47985351f7d 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -714,6 +714,9 @@ 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);
         }
@@ -721,27 +724,27 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
             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))),
         }
     }
 
diff --git a/src/test/pretty/cast-lt.pp b/src/test/pretty/cast-lt.pp
index 1ae30983d20..47a7dac95b9 100644
--- a/src/test/pretty/cast-lt.pp
+++ b/src/test/pretty/cast-lt.pp
@@ -8,6 +8,6 @@ extern crate std;
 // 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; }
diff --git a/src/test/pretty/delimited-token-groups.rs b/src/test/pretty/delimited-token-groups.rs
new file mode 100644
index 00000000000..768f27ad23a
--- /dev/null
+++ b/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() { }
diff --git a/src/test/pretty/issue-30731.rs b/src/test/pretty/issue-30731.rs
index ee81cce8641..02951395e70 100644
--- a/src/test/pretty/issue-30731.rs
+++ b/src/test/pretty/issue-30731.rs
@@ -5,4 +5,4 @@
 // pretty-compare-only
 // pp-exact
 
-fn main() { b!{ } c }
+fn main() { b! { } c }
diff --git a/src/test/pretty/stmt_expr_attributes.rs b/src/test/pretty/stmt_expr_attributes.rs
index acc11f3f84a..02d93238dd6 100644
--- a/src/test/pretty/stmt_expr_attributes.rs
+++ b/src/test/pretty/stmt_expr_attributes.rs
@@ -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() {
@@ -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};
diff --git a/src/test/run-make-fulldeps/pretty-expanded-hygiene/input.pp.rs b/src/test/run-make-fulldeps/pretty-expanded-hygiene/input.pp.rs
index b835bf8782c..9d081c970da 100644
--- a/src/test/run-make-fulldeps/pretty-expanded-hygiene/input.pp.rs
+++ b/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 */() { }
diff --git a/src/test/run-pass/macros/syntax-extension-source-utils.rs b/src/test/run-pass/macros/syntax-extension-source-utils.rs
index 12931159914..7e46260d516 100644
--- a/src/test/run-pass/macros/syntax-extension-source-utils.rs
+++ b/src/test/run-pass/macros/syntax-extension-source-utils.rs
@@ -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());
@@ -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)));
 }
diff --git a/src/test/ui/macro_backtrace/main.stderr b/src/test/ui/macro_backtrace/main.stderr
index 6f82d4040bc..e7bd141ccd5 100644
--- a/src/test/ui/macro_backtrace/main.stderr
+++ b/src/test/ui/macro_backtrace/main.stderr
@@ -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`
@@ -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
diff --git a/src/test/ui/macros/trace-macro.stderr b/src/test/ui/macros/trace-macro.stderr
index 545ed33cd10..287f7b297d5 100644
--- a/src/test/ui/macros/trace-macro.stderr
+++ b/src/test/ui/macros/trace-macro.stderr
@@ -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!")) ; }`
 
diff --git a/src/test/ui/proc-macro/attribute-spans-preserved.stdout b/src/test/ui/proc-macro/attribute-spans-preserved.stdout
index b2be35e8259..faf31712156 100644
--- a/src/test/ui/proc-macro/attribute-spans-preserved.stdout
+++ b/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" ; } }