Skip to content

Commit 9c2892f

Browse files
committed
Fix all clippy warnings (beta toolchain version 1.85.0-beta.1)
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]>
1 parent f7c68cb commit 9c2892f

File tree

17 files changed

+21
-51
lines changed

17 files changed

+21
-51
lines changed

src/commands/db.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,12 @@ fn cli(db_connection_config: DbConnectionConfig<'_>, matches: &ArgMatches) -> Re
9595
info!("psql exited successfully");
9696
Ok(())
9797
} else {
98-
Err(anyhow!("psql did not exit successfully"))
99-
.with_context(|| match String::from_utf8(out.stderr) {
98+
Err(anyhow!("psql did not exit successfully")).with_context(|| {
99+
match String::from_utf8(out.stderr) {
100100
Ok(log) => anyhow!("{}", log),
101101
Err(e) => anyhow!("Cannot parse log into valid UTF-8: {}", e),
102-
})
103-
.map_err(Error::from)
102+
}
103+
})
104104
}
105105
})
106106
}
@@ -127,12 +127,12 @@ fn cli(db_connection_config: DbConnectionConfig<'_>, matches: &ArgMatches) -> Re
127127
info!("pgcli exited successfully");
128128
Ok(())
129129
} else {
130-
Err(anyhow!("pgcli did not exit successfully"))
131-
.with_context(|| match String::from_utf8(out.stderr) {
130+
Err(anyhow!("pgcli did not exit successfully")).with_context(|| {
131+
match String::from_utf8(out.stderr) {
132132
Ok(log) => anyhow!("{}", log),
133133
Err(e) => anyhow!("Cannot parse log into valid UTF-8: {}", e),
134-
})
135-
.map_err(Error::from)
134+
}
135+
})
136136
}
137137
})
138138
}

src/commands/endpoint.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,6 @@ async fn containers_top(
385385
.top(None)
386386
.await
387387
.with_context(|| anyhow!("Fetching 'top' for {}", stat.id))
388-
.map_err(Error::from)
389388
.map(|top| (stat.id, top))
390389
})
391390
.collect::<futures::stream::FuturesUnordered<_>>()

src/commands/release.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ async fn new_release(
203203
.with_context(|| {
204204
anyhow!("Copying {} to {}", art_path.display(), dest_path.display())
205205
})
206-
.map_err(Error::from)
207206
.and_then(|_| {
208207
debug!("Updating {:?} to set released = true", art);
209208
let rel = crate::db::models::Release::create(

src/commands/source/download.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ pub async fn download(
246246
"Cannot download source that is marked for manual download"
247247
))
248248
.context(anyhow!("Creating source: {}", source.path().display()))
249-
.context(anyhow!("Downloading source: {}", source.url()))
250-
.map_err(Error::from);
249+
.context(anyhow!("Downloading source: {}", source.url()));
251250
}
252251

253252
if source_path_exists && !force {

src/commands/util.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ pub fn mk_package_name_regex(regex: &str) -> Result<Regex> {
159159
builder
160160
.build()
161161
.with_context(|| anyhow!("Failed to build regex from '{}'", regex))
162-
.map_err(Error::from)
163162
}
164163

165164
/// Make a header column for the ascii_table crate
@@ -259,7 +258,6 @@ pub fn get_date_filter(
259258
.checked_sub_signed(dur)
260259
.ok_or_else(|| anyhow!("Time calculation would overflow"))
261260
.with_context(|| anyhow!("Cannot subtract {} from 'now'", dur))
262-
.map_err(Error::from)
263261
})
264262
.transpose()
265263
}

src/config/util.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@
1212
//! configuration and having to use default values.
1313
1414
/// The default progress bar format
15+
// Ignore a false positive Clippy warning (we pass this format string to
16+
// `indicatif::ProgressBars` as `bar_template` instead of evaluating it here):
17+
#[rustversion::attr(since(1.83), allow(clippy::literal_string_with_formatting_args))]
1518
pub fn default_progress_format() -> String {
1619
String::from("{elapsed_precise} {percent:>3}% {bar:5.cyan/blue} | {msg}")
1720
}

src/db/models/githash.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,5 @@ impl GitHash {
5353
.find(git_hash_id)
5454
.first::<_>(database_connection)
5555
.context("Loading GitHash")
56-
.map_err(Error::from)
5756
}
5857
}

src/db/models/job.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ impl Job {
9292
.filter(uuid.eq(job_uuid))
9393
.first::<Job>(conn)
9494
.with_context(|| format!("Finding created job in database: {job_uuid}"))
95-
.map_err(Error::from)
9695
})
9796
}
9897

src/db/models/submit.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,5 @@ impl Submit {
8080
.filter(submits::uuid.eq(submit_id))
8181
.first::<Submit>(database_connection)
8282
.context("Loading submit")
83-
.map_err(Error::from)
8483
}
8584
}

src/endpoint/configured.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ impl Endpoint {
123123
crate::config::EndpointType::Http => shiplift::Uri::from_str(ep.uri())
124124
.map(shiplift::Docker::host)
125125
.with_context(|| anyhow!("Connecting to {}", ep.uri()))
126-
.map_err(Error::from)
127126
.map(|docker| {
128127
Endpoint::builder()
129128
.name(ep_name.clone())
@@ -596,7 +595,6 @@ impl<'a> PreparedContainer<'a> {
596595
container.id()
597596
)
598597
})
599-
.map_err(Error::from)
600598
})
601599
.collect::<futures::stream::FuturesUnordered<_>>()
602600
.collect::<Result<()>>()
@@ -608,7 +606,6 @@ impl<'a> PreparedContainer<'a> {
608606
)
609607
})
610608
.with_context(|| anyhow!("Copying sources to container {}", container.id()))
611-
.map_err(Error::from)
612609
}
613610

614611
async fn copy_patches_to_container(container: &Container<'_>, job: &RunnableJob) -> Result<()> {
@@ -655,15 +652,12 @@ impl<'a> PreparedContainer<'a> {
655652
container.id()
656653
)
657654
})
658-
.map_err(Error::from)
659655
})
660656
.collect::<futures::stream::FuturesUnordered<_>>()
661657
.collect::<Result<()>>()
662658
.await
663-
.map_err(Error::from)
664659
.inspect(|_| trace!("Copied all patches"))
665660
.with_context(|| anyhow!("Copying patches to container {}", container.id()))
666-
.map_err(Error::from)
667661
}
668662

669663
async fn copy_artifacts_to_container(
@@ -746,8 +740,7 @@ impl<'a> PreparedContainer<'a> {
746740
container.id(),
747741
destination.display()
748742
)
749-
})
750-
.map_err(Error::from);
743+
});
751744
drop(art); // ensure `art` is moved into closure
752745
r
753746
});
@@ -767,7 +760,6 @@ impl<'a> PreparedContainer<'a> {
767760
)
768761
})
769762
.with_context(|| anyhow!("Copying artifacts to container {}", container.id()))
770-
.map_err(Error::from)
771763
.map(|_| ())
772764
}
773765

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

784775
pub async fn start(self) -> Result<StartedContainer<'a>> {
@@ -877,7 +868,6 @@ impl<'a> StartedContainer<'a> {
877868
.with_context(|| anyhow!("Sending log to log sink"))
878869
.map(|_| exited_successfully)
879870
})
880-
.map_err(Error::from)
881871
})
882872
.collect::<Result<Vec<_>>>()
883873
.map(|r| {
@@ -964,7 +954,6 @@ impl ExecutedContainer<'_> {
964954
self.create_info.id
965955
)
966956
})
967-
.map_err(Error::from)
968957
});
969958

970959
let mut writelock = staging_store.write().await;

src/endpoint/scheduler.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,7 @@ impl JobHandle {
275275
&endpoint_uri,
276276
&container_id,
277277
)
278-
})
279-
.map_err(Error::from);
278+
});
280279

281280
if res.is_err() {
282281
trace!("Error was returned from script");
@@ -524,7 +523,6 @@ impl LogReceiver<'_> {
524523
.await
525524
.map(tokio::io::BufWriter::new)
526525
.with_context(|| anyhow!("Opening {}", path.display()))
527-
.map_err(Error::from)
528526
})
529527
} else {
530528
None

src/filestore/path.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,7 @@ impl<'a> FullArtifactPath<'a> {
206206
pub async fn read(self) -> Result<Vec<u8>> {
207207
tokio::fs::read(self.joined())
208208
.await
209-
.map(Vec::from)
210209
.with_context(|| anyhow!("Reading artifact from path {}", self.0.display()))
211-
.map_err(Error::from)
212210
}
213211
}
214212

src/filestore/staging.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use std::fmt::Debug;
1212

1313
use anyhow::anyhow;
1414
use anyhow::Context;
15-
use anyhow::Error;
1615
use anyhow::Result;
1716
use futures::stream::Stream;
1817
use indicatif::ProgressBar;
@@ -54,7 +53,6 @@ impl StagingStore {
5453
trace!("Unpacking archive to {}", dest.display());
5554
dest.unpack_archive_here(tar::Archive::new(&bytes[..]))
5655
.context("Unpacking TAR")
57-
.map_err(Error::from)
5856
})
5957
.context("Concatenating the output bytestream")?
6058
.into_iter()

src/package/script.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use std::process::ExitStatus;
1515

1616
use anyhow::anyhow;
1717
use anyhow::Context as AnyhowContext;
18-
use anyhow::Error;
1918
use anyhow::Result;
2019
use handlebars::{
2120
Context, Handlebars, Helper, HelperDef, HelperResult, JsonRender, Output, PathAndJson,
@@ -247,15 +246,13 @@ impl<'a> ScriptBuilder<'a> {
247246
trace!("Rendering Package: {:?}", package.debug_details());
248247
}
249248

250-
hb.render("script", package)
251-
.with_context(|| {
252-
anyhow!(
253-
"Rendering script for package {} {} failed",
254-
package.name(),
255-
package.version()
256-
)
257-
})
258-
.map_err(Error::from)
249+
hb.render("script", package).with_context(|| {
250+
anyhow!(
251+
"Rendering script for package {} {} failed",
252+
package.name(),
253+
package.version()
254+
)
255+
})
259256
}
260257
}
261258

src/package/version.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use std::ops::Deref;
1212

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

src/repository/fs/representation.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ fn load_file(path: &Path) -> Result<String> {
266266
trace!("Reading {}", path.display());
267267
std::fs::read_to_string(path)
268268
.with_context(|| anyhow!("Reading file from filesystem: {}", path.display()))
269-
.map_err(Error::from)
270269
}
271270

272271
#[cfg(test)]

src/source/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use std::path::PathBuf;
1212

1313
use anyhow::anyhow;
1414
use anyhow::Context;
15-
use anyhow::Error;
1615
use anyhow::Result;
1716
use tracing::trace;
1817
use url::Url;
@@ -140,6 +139,5 @@ impl SourceEntry {
140139
.open(&p)
141140
.await
142141
.with_context(|| anyhow!("Creating file: {}", p.display()))
143-
.map_err(Error::from)
144142
}
145143
}

0 commit comments

Comments
 (0)