@@ -9,7 +9,7 @@ use std::path::PathBuf;
99
1010use hir:: Expr ;
1111use rustc_ast:: ast:: Mutability ;
12- use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet } ;
12+ use rustc_data_structures:: fx:: { FxHashSet , FxIndexMap , FxIndexSet } ;
1313use rustc_data_structures:: sorted_map:: SortedMap ;
1414use rustc_data_structures:: unord:: UnordSet ;
1515use rustc_errors:: codes:: * ;
@@ -2988,40 +2988,46 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
29882988 let foreign_def_ids = foreign_preds
29892989 . iter ( )
29902990 . filter_map ( |pred| match pred. self_ty ( ) . kind ( ) {
2991- ty:: Adt ( def, _) => Some ( def. did ( ) ) ,
2991+ ty:: Adt ( def, _) => Some ( ( pred , def. did ( ) ) ) ,
29922992 _ => None ,
29932993 } )
2994- . collect :: < FxIndexSet < _ > > ( ) ;
2994+ . collect :: < Vec < _ > > ( ) ;
29952995 let mut foreign_spans: MultiSpan = foreign_def_ids
29962996 . iter ( )
2997- . filter_map ( |def_id| {
2997+ . filter_map ( |( _ , def_id) | {
29982998 let span = self . tcx . def_span ( * def_id) ;
2999- if span. is_dummy ( ) { None } else { Some ( span) }
2999+ ( ! span. is_dummy ( ) ) . then_some ( span)
30003000 } )
30013001 . collect :: < Vec < _ > > ( )
30023002 . into ( ) ;
3003- for pred in & foreign_preds {
3004- if let ty:: Adt ( def, _) = pred. self_ty ( ) . kind ( ) {
3003+
3004+ let unique_traits =
3005+ foreign_preds. iter ( ) . map ( |pred| pred. def_id ( ) ) . collect :: < FxHashSet < _ > > ( ) . len ( ) ;
3006+
3007+ if foreign_def_ids. len ( ) > 1 {
3008+ for ( pred, def_id) in foreign_def_ids {
30053009 foreign_spans. push_span_label (
3006- self . tcx . def_span ( def. did ( ) ) ,
3007- format ! ( "not implement `{}`" , pred. trait_ref. print_trait_sugared( ) ) ,
3010+ self . tcx . def_span ( def_id) ,
3011+ format ! (
3012+ "`{}` does not implement `{}`" ,
3013+ pred. self_ty( ) ,
3014+ pred. trait_ref. print_trait_sugared( )
3015+ ) ,
30083016 ) ;
30093017 }
30103018 }
3019+
30113020 if foreign_spans. primary_span ( ) . is_some ( ) {
30123021 let msg = if let [ foreign_pred] = foreign_preds. as_slice ( ) {
30133022 format ! (
3014- "the foreign item type `{}` doesn't implement `{}`" ,
3023+ "`{}`, which is defined in another crate, doesn't implement `{}`" ,
30153024 foreign_pred. self_ty( ) ,
30163025 foreign_pred. trait_ref. print_trait_sugared( )
30173026 )
30183027 } else {
30193028 format ! (
3020- "the foreign item type{} {} implement required trait{} for this \
3021- operation to be valid",
3022- pluralize!( foreign_def_ids. len( ) ) ,
3023- if foreign_def_ids. len( ) > 1 { "don't" } else { "doesn't" } ,
3024- pluralize!( foreign_preds. len( ) ) ,
3029+ "these types, defined in other crates, do not implement the required trait{}" ,
3030+ pluralize!( unique_traits) ,
30253031 )
30263032 } ;
30273033 err. span_note ( foreign_spans, msg) ;
0 commit comments