RS.CLIPPY.CHAR_LIT_AS_U8
Casting a character literal to `u8` truncates
This checker is a Clippy lint created by The Rust Project Contributors. The documentation shown here is a copy of the original documentation for: char_lit_as_u8. Copyright ©2025 The Rust Team. All rights reserved.
What it does
Checks for expressions where a character literal is cast
to u8 and suggests using a byte literal instead.
Why is this bad?
In general, casting values to smaller types is
error-prone and should be avoided where possible. In the particular case of
converting a character literal to u8, it is easy to avoid by just using a
byte literal instead. As an added bonus, b\'a\' is also slightly shorter
than \'a\' as u8.
Example
\'x\' as u8
A better version, using the byte literal:
b\'x\'