Skip to content

Commit 08a34a1

Browse files
committed
Check resulting Cursor instead of the existing one
Thanks @fitzgen for the correction. This also allows us to simplify the is_template method. Thanks @emilio for the suggestion.
1 parent 5f92d86 commit 08a34a1

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/clang.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ impl Cursor {
187187

188188
/// Is the referent a template specialization?
189189
pub fn is_template(&self) -> bool {
190-
self.specialized().map_or(false, |c| c.is_valid())
190+
self.specialized().is_some()
191191
}
192192

193193
/// Is the referent a fully specialized template specialization without any
@@ -288,14 +288,15 @@ impl Cursor {
288288
/// Given that this cursor points to a template specialization, get a cursor
289289
/// pointing to the template definition that is being specialized.
290290
pub fn specialized(&self) -> Option<Cursor> {
291-
if !self.is_valid() {
292-
return None;
293-
}
294-
295291
unsafe {
296-
Some(Cursor {
297-
x: clang_getSpecializedCursorTemplate(self.x),
298-
})
292+
let clang_specialized = clang_getSpecializedCursorTemplate(self.x);
293+
if clang_isInvalid(clang_getCursorKind(clang_specialized)) == 0 {
294+
Some(Cursor {
295+
x: clang_specialized,
296+
})
297+
} else {
298+
None
299+
}
299300
}
300301
}
301302

0 commit comments

Comments
 (0)