Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6b67c66

Browse files
committed
Auto merge ofrust-lang#126958 - dtolnay:u32char, r=Mark-Simulacrum
Stabilize const unchecked conversion from u32 to charClosesrust-lang#89259.The functions in this PR were left out of the initial set of `feature(const_char_convert)` stabilizations inrust-lang#102470, but have since been unblocked byrust-lang#118979.If `unsafe { from_u32_unchecked(u) }` is called in const with a value for which `from_u32(u)` returns None, we get the following compile error.```rustfn main() { let _ = const { unsafe { char::from_u32_unchecked(0xd800) } };}``````consoleerror[E0080]: it is undefined behavior to use this value --> src/main.rs:2:19 |2 | let _ = const { unsafe { char::from_u32_unchecked(0xd800) } }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constructing invalid value: encountered 0x0000d800, but expected a valid unicode scalar value (in `0..=0x10FFFF` but not in `0xD800..=0xDFFF`) | = note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. = note: the raw bytes of the constant (size: 4, align: 4) { 00 d8 00 00 │ .... }note: erroneous constant encountered --> src/main.rs:2:13 |2 | let _ = const { unsafe { char::from_u32_unchecked(0xd800) } }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^```
2 parents591aaaf +0fe5362 commit6b67c66

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

‎core/src/char/methods.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,10 @@ impl char {
223223
/// assert_eq!('❤', c);
224224
/// ```
225225
#[stable(feature ="assoc_char_funcs", since ="1.52.0")]
226-
#[rustc_const_unstable(feature ="const_char_from_u32_unchecked", issue ="89259")]
226+
#[rustc_const_stable(
227+
feature ="const_char_from_u32_unchecked",
228+
since ="CURRENT_RUSTC_VERSION"
229+
)]
227230
#[must_use]
228231
#[inline]
229232
pubconstunsafefnfrom_u32_unchecked(i:u32) ->char{

‎core/src/char/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ pub const fn from_u32(i: u32) -> Option<char> {
123123
/// Converts a `u32` to a `char`, ignoring validity. Use [`char::from_u32_unchecked`].
124124
/// instead.
125125
#[stable(feature ="char_from_unchecked", since ="1.5.0")]
126-
#[rustc_const_unstable(feature ="const_char_from_u32_unchecked",issue ="89259")]
126+
#[rustc_const_stable(feature ="const_char_from_u32_unchecked",since ="CURRENT_RUSTC_VERSION")]
127127
#[must_use]
128128
#[inline]
129129
pubconstunsafefnfrom_u32_unchecked(i:u32) ->char{

‎core/src/lib.rs‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@
119119
#![feature(const_bigint_helper_methods)]
120120
#![feature(const_black_box)]
121121
#![feature(const_cell_into_inner)]
122-
#![feature(const_char_from_u32_unchecked)]
123122
#![feature(const_eval_select)]
124123
#![feature(const_exact_div)]
125124
#![feature(const_float_bits_conv)]

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp