11//! impl char {} 
22
33use  super :: * ; 
4- use  crate :: intrinsics :: const_eval_select ; 
4+ use  crate :: macros :: const_panic ; 
55use  crate :: slice; 
66use  crate :: str:: from_utf8_unchecked_mut; 
77use  crate :: unicode:: printable:: is_printable; 
@@ -1774,17 +1774,7 @@ const fn len_utf16(code: u32) -> usize {
17741774#[ cfg_attr( bootstrap,  rustc_const_stable( feature = "const_char_encode_utf8" ,  since = "1.83.0" ) ) ]  
17751775#[ doc( hidden) ]  
17761776#[ inline]  
1777- #[ rustc_allow_const_fn_unstable( const_eval_select) ]  
17781777pub  const  fn  encode_utf8_raw ( code :  u32 ,  dst :  & mut  [ u8 ] )  -> & mut  [ u8 ]  { 
1779-     const  fn  panic_at_const ( _code :  u32 ,  _len :  usize ,  _dst_len :  usize )  { 
1780-         // Note that we cannot format in constant expressions. 
1781-         panic ! ( "encode_utf8: buffer does not have enough bytes to encode code point" ) ; 
1782-     } 
1783-     fn  panic_at_rt ( code :  u32 ,  len :  usize ,  dst_len :  usize )  { 
1784-         panic ! ( 
1785-             "encode_utf8: need {len} bytes to encode U+{code:04X} but buffer has just {dst_len}" , 
1786-         ) ; 
1787-     } 
17881778    let  len = len_utf8 ( code) ; 
17891779    match  ( len,  & mut  * dst)  { 
17901780        ( 1 ,  [ a,  ..] )  => { 
@@ -1805,8 +1795,15 @@ pub const fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> &mut [u8] {
18051795            * c = ( code >> 6  &  0x3F )  as  u8  | TAG_CONT ; 
18061796            * d = ( code &  0x3F )  as  u8  | TAG_CONT ; 
18071797        } 
1808-         // FIXME(const-hack): We would prefer to have streamlined panics when formatters become const-friendly. 
1809-         _ => const_eval_select ( ( code,  len,  dst. len ( ) ) ,  panic_at_const,  panic_at_rt) , 
1798+         _ => { 
1799+             const_panic ! ( 
1800+                 "encode_utf8: buffer does not have enough bytes to encode code point" , 
1801+                 "encode_utf8: need {len} bytes to encode U+{code:04X} but buffer has just {dst_len}" , 
1802+                 code:  u32  = code, 
1803+                 len:  usize  = len, 
1804+                 dst_len:  usize  = dst. len( ) , 
1805+             ) 
1806+         } 
18101807    } ; 
18111808    // SAFETY: `<&mut [u8]>::as_mut_ptr` is guaranteed to return a valid pointer and `len` has been tested to be within bounds. 
18121809    unsafe  {  slice:: from_raw_parts_mut ( dst. as_mut_ptr ( ) ,  len)  } 
@@ -1827,15 +1824,6 @@ pub const fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> &mut [u8] {
18271824#[ doc( hidden) ]  
18281825#[ inline]  
18291826pub  const  fn  encode_utf16_raw ( mut  code :  u32 ,  dst :  & mut  [ u16 ] )  -> & mut  [ u16 ]  { 
1830-     const  fn  panic_at_const ( _code :  u32 ,  _len :  usize ,  _dst_len :  usize )  { 
1831-         // Note that we cannot format in constant expressions. 
1832-         panic ! ( "encode_utf16: buffer does not have enough bytes to encode code point" ) ; 
1833-     } 
1834-     fn  panic_at_rt ( code :  u32 ,  len :  usize ,  dst_len :  usize )  { 
1835-         panic ! ( 
1836-             "encode_utf16: need {len} bytes to encode U+{code:04X} but buffer has just {dst_len}" , 
1837-         ) ; 
1838-     } 
18391827    let  len = len_utf16 ( code) ; 
18401828    match  ( len,  & mut  * dst)  { 
18411829        ( 1 ,  [ a,  ..] )  => { 
@@ -1846,8 +1834,15 @@ pub const fn encode_utf16_raw(mut code: u32, dst: &mut [u16]) -> &mut [u16] {
18461834            * a = ( code >> 10 )  as  u16  | 0xD800 ; 
18471835            * b = ( code &  0x3FF )  as  u16  | 0xDC00 ; 
18481836        } 
1849-         // FIXME(const-hack): We would prefer to have streamlined panics when formatters become const-friendly. 
1850-         _ => const_eval_select ( ( code,  len,  dst. len ( ) ) ,  panic_at_const,  panic_at_rt) , 
1837+         _ => { 
1838+             const_panic ! ( 
1839+                 "encode_utf16: buffer does not have enough bytes to encode code point" , 
1840+                 "encode_utf16: need {len} bytes to encode U+{code:04X} but buffer has just {dst_len}" , 
1841+                 code:  u32  = code, 
1842+                 len:  usize  = len, 
1843+                 dst_len:  usize  = dst. len( ) , 
1844+             ) 
1845+         } 
18511846    } ; 
18521847    // SAFETY: `<&mut [u16]>::as_mut_ptr` is guaranteed to return a valid pointer and `len` has been tested to be within bounds. 
18531848    unsafe  {  slice:: from_raw_parts_mut ( dst. as_mut_ptr ( ) ,  len)  } 
0 commit comments