@@ -420,7 +420,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
420
420
// `RegionConstraintData` contains the relationship here.
421
421
if * any_unifications {
422
422
* any_unifications = false ;
423
- self . unification_table ( ) . reset_unifications ( |_| UnifiedRegion ( None ) ) ;
423
+ self . unification_table_mut ( ) . reset_unifications ( |_| UnifiedRegion :: new ( None ) ) ;
424
424
}
425
425
426
426
data
@@ -447,7 +447,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
447
447
) -> RegionVid {
448
448
let vid = self . var_infos . push ( RegionVariableInfo { origin, universe } ) ;
449
449
450
- let u_vid = self . unification_table ( ) . new_key ( UnifiedRegion ( None ) ) ;
450
+ let u_vid = self . unification_table_mut ( ) . new_key ( UnifiedRegion :: new ( None ) ) ;
451
451
assert_eq ! ( vid, u_vid. vid) ;
452
452
self . undo_log . push ( AddVar ( vid) ) ;
453
453
debug ! ( "created new region variable {:?} in {:?} with origin {:?}" , vid, universe, origin) ;
@@ -516,13 +516,13 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
516
516
match ( sub, sup) {
517
517
( Region ( Interned ( ReVar ( sub) , _) ) , Region ( Interned ( ReVar ( sup) , _) ) ) => {
518
518
debug ! ( "make_eqregion: unifying {:?} with {:?}" , sub, sup) ;
519
- self . unification_table ( ) . union ( * sub, * sup) ;
519
+ self . unification_table_mut ( ) . union ( * sub, * sup) ;
520
520
self . any_unifications = true ;
521
521
}
522
522
( Region ( Interned ( ReVar ( vid) , _) ) , value)
523
523
| ( value, Region ( Interned ( ReVar ( vid) , _) ) ) => {
524
524
debug ! ( "make_eqregion: unifying {:?} with {:?}" , vid, value) ;
525
- self . unification_table ( ) . union_value ( * vid, UnifiedRegion ( Some ( value) ) ) ;
525
+ self . unification_table_mut ( ) . union_value ( * vid, UnifiedRegion :: new ( Some ( value) ) ) ;
526
526
self . any_unifications = true ;
527
527
}
528
528
( _, _) => { }
@@ -633,28 +633,25 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
633
633
}
634
634
}
635
635
636
- /// Resolves the passed RegionVid to the root RegionVid in the unification table
637
- pub ( super ) fn opportunistic_resolve_var ( & mut self , rid : ty:: RegionVid ) -> ty:: RegionVid {
638
- self . unification_table ( ) . find ( rid) . vid
639
- }
640
-
641
- /// If the Region is a `ReVar`, then resolves it either to the root value in
642
- /// the unification table, if it exists, or to the root `ReVar` in the table.
643
- /// If the Region is not a `ReVar`, just returns the Region itself.
644
- pub fn opportunistic_resolve_region (
636
+ /// Resolves a region var to its value in the unification table, if it exists.
637
+ /// Otherwise, it is resolved to the root `ReVar` in the table.
638
+ pub fn opportunistic_resolve_var (
645
639
& mut self ,
646
640
tcx : TyCtxt < ' tcx > ,
647
- region : ty:: Region < ' tcx > ,
641
+ vid : ty:: RegionVid ,
648
642
) -> ty:: Region < ' tcx > {
649
- match * region {
650
- ty:: ReVar ( rid) => {
651
- let unified_region = self . unification_table ( ) . probe_value ( rid) ;
652
- unified_region. 0 . unwrap_or_else ( || {
653
- let root = self . unification_table ( ) . find ( rid) . vid ;
654
- tcx. mk_re_var ( root)
655
- } )
656
- }
657
- _ => region,
643
+ let mut ut = self . unification_table_mut ( ) ; // FIXME(rust-lang/ena#42): unnecessary mut
644
+ let root_vid = ut. find ( vid) . vid ;
645
+ let resolved = ut
646
+ . probe_value ( root_vid)
647
+ . get_value_ignoring_universes ( )
648
+ . unwrap_or_else ( || tcx. mk_re_var ( root_vid) ) ;
649
+
650
+ // Don't resolve a variable to a region that it cannot name.
651
+ if self . var_universe ( vid) . can_name ( self . universe ( resolved) ) {
652
+ resolved
653
+ } else {
654
+ tcx. mk_re_var ( vid)
658
655
}
659
656
}
660
657
@@ -733,7 +730,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
733
730
}
734
731
735
732
#[ inline]
736
- fn unification_table ( & mut self ) -> super :: UnificationTable < ' _ , ' tcx , RegionVidKey < ' tcx > > {
733
+ fn unification_table_mut ( & mut self ) -> super :: UnificationTable < ' _ , ' tcx , RegionVidKey < ' tcx > > {
737
734
ut:: UnificationTable :: with_log ( & mut self . storage . unification_table , self . undo_log )
738
735
}
739
736
}
0 commit comments