Open
Description
Summary
unnecessary_cast triggers on casts from C FFI type aliases, even though the type aliases may not always match the type being cast to.
Lint Name
unnecessary_cast
Reproducer
I tried this code:
use core::ffi::c_ulong;
fn main() {
let x: c_ulong = 0;
let y = x as u64;
println!("Hello, {y}!");
}
I saw this happen:
warning: casting to the same type is unnecessary (`u64` -> `u64`)
--> src/main.rs:5:13
|
5 | let y = x as u64;
| ^^^^^^^^ help: try: `x`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
= note: `#[warn(clippy::unnecessary_cast)]` on by default
I expected to not get an error, because c_ulong
is a type alias that isn't always u64
.
I thought #8596 was supposed to fix this.
Version
rustc 1.68.1 (8460ca823 2023-03-20)
binary: rustc
commit-hash: 8460ca823e8367a30dda430efda790588b8c84d3
commit-date: 2023-03-20
host: x86_64-unknown-linux-gnu
release: 1.68.1
LLVM version: 15.0.6
Additional Labels
No response