|
1 | 1 | //! A pass that simplifies branches when their condition is known.
|
2 | 2 |
|
3 |
| -use rustc::ty::{self, TyCtxt, ParamEnv}; |
| 3 | +use rustc::ty::{TyCtxt, ParamEnv}; |
4 | 4 | use rustc::mir::*;
|
5 | 5 | use transform::{MirPass, MirSource};
|
6 | 6 |
|
@@ -30,21 +30,17 @@ impl MirPass for SimplifyBranches {
|
30 | 30 | discr: Operand::Constant(ref c), switch_ty, ref values, ref targets, ..
|
31 | 31 | } => {
|
32 | 32 | 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; |
43 | 41 | }
|
44 |
| - ret |
45 |
| - } else { |
46 |
| - continue |
47 | 42 | }
|
| 43 | + ret |
48 | 44 | } else {
|
49 | 45 | continue
|
50 | 46 | }
|
|
0 commit comments