diff options
| author | Nadrieril <nadrieril+git@gmail.com> | 2024-03-05 21:52:40 +0100 |
|---|---|---|
| committer | Nadrieril <nadrieril+git@gmail.com> | 2024-03-25 23:52:17 +0100 |
| commit | d1d9aa3108aaff42a1b71040d02012001cf53ae0 (patch) | |
| tree | 8fc326e115a3ffdf88fece527805f0c924a6ba22 | |
| parent | 08d73799611e06064001bc2839d134b98c07bdad (diff) | |
| download | rust-d1d9aa3108aaff42a1b71040d02012001cf53ae0.tar.gz rust-d1d9aa3108aaff42a1b71040d02012001cf53ae0.zip | |
Consistently merge simplifiable or-patterns
| -rw-r--r-- | compiler/rustc_mir_build/src/build/matches/mod.rs | 7 | ||||
| -rw-r--r-- | tests/mir-opt/issues/issue_75439.foo.MatchBranchSimplification.diff | 26 |
2 files changed, 13 insertions, 20 deletions
diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index 0b25213ca7b..fcfd05ccbac 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -1293,8 +1293,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // At least one of the candidates has been split into subcandidates. // We need to change the candidate list to include those. let mut new_candidates = Vec::new(); - - for candidate in candidates { + for candidate in candidates.iter_mut() { candidate.visit_leaves(|leaf_candidate| new_candidates.push(leaf_candidate)); } self.match_simplified_candidates( @@ -1304,6 +1303,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { otherwise_block, &mut *new_candidates, ); + + for candidate in candidates { + self.merge_trivial_subcandidates(candidate); + } } else { self.match_simplified_candidates( span, diff --git a/tests/mir-opt/issues/issue_75439.foo.MatchBranchSimplification.diff b/tests/mir-opt/issues/issue_75439.foo.MatchBranchSimplification.diff index f1d18b0f7ff..f11c993340f 100644 --- a/tests/mir-opt/issues/issue_75439.foo.MatchBranchSimplification.diff +++ b/tests/mir-opt/issues/issue_75439.foo.MatchBranchSimplification.diff @@ -26,18 +26,20 @@ _3 = _1; _2 = move _3 as [u32; 4] (Transmute); StorageDead(_3); - switchInt(_2[0 of 4]) -> [0: bb1, otherwise: bb6]; + switchInt(_2[0 of 4]) -> [0: bb1, otherwise: bb4]; } bb1: { - switchInt(_2[1 of 4]) -> [0: bb2, otherwise: bb6]; + switchInt(_2[1 of 4]) -> [0: bb2, otherwise: bb4]; } bb2: { - switchInt(_2[2 of 4]) -> [0: bb4, 4294901760: bb5, otherwise: bb6]; + switchInt(_2[2 of 4]) -> [0: bb3, 4294901760: bb3, otherwise: bb4]; } bb3: { + StorageLive(_4); + _4 = _2[3 of 4]; StorageLive(_5); StorageLive(_6); _6 = _4; @@ -46,27 +48,15 @@ _0 = Option::<[u8; 4]>::Some(move _5); StorageDead(_5); StorageDead(_4); - goto -> bb7; + goto -> bb5; } bb4: { - StorageLive(_4); - _4 = _2[3 of 4]; - goto -> bb3; - } - - bb5: { - StorageLive(_4); - _4 = _2[3 of 4]; - goto -> bb3; - } - - bb6: { _0 = Option::<[u8; 4]>::None; - goto -> bb7; + goto -> bb5; } - bb7: { + bb5: { StorageDead(_2); return; } |
