Corrected explicit_counter_loop missing lints if variable used after loop
This commit is contained in:
@@ -1996,6 +1996,9 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
|
|||||||
if self.state == VarState::DontWarn {
|
if self.state == VarState::DontWarn {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if self.past_loop {
|
||||||
|
return;
|
||||||
|
}
|
||||||
if SpanlessEq::new(self.cx).eq_expr(&expr, self.end_expr) {
|
if SpanlessEq::new(self.cx).eq_expr(&expr, self.end_expr) {
|
||||||
self.past_loop = true;
|
self.past_loop = true;
|
||||||
return;
|
return;
|
||||||
@@ -2024,12 +2027,7 @@ impl<'a, 'tcx> Visitor<'tcx> for InitializeVisitor<'a, 'tcx> {
|
|||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if is_loop(expr) {
|
||||||
if self.past_loop {
|
|
||||||
self.state = VarState::DontWarn;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
} else if !self.past_loop && is_loop(expr) {
|
|
||||||
self.state = VarState::DontWarn;
|
self.state = VarState::DontWarn;
|
||||||
return;
|
return;
|
||||||
} else if is_conditional(expr) {
|
} else if is_conditional(expr) {
|
||||||
|
|||||||
@@ -573,16 +573,45 @@ mod issue_2496 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod issue_1219 {
|
mod issue_1219 {
|
||||||
// potential false positive for explicit_counter_loop
|
#[warn(clippy::explicit_counter_loop)]
|
||||||
pub fn test() {
|
pub fn test() {
|
||||||
let thing = 5;
|
// should not trigger the lint, because of the continue statement
|
||||||
let text = "banana";
|
let text = "banana";
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
for ch in text.chars() {
|
for ch in text.chars() {
|
||||||
if ch == 'a' {
|
if ch == 'a' {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
count += 1
|
count += 1;
|
||||||
|
}
|
||||||
|
println!("{}", count);
|
||||||
|
|
||||||
|
// should trigger the lint
|
||||||
|
let text = "banana";
|
||||||
|
let mut count = 0;
|
||||||
|
for ch in text.chars() {
|
||||||
|
if ch == 'a' {
|
||||||
|
println!("abc")
|
||||||
|
}
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
println!("{}", count);
|
||||||
|
|
||||||
|
// should not trigger the lint
|
||||||
|
let text = "banana";
|
||||||
|
let mut count = 0;
|
||||||
|
for ch in text.chars() {
|
||||||
|
if ch == 'a' {
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
println!("{}", count);
|
||||||
|
|
||||||
|
// should trigger the lint
|
||||||
|
let text = "banana";
|
||||||
|
let mut count = 0;
|
||||||
|
for _ch in text.chars() {
|
||||||
|
count += 1;
|
||||||
}
|
}
|
||||||
println!("{}", count);
|
println!("{}", count);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user