rust-lang / rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code. Book: https://doc.rust-lang.org/clippy/
https://rust-lang.github.io/rust-clippy/
Other
11.5k stars 1.55k forks source link

False positive on `enum_clike_unportable_variant` #816

Open llogiq opened 8 years ago

llogiq commented 8 years ago
x = 1isize << 31; 

is okay as long as the specific bit pattern is of the essence; the actual value may vary.

E.g. see https://github.com/ledbettj/wavefile/blob/master/src/speakers.rs#L20

oli-obk commented 8 years ago

shouldn't the type in the example rather be i32?

oli-obk commented 8 years ago

if you want the bit pattern in a portable way use (1usize << 31) as isize, which is more explicit to your intent nevermind, We're checking the final value...

oh well... I still argue it's unportable... but we can split the lint into three, one for enums that implement PartialOrd, where it still is warn-by-default, and two for enums that don't implement PartialOrd (one for values that require more than 32 bit (warn-by-default), and one for values that will yield different values on 32 bit (allow-by-default))

llogiq commented 8 years ago

You are technically correct (which is after all the best kind of correct :smile:). Still I think it may be useful to split the lint so we can give more relevant report messages.