-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feature: Add 'destructure struct binding' assist #13997
Closed
Closed
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rustbot
added
the
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
label
Jan 21, 2023
lnicola
added
S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
and removed
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
labels
Feb 13, 2023
Veykril
added
S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
and removed
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
labels
Mar 25, 2023
I'm cleaning up our PR backlog right now, if you are coming back to this feel free to re-open. |
8 tasks
bors
added a commit
that referenced
this pull request
Feb 27, 2024
feature: Add `destructure_struct_binding` Adds an assist for destructuring a struct in a binding (#8673). I saw that #13997 has been abandoned for a while, so I thought I'd give it a go. ## Example ```rust let foo = Foo { bar: 1, baz: 2 }; let bar2 = foo.bar; let baz2 = foo.baz; let foo2 = foo; let fizz = Fizz(1, 2); let buzz = fizz.0; ``` becomes ```rust let Foo { bar, baz } = Foo { bar: 1, baz: 2 }; let bar2 = bar; let baz2 = baz; let foo2 = todo!(); let Fizz(_0, _1) = Fizz(1, 2); let buzz = _0; ``` More examples in the tests. ## What is included? - [x] Destructure record, tuple, and unit struct bindings - [x] Edit field usages - [x] Non-exhaustive structs in foreign crates and private fields get hidden behind `..` - [x] Nested bindings - [x] Carry over `mut` and `ref mut` in nested bindings to fields, i.e. `let Foo { ref mut bar } = ...` becomes `let Foo { bar: Bar { baz: ref mut baz } } = ...` - [x] Attempt to resolve collisions with other names in the scope - [x] If the binding is to a reference, field usages are dereferenced if required - [x] Use shorthand notation if possible ## Known limitations - `let foo = Foo { bar: 1 }; foo;` currently results in `let Foo { bar } = Foo { bar: 1 }; todo!();` instead of reassembling the struct. This requires user intervention. - Unused fields are not currently omitted. I thought that this is more ergonomic, as there already is a quick fix action for adding `: _` to unused field patterns.
bors
added a commit
that referenced
this pull request
Feb 29, 2024
feature: Add `destructure_struct_binding` Adds an assist for destructuring a struct in a binding (#8673). I saw that #13997 has been abandoned for a while, so I thought I'd give it a go. ## Example ```rust let foo = Foo { bar: 1, baz: 2 }; let bar2 = foo.bar; let baz2 = foo.baz; let foo2 = foo; let fizz = Fizz(1, 2); let buzz = fizz.0; ``` becomes ```rust let Foo { bar, baz } = Foo { bar: 1, baz: 2 }; let bar2 = bar; let baz2 = baz; let foo2 = todo!(); let Fizz(_0, _1) = Fizz(1, 2); let buzz = _0; ``` More examples in the tests. ## What is included? - [x] Destructure record, tuple, and unit struct bindings - [x] Edit field usages - [x] Non-exhaustive structs in foreign crates and private fields get hidden behind `..` - [x] Nested bindings - [x] Carry over `mut` and `ref mut` in nested bindings to fields, i.e. `let Foo { ref mut bar } = ...` becomes `let Foo { bar: Bar { baz: ref mut baz } } = ...` - [x] Attempt to resolve collisions with other names in the scope - [x] If the binding is to a reference, field usages are dereferenced if required - [x] Use shorthand notation if possible ## Known limitations - `let foo = Foo { bar: 1 }; foo;` currently results in `let Foo { bar } = Foo { bar: 1 }; todo!();` instead of reassembling the struct. This requires user intervention. - Unused fields are not currently omitted. I thought that this is more ergonomic, as there already is a quick fix action for adding `: _` to unused field patterns.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Adds an assist to destructure a struct in a binding. This is part of #8673, but more functionality is needed to bring it in line with tuple bindings. Similar to #9855 for tuple bindings, except that this pull does not yet edit the usages of the fields, just the original binding to an identifier.
->
Implemented:
mut
andref
from the original identifier to the fields of the structNot implemented:
#[non_exhaustive]
fields with..