summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2016-12-15 15:06:39 -0800
committerGitHub <noreply@github.com>2016-12-15 15:06:39 -0800
commit64038c3b33b0d1941ebbef57ed59772cf3007b93 (patch)
tree3297f5ecb1b27ffe3b01bbecf648720aeaf5d1b2
parent673cb5ff7555f2c026f4fbb6b8dfac0ff19e8725 (diff)
parent5417d97e3b791048628e0a97897f0f4312c11031 (diff)
Auto merge of #347 - impowski:typedef_type_cleanup, r=fitzgen
Wrap Type into Option Fix #129
-rw-r--r--libbindgen/src/clang.rs12
-rw-r--r--libbindgen/src/ir/ty.rs4
2 files changed, 8 insertions, 8 deletions
diff --git a/libbindgen/src/clang.rs b/libbindgen/src/clang.rs
index 3f272607..192ce09d 100644
--- a/libbindgen/src/clang.rs
+++ b/libbindgen/src/clang.rs
@@ -402,12 +402,12 @@ impl Cursor {
/// Given that this cursor's referent is a `typedef`, get the `Type` that is
/// being aliased.
- pub fn typedef_type(&self) -> Type {
- unsafe {
- Type {
- x: clang_getTypedefDeclUnderlyingType(self.x),
- }
- }
+ pub fn typedef_type(&self) -> Option<Type> {
+ let inner = Type {
+ x: unsafe { clang_getTypedefDeclUnderlyingType(self.x) }
+ };
+
+ if inner.is_valid() { Some(inner) } else { None }
}
/// Get the linkage kind for this cursor's referent.
diff --git a/libbindgen/src/ir/ty.rs b/libbindgen/src/ir/ty.rs
index 58ac7c87..3d379969 100644
--- a/libbindgen/src/ir/ty.rs
+++ b/libbindgen/src/ir/ty.rs
@@ -660,7 +660,7 @@ impl Type {
name = current.spelling();
- let inner_ty = cur.typedef_type();
+ let inner_ty = cur.typedef_type().expect("Not valid Type?");
inner = Item::from_ty(
&inner_ty,
Some(cur),
@@ -825,7 +825,7 @@ impl Type {
TypeKind::Function(signature)
}
CXType_Typedef => {
- let inner = cursor.typedef_type();
+ let inner = cursor.typedef_type().expect("Not valid Type?");
let inner =
Item::from_ty_or_ref(inner, location, parent_id, ctx);
TypeKind::Alias(ty.spelling(), inner)