Skip to content

clone_from behaviour for ManuallyDrop #86288

Closed
@m-ou-se

Description

@m-ou-se

With #[derive(Clone)] on ManuallyDrop<T>, x.clone_from(&y) will not drop the T inside x, just like x = y.clone(); does not drop the original x before overwriting it.

However, a manual implementation of clone_from can only make use of the efficiency of a overriden clone_from on T (e.g. memory reuse by a Vec::clone_from) by simply forwarding to it, which means that x.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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions