rust-lang/rust-clippy

from_iter_instead_of_collect / needless_collect interaction questionable

Fermée

#6 533 ouverte le 1 janv. 2021

 (2 commentaires) (0 réaction) (0 personne assignée)Rust (1 391 forks)batch import
C-enhancementI-false-negativeL-nurserygood first issue

Métriques du dépôt

Stars
 (10 406 étoiles)
Métriques de merge PR
 (Merge moyen 19j 22h) (113 PRs mergées en 30 j)

Description

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.

Guide contributeur