Closed
Description
I've come up with this example (playground):
#![feature(const_generics)]
fn works() {
let array/*: [_; _]*/ = default_array();
let _: [_; 4] = array;
Foo::foo(&array);
}
fn doesnt_work() {
let array/*: [_; _]*/ = default_array();
// ^ cannot infer type for type parameter `T` declared on the function `default_array`
Foo::foo(&array);
let _: [_; 4] = array;
}
trait Foo {
fn foo(&self) {}
}
impl Foo for [i32; 4] {}
impl Foo for [i64; 8] {}
// Only needed because `[_; _]` is not valid type syntax.
fn default_array<T, const N: usize>() -> [T; N]
where [T; N]: Default,
{
Default::default()
}
My understanding is that the error is caused by the [$T; $C]: Foo
obligation being stalled_on
on just $T
(which means it's not retried when $C
is unified with 4
), whereas it should be stalled on both $T
and $C
so that it's retried when either changes.
Right now stalled_on
is limited to type inference variables, so its representation will need to change, and Ty::walk
will need to expose constants too.
I believe #70107 ran into this as well, but for WF obligations, not trait ones.
I'm self-assigning this because I'm working on the fix (as part of a larger effort).