summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEthan Glasser-Camp <ethan@betacantrips.com>2016-11-02 13:05:22 -0400
committerEthan Glasser-Camp <ethan@betacantrips.com>2016-11-02 13:05:22 -0400
commit08a34a1eb5b8b21981cde35af1897cc9269e5a8e (patch)
tree59d09eb38be6d1af3f769589e88298be83eef7b2 /src
parent5f92d86a3c88c47817e061bb2870e917757a738c (diff)
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.
Diffstat (limited to 'src')
-rwxr-xr-xsrc/clang.rs17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/clang.rs b/src/clang.rs
index bbe0648d..3f23cbb6 100755
--- a/src/clang.rs
+++ b/src/clang.rs
@@ -187,7 +187,7 @@ impl Cursor {
/// Is the referent a template specialization?
pub fn is_template(&self) -> bool {
- self.specialized().map_or(false, |c| c.is_valid())
+ self.specialized().is_some()
}
/// Is the referent a fully specialized template specialization without any
@@ -288,14 +288,15 @@ impl Cursor {
/// Given that this cursor points to a template specialization, get a cursor
/// pointing to the template definition that is being specialized.
pub fn specialized(&self) -> Option<Cursor> {
- if !self.is_valid() {
- return None;
- }
-
unsafe {
- Some(Cursor {
- x: clang_getSpecializedCursorTemplate(self.x),
- })
+ let clang_specialized = clang_getSpecializedCursorTemplate(self.x);
+ if clang_isInvalid(clang_getCursorKind(clang_specialized)) == 0 {
+ Some(Cursor {
+ x: clang_specialized,
+ })
+ } else {
+ None
+ }
}
}