]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/dst-coerce-rc.rs
67dd4021cb5c8dd65ae347ec635c2858c4bbc6a6
[rustc.git] / src / test / run-pass / dst-coerce-rc.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
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
11 // Test a very simple custom DST coercion.
12
13 #![feature(core)]
14
15 use std::cell::RefCell;
16 use std::rc::Rc;
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 }
27
28 fn main() {
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);
38
39 let _c = b.clone();
40
41 let a: Rc<RefCell<i32>> = Rc::new(RefCell::new(42));
42 let b: Rc<RefCell<Baz>> = a.clone();
43 assert_eq!(b.borrow().get(), 42);
44 }