Panic in Vec drop
โ Rust ๐ 2026-02-27 ๐ค surdeus ๐๏ธ 3What happens after one of the elements of a Vec panics when it drops?
I donโt think it is defined anywhere, but my mental model is that the execution of Vec::drop function would be interrupted, so any elements that have not already been dropped will not be dropped.
I think if you write a Vec in Rust without doing something strange ( such as catching the panic ), this is what would happen.
However it seems that std::Vec DOES โcatch the panicโ (somehow - I donโt know how) and does drop more elements.
Playground example
Perhaps this is all a little academic, as also in my mental model is drop functions should/must not panic, as it sabotages panic recovery, but I just want to understand the situation.
18 posts - 5 participants
๐ท๏ธ Rust_feed