rustc accepts types requiring a greater-than-48-bit address space
Open
Nobody has claimed this yet.
A-layout
C-discussion
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
Code
I tried this code:
use std::mem::size_of;
pub fn main() {
assert_eq!(size_of::<[u8; (31 << 47) - 1]>(), (1 << 47) - 1);
}
I expected to see this happen: rustc rejects the code
Instead, this happened: rustc-nightly accepts it.
Version it worked on
It most recently worked on: Rust 1.82
% rustc test.rs
error[E0080]: evaluation of constant value failed
--> /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/mem/mod.rs:309:5
|
= note: values of the type `[u8; 4362862139015167]` are too big for the current architecture
|
note: inside `std::mem::size_of::<[u8; 4362862139015167]>`
--> /rustc/f6e511eec7342f59a25f7c0534f1dbea00d01b14/library/core/src/mem/mod.rs:309:5
note: inside `main`
--> src/main.rs:10:16
|
10 | assert_eq!(size_of::<[u8; (31 << 47) - 1]>(), (1 << 47) - 1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: erroneous constant encountered
--> src/main.rs:10:5
|
10 | assert_eq!(size_of::<[u8; (31 << 47) - 1]>(), (1 << 47) - 1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this note originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0080`.
%
% rustc --version --verbose
rustc 1.82.0 (f6e511eec 2024-10-15)
binary: rustc
commit-hash: f6e511eec7342f59a25f7c0534f1dbea00d01b14
commit-date: 2024-10-15
host: x86_64-unknown-linux-gnu
release: 1.82.0
LLVM version: 19.1.1
%
Version with regression
% rustc test.rs
%
% rustc --version --verbose
rustc 1.84.0-nightly (a0d98ff0e 2024-10-31)
binary: rustc
commit-hash: a0d98ff0e5b6e1f2c63fd26f68484792621b235c
commit-date: 2024-10-31
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1
%
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
Reproduce the example in test.rs with Rust 1.82 and the reported nightly, then inspect the size-of evaluation referenced at library/core/src/mem/mod.rs:309. Trace where the oversized type is accepted and add regression coverage for this case. Done means the example is rejected again with an appropriate compile-time error.
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
- 38/100