Skip to content

Commit ea360d6

Browse files
authored
Merge pull request #1551 from cgwalters/various-clippy
crates/*: Fix most clippy lints
2 parents d368ea8 + adab6b0 commit ea360d6

File tree

39 files changed

+131
-173
lines changed

39 files changed

+131
-173
lines changed

crates/blockdev/src/blockdev.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl Device {
4949

5050
#[allow(dead_code)]
5151
pub fn has_children(&self) -> bool {
52-
self.children.as_ref().map_or(false, |v| !v.is_empty())
52+
self.children.as_ref().is_some_and(|v| !v.is_empty())
5353
}
5454

5555
// The "start" parameter was only added in a version of util-linux that's only
@@ -451,7 +451,7 @@ mod test {
451451
#[test]
452452
fn test_parse_lsblk() {
453453
let fixture = include_str!("../tests/fixtures/lsblk.json");
454-
let devs: DevicesOutput = serde_json::from_str(&fixture).unwrap();
454+
let devs: DevicesOutput = serde_json::from_str(fixture).unwrap();
455455
let dev = devs.blockdevices.into_iter().next().unwrap();
456456
let children = dev.children.as_deref().unwrap();
457457
assert_eq!(children.len(), 3);
@@ -498,7 +498,7 @@ mod test {
498498
}
499499
}
500500
"# };
501-
let table: SfDiskOutput = serde_json::from_str(&fixture).unwrap();
501+
let table: SfDiskOutput = serde_json::from_str(fixture).unwrap();
502502
assert_eq!(
503503
table.partitiontable.find("/dev/loop0p2").unwrap().size,
504504
20961247

crates/lib/src/cfsctl.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,7 @@ enum Command {
148148
}
149149

150150
fn verity_opt(opt: &Option<String>) -> Result<Option<Sha512HashValue>> {
151-
Ok(opt
152-
.as_ref()
153-
.map(|value| FsVerityHashValue::from_hex(value))
154-
.transpose()?)
151+
Ok(opt.as_ref().map(FsVerityHashValue::from_hex).transpose()?)
155152
}
156153

157154
pub(crate) async fn run_from_iter<I>(system_store: &crate::store::Storage, args: I) -> Result<()>

crates/lib/src/cli.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -921,17 +921,9 @@ async fn upgrade(opts: UpgradeOpts) -> Result<()> {
921921

922922
// If there's no specified image, let's be nice and check if the booted system is using rpm-ostree
923923
if imgref.is_none() {
924-
let booted_incompatible = host
925-
.status
926-
.booted
927-
.as_ref()
928-
.map_or(false, |b| b.incompatible);
924+
let booted_incompatible = host.status.booted.as_ref().is_some_and(|b| b.incompatible);
929925

930-
let staged_incompatible = host
931-
.status
932-
.staged
933-
.as_ref()
934-
.map_or(false, |b| b.incompatible);
926+
let staged_incompatible = host.status.staged.as_ref().is_some_and(|b| b.incompatible);
935927

936928
if booted_incompatible || staged_incompatible {
937929
return Err(anyhow::anyhow!(

crates/lib/src/deploy.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ async fn handle_layer_progress_print(
201201
subtask = SubTaskBytes {
202202
subtask: layer_type.into(),
203203
description: format!("{layer_type}: {short_digest}").clone().into(),
204-
id: format!("{short_digest}").clone().into(),
204+
id: short_digest.to_string().clone().into(),
205205
bytes_cached: 0,
206206
bytes: 0,
207207
bytes_total: layer_size,

crates/lib/src/fsck.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,6 @@ async fn verity_state_of_all_objects(
213213
.map_err(|_| anyhow::anyhow!("Invalid UTF-8"))?;
214214

215215
let objdir = ent.open_dir()?;
216-
let expected = expected.clone();
217216
joinset.spawn_blocking(move || verity_state_of_objects(&objdir, name.as_str(), expected));
218217
}
219218

crates/lib/src/install.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,7 @@ async fn install_to_filesystem_impl(
14471447
if matches!(cleanup, Cleanup::TriggerOnNextBoot) {
14481448
let sysroot_dir = crate::utils::sysroot_dir(ostree)?;
14491449
tracing::debug!("Writing {DESTRUCTIVE_CLEANUP}");
1450-
sysroot_dir.atomic_write(format!("etc/{}", DESTRUCTIVE_CLEANUP), b"")?;
1450+
sysroot_dir.atomic_write(format!("etc/{DESTRUCTIVE_CLEANUP}"), b"")?;
14511451
}
14521452

14531453
// We must drop the sysroot here in order to close any open file

crates/lib/src/lints.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ impl Lint {
155155
f: LintFn,
156156
) -> Self {
157157
Lint {
158-
name: name,
158+
name,
159159
ty: LintType::Fatal,
160160
f: LintFnTy::Regular(f),
161-
description: description,
161+
description,
162162
root_type: None,
163163
}
164164
}
@@ -169,10 +169,10 @@ impl Lint {
169169
f: LintFn,
170170
) -> Self {
171171
Lint {
172-
name: name,
172+
name,
173173
ty: LintType::Warning,
174174
f: LintFnTy::Regular(f),
175-
description: description,
175+
description,
176176
root_type: None,
177177
}
178178
}
@@ -290,7 +290,7 @@ fn lint_inner<'skip>(
290290
results.push((lint, f(&root, &config)));
291291
}
292292

293-
let mut recursive_lints = BTreeSet::from_iter(recursive_lints.into_iter());
293+
let mut recursive_lints = BTreeSet::from_iter(recursive_lints);
294294
let mut recursive_errors = BTreeMap::new();
295295
root.walk(
296296
&WalkConfiguration::default()
@@ -327,7 +327,7 @@ fn lint_inner<'skip>(
327327
},
328328
)?;
329329
// Extend our overall result set with the recursive-lint errors.
330-
results.extend(recursive_errors.into_iter().map(|(lint, e)| (lint, e)));
330+
results.extend(recursive_errors);
331331
// Any recursive lint still in this list succeeded.
332332
results.extend(recursive_lints.into_iter().map(|lint| (lint, lint_ok())));
333333
for (lint, r) in results {
@@ -511,7 +511,7 @@ fn check_utf8(e: &WalkComponent, _config: &LintExecutionConfig) -> LintRecursive
511511

512512
if e.file_type.is_symlink() {
513513
let target = e.dir.read_link_contents(filename)?;
514-
if !target.to_str().is_some() {
514+
if target.to_str().is_none() {
515515
return lint_err(format!(
516516
"{}: Found non-utf8 symlink target",
517517
PathQuotedDisplay::new(&path)
@@ -754,7 +754,7 @@ Any content here in the container image will be masked at runtime.
754754
);
755755
fn check_boot(root: &Dir, config: &LintExecutionConfig) -> LintResult {
756756
let Some(d) = root.open_dir_optional("boot")? else {
757-
return lint_err(format!("Missing /boot directory"));
757+
return lint_err("Missing /boot directory");
758758
};
759759

760760
// First collect all entries to determine if the directory is empty
@@ -1161,7 +1161,7 @@ mod tests {
11611161
output_str.clear();
11621162

11631163
// Test case 2: Iterator with one item
1164-
let items_one = vec!["item1"];
1164+
let items_one = ["item1"];
11651165
format_items(&config, header, items_one.iter(), &mut output_str)?;
11661166
assert_eq!(output_str, "Test Header:\n item1\n");
11671167
output_str.clear();
@@ -1194,7 +1194,7 @@ mod tests {
11941194
output_str.clear();
11951195

11961196
// Test case 2: Iterator with fewer items than DEFAULT_TRUNCATED_OUTPUT
1197-
let items_few = vec!["item1", "item2"];
1197+
let items_few = ["item1", "item2"];
11981198
format_items(&config, header, items_few.iter(), &mut output_str)?;
11991199
assert_eq!(output_str, "Test Header:\n item1\n item2\n");
12001200
output_str.clear();
@@ -1246,7 +1246,7 @@ mod tests {
12461246
let header = "Numbers";
12471247
let mut output_str = String::new();
12481248

1249-
let items_numbers = vec![1, 2, 3];
1249+
let items_numbers = [1, 2, 3];
12501250
format_items(&config, header, items_numbers.iter(), &mut output_str)?;
12511251
similar_asserts::assert_eq!(output_str, "Numbers:\n 1\n 2\n 3\n");
12521252

crates/lib/src/podstorage.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ fn bind_storage_roots(cmd: &mut Command, storage_root: &Dir, run_root: &Dir) ->
122122
fn new_podman_cmd_in(storage_root: &Dir, run_root: &Dir) -> Result<Command> {
123123
let mut cmd = Command::new("podman");
124124
bind_storage_roots(&mut cmd, storage_root, run_root)?;
125-
let run_root = format!("/proc/self/fd/{}", STORAGE_RUN_FD);
125+
let run_root = format!("/proc/self/fd/{STORAGE_RUN_FD}");
126126
cmd.args(["--root", STORAGE_ALIAS_DIR, "--runroot", run_root.as_str()]);
127127
Ok(cmd)
128128
}
@@ -288,7 +288,6 @@ impl CStorage {
288288
Ok(r)
289289
})
290290
.await?
291-
.map_err(Into::into)
292291
}
293292

294293
#[context("Pruning")]

crates/lib/src/progress_jsonl.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl ProgressWriter {
248248
/// Send an event.
249249
pub(crate) async fn send(&self, event: Event<'_>) {
250250
if let Err(e) = self.send_impl(event, true).await {
251-
eprintln!("Failed to write to jsonl: {}", e);
251+
eprintln!("Failed to write to jsonl: {e}");
252252
// Stop writing to fd but let process continue
253253
// SAFETY: Propagating panics from the mutex here is intentional
254254
let _ = self.inner.lock().await.take();
@@ -258,7 +258,7 @@ impl ProgressWriter {
258258
/// Send an event that can be dropped.
259259
pub(crate) async fn send_lossy(&self, event: Event<'_>) {
260260
if let Err(e) = self.send_impl(event, false).await {
261-
eprintln!("Failed to write to jsonl: {}", e);
261+
eprintln!("Failed to write to jsonl: {e}");
262262
// Stop writing to fd but let process continue
263263
// SAFETY: Propagating panics from the mutex here is intentional
264264
let _ = self.inner.lock().await.take();

crates/lib/src/spec.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,7 @@ pub struct ImageReference {
9595
/// If the reference is in :tag@digest form, strip the tag.
9696
fn canonicalize_reference(reference: Reference) -> Option<Reference> {
9797
// No tag? Just pass through.
98-
if reference.tag().is_none() {
99-
return None;
100-
}
98+
reference.tag()?;
10199

102100
// No digest? Also pass through.
103101
let Some(digest) = reference.digest() else {
@@ -126,7 +124,7 @@ impl ImageReference {
126124
transport: self.transport.clone(),
127125
signature: self.signature.clone(),
128126
};
129-
return Ok(r);
127+
Ok(r)
130128
}
131129
_ => {
132130
// For other transports, we don't do any canonicalization
@@ -349,14 +347,14 @@ mod tests {
349347
let test_cases = [
350348
// When both a tag and digest are present, the digest should be used
351349
(
352-
format!("quay.io/example/someimage:latest@{}", sample_digest),
353-
format!("quay.io/example/someimage@{}", sample_digest),
350+
format!("quay.io/example/someimage:latest@{sample_digest}"),
351+
format!("quay.io/example/someimage@{sample_digest}"),
354352
"registry",
355353
),
356354
// When only a digest is present, it should be used
357355
(
358-
format!("quay.io/example/someimage@{}", sample_digest),
359-
format!("quay.io/example/someimage@{}", sample_digest),
356+
format!("quay.io/example/someimage@{sample_digest}"),
357+
format!("quay.io/example/someimage@{sample_digest}"),
360358
"registry",
361359
),
362360
// When only a tag is present, it should be preserved
@@ -385,13 +383,13 @@ mod tests {
385383
),
386384
// Other cases are not canonicalized
387385
(
388-
format!("quay.io/example/someimage:latest@{}", sample_digest),
389-
format!("quay.io/example/someimage:latest@{}", sample_digest),
386+
format!("quay.io/example/someimage:latest@{sample_digest}"),
387+
format!("quay.io/example/someimage:latest@{sample_digest}"),
390388
"containers-storage",
391389
),
392390
(
393-
format!("/path/to/dir:latest"),
394-
format!("/path/to/dir:latest"),
391+
"/path/to/dir:latest".to_string(),
392+
"/path/to/dir:latest".to_string(),
395393
"oci",
396394
),
397395
(

0 commit comments

Comments
 (0)