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 #![feature(box_syntax)]
13 #![feature(unsized_tuple_coercion)]
15 type Fat<T: ?Sized> = (isize, &'static str, T);
18 fn foo(x: &Fat<[isize]>) {
20 assert_eq!(x.2.len(), 3);
22 assert_eq!(x.2[1], 2);
24 assert_eq!(x.1, "some str");
27 fn foo2<T:ToBar>(x: &Fat<[T]>) {
30 assert_eq!(x.2.len(), 3);
31 assert_eq!(y[0].to_bar(), bar);
32 assert_eq!(x.2[1].to_bar(), bar);
34 assert_eq!(x.1, "some str");
37 fn foo3(x: &Fat<Fat<[isize]>>) {
40 assert_eq!(x.1, "some str");
41 assert_eq!((x.2).0, 8);
42 assert_eq!((x.2).1, "deep str");
43 assert_eq!((x.2).2.len(), 3);
45 assert_eq!((x.2).2[1], 2);
49 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
53 fn to_bar(&self) -> Bar;
57 fn to_bar(&self) -> Bar {
63 // With a vec of ints.
64 let f1 = (5, "some str", [1, 2, 3]);
68 let f3: &Fat<[isize]> = f2;
70 let f4: &Fat<[isize]> = &f1;
72 let f5: &Fat<[isize]> = &(5, "some str", [1, 2, 3]);
75 // With a vec of Bars.
77 let f1 = (5, "some str", [bar, bar, bar]);
81 let f3: &Fat<[Bar]> = f2;
83 let f4: &Fat<[Bar]> = &f1;
85 let f5: &Fat<[Bar]> = &(5, "some str", [bar, bar, bar]);
89 let f5: &mut Fat<[isize]> = &mut (5, "some str", [1, 2, 3]);
91 assert_eq!(f5.2[0], 1);
92 assert_eq!(f5.2[1], 34);
93 assert_eq!(f5.2[2], 3);
96 let f5: &Fat<[isize]> = &(5, "some str", []);
97 assert!(f5.2.is_empty());
98 let f5: &Fat<[Bar]> = &(5, "some str", []);
99 assert!(f5.2.is_empty());
102 let f1 = (5, "some str", (8, "deep str", [1, 2, 3]));
106 let f3: &Fat<Fat<[isize]>> = f2;
108 let f4: &Fat<Fat<[isize]>> = &f1;
110 let f5: &Fat<Fat<[isize]>> = &(5, "some str", (8, "deep str", [1, 2, 3]));
114 let f1 = Box::new([1, 2, 3]);
115 assert_eq!((*f1)[1], 2);
116 let f2: Box<[isize]> = f1;
117 assert_eq!((*f2)[1], 2);
120 let f1 : Box<Fat<[isize; 3]>> = box (5, "some str", [1, 2, 3]);
122 let f2 : Box<Fat<[isize]>> = f1;
125 let f3 : Box<Fat<[isize]>> =
126 Box::<Fat<[_; 3]>>::new((5, "some str", [1, 2, 3]));