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
Jump to file or symbol
Failed to load files and symbols.
+318 −306
Diff settings

Always

Just for now

Copy path View file
@@ -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;
Oops, something went wrong.
ProTip! Use n and p to navigate between commits in a pull request.