diff --git a/compiler/rustc_ast/src/tokenstream.rs b/compiler/rustc_ast/src/tokenstream.rs index 4111182c3b7dc..055b32de45cbe 100644 --- a/compiler/rustc_ast/src/tokenstream.rs +++ b/compiler/rustc_ast/src/tokenstream.rs @@ -978,7 +978,54 @@ pub struct DelimSpan { impl DelimSpan { pub fn from_single(sp: Span) -> Self { - DelimSpan { open: sp, close: sp } + let default_open = sp.shrink_to_lo(); + let default_close = sp.shrink_to_hi(); + + let Some(sm) = rustc_span::source_map::get_source_map() else { + // No source map available. + return Self { open: default_open, close: default_close }; + }; + + let (open, close) = sm + .span_to_source(sp, |src, start, end| { + let Some(src) = src.get(start..end) else { + return Ok((default_close, default_close)); + }; + + // Only check the first and last characters. + // If there is white space or other characters + // other than `( ... )`, `[ ... ]`, and `{ ... }`. + // I assume that is intentionally included in this + // span so we don't want to shrink the span by + // searching for the delimiters, and setting + // the open and close spans to some more interior + // position. + let mut chars = src.chars(); + // just using '_' as a place holder. + let first = chars.next().unwrap_or('_'); + let last = chars.last().unwrap_or('_'); + + // Thought maybe scan through if first is '(', '[', or '{' + // and see if the last matches up e.g. make sure it's not some + // extra mismatched delimiter. + + let open = sp.subspan(0..first.len_utf8()).unwrap_or(default_open); + + let len = (sp.hi() - sp.lo()).0 as usize; + let pos = len.checked_sub(last.len_utf8()).unwrap_or(0); + let close = sp.subspan(pos..).unwrap_or(default_close); + + Ok(match (first, last) { + ('(', ')') | ('{', '}') | ('[', ']') => (open, close), + ('(', _) | ('{', _) | ('[', _) => (open, default_close), + (_, ')') | (_, '}') | (_, ']') => (default_open, close), + (_, _) => (default_close, default_open), + }) + }) + .ok() + .unwrap_or((default_open, default_close)); + + DelimSpan { open, close } } pub fn from_pair(open: Span, close: Span) -> Self { diff --git a/compiler/rustc_span/src/lib.rs b/compiler/rustc_span/src/lib.rs index 2e03ccb1aa1a3..72631f1050ee6 100644 --- a/compiler/rustc_span/src/lib.rs +++ b/compiler/rustc_span/src/lib.rs @@ -77,7 +77,7 @@ use std::cmp::{self, Ordering}; use std::fmt::Display; use std::hash::Hash; use std::io::{self, Read}; -use std::ops::{Add, Range, Sub}; +use std::ops::{Add, Bound, Range, RangeBounds, Sub}; use std::path::{Path, PathBuf}; use std::str::FromStr; use std::sync::Arc; @@ -1176,6 +1176,37 @@ impl Span { pub fn normalize_to_macro_rules(self) -> Span { self.map_ctxt(|ctxt| ctxt.normalize_to_macro_rules()) } + + /// This function is similar to `Span::from_inner`, but it + /// will return `None` if the relative Range span exceeds + /// the bounds of span. + pub fn subspan>(self, subspan: R) -> Option + where + u32: TryFrom, + { + let lo = self.lo().0; + let hi = self.hi().0; + + let start = match subspan.start_bound() { + Bound::Included(s) => u32::try_from(*s).ok()?, + Bound::Excluded(s) => u32::try_from(*s).ok()?.checked_add(1)?, + Bound::Unbounded => 0, + }; + + let end = match subspan.end_bound() { + Bound::Included(e) => u32::try_from(*e).ok()?.checked_add(1)?, + Bound::Excluded(e) => u32::try_from(*e).ok()?, + Bound::Unbounded => hi - lo, + }; + + let new_lo = lo.checked_add(start)?; + let new_hi = lo.checked_add(end)?; + if new_lo > hi || new_hi > hi { + return None; + } + + Some(self.with_lo(BytePos(new_lo)).with_hi(BytePos(new_hi))) + } } impl Default for Span { diff --git a/src/tools/clippy/tests/ui/uninhabited_references.stderr b/src/tools/clippy/tests/ui/uninhabited_references.stderr index ac05ab5bb4d40..120911cc94e4a 100644 --- a/src/tools/clippy/tests/ui/uninhabited_references.stderr +++ b/src/tools/clippy/tests/ui/uninhabited_references.stderr @@ -11,7 +11,7 @@ error: dereferencing a reference to an uninhabited type would be undefined behav --> tests/ui/uninhabited_references.rs:12:30 | LL | fn $name(x: &$ty) -> &$ty { - | ^^^^ + | ^ ... LL | ret_something!(id_never, !); | --------------------------- in this macro invocation diff --git a/tests/ui/attributes/nonterminal-expansion.stderr b/tests/ui/attributes/nonterminal-expansion.stderr index 21912de210610..c16c5257e442d 100644 --- a/tests/ui/attributes/nonterminal-expansion.stderr +++ b/tests/ui/attributes/nonterminal-expansion.stderr @@ -1,8 +1,8 @@ error: expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found `expr` metavariable - --> $DIR/nonterminal-expansion.rs:7:22 + --> $DIR/nonterminal-expansion.rs:7:24 | LL | #[repr(align($n))] - | ^^ + | ^ ... LL | pass_nonterminal!(n!()); | ----------------------- in this macro invocation diff --git a/tests/ui/borrowck/span-semicolon-issue-139049.stderr b/tests/ui/borrowck/span-semicolon-issue-139049.stderr index 8d2de67382bd8..0d800baf4a53f 100644 --- a/tests/ui/borrowck/span-semicolon-issue-139049.stderr +++ b/tests/ui/borrowck/span-semicolon-issue-139049.stderr @@ -2,7 +2,7 @@ error[E0597]: `l` does not live long enough --> $DIR/span-semicolon-issue-139049.rs:11:41 | LL | macro_rules! perform { ($e:expr) => { D(&$e).end() } } - | --^^^- + | --^--- | | | | | borrowed value does not live long enough | a temporary with access to the borrow is created here ... @@ -24,7 +24,7 @@ error[E0597]: `l` does not live long enough --> $DIR/span-semicolon-issue-139049.rs:11:41 | LL | macro_rules! perform { ($e:expr) => { D(&$e).end() } } - | --^^^- + | --^--- | | | | | borrowed value does not live long enough | a temporary with access to the borrow is created here ... diff --git a/tests/ui/closures/2229_closure_analysis/migrations/closure-body-macro-fragment.fixed b/tests/ui/closures/2229_closure_analysis/migrations/closure-body-macro-fragment.fixed deleted file mode 100644 index e9e16ce951b24..0000000000000 --- a/tests/ui/closures/2229_closure_analysis/migrations/closure-body-macro-fragment.fixed +++ /dev/null @@ -1,33 +0,0 @@ -//@ run-rustfix -//@ edition:2018 -//@ check-pass -#![warn(rust_2021_compatibility)] - -#[derive(Debug)] -struct Foo(i32); -impl Drop for Foo { - fn drop(&mut self) { - println!("{:?} dropped", self.0); - } -} - -macro_rules! m { - (@ $body:expr) => {{ - let f = || $body; - //~^ WARNING: drop order - f(); - }}; - ($body:block) => {{ - m!(@ $body); - }}; -} - -fn main() { - let a = (Foo(0), Foo(1)); - m!({ - let _ = &a; - //~^ HELP: add a dummy - let x = a.0; - println!("{:?}", x); - }); -} diff --git a/tests/ui/closures/2229_closure_analysis/migrations/closure-body-macro-fragment.rs b/tests/ui/closures/2229_closure_analysis/migrations/closure-body-macro-fragment.rs index 0cb5351f595e0..4ec17ca69e123 100644 --- a/tests/ui/closures/2229_closure_analysis/migrations/closure-body-macro-fragment.rs +++ b/tests/ui/closures/2229_closure_analysis/migrations/closure-body-macro-fragment.rs @@ -1,4 +1,3 @@ -//@ run-rustfix //@ edition:2018 //@ check-pass #![warn(rust_2021_compatibility)] @@ -25,7 +24,6 @@ macro_rules! m { fn main() { let a = (Foo(0), Foo(1)); m!({ - //~^ HELP: add a dummy let x = a.0; println!("{:?}", x); }); diff --git a/tests/ui/closures/2229_closure_analysis/migrations/closure-body-macro-fragment.stderr b/tests/ui/closures/2229_closure_analysis/migrations/closure-body-macro-fragment.stderr index c49b1d2d0e069..5bc5a0244e146 100644 --- a/tests/ui/closures/2229_closure_analysis/migrations/closure-body-macro-fragment.stderr +++ b/tests/ui/closures/2229_closure_analysis/migrations/closure-body-macro-fragment.stderr @@ -1,5 +1,5 @@ warning: changes to closure capture in Rust 2021 will affect drop order - --> $DIR/closure-body-macro-fragment.rs:16:17 + --> $DIR/closure-body-macro-fragment.rs:15:17 | LL | let f = || $body; | ^^ @@ -8,7 +8,6 @@ LL | }}; | - in Rust 2018, `a` is dropped here, but in Rust 2021, only `a.0` will be dropped here as part of the closure ... LL | / m!({ -LL | | LL | | let x = a.0; | | --- in Rust 2018, this closure captures all of `a`, but in Rust 2021, it will only capture `a.0` LL | | println!("{:?}", x); @@ -17,7 +16,7 @@ LL | | }); | = note: for more information, see note: the lint level is defined here - --> $DIR/closure-body-macro-fragment.rs:4:9 + --> $DIR/closure-body-macro-fragment.rs:3:9 | LL | #![warn(rust_2021_compatibility)] | ^^^^^^^^^^^^^^^^^^^^^^^ @@ -25,9 +24,8 @@ LL | #![warn(rust_2021_compatibility)] = note: this warning originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) help: add a dummy let to cause `a` to be fully captured | -LL ~ m!({ -LL + let _ = &a; - | +LL | m!(@ $body{ let _ = &a; }); + | +++++++++++++ + warning: 1 warning emitted diff --git a/tests/ui/conditional-compilation/cfg-attr-syntax-validation.stderr b/tests/ui/conditional-compilation/cfg-attr-syntax-validation.stderr index e73b20f2d5d31..0061be11d47bb 100644 --- a/tests/ui/conditional-compilation/cfg-attr-syntax-validation.stderr +++ b/tests/ui/conditional-compilation/cfg-attr-syntax-validation.stderr @@ -92,10 +92,10 @@ LL | #[cfg(a = b"hi")] = note: expected a normal string literal, not a byte string literal error: expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found `expr` metavariable - --> $DIR/cfg-attr-syntax-validation.rs:51:25 + --> $DIR/cfg-attr-syntax-validation.rs:51:30 | LL | #[cfg(feature = $expr)] - | ^^^^^ + | ^ ... LL | generate_s10!(concat!("nonexistent")); | ------------------------------------- in this macro invocation diff --git a/tests/ui/conditional-compilation/cfg_attr-attr-syntax-validation.stderr b/tests/ui/conditional-compilation/cfg_attr-attr-syntax-validation.stderr index fd03fa62864af..e8d55ba56a13a 100644 --- a/tests/ui/conditional-compilation/cfg_attr-attr-syntax-validation.stderr +++ b/tests/ui/conditional-compilation/cfg_attr-attr-syntax-validation.stderr @@ -92,10 +92,10 @@ LL | #[cfg_attr(true)] = note: for more information, visit error: expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found `expr` metavariable - --> $DIR/cfg_attr-attr-syntax-validation.rs:30:30 + --> $DIR/cfg_attr-attr-syntax-validation.rs:30:35 | LL | #[cfg_attr(feature = $expr)] - | ---------------------^^^^^-- help: must be of the form: `#[cfg_attr(predicate, attr1, attr2, ...)]` + | --------------------------^- help: must be of the form: `#[cfg_attr(predicate, attr1, attr2, ...)]` ... LL | generate_s10!(concat!("nonexistent")); | ------------------------------------- in this macro invocation diff --git a/tests/ui/did_you_mean/bad-assoc-expr.stderr b/tests/ui/did_you_mean/bad-assoc-expr.stderr index b83078e21b6a1..5f9e85d557c74 100644 --- a/tests/ui/did_you_mean/bad-assoc-expr.stderr +++ b/tests/ui/did_you_mean/bad-assoc-expr.stderr @@ -90,7 +90,7 @@ error: missing angle brackets in associated item path --> $DIR/bad-assoc-expr.rs:23:19 | LL | ($ty: ty) => ($ty::clone(&0)) - | ^^^ + | ^ ... LL | expr!(u8); | --------- in this macro invocation @@ -98,8 +98,8 @@ LL | expr!(u8); = note: this error originates in the macro `expr` (in Nightly builds, run with -Z macro-backtrace for more info) help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths | -LL | ($ty: ty) => (<$ty>::clone(&0)) - | + + +LL | ($ty: ty) => (<>$ty::clone(&0)) + | ++ error: aborting due to 9 previous errors diff --git a/tests/ui/did_you_mean/bad-assoc-pat.stderr b/tests/ui/did_you_mean/bad-assoc-pat.stderr index 8bdeb8ffdd0a8..6e29eca04d639 100644 --- a/tests/ui/did_you_mean/bad-assoc-pat.stderr +++ b/tests/ui/did_you_mean/bad-assoc-pat.stderr @@ -57,7 +57,7 @@ error: missing angle brackets in associated item path --> $DIR/bad-assoc-pat.rs:21:19 | LL | ($ty: ty) => ($ty::AssocItem) - | ^^^ + | ^ ... LL | pat!(u8) => {} | -------- in this macro invocation @@ -65,8 +65,8 @@ LL | pat!(u8) => {} = note: this error originates in the macro `pat` (in Nightly builds, run with -Z macro-backtrace for more info) help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths | -LL | ($ty: ty) => (<$ty>::AssocItem) - | + + +LL | ($ty: ty) => (<>$ty::AssocItem) + | ++ error[E0599]: no associated item named `AssocItem` found for slice `[u8]` in the current scope --> $DIR/bad-assoc-pat.rs:3:15 diff --git a/tests/ui/did_you_mean/bad-assoc-ty.edition2015.stderr b/tests/ui/did_you_mean/bad-assoc-ty.edition2015.stderr index af0a9d064d571..b68b24ad220c5 100644 --- a/tests/ui/did_you_mean/bad-assoc-ty.edition2015.stderr +++ b/tests/ui/did_you_mean/bad-assoc-ty.edition2015.stderr @@ -90,7 +90,7 @@ error: missing angle brackets in associated item path --> $DIR/bad-assoc-ty.rs:44:19 | LL | ($ty: ty) => ($ty::AssocTy); - | ^^^ + | ^ ... LL | type J = ty!(u8); | ------- in this macro invocation @@ -98,8 +98,8 @@ LL | type J = ty!(u8); = note: this error originates in the macro `ty` (in Nightly builds, run with -Z macro-backtrace for more info) help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths | -LL | ($ty: ty) => (<$ty>::AssocTy); - | + + +LL | ($ty: ty) => (<>$ty::AssocTy); + | ++ error[E0223]: ambiguous associated type --> $DIR/bad-assoc-ty.rs:5:10 diff --git a/tests/ui/did_you_mean/bad-assoc-ty.edition2021.stderr b/tests/ui/did_you_mean/bad-assoc-ty.edition2021.stderr index 2ee8ab2760a92..c88a16a72894d 100644 --- a/tests/ui/did_you_mean/bad-assoc-ty.edition2021.stderr +++ b/tests/ui/did_you_mean/bad-assoc-ty.edition2021.stderr @@ -90,7 +90,7 @@ error: missing angle brackets in associated item path --> $DIR/bad-assoc-ty.rs:44:19 | LL | ($ty: ty) => ($ty::AssocTy); - | ^^^ + | ^ ... LL | type J = ty!(u8); | ------- in this macro invocation @@ -98,8 +98,8 @@ LL | type J = ty!(u8); = note: this error originates in the macro `ty` (in Nightly builds, run with -Z macro-backtrace for more info) help: types that don't start with an identifier need to be surrounded with angle brackets in qualified paths | -LL | ($ty: ty) => (<$ty>::AssocTy); - | + + +LL | ($ty: ty) => (<>$ty::AssocTy); + | ++ error[E0223]: ambiguous associated type --> $DIR/bad-assoc-ty.rs:5:10 diff --git a/tests/ui/half-open-range-patterns/half-open-range-pats-inclusive-dotdotdot-bad-syntax.stderr b/tests/ui/half-open-range-patterns/half-open-range-pats-inclusive-dotdotdot-bad-syntax.stderr index ec0e09a302ea1..85daf49016edf 100644 --- a/tests/ui/half-open-range-patterns/half-open-range-pats-inclusive-dotdotdot-bad-syntax.stderr +++ b/tests/ui/half-open-range-patterns/half-open-range-pats-inclusive-dotdotdot-bad-syntax.stderr @@ -66,7 +66,7 @@ error[E0005]: refutable pattern in local binding --> $DIR/half-open-range-pats-inclusive-dotdotdot-bad-syntax.rs:25:17 | LL | let ...$e; - | ^^^^^ pattern `1_i32..=i32::MAX` not covered + | ^^^ pattern `1_i32..=i32::MAX` not covered ... LL | mac!(0); | ------- in this macro invocation diff --git a/tests/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.stderr b/tests/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.stderr index 63258f3538313..956ef9fccba1a 100644 --- a/tests/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.stderr +++ b/tests/ui/half-open-range-patterns/half-open-range-pats-inclusive-no-end.stderr @@ -85,10 +85,10 @@ LL + let $e..; | error[E0005]: refutable pattern in local binding - --> $DIR/half-open-range-pats-inclusive-no-end.rs:18:17 + --> $DIR/half-open-range-pats-inclusive-no-end.rs:18:19 | LL | let $e...; - | ^^^^^ pattern `i32::MIN..=-1_i32` not covered + | ^^^ pattern `i32::MIN..=-1_i32` not covered ... LL | mac!(0); | ------- in this macro invocation @@ -99,10 +99,10 @@ LL | mac!(0); = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0005]: refutable pattern in local binding - --> $DIR/half-open-range-pats-inclusive-no-end.rs:20:17 + --> $DIR/half-open-range-pats-inclusive-no-end.rs:20:19 | LL | let $e..=; - | ^^^^^ pattern `i32::MIN..=-1_i32` not covered + | ^^^ pattern `i32::MIN..=-1_i32` not covered ... LL | mac!(0); | ------- in this macro invocation diff --git a/tests/ui/imports/import-prefix-macro-2.stderr b/tests/ui/imports/import-prefix-macro-2.stderr index fbeca99b13800..fb682e9268564 100644 --- a/tests/ui/imports/import-prefix-macro-2.stderr +++ b/tests/ui/imports/import-prefix-macro-2.stderr @@ -1,8 +1,8 @@ error: expected identifier, found metavariable - --> $DIR/import-prefix-macro-2.rs:11:26 + --> $DIR/import-prefix-macro-2.rs:11:28 | LL | ($p: path) => (use ::$p {S, Z}); - | ^^ expected identifier, found metavariable + | ^ expected identifier, found metavariable ... LL | import! { a::b::c } | ------------------- in this macro invocation diff --git a/tests/ui/lint/lint-double-negations-macro.stderr b/tests/ui/lint/lint-double-negations-macro.stderr index d6ac9be48f304..a8fc0850e21e9 100644 --- a/tests/ui/lint/lint-double-negations-macro.stderr +++ b/tests/ui/lint/lint-double-negations-macro.stderr @@ -2,7 +2,7 @@ warning: use of a double negation --> $DIR/lint-double-negations-macro.rs:9:9 | LL | --$e - | ^^^^ + | ^^ ... LL | bad_macro!(1); | ------------- in this macro invocation @@ -13,8 +13,8 @@ LL | bad_macro!(1); = note: this warning originates in the macro `bad_macro` (in Nightly builds, run with -Z macro-backtrace for more info) help: add parentheses for clarity | -LL | -(-$e) - | + + +LL | -(-)$e + | + + warning: 1 warning emitted diff --git a/tests/ui/lint/unreachable_pub.stderr b/tests/ui/lint/unreachable_pub.stderr index 5173ff1f0264d..30d696816624b 100644 --- a/tests/ui/lint/unreachable_pub.stderr +++ b/tests/ui/lint/unreachable_pub.stderr @@ -112,10 +112,10 @@ LL | pub type Oxygen = bool; = help: or consider exporting it for use by other crates warning: unreachable `pub` item - --> $DIR/unreachable_pub.rs:44:47 + --> $DIR/unreachable_pub.rs:44:58 | LL | ($visibility: vis, $name: ident) => { $visibility struct $name {} } - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^^^^ ... LL | define_empty_struct_with_visibility!(pub, Fluorine); | --------------------------------------------------- diff --git a/tests/ui/macros/issue-29084.stderr b/tests/ui/macros/issue-29084.stderr index 6e7474c5b3f74..b7faedae5f249 100644 --- a/tests/ui/macros/issue-29084.stderr +++ b/tests/ui/macros/issue-29084.stderr @@ -2,7 +2,7 @@ error[E0308]: mismatched types --> $DIR/issue-29084.rs:6:13 | LL | bar(&mut $d); - | --- ^^^^^^^ expected `u8`, found `&mut u8` + | --- ^^^^^ expected `u8`, found `&mut u8` | | | arguments to this function are incorrect ... diff --git a/tests/ui/macros/macro-interpolation.stderr b/tests/ui/macros/macro-interpolation.stderr index bc24a15861295..f4164555906ee 100644 --- a/tests/ui/macros/macro-interpolation.stderr +++ b/tests/ui/macros/macro-interpolation.stderr @@ -1,8 +1,8 @@ error: expected identifier, found metavariable - --> $DIR/macro-interpolation.rs:21:19 + --> $DIR/macro-interpolation.rs:21:25 | LL | <$type as $trait>::$name - | ^^^^^^ expected identifier, found metavariable + | ^ expected identifier, found metavariable ... LL | let _: qpath!(ty, ::Owned); | ----------------------------- diff --git a/tests/ui/macros/nonterminal-matching.stderr b/tests/ui/macros/nonterminal-matching.stderr index d01561415664c..cb24b046f0ec0 100644 --- a/tests/ui/macros/nonterminal-matching.stderr +++ b/tests/ui/macros/nonterminal-matching.stderr @@ -1,20 +1,20 @@ error: no rules expected `item` metavariable - --> $DIR/nonterminal-matching.rs:19:10 + --> $DIR/nonterminal-matching.rs:19:18 | LL | macro n(a $nt_item b) { | --------------------- when calling this macro ... LL | n!(a $nt_item b); - | ^^^^^^^^ no rules expected this token in macro call + | ^ no rules expected this token in macro call ... LL | complex_nonterminal!(enum E {}); | ------------------------------- in this macro invocation | note: while trying to match `item` metavariable - --> $DIR/nonterminal-matching.rs:15:15 + --> $DIR/nonterminal-matching.rs:15:23 | LL | macro n(a $nt_item b) { - | ^^^^^^^^ + | ^ ... LL | complex_nonterminal!(enum E {}); | ------------------------------- in this macro invocation @@ -24,10 +24,10 @@ LL | complex_nonterminal!(enum E {}); = note: this error originates in the macro `complex_nonterminal` (in Nightly builds, run with -Z macro-backtrace for more info) error: no rules expected `expr` metavariable - --> $DIR/nonterminal-matching.rs:32:35 + --> $DIR/nonterminal-matching.rs:32:37 | LL | (expr $x:expr) => { bar!(expr $x); }; - | ^^ no rules expected this token in macro call + | ^ no rules expected this token in macro call ... LL | macro_rules! bar { | ---------------- when calling this macro @@ -46,10 +46,10 @@ LL | (expr 3) => {}; = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) error: no rules expected `literal` metavariable - --> $DIR/nonterminal-matching.rs:33:44 + --> $DIR/nonterminal-matching.rs:33:46 | LL | (literal $x:literal) => { bar!(literal $x); }; - | ^^ no rules expected this token in macro call + | ^ no rules expected this token in macro call ... LL | macro_rules! bar { | ---------------- when calling this macro @@ -68,10 +68,10 @@ LL | (literal 4) => {}; = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) error: no rules expected `path` metavariable - --> $DIR/nonterminal-matching.rs:34:35 + --> $DIR/nonterminal-matching.rs:34:37 | LL | (path $x:path) => { bar!(path $x); }; - | ^^ no rules expected this token in macro call + | ^ no rules expected this token in macro call ... LL | macro_rules! bar { | ---------------- when calling this macro @@ -90,10 +90,10 @@ LL | (path a::b::c) => {}; = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) error: no rules expected `stmt` metavariable - --> $DIR/nonterminal-matching.rs:35:35 + --> $DIR/nonterminal-matching.rs:35:37 | LL | (stmt $x:stmt) => { bar!(stmt $x); }; - | ^^ no rules expected this token in macro call + | ^ no rules expected this token in macro call ... LL | macro_rules! bar { | ---------------- when calling this macro diff --git a/tests/ui/macros/syntax-error-recovery.stderr b/tests/ui/macros/syntax-error-recovery.stderr index a2059aa1aa802..869a050eb8775 100644 --- a/tests/ui/macros/syntax-error-recovery.stderr +++ b/tests/ui/macros/syntax-error-recovery.stderr @@ -1,8 +1,8 @@ error: expected one of `(`, `,`, `=`, `{`, or `}`, found `ty` metavariable - --> $DIR/syntax-error-recovery.rs:7:26 + --> $DIR/syntax-error-recovery.rs:7:32 | LL | $token $($inner)? = $value, - | ^^^^^^ expected one of `(`, `,`, `=`, `{`, or `}` + | ^ expected one of `(`, `,`, `=`, `{`, or `}` ... LL | values!(STRING(1) as (String) => cfg(test),); | -------------------------------------------- in this macro invocation @@ -11,10 +11,10 @@ LL | values!(STRING(1) as (String) => cfg(test),); = note: this error originates in the macro `values` (in Nightly builds, run with -Z macro-backtrace for more info) error: macro expansion ignores `ty` metavariable and any tokens following - --> $DIR/syntax-error-recovery.rs:7:26 + --> $DIR/syntax-error-recovery.rs:7:32 | LL | $token $($inner)? = $value, - | ^^^^^^ + | ^ ... LL | values!(STRING(1) as (String) => cfg(test),); | -------------------------------------------- caused by the macro expansion here diff --git a/tests/ui/macros/trace_faulty_macros.stderr b/tests/ui/macros/trace_faulty_macros.stderr index e90d7a98db4c7..c459c6743612b 100644 --- a/tests/ui/macros/trace_faulty_macros.stderr +++ b/tests/ui/macros/trace_faulty_macros.stderr @@ -51,10 +51,10 @@ LL | my_recursive_macro!(); = note: to `my_recursive_macro! ();` error: expected expression, found `pat` metavariable - --> $DIR/trace_faulty_macros.rs:16:9 + --> $DIR/trace_faulty_macros.rs:16:11 | LL | $a - | ^^ expected expression + | ^ expected expression ... LL | let a = pat_macro!(); | ------------ in this macro invocation @@ -70,10 +70,10 @@ LL | fn use_derive_macro_as_attr() {} | -------------------------------- not a `struct`, `enum` or `union` error: expected expression, found `pat` metavariable - --> $DIR/trace_faulty_macros.rs:49:37 + --> $DIR/trace_faulty_macros.rs:49:39 | LL | (($p:pat, $e:pat)) => {let $p = $e;}; - | ^^ expected expression + | ^ expected expression ... LL | test!(let x = 1+1); | ------------------ in this macro invocation diff --git a/tests/ui/parser/attribute/attr-bad-meta-4.stderr b/tests/ui/parser/attribute/attr-bad-meta-4.stderr index 1d939942fb9a9..50d1d890c39c6 100644 --- a/tests/ui/parser/attribute/attr-bad-meta-4.stderr +++ b/tests/ui/parser/attribute/attr-bad-meta-4.stderr @@ -11,10 +11,10 @@ LL + #[cfg(feature = 1)] | error: expected a literal (`1u8`, `1.0f32`, `"string"`, etc.) here, found `meta` metavariable - --> $DIR/attr-bad-meta-4.rs:3:15 + --> $DIR/attr-bad-meta-4.rs:3:25 | LL | #[cfg($attr_item)] - | ^^^^^^^^^^ + | ^ ... LL | mac!(an(arbitrary token stream)); | -------------------------------- in this macro invocation diff --git a/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body-2.stderr b/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body-2.stderr index 41e7b5ab759dd..ba2ebef3e5758 100644 --- a/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body-2.stderr +++ b/tests/ui/parser/attribute/properly-recover-from-trailing-outer-attribute-in-body-2.stderr @@ -1,10 +1,10 @@ error: expected `;`, found `#` - --> $DIR/properly-recover-from-trailing-outer-attribute-in-body-2.rs:6:13 + --> $DIR/properly-recover-from-trailing-outer-attribute-in-body-2.rs:6:9 | LL | #[cfg()] | -------- only `;` terminated statements or tail expressions are allowed after this attribute LL | $foo - | ^ expected `;` here + | ^ expected `;` here LL | LL | #[cfg(false)] | - unexpected token @@ -15,8 +15,8 @@ LL | the_macro!( (); (); ); = note: this error originates in the macro `the_macro` (in Nightly builds, run with -Z macro-backtrace for more info) help: add `;` here | -LL | $foo; - | + +LL | ;$foo + | + help: alternatively, consider surrounding the expression with a block | LL | the_macro!( { () }; (); ); diff --git a/tests/ui/parser/bad-interpolated-block.stderr b/tests/ui/parser/bad-interpolated-block.stderr index 651036c51c948..a9b323395cd12 100644 --- a/tests/ui/parser/bad-interpolated-block.stderr +++ b/tests/ui/parser/bad-interpolated-block.stderr @@ -1,8 +1,8 @@ error: cannot use a `block` macro fragment here - --> $DIR/bad-interpolated-block.rs:5:15 + --> $DIR/bad-interpolated-block.rs:5:17 | LL | 'lab: $b; - | ------^^ + | --------^ | | | the `block` fragment is within this context ... @@ -12,14 +12,14 @@ LL | m!({}); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) help: wrap this in another block | -LL | 'lab: { $b }; - | + + +LL | 'lab: $b{ }; + | + + error: cannot use a `block` macro fragment here - --> $DIR/bad-interpolated-block.rs:6:16 + --> $DIR/bad-interpolated-block.rs:6:18 | LL | unsafe $b; - | -------^^ + | ---------^ | | | the `block` fragment is within this context ... @@ -29,14 +29,14 @@ LL | m!({}); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) help: wrap this in another block | -LL | unsafe { $b }; - | + + +LL | unsafe $b{ }; + | + + error: cannot use a `block` macro fragment here - --> $DIR/bad-interpolated-block.rs:7:23 + --> $DIR/bad-interpolated-block.rs:7:25 | LL | |x: u8| -> () $b; - | ^^ the `block` fragment is within this context + | ^ the `block` fragment is within this context ... LL | m!({}); | ------ in this macro invocation @@ -44,8 +44,8 @@ LL | m!({}); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) help: wrap this in another block | -LL | |x: u8| -> () { $b }; - | + + +LL | |x: u8| -> () $b{ }; + | + + error: aborting due to 3 previous errors diff --git a/tests/ui/parser/float-field-interpolated.stderr b/tests/ui/parser/float-field-interpolated.stderr index e2b7e3a7dbe75..0b403f2aac94d 100644 --- a/tests/ui/parser/float-field-interpolated.stderr +++ b/tests/ui/parser/float-field-interpolated.stderr @@ -1,8 +1,8 @@ error: unexpected token: `literal` metavariable - --> $DIR/float-field-interpolated.rs:8:13 + --> $DIR/float-field-interpolated.rs:8:15 | LL | { s.$b; } - | ^^ + | ^ ... LL | generate_field_accesses!(1.1, 1.1, 1.1); | --------------------------------------- in this macro invocation @@ -10,10 +10,10 @@ LL | generate_field_accesses!(1.1, 1.1, 1.1); = note: this error originates in the macro `generate_field_accesses` (in Nightly builds, run with -Z macro-backtrace for more info) error: expected one of `.`, `;`, `?`, `}`, or an operator, found `literal` metavariable - --> $DIR/float-field-interpolated.rs:8:13 + --> $DIR/float-field-interpolated.rs:8:15 | LL | { s.$b; } - | ^^ expected one of `.`, `;`, `?`, `}`, or an operator + | ^ expected one of `.`, `;`, `?`, `}`, or an operator ... LL | generate_field_accesses!(1.1, 1.1, 1.1); | --------------------------------------- in this macro invocation @@ -21,10 +21,10 @@ LL | generate_field_accesses!(1.1, 1.1, 1.1); = note: this error originates in the macro `generate_field_accesses` (in Nightly builds, run with -Z macro-backtrace for more info) error: unexpected token: `expr` metavariable - --> $DIR/float-field-interpolated.rs:10:13 + --> $DIR/float-field-interpolated.rs:10:15 | LL | { s.$c; } - | ^^ + | ^ ... LL | generate_field_accesses!(1.1, 1.1, 1.1); | --------------------------------------- in this macro invocation @@ -32,10 +32,10 @@ LL | generate_field_accesses!(1.1, 1.1, 1.1); = note: this error originates in the macro `generate_field_accesses` (in Nightly builds, run with -Z macro-backtrace for more info) error: expected one of `.`, `;`, `?`, `}`, or an operator, found `expr` metavariable - --> $DIR/float-field-interpolated.rs:10:13 + --> $DIR/float-field-interpolated.rs:10:15 | LL | { s.$c; } - | ^^ expected one of `.`, `;`, `?`, `}`, or an operator + | ^ expected one of `.`, `;`, `?`, `}`, or an operator ... LL | generate_field_accesses!(1.1, 1.1, 1.1); | --------------------------------------- in this macro invocation diff --git a/tests/ui/parser/issues/issue-65122-mac-invoc-in-mut-patterns.stderr b/tests/ui/parser/issues/issue-65122-mac-invoc-in-mut-patterns.stderr index 59e1b64686b46..5501ff584bb54 100644 --- a/tests/ui/parser/issues/issue-65122-mac-invoc-in-mut-patterns.stderr +++ b/tests/ui/parser/issues/issue-65122-mac-invoc-in-mut-patterns.stderr @@ -16,10 +16,10 @@ LL + let $eval = (); | error: expected identifier, found metavariable - --> $DIR/issue-65122-mac-invoc-in-mut-patterns.rs:13:17 + --> $DIR/issue-65122-mac-invoc-in-mut-patterns.rs:13:22 | LL | let mut $eval = (); - | ^^^^^ expected identifier, found metavariable + | ^ expected identifier, found metavariable ... LL | mac2! { does_not_exist!() } | --------------------------- in this macro invocation diff --git a/tests/ui/parser/issues/issue-87812-path.stderr b/tests/ui/parser/issues/issue-87812-path.stderr index fbe26ea39595a..2fe205e30171a 100644 --- a/tests/ui/parser/issues/issue-87812-path.stderr +++ b/tests/ui/parser/issues/issue-87812-path.stderr @@ -1,8 +1,8 @@ error[E0308]: mismatched types - --> $DIR/issue-87812-path.rs:3:24 + --> $DIR/issue-87812-path.rs:3:26 | LL | let _: usize = $f; - | ----- ^^ expected `usize`, found `Baz` + | ----- ^ expected `usize`, found `Baz` | | | expected due to this ... diff --git a/tests/ui/parser/issues/issue-87812.stderr b/tests/ui/parser/issues/issue-87812.stderr index 35dc66a528a99..362116730f087 100644 --- a/tests/ui/parser/issues/issue-87812.stderr +++ b/tests/ui/parser/issues/issue-87812.stderr @@ -15,8 +15,8 @@ LL | #![deny(break_with_label_and_loop)] = note: this error originates in the macro `foo` (in Nightly builds, run with -Z macro-backtrace for more info) help: wrap this expression in parentheses | -LL | break '_l ($f); - | + + +LL | break '_l $f(); + | ++ error: aborting due to 1 previous error diff --git a/tests/ui/parser/labeled-no-colon-expr.stderr b/tests/ui/parser/labeled-no-colon-expr.stderr index 2478319281569..4f8d1f69636a0 100644 --- a/tests/ui/parser/labeled-no-colon-expr.stderr +++ b/tests/ui/parser/labeled-no-colon-expr.stderr @@ -81,10 +81,10 @@ LL | 'l4: 0; | + error: cannot use a `block` macro fragment here - --> $DIR/labeled-no-colon-expr.rs:11:17 + --> $DIR/labeled-no-colon-expr.rs:11:19 | LL | 'l5 $b; - | ----^^ + | ------^ | | | the `block` fragment is within this context ... @@ -94,8 +94,8 @@ LL | m!({}); = note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info) help: wrap this in another block | -LL | 'l5 { $b }; - | + + +LL | 'l5 $b{ }; + | + + error: labeled expression must be followed by `:` --> $DIR/labeled-no-colon-expr.rs:14:8 @@ -109,8 +109,9 @@ LL | m!({}); = note: labels are used before loops and blocks, allowing e.g., `break 'label` to them help: add `:` after the label | -LL | 'l5: $b; - | + +LL - 'l5 $b; +LL + 'l5: ; + | error: aborting due to 8 previous errors diff --git a/tests/ui/parser/macro/break-in-unlabeled-block-in-macro.stderr b/tests/ui/parser/macro/break-in-unlabeled-block-in-macro.stderr index 2f46cb36750be..72e97514350b6 100644 --- a/tests/ui/parser/macro/break-in-unlabeled-block-in-macro.stderr +++ b/tests/ui/parser/macro/break-in-unlabeled-block-in-macro.stderr @@ -13,7 +13,7 @@ error[E0268]: `break` outside of a loop or labeled block --> $DIR/break-in-unlabeled-block-in-macro.rs:6:9 | LL | break $e; - | ^^^^^^^^ cannot `break` outside of a loop or labeled block + | ^^^^^^ cannot `break` outside of a loop or labeled block ... LL | foo!(()); | -------- in this macro invocation @@ -41,7 +41,7 @@ error[E0268]: `break` outside of a loop or labeled block --> $DIR/break-in-unlabeled-block-in-macro.rs:12:11 | LL | { break $e; } - | ^^^^^^^^ cannot `break` outside of a loop or labeled block + | ^^^^^^ cannot `break` outside of a loop or labeled block ... LL | foo!(@ ()); | ---------- in this macro invocation diff --git a/tests/ui/parser/macro/issue-37113.stderr b/tests/ui/parser/macro/issue-37113.stderr index 560329df5ccbd..e073d55f23bd7 100644 --- a/tests/ui/parser/macro/issue-37113.stderr +++ b/tests/ui/parser/macro/issue-37113.stderr @@ -1,10 +1,10 @@ error: expected identifier, found metavariable - --> $DIR/issue-37113.rs:4:16 + --> $DIR/issue-37113.rs:4:18 | LL | enum SomeEnum { | -------- while parsing this enum LL | $( $t, )* - | ^^ expected identifier, found metavariable + | ^ expected identifier, found metavariable ... LL | test_macro!(String,); | -------------------- in this macro invocation diff --git a/tests/ui/parser/macro/macro-doc-comments-2.stderr b/tests/ui/parser/macro/macro-doc-comments-2.stderr index 02c12bf959114..f29fab1e8800d 100644 --- a/tests/ui/parser/macro/macro-doc-comments-2.stderr +++ b/tests/ui/parser/macro/macro-doc-comments-2.stderr @@ -1,14 +1,11 @@ error: no rules expected `[` - --> $DIR/macro-doc-comments-2.rs:6:5 + --> $DIR/macro-doc-comments-2.rs:6:14 | LL | macro_rules! inner { | ------------------ when calling this macro ... LL | /// Outer - | ^^^^^^^^^ - | | - | no rules expected this token in macro call - | outer doc comments expand to `#[doc = "..."]`, which is what this macro attempted to match + | ^ no rules expected this token in macro call | note: while trying to match `!` --> $DIR/macro-doc-comments-2.rs:2:7 diff --git a/tests/ui/parser/macro/trait-non-item-macros.stderr b/tests/ui/parser/macro/trait-non-item-macros.stderr index 62b42fa8b8dd7..3b5e694c2ab56 100644 --- a/tests/ui/parser/macro/trait-non-item-macros.stderr +++ b/tests/ui/parser/macro/trait-non-item-macros.stderr @@ -1,8 +1,8 @@ error: macro expansion ignores `expr` metavariable and any tokens following - --> $DIR/trait-non-item-macros.rs:3:9 + --> $DIR/trait-non-item-macros.rs:3:11 | LL | $a - | ^^ + | ^ ... LL | bah!(2); | ------- caused by the macro expansion here diff --git a/tests/ui/parser/mut-patterns.stderr b/tests/ui/parser/mut-patterns.stderr index 70099989c9ff0..29ba6e3336e23 100644 --- a/tests/ui/parser/mut-patterns.stderr +++ b/tests/ui/parser/mut-patterns.stderr @@ -159,10 +159,10 @@ LL + let W(mut a, W(mut b, W(ref c, W(mut d, B { box mut f })))) | error: expected identifier, found metavariable - --> $DIR/mut-patterns.rs:49:21 + --> $DIR/mut-patterns.rs:49:23 | LL | let mut $p = 0; - | ^^ expected identifier, found metavariable + | ^ expected identifier, found metavariable ... LL | foo!(x); | ------- in this macro invocation diff --git a/tests/ui/parser/recover/recover-range-pats.stderr b/tests/ui/parser/recover/recover-range-pats.stderr index 1570475a0989b..7e0dd1c8979d0 100644 --- a/tests/ui/parser/recover/recover-range-pats.stderr +++ b/tests/ui/parser/recover/recover-range-pats.stderr @@ -609,10 +609,10 @@ LL | if let ....3 = 0 {} | expected integer, found floating-point number error[E0005]: refutable pattern in local binding - --> $DIR/recover-range-pats.rs:135:17 + --> $DIR/recover-range-pats.rs:135:20 | LL | let $e1..$e2; - | ^^^^^^^^ patterns `i32::MIN..=-1_i32` and `1_i32..=i32::MAX` not covered + | ^^ patterns `i32::MIN..=-1_i32` and `1_i32..=i32::MAX` not covered ... LL | mac2!(0, 1); | ----------- in this macro invocation @@ -623,10 +623,10 @@ LL | mac2!(0, 1); = note: this error originates in the macro `mac2` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0005]: refutable pattern in local binding - --> $DIR/recover-range-pats.rs:137:17 + --> $DIR/recover-range-pats.rs:137:20 | LL | let $e1...$e2; - | ^^^^^^^^^ patterns `i32::MIN..=-1_i32` and `2_i32..=i32::MAX` not covered + | ^^^ patterns `i32::MIN..=-1_i32` and `2_i32..=i32::MAX` not covered ... LL | mac2!(0, 1); | ----------- in this macro invocation @@ -637,10 +637,10 @@ LL | mac2!(0, 1); = note: this error originates in the macro `mac2` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0005]: refutable pattern in local binding - --> $DIR/recover-range-pats.rs:141:17 + --> $DIR/recover-range-pats.rs:141:20 | LL | let $e1..=$e2; - | ^^^^^^^^^ patterns `i32::MIN..=-1_i32` and `2_i32..=i32::MAX` not covered + | ^^^ patterns `i32::MIN..=-1_i32` and `2_i32..=i32::MAX` not covered ... LL | mac2!(0, 1); | ----------- in this macro invocation @@ -654,7 +654,7 @@ error[E0005]: refutable pattern in local binding --> $DIR/recover-range-pats.rs:150:17 | LL | let ..$e; - | ^^^^ pattern `0_i32..=i32::MAX` not covered + | ^^ pattern `0_i32..=i32::MAX` not covered ... LL | mac!(0); | ------- in this macro invocation @@ -668,7 +668,7 @@ error[E0005]: refutable pattern in local binding --> $DIR/recover-range-pats.rs:152:17 | LL | let ...$e; - | ^^^^^ pattern `1_i32..=i32::MAX` not covered + | ^^^ pattern `1_i32..=i32::MAX` not covered ... LL | mac!(0); | ------- in this macro invocation @@ -682,7 +682,7 @@ error[E0005]: refutable pattern in local binding --> $DIR/recover-range-pats.rs:155:17 | LL | let ..=$e; - | ^^^^^ pattern `1_i32..=i32::MAX` not covered + | ^^^ pattern `1_i32..=i32::MAX` not covered ... LL | mac!(0); | ------- in this macro invocation @@ -693,10 +693,10 @@ LL | mac!(0); = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0005]: refutable pattern in local binding - --> $DIR/recover-range-pats.rs:157:17 + --> $DIR/recover-range-pats.rs:157:19 | LL | let $e..; - | ^^^^ pattern `i32::MIN..=-1_i32` not covered + | ^^ pattern `i32::MIN..=-1_i32` not covered ... LL | mac!(0); | ------- in this macro invocation @@ -707,10 +707,10 @@ LL | mac!(0); = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0005]: refutable pattern in local binding - --> $DIR/recover-range-pats.rs:159:17 + --> $DIR/recover-range-pats.rs:159:19 | LL | let $e...; - | ^^^^^ pattern `i32::MIN..=-1_i32` not covered + | ^^^ pattern `i32::MIN..=-1_i32` not covered ... LL | mac!(0); | ------- in this macro invocation @@ -721,10 +721,10 @@ LL | mac!(0); = note: this error originates in the macro `mac` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0005]: refutable pattern in local binding - --> $DIR/recover-range-pats.rs:161:17 + --> $DIR/recover-range-pats.rs:161:19 | LL | let $e..=; - | ^^^^^ pattern `i32::MIN..=-1_i32` not covered + | ^^^ pattern `i32::MIN..=-1_i32` not covered ... LL | mac!(0); | ------- in this macro invocation diff --git a/tests/ui/tuple/tuple-struct-fields/test2.stderr b/tests/ui/tuple/tuple-struct-fields/test2.stderr index 784411aba8f8a..b658b8856d178 100644 --- a/tests/ui/tuple/tuple-struct-fields/test2.stderr +++ b/tests/ui/tuple/tuple-struct-fields/test2.stderr @@ -2,9 +2,9 @@ error: expected one of `)` or `,`, found `(` --> $DIR/test2.rs:5:26 | LL | struct S3(pub $t ()); - | -^ expected one of `)` or `,` - | | - | help: missing `,` + | - ^ expected one of `)` or `,` + | | + | help: missing `,` ... LL | define_struct! { (foo) } | ------------------------ in this macro invocation