I have a enum:
const ERROR_BIT: usize = usize::MAX - (usize::MAX >> 1);
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, FromPrimitive)]
#[repr(usize)]
#[allow(clippy::pub_enum_variant_names)]
pub enum Error {
LoadError = ERROR_BIT | 1,
// ...
}
Clippy denies the code because it violates enum_clike_unportable_variant
:
error: C-like enum variant discriminant is not portable to 32-bit targets
--> bootloader/stable_uefi/src/result.rs:44:5
|
44 | LoadError = ERROR_BIT | 1,
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `#[deny(clippy::enum_clike_unportable_variant)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#enum_clike_unportable_variant
This is not false-positive because ERROR_BIT | 1
doesn't fit into an i32
value on a 64-bit environment. However, the value will not be truncated in a 32-bit environment. ERROR_BIT
is 0x8000_0000
on a 32-bit environment and 0x8000_0000_0000_0000
on a 64-bit environment.
I feel this lint is too strict. Why does this lint deny values that don't fit into i32
rather than isize
or usize
?