Skip to content

Commit

Permalink
Fix all clippy warnings (beta toolchain version 1.85.0-beta.1)
Browse files Browse the repository at this point in the history
The improved `useless_conversion` lint [0] found quite a few cases of
unnecessary conversions (basically all `map_err(anyhow::Error::from)`
calls except one unnecessary instance of `map(Vec::from)`).

The pretty new `literal_string_with_formatting_args` lint [1] also got
improved to discover a formatting string that we don't evaluate. This is
a false positive though as we pass it to `indicatif::ProgressBars` as
`bar_template` string.

[0]: https://rust-lang.github.io/rust-clippy/master/index.html#useless_conversion
[1]: https://rust-lang.github.io/rust-clippy/master/index.html#literal_string_with_formatting_args

Signed-off-by: Michael Weiss <[email protected]>
  • Loading branch information
primeos-work committed Jan 10, 2025
1 parent f7c68cb commit 9c2892f
Show file tree
Hide file tree
Showing 17 changed files with 21 additions and 51 deletions.
16 changes: 8 additions & 8 deletions src/commands/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,12 @@ fn cli(db_connection_config: DbConnectionConfig<'_>, matches: &ArgMatches) -> Re
info!("psql exited successfully");
Ok(())
} else {
Err(anyhow!("psql did not exit successfully"))
.with_context(|| match String::from_utf8(out.stderr) {
Err(anyhow!("psql did not exit successfully")).with_context(|| {
match String::from_utf8(out.stderr) {
Ok(log) => anyhow!("{}", log),
Err(e) => anyhow!("Cannot parse log into valid UTF-8: {}", e),
})
.map_err(Error::from)
}
})
}
})
}
Expand All @@ -127,12 +127,12 @@ fn cli(db_connection_config: DbConnectionConfig<'_>, matches: &ArgMatches) -> Re
info!("pgcli exited successfully");
Ok(())
} else {
Err(anyhow!("pgcli did not exit successfully"))
.with_context(|| match String::from_utf8(out.stderr) {
Err(anyhow!("pgcli did not exit successfully")).with_context(|| {
match String::from_utf8(out.stderr) {
Ok(log) => anyhow!("{}", log),
Err(e) => anyhow!("Cannot parse log into valid UTF-8: {}", e),
})
.map_err(Error::from)
}
})
}
})
}
Expand Down
1 change: 0 additions & 1 deletion src/commands/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ async fn containers_top(
.top(None)
.await
.with_context(|| anyhow!("Fetching 'top' for {}", stat.id))
.map_err(Error::from)
.map(|top| (stat.id, top))
})
.collect::<futures::stream::FuturesUnordered<_>>()
Expand Down
1 change: 0 additions & 1 deletion src/commands/release.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ async fn new_release(
.with_context(|| {
anyhow!("Copying {} to {}", art_path.display(), dest_path.display())
})
.map_err(Error::from)
.and_then(|_| {
debug!("Updating {:?} to set released = true", art);
let rel = crate::db::models::Release::create(
Expand Down
3 changes: 1 addition & 2 deletions src/commands/source/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,7 @@ pub async fn download(
"Cannot download source that is marked for manual download"
))
.context(anyhow!("Creating source: {}", source.path().display()))
.context(anyhow!("Downloading source: {}", source.url()))
.map_err(Error::from);
.context(anyhow!("Downloading source: {}", source.url()));
}

if source_path_exists && !force {
Expand Down
2 changes: 0 additions & 2 deletions src/commands/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ pub fn mk_package_name_regex(regex: &str) -> Result<Regex> {
builder
.build()
.with_context(|| anyhow!("Failed to build regex from '{}'", regex))
.map_err(Error::from)
}

/// Make a header column for the ascii_table crate
Expand Down Expand Up @@ -259,7 +258,6 @@ pub fn get_date_filter(
.checked_sub_signed(dur)
.ok_or_else(|| anyhow!("Time calculation would overflow"))
.with_context(|| anyhow!("Cannot subtract {} from 'now'", dur))
.map_err(Error::from)
})
.transpose()
}
3 changes: 3 additions & 0 deletions src/config/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
//! configuration and having to use default values.
/// The default progress bar format
// Ignore a false positive Clippy warning (we pass this format string to
// `indicatif::ProgressBars` as `bar_template` instead of evaluating it here):
#[rustversion::attr(since(1.83), allow(clippy::literal_string_with_formatting_args))]
pub fn default_progress_format() -> String {
String::from("{elapsed_precise} {percent:>3}% {bar:5.cyan/blue} | {msg}")
}
Expand Down
1 change: 0 additions & 1 deletion src/db/models/githash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,5 @@ impl GitHash {
.find(git_hash_id)
.first::<_>(database_connection)
.context("Loading GitHash")
.map_err(Error::from)
}
}
1 change: 0 additions & 1 deletion src/db/models/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ impl Job {
.filter(uuid.eq(job_uuid))
.first::<Job>(conn)
.with_context(|| format!("Finding created job in database: {job_uuid}"))
.map_err(Error::from)
})
}

Expand Down
1 change: 0 additions & 1 deletion src/db/models/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,5 @@ impl Submit {
.filter(submits::uuid.eq(submit_id))
.first::<Submit>(database_connection)
.context("Loading submit")
.map_err(Error::from)
}
}
13 changes: 1 addition & 12 deletions src/endpoint/configured.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ impl Endpoint {
crate::config::EndpointType::Http => shiplift::Uri::from_str(ep.uri())
.map(shiplift::Docker::host)
.with_context(|| anyhow!("Connecting to {}", ep.uri()))
.map_err(Error::from)
.map(|docker| {
Endpoint::builder()
.name(ep_name.clone())
Expand Down Expand Up @@ -596,7 +595,6 @@ impl<'a> PreparedContainer<'a> {
container.id()
)
})
.map_err(Error::from)
})
.collect::<futures::stream::FuturesUnordered<_>>()
.collect::<Result<()>>()
Expand All @@ -608,7 +606,6 @@ impl<'a> PreparedContainer<'a> {
)
})
.with_context(|| anyhow!("Copying sources to container {}", container.id()))
.map_err(Error::from)
}

async fn copy_patches_to_container(container: &Container<'_>, job: &RunnableJob) -> Result<()> {
Expand Down Expand Up @@ -655,15 +652,12 @@ impl<'a> PreparedContainer<'a> {
container.id()
)
})
.map_err(Error::from)
})
.collect::<futures::stream::FuturesUnordered<_>>()
.collect::<Result<()>>()
.await
.map_err(Error::from)
.inspect(|_| trace!("Copied all patches"))
.with_context(|| anyhow!("Copying patches to container {}", container.id()))
.map_err(Error::from)
}

async fn copy_artifacts_to_container(
Expand Down Expand Up @@ -746,8 +740,7 @@ impl<'a> PreparedContainer<'a> {
container.id(),
destination.display()
)
})
.map_err(Error::from);
});
drop(art); // ensure `art` is moved into closure
r
});
Expand All @@ -767,7 +760,6 @@ impl<'a> PreparedContainer<'a> {
)
})
.with_context(|| anyhow!("Copying artifacts to container {}", container.id()))
.map_err(Error::from)
.map(|_| ())
}

Expand All @@ -778,7 +770,6 @@ impl<'a> PreparedContainer<'a> {
.await
.inspect(|_| trace!("Successfully copied script to container {}", container.id()))
.with_context(|| anyhow!("Copying the script into container {}", container.id()))
.map_err(Error::from)
}

pub async fn start(self) -> Result<StartedContainer<'a>> {
Expand Down Expand Up @@ -877,7 +868,6 @@ impl<'a> StartedContainer<'a> {
.with_context(|| anyhow!("Sending log to log sink"))
.map(|_| exited_successfully)
})
.map_err(Error::from)
})
.collect::<Result<Vec<_>>>()
.map(|r| {
Expand Down Expand Up @@ -964,7 +954,6 @@ impl ExecutedContainer<'_> {
self.create_info.id
)
})
.map_err(Error::from)
});

let mut writelock = staging_store.write().await;
Expand Down
4 changes: 1 addition & 3 deletions src/endpoint/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,7 @@ impl JobHandle {
&endpoint_uri,
&container_id,
)
})
.map_err(Error::from);
});

if res.is_err() {
trace!("Error was returned from script");
Expand Down Expand Up @@ -524,7 +523,6 @@ impl LogReceiver<'_> {
.await
.map(tokio::io::BufWriter::new)
.with_context(|| anyhow!("Opening {}", path.display()))
.map_err(Error::from)
})
} else {
None
Expand Down
2 changes: 0 additions & 2 deletions src/filestore/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,9 +206,7 @@ impl<'a> FullArtifactPath<'a> {
pub async fn read(self) -> Result<Vec<u8>> {
tokio::fs::read(self.joined())
.await
.map(Vec::from)
.with_context(|| anyhow!("Reading artifact from path {}", self.0.display()))
.map_err(Error::from)
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/filestore/staging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use std::fmt::Debug;

use anyhow::anyhow;
use anyhow::Context;
use anyhow::Error;
use anyhow::Result;
use futures::stream::Stream;
use indicatif::ProgressBar;
Expand Down Expand Up @@ -54,7 +53,6 @@ impl StagingStore {
trace!("Unpacking archive to {}", dest.display());
dest.unpack_archive_here(tar::Archive::new(&bytes[..]))
.context("Unpacking TAR")
.map_err(Error::from)
})
.context("Concatenating the output bytestream")?
.into_iter()
Expand Down
17 changes: 7 additions & 10 deletions src/package/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use std::process::ExitStatus;

use anyhow::anyhow;
use anyhow::Context as AnyhowContext;
use anyhow::Error;
use anyhow::Result;
use handlebars::{
Context, Handlebars, Helper, HelperDef, HelperResult, JsonRender, Output, PathAndJson,
Expand Down Expand Up @@ -247,15 +246,13 @@ impl<'a> ScriptBuilder<'a> {
trace!("Rendering Package: {:?}", package.debug_details());
}

hb.render("script", package)
.with_context(|| {
anyhow!(
"Rendering script for package {} {} failed",
package.name(),
package.version()
)
})
.map_err(Error::from)
hb.render("script", package).with_context(|| {
anyhow!(
"Rendering script for package {} {} failed",
package.name(),
package.version()
)
})
}
}

Expand Down
2 changes: 0 additions & 2 deletions src/package/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use std::ops::Deref;

use anyhow::anyhow;
use anyhow::Context;
use anyhow::Error;
use anyhow::Result;
use pom::parser::Parser as PomParser;
use serde::Deserialize;
Expand Down Expand Up @@ -67,7 +66,6 @@ impl TryFrom<&str> for PackageVersionConstraint {
.parse(s.as_bytes())
.context(anyhow!("Failed to parse the following package version constraint: {}", s))
.context("A package version constraint must have a comparator (only `=` is currently supported) and a version string, like so: =0.1.0")
.map_err(Error::from)
}
}

Expand Down
1 change: 0 additions & 1 deletion src/repository/fs/representation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ fn load_file(path: &Path) -> Result<String> {
trace!("Reading {}", path.display());
std::fs::read_to_string(path)
.with_context(|| anyhow!("Reading file from filesystem: {}", path.display()))
.map_err(Error::from)
}

#[cfg(test)]
Expand Down
2 changes: 0 additions & 2 deletions src/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use std::path::PathBuf;

use anyhow::anyhow;
use anyhow::Context;
use anyhow::Error;
use anyhow::Result;
use tracing::trace;
use url::Url;
Expand Down Expand Up @@ -140,6 +139,5 @@ impl SourceEntry {
.open(&p)
.await
.with_context(|| anyhow!("Creating file: {}", p.display()))
.map_err(Error::from)
}
}

0 comments on commit 9c2892f

Please sign in to comment.