- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Description
play.rust-lang.org: http://is.gd/AnPaWL
When the same trait is used more than one time but for different concrete types, it triggers the error for duplicate constraints without being sound.
pub trait Get<T> {
    fn get(&self) -> T;
}
pub struct Foo {
    one: uint,
    two: uint
}
pub struct One(pub uint);
pub struct Two(pub uint);
impl Get<One> for Foo {
    fn get(&self) -> One { One(self.one) }
}
impl Get<Two> for Foo {
    fn get(&self) -> Two { Two(self.two) }
}
// error: trait `Get<Two>` already appears in the list of bounds [E0127]
fn bar<T: Get<One> + Get<Two>>(bar: &T) {
    let One(one) = bar.get();
    println!("{}", one);
    let Two(two) = bar.get();
    println!("{}", two);
}
fn main() {
    let foo = Foo { one: 1, two: 2 };
    // Works:
    let One(one) = foo.get();
    println!("{}", one);
    let Two(two) = foo.get();
    println!("{}", two);
    // Does not work:
    bar(&foo);
}Metadata
Metadata
Assignees
Labels
No labels