rust-lang / rust-lang/rust-analyzer

Refactor support for converting enum variants with fields to structs

Open
#6,129 3 comments 8 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-assists E-hard fun S-actionable
Dominant language
Rust
Stars
16.9k
Forks
2.2k
Avg merge
1d 12h
Merged PRs (30d)
72

Description

Use case: Rustdoc has a struct with a bunch of repeated fields:

pub enum DocFragment {
    SugaredDoc(usize, Span, String),
    RawDoc(usize, Span, String),
    Include(usize, Span, String, String),
}

I want to turn that into

pub struct DocFragment {
    line_number: usize,
    span: Span,
    doc: String,
    kind: DocKind,
}

pub enum DocKind {
  SugaredDoc,
  RawDoc,
  Include { filename: String },
}

and update all usages.

Probably this can't be 100% automated - the field names in particular need user input and refactoring out the enum might be tricky. But it would be nice to have some amount of support.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue provides the Rustdoc DocFragment enum example and the desired struct-plus-DocKind shape, but names no rust-analyzer files, tests, or entry points. Start by locating the refactoring support for enum variants with fields; done means providing useful conversion support and updating affected usages, with user-supplied field names where automation cannot decide.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.