Tracking Issue for const unreachable_unchecked · Issue #53188 · rust-lang/rust (original) (raw)

Currently one cannot call unreachable_unchecked in constant functions, so one cannot add hints of the form:

const fn foo(x: i32) -> i32 { if x < 0 { unreachable_unchecked() } else { x * 2 } }

These types of hints can heavily influence code generation, which can substantially change the performance of const fn when they are invoked at run-time.

It would be a shame to have to write and call foo_compile_time and foo_run_time because the code generated for foo_compile_time is sub-par.

This issue has been assigned to @canova via this comment.