@@ -141,6 +141,9 @@ pub struct BindgenContext<'ctx> {
141
141
142
142
/// Whether a bindgen complex was generated
143
143
generated_bindegen_complex : Cell < bool > ,
144
+
145
+ /// Counter for making our generated names for anonymous named types unique.
146
+ anon_named_type_counter : usize ,
144
147
}
145
148
146
149
impl < ' ctx > BindgenContext < ' ctx > {
@@ -178,6 +181,7 @@ impl<'ctx> BindgenContext<'ctx> {
178
181
translation_unit : translation_unit,
179
182
options : options,
180
183
generated_bindegen_complex : Cell :: new ( false ) ,
184
+ anon_named_type_counter : 0 ,
181
185
} ;
182
186
183
187
me. add_item ( root_module, None , None ) ;
@@ -1145,6 +1149,33 @@ impl<'ctx> BindgenContext<'ctx> {
1145
1149
pub fn need_bindegen_complex_type ( & self ) -> bool {
1146
1150
self . generated_bindegen_complex . get ( )
1147
1151
}
1152
+
1153
+ /// We must generate a unique name for unnamed template parameters.
1154
+ ///
1155
+ /// For example:
1156
+ ///
1157
+ /// ```c++
1158
+ /// template <typename> Foo { int x; };
1159
+ /// ```
1160
+ ///
1161
+ /// Must become something like this:
1162
+ ///
1163
+ /// ```ignore
1164
+ /// struct Foo<__anon_named_type_36> {
1165
+ /// x: std::os::raw::c_int,
1166
+ /// _phantom_0: PhantomData<__anon_named_type_36>,
1167
+ /// }
1168
+ /// ```
1169
+ ///
1170
+ /// Ideally, this counter would only be locally unique within an Item's
1171
+ /// direct siblings, parent, and children. However, we currently construct
1172
+ /// these names at parse time, before each item has a local ID, and it isn't
1173
+ /// clear that the extant local ID is unique enough for this purpose.
1174
+ pub fn allocate_anon_named_type_id ( & mut self ) -> usize {
1175
+ let id = self . anon_named_type_counter ;
1176
+ self . anon_named_type_counter += 1 ;
1177
+ id
1178
+ }
1148
1179
}
1149
1180
1150
1181
/// An iterator over whitelisted items.
0 commit comments