-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't
Description
Summary
The integer_division lint, as I've understood it, is meant to restrict the use of integer division. When dividing an integer by a NonZero version of it, whilst safe from division-by-zero errors, the remainder is still discarded. I believe that this lint should be emitted in such cases, but currently, it is not.
Lint Name
integer_division
Reproducer
I tried this code:
#![warn(clippy::integer_division)]
use std::num::NonZeroU32;
const TWO: NonZeroU32 = NonZeroU32::new(2).unwrap();
fn main() {
let x: u32 = 3;
// emits the lint
println!("{}", x / 2);
// does not emit the lint
println!("{}", x / TWO);
// both print "1"
}I expected to see this happen:
I expected x / TWO to produce a warning.
Instead, this happened:
No warning was emitted.
Version
rustc 1.86.0 (05f9846f8 2025-03-31)
binary: rustc
commit-hash: 05f9846f893b09a1be1fc8560e33fc3c815cfecb
commit-date: 2025-03-31
host: aarch64-apple-darwin
release: 1.86.0
LLVM version: 19.1.7
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn'tIssue: The lint should have been triggered on code, but wasn't