File tree Expand file tree Collapse file tree 2 files changed +51
-45
lines changed Expand file tree Collapse file tree 2 files changed +51
-45
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 11#![ feature( unsize, coerce_unsized) ]
22
3- #[ repr( packed) ]
4- struct S {
5- a : i32 ,
6- b : i64 ,
7- }
83
9- # [ repr ( packed ) ]
10- # [ allow ( dead_code ) ]
11- struct Test1 < ' a > {
12- x : u8 ,
13- other : & ' a u32 ,
14- }
4+ fn test_basic ( ) {
5+ # [ repr ( packed ) ]
6+ struct S {
7+ a : i32 ,
8+ b : i64 ,
9+ }
1510
16- #[ repr( packed) ]
17- #[ allow( dead_code) ]
18- struct Test2 < ' a > {
19- x : u8 ,
20- other : & ' a Test1 < ' a > ,
21- }
11+ #[ repr( packed) ]
12+ #[ allow( dead_code) ]
13+ struct Test1 < ' a > {
14+ x : u8 ,
15+ other : & ' a u32 ,
16+ }
17+
18+ #[ repr( packed) ]
19+ #[ allow( dead_code) ]
20+ struct Test2 < ' a > {
21+ x : u8 ,
22+ other : & ' a Test1 < ' a > ,
23+ }
2224
23- fn test ( t : Test2 ) {
24- let x = * t. other . other ;
25- assert_eq ! ( x, 42 ) ;
25+ fn test ( t : Test2 ) {
26+ let x = * t. other . other ;
27+ assert_eq ! ( x, 42 ) ;
28+ }
29+
30+ let mut x = S {
31+ a : 42 ,
32+ b : 99 ,
33+ } ;
34+ let a = x. a ;
35+ let b = x. b ;
36+ assert_eq ! ( a, 42 ) ;
37+ assert_eq ! ( b, 99 ) ;
38+ // can't do `assert_eq!(x.a, 42)`, because `assert_eq!` takes a reference
39+ assert_eq ! ( { x. a} , 42 ) ;
40+ assert_eq ! ( { x. b} , 99 ) ;
41+
42+ x. b = 77 ;
43+ assert_eq ! ( { x. b} , 77 ) ;
44+
45+ test ( Test2 { x : 0 , other : & Test1 { x : 0 , other : & 42 } } ) ;
2646}
2747
2848fn test_unsizing ( ) {
@@ -83,25 +103,21 @@ fn test_inner_packed() {
83103 let _o2 = o. clone ( ) ;
84104}
85105
86- fn main ( ) {
87- let mut x = S {
88- a : 42 ,
89- b : 99 ,
90- } ;
91- let a = x. a ;
92- let b = x. b ;
93- assert_eq ! ( a, 42 ) ;
94- assert_eq ! ( b, 99 ) ;
95- // can't do `assert_eq!(x.a, 42)`, because `assert_eq!` takes a reference
96- assert_eq ! ( { x. a} , 42 ) ;
97- assert_eq ! ( { x. b} , 99 ) ;
106+ fn test_static ( ) {
107+ #[ repr( packed) ]
108+ struct Foo {
109+ i : i32
110+ }
98111
99- x. b = 77 ;
100- assert_eq ! ( { x. b} , 77 ) ;
112+ static FOO : Foo = Foo { i : 42 } ;
101113
102- test ( Test2 { x : 0 , other : & Test1 { x : 0 , other : & 42 } } ) ;
114+ assert_eq ! ( { FOO . i} , 42 ) ;
115+ }
103116
117+ fn main ( ) {
118+ test_basic ( ) ;
104119 test_unsizing ( ) ;
105120 test_drop ( ) ;
106121 test_inner_packed ( ) ;
122+ test_static ( ) ;
107123}
You can’t perform that action at this time.
0 commit comments