rust/crates
bors 01d251789f Auto merge of #12539 - soruh:instanciate_empty_structs, r=Veykril
Automatically instaciate trivially instaciable structs in "Generate new" and "Fill struct fields"

As proposed in #12535 this PR changes the "Generate new" and "Fill struct fields" assist/diagnostic to instanciate structs with no fields and enums with a single empty variant.

For example:
```rust
pub enum Bar {
    Bar {},
}
struct Foo<T> {
    a: usize,
    bar: Bar,
    _phantom: std::marker::PhantomData<T>,
}
impl<T> Foo<T> {
    /* generate new */

    fn random() -> Self {
        Self { /* Fill struct fields */ }
    }
}
```

was previously:
```rust
impl<T> Foo<T> {
    fn new(a: usize, bar: Bar, _phantom: std::marker::PhantomData<T>) -> Self {
        Self { a, bar, _phantom }
    }

    fn random() -> Self {
        Self {
            a: todo!(),
            bar: todo!(),
            _phantom: todo!(),
        }
    }
}
```

and is now:
```rust
impl<T> Foo<T> {
  fn new(a: usize) -> Self {
      Self {
          a,
          bar: Bar::Bar {},
          _phantom: std::marker::PhantomData
      }
  }

  fn random() -> Self {
      Self {
          a: todo!(),
          bar: Bar::Bar {},
          _phantom: std::marker::PhantomData,
      }
  }
}
```

I'd be happy about any suggestions.

## TODO
   - [x]  deduplicate `use_trivial_constructor` (unclear how to do as it's used in two separate crates)
   - [x]  write tests

Closes #12535
2022-07-16 16:36:57 +00:00
..
base-db Update remaining GitHub URLs 2022-07-08 15:44:49 +02:00
cfg internal: Bump Dependencies 2022-06-10 17:30:02 +02:00
flycheck Bump cargo_metadata 2022-07-03 10:09:35 +03:00
hir Auto merge of #12766 - Veykril:completion-vis, r=Veykril 2022-07-16 09:29:20 +00:00
hir-def Auto merge of #12772 - Veykril:nameres, r=Veykril 2022-07-16 09:50:22 +00:00
hir-expand Improve syntax fixup a bit, handle incomplete if 2022-07-16 13:03:32 +02:00
hir-ty Update remaining GitHub URLs 2022-07-08 15:44:49 +02:00
ide Auto merge of #12712 - harpsword:fix-rename-crate-root, r=Veykril 2022-07-16 16:28:41 +00:00
ide-assists Auto merge of #12539 - soruh:instanciate_empty_structs, r=Veykril 2022-07-16 16:36:57 +00:00
ide-completion Auto merge of #12773 - Veykril:self-compl, r=Veykril 2022-07-16 10:28:52 +00:00
ide-db Auto merge of #12539 - soruh:instanciate_empty_structs, r=Veykril 2022-07-16 16:36:57 +00:00
ide-diagnostics Auto merge of #12539 - soruh:instanciate_empty_structs, r=Veykril 2022-07-16 16:36:57 +00:00
ide-ssr internal: Bump Dependencies 2022-06-10 17:30:02 +02:00
limit Use compare_exchange_weak in limit::Limit::check 2022-01-28 18:19:35 +03:00
mbe Improve syntax fixup a bit, handle incomplete if 2022-07-16 13:03:32 +02:00
parser Update remaining GitHub URLs 2022-07-08 15:44:49 +02:00
paths Bump MSRV (1.57) 2021-12-16 01:56:12 +05:00
proc-macro-api Update remaining GitHub URLs 2022-07-08 15:44:49 +02:00
proc-macro-srv Update 1.63 proc macro ABI to match rustc 2022-07-12 15:19:31 +02:00
proc-macro-test Bump cargo_metadata 2022-07-03 10:09:35 +03:00
profile Update remaining GitHub URLs 2022-07-08 15:44:49 +02:00
project-model Fix rustcSource -> rustc_source 2022-07-11 16:50:20 +09:00
rust-analyzer Fix obsolete enableRangeFormatting config 2022-07-11 16:52:35 +09:00
sourcegen Update remaining GitHub URLs 2022-07-08 15:44:49 +02:00
stdx Polish 2022-06-15 18:35:48 +02:00
syntax Update remaining GitHub URLs 2022-07-08 15:44:49 +02:00
test-utils internal: Bump Dependencies 2022-06-10 17:30:02 +02:00
text-edit style: rename crates to kebab case 2022-05-01 10:48:58 +00:00
toolchain Bump MSRV (1.57) 2021-12-16 01:56:12 +05:00
tt internal: Bump Dependencies 2022-06-10 17:30:02 +02:00
vfs Bump indexmap 2022-07-03 10:09:35 +03:00
vfs-notify Bump crossbeam-channel 2022-07-03 09:56:58 +03:00