Stream: t-compiler/rust-analyzer

Topic: New assist for converting tuple variant to struct variant

Joshua Warner (Jun 05 2021 at 02:45, on Zulip):

Hi! Aspiring new contributor here. I noticed there's an existing convert_tuple_struct_to_named_struct assist, and I've been toying with copy/paste/munging that into an assist that will do the analogous thing for tuple variants - e.g. enum E { V(usize) } -> enum E { V { field1: usize } }

I think I've gotten the hang of code layout/etc, and I have a new file, with content _mostly_ stolen from the original file. I've adapted some tests (which now fail, of course), as well as some of the code. For instance, it was fairly straight forward to turn edit_struct_def into edit_variant_def that does the obvious thing - and _seems_ to work.

The trouble comes with edit_struct_references, which starts with:

    let strukt_def = Definition::ModuleDef(hir::ModuleDef::Adt(hir::Adt::Struct(strukt)));
    let usages = strukt_def.usages(&ctx.sema).include_self_refs().all();

However, it's not obvious to me how to do the analogous thing to find the usages of a variant. Any tips?

Joshua Warner (Jun 05 2021 at 04:23, on Zulip):

Aha! Nevermind, figured it out. Definition::ModuleDef(hir::ModuleDef::Variant(variant)) was the ticket.

Joshua Warner (Jun 05 2021 at 04:51, on Zulip):


Last update: Jul 28 2021 at 04:15UTC