Skip to content

manual_div_ceil does not trigger for alternate form #16940

@ronnodas

Description

@ronnodas

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-false-negativeIssue: The lint should have been triggered on code, but wasn't

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions