-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Closes #11230 changelog: none
- Loading branch information
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Test for https://github.com/rust-lang/rust-clippy/issues/11230 | ||
#![warn(clippy::explicit_iter_loop)] | ||
#![warn(clippy::needless_collect)] | ||
|
||
// explicit_iter_loop | ||
fn main() { | ||
const A: &[for<'a> fn(&'a ())] = &[]; | ||
for v in A {} | ||
} | ||
|
||
// needless_collect | ||
trait Helper<'a>: Iterator<Item = fn()> {} | ||
|
||
fn x(w: &mut dyn for<'a> Helper<'a>) { | ||
w.next().is_none(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,16 @@ | ||
// Test for https://github.com/rust-lang/rust-clippy/issues/11230 | ||
#![warn(clippy::explicit_iter_loop)] | ||
#![warn(clippy::needless_collect)] | ||
|
||
// explicit_iter_loop | ||
fn main() { | ||
const A: &[for<'a> fn(&'a ())] = &[]; | ||
for v in A.iter() {} | ||
} | ||
|
||
// needless_collect | ||
trait Helper<'a>: Iterator<Item = fn()> {} | ||
|
||
fn x(w: &mut dyn for<'a> Helper<'a>) { | ||
w.collect::<Vec<_>>().is_empty(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
error: it is more concise to loop over references to containers instead of using explicit iteration methods | ||
--> tests/ui/crashes/ice-11230.rs:8:14 | ||
| | ||
LL | for v in A.iter() {} | ||
| ^^^^^^^^ help: to write this more concisely, try: `A` | ||
| | ||
= note: `-D clippy::explicit-iter-loop` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::explicit_iter_loop)]` | ||
|
||
error: avoid using `collect()` when not needed | ||
--> tests/ui/crashes/ice-11230.rs:15:7 | ||
| | ||
LL | w.collect::<Vec<_>>().is_empty(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `next().is_none()` | ||
| | ||
= note: `-D clippy::needless-collect` implied by `-D warnings` | ||
= help: to override `-D warnings` add `#[allow(clippy::needless_collect)]` | ||
|
||
error: aborting due to 2 previous errors | ||
|