Skip to content

disjointness based on associated types #10

Open
@lcnr

Description

@lcnr

it is possible to have multiple blanket impls whose disjointness is guaranteed by a projection super bound:

trait Trait {
    type Assoc;
}

trait Foo: Trait<Assoc = u32> {}
trait Bar: Trait<Assoc = String> {}

trait TwoBlankets {
    fn method();
}

mod blanket_impls {
    use super::*;
    trait Helper<A> {
        fn method();
    }
    impl<T: Trait + Helper<T::Assoc>> TwoBlankets for T {
        fn method() {
            <T as Helper<T::Assoc>>::method()
        }
    }
    impl<T: Foo> Helper<u32> for T {
        fn method() {
            println!("Foo");
        }
    }
    impl<T: Bar> Helper<String> for T {
        fn method() {
            println!("Bar");
        }
    }
}

first seen in rust-lang/rfcs#1672 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions