Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize unreachable_unchecked as const fn #89509

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion library/core/src/hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ use crate::intrinsics;
/// ```
#[inline]
#[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() -> ! {
// SAFETY: the safety contract for `intrinsics::unreachable` must
// be upheld by the caller.
Expand Down
2 changes: 1 addition & 1 deletion library/core/src/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,7 @@ extern "rust-intrinsic" {
/// reach code marked with this function.
///
/// 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() -> !;

/// Informs the optimizer that a condition is always true.
Expand Down
1 change: 0 additions & 1 deletion library/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@
#![feature(const_trait_impl)]
#![feature(const_type_id)]
#![feature(const_type_name)]
#![feature(const_unreachable_unchecked)]
#![feature(const_default_impls)]
#![feature(duration_consts_2)]
#![feature(ptr_metadata)]
Expand Down
4 changes: 1 addition & 3 deletions src/test/ui/consts/const_unsafe_unreachable.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// run-pass

#![feature(const_unreachable_unchecked)]

const unsafe fn foo(x: bool) -> bool {
match x {
true => true,
Expand All @@ -12,5 +10,5 @@ const unsafe fn foo(x: bool) -> bool {
const BAR: bool = unsafe { foo(true) };

fn main() {
assert_eq!(BAR, true);
assert_eq!(BAR, true);
}
3 changes: 1 addition & 2 deletions src/test/ui/consts/const_unsafe_unreachable_ub.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// error-pattern: evaluation of constant value failed
#![feature(const_unreachable_unchecked)]

const unsafe fn foo(x: bool) -> bool {
match x {
Expand All @@ -11,5 +10,5 @@ const unsafe fn foo(x: bool) -> bool {
const BAR: bool = unsafe { foo(false) };

fn main() {
assert_eq!(BAR, true);
assert_eq!(BAR, true);
}
6 changes: 3 additions & 3 deletions src/test/ui/consts/const_unsafe_unreachable_ub.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ LL | unsafe { intrinsics::unreachable() }
| entering unreachable code
| 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(),
| ---------------------------------- 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) };
| ---------- 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

Expand Down