]> git.lizzy.rs Git - rust.git/blob - tests/run-pass/std.rs
1d4dc8befef8c6e73455f872514e29a948015330
[rust.git] / tests / run-pass / std.rs
1 #![feature(custom_attribute, box_syntax)]
2 #![allow(dead_code, unused_attributes)]
3
4 use std::cell::{Cell, RefCell};
5 use std::rc::Rc;
6 use std::sync::Arc;
7
8 #[miri_run]
9 fn rc_cell() -> Rc<Cell<i32>> {
10     let r = Rc::new(Cell::new(42));
11     let x = r.get();
12     r.set(x + x);
13     r
14 }
15
16 // TODO(tsion): borrow code needs to evaluate string statics via Lvalue::Static
17 // TODO(tsion): also requires destructors to run for the second borrow to work
18 // #[miri_run]
19 // fn rc_refcell() -> i32 {
20 //     let r = Rc::new(RefCell::new(42));
21 //     *r.borrow_mut() += 10;
22 //     let x = *r.borrow();
23 //     x
24 // }
25
26 #[miri_run]
27 fn arc() -> Arc<i32> {
28     let a = Arc::new(42);
29     a
30 }
31
32 struct Loop(Rc<RefCell<Option<Loop>>>);
33
34 #[miri_run]
35 fn rc_reference_cycle() -> Loop {
36     let a = Rc::new(RefCell::new(None));
37     let b = a.clone();
38     *a.borrow_mut() = Some(Loop(b));
39     Loop(a)
40 }
41
42 #[miri_run]
43 fn true_assert() {
44     assert_eq!(1, 1);
45 }
46
47 #[miri_run]
48 fn main() {
49     //let x = rc_reference_cycle().0;
50     //assert!(x.borrow().is_some());
51     assert_eq!(*arc(), 42);
52     assert_eq!(rc_cell().get(), 84);
53 }