rust-lang / rust-lang/rust-analyzer

Parameter Size Display Bug

Open
#19,517 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-layout C-bug
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

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.