Skip to content

Tracking Issue for const checked slice to str conversions #91006

Closed

Description

@WaffleLapkin

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

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

Activity

  1. added
    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFC
    T-libs-api[DEPRECATED; DO NOT USE]
    on Nov 18, 2021
  2. Amanieu commented on May 23, 2022

    @Amanieu
    Member

    @rfcbot merge

  3. rfcbot commented on May 23, 2022

    @rfcbot

    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.

  4. added
    proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
    disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.
    on May 23, 2022
  5. WaffleLapkin commented on May 23, 2022

    @WaffleLapkin
    MemberAuthor

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

    cc @oli-obk

  6. Amanieu commented on May 23, 2022

    @Amanieu
    Member

    Tracking issue for &mut in const: #57349

  7. added
    final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
    and removed
    proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
    on Jun 8, 2022
  8. rfcbot commented on Jun 8, 2022

    @rfcbot

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

  9. added
    to-announceAnnounce this issue on triage meeting
    and removed
    final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.
    on Jun 18, 2022
  10. rfcbot commented on Jun 18, 2022

    @rfcbot

    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.

  11. 1 remaining item

  12. mina86 commented on Aug 8, 2022

    @mina86
    Contributor

    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.

  13. jhpratt commented on Feb 5, 2025

    @jhpratt
    Member

    As pointed out in #136517, there shouldn't be any blockers to stabilizing the mutable version of this.

    @rustbot label +I-libs-api-nominated

  14. added a commit that references this issue on Feb 24, 2025
  15. added a commit that references this issue on Feb 25, 2025
  16. added 2 commits that reference this issue on Mar 11, 2025
  17. added
    T-libsRelevant to the library team, which will review and decide on the PR/issue.
    and removed
    T-libs-api[DEPRECATED; DO NOT USE]
    on Aug 12, 2026
  18. maxdexh commented on Oct 21, 2026

    @maxdexh
    Member

    This tracking issue is not mentioned in any stability attrs anymore and the methods have all been const stable for a while.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libsRelevant to the library team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.finished-final-comment-periodThe final comment period is finished for this PR / Issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions