-
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
clone_from behaviour for ManuallyDrop #86288
Comments
I feel that the old behavior is correct (not calling drop). I don't think there is much loss of efficiency in practice: use of |
Sounds good. Closing this. |
No wait, we still need to do this part. :) |
…m, r=Mark-Simulacrum Test ManuallyDrop::clone_from. See rust-lang#86288
With
#[derive(Clone)]
onManuallyDrop<T>
,x.clone_from(&y)
will not drop theT
insidex
, just likex = y.clone();
does not drop the originalx
before overwriting it.However, a manual implementation of
clone_from
can only make use of the efficiency of a overridenclone_from
onT
(e.g. memory reuse by aVec::clone_from
) by simply forwarding to it, which means thatx.clone_from(&y)
will not forget the old value.This new (forwarding, so (potentially) dropping) behaviour was added in #85176, and (for now) reverted in #85758.
So question for @rust-lang/libs: What behaviour would be correct? There are arguments for both. Whatever the decision, we should document it and add a test for it.
The text was updated successfully, but these errors were encountered: