rust-lang / rust-lang/rust-bindgen

Blacklisting doesn't hide inner types, and the template analysis gets confused.

Open
#1,559 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

A-templates bug
Dominant language
Rust
Stars
5.3k
Forks
829
Avg merge
1d 1h
Merged PRs (30d)
15

Description

Input C/C++ Header
template <typename T>
struct Transform {
  T t;
};

template <typename A, typename B, typename C>
struct TransformOp {
  A a;
  B b;
  C c;
  struct InterpolateMatrix_Body {
    Transform<TransformOp<A, B, C>> from;
    Transform<TransformOp<A, B, C>> to;
    A a;
  };
};
Bindgen Invocation
$ ./target/debug/bindgen t.hpp --blacklist-type TransformOp --blacklist-type Transform
Actual Results
#[repr(C)]
pub struct TransformOp_InterpolateMatrix_Body<A> {
    pub from: Transform<TransformOp<A, B, C>>,
    pub to: Transform<TransformOp<A, B, C>>,
    pub a: A,
    pub _phantom_0: ::std::marker::PhantomData<::std::cell::UnsafeCell<A>>,
}

Which as you can see uses the types B, and C, which we forget to append to the aliases. I think blacklisting something should stop generating all the inner types, but not sure if anybody relies on that.

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

Reproduce the output from t.hpp with the shown bindgen invocation and blacklists for TransformOp and Transform. Trace how blacklisting interacts with the generated InterpolateMatrix_Body inner type and its aliases, then verify that the resulting bindings no longer produce the inconsistent A-only alias output.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, rust
Domain
compilers, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.