11
11
use super :: universal_regions:: UniversalRegions ;
12
12
use borrow_check:: nll:: region_infer:: values:: ToElementIndex ;
13
13
use rustc:: hir:: def_id:: DefId ;
14
+ use rustc:: infer:: canonical:: QueryRegionConstraint ;
14
15
use rustc:: infer:: error_reporting:: nice_region_error:: NiceRegionError ;
15
16
use rustc:: infer:: region_constraints:: { GenericKind , VarInfos } ;
16
17
use rustc:: infer:: InferCtxt ;
17
18
use rustc:: infer:: NLLRegionVariableOrigin ;
18
- use rustc:: infer:: RegionObligation ;
19
19
use rustc:: infer:: RegionVariableOrigin ;
20
- use rustc:: infer:: SubregionOrigin ;
21
20
use rustc:: mir:: {
22
21
ClosureOutlivesRequirement , ClosureOutlivesSubject , ClosureRegionRequirements , Local , Location ,
23
22
Mir ,
24
23
} ;
25
- use rustc:: traits:: ObligationCause ;
26
- use rustc:: ty:: { self , RegionVid , Ty , TypeFoldable } ;
24
+ use rustc:: ty:: { self , RegionVid , Ty , TyCtxt , TypeFoldable } ;
27
25
use rustc:: util:: common:: { self , ErrorReported } ;
28
26
use rustc_data_structures:: bitvec:: BitVector ;
29
27
use rustc_data_structures:: indexed_vec:: { Idx , IndexVec } ;
30
28
use std:: fmt;
31
29
use std:: rc:: Rc ;
32
- use syntax:: ast;
33
30
use syntax_pos:: Span ;
34
31
35
32
mod annotation;
@@ -1162,16 +1159,15 @@ impl fmt::Debug for OutlivesConstraint {
1162
1159
pub trait ClosureRegionRequirementsExt < ' gcx , ' tcx > {
1163
1160
fn apply_requirements (
1164
1161
& self ,
1165
- infcx : & InferCtxt < ' _ , ' gcx , ' tcx > ,
1166
- body_id : ast:: NodeId ,
1162
+ tcx : TyCtxt < ' _ , ' gcx , ' tcx > ,
1167
1163
location : Location ,
1168
1164
closure_def_id : DefId ,
1169
1165
closure_substs : ty:: ClosureSubsts < ' tcx > ,
1170
- ) ;
1166
+ ) -> Vec < QueryRegionConstraint < ' tcx > > ;
1171
1167
1172
1168
fn subst_closure_mapping < T > (
1173
1169
& self ,
1174
- infcx : & InferCtxt < ' _ , ' gcx , ' tcx > ,
1170
+ tcx : TyCtxt < ' _ , ' gcx , ' tcx > ,
1175
1171
closure_mapping : & IndexVec < RegionVid , ty:: Region < ' tcx > > ,
1176
1172
value : & T ,
1177
1173
) -> T
@@ -1194,14 +1190,11 @@ impl<'gcx, 'tcx> ClosureRegionRequirementsExt<'gcx, 'tcx> for ClosureRegionRequi
1194
1190
/// requirements.
1195
1191
fn apply_requirements (
1196
1192
& self ,
1197
- infcx : & InferCtxt < ' _ , ' gcx , ' tcx > ,
1198
- body_id : ast:: NodeId ,
1193
+ tcx : TyCtxt < ' _ , ' gcx , ' tcx > ,
1199
1194
location : Location ,
1200
1195
closure_def_id : DefId ,
1201
1196
closure_substs : ty:: ClosureSubsts < ' tcx > ,
1202
- ) {
1203
- let tcx = infcx. tcx ;
1204
-
1197
+ ) -> Vec < QueryRegionConstraint < ' tcx > > {
1205
1198
debug ! (
1206
1199
"apply_requirements(location={:?}, closure_def_id={:?}, closure_substs={:?})" ,
1207
1200
location, closure_def_id, closure_substs
@@ -1215,59 +1208,52 @@ impl<'gcx, 'tcx> ClosureRegionRequirementsExt<'gcx, 'tcx> for ClosureRegionRequi
1215
1208
// into a vector. These are the regions that we will be
1216
1209
// relating to one another.
1217
1210
let closure_mapping =
1218
- & UniversalRegions :: closure_mapping ( infcx , user_closure_ty, self . num_external_vids ) ;
1211
+ & UniversalRegions :: closure_mapping ( tcx , user_closure_ty, self . num_external_vids ) ;
1219
1212
debug ! ( "apply_requirements: closure_mapping={:?}" , closure_mapping) ;
1220
1213
1221
1214
// Create the predicates.
1222
- for outlives_requirement in & self . outlives_requirements {
1223
- let outlived_region = closure_mapping[ outlives_requirement. outlived_free_region ] ;
1224
-
1225
- // FIXME, this origin is not entirely suitable.
1226
- let origin = SubregionOrigin :: CallRcvr ( outlives_requirement. blame_span ) ;
1227
-
1228
- match outlives_requirement. subject {
1229
- ClosureOutlivesSubject :: Region ( region) => {
1230
- let region = closure_mapping[ region] ;
1231
- debug ! (
1232
- "apply_requirements: region={:?} \
1233
- outlived_region={:?} \
1234
- outlives_requirement={:?}",
1235
- region, outlived_region, outlives_requirement,
1236
- ) ;
1237
- infcx. sub_regions ( origin, outlived_region, region) ;
1238
- }
1215
+ self . outlives_requirements
1216
+ . iter ( )
1217
+ . map ( |outlives_requirement| {
1218
+ let outlived_region = closure_mapping[ outlives_requirement. outlived_free_region ] ;
1219
+
1220
+ match outlives_requirement. subject {
1221
+ ClosureOutlivesSubject :: Region ( region) => {
1222
+ let region = closure_mapping[ region] ;
1223
+ debug ! (
1224
+ "apply_requirements: region={:?} \
1225
+ outlived_region={:?} \
1226
+ outlives_requirement={:?}",
1227
+ region, outlived_region, outlives_requirement,
1228
+ ) ;
1229
+ ty:: Binder :: dummy ( ty:: OutlivesPredicate ( region. into ( ) , outlived_region) )
1230
+ }
1239
1231
1240
- ClosureOutlivesSubject :: Ty ( ty) => {
1241
- let ty = self . subst_closure_mapping ( infcx, closure_mapping, & ty) ;
1242
- debug ! (
1243
- "apply_requirements: ty={:?} \
1244
- outlived_region={:?} \
1245
- outlives_requirement={:?}",
1246
- ty, outlived_region, outlives_requirement,
1247
- ) ;
1248
- infcx. register_region_obligation (
1249
- body_id,
1250
- RegionObligation {
1251
- sup_type : ty,
1252
- sub_region : outlived_region,
1253
- cause : ObligationCause :: misc ( outlives_requirement. blame_span , body_id) ,
1254
- } ,
1255
- ) ;
1232
+ ClosureOutlivesSubject :: Ty ( ty) => {
1233
+ let ty = self . subst_closure_mapping ( tcx, closure_mapping, & ty) ;
1234
+ debug ! (
1235
+ "apply_requirements: ty={:?} \
1236
+ outlived_region={:?} \
1237
+ outlives_requirement={:?}",
1238
+ ty, outlived_region, outlives_requirement,
1239
+ ) ;
1240
+ ty:: Binder :: dummy ( ty:: OutlivesPredicate ( ty. into ( ) , outlived_region) )
1241
+ }
1256
1242
}
1257
- }
1258
- }
1243
+ } )
1244
+ . collect ( )
1259
1245
}
1260
1246
1261
1247
fn subst_closure_mapping < T > (
1262
1248
& self ,
1263
- infcx : & InferCtxt < ' _ , ' gcx , ' tcx > ,
1249
+ tcx : TyCtxt < ' _ , ' gcx , ' tcx > ,
1264
1250
closure_mapping : & IndexVec < RegionVid , ty:: Region < ' tcx > > ,
1265
1251
value : & T ,
1266
1252
) -> T
1267
1253
where
1268
1254
T : TypeFoldable < ' tcx > ,
1269
1255
{
1270
- infcx . tcx . fold_regions ( value, & mut false , |r, _depth| {
1256
+ tcx. fold_regions ( value, & mut false , |r, _depth| {
1271
1257
if let ty:: ReClosureBound ( vid) = r {
1272
1258
closure_mapping[ * vid]
1273
1259
} else {
0 commit comments