rust-bindgen
rust-bindgen copied to clipboard
std::vector<int>::iterator creates trouble
Input C/C++ Header
#include <vector>
namespace MySpace {
std::vector<int>::iterator x;
}
Bindgen Invocation
bindgen::Builder::default()
.header("wrapper.hpp")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.clang_arg("-x")
.clang_arg("c++")
.opaque_type("std::.*")
.whitelist_var("MySpace::.*")
.whitelist_type("MySpace::.*")
.whitelist_function("MySpace::.*")
.generate()
.expect("Unable to generate bindings");
Actual Results
... 89 lines of code ...
pub type pointer = pointer;
pub type pointer = pointer;
pub type pointer = pointer;
pub type pointer = *mut ::std::os::raw::c_int;
If you try to compile this, you get:
error[E0428]: the name `pointer` is defined multiple times
--> /home/volker/Sync/git/latexrust/latex_to_symbolic/target/debug/build/latex_to_symbolic-2a7cee1167c646ae/out/bindings.rs:91:1
|
90 | pub type pointer = pointer;
| --------------------------- previous definition of the type `pointer` here
91 | pub type pointer = pointer;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `pointer` redefined here
|
= note: `pointer` must be defined only once in the type namespace of this module
error[E0428]: the name `pointer` is defined multiple times
--> /home/volker/Sync/git/latexrust/latex_to_symbolic/target/debug/build/latex_to_symbolic-2a7cee1167c646ae/out/bindings.rs:92:1
|
90 | pub type pointer = pointer;
| --------------------------- previous definition of the type `pointer` here
91 | pub type pointer = pointer;
92 | pub type pointer = pointer;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `pointer` redefined here
|
= note: `pointer` must be defined only once in the type namespace of this module
error[E0428]: the name `pointer` is defined multiple times
--> /home/volker/Sync/git/latexrust/latex_to_symbolic/target/debug/build/latex_to_symbolic-2a7cee1167c646ae/out/bindings.rs:93:1
|
90 | pub type pointer = pointer;
| --------------------------- previous definition of the type `pointer` here
...
93 | pub type pointer = *mut ::std::os::raw::c_int;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `pointer` redefined here
|
= note: `pointer` must be defined only once in the type namespace of this module
error[E0391]: cycle detected when processing `pointer`
--> /home/volker/Sync/git/latexrust/latex_to_symbolic/target/debug/build/latex_to_symbolic-2a7cee1167c646ae/out/bindings.rs:90:20
|
90 | pub type pointer = pointer;
| ^^^^^^^
|
= note: ...which again requires processing `pointer`, completing the cycle
note: cycle used when processing `MySpace_x`
--> /home/volker/Sync/git/latexrust/latex_to_symbolic/target/debug/build/latex_to_symbolic-2a7cee1167c646ae/out/bindings.rs:88:59
|
88 | pub static mut MySpace_x: __gnu_cxx___normal_iterator<pointer>;
| ^^^^^^^
Expected Results
No compile errors?
This might be, sadly, just a case of the STL not being supported very well by bindgen. See https://github.com/rust-lang/rust-bindgen/issues/1808#issuecomment-647197424 and https://github.com/rust-lang/rust-bindgen/issues/1597#issuecomment-526871534.
Yeah, these are not necessarily unfixable though :)
I think we should not generate a bunch of these constants #1838. Same goes for the typedefs.
I haven't been catching up lately with all the rust improvements, but chances are that a few of those can be "properly" supported with stuff inside generic impl blocks like:
impl<T> Generic<T> {
pub type Bar = Foo<T>;
}
Or such.
I appreciate a lot all the reduced test-cases @Volker-Weissmann, thank you!
What I did for my code is write a script that removes all pub type pointer = pointer;. It is a super hacky solution, but it worked so far.
@Volker-Weissmann Does adding pointer to block list solve this issue?
Idk, I don't work on this project anymore.
No worries, I had a similar issue because bindgen generates duplicate types (from typedef), basically two pub type iterator consecutively:
pub type iterator = root::std::_Bit_iterator;
I added iterator to blocklist the issue went away.