rust-lang / rust-lang/rust-analyzer
inline assist not working properly on `Hash::hash`
Nobody has claimed this yet.
- 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)
};
...
&mutHshould be&mut H*selfshould 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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