Skip to content

Move needless_collect to nursery #9705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion clippy_lints/src/loops/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ declare_clippy_lint! {
/// ```
#[clippy::version = "1.30.0"]
pub NEEDLESS_COLLECT,
perf,
nursery,
"collecting an iterator when collect is not needed"
}

Expand Down
1 change: 1 addition & 0 deletions tests/ui/needless_collect_indirect.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![allow(clippy::uninlined_format_args)]
#![warn(clippy::needless_collect)]

use std::collections::{BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};

Expand Down
32 changes: 16 additions & 16 deletions tests/ui/needless_collect_indirect.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error: avoid using `collect()` when not needed
--> $DIR/needless_collect_indirect.rs:7:39
--> $DIR/needless_collect_indirect.rs:8:39
|
LL | let indirect_iter = sample.iter().collect::<Vec<_>>();
| ^^^^^^^
Expand All @@ -14,7 +14,7 @@ LL ~ sample.iter().map(|x| (x, x + 1)).collect::<HashMap<_, _>>();
|

error: avoid using `collect()` when not needed
--> $DIR/needless_collect_indirect.rs:9:38
--> $DIR/needless_collect_indirect.rs:10:38
|
LL | let indirect_len = sample.iter().collect::<VecDeque<_>>();
| ^^^^^^^
Expand All @@ -28,7 +28,7 @@ LL ~ sample.iter().count();
|

error: avoid using `collect()` when not needed
--> $DIR/needless_collect_indirect.rs:11:40
--> $DIR/needless_collect_indirect.rs:12:40
|
LL | let indirect_empty = sample.iter().collect::<VecDeque<_>>();
| ^^^^^^^
Expand All @@ -42,7 +42,7 @@ LL ~ sample.iter().next().is_none();
|

error: avoid using `collect()` when not needed
--> $DIR/needless_collect_indirect.rs:13:43
--> $DIR/needless_collect_indirect.rs:14:43
|
LL | let indirect_contains = sample.iter().collect::<VecDeque<_>>();
| ^^^^^^^
Expand All @@ -56,7 +56,7 @@ LL ~ sample.iter().any(|x| x == &5);
|

error: avoid using `collect()` when not needed
--> $DIR/needless_collect_indirect.rs:25:48
--> $DIR/needless_collect_indirect.rs:26:48
|
LL | let non_copy_contains = sample.into_iter().collect::<Vec<_>>();
| ^^^^^^^
Expand All @@ -70,7 +70,7 @@ LL ~ sample.into_iter().any(|x| x == a);
|

error: avoid using `collect()` when not needed
--> $DIR/needless_collect_indirect.rs:54:51
--> $DIR/needless_collect_indirect.rs:55:51
|
LL | let buffer: Vec<&str> = string.split('/').collect();
| ^^^^^^^
Expand All @@ -84,7 +84,7 @@ LL ~ string.split('/').count()
|

error: avoid using `collect()` when not needed
--> $DIR/needless_collect_indirect.rs:59:55
--> $DIR/needless_collect_indirect.rs:60:55
|
LL | let indirect_len: VecDeque<_> = sample.iter().collect();
| ^^^^^^^
Expand All @@ -98,7 +98,7 @@ LL ~ sample.iter().count()
|

error: avoid using `collect()` when not needed
--> $DIR/needless_collect_indirect.rs:64:57
--> $DIR/needless_collect_indirect.rs:65:57
|
LL | let indirect_len: LinkedList<_> = sample.iter().collect();
| ^^^^^^^
Expand All @@ -112,7 +112,7 @@ LL ~ sample.iter().count()
|

error: avoid using `collect()` when not needed
--> $DIR/needless_collect_indirect.rs:69:57
--> $DIR/needless_collect_indirect.rs:70:57
|
LL | let indirect_len: BinaryHeap<_> = sample.iter().collect();
| ^^^^^^^
Expand All @@ -126,7 +126,7 @@ LL ~ sample.iter().count()
|

error: avoid using `collect()` when not needed
--> $DIR/needless_collect_indirect.rs:129:59
--> $DIR/needless_collect_indirect.rs:130:59
|
LL | let y: Vec<usize> = vec.iter().map(|k| k * k).collect();
| ^^^^^^^
Expand All @@ -143,7 +143,7 @@ LL ~ vec.iter().map(|k| k * k).any(|x| x == i);
|

error: avoid using `collect()` when not needed
--> $DIR/needless_collect_indirect.rs:154:59
--> $DIR/needless_collect_indirect.rs:155:59
|
LL | let y: Vec<usize> = vec.iter().map(|k| k * k).collect();
| ^^^^^^^
Expand All @@ -160,7 +160,7 @@ LL ~ vec.iter().map(|k| k * k).any(|x| x == n);
|

error: avoid using `collect()` when not needed
--> $DIR/needless_collect_indirect.rs:183:63
--> $DIR/needless_collect_indirect.rs:184:63
|
LL | let y: Vec<usize> = vec.iter().map(|k| k * k).collect();
| ^^^^^^^
Expand All @@ -177,7 +177,7 @@ LL ~ vec.iter().map(|k| k * k).any(|x| x == n);
|

error: avoid using `collect()` when not needed
--> $DIR/needless_collect_indirect.rs:219:59
--> $DIR/needless_collect_indirect.rs:220:59
|
LL | let y: Vec<usize> = vec.iter().map(|k| k * k).collect();
| ^^^^^^^
Expand All @@ -195,7 +195,7 @@ LL ~ vec.iter().map(|k| k * k).any(|x| x == n);
|

error: avoid using `collect()` when not needed
--> $DIR/needless_collect_indirect.rs:244:26
--> $DIR/needless_collect_indirect.rs:245:26
|
LL | let w = v.iter().collect::<Vec<_>>();
| ^^^^^^^
Expand All @@ -211,7 +211,7 @@ LL ~ for _ in 0..v.iter().count() {
|

error: avoid using `collect()` when not needed
--> $DIR/needless_collect_indirect.rs:266:30
--> $DIR/needless_collect_indirect.rs:267:30
|
LL | let mut w = v.iter().collect::<Vec<_>>();
| ^^^^^^^
Expand All @@ -227,7 +227,7 @@ LL ~ while 1 == v.iter().count() {
|

error: avoid using `collect()` when not needed
--> $DIR/needless_collect_indirect.rs:288:30
--> $DIR/needless_collect_indirect.rs:289:30
|
LL | let mut w = v.iter().collect::<Vec<_>>();
| ^^^^^^^
Expand Down