From 5f38c839ad306bf230adb5f27b98983f1d04722b Mon Sep 17 00:00:00 2001 From: LeSeulArtichaut Date: Sat, 6 Mar 2021 22:41:47 +0100 Subject: [PATCH] Prevent stack overflow when building THIR --- compiler/rustc_mir_build/src/thir/cx/expr.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 00456a8bcc3..dfcb52c83c0 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -1,6 +1,7 @@ use crate::thir::cx::Cx; use crate::thir::util::UserAnnotatedTyHelpers; use crate::thir::*; +use rustc_data_structures::stack::ensure_sufficient_stack; use rustc_hir as hir; use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res}; use rustc_index::vec::Idx; @@ -23,7 +24,8 @@ impl<'thir, 'tcx> Cx<'thir, 'tcx> { /// /// [`mirror_exprs`]: Self::mirror_exprs crate fn mirror_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) -> &'thir Expr<'thir, 'tcx> { - self.arena.alloc(self.mirror_expr_inner(expr)) + // `mirror_expr` is recursing very deep. Make sure the stack doesn't overflow. + ensure_sufficient_stack(|| self.arena.alloc(self.mirror_expr_inner(expr))) } /// Mirrors and allocates a slice of [`hir::Expr`]s. They will be allocated as a