From eac429cc9e1e57ea9c91406dc149e7b1c79d86a0 Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Wed, 25 Sep 2013 10:55:04 +0200 Subject: [PATCH] Move the linearly-updated flag state into the Visitor. --- src/librustc/util/common.rs | 34 ++++++++++++++++++---------------- 1 file 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 {