Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This type derives `Copy`.
- #[derive(Clone, Copy, Debug, PartialEq)]
- struct Ptr<'a, T> {
- pointer: &'a T
- }
- // This type does not implement `Copy`.
- #[derive(PartialEq, Eq)]
- struct S {}
- // This struct derives `Copy`, and compiles ok.
- #[derive(Clone, Copy, PartialEq)]
- struct Foo1 {
- x: i32,
- y: &'static S,
- }
- // This struct derives `Copy`, but causes the following error:
- //
- // error[E0204]: the trait `Copy` may not be implemented for this type
- // --> c.rs:18:17
- // |
- // 18 | #[derive(Clone, Copy, PartialEq)]
- // | ^^^^
- // ...
- // 21 | z: Ptr<'static, S>,
- // | ------------------ this field does not implement `Copy`
- //
- #[derive(Clone, Copy, PartialEq)]
- struct Foo2 {
- x: i32,
- z: Ptr<'static, S>,
- }
- static Y: S = S {};
- fn main() {
- let foo1a = Foo1 { x: 0, y: &Y };
- let foo1b = foo1a;
- eprintln!("{}", foo1a == foo1b);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement