Skip to content

Commit b7c5465

Browse files
committed
Mark and implement 'make_ascii_uppercase' and 'make_ascii_lowercase' in '[u8]' and as const;
1 parent 2daf076 commit b7c5465

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

library/core/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
#![feature(const_ipv4)]
132132
#![feature(const_ipv6)]
133133
#![feature(const_likely)]
134+
#![feature(const_make_ascii)]
134135
#![feature(const_maybe_uninit_as_mut_ptr)]
135136
#![feature(const_maybe_uninit_assume_init)]
136137
#![feature(const_nonnull_new)]
@@ -150,6 +151,7 @@
150151
#![feature(const_slice_from_raw_parts_mut)]
151152
#![feature(const_slice_from_ref)]
152153
#![feature(const_slice_split_at_mut)]
154+
#![feature(const_str_as_mut)]
153155
#![feature(const_str_from_utf8_unchecked_mut)]
154156
#![feature(const_strict_overflow_ops)]
155157
#![feature(const_swap)]

library/core/src/slice/ascii.rs

+14-4
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,15 @@ impl [u8] {
6767
///
6868
/// [`to_ascii_uppercase`]: #method.to_ascii_uppercase
6969
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
70+
#[rustc_const_unstable(feature = "const_make_ascii", issue = "130698")]
7071
#[inline]
71-
pub fn make_ascii_uppercase(&mut self) {
72-
for byte in self {
72+
pub const fn make_ascii_uppercase(&mut self) {
73+
// FIXME(const-hack): We would like to simply iterate using `for` loops but this isn't currently allowed in constant expressions.
74+
let mut i = 0x0;
75+
while i < self.len() {
76+
let byte = &mut self[i];
7377
byte.make_ascii_uppercase();
78+
i += 0x1;
7479
}
7580
}
7681

@@ -84,10 +89,15 @@ impl [u8] {
8489
///
8590
/// [`to_ascii_lowercase`]: #method.to_ascii_lowercase
8691
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
92+
#[rustc_const_unstable(feature = "const_make_ascii", issue = "130698")]
8793
#[inline]
88-
pub fn make_ascii_lowercase(&mut self) {
89-
for byte in self {
94+
pub const fn make_ascii_lowercase(&mut self) {
95+
// FIXME(const-hack): We would like to simply iterate using `for` loops but this isn't currently allowed in constant expressions.
96+
let mut i = 0x0;
97+
while i < self.len() {
98+
let byte = &mut self[i];
9099
byte.make_ascii_lowercase();
100+
i += 0x1;
91101
}
92102
}
93103

library/core/src/str/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2469,8 +2469,9 @@ impl str {
24692469
/// assert_eq!("GRüßE, JüRGEN ❤", s);
24702470
/// ```
24712471
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
2472+
#[rustc_const_unstable(feature = "const_make_ascii", issue = "130698")]
24722473
#[inline]
2473-
pub fn make_ascii_uppercase(&mut self) {
2474+
pub const fn make_ascii_uppercase(&mut self) {
24742475
// SAFETY: changing ASCII letters only does not invalidate UTF-8.
24752476
let me = unsafe { self.as_bytes_mut() };
24762477
me.make_ascii_uppercase()
@@ -2496,8 +2497,9 @@ impl str {
24962497
/// assert_eq!("grÜße, jÜrgen ❤", s);
24972498
/// ```
24982499
#[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")]
2500+
#[rustc_const_unstable(feature = "const_make_ascii", issue = "130698")]
24992501
#[inline]
2500-
pub fn make_ascii_lowercase(&mut self) {
2502+
pub const fn make_ascii_lowercase(&mut self) {
25012503
// SAFETY: changing ASCII letters only does not invalidate UTF-8.
25022504
let me = unsafe { self.as_bytes_mut() };
25032505
me.make_ascii_lowercase()

0 commit comments

Comments
 (0)