Skip to content

Stabilize const unchecked conversion from u32 to char#126958

Merged
bors merged 1 commit into
rust-lang:masterfrom
dtolnay:u32char
Jul 13, 2024
Merged

Stabilize const unchecked conversion from u32 to char#126958
bors merged 1 commit into
rust-lang:masterfrom
dtolnay:u32char

Conversation

@dtolnay

@dtolnay dtolnay commented Jun 25, 2024

Copy link
Copy Markdown
Member

Closes #89259.

The functions in this PR were left out of the initial set of feature(const_char_convert) stabilizations in #102470, but have since been unblocked by #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.

fn main() {
    let _ = const { unsafe { char::from_u32_unchecked(0xd800) } };
}
error[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) } };
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

@rustbot

rustbot commented Jun 25, 2024

Copy link
Copy Markdown
Collaborator

r? @Mark-Simulacrum

rustbot has assigned @Mark-Simulacrum.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jun 25, 2024
@dtolnay dtolnay added S-waiting-on-team needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 25, 2024
@m-ou-se m-ou-se added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 10, 2024
@joshtriplett joshtriplett added the I-libs-api-nominated Nominated for discussion during a libs-api team meeting. label Jul 10, 2024
@dtolnay

dtolnay commented Jul 12, 2024

Copy link
Copy Markdown
Member Author

@rustbot ready (completed FCP in the tracking issue)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 12, 2024
@dtolnay dtolnay removed S-waiting-on-team needs-fcp This change is insta-stable, or significant enough to need a team FCP to proceed. I-libs-api-nominated Nominated for discussion during a libs-api team meeting. labels Jul 12, 2024
@Mark-Simulacrum

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented Jul 13, 2024

Copy link
Copy Markdown
Collaborator

📌 Commit 9d3c79b has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 13, 2024
@bors

bors commented Jul 13, 2024

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 9d3c79b with merge fcaa6fd...

@bors

bors commented Jul 13, 2024

Copy link
Copy Markdown
Collaborator

☀️ Test successful - checks-actions
Approved by: Mark-Simulacrum
Pushing fcaa6fd to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jul 13, 2024
@bors bors merged commit fcaa6fd into rust-lang:master Jul 13, 2024
@rustbot rustbot added this to the 1.81.0 milestone Jul 13, 2024
@dtolnay dtolnay deleted the u32char branch July 13, 2024 21:03
@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (fcaa6fd): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 704.234s -> 705.014s (0.11%)
Artifact size: 328.65 MiB -> 328.67 MiB (0.00%)

@dtolnay dtolnay removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tracking issue for const char conversions

7 participants