box.rs 650 B

12345678910111213141516171819202122232425262728293031323334
  1. extern crate ralloc;
  2. #[global_allocator]
  3. static ALLOCATOR: ralloc::Allocator = ralloc::Allocator;
  4. mod util;
  5. #[inline(never)]
  6. fn alloc_box() -> Box<u32> {
  7. Box::new(0xDEADBEAF)
  8. }
  9. #[test]
  10. fn simple_box() {
  11. util::multiply(|| {
  12. let mut a = Box::new(1);
  13. let mut b = Box::new(2);
  14. let mut c = Box::new(3);
  15. assert_eq!(*a, 1);
  16. assert_eq!(*b, 2);
  17. assert_eq!(*c, 3);
  18. assert_eq!(*alloc_box(), 0xDEADBEAF);
  19. util::acid(|| {
  20. *a = 0;
  21. *b = 0;
  22. *c = 0;
  23. });
  24. assert_eq!(*a, 0);
  25. assert_eq!(*b, 0);
  26. assert_eq!(*c, 0);
  27. });
  28. }