-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed
Closed
Copy link
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.F-const_generics`#![feature(const_generics)]``#![feature(const_generics)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
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).
varkor
Metadata
Metadata
Assignees
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-inferenceArea: Type inferenceArea: Type inferenceC-bugCategory: This is a bug.Category: This is a bug.F-const_generics`#![feature(const_generics)]``#![feature(const_generics)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.