pprust: Do not convert attributes into `MetaItem`s for printing

Fixes https://github.com/rust-lang/rust/issues/62628
This commit is contained in:
Vadim Petrochenkov 2019-07-13 23:24:58 +03:00
parent 160c40bc88
commit 75896011dc
3 changed files with 20 additions and 17 deletions

View File

@ -617,21 +617,17 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
ast::AttrStyle::Outer => self.word("#["), ast::AttrStyle::Outer => self.word("#["),
} }
self.ibox(0); self.ibox(0);
if let Some(mi) = attr.meta() { match attr.tokens.trees().next() {
self.print_meta_item(&mi); Some(TokenTree::Delimited(_, delim, tts)) => {
} else { self.print_mac_common(
match attr.tokens.trees().next() { Some(&attr.path), false, None, delim, tts, true, attr.span
Some(TokenTree::Delimited(_, delim, tts)) => { );
self.print_mac_common( }
Some(&attr.path), false, None, delim, tts, true, attr.span tree => {
); self.print_path(&attr.path, false, 0);
} if tree.is_some() {
tree => { self.space();
self.print_path(&attr.path, false, 0); self.print_tts(attr.tokens.clone(), true);
if tree.is_some() {
self.space();
self.print_tts(attr.tokens.clone(), true);
}
} }
} }
} }

View File

@ -5,10 +5,10 @@
#![feature(rustc_attrs)] #![feature(rustc_attrs)]
fn main() { 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] #[rustc_dummy = 8]
fn f() { } fn f() { }
#[rustc_dummy(1, 2, 3)] #[rustc_dummy(1 , 2 , 3)]
fn g() { } fn g() { }
} }

View File

@ -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() { }