Skip to content

Destructure assist #8673

Description

@Veykril

It would be nice to have an assist for destructuring a binding into its "subbindings" as in, when you have a name to a tuple value have it destructure into names for each componenet of the tuple, same for structure fields etc. See IntelliJ's implementation here https://github.com/intellij-rust/intellij-rust/blob/master/src/main/kotlin/org/rust/ide/intentions/DestructureIntention.kt

Some examples for how it should work:

let foo$0 = (1, 2, 3);
let bar = foo.0;
let _ = foo.into();

becomes

let (_0, _1, _2) = (1, 2, 3);
let bar = _0;
let _ = (_0, _1, _2).into();

Similarly this should work for TupleStructs and RecordStructs:

struct Foo { bar: i32 }
let foo$0 = Foo { bar: 1 };
let bar = foo.bar;
let _ = foo.into();

becomes

struct Foo { bar: i32 }
let Foo { bar } = Foo { bar: 1 };
let bar = bar;
let _ = (Foo { bar }).into();

This should also respect private fields as well as #[non_exhaustive], putting .. in that case for the fields that aren't exposed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-assistsA-patternpattern handling related thingsE-mediumS-actionableSomeone could pick this issue up and work on it right nowfunA technically challenging issue with high impact

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions