-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
MaybeUninit<T> could be Copy for all T #62835
Comments
I do agree it sounds safe, but perhaps the lack of this serves as a useful lint. E.g. somebody could do this: let place = MaybeUninit::<Vec<()>>::uninit();
place.write(vec![]);
// because they're calling "clone", user might think this is safe;
// but in reality, the same vec is read twice.
let vec_1 = unsafe { place.clone().assume_init() };
let vec_2 = unsafe { place.clone().assume_init() }; |
True, but then we probably need another way to make a non-Copy type Copy. |
The example above could be reproduced even without
@Diggsey what’s your use-case that’s not served by the APIs currently available? |
It came up whilst I was looking at ways to get
But there is no escape hatch for making non-Copy data Copy. |
There was talk about an |
Maybe there could be an explicit method to copy
|
@cuviper you mean something like this? EDIT: Ah, no you meant it should return a |
It wouldn't literally be |
Yeah, the issue is not with actually being able to do a |
Ran into this today when I tried to use |
At the moment it only implements
Copy
whenT: Copy
, but there's no memory-safety reason for it not to always beCopy
.The text was updated successfully, but these errors were encountered: