Skip to content

Commit 7dac420

Browse files
catdeskKiChjang
authored andcommitted
Change clang::Type::num_elements to return Option
1 parent f7b5fae commit 7dac420

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/clang.rs

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

679679
/// Given that this type is an array or vector type, return its number of
680680
/// elements.
681-
pub fn num_elements(&self) -> usize {
682-
unsafe {
683-
clang_getNumElements(self.x) as usize
681+
pub fn num_elements(&self) -> Option<usize> {
682+
let num_elements_returned = unsafe { clang_getNumElements(self.x) };
683+
if num_elements_returned != -1 {
684+
Some(num_elements_returned as usize)
685+
} else {
686+
None
684687
}
685688
}
686689

src/ir/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,7 +673,7 @@ impl Type {
673673
CXType_ConstantArray => {
674674
let inner = Item::from_ty(&ty.elem_type(), location, parent_id, ctx)
675675
.expect("Not able to resolve array element?");
676-
TypeKind::Array(inner, ty.num_elements())
676+
TypeKind::Array(inner, ty.num_elements().unwrap())
677677
}
678678
// A complex number is always a real and an imaginary part, so
679679
// represent that as a two-item array.

0 commit comments

Comments
 (0)