mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-09 16:37:36 +00:00
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.
This commit is contained in:
commit
91ff7c689d
@ -418,7 +418,7 @@ fn check_recursion_limit<'tcx>(
|
|||||||
let recursion_depth = recursion_depths.get(&def_id).cloned().unwrap_or(0);
|
let recursion_depth = recursion_depths.get(&def_id).cloned().unwrap_or(0);
|
||||||
debug!(" => recursion depth={}", recursion_depth);
|
debug!(" => recursion depth={}", recursion_depth);
|
||||||
|
|
||||||
let recursion_depth = if Some(def_id) == tcx.lang_items().drop_in_place_fn() {
|
let adjusted_recursion_depth = if Some(def_id) == tcx.lang_items().drop_in_place_fn() {
|
||||||
// HACK: drop_in_place creates tight monomorphization loops. Give
|
// HACK: drop_in_place creates tight monomorphization loops. Give
|
||||||
// it more margin.
|
// it more margin.
|
||||||
recursion_depth / 4
|
recursion_depth / 4
|
||||||
@ -429,7 +429,7 @@ fn check_recursion_limit<'tcx>(
|
|||||||
// Code that needs to instantiate the same function recursively
|
// Code that needs to instantiate the same function recursively
|
||||||
// more than the recursion limit is assumed to be causing an
|
// more than the recursion limit is assumed to be causing an
|
||||||
// infinite expansion.
|
// infinite expansion.
|
||||||
if recursion_depth > *tcx.sess.recursion_limit.get() {
|
if adjusted_recursion_depth > *tcx.sess.recursion_limit.get() {
|
||||||
let error = format!("reached the recursion limit while instantiating `{}`", instance);
|
let error = format!("reached the recursion limit while instantiating `{}`", instance);
|
||||||
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
|
if let Some(hir_id) = tcx.hir().as_local_hir_id(def_id) {
|
||||||
tcx.sess.span_fatal(tcx.hir().span(hir_id), &error);
|
tcx.sess.span_fatal(tcx.hir().span(hir_id), &error);
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
// check-pass
|
|
||||||
|
|
||||||
struct S<T> {
|
|
||||||
t : T,
|
|
||||||
s : Box<S<fn(u : T)>>
|
|
||||||
}
|
|
||||||
|
|
||||||
fn f(x : S<u32>) {}
|
|
||||||
|
|
||||||
fn main () {}
|
|
@ -3,7 +3,7 @@ error[E0391]: cycle detected when computing layout of `std::option::Option<S>`
|
|||||||
= note: ...which requires computing layout of `S`...
|
= note: ...which requires computing layout of `S`...
|
||||||
= note: ...which again requires computing layout of `std::option::Option<S>`, completing the cycle
|
= note: ...which again requires computing layout of `std::option::Option<S>`, completing the cycle
|
||||||
note: cycle used when processing `main`
|
note: cycle used when processing `main`
|
||||||
--> $DIR/issue-26548.rs:11:1
|
--> $DIR/issue-26548-recursion-via-normalize.rs:11:1
|
||||||
|
|
|
|
||||||
LL | fn main() {
|
LL | fn main() {
|
||||||
| ^^^^^^^^^
|
| ^^^^^^^^^
|
@ -0,0 +1,17 @@
|
|||||||
|
// Dropck shouldn't hit a recursion limit from checking `S<u32>` since it has
|
||||||
|
// no free regions or type parameters.
|
||||||
|
// Codegen however, has to error for the infinitely many `real_drop_in_place`
|
||||||
|
// functions it has been asked to create.
|
||||||
|
// build-fail
|
||||||
|
|
||||||
|
struct S<T> {
|
||||||
|
t: T,
|
||||||
|
s: Box<S<fn(u: T)>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn f(x: S<u32>) {}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
// Force instantiation.
|
||||||
|
f as fn(_);
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
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))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))>))`
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
Loading…
Reference in New Issue
Block a user