rust/tests/ui/iter_overeager_cloned.stderr
lengyijun fc061890d6 [iter_overeager_cloned]: detect .cloned().filter() and .cloned().find()
Key idea:
```
// before
iter.cloned().filter(|x| unimplemented!() )
// after
iter.filter(|&x| unimplemented!() ).cloned()

// before
iter.cloned().filter( foo )
// after
iter.filter(|&x| foo(x) ).cloned()
```
2023-08-14 09:13:01 +08:00

135 lines
5.2 KiB
Plaintext

error: unnecessarily eager cloning of iterator items
--> $DIR/iter_overeager_cloned.rs:7:29
|
LL | let _: Option<String> = vec.iter().cloned().last();
| ^^^^^^^^^^----------------
| |
| help: try: `.last().cloned()`
|
= note: `-D clippy::iter-overeager-cloned` implied by `-D warnings`
error: unnecessarily eager cloning of iterator items
--> $DIR/iter_overeager_cloned.rs:9:29
|
LL | let _: Option<String> = vec.iter().chain(vec.iter()).cloned().next();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------
| |
| help: try: `.next().cloned()`
error: unneeded cloning of iterator items
--> $DIR/iter_overeager_cloned.rs:11:20
|
LL | let _: usize = vec.iter().filter(|x| x == &"2").cloned().count();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^-----------------
| |
| help: try: `.count()`
|
= note: `-D clippy::redundant-clone` implied by `-D warnings`
error: unnecessarily eager cloning of iterator items
--> $DIR/iter_overeager_cloned.rs:13:21
|
LL | let _: Vec<_> = vec.iter().cloned().take(2).collect();
| ^^^^^^^^^^-----------------
| |
| help: try: `.take(2).cloned()`
error: unnecessarily eager cloning of iterator items
--> $DIR/iter_overeager_cloned.rs:15:21
|
LL | let _: Vec<_> = vec.iter().cloned().skip(2).collect();
| ^^^^^^^^^^-----------------
| |
| help: try: `.skip(2).cloned()`
error: unnecessarily eager cloning of iterator items
--> $DIR/iter_overeager_cloned.rs:17:13
|
LL | let _ = vec.iter().filter(|x| x == &"2").cloned().nth(2);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^----------------
| |
| help: try: `.nth(2).cloned()`
error: unnecessarily eager cloning of iterator items
--> $DIR/iter_overeager_cloned.rs:19:13
|
LL | let _ = [Some(Some("str".to_string())), Some(Some("str".to_string()))]
| _____________^
LL | | .iter()
LL | | .cloned()
LL | | .flatten();
| |__________________^
|
help: try
|
LL ~ .iter()
LL ~ .flatten().cloned();
|
error: unnecessarily eager cloning of iterator items
--> $DIR/iter_overeager_cloned.rs:24:13
|
LL | let _ = vec.iter().cloned().filter(|x| x.starts_with('2'));
| ^^^^^^^^^^----------------------------------------
| |
| help: try: `.filter(|&x| x.starts_with('2')).cloned()`
error: unnecessarily eager cloning of iterator items
--> $DIR/iter_overeager_cloned.rs:26:13
|
LL | let _ = vec.iter().cloned().find(|x| x == "2");
| ^^^^^^^^^^----------------------------
| |
| help: try: `.find(|&x| x == "2").cloned()`
error: unnecessarily eager cloning of iterator items
--> $DIR/iter_overeager_cloned.rs:30:17
|
LL | let _ = vec.iter().cloned().filter(f);
| ^^^^^^^^^^-------------------
| |
| help: try: `.filter(|&x| f(x)).cloned()`
error: unnecessarily eager cloning of iterator items
--> $DIR/iter_overeager_cloned.rs:31:17
|
LL | let _ = vec.iter().cloned().find(f);
| ^^^^^^^^^^-----------------
| |
| help: try: `.find(|&x| f(x)).cloned()`
error: unnecessarily eager cloning of iterator items
--> $DIR/iter_overeager_cloned.rs:37:17
|
LL | let _ = vec.iter().cloned().filter(f);
| ^^^^^^^^^^-------------------
| |
| help: try: `.filter(|&x| f(x)).cloned()`
error: unnecessarily eager cloning of iterator items
--> $DIR/iter_overeager_cloned.rs:38:17
|
LL | let _ = vec.iter().cloned().find(f);
| ^^^^^^^^^^-----------------
| |
| help: try: `.find(|&x| f(x)).cloned()`
error: unnecessarily eager cloning of iterator items
--> $DIR/iter_overeager_cloned.rs:45:9
|
LL | iter.cloned().filter(move |(&a, b)| a == 1 && b == &target)
| ^^^^-------------------------------------------------------
| |
| help: try: `.filter(move |&(&a, b)| a == 1 && b == &target).cloned()`
error: unnecessarily eager cloning of iterator items
--> $DIR/iter_overeager_cloned.rs:56:13
|
LL | iter.cloned().filter(move |S { a, b }| **a == 1 && b == &target)
| ^^^^------------------------------------------------------------
| |
| help: try: `.filter(move |&S { a, b }| **a == 1 && b == &target).cloned()`
error: aborting due to 15 previous errors