rust-lang / rust-lang/rust-clippy

`manual_div_ceil` does not trigger for alternate form

Open
#16,940 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-negative
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

The lint triggers for expressions of the form (a + b - 1) / b but not of the form (a - 1) / b + 1. For unsigned integers, these are equivalent ignoring overflow/underflow.

Lint Name

manual_div_ceil

Reproducer

I tried this code (playground):

fn div_ceil(a: u32, b: u32) -> u32 {
    (a - 1) / b + 1
}

I expected to see this happen:
The manual_div_ceil lint should trigger, suggesting a.div_ceil(b).

Instead, this happened:
Nothing.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the implementation and tests for the manual_div_ceil lint, then run Clippy on the provided (a - 1) / b + 1 reproducer. Confirm that the alternate unsigned-integer form is recognized and that the diagnostic suggests a.div_ceil(b), while preserving existing behavior for the original form.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
65/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.