I have the following code in src/algebra.rs
:
#![feature(const_generics, generic_const_exprs)]
// Algebra module.
struct Polynomial<const Order: usize> {
coefficients: [f64; Order + 1] // f(x) = sum_i=0^Order coefficients[i] * x^i
}
which is imported in src/lib.rs
:
pub mod algebra;
When I run cargo +nightly build
, I still get the error:
error: generic parameters may not be used in const operations
--> src\algebra.rs:5:25
|
5 | coefficients: [f64; Order + 1] // f(x) = sum_i=0^Order coefficients[i] * x^i
| ^^^^^ cannot perform const operation using `Order`
|
= help: const parameters may only be used as standalone arguments, i.e. `Order`
= help: use `#![feature(const_generics)]` and `#![feature(const_evaluatable_checked)]` to allow generic const expressions
error: aborting due to previous error
error: could not compile `optimisation`
To learn more, run the command again with --verbose.
I'm confused, because https://blog.rust-lang.org/inside-rust/2021/09/06/Splitting-const-generics.html says that #![feature(generic_const_exprs)]
is enough to enable const generic expressions? What am I doing wrong?
I am using 1.52.0 version of Rust.