File tree 4 files changed +57
-15
lines changed
4 files changed +57
-15
lines changed Original file line number Diff line number Diff line change @@ -320,23 +320,27 @@ impl<'ctx> BindgenContext<'ctx> {
320
320
let mut replacements = vec ! [ ] ;
321
321
322
322
for ( id, item) in self . items . iter ( ) {
323
+ // Calls to `canonical_name` are expensive, so eagerly filter out
324
+ // items that cannot be replaced.
323
325
let ty = match item. kind ( ) . as_type ( ) {
324
326
Some ( ty) => ty,
325
327
None => continue ,
326
328
} ;
327
329
328
- // canonical_name calls are expensive.
329
- let ci = match ty. as_comp ( ) {
330
- Some ( ci) => ci,
331
- None => continue ,
332
- } ;
333
-
334
- if ci. is_template_specialization ( ) {
335
- continue ;
330
+ match * ty. kind ( ) {
331
+ TypeKind :: Comp ( ref ci) if !ci. is_template_specialization ( ) => { }
332
+ TypeKind :: TemplateAlias ( _, _) |
333
+ TypeKind :: Alias ( _, _) => { }
334
+ _ => continue ,
336
335
}
337
336
338
- if let Some ( replacement) = self . replacements
339
- . get ( & item. canonical_name ( self ) ) {
337
+ let name = item. real_canonical_name ( self ,
338
+ self . options ( )
339
+ . enable_cxx_namespaces ,
340
+ true ) ;
341
+ let replacement = self . replacements . get ( & name) ;
342
+
343
+ if let Some ( replacement) = replacement {
340
344
if replacement != id {
341
345
// We set this just after parsing the annotation. It's
342
346
// very unlikely, but this can happen.
Original file line number Diff line number Diff line change @@ -539,11 +539,11 @@ impl Item {
539
539
///
540
540
/// This name should be derived from the immutable state contained in the
541
541
/// type and the parent chain, since it should be consistent.
542
- fn real_canonical_name ( & self ,
543
- ctx : & BindgenContext ,
544
- count_namespaces : bool ,
545
- for_name_checking : bool )
546
- -> String {
542
+ pub fn real_canonical_name ( & self ,
543
+ ctx : & BindgenContext ,
544
+ count_namespaces : bool ,
545
+ for_name_checking : bool )
546
+ -> String {
547
547
let base_name = match * self . kind ( ) {
548
548
ItemKind :: Type ( ref ty) => {
549
549
match * ty. kind ( ) {
Original file line number Diff line number Diff line change
1
+ /* automatically generated by rust-bindgen */
2
+
3
+
4
+ #![ allow( non_snake_case) ]
5
+
6
+
7
+ #[ repr( C ) ]
8
+ #[ derive( Debug , Copy , Clone ) ]
9
+ pub struct Rooted < T > {
10
+ pub ptr : MaybeWrapped < T > ,
11
+ }
12
+ /// But the replacement type does use T!
13
+ ///
14
+ /// <div rustbindgen replaces="MaybeWrapped" />
15
+ pub type MaybeWrapped < T > = T ;
Original file line number Diff line number Diff line change
1
+ // bindgen-flags: -- --std=c++14
2
+
3
+ namespace JS {
4
+ namespace detail {
5
+
6
+ // / Notice how this doesn't use T.
7
+ template <typename T>
8
+ using MaybeWrapped = int ;
9
+
10
+ }
11
+
12
+ template <typename T>
13
+ class Rooted {
14
+ detail::MaybeWrapped<T> ptr;
15
+ };
16
+
17
+ }
18
+
19
+ // / But the replacement type does use T!
20
+ // /
21
+ // / <div rustbindgen replaces="MaybeWrapped" />
22
+ template <typename T>
23
+ using replaces_MaybeWrapped = T;
You can’t perform that action at this time.
0 commit comments