File tree 1 file changed +21
-1
lines changed
src/librustc/middle/typeck/check
1 file changed +21
-1
lines changed Original file line number Diff line number Diff line change @@ -223,17 +223,37 @@ pub fn report_error(fcx: &FnCtxt,
223
223
{
224
224
match error {
225
225
NoMatch ( static_sources) => {
226
+ let cx = fcx. tcx ( ) ;
227
+ let method_ustring = method_name. user_string ( cx) ;
228
+
229
+ // True if the type is a struct and contains a field with
230
+ // the same name as the not-found method
231
+ let is_field = match ty:: get ( rcvr_ty) . sty {
232
+ ty_struct( did, _) =>
233
+ ty:: lookup_struct_fields ( cx, did)
234
+ . iter ( )
235
+ . any ( |f| f. name . user_string ( cx) == method_ustring) ,
236
+ _ => false
237
+ } ;
238
+
226
239
fcx. type_error_message (
227
240
span,
228
241
|actual| {
229
242
format ! ( "type `{}` does not implement any \
230
243
method in scope named `{}`",
231
244
actual,
232
- method_name . user_string ( fcx . tcx ( ) ) )
245
+ method_ustring )
233
246
} ,
234
247
rcvr_ty,
235
248
None ) ;
236
249
250
+ // If the method has the name of a field, give a help note
251
+ if is_field {
252
+ cx. sess . span_note ( span,
253
+ format ! ( "use `(s.{0})(...)` if you meant to call the \
254
+ function stored in the `{0}` field", method_ustring) . as_slice ( ) ) ;
255
+ }
256
+
237
257
if static_sources. len ( ) > 0 {
238
258
fcx. tcx ( ) . sess . fileline_note (
239
259
span,
You can’t perform that action at this time.
0 commit comments