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