Closed
Description
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();
}
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
[-]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[/+]olegnn commentedon Oct 21, 2019
UPD: the same problem occurs with (&mut self).
Use structured suggestion for disambiguating method calls
Rollup merge of rust-lang#67127 - estebank:disambiguate-suggestion, r…
Rollup merge of rust-lang#67127 - estebank:disambiguate-suggestion, r…
Rollup merge of rust-lang#67127 - estebank:disambiguate-suggestion, r…
Rollup merge of rust-lang#67127 - estebank:disambiguate-suggestion, r…
Rollup merge of rust-lang#67127 - estebank:disambiguate-suggestion, r…
Rollup merge of rust-lang#67127 - estebank:disambiguate-suggestion, r…