From 7957da317657e0c754653f676b7c8595ebd0fb3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Medina?= Date: Sun, 1 Dec 2024 09:23:35 -0800 Subject: [PATCH] address clippy --- faux_macros/src/methods/morphed.rs | 15 +++++---------- src/lib.rs | 18 +++++++++--------- src/mock/stub.rs | 4 ++-- src/mock/unchecked.rs | 2 +- src/when.rs | 3 ++- src/when/once.rs | 3 ++- 6 files changed, 21 insertions(+), 24 deletions(-) diff --git a/faux_macros/src/methods/morphed.rs b/faux_macros/src/methods/morphed.rs index 9c0a421..347515e 100644 --- a/faux_macros/src/methods/morphed.rs +++ b/faux_macros/src/methods/morphed.rs @@ -72,7 +72,7 @@ pub fn replace_impl_trait(ty: &syn::Type) -> Option { } } -impl<'a> ToTokens for WhenArg<'a> { +impl ToTokens for WhenArg<'_> { fn to_tokens(&self, token_stream: &mut proc_macro2::TokenStream) { match replace_impl_trait(self.0) { None => self.0.to_tokens(token_stream), @@ -340,7 +340,7 @@ impl<'a> Signature<'a> { } } -impl<'a> MethodData<'a> { +impl MethodData<'_> { pub fn create_when( &self, output: Option<&syn::Type>, @@ -464,7 +464,7 @@ fn ang_generic_contains_self(args: &syn::AngleBracketedGenericArguments, path: & fn return_contains_self(ret: &syn::ReturnType, path: &TypePath) -> bool { match &ret { syn::ReturnType::Default => false, - syn::ReturnType::Type(_, ty) => contains_self(&ty, path), + syn::ReturnType::Type(_, ty) => contains_self(ty, path), } } @@ -492,19 +492,14 @@ fn path_args_contains_self(path: &syn::Path, self_path: &syn::TypePath) -> bool PathArguments::AngleBracketed(args) => ang_generic_contains_self(args, self_path), PathArguments::Parenthesized(args) => { return_contains_self(&args.output, self_path) - || args.inputs.iter().any(|i| contains_self(&i, self_path)) + || args.inputs.iter().any(|i| contains_self(i, self_path)) } } } fn generic_type_idents(generics: Option) -> Vec { generics - .map(|g| { - g.type_params() - .into_iter() - .map(|tp| tp.ident.clone()) - .collect() - }) + .map(|g| g.type_params().map(|tp| tp.ident.clone()).collect()) .unwrap_or_default() } diff --git a/src/lib.rs b/src/lib.rs index 09c6432..f3844fe 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,14 +14,14 @@ //! At a high level, `faux` is split into: //! //! * [`#[create]`](create): transforms a struct into a mockable -//! equivalent +//! equivalent //! * [`#[methods]`](methods): transforms the methods in an `impl` -//! block into their mockable equivalents +//! block into their mockable equivalents //! * [`when!`]: initializes a method stub by returning a -//! [`When`]. Passing optional argument matchers restricts which -//! arguments will invoke the stub. +//! [`When`]. Passing optional argument matchers restricts which +//! arguments will invoke the stub. //! * [`When`]: lets you stub a method's return value or -//! implementation +//! implementation //! //! # Getting Started //! @@ -244,7 +244,7 @@ //! * Methods with pointer self types (e.g., `self: Rc`) //! * Methods in external modules //! * Support for `Debug`, `Default`, `Clone`, `Send`, and `Sync` -//! derive/auto traits. +//! derive/auto traits. //! //! `faux` also provides easy-to-use argument matchers. //! @@ -653,9 +653,9 @@ pub use faux_macros::create; /// * Returning the struct itself (e.g., `fn new() -> Self`) /// /// * Returning the struct wrapped directly in: `Rc`, `Arc`, `Box`, -/// `Result`, or `Option`. For `Result`, referring to the struct is -/// only allowed if it's the `Ok` variant of the result. (e.g., `fn -/// load() -> Result`) +/// `Result`, or `Option`. For `Result`, referring to the struct is +/// only allowed if it's the `Ok` variant of the result. (e.g., `fn +/// load() -> Result`) /// /// Any other kind of return type that refers to the mocked struct is /// not supported by `faux`. Please file an issue if you have a use diff --git a/src/mock/stub.rs b/src/mock/stub.rs index bdfafe1..16c1092 100644 --- a/src/mock/stub.rs +++ b/src/mock/stub.rs @@ -72,7 +72,7 @@ impl<'a, I, O> Stub<'a, I, O> { } } -impl<'a, I, O> Answer<'a, I, O> { +impl Answer<'_, I, O> { fn call(&mut self, input: I) -> Result { // no need to replace if we can keep decrementing if let Answer::Many { stub, times } = self { @@ -91,7 +91,7 @@ impl<'a, I, O> Answer<'a, I, O> { } } -impl<'a, I, O> fmt::Debug for Stub<'a, I, O> { +impl fmt::Debug for Stub<'_, I, O> { fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { f.debug_struct("Stub") // TODO: Add debug information for InvocationMatcher diff --git a/src/mock/unchecked.rs b/src/mock/unchecked.rs index 34ee4dd..1bb4191 100644 --- a/src/mock/unchecked.rs +++ b/src/mock/unchecked.rs @@ -70,7 +70,7 @@ impl<'stub, I, O> From> for Unchecked<'stub> { // * as_checked_mut: already marked as `unsafe` // * debug format: does not look into the unsafe fields unsafe { - let unsafe_mock = std::mem::transmute(mock); + let unsafe_mock: Mock<_, _> = std::mem::transmute(mock); Self { unsafe_mock, debug_repr, diff --git a/src/when.rs b/src/when.rs index afbad3e..dbe841d 100644 --- a/src/when.rs +++ b/src/when.rs @@ -326,7 +326,8 @@ impl<'m, R, I, O, M: InvocationMatcher + Send + 'static> When<'m, R, I, O, M> pub unsafe fn then_unchecked(self, stub: impl FnMut(I) -> O + Send) { let stub: Box O + Send> = Box::new(stub); // pretend the lifetime is 'static - self.add_stub(std::mem::transmute(stub)); + let stub: Box<_> = std::mem::transmute(stub); + self.add_stub(stub); } /// Limits the number of calls for which a mock is active. diff --git a/src/when/once.rs b/src/when/once.rs index 64a4609..19b1126 100644 --- a/src/when/once.rs +++ b/src/when/once.rs @@ -181,7 +181,8 @@ impl<'m, R, I, O, M: InvocationMatcher + Send + 'static> Once<'m, R, I, O, M> pub unsafe fn then_unchecked(self, stub: impl FnOnce(I) -> O + Send) { let stub: Box O + Send> = Box::new(stub); // pretend the lifetime is 'static - self.add_stub(std::mem::transmute(stub)); + let stub: Box<_> = std::mem::transmute(stub); + self.add_stub(stub); } fn add_stub(self, stub: Box O + Send + 'static>) {