Skip to content

Commit 69e97df

Browse files
committed
Auto merge of rust-lang#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`
2 parents 22d41ae + b92840a commit 69e97df

File tree

1 file changed

+30
-61
lines changed
  • compiler/rustc_infer/src/infer/lexical_region_resolve

1 file changed

+30
-61
lines changed

compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs

+30-61
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc_data_structures::graph::implementation::{
1515
use rustc_data_structures::intern::Interned;
1616
use rustc_index::{IndexSlice, IndexVec};
1717
use rustc_middle::ty::fold::TypeFoldable;
18-
use rustc_middle::ty::PlaceholderRegion;
1918
use rustc_middle::ty::{self, Ty, TyCtxt};
2019
use rustc_middle::ty::{ReEarlyBound, ReErased, ReError, ReFree, ReStatic};
2120
use rustc_middle::ty::{ReLateBound, RePlaceholder, ReVar};
@@ -173,38 +172,6 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
173172
}
174173
}
175174

176-
/// Gets the LUb of a given region and the empty region
177-
fn lub_empty(&self, a_region: Region<'tcx>) -> Result<Region<'tcx>, PlaceholderRegion> {
178-
match *a_region {
179-
ReLateBound(..) | ReErased => {
180-
bug!("cannot relate region: {:?}", a_region);
181-
}
182-
183-
ReVar(v_id) => {
184-
span_bug!(
185-
self.var_infos[v_id].origin.span(),
186-
"lub invoked with non-concrete regions: {:?}",
187-
a_region,
188-
);
189-
}
190-
191-
ReStatic => {
192-
// nothing lives longer than `'static`
193-
Ok(self.tcx().lifetimes.re_static)
194-
}
195-
196-
ReError(_) => Ok(a_region),
197-
198-
ReEarlyBound(_) | ReFree(_) => {
199-
// All empty regions are less than early-bound, free,
200-
// and scope regions.
201-
Ok(a_region)
202-
}
203-
204-
RePlaceholder(placeholder) => Err(placeholder),
205-
}
206-
}
207-
208175
fn expansion(&self, var_values: &mut LexicalRegionResolutions<'tcx>) {
209176
// In the first pass, we expand region vids according to constraints we
210177
// have previously found. In the second pass, we loop through the region
@@ -247,27 +214,25 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
247214
true
248215
}
249216
VarValue::Value(cur_region) => {
250-
let lub = match self.lub_empty(cur_region) {
251-
Ok(r) => r,
252-
// If the empty and placeholder regions are in the same universe,
253-
// then the LUB is the Placeholder region (which is the cur_region).
254-
// If they are not in the same universe, the LUB is the Static lifetime.
255-
Err(placeholder) if a_universe == placeholder.universe => {
256-
cur_region
217+
match *cur_region {
218+
// If this empty region is from a universe that can name the
219+
// placeholder universe, then the LUB is the Placeholder region
220+
// (which is the cur_region). Otherwise, the LUB is the Static
221+
// lifetime.
222+
RePlaceholder(placeholder)
223+
if !a_universe.can_name(placeholder.universe) =>
224+
{
225+
let lub = self.tcx().lifetimes.re_static;
226+
debug!(
227+
"Expanding value of {:?} from {:?} to {:?}",
228+
b_vid, cur_region, lub
229+
);
230+
231+
*b_data = VarValue::Value(lub);
232+
true
257233
}
258-
Err(_) => self.tcx().lifetimes.re_static,
259-
};
260-
261-
if lub == cur_region {
262-
false
263-
} else {
264-
debug!(
265-
"Expanding value of {:?} from {:?} to {:?}",
266-
b_vid, cur_region, lub
267-
);
268-
269-
*b_data = VarValue::Value(lub);
270-
true
234+
235+
_ => false,
271236
}
272237
}
273238

@@ -341,15 +306,19 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
341306

342307
match *b_data {
343308
VarValue::Empty(empty_ui) => {
344-
let lub = match self.lub_empty(a_region) {
345-
Ok(r) => r,
346-
// If this empty region is from a universe that can
347-
// name the placeholder, then the placeholder is
348-
// larger; otherwise, the only ancestor is `'static`.
349-
Err(placeholder) if empty_ui.can_name(placeholder.universe) => {
350-
ty::Region::new_placeholder(self.tcx(), placeholder)
309+
let lub = match *a_region {
310+
RePlaceholder(placeholder) => {
311+
// If this empty region is from a universe that can
312+
// name the placeholder, then the placeholder is
313+
// larger; otherwise, the only ancestor is `'static`.
314+
if empty_ui.can_name(placeholder.universe) {
315+
ty::Region::new_placeholder(self.tcx(), placeholder)
316+
} else {
317+
self.tcx().lifetimes.re_static
318+
}
351319
}
352-
Err(_) => self.tcx().lifetimes.re_static,
320+
321+
_ => a_region,
353322
};
354323

355324
debug!("Expanding value of {:?} from empty lifetime to {:?}", b_vid, lub);

0 commit comments

Comments
 (0)