]> git.lizzy.rs Git - rust.git/commitdiff
Simplify bit inspection of a constant
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Thu, 13 Dec 2018 10:15:18 +0000 (11:15 +0100)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Tue, 1 Jan 2019 19:05:02 +0000 (20:05 +0100)
src/librustc_mir/transform/simplify_branches.rs

index 60a569e297d292865d08624145d0f88cd00ed31f..abaea709463838cfdfbeb9a553866acbbeae0eb4 100644 (file)
@@ -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 @@ fn run_pass<'a, 'tcx>(&self,
                     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
                     }