Skip to content

Commit 72e8f2a

Browse files
committed
Add broken test
1 parent f8cd666 commit 72e8f2a

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

tests/ui/unnecessary_collection_clone.fixed

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ fn generic<T: Clone>(val: Vec<T>) -> Vec<T> {
1919
//~^ error: using clone on collection to own iterated items
2020
}
2121

22+
fn used_mutably<T: Clone>(mut vals: Vec<T>) {
23+
fn use_mutable<T>(_: &mut T) {}
24+
25+
for val in vals.iter().cloned() {
26+
use_mutable(&mut vals)
27+
}
28+
}
29+
2230
// Should not lint, as `Src` has no `iter` method to use.
2331
fn too_generic<Src, Dst, T: Clone>(val: Src) -> Dst
2432
where

tests/ui/unnecessary_collection_clone.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ fn generic<T: Clone>(val: Vec<T>) -> Vec<T> {
1919
//~^ error: using clone on collection to own iterated items
2020
}
2121

22+
fn used_mutably<T: Clone>(mut vals: Vec<T>) {
23+
fn use_mutable<T>(_: &mut T) {}
24+
25+
for val in vals.clone().into_iter() {
26+
use_mutable(&mut vals)
27+
}
28+
}
29+
2230
// Should not lint, as `Src` has no `iter` method to use.
2331
fn too_generic<Src, Dst, T: Clone>(val: Src) -> Dst
2432
where

tests/ui/unnecessary_collection_clone.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,11 @@ error: using clone on collection to own iterated items
1919
LL | val.clone().into_iter().collect()
2020
| ^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `val.iter().cloned()`
2121

22-
error: aborting due to 3 previous errors
22+
error: using clone on collection to own iterated items
23+
--> tests/ui/unnecessary_collection_clone.rs:25:16
24+
|
25+
LL | for val in vals.clone().into_iter() {
26+
| ^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `vals.iter().cloned()`
27+
28+
error: aborting due to 4 previous errors
2329

0 commit comments

Comments
 (0)