forked fromrust-lang/rust
- Notifications
You must be signed in to change notification settings - Fork0
Commit6b67c66
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) } }; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^```3 files changed
+5
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
226 | | - | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
227 | 230 | | |
228 | 231 | | |
229 | 232 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | | - | |
| 126 | + | |
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
123 | 122 | | |
124 | 123 | | |
125 | 124 | | |
| |||
0 commit comments
Comments
(0)