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 inherent_str_constructors #131114

Closed
2 of 4 tasks
robertbastian opened this issue Oct 1, 2024 · 6 comments · Fixed by #137277
Closed
2 of 4 tasks

Tracking Issue for inherent_str_constructors #131114

robertbastian opened this issue Oct 1, 2024 · 6 comments · Fixed by #137277
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC 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

@robertbastian
Copy link
Contributor

robertbastian commented Oct 1, 2024

Feature gate: #![feature(inherent_str_constructors)]

This is a tracking issue for inherent str constructors.

Public API

  • str::from_utf8
  • str::from_utf8_mut
  • str::from_utf8_unchecked
  • str::from_utf8_unchecked_mut

Steps / History

Unresolved Questions

  • None yet.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

@robertbastian robertbastian added C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Oct 1, 2024
jieyouxu added a commit to jieyouxu/rust that referenced this issue Feb 5, 2025
…rs, r=jhpratt

implement inherent str constructors

implement rust-lang#131114

this implements
- str::from_utf8
- str::from_utf8_mut
- str::from_utf8_unchecked
- str::from_utf8_unchecked_mut

i left `std::str::from_raw_parts` and `std::str::from_raw_parts_mut` out of this as those are unstable and were not mentioned by the tracking issue or the original pull request, but i can  add those here as well.

i was also unsure of what to do with the `rustc_const_(un)stable` attributes: i removed the `#[rustc_const_stable]` attribute from `str::from_utf8`, `str::from_utf8_unchecked` and `str::from_utf8_unchecked_mut`, and left the`#[rust_const_unstable]` in `str::from_utf8_mut` (btw why is that one not const stable yet with rust-lang#57349 merged?).

is there a way to redirect users to the stable `std::str::from_utf8` instead of only saying "hey this is unstable"?

for now i just removed the check for `str::from_utf8` in the test in `tests/ui/suggestions/suggest-std-when-using-type.rs`.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 6, 2025
Rollup merge of rust-lang#136517 - m4rch3n1ng:inherent-str-constructors, r=jhpratt

implement inherent str constructors

implement rust-lang#131114

this implements
- str::from_utf8
- str::from_utf8_mut
- str::from_utf8_unchecked
- str::from_utf8_unchecked_mut

i left `std::str::from_raw_parts` and `std::str::from_raw_parts_mut` out of this as those are unstable and were not mentioned by the tracking issue or the original pull request, but i can  add those here as well.

i was also unsure of what to do with the `rustc_const_(un)stable` attributes: i removed the `#[rustc_const_stable]` attribute from `str::from_utf8`, `str::from_utf8_unchecked` and `str::from_utf8_unchecked_mut`, and left the`#[rust_const_unstable]` in `str::from_utf8_mut` (btw why is that one not const stable yet with rust-lang#57349 merged?).

is there a way to redirect users to the stable `std::str::from_utf8` instead of only saying "hey this is unstable"?

for now i just removed the check for `str::from_utf8` in the test in `tests/ui/suggestions/suggest-std-when-using-type.rs`.
@hanna-kruppe
Copy link
Contributor

hanna-kruppe commented Feb 9, 2025

I would like to request stabilization of these constructors. Yes, they only landed in nightly a few days ago, but there shouldn't be any need to gather more experience with them since they're identical in every way to existing APIs that have been stable forever, except not requiring an import of the str module. On the contrary, them existing unstably currently degrades compiler diagnostics, so stabilizing them ASAP would be helpful.

Implementation history

API summary

impl str {
    pub const fn from_utf8(v: &[u8]) -> Result<&str, Utf8Error>;
    pub fn from_utf8_mut(v: &mut [u8]) -> Result<&mut str, Utf8Error>;
    pub const unsafe fn from_utf8_unchecked(v: &[u8]) -> &str;
    pub const unsafe fn from_utf8_unchecked_mut(v: &mut [u8]) -> &mut str;
}

The stable *_mut constructors The stable core::str::from_utf8_mut is not stably const yet, so the inherent equivalent should not be const-stabilized either at this point (but see #136668). The other three constructors are stably const, including from_utf8_unchecked_mut since 1.83.

Experience report

As @joshtriplett wrote on the ACP:

The reaction in today's @rust-lang/libs-api meeting was "why didn't we do this years ago".

I just tried it on a personal project, removing four imports of {std,core}::str and adding #![feature(inherent_str_constructors)] to the respective crate roots instead. Worked as expected. But I'm not going to commit those changes because having to add the feature flag wouldn't be worth it even if that project already required nightly.

@joshtriplett
Copy link
Member

@rfcbot merge

@rfcbot
Copy link

rfcbot commented Feb 9, 2025

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. final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels Feb 9, 2025
@rfcbot
Copy link

rfcbot commented Feb 9, 2025

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

@rfcbot rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Feb 9, 2025
@tgross35
Copy link
Contributor

tgross35 commented Feb 9, 2025

One concern: these new methods bypass the deny-by-default invalid_from_utf8_unchecked lint https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=d83927cfe3a10a45e8ce6684396396f5. Updating to cover both is pretty trivial, I think this should be done before stabilization.

There are also a few clippy lints that use the same diagnostic items, somebody should at least open an issue there so they can update.

Lint source: https://github.com/rust-lang/rust/blob/124cc92199ffa924f6b4c7cc819a85b65e0c3984/compiler/rustc_lint/src/invalid_from_utf8.rs

Edit: Thanks GrigorenkoPV for handling rustc, opened rust-lang/rust-clippy#14254 for clippy.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 17, 2025
…Urgau

`invalid_from_utf8[_unchecked]`: also lint inherent methods

Addressing rust-lang#131114 (comment)

Also corrected a typo: "_an_ invalid literal", not "_a_ invalid literal".
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 17, 2025
Rollup merge of rust-lang#137101 - GrigorenkoPV:str-inherent-lint, r=Urgau

`invalid_from_utf8[_unchecked]`: also lint inherent methods

Addressing rust-lang#131114 (comment)

Also corrected a typo: "_an_ invalid literal", not "_a_ invalid literal".
lnicola pushed a commit to lnicola/rust-analyzer that referenced this issue Feb 17, 2025
`invalid_from_utf8[_unchecked]`: also lint inherent methods

Addressing rust-lang/rust#131114 (comment)

Also corrected a typo: "_an_ invalid literal", not "_a_ invalid literal".
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Feb 18, 2025
…r=Amanieu

fix docs for inherent str constructors

related to rust-lang#131114

when implementing inherent str constructors in rust-lang#136517, i forgot to change the docs, so the code examples still imported the `std::str` module and used the constructor from there, instead of using "itself" (the inherent constructor).
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 18, 2025
…r=Amanieu

fix docs for inherent str constructors

related to rust-lang#131114

when implementing inherent str constructors in rust-lang#136517, i forgot to change the docs, so the code examples still imported the `std::str` module and used the constructor from there, instead of using "itself" (the inherent constructor).
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Feb 18, 2025
…r=Amanieu

fix docs for inherent str constructors

related to rust-lang#131114

when implementing inherent str constructors in rust-lang#136517, i forgot to change the docs, so the code examples still imported the `std::str` module and used the constructor from there, instead of using "itself" (the inherent constructor).
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 19, 2025
Rollup merge of rust-lang#137126 - m4rch3n1ng:fix-inherent-str-docs, r=Amanieu

fix docs for inherent str constructors

related to rust-lang#131114

when implementing inherent str constructors in rust-lang#136517, i forgot to change the docs, so the code examples still imported the `std::str` module and used the constructor from there, instead of using "itself" (the inherent constructor).
@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 Feb 19, 2025
@rfcbot
Copy link

rfcbot commented Feb 19, 2025

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.

@tgross35 tgross35 changed the title Tracking Issue for inherent_str_constructors Tracking Issue for inherent_str_constructors Feb 19, 2025
@bors bors closed this as completed in be73ea8 Feb 20, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Feb 20, 2025
Rollup merge of rust-lang#137277 - m4rch3n1ng:stabilize-inherent-str-constructors, r=tgross35

stabilize `inherent_str_constructors`

fcp done in rust-lang#131114 (comment).

tracking issue: rust-lang#131114
closes: rust-lang#131114
flip1995 pushed a commit to flip1995/rust-clippy that referenced this issue Feb 20, 2025
`invalid_from_utf8[_unchecked]`: also lint inherent methods

Addressing rust-lang/rust#131114 (comment)

Also corrected a typo: "_an_ invalid literal", not "_a_ invalid literal".
@apiraino apiraino removed the to-announce Announce this issue on triage meeting label Feb 21, 2025
RalfJung pushed a commit to RalfJung/miri that referenced this issue Feb 24, 2025
…ors, r=tgross35

stabilize `inherent_str_constructors`

fcp done in rust-lang/rust#131114 (comment).

tracking issue: #131114
closes: #131114
BoxyUwU pushed a commit to BoxyUwU/rustc-dev-guide that referenced this issue Feb 25, 2025
`invalid_from_utf8[_unchecked]`: also lint inherent methods

Addressing rust-lang/rust#131114 (comment)

Also corrected a typo: "_an_ invalid literal", not "_a_ invalid literal".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC 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

Successfully merging a pull request may close this issue.

6 participants