]> git.lizzy.rs Git - rust.git/commitdiff
Use wrapping shift for unsigned types
authorMichael Watzko <michael@watzko.de>
Sat, 28 Aug 2021 11:28:35 +0000 (13:28 +0200)
committerMichael Watzko <michael@watzko.de>
Sat, 28 Aug 2021 11:28:35 +0000 (13:28 +0200)
library/core/src/num/saturating.rs

index 2e84f0657131ddb8d77217c113ba89cbff5e1f32..b2705ca0cc47b2ab11797b22f60b076471b1ea25 100644 (file)
@@ -141,7 +141,7 @@ impl Shl<$f> for Saturating<$t> {
 
             #[inline]
             fn shl(self, other: $f) -> Saturating<$t> {
-                Saturating(self.0.shl((other & self::shift_max::$t as $f) as u32))
+                Saturating(self.0.wrapping_shl(other as u32))
             }
         }
         forward_ref_binop! { impl Shl, shl for Saturating<$t>, $f,
@@ -162,7 +162,7 @@ impl Shr<$f> for Saturating<$t> {
 
             #[inline]
             fn shr(self, other: $f) -> Saturating<$t> {
-                Saturating(self.0.shr((other & self::shift_max::$t as $f) as u32))
+                Saturating(self.0.wrapping_shr(other as u32))
             }
         }
         forward_ref_binop! { impl Shr, shr for Saturating<$t>, $f,