From ec2591cfe9bf39139304416d696766e79686d907 Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Fri, 6 Dec 2024 21:39:55 +1000 Subject: [PATCH] refac to separate finding fns from modifying fns --- soroban-sdk-macros/src/syn_ext.rs | 43 +++++++++++++++++-------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/soroban-sdk-macros/src/syn_ext.rs b/soroban-sdk-macros/src/syn_ext.rs index 6b2376e3..64273c01 100644 --- a/soroban-sdk-macros/src/syn_ext.rs +++ b/soroban-sdk-macros/src/syn_ext.rs @@ -225,25 +225,30 @@ fn flatten_associated_items_in_impl_fns(imp: &mut ItemImpl) { _ => None, }) .collect::>(); - for item in &mut imp.items { - if let ImplItem::Fn(f) = item { - for input in &mut f.sig.inputs { - if let FnArg::Typed(t) = input { - if let Type::Path(TypePath { qself: None, path }) = &mut *t.ty { - let segments = &path.segments; - if segments.len() == 2 - && segments.first() == Some(&PathSegment::from(format_ident!("Self"))) - { - if let Some(PathSegment { - arguments: PathArguments::None, - ident, - }) = segments.get(1) - { - if let Some(resolved_ty) = associated_types.get(ident) { - *t.ty = resolved_ty.clone(); - } - } - } + let fn_input_types = imp + .items + .iter_mut() + .filter_map(|item| match item { + ImplItem::Fn(f) => Some(f.sig.inputs.iter_mut().filter_map(|input| match input { + FnArg::Typed(t) => Some(&mut t.ty), + _ => None, + })), + _ => None, + }) + .flatten(); + for t in fn_input_types { + if let Type::Path(TypePath { qself: None, path }) = t.as_mut() { + let segments = &path.segments; + if segments.len() == 2 + && segments.first() == Some(&PathSegment::from(format_ident!("Self"))) + { + if let Some(PathSegment { + arguments: PathArguments::None, + ident, + }) = segments.get(1) + { + if let Some(resolved_ty) = associated_types.get(ident) { + *t.as_mut() = resolved_ty.clone(); } } }