Skip to content

Commit 6a165e5

Browse files
bors[bot]phansch
andcommitted
Merge #3392
3392: UI test cleanup: Extract for_loop_over_x tests r=matthiaskrgr a=phansch cc #2038 Co-authored-by: Philipp Hansch <[email protected]>
2 parents 73458ae + b421f5a commit 6a165e5

File tree

4 files changed

+318
-306
lines changed

4 files changed

+318
-306
lines changed

tests/ui/for_loop.rs

-60
Original file line numberDiff line numberDiff line change
@@ -7,71 +7,13 @@
77
// option. This file may not be copied, modified, or distributed
88
// except according to those terms.
99

10-
11-
12-
13-
1410
use std::collections::*;
1511
use std::rc::Rc;
1612

1713
static STATIC: [usize; 4] = [0, 1, 8, 16];
1814
const CONST: [usize; 4] = [0, 1, 8, 16];
1915

2016
#[warn(clippy::all)]
21-
fn for_loop_over_option_and_result() {
22-
let option = Some(1);
23-
let result = option.ok_or("x not found");
24-
let v = vec![0, 1, 2];
25-
26-
// check FOR_LOOP_OVER_OPTION lint
27-
for x in option {
28-
println!("{}", x);
29-
}
30-
31-
// check FOR_LOOP_OVER_RESULT lint
32-
for x in result {
33-
println!("{}", x);
34-
}
35-
36-
for x in option.ok_or("x not found") {
37-
println!("{}", x);
38-
}
39-
40-
// make sure LOOP_OVER_NEXT lint takes clippy::precedence when next() is the last call
41-
// in the chain
42-
for x in v.iter().next() {
43-
println!("{}", x);
44-
}
45-
46-
// make sure we lint when next() is not the last call in the chain
47-
for x in v.iter().next().and(Some(0)) {
48-
println!("{}", x);
49-
}
50-
51-
for x in v.iter().next().ok_or("x not found") {
52-
println!("{}", x);
53-
}
54-
55-
// check for false positives
56-
57-
// for loop false positive
58-
for x in v {
59-
println!("{}", x);
60-
}
61-
62-
// while let false positive for Option
63-
while let Some(x) = option {
64-
println!("{}", x);
65-
break;
66-
}
67-
68-
// while let false positive for Result
69-
while let Ok(x) = result {
70-
println!("{}", x);
71-
break;
72-
}
73-
}
74-
7517
struct Unrelated(Vec<u8>);
7618
impl Unrelated {
7719
fn next(&self) -> std::slice::Iter<u8> {
@@ -379,8 +321,6 @@ fn main() {
379321
}
380322
println!("index: {}", index);
381323

382-
for_loop_over_option_and_result();
383-
384324
let m: HashMap<u64, u64> = HashMap::new();
385325
for (_, v) in &m {
386326
let _v = v;

0 commit comments

Comments
 (0)