Email me

Rust errors / Types and traits

Rust compiler error · checked with rustc 1.99.0

Rust error E0119: conflicting implementations of trait for type

What it meansTwo impl blocks could both apply to the same type, so Rust cannot pick one. Often a blanket impl (impl<T: X> Tr for T) overlaps a specific one.

What rustc prints

error[E0119]: conflicting implementations of trait `MyTrait` for type `Foo`
  --> main.rs:13:1
   |
 5 | impl<T> MyTrait for T {
   | --------------------- first implementation here
...
13 | impl MyTrait for Foo { // error: conflicting implementations of trait
   | ^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `Foo`

Real output of rustc 1.99.0 compiling the official example below (2021 edition). Your names and line numbers will differ; the first line is the part to match.

Why it happens

  • A blanket impl plus a specific impl for a type that also meets the blanket's bounds.
  • A derive (like #[derive(Clone)]) plus a manual impl of the same trait.
  • Your impl From<X> for Y clashing with the standard library's impl<T> From<T> for T.

How to fix it

1. Remove one of the two

Drop the derive or the manual impl.

2. Narrow the blanket impl

Use a marker trait or a newtype so the two never overlap.

struct Meters(f64);
impl From<Meters> for f64 { fn from(m: Meters) -> f64 { m.0 } }

Other wordings of this error

conflicting implementations of trait for type, conflicting implementation in crate, first implementation here

E0119Types and traits
Activein rustc 1.99.0
8related errors linked below

The compiler team's explanation

There are conflicting trait implementations for the same type.

Erroneous code example:

trait MyTrait {
    fn get(&self) -> usize;
}

impl<T> MyTrait for T {
    fn get(&self) -> usize { 0 }
}

struct Foo {
    value: usize
}

impl MyTrait for Foo { // error: conflicting implementations of trait
                       //        `MyTrait` for type `Foo`
    fn get(&self) -> usize { self.value }
}

When looking for the implementation for the trait, the compiler finds both the impl<T> MyTrait for T where T is all types and the impl MyTrait for Foo. Since a trait cannot be implemented multiple times, this is an error. So, when you write:

trait MyTrait {
    fn get(&self) -> usize;
}

impl<T> MyTrait for T {
    fn get(&self) -> usize { 0 }
}

This makes the trait implemented on all types in the scope. So if you try to implement it on another one after that, the implementations will conflict. Example:

trait MyTrait {
    fn get(&self) -> usize;
}

impl<T> MyTrait for T {
    fn get(&self) -> usize { 0 }
}

struct Foo;

fn main() {
    let f = Foo;

    f.get(); // the trait is implemented so we can use it
}

From rustc --explain E0119 (1.99.0), part of the Rust project, MIT or Apache-2.0. Official page.

Related errors

All 518 Rust error codes · Rust crate data · Glossary

Up next

Often hit nextE0308: mismatched typesA related error from the same family.Read it next →

Did this answer your question?

Get the receipts by email.

What my AI agents tried this week, with the real numbers: what worked, what flopped, what made money. One email when there is something worth reading.

No spam, never sold. Every email has a one-click unsubscribe.

Popular in the shop

All 124 tools →

Browse: Bundles and kitsHome, family and schoolMoney and businessAI toolsSports and fitnessMaking and hobbiesFood and drinkIndie dev and launchTrading and quant

Free: Landing page teardown iPhone app cost calculator LLM API cost calculator Paid online: $49 Launch Check App builds Articles FAQ