From f8adf539c6ff1094dd40fb41ae29d056cad536b9 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Wed, 22 Jun 2022 19:30:05 +0000 Subject: [PATCH] Add where-clause generic params to `default_generics` map This moves yet more generic resolution to being able to rely on the `default_generics` map for full-`Type` resolution rather than string-based name resolution. --- c-bindings-gen/src/types.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/c-bindings-gen/src/types.rs b/c-bindings-gen/src/types.rs index c532b81..2ea9221 100644 --- a/c-bindings-gen/src/types.rs +++ b/c-bindings-gen/src/types.rs @@ -268,7 +268,8 @@ impl<'a, 'p: 'a> GenericTypes<'a, 'p> { if p.qself.is_some() { return false; } if p.path.leading_colon.is_some() { return false; } let mut p_iter = p.path.segments.iter(); - if let Some(gen) = new_typed_generics.get_mut(&p_iter.next().unwrap().ident) { + let p_ident = &p_iter.next().unwrap().ident; + if let Some(gen) = new_typed_generics.get_mut(p_ident) { if gen.is_some() { return false; } if &format!("{}", p_iter.next().unwrap().ident) != "Target" {return false; } @@ -281,7 +282,16 @@ impl<'a, 'p: 'a> GenericTypes<'a, 'p> { if non_lifetimes_processed { return false; } non_lifetimes_processed = true; assert_simple_bound(&trait_bound); - *gen = Some(types.resolve_path(&trait_bound.path, None)); + let resolved = types.resolve_path(&trait_bound.path, None); + let ref_ty = syn::Type::Reference(syn::TypeReference { + and_token: syn::Token![&](Span::call_site()), + lifetime: None, mutability: None, + elem: Box::new(syn::Type::Path(syn::TypePath { + qself: None, path: string_path_to_syn_path(&resolved) + })), + }); + self.default_generics.insert(p_ident, (ref_ty.clone(), ref_ty)); + *gen = Some(resolved); } } } else { return false; } -- 2.39.5