@@ -505,19 +505,21 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
505
505
}
506
506
_ => None ,
507
507
} ;
508
- if let Some ( hir:: Node :: Item ( hir:: Item { kind, .. } ) ) = node {
509
- if let Some ( g) = kind. generics ( ) {
510
- let key = (
511
- g. tail_span_for_predicate_suggestion ( ) ,
512
- g. add_where_or_trailing_comma ( ) ,
513
- ) ;
514
- type_params
515
- . entry ( key)
516
- . or_insert_with ( FxHashSet :: default)
517
- . insert ( obligation. to_owned ( ) ) ;
518
- }
508
+ if let Some ( hir:: Node :: Item ( hir:: Item { kind, .. } ) ) = node
509
+ && let Some ( g) = kind. generics ( )
510
+ {
511
+ let key = (
512
+ g. tail_span_for_predicate_suggestion ( ) ,
513
+ g. add_where_or_trailing_comma ( ) ,
514
+ ) ;
515
+ type_params
516
+ . entry ( key)
517
+ . or_insert_with ( FxHashSet :: default)
518
+ . insert ( obligation. to_owned ( ) ) ;
519
+ return true ;
519
520
}
520
521
}
522
+ false
521
523
} ;
522
524
let mut bound_span_label = |self_ty : Ty < ' _ > , obligation : & str , quiet : & str | {
523
525
let msg = format ! (
@@ -732,19 +734,39 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
732
734
unsatisfied_bounds = true ;
733
735
}
734
736
737
+ let mut suggested_bounds = FxHashSet :: default ( ) ;
735
738
// The requirements that didn't have an `impl` span to show.
736
739
let mut bound_list = unsatisfied_predicates
737
740
. iter ( )
738
741
. filter_map ( |( pred, parent_pred, _cause) | {
742
+ let mut suggested = false ;
739
743
format_pred ( * pred) . map ( |( p, self_ty) | {
740
- collect_type_param_suggestions ( self_ty, * pred, & p) ;
744
+ if let Some ( parent) = parent_pred && suggested_bounds. contains ( parent) {
745
+ // We don't suggest `PartialEq` when we already suggest `Eq`.
746
+ } else if !suggested_bounds. contains ( pred) {
747
+ if collect_type_param_suggestions ( self_ty, * pred, & p) {
748
+ suggested = true ;
749
+ suggested_bounds. insert ( pred) ;
750
+ }
751
+ }
741
752
(
742
753
match parent_pred {
743
754
None => format ! ( "`{}`" , & p) ,
744
755
Some ( parent_pred) => match format_pred ( * parent_pred) {
745
756
None => format ! ( "`{}`" , & p) ,
746
757
Some ( ( parent_p, _) ) => {
747
- collect_type_param_suggestions ( self_ty, * parent_pred, & p) ;
758
+ if !suggested
759
+ && !suggested_bounds. contains ( pred)
760
+ && !suggested_bounds. contains ( parent_pred)
761
+ {
762
+ if collect_type_param_suggestions (
763
+ self_ty,
764
+ * parent_pred,
765
+ & p,
766
+ ) {
767
+ suggested_bounds. insert ( pred) ;
768
+ }
769
+ }
748
770
format ! ( "`{}`\n which is required by `{}`" , p, parent_p)
749
771
}
750
772
} ,
0 commit comments