diff --git a/src/ir/var.rs b/src/ir/var.rs index 921dcf98c7..e55308ce35 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 0000000000..77dec91845 --- /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 0000000000..a337881f52 --- /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 4824f48457..7095068a11 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(),