Skip to content

Commit 823abd5

Browse files
author
bors-servo
authored
Auto merge of #203 - ajnirp:137-pointee-type, r=emilio
change return value of Type::pointee_type() to Option<Type> Fixes #137
2 parents 9073a4f + 45dd2ae commit 823abd5

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

src/clang.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -639,11 +639,19 @@ impl Type {
639639

640640
/// Given that this type is a pointer type, return the type that it points
641641
/// to.
642-
pub fn pointee_type(&self) -> Type {
643-
unsafe {
644-
Type {
645-
x: clang_getPointeeType(self.x),
642+
pub fn pointee_type(&self) -> Option<Type> {
643+
match self.kind() {
644+
CXType_Pointer |
645+
CXType_RValueReference |
646+
CXType_LValueReference |
647+
CXType_MemberPointer => {
648+
let ret = Type {
649+
x: unsafe { clang_getPointeeType(self.x) },
650+
};
651+
debug_assert!(ret.kind() != CXType_Invalid);
652+
Some(ret)
646653
}
654+
_ => None,
647655
}
648656
}
649657

src/ir/ty.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -677,21 +677,19 @@ impl Type {
677677
// process of resolving them.
678678
CXType_MemberPointer |
679679
CXType_Pointer => {
680-
let inner = Item::from_ty_or_ref(ty.pointee_type(),
681-
location,
682-
parent_id,
683-
ctx);
680+
let inner =
681+
Item::from_ty_or_ref(ty.pointee_type().unwrap(), location,
682+
parent_id, ctx);
684683
TypeKind::Pointer(inner)
685684
}
686685
CXType_BlockPointer => TypeKind::BlockPointer,
687686
// XXX: RValueReference is most likely wrong, but I don't think we
688687
// can even add bindings for that, so huh.
689688
CXType_RValueReference |
690689
CXType_LValueReference => {
691-
let inner = Item::from_ty_or_ref(ty.pointee_type(),
692-
location,
693-
parent_id,
694-
ctx);
690+
let inner =
691+
Item::from_ty_or_ref(ty.pointee_type().unwrap(), location,
692+
parent_id, ctx);
695693
TypeKind::Reference(inner)
696694
}
697695
// XXX DependentSizedArray is wrong

0 commit comments

Comments
 (0)