-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add clarification for from_iter_instead_of_collect #13208
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
Add clarification for from_iter_instead_of_collect #13208
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR. One thing I'd like changed is that we always put code snippets in back ticks, even when just naming a type, which your comment currently doesn't. Also when naming a call with one argument, we use an underscore for the call, e.g. from_iter(_)
. Other than that, this is a solid improvement, and I'll happily merge it once fixed.
clippy_lints/src/methods/mod.rs
Outdated
/// It is recommended style to use collect. See | ||
/// If it's needed to create a collection from the contents of an iterator, the Iterator::collect() | ||
/// method is preferred. However, when it's needed to specify the container type, | ||
/// FromIterator::from_iter() can be more readable than using a turbofish (e.g. ::<Vec<_>>()). See |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it make more sense to use e.g. Vec::from_iter(_)
as an example here?
430b500
to
4bb6b30
Compare
@llogiq Thanks for feedback. Done |
clippy_lints/src/methods/mod.rs
Outdated
@@ -1892,7 +1892,9 @@ declare_clippy_lint! { | |||
/// trait. | |||
/// | |||
/// ### Why is this bad? | |||
/// It is recommended style to use collect. See | |||
/// If it's needed to create a collection from the contents of an iterator, the `Iterator::collect()` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should either be Iterator::collect(self)
, Iterator::collect(_)
or simply _.collect()
.
4bb6b30
to
4d3a9e7
Compare
4d3a9e7
to
35dcc9b
Compare
Thank you! @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Close #13147
As mentioned at #13147 we should prefer to use collect depends on situation so clarify this at documentation and provide examples this cases.
changelog: none