Skip to content

Commit

Permalink
Add clarification for from_iter_instead_of_collect
Browse files Browse the repository at this point in the history
  • Loading branch information
alex-semenyuk committed Aug 3, 2024
1 parent 0347280 commit 4bb6b30
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion clippy_lints/src/methods/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()`
/// method is preferred. However, when it's needed to specify the container type,
/// `Vec::from_iter(_)` can be more readable than using a turbofish (e.g. `collect::<Vec<_>>()`). See
/// [FromIterator documentation](https://doc.rust-lang.org/std/iter/trait.FromIterator.html)
///
/// ### Example
Expand All @@ -1911,6 +1913,14 @@ declare_clippy_lint! {
///
/// assert_eq!(v, vec![5, 5, 5, 5, 5]);
/// ```
/// but prefer to use
/// ```no_run
/// let numbers: Vec<i32> = FromIterator::from_iter(1..=5);
/// ```
/// instead of
/// ```no_run
/// let numbers = (1..=5).collect::<Vec<_>>();
/// ```
#[clippy::version = "1.49.0"]
pub FROM_ITER_INSTEAD_OF_COLLECT,
pedantic,
Expand Down

0 comments on commit 4bb6b30

Please sign in to comment.