@@ -450,12 +450,27 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
450450 {
451451 "consider using `()`, or a `Result`" . to_owned ( )
452452 } 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+ }
459474 } ;
460475
461476 if self . suggest_add_reference_to_arg (
@@ -1805,13 +1820,21 @@ impl<'a, 'tcx> InferCtxtPrivExt<'a, 'tcx> for InferCtxt<'a, 'tcx> {
18051820 return false ;
18061821 }
18071822 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+ } ;
18081831 err. highlighted_help ( vec ! [
18091832 (
18101833 format!( "the trait `{}` " , candidates[ 0 ] . print_only_trait_path( ) ) ,
18111834 Style :: NoStyle ,
18121835 ) ,
18131836 ( "is" . to_string( ) , Style :: Highlight ) ,
1814- ( " implemented for `" . to_string ( ) , Style :: NoStyle ) ,
1837+ ( the_desc , Style :: NoStyle ) ,
18151838 ( candidates[ 0 ] . self_ty( ) . to_string( ) , Style :: Highlight ) ,
18161839 ( "`" . to_string( ) , Style :: NoStyle ) ,
18171840 ] ) ;
0 commit comments