3

I am following Rust By Example and am getting an error which I am not sure how to address:

fn main() {
    let x: f32 = 10.;

    if (x == 10) {
        println!("if");
    } else if (x > 10) && (x<-5) {
        println!("else if");
    } else {
        println!("else");
    }
}

The compiling error below looks to be as a results of the else if. How do perform two conditional checks in the else if and why is it not working?

error: placement-in expression syntax is experimental and subject to change. (see issue #27779)
 --> src/main.rs:6:28
  |
6 |     } else if (x > 10) && (x<-5) {
  |                            ^^^^
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Greg
  • 8,175
  • 16
  • 72
  • 125
  • 2
    Reminded me of [this classic](https://stackoverflow.com/questions/1642028/what-is-the-operator-in-c). – ljedrz Oct 31 '17 at 15:32

1 Answers1

6

Because you are writing x<-5 instead of x < -5 with whitespaces, Rust sees <- as the placement operator. Putting whitespace around your operators would in general be best, since it fixes this and also improved readability a lot.

loganfsmyth
  • 156,129
  • 30
  • 331
  • 251