Skip to content

Commit 2d5b651

Browse files
committed
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
1 parent 78a0d38 commit 2d5b651

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/comp/middle/typeck.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,8 +1605,11 @@ fn check_expr(fcx: &@fn_ctxt, expr: &@ast::expr) -> bool {
16051605
// A generic function for checking for or for-each loops
16061606

16071607
fn check_for_or_for_each(fcx: &@fn_ctxt, local: &@ast::local,
1608-
element_ty: &ty::t, body: &ast::blk,
1609-
node_id: ast::node_id) -> bool {
1608+
element_ty: ty::t, body: &ast::blk,
1609+
node_id: ast::node_id) -> bool {
1610+
let locid = lookup_local(fcx, local.span, local.node.id);
1611+
element_ty = demand::simple(fcx, local.span, element_ty,
1612+
ty::mk_var(fcx.ccx.tcx, locid));
16101613
let bot = check_decl_local(fcx, local);
16111614
check_block(fcx, body);
16121615
// Unify type of decl with element type of the seq

0 commit comments

Comments
 (0)