@@ -284,18 +284,40 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
284
284
debug ! ( "constrain_opaque_type: def_id={:?}" , def_id) ;
285
285
debug ! ( "constrain_opaque_type: opaque_defn={:#?}" , opaque_defn) ;
286
286
287
+ let tcx = self . tcx ;
288
+
287
289
let concrete_ty = self . resolve_type_vars_if_possible ( & opaque_defn. concrete_ty ) ;
288
290
289
291
debug ! ( "constrain_opaque_type: concrete_ty={:?}" , concrete_ty) ;
290
292
291
- let abstract_type_generics = self . tcx . generics_of ( def_id) ;
293
+ let abstract_type_generics = tcx. generics_of ( def_id) ;
292
294
293
- let span = self . tcx . def_span ( def_id) ;
295
+ let span = tcx. def_span ( def_id) ;
294
296
295
- // If there are required region bounds, we can just skip
296
- // ahead. There will already be a registered region
297
- // obligation related `concrete_ty` to those regions.
297
+ // If there are required region bounds, we can use them.
298
298
if opaque_defn. has_required_region_bounds {
299
+ let predicates_of = tcx. predicates_of ( def_id) ;
300
+ debug ! (
301
+ "constrain_opaque_type: predicates: {:#?}" ,
302
+ predicates_of,
303
+ ) ;
304
+ let bounds = predicates_of. instantiate ( tcx, opaque_defn. substs ) ;
305
+ debug ! ( "constrain_opaque_type: bounds={:#?}" , bounds) ;
306
+ let opaque_type = tcx. mk_opaque ( def_id, opaque_defn. substs ) ;
307
+
308
+ let required_region_bounds = tcx. required_region_bounds (
309
+ opaque_type,
310
+ bounds. predicates . clone ( ) ,
311
+ ) ;
312
+ debug_assert ! ( !required_region_bounds. is_empty( ) ) ;
313
+
314
+ for region in required_region_bounds {
315
+ concrete_ty. visit_with ( & mut OpaqueTypeOutlivesVisitor {
316
+ infcx : self ,
317
+ least_region : region,
318
+ span,
319
+ } ) ;
320
+ }
299
321
return ;
300
322
}
301
323
@@ -371,7 +393,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
371
393
}
372
394
}
373
395
374
- let least_region = least_region. unwrap_or ( self . tcx . lifetimes . re_static ) ;
396
+ let least_region = least_region. unwrap_or ( tcx. lifetimes . re_static ) ;
375
397
debug ! ( "constrain_opaque_types: least_region={:?}" , least_region) ;
376
398
377
399
concrete_ty. visit_with ( & mut OpaqueTypeOutlivesVisitor {
0 commit comments