Skip to content

Bug in checker for duplicate constraints #18693

Closed
@bvssvni

Description

@bvssvni

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

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