Skip to content

Commit 8c77da8

Browse files
authored
Rollup merge of #102470 - est31:stabilize_const_char_convert, r=joshtriplett
Stabilize const char convert Split out `const_char_from_u32_unchecked` from `const_char_convert` and stabilize the rest, i.e. stabilize the following functions: ```Rust impl char { pub const fn from_u32(self, i: u32) -> Option<char>; pub const fn from_digit(self, num: u32, radix: u32) -> Option<char>; pub const fn to_digit(self, radix: u32) -> Option<u32>; } // Available through core::char and std::char mod char { pub const fn from_u32(i: u32) -> Option<char>; pub const fn from_digit(num: u32, radix: u32) -> Option<char>; } ``` And put the following under the `from_u32_unchecked` const stability gate as it needs `Option::unwrap` which isn't const-stable (yet): ```Rust impl char { pub const unsafe fn from_u32_unchecked(i: u32) -> char; } // Available through core::char and std::char mod char { pub const unsafe fn from_u32_unchecked(i: u32) -> char; } ``` cc the tracking issue #89259 (which I'd like to keep open for `const_char_from_u32_unchecked`).
2 parents 9f3786b + 176c44c commit 8c77da8

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

library/core/src/char/convert.rs

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ pub(super) const fn from_u32(i: u32) -> Option<char> {
1818
}
1919

2020
/// Converts a `u32` to a `char`, ignoring validity. See [`char::from_u32_unchecked`].
21-
#[rustc_const_unstable(feature = "const_char_convert", issue = "89259")]
2221
#[inline]
2322
#[must_use]
2423
pub(super) const unsafe fn from_u32_unchecked(i: u32) -> char {

library/core/src/char/methods.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ impl char {
140140
/// assert_eq!(None, c);
141141
/// ```
142142
#[stable(feature = "assoc_char_funcs", since = "1.52.0")]
143-
#[rustc_const_unstable(feature = "const_char_convert", issue = "89259")]
143+
#[rustc_const_stable(feature = "const_char_convert", since = "CURRENT_RUSTC_VERSION")]
144144
#[must_use]
145145
#[inline]
146146
pub const fn from_u32(i: u32) -> Option<char> {
@@ -183,7 +183,7 @@ impl char {
183183
/// assert_eq!('❤', c);
184184
/// ```
185185
#[stable(feature = "assoc_char_funcs", since = "1.52.0")]
186-
#[rustc_const_unstable(feature = "const_char_convert", issue = "89259")]
186+
#[rustc_const_unstable(feature = "const_char_from_u32_unchecked", issue = "89259")]
187187
#[must_use]
188188
#[inline]
189189
pub const unsafe fn from_u32_unchecked(i: u32) -> char {
@@ -241,7 +241,7 @@ impl char {
241241
/// let _c = char::from_digit(1, 37);
242242
/// ```
243243
#[stable(feature = "assoc_char_funcs", since = "1.52.0")]
244-
#[rustc_const_unstable(feature = "const_char_convert", issue = "89259")]
244+
#[rustc_const_stable(feature = "const_char_convert", since = "CURRENT_RUSTC_VERSION")]
245245
#[must_use]
246246
#[inline]
247247
pub const fn from_digit(num: u32, radix: u32) -> Option<char> {
@@ -338,7 +338,7 @@ impl char {
338338
/// let _ = '1'.to_digit(37);
339339
/// ```
340340
#[stable(feature = "rust1", since = "1.0.0")]
341-
#[rustc_const_unstable(feature = "const_char_convert", issue = "89259")]
341+
#[rustc_const_stable(feature = "const_char_convert", since = "CURRENT_RUSTC_VERSION")]
342342
#[must_use = "this returns the result of the operation, \
343343
without modifying the original"]
344344
#[inline]

library/core/src/char/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub fn decode_utf16<I: IntoIterator<Item = u16>>(iter: I) -> DecodeUtf16<I::Into
110110

111111
/// Converts a `u32` to a `char`. Use [`char::from_u32`] instead.
112112
#[stable(feature = "rust1", since = "1.0.0")]
113-
#[rustc_const_unstable(feature = "const_char_convert", issue = "89259")]
113+
#[rustc_const_stable(feature = "const_char_convert", since = "CURRENT_RUSTC_VERSION")]
114114
#[must_use]
115115
#[inline]
116116
pub const fn from_u32(i: u32) -> Option<char> {
@@ -120,7 +120,7 @@ pub const fn from_u32(i: u32) -> Option<char> {
120120
/// Converts a `u32` to a `char`, ignoring validity. Use [`char::from_u32_unchecked`].
121121
/// instead.
122122
#[stable(feature = "char_from_unchecked", since = "1.5.0")]
123-
#[rustc_const_unstable(feature = "const_char_convert", issue = "89259")]
123+
#[rustc_const_unstable(feature = "const_char_from_u32_unchecked", issue = "89259")]
124124
#[must_use]
125125
#[inline]
126126
pub const unsafe fn from_u32_unchecked(i: u32) -> char {
@@ -130,7 +130,7 @@ pub const unsafe fn from_u32_unchecked(i: u32) -> char {
130130

131131
/// Converts a digit in the given radix to a `char`. Use [`char::from_digit`] instead.
132132
#[stable(feature = "rust1", since = "1.0.0")]
133-
#[rustc_const_unstable(feature = "const_char_convert", issue = "89259")]
133+
#[rustc_const_stable(feature = "const_char_convert", since = "CURRENT_RUSTC_VERSION")]
134134
#[must_use]
135135
#[inline]
136136
pub const fn from_digit(num: u32, radix: u32) -> Option<char> {

library/core/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
#![feature(const_black_box)]
105105
#![feature(const_caller_location)]
106106
#![feature(const_cell_into_inner)]
107-
#![feature(const_char_convert)]
107+
#![feature(const_char_from_u32_unchecked)]
108108
#![feature(const_clone)]
109109
#![feature(const_cmp)]
110110
#![feature(const_discriminant)]

0 commit comments

Comments
 (0)