3 #![warn(clippy::len_without_is_empty)]
4 #![allow(dead_code, unused)]
9 pub fn len(&self) -> isize {
15 // A second impl for this struct -- the error span shouldn't mention this.
16 pub fn irrelevant(&self) -> bool {
21 // Identical to `PubOne`, but with an `allow` attribute on the impl complaining `len`.
22 pub struct PubAllowed;
24 #[allow(clippy::len_without_is_empty)]
26 pub fn len(&self) -> isize {
31 // No `allow` attribute on this impl block, but that doesn't matter -- we only require one on the
32 // impl containing `len`.
34 pub fn irrelevant(&self) -> bool {
39 pub struct PubAllowedFn;
42 #[allow(clippy::len_without_is_empty)]
43 pub fn len(&self) -> isize {
48 #[allow(clippy::len_without_is_empty)]
49 pub struct PubAllowedStruct;
51 impl PubAllowedStruct {
52 pub fn len(&self) -> isize {
57 pub trait PubTraitsToo {
58 fn len(&self) -> isize;
61 impl PubTraitsToo for One {
62 fn len(&self) -> isize {
67 pub struct HasIsEmpty;
70 pub fn len(&self) -> isize {
74 fn is_empty(&self) -> bool {
79 pub struct HasWrongIsEmpty;
81 impl HasWrongIsEmpty {
82 pub fn len(&self) -> isize {
86 pub fn is_empty(&self, x: u32) -> bool {
91 pub struct MismatchedSelf;
94 pub fn len(self) -> isize {
98 pub fn is_empty(&self) -> bool {
106 pub fn len(&self) -> isize {
107 // No error; `len` is pub but `NotPubOne` is not exported anyway.
115 fn len(&self) -> isize {
116 // No error; `len` is private; see issue #1085.
122 fn len(&self) -> isize;
123 // No error; `len` is private; see issue #1085.
126 impl TraitsToo for One {
127 fn len(&self) -> isize {
132 struct HasPrivateIsEmpty;
134 impl HasPrivateIsEmpty {
135 pub fn len(&self) -> isize {
139 fn is_empty(&self) -> bool {
146 pub trait WithIsEmpty {
147 fn len(&self) -> isize;
148 fn is_empty(&self) -> bool;
151 impl WithIsEmpty for Wither {
152 fn len(&self) -> isize {
156 fn is_empty(&self) -> bool {
162 fn is_empty(&self) -> bool;
165 pub trait InheritingEmpty: Empty {
166 // Must not trigger `LEN_WITHOUT_IS_EMPTY`.
167 fn len(&self) -> isize;
171 pub trait Foo: Sized {}
173 pub trait DependsOnFoo: Foo {
174 fn len(&mut self) -> usize;
178 pub struct MultipleImpls;
181 pub fn len(&self) -> usize {
187 pub fn is_empty(&self) -> bool {
193 pub struct OptionalLen;
196 pub fn len(&self) -> Option<usize> {
200 pub fn is_empty(&self) -> Option<bool> {
205 pub struct OptionalLen2;
207 pub fn len(&self) -> Option<usize> {
211 pub fn is_empty(&self) -> bool {
216 pub struct OptionalLen3;
218 pub fn len(&self) -> usize {
222 // should lint, len is not an option
223 pub fn is_empty(&self) -> Option<bool> {
228 pub struct ResultLen;
230 pub fn len(&self) -> Result<usize, ()> {
234 // Differing result types
235 pub fn is_empty(&self) -> Option<bool> {
240 pub struct ResultLen2;
242 pub fn len(&self) -> Result<usize, ()> {
246 pub fn is_empty(&self) -> Result<bool, ()> {
251 pub struct ResultLen3;
253 pub fn len(&self) -> Result<usize, ()> {
257 // Non-fallible result is ok.
258 pub fn is_empty(&self) -> bool {
263 pub struct OddLenSig;
266 pub fn len(&self) -> bool {
274 async fn async_task(&self) -> bool {
278 pub async fn len(&self) -> usize {
279 if self.async_task().await { 0 } else { 1 }
282 pub async fn is_empty(&self) -> bool {
283 self.len().await == 0