A way to tell in drop() if you are currently panic'ing?

I've impl'd Drop for a cached data type T to give an error if you are dropping T with its dirty bit set.

Unfortunately, if the code panic's, drop(T) will get called and then I have a bunch of spurious "dropping while dirty messages" even though in this exceptional case I don't want to do the check.

Is there anything built-in to panic that I can check to see if the current thread is in a panic state?

I know I can write my own macro to do this, but wanted to check if there's a better way.

Also, panic!() in drop does not respect the RUST_BACKTRACE env variable and prints backtrace puke no matter the value of RUST_BACKTRACE.

2 Likes

Well, what do you know, thanks! Might be worth linking to this on the panic!() docs.