]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_mir/src/interpret/terminator.rs
Refactor how SwitchInt stores jump targets
[rust.git] / compiler / rustc_mir / src / interpret / terminator.rs
index 9f200ca62b8c606c6ae2d62980c8b41ffe985506..bb11c2a23bd813c230c94b9dfe0640ffed35701e 100644 (file)
@@ -24,16 +24,16 @@ pub(super) fn eval_terminator(
 
             Goto { target } => self.go_to_block(target),
 
-            SwitchInt { ref discr, ref values, ref targets, switch_ty } => {
+            SwitchInt { ref discr, ref targets, switch_ty } => {
                 let discr = self.read_immediate(self.eval_operand(discr, None)?)?;
                 trace!("SwitchInt({:?})", *discr);
                 assert_eq!(discr.layout.ty, switch_ty);
 
                 // Branch to the `otherwise` case by default, if no match is found.
-                assert!(!targets.is_empty());
-                let mut target_block = targets[targets.len() - 1];
+                assert!(!targets.iter().is_empty());
+                let mut target_block = targets.otherwise();
 
-                for (index, &const_int) in values.iter().enumerate() {
+                for (const_int, target) in targets.iter() {
                     // Compare using binary_op, to also support pointer values
                     let res = self
                         .overflowing_binary_op(
@@ -43,7 +43,7 @@ pub(super) fn eval_terminator(
                         )?
                         .0;
                     if res.to_bool()? {
-                        target_block = targets[index];
+                        target_block = target;
                         break;
                     }
                 }