rust-lang / rust-lang/rust-analyzer

Duplicated functions on the list

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

Nobody has claimed this yet.

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

Description

rust-analyzer version: v0.3.1258
rustc version: rustc 1.64.0 (a55dd71d5 2022-09-19)

Functions on the list are duplicated when implemented by macro.

pub struct Vec2<T> {
    pub x: T,
    pub y: T,
}

macro_rules! implement {
    ($type:ident) => {
        impl Vec2<$type> {
            pub fn length(&self) -> f64 {
                ((self.x as f64).powf(2.0) + (self.y as f64).powf(2.0)).sqrt()
            }
        }
    }
}

implement!(u8);
implement!(i8);
implement!(u16);
implement!(i16);
implement!(i32);
implement!(u32);

pub fn main() {
    // Vec2::
    // Vec2::<i32>::
}

The first case is when we don't specify the generic type in ``Vec2` explicitly:
image

The second case when using Vec2::<i32>:
image

While I can somehow understand why it's displaying duplicates in the first case (still don't like it tho), it rather shouldn't do it in the second one.

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 reproducing the duplicated completion results with the Rust macro example in the issue, checking both Vec2:: and Vec2::<i32>::. Trace the completion results for macro-generated functions and consider the work complete when the generic form lists length only once while the reproduction remains covered by an appropriate test.

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
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.