Skip to content

Confusing error message when mis-spelling macro invocation #38126

Closed
@jethrogb

Description

@jethrogb

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 `{`”.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-parserArea: The lexing & parsing of Rust source code to an ASTC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions