Skip to content

Commit

Permalink
Rust 1.73.0 clippy updates
Browse files Browse the repository at this point in the history
  • Loading branch information
schneems committed Oct 6, 2023
1 parent ce52872 commit 4b2e4c3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion buildpacks/ruby/src/layers/metrics_agent_install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ fn write_execd_script(
}

fn install_agentmon(dir: &Path) -> Result<PathBuf, MetricsAgentInstallError> {
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)
Expand Down
2 changes: 1 addition & 1 deletion buildpacks/ruby/src/layers/ruby_install_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ fn download_url(stack: &StackId, version: impl std::fmt::Display) -> Result<Url,
let mut url = Url::parse(base).map_err(RubyInstallError::UrlParseError)?;

url.path_segments_mut()
.map_err(|_| RubyInstallError::InvalidBaseUrl(String::from(base)))?
.map_err(|()| RubyInstallError::InvalidBaseUrl(String::from(base)))?
.push(stack)
.push(&filename);
Ok(url)
Expand Down
2 changes: 1 addition & 1 deletion commons/src/output/build_log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ where
formatted.push('\n');

match crate::output::warn_later::try_push(formatted) {
Ok(_) => {}
Ok(()) => {}
Err(error) => {
eprintln!("[Buildpack Warning]: Cannot use the delayed warning feature due to error: {error}");
self.log_warning_shared(s);
Expand Down
10 changes: 6 additions & 4 deletions commons/src/output/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::output::util::LinesWithEndings;
use const_format::formatcp;
use std::fmt::Write;

/// Helpers for formatting and colorizing your output
Expand Down Expand Up @@ -119,17 +120,18 @@ pub(crate) fn prefix_indent(prefix: impl AsRef<str>, contents: impl AsRef<str>)
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::<Vec<_>>();

if let Some((first, rest)) = lines.split_first() {
format!(
"{prefix}{first}{}",
rest.iter()
.map(|line| format!("{indent_str}{line}"))
.collect::<String>()
rest.iter().fold(String::new(), |mut output, line| {
let _ = write!(output, "{indent_str}{line}");
output
})
)
} else {
prefix.to_string()
Expand Down
16 changes: 10 additions & 6 deletions commons/src/output/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ pub(crate) fn strip_trailing_whitespace(s: impl AsRef<str>) -> String {
#[cfg(test)]
mod test {
use super::*;
use std::fmt::Write;

#[test]
fn test_trailing_whitespace() {
Expand All @@ -167,15 +168,18 @@ mod test {

#[test]
fn test_lines_with_endings() {
let actual = LinesWithEndings::from("foo\nbar")
.map(|line| format!("z{line}"))
.collect::<String>();
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::<String>();
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);
}
Expand Down

0 comments on commit 4b2e4c3

Please sign in to comment.