aboutsummaryrefslogtreecommitdiff
path: root/macros/src
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-09-30 17:09:24 +0200
committerHampusM <hampus@hampusmat.com>2023-09-30 17:09:24 +0200
commitba7af1342e9b4ae1ed691035ba90ef3776a9126a (patch)
tree4bc9fb94719c5d103213d99ff3175a8ed4037e91 /macros/src
parent756370ed8efd39281b21cd8656ee09d785a114dd (diff)
refactor: remove unnecessary cloning of impl generics & self type
Diffstat (limited to 'macros/src')
-rw-r--r--macros/src/injectable/implementation.rs32
-rw-r--r--macros/src/lib.rs2
2 files changed, 13 insertions, 21 deletions
diff --git a/macros/src/injectable/implementation.rs b/macros/src/injectable/implementation.rs
index 34c5437..a590ee4 100644
--- a/macros/src/injectable/implementation.rs
+++ b/macros/src/injectable/implementation.rs
@@ -3,16 +3,7 @@ use std::error::Error;
use proc_macro2::{Ident, Span};
use quote::{format_ident, quote, ToTokens};
use syn::spanned::Spanned;
-use syn::{
- parse_str,
- ExprMethodCall,
- FnArg,
- Generics,
- ImplItemMethod,
- ItemImpl,
- ReturnType,
- Type,
-};
+use syn::{parse_str, ExprMethodCall, FnArg, ImplItemMethod, ItemImpl, ReturnType, Type};
use crate::injectable::dependency::{DependencyError, IDependency};
use crate::util::error::diagnostic_error_enum;
@@ -25,10 +16,8 @@ const DEPENDENCY_HISTORY_VAR_NAME: &str = "dependency_history";
pub struct InjectableImpl<Dep: IDependency>
{
- pub dependencies: Vec<Dep>,
- pub self_type: Type,
- pub generics: Generics,
- pub original_impl: ItemImpl,
+ dependencies: Vec<Dep>,
+ original_impl: ItemImpl,
constructor_method: ImplItemMethod,
}
@@ -71,8 +60,6 @@ impl<Dep: IDependency> InjectableImpl<Dep>
Ok(Self {
dependencies,
- self_type: item_impl.self_ty.as_ref().clone(),
- generics: item_impl.generics.clone(),
original_impl: item_impl,
constructor_method,
})
@@ -136,6 +123,11 @@ impl<Dep: IDependency> InjectableImpl<Dep>
Ok(())
}
+ pub fn self_type(&self) -> &Type
+ {
+ &self.original_impl.self_ty
+ }
+
#[cfg(not(tarpaulin_include))]
pub fn expand(&self, no_doc_hidden: bool, is_async: bool)
-> proc_macro2::TokenStream
@@ -210,8 +202,8 @@ impl<Dep: IDependency> InjectableImpl<Dep>
get_dep_method_calls: &Vec<proc_macro2::TokenStream>,
) -> proc_macro2::TokenStream
{
- let generics = &self.generics;
- let self_type = &self.self_type;
+ let generics = &self.original_impl.generics;
+ let self_type = &self.original_impl.self_ty;
let constructor = &self.constructor_method.sig.ident;
let dependency_idents = (0..get_dep_method_calls.len())
@@ -273,8 +265,8 @@ impl<Dep: IDependency> InjectableImpl<Dep>
get_dep_method_calls: &Vec<proc_macro2::TokenStream>,
) -> proc_macro2::TokenStream
{
- let generics = &self.generics;
- let self_type = &self.self_type;
+ let generics = &self.original_impl.generics;
+ let self_type = &self.original_impl.self_ty;
let constructor = &self.constructor_method.sig.ident;
quote! {
diff --git a/macros/src/lib.rs b/macros/src/lib.rs
index 78895be..6bf5ac1 100644
--- a/macros/src/lib.rs
+++ b/macros/src/lib.rs
@@ -239,7 +239,7 @@ pub fn injectable(args_stream: TokenStream, input_stream: TokenStream) -> TokenS
let expanded_injectable_impl = injectable_impl.expand(no_doc_hidden, is_async);
- let self_type = &injectable_impl.self_type;
+ let self_type = injectable_impl.self_type();
let opt_interface = args.interface.map(Type::Path).or_else(|| {
if no_declare_concrete_interface {