Closed
Description
Input C/C++ Header
typedef const struct foo {
void *bar;
} *foo;
Bindgen Invocation
$ bindgen --no-layout-tests log.h > log.rs
Actual Results
/* automatically generated by rust-bindgen 0.59.2 */
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct foo {
pub bar: *mut ::std::os::raw::c_void,
}
pub type foo = *const foo;
and/or
error[E0428]: the name `foo` is defined multiple times
--> log.rs:8:1
|
5 | pub struct foo {
| -------------- previous definition of the type `foo` here
...
8 | pub type foo = *const foo;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ `foo` redefined here
|
= note: `foo` must be defined only once in the type namespace of this module
warning: type `foo` should have an upper camel case name
--> log.rs:8:10
|
8 | pub type foo = *const foo;
| ^^^ help: convert the identifier to upper camel case (notice the capitalization): `Foo`
|
= note: `#[warn(non_camel_case_types)]` on by default
error[E0601]: `main` function not found in crate `log`
--> log.rs:8:27
|
8 | pub type foo = *const foo;
| ^ consider adding a `main` function to `log.rs`
error[E0391]: cycle detected when expanding type alias `foo`
--> log.rs:8:23
|
8 | pub type foo = *const foo;
| ^^^
|
= note: ...which immediately requires expanding type alias `foo` again
= note: type aliases cannot be recursive
= help: consider using a struct, enum, or union instead to break the cycle
= help: see <https://doc.rust-lang.org/reference/types.html#recursive-types> for more information
note: cycle used when computing type of `<impl at log.rs:4:10: 4:15>`
--> log.rs:4:10
|
4 | #[derive(Debug, Copy, Clone)]
| ^
= note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
error: aborting due to 3 previous errors; 1 warning emitted
Some errors have detailed explanations: E0391, E0428, E0601.
For more information about an error, try `rustc --explain E0391`.
Expected Results
I’m not quite sure, as the issue is that struct *
and *
are two “namespaces” in C, and not in C++ or Rust. One solution would be to rename either the pointer typedef or the struct, another would be to not include the pointer typedef at all (but then people might get confused why it isn’t present, so perhaps emit a warning as well?), or at least reject the input file altogether as the result won’t be well-formed anyway.
The project in question uses this hack when built under C++, so for my usecase I could #define __cplusplus
in order to run bindgen in C++ mode:
#ifdef __cplusplus
# define PL_STRUCT(name) struct name##_t
#else
# define PL_STRUCT(name) struct name
#endif
Metadata
Metadata
Assignees
Labels
No labels