diff --git a/src/clang.rs b/src/clang.rs index 1239753463..315d87a0ae 100755 --- a/src/clang.rs +++ b/src/clang.rs @@ -263,11 +263,13 @@ impl Cursor { /// Given that this cursor's referent is reference type, get the cursor /// pointing to the referenced type. - pub fn referenced(&self) -> Cursor { + pub fn referenced(&self) -> Option { unsafe { - Cursor { + let ret = Cursor { x: clang_getCursorReferenced(self.x), - } + }; + + if ret.is_valid() { Some(ret) } else { None } } } diff --git a/src/ir/ty.rs b/src/ir/ty.rs index 77dc61be6d..09961637c4 100644 --- a/src/ir/ty.rs +++ b/src/ir/ty.rs @@ -612,7 +612,7 @@ impl Type { TypeKind::TemplateAlias(inner.unwrap(), args) } CXCursor_TemplateRef => { - let referenced = location.referenced(); + let referenced = location.referenced().expect("expected value, got none"); let referenced_ty = referenced.cur_type(); let referenced_declaration = Some(referenced_ty.declaration()); @@ -624,7 +624,7 @@ impl Type { ctx); } CXCursor_TypeRef => { - let referenced = location.referenced(); + let referenced = location.referenced().expect("expected value, got none"); let referenced_ty = referenced.cur_type(); let referenced_declaration = Some(referenced_ty.declaration());