@@ -26,7 +26,7 @@ use crate::constraints::{ConstraintSccIndex, OutlivesConstraintSet};
2626use crate :: consumers:: OutlivesConstraint ;
2727use crate :: type_check:: free_region_relations:: UniversalRegionRelations ;
2828use crate :: type_check:: { Locations , MirTypeckRegionConstraints } ;
29- use crate :: universal_regions:: UniversalRegions ;
29+ use crate :: universal_regions:: { self , RegionClassification , UniversalRegions } ;
3030use crate :: { BorrowCheckRootCtxt , BorrowckInferCtxt } ;
3131
3232pub ( crate ) fn handle_opaque_type_uses < ' tcx > (
@@ -77,11 +77,7 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
7777 ' entry: for ( & key, & hidden_type) in & opaque_types {
7878 let ( key, hidden_type) =
7979 fold_regions ( tcx, infcx. resolve_vars_if_possible ( ( key, hidden_type) ) , |r, _| {
80- if let ty:: RePlaceholder ( placeholder) = r. kind ( ) {
81- constraints. get_placeholder_region ( placeholder)
82- } else {
83- ty:: Region :: new_var ( tcx, universal_regions. to_region_vid ( r) )
84- }
80+ Region :: new_var ( tcx, to_region_vid ( & constraints, universal_regions, r) )
8581 } ) ;
8682 // Check whether the arguments are fully universal.
8783 //
@@ -93,7 +89,12 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
9389 if let Some ( region) = captured_arg. as_region ( ) {
9490 let scc = constraint_sccs. scc ( region. as_var ( ) ) ;
9591 let vid = constraint_sccs. annotation ( scc) . representative ;
96- if matches ! ( definitions[ vid] . origin, NllRegionVariableOrigin :: FreeRegion ) {
92+ if matches ! ( definitions[ vid] . origin, NllRegionVariableOrigin :: FreeRegion )
93+ && !matches ! (
94+ universal_regions. region_classification( vid) ,
95+ Some ( RegionClassification :: External )
96+ )
97+ {
9798 arg_regions. push ( ( vid, definitions[ vid] . external_name . unwrap ( ) ) ) ;
9899 } else {
99100 continue ' entry;
@@ -152,7 +153,7 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
152153 infcx,
153154 span : hidden_type. span ,
154155 universal_regions,
155- outlives_constraints : & mut constraints. outlives_constraints ,
156+ constraints : & mut constraints,
156157 } ;
157158 TypeRelation :: relate ( & mut relation, hidden_type. ty , expected) . unwrap ( ) ;
158159
@@ -171,6 +172,18 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
171172 constraints
172173}
173174
175+ fn to_region_vid < ' tcx > (
176+ constraints : & MirTypeckRegionConstraints < ' tcx > ,
177+ universal_regions : & UniversalRegions < ' tcx > ,
178+ r : Region < ' tcx > ,
179+ ) -> RegionVid {
180+ if let ty:: RePlaceholder ( placeholder) = r. kind ( ) {
181+ constraints. get_placeholder_region ( placeholder) . as_var ( )
182+ } else {
183+ universal_regions. to_region_vid ( r)
184+ }
185+ }
186+
174187struct OpaqueHiddenTypeFolder < ' a , ' tcx > {
175188 infcx : & ' a BorrowckInferCtxt < ' tcx > ,
176189 arg_regions : & ' a [ ( RegionVid , Region < ' tcx > ) ] ,
@@ -334,7 +347,7 @@ struct EquateRegions<'a, 'tcx> {
334347 infcx : & ' a BorrowckInferCtxt < ' tcx > ,
335348 span : Span ,
336349 universal_regions : & ' a UniversalRegions < ' tcx > ,
337- outlives_constraints : & ' a mut OutlivesConstraintSet < ' tcx > ,
350+ constraints : & ' a mut MirTypeckRegionConstraints < ' tcx > ,
338351}
339352
340353impl < ' tcx > TypeRelation < TyCtxt < ' tcx > > for EquateRegions < ' _ , ' tcx > {
@@ -366,10 +379,10 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for EquateRegions<'_, 'tcx> {
366379 return Ok ( a) ;
367380 }
368381
369- let a_vid = self . universal_regions . to_region_vid ( a) ;
370- let b_vid = self . universal_regions . to_region_vid ( b) ;
382+ let a_vid = to_region_vid ( self . constraints , self . universal_regions , a) ;
383+ let b_vid = to_region_vid ( self . constraints , self . universal_regions , b) ;
371384 let locations = Locations :: All ( self . span ) ;
372- self . outlives_constraints . push ( OutlivesConstraint {
385+ self . constraints . outlives_constraints . push ( OutlivesConstraint {
373386 sup : a_vid,
374387 sub : b_vid,
375388 locations,
@@ -378,7 +391,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for EquateRegions<'_, 'tcx> {
378391 variance_info : ty:: VarianceDiagInfo :: None ,
379392 from_closure : false ,
380393 } ) ;
381- self . outlives_constraints . push ( OutlivesConstraint {
394+ self . constraints . outlives_constraints . push ( OutlivesConstraint {
382395 sup : b_vid,
383396 sub : a_vid,
384397 locations,
@@ -457,10 +470,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
457470 // region which cannot be mapped back to a universal.
458471 // FIXME: We could probably compute the LUB if there is one.
459472 let scc = self . constraint_sccs . scc ( vid) ;
460- let upper_bounds: Vec < _ > = self
461- . rev_scc_graph
462- . as_ref ( )
463- . unwrap ( )
473+ let rev_scc_graph =
474+ & ReverseSccGraph :: compute ( & self . constraint_sccs , self . universal_regions ( ) ) ;
475+ let upper_bounds: Vec < _ > = rev_scc_graph
464476 . upper_bounds ( scc)
465477 . filter_map ( |vid| self . definitions [ vid] . external_name )
466478 . filter ( |r| !r. is_static ( ) )
0 commit comments