about summary refs log tree commit diff
path: root/src/comp
diff options
context:
space:
mode:
authorMarijn Haverbeke <marijnh@gmail.com>2011-08-02 15:09:27 +0200
committerMarijn Haverbeke <marijnh@gmail.com>2011-08-02 15:09:29 +0200
commit2d5b651f4981b85d0e3864d8df6bd0953578e1f4 (patch)
treecd6c1d79742df544d8943769668ffb89b8404771 /src/comp
parent78a0d380cc276116bd995bebbee10b0144d89432 (diff)
downloadrust-2d5b651f4981b85d0e3864d8df6bd0953578e1f4.tar.gz
rust-2d5b651f4981b85d0e3864d8df6bd0953578e1f4.zip
Assign collection element ty to loop local tvar when checking loops
This makes the type declarationg for the loop variable optional in
most cases.

Closes #790
Diffstat (limited to 'src/comp')
-rw-r--r--src/comp/middle/typeck.rs7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs
index 099cd045e6b..85b9dba0b32 100644
--- a/src/comp/middle/typeck.rs
+++ b/src/comp/middle/typeck.rs
@@ -1605,8 +1605,11 @@ fn check_expr(fcx: &@fn_ctxt, expr: &@ast::expr) -> bool {
     // A generic function for checking for or for-each loops
 
     fn check_for_or_for_each(fcx: &@fn_ctxt, local: &@ast::local,
-                                 element_ty: &ty::t, body: &ast::blk,
-                                 node_id: ast::node_id) -> bool {
+                             element_ty: ty::t, body: &ast::blk,
+                             node_id: ast::node_id) -> bool {
+        let locid = lookup_local(fcx, local.span, local.node.id);
+        element_ty = demand::simple(fcx, local.span, element_ty,
+                                    ty::mk_var(fcx.ccx.tcx, locid));
         let bot = check_decl_local(fcx, local);
         check_block(fcx, body);
         // Unify type of decl with element type of the seq