Skip to content

Confusing "this function doesn't have a self parameter" hint when using macro #66898

Closed
@Patryk27

Description

@Patryk27

Hi,

pub struct Foo;

macro_rules! call_bar {
    () => {
        self.bar();
    }
}

impl Foo {
    pub fn foo(&self) {
        call_bar!();
    }
    
    pub fn bar(&self) {
        
    }
}

... returns:

error[E0424]: expected value, found module `self`
  --> src/lib.rs:5:9
   |
5  |           self.bar();
   |           ^^^^ `self` value is a keyword only available in methods with a `self` parameter
...
10 | /     pub fn foo(&self) {
11 | |         call_bar!();
   | |         ------------ in this macro invocation
12 | |     }
   | |_____- this function doesn't have a `self` parameter

(playground)

Message says this function doesn't have a 'self' parameter, even though it does have a self parameter, which is kinda confusing.

This happens only on beta and nightly, since current stable doesn't provide that hint at all.

Thanks,
Patryk.

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.D-confusingDiagnostics: Confusing error or lint that should be reworked.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.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