Open
Description
Lint name: cast_possible_truncation
I tried this code:
#![deny(clippy::cast_possible_truncation)]
fn modulo(number: u64, other: u32) -> u32 {
// a u64 with guranteed value to be less than or equal to u32::max_value()
let other_u64 = other as u64;
// modulo gurantees that the following invariant holds:
// result < other_u64
// which implies that result < u32::max_value()
let result = number % other_u64;
result as u32
}
fn main() {
assert_eq!(modulo(11_u64, 5_u32), 1_u32);
}
I expected to see this happen: the lint should not trigger
Instead, this happened: the lint about a possible truncation has been emitted
Meta
cargo clippy -V
:clippy 0.1.55 (02718709 2021-07-22)
rustc -Vv
:
rustc 1.55.0-nightly (027187094 2021-07-22)
binary: rustc
commit-hash: 027187094ee05011d6602f5742f550851ccc7fd6
commit-date: 2021-07-22
host: x86_64-pc-windows-msvc
release: 1.55.0-nightly
LLVM version: 12.0.1