Skip to content

Commit 17db209

Browse files
committed
Simplify bit inspection of a constant
1 parent 37a0df3 commit 17db209

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/librustc_mir/transform/simplify_branches.rs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! A pass that simplifies branches when their condition is known.
22
3-
use rustc::ty::{self, TyCtxt, ParamEnv};
3+
use rustc::ty::{TyCtxt, ParamEnv};
44
use rustc::mir::*;
55
use transform::{MirPass, MirSource};
66

@@ -30,21 +30,17 @@ impl MirPass for SimplifyBranches {
3030
discr: Operand::Constant(ref c), switch_ty, ref values, ref targets, ..
3131
} => {
3232
let switch_ty = ParamEnv::empty().and(switch_ty);
33-
if let ty::LazyConst::Evaluated(c) = c.literal {
34-
let c = c.assert_bits(tcx, switch_ty);
35-
if let Some(constant) = c {
36-
let (otherwise, targets) = targets.split_last().unwrap();
37-
let mut ret = TerminatorKind::Goto { target: *otherwise };
38-
for (&v, t) in values.iter().zip(targets.iter()) {
39-
if v == constant {
40-
ret = TerminatorKind::Goto { target: *t };
41-
break;
42-
}
33+
let constant = c.literal.map_evaluated(|c| c.assert_bits(tcx, switch_ty));
34+
if let Some(constant) = constant {
35+
let (otherwise, targets) = targets.split_last().unwrap();
36+
let mut ret = TerminatorKind::Goto { target: *otherwise };
37+
for (&v, t) in values.iter().zip(targets.iter()) {
38+
if v == constant {
39+
ret = TerminatorKind::Goto { target: *t };
40+
break;
4341
}
44-
ret
45-
} else {
46-
continue
4742
}
43+
ret
4844
} else {
4945
continue
5046
}

0 commit comments

Comments
 (0)