Skip to content

Conversation

@Wilfred
Copy link
Contributor

@Wilfred Wilfred commented Jan 13, 2026

r-a already has the ability to fill in match arms as part of the add_missing_match_arms assist. However, there's currently no way to go from flavor to match flavor { Apple => {} ... }.

If a user does want the IDE to fill in match arms, they have to write the match and {} themselves. Other language LSPs supporting pattern matching (e.g. merlin for OCaml) support writing the whole match statement.

Whilst I'm aware there's a freeze on new assists, this assist is just a generalisation of add_missing_match_arms and reuses the existing logic there (which has great test coverage). I think it's a really compelling feature and hopefully a small ask.

AI disclosure: Written with a little bit of help from Claude in a few places.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 13, 2026
r-a already has the ability to fill in match arms as part of the
add_missing_match_arms assist. However, there's currently no way to go
from `flavor` to `match flavor { Apple => {} ... }`.

If a user does want the IDE to fill in match arms, they have to write
the `match` and `{}` themselves. Other language LSPs supporting
pattern matching (e.g. merlin for OCaml) support writing the whole
match statement.

Whilst I'm aware there's a freeze on new assists, this assist is just
a generalisation of add_missing_match_arms and reuses the existing
logic there (which has great test coverage). I think it's a really
compelling feature and hopefully a small ask.

AI disclosure: Written with a little bit of help from Claude in a few
places.
@Wilfred Wilfred force-pushed the destructure_match_assist branch from de1c771 to f59e5ab Compare January 13, 2026 13:43
@A4-Tacks
Copy link
Member

Currently, for Option and Result, postfix completion overlaps with this assistant

Perhaps we should strengthen postfix completion instead of adding assistants?

Related #11409

crates/ide-completion/src/completions/postfix.rs:165

@Wilfred
Copy link
Contributor Author

Wilfred commented Jan 13, 2026

Huh, I had totally forgotten about .match. Thanks for the issues too: in addition to #11409, I think the linked #8365 is very relevant. This PR is essentially adding case splitting (maybe that's a better name for this assist?).

The downsides of .match is that it's much harder to discover (not valid Rust syntax and I don't think there's precedent in other languages?) and it's awkward to use when you have larger expressions. For example, if I have foo.bar.baz I can highlight the whole expression, highlight foo.bar or just highlight foo and destructure depending on the type of those subexpressions.

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.

3 participants