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

0 commit comments

Comments
 (0)