@@ -450,12 +450,27 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
450
450
{
451
451
"consider using `()`, or a `Result`" . to_owned ( )
452
452
} else {
453
- format ! (
454
- "{}the trait `{}` is not implemented for `{}`" ,
455
- pre_message,
456
- trait_predicate. print_modifiers_and_trait_path( ) ,
457
- trait_ref. skip_binder( ) . self_ty( ) ,
458
- )
453
+ let ty_desc = match trait_ref. skip_binder ( ) . self_ty ( ) . kind ( ) {
454
+ ty:: FnDef ( _, _) => Some ( "fn item" ) ,
455
+ ty:: Closure ( _, _) => Some ( "closure" ) ,
456
+ _ => None ,
457
+ } ;
458
+
459
+ match ty_desc {
460
+ Some ( desc) => format ! (
461
+ "{}the trait `{}` is not implemented for {} `{}`" ,
462
+ pre_message,
463
+ trait_predicate. print_modifiers_and_trait_path( ) ,
464
+ desc,
465
+ trait_ref. skip_binder( ) . self_ty( ) ,
466
+ ) ,
467
+ None => format ! (
468
+ "{}the trait `{}` is not implemented for `{}`" ,
469
+ pre_message,
470
+ trait_predicate. print_modifiers_and_trait_path( ) ,
471
+ trait_ref. skip_binder( ) . self_ty( ) ,
472
+ ) ,
473
+ }
459
474
} ;
460
475
461
476
if self . suggest_add_reference_to_arg (
@@ -1805,13 +1820,21 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
1805
1820
return false ;
1806
1821
}
1807
1822
if candidates. len ( ) == 1 {
1823
+ let ty_desc = match candidates[ 0 ] . self_ty ( ) . kind ( ) {
1824
+ ty:: FnPtr ( _) => Some ( "fn pointer" ) ,
1825
+ _ => None ,
1826
+ } ;
1827
+ let the_desc = match ty_desc {
1828
+ Some ( desc) => format ! ( " implemented for {} `" , desc) ,
1829
+ None => " implemented for `" . to_string ( ) ,
1830
+ } ;
1808
1831
err. highlighted_help ( vec ! [
1809
1832
(
1810
1833
format!( "the trait `{}` " , candidates[ 0 ] . print_only_trait_path( ) ) ,
1811
1834
Style :: NoStyle ,
1812
1835
) ,
1813
1836
( "is" . to_string( ) , Style :: Highlight ) ,
1814
- ( " implemented for `" . to_string ( ) , Style :: NoStyle ) ,
1837
+ ( the_desc , Style :: NoStyle ) ,
1815
1838
( candidates[ 0 ] . self_ty( ) . to_string( ) , Style :: Highlight ) ,
1816
1839
( "`" . to_string( ) , Style :: NoStyle ) ,
1817
1840
] ) ;
0 commit comments