rust/tests/run-pass/std.rs

37 lines
680 B
Rust
Raw Normal View History

// FIXME: Due to https://github.com/rust-lang/rust/issues/43457 we have to disable validation
// compile-flags: -Zmir-emit-validate=0
2016-12-17 03:58:03 -06:00
use std::cell::{Cell, RefCell};
2016-04-06 05:20:35 -05:00
use std::rc::Rc;
use std::sync::Arc;
fn rc_cell() -> Rc<Cell<i32>> {
2016-03-21 05:18:30 -05:00
let r = Rc::new(Cell::new(42));
let x = r.get();
r.set(x + x);
2016-04-06 05:20:35 -05:00
r
2016-03-21 05:18:30 -05:00
}
2016-12-17 03:58:03 -06:00
fn rc_refcell() -> i32 {
let r = Rc::new(RefCell::new(42));
*r.borrow_mut() += 10;
let x = *r.borrow();
x
}
2016-03-21 19:53:39 -05:00
2016-04-06 05:20:35 -05:00
fn arc() -> Arc<i32> {
2016-03-21 05:18:30 -05:00
let a = Arc::new(42);
2016-04-06 05:20:35 -05:00
a
}
2016-03-21 05:37:28 -05:00
fn true_assert() {
assert_eq!(1, 1);
}
2016-04-22 03:34:14 -05:00
2016-04-22 07:38:46 -05:00
fn main() {
assert_eq!(*arc(), 42);
assert_eq!(rc_cell().get(), 84);
2016-12-17 03:58:03 -06:00
assert_eq!(rc_refcell(), 52);
true_assert();
2016-04-22 07:38:46 -05:00
}