Skip to content

Commit d98f19f

Browse files
committed
Return Option<Type> in clang::Type::ret_type fix rust-lang#141
1 parent f7b5fae commit d98f19f

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

src/clang.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,12 @@ impl Type {
714714

715715
/// Given that this type is a function type, get the type of its return
716716
/// value.
717-
pub fn ret_type(&self) -> Type {
718-
unsafe {
719-
Type { x: clang_getResultType(self.x) }
717+
pub fn ret_type(&self) -> Option<Type> {
718+
let rt = unsafe { Type { x: clang_getResultType(self.x) } };
719+
if rt.kind() == CXType_Invalid {
720+
None
721+
} else {
722+
Some(rt)
720723
}
721724
}
722725

src/ir/function.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,8 @@ impl FunctionSig {
186186
}
187187
}
188188

189-
let ret = try!(Item::from_ty(&ty.ret_type(), None, None, ctx));
189+
let ty_ret_type = ty.ret_type().expect("Expected a valid return type");
190+
let ret = try!(Item::from_ty(&ty_ret_type, None, None, ctx));
190191
let abi = get_abi(ty.call_conv());
191192

192193
Ok(Self::new(ret, args, ty.is_variadic(), abi))

src/ir/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ impl Type {
498498
// tests/headers/func_ptr_in_struct.h), so we do a
499499
// guess here trying to see if it has a valid return
500500
// type.
501-
if ty.ret_type().kind() != CXType_Invalid {
501+
if ty.ret_type().is_some() {
502502
let signature =
503503
try!(FunctionSig::from_ty(ty, &location.unwrap_or(cursor), ctx));
504504
TypeKind::Function(signature)

0 commit comments

Comments
 (0)