@@ -15,6 +15,7 @@ use rustc_data_structures::graph::implementation::{
1515use rustc_data_structures:: intern:: Interned ;
1616use rustc_index:: vec:: { Idx , IndexVec } ;
1717use rustc_middle:: ty:: fold:: TypeFoldable ;
18+ use rustc_middle:: ty:: PlaceholderRegion ;
1819use rustc_middle:: ty:: { self , Ty , TyCtxt } ;
1920use rustc_middle:: ty:: { ReEarlyBound , ReErased , ReFree , ReStatic } ;
2021use rustc_middle:: ty:: { ReLateBound , RePlaceholder , ReVar } ;
@@ -195,6 +196,36 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
195196 }
196197 }
197198
199+ /// Gets the LUb of a given region and the empty region
200+ fn lub_empty ( & self , a_region : Region < ' tcx > ) -> Result < Region < ' tcx > , PlaceholderRegion > {
201+ match * a_region {
202+ ReLateBound ( ..) | ReErased => {
203+ bug ! ( "cannot relate region: {:?}" , a_region) ;
204+ }
205+
206+ ReVar ( v_id) => {
207+ span_bug ! (
208+ self . var_infos[ v_id] . origin. span( ) ,
209+ "lub invoked with non-concrete regions: {:?}" ,
210+ a_region,
211+ ) ;
212+ }
213+
214+ ReStatic => {
215+ // nothing lives longer than `'static`
216+ Ok ( self . tcx ( ) . lifetimes . re_static )
217+ }
218+
219+ ReEarlyBound ( _) | ReFree ( _) => {
220+ // All empty regions are less than early-bound, free,
221+ // and scope regions.
222+ Ok ( a_region)
223+ }
224+
225+ RePlaceholder ( placeholder) => Err ( placeholder) ,
226+ }
227+ }
228+
198229 fn expansion ( & self , var_values : & mut LexicalRegionResolutions < ' tcx > ) {
199230 // In the first pass, we expand region vids according to constraints we
200231 // have previously found. In the second pass, we loop through the region
@@ -237,40 +268,15 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
237268 true
238269 }
239270 VarValue :: Value ( cur_region) => {
240- let lub = match * cur_region {
241- ReLateBound ( ..) | ReErased => {
242- bug ! ( "cannot relate region: {:?}" , cur_region) ;
243- }
244-
245- ReVar ( v_id) => {
246- span_bug ! (
247- self . var_infos[ v_id] . origin. span( ) ,
248- "lub_concrete_regions invoked with non-concrete regions: {:?}" ,
249- cur_region,
250- ) ;
251- }
252-
253- ReStatic => {
254- // nothing lives longer than `'static`
255- self . tcx ( ) . lifetimes . re_static
256- }
257-
258- ReEarlyBound ( _) | ReFree ( _) => {
259- // All empty regions are less than early-bound, free,
260- // and scope regions.
271+ let lub = match self . lub_empty ( cur_region) {
272+ Ok ( r) => r,
273+ // If the empty and placeholder regions are in the same universe,
274+ // then the LUB is the Placeholder region (which is the cur_region).
275+ // If they are not in the same universe, the LUB is the Static lifetime.
276+ Err ( placeholder) if a_universe == placeholder. universe => {
261277 cur_region
262278 }
263-
264- RePlaceholder ( placeholder) => {
265- // If the empty and placeholder regions are in the same universe,
266- // then the LUB is the Placeholder region (which is the cur_region).
267- // If they are not in the same universe, the LUB is the Static lifetime.
268- if a_universe == placeholder. universe {
269- cur_region
270- } else {
271- self . tcx ( ) . lifetimes . re_static
272- }
273- }
279+ Err ( _) => self . tcx ( ) . lifetimes . re_static ,
274280 } ;
275281
276282 if lub == cur_region {
@@ -368,40 +374,15 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
368374
369375 match * b_data {
370376 VarValue :: Empty ( empty_ui) => {
371- let lub = match * a_region {
372- ReLateBound ( ..) | ReErased => {
373- bug ! ( "cannot relate region: {:?}" , a_region) ;
374- }
375-
376- ReVar ( v_id) => {
377- span_bug ! (
378- self . var_infos[ v_id] . origin. span( ) ,
379- "expand_node invoked with non-concrete regions: {:?}" ,
380- a_region,
381- ) ;
382- }
383-
384- ReStatic => {
385- // nothing lives longer than `'static`
386- self . tcx ( ) . lifetimes . re_static
387- }
388-
389- ReEarlyBound ( _) | ReFree ( _) => {
390- // All empty regions are less than early-bound, free,
391- // and scope regions.
392- a_region
393- }
394-
395- RePlaceholder ( placeholder) => {
396- // If this empty region is from a universe that can
397- // name the placeholder, then the placeholder is
398- // larger; otherwise, the only ancestor is `'static`.
399- if empty_ui. can_name ( placeholder. universe ) {
400- self . tcx ( ) . mk_region ( RePlaceholder ( placeholder) )
401- } else {
402- self . tcx ( ) . lifetimes . re_static
403- }
377+ let lub = match self . lub_empty ( a_region) {
378+ Ok ( r) => r,
379+ // If this empty region is from a universe that can
380+ // name the placeholder, then the placeholder is
381+ // larger; otherwise, the only ancestor is `'static`.
382+ Err ( placeholder) if empty_ui. can_name ( placeholder. universe ) => {
383+ self . tcx ( ) . mk_region ( RePlaceholder ( placeholder) )
404384 }
385+ Err ( _) => self . tcx ( ) . lifetimes . re_static ,
405386 } ;
406387
407388 debug ! ( "Expanding value of {:?} from empty lifetime to {:?}" , b_vid, lub) ;
0 commit comments