Skip to content

Commit 818d7c9

Browse files
committed
Use visit_fn_{pre,post} to avoid going past lambdas during writeback instead of explicitly casing.
1 parent 4499ebe commit 818d7c9

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

src/comp/middle/typeck.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -966,13 +966,8 @@ mod writeback {
966966
fn visit_stmt_pre(@fn_ctxt fcx, &@ast::stmt s) {
967967
resolve_type_vars_for_node(fcx, s.span, ty::stmt_node_id(s));
968968
}
969-
fn visit_expr_pre(@mutable bool ignore, @fn_ctxt fcx, &@ast::expr e) {
969+
fn visit_expr_pre(@fn_ctxt fcx, &@ast::expr e) {
970970
resolve_type_vars_for_node(fcx, e.span, e.id);
971-
alt (e.node) {
972-
// We don't want to recurse down into lambdas.
973-
case (ast::expr_fn(_)) { *ignore = true; }
974-
case (_) { }
975-
}
976971
}
977972
fn visit_expr_post(@mutable bool ignore, &@ast::expr e) {
978973
*ignore = false;
@@ -1000,23 +995,31 @@ mod writeback {
1000995
}
1001996
}
1002997
fn resolve_type_vars_in_block(&@fn_ctxt fcx, &ast::block block) {
1003-
// A trick to ignore any contained items.
1004-
998+
// A trick to ignore any contained items and lambdas.
1005999
auto ignore = @mutable false;
10061000
fn visit_item_pre(@mutable bool ignore, &@ast::item item) {
10071001
*ignore = true;
10081002
}
10091003
fn visit_item_post(@mutable bool ignore, &@ast::item item) {
10101004
*ignore = false;
10111005
}
1006+
fn visit_fn_pre(@mutable bool ignore, &ast::_fn f, &span sp,
1007+
&ast::fn_ident i, ast::node_id d) {
1008+
*ignore = true;
1009+
}
1010+
fn visit_fn_post(@mutable bool ignore, &ast::_fn f, &span sp,
1011+
&ast::fn_ident i, ast::node_id d) {
1012+
*ignore = false;
1013+
}
10121014
fn keep_going(@mutable bool ignore) -> bool { ret !*ignore; }
10131015
auto visit =
10141016
rec(keep_going=bind keep_going(ignore),
10151017
visit_item_pre=bind visit_item_pre(ignore, _),
10161018
visit_item_post=bind visit_item_post(ignore, _),
1019+
visit_fn_pre=bind visit_fn_pre(ignore, _, _, _, _),
1020+
visit_fn_post=bind visit_fn_post(ignore, _, _, _, _),
10171021
visit_stmt_pre=bind visit_stmt_pre(fcx, _),
1018-
visit_expr_pre=bind visit_expr_pre(ignore, fcx, _),
1019-
visit_expr_post=bind visit_expr_post(ignore, _),
1022+
visit_expr_pre=bind visit_expr_pre(fcx, _),
10201023
visit_block_pre=bind visit_block_pre(fcx, _),
10211024
visit_pat_pre=bind visit_pat_pre(fcx, _),
10221025
visit_local_pre=bind visit_local_pre(fcx, _)

0 commit comments

Comments
 (0)