-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Closed as not planned
Closed as not planned
Copy link
Labels
C-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.T-langRelevant to the language teamRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
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
Metadata
Metadata
Assignees
Labels
C-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.T-langRelevant to the language teamRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.