diff options
author | Martin Fischer <martin@push-f.com> | 2021-11-19 09:50:34 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-11-19 09:51:58 +0100 |
commit | eb686879fdd7cde5d09837c202ebd25c9c9889a6 (patch) | |
tree | ec5388cd7e86513ed01dd5a89527fc44c4576777 /src/parse_trait_sig.rs | |
parent | 8e99d7bd6ebf9d1981667799f43cf45f682e1fff (diff) |
refactor: forward type param transforms as HashMap
Diffstat (limited to 'src/parse_trait_sig.rs')
-rw-r--r-- | src/parse_trait_sig.rs | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/src/parse_trait_sig.rs b/src/parse_trait_sig.rs index 0078c93..5b1f91a 100644 --- a/src/parse_trait_sig.rs +++ b/src/parse_trait_sig.rs @@ -1,8 +1,10 @@ +use std::collections::HashMap; + use proc_macro2::Span; use syn::{ spanned::Spanned, FnArg, PredicateType, Receiver, ReturnType, Type, TypePath, WherePredicate, }; -use syn::{Signature, TypeImplTrait}; +use syn::{Ident, Signature, TypeImplTrait}; use crate::syn_utils::{find_in_type, trait_bounds, TypeMatcher}; use crate::transform::{dynamize_function_bounds, AssocTypeConversions, TransformError}; @@ -40,7 +42,7 @@ impl TypeMatcher<TypeImplTrait> for ImplTraitMatcher { pub struct SignatureChanges { pub return_type: TypeTransform, - pub inputs: Vec<Option<Vec<TypeTransform>>>, + pub type_param_transforms: HashMap<Ident, Vec<TypeTransform>>, } pub fn parse_trait_signature( @@ -65,19 +67,6 @@ pub fn parse_trait_signature( let type_param_transforms = dynamize_function_bounds(&mut signature.generics, assoc_type_conversions)?; - let mut input_transforms = Vec::new(); - - for input in &signature.inputs { - if let FnArg::Typed(pattype) = input { - if let Type::Path(path) = &*pattype.ty { - if let Some(ident) = path.path.get_ident() { - input_transforms.push(type_param_transforms.get(ident).map(|x| (*x).clone())); - continue; - } - } - } - input_transforms.push(None); - } let return_type = match &mut signature.output { ReturnType::Type(_, og_type) => match assoc_type_conversions.parse_type_path(og_type) { @@ -93,7 +82,7 @@ pub fn parse_trait_signature( }; Ok(SignatureChanges { return_type, - inputs: input_transforms, + type_param_transforms, }) } @@ -184,7 +173,7 @@ mod tests { let mut assoc_type_map = AssocTypeConversions::default(); let ident = format_ident!("A"); let dest = Type::Verbatim(quote! {Example}); - assoc_type_map.0.insert(&ident, &dest); + assoc_type_map.0.insert(ident, &dest); assert!(matches!( parse_trait_signature(&mut type1.sig, &assoc_type_map), |