From 4eeb280f0da7ede784ef7f5e9d6aa89031959b39 Mon Sep 17 00:00:00 2001 From: Adrian Heine Date: Sun, 9 Jan 2022 11:51:53 +0100 Subject: [PATCH] Clippy --- src/async_utils.rs | 6 +++--- src/build.rs | 7 +++---- src/builder.rs | 4 ++-- src/command_runner.rs | 10 +++++----- src/lib.rs | 1 + src/locator.rs | 6 +++--- src/loggers.rs | 3 ++- src/resources/mod.rs | 2 +- src/setup/setup.rs | 7 ++++--- src/symbols/git/checkout.rs | 9 ++++----- src/symbols/mariadb/database.rs | 2 +- src/symbols/mariadb/dump.rs | 2 +- src/symbols/mariadb/user.rs | 2 +- src/symbols/npm.rs | 2 +- src/symbols/postgresql/database.rs | 4 ++-- src/symbols/saved_directory.rs | 2 +- src/symbols/systemd/user_service.rs | 2 +- src/symbols/wordpress/plugin.rs | 2 +- src/symbols/wordpress/translation.rs | 6 +++--- src/templates/nginx/server.rs | 5 ++--- tests/file.rs | 4 ++-- 21 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/async_utils.rs b/src/async_utils.rs index aaae4db..83517bb 100644 --- a/src/async_utils.rs +++ b/src/async_utils.rs @@ -36,7 +36,7 @@ impl Future for TimerFuture { type Output = (); fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { let mut state = self.state.lock().unwrap(); - if let State::Completed = *state { + if matches!(*state, State::Completed) { return Poll::Ready(()); } @@ -84,10 +84,10 @@ mod test { loop { futures_util::select! { _ = sleep => {}, - _ = ok => assert!((Instant::now() - start).as_millis() < 100), + _ = ok => assert!(start.elapsed().as_millis() < 100), complete => break, } } - }) + }); } } diff --git a/src/build.rs b/src/build.rs index 34e1595..772339c 100644 --- a/src/build.rs +++ b/src/build.rs @@ -15,13 +15,12 @@ pub fn create_static_output( .to_str() .ok_or("Filename is not valid unicode")? .to_uppercase(); - let content = String::from_utf8(read_file(&source_path)?)?; + let content = String::from_utf8(read_file(source_path)?)?; let fence = content.chars().filter(|&c| c == '#').collect::() + "#"; writeln!( target, - "pub const {}: &str = r{1}\"{2}\"{1};", - const_name, fence, content + "pub const {const_name}: &str = r{fence}\"{content}\"{fence};" )?; Ok(()) } @@ -39,7 +38,7 @@ pub fn create_static_output_files( } Err(err) => { if err.kind() != NotFound { - return Err(format!("Unexpected error: {}", err).into()); + return Err(format!("Unexpected error: {err}").into()); } } } diff --git a/src/builder.rs b/src/builder.rs index 4d5ab61..394d3d1 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -282,7 +282,7 @@ impl, C: Clone + Into> &resource.0, cert, key, - nginx::php_snippet(resource.2, &pool.0, &resource.1) + &resource.3, + nginx::php_snippet(resource.2, pool.0, &resource.1) + &resource.3, challenges_snippet_path, ), ), @@ -428,7 +428,7 @@ impl ImplementationBuilder> for DefaultBuilder { ( FileSymbol::new( conf_path.clone().into(), - php_fpm_pool_config(&user_name.0, &socket_path, &resource.1), + php_fpm_pool_config(&user_name.0, socket_path, &resource.1), ), ReloadServiceSymbol::new(StdCommandRunner, service_name.0.clone()), ) diff --git a/src/command_runner.rs b/src/command_runner.rs index 9508ee2..cca8207 100644 --- a/src/command_runner.rs +++ b/src/command_runner.rs @@ -82,8 +82,8 @@ pub struct SetuidCommandRunner> { user_name: U, } -impl<'a, U: AsRef> SetuidCommandRunner { - pub fn new(user_name: U) -> Self { +impl> SetuidCommandRunner { + pub const fn new(user_name: U) -> Self { Self { user_name } } } @@ -123,7 +123,7 @@ impl> CommandRunner for SetuidCommandRunner { .expect("User does not exist") .uid(); let set_home = TempSetEnv::new("HOME", format!("/home/{}", self.user_name.as_ref())); - let set_dbus = TempSetEnv::new("XDG_RUNTIME_DIR", format!("/run/user/{}", uid)); + let set_dbus = TempSetEnv::new("XDG_RUNTIME_DIR", format!("/run/user/{uid}")); //println!("{} {:?}", program, args); let mut child = Command::new(program) .args(args) @@ -167,10 +167,10 @@ mod test { loop { futures_util::select! { _ = res => {}, - _ = ps => assert!((Instant::now() - start).as_millis() < 1000), + _ = ps => assert!(start.elapsed().as_millis() < 1000), complete => break, } } - }) + }); } } diff --git a/src/lib.rs b/src/lib.rs index dc73e82..a63506f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,6 +21,7 @@ clippy::cargo_common_metadata, clippy::future_not_send, clippy::missing_errors_doc, + clippy::missing_panics_doc, clippy::module_name_repetitions, rustdoc::all, missing_docs, diff --git a/src/locator.rs b/src/locator.rs index 2b0561c..3322baa 100644 --- a/src/locator.rs +++ b/src/locator.rs @@ -37,7 +37,7 @@ pub trait Policy { #[must_use] fn path_for_data(name: impl Display) -> PathBuf { - Path::new("/root/data").join(format!("_{}", name)) + Path::new("/root/data").join(format!("_{name}")) } } @@ -121,7 +121,7 @@ impl> ResourceLocator> for DefaultLocator

> ResourceLocator> for DefaultLocator { +impl> ResourceLocator> for DefaultLocator { type Prerequisites = Dir; fn locate(resource: &File

) -> ( as Resource>::Artifact, Self::Prerequisites) { ((), Dir(resource.0.as_ref().parent().unwrap().into())) @@ -370,7 +370,7 @@ impl, P: Policy> ResourceLocator> for Defaul php_version, user.0 )), user, - ServiceNameArtifact(format!("php{}-fpm", php_version)), + ServiceNameArtifact(format!("php{php_version}-fpm")), ), (), ) diff --git a/src/loggers.rs b/src/loggers.rs index 1d96375..c970c47 100644 --- a/src/loggers.rs +++ b/src/loggers.rs @@ -8,7 +8,7 @@ use std::rc::Rc; // 1 - Error, 2 - Warn, 3 - Info, 4 - Debug, 5 - Trace pub type Level = usize; -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct Entry(pub Level, pub S); pub trait Logger { @@ -110,6 +110,7 @@ impl StoringLogger { Self::default() } + #[must_use] pub fn release(self) -> Vec> { Rc::try_unwrap(self.log).unwrap().into_inner().1 } diff --git a/src/resources/mod.rs b/src/resources/mod.rs index 9b16405..a4a8ab9 100644 --- a/src/resources/mod.rs +++ b/src/resources/mod.rs @@ -42,7 +42,7 @@ impl Resource for KeyAndCertBundle { #[derive(Debug, Hash, PartialEq, Eq)] pub struct File

(pub P, pub String); -impl<'a, P> Resource for File

{ +impl

Resource for File

{ type Artifact = (); } diff --git a/src/setup/setup.rs b/src/setup/setup.rs index a04e383..1b888f4 100644 --- a/src/setup/setup.rs +++ b/src/setup/setup.rs @@ -100,7 +100,7 @@ impl ); drop(resources); let result = future.await; - result.map_err(|e| e.into()) + result.map_err(std::convert::Into::into) }; result.map(|(t, did_run)| (t.into_artifact(), did_run)) } @@ -148,7 +148,7 @@ impl< let drain = recorder.clone(); let log = Rc::new(slog::Logger::root( drain, - o!("resource" => format!("{:?}", resource)), + o!("resource" => format!("{resource:?}")), )); let result = self.1.add(&log, resource, force_run).await; @@ -190,7 +190,7 @@ impl< let drain = recorder.clone(); let log = Rc::new(slog::Logger::root( drain, - o!("symbol" => format!("{:?}", symbol)), + o!("symbol" => format!("{symbol:?}")), )); let result = (self.1).0.core.run_symbol(&symbol, &log, force).await; @@ -332,6 +332,7 @@ mod test { } } + #[allow(clippy::type_complexity)] fn get_setup() -> ( Rc>, Setup< diff --git a/src/symbols/git/checkout.rs b/src/symbols/git/checkout.rs index f5399c7..5f57844 100644 --- a/src/symbols/git/checkout.rs +++ b/src/symbols/git/checkout.rs @@ -17,7 +17,7 @@ pub struct Checkout<_C, C, P, S, B> { phantom: PhantomData<_C>, } -impl Checkout<_C, C, P, S, B> { +impl<_C, C, P, S, B> Checkout<_C, C, P, S, B> { pub fn new(target: P, source: S, branch: B, command_runner: C) -> Self { Self { target, @@ -29,7 +29,7 @@ impl Checkout<_C, C, P, S, B> { } } -impl, P: AsRef, S, B> Checkout { +impl<_C: CommandRunner, C: Borrow<_C>, P: AsRef, S, B> Checkout<_C, C, P, S, B> { async fn run_git(&self, args: &[impl AsRef]) -> Result, Box> { let mut new_args = Vec::with_capacity(args.len() + 2); new_args.extend_from_slice(args!["-C", self.target.as_ref()]); @@ -43,8 +43,8 @@ impl, P: AsRef, S, B> Checkout, P: AsRef, S: AsRef, B: AsRef> Symbol - for Checkout +impl<_C: CommandRunner, C: Borrow<_C>, P: AsRef, S: AsRef, B: AsRef> Symbol + for Checkout<_C, C, P, S, B> { async fn target_reached(&self) -> Result> { if !self.target.as_ref().exists() { @@ -146,7 +146,6 @@ mod test { ["-C", "target", "rev-list", "-1", "HEAD"], ] ); - drop(first_two_args); assert_eq!(args[2], ["-C", "target", "rev-list", "-1", "FETCH_HEAD"]); assert!((end - start).as_millis() >= 100); diff --git a/src/symbols/mariadb/database.rs b/src/symbols/mariadb/database.rs index caace4e..95ae693 100644 --- a/src/symbols/mariadb/database.rs +++ b/src/symbols/mariadb/database.rs @@ -12,7 +12,7 @@ pub struct Database<'a, D, S, C> { } impl<'a, D, S, C: CommandRunner> Database<'a, D, S, C> { - pub fn new(db_name: D, seed_file: S, command_runner: &'a C) -> Self { + pub const fn new(db_name: D, seed_file: S, command_runner: &'a C) -> Self { Self { db_name, seed_file, diff --git a/src/symbols/mariadb/dump.rs b/src/symbols/mariadb/dump.rs index 11accac..7503ad1 100644 --- a/src/symbols/mariadb/dump.rs +++ b/src/symbols/mariadb/dump.rs @@ -13,7 +13,7 @@ pub struct Dump<'a, N, C, S> { } impl<'a, N, C: CommandRunner, S> Dump<'a, N, C, S> { - pub fn new(db_name: N, storage: S, command_runner: &'a C) -> Self { + pub const fn new(db_name: N, storage: S, command_runner: &'a C) -> Self { Self { db_name, storage, diff --git a/src/symbols/mariadb/user.rs b/src/symbols/mariadb/user.rs index b8eb4b5..9fb3730 100644 --- a/src/symbols/mariadb/user.rs +++ b/src/symbols/mariadb/user.rs @@ -10,7 +10,7 @@ pub struct User<'a, U, C> { } impl<'a, U: AsRef, C: CommandRunner> User<'a, U, C> { - pub fn new(user_name: U, command_runner: &'a C) -> Self { + pub const fn new(user_name: U, command_runner: &'a C) -> Self { Self { user_name, command_runner, diff --git a/src/symbols/npm.rs b/src/symbols/npm.rs index b2a95bc..5275d64 100644 --- a/src/symbols/npm.rs +++ b/src/symbols/npm.rs @@ -12,7 +12,7 @@ pub struct Install<'a, T: AsRef, C: CommandRunner> { } impl<'a, T: AsRef, C: CommandRunner> Install<'a, T, C> { - pub fn new(target: T, command_runner: &'a C) -> Self { + pub const fn new(target: T, command_runner: &'a C) -> Self { Self { target, command_runner, diff --git a/src/symbols/postgresql/database.rs b/src/symbols/postgresql/database.rs index bf36fea..3b825fd 100644 --- a/src/symbols/postgresql/database.rs +++ b/src/symbols/postgresql/database.rs @@ -12,7 +12,7 @@ pub struct PostgreSQLDatabase<'a, N: AsRef, S: AsRef, C: CommandRunner } impl<'a, N: AsRef, S: AsRef, C: CommandRunner> PostgreSQLDatabase<'a, N, S, C> { - pub fn new(name: N, seed_file: S, command_runner: &'a C) -> Self { + pub const fn new(name: N, seed_file: S, command_runner: &'a C) -> Self { PostgreSQLDatabase { name, seed_file, @@ -25,7 +25,7 @@ impl<'a, N: AsRef, S: AsRef, C: CommandRunner> PostgreSQLDatabase<'a, .command_runner .get_output( "su", - args!["-", "postgres", "-c", format!("psql -t -c \"{}\"", sql)], + args!["-", "postgres", "-c", format!("psql -t -c \"{sql}\"")], ) .await?; Ok(String::from_utf8(b)?) diff --git a/src/symbols/saved_directory.rs b/src/symbols/saved_directory.rs index d52091a..6e45c89 100644 --- a/src/symbols/saved_directory.rs +++ b/src/symbols/saved_directory.rs @@ -10,7 +10,7 @@ use std::marker::PhantomData; use std::path::Path; use std::str::FromStr; -#[derive(Debug, PartialEq)] +#[derive(Debug, PartialEq, Eq)] pub enum StorageDirection { Load, Store, diff --git a/src/symbols/systemd/user_service.rs b/src/symbols/systemd/user_service.rs index 9559eea..67ed3b2 100644 --- a/src/symbols/systemd/user_service.rs +++ b/src/symbols/systemd/user_service.rs @@ -15,7 +15,7 @@ pub struct UserService<'a, S: AsRef, U: AsRef> { } impl, U: AsRef> UserService<'static, S, U> { - pub fn new(socket_path: S, user_name: U, service_name: &'static str) -> Self { + pub const fn new(socket_path: S, user_name: U, service_name: &'static str) -> Self { Self { socket_path, service_name, diff --git a/src/symbols/wordpress/plugin.rs b/src/symbols/wordpress/plugin.rs index 8c280d8..6ac40e2 100644 --- a/src/symbols/wordpress/plugin.rs +++ b/src/symbols/wordpress/plugin.rs @@ -16,7 +16,7 @@ pub struct Plugin<'a, P, N, R> { } impl<'a, P: AsRef, N: AsRef, R: CommandRunner> Plugin<'a, P, N, R> { - pub fn new(base: P, name: N, command_runner: &'a R) -> Self { + pub const fn new(base: P, name: N, command_runner: &'a R) -> Self { Self { base, name, diff --git a/src/symbols/wordpress/translation.rs b/src/symbols/wordpress/translation.rs index 6643c9e..ac16ec3 100644 --- a/src/symbols/wordpress/translation.rs +++ b/src/symbols/wordpress/translation.rs @@ -19,7 +19,7 @@ pub struct Translation<'a, C, D, R> { } impl<'a, D, C: AsRef, R: CommandRunner> Translation<'a, C, D, R> { - pub fn new(path: D, version: &'a str, locale: C, command_runner: &'a R) -> Self { + pub const fn new(path: D, version: &'a str, locale: C, command_runner: &'a R) -> Self { Self { path, version, @@ -33,7 +33,7 @@ impl, D: AsRef, R: CommandRunner> Translation<'_, C, D, R> { fn get_pairs(&self) -> Vec<(String, PathBuf)> { let version_x = self .version - .trim_end_matches(|c: char| c.is_digit(10)) + .trim_end_matches(|c: char| c.is_ascii_digit()) .to_owned() + "x"; let locale = self.locale.as_ref(); @@ -51,7 +51,7 @@ impl, D: AsRef, R: CommandRunner> Translation<'_, C, D, R> { ] { for format in &["po", "mo"] { res.push(( - format!("https://translate.wordpress.org/projects/wp/{}/{}{}/default/export-translations?format={}", version_x, in_slug, path_locale, format), + format!("https://translate.wordpress.org/projects/wp/{version_x}/{in_slug}{path_locale}/default/export-translations?format={format}"), [self.path.as_ref(), format!("{}{}.{}", out_slug, self.locale.as_ref(), format).as_ref()].iter().collect() )); } diff --git a/src/templates/nginx/server.rs b/src/templates/nginx/server.rs index fe3b091..066777f 100644 --- a/src/templates/nginx/server.rs +++ b/src/templates/nginx/server.rs @@ -78,9 +78,8 @@ pub fn php_snippet, STATIC: AsRef>( pub fn redir_snippet(target: &str) -> String { format!( "location / {{ - return 301 $scheme://{}$request_uri; - }}", - target + return 301 $scheme://{target}$request_uri; + }}" ) } diff --git a/tests/file.rs b/tests/file.rs index b74c8d9..3043cdc 100644 --- a/tests/file.rs +++ b/tests/file.rs @@ -98,7 +98,7 @@ fn may_not_read_file() { #[test] fn may_not_create_file() { - let symbol = get_symbol(&Path::new("/proc/somefile")); + let symbol = get_symbol(Path::new("/proc/somefile")); run(async { // Could also return an error @@ -109,7 +109,7 @@ fn may_not_create_file() { #[test] fn directory_missing() { - let symbol = get_symbol(&Path::new("/nonexisting")); + let symbol = get_symbol(Path::new("/nonexisting")); run(async { // Could also return an error