Will `Box<T>` allocate memory by declaration?


Below will cause the stack overflow:

let foo: [i32; 10000000]; 

Below will not cause the stack overflow, but I wonder if it will allocate memory on the heap without initialization (Box<T>::new):

let bar: Box<[i32; 10000000]>;


Just realized after reading the source:


pub struct Box<T: ?Sized>(Unique<T>);

It won’t. All that does is reserve space on the stack for the Box pointer, but it can’t put anything in it until you allocate something.


Sadly it won’t. Issue on GH https://github.com/rust-lang/rust/issues/53827