@@ -74,6 +74,8 @@ pub struct FnDefn {
74
74
pub argument_types : Vec < Ty > ,
75
75
pub return_type : Ty ,
76
76
pub abi : FnAbi ,
77
+ pub safety : Safety ,
78
+ pub variadic : bool ,
77
79
}
78
80
79
81
#[ derive( Clone , PartialEq , Eq , Debug ) ]
@@ -259,6 +261,9 @@ pub enum Ty {
259
261
ForAll {
260
262
lifetime_names : Vec < Identifier > ,
261
263
types : Vec < Box < Ty > > ,
264
+ abi : FnAbi ,
265
+ safety : Safety ,
266
+ variadic : bool ,
262
267
} ,
263
268
Tuple {
264
269
types : Vec < Box < Ty > > ,
@@ -327,6 +332,18 @@ pub enum Mutability {
327
332
Not ,
328
333
}
329
334
335
+ #[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
336
+ pub enum Safety {
337
+ Safe ,
338
+ Unsafe ,
339
+ }
340
+
341
+ impl Default for Safety {
342
+ fn default ( ) -> Self {
343
+ Self :: Safe
344
+ }
345
+ }
346
+
330
347
#[ derive( Clone , PartialEq , Eq , Debug ) ]
331
348
pub enum Lifetime {
332
349
Id { name : Identifier } ,
@@ -450,3 +467,51 @@ pub enum ClosureKind {
450
467
FnMut ,
451
468
FnOnce ,
452
469
}
470
+
471
+ #[ derive( Clone , Eq , PartialEq , Debug ) ]
472
+ pub enum FnArg {
473
+ NonVariadic ( Ty ) ,
474
+ Variadic ,
475
+ }
476
+ #[ derive( Clone , Eq , PartialEq , Debug ) ]
477
+ pub enum FnArgs {
478
+ NonVariadic ( Vec < Ty > ) ,
479
+ Variadic ( Vec < Ty > ) ,
480
+ }
481
+
482
+ impl FnArgs {
483
+ pub fn is_variadic ( & self ) -> bool {
484
+ match self {
485
+ Self :: Variadic ( ..) => true ,
486
+ _ => false ,
487
+ }
488
+ }
489
+
490
+ pub fn to_tys ( self ) -> Vec < Ty > {
491
+ match self {
492
+ Self :: NonVariadic ( tys) | Self :: Variadic ( tys) => tys,
493
+ }
494
+ }
495
+
496
+ pub fn from_vec ( mut args : Vec < FnArg > ) -> Result < Self , & ' static str > {
497
+ let mut tys = Vec :: with_capacity ( args. len ( ) ) ;
498
+ let last = args. pop ( ) ;
499
+ for arg in args {
500
+ match arg {
501
+ FnArg :: NonVariadic ( ty) => tys. push ( ty) ,
502
+ FnArg :: Variadic => {
503
+ return Err ( "a variadic argument must be the last parameter in a function" ) ;
504
+ }
505
+ }
506
+ }
507
+
508
+ Ok ( match last {
509
+ Some ( FnArg :: NonVariadic ( ty) ) => {
510
+ tys. push ( ty) ;
511
+ FnArgs :: NonVariadic ( tys)
512
+ }
513
+ Some ( FnArg :: Variadic ) => FnArgs :: Variadic ( tys) ,
514
+ None => FnArgs :: NonVariadic ( tys) ,
515
+ } )
516
+ }
517
+ }
0 commit comments