From 16ec9aa6e7b999e235007f75af2fd631f7333a84 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Mon, 7 Jan 2013 16:57:43 -0800 Subject: [PATCH] Support assignability for struct fields. r=pcwalton --- src/librustc/middle/typeck/check/mod.rs | 8 +++++--- src/test/run-pass/struct-field-assignability.rs | 9 +++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 src/test/run-pass/struct-field-assignability.rs diff --git a/src/librustc/middle/typeck/check/mod.rs b/src/librustc/middle/typeck/check/mod.rs index 3086b2e7227..f4bae52bd91 100644 --- a/src/librustc/middle/typeck/check/mod.rs +++ b/src/librustc/middle/typeck/check/mod.rs @@ -1679,9 +1679,11 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, let expected_field_type = ty::lookup_field_type( tcx, class_id, field_id, substitutions); - bot |= check_expr(fcx, - field.node.expr, - Some(expected_field_type)); + bot |= + check_expr_with_assignability( + fcx, + field.node.expr, + expected_field_type); class_field_map.insert( field.node.ident, (field_id, true)); fields_found += 1; diff --git a/src/test/run-pass/struct-field-assignability.rs b/src/test/run-pass/struct-field-assignability.rs new file mode 100644 index 00000000000..93c490bd5f3 --- /dev/null +++ b/src/test/run-pass/struct-field-assignability.rs @@ -0,0 +1,9 @@ +struct Foo { + x: &int +} + +fn main() { + let f = Foo { x: @3 }; + assert *f.x == 3; +} +