1

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.

quant_dev
  • 6,181
  • 1
  • 34
  • 57
  • 2
    "I am using 1.52.0" 1.52 is 7 months old, this feature was renamed from `const_evaluatable_checked` to `generic_const_exprs` 3 months ago, between the forking of 1.55 and 1.56. – Masklinn Dec 15 '21 at 15:18
  • 1
    Thanks, upgrading to 1.57 and moving the feature declarations to `src/lib.rs` solved the problem. – quant_dev Dec 15 '21 at 15:53

0 Answers0