Skip to content

Constant evaluation in array and structure sizes #20414

@MihaelBercic

Description

@MihaelBercic

rust-analyzer version: rust-analyzer-2025-08-04

rustc version: rustc 1.88.0 (6b00bc388 2025-06-23)

editor or extension: Zed Editor - default rust-analyzer lsp support

relevant settings: /

repository link (if public, optional): /

Note: Can not be reproduced in smaller playgrounds, only bigger projects...

The issue is that the r-a cannot "understand" the constant value when calculating the sizes. This in turns is quite a big issue when improving the sizes of structures in larger projects where memory is a tight resource. Since the inability to calculate the size propagates to parent structures as well.

code snippet to reproduce:

// in another module
pub const MATTER_MESSAGE_EXTENSION_BYTES: usize = 10;

#[derive(Debug, Eq, PartialEq, Clone)]
struct Header {
    message_extensions: Option<[u8; MATTER_MESSAGE_EXTENSION_BYTES]>,
}

Output with the constant being used:

Image

Output without the constant being used:

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions