Skip to content

Commit a875c7a

Browse files
committed
Add assertion for len of vecs
1 parent 738ed9b commit a875c7a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

compiler/rustc_mir/src/transform/simplify_try.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -568,14 +568,15 @@ impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
568568
.basic_blocks()
569569
.iter_enumerated()
570570
.filter_map(|(bb_idx, bb)| {
571-
let (discr_switched_on, targets_and_values):(_, Vec<_>) = match &bb.terminator().kind {
571+
let (discr_switched_on, targets_and_values) = match &bb.terminator().kind {
572572
TerminatorKind::SwitchInt { targets, discr, values, .. } => {
573573
// if values.len() == targets.len() - 1, we need to include None where no value is present
574574
// such that the zip does not throw away targets. If no `otherwise` case is in targets, the zip will simply throw away the added None
575575
let values_extended = values.iter().map(|x|Some(*x)).chain(once(None));
576-
let targets_and_values = targets.iter().zip(values_extended)
577-
.map(|(target, value)| SwitchTargetAndValue{target:*target, value:value})
576+
let targets_and_values:Vec<_> = targets.iter().zip(values_extended)
577+
.map(|(target, value)| SwitchTargetAndValue{target:*target, value})
578578
.collect();
579+
assert_eq!(targets.len(), targets_and_values.len());
579580
(discr, targets_and_values)},
580581
_ => return None,
581582
};

0 commit comments

Comments
 (0)