@@ -384,8 +384,9 @@ impl char {
384
384
/// assert_eq!('❤'.escape_unicode().to_string(), "\\u{2764}");
385
385
/// ```
386
386
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
387
+ #[ rustc_const_stable( feature = "const_char_escape_unicode" , since = "1.50.0" ) ]
387
388
#[ inline]
388
- pub fn escape_unicode ( self ) -> EscapeUnicode {
389
+ pub const fn escape_unicode ( self ) -> EscapeUnicode {
389
390
let c = self as u32 ;
390
391
391
392
// or-ing 1 ensures that for c==0 the code computes that one
@@ -510,8 +511,9 @@ impl char {
510
511
/// assert_eq!('"'.escape_default().to_string(), "\\\"");
511
512
/// ```
512
513
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
514
+ #[ rustc_const_stable( feature = "const_char_escape_default" , since = "1.50.0" ) ]
513
515
#[ inline]
514
- pub fn escape_default ( self ) -> EscapeDefault {
516
+ pub const fn escape_default ( self ) -> EscapeDefault {
515
517
let init_state = match self {
516
518
'\t' => EscapeDefaultState :: Backslash ( 't' ) ,
517
519
'\r' => EscapeDefaultState :: Backslash ( 'r' ) ,
@@ -569,8 +571,9 @@ impl char {
569
571
/// assert_eq!(len, tokyo.len());
570
572
/// ```
571
573
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
574
+ #[ rustc_const_stable( feature = "const_char_len_utf" , since = "1.50.0" ) ]
572
575
#[ inline]
573
- pub fn len_utf8 ( self ) -> usize {
576
+ pub const fn len_utf8 ( self ) -> usize {
574
577
len_utf8 ( self as u32 )
575
578
}
576
579
@@ -594,8 +597,9 @@ impl char {
594
597
/// assert_eq!(len, 2);
595
598
/// ```
596
599
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
600
+ #[ rustc_const_stable( feature = "const_char_len_utf" , since = "1.50.0" ) ]
597
601
#[ inline]
598
- pub fn len_utf16 ( self ) -> usize {
602
+ pub const fn len_utf16 ( self ) -> usize {
599
603
let ch = self as u32 ;
600
604
if ( ch & 0xFFFF ) == ch { 1 } else { 2 }
601
605
}
@@ -1086,8 +1090,9 @@ impl char {
1086
1090
/// [`make_ascii_uppercase()`]: #method.make_ascii_uppercase
1087
1091
/// [`to_uppercase()`]: #method.to_uppercase
1088
1092
#[ stable( feature = "ascii_methods_on_intrinsics" , since = "1.23.0" ) ]
1093
+ #[ rustc_const_stable( feature = "const_ascii_methods_on_intrinsics" , since = "1.50.0" ) ]
1089
1094
#[ inline]
1090
- pub fn to_ascii_uppercase ( & self ) -> char {
1095
+ pub const fn to_ascii_uppercase ( & self ) -> char {
1091
1096
if self . is_ascii_lowercase ( ) {
1092
1097
( * self as u8 ) . ascii_change_case_unchecked ( ) as char
1093
1098
} else {
@@ -1118,8 +1123,9 @@ impl char {
1118
1123
/// [`make_ascii_lowercase()`]: #method.make_ascii_lowercase
1119
1124
/// [`to_lowercase()`]: #method.to_lowercase
1120
1125
#[ stable( feature = "ascii_methods_on_intrinsics" , since = "1.23.0" ) ]
1126
+ #[ rustc_const_stable( feature = "const_ascii_methods_on_intrinsics" , since = "1.50.0" ) ]
1121
1127
#[ inline]
1122
- pub fn to_ascii_lowercase ( & self ) -> char {
1128
+ pub const fn to_ascii_lowercase ( & self ) -> char {
1123
1129
if self . is_ascii_uppercase ( ) {
1124
1130
( * self as u8 ) . ascii_change_case_unchecked ( ) as char
1125
1131
} else {
@@ -1143,8 +1149,9 @@ impl char {
1143
1149
/// assert!(!upper_a.eq_ignore_ascii_case(&lower_z));
1144
1150
/// ```
1145
1151
#[ stable( feature = "ascii_methods_on_intrinsics" , since = "1.23.0" ) ]
1152
+ #[ rustc_const_stable( feature = "const_ascii_methods_on_intrinsics" , since = "1.50.0" ) ]
1146
1153
#[ inline]
1147
- pub fn eq_ignore_ascii_case ( & self , other : & char ) -> bool {
1154
+ pub const fn eq_ignore_ascii_case ( & self , other : & char ) -> bool {
1148
1155
self . to_ascii_lowercase ( ) == other. to_ascii_lowercase ( )
1149
1156
}
1150
1157
@@ -1561,7 +1568,7 @@ impl char {
1561
1568
}
1562
1569
1563
1570
#[ inline]
1564
- fn len_utf8 ( code : u32 ) -> usize {
1571
+ const fn len_utf8 ( code : u32 ) -> usize {
1565
1572
if code < MAX_ONE_B {
1566
1573
1
1567
1574
} else if code < MAX_TWO_B {
0 commit comments