Skip to content

Incorrect compiler hint for method with (&self) and (&mut self) signature when multiple applicable items are found in scope #65635

Closed
@olegnn

Description

@olegnn
Contributor

Code:

trait A {
    fn method(&self) {
        println!("A");
    }
}

trait B {
    fn method(&self) {
        println!("B");
    }
}

struct Empty {}

impl A for Empty {}
impl B for Empty {}

fn main() {
    Empty {}.method();
}

Playground

Error:

error[E0034]: multiple applicable items in scope
  --> src/main.rs:19:14
   |
19 |     Empty {}.method();
   |              ^^^^^^ multiple `method` found
   |
note: candidate #1 is defined in an impl of the trait `A` for the type `Empty`
  --> src/main.rs:2:5
   |
2  |     fn method(&self) {
   |     ^^^^^^^^^^^^^^^^
   = help: to disambiguate the method call, write `A::method(Empty {})` instead
note: candidate #2 is defined in an impl of the trait `B` for the type `Empty`
  --> src/main.rs:8:5
   |
8  |     fn method(&self) {
   |     ^^^^^^^^^^^^^^^^
   = help: to disambiguate the method call, write `B::method(Empty {})` instead

Should be A::method(&Empty {}) and B::method(&Empty {}).

Activity

added
A-diagnosticsArea: Messages for errors, warnings, and lints
A-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`
C-bugCategory: This is a bug.
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.
on Oct 20, 2019
changed the title [-]Incorrect compiler hint for method with (&self) signature when multiple applicable items are found in scope[/-] [+]Incorrect compiler hint for method with (&self) and (&mut self) signature when multiple applicable items are found in scope[/+] on Oct 21, 2019
olegnn

olegnn commented on Oct 21, 2019

@olegnn
ContributorAuthor

UPD: the same problem occurs with (&mut self).

added a commit that references this issue on Dec 12, 2019
3980342
added a commit that references this issue on Dec 18, 2019

Rollup merge of rust-lang#67127 - estebank:disambiguate-suggestion, r…

67d560b
added a commit that references this issue on Dec 18, 2019

Rollup merge of rust-lang#67127 - estebank:disambiguate-suggestion, r…

c012ebb
added a commit that references this issue on Dec 19, 2019

Rollup merge of rust-lang#67127 - estebank:disambiguate-suggestion, r…

dced4c2
added 3 commits that reference this issue on Dec 19, 2019

Rollup merge of rust-lang#67127 - estebank:disambiguate-suggestion, r…

8c15656

Rollup merge of rust-lang#67127 - estebank:disambiguate-suggestion, r…

c9f0481

Rollup merge of rust-lang#67127 - estebank:disambiguate-suggestion, r…

f0eb4b4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`C-bugCategory: This is a bug.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

      Participants

      @jonas-schievink@olegnn

      Issue actions

        Incorrect compiler hint for method with (&self) and (&mut self) signature when multiple applicable items are found in scope · Issue #65635 · rust-lang/rust