From e0624fe19846ead048135dd1f34faa71319e0748 Mon Sep 17 00:00:00 2001 From: la10736 Date: Tue, 9 Apr 2024 13:43:02 +0200 Subject: [PATCH] Fix clippy warning --- rstest/src/lib.rs | 1 + rstest_macros/src/lib.rs | 1 + rstest_macros/src/parse/fixture.rs | 4 +-- rstest_macros/src/parse/future.rs | 33 ++++++++++++------------- rstest_macros/src/parse/rstest/files.rs | 1 - rstest_macros/src/refident.rs | 10 +++----- 6 files changed, 24 insertions(+), 26 deletions(-) diff --git a/rstest/src/lib.rs b/rstest/src/lib.rs index ba4852fa..4b84b4c8 100644 --- a/rstest/src/lib.rs +++ b/rstest/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(clippy::test_attr_in_doctest)] //! This crate will help you to write simpler tests by leveraging a software testing concept called //! [test fixtures](https://en.wikipedia.org/wiki/Test_fixture#Software). A fixture is something //! that you can use in your tests to encapsulate a test's dependencies. diff --git a/rstest_macros/src/lib.rs b/rstest_macros/src/lib.rs index cb71efce..f372194b 100644 --- a/rstest_macros/src/lib.rs +++ b/rstest_macros/src/lib.rs @@ -1,3 +1,4 @@ +#![allow(clippy::test_attr_in_doctest)] #![cfg_attr(use_proc_macro_diagnostic, feature(proc_macro_diagnostic))] extern crate proc_macro; diff --git a/rstest_macros/src/parse/fixture.rs b/rstest_macros/src/parse/fixture.rs index 35ceddb7..93f73c36 100644 --- a/rstest_macros/src/parse/fixture.rs +++ b/rstest_macros/src/parse/fixture.rs @@ -134,9 +134,9 @@ impl VisitMut for FixturesFunctionExtractor { arg.attrs = remain; let (pos, errors) = parse_attribute_args_just_once(extracted.iter(), "with"); - self.1.extend(errors.into_iter()); + self.1.extend(errors); let (resolve, errors) = parse_attribute_args_just_once(extracted.iter(), "from"); - self.1.extend(errors.into_iter()); + self.1.extend(errors); if pos.is_some() || resolve.is_some() { self.0 .push(Fixture::new(name, resolve, pos.unwrap_or_default())) diff --git a/rstest_macros/src/parse/future.rs b/rstest_macros/src/parse/future.rs index e3576aa4..8668bf97 100644 --- a/rstest_macros/src/parse/future.rs +++ b/rstest_macros/src/parse/future.rs @@ -108,6 +108,21 @@ impl FutureFunctionExtractor { Err(self.errors.into()) } } + + fn compute_arguments_kind(arg: &syn::Attribute) -> Result { + if matches!(arg.meta, syn::Meta::Path(_)) { + Ok(FutureArg::Define) + } else { + match arg.parse_args::>()? { + Some(awt) if awt == format_ident!("awt") => Ok(FutureArg::Await), + None => Ok(FutureArg::Define), + Some(invalid) => Err(syn::Error::new_spanned( + arg.parse_args::>()?.into_token_stream(), + format!("Invalid '{invalid}' #[future(...)] arg."), + )), + } + } + } } impl VisitMut for FutureFunctionExtractor { @@ -118,23 +133,7 @@ impl VisitMut for FutureFunctionExtractor { match extract_argument_attrs( node, |a| attr_is(a, "future"), - |arg, name| { - let kind = if matches!(arg.meta, syn::Meta::Path(_)) { - FutureArg::Define - } else { - match arg.parse_args::>()? { - Some(awt) if awt == format_ident!("awt") => FutureArg::Await, - None => FutureArg::Define, - Some(invalid) => { - return Err(syn::Error::new_spanned( - arg.parse_args::>()?.into_token_stream(), - format!("Invalid '{invalid}' #[future(...)] arg."), - )); - } - } - }; - Ok((arg, name.clone(), kind)) - }, + |arg, name| Self::compute_arguments_kind(&arg).map(|kind| (arg, name.clone(), kind)), ) .collect::, _>>() { diff --git a/rstest_macros/src/parse/rstest/files.rs b/rstest_macros/src/parse/rstest/files.rs index 72d0d953..7b6fb9b6 100644 --- a/rstest_macros/src/parse/rstest/files.rs +++ b/rstest_macros/src/parse/rstest/files.rs @@ -253,7 +253,6 @@ impl BaseDir for DefaultBaseDir {} trait GlobResolver { fn glob(&self, pattern: &str) -> Result, String> { - let pattern = pattern; let globs = glob(pattern).map_err(|e| format!("glob failed for whole path `{pattern}` due {e}"))?; globs diff --git a/rstest_macros/src/refident.rs b/rstest_macros/src/refident.rs index 51a78e08..f125b7af 100644 --- a/rstest_macros/src/refident.rs +++ b/rstest_macros/src/refident.rs @@ -109,12 +109,10 @@ pub trait RemoveMutability { impl RemoveMutability for FnArg { fn remove_mutability(&mut self) { - match self { - FnArg::Typed(PatType { pat, .. }) => match pat.as_mut() { - Pat::Ident(ident) => ident.mutability = None, - _ => {} - }, - _ => {} + if let FnArg::Typed(PatType { pat, .. }) = self { + if let Pat::Ident(ident) = pat.as_mut() { + ident.mutability = None + } }; } }