needless_collect
: false positive when collecting std::thread::JoinHandle
or similar elements
#7207
Labels
C-bug
Category: Clippy is not doing the correct thing
I-false-positive
Issue: The lint was triggered on code it shouldn't have
L-nursery
Lint: Currently in the nursery group
Lint name:
needless_collect
I tried this code:
I expected to see this happen:
In my opinion, no warning should be emitted here because, in almost all cases, the user wants for the threads to run in parallel and "fixing" the lint would make them run sequentially. Unfortunately, I'm not sure how feasible it would be to fix those false positives in the general case. It's somewhat subjective when "collecting" is valid for parallelism. The obvious cases from the standard library are when collecting
std::thread::JoinHandle
orstd::process::Child
elements. However, the same could be true for other crates (e.g.crossbeam::thread::ScopedJoinHandle
).Instead, this happened:
Running
cargo clippy
, I get the following warning:Note that using a type hint (i.e.
let threads: Vec<_>
) instead of turbofish syntax doesn't produce the warning with clippy 0.1.52 because of an inconsistency bug. However, that bug has been fixed in clippy 0.1.54, which emits the warning in both cases. See issue #7194.Meta
cargo clippy -V
: clippy 0.1.52 (9bc8c42b 2021-05-09)(Note that I get the same result on the Rust Playground with clippy 0.1.54)
rustc -Vv
:The text was updated successfully, but these errors were encountered: