Skip to content
Latchkey

Rust E0119 "conflicting implementations of trait" in CI

rustc found two trait implementations that can both apply to the same type. Coherence forbids overlap, so it refuses to pick one -- commonly a hand-written impl colliding with a #[derive] or a blanket impl.

What this error means

The build stops with error[E0119]: conflicting implementations of trait Foo for type Bar`` and points at both impls. It reproduces deterministically.

cargo
error[E0119]: conflicting implementations of trait `Default` for type `Config`
 --> src/config.rs:8:10
  |
5 | #[derive(Default)]
  |          ------- first implementation here
...
8 | impl Default for Config { fn default() -> Self { Config { retries: 3 } } }
  | ^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Config`

Common causes

Manual impl plus a derive

A #[derive(Default)] (or similar) generates an impl, and a hand-written impl Default for the same type overlaps it.

Overlap with a blanket impl

A blanket impl such as impl<T: Bar> Foo for T already covers your type, so a specific impl Foo for MyType conflicts.

How to fix it

Keep only one implementation

  1. Decide whether you want the derived behavior or the manual one.
  2. Remove the #[derive(...)] if you keep the manual impl, or delete the manual impl if the derive is enough.
  3. For blanket-impl overlap, drop the specific impl or narrow the blanket bound so it no longer covers your type.
src/config.rs
// keep the manual impl, drop the derive:
struct Config { retries: u32 }
impl Default for Config {
    fn default() -> Self { Config { retries: 3 } }
}

How to prevent it

  • Do not pair a manual trait impl with a derive of the same trait.
  • Audit blanket impls before adding a specific impl for a covered type.
  • Run cargo check after adding or removing derives.

Frequently asked questions

What causes ""E0119: conflicting implementations""?
A #[derive(Default)] (or similar) generates an impl, and a hand-written impl Default for the same type overlaps it.
How do I fix "E0119: conflicting implementations"?
Keep only one implementation

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card