Skip to content

Commit a716657

Browse files
committed
#8263 part 2: Adding struct name.
1 parent 01ab854 commit a716657

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/librustc/middle/typeck/check/mod.rs

+9-4
Original file line numberDiff line numberDiff line change
@@ -2009,6 +2009,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
20092009
}
20102010

20112011
fn check_struct_or_variant_fields(fcx: @mut FnCtxt,
2012+
struct_ty: ty::t,
20122013
span: Span,
20132014
class_id: ast::DefId,
20142015
node_id: ast::NodeId,
@@ -2033,10 +2034,12 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
20332034
let pair = class_field_map.find(&field.ident.node.name).map(|x| *x);
20342035
match pair {
20352036
None => {
2036-
tcx.sess.span_err(
2037-
field.ident.span,
2038-
format!("structure has no field named `{}`",
2039-
tcx.sess.str_of(field.ident.node)));
2037+
fcx.type_error_message(
2038+
field.ident.span,
2039+
|actual| {
2040+
format!("structure `{}` has no field named `{}`",
2041+
actual, tcx.sess.str_of(field.ident.node))
2042+
}, struct_ty, None);
20402043
error_happened = true;
20412044
}
20422045
Some((_, true)) => {
@@ -2161,6 +2164,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
21612164
// Look up and check the fields.
21622165
let class_fields = ty::lookup_struct_fields(tcx, class_id);
21632166
check_struct_or_variant_fields(fcx,
2167+
struct_type,
21642168
span,
21652169
class_id,
21662170
id,
@@ -2248,6 +2252,7 @@ pub fn check_expr_with_unifier(fcx: @mut FnCtxt,
22482252
// Look up and check the enum variant fields.
22492253
let variant_fields = ty::lookup_struct_fields(tcx, variant_id);
22502254
check_struct_or_variant_fields(fcx,
2255+
enum_type,
22512256
span,
22522257
variant_id,
22532258
id,

src/test/compile-fail/issue-4736.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111
struct NonCopyable(());
1212

1313
fn main() {
14-
let z = NonCopyable{ p: () }; //~ ERROR structure has no field named `p`
14+
let z = NonCopyable{ p: () }; //~ ERROR structure `NonCopyable` has no field named `p`
1515
}

src/test/compile-fail/struct-fields-too-many.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ struct BuildData {
1515
fn main() {
1616
let foo = BuildData {
1717
foo: 0,
18-
bar: 0 //~ ERROR structure has no field named `bar`
18+
bar: 0 //~ ERROR structure `BuildData` has no field named `bar`
1919
};
2020
}

0 commit comments

Comments
 (0)