E4017#
Method of type is ambiguous, it may come from multiple traits.
Erroneous Example#
struct S { v : Int } derive(Show)
trait Tee { to_string(Self) -> String }
impl Tee for S with to_string(_self) { "Tee" }
let s : S = { v: 3 }
let t = s.to_string()
The example above tries to call the method to_string
on a type S
,
but the method name comes from both Show
and Tee
traits,
giving the following error on line 8:
Method to_string of type S is ambiguous, it may come from trait Tee or Show
Suggestion#
Disambiguate the method by specifying the trait it comes from:
struct S { v : Int } derive(Show)
trait Tee { to_string(Self) -> String }
impl Tee for S with to_string(_self) { "Tee" }
let s : S = { v: 3 }
let t = Tee::to_string(s)