Skip to content

Inner types are not qualified by namespace so may conflict #2056

Open
@adetaylor

Description

@adetaylor

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions