Closed as not planned
Description
Today this works:
fn bar<const N: usize>() {
let x = [0u32; N];
}
but this does not:
trait Foo {
const C: usize;
}
fn foo<T: Foo>() {
let x = [0u32; T::C];
}
with the following error:
error: constant expression depends on a generic parameter
--> src/lib.rs:7:20
|
7 | let y = [0u32; T::C];
| ^^^^
|
= note: this may fail depending on what value the parameter takes
We talked about this in the lang meeting today, and the consensus of those present was that this is not a sufficient justification for disallowing this. In particular, we are happy to allow this and issue a post-monomorphization error in the cases where the value of the const makes the array too large.
Ideally I'd like us to FCP this issue to formalize the consensus, but first want to collect any context we might be missing.
cc @nikomatsakis who had some context and was going to post it here.
cc @rust-lang/types; is there another justification we're missing?
cc @rust-lang/lang