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::non_ascii_literal,
10 clippy::new_without_default,
11 clippy::needless_pass_by_value,
13 clippy::must_use_candidate,
15 clippy::useless_format,
16 clippy::wrong_self_convention,
22 extern crate option_helpers;
24 use std::collections::BTreeMap;
25 use std::collections::HashMap;
26 use std::collections::HashSet;
27 use std::collections::VecDeque;
28 use std::iter::FromIterator;
30 use std::rc::{self, Rc};
31 use std::sync::{self, Arc};
33 use option_helpers::IteratorFalsePositives;
38 pub fn add(self, other: T) -> T {
42 // no error, not public interface
43 pub(crate) fn drop(&mut self) {}
45 // no error, private function
46 fn neg(self) -> Self {
50 // no error, private function
51 fn eq(&self, other: T) -> bool {
55 // No error; self is a ref.
56 fn sub(&self, other: T) -> &T {
60 // No error; different number of arguments.
65 // No error; wrong return type.
66 fn rem(self, other: T) {}
69 fn into_u32(self) -> u32 {
73 fn into_u16(&self) -> u16 {
77 fn to_something(self) -> u32 {
81 fn new(self) -> Self {
91 // The lifetime is different, but that’s irrelevant; see issue #734.
92 #[allow(clippy::needless_lifetimes)]
93 pub fn new<'b>(s: &'b str) -> Lt<'b> {
103 // The lifetime is different, but that’s irrelevant; see issue #734.
104 pub fn new(s: &str) -> Lt2 {
114 // The lifetime is different, but that’s irrelevant; see issue #734.
115 pub fn new() -> Lt3<'static> {
120 #[derive(Clone, Copy)]
127 // Ok because `U` is `Copy`.
128 fn to_something(self) -> u32 {
138 fn new() -> Option<V<T>> {
146 async fn new() -> Option<Self> {
161 // No error, obviously.
162 fn mul(self, other: T) -> T {
167 /// Checks implementation of `FILTER_NEXT` lint.
170 let v = vec![3, 2, 1, 0, -1, -2, -3];
173 let _ = v.iter().filter(|&x| *x < 0).next();
176 let _ = v.iter().filter(|&x| {
181 // Check that hat we don't lint if the caller is not an `Iterator`.
182 let foo = IteratorFalsePositives { foo: 0 };
183 let _ = foo.filter().next();
186 /// Checks implementation of `SEARCH_IS_SOME` lint.
188 fn search_is_some() {
189 let v = vec![3, 2, 1, 0, -1, -2, -3];
192 // Check `find().is_some()`, single-line case.
193 let _ = v.iter().find(|&x| *x < 0).is_some();
194 let _ = (0..1).find(|x| **y == *x).is_some(); // one dereference less
195 let _ = (0..1).find(|x| *x == 0).is_some();
196 let _ = v.iter().find(|x| **x == 0).is_some();
198 // Check `find().is_some()`, multi-line case.
199 let _ = v.iter().find(|&x| {
204 // Check `position().is_some()`, single-line case.
205 let _ = v.iter().position(|&x| x < 0).is_some();
207 // Check `position().is_some()`, multi-line case.
208 let _ = v.iter().position(|&x| {
213 // Check `rposition().is_some()`, single-line case.
214 let _ = v.iter().rposition(|&x| x < 0).is_some();
216 // Check `rposition().is_some()`, multi-line case.
217 let _ = v.iter().rposition(|&x| {
222 // Check that we don't lint if the caller is not an `Iterator`.
223 let foo = IteratorFalsePositives { foo: 0 };
224 let _ = foo.find().is_some();
225 let _ = foo.position().is_some();
226 let _ = foo.rposition().is_some();