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};
}
}
+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,
} 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);
_ => {}
}
}
- 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()
+ );
+ }
}
}
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("!");
}
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),
}
}
}
}
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,
);
}
}
}
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);
// 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; }
fn _9() {
macro_rules!
stmt_mac
- {( ) => { let _ = ( ) ; } }
+ {() => {let _ = () ; } }
#[rustc_dummy]
stmt_mac!();
let _ = ();
}
-macro_rules! expr_mac {( ) => { ( ) } }
+macro_rules! expr_mac {() => {() } }
fn _10() {
let _ = #[rustc_dummy] expr_mac!();
= 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
| ^^^^^ 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
|
= 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
| ^^^^^ 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
|
|
::: <::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`
|
::: <::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
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= 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!")) ; }`
| ^^^^^^^^^^^^^^^^^^^
|
= 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`
| ^^^^^^^^^^^^^^^^^^^^^^
|
= 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
-fn main ( ) { let y : u32 = "z" ; { let x : u32 = "y" ; } }
+fn main () {let y : u32 = "z" ; {let x : u32 = "y" ; } }
-PRINT-BANG INPUT (DISPLAY): struct M ( $crate :: S ) ;
+PRINT-BANG INPUT (DISPLAY): struct M ($crate :: S) ;
PRINT-BANG INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
},
]
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",
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",
},
]
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",
-PRINT-BANG INPUT (DISPLAY): struct M ( $crate :: S ) ;
+PRINT-BANG INPUT (DISPLAY): struct M ($crate :: S) ;
PRINT-BANG INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
},
]
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",
},
]
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",
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",
},
]
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",
},
]
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",