@@ -26,6 +26,8 @@ pub struct FunctionSignature {
26
26
pub kind : CallableKind ,
27
27
/// Optional visibility
28
28
pub visibility : Option < String > ,
29
+ /// Qualifiers like `async`, `unsafe`, ...
30
+ pub qualifier : FunctionQualifier ,
29
31
/// Name of the function
30
32
pub name : Option < String > ,
31
33
/// Documentation for the function
@@ -46,6 +48,16 @@ pub struct FunctionSignature {
46
48
pub has_self_param : bool ,
47
49
}
48
50
51
+ #[ derive( Debug , Default ) ]
52
+ pub struct FunctionQualifier {
53
+ // `async` and `const` are mutually exclusive. Do we need to enforcing it here?
54
+ pub is_async : bool ,
55
+ pub is_const : bool ,
56
+ pub is_unsafe : bool ,
57
+ /// The string `extern ".."`
58
+ pub extern_abi : Option < String > ,
59
+ }
60
+
49
61
impl FunctionSignature {
50
62
pub ( crate ) fn with_doc_opt ( mut self , doc : Option < Documentation > ) -> Self {
51
63
self . doc = doc;
@@ -83,6 +95,8 @@ impl FunctionSignature {
83
95
FunctionSignature {
84
96
kind : CallableKind :: StructConstructor ,
85
97
visibility : node. visibility ( ) . map ( |n| n. syntax ( ) . text ( ) . to_string ( ) ) ,
98
+ // Do we need `const`?
99
+ qualifier : Default :: default ( ) ,
86
100
name : node. name ( ) . map ( |n| n. text ( ) . to_string ( ) ) ,
87
101
ret_type : node. name ( ) . map ( |n| n. text ( ) . to_string ( ) ) ,
88
102
parameters : params,
@@ -128,6 +142,8 @@ impl FunctionSignature {
128
142
FunctionSignature {
129
143
kind : CallableKind :: VariantConstructor ,
130
144
visibility : None ,
145
+ // Do we need `const`?
146
+ qualifier : Default :: default ( ) ,
131
147
name : Some ( name) ,
132
148
ret_type : None ,
133
149
parameters : params,
@@ -151,6 +167,7 @@ impl FunctionSignature {
151
167
FunctionSignature {
152
168
kind : CallableKind :: Macro ,
153
169
visibility : None ,
170
+ qualifier : Default :: default ( ) ,
154
171
name : node. name ( ) . map ( |n| n. text ( ) . to_string ( ) ) ,
155
172
ret_type : None ,
156
173
parameters : params,
@@ -223,6 +240,12 @@ impl From<&'_ ast::FnDef> for FunctionSignature {
223
240
FunctionSignature {
224
241
kind : CallableKind :: Function ,
225
242
visibility : node. visibility ( ) . map ( |n| n. syntax ( ) . text ( ) . to_string ( ) ) ,
243
+ qualifier : FunctionQualifier {
244
+ is_async : node. async_token ( ) . is_some ( ) ,
245
+ is_const : node. const_token ( ) . is_some ( ) ,
246
+ is_unsafe : node. unsafe_token ( ) . is_some ( ) ,
247
+ extern_abi : node. abi ( ) . map ( |n| n. to_string ( ) ) ,
248
+ } ,
226
249
name : node. name ( ) . map ( |n| n. text ( ) . to_string ( ) ) ,
227
250
ret_type : node
228
251
. ret_type ( )
@@ -246,6 +269,23 @@ impl Display for FunctionSignature {
246
269
write ! ( f, "{} " , t) ?;
247
270
}
248
271
272
+ if self . qualifier . is_async {
273
+ write ! ( f, "async " ) ?;
274
+ }
275
+
276
+ if self . qualifier . is_const {
277
+ write ! ( f, "const " ) ?;
278
+ }
279
+
280
+ if self . qualifier . is_unsafe {
281
+ write ! ( f, "unsafe " ) ?;
282
+ }
283
+
284
+ if let Some ( extern_abi) = & self . qualifier . extern_abi {
285
+ // Keyword `extern` is included in the string.
286
+ write ! ( f, "{} " , extern_abi) ?;
287
+ }
288
+
249
289
if let Some ( name) = & self . name {
250
290
match self . kind {
251
291
CallableKind :: Function => write ! ( f, "fn {}" , name) ?,
0 commit comments