mirror of
https://gitee.com/openharmony/third_party_rust_bindgen
synced 2025-03-04 20:57:21 +00:00
function: Fix #[must_use] support in libclang 9+.
This commit is contained in:
parent
5d1c517d13
commit
71e0d9d5a7
33
src/clang.rs
33
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
|
||||
|
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user