@@ -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
}
@@ -310,12 +313,14 @@ impl FunctionSig {
310
313
return_type : TypeId ,
311
314
arguments : Vec < ( Option < String > , TypeId ) > ,
312
315
is_variadic : bool ,
316
+ must_use : bool ,
313
317
abi : Abi ,
314
318
) -> Self {
315
319
FunctionSig {
316
320
return_type : return_type,
317
321
argument_types : arguments,
318
322
is_variadic : is_variadic,
323
+ must_use : must_use,
319
324
abi : abi,
320
325
}
321
326
}
@@ -387,6 +392,24 @@ impl FunctionSig {
387
392
}
388
393
} ;
389
394
395
+ let mut must_use = false ;
396
+ cursor. visit ( |cur| {
397
+ if cur. kind ( ) == CXCursor_UnexposedAttr {
398
+ let attr_warn_unused_result = cur. tokens ( ) . map ( |tokens| {
399
+ tokens. iter ( ) . any ( |t| {
400
+ t. kind == CXToken_Identifier && t. spelling == "warn_unused_result"
401
+ } )
402
+ } ) . unwrap_or ( false ) ;
403
+
404
+ if attr_warn_unused_result {
405
+ must_use = true ;
406
+ return CXChildVisit_Break ;
407
+ }
408
+ }
409
+
410
+ CXChildVisit_Continue
411
+ } ) ;
412
+
390
413
let is_method = cursor. kind ( ) == CXCursor_CXXMethod ;
391
414
let is_constructor = cursor. kind ( ) == CXCursor_Constructor ;
392
415
let is_destructor = cursor. kind ( ) == CXCursor_Destructor ;
@@ -458,7 +481,7 @@ impl FunctionSig {
458
481
warn ! ( "Unknown calling convention: {:?}" , call_conv) ;
459
482
}
460
483
461
- Ok ( Self :: new ( ret. into ( ) , args, ty. is_variadic ( ) , abi) )
484
+ Ok ( Self :: new ( ret. into ( ) , args, ty. is_variadic ( ) , must_use , abi) )
462
485
}
463
486
464
487
/// Get this function signature's return type.
@@ -484,6 +507,11 @@ impl FunctionSig {
484
507
self . is_variadic && !self . argument_types . is_empty ( )
485
508
}
486
509
510
+ /// Must this function's return value be used?
511
+ pub fn must_use ( & self ) -> bool {
512
+ self . must_use
513
+ }
514
+
487
515
/// Are function pointers with this signature able to derive Rust traits?
488
516
/// Rust only supports deriving traits for function pointers with a limited
489
517
/// number of parameters and a couple ABIs.
0 commit comments