Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
ZerothLaw opened this issue Jul 31, 2018 · 1 comment

Comments

@ZerothLaw
Copy link

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.

@dtolnay
Copy link
Member

dtolnay commented Aug 13, 2018

Closing as a duplicate of #20400. Thanks anyway!

@dtolnay dtolnay closed this as completed Aug 13, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants