Closed
Description
Minimized test case
(taken from bstrie's comment below)
fn main() {
let x = X;
x.foobar();
}
trait Foo {
fn foobar(&self);
}
trait Bar {
fn foobar(&self);
}
trait FooBase {}
trait BarBase {}
impl<T: FooBase> Foo for T {
fn foobar(&self) {}
}
impl<T: BarBase> Bar for T {
fn foobar(&self) {}
}
struct X;
impl FooBase for X {}
Original bug report follows
I tried implementing of a trait Eq
for a generic type T: OrdEx
, but rustc says conflicting between impl <T: OrdEx> T: Eq
and impl Cmp: Eq
.
extcmp.rs:
use cmp::{Eq, Ord};
enum Cmp { Lt, Eq, Gt }
trait OrdEx {
pure fn cmp(&&other: self) -> Cmp;
}
impl Cmp : Eq {
pure fn eq(&&other: Cmp) -> bool {
match (self, other) {
(Lt, Lt) | (Gt, Gt) | (Eq, Eq) => true,
_ => false
}
}
pure fn ne(&&other: Cmp) -> bool { !self.eq(other) }
}
impl<T: OrdEx> T : Eq {
pure fn eq(&&other: T) -> bool { match self.cmp(other) { Eq => true, _ => false } }
pure fn ne(&&other: T) -> bool { !self.eq(other) }
}
impl<T: OrdEx> T : Ord {
pure fn lt(&&other: T) -> bool { match self.cmp(other) { Lt => true, _ => false} }
pure fn le(&&other: T) -> bool { match self.cmp(other) { Lt | Eq => true, _ => false} }
pure fn ge(&&other: T) -> bool { match self.cmp(other) { Eq | Gt => true, _ => false} }
pure fn gt(&&other: T) -> bool { match self.cmp(other) { Gt => true, _ => false} }
}
fn main() {
}
$ rustc extcmp.rs
extcmp.rs:19:0: 22:1 error: conflicting implementations for a trait
extcmp.rs:19 impl<T: OrdEx> T : Eq {
extcmp.rs:20 pure fn eq(&&other: T) -> bool { match self.cmp(other) { Eq => true, _ => false } }
extcmp.rs:21 pure fn ne(&&other: T) -> bool { !self.eq(other) }
extcmp.rs:22 }
extcmp.rs:9:0: 17:1 note: note conflicting implementation here
extcmp.rs:9 impl Cmp : Eq {
extcmp.rs:10 pure fn eq(&&other: Cmp) -> bool {
extcmp.rs:11 match (self, other) {
extcmp.rs:12 (Lt, Lt) | (Gt, Gt) | (Eq, Eq) => true,
extcmp.rs:13 _ => false
extcmp.rs:14 }
...
extcmp.rs:16:40: 16:47 error: multiple applicable methods in scope
extcmp.rs:16 pure fn ne(&&other: Cmp) -> bool { !self.eq(other) }
^~~~~~~
extcmp.rs:10:4: 15:5 note: candidate #1 is `__extensions__::eq`
extcmp.rs:10 pure fn eq(&&other: Cmp) -> bool {
extcmp.rs:11 match (self, other) {
extcmp.rs:12 (Lt, Lt) | (Gt, Gt) | (Eq, Eq) => true,
extcmp.rs:13 _ => false
extcmp.rs:14 }
extcmp.rs:15 }
extcmp.rs:20:4: 20:87 note: candidate #2 is `__extensions__::eq`
extcmp.rs:20 pure fn eq(&&other: T) -> bool { match self.cmp(other) { Eq => true, _ => false } }
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to 2 previous errors