Skip to content

Improve print_tts by making space_between smarter #117433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/rustc_ast_pretty/src/lib.rs
Original file line number Diff line number Diff line change
@@ -5,6 +5,8 @@
#![deny(rustc::diagnostic_outside_of_impl)]
#![feature(associated_type_bounds)]
#![feature(box_patterns)]
#![feature(if_let_guard)]
#![feature(let_chains)]
#![feature(with_negative_coherence)]
#![recursion_limit = "256"]

176 changes: 144 additions & 32 deletions compiler/rustc_ast_pretty/src/pprust/state.rs
Original file line number Diff line number Diff line change
@@ -146,37 +146,144 @@ pub fn print_crate<'a>(
s.s.eof()
}

/// This makes printed token streams look slightly nicer,
/// and also addresses some specific regressions described in #63896 and #73345.
fn space_between(prev: &TokenTree, curr: &TokenTree) -> bool {
if let TokenTree::Token(token, _) = prev {
// No space after these tokens, e.g. `x.y`, `$e`
// (The carets point to `prev`.) ^ ^
if matches!(token.kind, token::Dot | token::Dollar) {
return false;
}
if let token::DocComment(comment_kind, ..) = token.kind {
return comment_kind != CommentKind::Line;
}
}
match curr {
// No space before these tokens, e.g. `foo,`, `println!`, `x.y`
// (The carets point to `curr`.) ^ ^ ^
//
// FIXME: having `Not` here works well for macro invocations like
// `println!()`, but is bad when `!` means "logical not" or "the never
// type", where the lack of space causes ugliness like this:
// `Fn() ->!`, `x =! y`, `if! x { f(); }`.
TokenTree::Token(token, _) => !matches!(token.kind, token::Comma | token::Not | token::Dot),
// No space before parentheses if preceded by these tokens, e.g. `foo(...)`
TokenTree::Delimited(_, Delimiter::Parenthesis, _) => {
!matches!(prev, TokenTree::Token(Token { kind: token::Ident(..), .. }, _))
}
// No space before brackets if preceded by these tokens, e.g. `#[...]`
TokenTree::Delimited(_, Delimiter::Bracket, _) => {
!matches!(prev, TokenTree::Token(Token { kind: token::Pound, .. }, _))
}
TokenTree::Delimited(..) => true,
fn is_punct(tt: &TokenTree) -> bool {
matches!(tt, TokenTree::Token(tok, _) if tok.is_punct())
}

/// Should two consecutive token trees be printed with a space between them?
///
/// NOTE: should always be false if both token trees are punctuation, so that
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this function should return anything in this case, it should rather have assert!(!is_punct(tt1) || !is_punct(tt2)) at the start instead.

The decision should be made based on Spacing in that case, and we should never reach this function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or the Spacing-based decision can be made inside this function, then it will be if is_punct(tt1) && is_punct(tt2) { ... } at the start instead of the assert.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer to avoid making any pretty-printing decisions based on Spacing in this PR. We can leave those to #114571, which will change how space_between is called. I plan to add the Spacing::Unknown in that PR, for tokens coming from proc macros. Those will be the cases where space_between is used.

With that decided, the current position of the assertion has the advantage that it's only checked in the case where space_between returns false.

So I think this is good enough to merge, or do a crater run if you think that is necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok.
Crater run is needed in any case.

/// any old proc macro that parses pretty-printed code won't glue together
/// tokens that shouldn't be glued.
///
/// Note: some old proc macros parse pretty-printed output, so changes here can
/// break old code. For example:
/// - #63896: `#[allow(unused,` must be printed rather than `#[allow(unused ,`
/// - #73345: `#[allow(unused)] must be printed rather than `# [allow(unused)]
///
fn space_between(prev: Option<&TokenTree>, tt1: &TokenTree, tt2: &TokenTree) -> bool {
use token::*;
use Delimiter::*;
use TokenTree::Delimited as Del;
use TokenTree::Token as Tok;

// Each match arm has one or more examples in comments.
match (tt1, tt2) {
// No space after line doc comments.
(Tok(Token { kind: DocComment(CommentKind::Line, ..), .. }, _), _) => false,

// `.` + NON-PUNCT: `x.y`, `tup.0`
// `$` + NON-PUNCT: `$e`
(Tok(Token { kind: Dot | Dollar, .. }, _), tt2) if !is_punct(tt2) => false,

// NON-PUNCT + `,`: `foo,`
// NON-PUNCT + `;`: `x = 3;`, `[T; 3]`
// NON-PUNCT + `.`: `x.y`, `tup.0`
// NON-PUNCT + `:`: `'a: loop { ... }`, `x: u8`, `where T: U`,
// `<Self as T>::x`, `Trait<'a>: Sized`, `X<Y<Z>>: Send`,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These examples still involve punctuation and need an update.

// `let (a, b): (u32, u32);`
(tt1, Tok(Token { kind: Comma | Semi | Dot | Colon, .. }, _)) if !is_punct(tt1) => false,

// ANYTHING-BUT-`,`|`:`|`mut`|`<` + `[`: `<expr>[1]`, `vec![]`, `#[attr]`,
// `#![attr]`, but not `data: [T; 0]`, `f(a, [])`, `&mut [T]`,
// `NonNull< [T] >`
(Tok(Token { kind: Comma | Colon | Lt, .. }, _), Del(_, Bracket, _)) => true,
(Tok(Token { kind: Ident(sym, is_raw), .. }, _), Del(_, Bracket, _))
if *sym == kw::Mut && !is_raw =>
{
true
}
(Tok(_, _), Del(_, Bracket, _)) => false,

// IDENT|`fn`|`Self`|`pub` + `(`: `f(3)`, `fn(x: u8)`, `Self()`, `pub(crate)`,
// but `let (a, b) = (1, 2)` needs a space after the `let`
(Tok(Token { kind: Ident(sym, is_raw), span }, _), Del(_, Parenthesis, _))
if !Ident::new(*sym, *span).is_reserved()
|| *sym == kw::Fn
|| *sym == kw::SelfUpper
|| *sym == kw::Pub
|| *is_raw =>
{
false
}

// IDENT|`self`|`Self`|`$crate`|`crate`|`super` + `::`: `x::y`,
// `Self::a`, `$crate::x`, `crate::x`, `super::x`, but
// `if ::a::b() { ... }` needs a space after the `if`.
(Tok(Token { kind: Ident(sym, is_raw), span }, _), Tok(Token { kind: ModSep, .. }, _))
if !Ident::new(*sym, *span).is_reserved()
|| sym.is_path_segment_keyword()
|| *is_raw =>
{
false
}

// `::` + IDENT: `foo::bar`
// `::` + `{`: `use a::{b, c}`
(
Tok(Token { kind: ModSep, .. }, _),
Tok(Token { kind: Ident(..), .. }, _) | Del(_, Brace, _),
) => false,

// `impl` + `<`: `impl<T> Foo<T> { ... }`
// `for` + `<`: `for<'a> fn()`
(Tok(Token { kind: Ident(sym, is_raw), .. }, _), Tok(Token { kind: Lt, .. }, _))
if (*sym == kw::Impl || *sym == kw::For) && !is_raw =>
{
false
}

// `fn` + IDENT + `<`: `fn f<T>(t: T) { ... }`
(Tok(Token { kind: Ident(..), .. }, _), Tok(Token { kind: Lt, .. }, _))
if let Some(prev) = prev
&& let Tok(Token { kind: Ident(sym, is_raw), .. }, _) = prev
&& *sym == kw::Fn
&& !is_raw =>
{
false
}

// `>` + `(`: `f::<u8>()`
// `>>` + `(`: `collect::<Vec<_>>()`
(Tok(Token { kind: Gt | BinOp(Shr), .. }, _), Del(_, Parenthesis, _)) => false,

// IDENT + `!`: `println!()`, but `if !x { ... }` needs a space after the `if`
(Tok(Token { kind: Ident(sym, is_raw), span }, _), Tok(Token { kind: Not, .. }, _))
if !Ident::new(*sym, *span).is_reserved() || *is_raw =>
{
false
}

// ANYTHING-BUT-`macro_rules` + `!` + NON-PUNCT-OR-BRACE: `foo!()`, `vec![]`,
// `if !cond { ... }`, but not `macro_rules! m { ... }`
(Tok(Token { kind: Not, .. }, _), tt2) if is_punct(tt2) => true,
(Tok(Token { kind: Not, .. }, _), Del(_, Brace, _)) => true,
(Tok(Token { kind: Not, .. }, _), _) =>
if let Some(prev) = prev
&& let Tok(Token { kind: Ident(sym, is_raw), .. }, _) = prev
&& *sym == sym::macro_rules
&& !is_raw
{
true
} else {
false
}

// `~` + `const`: `impl ~const Clone`
(Tok(Token { kind: Tilde, .. }, _), Tok(Token { kind: Ident(sym, is_raw), .. }, _))
if *sym == kw::Const && !is_raw =>
{
false
}

// `?` + `Sized`: `dyn ?Sized`
(Tok(Token { kind: Question, .. }, _), Tok(Token { kind: Ident(sym, is_raw), .. }, _))
if *sym == sym::Sized && !is_raw =>
{
false
}

_ => true,
}
}

@@ -571,14 +678,19 @@ pub trait PrintState<'a>: std::ops::Deref<Target = pp::Printer> + std::ops::Dere
}

fn print_tts(&mut self, tts: &TokenStream, convert_dollar_crate: bool) {
let mut prev = None;
let mut iter = tts.trees().peekable();
while let Some(tt) = iter.next() {
self.print_tt(tt, convert_dollar_crate);
if let Some(next) = iter.peek() {
if space_between(tt, next) {
if space_between(prev, tt, next) {
self.space();
} else {
// There must be a space between two punctuation tokens.
assert!(!is_punct(tt) || !is_punct(next));
}
}
prev = Some(tt);
}
}

1 change: 1 addition & 0 deletions compiler/rustc_span/src/symbol.rs
Original file line number Diff line number Diff line change
@@ -302,6 +302,7 @@ symbols! {
Saturating,
Send,
SeqCst,
Sized,
SliceIndex,
SliceIter,
Some,
6 changes: 3 additions & 3 deletions tests/pretty/ast-stmt-expr-attr.rs
Original file line number Diff line number Diff line change
@@ -113,11 +113,11 @@ fn syntax() {
let _ = #[attr] continue;
let _ = #[attr] return;
let _ = #[attr] foo!();
let _ = #[attr] foo!(#! [attr]);
let _ = #[attr] foo!(# ![attr]);
let _ = #[attr] foo![];
let _ = #[attr] foo![#! [attr]];
let _ = #[attr] foo![# ![attr]];
let _ = #[attr] foo! {};
let _ = #[attr] foo! { #! [attr] };
let _ = #[attr] foo! { # ![attr] };
let _ = #[attr] Foo { bar: baz };
let _ = #[attr] Foo { ..foo };
let _ = #[attr] Foo { bar: baz, ..foo };
2 changes: 1 addition & 1 deletion tests/pretty/cast-lt.pp
Original file line number Diff line number Diff line change
@@ -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; }
10 changes: 5 additions & 5 deletions tests/pretty/delimited-token-groups.rs
Original file line number Diff line number Diff line change
@@ -2,23 +2,23 @@

#![feature(rustc_attrs)]

macro_rules! mac { ($($tt : tt) *) => () }
macro_rules! mac { ($($tt: tt) *) => () }

mac! {
struct S { field1 : u8, field2 : u16, } impl Clone for S
struct S { field1: u8, field2: u16, } impl Clone for S
{
fn clone() -> S
{
panic! () ;
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
{
aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa aaaaaaaa
2 changes: 1 addition & 1 deletion tests/pretty/macro.rs
Original file line number Diff line number Diff line change
@@ -2,6 +2,6 @@

#![feature(decl_macro)]

pub(crate) macro mac { ($arg : expr) => { $arg + $arg } }
pub(crate) macro mac { ($arg: expr) => { $arg + $arg } }

fn main() {}
14 changes: 7 additions & 7 deletions tests/pretty/macro_rules.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
// pp-exact

macro_rules! brace { () => {} ; }
macro_rules! brace { () => {}; }

macro_rules! bracket[() => {} ;];
macro_rules! bracket[() => {};];

macro_rules! paren(() => {} ;);
macro_rules! paren(() => {};);

macro_rules! matcher_brackets {
(paren) => {} ; (bracket) => {} ; (brace) => {} ;
(paren) => {}; (bracket) => {}; (brace) => {};
}

macro_rules! all_fragments {
($b : block, $e : expr, $i : ident, $it : item, $l : lifetime, $lit :
literal, $m : meta, $p : pat, $pth : path, $s : stmt, $tt : tt, $ty : ty,
$vis : vis) => {} ;
($b: block, $e: expr, $i: ident, $it: item, $l: lifetime, $lit: literal,
$m: meta, $p: pat, $pth: path, $s: stmt, $tt: tt, $ty: ty, $vis: vis) =>
{};
}

fn main() {}
2 changes: 1 addition & 1 deletion tests/pretty/offset_of.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// pp-exact
#![feature(offset_of)]

fn main() { std::mem::offset_of!(std :: ops :: Range < usize >, end); }
fn main() { std::mem::offset_of!(std::ops::Range < usize > , end); }
2 changes: 1 addition & 1 deletion tests/pretty/stmt_expr_attributes.rs
Original file line number Diff line number Diff line change
@@ -113,7 +113,7 @@ fn _8() {
}

fn _9() {
macro_rules! stmt_mac { () => { let _ = () ; } }
macro_rules! stmt_mac { () => { let _ = (); } }

#[rustc_dummy]
stmt_mac!();
2 changes: 1 addition & 1 deletion tests/run-make/rustc-macro-dep-files/foo.rs
Original file line number Diff line number Diff line change
@@ -7,6 +7,6 @@ use proc_macro::TokenStream;
#[proc_macro_derive(A)]
pub fn derive(input: TokenStream) -> TokenStream {
let input = input.to_string();
assert!(input.contains("struct A ;"));
assert!(input.contains("struct A;"));
"struct B;".parse().unwrap()
}
6 changes: 3 additions & 3 deletions tests/ui/async-await/issues/issue-60674.stdout
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
async fn f(mut x : u8) {}
async fn g((mut x, y, mut z) : (u8, u8, u8)) {}
async fn g(mut x : u8, (a, mut b, c) : (u8, u8, u8), y : u8) {}
async fn f(mut x: u8) {}
async fn g((mut x, y, mut z): (u8, u8, u8)) {}
async fn g(mut x: u8, (a, mut b, c): (u8, u8, u8), y: u8) {}
2 changes: 1 addition & 1 deletion tests/ui/hygiene/unpretty-debug.stdout
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@
#![feature /* 0#0 */(no_core)]
#![no_core /* 0#0 */]

macro_rules! foo /* 0#0 */ { ($x : ident) => { y + $x } }
macro_rules! foo /* 0#0 */ { ($x: ident) => { y + $x } }

fn bar /* 0#0 */() {
let x /* 0#0 */ = 1;
12 changes: 6 additions & 6 deletions tests/ui/infinite/issue-41731-infinite-macro-print.stderr
Original file line number Diff line number Diff line change
@@ -14,13 +14,13 @@ LL | stack!("overflow");
| ^^^^^^^^^^^^^^^^^^
|
= note: expanding `stack! { "overflow" }`
= note: to `print! (stack! ("overflow")) ;`
= note: expanding `print! { stack! ("overflow") }`
= note: to `{ $crate :: io :: _print($crate :: format_args! (stack! ("overflow"))) ; }`
= note: to `print!(stack!("overflow"));`
= note: expanding `print! { stack!("overflow") }`
= note: to `{ $crate::io::_print($crate::format_args!(stack!("overflow"))); }`
= note: expanding `stack! { "overflow" }`
= note: to `print! (stack! ("overflow")) ;`
= note: expanding `print! { stack! ("overflow") }`
= note: to `{ $crate :: io :: _print($crate :: format_args! (stack! ("overflow"))) ; }`
= note: to `print!(stack!("overflow"));`
= note: expanding `print! { stack!("overflow") }`
= note: to `{ $crate::io::_print($crate::format_args!(stack!("overflow"))); }`

error: format argument must be a string literal
--> $DIR/issue-41731-infinite-macro-print.rs:14:5
12 changes: 6 additions & 6 deletions tests/ui/infinite/issue-41731-infinite-macro-println.stderr
Original file line number Diff line number Diff line change
@@ -14,13 +14,13 @@ LL | stack!("overflow");
| ^^^^^^^^^^^^^^^^^^
|
= note: expanding `stack! { "overflow" }`
= note: to `println! (stack! ("overflow")) ;`
= note: expanding `println! { stack! ("overflow") }`
= note: to `{ $crate :: io :: _print($crate :: format_args_nl! (stack! ("overflow"))) ; }`
= note: to `println!(stack!("overflow"));`
= note: expanding `println! { stack!("overflow") }`
= note: to `{ $crate::io::_print($crate::format_args_nl!(stack!("overflow"))); }`
= note: expanding `stack! { "overflow" }`
= note: to `println! (stack! ("overflow")) ;`
= note: expanding `println! { stack! ("overflow") }`
= note: to `{ $crate :: io :: _print($crate :: format_args_nl! (stack! ("overflow"))) ; }`
= note: to `println!(stack!("overflow"));`
= note: expanding `println! { stack!("overflow") }`
= note: to `{ $crate::io::_print($crate::format_args_nl!(stack!("overflow"))); }`

error: format argument must be a string literal
--> $DIR/issue-41731-infinite-macro-println.rs:14:5
260 changes: 141 additions & 119 deletions tests/ui/macros/stringify.rs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion tests/ui/macros/trace-macro.stderr
Original file line number Diff line number Diff line change
@@ -5,5 +5,5 @@ LL | println!("Hello, World!");
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: expanding `println! { "Hello, World!" }`
= note: to `{ $crate :: io :: _print($crate :: format_args_nl! ("Hello, World!")) ; }`
= note: to `{ $crate::io::_print($crate::format_args_nl!("Hello, World!")); }`

14 changes: 7 additions & 7 deletions tests/ui/macros/trace_faulty_macros.stderr
Original file line number Diff line number Diff line change
@@ -20,7 +20,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 `my_recursive_macro!`
@@ -42,13 +42,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: expected expression, found `A { a: a, b: 0, c: _, .. }`
--> $DIR/trace_faulty_macros.rs:16:9
@@ -76,8 +76,8 @@ LL | let a = pat_macro!();
| ^^^^^^^^^^^^
|
= note: expanding `pat_macro! { }`
= note: to `pat_macro! (A { a : a, b : 0, c : _, .. }) ;`
= note: expanding `pat_macro! { A { a : a, b : 0, c : _, .. } }`
= note: to `pat_macro!(A { a: a, b: 0, c: _, .. });`
= note: expanding `pat_macro! { A { a: a, b: 0, c: _, .. } }`
= note: to `A { a: a, b: 0, c: _, .. }`

error: aborting due to 4 previous errors
10 changes: 5 additions & 5 deletions tests/ui/proc-macro/allowed-attr-stmt-expr.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PRINT-ATTR INPUT (DISPLAY): struct ItemWithSemi ;
PRINT-ATTR INPUT (DISPLAY): struct ItemWithSemi;
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
@@ -45,7 +45,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/allowed-attr-stmt-expr.rs:53:27: 53:29 (#0),
},
]
PRINT-ATTR INPUT (DISPLAY): #[expect_let] let string = "Hello, world!" ;
PRINT-ATTR INPUT (DISPLAY): #[expect_let] let string = "Hello, world!";
PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '#',
@@ -87,7 +87,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/allowed-attr-stmt-expr.rs:57:33: 57:34 (#0),
},
]
PRINT-ATTR INPUT (DISPLAY): #[expect_my_macro_stmt] my_macro! ("{}", string) ;
PRINT-ATTR INPUT (DISPLAY): #[expect_my_macro_stmt] my_macro!("{}", string);
PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '#',
@@ -140,7 +140,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/allowed-attr-stmt-expr.rs:61:28: 61:29 (#0),
},
]
PRINT-ATTR INPUT (DISPLAY): second_make_stmt! (#[allow(dead_code)] struct Bar {}) ;
PRINT-ATTR INPUT (DISPLAY): second_make_stmt!(#[allow(dead_code)] struct Bar {});
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "second_make_stmt",
@@ -288,7 +288,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/allowed-attr-stmt-expr.rs:68:18: 68:20 (#0),
},
]
PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct NonBracedStruct ;
PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] struct NonBracedStruct;
PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '#',
4 changes: 2 additions & 2 deletions tests/ui/proc-macro/attr-complex-fn.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PRINT-ATTR INPUT (DISPLAY): fn foo < T : MyTrait < MyStruct < { true } >> > () {}
PRINT-ATTR INPUT (DISPLAY): fn foo< T: MyTrait < MyStruct < { true } >> >() {}
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "fn",
@@ -76,7 +76,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/attr-complex-fn.rs:19:42: 19:44 (#0),
},
]
PRINT-ATTR INPUT (DISPLAY): impl < T > MyTrait < T > for MyStruct < { true } > { #! [rustc_dummy] }
PRINT-ATTR INPUT (DISPLAY): impl< T > MyTrait < T > for MyStruct < { true } > { # ![rustc_dummy] }
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "impl",
6 changes: 3 additions & 3 deletions tests/ui/proc-macro/attr-stmt-expr.stdout
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/attr-stmt-expr.rs:45:27: 45:29 (#0),
},
]
PRINT-ATTR INPUT (DISPLAY): #[expect_let] let string = "Hello, world!" ;
PRINT-ATTR INPUT (DISPLAY): #[expect_let] let string = "Hello, world!";
PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '#',
@@ -71,7 +71,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/attr-stmt-expr.rs:49:33: 49:34 (#0),
},
]
PRINT-ATTR INPUT (DISPLAY): #[expect_my_macro_stmt] my_macro! ("{}", string) ;
PRINT-ATTR INPUT (DISPLAY): #[expect_my_macro_stmt] my_macro!("{}", string);
PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '#',
@@ -124,7 +124,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/attr-stmt-expr.rs:53:28: 53:29 (#0),
},
]
PRINT-ATTR INPUT (DISPLAY): second_make_stmt! (#[allow(dead_code)] struct Bar {}) ;
PRINT-ATTR INPUT (DISPLAY): second_make_stmt!(#[allow(dead_code)] struct Bar {});
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "second_make_stmt",
4 changes: 2 additions & 2 deletions tests/ui/proc-macro/attribute-after-derive.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PRINT-ATTR INPUT (DISPLAY): #[derive(Print)] struct AttributeDerive { #[cfg(FALSE)] field : u8, }
PRINT-ATTR INPUT (DISPLAY): #[derive(Print)] struct AttributeDerive { #[cfg(FALSE)] field: u8, }
PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '#',
@@ -130,7 +130,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
span: $DIR/attribute-after-derive.rs:23:24: 26:2 (#0),
},
]
PRINT-ATTR INPUT (DISPLAY): struct DeriveAttribute { #[cfg(FALSE)] field : u8, }
PRINT-ATTR INPUT (DISPLAY): struct DeriveAttribute { #[cfg(FALSE)] field: u8, }
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/attribute-spans-preserved.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
fn main() { let y : u32 = "z" ; { let x : u32 = "y" ; } }
fn main() { let y: u32 = "z"; { let x: u32 = "y"; } }
6 changes: 3 additions & 3 deletions tests/ui/proc-macro/auxiliary/attr-stmt-expr-rpass.rs
Original file line number Diff line number Diff line change
@@ -10,14 +10,14 @@ use proc_macro::TokenStream;
#[proc_macro_attribute]
pub fn expect_let(attr: TokenStream, item: TokenStream) -> TokenStream {
assert!(attr.to_string().is_empty());
assert_eq!(item.to_string(), "let string = \"Hello, world!\" ;");
assert_eq!(item.to_string(), "let string = \"Hello, world!\";");
item
}

#[proc_macro_attribute]
pub fn expect_print_stmt(attr: TokenStream, item: TokenStream) -> TokenStream {
assert!(attr.to_string().is_empty());
assert_eq!(item.to_string(), "println! (\"{}\", string) ;");
assert_eq!(item.to_string(), "println!(\"{}\", string);");
item
}

@@ -31,7 +31,7 @@ pub fn expect_expr(attr: TokenStream, item: TokenStream) -> TokenStream {
#[proc_macro_attribute]
pub fn expect_print_expr(attr: TokenStream, item: TokenStream) -> TokenStream {
assert!(attr.to_string().is_empty());
assert_eq!(item.to_string(), "println! (\"{}\", string)");
assert_eq!(item.to_string(), "println!(\"{}\", string)");
item
}

6 changes: 3 additions & 3 deletions tests/ui/proc-macro/auxiliary/attr-stmt-expr.rs
Original file line number Diff line number Diff line change
@@ -10,14 +10,14 @@ use proc_macro::TokenStream;
#[proc_macro_attribute]
pub fn expect_let(attr: TokenStream, item: TokenStream) -> TokenStream {
assert!(attr.to_string().is_empty());
assert_eq!(item.to_string(), "let string = \"Hello, world!\" ;");
assert_eq!(item.to_string(), "let string = \"Hello, world!\";");
item
}

#[proc_macro_attribute]
pub fn expect_my_macro_stmt(attr: TokenStream, item: TokenStream) -> TokenStream {
assert!(attr.to_string().is_empty());
assert_eq!(item.to_string(), "my_macro! (\"{}\", string) ;");
assert_eq!(item.to_string(), "my_macro!(\"{}\", string);");
item
}

@@ -31,7 +31,7 @@ pub fn expect_expr(attr: TokenStream, item: TokenStream) -> TokenStream {
#[proc_macro_attribute]
pub fn expect_my_macro_expr(attr: TokenStream, item: TokenStream) -> TokenStream {
assert!(attr.to_string().is_empty());
assert_eq!(item.to_string(), "my_macro! (\"{}\", string)");
assert_eq!(item.to_string(), "my_macro!(\"{}\", string)");
item
}

2 changes: 1 addition & 1 deletion tests/ui/proc-macro/auxiliary/derive-a.rs
Original file line number Diff line number Diff line change
@@ -10,6 +10,6 @@ use proc_macro::TokenStream;
#[proc_macro_derive(A)]
pub fn derive(input: TokenStream) -> TokenStream {
let input = input.to_string();
assert!(input.contains("struct A ;"));
assert!(input.contains("struct A;"));
"".parse().unwrap()
}
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/auxiliary/derive-atob.rs
Original file line number Diff line number Diff line change
@@ -10,6 +10,6 @@ use proc_macro::TokenStream;
#[proc_macro_derive(AToB)]
pub fn derive(input: TokenStream) -> TokenStream {
let input = input.to_string();
assert_eq!(input, "struct A ;");
assert_eq!(input, "struct A;");
"struct B;".parse().unwrap()
}
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/auxiliary/derive-b-rpass.rs
Original file line number Diff line number Diff line change
@@ -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()
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/auxiliary/derive-ctod.rs
Original file line number Diff line number Diff line change
@@ -10,6 +10,6 @@ use proc_macro::TokenStream;
#[proc_macro_derive(CToD)]
pub fn derive(input: TokenStream) -> TokenStream {
let input = input.to_string();
assert_eq!(input, "struct C ;");
assert_eq!(input, "struct C;");
"struct D;".parse().unwrap()
}
4 changes: 2 additions & 2 deletions tests/ui/proc-macro/auxiliary/derive-same-struct.rs
Original file line number Diff line number Diff line change
@@ -10,12 +10,12 @@ use proc_macro::TokenStream;
#[proc_macro_derive(AToB)]
pub fn derive1(input: TokenStream) -> TokenStream {
println!("input1: {:?}", input.to_string());
assert_eq!(input.to_string(), "struct A ;");
assert_eq!(input.to_string(), "struct A;");
"#[derive(BToC)] struct B;".parse().unwrap()
}

#[proc_macro_derive(BToC)]
pub fn derive2(input: TokenStream) -> TokenStream {
assert_eq!(input.to_string(), "struct B ;");
assert_eq!(input.to_string(), "struct B;");
"struct C;".parse().unwrap()
}
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/auxiliary/derive-union.rs
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ pub fn derive(input: TokenStream) -> TokenStream {
let input = input.to_string();
assert!(input.contains("#[repr(C)]"));
assert!(input.contains("union Test {"));
assert!(input.contains("a : u8,"));
assert!(input.contains("a: u8,"));
assert!(input.contains("}"));
"".parse().unwrap()
}
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/auxiliary/expand-with-a-macro.rs
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ use proc_macro::TokenStream;
#[proc_macro_derive(A)]
pub fn derive(input: TokenStream) -> TokenStream {
let input = input.to_string();
assert!(input.contains("struct A ;"));
assert!(input.contains("struct A;"));
r#"
impl A {
fn a(&self) {
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/auxiliary/issue-79825.rs
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@ use proc_macro::TokenStream;

#[proc_macro_attribute]
pub fn assert_input(args: TokenStream, input: TokenStream) -> TokenStream {
assert_eq!(input.to_string(), "trait Alias = Sized ;");
assert_eq!(input.to_string(), "trait Alias = Sized;");
assert!(args.is_empty());
TokenStream::new()
}
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/capture-macro-rules-invoke.stdout
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
PRINT-BANG INPUT (DISPLAY): 1 + 1, { "a" }, let a = 1;, String, my_name, 'a, my_val = 30,
std::option::Option, pub(in some::path) , [a b c], -30
PRINT-BANG RE-COLLECTED (DISPLAY): 1 + 1, { "a" }, let a = 1, String, my_name, 'a, my_val = 30,
std :: option :: Option, pub(in some :: path), [a b c], - 30
std::option::Option, pub(in some::path), [a b c], - 30
PRINT-BANG INPUT (DEBUG): TokenStream [
Group {
delimiter: None,
8 changes: 4 additions & 4 deletions tests/ui/proc-macro/cfg-eval-inner.stdout
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
PRINT-ATTR INPUT (DISPLAY): impl Foo <
[u8 ;
[u8;
{
#! [rustc_dummy(cursed_inner)] #! [allow(unused)] struct Inner
{ field : [u8 ; { #! [rustc_dummy(another_cursed_inner)] 1 }] } 0
}] > { #! [rustc_dummy(evaluated_attr)] fn bar() {} }
# ![rustc_dummy(cursed_inner)] # ![allow(unused)] struct Inner
{ field: [u8; { # ![rustc_dummy(another_cursed_inner)] 1 }] } 0
}] > { # ![rustc_dummy(evaluated_attr)] fn bar() {} }
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "impl",
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/cfg-eval.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PRINT-ATTR INPUT (DISPLAY): struct S1 { #[cfg(all())] #[allow()] field_true : u8, }
PRINT-ATTR INPUT (DISPLAY): struct S1 { #[cfg(all())] #[allow()] field_true: u8, }
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/derive-same-struct.stdout
Original file line number Diff line number Diff line change
@@ -1 +1 @@
input1: "struct A ;"
input1: "struct A;"
4 changes: 2 additions & 2 deletions tests/ui/proc-macro/doc-comment-preserved.stdout
Original file line number Diff line number Diff line change
@@ -5,8 +5,8 @@ PRINT-BANG INPUT (DISPLAY): /**
* DOC *
*******
*/
pub struct S ;
PRINT-BANG RE-COLLECTED (DISPLAY): #[doc = "\n*******\n* DOC *\n* DOC *\n* DOC *\n*******\n"] pub struct S ;
pub struct S;
PRINT-BANG RE-COLLECTED (DISPLAY): #[doc = "\n*******\n* DOC *\n* DOC *\n* DOC *\n*******\n"] pub struct S;
PRINT-BANG INPUT (DEBUG): TokenStream [
Punct {
ch: '#',
4 changes: 2 additions & 2 deletions tests/ui/proc-macro/dollar-crate-issue-57089.stdout
Original file line number Diff line number Diff line change
@@ -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",
@@ -38,7 +38,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
span: $DIR/dollar-crate-issue-57089.rs:17:32: 17:33 (#3),
},
]
PRINT-ATTR INPUT (DISPLAY): struct A($crate :: S) ;
PRINT-ATTR INPUT (DISPLAY): struct A($crate::S);
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
4 changes: 2 additions & 2 deletions tests/ui/proc-macro/dollar-crate-issue-62325.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PRINT-ATTR INPUT (DISPLAY): struct A(identity! ($crate :: S)) ;
PRINT-ATTR INPUT (DISPLAY): struct A(identity!($crate::S));
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
@@ -53,7 +53,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/dollar-crate-issue-62325.rs:19:35: 19:36 (#3),
},
]
PRINT-ATTR INPUT (DISPLAY): struct B(identity! ($crate :: S)) ;
PRINT-ATTR INPUT (DISPLAY): struct B(identity!($crate::S));
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
12 changes: 6 additions & 6 deletions tests/ui/proc-macro/dollar-crate.stdout
Original file line number Diff line number Diff line change
@@ -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",
@@ -38,7 +38,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
span: $DIR/dollar-crate.rs:20:36: 20:37 (#3),
},
]
PRINT-ATTR INPUT (DISPLAY): struct A($crate :: S) ;
PRINT-ATTR INPUT (DISPLAY): struct A($crate::S);
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
@@ -78,7 +78,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/dollar-crate.rs:24:32: 24:33 (#3),
},
]
PRINT-DERIVE INPUT (DISPLAY): struct D($crate :: S) ;
PRINT-DERIVE INPUT (DISPLAY): struct D($crate::S);
PRINT-DERIVE INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
@@ -118,7 +118,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
span: $DIR/dollar-crate.rs:27:32: 27:33 (#3),
},
]
PRINT-BANG INPUT (DISPLAY): struct M($crate :: S) ;
PRINT-BANG INPUT (DISPLAY): struct M($crate::S);
PRINT-BANG INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
@@ -158,7 +158,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
span: $DIR/auxiliary/dollar-crate-external.rs:7:32: 7:33 (#14),
},
]
PRINT-ATTR INPUT (DISPLAY): struct A($crate :: S) ;
PRINT-ATTR INPUT (DISPLAY): struct A($crate::S);
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
@@ -198,7 +198,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
span: $DIR/auxiliary/dollar-crate-external.rs:11:28: 11:29 (#14),
},
]
PRINT-DERIVE INPUT (DISPLAY): struct D($crate :: S) ;
PRINT-DERIVE INPUT (DISPLAY): struct D($crate::S);
PRINT-DERIVE INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
4 changes: 2 additions & 2 deletions tests/ui/proc-macro/expand-to-derive.stdout
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PRINT-DERIVE INPUT (DISPLAY): struct Foo
{
field :
[bool ; { #[rustc_dummy] struct Inner { other_inner_field : u8, } 0 }]
field:
[bool; { #[rustc_dummy] struct Inner { other_inner_field: u8, } 0 }]
}
PRINT-DERIVE INPUT (DEBUG): TokenStream [
Ident {
22 changes: 11 additions & 11 deletions tests/ui/proc-macro/expr-stmt-nonterminal-tokens.stdout
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = #[allow(warnings)] 0 ; 0 }, }
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): enum E { V = { let _ = #[allow(warnings)] #[allow(warnings)] 0 ; 0 }, }
PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = #[allow(warnings)] 0; 0 }, }
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): enum E { V = { let _ = #[allow(warnings)] #[allow(warnings)] 0; 0 }, }
PRINT-DERIVE INPUT (DEBUG): TokenStream [
Ident {
ident: "enum",
@@ -122,8 +122,8 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
span: #3 bytes(306..355),
},
]
PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = { 0; } ; 0 }, }
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): enum E { V = { let _ = { 0 } ; 0 }, }
PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = { 0; }; 0 }, }
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): enum E { V = { let _ = { 0 }; 0 }, }
PRINT-DERIVE INPUT (DEBUG): TokenStream [
Ident {
ident: "enum",
@@ -202,7 +202,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
span: #7 bytes(430..483),
},
]
PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = { {} } ; 0 }, }
PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = { {} }; 0 }, }
PRINT-DERIVE INPUT (DEBUG): TokenStream [
Ident {
ident: "enum",
@@ -280,8 +280,8 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
span: #11 bytes(430..483),
},
]
PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = { PATH; } ; 0 }, }
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): enum E { V = { let _ = { PATH } ; 0 }, }
PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = { PATH; }; 0 }, }
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): enum E { V = { let _ = { PATH }; 0 }, }
PRINT-DERIVE INPUT (DEBUG): TokenStream [
Ident {
ident: "enum",
@@ -358,8 +358,8 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
span: #15 bytes(430..483),
},
]
PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = { 0 + 1; } ; 0 }, }
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): enum E { V = { let _ = { 0 + 1 } ; 0 }, }
PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = { 0 + 1; }; 0 }, }
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): enum E { V = { let _ = { 0 + 1 }; 0 }, }
PRINT-DERIVE INPUT (DEBUG): TokenStream [
Ident {
ident: "enum",
@@ -449,8 +449,8 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [
span: #19 bytes(430..483),
},
]
PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = { PATH + 1; } ; 0 }, }
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): enum E { V = { let _ = { PATH + 1 } ; 0 }, }
PRINT-DERIVE INPUT (DISPLAY): enum E { V = { let _ = { PATH + 1; }; 0 }, }
PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): enum E { V = { let _ = { PATH + 1 }; 0 }, }
PRINT-DERIVE INPUT (DEBUG): TokenStream [
Ident {
ident: "enum",
12 changes: 6 additions & 6 deletions tests/ui/proc-macro/inert-attribute-order.stdout
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PRINT-ATTR INPUT (DISPLAY): /// 1
#[rustfmt :: attr2] #[doc = "3"] #[doc = "4"] #[rustfmt :: attr5] /// 6
#[print_attr(nodebug)] struct S ;
PRINT-ATTR RE-COLLECTED (DISPLAY): #[doc = " 1"] #[rustfmt :: attr2] #[doc = "3"] #[doc = "4"]
#[rustfmt :: attr5] #[doc = " 6"] #[print_attr(nodebug)] struct S ;
PRINT-ATTR INPUT (DISPLAY): #[doc = " 1"] #[rustfmt :: attr2] #[doc = "3"] #[doc = "4"]
#[rustfmt :: attr5] #[doc = " 6"] struct S ;
#[rustfmt::attr2] #[doc = "3"] #[doc = "4"] #[rustfmt::attr5] /// 6
#[print_attr(nodebug)] struct S;
PRINT-ATTR RE-COLLECTED (DISPLAY): #[doc = " 1"] #[rustfmt::attr2] #[doc = "3"] #[doc = "4"] #[rustfmt::attr5]
#[doc = " 6"] #[print_attr(nodebug)] struct S;
PRINT-ATTR INPUT (DISPLAY): #[doc = " 1"] #[rustfmt::attr2] #[doc = "3"] #[doc = "4"] #[rustfmt::attr5]
#[doc = " 6"] struct S;
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/inner-attr-non-inline-mod.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PRINT-ATTR INPUT (DISPLAY): #[deny(unused_attributes)] mod module_with_attrs { #! [rustfmt :: skip] }
PRINT-ATTR INPUT (DISPLAY): #[deny(unused_attributes)] mod module_with_attrs { # ![rustfmt::skip] }
PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '#',
25 changes: 11 additions & 14 deletions tests/ui/proc-macro/inner-attrs.stdout
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
},
]
PRINT-ATTR INPUT (DISPLAY): #[print_target_and_args(second)] fn foo()
{ #! [print_target_and_args(third)] #! [print_target_and_args(fourth)] }
{ # ![print_target_and_args(third)] # ![print_target_and_args(fourth)] }
PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '#',
@@ -121,7 +121,7 @@ PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
},
]
PRINT-ATTR INPUT (DISPLAY): fn foo()
{ #! [print_target_and_args(third)] #! [print_target_and_args(fourth)] }
{ # ![print_target_and_args(third)] # ![print_target_and_args(fourth)] }
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "fn",
@@ -210,7 +210,7 @@ PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
span: $DIR/inner-attrs.rs:20:30: 20:35 (#0),
},
]
PRINT-ATTR INPUT (DISPLAY): fn foo() { #! [print_target_and_args(fourth)] }
PRINT-ATTR INPUT (DISPLAY): fn foo() { # ![print_target_and_args(fourth)] }
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "fn",
@@ -299,8 +299,8 @@ PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
]
PRINT-ATTR INPUT (DISPLAY): #[print_target_and_args(mod_second)] mod inline_mod
{
#! [print_target_and_args(mod_third)] #!
[print_target_and_args(mod_fourth)]
# ![print_target_and_args(mod_third)] #
![print_target_and_args(mod_fourth)]
}
PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
@@ -412,8 +412,8 @@ PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
]
PRINT-ATTR INPUT (DISPLAY): mod inline_mod
{
#! [print_target_and_args(mod_third)] #!
[print_target_and_args(mod_fourth)]
# ![print_target_and_args(mod_third)] #
![print_target_and_args(mod_fourth)]
}
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
@@ -498,7 +498,7 @@ PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
span: $DIR/inner-attrs.rs:27:30: 27:39 (#0),
},
]
PRINT-ATTR INPUT (DISPLAY): mod inline_mod { #! [print_target_and_args(mod_fourth)] }
PRINT-ATTR INPUT (DISPLAY): mod inline_mod { # ![print_target_and_args(mod_fourth)] }
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "mod",
@@ -569,10 +569,7 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
},
]
PRINT-DERIVE INPUT (DISPLAY): struct MyDerivePrint
{
field :
[u8 ; { match true { _ => { #! [rustc_dummy(third)] true } } ; 0 }]
}
{ field: [u8; { match true { _ => { # ![rustc_dummy(third)] true } }; 0 }] }
PRINT-DERIVE INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
@@ -705,7 +702,7 @@ PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
span: $DIR/inner-attrs.rs:49:29: 49:40 (#0),
},
]
PRINT-ATTR INPUT (DISPLAY): (3, 4, { #! [cfg_attr(not(FALSE), rustc_dummy(innermost))] 5 }) ;
PRINT-ATTR INPUT (DISPLAY): (3, 4, { # ![cfg_attr(not(FALSE), rustc_dummy(innermost))] 5 });
PRINT-ATTR INPUT (DEBUG): TokenStream [
Group {
delimiter: Parenthesis,
@@ -819,7 +816,7 @@ PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
span: $DIR/inner-attrs.rs:56:29: 56:40 (#0),
},
]
PRINT-ATTR INPUT (DISPLAY): (3, 4, { #! [cfg_attr(not(FALSE), rustc_dummy(innermost))] 5 }) ;
PRINT-ATTR INPUT (DISPLAY): (3, 4, { # ![cfg_attr(not(FALSE), rustc_dummy(innermost))] 5 });
PRINT-ATTR INPUT (DEBUG): TokenStream [
Group {
delimiter: Parenthesis,
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/input-interpolated.stdout
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [
span: #0 bytes(503..504),
},
]
PRINT-ATTR INPUT (DISPLAY): const A : u8 = 0 ;
PRINT-ATTR INPUT (DISPLAY): const A: u8 = 0;
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "const",
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/issue-75734-pp-paren.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PRINT-ATTR INPUT (DISPLAY): fn main() { & | _ : u8 | {} ; mul_2! (1 + 1) ; }
PRINT-ATTR INPUT (DISPLAY): fn main() { & | _: u8 | {}; mul_2!(1 + 1); }
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "fn",
36 changes: 18 additions & 18 deletions tests/ui/proc-macro/issue-75930-derive-cfg.stdout
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
PRINT-ATTR INPUT (DISPLAY): #[print_helper(a)] #[allow(dead_code)] #[derive(Print)] #[print_helper(b)]
struct Foo < #[cfg(FALSE)] A, B >
{
#[cfg(FALSE)] first : String, #[cfg_attr(FALSE, deny(warnings))] second :
bool, third :
[u8 ;
#[cfg(FALSE)] first: String, #[cfg_attr(FALSE, deny(warnings))] second:
bool, third:
[u8;
{
#[cfg(FALSE)] struct Bar ; #[cfg(not(FALSE))] struct Inner ;
#[cfg(FALSE)] let a = 25 ; match true
#[cfg(FALSE)] struct Bar; #[cfg(not(FALSE))] struct Inner;
#[cfg(FALSE)] let a = 25; match true
{
#[cfg(FALSE)] true => {}, #[cfg_attr(not(FALSE), allow(warnings))]
false => {}, _ => {}
} ; #[print_helper(should_be_removed)] fn removed_fn()
{ #! [cfg(FALSE)] } #[print_helper(c)] #[cfg(not(FALSE))] fn kept_fn()
{ #! [cfg(not(FALSE))] let my_val = true ; } enum TupleEnum
}; #[print_helper(should_be_removed)] fn removed_fn()
{ # ![cfg(FALSE)] } #[print_helper(c)] #[cfg(not(FALSE))] fn kept_fn()
{ # ![cfg(not(FALSE))] let my_val = true; } enum TupleEnum
{
Foo(#[cfg(FALSE)] u8, #[cfg(FALSE)] bool, #[cfg(not(FALSE))] i32,
#[cfg(FALSE)] String, u8)
} struct
TupleStruct(#[cfg(FALSE)] String, #[cfg(not(FALSE))] i32,
#[cfg(FALSE)] bool, u8) ; fn plain_removed_fn()
{ #! [cfg_attr(not(FALSE), cfg(FALSE))] } 0
}], #[print_helper(d)] fourth : B
#[cfg(FALSE)] bool, u8); fn plain_removed_fn()
{ # ![cfg_attr(not(FALSE), cfg(FALSE))] } 0
}], #[print_helper(d)] fourth: B
}
PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
@@ -1274,16 +1274,16 @@ PRINT-ATTR INPUT (DEBUG): TokenStream [
]
PRINT-DERIVE INPUT (DISPLAY): #[print_helper(a)] #[allow(dead_code)] #[print_helper(b)] struct Foo < B >
{
second : bool, third :
[u8 ;
second: bool, third:
[u8;
{
#[cfg(not(FALSE))] struct Inner ; match true
{ #[allow(warnings)] false => {}, _ => {} } ; #[print_helper(c)]
#[cfg(not(FALSE))] struct Inner; match true
{ #[allow(warnings)] false => {}, _ => {} }; #[print_helper(c)]
#[cfg(not(FALSE))] fn kept_fn()
{ #! [cfg(not(FALSE))] let my_val = true ; } enum TupleEnum
{ # ![cfg(not(FALSE))] let my_val = true; } enum TupleEnum
{ Foo(#[cfg(not(FALSE))] i32, u8) } struct
TupleStruct(#[cfg(not(FALSE))] i32, u8) ; 0
}], #[print_helper(d)] fourth : B
TupleStruct(#[cfg(not(FALSE))] i32, u8); 0
}], #[print_helper(d)] fourth: B
}
PRINT-DERIVE INPUT (DEBUG): TokenStream [
Punct {
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/issue-76182-leading-vert-pat.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PRINT-ATTR INPUT (DISPLAY): fn main() { match() { | () => () } }
PRINT-ATTR INPUT (DISPLAY): fn main() { match () { | () => () } }
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "fn",
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PRINT-BANG INPUT (DISPLAY): foo! { #[fake_attr] mod bar {
#![doc = r" Foo"]
} }
PRINT-BANG DEEP-RE-COLLECTED (DISPLAY): foo! { #[fake_attr] mod bar { #! [doc = r" Foo"] } }
PRINT-BANG DEEP-RE-COLLECTED (DISPLAY): foo! { #[fake_attr] mod bar { # ![doc = r" Foo"] } }
PRINT-BANG INPUT (DEBUG): TokenStream [
Ident {
ident: "foo",
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/keep-expr-tokens.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] { 1 + 1 ; }
PRINT-ATTR INPUT (DISPLAY): #[rustc_dummy] { 1 + 1; }
PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
ch: '#',
6 changes: 3 additions & 3 deletions tests/ui/proc-macro/macro-rules-derive-cfg.stdout
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
PRINT-DERIVE INPUT (DISPLAY): struct Foo
{
val :
[bool ;
val:
[bool;
{
let a = #[rustc_dummy(first)] #[rustc_dummy(second)]
{ #! [allow(unused)] 30 } ; 0
{ # ![allow(unused)] 30 }; 0
}]
}
PRINT-DERIVE INPUT (DEBUG): TokenStream [
4 changes: 2 additions & 2 deletions tests/ui/proc-macro/meta-macro-hygiene.stdout
Original file line number Diff line number Diff line change
@@ -32,13 +32,13 @@ macro_rules! produce_it
*/ {
() =>
{
meta_macro :: print_def_site! ($crate :: dummy! ()) ;
meta_macro::print_def_site!($crate::dummy!());
// `print_def_site!` will respan the `$crate` identifier
// with `Span::def_site()`. This should cause it to resolve
// relative to `meta_macro`, *not* `make_macro` (despite
// the fact that `print_def_site` is produced by a
// `macro_rules!` macro in `make_macro`).
} ;
};
}

fn main /* 0#0 */() { ; }
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/nested-derive-cfg.stdout
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PRINT-DERIVE INPUT (DISPLAY): struct Foo
{ my_array : [bool ; { struct Inner { non_removed_inner_field : usize } 0 }] }
{ my_array: [bool; { struct Inner { non_removed_inner_field: usize } 0 }] }
PRINT-DERIVE INPUT (DEBUG): TokenStream [
Ident {
ident: "struct",
1 change: 0 additions & 1 deletion tests/ui/proc-macro/nonterminal-expansion.stdout
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
PRINT-ATTR_ARGS INPUT (DISPLAY): a, line!(), b
PRINT-ATTR_ARGS RE-COLLECTED (DISPLAY): a, line! (), b
PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
Ident {
ident: "a",
7 changes: 3 additions & 4 deletions tests/ui/proc-macro/nonterminal-token-hygiene.stdout
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
PRINT-BANG INPUT (DISPLAY): struct S;
PRINT-BANG RE-COLLECTED (DISPLAY): struct S ;
PRINT-BANG INPUT (DEBUG): TokenStream [
Group {
delimiter: None,
@@ -51,11 +50,11 @@ macro_rules! outer
/*
0#0
*/ {
($item : item) =>
($item: item) =>
{
macro inner() { print_bang! { $item } } inner! () ;
macro inner() { print_bang! { $item } } inner!();

} ;
};
}

struct S /* 0#0 */;
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/pretty-print-tts.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PRINT-BANG INPUT (DISPLAY): { #! [rustc_dummy] let a = "hello".len() ; matches! (a, 5) ; }
PRINT-BANG INPUT (DISPLAY): { # ![rustc_dummy] let a = "hello".len(); matches!(a, 5); }
PRINT-BANG INPUT (DEBUG): TokenStream [
Group {
delimiter: Brace,
2 changes: 1 addition & 1 deletion tests/ui/proc-macro/trailing-plus.stdout
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PRINT-ATTR INPUT (DISPLAY): fn foo < T > () where T : Copy + {}
PRINT-ATTR INPUT (DISPLAY): fn foo< T >() where T: Copy + {}
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "fn",
10 changes: 5 additions & 5 deletions tests/ui/proc-macro/weird-braces.stdout
Original file line number Diff line number Diff line change
@@ -8,8 +8,8 @@ PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
PRINT-ATTR INPUT (DISPLAY): #[print_target_and_args(second_outer)] impl Bar < { 1 > 0 } > for Foo <
{ true } >
{
#! [print_target_and_args(first_inner)] #!
[print_target_and_args(second_inner)]
# ![print_target_and_args(first_inner)] #
![print_target_and_args(second_inner)]
}
PRINT-ATTR INPUT (DEBUG): TokenStream [
Punct {
@@ -182,8 +182,8 @@ PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
]
PRINT-ATTR INPUT (DISPLAY): impl Bar < { 1 > 0 } > for Foo < { true } >
{
#! [print_target_and_args(first_inner)] #!
[print_target_and_args(second_inner)]
# ![print_target_and_args(first_inner)] #
![print_target_and_args(second_inner)]
}
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
@@ -330,7 +330,7 @@ PRINT-ATTR_ARGS INPUT (DEBUG): TokenStream [
},
]
PRINT-ATTR INPUT (DISPLAY): impl Bar < { 1 > 0 } > for Foo < { true } >
{ #! [print_target_and_args(second_inner)] }
{ # ![print_target_and_args(second_inner)] }
PRINT-ATTR INPUT (DEBUG): TokenStream [
Ident {
ident: "impl",
40 changes: 20 additions & 20 deletions tests/ui/rfcs/rfc-2565-param-attrs/auxiliary/param-attrs.rs
Original file line number Diff line number Diff line change
@@ -17,27 +17,27 @@ macro_rules! checker {
}
}

checker!(attr_extern, r#"extern "C" { fn ffi(#[a1] arg1 : i32, #[a2] ...) ; }"#);
checker!(attr_extern_cvar, r#"unsafe extern "C" fn cvar(arg1 : i32, #[a1] mut args : ...) {}"#);
checker!(attr_alias, "type Alias = fn(#[a1] u8, #[a2] ...) ;");
checker!(attr_free, "fn free(#[a1] arg1 : u8) { let lam = | #[a2] W(x), #[a3] y | () ; }");
checker!(attr_inherent_1, "fn inherent1(#[a1] self, #[a2] arg1 : u8) {}");
checker!(attr_inherent_2, "fn inherent2(#[a1] & self, #[a2] arg1 : u8) {}");
checker!(attr_inherent_3, "fn inherent3 < 'a > (#[a1] & 'a mut self, #[a2] arg1 : u8) {}");
checker!(attr_inherent_4, "fn inherent4 < 'a > (#[a1] self : Box < Self >, #[a2] arg1 : u8) {}");
checker!(attr_inherent_issue_64682, "fn inherent5(#[a1] #[a2] arg1 : u8, #[a3] arg2 : u8) {}");
checker!(attr_trait_1, "fn trait1(#[a1] self, #[a2] arg1 : u8) ;");
checker!(attr_trait_2, "fn trait2(#[a1] & self, #[a2] arg1 : u8) ;");
checker!(attr_trait_3, "fn trait3 < 'a > (#[a1] & 'a mut self, #[a2] arg1 : u8) ;");
checker!(attr_trait_4, r#"fn trait4 < 'a >
(#[a1] self : Box < Self >, #[a2] arg1 : u8, #[a3] Vec < u8 >) ;"#);
checker!(attr_trait_issue_64682, "fn trait5(#[a1] #[a2] arg1 : u8, #[a3] arg2 : u8) ;");
checker!(attr_extern, r#"extern "C" { fn ffi(#[a1] arg1: i32, #[a2] ...); }"#);
checker!(attr_extern_cvar, r#"unsafe extern "C" fn cvar(arg1: i32, #[a1] mut args: ...) {}"#);
checker!(attr_alias, "type Alias = fn(#[a1] u8, #[a2] ...);");
checker!(attr_free, "fn free(#[a1] arg1: u8) { let lam = | #[a2] W(x), #[a3] y | (); }");
checker!(attr_inherent_1, "fn inherent1(#[a1] self, #[a2] arg1: u8) {}");
checker!(attr_inherent_2, "fn inherent2(#[a1] & self, #[a2] arg1: u8) {}");
checker!(attr_inherent_3, "fn inherent3< 'a >(#[a1] & 'a mut self, #[a2] arg1: u8) {}");
checker!(attr_inherent_4, "fn inherent4< 'a >(#[a1] self: Box < Self > , #[a2] arg1: u8) {}");
checker!(attr_inherent_issue_64682, "fn inherent5(#[a1] #[a2] arg1: u8, #[a3] arg2: u8) {}");
checker!(attr_trait_1, "fn trait1(#[a1] self, #[a2] arg1: u8);");
checker!(attr_trait_2, "fn trait2(#[a1] & self, #[a2] arg1: u8);");
checker!(attr_trait_3, "fn trait3< 'a >(#[a1] & 'a mut self, #[a2] arg1: u8);");
checker!(attr_trait_4,
r#"fn trait4< 'a >(#[a1] self: Box < Self > , #[a2] arg1: u8, #[a3] Vec < u8 >);"#);
checker!(attr_trait_issue_64682, "fn trait5(#[a1] #[a2] arg1: u8, #[a3] arg2: u8);");
checker!(rename_params, r#"impl Foo
{
fn hello(#[angery(true)] a : i32, #[a2] b : i32, #[what = "how"] c : u32)
fn hello(#[angery(true)] a: i32, #[a2] b: i32, #[what = "how"] c: u32) {}
fn
hello2(#[a1] #[a2] a: i32, #[what = "how"] b: i32, #[angery(true)] c: u32)
{} fn
hello2(#[a1] #[a2] a : i32, #[what = "how"] b : i32, #[angery(true)] c :
u32) {} fn
hello_self(#[a1] #[a2] & self, #[a1] #[a2] a : i32, #[what = "how"] b :
i32, #[angery(true)] c : u32) {}
hello_self(#[a1] #[a2] & self, #[a1] #[a2] a: i32, #[what = "how"] b: i32,
#[angery(true)] c: u32) {}
}"#);