rust-lang / rust-lang/rust-analyzer

"Rename" for references in HRTB

Open
#17,887 3 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

It seems like rust-analyzer doesn't support renaming lifetimes within a higher-ranked trait bound.

Example code: (from https://doc.rust-lang.org/nomicon/hrtb.html)

struct Closure<F> {
    data: (u8, u16),
    func: F,
}

impl<F> Closure<F>
where
    for<'a> F: Fn(&'a (u8, u16)) -> &'a u8,
{
    fn call<'x>(&'x self) -> &'x u8 {
        (self.func)(&self.data)
    }
}

Going to 'x and pressing F2 in VSCode shows a renaming dialog. However, trying to rename 'a doesn't work (Request failed: No references found at position in the trace).

image

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 higher-ranked trait bound example in the issue and reproduce the failed rename of 'a in VSCode. Trace rust-analyzer's rename and reference-resolution handling for lifetime parameters, then verify that renaming 'a updates all of its references without regressing the working 'x case.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, devtools
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.