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 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 {
134 println!("This should not happen!");
144 if y.len() == 0 { //no error because One does not have .is_empty()
145 println!("This should not happen either!");
148 let z : &TraitsToo = &y;
149 if z.len() > 0 { //no error, because TraitsToo has no .is_empty() method
150 println!("Nor should this!");
153 let has_is_empty = HasIsEmpty;
154 if has_is_empty.len() == 0 {
158 println!("Or this!");
160 if has_is_empty.len() != 0 {
164 println!("Or this!");
166 if has_is_empty.len() > 0 {
170 println!("Or this!");
172 assert!(!has_is_empty.is_empty());
174 let with_is_empty: &WithIsEmpty = &Wither;
175 if with_is_empty.len() == 0 {
179 println!("Or this!");
181 assert!(!with_is_empty.is_empty());
183 let has_wrong_is_empty = HasWrongIsEmpty;
184 if has_wrong_is_empty.len() == 0 { //no error as HasWrongIsEmpty does not have .is_empty()
185 println!("Or this!");