4 #![deny(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 {
131 println!("This should not happen!");
138 if y.len() == 0 { //no error because One does not have .is_empty()
139 println!("This should not happen either!");
142 let z : &TraitsToo = &y;
143 if z.len() > 0 { //no error, because TraitsToo has no .is_empty() method
144 println!("Nor should this!");
147 let has_is_empty = HasIsEmpty;
148 if has_is_empty.len() == 0 {
149 println!("Or this!");
151 if has_is_empty.len() != 0 {
152 println!("Or this!");
154 if has_is_empty.len() > 0 {
155 println!("Or this!");
157 assert!(!has_is_empty.is_empty());
159 let with_is_empty: &WithIsEmpty = &Wither;
160 if with_is_empty.len() == 0 {
161 println!("Or this!");
163 assert!(!with_is_empty.is_empty());
165 let has_wrong_is_empty = HasWrongIsEmpty;
166 if has_wrong_is_empty.len() == 0 { //no error as HasWrongIsEmpty does not have .is_empty()
167 println!("Or this!");
171 fn test_slice(b: &[u8]) {