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

Tracking issue for const char conversions #89259

Open
est31 opened this issue Sep 25, 2021 · 7 comments
Open

Tracking issue for const char conversions #89259

est31 opened this issue Sep 25, 2021 · 7 comments
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@est31
Copy link
Member

est31 commented Sep 25, 2021

This is a tracking issue for const char conversions. List of functions belonging to !#[feature(const_char_from_u32_unchecked)]:

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;
}

List of functions belonging to stable #![feature(const_char_convert)]:

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>;
}

Steps:

Stabilization is probably blocked by const panicing. Edit: const panic is stable now!

Stabilization is blocked by Option::unwrap const stability, which is blocked by #73255.

@est31 est31 added C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Sep 25, 2021
@leonardo-m
Copy link

We could keep a percentage counter somewhere that tells how much of stdlib is areweconstyet :)

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Nov 18, 2021
Make char conversion functions unstably const

The char conversion functions like `char::from_u32` do trivial computations and can easily be converted into const fns. Only smaller tricks are needed to avoid non-const standard library functions like `Result::ok` or `bool::then_some`.

Tracking issue: rust-lang#89259
JohnTitor added a commit to JohnTitor/rust that referenced this issue Nov 19, 2021
Make char conversion functions unstably const

The char conversion functions like `char::from_u32` do trivial computations and can easily be converted into const fns. Only smaller tricks are needed to avoid non-const standard library functions like `Result::ok` or `bool::then_some`.

Tracking issue: rust-lang#89259
@Nugine
Copy link
Contributor

Nugine commented Sep 29, 2022

Hi! Is there any plan of stabilization?

@est31
Copy link
Member Author

est31 commented Sep 29, 2022

@Nugine I've made a stabilization PR, let's see where this goes: #102470

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue 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 issue 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 issue 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`).
@ChrisDenton
Copy link
Contributor

Stabilization is blocked by #67441 const stability, which is blocked by #73255.

Could we not manually write out a match statement instead of using unwrap?

@est31
Copy link
Member Author

est31 commented Dec 15, 2023

I think the idea was that there should be no extra hacks done just to get things compatible with const fn, but I don't remember it fully any more.

@ChrisDenton
Copy link
Contributor

I've opened #118979 to see what T-libs thinks about it.

@ChrisDenton
Copy link
Contributor

#118979 is now merged so I think there's no blocker for from_u32_unchecked being stabilized as const.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants