I understand why stack overflows happen if you have too many recursive function calls, but I don't know why this specific code overflows. It's only using a for loop and the Boxs should mean that all the data is put on the heap not the stack(?). Any help would be appreciated 🙂
fn main() {
make_tree(1_000_000);
}
enum Tree{
Leaf,
Node((Box<Tree>, Box<Tree>))
}
fn make_tree(n:usize){
let mut res = Tree::Leaf;
for _ in 0..n {
res = Tree::Node((
Box::new(Tree::Leaf),
Box::new(res),
));
}
}