Skip to content

Commit 7589601

Browse files
committed
pprust: Do not convert attributes into MetaItems for printing
Fixes #62628
1 parent 160c40b commit 7589601

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

src/libsyntax/print/pprust.rs

+11-15
Original file line numberDiff line numberDiff line change
@@ -617,21 +617,17 @@ pub trait PrintState<'a>: std::ops::Deref<Target=pp::Printer> + std::ops::DerefM
617617
ast::AttrStyle::Outer => self.word("#["),
618618
}
619619
self.ibox(0);
620-
if let Some(mi) = attr.meta() {
621-
self.print_meta_item(&mi);
622-
} else {
623-
match attr.tokens.trees().next() {
624-
Some(TokenTree::Delimited(_, delim, tts)) => {
625-
self.print_mac_common(
626-
Some(&attr.path), false, None, delim, tts, true, attr.span
627-
);
628-
}
629-
tree => {
630-
self.print_path(&attr.path, false, 0);
631-
if tree.is_some() {
632-
self.space();
633-
self.print_tts(attr.tokens.clone(), true);
634-
}
620+
match attr.tokens.trees().next() {
621+
Some(TokenTree::Delimited(_, delim, tts)) => {
622+
self.print_mac_common(
623+
Some(&attr.path), false, None, delim, tts, true, attr.span
624+
);
625+
}
626+
tree => {
627+
self.print_path(&attr.path, false, 0);
628+
if tree.is_some() {
629+
self.space();
630+
self.print_tts(attr.tokens.clone(), true);
635631
}
636632
}
637633
}

src/test/pretty/attr-literals.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
#![feature(rustc_attrs)]
66

77
fn main() {
8-
#![rustc_dummy("hi", 1, 2, 1.012, pi = 3.14, bye, name("John"))]
8+
#![rustc_dummy("hi" , 1 , 2 , 1.012 , pi = 3.14 , bye , name ("John"))]
99
#[rustc_dummy = 8]
1010
fn f() { }
1111

12-
#[rustc_dummy(1, 2, 3)]
12+
#[rustc_dummy(1 , 2 , 3)]
1313
fn g() { }
1414
}
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Keywords in attribute paths are printed as raw idents,
2+
// but keywords in attribute arguments are not.
3+
4+
// pp-exact
5+
6+
#[rustfmt::r#final(final)]
7+
fn main() { }

0 commit comments

Comments
 (0)