summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ir/var.rs8
-rw-r--r--tests/expectations/tests/const_array.rs15
-rw-r--r--tests/headers/const_array.h2
-rw-r--r--tests/tests.rs4
4 files changed, 25 insertions, 4 deletions
diff --git a/src/ir/var.rs b/src/ir/var.rs
index 921dcf98..e55308ce 100644
--- a/src/ir/var.rs
+++ b/src/ir/var.rs
@@ -232,8 +232,12 @@ impl ClangSubItemParser for Var {
let ty = cursor.cur_type();
- // XXX this is redundant, remove!
- let is_const = ty.is_const();
+ // TODO(emilio): do we have to special-case constant arrays in
+ // some other places?
+ let is_const = ty.is_const() ||
+ (ty.kind() == CXType_ConstantArray &&
+ ty.elem_type()
+ .map_or(false, |element| element.is_const()));
let ty = match Item::from_ty(&ty, cursor, None, ctx) {
Ok(ty) => ty,
diff --git a/tests/expectations/tests/const_array.rs b/tests/expectations/tests/const_array.rs
new file mode 100644
index 00000000..77dec918
--- /dev/null
+++ b/tests/expectations/tests/const_array.rs
@@ -0,0 +1,15 @@
+/* automatically generated by rust-bindgen */
+
+#![allow(
+ dead_code,
+ non_snake_case,
+ non_camel_case_types,
+ non_upper_case_globals
+)]
+
+extern "C" {
+ pub static foo: [::std::os::raw::c_int; 1usize];
+}
+extern "C" {
+ pub static mut bar: [::std::os::raw::c_int; 1usize];
+}
diff --git a/tests/headers/const_array.h b/tests/headers/const_array.h
new file mode 100644
index 00000000..a337881f
--- /dev/null
+++ b/tests/headers/const_array.h
@@ -0,0 +1,2 @@
+extern const int foo[1];
+extern int bar[1];
diff --git a/tests/tests.rs b/tests/tests.rs
index 4824f484..7095068a 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -353,10 +353,10 @@ fn test_clang_env_args() {
"/* automatically generated by rust-bindgen */
extern \"C\" {
- pub static mut x: [::std::os::raw::c_int; 1usize];
+ pub static x: [::std::os::raw::c_int; 1usize];
}
extern \"C\" {
- pub static mut y: [::std::os::raw::c_int; 1usize];
+ pub static y: [::std::os::raw::c_int; 1usize];
}
"
.to_string(),