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.
13 struct Fat<T: ?Sized> {
18 fn foo(x: &Fat<[int]>) {
20 assert!(x.ptr.len() == 3);
22 assert!(x.ptr[1] == 2);
25 fn foo2<T:ToBar>(x: &Fat<[T]>) {
28 assert!(x.ptr.len() == 3);
29 assert!(y[0].to_bar() == bar);
30 assert!(x.ptr[1].to_bar() == bar);
33 #[derive(Copy, PartialEq, Eq)]
37 fn to_bar(&self) -> Bar;
41 fn to_bar(&self) -> Bar {
47 // With a vec of ints.
48 let f1 = Fat { ptr: [1, 2, 3] };
52 let f3: &Fat<[int]> = f2;
54 let f4: &Fat<[int]> = &f1;
56 let f5: &Fat<[int]> = &Fat { ptr: [1, 2, 3] };
59 // With a vec of Bars.
61 let f1 = Fat { ptr: [bar, bar, bar] };
65 let f3: &Fat<[Bar]> = f2;
67 let f4: &Fat<[Bar]> = &f1;
69 let f5: &Fat<[Bar]> = &Fat { ptr: [bar, bar, bar] };
73 let f5: &mut Fat<[int]> = &mut Fat { ptr: [1, 2, 3] };
75 assert!(f5.ptr[0] == 1);
76 assert!(f5.ptr[1] == 34);
77 assert!(f5.ptr[2] == 3);
80 let f5: &Fat<[int]> = &Fat { ptr: [] };
81 assert!(f5.ptr.len() == 0);
82 let f5: &Fat<[Bar]> = &Fat { ptr: [] };
83 assert!(f5.ptr.len() == 0);