rust-bindgen icon indicating copy to clipboard operation
rust-bindgen copied to clipboard

Generated bindings don't compile

Open jeikabu opened this issue 5 years ago • 2 comments

bindgen 0.51.0

Input C/C++ Header

template <class, class Compare = int> class a { Compare b; };
namespace AZ {
template <class> struct c;
template <class e> struct EBusRouterPolicy {
  using d = c<typename e::f>;
  typedef a<d> Container;
};
} // namespace AZ

Bindgen Invocation

$ bindgen __bindgen.ii -- --std=c++14

Actual Results

/* automatically generated by rust-bindgen */

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct a<Compare> {
    pub b: Compare,
    pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<Compare>>,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct AZ_c {
    pub _address: u8,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct AZ_EBusRouterPolicy {
    pub _address: u8,
}
pub type AZ_EBusRouterPolicy_d = AZ_c;
pub type AZ_EBusRouterPolicy_Container = a<Compare>;

Compile above with rustc --crate-type lib:

error[E0412]: cannot find type `Compare` in this scope
  --> bindgen.rs:20:44
   |
20 | pub type AZ_EBusRouterPolicy_Container = a<Compare>;
   |                                            ^^^^^^^ not found in this scope

Expected Results

Last line of bindings should probably be:

pub type AZ_EBusRouterPolicy_Container<Compare> = a<Compare>;

jeikabu avatar Aug 13 '19 07:08 jeikabu

Thanks, nice test-case :)

I think this is bindgen getting confused about the dependent type...

emilio avatar Aug 31 '19 22:08 emilio

I happened to confirm that the same error (Compare "not found in scope") occurs as of v0.60.1.

kulp avatar Jun 07 '22 01:06 kulp