-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Update docs for str::as_bytes_mut. #74381
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
src/libcore/str/mod.rs
Outdated
/// # Safety | ||
/// | ||
/// The caller must ensure that the content of the slice remains | ||
/// valid UTF-8. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to reflect the change from #71033. Any suggestions for clearer or more precise wording are welcome.
* Add "Safety" section describing UTF-8 invariant. * Remove mention of `from_utf8_mut`. It is not necessary to call a function to convert the byte slice back to a string slice. The original string becomes accessible again after the byte slice is no longer used (as shown in the example code).
@bors r+ rollup I think in theory we could relax even further -- e.g., calling this method on a non-UTF-8 str seems fine. But I think this is good enough for now and does not expand scope, so does not need T-libs/lang signoff. |
📌 Commit 6da69ec has been approved by |
Update docs for str::as_bytes_mut. * Add "Safety" section describing UTF-8 invariant. * Remove mention of `from_utf8_mut`. It is not necessary to call a function to convert the byte slice back to a string slice. The original string becomes accessible again after the byte slice is no longer used (as shown in the example code).
…arth Rollup of 7 pull requests Successful merges: - rust-lang#73421 (Clarify effect of orphan rule changes on From/Into) - rust-lang#74037 (Update reference to CONTRIBUTING.md) - rust-lang#74203 (Enforce the static symbol order.) - rust-lang#74295 (Add and fix BTreeMap comments) - rust-lang#74352 (Use local links in the alloc docs.) - rust-lang#74377 (Move libstd's default feature to libtest) - rust-lang#74381 (Update docs for str::as_bytes_mut.) Failed merges: r? @ghost
/// # Safety | ||
/// | ||
/// The caller must ensure that the content of the slice is valid UTF-8 | ||
/// before the borrow ends and the underlying `str` is used. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// before the borrow ends and the underlying `str` is used. | |
/// before the borrow ends and the underlying `str` is used again. |
/// The caller must ensure that the content of the slice is valid UTF-8 | ||
/// before the borrow ends and the underlying `str` is used. | ||
/// | ||
/// Use of a `str` whose contents are not valid UTF-8 is undefined behavior. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point we might want to be more clear about language-UB vs library-UB, but for now this wording seems fine to me.
Add "Safety" section describing UTF-8 invariant.
Remove mention of
from_utf8_mut
. It is not necessary to calla function to convert the byte slice back to a string slice. The
original string becomes accessible again after the byte slice is
no longer used (as shown in the example code).