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.
This commit is contained in:
Josh Stone 2025-06-04 15:03:19 -07:00
parent 4b27a04cc8
commit 925e76167c

View file

@ -38,7 +38,10 @@ impl<'tcx> ThirBuildCx<'tcx> {
}
pub(crate) fn mirror_exprs(&mut self, exprs: &'tcx [hir::Expr<'tcx>]) -> Box<[ExprId]> {
exprs.iter().map(|expr| self.mirror_expr_inner(expr)).collect()
// `mirror_exprs` may also recurse deeply, so it needs protection from stack overflow.
// Note that we *could* forward to `mirror_expr` for that, but we can consolidate the
// overhead of stack growth by doing it outside the iteration.
ensure_sufficient_stack(|| exprs.iter().map(|expr| self.mirror_expr_inner(expr)).collect())
}
#[instrument(level = "trace", skip(self, hir_expr))]