diff options
| author | Ralf Jung <post@ralfj.de> | 2022-03-06 19:11:31 -0500 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2022-03-06 19:11:31 -0500 |
| commit | ac844986d8f5646b686e2a5619e5a90372953b38 (patch) | |
| tree | c0e7ca50f19e0e36375405bfb1c45e451067c1e6 | |
| parent | 956659e5ced806360b726c103eb7ab1d960c163a (diff) | |
| download | rust-ac844986d8f5646b686e2a5619e5a90372953b38.tar.gz rust-ac844986d8f5646b686e2a5619e5a90372953b38.zip | |
use singed_int_max/min helper methods
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/intrinsics.rs | 11 |
1 files changed, 4 insertions, 7 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index 6578db04c07..63c0248993f 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -493,23 +493,20 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { // 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 { |
