Change:
Currently one cannot call in constant functions, so one cannot add hints of the form: These types of hints can heavily influence code generation, which can substantially change the performance of when they are invoked at run-time. It would be a shame to have to write and call and because the code generated for is sub-par. <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --This issue has been assigned to via . <!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOT_END --
One cannot do any sort of conditional control flow, so would currently be less than useless. Any test you can write would be undefined behaviour
the RFC for / in const was merged and is pending an implementation right? When that's implemented, will still be useless?
No it makes sense after we have conditional control flow.
As I understand / in const functions is now implemented. Can be made into a now?
yes. Basically you just need to add the attribute to the intrinsic and wrapper function. This is documented at https://rustc-dev- Let me know if anything is unclear (in which case we should update the guide)
Hi, It looks like previous PR is not being worked on currently. I'm working on this and will create a PR soon. claim
As mentioned in , this issue should be reopened (to track stablization)
cc ^
After a short discussion on Zulip, it was decided that it's best to wait for to stabilize to avoid a potential footgun wherein users use this instead of , leading to UB at runtime. I'm subscribed to the issue and intend to file a PR to stabilize this once the aforementioned happens.

Discussion:
/// ``` #[inline] #[stable(feature = "unreachable", since = "1.27.0")] <del> pub unsafe fn unreachable_unchecked() -> ! { </del> <ins> #[rustc_const_unstable(feature = "const_unreachable_unchecked", issue = "53188")] pub const unsafe fn unreachable_unchecked() -> ! { </ins> // SAFETY: the safety contract for `intrinsics::unreachable` must // be upheld by the caller. unsafe { intrinsics::unreachable() }

/// /// The stabilized version of this intrinsic is /// [`std::hint::unreachable_unchecked`](../../std/hint/fn.unreachable_unchecked.html). <ins> #[rustc_const_unstable(feature = "const_unreachable_unchecked", issue = "53188")] </ins> pub fn unreachable() -> !; /// Informs the optimizer that a condition is always true.

#![feature(const_slice_ptr_len)] #![feature(const_type_name)] #![feature(const_likely)] <ins> #![feature(const_unreachable_unchecked)] </ins> #![feature(custom_inner_attributes)] #![feature(decl_macro)] #![feature(doc_cfg)]

let (dest, ret) = match ret { None => match intrinsic_name { sym::transmute => throw_ub_format!("transmuting to uninhabited type"), <ins> sym::unreachable => throw_ub!(Unreachable), </ins> sym::abort => M::abort(self)?, // Unsupported diverging intrinsic. _ => return Ok(false),

<ins> // run-pass #![feature(const_fn)] #![feature(const_unreachable_unchecked)] const unsafe fn foo(x: bool) -> bool { match x { true => true, false => std::hint::unreachable_unchecked(), } } const BAR: bool = unsafe { foo(true) }; fn main() { assert_eq!(BAR, true); } </ins>

<ins> // build-fail #![feature(const_fn)] #![feature(const_unreachable_unchecked)] const unsafe fn foo(x: bool) -> bool { match x { true => true, false => std::hint::unreachable_unchecked(), } } #[warn(const_err)] const BAR: bool = unsafe { foo(false) }; fn main() { assert_eq!(BAR, true); //~^ ERROR E0080 //~| ERROR erroneous constant } </ins>

<ins> warning: any use of this value will cause an error --> $SRC_DIR/libcore/hint.rs:LL:COL | LL |     unsafe { intrinsics::unreachable() } |              ^^^^^^^^^^^^^^^^^^^^^^^^^ |              | |              entering unreachable code |              inside `std::hint::unreachable_unchecked` at $SRC_DIR/libcore/hint.rs:LL:COL |              inside `foo` at $DIR/const_unsafe_unreachable_ub.rs:9:18 |              inside `BAR` at $DIR/const_unsafe_unreachable_ub.rs:14:28 | ::: $DIR/const_unsafe_unreachable_ub.rs:14:1 | LL | const BAR: bool = unsafe { foo(false) }; | ---------------------------------------- | note: the lint level is defined here --> $DIR/const_unsafe_unreachable_ub.rs:13:8 | LL | #[warn(const_err)] |        ^^^^^^^^^ error[E0080]: evaluation of constant expression failed --> $DIR/const_unsafe_unreachable_ub.rs:17:3 | LL |   assert_eq!(BAR, true); |   ^^^^^^^^^^^---^^^^^^^^ |              | |              referenced constant has errors | = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: erroneous constant used --> $DIR/const_unsafe_unreachable_ub.rs:17:3 | LL |   assert_eq!(BAR, true); |   ^^^^^^^^^^^^^^^^^^^^^^ referenced constant has errors | = note: `#[deny(const_err)]` on by default = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info) error: aborting due to 2 previous errors; 1 warning emitted For more information about this error, try `rustc --explain E0080`. </ins>