Skip to main content

E0005: Unary Operator Type Mismatch

You used a unary operator with the wrong type.

Example

fn main() {
let x = -true; // Error: unary `-` expects type `i64` but found `bool`
}
fn main() {
let x = !42; // Error: unary `!` expects type `bool` but found `i64`
}

How to fix

Use the correct type for the operator:

fn main() {
let x = -42; // OK: negating an integer
let y = !true; // OK: logical not on a boolean
}