Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
3392: UI test cleanup: Extract for_loop_over_x tests r=matthiaskrgr a=phansch

cc rust-lang#2038

Co-authored-by: Philipp Hansch <dev@phansch.net>
  • Loading branch information
bors[bot] and phansch committed Oct 31, 2018
2 parents 73458ae + b421f5a commit 6a165e5
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
@@ -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> {
@@ -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;
Loading

0 comments on commit 6a165e5

Please sign in to comment.