@@ -388,22 +388,38 @@ where
388
388
// rule might not apply (but another rule might). For now, we err
389
389
// on the side of adding too few edges into the graph.
390
390
391
+ // Compute the bounds we can derive from the trait definition.
392
+ // These are guaranteed to apply, no matter the inference
393
+ // results.
394
+ let trait_bounds: Vec < _ > = self . verify_bound
395
+ . projection_declared_bounds_from_trait ( projection_ty)
396
+ . collect ( ) ;
397
+
391
398
// Compute the bounds we can derive from the environment. This
392
399
// is an "approximate" match -- in some cases, these bounds
393
400
// may not apply.
394
- let approx_env_bounds = self . verify_bound
401
+ let mut approx_env_bounds = self . verify_bound
395
402
. projection_approx_declared_bounds_from_env ( projection_ty) ;
396
403
debug ! (
397
404
"projection_must_outlive: approx_env_bounds={:?}" ,
398
405
approx_env_bounds
399
406
) ;
400
407
401
- // Compute the bounds we can derive from the trait definition.
402
- // These are guaranteed to apply, no matter the inference
403
- // results.
404
- let trait_bounds: Vec < _ > = self . verify_bound
405
- . projection_declared_bounds_from_trait ( projection_ty)
406
- . collect ( ) ;
408
+ // Remove outlives bounds that we get from the environment but
409
+ // which are also deducable from the trait. This arises (cc
410
+ // #55756) in cases where you have e.g. `<T as Foo<'a>>::Item:
411
+ // 'a` in the environment but `trait Foo<'b> { type Item: 'b
412
+ // }` in the trait definition.
413
+ approx_env_bounds. retain ( |bound| {
414
+ match bound. 0 . sty {
415
+ ty:: Projection ( projection_ty) => {
416
+ self . verify_bound . projection_declared_bounds_from_trait ( projection_ty)
417
+ . all ( |r| r != bound. 1 )
418
+ }
419
+
420
+ _ => panic ! ( "expected only projection types from env, not {:?}" , bound. 0 ) ,
421
+ }
422
+ } ) ;
407
423
408
424
// If declared bounds list is empty, the only applicable rule is
409
425
// OutlivesProjectionComponent. If there are inference variables,
0 commit comments