diff --git a/src/libsyntax/ext/tt/macro_parser.rs b/src/libsyntax/ext/tt/macro_parser.rs index f31d80acbfa4..26604c46be5f 100644 --- a/src/libsyntax/ext/tt/macro_parser.rs +++ b/src/libsyntax/ext/tt/macro_parser.rs @@ -724,7 +724,14 @@ pub fn parse( "ambiguity: multiple successful parses".to_string(), ); } else { - return Failure(parser.span, token::Eof); + return Failure( + if parser.span.is_dummy() { + parser.span + } else { + sess.source_map().next_point(parser.span) + }, + token::Eof, + ); } } // Performance hack: eof_items may share matchers via Rc with other things that we want @@ -757,7 +764,7 @@ pub fn parse( ); } // If there are no possible next positions AND we aren't waiting for the black-box parser, - // then their is a syntax error. + // then there is a syntax error. else if bb_items.is_empty() && next_items.is_empty() { return Failure(parser.span, parser.token); } diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs index 6bba891278ac..b67c46fe6f4b 100644 --- a/src/libsyntax/ext/tt/macro_rules.rs +++ b/src/libsyntax/ext/tt/macro_rules.rs @@ -53,6 +53,15 @@ impl<'a> ParserAnyMacro<'a> { let fragment = panictry!(parser.parse_ast_fragment(kind, true).map_err(|mut e| { if e.span.is_dummy() { // Get around lack of span in error (#30128) e.set_span(site_span); + } else if parser.token == token::Eof { // (#52866) + e.set_span(parser.sess.source_map().next_point(parser.span)); + } + if parser.token == token::Eof { + let msg = &e.message[0]; + e.message[0] = ( + msg.0.replace(", found ``", ", found the end of the macro arm"), + msg.1, + ); } e })); diff --git a/src/test/ui/directory_ownership/macro-expanded-mod.rs b/src/test/ui/directory_ownership/macro-expanded-mod.rs index 8e631a64f7a2..78356f981fce 100644 --- a/src/test/ui/directory_ownership/macro-expanded-mod.rs +++ b/src/test/ui/directory_ownership/macro-expanded-mod.rs @@ -12,6 +12,7 @@ macro_rules! mod_decl { ($i:ident) => { mod $i; } + //~^ ERROR Cannot declare a non-inline module inside a block } mod macro_expanded_mod_helper { @@ -19,5 +20,5 @@ mod macro_expanded_mod_helper { } fn main() { - mod_decl!(foo); //~ ERROR Cannot declare a non-inline module inside a block + mod_decl!(foo); } diff --git a/src/test/ui/directory_ownership/macro-expanded-mod.stderr b/src/test/ui/directory_ownership/macro-expanded-mod.stderr index a9efcd883c15..f58e864a7559 100644 --- a/src/test/ui/directory_ownership/macro-expanded-mod.stderr +++ b/src/test/ui/directory_ownership/macro-expanded-mod.stderr @@ -1,8 +1,8 @@ error: Cannot declare a non-inline module inside a block unless it has a path attribute - --> $DIR/macro-expanded-mod.rs:22:15 + --> $DIR/macro-expanded-mod.rs:14:28 | -LL | mod_decl!(foo); //~ ERROR Cannot declare a non-inline module inside a block - | ^^^ +LL | ($i:ident) => { mod $i; } + | ^ error: aborting due to previous error 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 b6ff60f1492e..bf7fc28c7581 100644 --- a/src/test/ui/editions/edition-keywords-2018-2015-parsing.stderr +++ b/src/test/ui/editions/edition-keywords-2018-2015-parsing.stderr @@ -22,11 +22,11 @@ error: no rules expected the token `async` LL | r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async` | ^^^^^ no rules expected the token `async` -error: expected one of `move`, `|`, or `||`, found `` - --> <::edition_kw_macro_2015::passes_ident macros>:1:22 +error: expected one of `move`, `|`, or `||`, found the end of the macro arm + --> <::edition_kw_macro_2015::passes_ident macros>:1:25 | LL | ( $ i : ident ) => ( $ i ) - | ^^^ expected one of `move`, `|`, or `||` here + | ^ error: aborting due to 5 previous errors 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 ffe666a7e644..4ab29ba67a0a 100644 --- a/src/test/ui/editions/edition-keywords-2018-2018-parsing.stderr +++ b/src/test/ui/editions/edition-keywords-2018-2018-parsing.stderr @@ -22,11 +22,11 @@ error: no rules expected the token `async` LL | r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async` | ^^^^^ no rules expected the token `async` -error: expected one of `move`, `|`, or `||`, found `` - --> <::edition_kw_macro_2018::passes_ident macros>:1:22 +error: expected one of `move`, `|`, or `||`, found the end of the macro arm + --> <::edition_kw_macro_2018::passes_ident macros>:1:25 | LL | ( $ i : ident ) => ( $ i ) - | ^^^ expected one of `move`, `|`, or `||` here + | ^ error: aborting due to 5 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 25dd66b81f56..19a9cf3a6f50 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 @@ -41,13 +41,13 @@ LL | barplus!(); //~ERROR unexpected end of macro invocation | ^^^^^^^^^^^ unexpected end of macro invocation error: unexpected end of macro invocation - --> $DIR/macro-at-most-once-rep-2018.rs:41:14 + --> $DIR/macro-at-most-once-rep-2018.rs:41:15 | LL | macro_rules! barplus { | -------------------- when calling this macro ... LL | barplus!(a); //~ERROR unexpected end of macro invocation - | ^ unexpected end of macro invocation + | ^ unexpected end of macro invocation error: no rules expected the token `?` --> $DIR/macro-at-most-once-rep-2018.rs:42:15 @@ -77,13 +77,13 @@ LL | barstar!(); //~ERROR unexpected end of macro invocation | ^^^^^^^^^^^ unexpected end of macro invocation error: unexpected end of macro invocation - --> $DIR/macro-at-most-once-rep-2018.rs:48:14 + --> $DIR/macro-at-most-once-rep-2018.rs:48:15 | LL | macro_rules! barstar { | -------------------- when calling this macro ... LL | barstar!(a); //~ERROR unexpected end of macro invocation - | ^ unexpected end of macro invocation + | ^ unexpected end of macro invocation error: no rules expected the token `?` --> $DIR/macro-at-most-once-rep-2018.rs:49:15 diff --git a/src/test/ui/macros/macro-in-expression-context-2.stderr b/src/test/ui/macros/macro-in-expression-context-2.stderr index 80d5dbd66cc2..3a4c9c0cdecf 100644 --- a/src/test/ui/macros/macro-in-expression-context-2.stderr +++ b/src/test/ui/macros/macro-in-expression-context-2.stderr @@ -1,4 +1,4 @@ -error: expected expression, found `` +error: expected expression, found the end of the macro arm --> $DIR/macro-in-expression-context-2.rs:5:16 | LL | _ => { empty!() }