about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJoshua Yanovski <pythonesque@gmail.com>2013-10-28 23:30:26 -0700
committerJoshua Yanovski <pythonesque@gmail.com>2013-10-28 23:51:10 -0700
commita71665798bdd629ff8d328ef325723b79a2542a7 (patch)
tree5137661edbf8e293bc081c6d3c2ca83711a1b4f9
parent01ab8542fbcfbea2cb0dcdc538e56a7167f70f51 (diff)
#8263 part 2: Adding struct name.
-rw-r--r--src/librustc/middle/typeck/check/mod.rs13
-rw-r--r--src/test/compile-fail/issue-4736.rs2
-rw-r--r--src/test/compile-fail/struct-fields-too-many.rs2
3 files changed, 11 insertions, 6 deletions
diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs
index 218a76a8e93..d71aa776689 100644
--- a/src/librustc/middle/typeck/check/mod.rs
+++ b/src/librustc/middle/typeck/check/mod.rs
@@ -2009,6 +2009,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
     }
 
     fn check_struct_or_variant_fields(fcx: @mut FnCtxt,
+                                      struct_ty: ty::t,
                                       span: Span,
                                       class_id: ast::DefId,
                                       node_id: ast::NodeId,
@@ -2033,10 +2034,12 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
             let pair = class_field_map.find(&field.ident.node.name).map(|x| *x);
             match pair {
                 None => {
-                    tcx.sess.span_err(
-                        field.ident.span,
-                        format!("structure has no field named `{}`",
-                             tcx.sess.str_of(field.ident.node)));
+                    fcx.type_error_message(
+                      field.ident.span,
+                      |actual| {
+                          format!("structure `{}` has no field named `{}`",
+                                  actual, tcx.sess.str_of(field.ident.node))
+                    }, struct_ty, None);
                     error_happened = true;
                 }
                 Some((_, true)) => {
@@ -2161,6 +2164,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
         // Look up and check the fields.
         let class_fields = ty::lookup_struct_fields(tcx, class_id);
         check_struct_or_variant_fields(fcx,
+                                           struct_type,
                                            span,
                                            class_id,
                                            id,
@@ -2248,6 +2252,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
         // Look up and check the enum variant fields.
         let variant_fields = ty::lookup_struct_fields(tcx, variant_id);
         check_struct_or_variant_fields(fcx,
+                                       enum_type,
                                        span,
                                        variant_id,
                                        id,
diff --git a/src/test/compile-fail/issue-4736.rs b/src/test/compile-fail/issue-4736.rs
index 6f410ea3c37..b63db7c5a30 100644
--- a/src/test/compile-fail/issue-4736.rs
+++ b/src/test/compile-fail/issue-4736.rs
@@ -11,5 +11,5 @@
 struct NonCopyable(());
 
 fn main() {
-    let z = NonCopyable{ p: () }; //~ ERROR structure has no field named `p`
+    let z = NonCopyable{ p: () }; //~ ERROR structure `NonCopyable` has no field named `p`
 }
diff --git a/src/test/compile-fail/struct-fields-too-many.rs b/src/test/compile-fail/struct-fields-too-many.rs
index 67897f6ef93..de58b5d110e 100644
--- a/src/test/compile-fail/struct-fields-too-many.rs
+++ b/src/test/compile-fail/struct-fields-too-many.rs
@@ -15,6 +15,6 @@ struct BuildData {
 fn main() {
     let foo = BuildData {
         foo: 0,
-        bar: 0 //~ ERROR structure has no field named `bar`
+        bar: 0 //~ ERROR structure `BuildData` has no field named `bar`
     };
 }