-
-
Notifications
You must be signed in to change notification settings - Fork 16k
String::as_mut_ptr is invalidated in unexected ways #158166
Copy link
Copy link
Open
Labels
A-collectionsArea: `std::collections`Area: `std::collections`A-raw-pointersArea: raw pointers, MaybeUninit, NonNullArea: raw pointers, MaybeUninit, NonNullA-strArea: str and StringArea: str and StringC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-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.T-opsemRelevant to the opsem teamRelevant to the opsem team
Description
Activity
Metadata
Metadata
Assignees
Labels
A-collectionsArea: `std::collections`Area: `std::collections`A-raw-pointersArea: raw pointers, MaybeUninit, NonNullArea: raw pointers, MaybeUninit, NonNullA-strArea: str and StringArea: str and StringC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.T-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.T-opsemRelevant to the opsem teamRelevant to the opsem team
This code has UB under both Stacked and Tree Borrows:
The corresponding code with
Vecis fine, becauseVec::as_mut_ptravoids invalidating previously created raw pointers to the vec's contents.String::as_mut_ptrdoes not exist, the code above relies onDerefMut for Stringandstr::as_mut_ptr, which creates some extra references that cause unexpected invalidation.Cc @rust-lang/libs-api -- would you be open to the idea of having
as_mut_ptronStringas well?Also see #97483, #106593