From 8a5b4f19fd6cec7b3ef583afa592fde99dabe58e Mon Sep 17 00:00:00 2001 From: Nathan Weston Date: Thu, 10 Sep 2015 08:33:29 -0400 Subject: [PATCH] Check for mutable borrow of counter variable --- src/loops.rs | 2 ++ tests/compile-fail/for_loop.rs | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/src/loops.rs b/src/loops.rs index 06892f6a74e..406fbee0b7c 100644 --- a/src/loops.rs +++ b/src/loops.rs @@ -351,6 +351,7 @@ impl<'v, 't> Visitor<'v> for IncrementVisitor<'v, 't> { } }, ExprAssign(ref lhs, _) if lhs.id == expr.id => *state = VarState::DontWarn, + ExprAddrOf(mutability,_) if mutability == MutMutable => *state = VarState::DontWarn, _ => () } } @@ -430,6 +431,7 @@ impl<'v, 't> Visitor<'v> for InitializeVisitor<'v, 't> { } else { VarState::DontWarn }}, + ExprAddrOf(mutability,_) if mutability == MutMutable => self.state = VarState::DontWarn, _ => () } } diff --git a/tests/compile-fail/for_loop.rs b/tests/compile-fail/for_loop.rs index 3320e9acc1d..d6d73db3c18 100755 --- a/tests/compile-fail/for_loop.rs +++ b/tests/compile-fail/for_loop.rs @@ -179,4 +179,8 @@ fn main() { let mut _index = 1; if false { _index = 0 }; for _v in &vec { _index += 1 } + + let mut _index = 0; + { let mut _x = &mut _index; } + for _v in &vec { _index += 1 } }