Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1a6ed30

Browse files
authoredNov 15, 2022
Rollup merge of #103439 - Nilstrieb:help-me-with-my-macro, r=estebank
Show note where the macro failed to match When feeding the wrong tokens, it used to fail with a very generic error that wasn't very helpful. This change tries to help by noting where specifically the matching went wrong. ```rust macro_rules! uwu { (a a a b) => {}; } uwu! { a a a c } ``` ```diff error: no rules expected the token `c` --> macros.rs:5:14 | 1 | macro_rules! uwu { | ---------------- when calling this macro ... 4 | uwu! { a a a c } | ^ no rules expected this token in macro call | +note: while trying to match `b` + --> macros.rs:2:12 + | +2 | (a a a b) => {}; + | ^ ```
2 parents ca92d90 + 7e7c11c commit 1a6ed30

25 files changed

+355
-11
lines changed
 

‎compiler/rustc_expand/src/mbe/macro_parser.rs

+47-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ pub(crate) use ParseResult::*;
7676
use crate::mbe::{macro_rules::Tracker, KleeneOp, TokenTree};
7777

7878
use rustc_ast::token::{self, DocComment, Nonterminal, NonterminalKind, Token};
79+
use rustc_ast_pretty::pprust;
7980
use rustc_data_structures::fx::FxHashMap;
8081
use rustc_data_structures::sync::Lrc;
8182
use rustc_errors::ErrorGuaranteed;
@@ -86,6 +87,7 @@ use rustc_span::symbol::MacroRulesNormalizedIdent;
8687
use rustc_span::Span;
8788
use std::borrow::Cow;
8889
use std::collections::hash_map::Entry::{Occupied, Vacant};
90+
use std::fmt::Display;
8991

9092
/// A unit within a matcher that a `MatcherPos` can refer to. Similar to (and derived from)
9193
/// `mbe::TokenTree`, but designed specifically for fast and easy traversal during matching.
@@ -96,7 +98,7 @@ use std::collections::hash_map::Entry::{Occupied, Vacant};
9698
///
9799
/// This means a matcher can be represented by `&[MatcherLoc]`, and traversal mostly involves
98100
/// simply incrementing the current matcher position index by one.
99-
#[derive(Debug)]
101+
#[derive(Debug, PartialEq, Clone)]
100102
pub(crate) enum MatcherLoc {
101103
Token {
102104
token: Token,
@@ -129,6 +131,46 @@ pub(crate) enum MatcherLoc {
129131
Eof,
130132
}
131133

134+
impl MatcherLoc {
135+
pub(super) fn span(&self) -> Option<Span> {
136+
match self {
137+
MatcherLoc::Token { token } => Some(token.span),
138+
MatcherLoc::Delimited => None,
139+
MatcherLoc::Sequence { .. } => None,
140+
MatcherLoc::SequenceKleeneOpNoSep { .. } => None,
141+
MatcherLoc::SequenceSep { .. } => None,
142+
MatcherLoc::SequenceKleeneOpAfterSep { .. } => None,
143+
MatcherLoc::MetaVarDecl { span, .. } => Some(*span),
144+
MatcherLoc::Eof => None,
145+
}
146+
}
147+
}
148+
149+
impl Display for MatcherLoc {
150+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
151+
match self {
152+
MatcherLoc::Token { token } | MatcherLoc::SequenceSep { separator: token } => {
153+
write!(f, "`{}`", pprust::token_to_string(token))
154+
}
155+
MatcherLoc::MetaVarDecl { bind, kind, .. } => {
156+
write!(f, "meta-variable `${bind}")?;
157+
if let Some(kind) = kind {
158+
write!(f, ":{}", kind)?;
159+
}
160+
write!(f, "`")?;
161+
Ok(())
162+
}
163+
MatcherLoc::Eof => f.write_str("end of macro"),
164+
165+
// These are not printed in the diagnostic
166+
MatcherLoc::Delimited => f.write_str("delimiter"),
167+
MatcherLoc::Sequence { .. } => f.write_str("sequence start"),
168+
MatcherLoc::SequenceKleeneOpNoSep { .. } => f.write_str("sequence end"),
169+
MatcherLoc::SequenceKleeneOpAfterSep { .. } => f.write_str("sequence end"),
170+
}
171+
}
172+
}
173+
132174
pub(super) fn compute_locs(matcher: &[TokenTree]) -> Vec<MatcherLoc> {
133175
fn inner(
134176
tts: &[TokenTree],
@@ -398,6 +440,10 @@ impl TtParser {
398440
}
399441
}
400442

443+
pub(super) fn has_no_remaining_items_for_step(&self) -> bool {
444+
self.cur_mps.is_empty()
445+
}
446+
401447
/// Process the matcher positions of `cur_mps` until it is empty. In the process, this will
402448
/// produce more mps in `next_mps` and `bb_mps`.
403449
///

‎compiler/rustc_expand/src/mbe/macro_rules.rs

+29-10
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ fn expand_macro<'cx>(
337337
return result;
338338
}
339339

340-
let Some((token, label)) = tracker.best_failure else {
340+
let Some((token, label, remaining_matcher)) = tracker.best_failure else {
341341
return tracker.result.expect("must have encountered Error or ErrorReported");
342342
};
343343

@@ -351,6 +351,12 @@ fn expand_macro<'cx>(
351351

352352
annotate_doc_comment(&mut err, sess.source_map(), span);
353353

354+
if let Some(span) = remaining_matcher.span() {
355+
err.span_note(span, format!("while trying to match {remaining_matcher}"));
356+
} else {
357+
err.note(format!("while trying to match {remaining_matcher}"));
358+
}
359+
354360
// Check whether there's a missing comma in this macro call, like `println!("{}" a);`
355361
if let Some((arg, comma_span)) = arg.add_comma() {
356362
for lhs in lhses {
@@ -379,17 +385,22 @@ fn expand_macro<'cx>(
379385
}
380386

381387
/// The tracker used for the slow error path that collects useful info for diagnostics.
382-
struct CollectTrackerAndEmitter<'a, 'cx> {
388+
struct CollectTrackerAndEmitter<'a, 'cx, 'matcher> {
383389
cx: &'a mut ExtCtxt<'cx>,
390+
remaining_matcher: Option<&'matcher MatcherLoc>,
384391
/// Which arm's failure should we report? (the one furthest along)
385-
best_failure: Option<(Token, &'static str)>,
392+
best_failure: Option<(Token, &'static str, MatcherLoc)>,
386393
root_span: Span,
387394
result: Option<Box<dyn MacResult + 'cx>>,
388395
}
389396

390-
impl<'a, 'cx, 'matcher> Tracker<'matcher> for CollectTrackerAndEmitter<'a, 'cx> {
391-
fn before_match_loc(&mut self, _parser: &TtParser, _matcher: &'matcher MatcherLoc) {
392-
// Empty for now.
397+
impl<'a, 'cx, 'matcher> Tracker<'matcher> for CollectTrackerAndEmitter<'a, 'cx, 'matcher> {
398+
fn before_match_loc(&mut self, parser: &TtParser, matcher: &'matcher MatcherLoc) {
399+
if self.remaining_matcher.is_none()
400+
|| (parser.has_no_remaining_items_for_step() && *matcher != MatcherLoc::Eof)
401+
{
402+
self.remaining_matcher = Some(matcher);
403+
}
393404
}
394405

395406
fn after_arm(&mut self, result: &NamedParseResult) {
@@ -398,8 +409,16 @@ impl<'a, 'cx, 'matcher> Tracker<'matcher> for CollectTrackerAndEmitter<'a, 'cx>
398409
unreachable!("should not collect detailed info for successful macro match");
399410
}
400411
Failure(token, msg) => match self.best_failure {
401-
Some((ref best_token, _)) if best_token.span.lo() >= token.span.lo() => {}
402-
_ => self.best_failure = Some((token.clone(), msg)),
412+
Some((ref best_token, _, _)) if best_token.span.lo() >= token.span.lo() => {}
413+
_ => {
414+
self.best_failure = Some((
415+
token.clone(),
416+
msg,
417+
self.remaining_matcher
418+
.expect("must have collected matcher already")
419+
.clone(),
420+
))
421+
}
403422
},
404423
Error(err_sp, msg) => {
405424
let span = err_sp.substitute_dummy(self.root_span);
@@ -415,9 +434,9 @@ impl<'a, 'cx, 'matcher> Tracker<'matcher> for CollectTrackerAndEmitter<'a, 'cx>
415434
}
416435
}
417436

418-
impl<'a, 'cx> CollectTrackerAndEmitter<'a, 'cx> {
437+
impl<'a, 'cx> CollectTrackerAndEmitter<'a, 'cx, '_> {
419438
fn new(cx: &'a mut ExtCtxt<'cx>, root_span: Span) -> Self {
420-
Self { cx, best_failure: None, root_span, result: None }
439+
Self { cx, remaining_matcher: None, best_failure: None, root_span, result: None }
421440
}
422441
}
423442

‎src/test/ui/array-slice-vec/vec-macro-with-comma-only.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error: no rules expected the token `,`
33
|
44
LL | vec![,];
55
| ^ no rules expected this token in macro call
6+
|
7+
= note: while trying to match end of macro
68

79
error: aborting due to previous error
810

‎src/test/ui/const-generics/min_const_generics/macro-fail.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ LL | macro_rules! gimme_a_const {
5353
...
5454
LL | let _fail = Example::<gimme_a_const!()>;
5555
| ^^^^^^^^^^^^^^^^ missing tokens in macro arguments
56+
|
57+
note: while trying to match meta-variable `$rusty:ident`
58+
--> $DIR/macro-fail.rs:28:8
59+
|
60+
LL | ($rusty: ident) => {{ let $rusty = 3; *&$rusty }}
61+
| ^^^^^^^^^^^^^
5662

5763
error[E0747]: type provided when a constant was expected
5864
--> $DIR/macro-fail.rs:14:33

‎src/test/ui/editions/edition-keywords-2015-2015-parsing.stderr

+12
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,24 @@ error: no rules expected the token `r#async`
33
|
44
LL | r#async = consumes_async!(r#async);
55
| ^^^^^^^ no rules expected this token in macro call
6+
|
7+
note: while trying to match `async`
8+
--> $DIR/auxiliary/edition-kw-macro-2015.rs:17:6
9+
|
10+
LL | (async) => (1)
11+
| ^^^^^
612

713
error: no rules expected the token `async`
814
--> $DIR/edition-keywords-2015-2015-parsing.rs:17:35
915
|
1016
LL | r#async = consumes_async_raw!(async);
1117
| ^^^^^ no rules expected this token in macro call
18+
|
19+
note: while trying to match `r#async`
20+
--> $DIR/auxiliary/edition-kw-macro-2015.rs:22:6
21+
|
22+
LL | (r#async) => (1)
23+
| ^^^^^^^
1224

1325
error: aborting due to 2 previous errors
1426

‎src/test/ui/editions/edition-keywords-2015-2018-parsing.stderr

+12
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,24 @@ error: no rules expected the token `r#async`
33
|
44
LL | r#async = consumes_async!(r#async);
55
| ^^^^^^^ no rules expected this token in macro call
6+
|
7+
note: while trying to match `async`
8+
--> $DIR/auxiliary/edition-kw-macro-2018.rs:17:6
9+
|
10+
LL | (async) => (1)
11+
| ^^^^^
612

713
error: no rules expected the token `async`
814
--> $DIR/edition-keywords-2015-2018-parsing.rs:17:35
915
|
1016
LL | r#async = consumes_async_raw!(async);
1117
| ^^^^^ no rules expected this token in macro call
18+
|
19+
note: while trying to match `r#async`
20+
--> $DIR/auxiliary/edition-kw-macro-2018.rs:22:6
21+
|
22+
LL | (r#async) => (1)
23+
| ^^^^^^^
1224

1325
error: aborting due to 2 previous errors
1426

‎src/test/ui/editions/edition-keywords-2018-2015-parsing.stderr

+12
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,24 @@ error: no rules expected the token `r#async`
2525
|
2626
LL | r#async = consumes_async!(r#async);
2727
| ^^^^^^^ no rules expected this token in macro call
28+
|
29+
note: while trying to match `async`
30+
--> $DIR/auxiliary/edition-kw-macro-2015.rs:17:6
31+
|
32+
LL | (async) => (1)
33+
| ^^^^^
2834

2935
error: no rules expected the token `async`
3036
--> $DIR/edition-keywords-2018-2015-parsing.rs:21:35
3137
|
3238
LL | r#async = consumes_async_raw!(async);
3339
| ^^^^^ no rules expected this token in macro call
40+
|
41+
note: while trying to match `r#async`
42+
--> $DIR/auxiliary/edition-kw-macro-2015.rs:22:6
43+
|
44+
LL | (r#async) => (1)
45+
| ^^^^^^^
3446

3547
error: macro expansion ends with an incomplete expression: expected one of `move`, `|`, or `||`
3648
--> $DIR/auxiliary/edition-kw-macro-2015.rs:27:23

‎src/test/ui/editions/edition-keywords-2018-2018-parsing.stderr

+12
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,24 @@ error: no rules expected the token `r#async`
2525
|
2626
LL | r#async = consumes_async!(r#async);
2727
| ^^^^^^^ no rules expected this token in macro call
28+
|
29+
note: while trying to match `async`
30+
--> $DIR/auxiliary/edition-kw-macro-2018.rs:17:6
31+
|
32+
LL | (async) => (1)
33+
| ^^^^^
2834

2935
error: no rules expected the token `async`
3036
--> $DIR/edition-keywords-2018-2018-parsing.rs:21:35
3137
|
3238
LL | r#async = consumes_async_raw!(async);
3339
| ^^^^^ no rules expected this token in macro call
40+
|
41+
note: while trying to match `r#async`
42+
--> $DIR/auxiliary/edition-kw-macro-2018.rs:22:6
43+
|
44+
LL | (r#async) => (1)
45+
| ^^^^^^^
3446

3547
error: macro expansion ends with an incomplete expression: expected one of `move`, `|`, or `||`
3648
--> $DIR/auxiliary/edition-kw-macro-2018.rs:27:23

‎src/test/ui/empty/empty-comment.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ LL | macro_rules! one_arg_macro {
66
...
77
LL | one_arg_macro!(/**/);
88
| ^^^^^^^^^^^^^^^^^^^^ missing tokens in macro arguments
9+
|
10+
note: while trying to match meta-variable `$fmt:expr`
11+
--> $DIR/empty-comment.rs:6:6
12+
|
13+
LL | ($fmt:expr) => (print!(concat!($fmt, "\n")));
14+
| ^^^^^^^^^
915

1016
error: aborting due to previous error
1117

‎src/test/ui/fail-simple.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ error: no rules expected the token `@`
33
|
44
LL | panic!(@);
55
| ^ no rules expected this token in macro call
6+
|
7+
= note: while trying to match end of macro
68

79
error: aborting due to previous error
810

‎src/test/ui/issues/issue-7970a.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ LL | macro_rules! one_arg_macro {
66
...
77
LL | one_arg_macro!();
88
| ^^^^^^^^^^^^^^^^ missing tokens in macro arguments
9+
|
10+
note: while trying to match meta-variable `$fmt:expr`
11+
--> $DIR/issue-7970a.rs:2:6
12+
|
13+
LL | ($fmt:expr) => (print!(concat!($fmt, "\n")));
14+
| ^^^^^^^^^
915

1016
error: aborting due to previous error
1117

‎src/test/ui/macros/assert-trailing-junk.with-generic-asset.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ LL | assert!(true, "whatever" blah);
1717
| -^^^^ no rules expected this token in macro call
1818
| |
1919
| help: missing comma here
20+
|
21+
= note: while trying to match sequence start
2022

2123
error: unexpected string literal
2224
--> $DIR/assert-trailing-junk.rs:18:18
@@ -33,6 +35,8 @@ LL | assert!(true "whatever" blah);
3335
| -^^^^ no rules expected this token in macro call
3436
| |
3537
| help: missing comma here
38+
|
39+
= note: while trying to match sequence start
3640

3741
error: macro requires an expression as an argument
3842
--> $DIR/assert-trailing-junk.rs:22:5

‎src/test/ui/macros/assert-trailing-junk.without-generic-asset.stderr

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ LL | assert!(true, "whatever" blah);
1717
| -^^^^ no rules expected this token in macro call
1818
| |
1919
| help: missing comma here
20+
|
21+
= note: while trying to match sequence start
2022

2123
error: unexpected string literal
2224
--> $DIR/assert-trailing-junk.rs:18:18
@@ -33,6 +35,8 @@ LL | assert!(true "whatever" blah);
3335
| -^^^^ no rules expected this token in macro call
3436
| |
3537
| help: missing comma here
38+
|
39+
= note: while trying to match sequence start
3640

3741
error: macro requires an expression as an argument
3842
--> $DIR/assert-trailing-junk.rs:22:5

‎src/test/ui/macros/macro-at-most-once-rep-2015.stderr

+54
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ LL | macro_rules! foo {
1212
...
1313
LL | foo!(a?);
1414
| ^ no rules expected this token in macro call
15+
|
16+
= note: while trying to match sequence end
1517

1618
error: no rules expected the token `?`
1719
--> $DIR/macro-at-most-once-rep-2015.rs:26:11
@@ -21,6 +23,8 @@ LL | macro_rules! foo {
2123
...
2224
LL | foo!(a?a);
2325
| ^ no rules expected this token in macro call
26+
|
27+
= note: while trying to match sequence end
2428

2529
error: no rules expected the token `?`
2630
--> $DIR/macro-at-most-once-rep-2015.rs:27:11
@@ -30,6 +34,8 @@ LL | macro_rules! foo {
3034
...
3135
LL | foo!(a?a?a);
3236
| ^ no rules expected this token in macro call
37+
|
38+
= note: while trying to match sequence end
3339

3440
error: unexpected end of macro invocation
3541
--> $DIR/macro-at-most-once-rep-2015.rs:29:5
@@ -39,6 +45,12 @@ LL | macro_rules! barplus {
3945
...
4046
LL | barplus!();
4147
| ^^^^^^^^^^ missing tokens in macro arguments
48+
|
49+
note: while trying to match `+`
50+
--> $DIR/macro-at-most-once-rep-2015.rs:15:11
51+
|
52+
LL | ($(a)?+) => {}; // ok. matches "a+" and "+"
53+
| ^
4254

4355
error: unexpected end of macro invocation
4456
--> $DIR/macro-at-most-once-rep-2015.rs:30:15
@@ -48,6 +60,12 @@ LL | macro_rules! barplus {
4860
...
4961
LL | barplus!(a);
5062
| ^ missing tokens in macro arguments
63+
|
64+
note: while trying to match `+`
65+
--> $DIR/macro-at-most-once-rep-2015.rs:15:11
66+
|
67+
LL | ($(a)?+) => {}; // ok. matches "a+" and "+"
68+
| ^
5169

5270
error: no rules expected the token `?`
5371
--> $DIR/macro-at-most-once-rep-2015.rs:31:15
@@ -57,6 +75,12 @@ LL | macro_rules! barplus {
5775
...
5876
LL | barplus!(a?);
5977
| ^ no rules expected this token in macro call
78+
|
79+
note: while trying to match `+`
80+
--> $DIR/macro-at-most-once-rep-2015.rs:15:11
81+
|
82+
LL | ($(a)?+) => {}; // ok. matches "a+" and "+"
83+
| ^
6084

6185
error: no rules expected the token `?`
6286
--> $DIR/macro-at-most-once-rep-2015.rs:32:15
@@ -66,6 +90,12 @@ LL | macro_rules! barplus {
6690
...
6791
LL | barplus!(a?a);
6892
| ^ no rules expected this token in macro call
93+
|
94+
note: while trying to match `+`
95+
--> $DIR/macro-at-most-once-rep-2015.rs:15:11
96+
|
97+
LL | ($(a)?+) => {}; // ok. matches "a+" and "+"
98+
| ^
6999

70100
error: unexpected end of macro invocation
71101
--> $DIR/macro-at-most-once-rep-2015.rs:36:5
@@ -75,6 +105,12 @@ LL | macro_rules! barstar {
75105
...
76106
LL | barstar!();
77107
| ^^^^^^^^^^ missing tokens in macro arguments
108+
|
109+
note: while trying to match `*`
110+
--> $DIR/macro-at-most-once-rep-2015.rs:19:11
111+
|
112+
LL | ($(a)?*) => {}; // ok. matches "a*" and "*"
113+
| ^
78114

79115
error: unexpected end of macro invocation
80116
--> $DIR/macro-at-most-once-rep-2015.rs:37:15
@@ -84,6 +120,12 @@ LL | macro_rules! barstar {
84120
...
85121
LL | barstar!(a);
86122
| ^ missing tokens in macro arguments
123+
|
124+
note: while trying to match `*`
125+
--> $DIR/macro-at-most-once-rep-2015.rs:19:11
126+
|
127+
LL | ($(a)?*) => {}; // ok. matches "a*" and "*"
128+
| ^
87129

88130
error: no rules expected the token `?`
89131
--> $DIR/macro-at-most-once-rep-2015.rs:38:15
@@ -93,6 +135,12 @@ LL | macro_rules! barstar {
93135
...
94136
LL | barstar!(a?);
95137
| ^ no rules expected this token in macro call
138+
|
139+
note: while trying to match `*`
140+
--> $DIR/macro-at-most-once-rep-2015.rs:19:11
141+
|
142+
LL | ($(a)?*) => {}; // ok. matches "a*" and "*"
143+
| ^
96144

97145
error: no rules expected the token `?`
98146
--> $DIR/macro-at-most-once-rep-2015.rs:39:15
@@ -102,6 +150,12 @@ LL | macro_rules! barstar {
102150
...
103151
LL | barstar!(a?a);
104152
| ^ no rules expected this token in macro call
153+
|
154+
note: while trying to match `*`
155+
--> $DIR/macro-at-most-once-rep-2015.rs:19:11
156+
|
157+
LL | ($(a)?*) => {}; // ok. matches "a*" and "*"
158+
| ^
105159

106160
error: aborting due to 12 previous errors
107161

‎src/test/ui/macros/macro-at-most-once-rep-2018.stderr

+54
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ LL | macro_rules! foo {
1212
...
1313
LL | foo!(a?);
1414
| ^ no rules expected this token in macro call
15+
|
16+
= note: while trying to match sequence end
1517

1618
error: no rules expected the token `?`
1719
--> $DIR/macro-at-most-once-rep-2018.rs:26:11
@@ -21,6 +23,8 @@ LL | macro_rules! foo {
2123
...
2224
LL | foo!(a?a);
2325
| ^ no rules expected this token in macro call
26+
|
27+
= note: while trying to match sequence end
2428

2529
error: no rules expected the token `?`
2630
--> $DIR/macro-at-most-once-rep-2018.rs:27:11
@@ -30,6 +34,8 @@ LL | macro_rules! foo {
3034
...
3135
LL | foo!(a?a?a);
3236
| ^ no rules expected this token in macro call
37+
|
38+
= note: while trying to match sequence end
3339

3440
error: unexpected end of macro invocation
3541
--> $DIR/macro-at-most-once-rep-2018.rs:29:5
@@ -39,6 +45,12 @@ LL | macro_rules! barplus {
3945
...
4046
LL | barplus!();
4147
| ^^^^^^^^^^ missing tokens in macro arguments
48+
|
49+
note: while trying to match `+`
50+
--> $DIR/macro-at-most-once-rep-2018.rs:15:11
51+
|
52+
LL | ($(a)?+) => {}; // ok. matches "a+" and "+"
53+
| ^
4254

4355
error: unexpected end of macro invocation
4456
--> $DIR/macro-at-most-once-rep-2018.rs:30:15
@@ -48,6 +60,12 @@ LL | macro_rules! barplus {
4860
...
4961
LL | barplus!(a);
5062
| ^ missing tokens in macro arguments
63+
|
64+
note: while trying to match `+`
65+
--> $DIR/macro-at-most-once-rep-2018.rs:15:11
66+
|
67+
LL | ($(a)?+) => {}; // ok. matches "a+" and "+"
68+
| ^
5169

5270
error: no rules expected the token `?`
5371
--> $DIR/macro-at-most-once-rep-2018.rs:31:15
@@ -57,6 +75,12 @@ LL | macro_rules! barplus {
5775
...
5876
LL | barplus!(a?);
5977
| ^ no rules expected this token in macro call
78+
|
79+
note: while trying to match `+`
80+
--> $DIR/macro-at-most-once-rep-2018.rs:15:11
81+
|
82+
LL | ($(a)?+) => {}; // ok. matches "a+" and "+"
83+
| ^
6084

6185
error: no rules expected the token `?`
6286
--> $DIR/macro-at-most-once-rep-2018.rs:32:15
@@ -66,6 +90,12 @@ LL | macro_rules! barplus {
6690
...
6791
LL | barplus!(a?a);
6892
| ^ no rules expected this token in macro call
93+
|
94+
note: while trying to match `+`
95+
--> $DIR/macro-at-most-once-rep-2018.rs:15:11
96+
|
97+
LL | ($(a)?+) => {}; // ok. matches "a+" and "+"
98+
| ^
6999

70100
error: unexpected end of macro invocation
71101
--> $DIR/macro-at-most-once-rep-2018.rs:36:5
@@ -75,6 +105,12 @@ LL | macro_rules! barstar {
75105
...
76106
LL | barstar!();
77107
| ^^^^^^^^^^ missing tokens in macro arguments
108+
|
109+
note: while trying to match `*`
110+
--> $DIR/macro-at-most-once-rep-2018.rs:19:11
111+
|
112+
LL | ($(a)?*) => {}; // ok. matches "a*" and "*"
113+
| ^
78114

79115
error: unexpected end of macro invocation
80116
--> $DIR/macro-at-most-once-rep-2018.rs:37:15
@@ -84,6 +120,12 @@ LL | macro_rules! barstar {
84120
...
85121
LL | barstar!(a);
86122
| ^ missing tokens in macro arguments
123+
|
124+
note: while trying to match `*`
125+
--> $DIR/macro-at-most-once-rep-2018.rs:19:11
126+
|
127+
LL | ($(a)?*) => {}; // ok. matches "a*" and "*"
128+
| ^
87129

88130
error: no rules expected the token `?`
89131
--> $DIR/macro-at-most-once-rep-2018.rs:38:15
@@ -93,6 +135,12 @@ LL | macro_rules! barstar {
93135
...
94136
LL | barstar!(a?);
95137
| ^ no rules expected this token in macro call
138+
|
139+
note: while trying to match `*`
140+
--> $DIR/macro-at-most-once-rep-2018.rs:19:11
141+
|
142+
LL | ($(a)?*) => {}; // ok. matches "a*" and "*"
143+
| ^
96144

97145
error: no rules expected the token `?`
98146
--> $DIR/macro-at-most-once-rep-2018.rs:39:15
@@ -102,6 +150,12 @@ LL | macro_rules! barstar {
102150
...
103151
LL | barstar!(a?a);
104152
| ^ no rules expected this token in macro call
153+
|
154+
note: while trying to match `*`
155+
--> $DIR/macro-at-most-once-rep-2018.rs:19:11
156+
|
157+
LL | ($(a)?*) => {}; // ok. matches "a*" and "*"
158+
| ^
105159

106160
error: aborting due to 12 previous errors
107161

‎src/test/ui/macros/macro-non-lifetime.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ LL | macro_rules! m { ($x:lifetime) => { } }
66
...
77
LL | m!(a);
88
| ^ no rules expected this token in macro call
9+
|
10+
note: while trying to match meta-variable `$x:lifetime`
11+
--> $DIR/macro-non-lifetime.rs:3:19
12+
|
13+
LL | macro_rules! m { ($x:lifetime) => { } }
14+
| ^^^^^^^^^^^
915

1016
error: aborting due to previous error
1117

‎src/test/ui/macros/missing-comma.stderr

+36
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ LL | foo!(a b);
1414
| -^ no rules expected this token in macro call
1515
| |
1616
| help: missing comma here
17+
|
18+
note: while trying to match meta-variable `$a:ident`
19+
--> $DIR/missing-comma.rs:2:6
20+
|
21+
LL | ($a:ident) => ();
22+
| ^^^^^^^^
1723

1824
error: no rules expected the token `e`
1925
--> $DIR/missing-comma.rs:23:21
@@ -25,6 +31,12 @@ LL | foo!(a, b, c, d e);
2531
| -^ no rules expected this token in macro call
2632
| |
2733
| help: missing comma here
34+
|
35+
note: while trying to match meta-variable `$d:ident`
36+
--> $DIR/missing-comma.rs:5:36
37+
|
38+
LL | ($a:ident, $b:ident, $c:ident, $d:ident) => ();
39+
| ^^^^^^^^
2840

2941
error: no rules expected the token `d`
3042
--> $DIR/missing-comma.rs:25:18
@@ -36,6 +48,12 @@ LL | foo!(a, b, c d, e);
3648
| -^ no rules expected this token in macro call
3749
| |
3850
| help: missing comma here
51+
|
52+
note: while trying to match meta-variable `$c:ident`
53+
--> $DIR/missing-comma.rs:4:26
54+
|
55+
LL | ($a:ident, $b:ident, $c:ident) => ();
56+
| ^^^^^^^^
3957

4058
error: no rules expected the token `d`
4159
--> $DIR/missing-comma.rs:27:18
@@ -45,6 +63,12 @@ LL | macro_rules! foo {
4563
...
4664
LL | foo!(a, b, c d e);
4765
| ^ no rules expected this token in macro call
66+
|
67+
note: while trying to match meta-variable `$c:ident`
68+
--> $DIR/missing-comma.rs:4:26
69+
|
70+
LL | ($a:ident, $b:ident, $c:ident) => ();
71+
| ^^^^^^^^
4872

4973
error: unexpected end of macro invocation
5074
--> $DIR/missing-comma.rs:29:23
@@ -54,6 +78,12 @@ LL | macro_rules! bar {
5478
...
5579
LL | bar!(Level::Error, );
5680
| ^ missing tokens in macro arguments
81+
|
82+
note: while trying to match meta-variable `$arg:tt`
83+
--> $DIR/missing-comma.rs:10:19
84+
|
85+
LL | ($lvl:expr, $($arg:tt)+) => {}
86+
| ^^^^^^^
5787

5888
error: no rules expected the token `,`
5989
--> $DIR/missing-comma.rs:32:38
@@ -63,6 +93,12 @@ LL | macro_rules! check {
6393
...
6494
LL | check!(<str as Debug>::fmt, "fmt",);
6595
| ^ no rules expected this token in macro call
96+
|
97+
note: while trying to match meta-variable `$expected:expr`
98+
--> $DIR/missing-comma.rs:14:14
99+
|
100+
LL | ($ty:ty, $expected:expr) => {};
101+
| ^^^^^^^^^^^^^^
66102

67103
error: aborting due to 7 previous errors
68104

‎src/test/ui/macros/nonterminal-matching.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ LL | n!(a $nt_item b);
1010
LL | complex_nonterminal!(enum E {});
1111
| ------------------------------- in this macro invocation
1212
|
13+
note: while trying to match `enum E {}`
14+
--> $DIR/nonterminal-matching.rs:15:15
15+
|
16+
LL | macro n(a $nt_item b) {
17+
| ^^^^^^^^
18+
...
19+
LL | complex_nonterminal!(enum E {});
20+
| ------------------------------- in this macro invocation
1321
= note: this error originates in the macro `complex_nonterminal` (in Nightly builds, run with -Z macro-backtrace for more info)
1422

1523
error: aborting due to previous error

‎src/test/ui/macros/trace_faulty_macros.stderr

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ LL | my_faulty_macro!(bcd);
1010
LL | my_faulty_macro!();
1111
| ------------------ in this macro invocation
1212
|
13+
= note: while trying to match end of macro
1314
= note: this error originates in the macro `my_faulty_macro` (in Nightly builds, run with -Z macro-backtrace for more info)
1415

1516
note: trace_macro

‎src/test/ui/or-patterns/or-patterns-syntactic-fail-2018.stderr

+12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ LL | macro_rules! accept_pat {
66
...
77
LL | accept_pat!(p | q);
88
| ^ no rules expected this token in macro call
9+
|
10+
note: while trying to match meta-variable `$p:pat`
11+
--> $DIR/or-patterns-syntactic-fail-2018.rs:9:6
12+
|
13+
LL | ($p:pat) => {};
14+
| ^^^^^^
915

1016
error: no rules expected the token `|`
1117
--> $DIR/or-patterns-syntactic-fail-2018.rs:13:13
@@ -15,6 +21,12 @@ LL | macro_rules! accept_pat {
1521
...
1622
LL | accept_pat!(|p| q);
1723
| ^ no rules expected this token in macro call
24+
|
25+
note: while trying to match meta-variable `$p:pat`
26+
--> $DIR/or-patterns-syntactic-fail-2018.rs:9:6
27+
|
28+
LL | ($p:pat) => {};
29+
| ^^^^^^
1830

1931
error: aborting due to 2 previous errors
2032

‎src/test/ui/parser/macro/macro-doc-comments-1.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ LL | //! Inner
99
| |
1010
| no rules expected this token in macro call
1111
| inner doc comments expand to `#![doc = "..."]`, which is what this macro attempted to match
12+
|
13+
note: while trying to match `[`
14+
--> $DIR/macro-doc-comments-1.rs:2:7
15+
|
16+
LL | (#[$outer:meta]) => ()
17+
| ^
1218

1319
error: aborting due to previous error
1420

‎src/test/ui/parser/macro/macro-doc-comments-2.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ LL | /// Outer
99
| |
1010
| no rules expected this token in macro call
1111
| outer doc comments expand to `#[doc = "..."]`, which is what this macro attempted to match
12+
|
13+
note: while trying to match `!`
14+
--> $DIR/macro-doc-comments-2.rs:2:7
15+
|
16+
LL | (#![$inner:meta]) => ()
17+
| ^
1218

1319
error: aborting due to previous error
1420

‎src/test/ui/rfc-2294-if-let-guard/feature-gate.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ LL | macro_rules! use_expr {
7272
...
7373
LL | use_expr!(let 0 = 1);
7474
| ^^^ no rules expected this token in macro call
75+
|
76+
note: while trying to match meta-variable `$e:expr`
77+
--> $DIR/feature-gate.rs:61:10
78+
|
79+
LL | ($e:expr) => {
80+
| ^^^^^^^
7581

7682
error[E0658]: `if let` guards are experimental
7783
--> $DIR/feature-gate.rs:7:12

‎src/test/ui/rfc-2497-if-let-chains/feature-gate.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ LL | macro_rules! use_expr {
1818
...
1919
LL | use_expr!(let 0 = 1);
2020
| ^^^ no rules expected this token in macro call
21+
|
22+
note: while trying to match meta-variable `$e:expr`
23+
--> $DIR/feature-gate.rs:50:10
24+
|
25+
LL | ($e:expr) => {
26+
| ^^^^^^^
2127

2228
error[E0658]: `let` expressions in this position are unstable
2329
--> $DIR/feature-gate.rs:14:16

‎src/test/ui/underscore-ident-matcher.stderr

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ LL | macro_rules! identity {
66
...
77
LL | let identity!(_) = 10;
88
| ^ no rules expected this token in macro call
9+
|
10+
note: while trying to match meta-variable `$i:ident`
11+
--> $DIR/underscore-ident-matcher.rs:2:6
12+
|
13+
LL | ($i: ident) => (
14+
| ^^^^^^^^^
915

1016
error: aborting due to previous error
1117

0 commit comments

Comments
 (0)
Please sign in to comment.