Skip to content

Fill match arms deletes _ case #4165

@tspiteri

Description

@tspiteri

With this

enum E { A, B, C }
// ...
match e {
    E::A => 1,
    _ => 2,
}

If I use "Fill match arms" I get

match e {
    E::A => 1,
    
    E::B => {}
    E::C => {}
}

I did not expect the code action to delete my code (only 2 here, but it could be longer). I expected one of these (in order of preference):

  1. E::B | E::C => 2,
  2. E::B => 2,\n E::C => 2, or E::B => { 2 }\n E::C => { 2 } with the disadvantage being code duplication, especially if there is a long expression instead of just 2.
  3. _ => 2 remains above the two added cases so that it can be removed after I fill them in. The disadvantage here is that it is easy to forget to remove it later, so maybe this is not a very good option, but at least it doesn't delete the code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-assistsS-actionableSomeone could pick this issue up and work on it right now

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions