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 checked slice to str conversions #91006

Open
3 of 5 tasks
WaffleLapkin opened this issue Nov 18, 2021 · 7 comments
Open
3 of 5 tasks

Tracking Issue for const checked slice to str conversions #91006

WaffleLapkin opened this issue Nov 18, 2021 · 7 comments
Labels
C-tracking-issue Category: A tracking issue for an RFC or an unstable feature. 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. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@WaffleLapkin
Copy link
Member

WaffleLapkin commented Nov 18, 2021

Feature gate: #![feature(const_str_from_utf8)]

This is a tracking issue for str::{from_utf8, from_utf8_mut} and str::Utf8Error::{valid_up_to, error_len} as const fn

Public API

// core::str

pub const fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error>;

Public API (stabilized in Rust 1.63)

// core::str

pub const fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error>;

impl Utf8Error {
    pub const fn valid_up_to(&self) -> usize;
    pub const fn error_len(&self) -> Option<usize>;
}

Steps / History

Unresolved Questions

  • None yet.
@WaffleLapkin WaffleLapkin 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 Nov 18, 2021
@Amanieu
Copy link
Member

Amanieu commented May 23, 2022

@rfcbot merge

@rfcbot
Copy link

rfcbot commented May 23, 2022

Team member @Amanieu 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 May 23, 2022
@WaffleLapkin
Copy link
Member Author

Note that from_utf8_mut is not being stabilized as &mut is still unstable in const context.

cc @oli-obk

@Amanieu
Copy link
Member

Amanieu commented May 23, 2022

Tracking issue for &mut in const: #57349

@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 Jun 8, 2022
@rfcbot
Copy link

rfcbot commented Jun 8, 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. to-announce Announce this issue on triage meeting and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Jun 18, 2022
@rfcbot
Copy link

rfcbot commented Jun 18, 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.

bors added a commit to rust-lang-ci/rust that referenced this issue Jun 19, 2022
…to_str_conv, r=dtolnay

Stabilize checked slice->str conversion functions

This PR stabilizes the following APIs as `const` functions in Rust 1.63:
```rust
// core::str

pub const fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error>;

impl Utf8Error {
    pub const fn valid_up_to(&self) -> usize;
    pub const fn error_len(&self) -> Option<usize>;
}
```

Note that the `from_utf8_mut` function is not stabilized as unique references (`&mut _`) are [unstable in const context].

FCP: rust-lang#91006 (comment)

[unstable in const context]: rust-lang#57349
@mina86
Copy link
Contributor

mina86 commented Aug 8, 2022

Could we also get std::ffi::CStr::to_str covered by this issue?

I was hoping this would give me a safe compile-time way to construct str from CStr but currently std::ffi::CStr::to_bytes is not const (for whatever reason) so std::str::from_utf8(cstr_value.to_bytes()) cannot be done in const context.

Alternatively, making std::ffi::CStr::to_bytes const would also work for me.

@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Sep 8, 2022
workingjubilee pushed a commit to tcdi/postgrestd that referenced this issue Sep 15, 2022
…nv, r=dtolnay

Stabilize checked slice->str conversion functions

This PR stabilizes the following APIs as `const` functions in Rust 1.63:
```rust
// core::str

pub const fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error>;

impl Utf8Error {
    pub const fn valid_up_to(&self) -> usize;
    pub const fn error_len(&self) -> Option<usize>;
}
```

Note that the `from_utf8_mut` function is not stabilized as unique references (`&mut _`) are [unstable in const context].

FCP: rust-lang/rust#91006 (comment)

[unstable in const context]: rust-lang/rust#57349
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. 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. 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

5 participants