Skip to content

Commit 91ff7c6

Browse files
committed
Auto merge of #67731 - matthewjasper:drop-in-place-reclimit, r=eddyb
Handle recursive instantiation of drop shims The compiler used to hang because the recursion limit was never hit.
2 parents 8cacf50 + 4843f22 commit 91ff7c6

6 files changed

+24
-13
lines changed

src/librustc_mir/monomorphize/collector.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ fn check_recursion_limit<'tcx>(
418418
let recursion_depth = recursion_depths.get(&def_id).cloned().unwrap_or(0);
419419
debug!(" => recursion depth={}", recursion_depth);
420420

421-
let recursion_depth = if Some(def_id) == tcx.lang_items().drop_in_place_fn() {
421+
let adjusted_recursion_depth = if Some(def_id) == tcx.lang_items().drop_in_place_fn() {
422422
// HACK: drop_in_place creates tight monomorphization loops. Give
423423
// it more margin.
424424
recursion_depth / 4
@@ -429,7 +429,7 @@ fn check_recursion_limit<'tcx>(
429429
// Code that needs to instantiate the same function recursively
430430
// more than the recursion limit is assumed to be causing an
431431
// infinite expansion.
432-
if recursion_depth > *tcx.sess.recursion_limit.get() {
432+
if adjusted_recursion_depth > *tcx.sess.recursion_limit.get() {
433433
let error = format!("reached the recursion limit while instantiating `{}`", instance);
434434
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
435435
tcx.sess.span_fatal(tcx.hir().span(hir_id), &error);

src/test/ui/issues/issue-38591.rs

-10
This file was deleted.

src/test/ui/issues/issue-26548.stderr renamed to src/test/ui/recursion/issue-26548-recursion-via-normalize.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ error[E0391]: cycle detected when computing layout of `std::option::Option<S>`
33
= note: ...which requires computing layout of `S`...
44
= note: ...which again requires computing layout of `std::option::Option<S>`, completing the cycle
55
note: cycle used when processing `main`
6-
--> $DIR/issue-26548.rs:11:1
6+
--> $DIR/issue-26548-recursion-via-normalize.rs:11:1
77
|
88
LL | fn main() {
99
| ^^^^^^^^^
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Dropck shouldn't hit a recursion limit from checking `S<u32>` since it has
2+
// no free regions or type parameters.
3+
// Codegen however, has to error for the infinitely many `real_drop_in_place`
4+
// functions it has been asked to create.
5+
// build-fail
6+
7+
struct S<T> {
8+
t: T,
9+
s: Box<S<fn(u: T)>>,
10+
}
11+
12+
fn f(x: S<u32>) {}
13+
14+
fn main() {
15+
// Force instantiation.
16+
f as fn(_);
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
error: reached the recursion limit while instantiating `std::ptr::real_drop_in_place::<S<fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(u32))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))>> - shim(Some(S<fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(fn(u32))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))>))`
2+
3+
error: aborting due to previous error
4+

0 commit comments

Comments
 (0)