Help optimize out backtraces when disabled by kornelski · Pull Request #92992 · rust-lang/rust (original) (raw)

The comment in rust_backtrace_env says:

// If the backtrace feature of this crate isn't enabled quickly return
// None so this can be constant propagated all over the place to turn
// optimize away callers.

but this optimization has regressed, because the only caller of this function had an alternative path that unconditionally (and pointlessly) asked for a full backtrace, so the disabled state couldn't propagate.

I've added a getter for the full format that respects the feature flag, so that the caller will now be able to really optimize out the disabled backtrace path. I've also made rust_backtrace_env trivially inlineable when backtraces are disabled.