-
- Notifications
You must be signed in to change notification settings - Fork 14.2k
Generalize impl<T> Clone for Box<T> to unsized types #146381
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
base: main
Are you sure you want to change the base?
Conversation
| rustbot has assigned @workingjubilee. Use |
This comment has been minimized.
This comment has been minimized.
| r? library |
| Failed to set assignee to
|
| r? libs |
This comment has been minimized.
This comment has been minimized.
| /// | ||
| /// # Safety | ||
| /// | ||
| /// `dest` must be a valid pointer to a valid value of the same concrete type than `self`. |
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.
Given that trait vtable pointers can be deduplicated, I'm not sure if "the same concrete type" is what we want to require here. cc #146381 (comment) . I.e. it's not possible in general to verify for certain that two dyn Trait pointers with the same metadata actually point to the same erased/concrete type.
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.
This seems similar to the issue with Rc::get_mut_unchecked, where either:
- if any other pointers exist to this value, we must only write a value that is valid for all those pointers' types/metadatas.
- if there are no other pointers to this value, we can write anything that is valid for this pointer's type/metadata.
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 think this is the right thing. It be not be possible in general, but it is in some cases (eg with TypeId). Another formulation would be that it is safe to create a mutable reference from dest.with_metadata_of(self).
| As CI is failing, @rustbot author |
| Reminder, once the PR becomes ready for a review, use |
f32cd66 to bdc70ea Compare This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
bdc70ea to 32deea5 Compare This comment has been minimized.
This comment has been minimized.
32deea5 to 6f53c47 Compare | This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
This comment has been minimized.
This comment has been minimized.
6f53c47 to 9cc7f3f Compare This comment has been minimized.
This comment has been minimized.
This new module contains a type that is like an uninitialized `Box`, but works with any type, not just `Sized` ones. Additionally, this will be useful for future work on in-place initialization (see rust-lang#142518).
This is necessary to properly support `Clone::clone_from`.
9cc7f3f to 84c014a Compare 84c014a to 9331815 Compare | @rustbot ready |
| I forgot I was assigned to this and apparently missed that it was ready for review. I'm busy at the moment, so passing off. r? libs |
Part of #142518
I had to add a non-default method to
CloneToUninitfor this to work, but I think this is fine. (I did not do the renaming toCloneUnsizedas suggested in #126799 (comment), as this is quite orthogonal)This also adds some infrastructure that will be helpful for in-place initialization.
Commits can be reviewed independently.