Skip to content

Commit 64038c3

Browse files
author
bors-servo
authored
Auto merge of #347 - impowski:typedef_type_cleanup, r=fitzgen
Wrap Type into Option Fix #129
2 parents 673cb5f + 5417d97 commit 64038c3

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

libbindgen/src/clang.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,12 +402,12 @@ impl Cursor {
402402

403403
/// Given that this cursor's referent is a `typedef`, get the `Type` that is
404404
/// being aliased.
405-
pub fn typedef_type(&self) -> Type {
406-
unsafe {
407-
Type {
408-
x: clang_getTypedefDeclUnderlyingType(self.x),
409-
}
410-
}
405+
pub fn typedef_type(&self) -> Option<Type> {
406+
let inner = Type {
407+
x: unsafe { clang_getTypedefDeclUnderlyingType(self.x) }
408+
};
409+
410+
if inner.is_valid() { Some(inner) } else { None }
411411
}
412412

413413
/// Get the linkage kind for this cursor's referent.

libbindgen/src/ir/ty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ impl Type {
660660

661661
name = current.spelling();
662662

663-
let inner_ty = cur.typedef_type();
663+
let inner_ty = cur.typedef_type().expect("Not valid Type?");
664664
inner = Item::from_ty(
665665
&inner_ty,
666666
Some(cur),
@@ -825,7 +825,7 @@ impl Type {
825825
TypeKind::Function(signature)
826826
}
827827
CXType_Typedef => {
828-
let inner = cursor.typedef_type();
828+
let inner = cursor.typedef_type().expect("Not valid Type?");
829829
let inner =
830830
Item::from_ty_or_ref(inner, location, parent_id, ctx);
831831
TypeKind::Alias(ty.spelling(), inner)

0 commit comments

Comments
 (0)