rust-lang / rust-lang/rust-analyzer

Feature request: Generate type definition from struct or enum literal

Open
#13,703 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

It would be really nice for quick prototyping if there was an assist that could generate a struct or enum definition given a corresponding literal with an undefined type name at the front.

Record struct:

let foo = Foo$0 { field: "hello".to_owned() };

// generate type definition
struct Foo {
    field: String,
}

Tuple struct:

let foo = Foo$0("world");

// generate type definition
struct Foo<'a>(&'a str);

Enum:

let bar = Foo$0::Bar;
let baz = Foo::Baz;

// generate type definition
enum Foo {
    Bar,
    Baz,
}

(and equivalent for enums with tuple or record fields)

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 names no files, tests, or entry points. Start by locating rust-analyzer's assist handling for undefined types and use the record, tuple-struct, and enum examples as acceptance cases. Done means generating struct or enum definitions, including tuple or record fields and required lifetimes, from the literals shown.

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
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.