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