Skip to content

Deriving Clone in structs with unions inside expect type parameters to be Clone, unlike structs. #36640

@emilio

Description

@emilio

Version: rustc 1.13.0-nightly (c772948 2016-09-20)

Test case:

#![feature(untagged_unions)]

#[repr(C)]
#[derive(Copy, Clone)]
pub struct Struct<T> {
    pub inner: Union<T>,
}

#[repr(C)]
#[derive(Copy, Clone)]
pub union Union<T> {
    pub foo: *mut (),
    pub _phantom_0: ::std::marker::PhantomData<T>,
}

URL: https://is.gd/snf8Kb

Note that replacing the union for an struct works fine.

Result

error[E0277]: the trait bound `T: std::marker::Copy` is not satisfied
 --> <anon>:6:5
  |
6 |     pub inner: Union<T>,
  |     ^^^^^^^^^^^^^^^^^^^ trait `T: std::marker::Copy` not satisfied
  |
  = help: consider adding a `where T: std::marker::Copy` bound
  = note: required because of the requirements on the impl of `std::clone::Clone` for `Union<T>`
  = note: required by `std::clone::Clone::clone`

Expected

No errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions