Skip to content

Commit

Permalink
pprust: Do not convert attributes into MetaItems for printing
Browse files Browse the repository at this point in the history
Fixes #62628
  • Loading branch information
petrochenkov committed Jul 15, 2019
1 parent 160c40b commit 7589601
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
26 changes: 11 additions & 15 deletions src/libsyntax/print/pprust.rs
Expand Up @@ -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);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/pretty/attr-literals.rs
Expand Up @@ -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() { }
}
7 changes: 7 additions & 0 deletions 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() { }

0 comments on commit 7589601

Please sign in to comment.