Skip to content

“Fill match arms” for nested enums #19859

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
kpreid opened this issue May 24, 2025 · 0 comments
Open

“Fill match arms” for nested enums #19859

kpreid opened this issue May 24, 2025 · 0 comments
Labels
A-assists C-feature Category: feature request

Comments

@kpreid
Copy link
Contributor

kpreid commented May 24, 2025

Consider the following code:

enum Example {
    One,
    Two,
    // ...and lots more, perhaps
}

pub fn example(e: Option<Example>) {
    match e {
         // want to fill this       
    }
}

Invoking “Fill match arms” on e will currently produce

        Some(_) => todo!(),
        None => todo!(),

However, I might want to match the inner enum, to produce:

        Some(Example::One) => todo!(),
        Some(Example::Two) => todo!(),
        None => todo!(),

This could be expressed by putting the cursor on the _ and invoking an assist that duplicates the arm with more specific patterns. (Or, “Fill match arms” could always descend into nested enums and rely on the user to delete unwanted ones, but that could potentially lead to quite an expansion in some cases, so I don’t think it is wise.) In general, I think it would make sense to have an assist that replaces an _ pattern or identifier pattern with an enum variant (or struct) pattern, and then duplicates the arm for all variants produced this way.


A different but closely related case is that I might be in the position of currently having some of these arms but not all (hence getting a non-exhaustive match error), and wanting to fill in the missing arms:

    match e {
        Some(Example::One) => todo!(),
        None => todo!(),
    }

In this case, the error's span is e (the same place that “Fill match arms” is available), but RA doesn't offer any assist/fix that will fill in the missing arm. In this case, I think “Fill match arms” should be available and fill in the missing Some(Example::Two) arm. This part won’t require any new UI design.

@kpreid kpreid added the C-feature Category: feature request label May 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-assists C-feature Category: feature request
Projects
None yet
Development

No branches or pull requests

2 participants