Skip to content

Commit d1d9aa3

Browse files
committed
Consistently merge simplifiable or-patterns
1 parent 08d7379 commit d1d9aa3

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

+5-2
Original file line numberDiff line numberDiff line change
@@ -1293,8 +1293,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
12931293
// At least one of the candidates has been split into subcandidates.
12941294
// We need to change the candidate list to include those.
12951295
let mut new_candidates = Vec::new();
1296-
1297-
for candidate in candidates {
1296+
for candidate in candidates.iter_mut() {
12981297
candidate.visit_leaves(|leaf_candidate| new_candidates.push(leaf_candidate));
12991298
}
13001299
self.match_simplified_candidates(
@@ -1304,6 +1303,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
13041303
otherwise_block,
13051304
&mut *new_candidates,
13061305
);
1306+
1307+
for candidate in candidates {
1308+
self.merge_trivial_subcandidates(candidate);
1309+
}
13071310
} else {
13081311
self.match_simplified_candidates(
13091312
span,

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

+8-18
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)