rust-lang / rust-lang/rust-bindgen

Inner types are not qualified by namespace so may conflict

Open
#2,056 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

Input C/C++ Header
template <typename b> class c {
public:
  using iterator = b;
};
namespace e {
class d;
class f {
  typedef c<d>::iterator iterator;
};
} // namespace e
namespace g {
class i;
class h {
  typedef c<i>::iterator iterator;
};
} // namespace g
Bindgen Invocation
$ ~/bindgen/target/release/bindgen  anon-doubled.h   "--allowlist-type" e::f "--allowlist-type"  g::h "--enable-cxx-namespaces"  "--" "-x" "c++" "-std=c++14"
Actual Results
/* automatically generated by rust-bindgen 0.58.1 */

#[allow(non_snake_case, non_camel_case_types, non_upper_case_globals)]
pub mod root {
    #[allow(unused_imports)]
    use self::super::root;
    pub mod e {
        #[allow(unused_imports)]
        use self::super::super::root;
        #[repr(C)]
        pub struct d {
            _unused: [u8; 0],
        }
        #[repr(C)]
        pub struct f {
            pub _address: u8,
        }
        pub type f_iterator = root::iterator;
    }
    pub mod g {
        #[allow(unused_imports)]
        use self::super::super::root;
        #[repr(C)]
        pub struct i {
            _unused: [u8; 0],
        }
        #[repr(C)]
        pub struct h {
            pub _address: u8,
        }
        pub type h_iterator = root::iterator;
    }
    pub type iterator = root::e::d;
    pub type iterator = root::g::i;
}

(layout tests and derives omitted for clarity)

error[E0428]: the name `iterator` is defined multiple times
  --> src/lib.rs:34:5
   |
33 |     pub type iterator = root::e::d;
   |     ------------------------------- previous definition of the type `iterator` here
34 |     pub type iterator = root::g::i;
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `iterator` redefined here
   |
   = note: `iterator` must be defined only once in the type namespace of this module

error: aborting due to previous error

For more information about this error, try `rustc --explain E0428`.
Expected Results

Two definitions of iterator should not be emitted in the root namespace.

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

Start with the minimal C++ header and bindgen invocation shown in the issue, then trace the namespace and inner-type emission that produces both root::iterator aliases. Done means the generated Rust bindings keep the two iterator definitions qualified without duplicate names in the root namespace.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
devtools
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.