-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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 str_from_raw_parts
#119206
Comments
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.
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.
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.
fix: make `str::from_raw_parts_mut` `mut` `str::from_raw_parts_mut` wasn't actually `mut` rust-lang#119206
fix: make `str::from_raw_parts_mut` `mut` `str::from_raw_parts_mut` wasn't actually `mut` rust-lang#119206
Rollup merge of rust-lang#124100 - dev-ardi:master, r=workingjubilee fix: make `str::from_raw_parts_mut` `mut` `str::from_raw_parts_mut` wasn't actually `mut` rust-lang#119206
I'm not a fan of this. This saves a negligible amount of code but bunches up a whole lot of safety considerations. unsafe {
let bytes = slice::from_raw_parts(ptr, len);
str::from_utf8_unchecked(bytes)
} but it should have really been // SAFETY: <explain why ptr and len make a valid slice>
let bytes = unsafe { slice::from_raw_parts(ptr, len) };
// SAFETY: <explain why this slice is UTF-8>
unsafe { str::from_utf8_unchecked(bytes) } I don't see the value of combining these to // SAFETY: <explain why ptr and len make a valid slice and why this slice is UTF-8>
unsafe { str::from_raw_parts(ptr, len) } The proposed documentation also says
which kind of admits that there are two safety considerations that should be handled by two function calls. In the end, docs could just recommend |
This API intends to be the borrowed equivalent the already-stable
The documentation could be improved to properly express the safety concerns. Also note that the ACP was accepted because of the existence of If you really don't want these functions to appear in your codebase, consider the # clippy.toml
disallowed-methods = [
"core::str::from_raw_parts",
"core::str::from_raw_parts_mut",
"alloc::string::String::from_raw_parts",
# ...
] |
It looks like
at which point why not just make those two calls?
|
I'll copy my comment from the ACP here, as something potentially still worth discussing at stabilization time:
(This is the same sentiment as #119206 (comment) above.) |
Hi, is there any progress on this feature? Seems there's no outstanding questions. |
Feature gate:
#![feature(str_from_raw_parts)]
This is a tracking issue for ACP#167, which adds
core::str::from_raw_parts[_mut]
.Public API
Steps / History
str::from_raw_parts()
andstr::from_raw_parts_mut()
#107207str::from_raw_parts[_mut]
#119466Unresolved Questions
Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩
The text was updated successfully, but these errors were encountered: