3 #![warn(clippy::len_zero)]
4 #![allow(dead_code, unused, clippy::len_without_is_empty)]
13 fn len(&self) -> isize;
14 // No error; `len` is private; see issue #1085.
17 impl TraitsToo for One {
18 fn len(&self) -> isize {
23 pub struct HasIsEmpty;
26 pub fn len(&self) -> isize {
30 fn is_empty(&self) -> bool {
35 pub struct HasWrongIsEmpty;
37 impl HasWrongIsEmpty {
38 pub fn len(&self) -> isize {
42 pub fn is_empty(&self, x: u32) -> bool {
47 pub trait WithIsEmpty {
48 fn len(&self) -> isize;
49 fn is_empty(&self) -> bool;
52 impl WithIsEmpty for Wither {
53 fn len(&self) -> isize {
57 fn is_empty(&self) -> bool {
62 struct DerefToDerefToString;
64 impl Deref for DerefToDerefToString {
65 type Target = DerefToString;
67 fn deref(&self) -> &Self::Target {
74 impl Deref for DerefToString {
77 fn deref(&self) -> &Self::Target {
85 println!("This should not happen!");
90 let s = "Hello, world!";
97 println!("{}", *s1 == "");
98 println!("{}", **s2 == "");
99 println!("{}", ***s3 == "");
100 println!("{}", ****s4 == "");
101 println!("{}", *****s5 == "");
102 println!("{}", ******(s6) == "");
104 let d2s = DerefToDerefToString {};
105 println!("{}", &**d2s == "");
109 // No error; `One` does not have `.is_empty()`.
110 println!("This should not happen either!");
113 let z: &dyn TraitsToo = &y;
115 // No error; `TraitsToo` has no `.is_empty()` method.
116 println!("Nor should this!");
119 let has_is_empty = HasIsEmpty;
120 if has_is_empty.len() == 0 {
121 println!("Or this!");
123 if has_is_empty.len() != 0 {
124 println!("Or this!");
126 if has_is_empty.len() > 0 {
127 println!("Or this!");
129 if has_is_empty.len() < 1 {
130 println!("Or this!");
132 if has_is_empty.len() >= 1 {
133 println!("Or this!");
135 if has_is_empty.len() > 1 {
137 println!("This can happen.");
139 if has_is_empty.len() <= 1 {
141 println!("This can happen.");
143 if 0 == has_is_empty.len() {
144 println!("Or this!");
146 if 0 != has_is_empty.len() {
147 println!("Or this!");
149 if 0 < has_is_empty.len() {
150 println!("Or this!");
152 if 1 <= has_is_empty.len() {
153 println!("Or this!");
155 if 1 > has_is_empty.len() {
156 println!("Or this!");
158 if 1 < has_is_empty.len() {
160 println!("This can happen.");
162 if 1 >= has_is_empty.len() {
164 println!("This can happen.");
166 assert!(!has_is_empty.is_empty());
168 let with_is_empty: &dyn WithIsEmpty = &Wither;
169 if with_is_empty.len() == 0 {
170 println!("Or this!");
172 assert!(!with_is_empty.is_empty());
174 let has_wrong_is_empty = HasWrongIsEmpty;
175 if has_wrong_is_empty.len() == 0 {
176 // No error; `HasWrongIsEmpty` does not have `.is_empty()`.
177 println!("Or this!");
181 fn test_slice(b: &[u8]) {