From 8c12f554e3ffaa27cfb48ddd41f74fb314cc10b5 Mon Sep 17 00:00:00 2001 From: michele Date: Tue, 4 Jul 2023 23:02:56 +0200 Subject: [PATCH] Apply clippy hints --- rstest_macros/src/parse/mod.rs | 8 +++----- rstest_macros/src/parse/rstest/files.rs | 22 +++++++++------------- rstest_macros/src/render/mod.rs | 3 +-- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/rstest_macros/src/parse/mod.rs b/rstest_macros/src/parse/mod.rs index f7ae5de..bb6d788 100644 --- a/rstest_macros/src/parse/mod.rs +++ b/rstest_macros/src/parse/mod.rs @@ -630,17 +630,15 @@ pub(crate) mod arguments { #[derive(PartialEq, Debug, Clone, Copy)] #[allow(dead_code)] + #[derive(Default)] pub(crate) enum FutureArg { + #[default] None, Define, Await, } - impl Default for FutureArg { - fn default() -> Self { - FutureArg::None - } - } + #[derive(PartialEq, Default, Debug)] pub(crate) struct ArgumentInfo { diff --git a/rstest_macros/src/parse/rstest/files.rs b/rstest_macros/src/parse/rstest/files.rs index 186441a..9cfb2e0 100644 --- a/rstest_macros/src/parse/rstest/files.rs +++ b/rstest_macros/src/parse/rstest/files.rs @@ -40,7 +40,7 @@ impl FilesGlobReferences { trait RaiseError: ToTokens { fn error(&self, msg: &str) -> syn::Error { - syn::Error::new_spanned(&self, msg) + syn::Error::new_spanned(self, msg) } } @@ -62,15 +62,11 @@ impl FilesGlobReferences { } fn is_valid(&self, p: &RelativePath) -> bool { - if self.ignore_dot_files { - if p.components() - .into_iter() - .any(|c| c.as_str().starts_with('.')) - { - return false; - } + if self.ignore_dot_files && p.components() + .any(|c| c.as_str().starts_with('.')) { + return false; } - !self.exclude.iter().any(|e| e.r.is_match(&p.to_string())) + !self.exclude.iter().any(|e| e.r.is_match(p.as_ref())) } } @@ -213,13 +209,13 @@ impl VisitMut for ValueFilesExtractor { let files = self.extract_files(node); let excludes = self.extract_exclude(node); let include_dot_files = self.extract_include_dot_files(node); - if include_dot_files.len() > 0 { + if !include_dot_files.is_empty() { include_dot_files.iter().skip(1).for_each(|attr| { self.errors .push(attr.error("Cannot use #[include_dot_files] more than once")) }) } - if files.len() > 0 { + if !files.is_empty() { self.files.push(( name, FilesGlobReferences::new(files, excludes, include_dot_files.is_empty()), @@ -255,7 +251,7 @@ impl BaseDir for DefaultBaseDir {} trait GlobResolver { fn glob(&self, pattern: &str) -> Result, String> { - let pattern = pattern.as_ref(); + let pattern = pattern; let globs = glob(pattern).map_err(|e| format!("glob failed for whole path `{pattern}` due {e}"))?; globs @@ -322,7 +318,7 @@ impl<'a> ValueListFromFiles<'a> { )) })?; if !refs.is_valid( - &RelativePath::from_path(relative_path) + RelativePath::from_path(relative_path) .map_err(|e| attr.error(&format!("Invalid glob path: {e}")))?, ) { continue; diff --git a/rstest_macros/src/render/mod.rs b/rstest_macros/src/render/mod.rs index 534227d..c293e40 100644 --- a/rstest_macros/src/render/mod.rs +++ b/rstest_macros/src/render/mod.rs @@ -207,8 +207,7 @@ fn render_test_call( ) -> TokenStream { let timeout = timeout.map(|x| quote! {#x}).or_else(|| { std::env::var("RSTEST_TIMEOUT") - .ok() - .and_then(|to| Some(quote! { std::time::Duration::from_secs( (#to).parse().unwrap()) })) + .ok().map(|to| quote! { std::time::Duration::from_secs( (#to).parse().unwrap()) }) }); match (timeout, is_async) { (Some(to_expr), true) => quote! {