Skip to content

rustc accepts types requiring a greater-than-48-bit address space #132525

Open
@shao-hua-li

Description

@shao-hua-li

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
%

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-layoutArea: Memory layout of typesC-discussionCategory: Discussion or questions that doesn't represent real issues.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions