diff options
author | Martin Fischer <martin@push-f.com> | 2021-11-25 09:31:22 +0100 |
---|---|---|
committer | Martin Fischer <martin@push-f.com> | 2021-11-25 09:31:41 +0100 |
commit | 0acd72140f5e1b854d6a30d27de11785b0be8a63 (patch) | |
tree | b54837ba5c59ea2c6bdcbc5abfa165248677353d | |
parent | 21583e526c8045c60026b1fe8ec9510734d1764d (diff) |
refactor: move variable declarations closer to usage
-rw-r--r-- | src/lib.rs | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -95,15 +95,6 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream { let mut original_trait = parse_macro_input!(input as ItemTrait); assert!(original_trait.auto_token.is_none()); - let original_trait_name = original_trait.ident.clone(); - - let mut objectifiable_methods: Vec<(Signature, SignatureChanges)> = Vec::new(); - - let mut type_converter = TypeConverter::default(); - - let mut blanket_impl_attrs = Vec::new(); - let mut dyn_trait_attrs = Vec::new(); - // just to provide a better error message for bound in trait_bounds(&original_trait.supertraits) { if let Some(assoc_type) = iter_path(&bound.path) @@ -117,6 +108,11 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream { } } + let mut type_converter = TypeConverter::default(); + + let mut blanket_impl_attrs = Vec::new(); + let mut dyn_trait_attrs = Vec::new(); + // FUTURE: use Vec::drain_filter once it's stable let mut i = 0; while i < original_trait.attrs.len() { @@ -186,6 +182,8 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream { } } + let mut objectifiable_methods: Vec<(Signature, SignatureChanges)> = Vec::new(); + for item in &original_trait.items { if let TraitItem::Method(method) = item { let mut signature = method.sig.clone(); @@ -280,6 +278,8 @@ pub fn dynamize(_attr: TokenStream, input: TokenStream) -> TokenStream { } } + let original_trait_name = original_trait.ident.clone(); + for (signature, parsed_method) in objectifiable_methods { let mut new_method = TraitItemMethod { attrs: Vec::new(), |