Open
Description
I tried this code:
Vec::from_iter(2..5)
I expected to see this happen: no warning
Instead, this happened:
warning: usage of `FromIterator::from_iter`
--> src/lib.rs:219:1
|
219 | Vec::from_iter(2..5);
| ^^^^^^^^^^^^^^^^^^^^ help: use `.collect()` instead of `::from_iter()`: `(2..5).collect::<Vec<_>>()`
|
= note: `#[warn(clippy::from_iter_instead_of_collect)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#from_iter_instead_of_collect
The Vec::from_iter
call is much more succinct and readable than .collect::<Vec<_>>()
, and rust-lang/rfcs#3114 is currently in FCP-disposition-merge to add std::iter::FromIterator
to the Rust 2021 prelude. Having Clippy recommend against using it seems to go against the decision there that it is a trait to be used directly.
I'm really not sure if there's some subset of this lint that would feel ok, there's maybe some sort of "collect
here would be more readable", but defining heuristics to detect when to enable that seems complicated.
Meta
cargo clippy -V
:clippy 0.1.53 (42816d6 2021-04-24)