diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-04-24 08:28:14 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-24 08:28:14 -0500 |
commit | ce8feb3262a26a24837a89a4702b606ebe705c8a (patch) | |
tree | 3b1b80c690de6591fc89529f16d8c80adae1ee88 | |
parent | 1cc2c64bb77f6e131b61c366011138c1cfeeaafd (diff) | |
parent | b8465342909b85e7b783f5ca098206cd8653941d (diff) |
Auto merge of #656 - emilio:fn-collision, r=fitzgen
codegen: Change forward-declared types to avoid collisions with functions.
Fixes #654
7 files changed, 38 insertions, 7 deletions
diff --git a/src/codegen/mod.rs b/src/codegen/mod.rs index a5df8945..39b115fa 100644 --- a/src/codegen/mod.rs +++ b/src/codegen/mod.rs @@ -1047,13 +1047,16 @@ impl CodeGenerator for CompInfo { // generate tuple struct if struct or union is a forward declaration, // skip for now if template parameters are needed. + // + // NB: We generate a proper struct to avoid struct/function name + // collisions. if self.is_forward_declaration() && used_template_params.is_none() { let struct_name = item.canonical_name(ctx); let struct_name = ctx.rust_ident_raw(&struct_name); let tuple_struct = quote_item!(ctx.ext_cx(), #[repr(C)] #[derive(Debug, Copy, Clone)] - pub struct $struct_name([u8; 0]); + pub struct $struct_name { _unused: [u8; 0] }; ) .unwrap(); result.push(tuple_struct); diff --git a/tests/expectations/tests/forward-declaration-autoptr.rs b/tests/expectations/tests/forward-declaration-autoptr.rs index b05984c8..d3729bed 100644 --- a/tests/expectations/tests/forward-declaration-autoptr.rs +++ b/tests/expectations/tests/forward-declaration-autoptr.rs @@ -6,7 +6,9 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct Foo([u8; 0]); +pub struct Foo { + _unused: [u8; 0], +} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct RefPtr<T> { diff --git a/tests/expectations/tests/forward_declared_complex_types.rs b/tests/expectations/tests/forward_declared_complex_types.rs index a6e67f7b..03330b2f 100644 --- a/tests/expectations/tests/forward_declared_complex_types.rs +++ b/tests/expectations/tests/forward_declared_complex_types.rs @@ -21,7 +21,9 @@ impl Clone for Foo_empty { } #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct Foo([u8; 0]); +pub struct Foo { + _unused: [u8; 0], +} #[repr(C)] #[derive(Debug, Copy)] pub struct Bar { @@ -51,14 +53,18 @@ extern "C" { } #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct Union([u8; 0]); +pub struct Union { + _unused: [u8; 0], +} extern "C" { #[link_name = "_Z9baz_unionP5Union"] pub fn baz_union(u: *mut Union); } #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct Quux([u8; 0]); +pub struct Quux { + _unused: [u8; 0], +} extern "C" { #[link_name = "_Z9baz_classP4Quux"] pub fn baz_class(q: *mut Quux); diff --git a/tests/expectations/tests/issue-654-struct-fn-collision.rs b/tests/expectations/tests/issue-654-struct-fn-collision.rs new file mode 100644 index 00000000..c2915b3f --- /dev/null +++ b/tests/expectations/tests/issue-654-struct-fn-collision.rs @@ -0,0 +1,14 @@ +/* automatically generated by rust-bindgen */ + + +#![allow(non_snake_case)] + + +#[repr(C)] +#[derive(Debug, Copy, Clone)] +pub struct foo { + _unused: [u8; 0], +} +extern "C" { + pub fn foo() -> ::std::os::raw::c_int; +} diff --git a/tests/expectations/tests/layout_array.rs b/tests/expectations/tests/layout_array.rs index 2cc85785..0f9944e8 100644 --- a/tests/expectations/tests/layout_array.rs +++ b/tests/expectations/tests/layout_array.rs @@ -10,7 +10,9 @@ pub const RTE_MEMPOOL_MAX_OPS_IDX: ::std::os::raw::c_uint = 16; pub const RTE_HEAP_NUM_FREELISTS: ::std::os::raw::c_uint = 13; #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct rte_mempool([u8; 0]); +pub struct rte_mempool { + _unused: [u8; 0], +} /** * Prototype for implementation specific data provisioning function. * diff --git a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs index 820b5e71..6ea05143 100644 --- a/tests/expectations/tests/same_struct_name_in_different_namespaces.rs +++ b/tests/expectations/tests/same_struct_name_in_different_namespaces.rs @@ -6,7 +6,9 @@ #[repr(C)] #[derive(Debug, Copy, Clone)] -pub struct JS_Zone([u8; 0]); +pub struct JS_Zone { + _unused: [u8; 0], +} #[repr(C)] #[derive(Debug, Default, Copy)] pub struct JS_shadow_Zone { diff --git a/tests/headers/issue-654-struct-fn-collision.h b/tests/headers/issue-654-struct-fn-collision.h new file mode 100644 index 00000000..f52a1b20 --- /dev/null +++ b/tests/headers/issue-654-struct-fn-collision.h @@ -0,0 +1,2 @@ +struct foo; +int foo(void); |