Question Details

No question body available.

Tags

rust

Answers (1)

Accepted Answer Available
Accepted Answer
June 25, 2026 Score: 5 Rep: 123,119 Quality: Expert Completeness: 80%

It is a technical limitation. LLVM uses 64-bit integers to represent the size of the object in bits. This leaves 61 bits for the size in bytes. So for an LLVM-based implementation an object cannot be larger than 2^61-1 bytes.

I could not find this in the documentation, but the limit is there in rustc source.

The number was bumped from 2^47 to 2^61 in 2024.

The line

let : [u8; isize::MAX as usize / 4 + 1];

is locally known to be a no-op, so perhaps this is the reason why it is accepted. The compiler doesn't need to actually create an object, so it doesn't need to check the size, regardless of what comes next in the program.

The line

let _a: [u8; isize::MAX as usize / 4];

is accepted because the size is exactly 2^61-1 bytes.

In actual practice the object size cannot be larger than the address space size supported by the hardware, which for Intel hardware is 2^57 bytes. Going over that limit is likely to result in a runtime error though, not a compilation error (if the object in question is not optimized out completely).

The practical size of an object on the stack is much smaller than that, but again that would be a runtime error.