-
Notifications
You must be signed in to change notification settings - Fork 13.3k
std::ptr::write
docs don't mention that src
is leaked
#39733
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
The initial value of dst wasn't dropped - that would print |
@sfackler Yes, and I said as much. That's not the problem. The problem is that although the docs mention that |
|
What I'm saying is that I opened this issue because someone in #rust-beginners was confused about this. They weren't sure whether it was safe to write a |
I agree with @sfackler that it doesn't make sense to describe this as a "leak" because the value that gets moved from |
Yes, that would work. Right now the docs don't make it clear enough that |
Clarify handling of `src` in `ptr::write` Fixes rust-lang#39733.
Clarify handling of `src` in `ptr::write` Fixes rust-lang#39733.
Clarify handling of `src` in `ptr::write` Fixes rust-lang#39733.
EDIT: To summarize it a bit better, since it seems like I worded things a bit unclearly:
src
's destructor doesn't get run when it's passed by-value toptr::write
, but the docs don't really make this clear. It would be better to clarify this, especially given it's an unsafe function.This code prints:
demonstrating that the original value stored in
dst
, and the value passed tostd::ptr::write
, were not dropped; onlydst
was dropped after theprintln!
line.However, the docs for
std::ptr::write
only mention that the former isn't dropped, saying nothing about the latter.The text was updated successfully, but these errors were encountered: