Update docs for str::as_bytes_mut.#74381
Merged
bors merged 1 commit intorust-lang:masterfrom Jul 16, 2020
Merged
Conversation
Contributor
|
(rust_highfive has picked a reviewer for you, use r? to override) |
src/libcore/str/mod.rs
Outdated
Member
Contributor
Author
There was a problem hiding this comment.
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).
Member
|
@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. |
Collaborator
|
📌 Commit 6da69ec has been approved by |
Manishearth
added a commit
to Manishearth/rust
that referenced
this pull request
Jul 16, 2020
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).
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Jul 16, 2020
…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
RalfJung
reviewed
Jul 16, 2020
| /// # 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. |
Member
There was a problem hiding this comment.
Suggested change
| /// before the borrow ends and the underlying `str` is used. | |
| /// before the borrow ends and the underlying `str` is used again. |
RalfJung
reviewed
Jul 16, 2020
| /// 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. |
Member
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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).