Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated code for inner class of template-class doesn't use type-parameter #1514

Closed
karroffel opened this issue Feb 4, 2019 · 3 comments
Closed

Comments

@karroffel
Copy link

While trying to generate bindings for a bigger file I encountered a Rust-compile error when compiling the binding code.

The generated code generally looks good, the only problem is that a type parameter for a generated struct is not applied.

Inside a template class I defined two inner-classes. Since the template parameters applies to inner items as well, the inner classes are not explicitly parameterized.

The problem occurs when one inner class inherits the other (which makes use of the template arg).

Input C/C++ Header

template<typename T>
struct Thing {
    struct Inner {
        T *ptr;
    };

    struct AnotherInner : Inner {
    };
};

Bindgen Invocation

bindgen::Builder::default()
    .header("test.hpp")
    .generate()
    .unwrap()

Actual Results

/* automatically generated by rust-bindgen */

#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Thing {
    pub _address: u8,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Thing_Inner<T> {
    pub ptr: *mut T,
    pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Thing_AnotherInner<T> {
    pub _base: Thing_Inner,
    pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
}

Compile error:

error[E0107]: wrong number of type arguments: expected 1, found 0
  --> ...project/target/debug/build/the-project-8f7347729392ec63/out/bindings.rs:17:16
   |
17 |     pub _base: Thing_Inner,
   |                ^^^^^^^^^^^ expected 1 type argument

error: aborting due to previous error

Expected Results

The field _base of the Thing_AnotherInner should have the type parameter applied.

When manually changing line 17 to pub _base: Thing_Inner<T>, it compiles fine.

@emilio
Copy link
Contributor

emilio commented Feb 4, 2019

Ah, nice catch, this should be easy enough to fix :)

@emilio
Copy link
Contributor

emilio commented Feb 4, 2019

Also, thanks so much for the reduced test-case!

@karroffel
Copy link
Author

Wow that was quick, amazing! Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants