Skip to content

Commit f64e58c

Browse files
committed
Ensure stack when type checking and building MIR for large if expressions
1 parent 0820e54 commit f64e58c

File tree

3 files changed

+10427
-2
lines changed

3 files changed

+10427
-2
lines changed

src/librustc_mir_build/build/expr/into.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder};
55
use crate::hair::*;
66
use rustc_ast::ast::InlineAsmOptions;
77
use rustc_data_structures::fx::FxHashMap;
8+
use rustc_data_structures::stack::ensure_sufficient_stack;
89
use rustc_hir as hir;
910
use rustc_middle::mir::*;
1011
use rustc_middle::ty::{self, CanonicalUserTypeAnnotation};
@@ -43,7 +44,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
4344
let block_and = match expr.kind {
4445
ExprKind::Scope { region_scope, lint_level, value } => {
4546
let region_scope = (region_scope, source_info);
46-
this.in_scope(region_scope, lint_level, |this| this.into(destination, block, value))
47+
ensure_sufficient_stack(|| {
48+
this.in_scope(region_scope, lint_level, |this| {
49+
this.into(destination, block, value)
50+
})
51+
})
4752
}
4853
ExprKind::Block { body: ast_block } => {
4954
this.ast_block(destination, block, ast_block, source_info)

src/librustc_typeck/check/expr.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use crate::type_error_struct;
1919
use rustc_ast::ast;
2020
use rustc_ast::util::lev_distance::find_best_match_for_name;
2121
use rustc_data_structures::fx::FxHashMap;
22+
use rustc_data_structures::stack::ensure_sufficient_stack;
2223
use rustc_errors::ErrorReported;
2324
use rustc_errors::{pluralize, struct_span_err, Applicability, DiagnosticBuilder, DiagnosticId};
2425
use rustc_hir as hir;
@@ -177,7 +178,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
177178
let old_diverges = self.diverges.replace(Diverges::Maybe);
178179
let old_has_errors = self.has_errors.replace(false);
179180

180-
let ty = self.check_expr_kind(expr, expected);
181+
let ty = ensure_sufficient_stack(|| self.check_expr_kind(expr, expected));
181182

182183
// Warn for non-block expressions with diverging children.
183184
match expr.kind {

0 commit comments

Comments
 (0)