Skip to content

Commit c709862

Browse files
committed
Auto merge of #74708 - kanru:issue-74564, r=davidtwco
Ensure stack when type checking and building MIR for large if expressions Fixes #74564
2 parents 6c8927b + 0e2ec8c commit c709862

File tree

4 files changed

+10429
-3
lines changed

4 files changed

+10429
-3
lines changed

src/librustc_expand/expand.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use rustc_ast::visit::{self, AssocCtxt, Visitor};
1717
use rustc_ast_pretty::pprust;
1818
use rustc_attr::{self as attr, is_builtin_attr, HasAttrs};
1919
use rustc_data_structures::map_in_place::MapInPlace;
20+
use rustc_data_structures::stack::ensure_sufficient_stack;
2021
use rustc_errors::{Applicability, PResult};
2122
use rustc_feature::Features;
2223
use rustc_parse::parser::Parser;
@@ -1165,7 +1166,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
11651166
self.check_attributes(&expr.attrs);
11661167
self.collect_bang(mac, expr.span, AstFragmentKind::Expr).make_expr().into_inner()
11671168
} else {
1168-
noop_visit_expr(&mut expr, self);
1169+
ensure_sufficient_stack(|| noop_visit_expr(&mut expr, self));
11691170
expr
11701171
}
11711172
});

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)