Skip to content

Commit a3beeaa

Browse files
committedJul 4, 2022
Auto merge of #98641 - lcnr:mir-dropck, r=oli-obk
fully move dropck to mir r? `@oli-obk`
2 parents 9c9ae85 + 8deadfa commit a3beeaa

16 files changed

+79
-124
lines changed
 

‎compiler/rustc_borrowck/src/type_check/liveness/mod.rs

+24-27
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
use itertools::{Either, Itertools};
12
use rustc_data_structures::fx::FxHashSet;
23
use rustc_middle::mir::{Body, Local};
34
use rustc_middle::ty::{RegionVid, TyCtxt};
4-
use std::rc::Rc;
5-
65
use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
76
use rustc_mir_dataflow::move_paths::MoveData;
87
use rustc_mir_dataflow::ResultsCursor;
8+
use std::rc::Rc;
99

1010
use crate::{
1111
constraints::OutlivesConstraintSet,
@@ -46,7 +46,8 @@ pub(super) fn generate<'mir, 'tcx>(
4646
&typeck.borrowck_context.universal_regions,
4747
&typeck.borrowck_context.constraints.outlives_constraints,
4848
);
49-
let live_locals = compute_live_locals(typeck.tcx(), &free_regions, &body);
49+
let (relevant_live_locals, boring_locals) =
50+
compute_relevant_live_locals(typeck.tcx(), &free_regions, &body);
5051
let facts_enabled = use_polonius || AllFacts::enabled(typeck.tcx());
5152

5253
let polonius_drop_used = if facts_enabled {
@@ -57,48 +58,44 @@ pub(super) fn generate<'mir, 'tcx>(
5758
None
5859
};
5960

60-
if !live_locals.is_empty() || facts_enabled {
61-
trace::trace(
62-
typeck,
63-
body,
64-
elements,
65-
flow_inits,
66-
move_data,
67-
live_locals,
68-
polonius_drop_used,
69-
);
70-
}
61+
trace::trace(
62+
typeck,
63+
body,
64+
elements,
65+
flow_inits,
66+
move_data,
67+
relevant_live_locals,
68+
boring_locals,
69+
polonius_drop_used,
70+
);
7171
}
7272

73-
// The purpose of `compute_live_locals` is to define the subset of `Local`
73+
// The purpose of `compute_relevant_live_locals` is to define the subset of `Local`
7474
// variables for which we need to do a liveness computation. We only need
7575
// to compute whether a variable `X` is live if that variable contains
7676
// some region `R` in its type where `R` is not known to outlive a free
7777
// region (i.e., where `R` may be valid for just a subset of the fn body).
78-
fn compute_live_locals<'tcx>(
78+
fn compute_relevant_live_locals<'tcx>(
7979
tcx: TyCtxt<'tcx>,
8080
free_regions: &FxHashSet<RegionVid>,
8181
body: &Body<'tcx>,
82-
) -> Vec<Local> {
83-
let live_locals: Vec<Local> = body
84-
.local_decls
85-
.iter_enumerated()
86-
.filter_map(|(local, local_decl)| {
82+
) -> (Vec<Local>, Vec<Local>) {
83+
let (boring_locals, relevant_live_locals): (Vec<_>, Vec<_>) =
84+
body.local_decls.iter_enumerated().partition_map(|(local, local_decl)| {
8785
if tcx.all_free_regions_meet(&local_decl.ty, |r| {
8886
free_regions.contains(&r.to_region_vid())
8987
}) {
90-
None
88+
Either::Left(local)
9189
} else {
92-
Some(local)
90+
Either::Right(local)
9391
}
94-
})
95-
.collect();
92+
});
9693

9794
debug!("{} total variables", body.local_decls.len());
98-
debug!("{} variables need liveness", live_locals.len());
95+
debug!("{} variables need liveness", relevant_live_locals.len());
9996
debug!("{} regions outlive free regions", free_regions.len());
10097

101-
live_locals
98+
(relevant_live_locals, boring_locals)
10299
}
103100

104101
/// Computes all regions that are (currently) known to outlive free

‎compiler/rustc_borrowck/src/type_check/liveness/trace.rs

+29-8
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,13 @@ pub(super) fn trace<'mir, 'tcx>(
4141
elements: &Rc<RegionValueElements>,
4242
flow_inits: &mut ResultsCursor<'mir, 'tcx, MaybeInitializedPlaces<'mir, 'tcx>>,
4343
move_data: &MoveData<'tcx>,
44-
live_locals: Vec<Local>,
44+
relevant_live_locals: Vec<Local>,
45+
boring_locals: Vec<Local>,
4546
polonius_drop_used: Option<Vec<(Local, Location)>>,
4647
) {
4748
debug!("trace()");
4849

49-
let local_use_map = &LocalUseMap::build(&live_locals, elements, body);
50+
let local_use_map = &LocalUseMap::build(&relevant_live_locals, elements, body);
5051

5152
let cx = LivenessContext {
5253
typeck,
@@ -61,10 +62,12 @@ pub(super) fn trace<'mir, 'tcx>(
6162
let mut results = LivenessResults::new(cx);
6263

6364
if let Some(drop_used) = polonius_drop_used {
64-
results.add_extra_drop_facts(drop_used, live_locals.iter().copied().collect())
65+
results.add_extra_drop_facts(drop_used, relevant_live_locals.iter().copied().collect())
6566
}
6667

67-
results.compute_for_all_locals(live_locals);
68+
results.compute_for_all_locals(relevant_live_locals);
69+
70+
results.dropck_boring_locals(boring_locals);
6871
}
6972

7073
/// Contextual state for the type-liveness generator.
@@ -133,8 +136,8 @@ impl<'me, 'typeck, 'flow, 'tcx> LivenessResults<'me, 'typeck, 'flow, 'tcx> {
133136
}
134137
}
135138

136-
fn compute_for_all_locals(&mut self, live_locals: Vec<Local>) {
137-
for local in live_locals {
139+
fn compute_for_all_locals(&mut self, relevant_live_locals: Vec<Local>) {
140+
for local in relevant_live_locals {
138141
self.reset_local_state();
139142
self.add_defs_for(local);
140143
self.compute_use_live_points_for(local);
@@ -157,19 +160,37 @@ impl<'me, 'typeck, 'flow, 'tcx> LivenessResults<'me, 'typeck, 'flow, 'tcx> {
157160
}
158161
}
159162

163+
// Runs dropck for locals whose liveness isn't relevant. This is
164+
// necessary to eagerly detect unbound recursion during drop glue computation.
165+
fn dropck_boring_locals(&mut self, boring_locals: Vec<Local>) {
166+
for local in boring_locals {
167+
let local_ty = self.cx.body.local_decls[local].ty;
168+
let drop_data = self.cx.drop_data.entry(local_ty).or_insert_with({
169+
let typeck = &mut self.cx.typeck;
170+
move || LivenessContext::compute_drop_data(typeck, local_ty)
171+
});
172+
173+
drop_data.dropck_result.report_overflows(
174+
self.cx.typeck.infcx.tcx,
175+
self.cx.body.local_decls[local].source_info.span,
176+
local_ty,
177+
);
178+
}
179+
}
180+
160181
/// Add extra drop facts needed for Polonius.
161182
///
162183
/// Add facts for all locals with free regions, since regions may outlive
163184
/// the function body only at certain nodes in the CFG.
164185
fn add_extra_drop_facts(
165186
&mut self,
166187
drop_used: Vec<(Local, Location)>,
167-
live_locals: FxHashSet<Local>,
188+
relevant_live_locals: FxHashSet<Local>,
168189
) {
169190
let locations = IntervalSet::new(self.cx.elements.num_points());
170191

171192
for (local, location) in drop_used {
172-
if !live_locals.contains(&local) {
193+
if !relevant_live_locals.contains(&local) {
173194
let local_ty = self.cx.body.local_decls[local].ty;
174195
if local_ty.has_free_regions() {
175196
self.cx.add_drop_live_facts_for(local, local_ty, &[location], &locations);

‎compiler/rustc_middle/src/query/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1825,7 +1825,8 @@ rustc_queries! {
18251825
remap_env_constness
18261826
}
18271827

1828-
/// Do not call this query directly: invoke `infcx.at().dropck_outlives()` instead.
1828+
/// Do not call this query directly:
1829+
/// invoke `DropckOutlives::new(dropped_ty)).fully_perform(typeck.infcx)` instead.
18291830
query dropck_outlives(
18301831
goal: CanonicalTyGoal<'tcx>
18311832
) -> Result<

‎compiler/rustc_typeck/src/check/dropck.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ use rustc_middle::ty::subst::SubstsRef;
88
use rustc_middle::ty::util::IgnoreRegions;
99
use rustc_middle::ty::{self, Predicate, Ty, TyCtxt};
1010
use rustc_span::Span;
11-
use rustc_trait_selection::traits::query::dropck_outlives::AtExt;
12-
use rustc_trait_selection::traits::ObligationCause;
1311

1412
/// This function confirms that the `Drop` implementation identified by
1513
/// `drop_impl_did` is not any more specialized than the type it is
@@ -234,18 +232,14 @@ fn ensure_drop_predicates_are_implied_by_item_defn<'tcx>(
234232
/// This function is not only checking that the dropck obligations are met for
235233
/// the given type, but it's also currently preventing non-regular recursion in
236234
/// types from causing stack overflows (dropck_no_diverge_on_nonregular_*.rs).
235+
///
236+
/// FIXME: Completely rip out dropck and regionck.
237237
pub(crate) fn check_drop_obligations<'a, 'tcx>(
238-
rcx: &mut RegionCtxt<'a, 'tcx>,
239-
ty: Ty<'tcx>,
240-
span: Span,
241-
body_id: hir::HirId,
238+
_rcx: &mut RegionCtxt<'a, 'tcx>,
239+
_ty: Ty<'tcx>,
240+
_span: Span,
241+
_body_id: hir::HirId,
242242
) {
243-
debug!("check_drop_obligations typ: {:?}", ty);
244-
245-
let cause = &ObligationCause::misc(span, body_id);
246-
let infer_ok = rcx.infcx.at(cause, rcx.fcx.param_env).dropck_outlives(ty);
247-
debug!("dropck_outlives = {:#?}", infer_ok);
248-
rcx.fcx.register_infer_ok_obligations(infer_ok);
249243
}
250244

251245
// This is an implementation of the TypeRelation trait with the

‎src/test/ui/dropck/dropck_no_diverge_on_nonregular_1.rs

-1
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,4 @@ enum FingerTree<T:'static> {
2323
fn main() {
2424
let ft = //~ ERROR overflow while adding drop-check rules for FingerTree
2525
FingerTree::Single(1);
26-
//~^ ERROR overflow while adding drop-check rules for FingerTree
2726
}

‎src/test/ui/dropck/dropck_no_diverge_on_nonregular_1.stderr

+1-9
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,5 @@ LL | let ft =
66
|
77
= note: overflowed on FingerTree<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<i32>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
88

9-
error[E0320]: overflow while adding drop-check rules for FingerTree<i32>
10-
--> $DIR/dropck_no_diverge_on_nonregular_1.rs:25:9
11-
|
12-
LL | FingerTree::Single(1);
13-
| ^^^^^^^^^^^^^^^^^^^^^
14-
|
15-
= note: overflowed on FingerTree<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<i32>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
16-
17-
error: aborting due to 2 previous errors
9+
error: aborting due to previous error
1810

‎src/test/ui/dropck/dropck_no_diverge_on_nonregular_2.rs

-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,4 @@ enum FingerTree<T:'static> {
2222
fn main() {
2323
let ft = //~ ERROR overflow while adding drop-check rules for FingerTree
2424
FingerTree::Single(1);
25-
//~^ ERROR overflow while adding drop-check rules for FingerTree
2625
}

‎src/test/ui/dropck/dropck_no_diverge_on_nonregular_2.stderr

+1-9
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,5 @@ LL | let ft =
66
|
77
= note: overflowed on FingerTree<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<i32>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
88

9-
error[E0320]: overflow while adding drop-check rules for FingerTree<i32>
10-
--> $DIR/dropck_no_diverge_on_nonregular_2.rs:24:9
11-
|
12-
LL | FingerTree::Single(1);
13-
| ^^^^^^^^^^^^^^^^^^^^^
14-
|
15-
= note: overflowed on FingerTree<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<i32>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
16-
17-
error: aborting due to 2 previous errors
9+
error: aborting due to previous error
1810

‎src/test/ui/dropck/dropck_no_diverge_on_nonregular_3.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,5 @@ enum Wrapper<T:'static> {
3131
fn main() {
3232
let w = //~ ERROR overflow while adding drop-check rules for Option
3333
Some(Wrapper::Simple::<u32>);
34-
//~^ ERROR overflow while adding drop-check rules for Option
35-
//~| ERROR overflow while adding drop-check rules for Wrapper
34+
//~^ ERROR overflow while adding drop-check rules for Wrapper
3635
}

‎src/test/ui/dropck/dropck_no_diverge_on_nonregular_3.stderr

+1-9
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,6 @@ LL | let w =
66
|
77
= note: overflowed on FingerTree<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<u32>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
88

9-
error[E0320]: overflow while adding drop-check rules for Option<Wrapper<u32>>
10-
--> $DIR/dropck_no_diverge_on_nonregular_3.rs:33:9
11-
|
12-
LL | Some(Wrapper::Simple::<u32>);
13-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
14-
|
15-
= note: overflowed on FingerTree<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<u32>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
16-
179
error[E0320]: overflow while adding drop-check rules for Wrapper<u32>
1810
--> $DIR/dropck_no_diverge_on_nonregular_3.rs:33:14
1911
|
@@ -22,5 +14,5 @@ LL | Some(Wrapper::Simple::<u32>);
2214
|
2315
= note: overflowed on FingerTree<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<Node<u32>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
2416

25-
error: aborting due to 3 previous errors
17+
error: aborting due to 2 previous errors
2618

‎src/test/ui/infinite/infinite-struct.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
struct Take(Take);
22
//~^ ERROR has infinite size
3-
//~| ERROR cycle detected
43

54
// check that we don't hang trying to find the tail of a recursive struct (#79437)
65
fn foo() -> Take {

‎src/test/ui/infinite/infinite-struct.stderr

+2-12
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@ help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `Take` repre
1111
LL | struct Take(Box<Take>);
1212
| ++++ +
1313

14-
error[E0391]: cycle detected when computing drop-check constraints for `Take`
15-
--> $DIR/infinite-struct.rs:1:1
16-
|
17-
LL | struct Take(Take);
18-
| ^^^^^^^^^^^
19-
|
20-
= note: ...which immediately requires computing drop-check constraints for `Take` again
21-
= note: cycle used when computing dropck types for `Canonical { max_universe: U0, variables: [], value: ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing, constness: NotConst }, value: Take } }`
22-
23-
error: aborting due to 2 previous errors
14+
error: aborting due to previous error
2415

25-
Some errors have detailed explanations: E0072, E0391.
26-
For more information about an error, try `rustc --explain E0072`.
16+
For more information about this error, try `rustc --explain E0072`.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
enum MList { Cons(isize, MList), Nil }
22
//~^ ERROR recursive type `MList` has infinite size
3-
//~| ERROR cycle detected when computing drop-check constraints for `MList`
43

54
fn main() { let a = MList::Cons(10, MList::Cons(11, MList::Nil)); }

‎src/test/ui/infinite/infinite-tag-type-recursion.stderr

+2-12
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@ help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to make `MList` repr
1111
LL | enum MList { Cons(isize, Box<MList>), Nil }
1212
| ++++ +
1313

14-
error[E0391]: cycle detected when computing drop-check constraints for `MList`
15-
--> $DIR/infinite-tag-type-recursion.rs:1:1
16-
|
17-
LL | enum MList { Cons(isize, MList), Nil }
18-
| ^^^^^^^^^^
19-
|
20-
= note: ...which immediately requires computing drop-check constraints for `MList` again
21-
= note: cycle used when computing dropck types for `Canonical { max_universe: U0, variables: [], value: ParamEnvAnd { param_env: ParamEnv { caller_bounds: [], reveal: UserFacing, constness: NotConst }, value: MList } }`
22-
23-
error: aborting due to 2 previous errors
14+
error: aborting due to previous error
2415

25-
Some errors have detailed explanations: E0072, E0391.
26-
For more information about an error, try `rustc --explain E0072`.
16+
For more information about this error, try `rustc --explain E0072`.

‎src/test/ui/recursion/issue-38591-non-regular-dropck-recursion.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
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 `drop_in_place`
4-
// functions it has been asked to create.
5-
6-
// build-fail
7-
// normalize-stderr-test: ".nll/" -> "/"
8-
// compile-flags: -Zmir-opt-level=0
1+
// `S` is infinitely recursing so it's not possible to generate a finite
2+
// drop impl (ignoring polymorphization).
3+
//
4+
// Dropck should therefore detect that this is the case and eagerly error.
95

106
struct S<T> {
117
t: T,
128
s: Box<S<fn(u: T)>>,
139
}
1410

15-
fn f(x: S<u32>) {}
11+
fn f(x: S<u32>) {} //~ ERROR overflow while adding drop-check rules for S<u32>
1612

1713
fn main() {
1814
// Force instantiation.
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
1-
error: reached the recursion limit while instantiating `std::ptr::drop_in_place::<S<fn(f...)))))))))))))))))))))))))))))>))`
2-
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
1+
error[E0320]: overflow while adding drop-check rules for S<u32>
2+
--> $DIR/issue-38591-non-regular-dropck-recursion.rs:11:6
33
|
4-
LL | pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
4+
LL | fn f(x: S<u32>) {}
5+
| ^
66
|
7-
note: `std::ptr::drop_in_place` defined here
8-
--> $SRC_DIR/core/src/ptr/mod.rs:LL:COL
9-
|
10-
LL | pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) {
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
= note: the full type name has been written to '$TEST_BUILD_DIR/recursion/issue-38591-non-regular-dropck-recursion/issue-38591-non-regular-dropck-recursion.long-type.txt'
7+
= note: overflowed on 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(u32)))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))))>
138

149
error: aborting due to previous error
1510

0 commit comments

Comments
 (0)
Please sign in to comment.