rust-lang/rust-clippy

from_iter_instead_of_collect / needless_collect interaction questionable

クローズ

#6,533 opened on 2021/01/01

 (2 件のコメント) (0 件のリアクション) (0 人の担当者)Rust (1,391 件のフォーク)batch import
C-enhancementI-false-negativeL-nurserygood first issue

Repository metrics

Stars
 (10,406 個のスター)
PR merge metrics
 (平均マージ 19d 22h) (30d で 113 merged PRs)

説明

for _i in Vec::from_iter([1, 2, 3].iter()) {}

clippy will suggest to use .collect() instead of from_iter() here but blindly replacing will not work because .collect() will need some kind of type hint.

Them again

for _i in [1, 2, 3].iter().collect::<Vec<&i32>>() {}

does not trigger clippy::needless_collect (although it should!; neither does the first example) because we can iterate over

for _i in [1, 2, 3].iter() {}

directly.

コントリビューターガイド