From fc4f1afdf6ac5b948d68a11209896cdfcda60b2a Mon Sep 17 00:00:00 2001 From: Samuel Tardieu Date: Tue, 9 Oct 2018 11:52:11 +0200 Subject: [PATCH] Fix CheckedShl/CheckedShr documentation 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. --- src/ops/checked.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/ops/checked.rs b/src/ops/checked.rs index b386e97..3865570 100644 --- a/src/ops/checked.rs +++ b/src/ops/checked.rs @@ -195,10 +195,11 @@ checked_impl_unary!(CheckedNeg, checked_neg, isize); #[cfg(has_i128)] checked_impl_unary!(CheckedNeg, checked_neg, i128); -/// Performs a left shift that returns `None` on overflow. +/// Performs a left shift that returns `None` on shifts larger than +/// the type width. pub trait CheckedShl: Sized + Shl { - /// Shifts a number to the left, checking for overflow. If overflow happens, - /// `None` is returned. + /// Checked shift left. Computes `self << rhs`, returning `None` + /// if `rhs` is larger than or equal to the number of bits in `self`. /// /// ``` /// use num_traits::CheckedShl; @@ -240,10 +241,11 @@ checked_shift_impl!(CheckedShl, checked_shl, isize); #[cfg(has_i128)] checked_shift_impl!(CheckedShl, checked_shl, i128); -/// Performs a right shift that returns `None` on overflow. +/// Performs a right shift that returns `None` on shifts larger than +/// the type width. pub trait CheckedShr: Sized + Shr { - /// Shifts a number to the left, checking for overflow. If overflow happens, - /// `None` is returned. + /// Checked shift right. Computes `self >> rhs`, returning `None` + /// if `rhs` is larger than or equal to the number of bits in `self`. /// /// ``` /// use num_traits::CheckedShr;