summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/clang.rs33
-rw-r--r--src/ir/function.rs2
2 files changed, 21 insertions, 14 deletions
diff --git a/src/clang.rs b/src/clang.rs
index 0a59c309..efb53074 100644
--- a/src/clang.rs
+++ b/src/clang.rs
@@ -527,25 +527,32 @@ impl Cursor {
}
}
- /// Does this cursor have the given simple attribute?
+ /// Whether this cursor has the `warn_unused_result` attribute.
+ pub fn has_warn_unused_result_attr(&self) -> bool {
+ // FIXME(emilio): clang-sys doesn't expose this (from clang 9).
+ const CXCursor_WarnUnusedResultAttr: CXCursorKind = 440;
+ self.has_attr("warn_unused_result", Some(CXCursor_WarnUnusedResultAttr))
+ }
+
+ /// Does this cursor have the given attribute?
///
- /// Note that this will only work for attributes that don't have an existing libclang
- /// CursorKind, e.g. pure, const, etc.
- pub fn has_simple_attr(&self, attr: &str) -> bool {
+ /// `name` is checked against unexposed attributes.
+ fn has_attr(&self, name: &str, clang_kind: Option<CXCursorKind>) -> bool {
let mut found_attr = false;
self.visit(|cur| {
- if cur.kind() == CXCursor_UnexposedAttr {
- found_attr = cur.tokens().iter().any(|t| {
+ let kind = cur.kind();
+ found_attr = clang_kind.map_or(false, |k| k == kind) ||
+ (kind == CXCursor_UnexposedAttr &&
+ cur.tokens().iter().any(|t| {
t.kind == CXToken_Identifier &&
- t.spelling() == attr.as_bytes()
- });
+ t.spelling() == name.as_bytes()
+ }));
- if found_attr {
- return CXChildVisit_Break;
- }
+ if found_attr {
+ CXChildVisit_Break
+ } else {
+ CXChildVisit_Continue
}
-
- CXChildVisit_Continue
});
found_attr
diff --git a/src/ir/function.rs b/src/ir/function.rs
index 9ccf4e14..0715ec54 100644
--- a/src/ir/function.rs
+++ b/src/ir/function.rs
@@ -424,7 +424,7 @@ impl FunctionSig {
};
let must_use = ctx.options().enable_function_attribute_detection &&
- cursor.has_simple_attr("warn_unused_result");
+ cursor.has_warn_unused_result_attr();
let is_method = kind == CXCursor_CXXMethod;
let is_constructor = kind == CXCursor_Constructor;
let is_destructor = kind == CXCursor_Destructor;