Summary
int_plus_one suggestions prevent overflows from happening because it removes a potential case where we could run into T::max() + 1
Reproducer
I tried this code:
fn main() {
dbg!(comp(254));
dbg!(comp(255)); // overflow/panic
dbg!(comp_clippyfixed(254));
dbg!(comp_clippyfixed(255)); // no panic
}
fn comp(x: u8) -> bool {
1 >= x + 1
}
fn comp_clippyfixed(x: u8) -> bool {
1 > x
}
Version
rustc 1.64.0-nightly (0f4bcadb4 2022-07-30)
binary: rustc
commit-hash: 0f4bcadb46006bc484dad85616b484f93879ca4e
commit-date: 2022-07-30
host: x86_64-unknown-linux-gnu
release: 1.64.0-nightly
LLVM version: 14.0.6
Additional Labels
No response
Summary
int_plus_onesuggestions prevent overflows from happening because it removes a potential case where we could run intoT::max() + 1Reproducer
I tried this code:
Version
Additional Labels
No response