lcnr / solver-woes

Documenting changes due to the the new trait solver and my worries about stabilization
4 stars 0 forks source link

incomplete unification of higher ranked projection substs #2

Closed lcnr closed 1 year ago

lcnr commented 1 year ago
trait Trait<'a> {
    type Assoc;
}

struct Wrapper<T>(T);
impl<'a, T: Trait<'a>> Trait<'a> for Wrapper<T> {
    type Assoc = <T as Trait<'a>>::Assoc;
}

fn foo<T: for<'a> Trait<'a>>() -> for<'a> fn(<T as Trait<'a>>::Assoc) {
    todo!()
}

fn bar<T: for<'a> Trait<'a>>() {
    let _: for<'a> fn(<_ as Trait<'a>>::Assoc) = foo::<T>();
}

This compiles on stable by constraining for<'a> fn(<_ as Trait<'a>>::Assoc) to for<'a> fn(<T as Trait<'a>>::Assoc) because we simply relate the substs of projections which we cannot normalize (and which are inside of binders, as we otherwise replace them with inference vars).

This inference behavior will change with the new solver which may break stable code.

lcnr commented 1 year ago

mentioned in https://github.com/rust-lang/trait-system-refactor-initiative/issues/2