Auto merge of #130738 - bjoernager:const-make-ascii, r=jhpratt · qinheping/verify-rust-std@194bbc7 (original) (raw)
3 files changed
lines changed
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -132,6 +132,7 @@ | ||
132 | 132 | #![feature(const_ipv4)] |
133 | 133 | #![feature(const_ipv6)] |
134 | 134 | #![feature(const_likely)] |
135 | +#![feature(const_make_ascii)] | |
135 | 136 | #![feature(const_maybe_uninit_assume_init)] |
136 | 137 | #![feature(const_nonnull_new)] |
137 | 138 | #![feature(const_num_midpoint)] |
@@ -150,6 +151,7 @@ | ||
150 | 151 | #![feature(const_slice_from_raw_parts_mut)] |
151 | 152 | #![feature(const_slice_from_ref)] |
152 | 153 | #![feature(const_slice_split_at_mut)] |
154 | +#![feature(const_str_as_mut)] | |
153 | 155 | #![feature(const_str_from_utf8_unchecked_mut)] |
154 | 156 | #![feature(const_strict_overflow_ops)] |
155 | 157 | #![feature(const_swap)] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -67,10 +67,15 @@ impl [u8] { | ||
67 | 67 | /// |
68 | 68 | /// [`to_ascii_uppercase`]: #method.to_ascii_uppercase |
69 | 69 | #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] |
70 | +#[rustc_const_unstable(feature = "const_make_ascii", issue = "130698")] | |
70 | 71 | #[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 = 0; | |
75 | +while i < self.len() { | |
76 | +let byte = &mut self[i]; | |
73 | 77 | byte.make_ascii_uppercase(); |
78 | + i += 1; | |
74 | 79 | } |
75 | 80 | } |
76 | 81 | |
@@ -84,10 +89,15 @@ impl [u8] { | ||
84 | 89 | /// |
85 | 90 | /// [`to_ascii_lowercase`]: #method.to_ascii_lowercase |
86 | 91 | #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] |
92 | +#[rustc_const_unstable(feature = "const_make_ascii", issue = "130698")] | |
87 | 93 | #[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 = 0; | |
97 | +while i < self.len() { | |
98 | +let byte = &mut self[i]; | |
90 | 99 | byte.make_ascii_lowercase(); |
100 | + i += 1; | |
91 | 101 | } |
92 | 102 | } |
93 | 103 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2473,8 +2473,9 @@ impl str { | ||
2473 | 2473 | /// assert_eq!("GRüßE, JüRGEN ❤", s); |
2474 | 2474 | /// ``` |
2475 | 2475 | #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] |
2476 | +#[rustc_const_unstable(feature = "const_make_ascii", issue = "130698")] | |
2476 | 2477 | #[inline] |
2477 | -pub fn make_ascii_uppercase(&mut self) { | |
2478 | +pub const fn make_ascii_uppercase(&mut self) { | |
2478 | 2479 | // SAFETY: changing ASCII letters only does not invalidate UTF-8. |
2479 | 2480 | let me = unsafe { self.as_bytes_mut() }; |
2480 | 2481 | me.make_ascii_uppercase() |
@@ -2500,8 +2501,9 @@ impl str { | ||
2500 | 2501 | /// assert_eq!("grÜße, jÜrgen ❤", s); |
2501 | 2502 | /// ``` |
2502 | 2503 | #[stable(feature = "ascii_methods_on_intrinsics", since = "1.23.0")] |
2504 | +#[rustc_const_unstable(feature = "const_make_ascii", issue = "130698")] | |
2503 | 2505 | #[inline] |
2504 | -pub fn make_ascii_lowercase(&mut self) { | |
2506 | +pub const fn make_ascii_lowercase(&mut self) { | |
2505 | 2507 | // SAFETY: changing ASCII letters only does not invalidate UTF-8. |
2506 | 2508 | let me = unsafe { self.as_bytes_mut() }; |
2507 | 2509 | me.make_ascii_lowercase() |