|
1 |
| -use crate::mir; |
2 |
| -use crate::mir::interpret::Scalar; |
3 |
| -use crate::ty::{self, Ty, TyCtxt}; |
4 | 1 | use smallvec::{smallvec, SmallVec};
|
5 | 2 |
|
6 | 3 | use super::{BasicBlock, InlineAsmOperand, Operand, SourceInfo, TerminatorKind};
|
@@ -131,17 +128,8 @@ impl<'tcx> Terminator<'tcx> {
|
131 | 128 | }
|
132 | 129 |
|
133 | 130 | impl<'tcx> TerminatorKind<'tcx> {
|
134 |
| - pub fn if_( |
135 |
| - tcx: TyCtxt<'tcx>, |
136 |
| - cond: Operand<'tcx>, |
137 |
| - t: BasicBlock, |
138 |
| - f: BasicBlock, |
139 |
| - ) -> TerminatorKind<'tcx> { |
140 |
| - TerminatorKind::SwitchInt { |
141 |
| - discr: cond, |
142 |
| - switch_ty: tcx.types.bool, |
143 |
| - targets: SwitchTargets::static_if(0, f, t), |
144 |
| - } |
| 131 | + pub fn if_(cond: Operand<'tcx>, t: BasicBlock, f: BasicBlock) -> TerminatorKind<'tcx> { |
| 132 | + TerminatorKind::SwitchInt { discr: cond, targets: SwitchTargets::static_if(0, f, t) } |
145 | 133 | }
|
146 | 134 |
|
147 | 135 | pub fn successors(&self) -> Successors<'_> {
|
@@ -264,11 +252,9 @@ impl<'tcx> TerminatorKind<'tcx> {
|
264 | 252 | }
|
265 | 253 | }
|
266 | 254 |
|
267 |
| - pub fn as_switch(&self) -> Option<(&Operand<'tcx>, Ty<'tcx>, &SwitchTargets)> { |
| 255 | + pub fn as_switch(&self) -> Option<(&Operand<'tcx>, &SwitchTargets)> { |
268 | 256 | match self {
|
269 |
| - TerminatorKind::SwitchInt { discr, switch_ty, targets } => { |
270 |
| - Some((discr, *switch_ty, targets)) |
271 |
| - } |
| 257 | + TerminatorKind::SwitchInt { discr, targets } => Some((discr, targets)), |
272 | 258 | _ => None,
|
273 | 259 | }
|
274 | 260 | }
|
@@ -403,21 +389,12 @@ impl<'tcx> TerminatorKind<'tcx> {
|
403 | 389 | match *self {
|
404 | 390 | Return | Resume | Abort | Unreachable | GeneratorDrop => vec![],
|
405 | 391 | Goto { .. } => vec!["".into()],
|
406 |
| - SwitchInt { ref targets, switch_ty, .. } => ty::tls::with(|tcx| { |
407 |
| - let param_env = ty::ParamEnv::empty(); |
408 |
| - let switch_ty = tcx.lift(switch_ty).unwrap(); |
409 |
| - let size = tcx.layout_of(param_env.and(switch_ty)).unwrap().size; |
410 |
| - targets |
411 |
| - .values |
412 |
| - .iter() |
413 |
| - .map(|&u| { |
414 |
| - mir::ConstantKind::from_scalar(tcx, Scalar::from_uint(u, size), switch_ty) |
415 |
| - .to_string() |
416 |
| - .into() |
417 |
| - }) |
418 |
| - .chain(iter::once("otherwise".into())) |
419 |
| - .collect() |
420 |
| - }), |
| 392 | + SwitchInt { ref targets, .. } => targets |
| 393 | + .values |
| 394 | + .iter() |
| 395 | + .map(|&u| Cow::Owned(u.to_string())) |
| 396 | + .chain(iter::once("otherwise".into())) |
| 397 | + .collect(), |
421 | 398 | Call { target: Some(_), cleanup: Some(_), .. } => {
|
422 | 399 | vec!["return".into(), "unwind".into()]
|
423 | 400 | }
|
|
0 commit comments