diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index 1b847addcf806..afca28a1f2fa0 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -390,8 +390,9 @@ impl char { /// assert_eq!('❤'.escape_unicode().to_string(), "\\u{2764}"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_char_escape_unicode", since = "1.50.0")] #[inline] - pub fn escape_unicode(self) -> EscapeUnicode { + pub const fn escape_unicode(self) -> EscapeUnicode { let c = self as u32; // or-ing 1 ensures that for c==0 the code computes that one @@ -517,8 +518,9 @@ impl char { /// assert_eq!('"'.escape_default().to_string(), "\\\""); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_char_escape_default", since = "1.50.0")] #[inline] - pub fn escape_default(self) -> EscapeDefault { + pub const fn escape_default(self) -> EscapeDefault { let init_state = match self { '\t' => EscapeDefaultState::Backslash('t'), '\r' => EscapeDefaultState::Backslash('r'), @@ -576,8 +578,9 @@ impl char { /// assert_eq!(len, tokyo.len()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_char_len_utf", since = "1.50.0")] #[inline] - pub fn len_utf8(self) -> usize { + pub const fn len_utf8(self) -> usize { len_utf8(self as u32) } @@ -601,8 +604,9 @@ impl char { /// assert_eq!(len, 2); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_char_len_utf", since = "1.50.0")] #[inline] - pub fn len_utf16(self) -> usize { + pub const fn len_utf16(self) -> usize { let ch = self as u32; if (ch & 0xFFFF) == ch { 1 } else { 2 } } @@ -1093,8 +1097,9 @@ impl char { /// [`make_ascii_uppercase`]: #method.make_ascii_uppercase /// [`to_uppercase`]: #method.to_uppercase #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] + #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.50.0")] #[inline] - pub fn to_ascii_uppercase(&self) -> char { + pub const fn to_ascii_uppercase(&self) -> char { if self.is_ascii() { (*self as u8).to_ascii_uppercase() as char } else { *self } } @@ -1121,8 +1126,9 @@ impl char { /// [`make_ascii_lowercase`]: #method.make_ascii_lowercase /// [`to_lowercase`]: #method.to_lowercase #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] + #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.50.0")] #[inline] - pub fn to_ascii_lowercase(&self) -> char { + pub const fn to_ascii_lowercase(&self) -> char { if self.is_ascii() { (*self as u8).to_ascii_lowercase() as char } else { *self } } @@ -1142,8 +1148,9 @@ impl char { /// assert!(!upper_a.eq_ignore_ascii_case(&lower_z)); /// ``` #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] + #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.50.0")] #[inline] - pub fn eq_ignore_ascii_case(&self, other: &char) -> bool { + pub const fn eq_ignore_ascii_case(&self, other: &char) -> bool { self.to_ascii_lowercase() == other.to_ascii_lowercase() } @@ -1560,7 +1567,7 @@ impl char { } #[inline] -fn len_utf8(code: u32) -> usize { +const fn len_utf8(code: u32) -> usize { if code < MAX_ONE_B { 1 } else if code < MAX_TWO_B { diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index 9f5ae57b74ade..d2e6955e241e1 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -199,8 +199,9 @@ impl u8 { /// /// [`make_ascii_uppercase`]: #method.make_ascii_uppercase #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] + #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.50.0")] #[inline] - pub fn to_ascii_uppercase(&self) -> u8 { + pub const fn to_ascii_uppercase(&self) -> u8 { // Unset the fifth bit if this is a lowercase letter *self & !((self.is_ascii_lowercase() as u8) << 5) } @@ -222,8 +223,9 @@ impl u8 { /// /// [`make_ascii_lowercase`]: #method.make_ascii_lowercase #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] + #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.50.0")] #[inline] - pub fn to_ascii_lowercase(&self) -> u8 { + pub const fn to_ascii_lowercase(&self) -> u8 { // Set the fifth bit if this is an uppercase letter *self | ((self.is_ascii_uppercase() as u8) << 5) } @@ -241,8 +243,9 @@ impl u8 { /// assert!(lowercase_a.eq_ignore_ascii_case(&uppercase_a)); /// ``` #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] + #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.50.0")] #[inline] - pub fn eq_ignore_ascii_case(&self, other: &u8) -> bool { + pub const fn eq_ignore_ascii_case(&self, other: &u8) -> bool { self.to_ascii_lowercase() == other.to_ascii_lowercase() }