]> git.lizzy.rs Git - rust.git/commitdiff
use singed_int_max/min helper methods
authorRalf Jung <post@ralfj.de>
Mon, 7 Mar 2022 00:11:31 +0000 (19:11 -0500)
committerRalf Jung <post@ralfj.de>
Mon, 7 Mar 2022 00:11:31 +0000 (19:11 -0500)
compiler/rustc_const_eval/src/interpret/intrinsics.rs

index 6578db04c07eb4364c0c9cb51299ef7700fb1d9d..63c0248993f6cff1c7b4037ec33e5f3c405f12d8 100644 (file)
@@ -493,23 +493,20 @@ pub fn saturating_arith(
                     // Negative overflow not possible since the positive first term
                     // can only increase an (in range) negative term for addition
                     // or corresponding negated positive term for subtraction
-                    Scalar::from_uint(
-                        (1u128 << (num_bits - 1)) - 1, // max positive
-                        Size::from_bits(num_bits),
-                    )
+                    Scalar::from_int(size.signed_int_max(), size)
                 } else {
                     // Positive overflow not possible for similar reason
                     // max negative
-                    Scalar::from_uint(1u128 << (num_bits - 1), Size::from_bits(num_bits))
+                    Scalar::from_int(size.signed_int_min(), size)
                 }
             } else {
                 // unsigned
                 if matches!(mir_op, BinOp::Add) {
                     // max unsigned
-                    Scalar::from_uint(size.unsigned_int_max(), Size::from_bits(num_bits))
+                    Scalar::from_uint(size.unsigned_int_max(), size)
                 } else {
                     // underflow to 0
-                    Scalar::from_uint(0u128, Size::from_bits(num_bits))
+                    Scalar::from_uint(0u128, size)
                 }
             }
         } else {