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

Implement str::from_raw_parts() and str::from_raw_parts_mut() #107207

Closed
wants to merge 2 commits into from

Conversation

Kixiron
Copy link
Member

@Kixiron Kixiron commented Jan 22, 2023

Implements str::from_raw_parts() and str::from_raw_parts_mut() which are effectively shorthand for

let bytes = slice::from_raw_parts(ptr, len);
str::from_utf8_unchecked(bytes)

@rustbot label: T-libs T-core

ACP: rust-lang/libs-team#167.

@rustbot
Copy link
Collaborator

rustbot commented Jan 22, 2023

r? @thomcc

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 22, 2023
@rustbot
Copy link
Collaborator

rustbot commented Jan 22, 2023

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

@Kixiron
Copy link
Member Author

Kixiron commented Jan 22, 2023

@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 Jan 22, 2023
@rust-log-analyzer
Copy link
Collaborator

The job x86_64-gnu-llvm-13 failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
error[E0133]: call to unsafe function is unsafe and requires unsafe block
  --> library/core/src/str/raw.rs:95:60
   |
89 |     unsafe {
   |     ------ items do not inherit unsafety from separate enclosing items
...
95 |                 && super::validations::run_utf8_validation(crate::slice::from_raw_parts(data, len)).is_ok()
   |
   = note: consult the function's documentation for information on how to avoid undefined behavior

error[E0133]: call to unsafe function is unsafe and requires unsafe block
error[E0133]: call to unsafe function is unsafe and requires unsafe block
   --> library/core/src/str/raw.rs:145:60
    |
139 |     unsafe {
    |     ------ items do not inherit unsafety from separate enclosing items
...
145 |                 && super::validations::run_utf8_validation(crate::slice::from_raw_parts(data, len)).is_ok()
    |
    = note: consult the function's documentation for information on how to avoid undefined behavior

For more information about this error, try `rustc --explain E0133`.

@thomcc
Copy link
Member

thomcc commented Jan 23, 2023

Can you file an ACP? NM, see rust-lang/libs-team#167.

@thomcc thomcc added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. S-waiting-on-ACP Status: PR has an ACP and is waiting for the ACP to complete. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jan 23, 2023
@thomcc thomcc added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-ACP Status: PR has an ACP and is waiting for the ACP to complete. labels Oct 24, 2023
@tgross35
Copy link
Contributor

tgross35 commented Oct 24, 2023

For the docs could you add something like, "if there is any doubt that the incoming data may not be UTF-8, prefer str::from_utf8(slice::from_raw_parts(ptr, len)) instead", to point people in the right diretion?

Also, I think it would be better to provide a short summary of the safety requirements and then point to slice::from_raw_parts{mut} for the details rather than duplicating the documentation.

@Sky9x
Copy link
Contributor

Sky9x commented Nov 23, 2023

any update on this? would be very nice to have

@Sky9x
Copy link
Contributor

Sky9x commented Dec 22, 2023

I've opened a tracking issue: #119206

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 26, 2024
Initial implementation of `str::from_raw_parts[_mut]`

ACP (accepted): rust-lang/libs-team#167
Tracking issue: rust-lang#119206

Thanks to `@Kixiron` for previous work on this (rust-lang#107207)

`@rustbot` label  T-libs-api -T-libs
r? `@thomcc`

Closes rust-lang#107207.
@bors bors closed this in 912877d Jan 26, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 26, 2024
Rollup merge of rust-lang#119466 - Sky9x:str_from_raw_parts, r=dtolnay

Initial implementation of `str::from_raw_parts[_mut]`

ACP (accepted): rust-lang/libs-team#167
Tracking issue: rust-lang#119206

Thanks to ``@Kixiron`` for previous work on this (rust-lang#107207)

``@rustbot`` label  T-libs-api -T-libs
r? ``@thomcc``

Closes rust-lang#107207.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

6 participants