@@ -4,7 +4,6 @@ use std::fmt::Write;
4
4
5
5
type BoxStr = Box < str > ;
6
6
7
- #[ cfg_attr( not( test) , expect( dead_code) ) ]
8
7
#[ derive( Clone , Copy , Debug , PartialEq , Eq ) ]
9
8
pub ( crate ) enum Constness {
10
9
Const ,
@@ -15,7 +14,6 @@ pub(crate) enum Constness {
15
14
use Constness :: { Const , Mut } ;
16
15
17
16
/// A basic representation of C's types.
18
- #[ cfg_attr( not( test) , expect( dead_code) ) ]
19
17
#[ derive( Clone , Debug ) ]
20
18
pub ( crate ) enum CTy {
21
19
/// `int`, `struct foo`, etc. There is only ever one basic type per decl.
@@ -85,7 +83,6 @@ pub(crate) struct InvalidReturn;
85
83
/// value to allow reusing allocations.
86
84
///
87
85
/// If needed, `name` can be empty (e.g. for function arguments).
88
- #[ cfg_attr( not( test) , expect( dead_code) ) ]
89
86
pub ( crate ) fn cdecl ( cty : & CTy , mut name : String ) -> Result < String , InvalidReturn > {
90
87
cdecl_impl ( cty, & mut name, None ) ?;
91
88
Ok ( name)
@@ -178,6 +175,74 @@ fn space_if(yes: bool, s: &mut String) {
178
175
}
179
176
}
180
177
178
+ pub ( crate ) fn named ( name : & str , constness : Constness ) -> CTy {
179
+ CTy :: Named {
180
+ name : name. into ( ) ,
181
+ qual : Qual {
182
+ constness,
183
+ volatile : false ,
184
+ restrict : false ,
185
+ } ,
186
+ }
187
+ }
188
+
189
+ #[ cfg_attr( not( test) , expect( unused) ) ]
190
+ pub ( crate ) fn named_qual ( name : & str , qual : Qual ) -> CTy {
191
+ CTy :: Named {
192
+ name : name. into ( ) ,
193
+ qual,
194
+ }
195
+ }
196
+
197
+ pub ( crate ) fn ptr ( inner : CTy , constness : Constness ) -> CTy {
198
+ ptr_qual (
199
+ inner,
200
+ Qual {
201
+ constness,
202
+ volatile : false ,
203
+ restrict : false ,
204
+ } ,
205
+ )
206
+ }
207
+
208
+ pub ( crate ) fn ptr_qual ( inner : CTy , qual : Qual ) -> CTy {
209
+ CTy :: Ptr {
210
+ ty : Box :: new ( inner) ,
211
+ qual,
212
+ }
213
+ }
214
+
215
+ pub ( crate ) fn array ( inner : CTy , len : Option < & str > ) -> CTy {
216
+ CTy :: Array {
217
+ ty : Box :: new ( inner) ,
218
+ len : len. map ( Into :: into) ,
219
+ }
220
+ }
221
+
222
+ /// Function type (not a pointer)
223
+ #[ cfg_attr( not( test) , expect( unused) ) ]
224
+ pub ( crate ) fn func ( args : Vec < CTy > , ret : CTy ) -> CTy {
225
+ CTy :: Fn {
226
+ args,
227
+ ret : Box :: new ( ret) ,
228
+ }
229
+ }
230
+
231
+ /// Function pointer
232
+ pub ( crate ) fn func_ptr ( args : Vec < CTy > , ret : CTy ) -> CTy {
233
+ CTy :: Ptr {
234
+ ty : Box :: new ( CTy :: Fn {
235
+ args,
236
+ ret : Box :: new ( ret) ,
237
+ } ) ,
238
+ qual : Qual {
239
+ constness : Constness :: Mut ,
240
+ volatile : false ,
241
+ restrict : false ,
242
+ } ,
243
+ }
244
+ }
245
+
181
246
/// Checked with <https://cdecl.org/>.
182
247
#[ cfg( test) ]
183
248
mod tests {
@@ -210,68 +275,6 @@ mod tests {
210
275
named ( "int" , Const )
211
276
}
212
277
213
- fn named ( name : & str , constness : Constness ) -> CTy {
214
- CTy :: Named {
215
- name : name. into ( ) ,
216
- qual : Qual {
217
- constness,
218
- volatile : false ,
219
- restrict : false ,
220
- } ,
221
- }
222
- }
223
-
224
- fn named_qual ( name : & str , qual : Qual ) -> CTy {
225
- CTy :: Named {
226
- name : name. into ( ) ,
227
- qual,
228
- }
229
- }
230
-
231
- fn ptr ( inner : CTy , constness : Constness ) -> CTy {
232
- ptr_qual (
233
- inner,
234
- Qual {
235
- constness,
236
- volatile : false ,
237
- restrict : false ,
238
- } ,
239
- )
240
- }
241
-
242
- fn ptr_qual ( inner : CTy , qual : Qual ) -> CTy {
243
- CTy :: Ptr {
244
- ty : Box :: new ( inner) ,
245
- qual,
246
- }
247
- }
248
-
249
- fn array ( inner : CTy , len : Option < & str > ) -> CTy {
250
- CTy :: Array {
251
- ty : Box :: new ( inner) ,
252
- len : len. map ( Into :: into) ,
253
- }
254
- }
255
-
256
- /// Function type (not a pointer)
257
- fn func ( args : Vec < CTy > , ret : CTy ) -> CTy {
258
- CTy :: Fn {
259
- args,
260
- ret : Box :: new ( ret) ,
261
- }
262
- }
263
-
264
- /// Function pointer
265
- fn func_ptr ( args : Vec < CTy > , ret : CTy ) -> CTy {
266
- ptr (
267
- CTy :: Fn {
268
- args,
269
- ret : Box :: new ( ret) ,
270
- } ,
271
- Mut ,
272
- )
273
- }
274
-
275
278
#[ test]
276
279
fn basic ( ) {
277
280
assert_decl ( & const_int ( ) , "const int foo" ) ;
@@ -350,7 +353,7 @@ mod tests {
350
353
// Can't return an array
351
354
assert ! ( cdecl( & func( vec![ ] , array( mut_int( ) , None ) ) , "foo" . to_owned( ) , ) . is_err( ) , ) ;
352
355
// Can't return a function
353
- assert ! ( cdecl( & func( vec![ ] , func( vec![ ] , mut_int( ) ) , ) , "foo" . to_owned( ) , ) . is_err( ) , ) ;
356
+ assert ! ( cdecl( & func( vec![ ] , func( vec![ ] , mut_int( ) ) ) , "foo" . to_owned( ) , ) . is_err( ) , ) ;
354
357
}
355
358
356
359
#[ test]
0 commit comments