External Publication
Visit Post

Err automatic hint::cold_path?

Rust Internals [Unofficial] June 19, 2026
Source

It's not obvious to me that this is the right thing for the standard library to do.

Notably, things like u32::from_str it's not obvious that the Err being cold is necessarily the right choice. And adding anything in ? is at risk of a pretty bad compilation-time hit. (IIRC serde isn't using ? because its generality and From made it materially slower to compile, even if it optimized away.)

So overall, I generally think that leaving this kind of thing to PGO is the better choice.

I definitely don't think doing it for Option would be good, because things like try { x?.foo() } being used on stuff that happens to be None is pretty common when it's used as "this property/hook/etc really is optional". Maybe it'd work in the Err arm for Result::branch? But that'd also make try { x? } no longer a no-op, which has its own consequences. You could always try making a PR for it and see what happens, though since the compiler uses PGO I doubt it'll show any improvement in the compiler perf suite.

Discussion in the ATmosphere

Loading comments...