Skip to content
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

suggest to use associated function syntax diagnostic take receiver as first arg mistakely #118469

Closed
Young-Flash opened this issue Nov 30, 2023 · 1 comment · Fixed by #118502
Closed
Assignees
Labels
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.

Comments

@Young-Flash
Copy link
Member

Young-Flash commented Nov 30, 2023

Code

struct A {}

impl A {
    fn hello(a: i32) {}
}

fn main() {
    let a = A {};
    a.hello(1);
}

Current output

error[E0599]: no method named `hello` found for struct `A` in the current scope
  --> src/main.rs:46:7
   |
38 | struct A {}
   | -------- method `hello` not found for this struct
...
46 |     a.hello(1);
   |     --^^^^^---
   |     | |
   |     | this is an associated function, not a method
   |     help: use associated function syntax instead: `A::hello(a, 1)`
   |
   = note: found the following associated functions; to be used as methods, functions must have a `self` parameter
note: the candidate is defined in an impl for the type `A`
  --> src/main.rs:41:5
   |
41 |     fn hello(a: i32) {}
   |     ^^^^^^^^^^^^^^^^

Desired output

receiver shouldn't be treated as the first arg of the assoc function when the first arg of the assoc function isn't the same as the current impl type

46 |     a.hello(1);
   |     --^^^^^---
   |     | |
   |     | this is an associated function, not a method
   |     help: use associated function syntax instead: `A::hello(1)`

Rationale and extra context

rustc --version
rustc 1.75.0-nightly (9d83ac2 2023-10-31)

Other cases

no

Anything else?

no

@Young-Flash Young-Flash 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 Nov 30, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Nov 30, 2023
@Young-Flash
Copy link
Member Author

I'll try to solve this if you guys think it does need to fix.

@rustbot claim

@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 2, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Dec 8, 2023
fix: correct the arg for 'suggest to use associated function syntax' diagnostic

close rust-lang#118469
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Dec 9, 2023
Rollup merge of rust-lang#118502 - Young-Flash:fix, r=compiler-errors

fix: correct the arg for 'suggest to use associated function syntax' diagnostic

close rust-lang#118469
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 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