Skip to content
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

special-case #[derive(Copy, Clone)] with a shallow clone #31414

Merged
merged 1 commit into from
Apr 27, 2016

Commits on Apr 26, 2016

  1. shallow Clone for #[derive(Copy,Clone)]

    Changes #[derive(Copy, Clone)] to use a faster impl of Clone when
    both derives are present, and there are no generics in the type.
    
    The faster impl is simply returning *self (which works because the
    type is also Copy). See the comments in libsyntax_ext/deriving/clone.rs
    for more details.
    
    There are a few types which are Copy but not Clone, in violation
    of the definition of Copy. These include large arrays and tuples. The
    very existence of these types is arguably a bug, but in order for this
    optimization not to change the applicability of #[derive(Copy, Clone)],
    the faster Clone impl also injects calls to a new function,
    core::clone::assert_receiver_is_clone, to verify that all members are
    actually Clone.
    
    This is not a breaking change, because pursuant to RFC 1521, any type
    that implements Copy should not do any observable work in its Clone
    impl.
    durka committed Apr 26, 2016
    Configuration menu
    Copy the full SHA
    9249e6a View commit details
    Browse the repository at this point in the history