Skip to content

Commit 4843f22

Browse files
committed
Handle recursive instantiation of drop shims
1 parent 580ac0b commit 4843f22

6 files changed

+24
-13
lines changed

src/librustc_mir/monomorphize/collector.rs

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

426-
let recursion_depth = if Some(def_id) == tcx.lang_items().drop_in_place_fn() {
426+
let adjusted_recursion_depth = if Some(def_id) == tcx.lang_items().drop_in_place_fn() {
427427
// HACK: drop_in_place creates tight monomorphization loops. Give
428428
// it more margin.
429429
recursion_depth / 4
@@ -434,7 +434,7 @@ fn check_recursion_limit<'tcx>(
434434
// Code that needs to instantiate the same function recursively
435435
// more than the recursion limit is assumed to be causing an
436436
// infinite expansion.
437-
if recursion_depth > *tcx.sess.recursion_limit.get() {
437+
if adjusted_recursion_depth > *tcx.sess.recursion_limit.get() {
438438
let error = format!("reached the recursion limit while instantiating `{}`", instance);
439439
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
440440
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)