Skip to content

Commit 604965a

Browse files
author
bors-servo
authored
Auto merge of rust-lang#165 - jeanphilippeD:issue141, r=emilio
Return Option<Type> in clang::Type::ret_type fix rust-lang#141 Fixes rust-lang#141
2 parents 1460787 + 17494de commit 604965a

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
@@ -717,9 +717,12 @@ impl Type {
717717

718718
/// Given that this type is a function type, get the type of its return
719719
/// value.
720-
pub fn ret_type(&self) -> Type {
721-
unsafe {
722-
Type { x: clang_getResultType(self.x) }
720+
pub fn ret_type(&self) -> Option<Type> {
721+
let rt = Type { x: unsafe { clang_getResultType(self.x) } };
722+
if rt.kind() == CXType_Invalid {
723+
None
724+
} else {
725+
Some(rt)
723726
}
724727
}
725728

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 = try!(ty.ret_type().ok_or(ParseError::Continue));
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
@@ -500,7 +500,7 @@ impl Type {
500500
// tests/headers/func_ptr_in_struct.h), so we do a
501501
// guess here trying to see if it has a valid return
502502
// type.
503-
if ty.ret_type().kind() != CXType_Invalid {
503+
if ty.ret_type().is_some() {
504504
let signature =
505505
try!(FunctionSig::from_ty(ty, &location.unwrap_or(cursor), ctx));
506506
TypeKind::Function(signature)

0 commit comments

Comments
 (0)