Open
Description
Summary
Casting a char
to a u32
is lossless, but the cast_lossless
lint doesn't cover it.
Lint Name
cast_lossless
Reproducer
I tried this code:
#![deny(clippy::cast_lossless)]
fn main() {
let _ = '|' as u32;
}
I expected to see this happen: Compiler error
error: casts from `char` to `u32` can be expressed infallibly using `From`
--> src/main.rs:4:13
|
4 | let _ = '|' as u32;
| ^^^^^^^^^^
|
= help: an `as` cast can become silently lossy if the types change in the future
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_lossless
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![deny(clippy::cast_lossless)]
| ^^^^^^^^^^^^^^^^^^^^^
help: use `u32::from` instead
|
4 | let _ = u32::from('|');
| ~~~~~~~~~~~~~~
Instead, this happened:
The code compiled without any issues.
Version
rustc 1.87.0-nightly (1aeb99d24 2025-03-19)
binary: rustc
commit-hash: 1aeb99d248e1b0069110cb03c6f1dcc7b36fd7f3
commit-date: 2025-03-19
host: x86_64-unknown-linux-gnu
release: 1.87.0-nightly
LLVM version: 20.1.0
(also on stable via playground)
This issue has been assigned to @lapla-cogito via this comment.