Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UI test cleanup: Extract for_loop_over_x tests #3392

Merged
merged 1 commit into from
Oct 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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