1 // Copyright 2014 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.
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.
12 #![allow(unknown_features)]
13 #![feature(box_syntax)]
15 struct Fat<T: ?Sized> {
22 fn foo(x: &Fat<[isize]>) {
24 assert_eq!(x.ptr.len(), 3);
26 assert_eq!(x.ptr[1], 2);
28 assert_eq!(x.f2, "some str");
31 fn foo2<T:ToBar>(x: &Fat<[T]>) {
34 assert_eq!(x.ptr.len(), 3);
35 assert_eq!(y[0].to_bar(), bar);
36 assert_eq!(x.ptr[1].to_bar(), bar);
38 assert_eq!(x.f2, "some str");
41 fn foo3(x: &Fat<Fat<[isize]>>) {
44 assert_eq!(x.f2, "some str");
45 assert_eq!(x.ptr.f1, 8);
46 assert_eq!(x.ptr.f2, "deep str");
47 assert_eq!(x.ptr.ptr.len(), 3);
49 assert_eq!(x.ptr.ptr[1], 2);
53 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
57 fn to_bar(&self) -> Bar;
61 fn to_bar(&self) -> Bar {
67 // With a vec of ints.
68 let f1 = Fat { f1: 5, f2: "some str", ptr: [1, 2, 3] };
72 let f3: &Fat<[isize]> = f2;
74 let f4: &Fat<[isize]> = &f1;
76 let f5: &Fat<[isize]> = &Fat { f1: 5, f2: "some str", ptr: [1, 2, 3] };
79 // With a vec of Bars.
81 let f1 = Fat { f1: 5, f2: "some str", ptr: [bar, bar, bar] };
85 let f3: &Fat<[Bar]> = f2;
87 let f4: &Fat<[Bar]> = &f1;
89 let f5: &Fat<[Bar]> = &Fat { f1: 5, f2: "some str", ptr: [bar, bar, bar] };
93 let f5: &mut Fat<[isize]> = &mut Fat { f1: 5, f2: "some str", ptr: [1, 2, 3] };
95 assert_eq!(f5.ptr[0], 1);
96 assert_eq!(f5.ptr[1], 34);
97 assert_eq!(f5.ptr[2], 3);
100 let f5: &Fat<[isize]> = &Fat { f1: 5, f2: "some str", ptr: [] };
101 assert!(f5.ptr.is_empty());
102 let f5: &Fat<[Bar]> = &Fat { f1: 5, f2: "some str", ptr: [] };
103 assert!(f5.ptr.is_empty());
106 let f1 = Fat { f1: 5, f2: "some str", ptr: Fat { f1: 8, f2: "deep str", ptr: [1, 2, 3]} };
110 let f3: &Fat<Fat<[isize]>> = f2;
112 let f4: &Fat<Fat<[isize]>> = &f1;
114 let f5: &Fat<Fat<[isize]>> =
115 &Fat { f1: 5, f2: "some str", ptr: Fat { f1: 8, f2: "deep str", ptr: [1, 2, 3]} };
119 let f1 = Box::new([1, 2, 3]);
120 assert_eq!((*f1)[1], 2);
121 let f2: Box<[isize]> = f1;
122 assert_eq!((*f2)[1], 2);
125 let f1 : Box<Fat<[isize; 3]>> = box Fat { f1: 5, f2: "some str", ptr: [1, 2, 3] };
127 let f2 : Box<Fat<[isize]>> = f1;
130 let f3 : Box<Fat<[isize]>> =
131 Box::<Fat<[_; 3]>>::new(Fat { f1: 5, f2: "some str", ptr: [1, 2, 3] });