rust-lang / rust-lang/rust-analyzer
Constant evaluation in array and structure sizes
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: 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:
Output without the constant being used:
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 with the provided Rust snippet and compare rust-analyzer's size calculation when the array length is a constant from another module versus a literal. The report names no source file or test, so locate the constant-evaluation and type-size analysis paths before investigating how the result propagates to parent structures. Done means the constant-based array and enclosing structure sizes are understood correctly in larger projects.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100