rust/crates
bors 71eb5400a3 Auto merge of #16638 - Lindronics:destructure-struct-binding, r=Veykril
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.
2024-02-29 14:07:50 +00:00
..
base-db fix: Fix modules in blocks not resolving in ide layer 2024-02-26 14:54:47 +01:00
cfg
flycheck Merge commit 'ac998a74b3c8ff4b81c3eeb9a18811d4cc76226d' into sync-from-ra 2024-02-18 09:41:20 +02:00
hir Fix goto index_mut 2024-02-29 00:52:58 +09:00
hir-def fix: Fix modules in blocks not resolving in ide layer 2024-02-26 14:54:47 +01:00
hir-expand Merge commit 'ac998a74b3c8ff4b81c3eeb9a18811d4cc76226d' into sync-from-ra 2024-02-18 09:41:20 +02:00
hir-ty Auto merge of #16630 - ShoyuVanilla:fix-closure-kind-inference, r=Veykril 2024-02-27 14:41:23 +00:00
ide Add a new failing test for Goto index_mut definition 2024-02-29 00:52:30 +09:00
ide-assists Fix usage in other assist 2024-02-29 13:17:45 +00:00
ide-completion Auto merge of #16687 - kilpkonn:master, r=Veykril 2024-02-27 09:41:14 +00:00
ide-db Auto merge of #16555 - davidbarsky:david/speedup-completions-by-exploiting-orphan-rules, r=Veykril 2024-02-26 18:05:52 +00:00
ide-diagnostics Auto merge of #16684 - Veykril:synthetic-fmt-args, r=Veykril 2024-02-26 16:47:57 +00:00
ide-ssr Merge commit 'ddf105b646c6749a2de2451c9a499a354eec79c2' into sync-from-ra 2024-02-11 08:40:19 +02:00
intern
limit Merge commit 'ddf105b646c6749a2de2451c9a499a354eec79c2' into sync-from-ra 2024-02-11 08:40:19 +02:00
load-cargo internal: Fetch toolchain and datalayout for DetachedFiles 2024-02-20 10:40:39 +01:00
mbe Merge commit 'ac998a74b3c8ff4b81c3eeb9a18811d4cc76226d' into sync-from-ra 2024-02-18 09:41:20 +02:00
parser Merge commit 'ac998a74b3c8ff4b81c3eeb9a18811d4cc76226d' into sync-from-ra 2024-02-18 09:41:20 +02:00
paths Add to_path_buf() method for RelPath 2024-02-27 18:33:47 +01:00
proc-macro-api Fix rust-analyzer not enabling rust-analyzer spans on the proc-macro server 2024-02-22 22:34:03 +01:00
proc-macro-srv fix: Fix proc-macro server not accounting for string delimiters correctly 2024-02-22 22:34:03 +01:00
proc-macro-srv-cli Merge commit 'ddf105b646c6749a2de2451c9a499a354eec79c2' into sync-from-ra 2024-02-11 08:40:19 +02:00
profile Merge commit 'ddf105b646c6749a2de2451c9a499a354eec79c2' into sync-from-ra 2024-02-11 08:40:19 +02:00
project-model fix: rust-project.json projects not preferring sysroot rustc 2024-02-27 10:20:07 +01:00
rust-analyzer Filter out false positive errors 2024-02-26 20:17:09 +02:00
salsa Remove salsa compile_fail tests 2024-02-26 15:26:55 +02:00
sourcegen Merge commit 'ddf105b646c6749a2de2451c9a499a354eec79c2' into sync-from-ra 2024-02-11 08:40:19 +02:00
span Merge commit 'ddf105b646c6749a2de2451c9a499a354eec79c2' into sync-from-ra 2024-02-11 08:40:19 +02:00
stdx Deduplicate references to macro argument 2024-02-19 12:23:59 +01:00
syntax Add destructure_struct_binding action 2024-02-29 13:17:44 +00:00
test-fixture Merge commit 'ac998a74b3c8ff4b81c3eeb9a18811d4cc76226d' into sync-from-ra 2024-02-18 09:41:20 +02:00
test-utils Merge commit 'ac998a74b3c8ff4b81c3eeb9a18811d4cc76226d' into sync-from-ra 2024-02-18 09:41:20 +02:00
text-edit Merge commit 'ddf105b646c6749a2de2451c9a499a354eec79c2' into sync-from-ra 2024-02-11 08:40:19 +02:00
toolchain prioritise rustup sysroots over system ones 2024-02-24 21:19:10 +00:00
tt Merge commit 'ac998a74b3c8ff4b81c3eeb9a18811d4cc76226d' into sync-from-ra 2024-02-18 09:41:20 +02:00
vfs Merge commit 'ddf105b646c6749a2de2451c9a499a354eec79c2' into sync-from-ra 2024-02-11 08:40:19 +02:00
vfs-notify