]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_error_codes/src/error_codes/E0054.md
Rollup merge of #92310 - ehuss:rustdoc-ice, r=estebank
[rust.git] / compiler / rustc_error_codes / src / error_codes / E0054.md
1 It is not allowed to cast to a bool.
2
3 Erroneous code example:
4
5 ```compile_fail,E0054
6 let x = 5;
7
8 // Not allowed, won't compile
9 let x_is_nonzero = x as bool;
10 ```
11
12 If you are trying to cast a numeric type to a bool, you can compare it with
13 zero instead:
14
15 ```
16 let x = 5;
17
18 // Ok
19 let x_is_nonzero = x != 0;
20 ```