@@ -375,9 +375,9 @@ impl AsciiChar {
375375 /// and `Some(AsciiChar::from_ascii_unchecked(128))` might be `None`.
376376 #[ inline]
377377 #[ must_use]
378- pub unsafe fn from_ascii_unchecked ( ch : u8 ) -> Self {
378+ pub const unsafe fn from_ascii_unchecked ( ch : u8 ) -> Self {
379379 // SAFETY: Caller guarantees `ch` is within bounds of ascii.
380- unsafe { ch . to_ascii_char_unchecked ( ) }
380+ unsafe { mem :: transmute ( ch ) }
381381 }
382382
383383 /// Converts an ASCII character into a `u8`.
@@ -659,14 +659,15 @@ impl AsciiChar {
659659 /// assert_eq!(AsciiChar::new('p').as_printable_char(), 'p');
660660 /// ```
661661 #[ must_use]
662- pub fn as_printable_char ( self ) -> char {
662+ pub const fn as_printable_char ( self ) -> char {
663+ #![ allow( clippy:: transmute_int_to_char) ] // from_utf32_unchecked() is not const fn yet.
663664 match self as u8 {
664665 // Non printable characters
665666 // SAFETY: From codepoint 0x2400 ('␀') to 0x241f (`␟`), there are characters representing
666667 // the unprintable characters from 0x0 to 0x1f, ordered correctly.
667668 // As `b` is guaranteed to be within 0x0 to 0x1f, the conversion represents a
668669 // valid character.
669- b @ 0x0 ..=0x1f => unsafe { char :: from_u32_unchecked ( u32 :: from ( '␀' ) + u32:: from ( b ) ) } ,
670+ b @ 0x0 ..=0x1f => unsafe { mem :: transmute ( '␀' as u32 + b as u32 ) } ,
670671
671672 // 0x7f (delete) has it's own character at codepoint 0x2420, not 0x247f, so it is special
672673 // cased to return it's character
0 commit comments