Closed
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.