Skip to content

Commit ea9ccb6

Browse files
committed
Point at end of macro arm when encountering EOF
Fix rust-lang#52866
1 parent 910ec6d commit ea9ccb6

8 files changed

+34
-17
lines changed

src/libsyntax/ext/tt/macro_parser.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,14 @@ pub fn parse(
724724
"ambiguity: multiple successful parses".to_string(),
725725
);
726726
} else {
727-
return Failure(parser.span, token::Eof);
727+
return Failure(
728+
if parser.span.is_dummy() {
729+
parser.span
730+
} else {
731+
sess.source_map().next_point(parser.span)
732+
},
733+
token::Eof,
734+
);
728735
}
729736
}
730737
// Performance hack: eof_items may share matchers via Rc with other things that we want
@@ -757,7 +764,7 @@ pub fn parse(
757764
);
758765
}
759766
// If there are no possible next positions AND we aren't waiting for the black-box parser,
760-
// then their is a syntax error.
767+
// then there is a syntax error.
761768
else if bb_items.is_empty() && next_items.is_empty() {
762769
return Failure(parser.span, parser.token);
763770
}

src/libsyntax/ext/tt/macro_rules.rs

+9
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,15 @@ impl<'a> ParserAnyMacro<'a> {
5353
let fragment = panictry!(parser.parse_ast_fragment(kind, true).map_err(|mut e| {
5454
if e.span.is_dummy() { // Get around lack of span in error (#30128)
5555
e.set_span(site_span);
56+
} else if parser.token == token::Eof { // (#52866)
57+
e.set_span(parser.sess.source_map().next_point(parser.span));
58+
}
59+
if parser.token == token::Eof {
60+
let msg = &e.message[0];
61+
e.message[0] = (
62+
msg.0.replace(", found `<eof>`", ", found the end of the macro arm"),
63+
msg.1,
64+
);
5665
}
5766
e
5867
}));

src/test/ui/directory_ownership/macro-expanded-mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212

1313
macro_rules! mod_decl {
1414
($i:ident) => { mod $i; }
15+
//~^ ERROR Cannot declare a non-inline module inside a block
1516
}
1617

1718
mod macro_expanded_mod_helper {
1819
mod_decl!(foo); // This should search in the folder `macro_expanded_mod_helper`
1920
}
2021

2122
fn main() {
22-
mod_decl!(foo); //~ ERROR Cannot declare a non-inline module inside a block
23+
mod_decl!(foo);
2324
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error: Cannot declare a non-inline module inside a block unless it has a path attribute
2-
--> $DIR/macro-expanded-mod.rs:22:15
2+
--> $DIR/macro-expanded-mod.rs:14:28
33
|
4-
LL | mod_decl!(foo); //~ ERROR Cannot declare a non-inline module inside a block
5-
| ^^^
4+
LL | ($i:ident) => { mod $i; }
5+
| ^
66

77
error: aborting due to previous error
88

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ error: no rules expected the token `async`
2222
LL | r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async`
2323
| ^^^^^ no rules expected the token `async`
2424

25-
error: expected one of `move`, `|`, or `||`, found `<eof>`
26-
--> <::edition_kw_macro_2015::passes_ident macros>:1:22
25+
error: expected one of `move`, `|`, or `||`, found the end of the macro arm
26+
--> <::edition_kw_macro_2015::passes_ident macros>:1:25
2727
|
2828
LL | ( $ i : ident ) => ( $ i )
29-
| ^^^ expected one of `move`, `|`, or `||` here
29+
| ^
3030

3131
error: aborting due to 5 previous errors
3232

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ error: no rules expected the token `async`
2222
LL | r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async`
2323
| ^^^^^ no rules expected the token `async`
2424

25-
error: expected one of `move`, `|`, or `||`, found `<eof>`
26-
--> <::edition_kw_macro_2018::passes_ident macros>:1:22
25+
error: expected one of `move`, `|`, or `||`, found the end of the macro arm
26+
--> <::edition_kw_macro_2018::passes_ident macros>:1:25
2727
|
2828
LL | ( $ i : ident ) => ( $ i )
29-
| ^^^ expected one of `move`, `|`, or `||` here
29+
| ^
3030

3131
error: aborting due to 5 previous errors
3232

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ LL | barplus!(); //~ERROR unexpected end of macro invocation
4141
| ^^^^^^^^^^^ unexpected end of macro invocation
4242

4343
error: unexpected end of macro invocation
44-
--> $DIR/macro-at-most-once-rep-2018.rs:41:14
44+
--> $DIR/macro-at-most-once-rep-2018.rs:41:15
4545
|
4646
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+
| ^ unexpected end of macro invocation
5151

5252
error: no rules expected the token `?`
5353
--> $DIR/macro-at-most-once-rep-2018.rs:42:15
@@ -77,13 +77,13 @@ LL | barstar!(); //~ERROR unexpected end of macro invocation
7777
| ^^^^^^^^^^^ unexpected end of macro invocation
7878

7979
error: unexpected end of macro invocation
80-
--> $DIR/macro-at-most-once-rep-2018.rs:48:14
80+
--> $DIR/macro-at-most-once-rep-2018.rs:48:15
8181
|
8282
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+
| ^ unexpected end of macro invocation
8787

8888
error: no rules expected the token `?`
8989
--> $DIR/macro-at-most-once-rep-2018.rs:49:15

src/test/ui/macros/macro-in-expression-context-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: expected expression, found `<eof>`
1+
error: expected expression, found the end of the macro arm
22
--> $DIR/macro-in-expression-context-2.rs:5:16
33
|
44
LL | _ => { empty!() }

0 commit comments

Comments
 (0)