Auto merge of #114990 - Zoxc:else-if-overflow, r=cjgillot
Fix a stack overflow with long else if chains This fixes stack overflows when running the `issue-74564-if-expr-stack-overflow.rs` test with the parallel compiler.
This commit is contained in:
commit
c0b6ffaaea
@ -13,6 +13,7 @@
|
||||
use crate::{ast::*, StaticItem};
|
||||
|
||||
use rustc_data_structures::flat_map_in_place::FlatMapInPlace;
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_span::source_map::Spanned;
|
||||
use rustc_span::symbol::Ident;
|
||||
@ -1369,7 +1370,7 @@ pub fn noop_visit_expr<T: MutVisitor>(
|
||||
ExprKind::If(cond, tr, fl) => {
|
||||
vis.visit_expr(cond);
|
||||
vis.visit_block(tr);
|
||||
visit_opt(fl, |fl| vis.visit_expr(fl));
|
||||
visit_opt(fl, |fl| ensure_sufficient_stack(|| vis.visit_expr(fl)));
|
||||
}
|
||||
ExprKind::While(cond, body, label) => {
|
||||
vis.visit_expr(cond);
|
||||
|
@ -22,6 +22,7 @@
|
||||
use rustc_ast::{Arm, Async, BlockCheckMode, Expr, ExprKind, Label, Movability, RangeLimits};
|
||||
use rustc_ast::{ClosureBinder, MetaItemLit, StmtKind};
|
||||
use rustc_ast_pretty::pprust;
|
||||
use rustc_data_structures::stack::ensure_sufficient_stack;
|
||||
use rustc_errors::{
|
||||
AddToDiagnostic, Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, IntoDiagnostic,
|
||||
PResult, StashKey,
|
||||
@ -2489,7 +2490,7 @@ fn parse_expr_else(&mut self) -> PResult<'a, P<Expr>> {
|
||||
let else_span = self.prev_token.span; // `else`
|
||||
let attrs = self.parse_outer_attributes()?; // For recovery.
|
||||
let expr = if self.eat_keyword(kw::If) {
|
||||
self.parse_expr_if()?
|
||||
ensure_sufficient_stack(|| self.parse_expr_if())?
|
||||
} else if self.check(&TokenKind::OpenDelim(Delimiter::Brace)) {
|
||||
self.parse_simple_block()?
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user