Advertisement
Guest User

Untitled

a guest
Jan 29th, 2015
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. #![feature(unsafe_destructor)]
  2.  
  3. use std::cell::Cell;
  4.  
  5. #[derive(Show)]
  6. struct C<'a> {
  7. f: Cell<Option<&'a C<'a>>>,
  8. g: Cell<Option<&'a C<'a>>>,
  9. }
  10.  
  11. impl<'a> C<'a> {
  12. fn new() -> C<'a> {
  13. C { f: Cell::new(None), g: Cell::new(None) }
  14. }
  15. }
  16.  
  17. #[unsafe_destructor]
  18. // force dropck to care about C<'a>
  19. impl<'a> Drop for C<'a> {
  20. fn drop(&mut self) { }
  21. }
  22.  
  23. fn f() {
  24. let c2;
  25. let mut c1;
  26.  
  27. c1 = C::new();
  28. c2 = C::new();
  29.  
  30. c1.f.set(Some(&c2));
  31. }
  32.  
  33. fn main() {
  34. f();
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement