@@ -980,6 +980,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
980980 trait_ref,
981981 obligation. cause . body_id ,
982982 & mut err,
983+ true ,
983984 ) {
984985 // This is *almost* equivalent to
985986 // `obligation.cause.code().peel_derives()`, but it gives us the
@@ -1015,6 +1016,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
10151016 trait_ref,
10161017 obligation. cause . body_id ,
10171018 & mut err,
1019+ true ,
10181020 ) ;
10191021 }
10201022 }
@@ -1432,6 +1434,7 @@ trait InferCtxtPrivExt<'tcx> {
14321434 trait_ref : ty:: PolyTraitRef < ' tcx > ,
14331435 body_id : hir:: HirId ,
14341436 err : & mut Diagnostic ,
1437+ other : bool ,
14351438 ) -> bool ;
14361439
14371440 /// Gets the parent trait chain start
@@ -1887,7 +1890,9 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
18871890 trait_ref : ty:: PolyTraitRef < ' tcx > ,
18881891 body_id : hir:: HirId ,
18891892 err : & mut Diagnostic ,
1893+ other : bool ,
18901894 ) -> bool {
1895+ let other = if other { "other " } else { "" } ;
18911896 let report = |mut candidates : Vec < TraitRef < ' tcx > > , err : & mut Diagnostic | {
18921897 candidates. sort ( ) ;
18931898 candidates. dedup ( ) ;
@@ -1938,7 +1943,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
19381943 candidates. dedup ( ) ;
19391944 let end = if candidates. len ( ) <= 9 { candidates. len ( ) } else { 8 } ;
19401945 err. help ( & format ! (
1941- "the following other types implement trait `{}`:{}{}" ,
1946+ "the following { other} types implement trait `{}`:{}{}" ,
19421947 trait_ref. print_only_trait_path( ) ,
19431948 candidates[ ..end] . join( "" ) ,
19441949 if len > 9 { format!( "\n and {} others" , len - 8 ) } else { String :: new( ) }
@@ -2179,14 +2184,26 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
21792184 trait_ref. skip_binder ( ) . substs . types ( ) . any ( |t| !t. is_ty_infer ( ) ) ;
21802185 // It doesn't make sense to talk about applicable impls if there are more
21812186 // than a handful of them.
2182- if impls. len ( ) > 1 && impls. len ( ) < 5 && has_non_region_infer {
2187+ if impls. len ( ) > 1 && impls. len ( ) < 10 && has_non_region_infer {
21832188 self . annotate_source_of_ambiguity ( & mut err, & impls, predicate) ;
21842189 } else {
21852190 if self . tainted_by_errors ( ) . is_some ( ) {
21862191 err. cancel ( ) ;
21872192 return ;
21882193 }
21892194 err. note ( & format ! ( "cannot satisfy `{}`" , predicate) ) ;
2195+ let impl_candidates = self . find_similar_impl_candidates (
2196+ predicate. to_opt_poly_trait_pred ( ) . unwrap ( ) ,
2197+ ) ;
2198+ if impl_candidates. len ( ) < 10 {
2199+ self . report_similar_impl_candidates (
2200+ impl_candidates,
2201+ trait_ref,
2202+ body_id. map ( |id| id. hir_id ) . unwrap_or ( obligation. cause . body_id ) ,
2203+ & mut err,
2204+ false ,
2205+ ) ;
2206+ }
21902207 }
21912208 }
21922209 _ => {
0 commit comments