External Publication
Visit Post

Err automatic hint::cold_path?

Rust Internals [Unofficial] June 23, 2026
Source

The other thing that people are already doing here is doing this specifically for error types.

If you look in anyhow, for example:

github.com/dtolnay/anyhow

src/error.rs

d9dc3faf7

    673. #[cfg(any(feature = "std", not(anyhow_no_core_error)))]


    674. impl<E> From<E> for Error


    675. where


    676.     E: StdError + Send + Sync + 'static,


    677. {


    678.     #[cold]


    679.     fn from(error: E) -> Self {


    680.         let backtrace = backtrace_if_absent!(&error);


    681.         Error::construct_from_std(error, backtrace)


    682.     }


    683. }

That's marked #[cold] so if you're using anyhow then any time ? wraps an error into an anyhow::Error it's already treated as cold automatically.

Which is nice in that it's specific to that error type, since for anyhow it definitely makes sense -- anything non-cold probably shouldn't be taking backtraces and such anyhow.

Discussion in the ATmosphere

Loading comments...