diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs index fb666550e9302..3d46415507def 100644 --- a/compiler/rustc_ast/src/tokenstream.rs +++ b/compiler/rustc_ast/src/tokenstream.rs @@ -661,11 +661,11 @@ impl TokenStream { if attr_style == AttrStyle::Inner { vec![ TokenTree::token_joint(token::Pound, span), - TokenTree::token_alone(token::Not, span), + TokenTree::token_joint_hidden(token::Not, span), body, ] } else { - vec![TokenTree::token_alone(token::Pound, span), body] + vec![TokenTree::token_joint_hidden(token::Pound, span), body] } } } diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index defb666e2b667..6e3b8ad4bdaee 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -524,7 +524,10 @@ pub trait PrintState<'a>: std::ops::Deref + std::ops::Dere } } - fn peek_comment<'b>(&'b self) -> Option<&'b Comment> where 'a: 'b { + fn peek_comment<'b>(&'b self) -> Option<&'b Comment> + where + 'a: 'b, + { self.comments().and_then(|c| c.peek()) } @@ -849,18 +852,11 @@ pub trait PrintState<'a>: std::ops::Deref + std::ops::Dere } fn nonterminal_to_string(&self, nt: &Nonterminal) -> String { - match nt { - token::NtExpr(e) => self.expr_to_string(e), - token::NtMeta(e) => self.attr_item_to_string(e), - token::NtTy(e) => self.ty_to_string(e), - token::NtPath(e) => self.path_to_string(e), - token::NtItem(e) => self.item_to_string(e), - token::NtBlock(e) => self.block_to_string(e), - token::NtStmt(e) => self.stmt_to_string(e), - token::NtPat(e) => self.pat_to_string(e), - token::NtLiteral(e) => self.expr_to_string(e), - token::NtVis(e) => self.vis_to_string(e), - } + // We convert the AST fragment to a token stream and pretty print that, + // rather than using AST pretty printing, because `Nonterminal` is + // slated for removal in #124141. (This method will also then be + // removed.) + self.tts_to_string(&TokenStream::from_nonterminal_ast(nt)) } /// Print the token kind precisely, without converting `$crate` into its respective crate name. @@ -994,6 +990,10 @@ pub trait PrintState<'a>: std::ops::Deref + std::ops::Dere Self::to_string(|s| s.print_attr_item(ai, ai.path.span)) } + fn tts_to_string(&self, tokens: &TokenStream) -> String { + Self::to_string(|s| s.print_tts(tokens, false)) + } + fn to_string(f: impl FnOnce(&mut State<'_>)) -> String { let mut printer = State::new(); f(&mut printer); @@ -2039,10 +2039,6 @@ impl<'a> State<'a> { }) } - pub(crate) fn tts_to_string(&self, tokens: &TokenStream) -> String { - Self::to_string(|s| s.print_tts(tokens, false)) - } - pub(crate) fn path_segment_to_string(&self, p: &ast::PathSegment) -> String { Self::to_string(|s| s.print_path_segment(p, false)) } diff --git a/compiler/rustc_builtin_macros/src/assert/context.rs b/compiler/rustc_builtin_macros/src/assert/context.rs index 085ea3458bbfa..7814422611439 100644 --- a/compiler/rustc_builtin_macros/src/assert/context.rs +++ b/compiler/rustc_builtin_macros/src/assert/context.rs @@ -153,7 +153,7 @@ impl<'cx, 'a> Context<'cx, 'a> { fn build_panic(&self, expr_str: &str, panic_path: Path) -> P { let escaped_expr_str = escape_to_fmt(expr_str); let initial = [ - TokenTree::token_joint_hidden( + TokenTree::token_joint( token::Literal(token::Lit { kind: token::LitKind::Str, symbol: Symbol::intern(&if self.fmt_string.is_empty() { @@ -172,7 +172,7 @@ impl<'cx, 'a> Context<'cx, 'a> { ]; let captures = self.capture_decls.iter().flat_map(|cap| { [ - TokenTree::token_joint_hidden( + TokenTree::token_joint( token::Ident(cap.ident.name, IdentIsRaw::No), cap.ident.span, ), diff --git a/compiler/rustc_expand/src/mbe.rs b/compiler/rustc_expand/src/mbe.rs index a805c4fcf7b97..7060a4b364c09 100644 --- a/compiler/rustc_expand/src/mbe.rs +++ b/compiler/rustc_expand/src/mbe.rs @@ -14,7 +14,7 @@ mod transcribe; use metavar_expr::MetaVarExpr; use rustc_ast::token::{Delimiter, NonterminalKind, Token, TokenKind}; -use rustc_ast::tokenstream::{DelimSpacing, DelimSpan}; +use rustc_ast::tokenstream::{DelimSpacing, DelimSpan, Spacing}; use rustc_macros::{Decodable, Encodable}; use rustc_span::symbol::Ident; use rustc_span::Span; @@ -68,7 +68,7 @@ pub(crate) enum KleeneOp { /// `MetaVarExpr` are "first-class" token trees. Useful for parsing macros. #[derive(Debug, PartialEq, Encodable, Decodable)] enum TokenTree { - Token(Token), + Token(Token, Spacing), /// A delimited sequence, e.g. `($e:expr)` (RHS) or `{ $e }` (LHS). Delimited(DelimSpan, DelimSpacing, Delimited), /// A kleene-style repetition sequence, e.g. `$($e:expr)*` (RHS) or `$($e),*` (LHS). @@ -90,7 +90,7 @@ impl TokenTree { /// Returns `true` if the given token tree is a token of the given kind. fn is_token(&self, expected_kind: &TokenKind) -> bool { match self { - TokenTree::Token(Token { kind: actual_kind, .. }) => actual_kind == expected_kind, + TokenTree::Token(Token { kind: actual_kind, .. }, _) => actual_kind == expected_kind, _ => false, } } @@ -98,7 +98,7 @@ impl TokenTree { /// Retrieves the `TokenTree`'s span. fn span(&self) -> Span { match *self { - TokenTree::Token(Token { span, .. }) + TokenTree::Token(Token { span, .. }, _) | TokenTree::MetaVar(span, _) | TokenTree::MetaVarDecl(span, _, _) => span, TokenTree::Delimited(span, ..) @@ -107,7 +107,7 @@ impl TokenTree { } } - fn token(kind: TokenKind, span: Span) -> TokenTree { - TokenTree::Token(Token::new(kind, span)) + fn token_alone(kind: TokenKind, span: Span) -> TokenTree { + TokenTree::Token(Token::new(kind, span), Spacing::Alone) } } diff --git a/compiler/rustc_expand/src/mbe/macro_check.rs b/compiler/rustc_expand/src/mbe/macro_check.rs index dce8e0c36edf7..c0df0b2794bb2 100644 --- a/compiler/rustc_expand/src/mbe/macro_check.rs +++ b/compiler/rustc_expand/src/mbe/macro_check.rs @@ -412,7 +412,7 @@ fn check_nested_occurrences( match (state, tt) { ( NestedMacroState::Empty, - &TokenTree::Token(Token { kind: TokenKind::Ident(name, IdentIsRaw::No), .. }), + &TokenTree::Token(Token { kind: TokenKind::Ident(name, IdentIsRaw::No), .. }, _), ) => { if name == kw::MacroRules { state = NestedMacroState::MacroRules; @@ -422,13 +422,13 @@ fn check_nested_occurrences( } ( NestedMacroState::MacroRules, - &TokenTree::Token(Token { kind: TokenKind::Not, .. }), + &TokenTree::Token(Token { kind: TokenKind::Not, .. }, _), ) => { state = NestedMacroState::MacroRulesNot; } ( NestedMacroState::MacroRulesNot, - &TokenTree::Token(Token { kind: TokenKind::Ident(..), .. }), + &TokenTree::Token(Token { kind: TokenKind::Ident(..), .. }, _), ) => { state = NestedMacroState::MacroRulesNotName; } @@ -459,7 +459,7 @@ fn check_nested_occurrences( } ( NestedMacroState::Macro, - &TokenTree::Token(Token { kind: TokenKind::Ident(..), .. }), + &TokenTree::Token(Token { kind: TokenKind::Ident(..), .. }, _), ) => { state = NestedMacroState::MacroName; } diff --git a/compiler/rustc_expand/src/mbe/macro_parser.rs b/compiler/rustc_expand/src/mbe/macro_parser.rs index 27cf6fee702a7..2e08b34631b7a 100644 --- a/compiler/rustc_expand/src/mbe/macro_parser.rs +++ b/compiler/rustc_expand/src/mbe/macro_parser.rs @@ -180,7 +180,7 @@ pub(super) fn compute_locs(matcher: &[TokenTree]) -> Vec { ) { for tt in tts { match tt { - TokenTree::Token(token) => { + TokenTree::Token(token, _) => { locs.push(MatcherLoc::Token { token: token.clone() }); } TokenTree::Delimited(span, _, delimited) => { diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index 470bde232d723..442ef45503934 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -11,7 +11,7 @@ use crate::mbe::transcribe::transcribe; use ast::token::IdentIsRaw; use rustc_ast as ast; use rustc_ast::token::{self, Delimiter, NonterminalKind, Token, TokenKind, TokenKind::*}; -use rustc_ast::tokenstream::{DelimSpan, TokenStream}; +use rustc_ast::tokenstream::{DelimSpan, Spacing, TokenStream}; use rustc_ast::{NodeId, DUMMY_NODE_ID}; use rustc_ast_pretty::pprust; use rustc_attr::{self as attr, TransparencyError}; @@ -402,7 +402,7 @@ pub fn compile_declarative_macro( mbe::SequenceRepetition { tts: vec![ mbe::TokenTree::MetaVarDecl(def.span, lhs_nm, tt_spec), - mbe::TokenTree::token(token::FatArrow, def.span), + mbe::TokenTree::token_alone(token::FatArrow, def.span), mbe::TokenTree::MetaVarDecl(def.span, rhs_nm, tt_spec), ], separator: Some(Token::new( @@ -417,7 +417,7 @@ pub fn compile_declarative_macro( mbe::TokenTree::Sequence( DelimSpan::dummy(), mbe::SequenceRepetition { - tts: vec![mbe::TokenTree::token( + tts: vec![mbe::TokenTree::token_alone( if macro_rules { token::Semi } else { token::Comma }, def.span, )], @@ -627,10 +627,11 @@ fn is_empty_token_tree(sess: &Session, seq: &mbe::SequenceRepetition) -> bool { while let Some(tt) = iter.next() { match tt { mbe::TokenTree::MetaVarDecl(_, _, Some(NonterminalKind::Vis)) => {} - mbe::TokenTree::Token(t @ Token { kind: DocComment(..), .. }) => { + mbe::TokenTree::Token(t @ Token { kind: DocComment(..), .. }, _) => { let mut now = t; while let Some(&mbe::TokenTree::Token( next @ Token { kind: DocComment(..), .. }, + _, )) = iter.peek() { now = next; @@ -696,10 +697,10 @@ fn has_compile_error_macro(rhs: &mbe::TokenTree) -> bool { match rhs { mbe::TokenTree::Delimited(.., d) => { let has_compile_error = d.tts.array_windows::<3>().any(|[ident, bang, args]| { - if let mbe::TokenTree::Token(ident) = ident + if let mbe::TokenTree::Token(ident, _) = ident && let TokenKind::Ident(ident, _) = ident.kind && ident == sym::compile_error - && let mbe::TokenTree::Token(bang) = bang + && let mbe::TokenTree::Token(bang, _) = bang && let TokenKind::Not = bang.kind && let mbe::TokenTree::Delimited(.., del) = args && del.delim != Delimiter::Invisible @@ -896,7 +897,9 @@ enum TtHandle<'tt> { impl<'tt> TtHandle<'tt> { fn from_token(tok: Token) -> Self { - TtHandle::Token(mbe::TokenTree::Token(tok)) + // `Spacing::Alone` is pessimistic but changing it has no effect on the + // current test suite. + TtHandle::Token(mbe::TokenTree::Token(tok, Spacing::Alone)) } fn from_token_kind(kind: TokenKind, span: Span) -> Self { @@ -925,8 +928,8 @@ impl<'tt> Clone for TtHandle<'tt> { // This variant *must* contain a `mbe::TokenTree::Token`, and not // any other variant of `mbe::TokenTree`. - TtHandle::Token(mbe::TokenTree::Token(tok)) => { - TtHandle::Token(mbe::TokenTree::Token(tok.clone())) + TtHandle::Token(mbe::TokenTree::Token(tok, spacing)) => { + TtHandle::Token(mbe::TokenTree::Token(tok.clone(), *spacing)) } _ => unreachable!(), @@ -1143,7 +1146,7 @@ fn check_matcher_core<'tt>( // whereas macros from an external crate have a dummy id. if def.id != DUMMY_NODE_ID && matches!(kind, NonterminalKind::PatParam { inferred: true }) - && matches!(next_token, TokenTree::Token(token) if token.kind == BinOp(token::BinOpToken::Or)) + && matches!(next_token, TokenTree::Token(token, _) if token.kind == BinOp(token::BinOpToken::Or)) { // It is suggestion to use pat_param, for example: $x:pat -> $x:pat_param. let suggestion = quoted_tt_to_string(&TokenTree::MetaVarDecl( @@ -1274,7 +1277,7 @@ enum IsInFollow { fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow { use mbe::TokenTree; - if let TokenTree::Token(Token { kind: token::CloseDelim(_), .. }) = *tok { + if let TokenTree::Token(Token { kind: token::CloseDelim(_), .. }, _) = *tok { // closing a token tree can never be matched by any fragment; // iow, we always require that `(` and `)` match, etc. IsInFollow::Yes @@ -1293,7 +1296,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow { NonterminalKind::Stmt | NonterminalKind::Expr => { const TOKENS: &[&str] = &["`=>`", "`,`", "`;`"]; match tok { - TokenTree::Token(token) => match token.kind { + TokenTree::Token(token, _) => match token.kind { FatArrow | Comma | Semi => IsInFollow::Yes, _ => IsInFollow::No(TOKENS), }, @@ -1303,7 +1306,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow { NonterminalKind::PatParam { .. } => { const TOKENS: &[&str] = &["`=>`", "`,`", "`=`", "`|`", "`if`", "`in`"]; match tok { - TokenTree::Token(token) => match token.kind { + TokenTree::Token(token, _) => match token.kind { FatArrow | Comma | Eq | BinOp(token::Or) => IsInFollow::Yes, Ident(name, IdentIsRaw::No) if name == kw::If || name == kw::In => { IsInFollow::Yes @@ -1316,7 +1319,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow { NonterminalKind::PatWithOr => { const TOKENS: &[&str] = &["`=>`", "`,`", "`=`", "`if`", "`in`"]; match tok { - TokenTree::Token(token) => match token.kind { + TokenTree::Token(token, _) => match token.kind { FatArrow | Comma | Eq => IsInFollow::Yes, Ident(name, IdentIsRaw::No) if name == kw::If || name == kw::In => { IsInFollow::Yes @@ -1332,7 +1335,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow { "`where`", ]; match tok { - TokenTree::Token(token) => match token.kind { + TokenTree::Token(token, _) => match token.kind { OpenDelim(Delimiter::Brace) | OpenDelim(Delimiter::Bracket) | Comma @@ -1369,7 +1372,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow { // Explicitly disallow `priv`, on the off chance it comes back. const TOKENS: &[&str] = &["`,`", "an ident", "a type"]; match tok { - TokenTree::Token(token) => match token.kind { + TokenTree::Token(token, _) => match token.kind { Comma => IsInFollow::Yes, Ident(_, IdentIsRaw::Yes) => IsInFollow::Yes, Ident(name, _) if name != kw::Priv => IsInFollow::Yes, @@ -1395,7 +1398,7 @@ fn is_in_follow(tok: &mbe::TokenTree, kind: NonterminalKind) -> IsInFollow { fn quoted_tt_to_string(tt: &mbe::TokenTree) -> String { match tt { - mbe::TokenTree::Token(token) => pprust::token_to_string(token).into(), + mbe::TokenTree::Token(token, _) => pprust::token_to_string(token).into(), mbe::TokenTree::MetaVar(_, name) => format!("${name}"), mbe::TokenTree::MetaVarDecl(_, name, Some(kind)) => format!("${name}:{kind}"), mbe::TokenTree::MetaVarDecl(_, name, None) => format!("${name}:"), diff --git a/compiler/rustc_expand/src/mbe/quoted.rs b/compiler/rustc_expand/src/mbe/quoted.rs index 2e5596f51c35d..8d2701623f7ab 100644 --- a/compiler/rustc_expand/src/mbe/quoted.rs +++ b/compiler/rustc_expand/src/mbe/quoted.rs @@ -180,7 +180,7 @@ fn parse_tree<'a>( err.emit(); // Returns early the same read `$` to avoid spanning // unrelated diagnostics that could be performed afterwards - return TokenTree::token(token::Dollar, span); + return TokenTree::token_alone(token::Dollar, span); } Ok(elem) => { maybe_emit_macro_metavar_expr_feature( @@ -220,11 +220,14 @@ fn parse_tree<'a>( // `tree` is followed by an `ident`. This could be `$meta_var` or the `$crate` // special metavariable that names the crate of the invocation. - Some(tokenstream::TokenTree::Token(token, _)) if token.is_ident() => { + Some(tokenstream::TokenTree::Token(token, spacing)) if token.is_ident() => { let (ident, is_raw) = token.ident().unwrap(); let span = ident.span.with_lo(span.lo()); if ident.name == kw::Crate && matches!(is_raw, IdentIsRaw::No) { - TokenTree::token(token::Ident(kw::DollarCrate, is_raw), span) + TokenTree::Token( + Token::new(token::Ident(kw::DollarCrate, is_raw), span), + *spacing, + ) } else { TokenTree::MetaVar(span, ident) } @@ -240,7 +243,7 @@ fn parse_tree<'a>( } else { maybe_emit_macro_metavar_expr_feature(features, sess, span); } - TokenTree::token(token::Dollar, span) + TokenTree::token_alone(token::Dollar, span) } // `tree` is followed by some other token. This is an error. @@ -252,12 +255,12 @@ fn parse_tree<'a>( } // There are no more tokens. Just return the `$` we already have. - None => TokenTree::token(token::Dollar, span), + None => TokenTree::token_alone(token::Dollar, span), } } // `tree` is an arbitrary token. Keep it. - tokenstream::TokenTree::Token(token, _) => TokenTree::Token(token.clone()), + tokenstream::TokenTree::Token(token, spacing) => TokenTree::Token(token.clone(), *spacing), // `tree` is the beginning of a delimited set of tokens (e.g., `(` or `{`). We need to // descend into the delimited set and further parse it. diff --git a/compiler/rustc_expand/src/mbe/transcribe.rs b/compiler/rustc_expand/src/mbe/transcribe.rs index 3901b82eb52ec..2a83ec57f861b 100644 --- a/compiler/rustc_expand/src/mbe/transcribe.rs +++ b/compiler/rustc_expand/src/mbe/transcribe.rs @@ -315,10 +315,10 @@ pub(super) fn transcribe<'a>( // Nothing much to do here. Just push the token to the result, being careful to // preserve syntax context. - mbe::TokenTree::Token(token) => { + mbe::TokenTree::Token(token, spacing) => { let mut token = token.clone(); mut_visit::visit_token(&mut token, &mut marker); - let tt = TokenTree::Token(token, Spacing::Alone); + let tt = TokenTree::Token(token, *spacing); result.push(tt); } diff --git a/compiler/rustc_expand/src/proc_macro_server.rs b/compiler/rustc_expand/src/proc_macro_server.rs index 1f3547c841a90..ec7e4416b9130 100644 --- a/compiler/rustc_expand/src/proc_macro_server.rs +++ b/compiler/rustc_expand/src/proc_macro_server.rs @@ -309,10 +309,10 @@ impl ToInternal> use rustc_ast::token::*; // The code below is conservative, using `token_alone`/`Spacing::Alone` - // in most places. When the resulting code is pretty-printed by - // `print_tts` it ends up with spaces between most tokens, which is - // safe but ugly. It's hard in general to do better when working at the - // token level. + // in most places. It's hard in general to do better when working at + // the token level. When the resulting code is pretty-printed by + // `print_tts` the `space_between` function helps avoid a lot of + // unnecessary whitespace, so the results aren't too bad. let (tree, rustc) = self; match tree { TokenTree::Punct(Punct { ch, joint, span }) => { diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 3e0a98a55ae9b..d4a2966ffe9fc 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -276,6 +276,7 @@ impl TokenCursor { token.kind, token::OpenDelim(_) | token::CloseDelim(_) )); + //eprintln!("t = {token:?}, sp = {spacing:?}"); return (token.clone(), spacing); } &TokenTree::Delimited(sp, spacing, delim, ref tts) => { diff --git a/tests/ui/infinite/issue-41731-infinite-macro-print.stderr b/tests/ui/infinite/issue-41731-infinite-macro-print.stderr index 71510816d0bea..2686b64f72ae4 100644 --- a/tests/ui/infinite/issue-41731-infinite-macro-print.stderr +++ b/tests/ui/infinite/issue-41731-infinite-macro-print.stderr @@ -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 diff --git a/tests/ui/infinite/issue-41731-infinite-macro-println.stderr b/tests/ui/infinite/issue-41731-infinite-macro-println.stderr index 645176d45cb9c..647384fe2134c 100644 --- a/tests/ui/infinite/issue-41731-infinite-macro-println.stderr +++ b/tests/ui/infinite/issue-41731-infinite-macro-println.stderr @@ -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 diff --git a/tests/ui/macros/issue-98790.rs b/tests/ui/macros/issue-98790.rs index b489efe9ce939..150132552e603 100644 --- a/tests/ui/macros/issue-98790.rs +++ b/tests/ui/macros/issue-98790.rs @@ -19,6 +19,8 @@ macro_rules! repro { fn main() { assert_eq!( repro!(match () { () => true } | true), - "pub fn repro() -> bool { (match () { () => true, }) | true }" + // njn: dtolnay will take care of this + //"pub fn repro() -> bool { (match () { () => true, }) | true }" + "pub fn repro() -> bool { match () { () => true } | true }" ); } diff --git a/tests/ui/macros/macro-first-set.rs b/tests/ui/macros/macro-first-set.rs index 0f8f26b88c288..ff148d15ecc95 100644 --- a/tests/ui/macros/macro-first-set.rs +++ b/tests/ui/macros/macro-first-set.rs @@ -26,7 +26,14 @@ macro_rules! foo_26444 { } fn test_26444() { - assert_eq!("a, b, c, d, e", foo_26444!(a, b; c; d, e)); + // This one may be surprising. The macro definition has `$($beginning,)*` + // and `$(,$end)*`. The two commas in those fragments have no space after + // them, so the first one is marked `JointHidden` (because it's followed by + // non-punctuation) and the second is marked `Joint` (because it's followed + // by puncuation). Then they get duplicated into the output. Then + // `stringify!` does token pretty printing and because they are both joint, + // no space is put after them. + assert_eq!("a,b,c,d,e", foo_26444!(a, b; c; d, e)); assert_eq!("f", foo_26444!(; f ;)); } diff --git a/tests/ui/macros/stringify.rs b/tests/ui/macros/stringify.rs index 6b215ba525deb..afb585e78cfe7 100644 --- a/tests/ui/macros/stringify.rs +++ b/tests/ui/macros/stringify.rs @@ -37,25 +37,22 @@ macro_rules! vis { ($vis:vis) => { stringify!($vis) }; } // the same result (which is preferable.) macro_rules! c1 { ($frag:ident, [$($tt:tt)*], $s:literal) => { + // Prior to #125174: + // - the first of these two lines created a `TokenKind::Interpolated` + // that was printed by the AST pretty printer; + // - the second of these two lines created a token stream that was + // printed by the TokenStream pretty printer. + // + // Now they are both printed by the TokenStream pretty printer. But it + // doesn't hurt to keep both assertions to ensure this remains true. + // + // (This also explains the name `c1`. There used to be a `c2` macro for + // cases where the two pretty printers produced different output.) assert_eq!($frag!($($tt)*), $s); assert_eq!(stringify!($($tt)*), $s); }; } -// Use this when AST pretty-printing and TokenStream pretty-printing give -// different results. -// -// `c1` and `c2` could be in a single macro, but having them separate makes it -// easy to find the cases where the two pretty-printing approaches give -// different results. -macro_rules! c2 { - ($frag:ident, [$($tt:tt)*], $s1:literal, $s2:literal $(,)?) => { - assert_ne!($s1, $s2, "should use `c1!` instead"); - assert_eq!($frag!($($tt)*), $s1); - assert_eq!(stringify!($($tt)*), $s2); - }; -} - #[test] fn test_block() { c1!(block, [ {} ], "{}"); @@ -76,7 +73,7 @@ fn test_expr() { // ExprKind::Array c1!(expr, [ [] ], "[]"); c1!(expr, [ [true] ], "[true]"); - c2!(expr, [ [true,] ], "[true]", "[true,]"); + c1!(expr, [ [true,] ], "[true,]"); c1!(expr, [ [true, true] ], "[true, true]"); // ExprKind::ConstBlock @@ -85,11 +82,11 @@ fn test_expr() { // ExprKind::Call c1!(expr, [ f() ], "f()"); c1!(expr, [ f::() ], "f::()"); - c2!(expr, [ f :: < u8>( ) ], "f::()", "f :: < u8>()"); + c1!(expr, [ f :: < u8>( ) ], "f :: < u8>()"); c1!(expr, [ f::<1>() ], "f::<1>()"); c1!(expr, [ f::<'a, u8, 1>() ], "f::<'a, u8, 1>()"); c1!(expr, [ f(true) ], "f(true)"); - c2!(expr, [ f(true,) ], "f(true)", "f(true,)"); + c1!(expr, [ f(true,) ], "f(true,)"); c1!(expr, [ ()() ], "()()"); // ExprKind::MethodCall @@ -101,7 +98,7 @@ fn test_expr() { c1!(expr, [ () ], "()"); c1!(expr, [ (true,) ], "(true,)"); c1!(expr, [ (true, false) ], "(true, false)"); - c2!(expr, [ (true, false,) ], "(true, false)", "(true, false,)"); + c1!(expr, [ (true, false,) ], "(true, false,)"); // ExprKind::Binary c1!(expr, [ true || false ], "true || false"); @@ -131,16 +128,12 @@ fn test_expr() { c1!(expr, [ if let Some(a) = b { c } else { d } ], "if let Some(a) = b { c } else { d }"); c1!(expr, [ if let _ = true && false {} ], "if let _ = true && false {}"); c1!(expr, [ if let _ = (true && false) {} ], "if let _ = (true && false) {}"); - macro_rules! c2_if_let { - ($expr:expr, $expr_expected:expr, $tokens_expected:expr $(,)?) => { - c2!(expr, [ if let _ = $expr {} ], $expr_expected, $tokens_expected); + macro_rules! c1_if_let { + ($expr:expr, $s:literal) => { + c1!(expr, [ if let _ = $expr {} ], $s); }; } - c2_if_let!( - true && false, - "if let _ = (true && false) {}", - "if let _ = true && false {}", - ); + c1_if_let!(true && false, "if let _ = true && false {}"); c1!(expr, [ match () { _ if let _ = Struct {} => {} } ], "match () { _ if let _ = Struct {} => {} }" @@ -203,31 +196,15 @@ fn test_expr() { } ], "match self { Ok => 1, Err => 0, }" ); - macro_rules! c2_match_arm { - ([ $expr:expr ], $expr_expected:expr, $tokens_expected:expr $(,)?) => { - c2!(expr, [ match () { _ => $expr } ], $expr_expected, $tokens_expected); + macro_rules! c1_match_arm { + ([ $expr:expr ], $s:literal) => { + c1!(expr, [ match () { _ => $expr } ], $s); }; } - c2_match_arm!( - [ { 1 } - 1 ], - "match () { _ => ({ 1 }) - 1, }", - "match () { _ => { 1 } - 1 }", - ); - c2_match_arm!( - [ m!() - 1 ], - "match () { _ => m!() - 1, }", - "match () { _ => m!() - 1 }", - ); - c2_match_arm!( - [ m![] - 1 ], - "match () { _ => m![] - 1, }", - "match () { _ => m![] - 1 }", - ); - c2_match_arm!( - [ m! {} - 1 ], - "match () { _ => m! {} - 1, }", - "match () { _ => m! {} - 1 }", - ); + c1_match_arm!([ { 1 } - 1 ], "match () { _ => { 1 } - 1 }"); + c1_match_arm!([ m!() - 1 ], "match () { _ => m!() - 1 }"); + c1_match_arm!([ m![] - 1 ], "match () { _ => m![] - 1 }"); + c1_match_arm!([ m! {} - 1 ], "match () { _ => m! {} - 1 }"); // ExprKind::Closure c1!(expr, [ || {} ], "|| {}"); @@ -242,22 +219,19 @@ fn test_expr() { c1!(expr, [ static async || self ], "static async || self"); c1!(expr, [ static async move || self ], "static async move || self"); c1!(expr, [ || -> u8 { self } ], "|| -> u8 { self }"); - c2!(expr, [ 1 + || {} ], "1 + (|| {})", "1 + || {}"); // AST?? + c1!(expr, [ 1 + || {} ], "1 + || {}"); // ExprKind::Block c1!(expr, [ {} ], "{}"); c1!(expr, [ unsafe {} ], "unsafe {}"); c1!(expr, [ 'a: {} ], "'a: {}"); c1!(expr, [ #[attr] {} ], "#[attr] {}"); - c2!(expr, + c1!(expr, [ { #![attr] } ], - "{\n\ - \x20 #![attr]\n\ - }", "{ #![attr] }" ); @@ -289,7 +263,7 @@ fn test_expr() { c1!(expr, [ ..hi ], "..hi"); c1!(expr, [ lo.. ], "lo.."); c1!(expr, [ lo..hi ], "lo..hi"); - c2!(expr, [ lo .. hi ], "lo..hi", "lo .. hi"); + c1!(expr, [ lo .. hi ], "lo .. hi"); c1!(expr, [ ..=hi ], "..=hi"); c1!(expr, [ lo..=hi ], "lo..=hi"); c1!(expr, [ -2..=-1 ], "-2..=-1"); @@ -382,11 +356,7 @@ fn test_item() { c1!(item, [ pub extern crate self as std; ], "pub extern crate self as std;"); // ItemKind::Use - c2!(item, - [ pub use crate::{a, b::c}; ], - "pub use crate::{a, b::c};", - "pub use crate::{ a, b::c };" // FIXME - ); + c1!(item, [ pub use crate::{a, b::c}; ], "pub use crate::{ a, b::c };"); // FIXME c1!(item, [ pub use A::*; ], "pub use A::*;"); // ItemKind::Static @@ -418,24 +388,19 @@ fn test_item() { // ItemKind::ForeignMod c1!(item, [ extern "C" {} ], "extern \"C\" {}"); - c2!(item, - [ pub extern "C" {} ], - "extern \"C\" {}", // ?? - "pub extern \"C\" {}" - ); + c1!(item, [ pub extern "C" {} ], "pub extern \"C\" {}"); c1!(item, [ unsafe extern "C++" {} ], "unsafe extern \"C++\" {}"); // ItemKind::GlobalAsm: untestable because this test works pre-expansion. // ItemKind::TyAlias - c2!(item, + c1!(item, [ pub default type Type<'a>: Bound where Self: 'a, = T; ], - "pub default type Type<'a>: Bound where Self: 'a = T;", "pub default type Type<'a>: Bound where Self: 'a, = T;" ); @@ -451,7 +416,7 @@ fn test_item() { ], "enum Empty { Unit, Tuple(), Struct {}, }" ); - c2!(item, + c1!(item, [ enum Enum where @@ -462,13 +427,6 @@ fn test_item() { Struct { t: T }, } ], - "enum Enum where T: 'a {\n\ - \x20 Unit,\n\ - \x20 Tuple(T),\n\ - \x20 Struct {\n\ - \x20 t: T,\n\ - \x20 },\n\ - }", "enum Enum where T: 'a, { Unit, Tuple(T), Struct { t: T }, }" ); @@ -477,7 +435,7 @@ fn test_item() { c1!(item, [ struct Tuple(); ], "struct Tuple();"); c1!(item, [ struct Tuple(T); ], "struct Tuple(T);"); c1!(item, [ struct Struct {} ], "struct Struct {}"); - c2!(item, + c1!(item, [ struct Struct where @@ -486,29 +444,23 @@ fn test_item() { t: T, } ], - "struct Struct where T: 'a {\n\ - \x20 t: T,\n\ - }", "struct Struct where T: 'a, { t: T, }" ); // ItemKind::Union c1!(item, [ pub union Union {} ], "pub union Union {}"); - c2!(item, + c1!(item, [ union Union where T: 'a { t: T, } ], - "union Union where T: 'a {\n\ - \x20 t: T,\n\ - }", "union Union where T: 'a { t: T, }" ); // ItemKind::Trait c1!(item, [ pub unsafe auto trait Send {} ], "pub unsafe auto trait Send {}"); - c2!(item, + c1!(item, [ trait Trait<'a>: Sized where @@ -516,7 +468,6 @@ fn test_item() { { } ], - "trait Trait<'a>: Sized where Self: 'a {}", "trait Trait<'a>: Sized where Self: 'a, {}" ); @@ -547,11 +498,7 @@ fn test_item() { ], "macro_rules! stringify { () => {}; }" ); - c2!(item, - [ pub macro stringify() {} ], - "pub macro stringify { () => {} }", // ?? - "pub macro stringify() {}" - ); + c1!(item, [ pub macro stringify() {} ], "pub macro stringify() {}"); } #[test] @@ -577,7 +524,7 @@ fn test_pat() { // PatKind::Struct c1!(pat, [ Struct {} ], "Struct {}"); c1!(pat, [ Struct:: {} ], "Struct:: {}"); - c2!(pat, [ Struct ::< u8 > {} ], "Struct:: {}", "Struct ::< u8 > {}"); + c1!(pat, [ Struct ::< u8 > {} ], "Struct ::< u8 > {}"); c1!(pat, [ Struct::<'static> {} ], "Struct::<'static> {}"); c1!(pat, [ Struct { x } ], "Struct { x }"); c1!(pat, [ Struct { x: _x } ], "Struct { x: _x }"); @@ -597,8 +544,8 @@ fn test_pat() { // PatKind::Or c1!(pat, [ true | false ], "true | false"); - c2!(pat, [ | true ], "true", "| true"); - c2!(pat, [ |true| false ], "true | false", "|true| false"); + c1!(pat, [ | true ], "| true"); + c1!(pat, [ |true| false ], "|true| false"); // PatKind::Path c1!(pat, [ crate::Path ], "crate::Path"); @@ -631,7 +578,7 @@ fn test_pat() { // PatKind::Slice c1!(pat, [ [] ], "[]"); c1!(pat, [ [true] ], "[true]"); - c2!(pat, [ [true,] ], "[true]", "[true,]"); + c1!(pat, [ [true,] ], "[true,]"); c1!(pat, [ [true, false] ], "[true, false]"); // PatKind::Rest @@ -658,7 +605,7 @@ fn test_path() { c1!(path, [ crate::thing ], "crate::thing"); c1!(path, [ Self::thing ], "Self::thing"); c1!(path, [ Self<'static> ], "Self<'static>"); - c2!(path, [ Self::<'static> ], "Self<'static>", "Self::<'static>"); + c1!(path, [ Self::<'static> ], "Self::<'static>"); c1!(path, [ Self() ], "Self()"); c1!(path, [ Self() -> () ], "Self() -> ()"); } @@ -666,40 +613,24 @@ fn test_path() { #[test] fn test_stmt() { // StmtKind::Local - c2!(stmt, [ let _ ], "let _;", "let _"); - c2!(stmt, [ let x = true ], "let x = true;", "let x = true"); - c2!(stmt, [ let x: bool = true ], "let x: bool = true;", "let x: bool = true"); - c2!(stmt, [ let (a, b) = (1, 2) ], "let (a, b) = (1, 2);", "let (a, b) = (1, 2)"); - c2!(stmt, - [ let (a, b): (u32, u32) = (1, 2) ], - "let (a, b): (u32, u32) = (1, 2);", - "let (a, b): (u32, u32) = (1, 2)" - ); - c2!(stmt, - [ let _ = f() else { return; } ], - "let _ = f() else { return; };", - "let _ = f() else { return; }", - ); - macro_rules! c2_let_expr_minus_one { - ([ $expr:expr ], $stmt_expected:expr, $tokens_expected:expr $(,)?) => { - c2!(stmt, [ let _ = $expr - 1 ], $stmt_expected, $tokens_expected); + c1!(stmt, [ let _ ], "let _"); + c1!(stmt, [ let x = true ], "let x = true"); + c1!(stmt, [ let x: bool = true ], "let x: bool = true"); + c1!(stmt, [ let (a, b) = (1, 2) ], "let (a, b) = (1, 2)"); + c1!(stmt, [ let (a, b): (u32, u32) = (1, 2) ], "let (a, b): (u32, u32) = (1, 2)"); + c1!(stmt, [ let _ = f() else { return; } ], "let _ = f() else { return; }"); + macro_rules! c1_let_expr_minus_one { + ([ $expr:expr ], $s:literal) => { + c1!(stmt, [ let _ = $expr - 1 ], $s); }; } - c2_let_expr_minus_one!( - [ match void {} ], - "let _ = match void {} - 1;", - "let _ = match void {} - 1", - ); - macro_rules! c2_let_expr_else_return { - ([ $expr:expr ], $stmt_expected:expr, $tokens_expected:expr $(,)?) => { - c2!(stmt, [ let _ = $expr else { return; } ], $stmt_expected, $tokens_expected); + c1_let_expr_minus_one!( [ match void {} ], "let _ = match void {} - 1"); + macro_rules! c1_let_expr_else_return { + ([ $expr:expr ], $s:literal) => { + c1!(stmt, [ let _ = $expr else { return; } ], $s); }; } - c2_let_expr_else_return!( - [ f() ], - "let _ = f() else { return; };", - "let _ = f() else { return; }", - ); + c1_let_expr_else_return!([ f() ], "let _ = f() else { return; }"); // StmtKind::Item c1!(stmt, [ struct S; ], "struct S;"); @@ -709,11 +640,12 @@ fn test_stmt() { c1!(stmt, [ loop {} ], "loop {}"); // StmtKind::Semi - c2!(stmt, [ 1 + 1 ], "1 + 1;", "1 + 1"); - macro_rules! c2_expr_as_stmt { + c1!(stmt, [ 1 + 1 ], "1 + 1"); + // njn: dtolnay will move these ones out of this test + macro_rules! c1_expr_as_stmt { // Parse as expr, then reparse as stmt. // - // The c2_minus_one macro below can't directly call `c2!(stmt, ...)` + // The c1_minus_one macro below can't directly call `c1!(stmt, ...)` // because `$expr - 1` cannot be parsed directly as a stmt. A statement // boundary occurs after the `match void {}`, after which the `-` token // hits "no rules expected this token in macro call". @@ -721,50 +653,22 @@ fn test_stmt() { // The unwanted statement boundary is exactly why the pretty-printer is // injecting parentheses around the subexpression, which is the behavior // we are interested in testing. - ([ $expr:expr ], $stmt_expected:expr, $tokens_expected:expr $(,)?) => { - c2!(stmt, [ $expr ], $stmt_expected, $tokens_expected); + ([ $expr:expr ], $s:literal) => { + c1!(stmt, [ $expr ], $s); }; } - macro_rules! c2_minus_one { - ([ $expr:expr ], $stmt_expected:expr, $tokens_expected:expr $(,)?) => { - c2_expr_as_stmt!([ $expr - 1 ], $stmt_expected, $tokens_expected); + macro_rules! c1_minus_one { + ([ $expr:expr ], $s:literal) => { + c1_expr_as_stmt!([ $expr - 1 ], $s); }; } - c2_minus_one!( - [ match void {} ], - "(match void {}) - 1;", - "match void {} - 1", - ); - c2_minus_one!( - [ match void {}() ], - "(match void {})() - 1;", - "match void {}() - 1", - ); - c2_minus_one!( - [ match void {}[0] ], - "(match void {})[0] - 1;", - "match void {}[0] - 1", - ); - c2_minus_one!( - [ loop { break 1; } ], - "(loop { break 1; }) - 1;", - "loop { break 1; } - 1", - ); - c2_minus_one!( - [ m!() ], - "m!() - 1;", - "m!() - 1" - ); - c2_minus_one!( - [ m![] ], - "m![] - 1;", - "m![] - 1" - ); - c2_minus_one!( - [ m! {} ], - "(m! {}) - 1;", - "m! {} - 1" - ); + c1_minus_one!( [ match void {} ], "match void {} - 1"); + c1_minus_one!( [ match void {}() ], "match void {}() - 1"); + c1_minus_one!( [ match void {}[0] ], "match void {}[0] - 1"); + c1_minus_one!( [ loop { break 1; } ], "loop { break 1; } - 1"); + c1_minus_one!( [ m!() ], "m!() - 1"); + c1_minus_one!( [ m![] ], "m![] - 1"); + c1_minus_one!( [ m! {} ], "m! {} - 1"); // StmtKind::Empty c1!(stmt, [ ; ], ";"); @@ -793,14 +697,14 @@ fn test_ty() { c1!(ty, [ &'a T ], "&'a T"); c1!(ty, [ &'a mut [T] ], "&'a mut [T]"); c1!(ty, [ &A>>> ], "&A>>>"); - c2!(ty, [ &A > > > ], "&A>>>", "&A > > >"); + c1!(ty, [ &A > > > ], "&A > > >"); // TyKind::BareFn c1!(ty, [ fn() ], "fn()"); c1!(ty, [ fn() -> () ], "fn() -> ()"); c1!(ty, [ fn(u8) ], "fn(u8)"); c1!(ty, [ fn(x: u8) ], "fn(x: u8)"); - c2!(ty, [ for<> fn() ], "fn()", "for<> fn()"); + c1!(ty, [ for<> fn() ], "for<> fn()"); c1!(ty, [ for<'a> fn() ], "for<'a> fn()"); // TyKind::Never @@ -819,7 +723,7 @@ fn test_ty() { c1!(ty, [ T ], "T"); c1!(ty, [ Ref<'a> ], "Ref<'a>"); c1!(ty, [ PhantomData ], "PhantomData"); - c2!(ty, [ PhantomData:: ], "PhantomData", "PhantomData::"); + c1!(ty, [ PhantomData:: ], "PhantomData::"); c1!(ty, [ Fn() -> ! ], "Fn() -> !"); c1!(ty, [ Fn(u8) -> ! ], "Fn(u8) -> !"); c1!(ty, [ ::Type ], "::Type"); @@ -864,23 +768,19 @@ fn test_ty() { #[test] fn test_vis() { // VisibilityKind::Public - c2!(vis, [ pub ], "pub ", "pub"); + c1!(vis, [ pub ], "pub"); // VisibilityKind::Restricted - c2!(vis, [ pub(crate) ], "pub(crate) ", "pub(crate)"); - c2!(vis, [ pub(self) ], "pub(self) ", "pub(self)"); - c2!(vis, [ pub(super) ], "pub(super) ", "pub(super)"); - c2!(vis, [ pub(in crate) ], "pub(in crate) ", "pub(in crate)"); - c2!(vis, [ pub(in self) ], "pub(in self) ", "pub(in self)"); - c2!(vis, [ pub(in super) ], "pub(in super) ", "pub(in super)"); - c2!(vis, [ pub(in path::to) ], "pub(in path::to) ", "pub(in path::to)"); - c2!(vis, [ pub(in ::path::to) ], "pub(in ::path::to) ", "pub(in ::path::to)"); - c2!(vis, [ pub(in self::path::to) ], "pub(in self::path::to) ", "pub(in self::path::to)"); - c2!(vis, - [ pub(in super::path::to) ], - "pub(in super::path::to) ", - "pub(in super::path::to)" - ); + c1!(vis, [ pub(crate) ], "pub(crate)"); + c1!(vis, [ pub(self) ], "pub(self)"); + c1!(vis, [ pub(super) ], "pub(super)"); + c1!(vis, [ pub(in crate) ], "pub(in crate)"); + c1!(vis, [ pub(in self) ], "pub(in self)"); + c1!(vis, [ pub(in super) ], "pub(in super)"); + c1!(vis, [ pub(in path::to) ], "pub(in path::to)"); + c1!(vis, [ pub(in ::path::to) ], "pub(in ::path::to)"); + c1!(vis, [ pub(in self::path::to) ], "pub(in self::path::to)"); + c1!(vis, [ pub(in super::path::to) ], "pub(in super::path::to)"); // VisibilityKind::Inherited // This one is different because directly calling `vis!` does not work. diff --git a/tests/ui/macros/trace-macro.stderr b/tests/ui/macros/trace-macro.stderr index dac4cc12f849d..0fbdc94269bcf 100644 --- a/tests/ui/macros/trace-macro.stderr +++ b/tests/ui/macros/trace-macro.stderr @@ -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!")); }` diff --git a/tests/ui/macros/trace_faulty_macros.rs b/tests/ui/macros/trace_faulty_macros.rs index ec1ce1a1f9259..87036bb9c6f75 100644 --- a/tests/ui/macros/trace_faulty_macros.rs +++ b/tests/ui/macros/trace_faulty_macros.rs @@ -46,7 +46,7 @@ macro_rules! test { (let $p:pat = $e:expr) => {test!(($p,$e))}; // this should be expr // vvv - (($p:pat, $e:pat)) => {let $p = $e;}; //~ ERROR expected expression, found pattern `1 + 1` + (($p:pat, $e:pat)) => {let $p = $e;}; //~ ERROR expected expression, found pattern `1+1` } fn foo() { diff --git a/tests/ui/macros/trace_faulty_macros.stderr b/tests/ui/macros/trace_faulty_macros.stderr index 665dcc7d0913c..111b50268ffb7 100644 --- a/tests/ui/macros/trace_faulty_macros.stderr +++ b/tests/ui/macros/trace_faulty_macros.stderr @@ -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,15 +42,15 @@ 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 pattern `A { a: a, b: 0, c: _, .. }` +error: expected expression, found pattern `A{ a:a, b:0, c:_, .. }` --> $DIR/trace_faulty_macros.rs:16:9 | LL | $a @@ -69,7 +69,7 @@ LL | #[derive(Debug)] LL | fn use_derive_macro_as_attr() {} | -------------------------------- not a `struct`, `enum` or `union` -error: expected expression, found pattern `1 + 1` +error: expected expression, found pattern `1+1` --> $DIR/trace_faulty_macros.rs:49:37 | LL | (let $p:pat = $e:expr) => {test!(($p,$e))}; @@ -94,9 +94,9 @@ 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 `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:_, .. }` note: trace_macro --> $DIR/trace_faulty_macros.rs:53:5 @@ -105,9 +105,9 @@ LL | test!(let x = 1+1); | ^^^^^^^^^^^^^^^^^^ | = note: expanding `test! { let x = 1+1 }` - = note: to `test! ((x, 1 + 1))` - = note: expanding `test! { (x, 1 + 1) }` - = note: to `let x = 1 + 1;` + = note: to `test!((x,1+1))` + = note: expanding `test! { (x,1+1) }` + = note: to `let x = 1+1;` error: aborting due to 5 previous errors diff --git a/tests/ui/proc-macro/capture-macro-rules-invoke.stdout b/tests/ui/proc-macro/capture-macro-rules-invoke.stdout index 71e34119ba7ee..172e5ec6e4277 100644 --- a/tests/ui/proc-macro/capture-macro-rules-invoke.stdout +++ b/tests/ui/proc-macro/capture-macro-rules-invoke.stdout @@ -11,9 +11,7 @@ PRINT-BANG INPUT (DEBUG): TokenStream [ span: $DIR/capture-macro-rules-invoke.rs:21:21: 21:26 (#3), }, ] -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, +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 DEEP-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 diff --git a/tests/ui/proc-macro/dollar-crate-issue-57089.stdout b/tests/ui/proc-macro/dollar-crate-issue-57089.stdout index 79b39d36ffb7d..b2623646bf112 100644 --- a/tests/ui/proc-macro/dollar-crate-issue-57089.stdout +++ b/tests/ui/proc-macro/dollar-crate-issue-57089.stdout @@ -1,4 +1,5 @@ -PRINT-BANG INPUT (DISPLAY): struct M($crate :: S); +PRINT-BANG INPUT (DISPLAY): struct M($crate::S); +PRINT-BANG DEEP-RE-COLLECTED (DISPLAY): struct M($crate :: S); PRINT-BANG INPUT (DEBUG): TokenStream [ Ident { ident: "struct", @@ -38,7 +39,8 @@ 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 DEEP-RE-COLLECTED (DISPLAY): struct A($crate :: S); PRINT-ATTR INPUT (DEBUG): TokenStream [ Ident { ident: "struct", diff --git a/tests/ui/proc-macro/dollar-crate-issue-62325.stdout b/tests/ui/proc-macro/dollar-crate-issue-62325.stdout index bfd013476f3a9..686f828c24ec6 100644 --- a/tests/ui/proc-macro/dollar-crate-issue-62325.stdout +++ b/tests/ui/proc-macro/dollar-crate-issue-62325.stdout @@ -1,4 +1,5 @@ -PRINT-ATTR INPUT (DISPLAY): struct A(identity! ($crate :: S)); +PRINT-ATTR INPUT (DISPLAY): struct A(identity!($crate::S)); +PRINT-ATTR DEEP-RE-COLLECTED (DISPLAY): struct A(identity! ($crate :: S)); PRINT-ATTR INPUT (DEBUG): TokenStream [ Ident { ident: "struct", @@ -53,7 +54,8 @@ 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 DEEP-RE-COLLECTED (DISPLAY): struct B(identity! ($crate :: S)); PRINT-ATTR INPUT (DEBUG): TokenStream [ Ident { ident: "struct", diff --git a/tests/ui/proc-macro/dollar-crate.stdout b/tests/ui/proc-macro/dollar-crate.stdout index 0278ef1ad0fcd..709f7ed3b6655 100644 --- a/tests/ui/proc-macro/dollar-crate.stdout +++ b/tests/ui/proc-macro/dollar-crate.stdout @@ -1,4 +1,5 @@ -PRINT-BANG INPUT (DISPLAY): struct M($crate :: S); +PRINT-BANG INPUT (DISPLAY): struct M($crate::S); +PRINT-BANG DEEP-RE-COLLECTED (DISPLAY): struct M($crate :: S); PRINT-BANG INPUT (DEBUG): TokenStream [ Ident { ident: "struct", @@ -38,7 +39,8 @@ 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 DEEP-RE-COLLECTED (DISPLAY): struct A($crate :: S); PRINT-ATTR INPUT (DEBUG): TokenStream [ Ident { ident: "struct", @@ -78,7 +80,8 @@ 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 DEEP-RE-COLLECTED (DISPLAY): struct D($crate :: S); PRINT-DERIVE INPUT (DEBUG): TokenStream [ Ident { ident: "struct", @@ -118,7 +121,8 @@ 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 DEEP-RE-COLLECTED (DISPLAY): struct M($crate :: S); PRINT-BANG INPUT (DEBUG): TokenStream [ Ident { ident: "struct", @@ -158,7 +162,8 @@ 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 DEEP-RE-COLLECTED (DISPLAY): struct A($crate :: S); PRINT-ATTR INPUT (DEBUG): TokenStream [ Ident { ident: "struct", @@ -198,7 +203,8 @@ 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 DEEP-RE-COLLECTED (DISPLAY): struct D($crate :: S); PRINT-DERIVE INPUT (DEBUG): TokenStream [ Ident { ident: "struct", diff --git a/tests/ui/proc-macro/expand-to-derive.stdout b/tests/ui/proc-macro/expand-to-derive.stdout index d59b7e5b88f45..1ee93b8a2b7d2 100644 --- a/tests/ui/proc-macro/expand-to-derive.stdout +++ b/tests/ui/proc-macro/expand-to-derive.stdout @@ -1,6 +1,6 @@ PRINT-DERIVE INPUT (DISPLAY): struct Foo { - field : + field: [bool; { #[rustc_dummy] struct Inner { other_inner_field: u8, } 0 }] } PRINT-DERIVE DEEP-RE-COLLECTED (DISPLAY): struct Foo diff --git a/tests/ui/proc-macro/expr-stmt-nonterminal-tokens.stdout b/tests/ui/proc-macro/expr-stmt-nonterminal-tokens.stdout index e11d2c0715cb3..6523f2485cd1f 100644 --- a/tests/ui/proc-macro/expr-stmt-nonterminal-tokens.stdout +++ b/tests/ui/proc-macro/expr-stmt-nonterminal-tokens.stdout @@ -1,5 +1,4 @@ -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)] #[allow(warnings)] 0; 0 }, } PRINT-DERIVE INPUT (DEBUG): TokenStream [ Ident { ident: "enum", @@ -122,8 +121,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ span: #3 bytes(308..357), }, ] -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 INPUT (DEBUG): TokenStream [ Ident { ident: "enum", @@ -280,8 +278,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ span: #11 bytes(432..485), }, ] -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 INPUT (DEBUG): TokenStream [ Ident { ident: "enum", @@ -358,8 +355,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ span: #15 bytes(432..485), }, ] -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 INPUT (DEBUG): TokenStream [ Ident { ident: "enum", @@ -449,8 +445,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ span: #19 bytes(432..485), }, ] -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 INPUT (DEBUG): TokenStream [ Ident { ident: "enum", diff --git a/tests/ui/proc-macro/issue-78675-captured-inner-attrs.stdout b/tests/ui/proc-macro/issue-78675-captured-inner-attrs.stdout index 37ecf3a8df331..346f87643c279 100644 --- a/tests/ui/proc-macro/issue-78675-captured-inner-attrs.stdout +++ b/tests/ui/proc-macro/issue-78675-captured-inner-attrs.stdout @@ -1,6 +1,4 @@ -PRINT-BANG INPUT (DISPLAY): foo! { #[fake_attr] mod bar { - #![doc = r" Foo"] -} } +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 INPUT (DEBUG): TokenStream [ Ident { diff --git a/tests/ui/proc-macro/macro-rules-derive-cfg.stdout b/tests/ui/proc-macro/macro-rules-derive-cfg.stdout index 257d59974b88d..4a3da7d2d19e6 100644 --- a/tests/ui/proc-macro/macro-rules-derive-cfg.stdout +++ b/tests/ui/proc-macro/macro-rules-derive-cfg.stdout @@ -1,6 +1,6 @@ PRINT-DERIVE INPUT (DISPLAY): struct Foo { - val : + val: [bool; { let a = #[rustc_dummy(first)] #[rustc_dummy(second)] diff --git a/tests/ui/proc-macro/pretty-print-hack-show.local.stdout b/tests/ui/proc-macro/pretty-print-hack-show.local.stdout index 3d793d2a0145c..eb15dab3cb6b3 100644 --- a/tests/ui/proc-macro/pretty-print-hack-show.local.stdout +++ b/tests/ui/proc-macro/pretty-print-hack-show.local.stdout @@ -1,5 +1,4 @@ -PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input, } -PRINT-DERIVE RE-COLLECTED (DISPLAY): enum ProceduralMasqueradeDummyType { Input } +PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input } PRINT-DERIVE INPUT (DEBUG): TokenStream [ Ident { ident: "enum", @@ -20,8 +19,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ span: $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:36: 14:2 (#0), }, ] -PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input, } -PRINT-DERIVE RE-COLLECTED (DISPLAY): enum ProceduralMasqueradeDummyType { Input } +PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input } PRINT-DERIVE INPUT (DEBUG): TokenStream [ Ident { ident: "enum", diff --git a/tests/ui/proc-macro/pretty-print-hack-show.remapped.stdout b/tests/ui/proc-macro/pretty-print-hack-show.remapped.stdout index 3d793d2a0145c..eb15dab3cb6b3 100644 --- a/tests/ui/proc-macro/pretty-print-hack-show.remapped.stdout +++ b/tests/ui/proc-macro/pretty-print-hack-show.remapped.stdout @@ -1,5 +1,4 @@ -PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input, } -PRINT-DERIVE RE-COLLECTED (DISPLAY): enum ProceduralMasqueradeDummyType { Input } +PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input } PRINT-DERIVE INPUT (DEBUG): TokenStream [ Ident { ident: "enum", @@ -20,8 +19,7 @@ PRINT-DERIVE INPUT (DEBUG): TokenStream [ span: $DIR/pretty-print-hack/allsorts-rental-0.5.6/src/lib.rs:4:36: 14:2 (#0), }, ] -PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input, } -PRINT-DERIVE RE-COLLECTED (DISPLAY): enum ProceduralMasqueradeDummyType { Input } +PRINT-DERIVE INPUT (DISPLAY): enum ProceduralMasqueradeDummyType { Input } PRINT-DERIVE INPUT (DEBUG): TokenStream [ Ident { ident: "enum",