-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Open
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
This should be applicable for both unsigned and signed types (the latter with feature int_roundings):
#![feature(int_roundings)]
let a: i32 = 8;
let b = 3;
assert_eq!(a.div_ceil(b), a.next_multiple_of(b) / b);
assert_eq!(a.div_ceil(-b), a.next_multiple_of(-b) / -b);
assert_eq!((-a).div_ceil(b), (-a).next_multiple_of(b) / b);
assert_eq!((-a).div_ceil(-b), (-a).next_multiple_of(-b) / -b);
Using div_ceil in this case has the advantage of avoiding the subtle issue that can occur if a.next_multiple_of(b) overflows.
Lint Name
manual_div_ceil
Reproducer
I tried this code:
let a: u32 = 8;
let b = 3;
let c = a.next_multiple_of(b) / b;I expected to see this happen:
clippy: manually reimplementing `div_ceil`
...
clippy: consider using `.div_ceil()`: `a.div_ceil(b)` [manual_div_ceil]
Instead, this happened: The lint did not fire.
Version
rustc 1.92.0 (ded5c06cf 2025-12-08)
binary: rustc
commit-hash: ded5c06cf21d2b93bffd5d884aa6e96934ee4234
commit-date: 2025-12-08
host: x86_64-unknown-linux-gnu
release: 1.92.0
LLVM version: 21.1.3
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