about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-07-13 23:08:29 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2019-07-15 12:42:07 +0300
commit11585b598ccf5942df405320bead98c096e93259 (patch)
tree583630e8c192b9e63be86a917497093b56419bea /src
parent23c5c1bfe7e3785fa1dcf1d3ff6e6bbaa855f66f (diff)
downloadrust-11585b598ccf5942df405320bead98c096e93259.tar.gz
rust-11585b598ccf5942df405320bead98c096e93259.zip
pprust: Use `print_mac_common` for delimited token groups
Diffstat (limited to 'src')
-rw-r--r--src/libsyntax/ast.rs12
-rw-r--r--src/libsyntax/print/pprust.rs60
-rw-r--r--src/test/pretty/cast-lt.pp2
-rw-r--r--src/test/pretty/stmt_expr_attributes.rs4
-rw-r--r--src/test/ui/editions/edition-keywords-2015-2018-expansion.stderr4
-rw-r--r--src/test/ui/editions/edition-keywords-2018-2015-parsing.stderr6
-rw-r--r--src/test/ui/editions/edition-keywords-2018-2018-expansion.stderr4
-rw-r--r--src/test/ui/editions/edition-keywords-2018-2018-parsing.stderr6
-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/macros/trace_faulty_macros.stderr10
-rw-r--r--src/test/ui/proc-macro/attribute-spans-preserved.stdout2
-rw-r--r--src/test/ui/proc-macro/dollar-crate-issue-57089.stdout4
-rw-r--r--src/test/ui/proc-macro/dollar-crate-issue-62325.stdout4
-rw-r--r--src/test/ui/proc-macro/dollar-crate.stdout12
15 files changed, 94 insertions, 78 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 8801e89a0cf..6cfc1b77e03 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -6,7 +6,7 @@ pub use crate::symbol::{Ident, Symbol as Name};
 pub use crate::util::parser::ExprPrecedence;
 
 use crate::ext::hygiene::{Mark, SyntaxContext};
-use crate::parse::token;
+use crate::parse::token::{self, DelimToken};
 use crate::print::pprust;
 use crate::ptr::P;
 use crate::source_map::{dummy_spanned, respan, Spanned};
@@ -1298,6 +1298,16 @@ impl Mac_ {
     }
 }
 
+impl MacDelimiter {
+    crate fn to_token(self) -> DelimToken {
+        match self {
+            MacDelimiter::Parenthesis => DelimToken::Paren,
+            MacDelimiter::Bracket => DelimToken::Bracket,
+            MacDelimiter::Brace => DelimToken::Brace,
+        }
+    }
+}
+
 #[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
 pub struct MacroDef {
     pub tokens: TokenStream,
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index af9f6bb442d..77f2dff0d8e 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -621,12 +621,9 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
             } else {
                 match attr.tokens.trees().next() {
                     Some(TokenTree::Delimited(_, delim, tts)) => {
-                        let delim = match delim {
-                            DelimToken::Brace => MacDelimiter::Brace,
-                            DelimToken::Bracket => MacDelimiter::Bracket,
-                            DelimToken::Paren | DelimToken::NoDelim => MacDelimiter::Parenthesis,
-                        };
-                        self.print_mac_common(&attr.path, false, None, tts, delim, attr.span);
+                        self.print_mac_common(
+                            Some(&attr.path), false, None, delim, tts, true, attr.span
+                        );
                     }
                     tree => {
                         self.print_path(&attr.path, false, 0);
@@ -692,13 +689,11 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
                     _ => {}
                 }
             }
-            TokenTree::Delimited(_, delim, tts) => {
-                self.word(token_kind_to_string(&token::OpenDelim(delim)));
-                self.space();
-                self.print_tts(tts, convert_dollar_crate);
-                self.space();
-                self.word(token_kind_to_string(&token::CloseDelim(delim)))
-            },
+            TokenTree::Delimited(dspan, delim, tts) => {
+                self.print_mac_common(
+                    None, false, None, delim, tts, convert_dollar_crate, dspan.entire()
+                );
+            }
         }
     }
 
@@ -715,14 +710,17 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
 
     fn print_mac_common(
         &mut self,
-        path: &ast::Path,
+        path: Option<&ast::Path>,
         has_bang: bool,
         ident: Option<ast::Ident>,
+        delim: DelimToken,
         tts: TokenStream,
-        delim: MacDelimiter,
+        convert_dollar_crate: bool,
         span: Span,
     ) {
-        self.print_path(path, false, 0);
+        if let Some(path) = path {
+            self.print_path(path, false, 0);
+        }
         if has_bang {
             self.word("!");
         }
@@ -732,18 +730,20 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
             self.space();
         }
         match delim {
-            MacDelimiter::Parenthesis => self.popen(),
-            MacDelimiter::Bracket => self.word("["),
-            MacDelimiter::Brace => {
+            DelimToken::Paren => self.popen(),
+            DelimToken::Bracket => self.word("["),
+            DelimToken::NoDelim => self.word(" "),
+            DelimToken::Brace => {
                 self.head("");
                 self.bopen();
             }
         }
-        self.print_tts(tts, true);
+        self.print_tts(tts, convert_dollar_crate);
         match delim {
-            MacDelimiter::Parenthesis => self.pclose(),
-            MacDelimiter::Bracket => self.word("]"),
-            MacDelimiter::Brace => self.bclose(span),
+            DelimToken::Paren => self.pclose(),
+            DelimToken::Bracket => self.word("]"),
+            DelimToken::NoDelim => self.word(" "),
+            DelimToken::Brace => self.bclose(span),
         }
     }
 
@@ -1356,9 +1356,14 @@ impl<'a> State<'a> {
                 }
             }
             ast::ItemKind::MacroDef(ref macro_def) => {
-                let path = &ast::Path::from_ident(ast::Ident::with_empty_ctxt(sym::macro_rules));
                 self.print_mac_common(
-                    path, true, Some(item.ident), macro_def.stream(), MacDelimiter::Brace, item.span
+                    Some(&ast::Path::from_ident(ast::Ident::with_empty_ctxt(sym::macro_rules))),
+                    true,
+                    Some(item.ident),
+                    DelimToken::Brace,
+                    macro_def.stream(),
+                    true,
+                    item.span,
                 );
             }
         }
@@ -1747,10 +1752,11 @@ impl<'a> State<'a> {
     }
 
     crate fn print_mac(&mut self, m: &ast::Mac) {
-        self.print_mac_common(&m.node.path, true, None, m.node.stream(), m.node.delim, m.span);
+        self.print_mac_common(
+            Some(&m.node.path), true, None, m.node.delim.to_token(), m.node.stream(), true, m.span
+        );
     }
 
-
     fn print_call_post(&mut self, args: &[P<ast::Expr>]) {
         self.popen();
         self.commasep_exprs(Inconsistent, args);
diff --git a/src/test/pretty/cast-lt.pp b/src/test/pretty/cast-lt.pp
index c9fd7816360..1ae30983d20 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/stmt_expr_attributes.rs b/src/test/pretty/stmt_expr_attributes.rs
index 0d438d457bf..acc11f3f84a 100644
--- a/src/test/pretty/stmt_expr_attributes.rs
+++ b/src/test/pretty/stmt_expr_attributes.rs
@@ -113,7 +113,7 @@ fn _8() {
 fn _9() {
     macro_rules!
     stmt_mac
-    {(  ) => { let _ = (  ) ; } }
+    {() => {let _ = () ; } }
 
     #[rustc_dummy]
     stmt_mac!();
@@ -130,7 +130,7 @@ fn _9() {
     let _ = ();
 }
 
-macro_rules! expr_mac {(  ) => { (  ) } }
+macro_rules! expr_mac {() => {() } }
 
 fn _10() {
     let _ = #[rustc_dummy] expr_mac!();
diff --git a/src/test/ui/editions/edition-keywords-2015-2018-expansion.stderr b/src/test/ui/editions/edition-keywords-2015-2018-expansion.stderr
index 9724f78db66..321545740cf 100644
--- a/src/test/ui/editions/edition-keywords-2015-2018-expansion.stderr
+++ b/src/test/ui/editions/edition-keywords-2015-2018-expansion.stderr
@@ -7,8 +7,8 @@ LL |     produces_async! {}
    = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
 help: you can escape reserved keywords to use them as identifiers
    |
-LL | (  ) => ( pub fn r#async (  ) {  } )
-   |                  ^^^^^^^
+LL | () => (pub fn r#async () { })
+   |               ^^^^^^^
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/editions/edition-keywords-2018-2015-parsing.stderr b/src/test/ui/editions/edition-keywords-2018-2015-parsing.stderr
index 0d8850c2397..3c4a1533534 100644
--- a/src/test/ui/editions/edition-keywords-2018-2015-parsing.stderr
+++ b/src/test/ui/editions/edition-keywords-2018-2015-parsing.stderr
@@ -31,10 +31,10 @@ LL |     r#async = consumes_async_raw!(async);
    |                                   ^^^^^ no rules expected this token in macro call
 
 error: macro expansion ends with an incomplete expression: expected one of `move`, `|`, or `||`
-  --> <::edition_kw_macro_2015::passes_ident macros>:1:25
+  --> <::edition_kw_macro_2015::passes_ident macros>:1:22
    |
-LL | ( $ i : ident ) => ( $ i )
-   |                         ^ expected one of `move`, `|`, or `||` here
+LL | ($ i : ident) => ($ i)
+   |                      ^ expected one of `move`, `|`, or `||` here
    | 
   ::: $DIR/edition-keywords-2018-2015-parsing.rs:16:8
    |
diff --git a/src/test/ui/editions/edition-keywords-2018-2018-expansion.stderr b/src/test/ui/editions/edition-keywords-2018-2018-expansion.stderr
index ab601c8d8a7..8942e3ce430 100644
--- a/src/test/ui/editions/edition-keywords-2018-2018-expansion.stderr
+++ b/src/test/ui/editions/edition-keywords-2018-2018-expansion.stderr
@@ -7,8 +7,8 @@ LL |     produces_async! {}
    = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
 help: you can escape reserved keywords to use them as identifiers
    |
-LL | (  ) => ( pub fn r#async (  ) {  } )
-   |                  ^^^^^^^
+LL | () => (pub fn r#async () { })
+   |               ^^^^^^^
 
 error: aborting due to previous error
 
diff --git a/src/test/ui/editions/edition-keywords-2018-2018-parsing.stderr b/src/test/ui/editions/edition-keywords-2018-2018-parsing.stderr
index 0604b600d23..46aa9ca34e1 100644
--- a/src/test/ui/editions/edition-keywords-2018-2018-parsing.stderr
+++ b/src/test/ui/editions/edition-keywords-2018-2018-parsing.stderr
@@ -31,10 +31,10 @@ LL |     r#async = consumes_async_raw!(async);
    |                                   ^^^^^ no rules expected this token in macro call
 
 error: macro expansion ends with an incomplete expression: expected one of `move`, `|`, or `||`
-  --> <::edition_kw_macro_2018::passes_ident macros>:1:25
+  --> <::edition_kw_macro_2018::passes_ident macros>:1:22
    |
-LL | ( $ i : ident ) => ( $ i )
-   |                         ^ expected one of `move`, `|`, or `||` here
+LL | ($ i : ident) => ($ i)
+   |                      ^ expected one of `move`, `|`, or `||` here
    | 
   ::: $DIR/edition-keywords-2018-2018-parsing.rs:16:8
    |
diff --git a/src/test/ui/macro_backtrace/main.stderr b/src/test/ui/macro_backtrace/main.stderr
index 239b53f2338..6f82d4040bc 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 ebfed41bc28..545ed33cd10 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/macros/trace_faulty_macros.stderr b/src/test/ui/macros/trace_faulty_macros.stderr
index fc05012377b..f06e6581ff7 100644
--- a/src/test/ui/macros/trace_faulty_macros.stderr
+++ b/src/test/ui/macros/trace_faulty_macros.stderr
@@ -17,7 +17,7 @@ LL |     my_faulty_macro!();
    |     ^^^^^^^^^^^^^^^^^^^
    |
    = note: expanding `my_faulty_macro! {  }`
-   = note: to `my_faulty_macro ! ( bcd ) ;`
+   = note: to `my_faulty_macro ! (bcd) ;`
    = note: expanding `my_faulty_macro! { bcd }`
 
 error: recursion limit reached while expanding the macro `my_recursive_macro`
@@ -38,13 +38,13 @@ LL |     my_recursive_macro!();
    |     ^^^^^^^^^^^^^^^^^^^^^^
    |
    = note: expanding `my_recursive_macro! {  }`
-   = note: to `my_recursive_macro ! (  ) ;`
+   = note: to `my_recursive_macro ! () ;`
    = note: expanding `my_recursive_macro! {  }`
-   = note: to `my_recursive_macro ! (  ) ;`
+   = note: to `my_recursive_macro ! () ;`
    = note: expanding `my_recursive_macro! {  }`
-   = note: to `my_recursive_macro ! (  ) ;`
+   = note: to `my_recursive_macro ! () ;`
    = note: expanding `my_recursive_macro! {  }`
-   = note: to `my_recursive_macro ! (  ) ;`
+   = note: to `my_recursive_macro ! () ;`
 
 error: aborting due to 2 previous errors
 
diff --git a/src/test/ui/proc-macro/attribute-spans-preserved.stdout b/src/test/ui/proc-macro/attribute-spans-preserved.stdout
index b1487fcd5ed..b2be35e8259 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" ; } }
diff --git a/src/test/ui/proc-macro/dollar-crate-issue-57089.stdout b/src/test/ui/proc-macro/dollar-crate-issue-57089.stdout
index 0611fcb13f2..0fe02a9a34d 100644
--- a/src/test/ui/proc-macro/dollar-crate-issue-57089.stdout
+++ b/src/test/ui/proc-macro/dollar-crate-issue-57089.stdout
@@ -1,4 +1,4 @@
-PRINT-BANG INPUT (DISPLAY): struct M ( $crate :: S ) ;
+PRINT-BANG INPUT (DISPLAY): struct M ($crate :: S) ;
 PRINT-BANG INPUT (DEBUG): TokenStream [
     Ident {
         ident: "struct",
@@ -39,7 +39,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
     },
 ]
 PRINT-ATTR INPUT (DISPLAY): struct A(crate::S);
-PRINT-ATTR RE-COLLECTED (DISPLAY): struct A ( $crate :: S ) ;
+PRINT-ATTR RE-COLLECTED (DISPLAY): struct A ($crate :: S) ;
 PRINT-ATTR INPUT (DEBUG): TokenStream [
     Ident {
         ident: "struct",
diff --git a/src/test/ui/proc-macro/dollar-crate-issue-62325.stdout b/src/test/ui/proc-macro/dollar-crate-issue-62325.stdout
index 6c483d7a91b..a499e1362ec 100644
--- a/src/test/ui/proc-macro/dollar-crate-issue-62325.stdout
+++ b/src/test/ui/proc-macro/dollar-crate-issue-62325.stdout
@@ -1,5 +1,5 @@
 PRINT-ATTR INPUT (DISPLAY): struct A(identity!(crate :: S));
-PRINT-ATTR RE-COLLECTED (DISPLAY): struct A ( identity ! ( $crate :: S ) ) ;
+PRINT-ATTR RE-COLLECTED (DISPLAY): struct A (identity ! ($crate :: S)) ;
 PRINT-ATTR INPUT (DEBUG): TokenStream [
     Ident {
         ident: "struct",
@@ -55,7 +55,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
     },
 ]
 PRINT-ATTR INPUT (DISPLAY): struct B(identity!(::dollar_crate_external :: S));
-PRINT-ATTR RE-COLLECTED (DISPLAY): struct B ( identity ! ( $crate :: S ) ) ;
+PRINT-ATTR RE-COLLECTED (DISPLAY): struct B (identity ! ($crate :: S)) ;
 PRINT-ATTR INPUT (DEBUG): TokenStream [
     Ident {
         ident: "struct",
diff --git a/src/test/ui/proc-macro/dollar-crate.stdout b/src/test/ui/proc-macro/dollar-crate.stdout
index 3c88ee99842..72b02ebcb76 100644
--- a/src/test/ui/proc-macro/dollar-crate.stdout
+++ b/src/test/ui/proc-macro/dollar-crate.stdout
@@ -1,4 +1,4 @@
-PRINT-BANG INPUT (DISPLAY): struct M ( $crate :: S ) ;
+PRINT-BANG INPUT (DISPLAY): struct M ($crate :: S) ;
 PRINT-BANG INPUT (DEBUG): TokenStream [
     Ident {
         ident: "struct",
@@ -39,7 +39,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
     },
 ]
 PRINT-ATTR INPUT (DISPLAY): struct A(crate::S);
-PRINT-ATTR RE-COLLECTED (DISPLAY): struct A ( $crate :: S ) ;
+PRINT-ATTR RE-COLLECTED (DISPLAY): struct A ($crate :: S) ;
 PRINT-ATTR INPUT (DEBUG): TokenStream [
     Ident {
         ident: "struct",
@@ -80,7 +80,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
     },
 ]
 PRINT-DERIVE INPUT (DISPLAY): struct D(crate::S);
-PRINT-DERIVE RE-COLLECTED (DISPLAY): struct D ( $crate :: S ) ;
+PRINT-DERIVE RE-COLLECTED (DISPLAY): struct D ($crate :: S) ;
 PRINT-DERIVE INPUT (DEBUG): TokenStream [
     Ident {
         ident: "struct",
@@ -120,7 +120,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
         span: #2 bytes(LO..HI),
     },
 ]
-PRINT-BANG INPUT (DISPLAY): struct M ( $crate :: S ) ;
+PRINT-BANG INPUT (DISPLAY): struct M ($crate :: S) ;
 PRINT-BANG INPUT (DEBUG): TokenStream [
     Ident {
         ident: "struct",
@@ -161,7 +161,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
     },
 ]
 PRINT-ATTR INPUT (DISPLAY): struct A(::dollar_crate_external::S);
-PRINT-ATTR RE-COLLECTED (DISPLAY): struct A ( $crate :: S ) ;
+PRINT-ATTR RE-COLLECTED (DISPLAY): struct A ($crate :: S) ;
 PRINT-ATTR INPUT (DEBUG): TokenStream [
     Ident {
         ident: "struct",
@@ -202,7 +202,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
     },
 ]
 PRINT-DERIVE INPUT (DISPLAY): struct D(::dollar_crate_external::S);
-PRINT-DERIVE RE-COLLECTED (DISPLAY): struct D ( $crate :: S ) ;
+PRINT-DERIVE RE-COLLECTED (DISPLAY): struct D ($crate :: S) ;
 PRINT-DERIVE INPUT (DEBUG): TokenStream [
     Ident {
         ident: "struct",