rust-lang / rust-lang/rust-analyzer
Destructure assist
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
- Tuple destructuring (implemented in #9855)
- RecordStruct destructuring
- TupleStruct destructuring
- Improve the implementation https://github.com/rust-lang/rust-analyzer/issues/8673#issuecomment-2547827440
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the existing destructuring-assist implementation for the already completed tuple, RecordStruct, and TupleStruct cases, then read the linked discussion about improving it. Confirm behavior against the examples, including references to subbindings, private fields, and #[non_exhaustive]; done means the assist handles the requested exposed-field cases without breaking existing behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- developer-experience, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100