Skip to content

improve diagnostic suggestion when matching struct variants with tuple#158748

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Snxhit:fix-struct-variant-suggestion
Jul 18, 2026
Merged

improve diagnostic suggestion when matching struct variants with tuple#158748
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
Snxhit:fix-struct-variant-suggestion

Conversation

@Snxhit

@Snxhit Snxhit commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

fixes #158641

changes:
passed sub_pats from resolve_pat_tuple_struct into report_unexpected_variant_res, match user's variable names to struct fields, fix suggestion name.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 3, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 3, 2026
@rustbot

rustbot commented Jul 3, 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 @hanna-kruppe (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: compiler
  • compiler expanded to 75 candidates
  • Random selection from 21 candidates

@rust-log-analyzer

This comment has been minimized.

@hanna-kruppe hanna-kruppe 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.

Thanks, this new suggestion is a big improvement.

I have some concerns about adding even more case distinctions and parameters to report_unexpected_variant_res as it's already very unwieldy. But I don't see a way to avoid that without a much larger refactoring, so I've limited my suggestions to the code this PR adds/touches.

There's also one more thing to improve about the suggestion and some more tests I'd like to see.

View changes since this review

Comment thread compiler/rustc_hir_typeck/src/lib.rs Outdated
Comment thread compiler/rustc_hir_typeck/src/lib.rs Outdated
Comment thread compiler/rustc_hir_typeck/src/lib.rs Outdated
Comment thread tests/ui/parser/recover/recover-from-bad-variant.stderr Outdated
Comment thread tests/ui/parser/recover/recover-from-bad-variant.stderr
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 12, 2026
@rustbot

rustbot commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rust-log-analyzer

This comment has been minimized.

@hanna-kruppe hanna-kruppe 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.

Thank you again. Please do the to_string cleanup and then squash the commits into one. r=me after that.

View changes since this review

Comment thread compiler/rustc_hir_typeck/src/lib.rs
…e syntax

- update `report_unexpected_variant_res` to suggest using proper struct usage instead of stating that fields are being ignored.
- add edge test cases in `tests/ui/parser/recover/recover-from-bad-variant.rs`
@Snxhit
Snxhit force-pushed the fix-struct-variant-suggestion branch from 0ab4103 to e8ddb78 Compare July 17, 2026 17:33
@hanna-kruppe

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

📌 Commit e8ddb78 has been approved by hanna-kruppe

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 17, 2026
rust-bors Bot pushed a commit that referenced this pull request Jul 17, 2026
…uwer

Rollup of 5 pull requests

Successful merges:

 - #158544 (Move `std::io::Read` to `alloc::io`)
 - #158668 (`DeeplyNormalize` and `normalize_with_depth_to` take `Unnormalized<T>` as input)
 - #157514 ([tiny] Use multipart suggestion for finding ident when literal was expected in attr)
 - #158748 (improve diagnostic suggestion when matching struct variants with tuple)
 - #159463 (triagebot: tweak wording for miri changes message)

Failed merges:

 - #158916 (Emit all borrowck errors at the end of borrowck)
@rust-bors
rust-bors Bot merged commit 2f253fb into rust-lang:main Jul 18, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Jul 18, 2026
rust-timer added a commit that referenced this pull request Jul 18, 2026
Rollup merge of #158748 - Snxhit:fix-struct-variant-suggestion, r=hanna-kruppe

improve diagnostic suggestion when matching struct variants with tuple

fixes #158641

changes:
passed `sub_pats` from `resolve_pat_tuple_struct` into `report_unexpected_variant_res`, match user's variable names to struct fields, fix suggestion name.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Misleading "fields are being ignored" help when changing a variant from tuple- to struct-like

4 participants