@@ -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:: {
@@ -675,25 +676,31 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
675
676
// fn foo(&self) where Self: 'static {}
676
677
// }
677
678
// ```
678
- let mut predicates: Vec < Span > = tcx
679
- . predicates_of ( def_id)
680
- . predicates
681
- . iter ( )
682
- . chain ( tcx. predicates_of ( parent) . predicates . iter ( ) )
683
- . filter_map ( |( pred, pred_span) | {
684
- if let Some ( ty:: ClauseKind :: TypeOutlives ( ty:: OutlivesPredicate ( pred_ty, r) ) ) =
685
- pred. kind ( ) . no_bound_vars ( )
686
- // Look for `'static` bounds
687
- && r. kind ( ) == ty:: ReStatic
688
- // We only want bounds on `Self`
689
- && self . infcx . can_eq ( self . param_env , ty, pred_ty)
690
- {
691
- Some ( * pred_span)
692
- } else {
693
- None
694
- }
695
- } )
696
- . collect ( ) ;
679
+ let mut predicates: Vec < Span > = traits:: elaborate (
680
+ tcx,
681
+ tcx. predicates_of ( def_id) . predicates . iter ( ) . map ( |( p, sp) | ( p. as_predicate ( ) , * sp) ) ,
682
+ )
683
+ . chain ( traits:: elaborate (
684
+ tcx,
685
+ tcx. predicates_of ( parent) . predicates . iter ( ) . map ( |( p, sp) | ( p. as_predicate ( ) , * sp) ) ,
686
+ ) )
687
+ . filter_map ( |( pred, pred_span) | {
688
+ if let ty:: PredicateKind :: Clause ( clause) = pred. kind ( ) . skip_binder ( )
689
+ && let ty:: ClauseKind :: TypeOutlives ( ty:: OutlivesPredicate ( pred_ty, r) ) = clause
690
+ // Look for `'static` bounds
691
+ && r. kind ( ) == ty:: ReStatic
692
+ // We only want bounds on `Self`
693
+ && ( self . infcx . can_eq ( self . param_env , ty, pred_ty)
694
+ || matches ! (
695
+ pred_ty. kind( ) ,
696
+ ty:: Param ( name) if name. name. as_str( ) == "Self" ) )
697
+ {
698
+ Some ( pred_span)
699
+ } else {
700
+ None
701
+ }
702
+ } )
703
+ . collect ( ) ;
697
704
698
705
// Look at the receiver for `&'static self`, which introduces a `'static` obligation.
699
706
// ```
0 commit comments