Skip to content

Commit b285185

Browse files
author
bors-servo
authored
Auto merge of #191 - glasserc:specialized-optional, r=emilio
Make clang::Cursor::specialized return an Option Fixes #122. pair=@Natim
2 parents ff12c0c + 94136d2 commit b285185

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

src/clang.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ impl Cursor {
182182

183183
/// Is the referent a template specialization?
184184
pub fn is_template(&self) -> bool {
185-
self.specialized().is_valid()
185+
self.specialized().is_some()
186186
}
187187

188188
/// Is the referent a fully specialized template specialization without any
@@ -282,11 +282,12 @@ impl Cursor {
282282

283283
/// Given that this cursor points to a template specialization, get a cursor
284284
/// pointing to the template definition that is being specialized.
285-
pub fn specialized(&self) -> Cursor {
285+
pub fn specialized(&self) -> Option<Cursor> {
286286
unsafe {
287-
Cursor {
288-
x: clang_getSpecializedCursorTemplate(self.x),
289-
}
287+
let ret = Cursor {
288+
x: clang_getSpecializedCursorTemplate(self.x)
289+
};
290+
if ret.is_valid() { Some(ret) } else { None }
290291
}
291292
}
292293

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| {

0 commit comments

Comments
 (0)