E4017

E4017#

Method of type is ambiguous, it may come from multiple traits.

Erroneous Example#

priv struct S {
  v : Int
}

priv trait A {
  value(Self) -> Int
}

priv trait B {
  value(Self) -> Int
}

impl A for S with value(self) {
  self.v
}

impl B for S with value(self) {
  self.v + 1
}

pub fn read() -> Int {
  let s : S = { v: 3 }
  s.value()
}

The example above tries to call the method value on a type S, but the method name comes from both A and B traits, giving an error like:

Method value of type S is ambiguous, it may come from trait A or B

Suggestion#

Disambiguate the method by specifying the trait it comes from:

priv struct S {
  v : Int
}

priv trait A {
  value(Self) -> Int
}

priv trait B {
  value(Self) -> Int
}

impl A for S with value(self) {
  self.v
}

impl B for S with value(self) {
  self.v + 1
}

pub fn read() -> Int {
  let s : S = { v: 3 }
  A::value(s) + B::value(s)
}