rust-lang / rust-lang/rust-bindgen
Aliases to template instantiations don't work
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5.3k
- Forks
- 829
- Avg merge
- 1d 1h
- Merged PRs (30d)
- 15
Description
As alluded to here, libclang doesn't expose any API for us to get the arguments to the template instantiation when it is the aliased type of a type alias.
Input C/C++ Header
template <class T, class U>
struct Thing {
T t;
U u;
};
template <class V>
using IntThing = Thing<int, V>;
Bindgen Invocation
$ bindgen input.h -- -std=c++14
Actual Results
/* automatically generated by rust-bindgen */
#[repr(C)]
#[derive(Debug, Copy, Clone)]
pub struct Thing<T, U> {
pub t: T,
pub u: U,
pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<T>>,
pub _phantom_1: ::std::marker::PhantomData<::std::cell::UnsafeCell<U>>,
}
pub type IntThing = Thing<T, U>;
Which fails to compile since T and U are not generic parameters in scope.
Expected Results
pub type IntThing<V> = Thing<int, V>;
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked context.rs location and reproduce the issue using the input.h template and bindgen input.h -- -std=c++14. Compare the generated IntThing alias with the expected generic alias, and consider the missing template arguments exposed by libclang. Done means the generated alias includes V and expands to Thing<int, V> without unresolved T or U.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100