-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add inherent unchecked_shl, unchecked_shr to integers #85703
Conversation
r? @scottmcm (rust-highfive has picked a reviewer for you, use r? to override) |
0ad17f6
to
ebcc995
Compare
Thanks for the PR, @clarfonthey! The shift semantics for Rust are a bit weird, though. Do you know any situations where the masking the shift amount is a problem in practice? I feel like someone reaching for these would often actually want things like But at the same time I guess we're stuck with Any thoughts on whether these should be added, @rust-lang/libs ? |
I thought about this some more, and came around to the idea that it's probably fine to have these in nightly because of the parallel with So @clarfonthey can you please:
|
Will update the docs for the methods in a bit. Also will add the In terms of the actual behaviour, even though we're technically tabling the discussion: I strongly believe that we should keep the existing behaviour, as it matches the overflow behaviour of the operators normally. I definitely think we could add new methods in the future for what you specified, though. For example, division can always allow a nonzero remainder, checked or not, but longer-term we can add a new method to use Mostly just my thoughts on that. |
Wording nit, not super important as you're already updating the docs, but noticed as I was reading. |
ebcc995
to
64659ef
Compare
Apologies, I just was about to push my changes that fixed that when you commented. :P I chose to use "larger than" instead of "greater than" since that's the wording that the existing |
@rustbot label -S-waiting-on-author +S-waiting-on-review |
This comment has been minimized.
This comment has been minimized.
64659ef
to
2a40f24
Compare
Thanks for the updates, @clarfonthey! I've updated the tracking issue with some extra things to ponder before stabilization. @bors r+ |
📌 Commit 2a40f24 has been approved by |
☀️ Test successful - checks-actions |
Tracking issue: #85122.
Adding more of these methods, since these are missing.