@@ -136,9 +136,10 @@ impl char {
136136 /// assert_eq!(None, c);
137137 /// ```
138138 #[ stable( feature = "assoc_char_funcs" , since = "1.52.0" ) ]
139+ #[ rustc_const_unstable( feature = "const_char_convert" , issue = "89259" ) ]
139140 #[ must_use]
140141 #[ inline]
141- pub fn from_u32 ( i : u32 ) -> Option < char > {
142+ pub const fn from_u32 ( i : u32 ) -> Option < char > {
142143 super :: convert:: from_u32 ( i)
143144 }
144145
@@ -178,9 +179,10 @@ impl char {
178179 /// assert_eq!('❤', c);
179180 /// ```
180181 #[ stable( feature = "assoc_char_funcs" , since = "1.52.0" ) ]
182+ #[ rustc_const_unstable( feature = "const_char_convert" , issue = "89259" ) ]
181183 #[ must_use]
182184 #[ inline]
183- pub unsafe fn from_u32_unchecked ( i : u32 ) -> char {
185+ pub const unsafe fn from_u32_unchecked ( i : u32 ) -> char {
184186 // SAFETY: the safety contract must be upheld by the caller.
185187 unsafe { super :: convert:: from_u32_unchecked ( i) }
186188 }
@@ -235,9 +237,10 @@ impl char {
235237 /// let _c = char::from_digit(1, 37);
236238 /// ```
237239 #[ stable( feature = "assoc_char_funcs" , since = "1.52.0" ) ]
240+ #[ rustc_const_unstable( feature = "const_char_convert" , issue = "89259" ) ]
238241 #[ must_use]
239242 #[ inline]
240- pub fn from_digit ( num : u32 , radix : u32 ) -> Option < char > {
243+ pub const fn from_digit ( num : u32 , radix : u32 ) -> Option < char > {
241244 super :: convert:: from_digit ( num, radix)
242245 }
243246
@@ -331,10 +334,11 @@ impl char {
331334 /// let _ = '1'.to_digit(37);
332335 /// ```
333336 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
337+ #[ rustc_const_unstable( feature = "const_char_convert" , issue = "89259" ) ]
334338 #[ must_use = "this returns the result of the operation, \
335339 without modifying the original"]
336340 #[ inline]
337- pub fn to_digit ( self , radix : u32 ) -> Option < u32 > {
341+ pub const fn to_digit ( self , radix : u32 ) -> Option < u32 > {
338342 assert ! ( radix <= 36 , "to_digit: radix is too high (maximum 36)" ) ;
339343 // If not a digit, a number greater than radix will be created.
340344 let mut digit = ( self as u32 ) . wrapping_sub ( '0' as u32 ) ;
@@ -345,7 +349,8 @@ impl char {
345349 // Force the 6th bit to be set to ensure ascii is lower case.
346350 digit = ( self as u32 | 0b10_0000 ) . wrapping_sub ( 'a' as u32 ) . saturating_add ( 10 ) ;
347351 }
348- ( digit < radix) . then_some ( digit)
352+ // FIXME: once then_some is const fn, use it here
353+ if digit < radix { Some ( digit) } else { None }
349354 }
350355
351356 /// Returns an iterator that yields the hexadecimal Unicode escape of a
0 commit comments