book
book copied to clipboard
Section 15.01 Add a warning for recursive drop
Currently, in section 15.01, the book explains how Box can be used to build recursive data structures(in particular, linked list.) However, the book does not warn against the potential stack overflow issue due to recursive drop in such data structures. This can bite new users, especially people from GC'ed languages.
Maybe we can add a warning in that section? A new paragraph like 'Note: implementing recursive data structures is more complex than this example because the default Drop implementation can lead to stack overflow. Rust Nominocon provides more details.' might be sufficient.
While writing recursive data structures in Rust is difficult in general and the book probably cannot document every detail, stack overflow is particularly annoying because it can only be triggered in runtime for large enough inputs, unlike those lifetime issues. Hence, I think adding this specific warning can be helpful.
Hmm, this is an interesting one. The book doesn’t talk about the Drop trait till 15.3, and the first time it brings up stack overflows is 15.6. Accordingly, we definitely should not discuss it in 15.1. I am iffy on whether we should bring it up at all, though. As you say:
the book probably cannot document every detail
There are many such things the book does not cover. My current feeling is that this one is probably best left for other materials—while I am certainly aware this can come up, I have not hit it at any point in the last nine years, and I don’t think it is especially common. It is also the kind of thing someone can fairly readily look up (see e.g. the DuckDuckGo results for the phrase "rust stack overflow in drop").
I am not closing this just yet because I want to mull on it a bit longer, but I think we will most likely leave it as is.
I’ve reread this section and thought on it a bunch, and I think unfortunately this is going to have to stay in the “too much detail” bucket. It’s true that you can do this, but it’s also relatively easy to figure out by searching online, and I cannot see a good spot in the chapter to mention it! (I spent way too long just now looking for such a spot. 😅)