Skip to content

Misleading error message for using self in a macro #39057

Closed
@whitequark

Description

@whitequark

To reproduce:

macro_rules! x {
    () => (self)
}

struct X;
impl X {
    fn y(&self) {
        x!()
    }
}
error[E0424]: `self` is not available in a static method
 --> <anon>:2:12
  |
2 |     () => (self)
  |            ^^^^ not available in static method
...
8 |         x!()
  |         ---- in this macro invocation
  |
  = note: maybe a `self` argument is missing?

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