@@ -71,7 +71,7 @@ use rustc_data_structures::undo_log::UndoLogs;
71
71
use rustc_hir:: def_id:: LocalDefId ;
72
72
use rustc_middle:: mir:: ConstraintCategory ;
73
73
use rustc_middle:: ty:: subst:: GenericArgKind ;
74
- use rustc_middle:: ty:: { self , Region , Ty , TyCtxt , TypeVisitable } ;
74
+ use rustc_middle:: ty:: { self , Region , SubstsRef , Ty , TyCtxt , TypeVisitable } ;
75
75
use smallvec:: smallvec;
76
76
77
77
impl < ' cx , ' tcx > InferCtxt < ' cx , ' tcx > {
@@ -352,7 +352,7 @@ where
352
352
// may not apply.
353
353
let mut approx_env_bounds =
354
354
self . verify_bound . projection_approx_declared_bounds_from_env ( projection_ty) ;
355
- debug ! ( "projection_must_outlive: approx_env_bounds={:?}" , approx_env_bounds) ;
355
+ debug ! ( ? approx_env_bounds) ;
356
356
357
357
// Remove outlives bounds that we get from the environment but
358
358
// which are also deducible from the trait. This arises (cc
@@ -392,27 +392,9 @@ where
392
392
// edges, which winds up enforcing the same condition.
393
393
let needs_infer = projection_ty. needs_infer ( ) ;
394
394
if approx_env_bounds. is_empty ( ) && trait_bounds. is_empty ( ) && needs_infer {
395
- debug ! ( "projection_must_outlive: no declared bounds" ) ;
396
-
397
- let constraint = origin. to_constraint_category ( ) ;
398
- for k in projection_ty. substs {
399
- match k. unpack ( ) {
400
- GenericArgKind :: Lifetime ( lt) => {
401
- self . delegate . push_sub_region_constraint (
402
- origin. clone ( ) ,
403
- region,
404
- lt,
405
- constraint,
406
- ) ;
407
- }
408
- GenericArgKind :: Type ( ty) => {
409
- self . type_must_outlive ( origin. clone ( ) , ty, region, constraint) ;
410
- }
411
- GenericArgKind :: Const ( _) => {
412
- // Const parameters don't impose constraints.
413
- }
414
- }
415
- }
395
+ debug ! ( "no declared bounds" ) ;
396
+
397
+ self . substs_must_outlive ( projection_ty. substs , origin, region) ;
416
398
417
399
return ;
418
400
}
@@ -442,8 +424,8 @@ where
442
424
. all ( |b| b == Some ( trait_bounds[ 0 ] ) )
443
425
{
444
426
let unique_bound = trait_bounds[ 0 ] ;
445
- debug ! ( "projection_must_outlive: unique trait bound = {:?}" , unique_bound) ;
446
- debug ! ( "projection_must_outlive: unique declared bound appears in trait ref" ) ;
427
+ debug ! ( ? unique_bound) ;
428
+ debug ! ( "unique declared bound appears in trait ref" ) ;
447
429
let category = origin. to_constraint_category ( ) ;
448
430
self . delegate . push_sub_region_constraint ( origin, region, unique_bound, category) ;
449
431
return ;
@@ -459,6 +441,33 @@ where
459
441
debug ! ( "projection_must_outlive: pushing {:?}" , verify_bound) ;
460
442
self . delegate . push_verify ( origin, generic, region, verify_bound) ;
461
443
}
444
+
445
+ fn substs_must_outlive (
446
+ & mut self ,
447
+ substs : SubstsRef < ' tcx > ,
448
+ origin : infer:: SubregionOrigin < ' tcx > ,
449
+ region : ty:: Region < ' tcx > ,
450
+ ) {
451
+ let constraint = origin. to_constraint_category ( ) ;
452
+ for k in substs {
453
+ match k. unpack ( ) {
454
+ GenericArgKind :: Lifetime ( lt) => {
455
+ self . delegate . push_sub_region_constraint (
456
+ origin. clone ( ) ,
457
+ region,
458
+ lt,
459
+ constraint,
460
+ ) ;
461
+ }
462
+ GenericArgKind :: Type ( ty) => {
463
+ self . type_must_outlive ( origin. clone ( ) , ty, region, constraint) ;
464
+ }
465
+ GenericArgKind :: Const ( _) => {
466
+ // Const parameters don't impose constraints.
467
+ }
468
+ }
469
+ }
470
+ }
462
471
}
463
472
464
473
impl < ' cx , ' tcx > TypeOutlivesDelegate < ' tcx > for & ' cx InferCtxt < ' cx , ' tcx > {
0 commit comments