@@ -26,7 +26,7 @@ use crate::constraints::{ConstraintSccIndex, OutlivesConstraintSet};
26
26
use crate :: consumers:: OutlivesConstraint ;
27
27
use crate :: type_check:: free_region_relations:: UniversalRegionRelations ;
28
28
use crate :: type_check:: { Locations , MirTypeckRegionConstraints } ;
29
- use crate :: universal_regions:: UniversalRegions ;
29
+ use crate :: universal_regions:: { self , RegionClassification , UniversalRegions } ;
30
30
use crate :: { BorrowCheckRootCtxt , BorrowckInferCtxt } ;
31
31
32
32
pub ( crate ) fn handle_opaque_type_uses < ' tcx > (
@@ -77,11 +77,7 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
77
77
' entry: for ( & key, & hidden_type) in & opaque_types {
78
78
let ( key, hidden_type) =
79
79
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) )
85
81
} ) ;
86
82
// Check whether the arguments are fully universal.
87
83
//
@@ -93,7 +89,12 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
93
89
if let Some ( region) = captured_arg. as_region ( ) {
94
90
let scc = constraint_sccs. scc ( region. as_var ( ) ) ;
95
91
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
+ {
97
98
arg_regions. push ( ( vid, definitions[ vid] . external_name . unwrap ( ) ) ) ;
98
99
} else {
99
100
continue ' entry;
@@ -152,7 +153,7 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
152
153
infcx,
153
154
span : hidden_type. span ,
154
155
universal_regions,
155
- outlives_constraints : & mut constraints. outlives_constraints ,
156
+ constraints : & mut constraints,
156
157
} ;
157
158
TypeRelation :: relate ( & mut relation, hidden_type. ty , expected) . unwrap ( ) ;
158
159
@@ -171,6 +172,18 @@ pub(crate) fn handle_opaque_type_uses<'tcx>(
171
172
constraints
172
173
}
173
174
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
+
174
187
struct OpaqueHiddenTypeFolder < ' a , ' tcx > {
175
188
infcx : & ' a BorrowckInferCtxt < ' tcx > ,
176
189
arg_regions : & ' a [ ( RegionVid , Region < ' tcx > ) ] ,
@@ -334,7 +347,7 @@ struct EquateRegions<'a, 'tcx> {
334
347
infcx : & ' a BorrowckInferCtxt < ' tcx > ,
335
348
span : Span ,
336
349
universal_regions : & ' a UniversalRegions < ' tcx > ,
337
- outlives_constraints : & ' a mut OutlivesConstraintSet < ' tcx > ,
350
+ constraints : & ' a mut MirTypeckRegionConstraints < ' tcx > ,
338
351
}
339
352
340
353
impl < ' tcx > TypeRelation < TyCtxt < ' tcx > > for EquateRegions < ' _ , ' tcx > {
@@ -366,10 +379,10 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for EquateRegions<'_, 'tcx> {
366
379
return Ok ( a) ;
367
380
}
368
381
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) ;
371
384
let locations = Locations :: All ( self . span ) ;
372
- self . outlives_constraints . push ( OutlivesConstraint {
385
+ self . constraints . outlives_constraints . push ( OutlivesConstraint {
373
386
sup : a_vid,
374
387
sub : b_vid,
375
388
locations,
@@ -378,7 +391,7 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for EquateRegions<'_, 'tcx> {
378
391
variance_info : ty:: VarianceDiagInfo :: None ,
379
392
from_closure : false ,
380
393
} ) ;
381
- self . outlives_constraints . push ( OutlivesConstraint {
394
+ self . constraints . outlives_constraints . push ( OutlivesConstraint {
382
395
sup : b_vid,
383
396
sub : a_vid,
384
397
locations,
@@ -457,10 +470,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
457
470
// region which cannot be mapped back to a universal.
458
471
// FIXME: We could probably compute the LUB if there is one.
459
472
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
464
476
. upper_bounds ( scc)
465
477
. filter_map ( |vid| self . definitions [ vid] . external_name )
466
478
. filter ( |r| !r. is_static ( ) )
0 commit comments