1 #![warn(clippy::len_without_is_empty)]
2 #![allow(dead_code, unused)]
7 pub fn len(&self) -> isize {
13 // A second impl for this struct -- the error span shouldn't mention this.
14 pub fn irrelevant(&self) -> bool {
19 // Identical to `PubOne`, but with an `allow` attribute on the impl complaining `len`.
20 pub struct PubAllowed;
22 #[allow(clippy::len_without_is_empty)]
24 pub fn len(&self) -> isize {
29 // No `allow` attribute on this impl block, but that doesn't matter -- we only require one on the
30 // impl containing `len`.
32 pub fn irrelevant(&self) -> bool {
37 pub struct PubAllowedFn;
40 #[allow(clippy::len_without_is_empty)]
41 pub fn len(&self) -> isize {
46 #[allow(clippy::len_without_is_empty)]
47 pub struct PubAllowedStruct;
49 impl PubAllowedStruct {
50 pub fn len(&self) -> isize {
55 pub trait PubTraitsToo {
56 fn len(&self) -> isize;
59 impl PubTraitsToo for One {
60 fn len(&self) -> isize {
65 pub struct HasIsEmpty;
68 pub fn len(&self) -> isize {
72 fn is_empty(&self) -> bool {
77 pub struct HasWrongIsEmpty;
79 impl HasWrongIsEmpty {
80 pub fn len(&self) -> isize {
84 pub fn is_empty(&self, x: u32) -> bool {
89 pub struct MismatchedSelf;
92 pub fn len(self) -> isize {
96 pub fn is_empty(&self) -> bool {
104 pub fn len(&self) -> isize {
105 // No error; `len` is pub but `NotPubOne` is not exported anyway.
113 fn len(&self) -> isize {
114 // No error; `len` is private; see issue #1085.
120 fn len(&self) -> isize;
121 // No error; `len` is private; see issue #1085.
124 impl TraitsToo for One {
125 fn len(&self) -> isize {
130 struct HasPrivateIsEmpty;
132 impl HasPrivateIsEmpty {
133 pub fn len(&self) -> isize {
137 fn is_empty(&self) -> bool {
144 pub trait WithIsEmpty {
145 fn len(&self) -> isize;
146 fn is_empty(&self) -> bool;
149 impl WithIsEmpty for Wither {
150 fn len(&self) -> isize {
154 fn is_empty(&self) -> bool {
160 fn is_empty(&self) -> bool;
163 pub trait InheritingEmpty: Empty {
164 // Must not trigger `LEN_WITHOUT_IS_EMPTY`.
165 fn len(&self) -> isize;
169 pub trait Foo: Sized {}
171 pub trait DependsOnFoo: Foo {
172 fn len(&mut self) -> usize;
176 pub struct MultipleImpls;
179 pub fn len(&self) -> usize {
185 pub fn is_empty(&self) -> bool {
191 pub struct OptionalLen;
194 pub fn len(&self) -> Option<usize> {
198 pub fn is_empty(&self) -> Option<bool> {
203 pub struct OptionalLen2;
205 pub fn len(&self) -> Option<usize> {
209 pub fn is_empty(&self) -> bool {
214 pub struct OptionalLen3;
216 pub fn len(&self) -> usize {
220 // should lint, len is not an option
221 pub fn is_empty(&self) -> Option<bool> {
226 pub struct ResultLen;
228 pub fn len(&self) -> Result<usize, ()> {
232 // Differing result types
233 pub fn is_empty(&self) -> Option<bool> {
238 pub struct ResultLen2;
240 pub fn len(&self) -> Result<usize, ()> {
244 pub fn is_empty(&self) -> Result<bool, ()> {
249 pub struct ResultLen3;
251 pub fn len(&self) -> Result<usize, ()> {
255 // Non-fallible result is ok.
256 pub fn is_empty(&self) -> bool {
261 pub struct OddLenSig;
264 pub fn len(&self) -> bool {
272 async fn async_task(&self) -> bool {
276 pub async fn len(&self) -> usize {
277 if self.async_task().await { 0 } else { 1 }
280 pub async fn is_empty(&self) -> bool {
281 self.len().await == 0