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) {
  |                            ^^^^
1
  • 2
    Reminded me of this classic. Commented Oct 31, 2017 at 15:32

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.