Skip to content

Commit bc51842

Browse files
committed
rustc: Don't go over inner functions' locals during the writeback phase of typechecking
1 parent 84321d1 commit bc51842

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

src/comp/middle/typeck.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1437,8 +1437,10 @@ fn demand_block(&@fn_ctxt fcx, @ty.t expected, &ast.block bloc) -> ast.block {
14371437

14381438
// Writeback: the phase that writes inferred types back into the AST.
14391439

1440-
fn writeback_local(&@fn_ctxt fcx, &span sp, @ast.local local)
1440+
fn writeback_local(&option.t[@fn_ctxt] env, &span sp, @ast.local local)
14411441
-> @ast.decl {
1442+
auto fcx = option.get[@fn_ctxt](env);
1443+
14421444
if (!fcx.locals.contains_key(local.id)) {
14431445
fcx.ccx.sess.span_err(sp, "unable to determine type of local: "
14441446
+ local.ident);
@@ -1452,10 +1454,25 @@ fn writeback_local(&@fn_ctxt fcx, &span sp, @ast.local local)
14521454
}
14531455

14541456
fn writeback(&@fn_ctxt fcx, &ast.block block) -> ast.block {
1455-
auto fld = fold.new_identity_fold[@fn_ctxt]();
1456-
auto f = writeback_local;
1457-
fld = @rec(fold_decl_local = f with *fld);
1458-
ret fold.fold_block[@fn_ctxt](fcx, fld, block);
1457+
fn update_env_for_item(&option.t[@fn_ctxt] env, @ast.item i)
1458+
-> option.t[@fn_ctxt] {
1459+
ret none[@fn_ctxt];
1460+
}
1461+
fn keep_going(&option.t[@fn_ctxt] env) -> bool {
1462+
ret !option.is_none[@fn_ctxt](env);
1463+
}
1464+
1465+
auto fld = fold.new_identity_fold[option.t[@fn_ctxt]]();
1466+
auto wbl = writeback_local;
1467+
auto uefi = update_env_for_item;
1468+
auto kg = keep_going;
1469+
fld = @rec(
1470+
fold_decl_local = wbl,
1471+
update_env_for_item = uefi,
1472+
keep_going = kg
1473+
with *fld
1474+
);
1475+
ret fold.fold_block[option.t[@fn_ctxt]](some[@fn_ctxt](fcx), fld, block);
14591476
}
14601477

14611478
// AST fragment checking

0 commit comments

Comments
 (0)