Fix needless_collect suggests a suggestion that cannot be typed#17383
Fix needless_collect suggests a suggestion that cannot be typed#17383AnHoang-alex wants to merge 3 commits into
Conversation
|
Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @llogiq (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
Why was this reviewer chosen?The reviewer was selected based on:
|
8426026 to
0c209c1
Compare
|
This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
| /// Returns `true` if `collect_expr`'s turbofish is fully concrete (has | ||
| /// generic arguments and none of them are inference placeholders) | ||
| fn collect_turbofish_is_fully_concrete(collect_expr: &Expr<'_>) -> bool { | ||
| if let ExprKind::MethodCall(segment, ..) = collect_expr.kind | ||
| && let Some(args) = segment.args | ||
| && !args.args.is_empty() | ||
| { | ||
| args.args.iter().all(generic_arg_is_fully_concrete) | ||
| } else { | ||
| false | ||
| } | ||
| } |
There was a problem hiding this comment.
collect has only a single generic parameter, so either it is given and concrete, or it isn't. The code makes it seem like the number of generic parameters is unknown, and thus has to manually fix the empty case, because all would give true.
There was a problem hiding this comment.
I guess matching args.args with [a] if generic_arg_is_fully_concrete(a) should do the trick?
changelog: [
needless_collect]: no longer suggests a fix whencollect's turbofish may be the only thing anchoring type inferencefixes #17315