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 // Test structs with always-unsized fields.
13 #![allow(unknown_features)]
14 #![feature(box_syntax)]
34 fn foo(&self) -> uint;
42 fn foo(&self) -> uint {
60 let _ = mem::size_of::<Box<Foo<u8>>>();
61 let _ = mem::size_of::<Box<Bar>>();
62 let _ = mem::size_of::<Box<Baz>>();
69 let data = box Foo_{f: [1i32, 2, 3] };
70 let x: &Foo<i32> = mem::transmute(raw::Slice { len: 3, data: &*data });
71 assert!(x.f.len() == 3);
81 let data = box Baz_{ f1: 42, f2: ['a' as u8, 'b' as u8, 'c' as u8, 'd' as u8, 'e' as u8] };
82 let x: &Baz = mem::transmute( raw::Slice { len: 5, data: &*data } );
84 let chs: Vec<char> = x.f2.chars().collect();
85 assert!(chs.len() == 5);
86 assert!(chs[0] == 'a');
87 assert!(chs[1] == 'b');
88 assert!(chs[2] == 'c');
89 assert!(chs[3] == 'd');
90 assert!(chs[4] == 'e');
96 let obj: Box<St> = box St { f: 42 };
98 let obj: raw::TraitObject = mem::transmute(&*obj);
99 let data = box Qux_{ f: St { f: 234 } };
100 let x: &Qux = mem::transmute(raw::TraitObject { vtable: obj.vtable,
101 data: mem::transmute(&*data) });
102 assert!(x.f.foo() == 234);