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

Denote types with unused template params.

Open adetaylor opened this issue 10 months ago • 0 comments

Downstream postprocessors such as autocxx may want to use bindgen's representation of types to generate additional C++ code. bindgen is remarkably faithful at passing through enough information to make this possible - but for some C++ types, bindgen chooses to elide some template parameters. It's not safe for additional C++ code to be generated which references that type.

This adds a callback by which such tools can recognize types where template parameters have been elided like this, so that extra C++ is avoided.

This information could be provided in the existing new_item_found callback, but it's very niche and unlikely to be used by the majority of consumers, so a new callback is added instead.

An alternative approach here is to provide a mode to bindgen where it always uses all template params, by adding additional PhantomData fields to structs where those params are not currently used. This is being prototyped in https://github.com/google/autocxx/pull/1425 but is unlikely to be successful, on the assumption that lots of the templated types can't actually be properly represented by bindgen/Rust, so the current strategy of discarding them is more likely to work in the broad strokes.

This PR is built on top of #3146, which in turn is on top of various others.

Part of https://github.com/google/autocxx/issues/124

adetaylor avatar Feb 22 '25 10:02 adetaylor