4 #![warn(len_without_is_empty, len_zero)]
5 #![allow(dead_code, unused)]
10 pub fn len(self: &Self) -> isize {
15 impl PubOne { // A second impl for this struct - the error span shouldn't mention this
16 pub fn irrelevant(self: &Self) -> bool {
21 // Identical to PubOne, but with an allow attribute on the impl complaining len
22 pub struct PubAllowed;
24 #[allow(len_without_is_empty)]
26 pub fn len(self: &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: &Self) -> bool {
42 pub fn len(self: &Self) -> isize { // no error, len is pub but `NotPubOne` is not exported anyway
50 fn len(self: &Self) -> isize { // no error, len is private, see #1085
55 pub trait PubTraitsToo {
56 fn len(self: &Self) -> isize;
59 impl PubTraitsToo for One {
60 fn len(self: &Self) -> isize {
66 fn len(self: &Self) -> isize; // no error, len is private, see #1085
69 impl TraitsToo for One {
70 fn len(self: &Self) -> isize {
75 struct HasPrivateIsEmpty;
77 impl HasPrivateIsEmpty {
78 pub fn len(self: &Self) -> isize {
82 fn is_empty(self: &Self) -> bool {
87 pub struct HasIsEmpty;
90 pub fn len(self: &Self) -> isize {
94 fn is_empty(self: &Self) -> bool {
101 pub trait WithIsEmpty {
102 fn len(self: &Self) -> isize;
103 fn is_empty(self: &Self) -> bool;
106 impl WithIsEmpty for Wither {
107 fn len(self: &Self) -> isize {
111 fn is_empty(self: &Self) -> bool {
116 pub struct HasWrongIsEmpty;
118 impl HasWrongIsEmpty {
119 pub fn len(self: &Self) -> isize {
123 pub fn is_empty(self: &Self, x : u32) -> bool {
129 fn is_empty(&self) -> bool;
132 pub trait InheritingEmpty: Empty { //must not trigger LEN_WITHOUT_IS_EMPTY
133 fn len(&self) -> isize;
141 println!("This should not happen!");
148 if y.len() == 0 { //no error because One does not have .is_empty()
149 println!("This should not happen either!");
152 let z : &TraitsToo = &y;
153 if z.len() > 0 { //no error, because TraitsToo has no .is_empty() method
154 println!("Nor should this!");
157 let has_is_empty = HasIsEmpty;
158 if has_is_empty.len() == 0 {
159 println!("Or this!");
161 if has_is_empty.len() != 0 {
162 println!("Or this!");
164 if has_is_empty.len() > 0 {
165 println!("Or this!");
167 assert!(!has_is_empty.is_empty());
169 let with_is_empty: &WithIsEmpty = &Wither;
170 if with_is_empty.len() == 0 {
171 println!("Or this!");
173 assert!(!with_is_empty.is_empty());
175 let has_wrong_is_empty = HasWrongIsEmpty;
176 if has_wrong_is_empty.len() == 0 { //no error as HasWrongIsEmpty does not have .is_empty()
177 println!("Or this!");
181 fn test_slice(b: &[u8]) {
187 pub trait Foo: Sized {}
189 pub trait DependsOnFoo: Foo {
190 fn len(&mut self) -> usize;