Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 6b1ee67

Browse files
committed
Ensure stack when building MIR for matches
In particular matching on complex types such as strings will cause deep recursion to happen. Fixes rust-lang#72933
1 parent fe10f1a commit 6b1ee67

File tree

2 files changed

+5233
-23
lines changed

2 files changed

+5233
-23
lines changed

src/librustc_mir_build/build/matches/mod.rs

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::build::ForGuard::{self, OutsideGuard, RefWithinGuard};
1010
use crate::build::{BlockAnd, BlockAndExtension, Builder};
1111
use crate::build::{GuardFrame, GuardFrameLocal, LocalsForNode};
1212
use crate::hair::{self, *};
13-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
13+
use rustc_data_structures::{fx::{FxHashMap, FxHashSet}, stack::ensure_sufficient_stack};
1414
use rustc_hir::HirId;
1515
use rustc_index::bit_set::BitSet;
1616
use rustc_middle::middle::region;
@@ -907,30 +907,32 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
907907
split_or_candidate |= self.simplify_candidate(candidate);
908908
}
909909

910-
if split_or_candidate {
911-
// At least one of the candidates has been split into subcandidates.
912-
// We need to change the candidate list to include those.
913-
let mut new_candidates = Vec::new();
910+
ensure_sufficient_stack(|| {
911+
if split_or_candidate {
912+
// At least one of the candidates has been split into subcandidates.
913+
// We need to change the candidate list to include those.
914+
let mut new_candidates = Vec::new();
914915

915-
for candidate in candidates {
916-
candidate.visit_leaves(|leaf_candidate| new_candidates.push(leaf_candidate));
916+
for candidate in candidates {
917+
candidate.visit_leaves(|leaf_candidate| new_candidates.push(leaf_candidate));
918+
}
919+
self.match_simplified_candidates(
920+
span,
921+
start_block,
922+
otherwise_block,
923+
&mut *new_candidates,
924+
fake_borrows,
925+
);
926+
} else {
927+
self.match_simplified_candidates(
928+
span,
929+
start_block,
930+
otherwise_block,
931+
candidates,
932+
fake_borrows,
933+
);
917934
}
918-
self.match_simplified_candidates(
919-
span,
920-
start_block,
921-
otherwise_block,
922-
&mut *new_candidates,
923-
fake_borrows,
924-
);
925-
} else {
926-
self.match_simplified_candidates(
927-
span,
928-
start_block,
929-
otherwise_block,
930-
candidates,
931-
fake_borrows,
932-
);
933-
};
935+
});
934936
}
935937

936938
fn match_simplified_candidates(

0 commit comments

Comments
 (0)