I don’t think that’s a valid comparison. The behavior does differ when it comes to cleanly releasing resources. Rust’s panic performs the drop actions for the current values on the stack, a SIGILL or SIGSEGV crash doesn’t.
#[derive(Debug)]
struct MyStruct {}
impl Drop for MyStruct {
fn drop(&mut self) {
println!("{:?}", "imagine cleanup here"); // this is called
}
}
fn main() {
let a = MyStruct {};
panic!("panic!");
println!("{a:?}");
}
That’s fair, although technically you could catch SIGSEGV and release resources that way too.
Also, given that resources will be reclaimed by the OS regardless of which kind of crash we’re talking about, the effective difference is usually (but not always) negligible.
Either way, no user would consider a panic!() to be not a crash because destructors ran. And most developers don’t either.
I don’t think that’s a valid comparison. The behavior does differ when it comes to cleanly releasing resources. Rust’s panic performs the drop actions for the current values on the stack, a SIGILL or SIGSEGV crash doesn’t.
Try it yourself
That’s fair, although technically you could catch SIGSEGV and release resources that way too.
Also, given that resources will be reclaimed by the OS regardless of which kind of crash we’re talking about, the effective difference is usually (but not always) negligible.
Either way, no user would consider a
panic!()
to be not a crash because destructors ran. And most developers don’t either.