Skip to content

Commit

Permalink
UI test cleanup: Extract for_loop_over_x tests
Browse files Browse the repository at this point in the history
  • Loading branch information
phansch committed Oct 30, 2018
1 parent 481f788 commit b421f5a
Show file tree
Hide file tree
Showing 4 changed files with 318 additions and 306 deletions.
60 changes: 0 additions & 60 deletions tests/ui/for_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,71 +7,13 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.





use std::collections::*;
use std::rc::Rc;

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

#[warn(clippy::all)]
fn for_loop_over_option_and_result() {
let option = Some(1);
let result = option.ok_or("x not found");
let v = vec![0, 1, 2];

// check FOR_LOOP_OVER_OPTION lint
for x in option {
println!("{}", x);
}

// check FOR_LOOP_OVER_RESULT lint
for x in result {
println!("{}", x);
}

for x in option.ok_or("x not found") {
println!("{}", x);
}

// make sure LOOP_OVER_NEXT lint takes clippy::precedence when next() is the last call
// in the chain
for x in v.iter().next() {
println!("{}", x);
}

// make sure we lint when next() is not the last call in the chain
for x in v.iter().next().and(Some(0)) {
println!("{}", x);
}

for x in v.iter().next().ok_or("x not found") {
println!("{}", x);
}

// check for false positives

// for loop false positive
for x in v {
println!("{}", x);
}

// while let false positive for Option
while let Some(x) = option {
println!("{}", x);
break;
}

// while let false positive for Result
while let Ok(x) = result {
println!("{}", x);
break;
}
}

struct Unrelated(Vec<u8>);
impl Unrelated {
fn next(&self) -> std::slice::Iter<u8> {
Expand Down Expand Up @@ -379,8 +321,6 @@ fn main() {
}
println!("index: {}", index);

for_loop_over_option_and_result();

let m: HashMap<u64, u64> = HashMap::new();
for (_, v) in &m {
let _v = v;
Expand Down
Loading

0 comments on commit b421f5a

Please sign in to comment.