This commit is contained in:
parent
b2462aa0e1
commit
cb4de738cf
4 changed files with 39 additions and 5 deletions
|
@ -1457,6 +1457,8 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
|
||||||
let tcx = fcx.ccx.tcx;
|
let tcx = fcx.ccx.tcx;
|
||||||
let mut bot = false;
|
let mut bot = false;
|
||||||
|
|
||||||
|
error!("%? %?", ast_fields.len(), field_types.len());
|
||||||
|
|
||||||
let class_field_map = HashMap();
|
let class_field_map = HashMap();
|
||||||
let mut fields_found = 0;
|
let mut fields_found = 0;
|
||||||
for field_types.each |field| {
|
for field_types.each |field| {
|
||||||
|
@ -1470,7 +1472,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
|
||||||
None => {
|
None => {
|
||||||
tcx.sess.span_err(
|
tcx.sess.span_err(
|
||||||
field.span,
|
field.span,
|
||||||
fmt!("structure has no field named field named `%s`",
|
fmt!("structure has no field named `%s`",
|
||||||
tcx.sess.str_of(field.node.ident)));
|
tcx.sess.str_of(field.node.ident)));
|
||||||
}
|
}
|
||||||
Some((_, true)) => {
|
Some((_, true)) => {
|
||||||
|
@ -1486,6 +1488,8 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
|
||||||
bot |= check_expr(fcx,
|
bot |= check_expr(fcx,
|
||||||
field.node.expr,
|
field.node.expr,
|
||||||
Some(expected_field_type));
|
Some(expected_field_type));
|
||||||
|
class_field_map.insert(
|
||||||
|
field.node.ident, (field_id, true));
|
||||||
fields_found += 1;
|
fields_found += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1493,11 +1497,11 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
|
||||||
|
|
||||||
if check_completeness {
|
if check_completeness {
|
||||||
// Make sure the programmer specified all the fields.
|
// Make sure the programmer specified all the fields.
|
||||||
assert fields_found <= ast_fields.len();
|
assert fields_found <= field_types.len();
|
||||||
if fields_found < ast_fields.len() {
|
if fields_found < field_types.len() {
|
||||||
let mut missing_fields = ~[];
|
let mut missing_fields = ~[];
|
||||||
for ast_fields.each |class_field| {
|
for field_types.each |class_field| {
|
||||||
let name = class_field.node.ident;
|
let name = class_field.ident;
|
||||||
let (_, seen) = class_field_map.get(name);
|
let (_, seen) = class_field_map.get(name);
|
||||||
if !seen {
|
if !seen {
|
||||||
missing_fields.push(
|
missing_fields.push(
|
||||||
|
|
10
src/test/compile-fail/struct-fields-dupe.rs
Normal file
10
src/test/compile-fail/struct-fields-dupe.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
struct BuildData {
|
||||||
|
foo: int,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let foo = BuildData {
|
||||||
|
foo: 0,
|
||||||
|
foo: 0 //~ ERROR field `foo` specified more than once
|
||||||
|
};
|
||||||
|
}
|
10
src/test/compile-fail/struct-fields-missing.rs
Normal file
10
src/test/compile-fail/struct-fields-missing.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
struct BuildData {
|
||||||
|
foo: int,
|
||||||
|
bar: ~int
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let foo = BuildData { //~ ERROR missing field: `bar`
|
||||||
|
foo: 0
|
||||||
|
};
|
||||||
|
}
|
10
src/test/compile-fail/struct-fields-too-many.rs
Normal file
10
src/test/compile-fail/struct-fields-too-many.rs
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
struct BuildData {
|
||||||
|
foo: int,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let foo = BuildData {
|
||||||
|
foo: 0,
|
||||||
|
bar: 0 //~ ERROR structure has no field named `bar`
|
||||||
|
};
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue