Open
Description
I have encountered a C header file like the following in the wild:
struct A { int x; };
typedef struct A B;
struct B;
void foo(B *b);
When I run rust-bindgen
on this and try to compile the resulting Rust, I get a type error due to a redefinition of B
:
$ bindgen test.h > test.rs
$ cat test.rs
[ ... ]
pub type B = A;
[ ... ]
struct B { [ ... ] }
$ rustc test.rs
error[E0428]: the name `B` is defined multiple times
--> test.rs:17:1
|
14 | pub type B = A;
| --------------- previous definition of the type `B` here
...
17 | pub struct B {
| ^^^^^^^^^^^^ `B` redefined here
|
= note: `B` must be defined only once in the type namespace of this module
The root problem appears to be that the struct-tag namespace and the type namespace, which are distinct in C, are both projected into the type namespace in Rust, so a name conflict occurs. The C code above is weird and probably doesn't do what the author intends, but it is valid C. For now I've made an edit to the header file, but it would be nice if rust-bindgen would either produce an error in this case, choose one of the definitions, or rename one (B
and __struct_B
for example?) to avoid the conflict.
Metadata
Metadata
Assignees
Labels
No labels
Activity