-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
Remove internal PathBuf::as_mut_vec #126333
Copy link
Copy link
Closed
Labels
C-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: PRs that clean code up or issues documenting cleanup.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call 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.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.O-windowsOperating system: WindowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
C-cleanupCategory: PRs that clean code up or issues documenting cleanup.Category: PRs that clean code up or issues documenting cleanup.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call 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.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.O-windowsOperating system: WindowsOperating system: WindowsT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
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 updatesis_known_utf8as a result. Their implementation would be trivial on other platforms.