Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
nagisa opened this issue Apr 30, 2025 · 1 comment · May be fixed by #140591
Open

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

nagisa opened this issue Apr 30, 2025 · 1 comment · May be fixed by #140591
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@nagisa
Copy link
Member

nagisa commented Apr 30, 2025

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

@nagisa nagisa added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 30, 2025
@moxian
Copy link
Contributor

moxian commented Apr 30, 2025

@rustbot label: +A-macros +D-invalid-suggestion

@rustbot rustbot added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. labels Apr 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants