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("#["),
}
self.ibox(0);
if let Some(mi) = attr.meta() {
self.print_meta_item(&mi);
} else {
match attr.tokens.trees().next() {
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() {
self.space();
self.print_tts(attr.tokens.clone(), true);
}
match attr.tokens.trees().next() {
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() {
self.space();
self.print_tts(attr.tokens.clone(), true);
}
}
}

View File

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

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