rust-lang / rust-lang/rust-analyzer

Generate method assist misses generics when generating an impl block

Open
#19,806 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Input:

struct Generic<T: Send>(T);

fn foo() {
    Generic("test").do_a_thing()
}

Current output:

struct Generic<T: Send>(T);
impl Generic {
    fn do_a_thing(&self) {
        todo!()
    }
}

fn foo() {
    Generic("test").do_a_thing()
}

Expected output:

struct Generic<T: Send>(T);

impl<T: Send> Generic<T> {
    fn do_a_thing(&self) {
        todo!()
    }
}

fn foo() {
    Generic("test").do_a_thing()
}

I suppose impl Generic<&'static str> would also be an option, but less likely to be what the user intended.

rust-analyzer version: 0.4.2462-standalone
rustc version: 1.89.0-nightly (414482f6a 2025-05-13)
editor or extension: VSCode (ext version 0.4.2462)

@rustbot label +A-assists

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

Reproduce the method-assist case from the issue with the generic Generic<T: Send> and compare the generated impl block with the expected output. Trace the generate-method assist and its impl-block generation to find where generic parameters are lost; done means the assist preserves the bounds and type parameters shown in the expected output.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.