Skip to content

Commit a895beb

Browse files
authored
add more test coverage for #11230 (#13915)
Closes #11230 changelog: none
2 parents ab55d3f + 8275f42 commit a895beb

File tree

3 files changed

+46
-0
lines changed

3 files changed

+46
-0
lines changed

Diff for: tests/ui/crashes/ice-11230.fixed

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Test for https://github.com/rust-lang/rust-clippy/issues/11230
2+
#![warn(clippy::explicit_iter_loop)]
3+
#![warn(clippy::needless_collect)]
4+
5+
// explicit_iter_loop
6+
fn main() {
7+
const A: &[for<'a> fn(&'a ())] = &[];
8+
for v in A {}
9+
}
10+
11+
// needless_collect
12+
trait Helper<'a>: Iterator<Item = fn()> {}
13+
14+
fn x(w: &mut dyn for<'a> Helper<'a>) {
15+
w.next().is_none();
16+
}

Diff for: tests/ui/crashes/ice-11230.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
// Test for https://github.com/rust-lang/rust-clippy/issues/11230
2+
#![warn(clippy::explicit_iter_loop)]
3+
#![warn(clippy::needless_collect)]
24

5+
// explicit_iter_loop
36
fn main() {
47
const A: &[for<'a> fn(&'a ())] = &[];
58
for v in A.iter() {}
69
}
10+
11+
// needless_collect
12+
trait Helper<'a>: Iterator<Item = fn()> {}
13+
14+
fn x(w: &mut dyn for<'a> Helper<'a>) {
15+
w.collect::<Vec<_>>().is_empty();
16+
}

Diff for: tests/ui/crashes/ice-11230.stderr

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
error: it is more concise to loop over references to containers instead of using explicit iteration methods
2+
--> tests/ui/crashes/ice-11230.rs:8:14
3+
|
4+
LL | for v in A.iter() {}
5+
| ^^^^^^^^ help: to write this more concisely, try: `A`
6+
|
7+
= note: `-D clippy::explicit-iter-loop` implied by `-D warnings`
8+
= help: to override `-D warnings` add `#[allow(clippy::explicit_iter_loop)]`
9+
10+
error: avoid using `collect()` when not needed
11+
--> tests/ui/crashes/ice-11230.rs:15:7
12+
|
13+
LL | w.collect::<Vec<_>>().is_empty();
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()`
15+
|
16+
= note: `-D clippy::needless-collect` implied by `-D warnings`
17+
= help: to override `-D warnings` add `#[allow(clippy::needless_collect)]`
18+
19+
error: aborting due to 2 previous errors
20+

0 commit comments

Comments
 (0)