4 ms·
Rust does have unreachable!() which panics.
by CUViper 10y ago
Rust does have unreachable!() which panics.
- dikaiosune 10y agoPanics are possible with #![no_std], but it does require that you supply a working implementation of panic_fmt, which I haven't gotten to yet (mostly because I was waiting on panic-as-abort to land which it recently did).
- steveklabnik 10y agoNB: you still need panic_fmt with panic == abort; the default panic handler still prints a message, even though it doesn't go through with the unwinding.
- CUViper 10y agoOK, another option is to make it an explicit infinite "loop{...}" which only exits by returning. The "0.." is effectively infinite anyway, because it will overflow freely in release mode. (But surely you'll hit an invalid memory page before that happens.)
- dikaiosune 10y agoYou're right, I think this version is a bit clearer: https://is.gd/lck8c7 https://is.gd/lck8c7
- loeg 10y agopanic_fmt can be as simple as (C pseudocode): printf("..."); kill(getpid(), SIGABRT); while(true) /* In case kill(ABRT) returns, halt. */;