Skip to content

Commit 925e761

Browse files
committed
Ensure stack in ThirBuildCx::mirror_exprs
This solve a stack overflow found on Fedora s390x when building `tests/ui/parser/survive-peano-lesson-queue.rs`. Note that the singular `mirror_expr` method already has this stack check, but in this case the plural method was the one recursing too deeply.
1 parent 4b27a04 commit 925e761

File tree

1 file changed

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

1 file changed

+4
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ impl<'tcx> ThirBuildCx<'tcx> {
3838
}
3939

4040
pub(crate) fn mirror_exprs(&mut self, exprs: &'tcx [hir::Expr<'tcx>]) -> Box<[ExprId]> {
41-
exprs.iter().map(|expr| self.mirror_expr_inner(expr)).collect()
41+
// `mirror_exprs` may also recurse deeply, so it needs protection from stack overflow.
42+
// Note that we *could* forward to `mirror_expr` for that, but we can consolidate the
43+
// overhead of stack growth by doing it outside the iteration.
44+
ensure_sufficient_stack(|| exprs.iter().map(|expr| self.mirror_expr_inner(expr)).collect())
4245
}
4346

4447
#[instrument(level = "trace", skip(self, hir_expr))]

0 commit comments

Comments
 (0)