You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Compiling playground v0.0.1 (/playground)
error[E0015]: cannot call non-const operator in constants
--> src/main.rs:6:26
|
6 | const Z: Complex32 = X + Y;
| ^^^^^
|
note: impl defined here, but it is not `const`
--> /playground/.cargo/registry/src/index.crates.io-6f17d22bba15001f/num-complex-0.4.4/src/lib.rs:724:1
|
724 | impl<T: Clone + Num> Add<Complex<T>> for Complex<T> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: calls in constants are limited to constant functions, tuple structs and tuple variants
For more information about this error, try `rustc --explain E0015`.
The text was updated successfully, but these errors were encountered:
Rust as a language doesn't have const trait implementations yet, so we don't have any way to make stuff like operator + const. Most of the inherent methods of Complex also depend on trait bounds, so they can't be const yet either -- e.g. even something simple like const fn i() would need const Zero and One.
oh, sorry, i didn't even realise that!
i just looked around a bit and it seems that it'll need this nightly feature to be stabilised: rust-lang/rust#67792
once that's done it should be possible to make these implementations const
as the title says: it'd be great if as many functions as possible were made
const
so that they can be used in a const environment.currently this code will not compile because the
Add
implementation ofComplex
isn'tconst
:you can find the same example on the playground.
error from the playground:
The text was updated successfully, but these errors were encountered: