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.
11 // As dst-struct.rs, but the unsized field is the only field in the struct.
14 struct Fat<T: ?Sized> {
19 fn foo(x: &Fat<[isize]>) {
21 assert_eq!(x.ptr.len(), 3);
23 assert_eq!(x.ptr[1], 2);
26 fn foo2<T:ToBar>(x: &Fat<[T]>) {
29 assert_eq!(x.ptr.len(), 3);
30 assert_eq!(y[0].to_bar(), bar);
31 assert_eq!(x.ptr[1].to_bar(), bar);
34 #[derive(Copy, Clone, PartialEq, Eq, Debug)]
38 fn to_bar(&self) -> Bar;
42 fn to_bar(&self) -> Bar {
48 // With a vec of ints.
49 let f1 = Fat { ptr: [1, 2, 3] };
53 let f3: &Fat<[isize]> = f2;
55 let f4: &Fat<[isize]> = &f1;
57 let f5: &Fat<[isize]> = &Fat { ptr: [1, 2, 3] };
60 // With a vec of Bars.
62 let f1 = Fat { ptr: [bar, bar, bar] };
66 let f3: &Fat<[Bar]> = f2;
68 let f4: &Fat<[Bar]> = &f1;
70 let f5: &Fat<[Bar]> = &Fat { ptr: [bar, bar, bar] };
74 let f5: &mut Fat<[isize]> = &mut Fat { ptr: [1, 2, 3] };
76 assert_eq!(f5.ptr[0], 1);
77 assert_eq!(f5.ptr[1], 34);
78 assert_eq!(f5.ptr[2], 3);
81 let f5: &Fat<[isize]> = &Fat { ptr: [] };
82 assert!(f5.ptr.is_empty());
83 let f5: &Fat<[Bar]> = &Fat { ptr: [] };
84 assert!(f5.ptr.is_empty());