Skip to content
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

Lint suggestion: use .collect() instead of ::from_iter() #5679

Closed
meithecatte opened this issue Jun 2, 2020 · 6 comments · Fixed by #6101
Closed

Lint suggestion: use .collect() instead of ::from_iter() #5679

meithecatte opened this issue Jun 2, 2020 · 6 comments · Fixed by #6101
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy

Comments

@meithecatte
Copy link
Contributor

When the user writes, say, HashMap::from_iter($iter_expr), suggest $iter_expr.collect().

This would be primarily beneficial to beginners. In fact, I've just seen this in the wild on Exercism ;)

@flip1995
Copy link
Member

flip1995 commented Jun 2, 2020

See also the documentation of FromIterator: https://doc.rust-lang.org/std/iter/trait.FromIterator.html

@flip1995 flip1995 added good-first-issue These issues are a good way to get started with Clippy A-lint Area: New lints labels Jun 2, 2020
@meithecatte
Copy link
Contributor Author

True, the documentation already mentions this, but it is not visible when you find the method in the list of traits a type implements.

Actually, I just realized that this is more general. I have also seen people explicitly use std::ops::Add::add, without realizing that this is equivalent to using the + operator.

@craigpastro
Copy link

Would it be okay if I gave this one a try?

@meithecatte
Copy link
Contributor Author

Go ahead!

@pitiK3U
Copy link
Contributor

pitiK3U commented Sep 10, 2020

@siyopao Still working on it or can I give it a try?

@craigpastro
Copy link

Hi @pitiK3U, sorry, yes, please go ahead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: New lints good-first-issue These issues are a good way to get started with Clippy
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants