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

disjointness based on associated types #10

Open
lcnr opened this issue Oct 22, 2024 · 0 comments
Open

disjointness based on associated types #10

lcnr opened this issue Oct 22, 2024 · 0 comments

Comments

@lcnr
Copy link
Owner

lcnr commented Oct 22, 2024

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)

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

1 participant