1 // aux-build:option_helpers.rs
4 #![warn(clippy::all, clippy::pedantic)]
6 clippy::blacklisted_name,
7 clippy::default_trait_access,
8 clippy::missing_docs_in_private_items,
9 clippy::missing_safety_doc,
10 clippy::non_ascii_literal,
11 clippy::new_without_default,
12 clippy::needless_pass_by_value,
14 clippy::must_use_candidate,
16 clippy::useless_format,
17 clippy::wrong_self_convention,
23 extern crate option_helpers;
25 use std::collections::BTreeMap;
26 use std::collections::HashMap;
27 use std::collections::HashSet;
28 use std::collections::VecDeque;
29 use std::iter::FromIterator;
31 use std::rc::{self, Rc};
32 use std::sync::{self, Arc};
34 use option_helpers::IteratorFalsePositives;
39 pub fn add(self, other: T) -> T {
43 // no error, not public interface
44 pub(crate) fn drop(&mut self) {}
46 // no error, private function
47 fn neg(self) -> Self {
51 // no error, private function
52 fn eq(&self, other: T) -> bool {
56 // No error; self is a ref.
57 fn sub(&self, other: T) -> &T {
61 // No error; different number of arguments.
66 // No error; wrong return type.
67 fn rem(self, other: T) {}
70 fn into_u32(self) -> u32 {
74 fn into_u16(&self) -> u16 {
78 fn to_something(self) -> u32 {
82 fn new(self) -> Self {
90 // Shouldn't trigger lint as it is unsafe.
91 pub unsafe fn add(self, rhs: T1) -> T1 {
95 // Should not trigger lint since this is an async function.
96 pub async fn next(&mut self) -> Option<T1> {
106 // The lifetime is different, but that’s irrelevant; see issue #734.
107 #[allow(clippy::needless_lifetimes)]
108 pub fn new<'b>(s: &'b str) -> Lt<'b> {
118 // The lifetime is different, but that’s irrelevant; see issue #734.
119 pub fn new(s: &str) -> Lt2 {
129 // The lifetime is different, but that’s irrelevant; see issue #734.
130 pub fn new() -> Lt3<'static> {
135 #[derive(Clone, Copy)]
142 // Ok because `U` is `Copy`.
143 fn to_something(self) -> u32 {
153 fn new() -> Option<V<T>> {
161 async fn new() -> Option<Self> {
176 // No error, obviously.
177 fn mul(self, other: T) -> T {
182 /// Checks implementation of `FILTER_NEXT` lint.
185 let v = vec![3, 2, 1, 0, -1, -2, -3];
188 let _ = v.iter().filter(|&x| *x < 0).next();
191 let _ = v.iter().filter(|&x| {
196 // Check that hat we don't lint if the caller is not an `Iterator`.
197 let foo = IteratorFalsePositives { foo: 0 };
198 let _ = foo.filter().next();
201 /// Checks implementation of `SEARCH_IS_SOME` lint.
203 fn search_is_some() {
204 let v = vec![3, 2, 1, 0, -1, -2, -3];
207 // Check `find().is_some()`, single-line case.
208 let _ = v.iter().find(|&x| *x < 0).is_some();
209 let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less
210 let _ = (0..1).find(|x| *x == 0).is_some();
211 let _ = v.iter().find(|x| **x == 0).is_some();
213 // Check `find().is_some()`, multi-line case.
214 let _ = v.iter().find(|&x| {
219 // Check `position().is_some()`, single-line case.
220 let _ = v.iter().position(|&x| x < 0).is_some();
222 // Check `position().is_some()`, multi-line case.
223 let _ = v.iter().position(|&x| {
228 // Check `rposition().is_some()`, single-line case.
229 let _ = v.iter().rposition(|&x| x < 0).is_some();
231 // Check `rposition().is_some()`, multi-line case.
232 let _ = v.iter().rposition(|&x| {
237 // Check that we don't lint if the caller is not an `Iterator`.
238 let foo = IteratorFalsePositives { foo: 0 };
239 let _ = foo.find().is_some();
240 let _ = foo.position().is_some();
241 let _ = foo.rposition().is_some();