Skip to content

Commit eac429c

Browse files
committed
Move the linearly-updated flag state into the Visitor.
1 parent 6ed338c commit eac429c

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

src/librustc/util/common.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -61,52 +61,54 @@ pub fn field_exprs(fields: ~[ast::Field]) -> ~[@ast::Expr] {
6161
}
6262

6363
struct LoopQueryVisitor<'self> {
64-
p: &'self fn(&ast::Expr_) -> bool
64+
p: &'self fn(&ast::Expr_) -> bool,
65+
flag: bool,
6566
}
6667

67-
impl<'self> Visitor<@mut bool> for LoopQueryVisitor<'self> {
68-
fn visit_expr(&mut self, e: @ast::Expr, flag: @mut bool) {
69-
*flag |= (self.p)(&e.node);
68+
impl<'self> Visitor<()> for LoopQueryVisitor<'self> {
69+
fn visit_expr(&mut self, e: @ast::Expr, _: ()) {
70+
self.flag |= (self.p)(&e.node);
7071
match e.node {
7172
// Skip inner loops, since a break in the inner loop isn't a
7273
// break inside the outer loop
7374
ast::ExprLoop(*) | ast::ExprWhile(*) => {}
74-
_ => visit::walk_expr(self, e, flag)
75+
_ => visit::walk_expr(self, e, ())
7576
}
7677
}
7778
}
7879

7980
// Takes a predicate p, returns true iff p is true for any subexpressions
8081
// of b -- skipping any inner loops (loop, while, loop_body)
8182
pub fn loop_query(b: &ast::Block, p: &fn(&ast::Expr_) -> bool) -> bool {
82-
let rs = @mut false;
8383
let mut v = LoopQueryVisitor {
8484
p: p,
85+
flag: false,
8586
};
86-
visit::walk_block(&mut v, b, rs);
87-
return *rs;
87+
visit::walk_block(&mut v, b, ());
88+
return v.flag;
8889
}
8990

9091
struct BlockQueryVisitor<'self> {
91-
p: &'self fn(@ast::Expr) -> bool
92+
p: &'self fn(@ast::Expr) -> bool,
93+
flag: bool,
9294
}
9395

94-
impl<'self> Visitor<@mut bool> for BlockQueryVisitor<'self> {
95-
fn visit_expr(&mut self, e: @ast::Expr, flag: @mut bool) {
96-
*flag |= (self.p)(e);
97-
visit::walk_expr(self, e, flag)
96+
impl<'self> Visitor<()> for BlockQueryVisitor<'self> {
97+
fn visit_expr(&mut self, e: @ast::Expr, _:()) {
98+
self.flag |= (self.p)(e);
99+
visit::walk_expr(self, e, ())
98100
}
99101
}
100102

101103
// Takes a predicate p, returns true iff p is true for any subexpressions
102104
// of b -- skipping any inner loops (loop, while, loop_body)
103105
pub fn block_query(b: &ast::Block, p: &fn(@ast::Expr) -> bool) -> bool {
104-
let rs = @mut false;
105106
let mut v = BlockQueryVisitor {
106107
p: p,
108+
flag: false,
107109
};
108-
visit::walk_block(&mut v, b, rs);
109-
return *rs;
110+
visit::walk_block(&mut v, b, ());
111+
return v.flag;
110112
}
111113

112114
pub fn local_rhs_span(l: @ast::Local, def: Span) -> Span {

0 commit comments

Comments
 (0)