diff options
| author | Gabriel Bjørnager Jensen <gabriel@achernar.io> | 2024-09-23 11:54:41 +0200 |
|---|---|---|
| committer | Gabriel Bjørnager Jensen <gabriel@achernar.io> | 2024-09-24 08:50:40 +0200 |
| commit | e723fe1713b9db2ac7e3250ec8efe742cbcd46fe (patch) | |
| tree | 0d8e5ec8fe8c17d9fed9506279e27b109032a418 /library/core/src/slice | |
| parent | 702987f75b74f789ba227ee04a3d7bb1680c2309 (diff) | |
| download | rust-e723fe1713b9db2ac7e3250ec8efe742cbcd46fe.tar.gz rust-e723fe1713b9db2ac7e3250ec8efe742cbcd46fe.zip | |
Mark and implement 'make_ascii_uppercase' and 'make_ascii_lowercase' in '[u8]' and 'str' as const;
Diffstat (limited to 'library/core/src/slice')
| -rw-r--r-- | library/core/src/slice/ascii.rs | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/library/core/src/slice/ascii.rs b/library/core/src/slice/ascii.rs index d1ea52fab6b..8f8050fdc3a 100644 --- a/library/core/src/slice/ascii.rs +++ b/library/core/src/slice/ascii.rs @@ -67,10 +67,15 @@ impl [u8] { /// /// [`to_ascii_uppercase`]: #method.to_ascii_uppercase #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] + #[rustc_const_unstable(feature = "const_make_ascii", issue = "130698")] #[inline] - pub fn make_ascii_uppercase(&mut self) { - for byte in self { + pub const fn make_ascii_uppercase(&mut self) { + // FIXME(const-hack): We would like to simply iterate using `for` loops but this isn't currently allowed in constant expressions. + let mut i = 0; + while i < self.len() { + let byte = &mut self[i]; byte.make_ascii_uppercase(); + i += 1; } } @@ -84,10 +89,15 @@ impl [u8] { /// /// [`to_ascii_lowercase`]: #method.to_ascii_lowercase #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] + #[rustc_const_unstable(feature = "const_make_ascii", issue = "130698")] #[inline] - pub fn make_ascii_lowercase(&mut self) { - for byte in self { + pub const fn make_ascii_lowercase(&mut self) { + // FIXME(const-hack): We would like to simply iterate using `for` loops but this isn't currently allowed in constant expressions. + let mut i = 0; + while i < self.len() { + let byte = &mut self[i]; byte.make_ascii_lowercase(); + i += 1; } } |
