Skip to content

Commit

Permalink
Rollup merge of #72087 - matthewjasper:regionck-hang, r=nikomatsakis
Browse files Browse the repository at this point in the history
Fix hang in lexical_region_resolve

Regionck was stuck in a loop where a region value was changing between two equal regions.

Closes #72051
  • Loading branch information
Dylan-DPC committed May 14, 2020
2 parents b20b200 + e7b0204 commit 2e65f7b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/librustc_infer/infer/lexical_region_resolve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,21 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
}
}

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

(&ReEarlyBound(_), &ReEarlyBound(_) | &ReFree(_))
| (&ReFree(_), &ReEarlyBound(_) | &ReFree(_)) => {
(&ReEarlyBound(_) | &ReFree(_), &ReEarlyBound(_) | &ReFree(_)) => {
self.region_rels.lub_free_regions(a, b)
}

Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/regions/issue-72051-member-region-hang.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Regression test for #72051, hang when resolving regions.

// check-pass
// edition:2018

pub async fn query<'a>(_: &(), _: &(), _: (&(dyn std::any::Any + 'a),) ) {}
fn main() {}

0 comments on commit 2e65f7b

Please sign in to comment.