mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-08 16:07:43 +00:00
![]() 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 |
||
---|---|---|
.. | ||
generated | ||
imports | ||
syntax_helpers | ||
test_data | ||
tests | ||
active_parameter.rs | ||
apply_change.rs | ||
assists.rs | ||
defs.rs | ||
famous_defs.rs | ||
helpers.rs | ||
items_locator.rs | ||
label.rs | ||
lib.rs | ||
line_index.rs | ||
path_transform.rs | ||
rename.rs | ||
rust_doc.rs | ||
search.rs | ||
source_change.rs | ||
symbol_index.rs | ||
traits.rs | ||
ty_filter.rs | ||
use_trivial_contructor.rs |