I'm not sure if it is expected behavior or not.
I tried this code:
fn main() {
if 1 as f64 < 0.0 && 1 >= 0 {
}
}
I expected to see this happen: the code compiles without errors
Instead, this happened:
Compiling playground v0.0.1 (/playground)
error: expressions must be enclosed in braces to be used as const generic arguments
--> src/main.rs:3:19
|
3 | if 1 as f64 < 0.0 && 1 >= 0 {
| ^^^^^^^^
|
help: enclose the `const` expression in braces
|
3 | if 1 as f64 < { 0.0 && 1 } >= 0 {
| + +
error[E0109]: const arguments are not allowed for this type
--> src/main.rs:3:19
|
3 | if 1 as f64 < 0.0 && 1 >= 0 {
| ^^^^^^^^ const argument not allowed
error[E0308]: mismatched types
--> src/main.rs:3:8
|
3 | if 1 as f64 < 0.0 && 1 >= 0 {
| ^^^^^^^^^^^^^^^^^^^^^^^^ expected `bool`, found `()`
|
help: you might have meant to use pattern matching
|
3 | if let 1 as f64 < 0.0 && 1 >= 0 {
| +++
error[E0308]: mismatched types
--> src/main.rs:3:19
|
3 | if 1 as f64 < 0.0 && 1 >= 0 {
| ^^^ expected `bool`, found floating-point number
error[E0308]: mismatched types
--> src/main.rs:3:26
|
3 | if 1 as f64 < 0.0 && 1 >= 0 {
| ^ expected `bool`, found integer
Some errors have detailed explanations: E0109, E0308.
For more information about an error, try `rustc --explain E0109`.
error: could not compile `playground` due to 5 previous errors
rustc 1.54.0 stable.
If I change to (1 as f64) < 0.0 && 1 >= 0 it compiles.
Link to playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=48dbdf8fc80dde053da67f6b3db3d143
I'm not sure if it is expected behavior or not.
I tried this code:
I expected to see this happen: the code compiles without errors
Instead, this happened:
rustc 1.54.0 stable.
If I change to (1 as f64) < 0.0 && 1 >= 0 it compiles.
Link to playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=48dbdf8fc80dde053da67f6b3db3d143