]> git.lizzy.rs Git - rust.git/blob - src/docs/char_lit_as_u8.txt
[Arithmetic] Consider literals
[rust.git] / src / docs / char_lit_as_u8.txt
1 ### What it does
2 Checks for expressions where a character literal is cast
3 to `u8` and suggests using a byte literal instead.
4
5 ### Why is this bad?
6 In general, casting values to smaller types is
7 error-prone and should be avoided where possible. In the particular case of
8 converting a character literal to u8, it is easy to avoid by just using a
9 byte literal instead. As an added bonus, `b'a'` is even slightly shorter
10 than `'a' as u8`.
11
12 ### Example
13 ```
14 'x' as u8
15 ```
16
17 A better version, using the byte literal:
18
19 ```
20 b'x'
21 ```