2020-10-17 16:28:00 -05:00
|
|
|
// run-rustfix
|
2021-03-20 08:30:45 -05:00
|
|
|
#![allow(dead_code)]
|
2020-10-17 16:28:00 -05:00
|
|
|
#![warn(clippy::search_is_some)]
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let v = vec![3, 2, 1, 0, -1, -2, -3];
|
|
|
|
|
|
|
|
// Check `find().is_some()`, single-line case.
|
|
|
|
let _ = v.iter().any(|x| *x < 0);
|
|
|
|
|
|
|
|
// Check `position().is_some()`, single-line case.
|
|
|
|
let _ = v.iter().any(|&x| x < 0);
|
|
|
|
|
|
|
|
// Check `rposition().is_some()`, single-line case.
|
|
|
|
let _ = v.iter().any(|&x| x < 0);
|
|
|
|
|
|
|
|
let s1 = String::from("hello world");
|
|
|
|
let s2 = String::from("world");
|
|
|
|
// caller of `find()` is a `&`static str`
|
|
|
|
let _ = "hello world".contains("world");
|
|
|
|
let _ = "hello world".contains(&s2);
|
|
|
|
let _ = "hello world".contains(&s2[2..]);
|
|
|
|
// caller of `find()` is a `String`
|
|
|
|
let _ = s1.contains("world");
|
|
|
|
let _ = s1.contains(&s2);
|
|
|
|
let _ = s1.contains(&s2[2..]);
|
|
|
|
// caller of `find()` is slice of `String`
|
|
|
|
let _ = s1[2..].contains("world");
|
|
|
|
let _ = s1[2..].contains(&s2);
|
|
|
|
let _ = s1[2..].contains(&s2[2..]);
|
|
|
|
}
|
2021-03-20 08:30:45 -05:00
|
|
|
|
|
|
|
fn is_none() {
|
|
|
|
let v = vec![3, 2, 1, 0, -1, -2, -3];
|
|
|
|
|
|
|
|
// Check `find().is_none()`, single-line case.
|
|
|
|
let _ = !v.iter().any(|x| *x < 0);
|
|
|
|
|
|
|
|
// Check `position().is_none()`, single-line case.
|
|
|
|
let _ = !v.iter().any(|&x| x < 0);
|
|
|
|
|
|
|
|
// Check `rposition().is_none()`, single-line case.
|
|
|
|
let _ = !v.iter().any(|&x| x < 0);
|
|
|
|
|
|
|
|
let s1 = String::from("hello world");
|
|
|
|
let s2 = String::from("world");
|
|
|
|
|
|
|
|
// caller of `find()` is a `&`static str`
|
|
|
|
let _ = !"hello world".contains("world");
|
|
|
|
let _ = !"hello world".contains(&s2);
|
|
|
|
let _ = !"hello world".contains(&s2[2..]);
|
|
|
|
// caller of `find()` is a `String`
|
|
|
|
let _ = !s1.contains("world");
|
|
|
|
let _ = !s1.contains(&s2);
|
|
|
|
let _ = !s1.contains(&s2[2..]);
|
|
|
|
// caller of `find()` is slice of `String`
|
|
|
|
let _ = !s1[2..].contains("world");
|
|
|
|
let _ = !s1[2..].contains(&s2);
|
|
|
|
let _ = !s1[2..].contains(&s2[2..]);
|
|
|
|
}
|