@@ -53,7 +53,7 @@ use crate::errors::{self, ObligationCauseFailureCode, TypeErrorAdditionalDiags};
53
53
use crate :: infer;
54
54
use crate :: infer:: error_reporting:: nice_region_error:: find_anon_type:: find_anon_type;
55
55
use crate :: infer:: ExpectedFound ;
56
- use crate :: traits:: util:: elaborate ;
56
+ use crate :: traits:: util:: elaborate_predicates_of ;
57
57
use crate :: traits:: {
58
58
IfExpressionCause , MatchExpressionArmCause , ObligationCause , ObligationCauseCode ,
59
59
PredicateObligation ,
@@ -493,36 +493,26 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
493
493
// Collect all the `Span`s corresponding to the predicates introducing
494
494
// the `sub` lifetime that couldn't be met (sometimes `'static`) on
495
495
// 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 ( ) ;
526
516
527
517
if !spans. is_empty ( ) {
528
518
let spans_len = spans. len ( ) ;
@@ -2759,29 +2749,21 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2759
2749
for ptr in poly_trait_refs {
2760
2750
if let Some ( def_id) = ptr. trait_ref . trait_def_id ( ) {
2761
2751
// Find the bounds on the trait with the lifetime that couldn't be met.
2762
- let bindings: Vec < Span > = elaborate (
2763
- self . tcx ,
2764
- self . tcx
2765
- . predicates_of ( def_id)
2766
- . predicates
2767
- . iter ( )
2768
- . map ( |( p, sp) | ( p. as_predicate ( ) , * sp) ) ,
2769
- )
2770
- . filter_map ( |( pred, pred_span) | {
2771
- if let ty:: PredicateKind :: Clause ( clause) =
2772
- pred. kind ( ) . skip_binder ( )
2773
- && let ty:: ClauseKind :: TypeOutlives ( ty:: OutlivesPredicate (
2774
- _pred_ty,
2775
- r,
2776
- ) ) = clause
2777
- && r == self . found_region
2778
- {
2779
- Some ( pred_span)
2780
- } else {
2781
- None
2782
- }
2783
- } )
2784
- . collect ( ) ;
2752
+ let bindings: Vec < Span > = elaborate_predicates_of ( self . tcx , def_id)
2753
+ . filter_map ( |( pred, pred_span) | {
2754
+ if let ty:: PredicateKind :: Clause ( clause) =
2755
+ pred. kind ( ) . skip_binder ( )
2756
+ && let ty:: ClauseKind :: TypeOutlives (
2757
+ ty:: OutlivesPredicate ( _pred_ty, r) ,
2758
+ ) = clause
2759
+ && r == self . found_region
2760
+ {
2761
+ Some ( pred_span)
2762
+ } else {
2763
+ None
2764
+ }
2765
+ } )
2766
+ . collect ( ) ;
2785
2767
if !bindings. is_empty ( ) {
2786
2768
self . lifetime_spans . insert ( ptr. span ) ;
2787
2769
self . pred_spans . extend ( bindings) ;
@@ -2792,30 +2774,23 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
2792
2774
// Detect when an associated item is given a lifetime restriction that the
2793
2775
// definition of that associated item couldn't meet.
2794
2776
hir:: TyKind :: Path ( hir:: QPath :: Resolved ( Some ( _) , path) ) => {
2795
- self . pred_spans = elaborate (
2796
- self . tcx ,
2797
- self . tcx
2798
- . predicates_of ( path. res . def_id ( ) )
2799
- . predicates
2800
- . iter ( )
2801
- . map ( |( p, sp) | ( p. as_predicate ( ) , * sp) ) ,
2802
- )
2803
- . filter_map ( |( pred, pred_span) | {
2804
- match pred. kind ( ) . skip_binder ( ) {
2805
- ty:: PredicateKind :: Clause ( ty:: ClauseKind :: TypeOutlives (
2806
- ty:: OutlivesPredicate (
2807
- // What should I filter this with?
2808
- _pred_ty,
2809
- r,
2810
- ) ,
2811
- ) ) if r == self . found_region => Some ( pred_span) ,
2812
- ty:: PredicateKind :: Clause ( ty:: ClauseKind :: RegionOutlives (
2813
- ty:: OutlivesPredicate ( _, r) ,
2814
- ) ) if r == self . found_region => Some ( pred_span) ,
2815
- _ => None ,
2816
- }
2817
- } )
2818
- . collect ( ) ;
2777
+ self . pred_spans = elaborate_predicates_of ( self . tcx , path. res . def_id ( ) )
2778
+ . filter_map ( |( pred, pred_span) | {
2779
+ match pred. kind ( ) . skip_binder ( ) {
2780
+ ty:: PredicateKind :: Clause ( ty:: ClauseKind :: TypeOutlives (
2781
+ ty:: OutlivesPredicate (
2782
+ // What should I filter this with?
2783
+ _pred_ty,
2784
+ r,
2785
+ ) ,
2786
+ ) ) if r == self . found_region => Some ( pred_span) ,
2787
+ ty:: PredicateKind :: Clause ( ty:: ClauseKind :: RegionOutlives (
2788
+ ty:: OutlivesPredicate ( _, r) ,
2789
+ ) ) if r == self . found_region => Some ( pred_span) ,
2790
+ _ => None ,
2791
+ }
2792
+ } )
2793
+ . collect ( ) ;
2819
2794
}
2820
2795
_ => { }
2821
2796
}
0 commit comments