]>
Commit | Line | Data |
---|---|---|
1a4d82fc | 1 | // Copyright 2015 The Rust Project Developers. See the COPYRIGHT |
223e47cc LB |
2 | // file at the top-level directory of this distribution and at |
3 | // http://rust-lang.org/COPYRIGHT. | |
4 | // | |
5 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
6 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
7 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
8 | // option. This file may not be copied, modified, or distributed | |
9 | // except according to those terms. | |
10 | ||
d9579d0f AL |
11 | // Test a very simple custom DST coercion. |
12 | ||
c1a9b12d | 13 | #![feature(core, rc_weak)] |
d9579d0f | 14 | |
62682a34 | 15 | use std::cell::RefCell; |
c1a9b12d | 16 | use std::rc::{Rc, Weak}; |
d9579d0f AL |
17 | |
18 | trait Baz { | |
19 | fn get(&self) -> i32; | |
20 | } | |
21 | ||
22 | impl Baz for i32 { | |
23 | fn get(&self) -> i32 { | |
24 | *self | |
25 | } | |
26 | } | |
85aaf69f | 27 | |
c34b1796 | 28 | fn main() { |
d9579d0f AL |
29 | let a: Rc<[i32; 3]> = Rc::new([1, 2, 3]); |
30 | let b: Rc<[i32]> = a; | |
31 | assert_eq!(b[0], 1); | |
32 | assert_eq!(b[1], 2); | |
33 | assert_eq!(b[2], 3); | |
34 | ||
35 | let a: Rc<i32> = Rc::new(42); | |
36 | let b: Rc<Baz> = a.clone(); | |
37 | assert_eq!(b.get(), 42); | |
223e47cc | 38 | |
c1a9b12d SL |
39 | let c: Weak<i32> = a.downgrade(); |
40 | let d: Weak<Baz> = c.clone(); | |
41 | ||
d9579d0f | 42 | let _c = b.clone(); |
62682a34 SL |
43 | |
44 | let a: Rc<RefCell<i32>> = Rc::new(RefCell::new(42)); | |
45 | let b: Rc<RefCell<Baz>> = a.clone(); | |
46 | assert_eq!(b.borrow().get(), 42); | |
c1a9b12d | 47 | let c: Weak<RefCell<Baz>> = a.downgrade(); |
c34b1796 | 48 | } |