docs

You are reading the docs for v0.1.0. Nabi 0.1.0 is no longer supported. Latest release: v0.1.3 →

#E0075: conflicting implementations

Two impls give the same trait, or the same method, for one type. Remove one, or narrow a generic impl so they no longer overlap.

nabi
trait Show { fn show(self) -> str; }
impl<T> Show for T { fn show(self) -> str { "any" } }
impl Show for i32 { fn show(self) -> str { "i32" } }
error[E0075]: conflicting implementations of trait `Show` for `i32`: the concrete impl overlaps `impl<..> Show for T` (one impl per trait and type; no specialization)
  --> main.nabi:2:18
   |
 2 | impl<T> Show for T { fn show(self) -> str { "any" } }
   |                  ^
   |
   = help: put the `i32` case in the generic impl: `if Self is i32 { .. }`

Keep one impl for each trait and type:

nabi
trait Show { fn show(self) -> str; }
impl Show for i32 { fn show(self) -> str { "i32" } }
println(3.show());
i32

Or keep the generic impl and give i32 its own branch in it:

nabi
trait Show { fn show(self) -> str; }
impl<T> Show for T {
    fn show(self) -> str {
        if Self is i32 { "i32" } else { "any" }
    }
}
println(f"{3i32.show()} {1.5.show()}");
i32 any

Related: E0076 impl of a foreign trait for a foreign type, E0087 ambiguous associated item

Found a mistake? Edit this page on GitHub. Last updated