@@ -25,6 +25,7 @@ use rustc_middle::traits::ObligationCauseCode;
25
25
use rustc_middle:: ty:: { self , GenericArgs , Region , RegionVid , Ty , TyCtxt , TypeVisitor } ;
26
26
use rustc_span:: symbol:: { kw, Ident } ;
27
27
use rustc_span:: Span ;
28
+ use rustc_trait_selection:: traits;
28
29
29
30
use crate :: borrowck_errors;
30
31
use crate :: session_diagnostics:: {
@@ -672,25 +673,31 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
672
673
// fn foo(&self) where Self: 'static {}
673
674
// }
674
675
// ```
675
- let mut predicates: Vec < Span > = tcx
676
- . predicates_of ( def_id)
677
- . predicates
678
- . iter ( )
679
- . chain ( tcx. predicates_of ( parent) . predicates . iter ( ) )
680
- . filter_map ( |( pred, pred_span) | {
681
- if let Some ( ty:: ClauseKind :: TypeOutlives ( ty:: OutlivesPredicate ( pred_ty, r) ) ) =
682
- pred. kind ( ) . no_bound_vars ( )
683
- // Look for `'static` bounds
684
- && r. kind ( ) == ty:: ReStatic
685
- // We only want bounds on `Self`
686
- && self . infcx . can_eq ( self . param_env , ty, pred_ty)
687
- {
688
- Some ( * pred_span)
689
- } else {
690
- None
691
- }
692
- } )
693
- . collect ( ) ;
676
+ let mut predicates: Vec < Span > = traits:: elaborate (
677
+ tcx,
678
+ tcx. predicates_of ( def_id) . predicates . iter ( ) . map ( |( p, sp) | ( p. as_predicate ( ) , * sp) ) ,
679
+ )
680
+ . chain ( traits:: elaborate (
681
+ tcx,
682
+ tcx. predicates_of ( parent) . predicates . iter ( ) . map ( |( p, sp) | ( p. as_predicate ( ) , * sp) ) ,
683
+ ) )
684
+ . filter_map ( |( pred, pred_span) | {
685
+ if let ty:: PredicateKind :: Clause ( clause) = pred. kind ( ) . skip_binder ( )
686
+ && let ty:: ClauseKind :: TypeOutlives ( ty:: OutlivesPredicate ( pred_ty, r) ) = clause
687
+ // Look for `'static` bounds
688
+ && r. kind ( ) == ty:: ReStatic
689
+ // We only want bounds on `Self`
690
+ && ( self . infcx . can_eq ( self . param_env , ty, pred_ty)
691
+ || matches ! (
692
+ pred_ty. kind( ) ,
693
+ ty:: Param ( name) if name. name. as_str( ) == "Self" ) )
694
+ {
695
+ Some ( pred_span)
696
+ } else {
697
+ None
698
+ }
699
+ } )
700
+ . collect ( ) ;
694
701
695
702
// Look at the receiver for `&'static self`, which introduces a `'static` obligation.
696
703
// ```
0 commit comments