Hello,
I am not sure if I'm doing something wrong or this is a bug to be reported, but this is the situation:
The following code on its own (as expected) does not compile:

trait Trait { const N: usize; fn foo() -> [u8; Self::N]; } 

The error message suggests adding the generic_const_exprs feature or gca_const_items (which I assume is a new feature, I have not heard of it before). After using gca_const_items, the compiler suggestion is this:

 | 5 | fn foo() -> [u8; Self::N]; | ^^^^ | = help: consider factoring the expression into a `type const` item and use it as the const argument instead 

Which I understood to mean that the correct form is:

#![feature(gca_const_items)] #![feature(gca_min_const_items)] trait Trait { type const N: usize; fn foo() -> [u8; Self::N]; } 

This is also what the documentation in the Unstable Book describes, but it fails with a parse error:

 | 4 | type const N: usize; | ^^^^^ expected identifier, found keyword 

Is there some other feature I need to enable? The docs are not exactly detailed or beginner-friendly as to what the type const syntax even means, or how to use it...

3 posts - 2 participants

Read full topic