Skip to content

macros can't interpolate impl items (or really parse them at all) #48137

Closed
@durka

Description

@durka

This macro will never work:

macro_rules! foo {
    ($name:ident; $method:item) => (
        struct $name();
        impl $name {
            $method
        }
    )
}

Instead of reinterpreting $method as an impl item, the macro expander says it was expecting const, crate, default, extern, fn, pub, type, unsafe, or }.

Moreover :item isn't good enough for parsing impl items because it doesn't have a special case for self arguments.

Is the solution to create a new :implitem or to make :item more flexible in parsing and expansion?

Metadata

Metadata

Assignees

Labels

A-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