Skip to content

Commit 5f92d86

Browse files
committed
Make clang::Cursor::specialized return an Option
Fixes rust-lang#122.
1 parent ff53d7a commit 5f92d86

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/clang.rs

+8-4
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().is_valid()
190+
self.specialized().map_or(false, |c| c.is_valid())
191191
}
192192

193193
/// Is the referent a fully specialized template specialization without any
@@ -287,11 +287,15 @@ impl Cursor {
287287

288288
/// Given that this cursor points to a template specialization, get a cursor
289289
/// pointing to the template definition that is being specialized.
290-
pub fn specialized(&self) -> Cursor {
290+
pub fn specialized(&self) -> Option<Cursor> {
291+
if !self.is_valid() {
292+
return None;
293+
}
294+
291295
unsafe {
292-
Cursor {
296+
Some(Cursor {
293297
x: clang_getSpecializedCursorTemplate(self.x),
294-
}
298+
})
295299
}
296300
}
297301

src/ir/comp.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,8 @@ impl CompInfo {
512512
}
513513
};
514514

515-
ci.ref_template = Item::parse(cursor.specialized(), None, ctx).ok();
515+
ci.ref_template = cursor.specialized()
516+
.and_then(|c| Item::parse(c, None, ctx).ok());
516517

517518
let mut maybe_anonymous_struct_field = None;
518519
cursor.visit(|cur, _other| {

0 commit comments

Comments
 (0)