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_expand/src/mbe/transcribe.rs b/compiler/rustc_expand/src/mbe/transcribe.rs index e35eba0f859b8..8b8ef0dc6e74a 100644 --- a/compiler/rustc_expand/src/mbe/transcribe.rs +++ b/compiler/rustc_expand/src/mbe/transcribe.rs @@ -318,6 +318,10 @@ pub(super) fn transcribe<'a>( mbe::TokenTree::Token(token) => { let mut token = token.clone(); mut_visit::visit_token(&mut token, &mut marker); + // njn: need spacing in mbe::TokenTree::Token + // njn: try changing other Alone/token_alone occurrences, see + // if any tests are affected + // - why do braces on `use` lines have a space after them? e.g. in stringify.rs let tt = TokenTree::Token(token, Spacing::Alone); result.push(tt); } 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/macros/issue-98790.rs b/tests/ui/macros/issue-98790.rs index b489efe9ce939..8b36e1710835f 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 must take care of this + //"pub fn repro() -> bool { (match () { () => true, }) | true }" + "pub fn repro() -> bool { match () { () => true } | true }" ); } diff --git a/tests/ui/macros/stringify.rs b/tests/ui/macros/stringify.rs index 6b215ba525deb..e50f37cf1fe9c 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,13 @@ 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: this is no longer testing AST pretty-printing, which is where the + // parens are inserted + 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 +654,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 +698,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 +724,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 +769,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_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..66d7b76bb0726 100644 --- a/tests/ui/macros/trace_faulty_macros.stderr +++ b/tests/ui/macros/trace_faulty_macros.stderr @@ -50,7 +50,7 @@ LL | my_recursive_macro!(); = note: expanding `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))}; @@ -96,7 +96,7 @@ 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 `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/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..a9a890b5cf153 100644 --- a/tests/ui/proc-macro/issue-78675-captured-inner-attrs.stdout +++ b/tests/ui/proc-macro/issue-78675-captured-inner-attrs.stdout @@ -1,7 +1,4 @@ -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 (DISPLAY): foo! { #[fake_attr] mod bar { #! [doc = r" Foo"] } } PRINT-BANG INPUT (DEBUG): TokenStream [ Ident { ident: "foo", 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",