Skip to content

MGCA: Support array expressions as direct const arguments #150612

@BoxyUwU

Description

@BoxyUwU

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.

Metadata

Metadata

Assignees

Labels

A-const-genericsArea: const generics (parameters and arguments)E-mediumCall for participation: Medium difficulty. Experience needed to fix: Intermediate.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.F-min_generic_const_args`#![feature(min_generic_const_args)]`T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions