Summary
Closely related to #6331:
#[cfg(unix)]
type CfgDependent = u8;
#[cfg(not(unix))]
type CfgDependent = i8;
type AlsoCfgDependent = CfgDependent;
fn main() {
let _ = 0 as CfgDependent;
let _ = 0 as AlsoCfgDependent;
}
$ cargo clippy
warning: casting integer literal to `u8` is unnecessary
--> src/main.rs:11:13
|
11 | let _ = 0 as AlsoCfgDependent;
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `0_u8`
|
= note: `#[warn(clippy::unnecessary_cast)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_cast
Following the fix of #6331, Clippy is correctly no longer triggering unnecessary_cast on 0 as CfgDependent. However the same lint is still triggered on 0 as AlsoCfgDependent in which Clippy's suggested replacement is incorrect for exactly the same reason. It would be better to transitively look through type aliases when looking for the presence of a cfg attribute.
Lint Name
unnecessary_cast
Version
rustc 1.59.0-nightly (0b6f079e4 2021-12-07)
binary: rustc
commit-hash: 0b6f079e4987ded15c13a15b734e7cfb8176839f
commit-date: 2021-12-07
host: x86_64-unknown-linux-gnu
release: 1.59.0-nightly
LLVM version: 13.0.0
Additional Labels
@rustbot label +I-suggestion-causes-error
Summary
Closely related to #6331:
Following the fix of #6331, Clippy is correctly no longer triggering
unnecessary_caston0 as CfgDependent. However the same lint is still triggered on0 as AlsoCfgDependentin which Clippy's suggested replacement is incorrect for exactly the same reason. It would be better to transitively look through type aliases when looking for the presence of a cfg attribute.Lint Name
unnecessary_cast
Version
Additional Labels
@rustbot label +I-suggestion-causes-error