rust-lang / rust-lang/rust-bindgen
Bindings fail to compile with "the name ... is defined multiple times" and "cycle detected when computing type of ..."
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
c++ header
template <typename> struct a { typedef int b; };
template <typename = a<int>> class c;
template <typename e> class c {
typedef typename e::b b;
c &d(long, b);
};
template <> c<> &c<>::d(long, b);
bindgen test-case-4.hpp -- -x c++ produces
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct a {
pub _address: u8,
}
pub type a_b = ::std::os::raw::c_int;
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct c {
pub _address: u8,
}
pub type c_b = [u8; 0usize];
pub type b = b;
pub type b = ::std::os::raw::c_int;
`rustc --crate-type lib bindings.rs``` produces
error[E0428]: the name `b` is defined multiple times
--> bindings.rs:16:1
|
15 | pub type b = b;
| --------------- previous definition of the type `b` here
16 | pub type b = ::std::os::raw::c_int;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `b` redefined here
|
= note: `b` must be defined only once in the type namespace of this module
error[E0391]: cycle detected when computing type of `b`
--> bindings.rs:15:14
|
15 | pub type b = b;
| ^
|
= note: ...which again requires computing type of `b`, completing the cycle
note: cycle used when collecting item types in top-level module
--> bindings.rs:3:1
|
3 | / #[repr(C)]
4 | | #[derive(Debug, Copy, Clone)]
5 | | pub struct a {
6 | | pub _address: u8,
... |
15 | | pub type b = b;
16 | | pub type b = ::std::os::raw::c_int;
| |___________________________________^
This might be template specialization (my c++ is really poor) and so not expected to work. I wish bindgen would warn me that that was taking place instead of producing bindings that can't compile.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with test-case-4.hpp using bindgen test-case-4.hpp -- -x c++, then compile the generated bindings.rs with rustc. Inspect how the C++ template declarations produce the duplicate b aliases and the self-referential alias. Done means the unsupported case is handled with a clear warning or otherwise no longer produces uncompilable bindings.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, rust
- Domain
- compilers, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100