-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
inconsistent needless_collect
lint for turbofish syntax vs type hint
#7194
Comments
This has been already fixed by #7163, so I'm closing this. FYI You can check it work on playground. |
@giraffate Great! Indeed, it works with clippy 0.1.54 on playground. However, I noticed that, even with clippy 0.1.54 on playground, you get the same warning for the following snippet: fn main() {
let threads: Vec<_> = (1..5).map(|n| std::thread::spawn(move || n * n)).collect();
threads.into_iter().for_each(|thread| println!("{}", thread.join().unwrap()));
} 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. The same is true for Should I open a separate issue for this? Or is this not considered a bug with clippy, and the intention is that we should use |
Reopened for further discussion. It looks like a false positive. |
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 I don't know if the code in |
A new issue for this would be good. Yikes, this looks like a hard one. 😬 |
@camsteffen: I've opened a separate issue (#7207) for it. Feel free to close this one if appropriate! |
I tried this code:
I also tried this code:
I expected to see this happen:
I guess it's debatable whether the two snippets above should emit a
needless_collect
warning. In my opinion, it should in the scenario above but it shouldn't in other scenarios (e.g. when collecting a vector ofJoinHandle<T>
). However, I think it's clear that both snippets should behave identically.Instead, this happened:
For the first snippet (i.e. type hint), running
cargo clippy
doesn't generate any warning. However, for the second snippet (i.e. turbofish syntax), runningcargo clippy
generates the following warning:I am willing to contribute to a pull request, but I want to make sure that we agree on the expected behavior: should they both emit a warning, or should they both NOT emit a warning? Or perhaps, I'm mistaken and they should behave differently...
Meta
cargo clippy -V
: clippy 0.1.52 (88f19c6d 2021-05-03)rustc -Vv
:The text was updated successfully, but these errors were encountered: