Skip to content

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

Closed
@Young-Flash

Description

@Young-Flash

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)

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsT-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