@@ -136,9 +136,10 @@ impl char {
136
136
/// assert_eq!(None, c);
137
137
/// ```
138
138
#[ stable( feature = "assoc_char_funcs" , since = "1.52.0" ) ]
139
+ #[ rustc_const_unstable( feature = "const_char_convert" , issue = "89259" ) ]
139
140
#[ must_use]
140
141
#[ inline]
141
- pub fn from_u32 ( i : u32 ) -> Option < char > {
142
+ pub const fn from_u32 ( i : u32 ) -> Option < char > {
142
143
super :: convert:: from_u32 ( i)
143
144
}
144
145
@@ -178,9 +179,10 @@ impl char {
178
179
/// assert_eq!('❤', c);
179
180
/// ```
180
181
#[ stable( feature = "assoc_char_funcs" , since = "1.52.0" ) ]
182
+ #[ rustc_const_unstable( feature = "const_char_convert" , issue = "89259" ) ]
181
183
#[ must_use]
182
184
#[ inline]
183
- pub unsafe fn from_u32_unchecked ( i : u32 ) -> char {
185
+ pub const unsafe fn from_u32_unchecked ( i : u32 ) -> char {
184
186
// SAFETY: the safety contract must be upheld by the caller.
185
187
unsafe { super :: convert:: from_u32_unchecked ( i) }
186
188
}
@@ -235,9 +237,10 @@ impl char {
235
237
/// let _c = char::from_digit(1, 37);
236
238
/// ```
237
239
#[ stable( feature = "assoc_char_funcs" , since = "1.52.0" ) ]
240
+ #[ rustc_const_unstable( feature = "const_char_convert" , issue = "89259" ) ]
238
241
#[ must_use]
239
242
#[ inline]
240
- pub fn from_digit ( num : u32 , radix : u32 ) -> Option < char > {
243
+ pub const fn from_digit ( num : u32 , radix : u32 ) -> Option < char > {
241
244
super :: convert:: from_digit ( num, radix)
242
245
}
243
246
@@ -331,10 +334,11 @@ impl char {
331
334
/// let _ = '1'.to_digit(37);
332
335
/// ```
333
336
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
337
+ #[ rustc_const_unstable( feature = "const_char_convert" , issue = "89259" ) ]
334
338
#[ must_use = "this returns the result of the operation, \
335
339
without modifying the original"]
336
340
#[ inline]
337
- pub fn to_digit ( self , radix : u32 ) -> Option < u32 > {
341
+ pub const fn to_digit ( self , radix : u32 ) -> Option < u32 > {
338
342
assert ! ( radix <= 36 , "to_digit: radix is too high (maximum 36)" ) ;
339
343
// If not a digit, a number greater than radix will be created.
340
344
let mut digit = ( self as u32 ) . wrapping_sub ( '0' as u32 ) ;
@@ -345,7 +349,8 @@ impl char {
345
349
// Force the 6th bit to be set to ensure ascii is lower case.
346
350
digit = ( self as u32 | 0b10_0000 ) . wrapping_sub ( 'a' as u32 ) . saturating_add ( 10 ) ;
347
351
}
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 }
349
354
}
350
355
351
356
/// Returns an iterator that yields the hexadecimal Unicode escape of a
0 commit comments