Can I make assert! crash my application?

Right now the behaviour of assert! is to stop/terminate current thread (where it was called).

For example, this code running in a non-main thread:

impl Reader {
   pub fn event_loop(&self) {
      while self.stop_requested.load(std::sync::atomic::Ordering::Relaxed) == false {

produces this output:

thread '<unnamed>' panicked at digester/src/source/
assertion failed: false
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Printing a message every second...
Printing a message every second...

as you can see, another process continues working.

Adding this in Cargo.toml does not work:

panic = "abort"

panic = "abort"


I understand that I can manually inspect what thread.join returns (for example, reader_thread.join().unwrap();), but this is not what I am asking.

panic = abort should work. Make sure the profile is used, e.g. if you’re using workspaces put it in the root Cargo.toml.

Of course there’s also std::process::abort() and exit() if you just need the process to stop in this one case.

1 Like

You are right! I did not put it in the root Cargo.toml.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.