summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTai Sassen-Liang <tsl@rupsvak.net>2016-11-07 00:19:12 +0100
committerTai Sassen-Liang <tsl@rupsvak.net>2016-11-20 18:20:30 +0100
commit9ac13adc1ff5a8f102b5efdce35411379a772a43 (patch)
tree202cb8c360e7e3954cafe91c03cc00ede9e073d5
parent1a8a2ac1c325487be455b434749c0b246f27e242 (diff)
clang::Cursor::enum_type should return an Option<Type>
Fixes issue #125
-rw-r--r--libbindgen/src/clang.rs7
-rw-r--r--libbindgen/src/ir/enum_ty.rs4
2 files changed, 6 insertions, 5 deletions
diff --git a/libbindgen/src/clang.rs b/libbindgen/src/clang.rs
index 6c95b22f..08c77b19 100644
--- a/libbindgen/src/clang.rs
+++ b/libbindgen/src/clang.rs
@@ -362,11 +362,12 @@ impl Cursor {
/// Get the integer representation type used to hold this cursor's referent
/// enum type.
- pub fn enum_type(&self) -> Type {
+ pub fn enum_type(&self) -> Option<Type> {
unsafe {
- Type {
+ let t = Type {
x: clang_getEnumDeclIntegerType(self.x),
- }
+ };
+ if t.kind() == CXType_Invalid { None } else { Some(t) }
}
}
diff --git a/libbindgen/src/ir/enum_ty.rs b/libbindgen/src/ir/enum_ty.rs
index 6085833d..0d4f955b 100644
--- a/libbindgen/src/ir/enum_ty.rs
+++ b/libbindgen/src/ir/enum_ty.rs
@@ -49,8 +49,8 @@ impl Enum {
}
let declaration = ty.declaration().canonical();
- let repr = Item::from_ty(&declaration.enum_type(), None, None, ctx)
- .ok();
+ let et = &declaration.enum_type().expect("This should be an enum since we checked above!");
+ let repr = Item::from_ty(et, None, None, ctx).ok();
let mut variants = vec![];
let is_signed = match repr {