You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Tracking Issue for const unreachable_unchecked #53188
Currently one cannot call unreachable_unchecked in constant functions, so one cannot add hints of the form:
constfnfoo(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.
One cannot do any sort of conditional control flow, so unreachable_unchecked would currently be less than useless. Any test you can write would be undefined behaviour
@oli-obk the RFC for if/match in const was merged and is pending an implementation right? When that's implemented, will unreachable_unchecked still be useless?
After a short discussion on Zulip, it was decided that it's best to wait for const_panic to stabilize to avoid a potential footgun wherein users use this instead of panic!(), leading to UB at runtime.
I'm subscribed to the const_panic issue and intend to file a PR to stabilize this once the aforementioned happens.
Activity
oli-obk commentedon Aug 8, 2018
One cannot do any sort of conditional control flow, so
unreachable_uncheckedwould currently be less than useless. Any test you can write would be undefined behaviourgnzlbg commentedon Aug 8, 2018
@oli-obk the RFC for
if/matchin const was merged and is pending an implementation right? When that's implemented, willunreachable_uncheckedstill be useless?oli-obk commentedon Aug 8, 2018
No it makes sense after we have conditional control flow.
q2p commentedon Mar 21, 2020
As I understand
if/matchin const functions is now implemented.Can
unreachable_uncheckedbe made into aconst fnnow?oli-obk commentedon Mar 22, 2020
yes. Basically you just need to add the
rustc_const_unstableattribute to the intrinsic and wrapper function. This is documented at https://rustc-dev-guide.rust-lang.org/stability.html?highlight=rustc_const_un#rustc_const_unstable Let me know if anything is unclear (in which case we should update the guide)canova commentedon Jul 17, 2020
Hi, It looks like previous PR is not being worked on currently. I'm working on this and will create a PR soon.
@rustbot claim
Rollup merge of rust-lang#74459 - canova:const-unreachable-unchecked,…
josephlr commentedon Sep 12, 2020
As mentioned in #76209, this issue should be reopened (to track stablization)
tesuji commentedon Sep 20, 2020
cc @RalfJung ^
jhpratt commentedon May 10, 2021
After a short discussion on Zulip, it was decided that it's best to wait for
const_panicto stabilize to avoid a potential footgun wherein users use this instead ofpanic!(), leading to UB at runtime.I'm subscribed to the
const_panicissue and intend to file a PR to stabilize this once the aforementioned happens.[-]Consider making unreachable_unchecked const[/-][+]Tracking Issue for const `unreachable_unchecked`[/+]Rollup merge of rust-lang#89509 - jhpratt:stabilize-const_unreachable…
Rollup merge of rust-lang#89509 - jhpratt:stabilize-const_unreachable…
Rollup merge of rust-lang#89509 - jhpratt:stabilize-const_unreachable…
Rollup merge of rust-lang#89509 - jhpratt:stabilize-const_unreachable…
Rollup merge of rust-lang#89509 - jhpratt:stabilize-const_unreachable…