11// run-pass
22// Test structs with always-unsized fields.
33
4-
54#![ allow( warnings) ]
6- #![ feature( box_syntax, unsize, raw ) ]
5+ #![ feature( box_syntax, unsize, ptr_metadata ) ]
76
87use std:: mem;
9- use std:: raw ;
8+ use std:: ptr ;
109use std:: slice;
1110
1211struct Foo < T > {
@@ -28,7 +27,7 @@ trait Tr {
2827}
2928
3029struct St {
31- f : usize
30+ f : usize ,
3231}
3332
3433impl Tr for St {
@@ -38,7 +37,7 @@ impl Tr for St {
3837}
3938
4039struct Qux < ' a > {
41- f : Tr + ' a
40+ f : Tr + ' a ,
4241}
4342
4443pub fn main ( ) {
@@ -56,10 +55,10 @@ pub fn main() {
5655
5756 unsafe {
5857 struct Foo_ < T > {
59- f : [ T ; 3 ]
58+ f : [ T ; 3 ] ,
6059 }
6160
62- let data: Box < Foo_ < i32 > > = box Foo_ { f : [ 1 , 2 , 3 ] } ;
61+ let data: Box < Foo_ < i32 > > = box Foo_ { f : [ 1 , 2 , 3 ] } ;
6362 let x: & Foo < i32 > = mem:: transmute ( slice:: from_raw_parts ( & * data, 3 ) ) ;
6463 assert_eq ! ( x. f. len( ) , 3 ) ;
6564 assert_eq ! ( x. f[ 0 ] , 1 ) ;
@@ -69,8 +68,8 @@ pub fn main() {
6968 f2 : [ u8 ; 5 ] ,
7069 }
7170
72- let data: Box < _ > = box Baz_ {
73- f1 : 42 , f2 : [ 'a' as u8 , 'b' as u8 , 'c' as u8 , 'd' as u8 , 'e' as u8 ] } ;
71+ let data: Box < _ > =
72+ box Baz_ { f1 : 42 , f2 : [ 'a' as u8 , 'b' as u8 , 'c' as u8 , 'd' as u8 , 'e' as u8 ] } ;
7473 let x: & Baz = mem:: transmute ( slice:: from_raw_parts ( & * data, 5 ) ) ;
7574 assert_eq ! ( x. f1, 42 ) ;
7675 let chs: Vec < char > = x. f2 . chars ( ) . collect ( ) ;
@@ -82,15 +81,13 @@ pub fn main() {
8281 assert_eq ! ( chs[ 4 ] , 'e' ) ;
8382
8483 struct Qux_ {
85- f : St
84+ f : St ,
8685 }
8786
8887 let obj: Box < St > = box St { f : 42 } ;
8988 let obj: & Tr = & * obj;
90- let obj: raw:: TraitObject = mem:: transmute ( & * obj) ;
91- let data: Box < _ > = box Qux_ { f : St { f : 234 } } ;
92- let x: & Qux = mem:: transmute ( raw:: TraitObject { vtable : obj. vtable ,
93- data : mem:: transmute ( & * data) } ) ;
89+ let data: Box < _ > = box Qux_ { f : St { f : 234 } } ;
90+ let x: & Qux = & * ptr:: from_raw_parts :: < Qux > ( ( & * data as * const _ ) . cast ( ) , ptr:: metadata ( obj) ) ;
9491 assert_eq ! ( x. f. foo( ) , 234 ) ;
9592 }
9693}
0 commit comments