Skip to content

Fix needless_collect suggests a suggestion that cannot be typed#17383

Open
AnHoang-alex wants to merge 3 commits into
rust-lang:masterfrom
AnHoang-alex:fix-needless-collect-suggestion
Open

Fix needless_collect suggests a suggestion that cannot be typed#17383
AnHoang-alex wants to merge 3 commits into
rust-lang:masterfrom
AnHoang-alex:fix-needless-collect-suggestion

Conversation

@AnHoang-alex

@AnHoang-alex AnHoang-alex commented Jul 9, 2026

Copy link
Copy Markdown

changelog: [needless_collect]: no longer suggests a fix when collect's turbofish may be the only thing anchoring type inference

fixes #17315

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jul 9, 2026
@rustbot

rustbot commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

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 (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue
Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: 8 candidates
  • 8 candidates expanded to 8 candidates
  • Random selection from Jarcho, llogiq, samueltardieu

@AnHoang-alex AnHoang-alex force-pushed the fix-needless-collect-suggestion branch from 8426026 to 0c209c1 Compare July 9, 2026 14:21
@rustbot

rustbot commented Jul 9, 2026

Copy link
Copy Markdown
Collaborator

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.

Comment on lines +237 to +248
/// 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
}
}

@hkBst hkBst Jul 11, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess matching args.args with [a] if generic_arg_is_fully_concrete(a) should do the trick?

@llogiq llogiq left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good modulo a small nit.

View changes since this review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

needless_collect untypable suggestion

4 participants