Skip to content

Commit 481ed2d

Browse files
committed
address review: modify matches/mod.rs
The candidate shouldn't have false_edge_start_block if it has sub candidates. In remove_never_subcandidates(), the false_edge_start_block from the first sub candidte is assigned to a value and the value is later used if all sub candidates are removed and candidate doesn't have false_edge_start_block. In merge_trivial_subcandidates, I leave the if block which assign a false_edge_start_block into the candidate as before I put this commit since compile panics. Signed-off-by: Shunpoco <[email protected]>
1 parent d8a216b commit 481ed2d

File tree

1 file changed

+9
-4
lines changed
  • compiler/rustc_mir_build/src/builder/matches

1 file changed

+9
-4
lines changed

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1940,10 +1940,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
19401940
/// in match tree lowering.
19411941
fn merge_trivial_subcandidates(&mut self, candidate: &mut Candidate<'_, 'tcx>) {
19421942
assert!(!candidate.subcandidates.is_empty());
1943-
if candidate.false_edge_start_block.is_none() {
1944-
candidate.false_edge_start_block = candidate.subcandidates[0].false_edge_start_block;
1945-
}
1946-
19471943
if candidate.has_guard {
19481944
// FIXME(or_patterns; matthewjasper) Don't give up if we have a guard.
19491945
return;
@@ -1963,6 +1959,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
19631959
let or_span = candidate.or_span.take().unwrap();
19641960
let source_info = self.source_info(or_span);
19651961

1962+
if candidate.false_edge_start_block.is_none() {
1963+
candidate.false_edge_start_block = candidate.subcandidates[0].false_edge_start_block;
1964+
}
1965+
19661966
// Remove the (known-trivial) subcandidates from the candidate tree,
19671967
// so that they aren't visible after match tree lowering, and wire them
19681968
// all to join up at a single shared pre-binding block.
@@ -1986,6 +1986,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
19861986
return;
19871987
}
19881988

1989+
let false_edge_start_block = candidate.subcandidates[0].false_edge_start_block;
19891990
candidate.subcandidates.retain_mut(|candidate| {
19901991
if candidate.extra_data.is_never {
19911992
candidate.visit_leaves(|subcandidate| {
@@ -2004,6 +2005,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
20042005
let next_block = self.cfg.start_new_block();
20052006
candidate.pre_binding_block = Some(next_block);
20062007
candidate.otherwise_block = Some(next_block);
2008+
// In addition, if `candidate` should have `false_edge_start_block`.
2009+
if candidate.false_edge_start_block.is_none() {
2010+
candidate.false_edge_start_block = false_edge_start_block;
2011+
}
20072012
}
20082013
}
20092014

0 commit comments

Comments
 (0)