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