2023-04-20 09:37:15 -05:00
|
|
|
//@aux-build:option_helpers.rs
|
2021-03-20 08:30:45 -05:00
|
|
|
#![warn(clippy::search_is_some)]
|
2024-06-11 14:56:14 -05:00
|
|
|
#![allow(clippy::manual_pattern_char_comparison)]
|
2023-06-06 15:56:57 -05:00
|
|
|
#![allow(clippy::useless_vec)]
|
2021-03-20 08:30:45 -05:00
|
|
|
#![allow(dead_code)]
|
2020-10-17 16:07:22 -05:00
|
|
|
extern crate option_helpers;
|
|
|
|
use option_helpers::IteratorFalsePositives;
|
2023-07-27 06:40:22 -05:00
|
|
|
//@no-rustfix
|
2020-10-17 16:07:22 -05:00
|
|
|
#[rustfmt::skip]
|
|
|
|
fn main() {
|
|
|
|
let v = vec![3, 2, 1, 0, -1, -2, -3];
|
|
|
|
let y = &&42;
|
|
|
|
|
|
|
|
|
|
|
|
// Check `find().is_some()`, multi-line case.
|
|
|
|
let _ = v.iter().find(|&x| {
|
|
|
|
*x < 0
|
|
|
|
}
|
|
|
|
).is_some();
|
|
|
|
|
|
|
|
// Check `position().is_some()`, multi-line case.
|
|
|
|
let _ = v.iter().position(|&x| {
|
|
|
|
x < 0
|
|
|
|
}
|
|
|
|
).is_some();
|
|
|
|
|
|
|
|
// Check `rposition().is_some()`, multi-line case.
|
|
|
|
let _ = v.iter().rposition(|&x| {
|
|
|
|
x < 0
|
|
|
|
}
|
|
|
|
).is_some();
|
|
|
|
|
|
|
|
// Check that we don't lint if the caller is not an `Iterator` or string
|
2020-11-11 00:48:01 -06:00
|
|
|
let falsepos = IteratorFalsePositives { foo: 0 };
|
|
|
|
let _ = falsepos.find().is_some();
|
|
|
|
let _ = falsepos.position().is_some();
|
|
|
|
let _ = falsepos.rposition().is_some();
|
2020-10-17 16:07:22 -05:00
|
|
|
// check that we don't lint if `find()` is called with
|
|
|
|
// `Pattern` that is not a string
|
|
|
|
let _ = "hello world".find(|c: char| c == 'o' || c == 'l').is_some();
|
2021-10-20 15:04:56 -05:00
|
|
|
|
|
|
|
let some_closure = |x: &u32| *x == 0;
|
|
|
|
let _ = (0..1).find(some_closure).is_some();
|
2020-10-17 16:07:22 -05:00
|
|
|
}
|
2021-03-20 08:30:45 -05:00
|
|
|
|
|
|
|
#[rustfmt::skip]
|
|
|
|
fn is_none() {
|
|
|
|
let v = vec![3, 2, 1, 0, -1, -2, -3];
|
|
|
|
let y = &&42;
|
|
|
|
|
|
|
|
|
|
|
|
// Check `find().is_none()`, multi-line case.
|
|
|
|
let _ = v.iter().find(|&x| {
|
|
|
|
*x < 0
|
|
|
|
}
|
|
|
|
).is_none();
|
|
|
|
|
|
|
|
// Check `position().is_none()`, multi-line case.
|
|
|
|
let _ = v.iter().position(|&x| {
|
|
|
|
x < 0
|
|
|
|
}
|
|
|
|
).is_none();
|
|
|
|
|
|
|
|
// Check `rposition().is_none()`, multi-line case.
|
|
|
|
let _ = v.iter().rposition(|&x| {
|
|
|
|
x < 0
|
|
|
|
}
|
|
|
|
).is_none();
|
|
|
|
|
|
|
|
// Check that we don't lint if the caller is not an `Iterator` or string
|
|
|
|
let falsepos = IteratorFalsePositives { foo: 0 };
|
|
|
|
let _ = falsepos.find().is_none();
|
|
|
|
let _ = falsepos.position().is_none();
|
|
|
|
let _ = falsepos.rposition().is_none();
|
|
|
|
// check that we don't lint if `find()` is called with
|
|
|
|
// `Pattern` that is not a string
|
|
|
|
let _ = "hello world".find(|c: char| c == 'o' || c == 'l').is_none();
|
2021-10-20 15:04:56 -05:00
|
|
|
|
|
|
|
let some_closure = |x: &u32| *x == 0;
|
|
|
|
let _ = (0..1).find(some_closure).is_none();
|
2021-03-20 08:30:45 -05:00
|
|
|
}
|