Skip to content

Commit 7f88e8e

Browse files
author
bors-servo
authored
Auto merge of #208 - Natim:123-clang-cursor-definition-option-cursor, r=emilio
clang::Cursor::definition should return Option<clang::Cursor> Fixes #123 Paired with @glasserc
2 parents b4d5338 + 42f1078 commit 7f88e8e

File tree

2 files changed

+7
-15
lines changed

2 files changed

+7
-15
lines changed

src/clang.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,11 +249,13 @@ impl Cursor {
249249
/// Given that this cursor's referent is a reference to another type, or is
250250
/// a declaration, get the cursor pointing to the referenced type or type of
251251
/// the declared thing.
252-
pub fn definition(&self) -> Cursor {
252+
pub fn definition(&self) -> Option<Cursor> {
253253
unsafe {
254-
Cursor {
254+
let ret = Cursor {
255255
x: clang_getCursorDefinition(self.x),
256-
}
256+
};
257+
258+
if ret.is_valid() { Some(ret) } else { None }
257259
}
258260
}
259261

src/ir/item.rs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -801,12 +801,7 @@ impl ClangItemParser for Item {
801801
// Types are sort of special, so to avoid parsing template classes
802802
// twice, handle them separately.
803803
{
804-
let definition = cursor.definition();
805-
let applicable_cursor = if definition.is_valid() {
806-
definition
807-
} else {
808-
cursor
809-
};
804+
let applicable_cursor = cursor.definition().unwrap_or(cursor);
810805
match Self::from_ty(&applicable_cursor.cur_type(),
811806
Some(applicable_cursor),
812807
parent_id,
@@ -937,12 +932,7 @@ impl ClangItemParser for Item {
937932

938933
let decl = {
939934
let decl = ty.declaration();
940-
let definition = decl.definition();
941-
if definition.is_valid() {
942-
definition
943-
} else {
944-
decl
945-
}
935+
decl.definition().unwrap_or(decl)
946936
};
947937

948938
let comment = decl.raw_comment()

0 commit comments

Comments
 (0)