Skip to content

match exhaustiveness diagnostics: show a trailing comma on singleton tuple consructors in witness patterns (and clean up a little) #145234

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

dianne
Copy link
Contributor

@dianne dianne commented Aug 10, 2025

Constructor patterns of type (T,) are written (pat,), not (pat). However, exhaustiveness/usefulness diagnostics would print them as (pat) when e.g. providing a witness of non-exhaustiveness and suggesting adding arms to make matches exhaustive; this would result in an error when applied.
rust-analyzer already prints the trailing comma, so it doesn't need changing.

This also includes some cleanup in the second commit, with justification in the commit message.

dianne added 2 commits August 10, 2025 15:32
By construction, `subpatterns` contains all fields in order. Witness
patterns are constructed with all fields in order by
`WitnessPat::wild_from_ctor` and `WitnessStack::apply_constructor`, and
the order is preserved at `write_struct_like`'s call-site in
`print_witness_pat`. It's thus no longer necessary to go looking for
fields or handle missing fields.
@rustbot
Copy link
Collaborator

rustbot commented Aug 10, 2025

r? @jackh726

rustbot has assigned @jackh726.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 10, 2025
@rustbot
Copy link
Collaborator

rustbot commented Aug 10, 2025

Some changes occurred in exhaustiveness checking

cc @Nadrieril

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I haven't added a test specifically for singleton tuple witnesses since this test included them. I could add a separate test if it would be preferable, though, to make sure it's still tested even if this test changes.

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. 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.

3 participants