Skip to content

Remove internal PathBuf::as_mut_vec  #126333

Description

@workingjubilee

This function allows breaking the invariants of the OsString that PathBuf wraps, which, combined with the optimizations introduced in #96869 which bypassed the "scan the entire string" check, led to #126291 as a result. That was fixed in #126305 but the "fix" was the brutal hack of "simply remove the opt every time".

It has been there for a long time because it lends PathBuf, in general, a simpler implementation, and works fine for strings-are-byte-strings platforms.

We can afford to "complicate" things a little in order to actually preserve our invariants. A likely approach would be to remove PathBuf::as_mut_vec, and add a set of new fn to the Wtf8Buf / Buf / OsString types that directly implement the desired behaviors (e.g. truncating to a byte len), so that each such fn correctly updates is_known_utf8 as a result. Their implementation would be trivial on other platforms.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

C-cleanupCategory: PRs that clean code up or issues documenting cleanup.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.O-windowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions