Add #[must_use] to len and is_empty

This commit is contained in:
John Kugelman 2021-10-11 16:15:50 -04:00
parent 5cf4984872
commit 892063ed2d
3 changed files with 39 additions and 37 deletions

View File

@ -33,6 +33,7 @@ impl HasIter {
} }
} }
#[allow(unused_must_use)]
fn main() { fn main() {
let mut vec = vec![0, 1, 2, 3]; let mut vec = vec![0, 1, 2, 3];
let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]); let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]);
@ -50,7 +51,7 @@ fn main() {
linked_list.push_back(1); linked_list.push_back(1);
binary_heap.push(1); binary_heap.push(1);
let _ = &vec[..].len(); &vec[..].len();
vec.len(); vec.len();
boxed_slice.len(); boxed_slice.len();
vec_deque.len(); vec_deque.len();
@ -62,13 +63,13 @@ fn main() {
binary_heap.len(); binary_heap.len();
vec.len(); vec.len();
let _ = &vec[..].len(); &vec[..].len();
vec_deque.len(); vec_deque.len();
hash_map.len(); hash_map.len();
b_tree_map.len(); b_tree_map.len();
linked_list.len(); linked_list.len();
let _ = &vec[..].len(); &vec[..].len();
vec.len(); vec.len();
vec_deque.len(); vec_deque.len();
hash_set.len(); hash_set.len();

View File

@ -33,6 +33,7 @@ impl HasIter {
} }
} }
#[allow(unused_must_use)]
fn main() { fn main() {
let mut vec = vec![0, 1, 2, 3]; let mut vec = vec![0, 1, 2, 3];
let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]); let mut boxed_slice: Box<[u8]> = Box::new([0, 1, 2, 3]);
@ -50,7 +51,7 @@ fn main() {
linked_list.push_back(1); linked_list.push_back(1);
binary_heap.push(1); binary_heap.push(1);
let _ = &vec[..].iter().count(); &vec[..].iter().count();
vec.iter().count(); vec.iter().count();
boxed_slice.iter().count(); boxed_slice.iter().count();
vec_deque.iter().count(); vec_deque.iter().count();
@ -62,13 +63,13 @@ fn main() {
binary_heap.iter().count(); binary_heap.iter().count();
vec.iter_mut().count(); vec.iter_mut().count();
let _ = &vec[..].iter_mut().count(); &vec[..].iter_mut().count();
vec_deque.iter_mut().count(); vec_deque.iter_mut().count();
hash_map.iter_mut().count(); hash_map.iter_mut().count();
b_tree_map.iter_mut().count(); b_tree_map.iter_mut().count();
linked_list.iter_mut().count(); linked_list.iter_mut().count();
let _ = &vec[..].into_iter().count(); &vec[..].into_iter().count();
vec.into_iter().count(); vec.into_iter().count();
vec_deque.into_iter().count(); vec_deque.into_iter().count();
hash_set.into_iter().count(); hash_set.into_iter().count();

View File

@ -1,151 +1,151 @@
error: called `.iter().count()` on a `slice` error: called `.iter().count()` on a `slice`
--> $DIR/iter_count.rs:53:14 --> $DIR/iter_count.rs:54:6
| |
LL | let _ = &vec[..].iter().count(); LL | &vec[..].iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()`
| |
= note: `-D clippy::iter-count` implied by `-D warnings` = note: `-D clippy::iter-count` implied by `-D warnings`
error: called `.iter().count()` on a `Vec` error: called `.iter().count()` on a `Vec`
--> $DIR/iter_count.rs:54:5 --> $DIR/iter_count.rs:55:5
| |
LL | vec.iter().count(); LL | vec.iter().count();
| ^^^^^^^^^^^^^^^^^^ help: try: `vec.len()` | ^^^^^^^^^^^^^^^^^^ help: try: `vec.len()`
error: called `.iter().count()` on a `slice` error: called `.iter().count()` on a `slice`
--> $DIR/iter_count.rs:55:5 --> $DIR/iter_count.rs:56:5
| |
LL | boxed_slice.iter().count(); LL | boxed_slice.iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `boxed_slice.len()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `boxed_slice.len()`
error: called `.iter().count()` on a `VecDeque` error: called `.iter().count()` on a `VecDeque`
--> $DIR/iter_count.rs:56:5 --> $DIR/iter_count.rs:57:5
| |
LL | vec_deque.iter().count(); LL | vec_deque.iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()` | ^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()`
error: called `.iter().count()` on a `HashSet` error: called `.iter().count()` on a `HashSet`
--> $DIR/iter_count.rs:57:5 --> $DIR/iter_count.rs:58:5
| |
LL | hash_set.iter().count(); LL | hash_set.iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_set.len()` | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_set.len()`
error: called `.iter().count()` on a `HashMap` error: called `.iter().count()` on a `HashMap`
--> $DIR/iter_count.rs:58:5 --> $DIR/iter_count.rs:59:5
| |
LL | hash_map.iter().count(); LL | hash_map.iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()` | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()`
error: called `.iter().count()` on a `BTreeMap` error: called `.iter().count()` on a `BTreeMap`
--> $DIR/iter_count.rs:59:5 --> $DIR/iter_count.rs:60:5
| |
LL | b_tree_map.iter().count(); LL | b_tree_map.iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_map.len()` | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_map.len()`
error: called `.iter().count()` on a `BTreeSet` error: called `.iter().count()` on a `BTreeSet`
--> $DIR/iter_count.rs:60:5 --> $DIR/iter_count.rs:61:5
| |
LL | b_tree_set.iter().count(); LL | b_tree_set.iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_set.len()` | ^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_set.len()`
error: called `.iter().count()` on a `LinkedList` error: called `.iter().count()` on a `LinkedList`
--> $DIR/iter_count.rs:61:5 --> $DIR/iter_count.rs:62:5
| |
LL | linked_list.iter().count(); LL | linked_list.iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()`
error: called `.iter().count()` on a `BinaryHeap` error: called `.iter().count()` on a `BinaryHeap`
--> $DIR/iter_count.rs:62:5 --> $DIR/iter_count.rs:63:5
| |
LL | binary_heap.iter().count(); LL | binary_heap.iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `binary_heap.len()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `binary_heap.len()`
error: called `.iter_mut().count()` on a `Vec` error: called `.iter_mut().count()` on a `Vec`
--> $DIR/iter_count.rs:64:5 --> $DIR/iter_count.rs:65:5
| |
LL | vec.iter_mut().count(); LL | vec.iter_mut().count();
| ^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.len()` | ^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.len()`
error: called `.iter_mut().count()` on a `slice` error: called `.iter_mut().count()` on a `slice`
--> $DIR/iter_count.rs:65:14 --> $DIR/iter_count.rs:66:6
| |
LL | let _ = &vec[..].iter_mut().count(); LL | &vec[..].iter_mut().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()`
error: called `.iter_mut().count()` on a `VecDeque` error: called `.iter_mut().count()` on a `VecDeque`
--> $DIR/iter_count.rs:66:5 --> $DIR/iter_count.rs:67:5
| |
LL | vec_deque.iter_mut().count(); LL | vec_deque.iter_mut().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()`
error: called `.iter_mut().count()` on a `HashMap` error: called `.iter_mut().count()` on a `HashMap`
--> $DIR/iter_count.rs:67:5 --> $DIR/iter_count.rs:68:5
| |
LL | hash_map.iter_mut().count(); LL | hash_map.iter_mut().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()`
error: called `.iter_mut().count()` on a `BTreeMap` error: called `.iter_mut().count()` on a `BTreeMap`
--> $DIR/iter_count.rs:68:5 --> $DIR/iter_count.rs:69:5
| |
LL | b_tree_map.iter_mut().count(); LL | b_tree_map.iter_mut().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_map.len()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_map.len()`
error: called `.iter_mut().count()` on a `LinkedList` error: called `.iter_mut().count()` on a `LinkedList`
--> $DIR/iter_count.rs:69:5 --> $DIR/iter_count.rs:70:5
| |
LL | linked_list.iter_mut().count(); LL | linked_list.iter_mut().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()`
error: called `.into_iter().count()` on a `slice` error: called `.into_iter().count()` on a `slice`
--> $DIR/iter_count.rs:71:14 --> $DIR/iter_count.rs:72:6
| |
LL | let _ = &vec[..].into_iter().count(); LL | &vec[..].into_iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec[..].len()`
error: called `.into_iter().count()` on a `Vec` error: called `.into_iter().count()` on a `Vec`
--> $DIR/iter_count.rs:72:5 --> $DIR/iter_count.rs:73:5
| |
LL | vec.into_iter().count(); LL | vec.into_iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.len()` | ^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec.len()`
error: called `.into_iter().count()` on a `VecDeque` error: called `.into_iter().count()` on a `VecDeque`
--> $DIR/iter_count.rs:73:5 --> $DIR/iter_count.rs:74:5
| |
LL | vec_deque.into_iter().count(); LL | vec_deque.into_iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `vec_deque.len()`
error: called `.into_iter().count()` on a `HashSet` error: called `.into_iter().count()` on a `HashSet`
--> $DIR/iter_count.rs:74:5 --> $DIR/iter_count.rs:75:5
| |
LL | hash_set.into_iter().count(); LL | hash_set.into_iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_set.len()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_set.len()`
error: called `.into_iter().count()` on a `HashMap` error: called `.into_iter().count()` on a `HashMap`
--> $DIR/iter_count.rs:75:5 --> $DIR/iter_count.rs:76:5
| |
LL | hash_map.into_iter().count(); LL | hash_map.into_iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `hash_map.len()`
error: called `.into_iter().count()` on a `BTreeMap` error: called `.into_iter().count()` on a `BTreeMap`
--> $DIR/iter_count.rs:76:5 --> $DIR/iter_count.rs:77:5
| |
LL | b_tree_map.into_iter().count(); LL | b_tree_map.into_iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_map.len()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_map.len()`
error: called `.into_iter().count()` on a `BTreeSet` error: called `.into_iter().count()` on a `BTreeSet`
--> $DIR/iter_count.rs:77:5 --> $DIR/iter_count.rs:78:5
| |
LL | b_tree_set.into_iter().count(); LL | b_tree_set.into_iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_set.len()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `b_tree_set.len()`
error: called `.into_iter().count()` on a `LinkedList` error: called `.into_iter().count()` on a `LinkedList`
--> $DIR/iter_count.rs:78:5 --> $DIR/iter_count.rs:79:5
| |
LL | linked_list.into_iter().count(); LL | linked_list.into_iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `linked_list.len()`
error: called `.into_iter().count()` on a `BinaryHeap` error: called `.into_iter().count()` on a `BinaryHeap`
--> $DIR/iter_count.rs:79:5 --> $DIR/iter_count.rs:80:5
| |
LL | binary_heap.into_iter().count(); LL | binary_heap.into_iter().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `binary_heap.len()` | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `binary_heap.len()`