@@ -26,6 +26,8 @@ pub struct FunctionSignature {
2626 pub kind : CallableKind ,
2727 /// Optional visibility
2828 pub visibility : Option < String > ,
29+ /// Qualifiers like `async`, `unsafe`, ...
30+ pub qualifier : FunctionQualifier ,
2931 /// Name of the function
3032 pub name : Option < String > ,
3133 /// Documentation for the function
@@ -46,6 +48,16 @@ pub struct FunctionSignature {
4648 pub has_self_param : bool ,
4749}
4850
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+
4961impl FunctionSignature {
5062 pub ( crate ) fn with_doc_opt ( mut self , doc : Option < Documentation > ) -> Self {
5163 self . doc = doc;
@@ -83,6 +95,8 @@ impl FunctionSignature {
8395 FunctionSignature {
8496 kind : CallableKind :: StructConstructor ,
8597 visibility : node. visibility ( ) . map ( |n| n. syntax ( ) . text ( ) . to_string ( ) ) ,
98+ // Do we need `const`?
99+ qualifier : Default :: default ( ) ,
86100 name : node. name ( ) . map ( |n| n. text ( ) . to_string ( ) ) ,
87101 ret_type : node. name ( ) . map ( |n| n. text ( ) . to_string ( ) ) ,
88102 parameters : params,
@@ -128,6 +142,8 @@ impl FunctionSignature {
128142 FunctionSignature {
129143 kind : CallableKind :: VariantConstructor ,
130144 visibility : None ,
145+ // Do we need `const`?
146+ qualifier : Default :: default ( ) ,
131147 name : Some ( name) ,
132148 ret_type : None ,
133149 parameters : params,
@@ -151,6 +167,7 @@ impl FunctionSignature {
151167 FunctionSignature {
152168 kind : CallableKind :: Macro ,
153169 visibility : None ,
170+ qualifier : Default :: default ( ) ,
154171 name : node. name ( ) . map ( |n| n. text ( ) . to_string ( ) ) ,
155172 ret_type : None ,
156173 parameters : params,
@@ -223,6 +240,12 @@ impl From<&'_ ast::FnDef> for FunctionSignature {
223240 FunctionSignature {
224241 kind : CallableKind :: Function ,
225242 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+ } ,
226249 name : node. name ( ) . map ( |n| n. text ( ) . to_string ( ) ) ,
227250 ret_type : node
228251 . ret_type ( )
@@ -246,6 +269,23 @@ impl Display for FunctionSignature {
246269 write ! ( f, "{} " , t) ?;
247270 }
248271
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+
249289 if let Some ( name) = & self . name {
250290 match self . kind {
251291 CallableKind :: Function => write ! ( f, "fn {}" , name) ?,
0 commit comments