This code runs fine:
use std::mem::size_of;
fn main() {
println!("{}", size_of::<[(); usize::max_value()]>());
let x = [(); usize::max_value()];
println!("done");
}
It immediately prints 0 and done. The array is 0 bytes large after all, so this is expected.
If I use a Vec however, things look different:
fn main() {
let x = vec![(); usize::max_value()];
println!("done");
}
This runs a very long time and never prints done. Why is that? I also expect the vector to have 0 actual size. So it shouldn't need to allocate or write any memory. What is taking so long?
This only happens when I compile without optimizations. With optimizations, it finished immediately.