You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
///Performs a left shift that returns `None` on overflow.pubtraitCheckedShl:Sized + Shl<u32,Output=Self>{/// Shifts a number to the left, checking for overflow. If overflow happens,/// `None` is returned.
...
fnchecked_shl(&self,rhs:u32) -> Option<Self>;
The current wording seems to imply that if bits are shifted past the integer's range, then None is returned. This is not the case, the primitive checked_shl explicitly documents this:
/// Checked shift left. Computes `self << rhs`, returning `None`/// if `rhs` is larger than or equal to the number of bits in `self`.
...#[stable(feature = "wrapping", since = "1.7.0")]#[inline]pubfnchecked_shl(self,rhs:u32) -> Option<Self>{let(a, b) = self.overflowing_shl(rhs);if b {None}else{Some(a)}}
None is only returned if rhs is larger than the number of bits in the numeric type.
E.g.
90: Fix CheckedShl/CheckedShr documentation r=cuviper a=samueltardieu
Fix#57 and more:
- CheckedShl was hinting that None was returned on overflow rather than
on too large a rhs.
- Ditto for CheckedShr.
- CheckedShr documentation erroneously indicated that a left shift was
going to be performed instead of a right shift.
Co-authored-by: Samuel Tardieu <sam@rfc1149.net>
Excerpt from the
CheckedShl
trait:The current wording seems to imply that if bits are shifted past the integer's range, then None is returned. This is not the case, the primitive checked_shl explicitly documents this:
None is only returned if
rhs
is larger than the number of bits in the numeric type.E.g.
The text was updated successfully, but these errors were encountered: