Skip to content

signed strict division: just use normal division#158483

Open
RalfJung wants to merge 1 commit into
rust-lang:mainfrom
RalfJung:signed-strict-div
Open

signed strict division: just use normal division#158483
RalfJung wants to merge 1 commit into
rust-lang:mainfrom
RalfJung:signed-strict-div

Conversation

@RalfJung

@RalfJung RalfJung commented Jun 27, 2026

Copy link
Copy Markdown
Member

For some reason, #116090 picked an unnecessarily complicated implementation for this. I don't know if there was any specific reason for this;. Cc @rmehri01 @m-ou-se in case someone remembers.

This was pointed out on IRLO: https://internals.rust-lang.org/t/why-is-strict-div-implemented-in-terms-of-overflowing-div-for-signed-integers/24387

Let's just use regular division here, which is consistent with what we do for unsigned types.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 27, 2026
@rustbot

rustbot commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: libs
  • libs expanded to 12 candidates
  • Random selection from Darksonn, JohnTitor, Mark-Simulacrum, clarfonthey, jhpratt

@RalfJung RalfJung force-pushed the signed-strict-div branch 2 times, most recently from 9e095fa to 8e814f3 Compare June 27, 2026 12:13
@jhpratt

jhpratt commented Jun 27, 2026

Copy link
Copy Markdown
Member

r=me if there's no concerns. My suspicion is that this was written with #[rustc_inherit_overflow_checks] in mind even though it's not present here.

r? jhpratt

@rustbot rustbot assigned jhpratt and unassigned Mark-Simulacrum Jun 27, 2026
@scottmcm

Copy link
Copy Markdown
Member

The only thing that comes to mind is if someone was wanting it to panic for x / 0 but have overflow behaviour for INT_MIN / -1 -- but of course that's not how our division works today.

@RalfJung

RalfJung commented Jun 27, 2026

Copy link
Copy Markdown
Member Author

The only thing that comes to mind is if someone was wanting it to panic for x / 0 but have overflow behaviour for INT_MIN / -1 -- but of course that's not how our division works today.

That exists, it is called overflowing_div.

@rust-bors

This comment has been minimized.

@jhpratt

jhpratt commented Jun 27, 2026

Copy link
Copy Markdown
Member

I meant if it existed on the strict function, which it definitely doesn't.

@RalfJung RalfJung force-pushed the signed-strict-div branch from 8e814f3 to 10fb96c Compare June 27, 2026 21:13
@rustbot

rustbot commented Jun 27, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants