Skip to content

clang::Cursor::referenced should return Option<clang::Cursor> #232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/clang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Cursor> {
unsafe {
Cursor {
let ret = Cursor {
x: clang_getCursorReferenced(self.x),
}
};

if ret.is_valid() { Some(ret) } else { None }
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/ir/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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());
Expand Down