Skip to content

Commit e5cd1ed

Browse files
committed
Reword incorrect macro invocation primary label
1 parent 34bd86a commit e5cd1ed

20 files changed

+57
-45
lines changed

src/libsyntax/ext/tt/macro_parser.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ pub enum ParseResult<T> {
281281
Success(T),
282282
/// Arm failed to match. If the second parameter is `token::Eof`, it indicates an unexpected
283283
/// end of macro invocation. Otherwise, it indicates that no rules expected the given token.
284-
Failure(syntax_pos::Span, Token),
284+
Failure(syntax_pos::Span, Token, String),
285285
/// Fatal error (malformed macro?). Abort compilation.
286286
Error(syntax_pos::Span, String),
287287
}
@@ -698,7 +698,7 @@ pub fn parse(
698698
parser.span,
699699
) {
700700
Success(_) => {}
701-
Failure(sp, tok) => return Failure(sp, tok),
701+
Failure(sp, tok, t) => return Failure(sp, tok, t),
702702
Error(sp, msg) => return Error(sp, msg),
703703
}
704704

@@ -710,7 +710,7 @@ pub fn parse(
710710
// Error messages here could be improved with links to original rules.
711711

712712
// If we reached the EOF, check that there is EXACTLY ONE possible matcher. Otherwise,
713-
// either the parse is ambiguous (which should never happen) or their is a syntax error.
713+
// either the parse is ambiguous (which should never happen) or there is a syntax error.
714714
if token_name_eq(&parser.token, &token::Eof) {
715715
if eof_items.len() == 1 {
716716
let matches = eof_items[0]
@@ -731,6 +731,7 @@ pub fn parse(
731731
sess.source_map().next_point(parser.span)
732732
},
733733
token::Eof,
734+
"missing tokens in macro arguments".to_string(),
734735
);
735736
}
736737
}
@@ -766,7 +767,11 @@ pub fn parse(
766767
// If there are no possible next positions AND we aren't waiting for the black-box parser,
767768
// then there is a syntax error.
768769
else if bb_items.is_empty() && next_items.is_empty() {
769-
return Failure(parser.span, parser.token);
770+
return Failure(
771+
parser.span,
772+
parser.token,
773+
"no rules expected this token in macro call".to_string(),
774+
);
770775
}
771776
// Dump all possible `next_items` into `cur_items` for the next iteration.
772777
else if !next_items.is_empty() {

src/libsyntax/ext/tt/macro_rules.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use {ast, attr};
1212
use syntax_pos::{Span, DUMMY_SP};
1313
use edition::Edition;
14+
use errors::FatalError;
1415
use ext::base::{DummyResult, ExtCtxt, MacResult, SyntaxExtension};
1516
use ext::base::{NormalTT, TTMacroExpander};
1617
use ext::expand::{AstFragment, AstFragmentKind};
@@ -130,6 +131,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
130131
// Which arm's failure should we report? (the one furthest along)
131132
let mut best_fail_spot = DUMMY_SP;
132133
let mut best_fail_tok = None;
134+
let mut best_fail_text = None;
133135

134136
for (i, lhs) in lhses.iter().enumerate() { // try each arm's matchers
135137
let lhs_tt = match *lhs {
@@ -185,9 +187,10 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
185187
macro_ident: name
186188
})
187189
}
188-
Failure(sp, tok) => if sp.lo() >= best_fail_spot.lo() {
190+
Failure(sp, tok, t) => if sp.lo() >= best_fail_spot.lo() {
189191
best_fail_spot = sp;
190192
best_fail_tok = Some(tok);
193+
best_fail_text = Some(t);
191194
},
192195
Error(err_sp, ref msg) => {
193196
cx.span_fatal(err_sp.substitute_dummy(sp), &msg[..])
@@ -198,7 +201,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
198201
let best_fail_msg = parse_failure_msg(best_fail_tok.expect("ran no matchers"));
199202
let span = best_fail_spot.substitute_dummy(sp);
200203
let mut err = cx.struct_span_err(span, &best_fail_msg);
201-
err.span_label(span, best_fail_msg);
204+
err.span_label(span, best_fail_text.unwrap_or(best_fail_msg));
202205
if let Some(sp) = def_span {
203206
if cx.source_map().span_to_filename(sp).is_real() && !sp.is_dummy() {
204207
err.span_label(cx.source_map().def_span(sp), "when calling this macro");
@@ -278,9 +281,13 @@ pub fn compile(sess: &ParseSess, features: &Features, def: &ast::Item, edition:
278281

279282
let argument_map = match parse(sess, body.stream(), &argument_gram, None, true) {
280283
Success(m) => m,
281-
Failure(sp, tok) => {
284+
Failure(sp, tok, t) => {
282285
let s = parse_failure_msg(tok);
283-
sess.span_diagnostic.span_fatal(sp.substitute_dummy(def.span), &s).raise();
286+
let sp = sp.substitute_dummy(def.span);
287+
let mut err = sess.span_diagnostic.struct_span_fatal(sp, &s);
288+
err.span_label(sp, t);
289+
err.emit();
290+
FatalError.raise();
284291
}
285292
Error(sp, s) => {
286293
sess.span_diagnostic.span_fatal(sp.substitute_dummy(def.span), &s).raise();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ error: no rules expected the token `r#async`
22
--> $DIR/edition-keywords-2015-2015-parsing.rs:22:31
33
|
44
LL | r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async`
5-
| ^^^^^^^ no rules expected the token `r#async`
5+
| ^^^^^^^ no rules expected this token in macro call
66

77
error: no rules expected the token `async`
88
--> $DIR/edition-keywords-2015-2015-parsing.rs:23:35
99
|
1010
LL | r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async`
11-
| ^^^^^ no rules expected the token `async`
11+
| ^^^^^ no rules expected this token in macro call
1212

1313
error: aborting due to 2 previous errors
1414

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ error: no rules expected the token `r#async`
22
--> $DIR/edition-keywords-2015-2018-parsing.rs:22:31
33
|
44
LL | r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async`
5-
| ^^^^^^^ no rules expected the token `r#async`
5+
| ^^^^^^^ no rules expected this token in macro call
66

77
error: no rules expected the token `async`
88
--> $DIR/edition-keywords-2015-2018-parsing.rs:23:35
99
|
1010
LL | r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async`
11-
| ^^^^^ no rules expected the token `async`
11+
| ^^^^^ no rules expected this token in macro call
1212

1313
error: aborting due to 2 previous errors
1414

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ error: no rules expected the token `r#async`
1414
--> $DIR/edition-keywords-2018-2015-parsing.rs:22:31
1515
|
1616
LL | r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async`
17-
| ^^^^^^^ no rules expected the token `r#async`
17+
| ^^^^^^^ no rules expected this token in macro call
1818

1919
error: no rules expected the token `async`
2020
--> $DIR/edition-keywords-2018-2015-parsing.rs:23:35
2121
|
2222
LL | r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async`
23-
| ^^^^^ no rules expected the token `async`
23+
| ^^^^^ no rules expected this token in macro call
2424

2525
error: expected one of `move`, `|`, or `||`, found the end of the macro arm
2626
--> <::edition_kw_macro_2015::passes_ident macros>:1:25

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ error: no rules expected the token `r#async`
1414
--> $DIR/edition-keywords-2018-2018-parsing.rs:22:31
1515
|
1616
LL | r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async`
17-
| ^^^^^^^ no rules expected the token `r#async`
17+
| ^^^^^^^ no rules expected this token in macro call
1818

1919
error: no rules expected the token `async`
2020
--> $DIR/edition-keywords-2018-2018-parsing.rs:23:35
2121
|
2222
LL | r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async`
23-
| ^^^^^ no rules expected the token `async`
23+
| ^^^^^ no rules expected this token in macro call
2424

2525
error: expected one of `move`, `|`, or `||`, found the end of the macro arm
2626
--> <::edition_kw_macro_2018::passes_ident macros>:1:25

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | macro_rules! one_arg_macro {
55
| -------------------------- when calling this macro
66
...
77
LL | one_arg_macro!(/**/); //~ ERROR unexpected end
8-
| ^^^^^^^^^^^^^^^^^^^^^ unexpected end of macro invocation
8+
| ^^^^^^^^^^^^^^^^^^^^^ missing tokens in macro arguments
99

1010
error: aborting due to previous error
1111

src/test/ui/fail-simple.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: no rules expected the token `@`
22
--> $DIR/fail-simple.rs:12:12
33
|
44
LL | panic!(@); //~ ERROR no rules expected the token `@`
5-
| ^ no rules expected the token `@`
5+
| ^ no rules expected this token in macro call
66

77
error: aborting due to previous error
88

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | macro_rules! one_arg_macro {
55
| -------------------------- when calling this macro
66
...
77
LL | one_arg_macro!();
8-
| ^^^^^^^^^^^^^^^^^ unexpected end of macro invocation
8+
| ^^^^^^^^^^^^^^^^^ missing tokens in macro arguments
99

1010
error: aborting due to previous error
1111

src/test/ui/issues/issue-7970b.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: unexpected end of macro invocation
22
--> $DIR/issue-7970b.rs:13:1
33
|
44
LL | macro_rules! test {}
5-
| ^^^^^^^^^^^^^^^^^^^^
5+
| ^^^^^^^^^^^^^^^^^^^^ missing tokens in macro arguments
66

77
error: aborting due to previous error
88

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ LL | macro_rules! foo {
5555
| ---------------- when calling this macro
5656
...
5757
LL | foo!(a?); //~ ERROR no rules expected the token `?`
58-
| ^ no rules expected the token `?`
58+
| ^ no rules expected this token in macro call
5959

6060
error: no rules expected the token `?`
6161
--> $DIR/macro-at-most-once-rep-2018-feature-gate.rs:42:11
@@ -64,7 +64,7 @@ LL | macro_rules! foo {
6464
| ---------------- when calling this macro
6565
...
6666
LL | foo!(a?a); //~ ERROR no rules expected the token `?`
67-
| ^ no rules expected the token `?`
67+
| ^ no rules expected this token in macro call
6868

6969
error: no rules expected the token `?`
7070
--> $DIR/macro-at-most-once-rep-2018-feature-gate.rs:43:11
@@ -73,7 +73,7 @@ LL | macro_rules! foo {
7373
| ---------------- when calling this macro
7474
...
7575
LL | foo!(a?a?a); //~ ERROR no rules expected the token `?`
76-
| ^ no rules expected the token `?`
76+
| ^ no rules expected this token in macro call
7777

7878
error: aborting due to 10 previous errors
7979

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | macro_rules! foo {
1111
| ---------------- when calling this macro
1212
...
1313
LL | foo!(a?); //~ ERROR no rules expected the token `?`
14-
| ^ no rules expected the token `?`
14+
| ^ no rules expected this token in macro call
1515

1616
error: no rules expected the token `?`
1717
--> $DIR/macro-at-most-once-rep-2018.rs:37:11
@@ -20,7 +20,7 @@ LL | macro_rules! foo {
2020
| ---------------- when calling this macro
2121
...
2222
LL | foo!(a?a); //~ ERROR no rules expected the token `?`
23-
| ^ no rules expected the token `?`
23+
| ^ no rules expected this token in macro call
2424

2525
error: no rules expected the token `?`
2626
--> $DIR/macro-at-most-once-rep-2018.rs:38:11
@@ -29,7 +29,7 @@ LL | macro_rules! foo {
2929
| ---------------- when calling this macro
3030
...
3131
LL | foo!(a?a?a); //~ ERROR no rules expected the token `?`
32-
| ^ no rules expected the token `?`
32+
| ^ no rules expected this token in macro call
3333

3434
error: unexpected end of macro invocation
3535
--> $DIR/macro-at-most-once-rep-2018.rs:40:5
@@ -38,7 +38,7 @@ LL | macro_rules! barplus {
3838
| -------------------- when calling this macro
3939
...
4040
LL | barplus!(); //~ERROR unexpected end of macro invocation
41-
| ^^^^^^^^^^^ unexpected end of macro invocation
41+
| ^^^^^^^^^^^ missing tokens in macro arguments
4242

4343
error: unexpected end of macro invocation
4444
--> $DIR/macro-at-most-once-rep-2018.rs:41:15
@@ -47,7 +47,7 @@ LL | macro_rules! barplus {
4747
| -------------------- when calling this macro
4848
...
4949
LL | barplus!(a); //~ERROR unexpected end of macro invocation
50-
| ^ unexpected end of macro invocation
50+
| ^ missing tokens in macro arguments
5151

5252
error: no rules expected the token `?`
5353
--> $DIR/macro-at-most-once-rep-2018.rs:42:15
@@ -56,7 +56,7 @@ LL | macro_rules! barplus {
5656
| -------------------- when calling this macro
5757
...
5858
LL | barplus!(a?); //~ ERROR no rules expected the token `?`
59-
| ^ no rules expected the token `?`
59+
| ^ no rules expected this token in macro call
6060

6161
error: no rules expected the token `?`
6262
--> $DIR/macro-at-most-once-rep-2018.rs:43:15
@@ -65,7 +65,7 @@ LL | macro_rules! barplus {
6565
| -------------------- when calling this macro
6666
...
6767
LL | barplus!(a?a); //~ ERROR no rules expected the token `?`
68-
| ^ no rules expected the token `?`
68+
| ^ no rules expected this token in macro call
6969

7070
error: unexpected end of macro invocation
7171
--> $DIR/macro-at-most-once-rep-2018.rs:47:5
@@ -74,7 +74,7 @@ LL | macro_rules! barstar {
7474
| -------------------- when calling this macro
7575
...
7676
LL | barstar!(); //~ERROR unexpected end of macro invocation
77-
| ^^^^^^^^^^^ unexpected end of macro invocation
77+
| ^^^^^^^^^^^ missing tokens in macro arguments
7878

7979
error: unexpected end of macro invocation
8080
--> $DIR/macro-at-most-once-rep-2018.rs:48:15
@@ -83,7 +83,7 @@ LL | macro_rules! barstar {
8383
| -------------------- when calling this macro
8484
...
8585
LL | barstar!(a); //~ERROR unexpected end of macro invocation
86-
| ^ unexpected end of macro invocation
86+
| ^ missing tokens in macro arguments
8787

8888
error: no rules expected the token `?`
8989
--> $DIR/macro-at-most-once-rep-2018.rs:49:15
@@ -92,7 +92,7 @@ LL | macro_rules! barstar {
9292
| -------------------- when calling this macro
9393
...
9494
LL | barstar!(a?); //~ ERROR no rules expected the token `?`
95-
| ^ no rules expected the token `?`
95+
| ^ no rules expected this token in macro call
9696

9797
error: no rules expected the token `?`
9898
--> $DIR/macro-at-most-once-rep-2018.rs:50:15
@@ -101,7 +101,7 @@ LL | macro_rules! barstar {
101101
| -------------------- when calling this macro
102102
...
103103
LL | barstar!(a?a); //~ ERROR no rules expected the token `?`
104-
| ^ no rules expected the token `?`
104+
| ^ no rules expected this token in macro call
105105

106106
error: aborting due to 12 previous errors
107107

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | macro_rules! m { ($x:lifetime) => { } }
55
| -------------- when calling this macro
66
...
77
LL | m!(a);
8-
| ^ no rules expected the token `a`
8+
| ^ no rules expected this token in macro call
99

1010
error: aborting due to previous error
1111

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LL | macro_rules! foo {
1111
| ---------------- when calling this macro
1212
...
1313
LL | foo!(a b);
14-
| -^ no rules expected the token `b`
14+
| -^ no rules expected this token in macro call
1515
| |
1616
| help: missing comma here
1717

@@ -22,7 +22,7 @@ LL | macro_rules! foo {
2222
| ---------------- when calling this macro
2323
...
2424
LL | foo!(a, b, c, d e);
25-
| -^ no rules expected the token `e`
25+
| -^ no rules expected this token in macro call
2626
| |
2727
| help: missing comma here
2828

@@ -33,7 +33,7 @@ LL | macro_rules! foo {
3333
| ---------------- when calling this macro
3434
...
3535
LL | foo!(a, b, c d, e);
36-
| -^ no rules expected the token `d`
36+
| -^ no rules expected this token in macro call
3737
| |
3838
| help: missing comma here
3939

@@ -44,7 +44,7 @@ LL | macro_rules! foo {
4444
| ---------------- when calling this macro
4545
...
4646
LL | foo!(a, b, c d e);
47-
| ^ no rules expected the token `d`
47+
| ^ no rules expected this token in macro call
4848

4949
error: aborting due to 5 previous errors
5050

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: no rules expected the token `enum E { }`
22
--> $DIR/nonterminal-matching.rs:29:10
33
|
44
LL | n!(a $nt_item b); //~ ERROR no rules expected the token `enum E { }`
5-
| ^^^^^^^^ no rules expected the token `enum E { }`
5+
| ^^^^^^^^ no rules expected this token in macro call
66
...
77
LL | complex_nonterminal!(enum E {});
88
| -------------------------------- in this macro invocation

src/test/ui/macros/trace_faulty_macros.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | macro_rules! my_faulty_macro {
55
| ---------------------------- when calling this macro
66
LL | () => {
77
LL | my_faulty_macro!(bcd); //~ ERROR no rules
8-
| ^^^ no rules expected the token `bcd`
8+
| ^^^ no rules expected this token in macro call
99
...
1010
LL | my_faulty_macro!();
1111
| ------------------- in this macro invocation

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | macro_rules! outer {
55
| ------------------ when calling this macro
66
...
77
LL | //! Inner
8-
| ^^^^^^^^^ no rules expected the token `!`
8+
| ^^^^^^^^^ no rules expected this token in macro call
99

1010
error: aborting due to previous error
1111

0 commit comments

Comments
 (0)