Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

End of macro invocation before expected produces EOF #27569

Closed
Wilfred opened this issue Aug 6, 2015 · 3 comments · Fixed by #61026
Closed

End of macro invocation before expected produces EOF #27569

Wilfred opened this issue Aug 6, 2015 · 3 comments · Fixed by #61026
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-parser Area: The parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@Wilfred
Copy link
Contributor

Wilfred commented Aug 6, 2015

fn main() {
    let message = "world";
    println!("Hello, {}", message/);
}

This gives the following compile error:



<anon>:3:34: 3:35 error: unexpected token: `<eof>`
<anon>:3     println!("Hello, {}", message/);
                                          ^

I think this is slightly misleading: it's not an EOF at the position where the caret is.

@Aatch
Copy link
Contributor

Aatch commented Aug 7, 2015

This is because of the macro. For message/ there the token stream is literally just message and /, so the expression parser hits an "EOF", as it can only parse the tokens inside the macro. It's an unfortunate error message, but technically correct, from the perspective of the parser anyway.

There should probably be something to catch "EOF" errors in macro/syntax extension expansion and turn them into something more accurate.

@Aatch Aatch added A-diagnostics Area: Messages for errors, warnings, and lints A-parser Area: The parsing of Rust source code to an AST labels Aug 7, 2015
@gchp
Copy link
Contributor

gchp commented Jan 22, 2016

@Wilfred @Aatch I'd like to take a look at this issue.

What do you think would be a good message for the example above?

gchp added a commit to gchp/rust that referenced this issue May 30, 2016
@steveklabnik steveklabnik removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum Mark-Simulacrum added the A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) label Jun 1, 2017
@Mark-Simulacrum Mark-Simulacrum changed the title Strange EOF lexing error End of macro invocation before expected produces EOF Jun 1, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 22, 2017
@estebank
Copy link
Contributor

Current output:

error: expected expression, found `<eof>`
 --> src/main.rs:3:34
  |
3 |     println!("Hello, {}", message/);
  |                                  ^ expected expression

Centril added a commit to Centril/rust that referenced this issue May 25, 2019
…enkov

Tweak macro parse errors when reaching EOF during macro call parse

Add detail on origin of current parser when reaching EOF, stop saying "found `<eof>`" and point at the end of macro calls.

Fix rust-lang#27569.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-parser Area: The parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants