Skip to content

alias-eq is weaker than just subst-relate for "rigid" associated types #2

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

Closed
compiler-errors opened this issue Apr 13, 2023 · 1 comment

Comments

@compiler-errors
Copy link
Member

trait Mk {
    type Assoc;
}

fn mk<T: Mk>(t: T) -> T::Assoc {
    todo!()
}

fn foo<S: Mk + Default>() {
    let x = Default::default();
    let y = mk::<_ /* ?z */>(x);
    let x: S = x;
}
error[E0282]: type annotations needed for `<_ as Mk>::Assoc`
  --> <source>:11:9
   |
11 |     let y = mk::<_ /* ?z */>(x);
   |         ^
   |
help: consider giving `y` an explicit type, where the type for associated type `<_ as Mk>::Assoc` is specified
   |
11 |     let y: <_ as Mk>::Assoc = mk::<_ /* ?z */>(x);
   |          ++++++++++++++++++

Related, heavily reduced from an example in syn:

fn main() {
    let mut x: Vec<_> = vec![];
    x.extend(Some(1i32).into_iter().map(|x| x));
}
@lcnr lcnr changed the title Alias-eq is weaker than just subst-relate for "rigid" associated types alias-eq is weaker than just subst-relate for "rigid" associated types Apr 14, 2023
@lcnr
Copy link
Contributor

lcnr commented Apr 17, 2023

This is related to

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants