rust-lang / rust-lang/rust-analyzer
Parameter Size Display Bug
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.9k
- Forks
- 2.2k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 72
Description
I've found what I understand to be a minor bug in how rust-analyzer displays size information for variables. In a generic function, parameters of type &T are assumed to be one word in size, even with the type bound T: ?Sized. But if T happens to be a dynamically sized type, then a parameter of type &T will be a wide pointer, which is two words in size. In this case, we have an inconsistency:
// parameter `_x` has `size = 8, align = 0x8`
fn foo<T: ?Sized>(_x: &T) {}
fn main() {
// variable `x` has `size = 16 (0x10), align = 0x8`
let x = "";
foo(x);
}
The comments in the code above refer to what rust-analyzer displays when hovering the mouse over the declaration of the parameter/variable. The issue here is that the display for _x as a parameter of foo is not necessarily correct.
rust-analyzer version:
0.3.2362-standalone (fb133c8c80 2025-03-29)
rustc version:
rustc 1.85.0 (4d91de4e4 2025-02-17)
editor:
VSCode, Version 1.98.2
This is my first time contributing to a public project, so I especially appreciate any input for improving this report.
To whom it may concern, I thank you for your time. Hugs and kisses.
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
The report names no source file or test. Reproduce the generic fn foo<T: ?Sized>(_x: &T) example in VSCode and trace the hover size display for the parameter versus the dynamically sized value; done when the parameter's displayed size accounts for a wide pointer when appropriate.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100