W3cubDocs

/Rust

Error code E0054

It is not allowed to cast to a bool.

Erroneous code example:

#![allow(unused)]
fn main() {
let x = 5;

// Not allowed, won't compile
let x_is_nonzero = x as bool;
}

If you are trying to cast a numeric type to a bool, you can compare it with zero instead:

#![allow(unused)]
fn main() {
let x = 5;

// Ok
let x_is_nonzero = x != 0;
}

© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/error_codes/E0054.html