rust-lang / rust-lang/rust-analyzer

'inline function' assist does not take generic type parameters into account

Open
#16,373 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

rust-analyzer version: rust-analyzer version: 0.4.1808-standalone (a616c4d11 2024-01-15)

rustc version: rustc 1.75.0 (82e1608df 2023-12-21)

relevant settings: none

This issue is similar to https://github.com/rust-lang/rust-analyzer/issues/16090 but it seems more likely to happen on most generic types.

use std::ops::Add;

struct Foo<T: Add + Default>(T);

impl<T: Add + Default> Foo<T> {
    fn clear(&mut self) {
        self.0 = T::default();
    }
}

fn main() {
    let foo: &mut Foo<i32> = &mut Foo(3);
    // foo.clear(); inline `clear` yeild:
    {
        let ref mut this = foo;
        this.0 = T::default();
        //       ^------------ expect: i32
    };
    foo.0 += 1;
}

### Tasks
- [ ] https://github.com/rust-lang/rust-analyzer/issues/16090
- [ ] https://github.com/rust-lang/rust-analyzer/issues/15471
- [ ] https://github.com/rust-lang/rust-analyzer/issues/15470

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 inline clear assist behavior with the Rust example in the issue, focusing on the generic T used in T::default(). Compare the generated code with the expected i32 type; done means the assist accounts for the impl's generic type parameters.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.