Skip to content

Commit e26ef22

Browse files
authored
Rollup merge of rust-lang#72087 - matthewjasper:regionck-hang, r=nikomatsakis
Fix hang in lexical_region_resolve Regionck was stuck in a loop where a region value was changing between two equal regions. Closes rust-lang#72051
2 parents c3d9872 + e7b0204 commit e26ef22

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

Diff for: src/librustc_infer/infer/lexical_region_resolve/mod.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,21 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
325325
}
326326
}
327327

328-
debug!("enforce_member_constraint: final least choice = {:?}", least_choice);
329-
if least_choice != member_lower_bound {
328+
// (#72087) Different `ty::Regions` can be known to be equal, for
329+
// example, we know that `'a` and `'static` are equal in a function
330+
// with a parameter of type `&'static &'a ()`.
331+
//
332+
// When we have two equal regions like this `expansion` will use
333+
// `lub_concrete_regions` to pick a canonical representative. The same
334+
// choice is needed here so that we don't end up in a cycle of
335+
// `expansion` changing the region one way and the code here changing
336+
// it back.
337+
let lub = self.lub_concrete_regions(least_choice, member_lower_bound);
338+
debug!(
339+
"enforce_member_constraint: final least choice = {:?}\nlub = {:?}",
340+
least_choice, lub
341+
);
342+
if lub != member_lower_bound {
330343
*var_values.value_mut(member_vid) = VarValue::Value(least_choice);
331344
true
332345
} else {
@@ -578,8 +591,7 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
578591
self.tcx().mk_region(ReScope(lub))
579592
}
580593

581-
(&ReEarlyBound(_), &ReEarlyBound(_) | &ReFree(_))
582-
| (&ReFree(_), &ReEarlyBound(_) | &ReFree(_)) => {
594+
(&ReEarlyBound(_) | &ReFree(_), &ReEarlyBound(_) | &ReFree(_)) => {
583595
self.region_rels.lub_free_regions(a, b)
584596
}
585597

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Regression test for #72051, hang when resolving regions.
2+
3+
// check-pass
4+
// edition:2018
5+
6+
pub async fn query<'a>(_: &(), _: &(), _: (&(dyn std::any::Any + 'a),) ) {}
7+
fn main() {}

0 commit comments

Comments
 (0)