The idea is that for situations where I'd like to panic!(), I can instead use this macro, and I'll avoid taking down my entire app and log instead. But, in debug mode, it'll still force a crash and force me to go debug something. I realize it's not the most common use case, but it works nicely for me.
My problem is that in debug mode, any code after this gets warned as unreachable. This is why I added the if true {} block around the panic. I was wondering how stable that hack is? Is there a better way to silence the unreachable code lint in debug mode?
I don’t think there is a better way. if true {} isn't specifically guaranteed to do this, but it would be quite a significant change to the compiler for it to start examining boolean expressions for control flow analysis (which also affects type and borrow checking, so now values would be influencing types).
so it ensures that both compile regardless of which configuration you're actually running, and even in opt-level=0 codegen the compiler recognizes if const { ... } to avoid emitting the code for the impossible branch.