Skip to content

Commit fcab11d

Browse files
committed
Refactor; annotate a FIXME
1 parent 24f9f45 commit fcab11d

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

src/rustc/util/common.rs

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,36 +33,28 @@ fn field_exprs(fields: [ast::field]) -> [@ast::expr] {
3333
ret es;
3434
}
3535

36-
fn has_nonlocal_exits(b: ast::blk) -> bool {
37-
let has_exits = @mut false;
38-
fn visit_expr(flag: @mut bool, e: @ast::expr) {
39-
alt e.node {
40-
ast::expr_break { *flag = true; }
41-
ast::expr_cont { *flag = true; }
42-
_ { }
43-
}
44-
}
36+
// Takes a predicate p, returns true iff p is true for any subexpressions
37+
// of b
38+
fn block_expr_query(b: ast::blk, p: fn@(ast::expr_) -> bool) -> bool {
39+
let rs = @mut false;
40+
let visit_expr = {|flag: @mut bool, e: @ast::expr| *flag |= p(e.node)};
4541
let v =
46-
visit::mk_simple_visitor(@{visit_expr: bind visit_expr(has_exits, _)
42+
visit::mk_simple_visitor(@{visit_expr: bind visit_expr(rs, _)
4743
with *visit::default_simple_visitor()});
4844
visit::visit_block(b, (), v);
49-
ret *has_exits;
45+
ret *rs;
46+
}
47+
48+
fn has_nonlocal_exits(b: ast::blk) -> bool {
49+
block_expr_query(b) {|e| alt e {
50+
ast::expr_break | ast::expr_cont { true }
51+
_ { false }}}
5052
}
5153

52-
/* FIXME: copy/paste, yuck */
5354
fn may_break(b: ast::blk) -> bool {
54-
let has_exits = @mut false;
55-
fn visit_expr(flag: @mut bool, e: @ast::expr) {
56-
alt e.node {
57-
ast::expr_break { *flag = true; }
58-
_ { }
59-
}
60-
}
61-
let v =
62-
visit::mk_simple_visitor(@{visit_expr: bind visit_expr(has_exits, _)
63-
with *visit::default_simple_visitor()});
64-
visit::visit_block(b, (), v);
65-
ret *has_exits;
55+
block_expr_query(b) {|e| alt e {
56+
ast::expr_break { true }
57+
_ { false }}}
6658
}
6759

6860
fn local_rhs_span(l: @ast::local, def: span) -> span {
@@ -71,7 +63,7 @@ fn local_rhs_span(l: @ast::local, def: span) -> span {
7163

7264
fn is_main_name(path: syntax::ast_map::path) -> bool {
7365
// FIXME: path should be a constrained type, so we know
74-
// the call to last doesn't fail
66+
// the call to last doesn't fail (#34)
7567
vec::last(path) == syntax::ast_map::path_name(@"main")
7668
}
7769

0 commit comments

Comments
 (0)