]> git.lizzy.rs Git - rust.git/blob - src/test/ui/overloaded/overloaded-autoderef.rs
Pin panic-in-drop=abort test to old pass manager
[rust.git] / src / test / ui / overloaded / overloaded-autoderef.rs
1 // run-pass
2 #![allow(unused_variables)]
3 #![allow(stable_features)]
4
5 #![feature(box_syntax, core)]
6
7 use std::cell::RefCell;
8 use std::rc::Rc;
9
10 #[derive(PartialEq, Debug)]
11 struct Point {
12     x: isize,
13     y: isize
14 }
15
16 pub fn main() {
17     let box_5: Box<_> = box 5_usize;
18     let point = Rc::new(Point {x: 2, y: 4});
19     assert_eq!(point.x, 2);
20     assert_eq!(point.y, 4);
21
22     let i = Rc::new(RefCell::new(2));
23     let i_value = *i.borrow();
24     *i.borrow_mut() = 5;
25     assert_eq!((i_value, *i.borrow()), (2, 5));
26
27     let s = Rc::new("foo".to_string());
28     assert_eq!(&**s, "foo");
29
30     let mut_s = Rc::new(RefCell::new(String::from("foo")));
31     mut_s.borrow_mut().push_str("bar");
32     // HACK assert_eq! would panic here because it stores the LHS and RHS in two locals.
33     assert_eq!(&**mut_s.borrow(), "foobar");
34     assert_eq!(&**mut_s.borrow_mut(), "foobar");
35
36     let p = Rc::new(RefCell::new(Point {x: 1, y: 2}));
37     p.borrow_mut().x = 3;
38     p.borrow_mut().y += 3;
39     assert_eq!(*p.borrow(), Point {x: 3, y: 5});
40
41     let v = Rc::new(RefCell::new([1, 2, 3]));
42     v.borrow_mut()[0] = 3;
43     v.borrow_mut()[1] += 3;
44     assert_eq!((v.borrow()[0], v.borrow()[1], v.borrow()[2]), (3, 5, 3));
45 }