Auto merge of #115224 - spastorino:remove-lub_empty, r=lcnr

Remove lub_empty from lexical region resolve

As of my understanding this method made sense when we had `ReEmpty`.
Removed `lub_empty` and made the calling site code equivalent.

r? `@lcnr` `@compiler-errors`
This commit is contained in:
bors 2023-08-26 20:45:46 +00:00
commit 69e97df5ce

View File

@ -15,7 +15,6 @@
use rustc_data_structures::intern::Interned; use rustc_data_structures::intern::Interned;
use rustc_index::{IndexSlice, IndexVec}; use rustc_index::{IndexSlice, IndexVec};
use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::PlaceholderRegion;
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::ty::{ReEarlyBound, ReErased, ReError, ReFree, ReStatic}; use rustc_middle::ty::{ReEarlyBound, ReErased, ReError, ReFree, ReStatic};
use rustc_middle::ty::{ReLateBound, RePlaceholder, ReVar}; use rustc_middle::ty::{ReLateBound, RePlaceholder, ReVar};
@ -173,38 +172,6 @@ fn dump_constraints(&self) {
} }
} }
/// Gets the LUb of a given region and the empty region
fn lub_empty(&self, a_region: Region<'tcx>) -> Result<Region<'tcx>, PlaceholderRegion> {
match *a_region {
ReLateBound(..) | ReErased => {
bug!("cannot relate region: {:?}", a_region);
}
ReVar(v_id) => {
span_bug!(
self.var_infos[v_id].origin.span(),
"lub invoked with non-concrete regions: {:?}",
a_region,
);
}
ReStatic => {
// nothing lives longer than `'static`
Ok(self.tcx().lifetimes.re_static)
}
ReError(_) => Ok(a_region),
ReEarlyBound(_) | ReFree(_) => {
// All empty regions are less than early-bound, free,
// and scope regions.
Ok(a_region)
}
RePlaceholder(placeholder) => Err(placeholder),
}
}
fn expansion(&self, var_values: &mut LexicalRegionResolutions<'tcx>) { fn expansion(&self, var_values: &mut LexicalRegionResolutions<'tcx>) {
// In the first pass, we expand region vids according to constraints we // In the first pass, we expand region vids according to constraints we
// have previously found. In the second pass, we loop through the region // have previously found. In the second pass, we loop through the region
@ -247,20 +214,15 @@ fn expansion(&self, var_values: &mut LexicalRegionResolutions<'tcx>) {
true true
} }
VarValue::Value(cur_region) => { VarValue::Value(cur_region) => {
let lub = match self.lub_empty(cur_region) { match *cur_region {
Ok(r) => r, // If this empty region is from a universe that can name the
// If the empty and placeholder regions are in the same universe, // placeholder universe, then the LUB is the Placeholder region
// then the LUB is the Placeholder region (which is the cur_region). // (which is the cur_region). Otherwise, the LUB is the Static
// If they are not in the same universe, the LUB is the Static lifetime. // lifetime.
Err(placeholder) if a_universe == placeholder.universe => { RePlaceholder(placeholder)
cur_region if !a_universe.can_name(placeholder.universe) =>
} {
Err(_) => self.tcx().lifetimes.re_static, let lub = self.tcx().lifetimes.re_static;
};
if lub == cur_region {
false
} else {
debug!( debug!(
"Expanding value of {:?} from {:?} to {:?}", "Expanding value of {:?} from {:?} to {:?}",
b_vid, cur_region, lub b_vid, cur_region, lub
@ -269,6 +231,9 @@ fn expansion(&self, var_values: &mut LexicalRegionResolutions<'tcx>) {
*b_data = VarValue::Value(lub); *b_data = VarValue::Value(lub);
true true
} }
_ => false,
}
} }
VarValue::ErrorValue => false, VarValue::ErrorValue => false,
@ -341,15 +306,19 @@ fn expand_node(
match *b_data { match *b_data {
VarValue::Empty(empty_ui) => { VarValue::Empty(empty_ui) => {
let lub = match self.lub_empty(a_region) { let lub = match *a_region {
Ok(r) => r, RePlaceholder(placeholder) => {
// If this empty region is from a universe that can // If this empty region is from a universe that can
// name the placeholder, then the placeholder is // name the placeholder, then the placeholder is
// larger; otherwise, the only ancestor is `'static`. // larger; otherwise, the only ancestor is `'static`.
Err(placeholder) if empty_ui.can_name(placeholder.universe) => { if empty_ui.can_name(placeholder.universe) {
ty::Region::new_placeholder(self.tcx(), placeholder) ty::Region::new_placeholder(self.tcx(), placeholder)
} else {
self.tcx().lifetimes.re_static
} }
Err(_) => self.tcx().lifetimes.re_static, }
_ => a_region,
}; };
debug!("Expanding value of {:?} from empty lifetime to {:?}", b_vid, lub); debug!("Expanding value of {:?} from empty lifetime to {:?}", b_vid, lub);