@@ -620,6 +620,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
620
620
outlived_fr : RegionVid ,
621
621
) {
622
622
let tcx = self . infcx . tcx ;
623
+ debug ! ( ?code) ;
623
624
let ObligationCauseCode :: MethodCallConstraint ( ty, call_span) = code else {
624
625
return ;
625
626
} ;
@@ -634,10 +635,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
634
635
) else {
635
636
return ;
636
637
} ;
638
+ debug ! ( ?instance) ;
637
639
let def_id = instance. def_id ( ) ;
638
640
let mut parent = tcx. parent ( def_id) ;
639
- match tcx. def_kind ( parent) {
640
- hir:: def:: DefKind :: Impl { .. } => { }
641
+ debug ! ( ?def_id, ?parent) ;
642
+ let trait_preds = match tcx. def_kind ( parent) {
643
+ hir:: def:: DefKind :: Impl { .. } => & [ ] ,
641
644
hir:: def:: DefKind :: Trait => {
642
645
let Some ( ty) = args. get ( 0 ) . and_then ( |arg| arg. as_type ( ) ) else {
643
646
return ;
@@ -649,14 +652,18 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
649
652
if let [ def_id] = impls[ ..] {
650
653
// The method we have is on the trait, but for `parent` we want to analyze the
651
654
// relevant impl instead.
655
+ let preds = tcx. predicates_of ( parent) . predicates ;
652
656
parent = def_id;
657
+ preds
653
658
} else {
654
659
return ;
655
- } ;
660
+ }
656
661
}
657
662
_ => return ,
658
- }
663
+ } ;
664
+ debug ! ( ?def_id, ?parent) ;
659
665
let ty = tcx. type_of ( parent) . instantiate_identity ( ) ;
666
+ debug ! ( ?ty) ;
660
667
if self . to_error_region ( outlived_fr) != Some ( tcx. lifetimes . re_static ) {
661
668
return ;
662
669
}
@@ -675,23 +682,17 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
675
682
// ```
676
683
let mut predicates: Vec < Span > = traits:: elaborate (
677
684
tcx,
678
- tcx. predicates_of ( def_id)
679
- . predicates
680
- . iter ( )
681
- . map ( |( p, sp) | ( p. as_predicate ( ) , * sp) )
682
- . chain (
683
- tcx. predicates_of ( parent)
684
- . predicates
685
- . iter ( )
686
- . map ( |( p, sp) | ( p. as_predicate ( ) , * sp) ) ,
687
- ) ,
685
+ tcx. predicates_of ( def_id) . predicates . iter ( ) . map ( |( p, sp) | ( p. as_predicate ( ) , * sp) ) ,
688
686
)
687
+ . chain ( traits:: elaborate (
688
+ tcx,
689
+ tcx. predicates_of ( parent) . predicates . iter ( ) . map ( |( p, sp) | ( p. as_predicate ( ) , * sp) ) ,
690
+ ) )
691
+ . chain ( traits:: elaborate ( tcx, trait_preds. iter ( ) . map ( |( p, sp) | ( p. as_predicate ( ) , * sp) ) ) )
689
692
. filter_map ( |( pred, pred_span) | {
690
693
if let ty:: PredicateKind :: Clause ( clause) = pred. kind ( ) . skip_binder ( )
691
694
&& let ty:: ClauseKind :: TypeOutlives ( ty:: OutlivesPredicate ( pred_ty, r) ) = clause
692
- // Look for `'static` bounds
693
695
&& r. kind ( ) == ty:: ReStatic
694
- // We only want bounds on `Self`
695
696
&& ( self . infcx . can_eq ( self . param_env , ty, pred_ty)
696
697
|| matches ! (
697
698
pred_ty. kind( ) ,
@@ -703,6 +704,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
703
704
}
704
705
} )
705
706
. collect ( ) ;
707
+ debug ! ( ?predicates) ;
706
708
707
709
// Look at the receiver for `&'static self`, which introduces a `'static` obligation.
708
710
// ```
0 commit comments