Skip to content

Commit

Permalink
#8263 part 2: Adding struct name.
Browse files Browse the repository at this point in the history
  • Loading branch information
pythonesque committed Oct 29, 2013
1 parent 01ab854 commit a716657
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
13 changes: 9 additions & 4 deletions src/librustc/middle/typeck/check/mod.rs
Expand Up @@ -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,
Expand All @@ -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)) => {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-4736.rs
Expand Up @@ -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`
}
2 changes: 1 addition & 1 deletion src/test/compile-fail/struct-fields-too-many.rs
Expand Up @@ -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`
};
}

5 comments on commit a716657

@bors
Copy link
Contributor

@bors bors commented on a716657 Oct 29, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from catamorphism
at pythonesque@a716657

@bors
Copy link
Contributor

@bors bors commented on a716657 Oct 29, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging pythonesque/rust/issue-8263 = a716657 into auto

@bors
Copy link
Contributor

@bors bors commented on a716657 Oct 29, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pythonesque/rust/issue-8263 = a716657 merged ok, testing candidate = e6650c8

@bors
Copy link
Contributor

@bors bors commented on a716657 Oct 29, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on a716657 Oct 29, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = e6650c8

Please sign in to comment.