rust-lang/rust-clippy

from_iter_instead_of_collect / needless_collect interaction questionable

已關閉

#6,533 建立於 2021年1月1日

 (2 則留言) (0 個反應) (0 位負責人)Rust (1,391 個分叉)batch import
C-enhancementI-false-negativeL-nurserygood first issue

倉庫指標

星標
 (10,406 顆星)
PR 合併指標
 (平均合併 19天 22小時) (30 天內合併 113 個 PR)

描述

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.

貢獻者指南