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