Skip to content

Confusing error message when mis-spelling macro invocation #38126

New issue

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

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

Already on GitHub? # to your account

Closed
jethrogb opened this issue Dec 2, 2016 · 4 comments
Closed

Confusing error message when mis-spelling macro invocation #38126

jethrogb opened this issue Dec 2, 2016 · 4 comments
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 lexing & parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jethrogb
Copy link
Contributor

jethrogb commented Dec 2, 2016

When compiling

thread_local {
    static I: i32 = 0;
}

the following error is generated

error: expected one of `!` or `::`, found `{`
 --> m.rs:1:14
  |
1 | thread_local {
  |              ^

This happens because the only thing that could possibly be in an item position and not start with a keyword is a macro, and macros start with a path. A path can contain double colons. However, a macro invocation can not, and the compiler will generate an error at a later stage if you try to invoke a macro that way. See #28558

To be clear, I think the error message should just be “expected `!`, found `{`”.

@petrochenkov
Copy link
Contributor

A path can contain double colons. However, a macro invocation can not

This will change pretty soon - #38082

@sanxiyn sanxiyn added the A-diagnostics Area: Messages for errors, warnings, and lints label Dec 2, 2016
@jethrogb
Copy link
Contributor Author

jethrogb commented Dec 2, 2016

I suppose it's not feasible to change the parser error message based on whether the feature is activated?

@jseyfried
Copy link
Contributor

@jethrogb It's feasible, but I don't think the extra complexity is worth it.

@steveklabnik steveklabnik added 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 A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) A-parser Area: The lexing & parsing of Rust source code to an AST labels May 30, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 26, 2017
@jethrogb
Copy link
Contributor Author

jethrogb commented Oct 4, 2018

Closing this because macros 2.0 is pretty much around the corner.

@jethrogb jethrogb closed this as completed Oct 4, 2018
# for free to join this conversation on GitHub. Already have an account? # 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 lexing & parsing of Rust source code to an AST C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants