Skip to content

Commit f2c4ccd

Browse files
committed
Auto merge of rust-lang#136352 - lqd:ensure-stacks, r=compiler-errors
Add a couple of missing `ensure_sufficient_stacks` r? `@saethlin` I hope you didn't spend time on this already. (I couldn't sleep, opened `check_tail_calls`, there was a single call where it could happen, might as well fix it) This PR adds a couple of missing `ensure_sufficient_stack`s: - one in `check_tail_calls` that prevented the rust-lang#135709 backport on some targets. - after that was fixed, the test still didn't pass starting at 4MB, so I also added one in `check_unsafety` and that made it pass. I didn't add an `rmake` test purposefully limiting the min stack size on `issue-74564-if-expr-stack-overflow.rs`, but we could if we wanted to. On `apple-aarch64-darwin`, this is enough to make `RUST_MIN_STACK=$((1024*1024*3)) ./x test tests/ui --test-args tests/ui/issues/issue-74564-if-expr-stack-overflow.rs` pass for me locally, and it does stack overflow otherwise.
2 parents a5db378 + 94562ee commit f2c4ccd

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

compiler/rustc_mir_build/src/check_tail_calls.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_abi::ExternAbi;
2+
use rustc_data_structures::stack::ensure_sufficient_stack;
23
use rustc_errors::Applicability;
34
use rustc_hir::LangItem;
45
use rustc_hir::def::DefKind;
@@ -344,12 +345,14 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for TailCallCkVisitor<'a, 'tcx> {
344345
}
345346

346347
fn visit_expr(&mut self, expr: &'a Expr<'tcx>) {
347-
if let ExprKind::Become { value } = expr.kind {
348-
let call = &self.thir[value];
349-
self.check_tail_call(call, expr);
350-
}
348+
ensure_sufficient_stack(|| {
349+
if let ExprKind::Become { value } = expr.kind {
350+
let call = &self.thir[value];
351+
self.check_tail_call(call, expr);
352+
}
351353

352-
visit::walk_expr(self, expr);
354+
visit::walk_expr(self, expr);
355+
});
353356
}
354357
}
355358

compiler/rustc_mir_build/src/check_unsafety.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::borrow::Cow;
22
use std::mem;
33
use std::ops::Bound;
44

5+
use rustc_data_structures::stack::ensure_sufficient_stack;
56
use rustc_errors::DiagArgValue;
67
use rustc_hir::def::DefKind;
78
use rustc_hir::{self as hir, BindingMode, ByRef, HirId, Mutability};
@@ -476,7 +477,9 @@ impl<'a, 'tcx> Visitor<'a, 'tcx> for UnsafetyVisitor<'a, 'tcx> {
476477
ExprKind::Scope { value, lint_level: LintLevel::Explicit(hir_id), region_scope: _ } => {
477478
let prev_id = self.hir_context;
478479
self.hir_context = hir_id;
479-
self.visit_expr(&self.thir[value]);
480+
ensure_sufficient_stack(|| {
481+
self.visit_expr(&self.thir[value]);
482+
});
480483
self.hir_context = prev_id;
481484
return; // don't visit the whole expression
482485
}

0 commit comments

Comments
 (0)