I had a struct containing a array of values
struct WithConstGeneric<const R:usize, T>
{
values: [T; R]
}
And I thought it would be nice to use an associated constant instead
#![feature(generic_const_exprs)]
struct WithTrait<T, R: Resolution>
{
values: [T; R::ENTRIES]
}
trait Resolution {
const ENTRIES: usize;
}
struct Hour;
impl Resolution for Hour {
const ENTRIES: usize = 24;
}
to my suprise this does not compile.
The error message helpfully points out how to make it work.
error: unconstrained generic constant
--> src/main.rs:18:13
|
18 | values: [T; R::ENTRIES]
| ^^^^^^^^^^^^^^^
| help: try adding a `where` bound
|
13 | struct WithTrait<T, R: Resolution> where [(); R::ENTRIES]:
|
I was again surprised that where bounds with nothing on the right of the : are even a thing but I guess it makes sense when the only requirement is that the type is valid.
It seems like it should not be needed given that struct WithConstGeneric<const R:usize, T>
works without a where bound. The question is am I wrong and it is needed for some reason I failed to consider or can / will the need for this bound be removed in the future given that generic_const_exprs is explicitly marked as incomplete?