mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-05 03:38:29 +00:00
Add assertion for len of vecs
This commit is contained in:
parent
738ed9b5ec
commit
a875c7a1ea
@ -568,14 +568,15 @@ impl<'a, 'tcx> SimplifyBranchSameOptimizationFinder<'a, 'tcx> {
|
|||||||
.basic_blocks()
|
.basic_blocks()
|
||||||
.iter_enumerated()
|
.iter_enumerated()
|
||||||
.filter_map(|(bb_idx, bb)| {
|
.filter_map(|(bb_idx, bb)| {
|
||||||
let (discr_switched_on, targets_and_values):(_, Vec<_>) = match &bb.terminator().kind {
|
let (discr_switched_on, targets_and_values) = match &bb.terminator().kind {
|
||||||
TerminatorKind::SwitchInt { targets, discr, values, .. } => {
|
TerminatorKind::SwitchInt { targets, discr, values, .. } => {
|
||||||
// if values.len() == targets.len() - 1, we need to include None where no value is present
|
// if values.len() == targets.len() - 1, we need to include None where no value is present
|
||||||
// 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
|
// 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
|
||||||
let values_extended = values.iter().map(|x|Some(*x)).chain(once(None));
|
let values_extended = values.iter().map(|x|Some(*x)).chain(once(None));
|
||||||
let targets_and_values = targets.iter().zip(values_extended)
|
let targets_and_values:Vec<_> = targets.iter().zip(values_extended)
|
||||||
.map(|(target, value)| SwitchTargetAndValue{target:*target, value:value})
|
.map(|(target, value)| SwitchTargetAndValue{target:*target, value})
|
||||||
.collect();
|
.collect();
|
||||||
|
assert_eq!(targets.len(), targets_and_values.len());
|
||||||
(discr, targets_and_values)},
|
(discr, targets_and_values)},
|
||||||
_ => return None,
|
_ => return None,
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user