Specialization and Associated Const Equality give auto traits

Hello, I just want to share interesting thing: if specialization and associated const equality are combined, they basically give auto traits:

    trait Auto {
        const BOOL: bool;
    }
    impl<T> Auto for T {
        default const BOOL: bool = false;
    }
    impl Auto for i32 {
        const BOOL: bool = true;
    }
    fn auto<T: Auto<BOOL = true>>(t: T)
    where
        T: Auto,
    {
    }

And even that (iirc it was explicitly broken resently for auto traits):

    trait Different {}
    trait DifferentBool {
        const BOOL: bool;
    }
    impl<A, B> DifferentBool for (A, B) {
        default const BOOL: bool = true;
    }
    impl<A> DifferentBool for (A, A) {
        const BOOL: bool = false;
    }
    impl<A, B> Different for (A, B) where (A, B): DifferentBool<BOOL = true> {}

    fn different<A, B>(_: A, _: B)
    where
        (A, B): Different,
    {
    }

    fn foo() {
        different(42u8, 42u16);
    }

That code is not compiling in nightly with features, but it is probably a problem with implementation.

Auto traits are based on a type’s fields, so this isn’t really all the way there. You’d need some kind of compile-time introspection for that.