rust-lang / rust-lang/rust-analyzer

rust-analyzer's function argument tooltip shows wrong `impl Trait` type.

Open
#12,700 2 comments 0 reactions 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: rust-analyzer version: 0.0.0 (ce3644694 2022-06-30)

rustc version: cargo 1.62.0-nightly (a44758ac8 2022-05-04)

For this code:

trait Foo{}
fn foo(_x: impl Foo){}

trait Bar{}
fn bar() -> impl Bar {  }
impl Bar for (){}
impl<T:Bar> Foo for T{} 

fn main() {
    let a = bar();
    foo(┃a); // tooltip when completing arguments: fn foo(_x: impl Bar)
    // expected:  fn foo(_x: impl Foo)
}

I expect RA to show impl Foo when completing arguments (Ctrl+Shift+Space) from within function call parentheses.
However, it shows as if function accepts another trait impl, being influenced by the type of the variable that is passed into the function call.
Tooltop for the function itself correctly shows impl Foo instead, and I expect argument completion tooltip to match the documentation tooltip unless RA lacks some info.

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 with the minimal Rust example in the issue and reproduce the argument-completion tooltip using Ctrl+Shift+Space. Compare it with the function's documentation tooltip; done means argument completion displays fn foo(_x: impl Foo) rather than using the passed variable's impl Bar type.

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
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.