Auto merge of #13208 - alex-semenyuk:fix_doc_from_iter_instead_of_collect, r=llogiq
Add clarification for from_iter_instead_of_collect 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
This commit is contained in:
commit
eb7b6769f1
@ -1892,7 +1892,9 @@
|
||||
/// 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
|
||||
@ -1911,6 +1913,14 @@
|
||||
///
|
||||
/// 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,
|
||||
|
Loading…
Reference in New Issue
Block a user