ab62c0186f
feat: implement tuple return type to tuple struct assist This PR implements the `convert_tuple_return_type_to_struct` assist, for converting the return type of a function or method from a tuple to a tuple struct. Additionally, it moves the `to_camel_case` and `char_has_case` functions from `case_conv` to `stdx` so that they can be used similar to `to_lower_snake_case`. [tuple_return_type_to_tuple_struct.webm](https://github.com/rust-lang/rust-analyzer/assets/52933714/2803ff58-fde3-4144-9495-7c7c7e139075) Currently, the assist puts the struct definition above the function, or above the nearest `impl` or `trait` if applicable and only rewrites literal tuples that are returned in the body of the function. Additionally, it only attempts to rewrite simple tuple pattern usages with the corresponding tuple struct pattern but does so across files and modules. I think that this is sufficient for the majority of use cases but I could be wrong. One thing I'm still not sure how to approach is handling `Self` and generics/lifetimes in the tuple type to be extracted. I was thinking of either manually figuring out what lifetimes and generics are in scope and using them (sort of similar to the `generate_function` assist) or maybe using `ctx.sema.resolve_type` and `generic_params` on `hir::Type` but this seems to not deal with lifetimes. Closes #14293 |
||
---|---|---|
.. | ||
consteval | ||
diagnostics | ||
infer | ||
layout | ||
mir | ||
tests | ||
autoderef.rs | ||
builder.rs | ||
chalk_db.rs | ||
chalk_ext.rs | ||
consteval.rs | ||
db.rs | ||
diagnostics.rs | ||
display.rs | ||
infer.rs | ||
inhabitedness.rs | ||
interner.rs | ||
lang_items.rs | ||
layout.rs | ||
lib.rs | ||
lower.rs | ||
mapping.rs | ||
method_resolution.rs | ||
mir.rs | ||
primitive.rs | ||
test_db.rs | ||
tests.rs | ||
tls.rs | ||
traits.rs | ||
utils.rs |