rust-lang / rust-lang/rust-bindgen

Aliases to template instantiations don't work

Open
#931 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-C++ A-libclang A-templates I-bogus-codegen
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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.