-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Closed
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.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.
Description
I tried this code:
#![feature(min_const_generics)]
struct X<const S: usize>;
impl<const S: usize> X<S> {
const LEN: usize = S + 1;
}
struct Y<const S: usize> {
stuff: [u8; { S + 1 }],
}This gave an error message:
error: generic parameters may not be used in const operations
--> src/lib.rs:10:17
|
10 | stuff: [u8; { S + 1 }],
| ^ cannot perform const operation using `S`
|
= help: const parameters may only be used as standalone arguments, i.e. `S`
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
But you can see in X::LEN that you can perform const operations using S, the restriction this hits is more subtle in that you cannot perform const operations using generic parameters when these will impact the type system (as I understand it, I may be wrong). This also comes up if a generic parameter is used in defining an associated type.
sassman, youknowone, natto1784, chuigda, saona-raimundo and 10 moreschneiderfelipe
Metadata
Metadata
Assignees
Labels
A-const-genericsArea: const generics (parameters and arguments)Area: const generics (parameters and arguments)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.Category: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.Diagnostics: Confusing error or lint that should be reworked.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.