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