You can use this unstable code in your binary or library to cause an error when -C panic=abort
is specified:
#![feature(panic_unwind)]
extern crate panic_unwind;
Which causes this helpful error when the wrong panic strategy is used:
error: the linked panic runtime `panic_unwind` is not compiled with this crate's panic strategy `abort`
When the panic strategy is correct, the extern crate
declaration is redundant, but does nothing. When the panic strategy is wrong, it causes a linking error since you can't have two different panic strategy crates in the same binary. Since this check happens when crates are linked, note that if a library is never actually used by the top-level crate, then the check isn't run. (but this is a good thing: if your library is unused, then there is no need for this check anyways!)
Also, this error happens very late in the compilation process, so while cargo build
will error out, cargo check
won't complain since cargo check
doesn't check for linking errors for performance reasons.
Unfortunately, there doesn't seem to be a way to do this on the stable channel.