@@ -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" ) ]
1920const 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" ) ]
2527const 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" ) ]
3134const 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" ) ]
3842pub 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" ) ]
4853const 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" ) ]
6372const 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