@@ -59,12 +59,24 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
59
59
None ) ;
60
60
61
61
// If the item has the name of a field, give a help note
62
- if let ( & ty:: TyStruct ( did, _ ) , Some ( _) ) = ( & rcvr_ty. sty , rcvr_expr) {
62
+ if let ( & ty:: TyStruct ( did, substs ) , Some ( _) ) = ( & rcvr_ty. sty , rcvr_expr) {
63
63
let fields = ty:: lookup_struct_fields ( cx, did) ;
64
- if fields. iter ( ) . any ( |f| f. name == item_name) {
65
- cx. sess . span_note ( span,
66
- & format ! ( "use `(s.{0})(...)` if you meant to call the \
67
- function stored in the `{0}` field", item_name) ) ;
64
+
65
+ if let Some ( field) = fields. iter ( ) . find ( |f| f. name == item_name) {
66
+
67
+ match ty:: lookup_field_type ( cx, did, field. id , substs) . sty {
68
+ ty:: TyClosure ( _, _) | ty:: TyBareFn ( _, _) => {
69
+ cx. sess . span_note ( span,
70
+ & format ! ( "use `({0}.{1})(...)` if you meant to call the \
71
+ function stored in the `{1}` field",
72
+ ty:: item_path_str( cx, did) , item_name) ) ;
73
+ } ,
74
+ _ => {
75
+ cx. sess . span_note ( span,
76
+ & format ! ( "did you mean to write `{0}.{1}`?" ,
77
+ ty:: item_path_str( cx, did) , item_name) ) ;
78
+ } ,
79
+ } ;
68
80
}
69
81
}
70
82
0 commit comments