]> git.lizzy.rs Git - rust.git/commitdiff
pprust: Fix formatting regressions from the previous commits
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Sat, 13 Jul 2019 21:11:59 +0000 (00:11 +0300)
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>
Mon, 15 Jul 2019 09:42:07 +0000 (12:42 +0300)
Fix some remaining cases of bad formatting
Update some failing tests

src/libsyntax/mut_visit.rs
src/libsyntax/print/pprust.rs
src/test/pretty/cast-lt.pp
src/test/pretty/delimited-token-groups.rs [new file with mode: 0644]
src/test/pretty/issue-30731.rs
src/test/pretty/stmt_expr_attributes.rs
src/test/run-make-fulldeps/pretty-expanded-hygiene/input.pp.rs
src/test/run-pass/macros/syntax-extension-source-utils.rs
src/test/ui/macro_backtrace/main.stderr
src/test/ui/macros/trace-macro.stderr
src/test/ui/proc-macro/attribute-spans-preserved.stdout

index 11a1de13fc217874cef8fb8d67eed2fefc9bd50b..dc656222fbc1082659d2915a62abe979dccc5169 100644 (file)
@@ -1328,7 +1328,7 @@ macro_rules! assert_pred {
                 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());
         })
     }
 }
index a07bba044898b7824b3a7acac4904587fb9e15cc..47985351f7d33ee527a768e3b8bf9512dc0dd36a 100644 (file)
@@ -714,6 +714,9 @@ fn print_mac_common(
         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 @@ fn print_mac_common(
             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))),
         }
     }
 
index 1ae30983d202abba383bfa7c2db74fe6870707f5..47a7dac95b9c5081cf936c03538e84c12925ea9b 100644 (file)
@@ -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 (file)
index 0000000..768f27a
--- /dev/null
@@ -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() { }
index ee81cce864171a1e0f6f4220dcc4ab94bb5995cf..02951395e70b440491cab26889ef5c1301bda97c 100644 (file)
@@ -5,4 +5,4 @@
 // pretty-compare-only
 // pp-exact
 
-fn main() { b!{ } c }
+fn main() { b! { } c }
index acc11f3f84abac69fdaa86e387e3c3a4f0df5b76..02d93238dd6435497b797b9939c5b31bce5305f4 100644 (file)
@@ -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};
index b835bf8782cc3fcc2391a95a53852bad2a3c611f..9d081c970dabca125628d0ac6a7803c4647e3a0b 100644 (file)
@@ -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 */() { }
index 129311599141f6f8910d7f547c7d4728c02b1879..7e46260d5163f7282e633e67da4a696b378b9c47 100644 (file)
@@ -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)));
 }
index 6f82d4040bce5ec5eccdda4a67b8bbf38ff47b34..e7bd141ccd5ae94dc3b1b2fdb149d991dc698735 100644 (file)
@@ -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
index 545ed33cd10be2e34c79efc321727752cdafbafb..287f7b297d5c60350dc226b1597808d37969789c 100644 (file)
@@ -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!")) ; }`
 
index b2be35e8259936e73f10c550be06c9fcc569e317..faf31712156654edaf1f5431c435c1d5af7388a7 100644 (file)
@@ -1 +1 @@
-fn main () {let y : u32 = "z" ; {let x : u32 = "y" ; } }
+fn main () { let y : u32 = "z" ; { let x : u32 = "y" ; } }