Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Rust: other types don't have true/false values

fn main() {
    let x = 3;
    if x {
        println!("x is true");
    }
}
error[E0308]: mismatched types
 --> examples/booleans/other.rs:3:8
  |
3 |     if x {      // expected `bool`, found integer
  |        ^ expected `bool`, found integer

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
  • expected bool, found integer