diff options
| -rw-r--r-- | examples/generic_method.rs | 4 | ||||
| -rw-r--r-- | macros/src/expectation.rs | 36 | ||||
| -rw-r--r-- | macros/src/mock.rs | 2 | 
3 files changed, 7 insertions, 35 deletions
diff --git a/examples/generic_method.rs b/examples/generic_method.rs index 995c67d..4262ee2 100644 --- a/examples/generic_method.rs +++ b/examples/generic_method.rs @@ -5,6 +5,8 @@ use ridicule::mock;  trait Foo  {      fn bar<Baz: Display>(&self, num: u128) -> Baz; + +    fn abc<Baz: Display>(&mut self, baz: Baz);  }  mock! { @@ -13,6 +15,8 @@ mock! {      impl Foo for MockFoo      {          fn bar<Baz: Display>(&self, num: u128) -> Baz; + +        fn abc<Baz: Display>(&mut self, baz_baz: Baz);      }  } diff --git a/macros/src/expectation.rs b/macros/src/expectation.rs index 436d571..5a4922c 100644 --- a/macros/src/expectation.rs +++ b/macros/src/expectation.rs @@ -16,9 +16,6 @@ use syn::{      ImplItemMethod,      ItemStruct,      Lifetime, -    Pat, -    PatIdent, -    PatType,      Path,      PathSegment,      Receiver, @@ -268,35 +265,6 @@ impl ToTokens for Expectation              self.return_type.clone(),          )); -        let args = opt_self_type -            .iter() -            .chain(self.arg_types.iter()) -            .enumerate() -            .map(|(index, ty)| { -                FnArg::Typed(PatType { -                    attrs: vec![], -                    pat: Box::new(Pat::Ident(PatIdent { -                        attrs: vec![], -                        by_ref: None, -                        mutability: None, -                        ident: format_ident!("arg_{index}"), -                        subpat: None, -                    })), -                    colon_token: <Token![:]>::default(), -                    ty: Box::new(ty.clone()), -                }) -            }) -            .collect::<Vec<_>>(); - -        let arg_idents = opt_self_type -            .iter() -            .chain(self.arg_types.iter()) -            .enumerate() -            .map(|(index, _)| format_ident!("arg_{index}")) -            .collect::<Vec<_>>(); - -        let return_type = &self.return_type; -          let method_ident = &self.method_ident;          let expectation_struct = Self::create_struct( @@ -358,7 +326,7 @@ impl ToTokens for Expectation                      unsafe { std::mem::transmute(self) }                  } -                fn call_returning(&self, #(#args),*) #return_type +                fn get_returning(&self) -> &#returning_fn                  {                      let Some(returning) = &self.returning else {                          panic!(concat!( @@ -398,7 +366,7 @@ impl ToTokens for Expectation                      self.call_cnt.fetch_add(1, std::sync::atomic::Ordering::Relaxed); -                    (returning)(#(#arg_idents),*) +                    returning                  }              } diff --git a/macros/src/mock.rs b/macros/src/mock.rs index d2eb451..2ac27e5 100644 --- a/macros/src/mock.rs +++ b/macros/src/mock.rs @@ -247,7 +247,7 @@ fn create_mock_function(                      ))                      .with_generic_params::<#(#type_param_idents,)*>(); -                expectation.call_returning(#(#args),*) +                (expectation.get_returning())(#(#args),*)              }          })          .unwrap_or_abort(),  | 
