Skip to content

Commit 63f8296

Browse files
author
bors-servo
authored
Auto merge of rust-lang#163 - catdesk:master, r=KiChjang
Change clang::Type::num_elements to return Option Fixes rust-lang#139.
2 parents c15e221 + 7dac420 commit 63f8296

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
@@ -681,7 +681,7 @@ impl Type {
681681
CXType_ConstantArray => {
682682
let inner = Item::from_ty(&ty.elem_type(), location, parent_id, ctx)
683683
.expect("Not able to resolve array element?");
684-
TypeKind::Array(inner, ty.num_elements())
684+
TypeKind::Array(inner, ty.num_elements().unwrap())
685685
}
686686
// A complex number is always a real and an imaginary part, so
687687
// represent that as a two-item array.

0 commit comments

Comments
 (0)