-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Description
We should support array expressions as direct const arguments so that array types as const generics work nicely.
#![feature(min_generic_const_args, adt_const_params)]
fn takes_array<const A: [u32; 3]>() {}
fn generic_caller<const N: u32, const N2: u32>() {
takes_array::<{ [N, N2, 1 + 1] }>();
}These should lower directly to a ConstKind::Value in HIR ty lowering.
Supporting array repeat expression, e.g. takes_array::<{ [N; 3] }>(); is more complex as we can't lower to a ConstKind::Value. It should be done separately from the previous change.
We can possibly shoehorn this into the ConstKind::Unevaluated by defining a const item such as const REPEAT<T, const E: T, const N: usize>: [T, N] = [E; N];. This likely has to wait until feature(generic_const_args) exists. It's unclear how lowering the argument to the T type parameter should work as we can't try to solve a ConstArgHasType(E, ?x) goal to produce the inferred ?x.
Alternatively this could motivate a ConstKind::Expr variant.