@@ -178,28 +178,43 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
178
178
rcvr_ty,
179
179
None ) ;
180
180
181
- // If the item has the name of a field, give a help note
182
- if let ( & ty:: TyStruct ( def, substs) , Some ( expr) ) = ( & rcvr_ty. sty , rcvr_expr) {
183
- if let Some ( field) = def. struct_variant ( ) . find_field_named ( item_name) {
184
- let expr_string = match tcx. sess . codemap ( ) . span_to_snippet ( expr. span ) {
185
- Ok ( expr_string) => expr_string,
186
- _ => "s" . into ( ) // Default to a generic placeholder for the
187
- // expression when we can't generate a string
188
- // snippet
189
- } ;
190
-
191
- let field_ty = field. ty ( tcx, substs) ;
192
-
193
- if self . is_fn_ty ( & field_ty, span) {
194
- err. span_note ( span,
195
- & format ! ( "use `({0}.{1})(...)` if you meant to call \
196
- the function stored in the `{1}` field",
197
- expr_string, item_name) ) ;
198
- } else {
199
- err. span_note ( span, & format ! ( "did you mean to write `{0}.{1}`?" ,
200
- expr_string, item_name) ) ;
201
- }
202
- }
181
+ // If the method name is the name of a field with a function or closure type,
182
+ // give a helping note that it has to be called as (x.f)(...).
183
+ if let Some ( expr) = rcvr_expr {
184
+ self . autoderef (
185
+ span,
186
+ rcvr_ty,
187
+ || None ,
188
+ UnresolvedTypeAction :: Ignore ,
189
+ LvaluePreference :: NoPreference ,
190
+ |ty, _| {
191
+ if let ty:: TyStruct ( def, substs) = ty. sty {
192
+ if let Some ( field) = def. struct_variant ( )
193
+ . find_field_named ( item_name) {
194
+ let snippet = tcx. sess . codemap ( ) . span_to_snippet ( expr. span ) ;
195
+ let expr_string = match snippet {
196
+ Ok ( expr_string) => expr_string,
197
+ _ => "s" . into ( ) // Default to a generic placeholder for the
198
+ // expression when we can't generate a
199
+ // string snippet
200
+ } ;
201
+
202
+ let field_ty = field. ty ( tcx, substs) ;
203
+
204
+ if self . is_fn_ty ( & field_ty, span) {
205
+ err. note ( & format ! ( "use `({0}.{1})(...)` if you meant to \
206
+ call the function stored in the `{1}` \
207
+ field",
208
+ expr_string, item_name) ) ;
209
+ } else {
210
+ err. note ( & format ! ( "did you mean to write `{0}.{1}`?" ,
211
+ expr_string, item_name) ) ;
212
+ }
213
+ return Some ( ( ) ) ;
214
+ }
215
+ }
216
+ None
217
+ } ) ;
203
218
}
204
219
205
220
if self . is_fn_ty ( & rcvr_ty, span) {
0 commit comments