diff options
| author | bors <bors@rust-lang.org> | 2022-07-16 16:36:57 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-07-16 16:36:57 +0000 |
| commit | 01d251789f3fee16b9f9a2663ca2922abec5269f (patch) | |
| tree | 8ad753e287d2667033ae719e68f3c459f0d212d0 /src/test/codegen/src-hash-algorithm | |
| parent | ac526e029a22b64e59f9ab65500898d5399869c4 (diff) | |
| parent | a5ad4de11186961f8f9b13cfee383af59e75c5d1 (diff) | |
| download | rust-01d251789f3fee16b9f9a2663ca2922abec5269f.tar.gz rust-01d251789f3fee16b9f9a2663ca2922abec5269f.zip | |
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
Diffstat (limited to 'src/test/codegen/src-hash-algorithm')
0 files changed, 0 insertions, 0 deletions
