3 #![warn(clippy::len_zero)]
4 #![allow(dead_code, unused, clippy::len_without_is_empty)]
10 fn len(&self) -> isize;
11 // No error; `len` is private; see issue #1085.
14 impl TraitsToo for One {
15 fn len(&self) -> isize {
20 pub struct HasIsEmpty;
23 pub fn len(&self) -> isize {
27 fn is_empty(&self) -> bool {
32 pub struct HasWrongIsEmpty;
34 impl HasWrongIsEmpty {
35 pub fn len(&self) -> isize {
39 pub fn is_empty(&self, x: u32) -> bool {
44 pub trait WithIsEmpty {
45 fn len(&self) -> isize;
46 fn is_empty(&self) -> bool;
49 impl WithIsEmpty for Wither {
50 fn len(&self) -> isize {
54 fn is_empty(&self) -> bool {
62 println!("This should not happen!");
69 // No error; `One` does not have `.is_empty()`.
70 println!("This should not happen either!");
73 let z: &dyn TraitsToo = &y;
75 // No error; `TraitsToo` has no `.is_empty()` method.
76 println!("Nor should this!");
79 let has_is_empty = HasIsEmpty;
80 if has_is_empty.len() == 0 {
83 if has_is_empty.len() != 0 {
86 if has_is_empty.len() > 0 {
89 if has_is_empty.len() < 1 {
92 if has_is_empty.len() >= 1 {
95 if has_is_empty.len() > 1 {
97 println!("This can happen.");
99 if has_is_empty.len() <= 1 {
101 println!("This can happen.");
103 if 0 == has_is_empty.len() {
104 println!("Or this!");
106 if 0 != has_is_empty.len() {
107 println!("Or this!");
109 if 0 < has_is_empty.len() {
110 println!("Or this!");
112 if 1 <= has_is_empty.len() {
113 println!("Or this!");
115 if 1 > has_is_empty.len() {
116 println!("Or this!");
118 if 1 < has_is_empty.len() {
120 println!("This can happen.");
122 if 1 >= has_is_empty.len() {
124 println!("This can happen.");
126 assert!(!has_is_empty.is_empty());
128 let with_is_empty: &dyn WithIsEmpty = &Wither;
129 if with_is_empty.len() == 0 {
130 println!("Or this!");
132 assert!(!with_is_empty.is_empty());
134 let has_wrong_is_empty = HasWrongIsEmpty;
135 if has_wrong_is_empty.len() == 0 {
136 // No error; `HasWrongIsEmpty` does not have `.is_empty()`.
137 println!("Or this!");
141 fn test_slice(b: &[u8]) {
146 // Avoid suggesting changes to ranges if the user did not enable `range_is_empty`.
147 // See https://github.com/rust-lang/rust/issues/48111#issuecomment-445132965
149 let _ = (0..42).len() == 0;