Skip to content

Commit 4f45632

Browse files
committed
Always merge simplifiable or-patterns
1 parent b8a26da commit 4f45632

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

compiler/rustc_mir_build/src/build/matches/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,8 +1306,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
13061306
// At least one of the candidates has been split into subcandidates.
13071307
// We need to change the candidate list to include those.
13081308
let mut new_candidates = Vec::new();
1309-
1310-
for candidate in candidates {
1309+
for candidate in candidates.iter_mut() {
13111310
candidate.visit_leaves(|leaf_candidate| new_candidates.push(leaf_candidate));
13121311
}
13131312
self.match_simplified_candidates(
@@ -1317,6 +1316,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
13171316
otherwise_block,
13181317
&mut *new_candidates,
13191318
);
1319+
1320+
for candidate in candidates {
1321+
self.merge_trivial_subcandidates(candidate);
1322+
}
13201323
} else {
13211324
self.match_simplified_candidates(
13221325
span,

tests/mir-opt/issues/issue_75439.foo.MatchBranchSimplification.diff

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,20 @@
2626
_3 = _1;
2727
_2 = move _3 as [u32; 4] (Transmute);
2828
StorageDead(_3);
29-
switchInt(_2[0 of 4]) -> [0: bb1, otherwise: bb6];
29+
switchInt(_2[0 of 4]) -> [0: bb1, otherwise: bb4];
3030
}
3131

3232
bb1: {
33-
switchInt(_2[1 of 4]) -> [0: bb2, otherwise: bb6];
33+
switchInt(_2[1 of 4]) -> [0: bb2, otherwise: bb4];
3434
}
3535

3636
bb2: {
37-
switchInt(_2[2 of 4]) -> [0: bb4, 4294901760: bb5, otherwise: bb6];
37+
switchInt(_2[2 of 4]) -> [0: bb3, 4294901760: bb3, otherwise: bb4];
3838
}
3939

4040
bb3: {
41+
StorageLive(_4);
42+
_4 = _2[3 of 4];
4143
StorageLive(_5);
4244
StorageLive(_6);
4345
_6 = _4;
@@ -46,27 +48,15 @@
4648
_0 = Option::<[u8; 4]>::Some(move _5);
4749
StorageDead(_5);
4850
StorageDead(_4);
49-
goto -> bb7;
51+
goto -> bb5;
5052
}
5153

5254
bb4: {
53-
StorageLive(_4);
54-
_4 = _2[3 of 4];
55-
goto -> bb3;
56-
}
57-
58-
bb5: {
59-
StorageLive(_4);
60-
_4 = _2[3 of 4];
61-
goto -> bb3;
62-
}
63-
64-
bb6: {
6555
_0 = Option::<[u8; 4]>::None;
66-
goto -> bb7;
56+
goto -> bb5;
6757
}
6858

69-
bb7: {
59+
bb5: {
7060
StorageDead(_2);
7161
return;
7262
}

0 commit comments

Comments
 (0)