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)]
14 #![feature(unsized_tuple_coercion)]
16 type Fat<T: ?Sized> = (isize, &'static str, T);
19 fn foo(x: &Fat<[isize]>) {
21 assert_eq!(x.2.len(), 3);
23 assert_eq!(x.2[1], 2);
25 assert_eq!(x.1, "some str");
28 fn foo2<T:ToBar>(x: &Fat<[T]>) {
31 assert_eq!(x.2.len(), 3);
32 assert_eq!(y[0].to_bar(), bar);
33 assert_eq!(x.2[1].to_bar(), bar);
35 assert_eq!(x.1, "some str");
38 fn foo3(x: &Fat<Fat<[isize]>>) {
41 assert_eq!(x.1, "some str");
42 assert_eq!((x.2).0, 8);
43 assert_eq!((x.2).1, "deep str");
44 assert_eq!((x.2).2.len(), 3);
46 assert_eq!((x.2).2[1], 2);
50 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
54 fn to_bar(&self) -> Bar;
58 fn to_bar(&self) -> Bar {
64 // With a vec of ints.
65 let f1 = (5, "some str", [1, 2, 3]);
69 let f3: &Fat<[isize]> = f2;
71 let f4: &Fat<[isize]> = &f1;
73 let f5: &Fat<[isize]> = &(5, "some str", [1, 2, 3]);
76 // With a vec of Bars.
78 let f1 = (5, "some str", [bar, bar, bar]);
82 let f3: &Fat<[Bar]> = f2;
84 let f4: &Fat<[Bar]> = &f1;
86 let f5: &Fat<[Bar]> = &(5, "some str", [bar, bar, bar]);
90 let f5: &mut Fat<[isize]> = &mut (5, "some str", [1, 2, 3]);
92 assert_eq!(f5.2[0], 1);
93 assert_eq!(f5.2[1], 34);
94 assert_eq!(f5.2[2], 3);
97 let f5: &Fat<[isize]> = &(5, "some str", []);
98 assert!(f5.2.is_empty());
99 let f5: &Fat<[Bar]> = &(5, "some str", []);
100 assert!(f5.2.is_empty());
103 let f1 = (5, "some str", (8, "deep str", [1, 2, 3]));
107 let f3: &Fat<Fat<[isize]>> = f2;
109 let f4: &Fat<Fat<[isize]>> = &f1;
111 let f5: &Fat<Fat<[isize]>> = &(5, "some str", (8, "deep str", [1, 2, 3]));
115 let f1 = Box::new([1, 2, 3]);
116 assert_eq!((*f1)[1], 2);
117 let f2: Box<[isize]> = f1;
118 assert_eq!((*f2)[1], 2);
121 let f1 : Box<Fat<[isize; 3]>> = box (5, "some str", [1, 2, 3]);
123 let f2 : Box<Fat<[isize]>> = f1;
126 let f3 : Box<Fat<[isize]>> =
127 Box::<Fat<[_; 3]>>::new((5, "some str", [1, 2, 3]));