@@ -53,7 +53,7 @@ use crate::errors::{self, ObligationCauseFailureCode, TypeErrorAdditionalDiags};
5353use crate :: infer;
5454use crate :: infer:: error_reporting:: nice_region_error:: find_anon_type:: find_anon_type;
5555use crate :: infer:: ExpectedFound ;
56- use crate :: traits:: util:: elaborate ;
56+ use crate :: traits:: util:: elaborate_predicates_of ;
5757use crate :: traits:: {
5858 IfExpressionCause , MatchExpressionArmCause , ObligationCause , ObligationCauseCode ,
5959 PredicateObligation ,
@@ -493,36 +493,26 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
493493 // Collect all the `Span`s corresponding to the predicates introducing
494494 // the `sub` lifetime that couldn't be met (sometimes `'static`) on
495495 // both the `trait` and the `impl`.
496- let spans: Vec < Span > = elaborate (
497- self . tcx ,
498- self . tcx
499- . predicates_of ( def_id)
500- . predicates
501- . iter ( )
502- . map ( |( p, sp) | ( p. as_predicate ( ) , * sp) ) ,
503- )
504- . chain ( elaborate (
505- self . tcx ,
506- self . tcx
507- . predicates_of ( generic_param_scope)
508- . predicates
509- . iter ( )
510- . map ( |( p, sp) | ( p. as_predicate ( ) , * sp) ) ,
511- ) )
512- . filter_map ( |( pred, pred_span) | {
513- if let ty:: PredicateKind :: Clause ( clause) = pred. kind ( ) . skip_binder ( )
514- && let ty:: ClauseKind :: TypeOutlives ( ty:: OutlivesPredicate (
515- _pred_ty,
516- r,
517- ) ) = clause
518- && r. kind ( ) == ty:: ReStatic
519- {
520- Some ( pred_span)
521- } else {
522- None
523- }
524- } )
525- . collect ( ) ;
496+ let spans: Vec < Span > = elaborate_predicates_of ( self . tcx , def_id)
497+ . chain ( elaborate_predicates_of (
498+ self . tcx ,
499+ generic_param_scope. into ( ) ,
500+ ) )
501+ . filter_map ( |( pred, pred_span) | {
502+ if let ty:: PredicateKind :: Clause ( clause) =
503+ pred. kind ( ) . skip_binder ( )
504+ && let ty:: ClauseKind :: TypeOutlives ( ty:: OutlivesPredicate (
505+ _pred_ty,
506+ r,
507+ ) ) = clause
508+ && r. kind ( ) == ty:: ReStatic
509+ {
510+ Some ( pred_span)
511+ } else {
512+ None
513+ }
514+ } )
515+ . collect ( ) ;
526516
527517 if !spans. is_empty ( ) {
528518 let spans_len = spans. len ( ) ;
@@ -2770,29 +2760,21 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
27702760 for ptr in poly_trait_refs {
27712761 if let Some ( def_id) = ptr. trait_ref . trait_def_id ( ) {
27722762 // Find the bounds on the trait with the lifetime that couldn't be met.
2773- let bindings: Vec < Span > = elaborate (
2774- self . tcx ,
2775- self . tcx
2776- . predicates_of ( def_id)
2777- . predicates
2778- . iter ( )
2779- . map ( |( p, sp) | ( p. as_predicate ( ) , * sp) ) ,
2780- )
2781- . filter_map ( |( pred, pred_span) | {
2782- if let ty:: PredicateKind :: Clause ( clause) =
2783- pred. kind ( ) . skip_binder ( )
2784- && let ty:: ClauseKind :: TypeOutlives ( ty:: OutlivesPredicate (
2785- _pred_ty,
2786- r,
2787- ) ) = clause
2788- && r == self . found_region
2789- {
2790- Some ( pred_span)
2791- } else {
2792- None
2793- }
2794- } )
2795- . collect ( ) ;
2763+ let bindings: Vec < Span > = elaborate_predicates_of ( self . tcx , def_id)
2764+ . filter_map ( |( pred, pred_span) | {
2765+ if let ty:: PredicateKind :: Clause ( clause) =
2766+ pred. kind ( ) . skip_binder ( )
2767+ && let ty:: ClauseKind :: TypeOutlives (
2768+ ty:: OutlivesPredicate ( _pred_ty, r) ,
2769+ ) = clause
2770+ && r == self . found_region
2771+ {
2772+ Some ( pred_span)
2773+ } else {
2774+ None
2775+ }
2776+ } )
2777+ . collect ( ) ;
27962778 if !bindings. is_empty ( ) {
27972779 self . lifetime_spans . insert ( ptr. span ) ;
27982780 self . pred_spans . extend ( bindings) ;
@@ -2803,30 +2785,23 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
28032785 // Detect when an associated item is given a lifetime restriction that the
28042786 // definition of that associated item couldn't meet.
28052787 hir:: TyKind :: Path ( hir:: QPath :: Resolved ( Some ( _) , path) ) => {
2806- self . pred_spans = elaborate (
2807- self . tcx ,
2808- self . tcx
2809- . predicates_of ( path. res . def_id ( ) )
2810- . predicates
2811- . iter ( )
2812- . map ( |( p, sp) | ( p. as_predicate ( ) , * sp) ) ,
2813- )
2814- . filter_map ( |( pred, pred_span) | {
2815- match pred. kind ( ) . skip_binder ( ) {
2816- ty:: PredicateKind :: Clause ( ty:: ClauseKind :: TypeOutlives (
2817- ty:: OutlivesPredicate (
2818- // What should I filter this with?
2819- _pred_ty,
2820- r,
2821- ) ,
2822- ) ) if r == self . found_region => Some ( pred_span) ,
2823- ty:: PredicateKind :: Clause ( ty:: ClauseKind :: RegionOutlives (
2824- ty:: OutlivesPredicate ( _, r) ,
2825- ) ) if r == self . found_region => Some ( pred_span) ,
2826- _ => None ,
2827- }
2828- } )
2829- . collect ( ) ;
2788+ self . pred_spans = elaborate_predicates_of ( self . tcx , path. res . def_id ( ) )
2789+ . filter_map ( |( pred, pred_span) | {
2790+ match pred. kind ( ) . skip_binder ( ) {
2791+ ty:: PredicateKind :: Clause ( ty:: ClauseKind :: TypeOutlives (
2792+ ty:: OutlivesPredicate (
2793+ // What should I filter this with?
2794+ _pred_ty,
2795+ r,
2796+ ) ,
2797+ ) ) if r == self . found_region => Some ( pred_span) ,
2798+ ty:: PredicateKind :: Clause ( ty:: ClauseKind :: RegionOutlives (
2799+ ty:: OutlivesPredicate ( _, r) ,
2800+ ) ) if r == self . found_region => Some ( pred_span) ,
2801+ _ => None ,
2802+ }
2803+ } )
2804+ . collect ( ) ;
28302805 }
28312806 _ => { }
28322807 }
0 commit comments