From 2bf260e14ad52769d8923fb250c5fe2d767290a8 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Thu, 15 Apr 2021 13:11:04 -0400 Subject: [PATCH] Support concretizing generics in template parameters --- c-bindings-gen/src/types.rs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/c-bindings-gen/src/types.rs b/c-bindings-gen/src/types.rs index 16f3ff5..acfcc1d 100644 --- a/c-bindings-gen/src/types.rs +++ b/c-bindings-gen/src/types.rs @@ -507,11 +507,20 @@ impl<'mod_lifetime, 'crate_lft: 'mod_lifetime> ImportResolver<'mod_lifetime, 'cr pub fn resolve_imported_refs(&self, mut ty: syn::Type) -> syn::Type { match &mut ty { syn::Type::Path(p) => { - if let Some(ident) = p.path.get_ident() { - if let Some((_, newpath)) = self.imports.get(ident) { - p.path = newpath.clone(); +eprintln!("rir {:?}", p); + if p.path.segments.len() != 1 { unimplemented!(); } + let mut args = p.path.segments[0].arguments.clone(); + if let syn::PathArguments::AngleBracketed(ref mut generics) = &mut args { + for arg in generics.args.iter_mut() { + if let syn::GenericArgument::Type(ref mut t) = arg { + *t = self.resolve_imported_refs(t.clone()); + } } - } else { unimplemented!(); } + } + if let Some((_, newpath)) = self.imports.get(single_ident_generic_path_to_ident(&p.path).unwrap()) { + p.path = newpath.clone(); + } + p.path.segments[0].arguments = args; }, syn::Type::Reference(r) => { r.elem = Box::new(self.resolve_imported_refs((*r.elem).clone())); -- 2.39.5