]> git.proxmox.com Git - rustc.git/blame - src/tools/clippy/tests/ui/len_without_is_empty.rs
Merge tag 'debian/1.52.1+dfsg1-1_exp2' into proxmox/buster
[rustc.git] / src / tools / clippy / tests / ui / len_without_is_empty.rs
CommitLineData
f20569fa
XL
1#![warn(clippy::len_without_is_empty)]
2#![allow(dead_code, unused)]
3
4pub struct PubOne;
5
6impl PubOne {
7 pub fn len(&self) -> isize {
8 1
9 }
10}
11
12impl PubOne {
13 // A second impl for this struct -- the error span shouldn't mention this.
14 pub fn irrelevant(&self) -> bool {
15 false
16 }
17}
18
19// Identical to `PubOne`, but with an `allow` attribute on the impl complaining `len`.
20pub struct PubAllowed;
21
22#[allow(clippy::len_without_is_empty)]
23impl PubAllowed {
24 pub fn len(&self) -> isize {
25 1
26 }
27}
28
29// No `allow` attribute on this impl block, but that doesn't matter -- we only require one on the
30// impl containing `len`.
31impl PubAllowed {
32 pub fn irrelevant(&self) -> bool {
33 false
34 }
35}
36
37pub struct PubAllowedFn;
38
39impl PubAllowedFn {
40 #[allow(clippy::len_without_is_empty)]
41 pub fn len(&self) -> isize {
42 1
43 }
44}
45
46#[allow(clippy::len_without_is_empty)]
47pub struct PubAllowedStruct;
48
49impl PubAllowedStruct {
50 pub fn len(&self) -> isize {
51 1
52 }
53}
54
55pub trait PubTraitsToo {
56 fn len(&self) -> isize;
57}
58
59impl PubTraitsToo for One {
60 fn len(&self) -> isize {
61 0
62 }
63}
64
65pub struct HasIsEmpty;
66
67impl HasIsEmpty {
68 pub fn len(&self) -> isize {
69 1
70 }
71
72 fn is_empty(&self) -> bool {
73 false
74 }
75}
76
77pub struct HasWrongIsEmpty;
78
79impl HasWrongIsEmpty {
80 pub fn len(&self) -> isize {
81 1
82 }
83
84 pub fn is_empty(&self, x: u32) -> bool {
85 false
86 }
87}
88
89pub struct MismatchedSelf;
90
91impl MismatchedSelf {
92 pub fn len(self) -> isize {
93 1
94 }
95
96 pub fn is_empty(&self) -> bool {
97 false
98 }
99}
100
101struct NotPubOne;
102
103impl NotPubOne {
104 pub fn len(&self) -> isize {
105 // No error; `len` is pub but `NotPubOne` is not exported anyway.
106 1
107 }
108}
109
110struct One;
111
112impl One {
113 fn len(&self) -> isize {
114 // No error; `len` is private; see issue #1085.
115 1
116 }
117}
118
119trait TraitsToo {
120 fn len(&self) -> isize;
121 // No error; `len` is private; see issue #1085.
122}
123
124impl TraitsToo for One {
125 fn len(&self) -> isize {
126 0
127 }
128}
129
130struct HasPrivateIsEmpty;
131
132impl HasPrivateIsEmpty {
133 pub fn len(&self) -> isize {
134 1
135 }
136
137 fn is_empty(&self) -> bool {
138 false
139 }
140}
141
142struct Wither;
143
144pub trait WithIsEmpty {
145 fn len(&self) -> isize;
146 fn is_empty(&self) -> bool;
147}
148
149impl WithIsEmpty for Wither {
150 fn len(&self) -> isize {
151 1
152 }
153
154 fn is_empty(&self) -> bool {
155 false
156 }
157}
158
159pub trait Empty {
160 fn is_empty(&self) -> bool;
161}
162
163pub trait InheritingEmpty: Empty {
164 // Must not trigger `LEN_WITHOUT_IS_EMPTY`.
165 fn len(&self) -> isize;
166}
167
168// This used to ICE.
169pub trait Foo: Sized {}
170
171pub trait DependsOnFoo: Foo {
172 fn len(&mut self) -> usize;
173}
174
175pub struct MultipleImpls;
176
177// issue #1562
178impl MultipleImpls {
179 pub fn len(&self) -> usize {
180 1
181 }
182}
183
184impl MultipleImpls {
185 pub fn is_empty(&self) -> bool {
186 false
187 }
188}
189
190fn main() {}