Skip to content

Commit 7599168

Browse files
committed
Stabilize hint_assert_unchecked
Make both `hint_assert_unchecked` and `const_hint_assert_unchecked` stable as `hint_assert_unchecked`.
1 parent 5ce23c1 commit 7599168

File tree

7 files changed

+9
-17
lines changed

7 files changed

+9
-17
lines changed

library/alloc/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@
126126
#![feature(fn_traits)]
127127
#![feature(generic_nonzero)]
128128
#![feature(hasher_prefixfree_extras)]
129-
#![feature(hint_assert_unchecked)]
130129
#![feature(inline_const)]
131130
#![feature(inplace_iteration)]
132131
#![feature(iter_advance_by)]

library/core/src/hint.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,9 @@ pub const unsafe fn unreachable_unchecked() -> ! {
137137
///
138138
/// In release mode, the argument will most likely not actually be evaluated.
139139
///
140-
/// If ever you are tempted to write `assert_unchecked(false)`, then you are actually looking for
141-
/// [`unreachable_unchecked()`].
140+
/// `assert_unchecked` is logically equivalent to `if !cond { unreachable_unchecked(); }`. If`
141+
/// ever you are tempted to write `assert_unchecked(false)`, you should instead use
142+
/// [`unreachable_unchecked()`] directly.
142143
///
143144
/// # Safety
144145
///
@@ -147,8 +148,6 @@ pub const unsafe fn unreachable_unchecked() -> ! {
147148
/// # Example
148149
///
149150
/// ```
150-
/// #![feature(hint_assert_unchecked)]
151-
///
152151
/// use core::hint;
153152
///
154153
/// /// # Safety
@@ -196,11 +195,11 @@ pub const unsafe fn unreachable_unchecked() -> ! {
196195
/// pointer already has the builtin assumption that it is nonnull. However, the optimizer can
197196
/// make use of this information even when it isn't as obvious, such as when checks happen in
198197
/// called functions.
198+
#[track_caller]
199199
#[inline(always)]
200200
#[doc(alias = "assume")]
201-
#[track_caller]
202-
#[unstable(feature = "hint_assert_unchecked", issue = "119131")]
203-
#[rustc_const_unstable(feature = "const_hint_assert_unchecked", issue = "119131")]
201+
#[stable(feature = "hint_assert_unchecked", since = "CURRENT_RUSTC_VERSION")]
202+
#[rustc_const_stable(feature = "hint_assert_unchecked", since = "CURRENT_RUSTC_VERSION")]
204203
pub const unsafe fn assert_unchecked(cond: bool) {
205204
// SAFETY: The caller promised `cond` is true.
206205
unsafe {

library/core/src/intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -960,7 +960,7 @@ extern "rust-intrinsic" {
960960
/// not be used if the invariant can be discovered by the optimizer on its
961961
/// own, or if it does not enable any significant optimizations.
962962
///
963-
/// This intrinsic does not have a stable counterpart.
963+
/// The stabilized version of this intrinsic is [`core::hint::assert_unchecked`].
964964
#[rustc_const_stable(feature = "const_assume", since = "1.77.0")]
965965
#[rustc_nounwind]
966966
#[unstable(feature = "core_intrinsics", issue = "none")]

library/core/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@
130130
#![feature(const_fmt_arguments_new)]
131131
#![feature(const_hash)]
132132
#![feature(const_heap)]
133-
#![feature(const_hint_assert_unchecked)]
134133
#![feature(const_index_range_slice_index)]
135134
#![feature(const_int_from_str)]
136135
#![feature(const_intrinsic_copy)]

library/std/src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,6 @@
327327
#![feature(generic_nonzero)]
328328
#![feature(hasher_prefixfree_extras)]
329329
#![feature(hashmap_internals)]
330-
#![feature(hint_assert_unchecked)]
331330
#![feature(ip)]
332331
#![feature(maybe_uninit_slice)]
333332
#![feature(maybe_uninit_uninit_array)]
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
#![feature(hint_assert_unchecked)]
2-
#![feature(const_hint_assert_unchecked)]
3-
41
const _: () = unsafe {
52
let n = u32::MAX.count_ones();
63
std::hint::assert_unchecked(n < 32); //~ ERROR evaluation of constant value failed
74
};
85

9-
fn main() {
10-
}
6+
fn main() {}

tests/ui/consts/const-assert-unchecked-ub.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0080]: evaluation of constant value failed
2-
--> $DIR/const-assert-unchecked-ub.rs:6:5
2+
--> $DIR/const-assert-unchecked-ub.rs:3:5
33
|
44
LL | std::hint::assert_unchecked(n < 32);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `assume` called with `false`

0 commit comments

Comments
 (0)