Skip to content

Fix an invalid suggestion in needless_collect test #6202

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

giraffate
Copy link
Contributor

@giraffate giraffate commented Oct 21, 2020

A test, https://github.com/rust-lang/rust-clippy/blob/master/tests/ui/needless_collect_indirect.rs#L11-L12, suggests following codes, but the suggested codes don't work. An example is here: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=6947d9f2806a83f41cc5eb8e39b09d0b.

error: avoid using `collect()` when not needed
  --> $DIR/needless_collect_indirect.rs:11:5
   |
LL | /     let indirect_contains = sample.iter().collect::<VecDeque<_>>();
LL | |     indirect_contains.contains(&&5);
   | |____^
   |
help: Check if the original Iterator contains an element instead of collecting then checking
   |
LL |     
LL |     sample.iter().any(|x| x == &&5);

changelog: none

@rust-highfive
Copy link

r? @phansch

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Oct 21, 2020
@flip1995
Copy link
Member

Does this fix also work for non-Copy types?

@giraffate giraffate force-pushed the fix_invalid_suggestion_in_needless_collect_test branch from edab094 to 2f5d418 Compare October 25, 2020 15:05
@giraffate
Copy link
Contributor Author

@flip1995 Thanks for your review. Do you mean this test case (String has no Copy trait. 2f5d418 ) ?

@flip1995 flip1995 added S-waiting-on-bors Status: The marked PR was approved and is only waiting bors and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Oct 25, 2020
Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, perfect. Waiting on rustup

@flip1995
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Oct 25, 2020

📌 Commit 2f5d418 has been approved by flip1995

@bors
Copy link
Contributor

bors commented Oct 25, 2020

⌛ Testing commit 2f5d418 with merge 83bb5ec...

@bors
Copy link
Contributor

bors commented Oct 25, 2020

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: flip1995
Pushing 83bb5ec to master...

@bors bors merged commit 83bb5ec into rust-lang:master Oct 25, 2020
@giraffate giraffate deleted the fix_invalid_suggestion_in_needless_collect_test branch October 26, 2020 00:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: The marked PR was approved and is only waiting bors
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants