@@ -5,6 +5,7 @@ const STRING_TY: TypeId = const { TypeId::of::<String>() };
55const U8_TY : TypeId = const { TypeId :: of :: < u8 > ( ) } ;
66const _U8_REF_TY: TypeId = const { TypeId :: of :: < & u8 > ( ) } ;
77const UNIT_TY : TypeId = const { TypeId :: of :: < ( ) > ( ) } ;
8+ const TUPLE_STRING_U8_TY : TypeId = const { TypeId :: of :: < ( String , u8 ) > ( ) } ;
89
910#[ test]
1011fn test_fn_ptrs ( ) {
@@ -14,6 +15,8 @@ fn test_fn_ptrs() {
1415 inputs : & [ ] ,
1516 output,
1617 variadic : false ,
18+ is_splatted : false ,
19+ splatted_index : _,
1720 } ) = ( const { Type :: of :: < fn ( ) > ( ) . kind } )
1821 else {
1922 panic ! ( ) ;
@@ -31,6 +34,8 @@ fn test_ref() {
3134 inputs : & [ ty1, ty2] ,
3235 output,
3336 variadic : false ,
37+ is_splatted : false ,
38+ splatted_index : _,
3439 } ) = ( const { Type :: of :: < fn ( & u8 , & u8 ) > ( ) . kind } )
3540 else {
3641 panic ! ( ) ;
@@ -61,6 +66,8 @@ fn test_unsafe() {
6166 inputs : & [ ] ,
6267 output,
6368 variadic : false ,
69+ is_splatted : false ,
70+ splatted_index : _,
6471 } ) = ( const { Type :: of :: < unsafe fn ( ) > ( ) . kind } )
6572 else {
6673 panic ! ( ) ;
@@ -75,6 +82,8 @@ fn test_abi() {
7582 inputs : & [ ] ,
7683 output,
7784 variadic : false ,
85+ is_splatted : false ,
86+ splatted_index : _,
7887 } ) = ( const { Type :: of :: < extern "Rust" fn ( ) > ( ) . kind } )
7988 else {
8089 panic ! ( ) ;
@@ -87,6 +96,8 @@ fn test_abi() {
8796 inputs : & [ ] ,
8897 output,
8998 variadic : false ,
99+ is_splatted : false ,
100+ splatted_index : _,
90101 } ) = ( const { Type :: of :: < extern "C" fn ( ) > ( ) . kind } )
91102 else {
92103 panic ! ( ) ;
@@ -99,6 +110,8 @@ fn test_abi() {
99110 inputs : & [ ] ,
100111 output,
101112 variadic : false ,
113+ is_splatted : false ,
114+ splatted_index : _,
102115 } ) = ( const { Type :: of :: < unsafe extern "system" fn ( ) > ( ) . kind } )
103116 else {
104117 panic ! ( ) ;
@@ -114,6 +127,8 @@ fn test_inputs() {
114127 inputs : & [ ty1, ty2] ,
115128 output,
116129 variadic : false ,
130+ is_splatted : false ,
131+ splatted_index : _,
117132 } ) = ( const { Type :: of :: < fn ( String , u8 ) > ( ) . kind } )
118133 else {
119134 panic ! ( ) ;
@@ -128,6 +143,8 @@ fn test_inputs() {
128143 inputs : & [ ty1, ty2] ,
129144 output,
130145 variadic : false ,
146+ is_splatted : false ,
147+ splatted_index : _,
131148 } ) = ( const { Type :: of :: < fn ( val : String , p2 : u8 ) > ( ) . kind } )
132149 else {
133150 panic ! ( ) ;
@@ -145,6 +162,8 @@ fn test_output() {
145162 inputs : & [ ] ,
146163 output,
147164 variadic : false ,
165+ is_splatted : false ,
166+ splatted_index : _,
148167 } ) = ( const { Type :: of :: < fn ( ) -> u8 > ( ) . kind } )
149168 else {
150169 panic ! ( ) ;
@@ -160,10 +179,57 @@ fn test_variadic() {
160179 inputs : [ ty1] ,
161180 output,
162181 variadic : true ,
182+ is_splatted : false ,
183+ splatted_index : _,
163184 } ) = & ( const { Type :: of :: < extern "C" fn ( u8 , ...) > ( ) . kind } )
164185 else {
165186 panic ! ( ) ;
166187 } ;
167188 assert_eq ! ( output, & UNIT_TY ) ;
168189 assert_eq ! ( * ty1, U8_TY ) ;
169190}
191+
192+ #[ test]
193+ fn test_splat ( ) {
194+ #[ rustfmt:: skip]
195+ let TypeKind :: FnPtr ( fn_ptr_ty) = & ( const { Type :: of :: < fn ( #[ splat] ( String , u8 ) ) > ( ) . kind } ) else {
196+ panic ! ( ) ;
197+ } ;
198+ let FnPtr {
199+ unsafety : false ,
200+ abi : Abi :: ExternRust ,
201+ inputs : [ ty1] ,
202+ output,
203+ variadic : false ,
204+ is_splatted : true ,
205+ splatted_index : 0 ,
206+ } = fn_ptr_ty
207+ else {
208+ panic ! ( ) ;
209+ } ;
210+ assert_eq ! ( output, & UNIT_TY ) ;
211+ assert_eq ! ( * ty1, TUPLE_STRING_U8_TY ) ;
212+ assert_eq ! ( fn_ptr_ty. splatted( ) , Some ( 0 ) ) ;
213+ }
214+
215+ #[ test]
216+ fn test_not_splat ( ) {
217+ let TypeKind :: FnPtr ( fn_ptr_ty) = & ( const { Type :: of :: < fn ( ( String , u8 ) ) > ( ) . kind } ) else {
218+ panic ! ( ) ;
219+ } ;
220+ let FnPtr {
221+ unsafety : false ,
222+ abi : Abi :: ExternRust ,
223+ inputs : [ ty1] ,
224+ output,
225+ variadic : false ,
226+ is_splatted : false ,
227+ splatted_index : _,
228+ } = fn_ptr_ty
229+ else {
230+ panic ! ( ) ;
231+ } ;
232+ assert_eq ! ( output, & UNIT_TY ) ;
233+ assert_eq ! ( * ty1, TUPLE_STRING_U8_TY ) ;
234+ assert_eq ! ( fn_ptr_ty. splatted( ) , None ) ;
235+ }
0 commit comments