size_of_val is allowed on an uninitialized static
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I don't know if this is a bug or working as intended. So I'm filing an issue just in case.
trait Trait {}
impl Trait for usize {}
static X: usize = std::mem::size_of_val(&X as &dyn Trait);
fn main() {
println!("{X}");
}
This code compiles and prints 8. I'm not sure if this code is supposed to compile.
See also https://github.com/rust-lang/rust/issues/142532 and https://github.com/rust-lang/rust/issues/142404 for shenanigans with uninitialized statics.
Meta
rustc --version --verbose:
rustc 1.89.0-nightly (be19eda0d 2025-06-22)
binary: rustc
commit-hash: be19eda0dc4c22c5cf5f1b48fd163acf9bd4b0a6
commit-date: 2025-06-22
host: aarch64-apple-darwin
release: 1.89.0-nightly
LLVM version: 20.1.7
@rustbot labels +A-const-eval
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 by compiling the supplied Rust reproduction with the reported nightly version and compare its behavior with issues #142532 and #142404. The issue names no source file or test; progress would require establishing whether this const-evaluation behavior is valid and documenting a clear expected outcome.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100