Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. // This type derives `Copy`.
  2. #[derive(Clone, Copy, Debug, PartialEq)]
  3. struct Ptr<'a, T> {
  4. pointer: &'a T
  5. }
  6.  
  7. // This type does not implement `Copy`.
  8. #[derive(PartialEq, Eq)]
  9. struct S {}
  10.  
  11. // This struct derives `Copy`, and compiles ok.
  12. #[derive(Clone, Copy, PartialEq)]
  13. struct Foo1 {
  14. x: i32,
  15. y: &'static S,
  16. }
  17.  
  18. // This struct derives `Copy`, but causes the following error:
  19. //
  20. // error[E0204]: the trait `Copy` may not be implemented for this type
  21. // --> c.rs:18:17
  22. // |
  23. // 18 | #[derive(Clone, Copy, PartialEq)]
  24. // | ^^^^
  25. // ...
  26. // 21 | z: Ptr<'static, S>,
  27. // | ------------------ this field does not implement `Copy`
  28. //
  29. #[derive(Clone, Copy, PartialEq)]
  30. struct Foo2 {
  31. x: i32,
  32. z: Ptr<'static, S>,
  33. }
  34.  
  35. static Y: S = S {};
  36.  
  37. fn main() {
  38. let foo1a = Foo1 { x: 0, y: &Y };
  39. let foo1b = foo1a;
  40. eprintln!("{}", foo1a == foo1b);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement