Skip to content

E0119 errors are unhelpful when doing things involving types from another crate #36162

Closed
@glandium

Description

@glandium

I was trying to do something like this:

use std::io;

enum Foo<T> {
    Bar(T),
    Qux,
}

impl<T: PartialEq> PartialEq for Foo<T> {
    fn eq(&self, other: &Self) -> bool {
        match (self, other) {
            (&Foo::Bar(ref a), &Foo::Bar(ref b)) => a == b,
            (&Foo::Qux, &Foo::Qux) => true,
            (_, _) => false,
        }
    }
}

impl PartialEq for Foo<io::Error> {
    fn eq(&self, other: &Self) -> bool {
        unimplemented!()
    }
}

And got the following error as a result:

error: conflicting implementations of trait `std::cmp::PartialEq` for type `Foo<std::io::Error>`: [--explain E0119]
  --> <anon>:18:1
   |>
18 |> impl PartialEq for Foo<io::Error> {
   |> ^
note: conflicting implementation is here:
 --> <anon>:8:1
  |>
8 |> impl<T: PartialEq> PartialEq for Foo<T> {
  |> ^

error: aborting due to previous error

In and of itself, there is no straightforward explanation as to why this is happening, since io::Error doesn't implement PartialEq.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions