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