about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMazdak Farrokhzad <twingoow@gmail.com>2019-03-13 03:33:49 +0100
committerGitHub <noreply@github.com>2019-03-13 03:33:49 +0100
commit6c9bdc341031b276c6d48d986530b86c7f64bd4d (patch)
tree73e5456ef3c41350010e1f093776a944cda86e91 /src
parentf95bbf3da398fa68370a832c9b0492399ff43241 (diff)
parent18b40c64136aedb78a494c0c7e44273353198b0e (diff)
downloadrust-6c9bdc341031b276c6d48d986530b86c7f64bd4d.tar.gz
rust-6c9bdc341031b276c6d48d986530b86c7f64bd4d.zip
Rollup merge of #59101 - kenta7777:reduce-code-repetition, r=oli-obk
Reduces Code Repetitions like `!n >> amt`

Fixes #49937 .
This PR contains defining a function which operates bit inversion and reducing bit operation like `!0u128 >> (128 - size.bits())`.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_mir/build/matches/simplify.rs5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/librustc_mir/build/matches/simplify.rs b/src/librustc_mir/build/matches/simplify.rs
index 01f8cbfbe8e..d60a0941b59 100644
--- a/src/librustc_mir/build/matches/simplify.rs
+++ b/src/librustc_mir/build/matches/simplify.rs
@@ -19,6 +19,7 @@ use rustc::ty;
 use rustc::ty::layout::{Integer, IntegerExt, Size};
 use syntax::attr::{SignedInt, UnsignedInt};
 use rustc::hir::RangeEnd;
+use rustc::mir::interpret::truncate;
 
 use std::mem;
 
@@ -115,14 +116,14 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
                     ty::Int(ity) => {
                         // FIXME(49937): refactor these bit manipulations into interpret.
                         let size = Integer::from_attr(&tcx, SignedInt(ity)).size();
-                        let max = !0u128 >> (128 - size.bits());
+                        let max = truncate(u128::max_value(), size);
                         let bias = 1u128 << (size.bits() - 1);
                         (Some((0, max, size)), bias)
                     }
                     ty::Uint(uty) => {
                         // FIXME(49937): refactor these bit manipulations into interpret.
                         let size = Integer::from_attr(&tcx, UnsignedInt(uty)).size();
-                        let max = !0u128 >> (128 - size.bits());
+                        let max = truncate(u128::max_value(), size);
                         (Some((0, max, size)), 0)
                     }
                     _ => (None, 0),