@@ -221,6 +221,9 @@ pub struct FunctionSig {
221
221
/// Whether this function is variadic.
222
222
is_variadic : bool ,
223
223
224
+ /// Whether this function's return value must be used.
225
+ must_use : bool ,
226
+
224
227
/// The ABI of this function.
225
228
abi : Abi ,
226
229
}
@@ -308,14 +311,16 @@ impl FunctionSig {
308
311
/// Construct a new function signature.
309
312
pub fn new (
310
313
return_type : TypeId ,
311
- arguments : Vec < ( Option < String > , TypeId ) > ,
314
+ argument_types : Vec < ( Option < String > , TypeId ) > ,
312
315
is_variadic : bool ,
316
+ must_use : bool ,
313
317
abi : Abi ,
314
318
) -> Self {
315
319
FunctionSig {
316
- return_type : return_type,
317
- argument_types : arguments,
318
- is_variadic : is_variadic,
320
+ return_type,
321
+ argument_types,
322
+ is_variadic,
323
+ must_use,
319
324
abi : abi,
320
325
}
321
326
}
@@ -387,6 +392,7 @@ impl FunctionSig {
387
392
}
388
393
} ;
389
394
395
+ let must_use = cursor. has_simple_attr ( "warn_unused_result" ) ;
390
396
let is_method = cursor. kind ( ) == CXCursor_CXXMethod ;
391
397
let is_constructor = cursor. kind ( ) == CXCursor_Constructor ;
392
398
let is_destructor = cursor. kind ( ) == CXCursor_Destructor ;
@@ -458,7 +464,7 @@ impl FunctionSig {
458
464
warn ! ( "Unknown calling convention: {:?}" , call_conv) ;
459
465
}
460
466
461
- Ok ( Self :: new ( ret. into ( ) , args, ty. is_variadic ( ) , abi) )
467
+ Ok ( Self :: new ( ret. into ( ) , args, ty. is_variadic ( ) , must_use , abi) )
462
468
}
463
469
464
470
/// Get this function signature's return type.
@@ -484,6 +490,11 @@ impl FunctionSig {
484
490
self . is_variadic && !self . argument_types . is_empty ( )
485
491
}
486
492
493
+ /// Must this function's return value be used?
494
+ pub fn must_use ( & self ) -> bool {
495
+ self . must_use
496
+ }
497
+
487
498
/// Are function pointers with this signature able to derive Rust traits?
488
499
/// Rust only supports deriving traits for function pointers with a limited
489
500
/// number of parameters and a couple ABIs.
0 commit comments