]>
Commit | Line | Data |
---|---|---|
60c5eb7d XL |
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 | ``` |