Skip to content

fix(integer_division_remainder_used): also detect inherent division/r… - #17618

Open
durationextender wants to merge 1 commit into
rust-lang:masterfrom
durationextender:fix/integer-division-remainder-inherent-methods
Open

fix(integer_division_remainder_used): also detect inherent division/r…#17618
durationextender wants to merge 1 commit into
rust-lang:masterfrom
durationextender:fix/integer-division-remainder-inherent-methods

Conversation

@durationextender

@durationextender durationextender commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

integer_division_remainder_used only caught the / and % operators, missing equivalent inherent methods like .div_ceil(), .wrapping_div(), .checked_rem(), etc. Now checks method calls too, matching against the method name and confirming the receiver is actually an integer type (so it doesn't fire on things like f64::div_euclid, which shares a name but isn't the same concern).

fixes #17603

changelog: [integer_division_remainder_used]: also detect inherent integer division/remainder methods, not just the / and % operators

@rustbot rustbot added the S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned. label Aug 23, 2026
@rustbot

rustbot commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request. A reviewer will take a look after it receives 2 community reviews.

In the meantime, we would highly appreciate if you could try to review any of PRs waiting on community reviews.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Aug 23, 2026
@rustbot

rustbot commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

⚠️ Warning ⚠️

  • There are issue links (such as #123) in the commit messages of the following commits.
    Please move them to the PR description, to avoid spamming the issues with references to the commit, and so this bot can automatically canonicalize them to avoid issues with subtree.

@durationextender

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@github-actions

Copy link
Copy Markdown

Lintcheck changes for 91d00cf

Lint Added Removed Changed
clippy::integer_division_remainder_used 71 0 3

This comment will be updated if you push new changes

@CommanderStorm CommanderStorm left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

community review: needs a bit of cleanup, but generally looks like the right path
@rustbot author

View changes since this review

Comment on lines +30 to +51
"checked_div"
| "checked_div_euclid"
| "checked_div_exact"
| "checked_rem"
| "checked_rem_euclid"
| "div_ceil"
| "div_euclid"
| "div_exact"
| "overflowing_div"
| "overflowing_div_euclid"
| "overflowing_rem"
| "overflowing_rem_euclid"
| "rem_euclid"
| "strict_div"
| "strict_div_euclid"
| "saturating_div"
| "strict_rem"
| "strict_rem_euclid"
| "wrapping_div"
| "wrapping_div_euclid"
| "wrapping_rem"
| "wrapping_rem_euclid"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please check using sym::* instead, since more efficient (?), better typed, ... and generally superiour

}
// check method call is present in specific list if yes also lint it
pub(super) fn check_method_call(cx: &LateContext<'_>, method_name: &str, receiver: &Expr<'_>, span: Span) {
let instance_ty = cx.typeck_results().expr_ty(receiver);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please change the order here that we first check the name, then cx.typeck_results... since performance wise this is the better order

Comment on lines +23 to +35
let x: u16 = 7;
let _ = x.div_ceil(3);
//~^ integer_division_remainder_used

let _ = x.wrapping_div(3);
//~^ integer_division_remainder_used

let _ = x.checked_rem(3);
//~^ integer_division_remainder_used

let f: f64 = 7.0;
let _ = f.div_euclid(3.0);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for each of the methods noted above, I would expect one testcase, so please copy paste the list and add a testcase for each 😉

Since div_euclid does not lint here, also keep the cases where it lints and does not for each.

Comment on lines +25 to +26
// check method call is present in specific list if yes also lint it
pub(super) fn check_method_call(cx: &LateContext<'_>, method_name: &str, receiver: &Expr<'_>, span: Span) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not seem like very usefull docs.. I can see this by glossing over the fn..
Also not a doc comment

Suggested change
// check method call is present in specific list if yes also lint it
pub(super) fn check_method_call(cx: &LateContext<'_>, method_name: &str, receiver: &Expr<'_>, span: Span) {
pub(super) fn check_method_call(cx: &LateContext<'_>, method_name: &str, receiver: &Expr<'_>, span: Span) {

@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Aug 23, 2026
@rustbot

rustbot commented Aug 23, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rustbot rustbot added the S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) label Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) S-waiting-on-community-reviews Status: This is awaiting for positive reviews from the community before a maintainer is assigned.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

integer_division_remainder_used not triggered by inherent division methods

3 participants