mirror of https://github.com/rust-lang/rust.git
Reword incorrect macro invocation primary label
This commit is contained in:
parent
34bd86a3fd
commit
e5cd1edfa1
|
@ -281,7 +281,7 @@ pub enum ParseResult<T> {
|
|||
Success(T),
|
||||
/// Arm failed to match. If the second parameter is `token::Eof`, it indicates an unexpected
|
||||
/// end of macro invocation. Otherwise, it indicates that no rules expected the given token.
|
||||
Failure(syntax_pos::Span, Token),
|
||||
Failure(syntax_pos::Span, Token, String),
|
||||
/// Fatal error (malformed macro?). Abort compilation.
|
||||
Error(syntax_pos::Span, String),
|
||||
}
|
||||
|
@ -698,7 +698,7 @@ pub fn parse(
|
|||
parser.span,
|
||||
) {
|
||||
Success(_) => {}
|
||||
Failure(sp, tok) => return Failure(sp, tok),
|
||||
Failure(sp, tok, t) => return Failure(sp, tok, t),
|
||||
Error(sp, msg) => return Error(sp, msg),
|
||||
}
|
||||
|
||||
|
@ -710,7 +710,7 @@ pub fn parse(
|
|||
// Error messages here could be improved with links to original rules.
|
||||
|
||||
// If we reached the EOF, check that there is EXACTLY ONE possible matcher. Otherwise,
|
||||
// either the parse is ambiguous (which should never happen) or their is a syntax error.
|
||||
// either the parse is ambiguous (which should never happen) or there is a syntax error.
|
||||
if token_name_eq(&parser.token, &token::Eof) {
|
||||
if eof_items.len() == 1 {
|
||||
let matches = eof_items[0]
|
||||
|
@ -731,6 +731,7 @@ pub fn parse(
|
|||
sess.source_map().next_point(parser.span)
|
||||
},
|
||||
token::Eof,
|
||||
"missing tokens in macro arguments".to_string(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -766,7 +767,11 @@ pub fn parse(
|
|||
// If there are no possible next positions AND we aren't waiting for the black-box parser,
|
||||
// then there is a syntax error.
|
||||
else if bb_items.is_empty() && next_items.is_empty() {
|
||||
return Failure(parser.span, parser.token);
|
||||
return Failure(
|
||||
parser.span,
|
||||
parser.token,
|
||||
"no rules expected this token in macro call".to_string(),
|
||||
);
|
||||
}
|
||||
// Dump all possible `next_items` into `cur_items` for the next iteration.
|
||||
else if !next_items.is_empty() {
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
use {ast, attr};
|
||||
use syntax_pos::{Span, DUMMY_SP};
|
||||
use edition::Edition;
|
||||
use errors::FatalError;
|
||||
use ext::base::{DummyResult, ExtCtxt, MacResult, SyntaxExtension};
|
||||
use ext::base::{NormalTT, TTMacroExpander};
|
||||
use ext::expand::{AstFragment, AstFragmentKind};
|
||||
|
@ -130,6 +131,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
|
|||
// Which arm's failure should we report? (the one furthest along)
|
||||
let mut best_fail_spot = DUMMY_SP;
|
||||
let mut best_fail_tok = None;
|
||||
let mut best_fail_text = None;
|
||||
|
||||
for (i, lhs) in lhses.iter().enumerate() { // try each arm's matchers
|
||||
let lhs_tt = match *lhs {
|
||||
|
@ -185,9 +187,10 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
|
|||
macro_ident: name
|
||||
})
|
||||
}
|
||||
Failure(sp, tok) => if sp.lo() >= best_fail_spot.lo() {
|
||||
Failure(sp, tok, t) => if sp.lo() >= best_fail_spot.lo() {
|
||||
best_fail_spot = sp;
|
||||
best_fail_tok = Some(tok);
|
||||
best_fail_text = Some(t);
|
||||
},
|
||||
Error(err_sp, ref msg) => {
|
||||
cx.span_fatal(err_sp.substitute_dummy(sp), &msg[..])
|
||||
|
@ -198,7 +201,7 @@ fn generic_extension<'cx>(cx: &'cx mut ExtCtxt,
|
|||
let best_fail_msg = parse_failure_msg(best_fail_tok.expect("ran no matchers"));
|
||||
let span = best_fail_spot.substitute_dummy(sp);
|
||||
let mut err = cx.struct_span_err(span, &best_fail_msg);
|
||||
err.span_label(span, best_fail_msg);
|
||||
err.span_label(span, best_fail_text.unwrap_or(best_fail_msg));
|
||||
if let Some(sp) = def_span {
|
||||
if cx.source_map().span_to_filename(sp).is_real() && !sp.is_dummy() {
|
||||
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:
|
|||
|
||||
let argument_map = match parse(sess, body.stream(), &argument_gram, None, true) {
|
||||
Success(m) => m,
|
||||
Failure(sp, tok) => {
|
||||
Failure(sp, tok, t) => {
|
||||
let s = parse_failure_msg(tok);
|
||||
sess.span_diagnostic.span_fatal(sp.substitute_dummy(def.span), &s).raise();
|
||||
let sp = sp.substitute_dummy(def.span);
|
||||
let mut err = sess.span_diagnostic.struct_span_fatal(sp, &s);
|
||||
err.span_label(sp, t);
|
||||
err.emit();
|
||||
FatalError.raise();
|
||||
}
|
||||
Error(sp, s) => {
|
||||
sess.span_diagnostic.span_fatal(sp.substitute_dummy(def.span), &s).raise();
|
||||
|
|
|
@ -2,13 +2,13 @@ error: no rules expected the token `r#async`
|
|||
--> $DIR/edition-keywords-2015-2015-parsing.rs:22:31
|
||||
|
|
||||
LL | r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async`
|
||||
| ^^^^^^^ no rules expected the token `r#async`
|
||||
| ^^^^^^^ no rules expected this token in macro call
|
||||
|
||||
error: no rules expected the token `async`
|
||||
--> $DIR/edition-keywords-2015-2015-parsing.rs:23:35
|
||||
|
|
||||
LL | r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async`
|
||||
| ^^^^^ no rules expected the token `async`
|
||||
| ^^^^^ no rules expected this token in macro call
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
@ -2,13 +2,13 @@ error: no rules expected the token `r#async`
|
|||
--> $DIR/edition-keywords-2015-2018-parsing.rs:22:31
|
||||
|
|
||||
LL | r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async`
|
||||
| ^^^^^^^ no rules expected the token `r#async`
|
||||
| ^^^^^^^ no rules expected this token in macro call
|
||||
|
||||
error: no rules expected the token `async`
|
||||
--> $DIR/edition-keywords-2015-2018-parsing.rs:23:35
|
||||
|
|
||||
LL | r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async`
|
||||
| ^^^^^ no rules expected the token `async`
|
||||
| ^^^^^ no rules expected this token in macro call
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
|
|
|
@ -14,13 +14,13 @@ error: no rules expected the token `r#async`
|
|||
--> $DIR/edition-keywords-2018-2015-parsing.rs:22:31
|
||||
|
|
||||
LL | r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async`
|
||||
| ^^^^^^^ no rules expected the token `r#async`
|
||||
| ^^^^^^^ no rules expected this token in macro call
|
||||
|
||||
error: no rules expected the token `async`
|
||||
--> $DIR/edition-keywords-2018-2015-parsing.rs:23:35
|
||||
|
|
||||
LL | r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async`
|
||||
| ^^^^^ no rules expected the token `async`
|
||||
| ^^^^^ no rules expected this token in macro call
|
||||
|
||||
error: expected one of `move`, `|`, or `||`, found the end of the macro arm
|
||||
--> <::edition_kw_macro_2015::passes_ident macros>:1:25
|
||||
|
|
|
@ -14,13 +14,13 @@ error: no rules expected the token `r#async`
|
|||
--> $DIR/edition-keywords-2018-2018-parsing.rs:22:31
|
||||
|
|
||||
LL | r#async = consumes_async!(r#async); //~ ERROR no rules expected the token `r#async`
|
||||
| ^^^^^^^ no rules expected the token `r#async`
|
||||
| ^^^^^^^ no rules expected this token in macro call
|
||||
|
||||
error: no rules expected the token `async`
|
||||
--> $DIR/edition-keywords-2018-2018-parsing.rs:23:35
|
||||
|
|
||||
LL | r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async`
|
||||
| ^^^^^ no rules expected the token `async`
|
||||
| ^^^^^ no rules expected this token in macro call
|
||||
|
||||
error: expected one of `move`, `|`, or `||`, found the end of the macro arm
|
||||
--> <::edition_kw_macro_2018::passes_ident macros>:1:25
|
||||
|
|
|
@ -5,7 +5,7 @@ LL | macro_rules! one_arg_macro {
|
|||
| -------------------------- when calling this macro
|
||||
...
|
||||
LL | one_arg_macro!(/**/); //~ ERROR unexpected end
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ unexpected end of macro invocation
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ missing tokens in macro arguments
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ error: no rules expected the token `@`
|
|||
--> $DIR/fail-simple.rs:12:12
|
||||
|
|
||||
LL | panic!(@); //~ ERROR no rules expected the token `@`
|
||||
| ^ no rules expected the token `@`
|
||||
| ^ no rules expected this token in macro call
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ LL | macro_rules! one_arg_macro {
|
|||
| -------------------------- when calling this macro
|
||||
...
|
||||
LL | one_arg_macro!();
|
||||
| ^^^^^^^^^^^^^^^^^ unexpected end of macro invocation
|
||||
| ^^^^^^^^^^^^^^^^^ missing tokens in macro arguments
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ error: unexpected end of macro invocation
|
|||
--> $DIR/issue-7970b.rs:13:1
|
||||
|
|
||||
LL | macro_rules! test {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^^^^^^^^^^^^^^^^ missing tokens in macro arguments
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -55,7 +55,7 @@ LL | macro_rules! foo {
|
|||
| ---------------- when calling this macro
|
||||
...
|
||||
LL | foo!(a?); //~ ERROR no rules expected the token `?`
|
||||
| ^ no rules expected the token `?`
|
||||
| ^ no rules expected this token in macro call
|
||||
|
||||
error: no rules expected the token `?`
|
||||
--> $DIR/macro-at-most-once-rep-2018-feature-gate.rs:42:11
|
||||
|
@ -64,7 +64,7 @@ LL | macro_rules! foo {
|
|||
| ---------------- when calling this macro
|
||||
...
|
||||
LL | foo!(a?a); //~ ERROR no rules expected the token `?`
|
||||
| ^ no rules expected the token `?`
|
||||
| ^ no rules expected this token in macro call
|
||||
|
||||
error: no rules expected the token `?`
|
||||
--> $DIR/macro-at-most-once-rep-2018-feature-gate.rs:43:11
|
||||
|
@ -73,7 +73,7 @@ LL | macro_rules! foo {
|
|||
| ---------------- when calling this macro
|
||||
...
|
||||
LL | foo!(a?a?a); //~ ERROR no rules expected the token `?`
|
||||
| ^ no rules expected the token `?`
|
||||
| ^ no rules expected this token in macro call
|
||||
|
||||
error: aborting due to 10 previous errors
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ LL | macro_rules! foo {
|
|||
| ---------------- when calling this macro
|
||||
...
|
||||
LL | foo!(a?); //~ ERROR no rules expected the token `?`
|
||||
| ^ no rules expected the token `?`
|
||||
| ^ no rules expected this token in macro call
|
||||
|
||||
error: no rules expected the token `?`
|
||||
--> $DIR/macro-at-most-once-rep-2018.rs:37:11
|
||||
|
@ -20,7 +20,7 @@ LL | macro_rules! foo {
|
|||
| ---------------- when calling this macro
|
||||
...
|
||||
LL | foo!(a?a); //~ ERROR no rules expected the token `?`
|
||||
| ^ no rules expected the token `?`
|
||||
| ^ no rules expected this token in macro call
|
||||
|
||||
error: no rules expected the token `?`
|
||||
--> $DIR/macro-at-most-once-rep-2018.rs:38:11
|
||||
|
@ -29,7 +29,7 @@ LL | macro_rules! foo {
|
|||
| ---------------- when calling this macro
|
||||
...
|
||||
LL | foo!(a?a?a); //~ ERROR no rules expected the token `?`
|
||||
| ^ no rules expected the token `?`
|
||||
| ^ no rules expected this token in macro call
|
||||
|
||||
error: unexpected end of macro invocation
|
||||
--> $DIR/macro-at-most-once-rep-2018.rs:40:5
|
||||
|
@ -38,7 +38,7 @@ LL | macro_rules! barplus {
|
|||
| -------------------- when calling this macro
|
||||
...
|
||||
LL | barplus!(); //~ERROR unexpected end of macro invocation
|
||||
| ^^^^^^^^^^^ unexpected end of macro invocation
|
||||
| ^^^^^^^^^^^ missing tokens in macro arguments
|
||||
|
||||
error: unexpected end of macro invocation
|
||||
--> $DIR/macro-at-most-once-rep-2018.rs:41:15
|
||||
|
@ -47,7 +47,7 @@ LL | macro_rules! barplus {
|
|||
| -------------------- when calling this macro
|
||||
...
|
||||
LL | barplus!(a); //~ERROR unexpected end of macro invocation
|
||||
| ^ unexpected end of macro invocation
|
||||
| ^ missing tokens in macro arguments
|
||||
|
||||
error: no rules expected the token `?`
|
||||
--> $DIR/macro-at-most-once-rep-2018.rs:42:15
|
||||
|
@ -56,7 +56,7 @@ LL | macro_rules! barplus {
|
|||
| -------------------- when calling this macro
|
||||
...
|
||||
LL | barplus!(a?); //~ ERROR no rules expected the token `?`
|
||||
| ^ no rules expected the token `?`
|
||||
| ^ no rules expected this token in macro call
|
||||
|
||||
error: no rules expected the token `?`
|
||||
--> $DIR/macro-at-most-once-rep-2018.rs:43:15
|
||||
|
@ -65,7 +65,7 @@ LL | macro_rules! barplus {
|
|||
| -------------------- when calling this macro
|
||||
...
|
||||
LL | barplus!(a?a); //~ ERROR no rules expected the token `?`
|
||||
| ^ no rules expected the token `?`
|
||||
| ^ no rules expected this token in macro call
|
||||
|
||||
error: unexpected end of macro invocation
|
||||
--> $DIR/macro-at-most-once-rep-2018.rs:47:5
|
||||
|
@ -74,7 +74,7 @@ LL | macro_rules! barstar {
|
|||
| -------------------- when calling this macro
|
||||
...
|
||||
LL | barstar!(); //~ERROR unexpected end of macro invocation
|
||||
| ^^^^^^^^^^^ unexpected end of macro invocation
|
||||
| ^^^^^^^^^^^ missing tokens in macro arguments
|
||||
|
||||
error: unexpected end of macro invocation
|
||||
--> $DIR/macro-at-most-once-rep-2018.rs:48:15
|
||||
|
@ -83,7 +83,7 @@ LL | macro_rules! barstar {
|
|||
| -------------------- when calling this macro
|
||||
...
|
||||
LL | barstar!(a); //~ERROR unexpected end of macro invocation
|
||||
| ^ unexpected end of macro invocation
|
||||
| ^ missing tokens in macro arguments
|
||||
|
||||
error: no rules expected the token `?`
|
||||
--> $DIR/macro-at-most-once-rep-2018.rs:49:15
|
||||
|
@ -92,7 +92,7 @@ LL | macro_rules! barstar {
|
|||
| -------------------- when calling this macro
|
||||
...
|
||||
LL | barstar!(a?); //~ ERROR no rules expected the token `?`
|
||||
| ^ no rules expected the token `?`
|
||||
| ^ no rules expected this token in macro call
|
||||
|
||||
error: no rules expected the token `?`
|
||||
--> $DIR/macro-at-most-once-rep-2018.rs:50:15
|
||||
|
@ -101,7 +101,7 @@ LL | macro_rules! barstar {
|
|||
| -------------------- when calling this macro
|
||||
...
|
||||
LL | barstar!(a?a); //~ ERROR no rules expected the token `?`
|
||||
| ^ no rules expected the token `?`
|
||||
| ^ no rules expected this token in macro call
|
||||
|
||||
error: aborting due to 12 previous errors
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ LL | macro_rules! m { ($x:lifetime) => { } }
|
|||
| -------------- when calling this macro
|
||||
...
|
||||
LL | m!(a);
|
||||
| ^ no rules expected the token `a`
|
||||
| ^ no rules expected this token in macro call
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ LL | macro_rules! foo {
|
|||
| ---------------- when calling this macro
|
||||
...
|
||||
LL | foo!(a b);
|
||||
| -^ no rules expected the token `b`
|
||||
| -^ no rules expected this token in macro call
|
||||
| |
|
||||
| help: missing comma here
|
||||
|
||||
|
@ -22,7 +22,7 @@ LL | macro_rules! foo {
|
|||
| ---------------- when calling this macro
|
||||
...
|
||||
LL | foo!(a, b, c, d e);
|
||||
| -^ no rules expected the token `e`
|
||||
| -^ no rules expected this token in macro call
|
||||
| |
|
||||
| help: missing comma here
|
||||
|
||||
|
@ -33,7 +33,7 @@ LL | macro_rules! foo {
|
|||
| ---------------- when calling this macro
|
||||
...
|
||||
LL | foo!(a, b, c d, e);
|
||||
| -^ no rules expected the token `d`
|
||||
| -^ no rules expected this token in macro call
|
||||
| |
|
||||
| help: missing comma here
|
||||
|
||||
|
@ -44,7 +44,7 @@ LL | macro_rules! foo {
|
|||
| ---------------- when calling this macro
|
||||
...
|
||||
LL | foo!(a, b, c d e);
|
||||
| ^ no rules expected the token `d`
|
||||
| ^ no rules expected this token in macro call
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ error: no rules expected the token `enum E { }`
|
|||
--> $DIR/nonterminal-matching.rs:29:10
|
||||
|
|
||||
LL | n!(a $nt_item b); //~ ERROR no rules expected the token `enum E { }`
|
||||
| ^^^^^^^^ no rules expected the token `enum E { }`
|
||||
| ^^^^^^^^ no rules expected this token in macro call
|
||||
...
|
||||
LL | complex_nonterminal!(enum E {});
|
||||
| -------------------------------- in this macro invocation
|
||||
|
|
|
@ -5,7 +5,7 @@ LL | macro_rules! my_faulty_macro {
|
|||
| ---------------------------- when calling this macro
|
||||
LL | () => {
|
||||
LL | my_faulty_macro!(bcd); //~ ERROR no rules
|
||||
| ^^^ no rules expected the token `bcd`
|
||||
| ^^^ no rules expected this token in macro call
|
||||
...
|
||||
LL | my_faulty_macro!();
|
||||
| ------------------- in this macro invocation
|
||||
|
|
|
@ -5,7 +5,7 @@ LL | macro_rules! outer {
|
|||
| ------------------ when calling this macro
|
||||
...
|
||||
LL | //! Inner
|
||||
| ^^^^^^^^^ no rules expected the token `!`
|
||||
| ^^^^^^^^^ no rules expected this token in macro call
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ LL | macro_rules! inner {
|
|||
| ------------------ when calling this macro
|
||||
...
|
||||
LL | /// Outer
|
||||
| ^ no rules expected the token `[`
|
||||
| ^ no rules expected this token in macro call
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ LL | macro_rules! identity {
|
|||
| --------------------- when calling this macro
|
||||
...
|
||||
LL | let identity!(_) = 10; //~ ERROR no rules expected the token `_`
|
||||
| ^ no rules expected the token `_`
|
||||
| ^ no rules expected this token in macro call
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ error: no rules expected the token `,`
|
|||
--> $DIR/vec-macro-with-comma-only.rs:12:10
|
||||
|
|
||||
LL | vec![,]; //~ ERROR no rules expected the token `,`
|
||||
| ^ no rules expected the token `,`
|
||||
| ^ no rules expected this token in macro call
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
Loading…
Reference in New Issue