Skip to content

Commit

Permalink
address clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
nrxus committed Dec 1, 2024
1 parent eb25d4b commit 7957da3
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 24 deletions.
15 changes: 5 additions & 10 deletions faux_macros/src/methods/morphed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ pub fn replace_impl_trait(ty: &syn::Type) -> Option<syn::Type> {
}
}

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),
Expand Down Expand Up @@ -340,7 +340,7 @@ impl<'a> Signature<'a> {
}
}

impl<'a> MethodData<'a> {
impl MethodData<'_> {
pub fn create_when(
&self,
output: Option<&syn::Type>,
Expand Down Expand Up @@ -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),
}
}

Expand Down Expand Up @@ -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<Generics>) -> Vec<Ident> {
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()
}

Expand Down
18 changes: 9 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
//!
Expand Down Expand Up @@ -244,7 +244,7 @@
//! * Methods with pointer self types (e.g., `self: Rc<Self>`)
//! * 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.
//!
Expand Down Expand Up @@ -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<Self, Error>`)
/// `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<Self, Error>`)
///
/// 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
Expand Down
4 changes: 2 additions & 2 deletions src/mock/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl<'a, I, O> Stub<'a, I, O> {
}
}

impl<'a, I, O> Answer<'a, I, O> {
impl<I, O> Answer<'_, I, O> {
fn call(&mut self, input: I) -> Result<O, (I, Error)> {
// no need to replace if we can keep decrementing
if let Answer::Many { stub, times } = self {
Expand All @@ -91,7 +91,7 @@ impl<'a, I, O> Answer<'a, I, O> {
}
}

impl<'a, I, O> fmt::Debug for Stub<'a, I, O> {
impl<I, O> fmt::Debug for Stub<'_, I, O> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
f.debug_struct("Stub")
// TODO: Add debug information for InvocationMatcher
Expand Down
2 changes: 1 addition & 1 deletion src/mock/unchecked.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl<'stub, I, O> From<Mock<'stub, I, O>> 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,
Expand Down
3 changes: 2 additions & 1 deletion src/when.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ impl<'m, R, I, O, M: InvocationMatcher<I> + Send + 'static> When<'m, R, I, O, M>
pub unsafe fn then_unchecked(self, stub: impl FnMut(I) -> O + Send) {
let stub: Box<dyn FnMut(I) -> 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.
Expand Down
3 changes: 2 additions & 1 deletion src/when/once.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ impl<'m, R, I, O, M: InvocationMatcher<I> + Send + 'static> Once<'m, R, I, O, M>
pub unsafe fn then_unchecked(self, stub: impl FnOnce(I) -> O + Send) {
let stub: Box<dyn FnOnce(I) -> 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<dyn FnOnce(I) -> O + Send + 'static>) {
Expand Down

0 comments on commit 7957da3

Please sign in to comment.