Open CrazyboyQCD opened 1 week ago
cast_lossless does not effect on conversion of 8 or 16 bit integer to isize/usize.
cast_lossless
isize/usize
I tried this code:
fn main() { let x = 1u8; let y = 1i16; let a = x as usize; let b = y as isize; println!("{} {}", a, b); }
cargo clippy --fix -- -D clippy::cast_lossless I expected to see this happen: Convert the code into:
cargo clippy --fix -- -D clippy::cast_lossless
fn main() { let x = 1u8; let y = 1i16; let a = usize::from(x); let b = isize::from(y); println!("{} {}", a, b); }
Instead, this happened: Nothing changed.
rustc 1.81.0-nightly (bcf94dec5 2024-06-23) binary: rustc commit-hash: bcf94dec5ba6838e435902120c0384c360126a26 commit-date: 2024-06-23 host: x86_64-pc-windows-msvc release: 1.81.0-nightly LLVM version: 18.1.7
[_ as usize] is a common statement and [usize::from(_)] is noisy with brackets sticked together, so it would be better to leave [_ as usize] unchanged.
[_ as usize]
[usize::from(_)]
Summary
cast_lossless
does not effect on conversion of 8 or 16 bit integer toisize/usize
.Lint Name
cast_lossless
Reproducer
I tried this code:
cargo clippy --fix -- -D clippy::cast_lossless
I expected to see this happen: Convert the code into:Instead, this happened: Nothing changed.
Version