Skip to content

Commit fc44861

Browse files
authored
Rollup merge of rust-lang#72941 - nagisa:ensure-stack-for-match, r=oli-obk
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 r? @matthewjasper @oli-obk
2 parents 0f03fdd + 6b1ee67 commit fc44861

File tree

2 files changed

+5233
-23
lines changed

2 files changed

+5233
-23
lines changed

src/librustc_mir_build/build/matches/mod.rs

+25-23
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;
@@ -909,30 +909,32 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
909909
split_or_candidate |= self.simplify_candidate(candidate);
910910
}
911911

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

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

938940
fn match_simplified_candidates(

0 commit comments

Comments
 (0)