From e92a7881654085a47a1e2da5baa9eb799f425a5c Mon Sep 17 00:00:00 2001 From: YenForYang Date: Sun, 29 Nov 2020 20:16:31 -0600 Subject: [PATCH 1/9] Make char methods const `escape_unicode`, `escape_default`, `len_utf8`, `len_utf16`, to_ascii_lowercase`, `eq_ignore_ascii_case` `u8` methods `to_ascii_lowercase`, `to_ascii_uppercase` also must be made const --- library/core/src/char/methods.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index 1b847addcf806..d8e97a2bec483 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -391,7 +391,7 @@ impl char { /// ``` #[stable(feature = "rust1", since = "1.0.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 @@ -518,7 +518,7 @@ impl char { /// ``` #[stable(feature = "rust1", since = "1.0.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'), @@ -577,7 +577,7 @@ impl char { /// ``` #[stable(feature = "rust1", since = "1.0.0")] #[inline] - pub fn len_utf8(self) -> usize { + pub const fn len_utf8(self) -> usize { len_utf8(self as u32) } @@ -602,7 +602,7 @@ impl char { /// ``` #[stable(feature = "rust1", since = "1.0.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 } } @@ -1560,7 +1560,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 { From 5ac83798fe0686a13a3086410d410c96a6e2845a Mon Sep 17 00:00:00 2001 From: YenForYang Date: Sun, 29 Nov 2020 20:23:38 -0600 Subject: [PATCH 2/9] u8 methods made const --- library/core/src/num/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index 9f5ae57b74ade..b91a8e4987e59 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -200,7 +200,7 @@ impl u8 { /// [`make_ascii_uppercase`]: #method.make_ascii_uppercase #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.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) } @@ -223,7 +223,7 @@ impl u8 { /// [`make_ascii_lowercase`]: #method.make_ascii_lowercase #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.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) } @@ -242,7 +242,7 @@ impl u8 { /// ``` #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.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() } From 0091322d2787b8f6f101ca724b1523a34dda4c37 Mon Sep 17 00:00:00 2001 From: YenForYang Date: Sun, 29 Nov 2020 20:52:27 -0600 Subject: [PATCH 3/9] Update methods.rs --- library/core/src/char/methods.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index d8e97a2bec483..4a26a9cc3a129 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -390,6 +390,7 @@ impl char { /// assert_eq!('❤'.escape_unicode().to_string(), "\\u{2764}"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[stable(feature = "const_char_escape_unicode", since = "1.48.0")] #[inline] pub const fn escape_unicode(self) -> EscapeUnicode { let c = self as u32; @@ -517,6 +518,7 @@ impl char { /// assert_eq!('"'.escape_default().to_string(), "\\\""); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[stable(feature = "const_char_escape_default", since = "1.48.0")] #[inline] pub const fn escape_default(self) -> EscapeDefault { let init_state = match self { @@ -576,6 +578,7 @@ impl char { /// assert_eq!(len, tokyo.len()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_char_len_utf", since = "1.48.0")] #[inline] pub const fn len_utf8(self) -> usize { len_utf8(self as u32) @@ -601,6 +604,7 @@ impl char { /// assert_eq!(len, 2); /// ``` #[stable(feature = "rust1", since = "1.0.0")] + #[rustc_const_stable(feature = "const_char_len_utf", since = "1.48.0")] #[inline] pub const fn len_utf16(self) -> usize { let ch = self as u32; @@ -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.48.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.48.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.48.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() } From a7de9c15ae4c88f94f2d1ab6772a1b5b9454d1ba Mon Sep 17 00:00:00 2001 From: YenForYang Date: Sun, 29 Nov 2020 20:55:19 -0600 Subject: [PATCH 4/9] Update mod.rs --- library/core/src/num/mod.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index b91a8e4987e59..a44b1fdfa2cea 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -199,6 +199,7 @@ 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.48.0")] #[inline] pub const fn to_ascii_uppercase(&self) -> u8 { // Unset the fifth bit if this is a lowercase letter @@ -222,6 +223,7 @@ 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.48.0")] #[inline] pub const fn to_ascii_lowercase(&self) -> u8 { // Set the fifth bit if this is an uppercase letter @@ -241,6 +243,7 @@ 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.48.0")] #[inline] pub const fn eq_ignore_ascii_case(&self, other: &u8) -> bool { self.to_ascii_lowercase() == other.to_ascii_lowercase() From 0a4416c36fc8ecca2b8f0a480e6a9f7d73133934 Mon Sep 17 00:00:00 2001 From: YenForYang Date: Sun, 29 Nov 2020 20:59:25 -0600 Subject: [PATCH 5/9] Update methods.rs --- library/core/src/char/methods.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index 4a26a9cc3a129..4af0c7b160052 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -390,7 +390,7 @@ impl char { /// assert_eq!('❤'.escape_unicode().to_string(), "\\u{2764}"); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[stable(feature = "const_char_escape_unicode", since = "1.48.0")] + #[rustc_const_stable(feature = "const_char_escape_unicode", since = "1.48.0")] #[inline] pub const fn escape_unicode(self) -> EscapeUnicode { let c = self as u32; @@ -518,7 +518,7 @@ impl char { /// assert_eq!('"'.escape_default().to_string(), "\\\""); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[stable(feature = "const_char_escape_default", since = "1.48.0")] + #[rustc_const_stable(feature = "const_char_escape_default", since = "1.48.0")] #[inline] pub const fn escape_default(self) -> EscapeDefault { let init_state = match self { From 9060936e292833d743e4205acfc3b1c4a23d04f3 Mon Sep 17 00:00:00 2001 From: YenForYang Date: Tue, 1 Dec 2020 14:30:11 -0600 Subject: [PATCH 6/9] Fix `since` in rustc_const_stable to next stable --- library/core/src/char/methods.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index 4af0c7b160052..6942d7857c45a 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -390,7 +390,7 @@ 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.48.0")] + #[rustc_const_stable(feature = "const_char_escape_unicode", since = "1.49.0")] #[inline] pub const fn escape_unicode(self) -> EscapeUnicode { let c = self as u32; @@ -518,7 +518,7 @@ 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.48.0")] + #[rustc_const_stable(feature = "const_char_escape_default", since = "1.49.0")] #[inline] pub const fn escape_default(self) -> EscapeDefault { let init_state = match self { @@ -578,7 +578,7 @@ impl char { /// assert_eq!(len, tokyo.len()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "const_char_len_utf", since = "1.48.0")] + #[rustc_const_stable(feature = "const_char_len_utf", since = "1.49.0")] #[inline] pub const fn len_utf8(self) -> usize { len_utf8(self as u32) @@ -604,7 +604,7 @@ impl char { /// assert_eq!(len, 2); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "const_char_len_utf", since = "1.48.0")] + #[rustc_const_stable(feature = "const_char_len_utf", since = "1.49.0")] #[inline] pub const fn len_utf16(self) -> usize { let ch = self as u32; @@ -1097,7 +1097,7 @@ 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.48.0")] + #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.49.0")] #[inline] pub const fn to_ascii_uppercase(&self) -> char { if self.is_ascii() { (*self as u8).to_ascii_uppercase() as char } else { *self } @@ -1126,7 +1126,7 @@ 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.48.0")] + #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.49.0")] #[inline] pub const fn to_ascii_lowercase(&self) -> char { if self.is_ascii() { (*self as u8).to_ascii_lowercase() as char } else { *self } @@ -1148,7 +1148,7 @@ 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.48.0")] + #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.49.0")] #[inline] pub const fn eq_ignore_ascii_case(&self, other: &char) -> bool { self.to_ascii_lowercase() == other.to_ascii_lowercase() From 4337b2ae648933d42dd5ea63afdb473da3db8437 Mon Sep 17 00:00:00 2001 From: YenForYang Date: Tue, 1 Dec 2020 14:33:35 -0600 Subject: [PATCH 7/9] Fix `since` in rustc_const_stable to next stable --- library/core/src/num/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index a44b1fdfa2cea..1e68f9d610d58 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -199,7 +199,7 @@ 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.48.0")] + #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.49.0")] #[inline] pub const fn to_ascii_uppercase(&self) -> u8 { // Unset the fifth bit if this is a lowercase letter @@ -223,7 +223,7 @@ 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.48.0")] + #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.49.0")] #[inline] pub const fn to_ascii_lowercase(&self) -> u8 { // Set the fifth bit if this is an uppercase letter @@ -243,7 +243,7 @@ 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.48.0")] + #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.49.0")] #[inline] pub const fn eq_ignore_ascii_case(&self, other: &u8) -> bool { self.to_ascii_lowercase() == other.to_ascii_lowercase() From b5cf6ad642e856e24d22a998ed322e1b195fd501 Mon Sep 17 00:00:00 2001 From: YenForYang Date: Tue, 1 Dec 2020 15:32:17 -0600 Subject: [PATCH 8/9] Update methods.rs --- library/core/src/char/methods.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/library/core/src/char/methods.rs b/library/core/src/char/methods.rs index 6942d7857c45a..afca28a1f2fa0 100644 --- a/library/core/src/char/methods.rs +++ b/library/core/src/char/methods.rs @@ -390,7 +390,7 @@ 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.49.0")] + #[rustc_const_stable(feature = "const_char_escape_unicode", since = "1.50.0")] #[inline] pub const fn escape_unicode(self) -> EscapeUnicode { let c = self as u32; @@ -518,7 +518,7 @@ 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.49.0")] + #[rustc_const_stable(feature = "const_char_escape_default", since = "1.50.0")] #[inline] pub const fn escape_default(self) -> EscapeDefault { let init_state = match self { @@ -578,7 +578,7 @@ impl char { /// assert_eq!(len, tokyo.len()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "const_char_len_utf", since = "1.49.0")] + #[rustc_const_stable(feature = "const_char_len_utf", since = "1.50.0")] #[inline] pub const fn len_utf8(self) -> usize { len_utf8(self as u32) @@ -604,7 +604,7 @@ impl char { /// assert_eq!(len, 2); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - #[rustc_const_stable(feature = "const_char_len_utf", since = "1.49.0")] + #[rustc_const_stable(feature = "const_char_len_utf", since = "1.50.0")] #[inline] pub const fn len_utf16(self) -> usize { let ch = self as u32; @@ -1097,7 +1097,7 @@ 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.49.0")] + #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.50.0")] #[inline] pub const fn to_ascii_uppercase(&self) -> char { if self.is_ascii() { (*self as u8).to_ascii_uppercase() as char } else { *self } @@ -1126,7 +1126,7 @@ 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.49.0")] + #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.50.0")] #[inline] pub const fn to_ascii_lowercase(&self) -> char { if self.is_ascii() { (*self as u8).to_ascii_lowercase() as char } else { *self } @@ -1148,7 +1148,7 @@ 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.49.0")] + #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.50.0")] #[inline] pub const fn eq_ignore_ascii_case(&self, other: &char) -> bool { self.to_ascii_lowercase() == other.to_ascii_lowercase() From 8b303a63c0b38377a64ade85573b125866d568fe Mon Sep 17 00:00:00 2001 From: YenForYang Date: Tue, 1 Dec 2020 15:35:53 -0600 Subject: [PATCH 9/9] Update mod.rs --- library/core/src/num/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/library/core/src/num/mod.rs b/library/core/src/num/mod.rs index 1e68f9d610d58..d2e6955e241e1 100644 --- a/library/core/src/num/mod.rs +++ b/library/core/src/num/mod.rs @@ -199,7 +199,7 @@ 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.49.0")] + #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.50.0")] #[inline] pub const fn to_ascii_uppercase(&self) -> u8 { // Unset the fifth bit if this is a lowercase letter @@ -223,7 +223,7 @@ 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.49.0")] + #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.50.0")] #[inline] pub const fn to_ascii_lowercase(&self) -> u8 { // Set the fifth bit if this is an uppercase letter @@ -243,7 +243,7 @@ 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.49.0")] + #[rustc_const_stable(feature = "const_ascii_methods_on_intrinsics", since = "1.50.0")] #[inline] pub const fn eq_ignore_ascii_case(&self, other: &u8) -> bool { self.to_ascii_lowercase() == other.to_ascii_lowercase()