-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ACP: impl {Div,Rem}Assign<NonZeroX> for X
#346
Labels
ACP-accepted
API Change Proposal is accepted (seconded with no objections)
api-change-proposal
A proposal to add or alter unstable APIs in the standard libraries
T-libs-api
Comments
We briefly discussed this in the libs-api meeting. This looks fine to us. Since this is insta-stable, we'll propose an FCP on the PR. |
bors
added a commit
to rust-lang-ci/rust
that referenced
this issue
Mar 17, 2024
feat: implement `{Div,Rem}Assign<NonZero<X>>` on `X` # Description This PR implements `DivAssign<X>` and `RemAssign<X>` on `X` as suggested in rust-lang/libs-team#346. Since this is just a trait implementation on an already stable type, for which non-assign operator traits are already stable, I suggest that it is an insta-stable feature.
bors
added a commit
to rust-lang-ci/rust
that referenced
this issue
Mar 18, 2024
feat: implement `{Div,Rem}Assign<NonZero<X>>` on `X` # Description This PR implements `DivAssign<X>` and `RemAssign<X>` on `X` as suggested in rust-lang/libs-team#346. Since this is just a trait implementation on an already stable type, for which non-assign operator traits are already stable, I suggest that it is an insta-stable feature.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
ACP-accepted
API Change Proposal is accepted (seconded with no objections)
api-change-proposal
A proposal to add or alter unstable APIs in the standard libraries
T-libs-api
Proposal
Problem statement
At the moment, there are
impl {Div,Rem}<NonZeroX> for X
which use the fact that the division by a non-zero value are always infallible.Yet there seem to be no corresponding
{Div,Rem}Assign
implementations. While thelhs %= rhs
andlhs/= rhs
can be described in user code withlhs = lhs / rhs
andlhs = lhs % rhs
respectively, there seems to be no reason to not implement the corresponding traits on numeric types themselves.Motivating examples or use cases
Simply,
compiles; but
does not.
Solution sketch
The implementation (tested against
master
) adds the following intocore::num::nonzero::nonzero_integer_signedness_dependent_impls
:Diff
I've used the synthetic
nonzero_div2
feature for these and, IMO, they may be an insta-stable API.Alternatives
The text was updated successfully, but these errors were encountered: