Skip to content

Avoid redundant WTF-8 checks in PathBuf #140159

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

thaliaarchi
Copy link
Contributor

Eliminate checks for WTF-8 boundaries in PathBuf::set_extension and add_extension, where joining WTF-8 surrogate halves is impossible. Don't convert the str to OsStr, because OsString::push specializes to skip the joining when given strings.

To assist in this, mark the internal methods OsString::truncate and extend_from_slice as unsafe to communicate their safety invariants better than with module privacy.

Similar to #137777.

cc @joboet @ChrisDenton

Communicate the safety invariants of these methods with `unsafe fn`
rather than privacy.
Eliminate checks for WTF-8 boundaries in `PathBuf::set_extension` and
`add_extension`, where joining WTF-8 surrogate halves is impossible.
Don't convert the `str` to `OsStr`, because `OsString::push` specializes
to skip the joining when given strings.
@rustbot
Copy link
Collaborator

rustbot commented Apr 22, 2025

r? @workingjubilee

rustbot has assigned @workingjubilee.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants