rust-lang / rust-lang/rust-analyzer

Provide assistance for writing an impl block

Open
#17,590 7 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

When I am at a type, I can select a "generate impl" assist and it will generate a block right below the type. That's useful, but often I am somewhere else in the project (might not even be the same file), and I want to generate an impl block here. Would be great if there was some way to get the assist there as well. :)

What I usually try is to write impl TypeName, and then my hope would be that (a) I get auto-complete (including auto-import) for the type name, and (b) I can then select an assist to generate an impl block, and it will turn this into

impl<'a, T: Bound> TypeName<'a, T> {
  /* cursor here */
}

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

Start by locating the existing "generate impl" assist that works when the cursor is at a type, then inspect how it determines the target type and creates the impl block. The work is done when the assist is available after writing impl TypeName elsewhere and produces the requested generic and lifetime-aware block, including the cursor position.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.