From 2d5b651f4981b85d0e3864d8df6bd0953578e1f4 Mon Sep 17 00:00:00 2001 From: Marijn Haverbeke Date: Tue, 2 Aug 2011 15:09:27 +0200 Subject: [PATCH] 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 --- src/comp/middle/typeck.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/comp/middle/typeck.rs b/src/comp/middle/typeck.rs index 099cd045e6bb..85b9dba0b321 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