Skip to content

Parameter Size Display Bug #19517

Open
Open
@TheoAC

Description

@TheoAC

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 (fb133c8 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-layoutMemory layout of typesC-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions