about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/librustc_typeck/check/method/suggest.rs22
-rw-r--r--src/test/compile-fail/issue-18343.rs11
2 files changed, 28 insertions, 5 deletions
diff --git a/src/librustc_typeck/check/method/suggest.rs b/src/librustc_typeck/check/method/suggest.rs
index b098fb56d4d..be34c705721 100644
--- a/src/librustc_typeck/check/method/suggest.rs
+++ b/src/librustc_typeck/check/method/suggest.rs
@@ -59,12 +59,24 @@ pub fn report_error<'a, 'tcx>(fcx: &FnCtxt<'a, 'tcx>,
                 None);
 
             // If the item has the name of a field, give a help note
-            if let (&ty::TyStruct(did, _), Some(_)) = (&rcvr_ty.sty, rcvr_expr) {
+            if let (&ty::TyStruct(did, substs), Some(_)) = (&rcvr_ty.sty, rcvr_expr) {
                 let fields = ty::lookup_struct_fields(cx, did);
-                if fields.iter().any(|f| f.name == item_name) {
-                    cx.sess.span_note(span,
-                        &format!("use `(s.{0})(...)` if you meant to call the \
-                                 function stored in the `{0}` field", item_name));
+
+                if let Some(field) = fields.iter().find(|f| f.name == item_name) {
+
+                    match ty::lookup_field_type(cx, did, field.id, substs).sty {
+                        ty::TyClosure(_, _) | ty::TyBareFn(_,_) => {
+                            cx.sess.span_note(span,
+                                &format!("use `({0}.{1})(...)` if you meant to call the \
+                                          function stored in the `{1}` field",
+                                    ty::item_path_str(cx, did), item_name));
+                        },
+                        _ => {
+                            cx.sess.span_note(span,
+                                &format!("did you mean to write `{0}.{1}`?",
+                                    ty::item_path_str(cx, did), item_name));
+                        },
+                    };
                 }
             }
 
diff --git a/src/test/compile-fail/issue-18343.rs b/src/test/compile-fail/issue-18343.rs
index 43e9ca5fa6e..3572e5084c1 100644
--- a/src/test/compile-fail/issue-18343.rs
+++ b/src/test/compile-fail/issue-18343.rs
@@ -10,10 +10,21 @@
 
 struct Obj<F> where F: FnMut() -> u32 {
     closure: F,
+    nfn: usize,
+}
+
+fn func() -> u32 {
+    0
 }
 
 fn main() {
     let o = Obj { closure: || 42 };
     o.closure(); //~ ERROR no method named `closure` found
     //~^ NOTE use `(s.closure)(...)` if you meant to call the function stored in the `closure` field
+    let x = o.nfn(); //~ ERROR no method named `closure` found
+    //~^ NOTE did you mean `o.nfn`?
+
+    let b = Obj { closure: func };
+    b.closure(); //~ ERROR no method named `closure` found
+    //~^ NOTE use `(s.closure)(...)` if you meant to call the function stored in the `closure` field
 }