Why does this Rust binary tree overflow its stack in tests? [duplicate]
Why does this Rust binary tree overflow its stack in tests? [duplicate] This question already has an answer here: I've written a binary tree-like structure, but I've been getting stack-overflow errors in some of my stress tests. I've reduced the error-causing code down to the following: struct Node { index: usize, right: Option>, } struct BoxedTree { root: Option<Box<Node>>, } fn build_degenerate() { let mut t = BoxedTree { root: Some(Box::new(Node { index: 0, right: None, })), }; let mut n = t.root.as_mut().unwrap(); for i in 1..50000 { let cur = n; let p = &mut cur.right; *p = Some(Box::new(Node { index: i, right: None, })); n = p.as_mut().unwrap(); } println!("{}", n.index); } fn main() { build_degenerate(); } #[cfg(test)] mod tests { use super::*; #[test] fn mytest() { ...