summary refs log tree commit diff
diff options
context:
space:
mode:
authorFelix S. Klock II <pnkfelix@pnkfx.org>2013-09-25 10:55:04 +0200
committerFelix S. Klock II <pnkfelix@pnkfx.org>2013-09-25 10:55:04 +0200
commiteac429cc9e1e57ea9c91406dc149e7b1c79d86a0 (patch)
tree69df06cfe09e831f16574e7fd25c69380656d54e
parent6ed338caa7fd4017d57254cdc13a77e38505dd02 (diff)
downloadrust-eac429cc9e1e57ea9c91406dc149e7b1c79d86a0.tar.gz
rust-eac429cc9e1e57ea9c91406dc149e7b1c79d86a0.zip
Move the linearly-updated flag state into the Visitor.
-rw-r--r--src/librustc/util/common.rs34
1 files changed, 18 insertions, 16 deletions
diff --git a/src/librustc/util/common.rs b/src/librustc/util/common.rs
index 8337354724a..eeef2b798e2 100644
--- a/src/librustc/util/common.rs
+++ b/src/librustc/util/common.rs
@@ -61,17 +61,18 @@ pub fn field_exprs(fields: ~[ast::Field]) -> ~[@ast::Expr] {
 }
 
 struct LoopQueryVisitor<'self> {
-    p: &'self fn(&ast::Expr_) -> bool
+    p: &'self fn(&ast::Expr_) -> bool,
+    flag: bool,
 }
 
-impl<'self> Visitor<@mut bool> for LoopQueryVisitor<'self> {
-    fn visit_expr(&mut self, e: @ast::Expr, flag: @mut bool) {
-        *flag |= (self.p)(&e.node);
+impl<'self> Visitor<()> for LoopQueryVisitor<'self> {
+    fn visit_expr(&mut self, e: @ast::Expr, _: ()) {
+        self.flag |= (self.p)(&e.node);
         match e.node {
           // Skip inner loops, since a break in the inner loop isn't a
           // break inside the outer loop
           ast::ExprLoop(*) | ast::ExprWhile(*) => {}
-          _ => visit::walk_expr(self, e, flag)
+          _ => visit::walk_expr(self, e, ())
         }
     }
 }
@@ -79,34 +80,35 @@ impl<'self> Visitor<@mut bool> for LoopQueryVisitor<'self> {
 // Takes a predicate p, returns true iff p is true for any subexpressions
 // of b -- skipping any inner loops (loop, while, loop_body)
 pub fn loop_query(b: &ast::Block, p: &fn(&ast::Expr_) -> bool) -> bool {
-    let rs = @mut false;
     let mut v = LoopQueryVisitor {
         p: p,
+        flag: false,
     };
-    visit::walk_block(&mut v, b, rs);
-    return *rs;
+    visit::walk_block(&mut v, b, ());
+    return v.flag;
 }
 
 struct BlockQueryVisitor<'self> {
-    p: &'self fn(@ast::Expr) -> bool
+    p: &'self fn(@ast::Expr) -> bool,
+    flag: bool,
 }
 
-impl<'self> Visitor<@mut bool> for BlockQueryVisitor<'self> {
-    fn visit_expr(&mut self, e: @ast::Expr, flag: @mut bool) {
-        *flag |= (self.p)(e);
-        visit::walk_expr(self, e, flag)
+impl<'self> Visitor<()> for BlockQueryVisitor<'self> {
+    fn visit_expr(&mut self, e: @ast::Expr, _:()) {
+        self.flag |= (self.p)(e);
+        visit::walk_expr(self, e, ())
     }
 }
 
 // Takes a predicate p, returns true iff p is true for any subexpressions
 // of b -- skipping any inner loops (loop, while, loop_body)
 pub fn block_query(b: &ast::Block, p: &fn(@ast::Expr) -> bool) -> bool {
-    let rs = @mut false;
     let mut v = BlockQueryVisitor {
         p: p,
+        flag: false,
     };
-    visit::walk_block(&mut v, b, rs);
-    return *rs;
+    visit::walk_block(&mut v, b, ());
+    return v.flag;
 }
 
 pub fn local_rhs_span(l: @ast::Local, def: Span) -> Span {