This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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
36fn 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+ }
Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments