about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Scherer <github35764891676564198441@oli-obk.de>2018-12-13 11:15:18 +0100
committerOliver Scherer <github35764891676564198441@oli-obk.de>2019-01-01 20:05:02 +0100
commit17db209d4bdf9812fcf2c2afa37ca2d3878a8d48 (patch)
tree766c1a5df611ec0b8e82d85e293892d2b2823c39
parent37a0df3e9db1b934dfb698fc1d7cbf506532004f (diff)
downloadrust-17db209d4bdf9812fcf2c2afa37ca2d3878a8d48.tar.gz
rust-17db209d4bdf9812fcf2c2afa37ca2d3878a8d48.zip
Simplify bit inspection of a constant
-rw-r--r--src/librustc_mir/transform/simplify_branches.rs24
1 files changed, 10 insertions, 14 deletions
diff --git a/src/librustc_mir/transform/simplify_branches.rs b/src/librustc_mir/transform/simplify_branches.rs
index 60a569e297d..abaea709463 100644
--- a/src/librustc_mir/transform/simplify_branches.rs
+++ b/src/librustc_mir/transform/simplify_branches.rs
@@ -1,6 +1,6 @@
 //! A pass that simplifies branches when their condition is known.
 
-use rustc::ty::{self, TyCtxt, ParamEnv};
+use rustc::ty::{TyCtxt, ParamEnv};
 use rustc::mir::*;
 use transform::{MirPass, MirSource};
 
@@ -30,21 +30,17 @@ impl MirPass for SimplifyBranches {
                     discr: Operand::Constant(ref c), switch_ty, ref values, ref targets, ..
                 } => {
                     let switch_ty = ParamEnv::empty().and(switch_ty);
-                    if let ty::LazyConst::Evaluated(c) = c.literal {
-                        let c = c.assert_bits(tcx, switch_ty);
-                        if let Some(constant) = c {
-                            let (otherwise, targets) = targets.split_last().unwrap();
-                            let mut ret = TerminatorKind::Goto { target: *otherwise };
-                            for (&v, t) in values.iter().zip(targets.iter()) {
-                                if v == constant {
-                                    ret = TerminatorKind::Goto { target: *t };
-                                    break;
-                                }
+                    let constant = c.literal.map_evaluated(|c| c.assert_bits(tcx, switch_ty));
+                    if let Some(constant) = constant {
+                        let (otherwise, targets) = targets.split_last().unwrap();
+                        let mut ret = TerminatorKind::Goto { target: *otherwise };
+                        for (&v, t) in values.iter().zip(targets.iter()) {
+                            if v == constant {
+                                ret = TerminatorKind::Goto { target: *t };
+                                break;
                             }
-                            ret
-                        } else {
-                            continue
                         }
+                        ret
                     } else {
                         continue
                     }