-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Documentation for mem::forget implies that it may invalidate raw pointers to heap allocations #79320
Comments
Would like to work on this! ✋ @rustbot claim |
So what can we say for sure? Maybe, based on @fleabitdev's comment: "Heap allocations owned by a value passed to Perhaps simply adding the sentence above would help? ("Heap allocations owned by a value passed to |
Thoughts, @jyn514? Just trying to wrap my head around this. |
@pierwill sorry, I don't even understand why the original example is incorrect, I can't guess why the third example is sound. |
When a value is passed to It's an important property of |
cc @rust-lang/lang @rust-lang/libs |
@rustbot release-assignment |
I think this is best handled by delegating to the unsafe-code-guidelines WG. (That is, I think any of the footguns and issues discussed arised solely in the context of unsafe code. All sound code should continue to be sound.) Filed rust-lang/unsafe-code-guidelines#320 and closing this. |
The doc comment for
mem::forget
currently reads:The second sentence was introduced in #53503, with this rationale:
In other words, it's intended to be a warning about these two footguns:
To me, the current language is too broad. It implies that heap allocations owned by a value passed to
mem::forget
may be invalidated. For example, it implies that the following code is unsound:Opening an issue rather than a PR because I'm not sure how best to rephrase this.
The text was updated successfully, but these errors were encountered: