Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Expand
CloneToUninit
documentation. #133055Expand
CloneToUninit
documentation. #133055Changes from 1 commit
769425a
2cc999d
96814ae
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think assignment assumes initialized memory for Copy types, and Miri is fine with it: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2024&gist=2d5d4affa1262eff4a7c5d1a2a7fd14b
The unsound operation is dropping the memory behind the pointer, but for Copy types that doesn't happen.
I'd probably still write it this way, but I don't think we should write something misleading in the comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to write a good comment, and was unhappy with all the versions I came up with without also changing the code. I ended up changing the code to
.clone_to_uninit()
theflag
too, because it's easier to justify as “most general”. Not sure that makes sense.— actually, it doesn't make sense, because the easiest way to ensure the desirable no-memory-leaks property would be to strictly use
.clone()
on all the sized fields first (so the values are held in drop-tracked locals), then clone the uninit field. And then I don't have to hedge anything about leaking. Please wait while I rewrite again…There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've now rewritten the example so that
Copy
, andand there is one straightforward correct way to do that, so we no longer have any reason to talk about the other options. What do you think?