Alias-eq weakens inference in HIR typeck
compiler-errors opened this issue · 1 comments
compiler-errors commented
originally reported this in lcnr/solver-woes#13 --
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));
}General direction of the fix would be to not prefer the subst-relate branch of alias-relate...
Something like compiler-errors/rust@d7001d2 + compiler-errors/rust@10064381389 (so we don't prefer alias-eq results that do no inference) will probably be needed ultimately, though fixed so it doesn't do this behavior during coherence, etc., maybe some other tweaking idk.