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

disambiguate the associated function diagnostic take receiver as first arg mistakely #118819

Closed
Young-Flash opened this issue Dec 11, 2023 · 1 comment · Fixed by #118911
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 Dec 11, 2023

Code

struct A {
}

trait M {
    fn new();
}
impl M for A {
    fn new() {
        todo!()
    }
}

trait N {
    fn new();
}
impl N for A {
    fn new() {
        todo!()
    }
}

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

Current output

error[E0599]: no method named `new` found for struct `A` in the current scope
  --> src/main.rs:37:7
   |
14 | struct A {
   | -------- method `new` not found for this struct
...
37 |     a.new();
   |       ^^^ this is an associated function, not a method
   |
   = note: found the following associated functions; to be used as methods, functions must have a `self` parameter
note: candidate #1 is defined in the trait `M`
  --> src/main.rs:18:5
   |
18 |     fn new();
   |     ^^^^^^^^^
note: candidate #2 is defined in the trait `N`
  --> src/main.rs:27:5
   |
27 |     fn new();
   |     ^^^^^^^^^
help: disambiguate the associated function for candidate #1
   |
37 |     <A as M>::new(a);
   |     ~~~~~~~~~~~~~~~~
help: disambiguate the associated function for candidate #2
   |
37 |     <A as N>::new(a);
   |     ~~~~~~~~~~~~~~~~

Desired output

help: disambiguate the associated function for candidate #1
   |
37 |     <A as M>::new();
   |     ~~~~~~~~~~~~~~~~
help: disambiguate the associated function for candidate #2
   |
37 |     <A as N>::new();
   |     ~~~~~~~~~~~~~~~~

Rationale and extra context

This is somehow silimar to #118469, we shouldn't take receiver as first arg all the cases.

Other cases

No response

Anything else?

rustc --version
rustc 1.76.0-nightly (d86d65b 2023-12-10)

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

@rustbot claim

@Noratrieb Noratrieb removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Dec 11, 2023
@bors bors closed this as completed in 3cdd004 Dec 29, 2023
github-actions bot pushed a commit to rust-lang/miri that referenced this issue Dec 31, 2023
fix: correct the args for `disambiguate the associated function` diagnostic

This is somehow silimar to rust-lang/rust#118502, we shouldn't take receiver as first arg all the cases.

close rust-lang/rust#118819
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Apr 7, 2024
fix: correct the args for `disambiguate the associated function` diagnostic

This is somehow silimar to rust-lang/rust#118502, we shouldn't take receiver as first arg all the cases.

close rust-lang/rust#118819
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this issue Apr 27, 2024
fix: correct the args for `disambiguate the associated function` diagnostic

This is somehow silimar to rust-lang/rust#118502, we shouldn't take receiver as first arg all the cases.

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