1
1
// run-pass
2
2
// Test structs with always-unsized fields.
3
3
4
-
5
4
#![ allow( warnings) ]
6
- #![ feature( box_syntax, unsize, raw ) ]
5
+ #![ feature( box_syntax, unsize, ptr_metadata ) ]
7
6
8
7
use std:: mem;
9
- use std:: raw ;
8
+ use std:: ptr ;
10
9
use std:: slice;
11
10
12
11
struct Foo < T > {
@@ -28,7 +27,7 @@ trait Tr {
28
27
}
29
28
30
29
struct St {
31
- f : usize
30
+ f : usize ,
32
31
}
33
32
34
33
impl Tr for St {
@@ -38,7 +37,7 @@ impl Tr for St {
38
37
}
39
38
40
39
struct Qux < ' a > {
41
- f : Tr + ' a
40
+ f : Tr + ' a ,
42
41
}
43
42
44
43
pub fn main ( ) {
@@ -56,10 +55,10 @@ pub fn main() {
56
55
57
56
unsafe {
58
57
struct Foo_ < T > {
59
- f : [ T ; 3 ]
58
+ f : [ T ; 3 ] ,
60
59
}
61
60
62
- let data: Box < Foo_ < i32 > > = box Foo_ { f : [ 1 , 2 , 3 ] } ;
61
+ let data: Box < Foo_ < i32 > > = box Foo_ { f : [ 1 , 2 , 3 ] } ;
63
62
let x: & Foo < i32 > = mem:: transmute ( slice:: from_raw_parts ( & * data, 3 ) ) ;
64
63
assert_eq ! ( x. f. len( ) , 3 ) ;
65
64
assert_eq ! ( x. f[ 0 ] , 1 ) ;
@@ -69,8 +68,8 @@ pub fn main() {
69
68
f2 : [ u8 ; 5 ] ,
70
69
}
71
70
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 ] } ;
74
73
let x: & Baz = mem:: transmute ( slice:: from_raw_parts ( & * data, 5 ) ) ;
75
74
assert_eq ! ( x. f1, 42 ) ;
76
75
let chs: Vec < char > = x. f2 . chars ( ) . collect ( ) ;
@@ -82,15 +81,13 @@ pub fn main() {
82
81
assert_eq ! ( chs[ 4 ] , 'e' ) ;
83
82
84
83
struct Qux_ {
85
- f : St
84
+ f : St ,
86
85
}
87
86
88
87
let obj: Box < St > = box St { f : 42 } ;
89
88
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) ) ;
94
91
assert_eq ! ( x. f. foo( ) , 234 ) ;
95
92
}
96
93
}
0 commit comments