Error: unconstrained generic constant


I am trying to write a generic struct which can store a data-set of variable size provided during compile time. I've encountered an error which I do not understand and would like to ask for your help.

struct DataSet<const N: usize>([u8; N]);

impl<const N: usize> DataSet<N> {
    fn double_size(&self) -> DataSet<{N*2}> {
        let mut data_set = DataSet([0; N*2]);
        for i in 0..N {
            data_set.0[i] = self.0[i];

    fn foo(&self, data_set: &DataSet<N>) {
        let tmp = data_set.double_size();

I get the error-message

error: unconstrained generic constant
--> src/bin/
487 | let tmp = data_set.double_size();
| ^^^^^^^^^^^
= help: try adding a where bound using this expression: where [(); {N*2}]:

You need the incomplete generic_const_exprs feature and the where bound suggested by the compiler like this.
You can also replace the N * 2 with Self::M via

impl<const N: usize> DataSet<N> {
    const M: usize = N * 2;

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.