We can use std::hint::unreachable_unchecked to give the compiler hints about what is/isn’t true. Should we add a wrapper macro (e.g. std::hint::performance_assert!) for assertions that check their arguments in debug mode, but in release mode will cause the compiler to assume they’re true?
Of course this macro would only be usable in unsafe mode.
This macro is simple to implement and can already be implemented in stable Rust in user code (as shown in the OP). Given this, and the relative footgun nature of using this macro, I think it’s best to not put this in std and instead require users to implement it themselves if they really want it.
I disagree. The status-quo is std::hint::unreachable_unchecked. If someone is looking to perform an optimization like this, that is what they will reach for. That macro is more dangerous than this one, since even in debug mode it will cause UB rather than panic.
Where if that function actually gets called, it’ll trigger an invalid opcode exception, stopping the program (in a way that your debugger will hopefully get the callstack).
I don’t think that we should add macro just because Rust currently does not support automatic std recompiling with enabled debug assertions. And it’s only one case where debug asserts in std will be useful, as the previously linked issue demonstrates. Should we add macros for every other case as well? Highly doubt it.