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, core)]
35 fn foo(&self) -> usize;
43 fn foo(&self) -> usize {
61 let _ = mem::size_of::<Box<Foo<u8>>>();
62 let _ = mem::size_of::<Box<Bar>>();
63 let _ = mem::size_of::<Box<Baz>>();
70 let data: Box<Foo_<i32>> = box Foo_{f: [1, 2, 3] };
71 let x: &Foo<i32> = mem::transmute(slice::from_raw_parts(&*data, 3));
72 assert!(x.f.len() == 3);
80 let data: Box<_> = box Baz_ {
81 f1: 42, f2: ['a' as u8, 'b' as u8, 'c' as u8, 'd' as u8, 'e' as u8] };
82 let x: &Baz = mem::transmute(slice::from_raw_parts(&*data, 5));
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<_> = 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);