mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-02 07:22:42 +00:00
01d251789f
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 |
||
---|---|---|
.. | ||
base-db | ||
cfg | ||
flycheck | ||
hir | ||
hir-def | ||
hir-expand | ||
hir-ty | ||
ide | ||
ide-assists | ||
ide-completion | ||
ide-db | ||
ide-diagnostics | ||
ide-ssr | ||
limit | ||
mbe | ||
parser | ||
paths | ||
proc-macro-api | ||
proc-macro-srv | ||
proc-macro-test | ||
profile | ||
project-model | ||
rust-analyzer | ||
sourcegen | ||
stdx | ||
syntax | ||
test-utils | ||
text-edit | ||
toolchain | ||
tt | ||
vfs | ||
vfs-notify |