Skip to content

Commit 5f38c83

Browse files
Prevent stack overflow when building THIR
1 parent cd049ef commit 5f38c83

File tree

1 file changed

+3
-1
lines changed
  • compiler/rustc_mir_build/src/thir/cx

1 file changed

+3
-1
lines changed

compiler/rustc_mir_build/src/thir/cx/expr.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use crate::thir::cx::Cx;
22
use crate::thir::util::UserAnnotatedTyHelpers;
33
use crate::thir::*;
4+
use rustc_data_structures::stack::ensure_sufficient_stack;
45
use rustc_hir as hir;
56
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
67
use rustc_index::vec::Idx;
@@ -23,7 +24,8 @@ impl<'thir, 'tcx> Cx<'thir, 'tcx> {
2324
///
2425
/// [`mirror_exprs`]: Self::mirror_exprs
2526
crate fn mirror_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) -> &'thir Expr<'thir, 'tcx> {
26-
self.arena.alloc(self.mirror_expr_inner(expr))
27+
// `mirror_expr` is recursing very deep. Make sure the stack doesn't overflow.
28+
ensure_sufficient_stack(|| self.arena.alloc(self.mirror_expr_inner(expr)))
2729
}
2830

2931
/// Mirrors and allocates a slice of [`hir::Expr`]s. They will be allocated as a

0 commit comments

Comments
 (0)