Skip to content

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

Merged

Conversation

alex-semenyuk
Copy link
Member

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

@rustbot
Copy link
Collaborator

rustbot commented Aug 3, 2024

r? @llogiq

rustbot has assigned @llogiq.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Aug 3, 2024
@alex-semenyuk alex-semenyuk marked this pull request as draft August 3, 2024 09:52
Copy link
Contributor

@llogiq llogiq left a 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.

/// 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
Copy link
Contributor

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?

@alex-semenyuk alex-semenyuk force-pushed the fix_doc_from_iter_instead_of_collect branch from 430b500 to 4bb6b30 Compare August 3, 2024 13:19
@alex-semenyuk
Copy link
Member Author

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.

@llogiq Thanks for feedback. Done

@alex-semenyuk alex-semenyuk marked this pull request as ready for review August 3, 2024 13:30
@@ -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()`
Copy link
Contributor

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().

@alex-semenyuk alex-semenyuk force-pushed the fix_doc_from_iter_instead_of_collect branch from 4bb6b30 to 4d3a9e7 Compare August 3, 2024 14:27
@alex-semenyuk alex-semenyuk force-pushed the fix_doc_from_iter_instead_of_collect branch from 4d3a9e7 to 35dcc9b Compare August 3, 2024 14:28
@alex-semenyuk alex-semenyuk requested a review from llogiq August 3, 2024 14:40
@llogiq
Copy link
Contributor

llogiq commented Aug 3, 2024

Thank you!

@bors r+

@bors
Copy link
Contributor

bors commented Aug 3, 2024

📌 Commit 35dcc9b has been approved by llogiq

It is now in the queue for this repository.

@bors
Copy link
Contributor

bors commented Aug 3, 2024

⌛ Testing commit 35dcc9b with merge eb7b676...

@bors
Copy link
Contributor

bors commented Aug 3, 2024

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: llogiq
Pushing eb7b676 to master...

@bors bors merged commit eb7b676 into rust-lang:master Aug 3, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Documentation for from_iter_instead_of_collect is incorrect
4 participants