From 7e7c11cf560527c4a7c70da63455cc23f4c51235 Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sat, 12 Nov 2022 23:18:32 +0100 Subject: [PATCH] Show a note where a macro failed to match This shows a small note on what the macro matcher was currently processing to aid with "no rules expected the token X" errors. --- compiler/rustc_expand/src/mbe/macro_parser.rs | 48 ++++++++++++++++- compiler/rustc_expand/src/mbe/macro_rules.rs | 39 ++++++++++---- .../vec-macro-with-comma-only.stderr | 2 + .../min_const_generics/macro-fail.stderr | 6 +++ .../edition-keywords-2015-2015-parsing.stderr | 12 +++++ .../edition-keywords-2015-2018-parsing.stderr | 12 +++++ .../edition-keywords-2018-2015-parsing.stderr | 12 +++++ .../edition-keywords-2018-2018-parsing.stderr | 12 +++++ src/test/ui/empty/empty-comment.stderr | 6 +++ src/test/ui/fail-simple.stderr | 2 + src/test/ui/issues/issue-7970a.stderr | 6 +++ ...rt-trailing-junk.with-generic-asset.stderr | 4 ++ ...trailing-junk.without-generic-asset.stderr | 4 ++ .../macros/macro-at-most-once-rep-2015.stderr | 54 +++++++++++++++++++ .../macros/macro-at-most-once-rep-2018.stderr | 54 +++++++++++++++++++ src/test/ui/macros/macro-non-lifetime.stderr | 6 +++ src/test/ui/macros/missing-comma.stderr | 36 +++++++++++++ .../ui/macros/nonterminal-matching.stderr | 8 +++ src/test/ui/macros/trace_faulty_macros.stderr | 1 + .../or-patterns-syntactic-fail-2018.stderr | 12 +++++ .../parser/macro/macro-doc-comments-1.stderr | 6 +++ .../parser/macro/macro-doc-comments-2.stderr | 6 +++ .../rfc-2294-if-let-guard/feature-gate.stderr | 6 +++ .../feature-gate.stderr | 6 +++ src/test/ui/underscore-ident-matcher.stderr | 6 +++ 25 files changed, 355 insertions(+), 11 deletions(-) diff --git a/compiler/rustc_expand/src/mbe/macro_parser.rs b/compiler/rustc_expand/src/mbe/macro_parser.rs index 95cec8d7ae299..d161868edce77 100644 --- a/compiler/rustc_expand/src/mbe/macro_parser.rs +++ b/compiler/rustc_expand/src/mbe/macro_parser.rs @@ -76,6 +76,7 @@ pub(crate) use ParseResult::*; use crate::mbe::{macro_rules::Tracker, KleeneOp, TokenTree}; use rustc_ast::token::{self, DocComment, Nonterminal, NonterminalKind, Token}; +use rustc_ast_pretty::pprust; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::Lrc; use rustc_errors::ErrorGuaranteed; @@ -86,6 +87,7 @@ use rustc_span::symbol::MacroRulesNormalizedIdent; use rustc_span::Span; use std::borrow::Cow; use std::collections::hash_map::Entry::{Occupied, Vacant}; +use std::fmt::Display; /// A unit within a matcher that a `MatcherPos` can refer to. Similar to (and derived from) /// `mbe::TokenTree`, but designed specifically for fast and easy traversal during matching. @@ -96,7 +98,7 @@ use std::collections::hash_map::Entry::{Occupied, Vacant}; /// /// This means a matcher can be represented by `&[MatcherLoc]`, and traversal mostly involves /// simply incrementing the current matcher position index by one. -#[derive(Debug)] +#[derive(Debug, PartialEq, Clone)] pub(crate) enum MatcherLoc { Token { token: Token, @@ -129,6 +131,46 @@ pub(crate) enum MatcherLoc { Eof, } +impl MatcherLoc { + pub(super) fn span(&self) -> Option { + match self { + MatcherLoc::Token { token } => Some(token.span), + MatcherLoc::Delimited => None, + MatcherLoc::Sequence { .. } => None, + MatcherLoc::SequenceKleeneOpNoSep { .. } => None, + MatcherLoc::SequenceSep { .. } => None, + MatcherLoc::SequenceKleeneOpAfterSep { .. } => None, + MatcherLoc::MetaVarDecl { span, .. } => Some(*span), + MatcherLoc::Eof => None, + } + } +} + +impl Display for MatcherLoc { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + match self { + MatcherLoc::Token { token } | MatcherLoc::SequenceSep { separator: token } => { + write!(f, "`{}`", pprust::token_to_string(token)) + } + MatcherLoc::MetaVarDecl { bind, kind, .. } => { + write!(f, "meta-variable `${bind}")?; + if let Some(kind) = kind { + write!(f, ":{}", kind)?; + } + write!(f, "`")?; + Ok(()) + } + MatcherLoc::Eof => f.write_str("end of macro"), + + // These are not printed in the diagnostic + MatcherLoc::Delimited => f.write_str("delimiter"), + MatcherLoc::Sequence { .. } => f.write_str("sequence start"), + MatcherLoc::SequenceKleeneOpNoSep { .. } => f.write_str("sequence end"), + MatcherLoc::SequenceKleeneOpAfterSep { .. } => f.write_str("sequence end"), + } + } +} + pub(super) fn compute_locs(matcher: &[TokenTree]) -> Vec { fn inner( tts: &[TokenTree], @@ -398,6 +440,10 @@ impl TtParser { } } + pub(super) fn has_no_remaining_items_for_step(&self) -> bool { + self.cur_mps.is_empty() + } + /// Process the matcher positions of `cur_mps` until it is empty. In the process, this will /// produce more mps in `next_mps` and `bb_mps`. /// diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs index 99af91072882e..80c2db030fc57 100644 --- a/compiler/rustc_expand/src/mbe/macro_rules.rs +++ b/compiler/rustc_expand/src/mbe/macro_rules.rs @@ -337,7 +337,7 @@ fn expand_macro<'cx>( return result; } - let Some((token, label)) = tracker.best_failure else { + let Some((token, label, remaining_matcher)) = tracker.best_failure else { return tracker.result.expect("must have encountered Error or ErrorReported"); }; @@ -351,6 +351,12 @@ fn expand_macro<'cx>( annotate_doc_comment(&mut err, sess.source_map(), span); + if let Some(span) = remaining_matcher.span() { + err.span_note(span, format!("while trying to match {remaining_matcher}")); + } else { + err.note(format!("while trying to match {remaining_matcher}")); + } + // Check whether there's a missing comma in this macro call, like `println!("{}" a);` if let Some((arg, comma_span)) = arg.add_comma() { for lhs in lhses { @@ -379,17 +385,22 @@ fn expand_macro<'cx>( } /// The tracker used for the slow error path that collects useful info for diagnostics. -struct CollectTrackerAndEmitter<'a, 'cx> { +struct CollectTrackerAndEmitter<'a, 'cx, 'matcher> { cx: &'a mut ExtCtxt<'cx>, + remaining_matcher: Option<&'matcher MatcherLoc>, /// Which arm's failure should we report? (the one furthest along) - best_failure: Option<(Token, &'static str)>, + best_failure: Option<(Token, &'static str, MatcherLoc)>, root_span: Span, result: Option>, } -impl<'a, 'cx, 'matcher> Tracker<'matcher> for CollectTrackerAndEmitter<'a, 'cx> { - fn before_match_loc(&mut self, _parser: &TtParser, _matcher: &'matcher MatcherLoc) { - // Empty for now. +impl<'a, 'cx, 'matcher> Tracker<'matcher> for CollectTrackerAndEmitter<'a, 'cx, 'matcher> { + fn before_match_loc(&mut self, parser: &TtParser, matcher: &'matcher MatcherLoc) { + if self.remaining_matcher.is_none() + || (parser.has_no_remaining_items_for_step() && *matcher != MatcherLoc::Eof) + { + self.remaining_matcher = Some(matcher); + } } fn after_arm(&mut self, result: &NamedParseResult) { @@ -398,8 +409,16 @@ impl<'a, 'cx, 'matcher> Tracker<'matcher> for CollectTrackerAndEmitter<'a, 'cx> unreachable!("should not collect detailed info for successful macro match"); } Failure(token, msg) => match self.best_failure { - Some((ref best_token, _)) if best_token.span.lo() >= token.span.lo() => {} - _ => self.best_failure = Some((token.clone(), msg)), + Some((ref best_token, _, _)) if best_token.span.lo() >= token.span.lo() => {} + _ => { + self.best_failure = Some(( + token.clone(), + msg, + self.remaining_matcher + .expect("must have collected matcher already") + .clone(), + )) + } }, Error(err_sp, msg) => { let span = err_sp.substitute_dummy(self.root_span); @@ -415,9 +434,9 @@ impl<'a, 'cx, 'matcher> Tracker<'matcher> for CollectTrackerAndEmitter<'a, 'cx> } } -impl<'a, 'cx> CollectTrackerAndEmitter<'a, 'cx> { +impl<'a, 'cx> CollectTrackerAndEmitter<'a, 'cx, '_> { fn new(cx: &'a mut ExtCtxt<'cx>, root_span: Span) -> Self { - Self { cx, best_failure: None, root_span, result: None } + Self { cx, remaining_matcher: None, best_failure: None, root_span, result: None } } } diff --git a/src/test/ui/array-slice-vec/vec-macro-with-comma-only.stderr b/src/test/ui/array-slice-vec/vec-macro-with-comma-only.stderr index abbee347c00bc..ec4a001f4d01a 100644 --- a/src/test/ui/array-slice-vec/vec-macro-with-comma-only.stderr +++ b/src/test/ui/array-slice-vec/vec-macro-with-comma-only.stderr @@ -3,6 +3,8 @@ error: no rules expected the token `,` | LL | vec![,]; | ^ no rules expected this token in macro call + | + = note: while trying to match end of macro error: aborting due to previous error diff --git a/src/test/ui/const-generics/min_const_generics/macro-fail.stderr b/src/test/ui/const-generics/min_const_generics/macro-fail.stderr index 2b75c19774842..9f73b91aabebf 100644 --- a/src/test/ui/const-generics/min_const_generics/macro-fail.stderr +++ b/src/test/ui/const-generics/min_const_generics/macro-fail.stderr @@ -53,6 +53,12 @@ LL | macro_rules! gimme_a_const { ... LL | let _fail = Example::; | ^^^^^^^^^^^^^^^^ missing tokens in macro arguments + | +note: while trying to match meta-variable `$rusty:ident` + --> $DIR/macro-fail.rs:28:8 + | +LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }} + | ^^^^^^^^^^^^^ error[E0747]: type provided when a constant was expected --> $DIR/macro-fail.rs:14:33 diff --git a/src/test/ui/editions/edition-keywords-2015-2015-parsing.stderr b/src/test/ui/editions/edition-keywords-2015-2015-parsing.stderr index 3435fdfd72570..39944622d07b9 100644 --- a/src/test/ui/editions/edition-keywords-2015-2015-parsing.stderr +++ b/src/test/ui/editions/edition-keywords-2015-2015-parsing.stderr @@ -3,12 +3,24 @@ error: no rules expected the token `r#async` | LL | r#async = consumes_async!(r#async); | ^^^^^^^ no rules expected this token in macro call + | +note: while trying to match `async` + --> $DIR/auxiliary/edition-kw-macro-2015.rs:17:6 + | +LL | (async) => (1) + | ^^^^^ error: no rules expected the token `async` --> $DIR/edition-keywords-2015-2015-parsing.rs:17:35 | LL | r#async = consumes_async_raw!(async); | ^^^^^ no rules expected this token in macro call + | +note: while trying to match `r#async` + --> $DIR/auxiliary/edition-kw-macro-2015.rs:22:6 + | +LL | (r#async) => (1) + | ^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/editions/edition-keywords-2015-2018-parsing.stderr b/src/test/ui/editions/edition-keywords-2015-2018-parsing.stderr index 6e86d746f5442..fa83908e6666e 100644 --- a/src/test/ui/editions/edition-keywords-2015-2018-parsing.stderr +++ b/src/test/ui/editions/edition-keywords-2015-2018-parsing.stderr @@ -3,12 +3,24 @@ error: no rules expected the token `r#async` | LL | r#async = consumes_async!(r#async); | ^^^^^^^ no rules expected this token in macro call + | +note: while trying to match `async` + --> $DIR/auxiliary/edition-kw-macro-2018.rs:17:6 + | +LL | (async) => (1) + | ^^^^^ error: no rules expected the token `async` --> $DIR/edition-keywords-2015-2018-parsing.rs:17:35 | LL | r#async = consumes_async_raw!(async); | ^^^^^ no rules expected this token in macro call + | +note: while trying to match `r#async` + --> $DIR/auxiliary/edition-kw-macro-2018.rs:22:6 + | +LL | (r#async) => (1) + | ^^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/editions/edition-keywords-2018-2015-parsing.stderr b/src/test/ui/editions/edition-keywords-2018-2015-parsing.stderr index e1eea725bb0b0..1a4a94e973327 100644 --- a/src/test/ui/editions/edition-keywords-2018-2015-parsing.stderr +++ b/src/test/ui/editions/edition-keywords-2018-2015-parsing.stderr @@ -25,12 +25,24 @@ error: no rules expected the token `r#async` | LL | r#async = consumes_async!(r#async); | ^^^^^^^ no rules expected this token in macro call + | +note: while trying to match `async` + --> $DIR/auxiliary/edition-kw-macro-2015.rs:17:6 + | +LL | (async) => (1) + | ^^^^^ error: no rules expected the token `async` --> $DIR/edition-keywords-2018-2015-parsing.rs:21:35 | LL | r#async = consumes_async_raw!(async); | ^^^^^ no rules expected this token in macro call + | +note: while trying to match `r#async` + --> $DIR/auxiliary/edition-kw-macro-2015.rs:22:6 + | +LL | (r#async) => (1) + | ^^^^^^^ error: macro expansion ends with an incomplete expression: expected one of `move`, `|`, or `||` --> $DIR/auxiliary/edition-kw-macro-2015.rs:27:23 diff --git a/src/test/ui/editions/edition-keywords-2018-2018-parsing.stderr b/src/test/ui/editions/edition-keywords-2018-2018-parsing.stderr index 0af4da09c19e3..19eb7ac98239e 100644 --- a/src/test/ui/editions/edition-keywords-2018-2018-parsing.stderr +++ b/src/test/ui/editions/edition-keywords-2018-2018-parsing.stderr @@ -25,12 +25,24 @@ error: no rules expected the token `r#async` | LL | r#async = consumes_async!(r#async); | ^^^^^^^ no rules expected this token in macro call + | +note: while trying to match `async` + --> $DIR/auxiliary/edition-kw-macro-2018.rs:17:6 + | +LL | (async) => (1) + | ^^^^^ error: no rules expected the token `async` --> $DIR/edition-keywords-2018-2018-parsing.rs:21:35 | LL | r#async = consumes_async_raw!(async); | ^^^^^ no rules expected this token in macro call + | +note: while trying to match `r#async` + --> $DIR/auxiliary/edition-kw-macro-2018.rs:22:6 + | +LL | (r#async) => (1) + | ^^^^^^^ error: macro expansion ends with an incomplete expression: expected one of `move`, `|`, or `||` --> $DIR/auxiliary/edition-kw-macro-2018.rs:27:23 diff --git a/src/test/ui/empty/empty-comment.stderr b/src/test/ui/empty/empty-comment.stderr index f583dbbdc64f8..7cc8d8fe9229a 100644 --- a/src/test/ui/empty/empty-comment.stderr +++ b/src/test/ui/empty/empty-comment.stderr @@ -6,6 +6,12 @@ LL | macro_rules! one_arg_macro { ... LL | one_arg_macro!(/**/); | ^^^^^^^^^^^^^^^^^^^^ missing tokens in macro arguments + | +note: while trying to match meta-variable `$fmt:expr` + --> $DIR/empty-comment.rs:6:6 + | +LL | ($fmt:expr) => (print!(concat!($fmt, "\n"))); + | ^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/fail-simple.stderr b/src/test/ui/fail-simple.stderr index 26ed918e94d91..af8f54291ff47 100644 --- a/src/test/ui/fail-simple.stderr +++ b/src/test/ui/fail-simple.stderr @@ -3,6 +3,8 @@ error: no rules expected the token `@` | LL | panic!(@); | ^ no rules expected this token in macro call + | + = note: while trying to match end of macro error: aborting due to previous error diff --git a/src/test/ui/issues/issue-7970a.stderr b/src/test/ui/issues/issue-7970a.stderr index ea400d7e1917e..b04a0eef37139 100644 --- a/src/test/ui/issues/issue-7970a.stderr +++ b/src/test/ui/issues/issue-7970a.stderr @@ -6,6 +6,12 @@ LL | macro_rules! one_arg_macro { ... LL | one_arg_macro!(); | ^^^^^^^^^^^^^^^^ missing tokens in macro arguments + | +note: while trying to match meta-variable `$fmt:expr` + --> $DIR/issue-7970a.rs:2:6 + | +LL | ($fmt:expr) => (print!(concat!($fmt, "\n"))); + | ^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/macros/assert-trailing-junk.with-generic-asset.stderr b/src/test/ui/macros/assert-trailing-junk.with-generic-asset.stderr index 09dd16a0b0d89..1e73320e43912 100644 --- a/src/test/ui/macros/assert-trailing-junk.with-generic-asset.stderr +++ b/src/test/ui/macros/assert-trailing-junk.with-generic-asset.stderr @@ -17,6 +17,8 @@ LL | assert!(true, "whatever" blah); | -^^^^ no rules expected this token in macro call | | | help: missing comma here + | + = note: while trying to match sequence start error: unexpected string literal --> $DIR/assert-trailing-junk.rs:18:18 @@ -33,6 +35,8 @@ LL | assert!(true "whatever" blah); | -^^^^ no rules expected this token in macro call | | | help: missing comma here + | + = note: while trying to match sequence start error: macro requires an expression as an argument --> $DIR/assert-trailing-junk.rs:22:5 diff --git a/src/test/ui/macros/assert-trailing-junk.without-generic-asset.stderr b/src/test/ui/macros/assert-trailing-junk.without-generic-asset.stderr index 09dd16a0b0d89..1e73320e43912 100644 --- a/src/test/ui/macros/assert-trailing-junk.without-generic-asset.stderr +++ b/src/test/ui/macros/assert-trailing-junk.without-generic-asset.stderr @@ -17,6 +17,8 @@ LL | assert!(true, "whatever" blah); | -^^^^ no rules expected this token in macro call | | | help: missing comma here + | + = note: while trying to match sequence start error: unexpected string literal --> $DIR/assert-trailing-junk.rs:18:18 @@ -33,6 +35,8 @@ LL | assert!(true "whatever" blah); | -^^^^ no rules expected this token in macro call | | | help: missing comma here + | + = note: while trying to match sequence start error: macro requires an expression as an argument --> $DIR/assert-trailing-junk.rs:22:5 diff --git a/src/test/ui/macros/macro-at-most-once-rep-2015.stderr b/src/test/ui/macros/macro-at-most-once-rep-2015.stderr index 9a3df858e515f..7c45b85bc8d4e 100644 --- a/src/test/ui/macros/macro-at-most-once-rep-2015.stderr +++ b/src/test/ui/macros/macro-at-most-once-rep-2015.stderr @@ -12,6 +12,8 @@ LL | macro_rules! foo { ... LL | foo!(a?); | ^ no rules expected this token in macro call + | + = note: while trying to match sequence end error: no rules expected the token `?` --> $DIR/macro-at-most-once-rep-2015.rs:26:11 @@ -21,6 +23,8 @@ LL | macro_rules! foo { ... LL | foo!(a?a); | ^ no rules expected this token in macro call + | + = note: while trying to match sequence end error: no rules expected the token `?` --> $DIR/macro-at-most-once-rep-2015.rs:27:11 @@ -30,6 +34,8 @@ LL | macro_rules! foo { ... LL | foo!(a?a?a); | ^ no rules expected this token in macro call + | + = note: while trying to match sequence end error: unexpected end of macro invocation --> $DIR/macro-at-most-once-rep-2015.rs:29:5 @@ -39,6 +45,12 @@ LL | macro_rules! barplus { ... LL | barplus!(); | ^^^^^^^^^^ missing tokens in macro arguments + | +note: while trying to match `+` + --> $DIR/macro-at-most-once-rep-2015.rs:15:11 + | +LL | ($(a)?+) => {}; // ok. matches "a+" and "+" + | ^ error: unexpected end of macro invocation --> $DIR/macro-at-most-once-rep-2015.rs:30:15 @@ -48,6 +60,12 @@ LL | macro_rules! barplus { ... LL | barplus!(a); | ^ missing tokens in macro arguments + | +note: while trying to match `+` + --> $DIR/macro-at-most-once-rep-2015.rs:15:11 + | +LL | ($(a)?+) => {}; // ok. matches "a+" and "+" + | ^ error: no rules expected the token `?` --> $DIR/macro-at-most-once-rep-2015.rs:31:15 @@ -57,6 +75,12 @@ LL | macro_rules! barplus { ... LL | barplus!(a?); | ^ no rules expected this token in macro call + | +note: while trying to match `+` + --> $DIR/macro-at-most-once-rep-2015.rs:15:11 + | +LL | ($(a)?+) => {}; // ok. matches "a+" and "+" + | ^ error: no rules expected the token `?` --> $DIR/macro-at-most-once-rep-2015.rs:32:15 @@ -66,6 +90,12 @@ LL | macro_rules! barplus { ... LL | barplus!(a?a); | ^ no rules expected this token in macro call + | +note: while trying to match `+` + --> $DIR/macro-at-most-once-rep-2015.rs:15:11 + | +LL | ($(a)?+) => {}; // ok. matches "a+" and "+" + | ^ error: unexpected end of macro invocation --> $DIR/macro-at-most-once-rep-2015.rs:36:5 @@ -75,6 +105,12 @@ LL | macro_rules! barstar { ... LL | barstar!(); | ^^^^^^^^^^ missing tokens in macro arguments + | +note: while trying to match `*` + --> $DIR/macro-at-most-once-rep-2015.rs:19:11 + | +LL | ($(a)?*) => {}; // ok. matches "a*" and "*" + | ^ error: unexpected end of macro invocation --> $DIR/macro-at-most-once-rep-2015.rs:37:15 @@ -84,6 +120,12 @@ LL | macro_rules! barstar { ... LL | barstar!(a); | ^ missing tokens in macro arguments + | +note: while trying to match `*` + --> $DIR/macro-at-most-once-rep-2015.rs:19:11 + | +LL | ($(a)?*) => {}; // ok. matches "a*" and "*" + | ^ error: no rules expected the token `?` --> $DIR/macro-at-most-once-rep-2015.rs:38:15 @@ -93,6 +135,12 @@ LL | macro_rules! barstar { ... LL | barstar!(a?); | ^ no rules expected this token in macro call + | +note: while trying to match `*` + --> $DIR/macro-at-most-once-rep-2015.rs:19:11 + | +LL | ($(a)?*) => {}; // ok. matches "a*" and "*" + | ^ error: no rules expected the token `?` --> $DIR/macro-at-most-once-rep-2015.rs:39:15 @@ -102,6 +150,12 @@ LL | macro_rules! barstar { ... LL | barstar!(a?a); | ^ no rules expected this token in macro call + | +note: while trying to match `*` + --> $DIR/macro-at-most-once-rep-2015.rs:19:11 + | +LL | ($(a)?*) => {}; // ok. matches "a*" and "*" + | ^ error: aborting due to 12 previous errors diff --git a/src/test/ui/macros/macro-at-most-once-rep-2018.stderr b/src/test/ui/macros/macro-at-most-once-rep-2018.stderr index 013fabe13e5f6..696520b28268a 100644 --- a/src/test/ui/macros/macro-at-most-once-rep-2018.stderr +++ b/src/test/ui/macros/macro-at-most-once-rep-2018.stderr @@ -12,6 +12,8 @@ LL | macro_rules! foo { ... LL | foo!(a?); | ^ no rules expected this token in macro call + | + = note: while trying to match sequence end error: no rules expected the token `?` --> $DIR/macro-at-most-once-rep-2018.rs:26:11 @@ -21,6 +23,8 @@ LL | macro_rules! foo { ... LL | foo!(a?a); | ^ no rules expected this token in macro call + | + = note: while trying to match sequence end error: no rules expected the token `?` --> $DIR/macro-at-most-once-rep-2018.rs:27:11 @@ -30,6 +34,8 @@ LL | macro_rules! foo { ... LL | foo!(a?a?a); | ^ no rules expected this token in macro call + | + = note: while trying to match sequence end error: unexpected end of macro invocation --> $DIR/macro-at-most-once-rep-2018.rs:29:5 @@ -39,6 +45,12 @@ LL | macro_rules! barplus { ... LL | barplus!(); | ^^^^^^^^^^ missing tokens in macro arguments + | +note: while trying to match `+` + --> $DIR/macro-at-most-once-rep-2018.rs:15:11 + | +LL | ($(a)?+) => {}; // ok. matches "a+" and "+" + | ^ error: unexpected end of macro invocation --> $DIR/macro-at-most-once-rep-2018.rs:30:15 @@ -48,6 +60,12 @@ LL | macro_rules! barplus { ... LL | barplus!(a); | ^ missing tokens in macro arguments + | +note: while trying to match `+` + --> $DIR/macro-at-most-once-rep-2018.rs:15:11 + | +LL | ($(a)?+) => {}; // ok. matches "a+" and "+" + | ^ error: no rules expected the token `?` --> $DIR/macro-at-most-once-rep-2018.rs:31:15 @@ -57,6 +75,12 @@ LL | macro_rules! barplus { ... LL | barplus!(a?); | ^ no rules expected this token in macro call + | +note: while trying to match `+` + --> $DIR/macro-at-most-once-rep-2018.rs:15:11 + | +LL | ($(a)?+) => {}; // ok. matches "a+" and "+" + | ^ error: no rules expected the token `?` --> $DIR/macro-at-most-once-rep-2018.rs:32:15 @@ -66,6 +90,12 @@ LL | macro_rules! barplus { ... LL | barplus!(a?a); | ^ no rules expected this token in macro call + | +note: while trying to match `+` + --> $DIR/macro-at-most-once-rep-2018.rs:15:11 + | +LL | ($(a)?+) => {}; // ok. matches "a+" and "+" + | ^ error: unexpected end of macro invocation --> $DIR/macro-at-most-once-rep-2018.rs:36:5 @@ -75,6 +105,12 @@ LL | macro_rules! barstar { ... LL | barstar!(); | ^^^^^^^^^^ missing tokens in macro arguments + | +note: while trying to match `*` + --> $DIR/macro-at-most-once-rep-2018.rs:19:11 + | +LL | ($(a)?*) => {}; // ok. matches "a*" and "*" + | ^ error: unexpected end of macro invocation --> $DIR/macro-at-most-once-rep-2018.rs:37:15 @@ -84,6 +120,12 @@ LL | macro_rules! barstar { ... LL | barstar!(a); | ^ missing tokens in macro arguments + | +note: while trying to match `*` + --> $DIR/macro-at-most-once-rep-2018.rs:19:11 + | +LL | ($(a)?*) => {}; // ok. matches "a*" and "*" + | ^ error: no rules expected the token `?` --> $DIR/macro-at-most-once-rep-2018.rs:38:15 @@ -93,6 +135,12 @@ LL | macro_rules! barstar { ... LL | barstar!(a?); | ^ no rules expected this token in macro call + | +note: while trying to match `*` + --> $DIR/macro-at-most-once-rep-2018.rs:19:11 + | +LL | ($(a)?*) => {}; // ok. matches "a*" and "*" + | ^ error: no rules expected the token `?` --> $DIR/macro-at-most-once-rep-2018.rs:39:15 @@ -102,6 +150,12 @@ LL | macro_rules! barstar { ... LL | barstar!(a?a); | ^ no rules expected this token in macro call + | +note: while trying to match `*` + --> $DIR/macro-at-most-once-rep-2018.rs:19:11 + | +LL | ($(a)?*) => {}; // ok. matches "a*" and "*" + | ^ error: aborting due to 12 previous errors diff --git a/src/test/ui/macros/macro-non-lifetime.stderr b/src/test/ui/macros/macro-non-lifetime.stderr index 6234735dfc8a4..e1ed87f943551 100644 --- a/src/test/ui/macros/macro-non-lifetime.stderr +++ b/src/test/ui/macros/macro-non-lifetime.stderr @@ -6,6 +6,12 @@ LL | macro_rules! m { ($x:lifetime) => { } } ... LL | m!(a); | ^ no rules expected this token in macro call + | +note: while trying to match meta-variable `$x:lifetime` + --> $DIR/macro-non-lifetime.rs:3:19 + | +LL | macro_rules! m { ($x:lifetime) => { } } + | ^^^^^^^^^^^ error: aborting due to previous error diff --git a/src/test/ui/macros/missing-comma.stderr b/src/test/ui/macros/missing-comma.stderr index 6da92bdea19e0..81877a29ed8ae 100644 --- a/src/test/ui/macros/missing-comma.stderr +++ b/src/test/ui/macros/missing-comma.stderr @@ -14,6 +14,12 @@ LL | foo!(a b); | -^ no rules expected this token in macro call | | | help: missing comma here + | +note: while trying to match meta-variable `$a:ident` + --> $DIR/missing-comma.rs:2:6 + | +LL | ($a:ident) => (); + | ^^^^^^^^ error: no rules expected the token `e` --> $DIR/missing-comma.rs:23:21 @@ -25,6 +31,12 @@ LL | foo!(a, b, c, d e); | -^ no rules expected this token in macro call | | | help: missing comma here + | +note: while trying to match meta-variable `$d:ident` + --> $DIR/missing-comma.rs:5:36 + | +LL | ($a:ident, $b:ident, $c:ident, $d:ident) => (); + | ^^^^^^^^ error: no rules expected the token `d` --> $DIR/missing-comma.rs:25:18 @@ -36,6 +48,12 @@ LL | foo!(a, b, c d, e); | -^ no rules expected this token in macro call | | | help: missing comma here + | +note: while trying to match meta-variable `$c:ident` + --> $DIR/missing-comma.rs:4:26 + | +LL | ($a:ident, $b:ident, $c:ident) => (); + | ^^^^^^^^ error: no rules expected the token `d` --> $DIR/missing-comma.rs:27:18 @@ -45,6 +63,12 @@ LL | macro_rules! foo { ... LL | foo!(a, b, c d e); | ^ no rules expected this token in macro call + | +note: while trying to match meta-variable `$c:ident` + --> $DIR/missing-comma.rs:4:26 + | +LL | ($a:ident, $b:ident, $c:ident) => (); + | ^^^^^^^^ error: unexpected end of macro invocation --> $DIR/missing-comma.rs:29:23 @@ -54,6 +78,12 @@ LL | macro_rules! bar { ... LL | bar!(Level::Error, ); | ^ missing tokens in macro arguments + | +note: while trying to match meta-variable `$arg:tt` + --> $DIR/missing-comma.rs:10:19 + | +LL | ($lvl:expr, $($arg:tt)+) => {} + | ^^^^^^^ error: no rules expected the token `,` --> $DIR/missing-comma.rs:32:38 @@ -63,6 +93,12 @@ LL | macro_rules! check { ... LL | check!(::fmt, "fmt",); | ^ no rules expected this token in macro call + | +note: while trying to match meta-variable `$expected:expr` + --> $DIR/missing-comma.rs:14:14 + | +LL | ($ty:ty, $expected:expr) => {}; + | ^^^^^^^^^^^^^^ error: aborting due to 7 previous errors diff --git a/src/test/ui/macros/nonterminal-matching.stderr b/src/test/ui/macros/nonterminal-matching.stderr index 585f2355321f5..5bbd543909833 100644 --- a/src/test/ui/macros/nonterminal-matching.stderr +++ b/src/test/ui/macros/nonterminal-matching.stderr @@ -10,6 +10,14 @@ LL | n!(a $nt_item b); LL | complex_nonterminal!(enum E {}); | ------------------------------- in this macro invocation | +note: while trying to match `enum E {}` + --> $DIR/nonterminal-matching.rs:15:15 + | +LL | macro n(a $nt_item b) { + | ^^^^^^^^ +... +LL | complex_nonterminal!(enum E {}); + | ------------------------------- in this macro invocation = note: this error originates in the macro `complex_nonterminal` (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to previous error diff --git a/src/test/ui/macros/trace_faulty_macros.stderr b/src/test/ui/macros/trace_faulty_macros.stderr index d6fc694021448..21e47da075716 100644 --- a/src/test/ui/macros/trace_faulty_macros.stderr +++ b/src/test/ui/macros/trace_faulty_macros.stderr @@ -10,6 +10,7 @@ LL | my_faulty_macro!(bcd); LL | my_faulty_macro!(); | ------------------ in this macro invocation | + = note: while trying to match end of macro = note: this error originates in the macro `my_faulty_macro` (in Nightly builds, run with -Z macro-backtrace for more info) note: trace_macro diff --git a/src/test/ui/or-patterns/or-patterns-syntactic-fail-2018.stderr b/src/test/ui/or-patterns/or-patterns-syntactic-fail-2018.stderr index 001c68a977473..acc2099bbc6a8 100644 --- a/src/test/ui/or-patterns/or-patterns-syntactic-fail-2018.stderr +++ b/src/test/ui/or-patterns/or-patterns-syntactic-fail-2018.stderr @@ -6,6 +6,12 @@ LL | macro_rules! accept_pat { ... LL | accept_pat!(p | q); | ^ no rules expected this token in macro call + | +note: while trying to match meta-variable `$p:pat` + --> $DIR/or-patterns-syntactic-fail-2018.rs:9:6 + | +LL | ($p:pat) => {}; + | ^^^^^^ error: no rules expected the token `|` --> $DIR/or-patterns-syntactic-fail-2018.rs:13:13 @@ -15,6 +21,12 @@ LL | macro_rules! accept_pat { ... LL | accept_pat!(|p| q); | ^ no rules expected this token in macro call + | +note: while trying to match meta-variable `$p:pat` + --> $DIR/or-patterns-syntactic-fail-2018.rs:9:6 + | +LL | ($p:pat) => {}; + | ^^^^^^ error: aborting due to 2 previous errors diff --git a/src/test/ui/parser/macro/macro-doc-comments-1.stderr b/src/test/ui/parser/macro/macro-doc-comments-1.stderr index 0ebf3d52b6372..eaeb62d2cfd98 100644 --- a/src/test/ui/parser/macro/macro-doc-comments-1.stderr +++ b/src/test/ui/parser/macro/macro-doc-comments-1.stderr @@ -9,6 +9,12 @@ LL | //! Inner | | | no rules expected this token in macro call | inner doc comments expand to `#![doc = "..."]`, which is what this macro attempted to match + | +note: while trying to match `[` + --> $DIR/macro-doc-comments-1.rs:2:7 + | +LL | (#[$outer:meta]) => () + | ^ error: aborting due to previous error diff --git a/src/test/ui/parser/macro/macro-doc-comments-2.stderr b/src/test/ui/parser/macro/macro-doc-comments-2.stderr index 346d865868d99..1dcd95f6fad4f 100644 --- a/src/test/ui/parser/macro/macro-doc-comments-2.stderr +++ b/src/test/ui/parser/macro/macro-doc-comments-2.stderr @@ -9,6 +9,12 @@ LL | /// Outer | | | no rules expected this token in macro call | outer doc comments expand to `#[doc = "..."]`, which is what this macro attempted to match + | +note: while trying to match `!` + --> $DIR/macro-doc-comments-2.rs:2:7 + | +LL | (#![$inner:meta]) => () + | ^ error: aborting due to previous error diff --git a/src/test/ui/rfc-2294-if-let-guard/feature-gate.stderr b/src/test/ui/rfc-2294-if-let-guard/feature-gate.stderr index e017d04a5c933..96fe11911b7a0 100644 --- a/src/test/ui/rfc-2294-if-let-guard/feature-gate.stderr +++ b/src/test/ui/rfc-2294-if-let-guard/feature-gate.stderr @@ -72,6 +72,12 @@ LL | macro_rules! use_expr { ... LL | use_expr!(let 0 = 1); | ^^^ no rules expected this token in macro call + | +note: while trying to match meta-variable `$e:expr` + --> $DIR/feature-gate.rs:61:10 + | +LL | ($e:expr) => { + | ^^^^^^^ error[E0658]: `if let` guards are experimental --> $DIR/feature-gate.rs:7:12 diff --git a/src/test/ui/rfc-2497-if-let-chains/feature-gate.stderr b/src/test/ui/rfc-2497-if-let-chains/feature-gate.stderr index feea1c254d8da..7a43b71fc8b89 100644 --- a/src/test/ui/rfc-2497-if-let-chains/feature-gate.stderr +++ b/src/test/ui/rfc-2497-if-let-chains/feature-gate.stderr @@ -18,6 +18,12 @@ LL | macro_rules! use_expr { ... LL | use_expr!(let 0 = 1); | ^^^ no rules expected this token in macro call + | +note: while trying to match meta-variable `$e:expr` + --> $DIR/feature-gate.rs:50:10 + | +LL | ($e:expr) => { + | ^^^^^^^ error[E0658]: `let` expressions in this position are unstable --> $DIR/feature-gate.rs:14:16 diff --git a/src/test/ui/underscore-ident-matcher.stderr b/src/test/ui/underscore-ident-matcher.stderr index 241c3d3d8ce61..b0e4d88f67186 100644 --- a/src/test/ui/underscore-ident-matcher.stderr +++ b/src/test/ui/underscore-ident-matcher.stderr @@ -6,6 +6,12 @@ LL | macro_rules! identity { ... LL | let identity!(_) = 10; | ^ no rules expected this token in macro call + | +note: while trying to match meta-variable `$i:ident` + --> $DIR/underscore-ident-matcher.rs:2:6 + | +LL | ($i: ident) => ( + | ^^^^^^^^^ error: aborting due to previous error