]>
Commit | Line | Data |
---|---|---|
f20569fa | 1 | // aux-build:option_helpers.rs |
f20569fa XL |
2 | |
3 | #![warn(clippy::all, clippy::pedantic)] | |
4 | #![allow( | |
5 | clippy::blacklisted_name, | |
6 | clippy::default_trait_access, | |
7 | clippy::missing_docs_in_private_items, | |
8 | clippy::missing_safety_doc, | |
9 | clippy::non_ascii_literal, | |
10 | clippy::new_without_default, | |
11 | clippy::needless_pass_by_value, | |
12 | clippy::needless_lifetimes, | |
13 | clippy::print_stdout, | |
14 | clippy::must_use_candidate, | |
15 | clippy::use_self, | |
16 | clippy::useless_format, | |
17 | clippy::wrong_self_convention, | |
18 | clippy::unused_self, | |
19 | unused | |
20 | )] | |
21 | ||
22 | #[macro_use] | |
23 | extern crate option_helpers; | |
24 | ||
25 | use std::collections::BTreeMap; | |
26 | use std::collections::HashMap; | |
27 | use std::collections::HashSet; | |
28 | use std::collections::VecDeque; | |
f20569fa XL |
29 | use std::ops::Mul; |
30 | use std::rc::{self, Rc}; | |
31 | use std::sync::{self, Arc}; | |
32 | ||
c295e0f8 | 33 | use option_helpers::{IteratorFalsePositives, IteratorMethodFalsePositives}; |
f20569fa XL |
34 | |
35 | struct Lt<'a> { | |
36 | foo: &'a u32, | |
37 | } | |
38 | ||
39 | impl<'a> Lt<'a> { | |
40 | // The lifetime is different, but that’s irrelevant; see issue #734. | |
41 | #[allow(clippy::needless_lifetimes)] | |
42 | pub fn new<'b>(s: &'b str) -> Lt<'b> { | |
43 | unimplemented!() | |
44 | } | |
45 | } | |
46 | ||
47 | struct Lt2<'a> { | |
48 | foo: &'a u32, | |
49 | } | |
50 | ||
51 | impl<'a> Lt2<'a> { | |
52 | // The lifetime is different, but that’s irrelevant; see issue #734. | |
53 | pub fn new(s: &str) -> Lt2 { | |
54 | unimplemented!() | |
55 | } | |
56 | } | |
57 | ||
58 | struct Lt3<'a> { | |
59 | foo: &'a u32, | |
60 | } | |
61 | ||
62 | impl<'a> Lt3<'a> { | |
63 | // The lifetime is different, but that’s irrelevant; see issue #734. | |
64 | pub fn new() -> Lt3<'static> { | |
65 | unimplemented!() | |
66 | } | |
67 | } | |
68 | ||
69 | #[derive(Clone, Copy)] | |
70 | struct U; | |
71 | ||
72 | impl U { | |
73 | fn new() -> Self { | |
74 | U | |
75 | } | |
76 | // Ok because `U` is `Copy`. | |
77 | fn to_something(self) -> u32 { | |
78 | 0 | |
79 | } | |
80 | } | |
81 | ||
82 | struct V<T> { | |
83 | _dummy: T, | |
84 | } | |
85 | ||
86 | impl<T> V<T> { | |
87 | fn new() -> Option<V<T>> { | |
88 | None | |
89 | } | |
90 | } | |
91 | ||
92 | struct AsyncNew; | |
93 | ||
94 | impl AsyncNew { | |
95 | async fn new() -> Option<Self> { | |
96 | None | |
97 | } | |
98 | } | |
99 | ||
100 | struct BadNew; | |
101 | ||
102 | impl BadNew { | |
103 | fn new() -> i32 { | |
104 | 0 | |
105 | } | |
106 | } | |
107 | ||
108 | struct T; | |
109 | ||
110 | impl Mul<T> for T { | |
111 | type Output = T; | |
112 | // No error, obviously. | |
113 | fn mul(self, other: T) -> T { | |
114 | self | |
115 | } | |
116 | } | |
117 | ||
118 | /// Checks implementation of `FILTER_NEXT` lint. | |
119 | #[rustfmt::skip] | |
120 | fn filter_next() { | |
121 | let v = vec![3, 2, 1, 0, -1, -2, -3]; | |
122 | ||
123 | // Multi-line case. | |
124 | let _ = v.iter().filter(|&x| { | |
125 | *x < 0 | |
126 | } | |
127 | ).next(); | |
128 | ||
129 | // Check that we don't lint if the caller is not an `Iterator`. | |
130 | let foo = IteratorFalsePositives { foo: 0 }; | |
131 | let _ = foo.filter().next(); | |
c295e0f8 XL |
132 | |
133 | let foo = IteratorMethodFalsePositives {}; | |
134 | let _ = foo.filter(42).next(); | |
f20569fa XL |
135 | } |
136 | ||
137 | fn main() { | |
138 | filter_next(); | |
139 | } |