Skip to content

Commit e503476

Browse files
pvdrzemilio
authored andcommitted
bring back optional cursor kind
1 parent fb5f9b9 commit e503476

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/clang.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use std::{mem, ptr, slice};
1818
/// function.
1919
pub struct Attribute {
2020
name: &'static [u8],
21-
kind: CXCursorKind,
21+
kind: Option<CXCursorKind>,
2222
token_kind: CXTokenKind,
2323
}
2424

@@ -27,14 +27,14 @@ impl Attribute {
2727
pub const MUST_USE: Self = Self {
2828
name: b"warn_unused_result",
2929
// FIXME(emilio): clang-sys doesn't expose `CXCursor_WarnUnusedResultAttr` (from clang 9).
30-
kind: 440,
30+
kind: Some(440),
3131
token_kind: CXToken_Identifier,
3232
};
3333

3434
/// A `_Noreturn` attribute.
3535
pub const NO_RETURN: Self = Self {
3636
name: b"_Noreturn",
37-
kind: CXCursor_UnexposedAttr,
37+
kind: None,
3838
token_kind: CXToken_Keyword,
3939
};
4040
}
@@ -678,11 +678,13 @@ impl Cursor {
678678
for (idx, attr) in attrs.iter().enumerate() {
679679
let found_attr = &mut found_attrs[idx];
680680
if !*found_attr {
681-
if kind == attr.kind &&
682-
cur.tokens().iter().any(|t| {
683-
t.kind == attr.token_kind &&
684-
t.spelling() == attr.name
685-
})
681+
// `attr.name` and` attr.token_kind` are checked against unexposed attributes only.
682+
if attr.kind.map_or(false, |k| k == kind) ||
683+
(kind == CXCursor_UnexposedAttr &&
684+
cur.tokens().iter().any(|t| {
685+
t.kind == attr.token_kind &&
686+
t.spelling() == attr.name
687+
}))
686688
{
687689
*found_attr = true;
688690
found_count += 1;

0 commit comments

Comments
 (0)