Skip to content

Commit 93c378e

Browse files
committed
---
yaml --- r: 13466 b: refs/heads/master c: fcab11d h: refs/heads/master v: v3
1 parent 81c4182 commit 93c378e

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 24f9f45ac68f4b29997a20b63de7997536f89dd1
2+
refs/heads/master: fcab11da47daa6461a3b5895a1dc16e582f7cae3
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/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)