@@ -92,6 +92,18 @@ mod tests {
92
92
#[ derive( Copy , Clone ) ]
93
93
pub struct Floats { a : f64 , b : u8 , c : f64 }
94
94
95
+ #[ repr( C , u8 ) ]
96
+ pub enum U8TaggedEnumOptionU64U64 {
97
+ None ,
98
+ Some ( u64 , u64 ) ,
99
+ }
100
+
101
+ #[ repr( C , u8 ) ]
102
+ pub enum U8TaggedEnumOptionU64 {
103
+ None ,
104
+ Some ( u64 ) ,
105
+ }
106
+
95
107
#[ link( name = "rust_test_helpers" , kind = "static" ) ]
96
108
extern "sysv64" {
97
109
pub fn rust_int8_to_int32 ( _: i8 ) -> i32 ;
@@ -125,6 +137,12 @@ mod tests {
125
137
) -> f32 ;
126
138
pub fn rust_dbg_abi_1 ( q : Quad ) -> Quad ;
127
139
pub fn rust_dbg_abi_2 ( f : Floats ) -> Floats ;
140
+ pub fn rust_dbg_new_some_u64u64 ( a : u64 , b : u64 ) -> U8TaggedEnumOptionU64U64 ;
141
+ pub fn rust_dbg_new_none_u64u64 ( ) -> U8TaggedEnumOptionU64U64 ;
142
+ pub fn rust_dbg_unpack_option_u64u64 ( o : U8TaggedEnumOptionU64U64 , a : * mut u64 , b : * mut u64 ) -> i32 ;
143
+ pub fn rust_dbg_new_some_u64 ( some : u64 ) -> U8TaggedEnumOptionU64 ;
144
+ pub fn rust_dbg_new_none_u64 ( ) -> U8TaggedEnumOptionU64 ;
145
+ pub fn rust_dbg_unpack_option_u64 ( o : U8TaggedEnumOptionU64 , v : * mut u64 ) -> i32 ;
128
146
}
129
147
130
148
pub fn cabi_int_widening ( ) {
@@ -336,6 +354,59 @@ mod tests {
336
354
test1 ( ) ;
337
355
test2 ( ) ;
338
356
}
357
+
358
+ pub fn enum_passing_and_return_pair ( ) {
359
+ let some_u64u64 = unsafe { rust_dbg_new_some_u64u64 ( 10 , 20 ) } ;
360
+ if let U8TaggedEnumOptionU64U64 :: Some ( a, b) = some_u64u64 {
361
+ assert_eq ! ( 10 , a) ;
362
+ assert_eq ! ( 20 , b) ;
363
+ } else {
364
+ panic ! ( "unexpected none" ) ;
365
+ }
366
+
367
+ let none_u64u64 = unsafe { rust_dbg_new_none_u64u64 ( ) } ;
368
+ if let U8TaggedEnumOptionU64U64 :: Some ( _, _) = none_u64u64 {
369
+ panic ! ( "unexpected some" ) ;
370
+ }
371
+
372
+ let mut a: u64 = 0 ;
373
+ let mut b: u64 = 0 ;
374
+ let r = unsafe { rust_dbg_unpack_option_u64u64 ( some_u64u64, & mut a as * mut _ , & mut b as * mut _ ) } ;
375
+ assert_eq ! ( 1 , r) ;
376
+ assert_eq ! ( 10 , a) ;
377
+ assert_eq ! ( 20 , b) ;
378
+
379
+ let mut a: u64 = 0 ;
380
+ let mut b: u64 = 0 ;
381
+ let r = unsafe { rust_dbg_unpack_option_u64u64 ( none_u64u64, & mut a as * mut _ , & mut b as * mut _ ) } ;
382
+ assert_eq ! ( 0 , r) ;
383
+ assert_eq ! ( 0 , a) ;
384
+ assert_eq ! ( 0 , b) ;
385
+ }
386
+
387
+ pub fn enum_passing_and_return ( ) {
388
+ let some_u64 = unsafe { rust_dbg_new_some_u64 ( 10 ) } ;
389
+ if let U8TaggedEnumOptionU64 :: Some ( v) = some_u64 {
390
+ assert_eq ! ( 10 , v) ;
391
+ } else {
392
+ panic ! ( "unexpected none" ) ;
393
+ }
394
+
395
+ let none_u64 = unsafe { rust_dbg_new_none_u64 ( ) } ;
396
+ if let U8TaggedEnumOptionU64 :: Some ( _) = none_u64 {
397
+ panic ! ( "unexpected some" ) ;
398
+ }
399
+
400
+ let mut target: u64 = 0 ;
401
+ let r = unsafe { rust_dbg_unpack_option_u64 ( some_u64, & mut target as * mut _ ) } ;
402
+ assert_eq ! ( 1 , r) ;
403
+ assert_eq ! ( 10 , target) ;
404
+
405
+ let mut target: u64 = 0 ;
406
+ let r = unsafe { rust_dbg_unpack_option_u64 ( none_u64, & mut target as * mut _ ) } ;
407
+ assert_eq ! ( 0 , r) ;
408
+ assert_eq ! ( 0 , target) ;
409
+ }
339
410
}
340
411
341
412
#[ cfg( target_arch = "x86_64" ) ]
@@ -359,6 +430,8 @@ fn main() {
359
430
issue_28676 ( ) ;
360
431
issue_62350 ( ) ;
361
432
struct_return ( ) ;
433
+ enum_passing_and_return_pair ( ) ;
434
+ enum_passing_and_return ( ) ;
362
435
}
363
436
364
437
#[ cfg( not( target_arch = "x86_64" ) ) ]
0 commit comments