@@ -71,7 +71,7 @@ use rustc_data_structures::undo_log::UndoLogs;
7171use rustc_hir:: def_id:: LocalDefId ;
7272use rustc_middle:: mir:: ConstraintCategory ;
7373use 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 } ;
7575use smallvec:: smallvec;
7676
7777impl < ' cx , ' tcx > InferCtxt < ' cx , ' tcx > {
@@ -352,7 +352,7 @@ where
352352 // may not apply.
353353 let mut approx_env_bounds =
354354 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) ;
356356
357357 // Remove outlives bounds that we get from the environment but
358358 // which are also deducible from the trait. This arises (cc
@@ -392,27 +392,9 @@ where
392392 // edges, which winds up enforcing the same condition.
393393 let needs_infer = projection_ty. needs_infer ( ) ;
394394 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) ;
416398
417399 return ;
418400 }
@@ -442,8 +424,8 @@ where
442424 . all ( |b| b == Some ( trait_bounds[ 0 ] ) )
443425 {
444426 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" ) ;
447429 let category = origin. to_constraint_category ( ) ;
448430 self . delegate . push_sub_region_constraint ( origin, region, unique_bound, category) ;
449431 return ;
@@ -459,6 +441,33 @@ where
459441 debug ! ( "projection_must_outlive: pushing {:?}" , verify_bound) ;
460442 self . delegate . push_verify ( origin, generic, region, verify_bound) ;
461443 }
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+ }
462471}
463472
464473impl < ' cx , ' tcx > TypeOutlivesDelegate < ' tcx > for & ' cx InferCtxt < ' cx , ' tcx > {
0 commit comments