Skip to content

A 'top-level' scope in a macro in item position unintuitively ignores everything #17022

@huonw

Description

@huonw
#![feature(macro_rules)]

macro_rules! x {
    () => {{
        struct Foo;
    }}
}

x!()
<anon>:4:12: 4:13 error: macro expansion ignores token `{` and any following
<anon>:4     () => {{
                    ^

i.e. the parser is seeing the { and bailing on parsing an item, and the macro expander is diligently reporting that those tokens were ignored. It would be better if we could emit a more helpful message for this case specifically, since expression macros require the {s to be able to contain multiple things so users used to this can get tripped up (item macros don't need scopes for multiple items, and doing this would restrict those items to that inner scope anyway).

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, ..)C-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