diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-11-23 15:35:30 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-23 15:35:30 -0800 |
commit | 7d6cc9a96d9011f089feaac45264ae955215b7d9 (patch) | |
tree | a3276bbadaa78e590918d434e3866575f125b950 | |
parent | dad1fd3ca15d116f422a1db91c9796c22fd38e40 (diff) | |
parent | 27eea057f029ec8ceada1b0718888a4cbe6ce206 (diff) |
Auto merge of #285 - tsliang:issue-125, r=emilio
clang::Cursor::enum_type should return an Option<Type>
Returning an Option<Type> relieves callers from having to check whether clang::Cursor::enum_type returns `CXType_Invalid`.
Fixes #125
-rw-r--r-- | libbindgen/src/clang.rs | 7 | ||||
-rw-r--r-- | libbindgen/src/ir/enum_ty.rs | 5 |
2 files changed, 7 insertions, 5 deletions
diff --git a/libbindgen/src/clang.rs b/libbindgen/src/clang.rs index a11903aa..72069644 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.is_valid() { Some(t) } else { None } } } diff --git a/libbindgen/src/ir/enum_ty.rs b/libbindgen/src/ir/enum_ty.rs index 6085833d..f728b22a 100644 --- a/libbindgen/src/ir/enum_ty.rs +++ b/libbindgen/src/ir/enum_ty.rs @@ -49,8 +49,9 @@ impl Enum { } let declaration = ty.declaration().canonical(); - let repr = Item::from_ty(&declaration.enum_type(), None, None, ctx) - .ok(); + let repr = declaration.enum_type().and_then(|et| { + Item::from_ty(&et, None, None, ctx).ok() + }); let mut variants = vec![]; let is_signed = match repr { |