Skip to content

Commit 45dd2ae

Browse files
Rohan Prinjaajnirp
Rohan Prinja
authored andcommitted
change return value of Type::pointee_type() to Option<Type>
1 parent 624c32c commit 45dd2ae

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
@@ -647,11 +647,19 @@ impl Type {
647647

648648
/// Given that this type is a pointer type, return the type that it points
649649
/// to.
650-
pub fn pointee_type(&self) -> Type {
651-
unsafe {
652-
Type {
653-
x: clang_getPointeeType(self.x),
650+
pub fn pointee_type(&self) -> Option<Type> {
651+
match self.kind() {
652+
CXType_Pointer |
653+
CXType_RValueReference |
654+
CXType_LValueReference |
655+
CXType_MemberPointer => {
656+
let ret = Type {
657+
x: unsafe { clang_getPointeeType(self.x) },
658+
};
659+
debug_assert!(ret.kind() != CXType_Invalid);
660+
Some(ret)
654661
}
662+
_ => None,
655663
}
656664
}
657665

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)