Rollup merge of #89509 - jhpratt:stabilize-const_unreachable_unchecked, r=oli-obk
Stabilize `unreachable_unchecked` as `const fn` Closes #53188 This PR stabilizes `core::hint::unreachable_unchecked` as `const fn`. MIRI is able to detect when this method is called. Stabilization was delayed until `const_panic` was stabilized so as to avoid users calling this method in its place (thus resulting in runtime UB). With #89508, that is no longer an issue. ````@rustbot```` label +A-const-eval +A-const-fn +T-lang +S-blocked (not sure why it's T-lang, but that's what the tracking issue is)
This commit is contained in:
commit
9ae0804859
6 changed files with 7 additions and 11 deletions
|
@ -44,7 +44,7 @@ use crate::intrinsics;
|
||||||
/// ```
|
/// ```
|
||||||
#[inline]
|
#[inline]
|
||||||
#[stable(feature = "unreachable", since = "1.27.0")]
|
#[stable(feature = "unreachable", since = "1.27.0")]
|
||||||
#[rustc_const_unstable(feature = "const_unreachable_unchecked", issue = "53188")]
|
#[rustc_const_stable(feature = "const_unreachable_unchecked", since = "1.57.0")]
|
||||||
pub const unsafe fn unreachable_unchecked() -> ! {
|
pub const unsafe fn unreachable_unchecked() -> ! {
|
||||||
// SAFETY: the safety contract for `intrinsics::unreachable` must
|
// SAFETY: the safety contract for `intrinsics::unreachable` must
|
||||||
// be upheld by the caller.
|
// be upheld by the caller.
|
||||||
|
|
|
@ -735,7 +735,7 @@ extern "rust-intrinsic" {
|
||||||
/// reach code marked with this function.
|
/// reach code marked with this function.
|
||||||
///
|
///
|
||||||
/// The stabilized version of this intrinsic is [`core::hint::unreachable_unchecked`].
|
/// The stabilized version of this intrinsic is [`core::hint::unreachable_unchecked`].
|
||||||
#[rustc_const_unstable(feature = "const_unreachable_unchecked", issue = "53188")]
|
#[rustc_const_stable(feature = "const_unreachable_unchecked", since = "1.57.0")]
|
||||||
pub fn unreachable() -> !;
|
pub fn unreachable() -> !;
|
||||||
|
|
||||||
/// Informs the optimizer that a condition is always true.
|
/// Informs the optimizer that a condition is always true.
|
||||||
|
|
|
@ -130,7 +130,6 @@
|
||||||
#![feature(const_trait_impl)]
|
#![feature(const_trait_impl)]
|
||||||
#![feature(const_type_id)]
|
#![feature(const_type_id)]
|
||||||
#![feature(const_type_name)]
|
#![feature(const_type_name)]
|
||||||
#![feature(const_unreachable_unchecked)]
|
|
||||||
#![feature(const_default_impls)]
|
#![feature(const_default_impls)]
|
||||||
#![feature(duration_consts_2)]
|
#![feature(duration_consts_2)]
|
||||||
#![feature(ptr_metadata)]
|
#![feature(ptr_metadata)]
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
// run-pass
|
// run-pass
|
||||||
|
|
||||||
#![feature(const_unreachable_unchecked)]
|
|
||||||
|
|
||||||
const unsafe fn foo(x: bool) -> bool {
|
const unsafe fn foo(x: bool) -> bool {
|
||||||
match x {
|
match x {
|
||||||
true => true,
|
true => true,
|
||||||
|
@ -12,5 +10,5 @@ const unsafe fn foo(x: bool) -> bool {
|
||||||
const BAR: bool = unsafe { foo(true) };
|
const BAR: bool = unsafe { foo(true) };
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
assert_eq!(BAR, true);
|
assert_eq!(BAR, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
// error-pattern: evaluation of constant value failed
|
// error-pattern: evaluation of constant value failed
|
||||||
#![feature(const_unreachable_unchecked)]
|
|
||||||
|
|
||||||
const unsafe fn foo(x: bool) -> bool {
|
const unsafe fn foo(x: bool) -> bool {
|
||||||
match x {
|
match x {
|
||||||
|
@ -11,5 +10,5 @@ const unsafe fn foo(x: bool) -> bool {
|
||||||
const BAR: bool = unsafe { foo(false) };
|
const BAR: bool = unsafe { foo(false) };
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
assert_eq!(BAR, true);
|
assert_eq!(BAR, true);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,13 @@ LL | unsafe { intrinsics::unreachable() }
|
||||||
| entering unreachable code
|
| entering unreachable code
|
||||||
| inside `unreachable_unchecked` at $SRC_DIR/core/src/hint.rs:LL:COL
|
| inside `unreachable_unchecked` at $SRC_DIR/core/src/hint.rs:LL:COL
|
||||||
|
|
|
|
||||||
::: $DIR/const_unsafe_unreachable_ub.rs:7:18
|
::: $DIR/const_unsafe_unreachable_ub.rs:6:18
|
||||||
|
|
|
|
||||||
LL | false => std::hint::unreachable_unchecked(),
|
LL | false => std::hint::unreachable_unchecked(),
|
||||||
| ---------------------------------- inside `foo` at $DIR/const_unsafe_unreachable_ub.rs:7:18
|
| ---------------------------------- inside `foo` at $DIR/const_unsafe_unreachable_ub.rs:6:18
|
||||||
...
|
...
|
||||||
LL | const BAR: bool = unsafe { foo(false) };
|
LL | const BAR: bool = unsafe { foo(false) };
|
||||||
| ---------- inside `BAR` at $DIR/const_unsafe_unreachable_ub.rs:11:28
|
| ---------- inside `BAR` at $DIR/const_unsafe_unreachable_ub.rs:10:28
|
||||||
|
|
||||||
error: aborting due to previous error
|
error: aborting due to previous error
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue