@@ -614,6 +614,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
614614 outlived_fr : RegionVid ,
615615 ) {
616616 let tcx = self . infcx . tcx ;
617+ debug ! ( ?code) ;
617618 let ObligationCauseCode :: MethodCallConstraint ( ty, call_span) = code else {
618619 return ;
619620 } ;
@@ -628,10 +629,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
628629 ) else {
629630 return ;
630631 } ;
632+ debug ! ( ?instance) ;
631633 let def_id = instance. def_id ( ) ;
632634 let mut parent = tcx. parent ( def_id) ;
633- match tcx. def_kind ( parent) {
634- hir:: def:: DefKind :: Impl { .. } => { }
635+ debug ! ( ?def_id, ?parent) ;
636+ let trait_preds = match tcx. def_kind ( parent) {
637+ hir:: def:: DefKind :: Impl { .. } => & [ ] ,
635638 hir:: def:: DefKind :: Trait => {
636639 let Some ( ty) = args. get ( 0 ) . and_then ( |arg| arg. as_type ( ) ) else {
637640 return ;
@@ -643,14 +646,18 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
643646 if let [ def_id] = impls[ ..] {
644647 // The method we have is on the trait, but for `parent` we want to analyze the
645648 // relevant impl instead.
649+ let preds = tcx. predicates_of ( parent) . predicates ;
646650 parent = def_id;
651+ preds
647652 } else {
648653 return ;
649- } ;
654+ }
650655 }
651656 _ => return ,
652- }
657+ } ;
658+ debug ! ( ?def_id, ?parent) ;
653659 let ty = tcx. type_of ( parent) . instantiate_identity ( ) ;
660+ debug ! ( ?ty) ;
654661 if self . to_error_region ( outlived_fr) != Some ( tcx. lifetimes . re_static ) {
655662 return ;
656663 }
@@ -669,23 +676,17 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
669676 // ```
670677 let mut predicates: Vec < Span > = traits:: elaborate (
671678 tcx,
672- tcx. predicates_of ( def_id)
673- . predicates
674- . iter ( )
675- . map ( |( p, sp) | ( p. as_predicate ( ) , * sp) )
676- . chain (
677- tcx. predicates_of ( parent)
678- . predicates
679- . iter ( )
680- . map ( |( p, sp) | ( p. as_predicate ( ) , * sp) ) ,
681- ) ,
679+ tcx. predicates_of ( def_id) . predicates . iter ( ) . map ( |( p, sp) | ( p. as_predicate ( ) , * sp) ) ,
682680 )
681+ . chain ( traits:: elaborate (
682+ tcx,
683+ tcx. predicates_of ( parent) . predicates . iter ( ) . map ( |( p, sp) | ( p. as_predicate ( ) , * sp) ) ,
684+ ) )
685+ . chain ( traits:: elaborate ( tcx, trait_preds. iter ( ) . map ( |( p, sp) | ( p. as_predicate ( ) , * sp) ) ) )
683686 . filter_map ( |( pred, pred_span) | {
684687 if let ty:: PredicateKind :: Clause ( clause) = pred. kind ( ) . skip_binder ( )
685688 && let ty:: ClauseKind :: TypeOutlives ( ty:: OutlivesPredicate ( pred_ty, r) ) = clause
686- // Look for `'static` bounds
687689 && r. kind ( ) == ty:: ReStatic
688- // We only want bounds on `Self`
689690 && ( self . infcx . can_eq ( self . param_env , ty, pred_ty)
690691 || matches ! (
691692 pred_ty. kind( ) ,
@@ -697,6 +698,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
697698 }
698699 } )
699700 . collect ( ) ;
701+ debug ! ( ?predicates) ;
700702
701703 // Look at the receiver for `&'static self`, which introduces a `'static` obligation.
702704 // ```
0 commit comments