rust-lang / rust-lang/rust-bindgen

std::vector<int>::iterator creates trouble

Open
#1,839 7 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-C++ A-templates bug help wanted
Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

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?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue using wrapper.hpp and the shown bindgen::Builder configuration, then inspect the generated bindings around MySpace_x and __gnu_cxx___normal_iterator. Trace why repeated pointer aliases are emitted for std::vector::iterator. Done means the same input generates bindings that compile without duplicate definitions or the pointer cycle.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.