2020-10-17 16:07:22 -05:00
|
|
|
// run-rustfix
|
2021-03-20 08:30:45 -05:00
|
|
|
#![allow(dead_code)]
|
2020-10-17 16:07:22 -05:00
|
|
|
#![warn(clippy::search_is_some)]
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let v = vec![3, 2, 1, 0, -1, -2, -3];
|
2021-08-18 09:51:34 -05:00
|
|
|
let y = &&42;
|
2020-10-17 16:28:00 -05:00
|
|
|
|
2020-10-17 16:07:22 -05:00
|
|
|
// Check `find().is_some()`, single-line case.
|
|
|
|
let _ = v.iter().find(|&x| *x < 0).is_some();
|
2021-08-18 09:51:34 -05:00
|
|
|
let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less
|
|
|
|
let _ = (0..1).find(|x| *x == 0).is_some();
|
|
|
|
let _ = v.iter().find(|x| **x == 0).is_some();
|
|
|
|
let _ = (4..5).find(|x| *x == 1 || *x == 3 || *x == 5).is_some();
|
|
|
|
let _ = (1..3).find(|x| [1, 2, 3].contains(x)).is_some();
|
|
|
|
let _ = (1..3).find(|x| *x == 0 || [1, 2, 3].contains(x)).is_some();
|
|
|
|
let _ = (1..3).find(|x| [1, 2, 3].contains(x) || *x == 0).is_some();
|
|
|
|
let _ = (1..3)
|
|
|
|
.find(|x| [1, 2, 3].contains(x) || *x == 0 || [4, 5, 6].contains(x) || *x == -1)
|
|
|
|
.is_some();
|
2020-10-17 16:28:00 -05:00
|
|
|
|
2020-10-17 16:07:22 -05:00
|
|
|
// Check `position().is_some()`, single-line case.
|
|
|
|
let _ = v.iter().position(|&x| x < 0).is_some();
|
2020-10-17 16:28:00 -05:00
|
|
|
|
2020-10-17 16:07:22 -05:00
|
|
|
// Check `rposition().is_some()`, single-line case.
|
|
|
|
let _ = v.iter().rposition(|&x| x < 0).is_some();
|
|
|
|
|
|
|
|
let s1 = String::from("hello world");
|
|
|
|
let s2 = String::from("world");
|
|
|
|
// caller of `find()` is a `&`static str`
|
|
|
|
let _ = "hello world".find("world").is_some();
|
|
|
|
let _ = "hello world".find(&s2).is_some();
|
|
|
|
let _ = "hello world".find(&s2[2..]).is_some();
|
|
|
|
// caller of `find()` is a `String`
|
|
|
|
let _ = s1.find("world").is_some();
|
|
|
|
let _ = s1.find(&s2).is_some();
|
|
|
|
let _ = s1.find(&s2[2..]).is_some();
|
|
|
|
// caller of `find()` is slice of `String`
|
|
|
|
let _ = s1[2..].find("world").is_some();
|
|
|
|
let _ = s1[2..].find(&s2).is_some();
|
|
|
|
let _ = s1[2..].find(&s2[2..]).is_some();
|
|
|
|
}
|
2021-03-20 08:30:45 -05:00
|
|
|
|
2021-08-18 09:51:34 -05:00
|
|
|
#[allow(clippy::clone_on_copy, clippy::map_clone)]
|
|
|
|
mod issue7392 {
|
|
|
|
struct Player {
|
|
|
|
hand: Vec<usize>,
|
|
|
|
}
|
|
|
|
fn filter() {
|
|
|
|
let p = Player {
|
|
|
|
hand: vec![1, 2, 3, 4, 5],
|
|
|
|
};
|
|
|
|
let filter_hand = vec![5];
|
|
|
|
let _ = p
|
|
|
|
.hand
|
|
|
|
.iter()
|
2021-08-19 03:38:40 -05:00
|
|
|
.filter(|c| filter_hand.iter().find(|cc| c == cc).is_some())
|
2021-08-18 09:51:34 -05:00
|
|
|
.map(|c| c.clone())
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
}
|
|
|
|
|
|
|
|
struct PlayerTuple {
|
|
|
|
hand: Vec<(usize, char)>,
|
|
|
|
}
|
|
|
|
fn filter_tuple() {
|
|
|
|
let p = PlayerTuple {
|
|
|
|
hand: vec![(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e')],
|
|
|
|
};
|
|
|
|
let filter_hand = vec![5];
|
|
|
|
let _ = p
|
|
|
|
.hand
|
|
|
|
.iter()
|
2021-08-19 03:38:40 -05:00
|
|
|
.filter(|(c, _)| filter_hand.iter().find(|cc| c == *cc).is_some())
|
2021-08-18 09:51:34 -05:00
|
|
|
.map(|c| c.clone())
|
|
|
|
.collect::<Vec<_>>();
|
|
|
|
}
|
|
|
|
}
|