]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/methods.rs
New upstream version 1.63.0+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / methods.rs
CommitLineData
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]
23extern crate option_helpers;
24
25use std::collections::BTreeMap;
26use std::collections::HashMap;
27use std::collections::HashSet;
28use std::collections::VecDeque;
f20569fa
XL
29use std::ops::Mul;
30use std::rc::{self, Rc};
31use std::sync::{self, Arc};
32
c295e0f8 33use option_helpers::{IteratorFalsePositives, IteratorMethodFalsePositives};
f20569fa
XL
34
35struct Lt<'a> {
36 foo: &'a u32,
37}
38
39impl<'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
47struct Lt2<'a> {
48 foo: &'a u32,
49}
50
51impl<'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
58struct Lt3<'a> {
59 foo: &'a u32,
60}
61
62impl<'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)]
70struct U;
71
72impl 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
82struct V<T> {
83 _dummy: T,
84}
85
86impl<T> V<T> {
87 fn new() -> Option<V<T>> {
88 None
89 }
90}
91
92struct AsyncNew;
93
94impl AsyncNew {
95 async fn new() -> Option<Self> {
96 None
97 }
98}
99
100struct BadNew;
101
102impl BadNew {
103 fn new() -> i32 {
104 0
105 }
106}
107
108struct T;
109
110impl 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]
120fn 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
137fn main() {
138 filter_next();
139}