Skip to content

Commit 877e9f5

Browse files
committed
Change 'from_bytes_until_nul' to const stable
1 parent 83b05ef commit 877e9f5

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

library/core/src/ffi/c_str.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,9 @@ impl CStr {
320320
/// assert_eq!(c_str.to_str().unwrap(), "AAAAAAAA");
321321
/// ```
322322
///
323+
#[rustc_allow_const_fn_unstable(const_slice_index)]
323324
#[stable(feature = "cstr_from_bytes_until_nul", since = "CURRENT_RUSTC_VERSION")]
324-
#[rustc_const_unstable(feature = "const_cstr_from_bytes_until_nul", issue = "95027")]
325+
#[rustc_const_stable(feature = "cstr_from_bytes_until_nul", since = "CURRENT_RUSTC_VERSION")]
325326
pub const fn from_bytes_until_nul(bytes: &[u8]) -> Result<&CStr, FromBytesUntilNulError> {
326327
let nul_pos = memchr::memchr(0, bytes);
327328
match nul_pos {

library/core/src/slice/memchr.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,29 @@ const USIZE_BYTES: usize = mem::size_of::<usize>();
1616
/// bytes where the borrow propagated all the way to the most significant
1717
/// bit."
1818
#[inline]
19+
#[rustc_const_stable(feature = "const_memchr", since = "1.65.0")]
1920
const fn contains_zero_byte(x: usize) -> bool {
2021
x.wrapping_sub(LO_USIZE) & !x & HI_USIZE != 0
2122
}
2223

23-
#[cfg(target_pointer_width = "16")]
2424
#[inline]
25+
#[cfg(target_pointer_width = "16")]
26+
#[rustc_const_stable(feature = "const_memchr", since = "1.65.0")]
2527
const fn repeat_byte(b: u8) -> usize {
2628
(b as usize) << 8 | b as usize
2729
}
2830

29-
#[cfg(not(target_pointer_width = "16"))]
3031
#[inline]
32+
#[cfg(not(target_pointer_width = "16"))]
33+
#[rustc_const_stable(feature = "const_memchr", since = "1.65.0")]
3134
const fn repeat_byte(b: u8) -> usize {
3235
(b as usize) * (usize::MAX / 255)
3336
}
3437

3538
/// Returns the first index matching the byte `x` in `text`.
36-
#[must_use]
3739
#[inline]
40+
#[must_use]
41+
#[rustc_const_stable(feature = "const_memchr", since = "1.65.0")]
3842
pub const fn memchr(x: u8, text: &[u8]) -> Option<usize> {
3943
// Fast path for small slices.
4044
if text.len() < 2 * USIZE_BYTES {
@@ -45,6 +49,7 @@ pub const fn memchr(x: u8, text: &[u8]) -> Option<usize> {
4549
}
4650

4751
#[inline]
52+
#[rustc_const_stable(feature = "const_memchr", since = "1.65.0")]
4853
const fn memchr_naive(x: u8, text: &[u8]) -> Option<usize> {
4954
let mut i = 0;
5055

@@ -60,6 +65,10 @@ const fn memchr_naive(x: u8, text: &[u8]) -> Option<usize> {
6065
None
6166
}
6267

68+
#[rustc_allow_const_fn_unstable(const_cmp)]
69+
#[rustc_allow_const_fn_unstable(const_slice_index)]
70+
#[rustc_allow_const_fn_unstable(const_align_offset)]
71+
#[rustc_const_stable(feature = "const_memchr", since = "1.65.0")]
6372
const fn memchr_aligned(x: u8, text: &[u8]) -> Option<usize> {
6473
// Scan for a single byte value by reading two `usize` words at a time.
6574
//

0 commit comments

Comments
 (0)