3 ms·
Panics have nothing to do with Rust's safety guarantees or unsafe. A panic is a way of signalling "uh oh the program made an assumption that doesn't hold, ther
by Manishearth 10y ago
Panics have nothing to do with Rust's safety guarantees or unsafe.
A panic is a way of signalling "uh oh the program made an assumption that doesn't hold, there's something horribly wrong, please exit". A fatal exception.
Most languages, including Rust, will not let you encode all invariants of a program into the type system. Only languages that come bundled with proof checkers can do that, and that's tedious. So you will have situations where you have to assume an invariant to be true, and if it isn't, there's something horribly wrong and the program should exit. That's a panic.
Rust makes sure that wrong assumptions about invariants can't lead to memory unsafety. It can't magically make bugs go away.