-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Support #[derive(Copy, Clone)]
and #[derive(Clone)]
for unions with Copy
fields
#36043
Comments
I knew that hack would come back to bite us :) We can just remove it if we agree on the policy that all Clone + !Copy On Sat, Aug 27, 2016 at 12:03 PM, Vadim Petrochenkov <
|
Reproducing @petrochenkov's comment from the union PR:
Can we instead remove the parameter from
|
For unions |
(@durka pedantic |
@Stebalien oops yeah. On Sat, Aug 27, 2016 at 8:46 PM, Steven Allen [email protected]
|
|
Uh, they aren't supposed to. I added the check to the |
Improve shallow `Clone` deriving `Copy` unions now support `#[derive(Clone)]`. Less code is generated for `#[derive(Clone, Copy)]`. + Unions now support `#[derive(Eq)]`. Less code is generated for `#[derive(Eq)]`. --- Example of code reduction: ``` enum E { A { a: u8, b: u16 }, B { c: [u8; 100] }, } ``` Before: ``` fn clone(&self) -> E { match (&*self,) { (&E::A { a: ref __self_0, b: ref __self_1 },) => { ::std::clone::assert_receiver_is_clone(&(*__self_0)); ::std::clone::assert_receiver_is_clone(&(*__self_1)); *self } (&E::B { c: ref __self_0 },) => { ::std::clone::assert_receiver_is_clone(&(*__self_0)); *self } } } ``` After: ``` fn clone(&self) -> E { { let _: ::std::clone::AssertParamIsClone<u8>; let _: ::std::clone::AssertParamIsClone<u16>; let _: ::std::clone::AssertParamIsClone<[u8; 100]>; *self } } ``` All the matches are removed, bound assertions are more lightweight. `let _: Checker<CheckMe>;`, unlike `checker(&check_me);`, doesn't have to be translated by rustc_trans and then inlined by LLVM, it doesn't even exist in MIR, this means faster compilation. --- Union impls are generated like this: ``` union U { a: u8, b: u16, c: [u8; 100], } ``` ``` fn clone(&self) -> U { { let _: ::std::clone::AssertParamIsCopy<Self>; *self } } ``` Fixes rust-lang#36043 cc @durka r? @alexcrichton
This wasn't implemented in #36016 for reasons described in #36016 (comment)
cc #32836 #31414 @durka
The text was updated successfully, but these errors were encountered: