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

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

Closed
olegnn opened this issue Oct 20, 2019 · 1 comment · Fixed by #67127
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-bug Category: This is a bug. 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

@olegnn
Copy link
Contributor

olegnn commented Oct 20, 2019

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 {}).

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-bug Category: This is a bug. 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. labels Oct 20, 2019
@olegnn olegnn 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 Oct 21, 2019
@olegnn
Copy link
Contributor Author

olegnn commented Oct 21, 2019

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

Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Dec 18, 2019
…=varkor

Use structured suggestion for disambiguating method calls

Fix rust-lang#65635.
tmandry added a commit to tmandry/rust that referenced this issue Dec 18, 2019
…=varkor

Use structured suggestion for disambiguating method calls

Fix rust-lang#65635.
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this issue Dec 19, 2019
…=varkor

Use structured suggestion for disambiguating method calls

Fix rust-lang#65635.
Centril added a commit to Centril/rust that referenced this issue Dec 19, 2019
…=varkor

Use structured suggestion for disambiguating method calls

Fix rust-lang#65635.
Centril added a commit to Centril/rust that referenced this issue Dec 20, 2019
…=varkor

Use structured suggestion for disambiguating method calls

Fix rust-lang#65635.
Centril added a commit to Centril/rust that referenced this issue Dec 20, 2019
…=varkor

Use structured suggestion for disambiguating method calls

Fix rust-lang#65635.
@bors bors closed this as completed in 3980342 Dec 20, 2019
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-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. C-bug Category: This is a bug. 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.

2 participants