Skip to content

Commit 949b125

Browse files
committed
Add unit tests for new lint
1 parent c5f3f9d commit 949b125

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

tests/ui/for_loops_over_options.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#![warn(clippy::for_loops_over_options)]
2+
3+
fn main() {
4+
let x = vec![Some(1), Some(2), Some(3)];
5+
for n in x {
6+
if let Some(n) = n {
7+
println!("{}", n);
8+
}
9+
}
10+
11+
let y: Vec<Result<i32, i32>> = vec![];
12+
for n in y.clone() {
13+
if let Ok(n) = n {
14+
println!("{}", n);
15+
}
16+
}
17+
18+
// This should not trigger the lint
19+
for n in y.clone() {
20+
if let Ok(n) = n {
21+
println!("{}", n);
22+
} else {
23+
println!("Oops!");
24+
}
25+
}
26+
27+
// This should not trigger the lint
28+
for n in vec![Some(1), Some(2), Some(3)].iter().flatten() {
29+
println!("{}", n);
30+
}
31+
}

0 commit comments

Comments
 (0)