@@ -614,6 +614,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
614
614
outlived_fr : RegionVid ,
615
615
) {
616
616
let tcx = self . infcx . tcx ;
617
+ debug ! ( ?code) ;
617
618
let ObligationCauseCode :: MethodCallConstraint ( ty, call_span) = code else {
618
619
return ;
619
620
} ;
@@ -628,10 +629,12 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
628
629
) else {
629
630
return ;
630
631
} ;
632
+ debug ! ( ?instance) ;
631
633
let def_id = instance. def_id ( ) ;
632
634
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 { .. } => & [ ] ,
635
638
hir:: def:: DefKind :: Trait => {
636
639
let Some ( ty) = args. get ( 0 ) . and_then ( |arg| arg. as_type ( ) ) else {
637
640
return ;
@@ -643,14 +646,18 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
643
646
if let [ def_id] = impls[ ..] {
644
647
// The method we have is on the trait, but for `parent` we want to analyze the
645
648
// relevant impl instead.
649
+ let preds = tcx. predicates_of ( parent) . predicates ;
646
650
parent = def_id;
651
+ preds
647
652
} else {
648
653
return ;
649
- } ;
654
+ }
650
655
}
651
656
_ => return ,
652
- }
657
+ } ;
658
+ debug ! ( ?def_id, ?parent) ;
653
659
let ty = tcx. type_of ( parent) . instantiate_identity ( ) ;
660
+ debug ! ( ?ty) ;
654
661
if self . to_error_region ( outlived_fr) != Some ( tcx. lifetimes . re_static ) {
655
662
return ;
656
663
}
@@ -669,23 +676,17 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
669
676
// ```
670
677
let mut predicates: Vec < Span > = traits:: elaborate (
671
678
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) ) ,
682
680
)
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) ) ) )
683
686
. filter_map ( |( pred, pred_span) | {
684
687
if let ty:: PredicateKind :: Clause ( clause) = pred. kind ( ) . skip_binder ( )
685
688
&& let ty:: ClauseKind :: TypeOutlives ( ty:: OutlivesPredicate ( pred_ty, r) ) = clause
686
- // Look for `'static` bounds
687
689
&& r. kind ( ) == ty:: ReStatic
688
- // We only want bounds on `Self`
689
690
&& ( self . infcx . can_eq ( self . param_env , ty, pred_ty)
690
691
|| matches ! (
691
692
pred_ty. kind( ) ,
@@ -697,6 +698,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
697
698
}
698
699
} )
699
700
. collect ( ) ;
701
+ debug ! ( ?predicates) ;
700
702
701
703
// Look at the receiver for `&'static self`, which introduces a `'static` obligation.
702
704
// ```
0 commit comments