Skip to content

Commit 3c845fe

Browse files
committed
Rollup merge of rust-lang#31535 - Ketsuban:more-detail-in-wrapping-shift-documentation, r=steveklabnik
`wrapping_shl` and `wrapping_shr` are easy to mistake for rotations, when in fact they work somewhat differently. The documentation currently available is a little sparse and easy to misinterpret, so I've added a warning to anyone who bumps into them that the equivalent rotate methods may actually be what they're looking for. If it's deemed useful to add a symmetrical mention to the documentation for the `rotate_left` and `rotate_right` methods, I can certainly have a go at that, but my gut feeling is that people likely to want a rotate will already know about the wrapping-arithmetic methods, for example from writing CPU simulators.
2 parents 6e44653 + 8d5dcf9 commit 3c845fe

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/libcore/num/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -741,6 +741,13 @@ macro_rules! int_impl {
741741
/// where `mask` removes any high-order bits of `rhs` that
742742
/// would cause the shift to exceed the bitwidth of the type.
743743
///
744+
/// Note that this is *not* the same as a rotate-left; the
745+
/// RHS of a wrapping shift-left is restricted to the range
746+
/// of the type, rather than the bits shifted out of the LHS
747+
/// being returned to the other end. The primitive integer
748+
/// types all implement a `rotate_left` function, which may
749+
/// be what you want instead.
750+
///
744751
/// # Examples
745752
///
746753
/// Basic usage:
@@ -759,6 +766,13 @@ macro_rules! int_impl {
759766
/// where `mask` removes any high-order bits of `rhs` that
760767
/// would cause the shift to exceed the bitwidth of the type.
761768
///
769+
/// Note that this is *not* the same as a rotate-right; the
770+
/// RHS of a wrapping shift-right is restricted to the range
771+
/// of the type, rather than the bits shifted out of the LHS
772+
/// being returned to the other end. The primitive integer
773+
/// types all implement a `rotate_right` function, which may
774+
/// be what you want instead.
775+
///
762776
/// # Examples
763777
///
764778
/// Basic usage:

0 commit comments

Comments
 (0)