Open
Description
I tried this code:
fn main() {
println!("Overloading");
#[derive(Debug)]
struct Container2 {
val: String
};
trait AName2 {
fn name(&self) -> String;
}
trait BName2 {
fn name(&self, v: bool) -> String;
}
impl AName2 for Container2 {
fn name(&self) -> String {
"aname2".into()
}
}
impl BName2 for Container2 {
fn name(&self, v: bool) -> String {
"bname2".into()
}
}
let c2 = Container2 { val: "abc".into() };
println!("c2 = {:?}", c2.name());
}
I expected to see helpful message from compiler.
Instead, this happened:
54 | fn name(&self) -> String {
| ^^^^^^^^^^^^^^^^^^^^^^^^
note: candidate #2 is defined in an impl of the trait `BName2` for the type `Container2`
--> src/main.rs:60:9
|
60 | fn name(&self, v: bool) -> String {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
help: disambiguate the method for candidate #1
|
66 - println!("c2 = {:?}", c2.name());
66 + println!("c2 = {:?}", AName2::name(&c2));
|
help: disambiguate the method for candidate #2
|
66 - println!("c2 = {:?}", c2.name());
66 + println!("c2 = {:?}", BName2::name(&c2));
|
Suggestion in 66 is wrong, as BName2::name has TWO args, not one.
Meta
rustc --version --verbose
:
1.88.0 stable on rust playground