Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize const char convert #102470

Merged
merged 2 commits into from
Nov 15, 2022
Merged

Conversation

est31
Copy link
Member

@est31 est31 commented Sep 29, 2022

Split out const_char_from_u32_unchecked from const_char_convert and stabilize the rest, i.e. stabilize the following functions:

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):

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).

It relies on the Option::unwrap function which is not const-stable (yet).
@rustbot rustbot added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Sep 29, 2022
@rustbot
Copy link
Collaborator

rustbot commented Sep 29, 2022

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@rust-highfive
Copy link
Collaborator

r? @scottmcm

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 29, 2022
@est31
Copy link
Member Author

est31 commented Sep 29, 2022

I'd like to have an FCP for the stabilization, ideally here because I'd like to re-use the tracking issue. I've opened #89258 12 months ago, and it's been merged 10 months ago, so the feature had plenty of time in nightly.

@rustbot label +T-libs-api -T-libs

@rustbot rustbot 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 Sep 29, 2022
@est31
Copy link
Member Author

est31 commented Oct 6, 2022

r? rust-lang/libs-api

@scottmcm
Copy link
Member

scottmcm commented Oct 6, 2022

There's no group for libs-api, so I (got ddg to) flip a coin, and it came up
r? @joshtriplett

@joshtriplett
Copy link
Member

Seems reasonable to me!

@rfcbot merge

@rfcbot
Copy link

rfcbot commented Oct 14, 2022

Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@rfcbot rfcbot added proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. labels Oct 14, 2022
@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels Oct 25, 2022
@rfcbot
Copy link

rfcbot commented Oct 25, 2022

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Nov 4, 2022
@rfcbot
Copy link

rfcbot commented Nov 4, 2022

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

@rfcbot rfcbot added the to-announce Announce this issue on triage meeting label Nov 4, 2022
@est31
Copy link
Member Author

est31 commented Nov 14, 2022

r? @joshtriplett it's ready for approval now that the FCP has passed :)

@rustbot
Copy link
Collaborator

rustbot commented Nov 14, 2022

Could not assign reviewer from: joshtriplett.
User(s) joshtriplett are either the PR author or are already assigned, and there are no other candidates.
Use r? to specify someone else to assign.

@joshtriplett
Copy link
Member

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Nov 14, 2022

📌 Commit 176c44c has been approved by joshtriplett

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 Nov 14, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 14, 2022
…, 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 rust-lang#89259 (which I'd like to keep open for `const_char_from_u32_unchecked`).
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 14, 2022
…, 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 rust-lang#89259 (which I'd like to keep open for `const_char_from_u32_unchecked`).
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 15, 2022
…iaskrgr

Rollup of 11 pull requests

Successful merges:

 - rust-lang#101967 (Move `unix_socket_abstract` feature API to `SocketAddrExt`.)
 - rust-lang#102470 (Stabilize const char convert)
 - rust-lang#104223 (Recover from function pointer types with generic parameter list)
 - rust-lang#104229 (Don't print full paths in overlap errors)
 - rust-lang#104294 (Don't ICE with inline const errors during MIR build)
 - rust-lang#104332 (Fixed some `_i32` notation in `maybe_uninit`’s doc)
 - rust-lang#104349 (fix some typos in comments)
 - rust-lang#104350 (Fix x finding Python on Windows)
 - rust-lang#104356 (interpret: make check_mplace public)
 - rust-lang#104364 (rustdoc: Resolve doc links in external traits having local impls)
 - rust-lang#104378 (Bump chalk to v0.87)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 8c77da8 into rust-lang:master Nov 15, 2022
@rustbot rustbot added this to the 1.67.0 milestone Nov 15, 2022
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Jan 5, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 28, 2023
Const stabilize mem::discriminant

Tracking issue: rust-lang#69821.

This PR is a rebase of rust-lang#103893 to resolve conflicts in library/core/src/lib.rs (against rust-lang#102470 and rust-lang#110393).
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 28, 2023
Const stabilize mem::discriminant

Tracking issue: rust-lang#69821.

This PR is a rebase of rust-lang#103893 to resolve conflicts in library/core/src/lib.rs (against rust-lang#102470 and rust-lang#110393).
bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 13, 2024
Stabilize const unchecked conversion from u32 to char

Closes rust-lang#89259.

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

```rust
fn main() {
    let _ = const { unsafe { char::from_u32_unchecked(0xd800) } };
}
```

```console
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) } };
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Jul 16, 2024
Stabilize const unchecked conversion from u32 to char

Closes rust-lang/rust#89259.

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

```rust
fn main() {
    let _ = const { unsafe { char::from_u32_unchecked(0xd800) } };
}
```

```console
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) } };
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
lnicola pushed a commit to lnicola/rust-analyzer that referenced this pull request Jul 16, 2024
Stabilize const unchecked conversion from u32 to char

Closes rust-lang/rust#89259.

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

```rust
fn main() {
    let _ = const { unsafe { char::from_u32_unchecked(0xd800) } };
}
```

```console
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) } };
  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

8 participants