From 4b2e4c3bc9fa39e5eacdf4591fc7d15df8bf65d9 Mon Sep 17 00:00:00 2001 From: Richard Schneeman Date: Fri, 6 Oct 2023 10:33:15 -0500 Subject: [PATCH] Rust 1.73.0 clippy updates --- .../ruby/src/layers/metrics_agent_install.rs | 2 +- buildpacks/ruby/src/layers/ruby_install_layer.rs | 2 +- commons/src/output/build_log.rs | 2 +- commons/src/output/fmt.rs | 10 ++++++---- commons/src/output/util.rs | 16 ++++++++++------ 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/buildpacks/ruby/src/layers/metrics_agent_install.rs b/buildpacks/ruby/src/layers/metrics_agent_install.rs index 0bdaf63f..d1400c3f 100644 --- a/buildpacks/ruby/src/layers/metrics_agent_install.rs +++ b/buildpacks/ruby/src/layers/metrics_agent_install.rs @@ -201,7 +201,7 @@ fn write_execd_script( } fn install_agentmon(dir: &Path) -> Result { - let agentmon = download_untar(DOWNLOAD_URL, dir).map(|_| dir.join("agentmon"))?; + let agentmon = download_untar(DOWNLOAD_URL, dir).map(|()| dir.join("agentmon"))?; chmod_plus_x(&agentmon).map_err(MetricsAgentInstallError::PermissionError)?; Ok(agentmon) diff --git a/buildpacks/ruby/src/layers/ruby_install_layer.rs b/buildpacks/ruby/src/layers/ruby_install_layer.rs index 21e7f355..833224c2 100644 --- a/buildpacks/ruby/src/layers/ruby_install_layer.rs +++ b/buildpacks/ruby/src/layers/ruby_install_layer.rs @@ -132,7 +132,7 @@ fn download_url(stack: &StackId, version: impl std::fmt::Display) -> Result {} + Ok(()) => {} Err(error) => { eprintln!("[Buildpack Warning]: Cannot use the delayed warning feature due to error: {error}"); self.log_warning_shared(s); diff --git a/commons/src/output/fmt.rs b/commons/src/output/fmt.rs index 6978f81a..abe5c7a6 100644 --- a/commons/src/output/fmt.rs +++ b/commons/src/output/fmt.rs @@ -1,5 +1,6 @@ use crate::output::util::LinesWithEndings; use const_format::formatcp; +use std::fmt::Write; /// Helpers for formatting and colorizing your output @@ -119,7 +120,7 @@ pub(crate) fn prefix_indent(prefix: impl AsRef, contents: impl AsRef) let prefix = prefix.as_ref(); let contents = contents.as_ref(); let non_whitespace_re = regex::Regex::new("\\S").expect("Clippy"); - let clean_prefix = strip_control_codes(prefix.clone()); + let clean_prefix = strip_control_codes(prefix); let indent_str = non_whitespace_re.replace_all(&clean_prefix, " "); // Preserve whitespace characters like tab and space, replace all characters with spaces let lines = LinesWithEndings::from(contents).collect::>(); @@ -127,9 +128,10 @@ pub(crate) fn prefix_indent(prefix: impl AsRef, contents: impl AsRef) if let Some((first, rest)) = lines.split_first() { format!( "{prefix}{first}{}", - rest.iter() - .map(|line| format!("{indent_str}{line}")) - .collect::() + rest.iter().fold(String::new(), |mut output, line| { + let _ = write!(output, "{indent_str}{line}"); + output + }) ) } else { prefix.to_string() diff --git a/commons/src/output/util.rs b/commons/src/output/util.rs index 5d8be003..8b49fa6b 100644 --- a/commons/src/output/util.rs +++ b/commons/src/output/util.rs @@ -155,6 +155,7 @@ pub(crate) fn strip_trailing_whitespace(s: impl AsRef) -> String { #[cfg(test)] mod test { use super::*; + use std::fmt::Write; #[test] fn test_trailing_whitespace() { @@ -167,15 +168,18 @@ mod test { #[test] fn test_lines_with_endings() { - let actual = LinesWithEndings::from("foo\nbar") - .map(|line| format!("z{line}")) - .collect::(); + let actual = LinesWithEndings::from("foo\nbar").fold(String::new(), |mut output, line| { + let _ = write!(output, "z{line}"); + output + }); assert_eq!("zfoo\nzbar", actual); - let actual = LinesWithEndings::from("foo\nbar\n") - .map(|line| format!("z{line}")) - .collect::(); + let actual = + LinesWithEndings::from("foo\nbar\n").fold(String::new(), |mut output, line| { + let _ = write!(output, "z{line}"); + output + }); assert_eq!("zfoo\nzbar\n", actual); }