rust-lang / rust-lang/rust-analyzer

`implement missing members` doesn't apply feature flags

Open
#11,203 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

rust-analyzer version: 0add6e95e 2021-12-20 stable

rustc version: rustc 1.56.1 (59eed8a2a 2021-11-01)

rust-analyzer doesn't respect cfg(test) (or other feature flags) when applying the implement missing members assist. In practice this means that if I have this code:

trait Foo {
    #[cfg(test)]
    fn foo_method();
}

struct Bar;

impl Foo for Bar {}

Then applying "implement missing members" on that impl block gives:

trait Foo {
    #[cfg(test)]
    fn foo_method();
}

struct Bar;

impl Foo for Bar {
    fn foo_method() {
        todo!()
    }
}

Whereas I would like to get:

trait Foo {
    #[cfg(test)]
    fn foo_method();
}

struct Bar;

impl Foo for Bar {
    #[cfg(test)]
    fn foo_method() {
        todo!()
    }
}

I'm guessing this is a non-trivial problem, but it would be super nice if rust-analyzer could pick up on some of these cases (even if it's just cfg(test)) and handle them correctly.

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 at the implement missing members assist and trace how it copies trait members into the impl. Check how cfg(test) and feature flags are handled there; done when generated methods preserve applicable cfg attributes, with tests covering the shown case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.