rust-lang / rust-lang/rust-analyzer

inline assist not working properly on `Hash::hash`

Open
#16,471 12 comments 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: 0.4.1810-standalone

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

relevant settings: None

with this code,

pub struct MyStruct {
    value: u64,
}

impl std::hash::Hash for MyStruct {
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        self.value.hash(state);
    }
}

impl MyStruct {
    pub fn as_u64(&self) -> u64 {
        self.value
    }
}

place the cursor on hash in self.value.hash(state); and apply the inline function assist

this is the result:

...
        {
            let this = &self.value;
            let state: &mutH = state;
          state.write_u64(*self)
        };
...
  • &mutH should be &mut H
  • *self should be *this
  • the first two lines are indented with 4 spaces (normal), but state.write_u64(*self) only with 2, this is automatically fixed with the formatter but still doesnt look nice

the cause could be that the Hash impl for u64 is macro generated, but i dont know exactly

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 function assist on self.value.hash(state) with the Rust snippet in the report, then inspect the inline function assist implementation and its generated output. Done means the assist preserves the space in &mut H, uses *this, and produces consistently formatted indentation before running the relevant assist tests.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.