diff --git a/src/librustc/hir/print.rs b/src/librustc/hir/print.rs index 5a14b30e699be..3e571baaa4e51 100644 --- a/src/librustc/hir/print.rs +++ b/src/librustc/hir/print.rs @@ -4,7 +4,7 @@ use syntax::source_map::{SourceMap, Spanned}; use syntax::parse::ParseSess; use syntax::print::pp::{self, Breaks}; use syntax::print::pp::Breaks::{Consistent, Inconsistent}; -use syntax::print::pprust::{Comments, PrintState}; +use syntax::print::pprust::{self, Comments, PrintState}; use syntax::symbol::kw; use syntax::util::parser::{self, AssocOp, Fixity}; use syntax_pos::{self, BytePos, FileName}; @@ -90,6 +90,15 @@ impl<'a> PrintState<'a> for State<'a> { fn comments(&mut self) -> &mut Option> { &mut self.comments } + + fn print_ident(&mut self, ident: ast::Ident) { + self.s.word(pprust::ast_ident_to_string(ident, ident.is_raw_guess())); + self.ann.post(self, AnnNode::Name(&ident.name)) + } + + fn print_generic_args(&mut self, args: &ast::GenericArgs, _colons_before_params: bool) { + span_bug!(args.span(), "AST generic args printed by HIR pretty-printer"); + } } pub const INDENT_UNIT: usize = 4; @@ -1442,15 +1451,6 @@ impl<'a> State<'a> { self.s.word(i.to_string()) } - pub fn print_ident(&mut self, ident: ast::Ident) { - if ident.is_raw_guess() { - self.s.word(format!("r#{}", ident.name)); - } else { - self.s.word(ident.as_str().to_string()); - } - self.ann.post(self, AnnNode::Name(&ident.name)) - } - pub fn print_name(&mut self, name: ast::Name) { self.print_ident(ast::Ident::with_empty_ctxt(name)) } diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs index 8801e89a0cfc4..6cfc1b77e03fe 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/mut_visit.rs b/src/libsyntax/mut_visit.rs index 11a1de13fc217..dc656222fbc10 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 0e3ce2787f3ed..16e0bace92584 100644 --- a/src/libsyntax/print/pprust.rs +++ b/src/libsyntax/print/pprust.rs @@ -4,7 +4,7 @@ use crate::ast::{Attribute, MacDelimiter, GenericArg}; use crate::util::parser::{self, AssocOp, Fixity}; use crate::attr; use crate::source_map::{self, SourceMap, Spanned}; -use crate::parse::token::{self, BinOpToken, Nonterminal, Token, TokenKind}; +use crate::parse::token::{self, BinOpToken, DelimToken, Nonterminal, Token, TokenKind}; use crate::parse::lexer::comments; use crate::parse::{self, ParseSess}; use crate::print::pp::{self, Breaks}; @@ -20,6 +20,11 @@ use syntax_pos::{DUMMY_SP, FileName, Span}; use std::borrow::Cow; +pub enum MacHeader<'a> { + Path(&'a ast::Path), + Keyword(&'static str), +} + pub enum AnnNode<'a> { Ident(&'a ast::Ident), Name(&'a ast::Name), @@ -188,7 +193,7 @@ pub fn literal_to_string(lit: token::Lit) -> String { } /// Print an ident from AST, `$crate` is converted into its respective crate name. -fn ast_ident_to_string(ident: ast::Ident, is_raw: bool) -> String { +pub fn ast_ident_to_string(ident: ast::Ident, is_raw: bool) -> String { ident_to_string(ident.name, is_raw, Some(ident.span)) } @@ -446,6 +451,8 @@ impl std::ops::DerefMut for State<'_> { pub trait PrintState<'a>: std::ops::Deref + std::ops::DerefMut { fn comments(&mut self) -> &mut Option>; + fn print_ident(&mut self, ident: ast::Ident); + fn print_generic_args(&mut self, args: &ast::GenericArgs, colons_before_params: bool); fn commasep(&mut self, b: Breaks, elts: &[T], mut op: F) where F: FnMut(&mut Self, &T), @@ -596,17 +603,6 @@ pub trait PrintState<'a>: std::ops::Deref + std::ops::DerefM } } - fn print_attribute_path(&mut self, path: &ast::Path) { - for (i, segment) in path.segments.iter().enumerate() { - if i > 0 { - self.word("::"); - } - if segment.ident.name != kw::PathRoot { - self.word(ast_ident_to_string(segment.ident, segment.ident.is_raw_guess())); - } - } - } - fn print_attribute(&mut self, attr: &ast::Attribute) { self.print_attribute_inline(attr, false) } @@ -625,13 +621,22 @@ pub trait PrintState<'a>: std::ops::Deref + std::ops::DerefM ast::AttrStyle::Inner => self.word("#!["), ast::AttrStyle::Outer => self.word("#["), } - if let Some(mi) = attr.meta() { - self.print_meta_item(&mi); - } else { - self.print_attribute_path(&attr.path); - self.space(); - self.print_tts(attr.tokens.clone(), true); + self.ibox(0); + match attr.tokens.trees().next() { + Some(TokenTree::Delimited(_, delim, tts)) => { + self.print_mac_common( + Some(MacHeader::Path(&attr.path)), false, None, delim, tts, true, attr.span + ); + } + tree => { + self.print_path(&attr.path, false, 0); + if tree.is_some() { + self.space(); + self.print_tts(attr.tokens.clone(), true); + } + } } + self.end(); self.word("]"); } } @@ -650,15 +655,15 @@ pub trait PrintState<'a>: std::ops::Deref + std::ops::DerefM fn print_meta_item(&mut self, item: &ast::MetaItem) { self.ibox(INDENT_UNIT); match item.node { - ast::MetaItemKind::Word => self.print_attribute_path(&item.path), + ast::MetaItemKind::Word => self.print_path(&item.path, false, 0), ast::MetaItemKind::NameValue(ref value) => { - self.print_attribute_path(&item.path); + self.print_path(&item.path, false, 0); self.space(); self.word_space("="); self.print_literal(value); } ast::MetaItemKind::List(ref items) => { - self.print_attribute_path(&item.path); + self.print_path(&item.path, false, 0); self.popen(); self.commasep(Consistent, &items[..], @@ -687,36 +692,90 @@ pub trait PrintState<'a>: std::ops::Deref + 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() + ); + } } } fn print_tts(&mut self, tts: tokenstream::TokenStream, convert_dollar_crate: bool) { - self.ibox(0); for (i, tt) in tts.into_trees().enumerate() { if i != 0 { self.space(); } self.print_tt(tt, convert_dollar_crate); } + } + + fn print_mac_common( + &mut self, + header: Option>, + has_bang: bool, + ident: Option, + delim: DelimToken, + tts: TokenStream, + convert_dollar_crate: bool, + span: Span, + ) { + if delim == DelimToken::Brace { + self.cbox(INDENT_UNIT); + } + match header { + Some(MacHeader::Path(path)) => self.print_path(path, false, 0), + Some(MacHeader::Keyword(kw)) => self.word(kw), + None => {} + } + if has_bang { + self.word("!"); + } + if let Some(ident) = ident { + self.nbsp(); + self.print_ident(ident); + } + match delim { + DelimToken::Brace => { + if header.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::Brace => self.bclose(span), + _ => self.word(token_kind_to_string(&token::CloseDelim(delim))), + } } -} -impl<'a> PrintState<'a> for State<'a> { - fn comments(&mut self) -> &mut Option> { - &mut self.comments + fn print_path(&mut self, path: &ast::Path, colons_before_params: bool, depth: usize) { + self.maybe_print_comment(path.span.lo()); + + for (i, segment) in path.segments[..path.segments.len() - depth].iter().enumerate() { + if i > 0 { + self.word("::") + } + self.print_path_segment(segment, colons_before_params); + } } -} -impl<'a> State<'a> { - crate fn head>>(&mut self, w: S) { + fn print_path_segment(&mut self, segment: &ast::PathSegment, colons_before_params: bool) { + if segment.ident.name != kw::PathRoot { + self.print_ident(segment.ident); + if let Some(ref args) = segment.args { + self.print_generic_args(args, colons_before_params); + } + } + } + + fn head>>(&mut self, w: S) { let w = w.into(); // outer-box is consistent self.cbox(INDENT_UNIT); @@ -728,36 +787,103 @@ impl<'a> State<'a> { } } - crate fn bopen(&mut self) { - self.s.word("{"); + fn bopen(&mut self) { + self.word("{"); self.end(); // close the head-box } - crate fn bclose_maybe_open(&mut self, span: syntax_pos::Span, close_box: bool) { + fn bclose_maybe_open(&mut self, span: syntax_pos::Span, close_box: bool) { self.maybe_print_comment(span.hi()); self.break_offset_if_not_bol(1, -(INDENT_UNIT as isize)); - self.s.word("}"); + self.word("}"); if close_box { self.end(); // close the outer-box } } - crate fn bclose(&mut self, span: syntax_pos::Span) { + + fn bclose(&mut self, span: syntax_pos::Span) { self.bclose_maybe_open(span, true) } - crate fn break_offset_if_not_bol(&mut self, n: usize, off: isize) { - if !self.s.is_beginning_of_line() { - self.s.break_offset(n, off) + fn break_offset_if_not_bol(&mut self, n: usize, off: isize) { + if !self.is_beginning_of_line() { + self.break_offset(n, off) } else { - if off != 0 && self.s.last_token().is_hardbreak_tok() { + if off != 0 && self.last_token().is_hardbreak_tok() { // We do something pretty sketchy here: tuck the nonzero // offset-adjustment we were going to deposit along with the // break into the previous hardbreak. - self.s.replace_last_token(pp::Printer::hardbreak_tok_offset(off)); + self.replace_last_token(pp::Printer::hardbreak_tok_offset(off)); + } + } + } +} + +impl<'a> PrintState<'a> for State<'a> { + fn comments(&mut self) -> &mut Option> { + &mut self.comments + } + + fn print_ident(&mut self, ident: ast::Ident) { + self.s.word(ast_ident_to_string(ident, ident.is_raw_guess())); + self.ann.post(self, AnnNode::Ident(&ident)) + } + + fn print_generic_args(&mut self, args: &ast::GenericArgs, colons_before_params: bool) { + if colons_before_params { + self.s.word("::") + } + + match *args { + ast::GenericArgs::AngleBracketed(ref data) => { + self.s.word("<"); + + self.commasep(Inconsistent, &data.args, |s, generic_arg| { + s.print_generic_arg(generic_arg) + }); + + let mut comma = data.args.len() != 0; + + for constraint in data.constraints.iter() { + if comma { + self.word_space(",") + } + self.print_ident(constraint.ident); + self.s.space(); + match constraint.kind { + ast::AssocTyConstraintKind::Equality { ref ty } => { + self.word_space("="); + self.print_type(ty); + } + ast::AssocTyConstraintKind::Bound { ref bounds } => { + self.print_type_bounds(":", &*bounds); + } + } + comma = true; + } + + self.s.word(">") + } + + ast::GenericArgs::Parenthesized(ref data) => { + self.s.word("("); + self.commasep( + Inconsistent, + &data.inputs, + |s, ty| s.print_type(ty)); + self.s.word(")"); + + if let Some(ref ty) = data.output { + self.space_if_not_bol(); + self.word_space("->"); + self.print_type(ty); + } } } } +} +impl<'a> State<'a> { // Synthesizes a comment that was not textually present in the original source // file. pub fn synth_comment(&mut self, text: String) { @@ -1231,33 +1357,24 @@ impl<'a> State<'a> { self.s.word(";"); } ast::ItemKind::Mac(ref mac) => { - if item.ident.name == kw::Invalid { - self.print_mac(mac); - match mac.node.delim { - MacDelimiter::Brace => {} - _ => self.s.word(";"), - } - } else { - self.print_path(&mac.node.path, false, 0); - self.s.word("! "); - self.print_ident(item.ident); - self.cbox(INDENT_UNIT); - self.popen(); - self.print_tts(mac.node.stream(), true); - self.pclose(); - self.s.word(";"); - self.end(); + self.print_mac(mac); + match mac.node.delim { + MacDelimiter::Brace => {} + _ => self.s.word(";"), } } - ast::ItemKind::MacroDef(ref tts) => { - self.s.word("macro_rules! "); - self.print_ident(item.ident); - self.cbox(INDENT_UNIT); - self.popen(); - self.print_tts(tts.stream(), true); - self.pclose(); - self.s.word(";"); - self.end(); + ast::ItemKind::MacroDef(ref macro_def) => { + let (kw, has_bang) = + if macro_def.legacy { ("macro_rules", true) } else { ("macro", false) }; + self.print_mac_common( + Some(MacHeader::Keyword(kw)), + has_bang, + Some(item.ident), + DelimToken::Brace, + macro_def.stream(), + true, + item.span, + ); } } self.ann.post(self, AnnNode::Item(item)) @@ -1645,25 +1762,17 @@ impl<'a> State<'a> { } crate fn print_mac(&mut self, m: &ast::Mac) { - self.print_path(&m.node.path, false, 0); - self.s.word("!"); - match m.node.delim { - MacDelimiter::Parenthesis => self.popen(), - MacDelimiter::Bracket => self.s.word("["), - MacDelimiter::Brace => { - self.head(""); - self.bopen(); - } - } - self.print_tts(m.node.stream(), true); - match m.node.delim { - MacDelimiter::Parenthesis => self.pclose(), - MacDelimiter::Bracket => self.s.word("]"), - MacDelimiter::Brace => self.bclose(m.span), - } + self.print_mac_common( + Some(MacHeader::Path(&m.node.path)), + true, + None, + m.node.delim.to_token(), + m.node.stream(), + true, + m.span, + ); } - fn print_call_post(&mut self, args: &[P]) { self.popen(); self.commasep_exprs(Inconsistent, args); @@ -2204,11 +2313,6 @@ impl<'a> State<'a> { } } - crate fn print_ident(&mut self, ident: ast::Ident) { - self.s.word(ast_ident_to_string(ident, ident.is_raw_guess())); - self.ann.post(self, AnnNode::Ident(&ident)) - } - crate fn print_usize(&mut self, i: usize) { self.s.word(i.to_string()) } @@ -2218,31 +2322,6 @@ impl<'a> State<'a> { self.ann.post(self, AnnNode::Name(&name)) } - fn print_path(&mut self, - path: &ast::Path, - colons_before_params: bool, - depth: usize) { - self.maybe_print_comment(path.span.lo()); - - for (i, segment) in path.segments[..path.segments.len() - depth].iter().enumerate() { - if i > 0 { - self.s.word("::") - } - self.print_path_segment(segment, colons_before_params); - } - } - - fn print_path_segment(&mut self, - segment: &ast::PathSegment, - colons_before_params: bool) { - if segment.ident.name != kw::PathRoot { - self.print_ident(segment.ident); - if let Some(ref args) = segment.args { - self.print_generic_args(args, colons_before_params); - } - } - } - fn print_qpath(&mut self, path: &ast::Path, qself: &ast::QSelf, @@ -2266,62 +2345,6 @@ impl<'a> State<'a> { } } - fn print_generic_args(&mut self, - args: &ast::GenericArgs, - colons_before_params: bool) - { - if colons_before_params { - self.s.word("::") - } - - match *args { - ast::GenericArgs::AngleBracketed(ref data) => { - self.s.word("<"); - - self.commasep(Inconsistent, &data.args, |s, generic_arg| { - s.print_generic_arg(generic_arg) - }); - - let mut comma = data.args.len() != 0; - - for constraint in data.constraints.iter() { - if comma { - self.word_space(",") - } - self.print_ident(constraint.ident); - self.s.space(); - match constraint.kind { - ast::AssocTyConstraintKind::Equality { ref ty } => { - self.word_space("="); - self.print_type(ty); - } - ast::AssocTyConstraintKind::Bound { ref bounds } => { - self.print_type_bounds(":", &*bounds); - } - } - comma = true; - } - - self.s.word(">") - } - - ast::GenericArgs::Parenthesized(ref data) => { - self.s.word("("); - self.commasep( - Inconsistent, - &data.inputs, - |s, ty| s.print_type(ty)); - self.s.word(")"); - - if let Some(ref ty) = data.output { - self.space_if_not_bol(); - self.word_space("->"); - self.print_type(ty); - } - } - } - } - crate fn print_pat(&mut self, pat: &ast::Pat) { self.maybe_print_comment(pat.span.lo()); self.ann.pre(self, AnnNode::Pat(pat)); diff --git a/src/test/pretty/attr-literals.rs b/src/test/pretty/attr-literals.rs index 44d2c5db3e668..bcd6ffaaf815b 100644 --- a/src/test/pretty/attr-literals.rs +++ b/src/test/pretty/attr-literals.rs @@ -5,10 +5,10 @@ #![feature(rustc_attrs)] fn main() { - #![rustc_dummy("hi", 1, 2, 1.012, pi = 3.14, bye, name("John"))] + #![rustc_dummy("hi" , 1 , 2 , 1.012 , pi = 3.14 , bye , name ("John"))] #[rustc_dummy = 8] fn f() { } - #[rustc_dummy(1, 2, 3)] + #[rustc_dummy(1 , 2 , 3)] fn g() { } } diff --git a/src/test/pretty/attr-tokens-raw-ident.rs b/src/test/pretty/attr-tokens-raw-ident.rs new file mode 100644 index 0000000000000..bb2c4bb558e57 --- /dev/null +++ b/src/test/pretty/attr-tokens-raw-ident.rs @@ -0,0 +1,7 @@ +// Keywords in attribute paths are printed as raw idents, +// but keywords in attribute arguments are not. + +// pp-exact + +#[rustfmt::r#final(final)] +fn main() { } diff --git a/src/test/pretty/cast-lt.pp b/src/test/pretty/cast-lt.pp index 351889da2453d..47a7dac95b9c5 100644 --- a/src/test/pretty/cast-lt.pp +++ b/src/test/pretty/cast-lt.pp @@ -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; } diff --git a/src/test/pretty/delimited-token-groups.rs b/src/test/pretty/delimited-token-groups.rs new file mode 100644 index 0000000000000..768f27ad23a8e --- /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 ee81cce864171..02951395e70b4 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/issue-4264.pp b/src/test/pretty/issue-4264.pp index ad663412e7776..bd839d3542199 100644 --- a/src/test/pretty/issue-4264.pp +++ b/src/test/pretty/issue-4264.pp @@ -29,8 +29,8 @@ - (($crate::fmt::format as - for<'r> fn(std::fmt::Arguments<'r>) -> std::string::String {std::fmt::format})(((<$crate::fmt::Arguments>::new_v1 + ((::alloc::fmt::format as + for<'r> fn(std::fmt::Arguments<'r>) -> std::string::String {std::fmt::format})(((<::std::fmt::Arguments>::new_v1 as fn(&[&str], &[std::fmt::ArgumentV1<'_>]) -> std::fmt::Arguments<'_> {std::fmt::Arguments::<'_>::new_v1})((&([("test" as diff --git a/src/test/pretty/macro.rs b/src/test/pretty/macro.rs new file mode 100644 index 0000000000000..39677d1dc2da3 --- /dev/null +++ b/src/test/pretty/macro.rs @@ -0,0 +1,7 @@ +// pp-exact + +#![feature(decl_macro)] + +macro mac { ($ arg : expr) => { $ arg + $ arg } } + +fn main() { } diff --git a/src/test/pretty/stmt_expr_attributes.rs b/src/test/pretty/stmt_expr_attributes.rs index d81485b555fa6..02d93238dd643 100644 --- a/src/test/pretty/stmt_expr_attributes.rs +++ b/src/test/pretty/stmt_expr_attributes.rs @@ -111,29 +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() { @@ -236,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 b835bf8782cc3..570dece023dea 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! 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 129311599141f..7e46260d5163f 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/run-pass/proc-macro/auxiliary/derive-b.rs b/src/test/run-pass/proc-macro/auxiliary/derive-b.rs index fd056d605a0e6..3e6af67a9f412 100644 --- a/src/test/run-pass/proc-macro/auxiliary/derive-b.rs +++ b/src/test/run-pass/proc-macro/auxiliary/derive-b.rs @@ -10,7 +10,7 @@ use proc_macro::TokenStream; #[proc_macro_derive(B, attributes(B, C))] pub fn derive(input: TokenStream) -> TokenStream { let input = input.to_string(); - assert!(input.contains("#[B [ arbitrary tokens ]]")); + assert!(input.contains("#[B[arbitrary tokens]]")); assert!(input.contains("struct B {")); assert!(input.contains("#[C]")); "".parse().unwrap() 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 9724f78db6618..321545740cf48 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 0d8850c2397c6..3c4a153353447 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 ab601c8d8a707..8942e3ce430a8 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 0604b600d23d0..46aa9ca34e17c 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 239b53f2338c4..e7bd141ccd5ae 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 ebfed41bc280e..287f7b297d5c6 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 fc05012377b2a..f06e6581ff7fb 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 b1487fcd5edbd..faf3171215665 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 0611fcb13f267..0fe02a9a34d18 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 6c483d7a91bba..a499e1362ec0b 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 3c88ee99842a2..72b02ebcb76f4 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",