rust/crates/ide-db/src
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
..
generated style: rename crates to kebab case 2022-05-01 10:48:58 +00:00
imports fix: Fix imports being inserted before doc comments in inline modules 2022-07-14 22:56:56 +02:00
syntax_helpers fix: improve whitespace insertion in pretty printer 2022-06-28 20:44:55 +09:00
test_data style: rename crates to kebab case 2022-05-01 10:48:58 +00:00
tests style: rename crates to kebab case 2022-05-01 10:48:58 +00:00
active_parameter.rs style: rename crates to kebab case 2022-05-01 10:48:58 +00:00
apply_change.rs style: rename crates to kebab case 2022-05-01 10:48:58 +00:00
assists.rs style: rename crates to kebab case 2022-05-01 10:48:58 +00:00
defs.rs minor: Simplify 2022-05-20 16:52:10 +02:00
famous_defs.rs Improve "Generate Deref impl" assist 2022-05-16 20:10:46 +02:00
helpers.rs style: rename crates to kebab case 2022-05-01 10:48:58 +00:00
items_locator.rs style: rename crates to kebab case 2022-05-01 10:48:58 +00:00
label.rs style: rename crates to kebab case 2022-05-01 10:48:58 +00:00
lib.rs apply suggestions 2022-06-22 16:29:59 +02:00
line_index.rs style: rename crates to kebab case 2022-05-01 10:48:58 +00:00
path_transform.rs style: rename crates to kebab case 2022-05-01 10:48:58 +00:00
rename.rs Auto merge of #12712 - harpsword:fix-rename-crate-root, r=Veykril 2022-07-16 16:28:41 +00:00
rust_doc.rs style: rename crates to kebab case 2022-05-01 10:48:58 +00:00
search.rs fix: Fix unresolved proc macro diagnostics pointing to macro expansions 2022-07-05 12:46:09 +02:00
source_change.rs style: rename crates to kebab case 2022-05-01 10:48:58 +00:00
symbol_index.rs dead code 2022-05-21 13:39:59 +01:00
traits.rs style: rename crates to kebab case 2022-05-01 10:48:58 +00:00
ty_filter.rs style: rename crates to kebab case 2022-05-01 10:48:58 +00:00
use_trivial_contructor.rs add doc strings to use_trivial_contructor.rs 2022-06-22 16:49:50 +02:00