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