I am trying to compile code such as the following:
lib.rs
use nalgebra::ComplexField;
use num::FromPrimitive;
use bacon_sci::polynomial;
use bacon_sci::polynomial::Polynomial;
fn foo <R> () -> Polynomial <R>
where
R: FromPrimitive + ComplexField + Copy,
<R as ComplexField>::RealField: Copy + FromPrimitive
{
polynomial! (1, 2, 3)
}
It fails with:
Compiling learning_engine v0.1.0 (/home/zistack/Projects/learning_engine)
error[E0277]: the trait bound `R: simba::scalar::complex::ComplexField` is not satisfied
--> src/lib.rs:6:18
|
6 | fn foo <R> () -> Polynomial <R>
| ^^^^^^^^^^^^^^ the trait `simba::scalar::complex::ComplexField` is not implemented for `R`
|
note: required by a bound in `Polynomial`
--> /home/zistack/.cargo/registry/src/github.com-1ecc6299db9ec823/bacon-sci-0.13.1/src/polynomial/mod.rs:10:26
|
10 | pub struct Polynomial<N: ComplexField + FromPrimitive + Copy>
| ^^^^^^^^^^^^ required by this bound in `Polynomial`
help: consider further restricting this bound
|
8 | R: FromPrimitive + ComplexField + Copy + simba::scalar::complex::ComplexField,
| ++++++++++++++++++++++++++++++++++++++
For more information about this error, try `rustc --explain E0277`.
error: could not compile `learning_engine` due to previous error
Why?
Here's what really confuses me about this. bacon-sci
imports their ComplexField trait from nalgebra
exactly the same way I do in the file that defines the Polynomial
type, and nalgebra
does indeed get their definition from simba
. The compiler correctly identifies the trait that needs to be satisfied, but somehow doesn't believe that I'm forcing it to be satisfied, even though I'm pulling the trait from exactly the same place.
Adding the code that the compiler suggests doesn't work, because simba::scalar::complex
is a private module. Adding simba::scalar::ComplexField
(which is what you would normally do) also doesn't work, failing in exactly the same way as before.
I am using rust nightly.
The relevant section of my Cargo.toml
:
[dependencies]
bacon-sci = "0.13"
nalgebra = "0.31"
num = "0.4"
simba = "0.7"