Skip to content

Commit b82ee57

Browse files
committed
Improve arm filtering
Unmatchable arm patterns are now also filtered, even if the arm itself is reachable.
1 parent e22be28 commit b82ee57

File tree

1 file changed

+5
-3
lines changed
  • src/librustc_mir/build/matches

1 file changed

+5
-3
lines changed

src/librustc_mir/build/matches/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,11 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
5454
let dummy_temp = self.temp(dummy_ty, dummy_source_info.span);
5555
self.cfg.push_assign(block, dummy_source_info, &dummy_temp, dummy_access);
5656

57-
let arms: Vec<Arm<'tcx>> = arms.into_iter().filter(|arm|
58-
arm.patterns.iter().any(|pat| !pat.is_unreachable())
59-
).collect();
57+
let arms: Vec<Arm<'tcx>> = arms.into_iter().filter_map(|mut arm| {
58+
arm.patterns =
59+
arm.patterns.iter().filter(|pat| !pat.is_unreachable()).cloned().collect();
60+
if !arm.patterns.is_empty() { Some(arm) } else { None }
61+
}).collect();
6062

6163
let mut arm_blocks = ArmBlocks {
6264
blocks: arms.iter()

0 commit comments

Comments
 (0)