rust-lang / rust-lang/rust-analyzer

Show bounds on variable with generic type

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

Nobody has claimed this yet.

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

Description

When I place the cursor over a variable defined with a generic type, I only get the name of the generic type, not its trait bounds (which is what I'm interested in, especially for types bounded by closure traits). For example, in a function defined like this:

pub fn run<F>(make_sessionizer: F)
where
    F: FnOnce(&Arc<Database>),
{
    // imagine many lines here...
    let sessionizer = make_sessionizer(Arc::new(Database));
    // ...
}

I would expect hovering above make_sessionizer to tell me how I can call the function, e.g. something like F: FnOnce(&Arc<Database>). What I actually get is make_sessionizer: F, which is technically correct, but not very useful on its own:

image

I use Emacs with Rustic, but I believe the contents of the popup entirely comes from rust-analyzer. For example (taken on slightly different code, but showing the same thing):

[Trace - 03:44:39 PM] Received response 'textDocument/hover - (6979)' in 887ms.
Result: {
  "range": {
    "end": {
      "character": 34,
      "line": 227
    },
    "start": {
      "character": 17,
      "line": 227
    }
  },
  "contents": {
    "value": "\n```rust\nmake_event_loader: F\n```",
    "kind": "markdown"
  }
}

Originally reported as brotzeit/rustic#311.

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 tracing rust-analyzer's textDocument/hover handling for the reported variable type, using the captured response as the expected current behavior. Determine how generic type bounds are represented for hover content, then verify that hovering make_sessionizer presents its FnOnce(&Arc) bound rather than only F.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
developer-experience, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.