core: Improve the documentation for funnel shifts#154150
Open
tgross35 wants to merge 3 commits intorust-lang:mainfrom
Open
core: Improve the documentation for funnel shifts#154150tgross35 wants to merge 3 commits intorust-lang:mainfrom
tgross35 wants to merge 3 commits intorust-lang:mainfrom
Conversation
`rhs` is confusing since for the `Shl` and `Shr` traits, that is the name used for the value to shift by (i.e. `self >> rhs`).
It's a bit easier to understand the results of shifts and otherwise bitwise operations when leading zeros are present.
Collaborator
Collaborator
|
r? @joboet rustbot has assigned @joboet. Use Why was this reviewer chosen?The reviewer was selected based on:
|
8683922 to
5ae8d71
Compare
Contributor
Author
|
Cc @clarfonthey since you requested some of this at #145686 (comment) |
Contributor
Author
Shorten the summary line, cover shifts by zeros, rotates, and panics in examples, and turn the "Panics" section into a complete sentence.
5ae8d71 to
7a02613
Compare
Contributor
Author
|
Some ascii art I sketched for this but decided to exclude: // high low
// |0x1234 0x5678| <- shift left 12 bits
// \ /
// \--| /
// |0x4567|
// result
//
// high low
// |0x1234 0x5678| -> shift right 12 bits
// \ /
// \ |--/
// |0x2345|
// result |
RalfJung
reviewed
Mar 20, 2026
| without modifying the original"] | ||
| #[inline(always)] | ||
| pub const fn funnel_shr(self, rhs: Self, n: u32) -> Self { | ||
| pub const fn funnel_shr(self, low: Self, n: u32) -> Self { |
Member
There was a problem hiding this comment.
Personally I think "right" gives a better intuition here than "low". This is about the number as a bitstring after all, not about it's numeric value.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Change the variable name to make things a bit more clear, then rework funnel shift documentation. Examples now cover shifting by zero and emulating rotates.
Tracking issue: #145686