rust-bindgen
rust-bindgen copied to clipboard
Binding for const <typedef-ed array type> has incorrect mutability
Input C/C++ Header
typedef int int1[1];
void f(const int1 x);
Bindgen Invocation
$ bindgen test.h
Actual Results
/* automatically generated by rust-bindgen 0.56.0 */
pub type int1 = [::std::os::raw::c_int; 1usize];
extern "C" {
pub fn f(x: *mut ::std::os::raw::c_int);
}
Expected Results
The type of the parameter x
should be *const ::std::os::raw::c_int
:
/* automatically generated by rust-bindgen 0.56.0 */
pub type int1 = [::std::os::raw::c_int; 1usize];
extern "C" {
pub fn f(x: *const ::std::os::raw::c_int);
}
It appears that we need to propagate self.is_const
here:
https://github.com/rust-lang/rust-bindgen/blob/2aed6b0216805e27228ed39988ffe1a1ffd7e940/src/ir/ty.rs#L324-L328
But that is not possible because the method returns the canonical type by reference.
Are there any workarounds for this? I'm using bindgen on some large-ish libraries and most of the binding arguments are mutable when they should be const
. Manually correcting them takes a very long time, but it's the only fix I have for now.
Here's an example if it helps: https://github.com/wjyoumans/arb-sys/issues/2