Skip to content

Associated Type bounds not checked when checking for conflicting implementations of traits #52912

@ZerothLaw

Description

@ZerothLaw

Not sure if this has already been brought up or discussed elsewhere, and if so, I apologize in advance.

trait Xxx {
    type Target;
}
trait Yyy {}
trait Zzz {
    fn do_stuff(&self) -> i32;
}

struct Www{}
struct Uuu{}

struct Vvv {}
struct Qqq {}

impl Xxx for Vvv {
    type Target = Www;
}

//This is disallowed by the compiler
/*impl Xxx for Vvv {
    type Target = Uuu; 
}*/

impl<T> Zzz for T where T: Xxx<Target=Www> {
    fn do_stuff(&self) -> i32 {
        1
    }
}

//Therefore this should be possible. The two sets here are disjoint 
//with no possibility of overlap
impl<T> Zzz for T where T: Xxx<Target=Uuu> {
    fn do_stuff(&self) -> i32 {
        2
    }
}

fn main() {
}

(Playground)

Errors:

   Compiling playground v0.0.1 (file:///playground)
error[E0119]: conflicting implementations of trait `Zzz`:
  --> src/main.rs:32:1
   |
24 | impl<T> Zzz for T where T: Xxx<Target=Www> {
   | ------------------------------------------ first implementation here
...
32 | impl<T> Zzz for T where T: Xxx<Target=Uuu> {
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation

error: aborting due to previous error

For more information about this error, try `rustc --explain E0119`.
error: Could not compile `playground`.

To learn more, run the command again with --verbose.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions