I'm experimenting with const expressions and generics in Rust and stumbled across the following problem. When I want to use the const generic argument (here N
) indirectly like for example N + 1
, the compiler tells me that I need to add a "where-bound" like this one:
where [(); N + 1]:,
.
I don't understand the meaning of this. To me it looks like a constraint that says: "There is an array of type "empty tuple / unit" and "N + 1" entries which is bound to (nothing; as there is nothing after the colon)".
Can anyone help me understand the parts of this constraint?
Minimal example:
#![allow(unused)]
#![allow(incomplete_features)]
#![feature(generic_const_exprs)]
struct Foo<const N: usize> {}
impl<const N: usize> Foo<N>
where
[(); N + 1]:,
{
const BAR: [u32; N + 1] = [0u32; N + 1];
}
fn main() {}