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` }; }