diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-02-14 01:18:26 +0100 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2017-02-14 01:23:14 +0100 |
commit | af6d59c29a9b7a4c43ae857eb03b653cf598c852 (patch) | |
tree | f14ab3827366fdd27545e9fde76f84c2ad17de1a | |
parent | c8f1855e31475876faa7f481a8b0ec606f4ed3dc (diff) |
codegen: Use the constness of the inner type when converting array function arguments.
Fixes https://github.com/servo/rust-bindgen/issues/509
I'm actually surprised we had no tests for this.
Signed-off-by: Emilio Cobos Álvarez <emilio@crisal.io>
-rw-r--r-- | src/codegen/mod.rs | 2 | ||||
-rw-r--r-- | tests/expectations/tests/const_array_fn_arg.rs | 9 | ||||
-rw-r--r-- | tests/headers/const_array_fn_arg.h | 1 |
3 files changed, 11 insertions, 1 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index 99400f7a..d5c38aa8 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -2828,7 +2828,7 @@ mod utils { // [1]: http://c0x.coding-guidelines.com/6.7.5.3.html let arg_ty = match *arg_ty.canonical_type(ctx).kind() { TypeKind::Array(t, _) => { - t.to_rust_ty(ctx).to_ptr(arg_ty.is_const(), ctx.span()) + t.to_rust_ty(ctx).to_ptr(ctx.resolve_type(t).is_const(), ctx.span()) }, TypeKind::Pointer(inner) => { let inner = ctx.resolve_item(inner); diff --git a/tests/expectations/tests/const_array_fn_arg.rs b/tests/expectations/tests/const_array_fn_arg.rs new file mode 100644 index 00000000..623d28b2 --- /dev/null +++ b/tests/expectations/tests/const_array_fn_arg.rs @@ -0,0 +1,9 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +extern "C" { + pub fn f(a: *const ::std::os::raw::c_int); +} diff --git a/tests/headers/const_array_fn_arg.h b/tests/headers/const_array_fn_arg.h new file mode 100644 index 00000000..ebe22861 --- /dev/null +++ b/tests/headers/const_array_fn_arg.h @@ -0,0 +1 @@ +void f(const int a[]); |