Skip to content

Malformed suggestion for E0061 when in macro context and method is a macro token #140512

@nagisa

Description

@nagisa

Code

macro_rules! delegate {
    ($method:ident) => {
        <Self>::$method(8)
    }
}

struct Bar;

impl Bar {
    fn foo(a: u8, b: u8) {
    
    }
    fn bar() {
        delegate!(foo);
    }
}

Current output

error[E0061]: this function takes 2 arguments but 1 argument was supplied
  --> src/main.rs:3:9
   |
3  |         <Self>::$method(8)
   |         ^^^^^^^^^^^^^^^--- argument #2 of type `u8` is missing
...
14 |         delegate!(foo);
   |         -------------- in this macro invocation
   |
note: associated function defined here
  --> src/main.rs:10:8
   |
10 |     fn foo(a: u8, b: u8) {
   |        ^^^        -----
   = note: this error originates in the macro `delegate` (in Nightly builds, run with -Z macro-backtrace for more info)
help: provide the argument
   |
3  -         <Self>::$method(8)
3  +         <Self>::<Self>::$method(8, /* u8 */)
   |

Desired output

Should not add the extra ::<Self> in the suggestion.

Rationale and extra context

<Self>::<Self> is not valid Rust :)

Other cases

Rust Version

1.88.0-nightly (2025-04-29 74509131e85a97353c67)

Anything else?

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=cb4f2a307c6deb3ae21c782eb50d171c

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, ..)D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.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