-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Open
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
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 #142532 and #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
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.