Skip to content

Derive Copy/Clone on generic Union working incorrectly. #62427

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

Closed
rickvanprim opened this issue Jul 5, 2019 · 2 comments
Closed

Derive Copy/Clone on generic Union working incorrectly. #62427

rickvanprim opened this issue Jul 5, 2019 · 2 comments

Comments

@rickvanprim
Copy link

The following code reports an error about the value being moved:

use std::marker::PhantomData;

trait Foo {}

struct Bar {}

impl Foo for Bar {}

#[derive(Copy, Clone)]
union U<T>
where T: Foo
{
    value1: u32,
    value2: *const (),
    phantom: PhantomData<*const T>
}

fn test()
{
    let a: U<Bar> = U { value1: 5 };
    let b = a;
    let c = a;
}

While the following code works as expected:

use std::marker::PhantomData;

trait Foo {}

struct Bar {}

impl Foo for Bar {}

union U<T>
where T: Foo
{
    value1: u32,
    value2: *const (),
    phantom: PhantomData<*const T>
}

impl<T> Copy for U<T> where T: Foo {}

impl<T> Clone for U<T> where T: Foo
{
    fn clone(&self) -> Self
    {
        *self
    }
}

fn test()
{
    let a: U<Bar> = U { value1: 5 };
    let b = a;
    let c = a;
}
@ecstatic-morse
Copy link
Contributor

ecstatic-morse commented Jul 6, 2019

This seems like a duplicate of #26925?

@rickvanprim
Copy link
Author

Seems fair @ecstatic-morse . Also looking at #56008 was useful for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants