From 7ff34f00c2e5f1b69a8d5032d91a0a03f9e62780 Mon Sep 17 00:00:00 2001 From: Ruoqing He Date: Fri, 23 May 2025 11:27:47 +0000 Subject: [PATCH] agent: Fix clippy `single_match` Fix `single_match` clippy warning as suggested by rust 1.85.1. ```console warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` --> src/image.rs:241:9 | 241 | / match oci.annotations() { 242 | | Some(a) => { 243 | | if ImageService::is_sandbox(a) { 244 | | return ImageService::get_pause_image_process(); ... | 247 | | None => {} 248 | | } | |_________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#single_match help: try | 241 ~ if let Some(a) = oci.annotations() { 242 + if ImageService::is_sandbox(a) { 243 + return ImageService::get_pause_image_process(); 244 + } 245 + } | ``` Signed-off-by: Ruoqing He --- src/agent/src/image.rs | 9 +++------ src/agent/src/sandbox.rs | 9 +++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/agent/src/image.rs b/src/agent/src/image.rs index 74adb5dbbc..861ca3a5b9 100644 --- a/src/agent/src/image.rs +++ b/src/agent/src/image.rs @@ -238,13 +238,10 @@ pub fn get_process( } } if guest_pull { - match oci.annotations() { - Some(a) => { - if ImageService::is_sandbox(a) { - return ImageService::get_pause_image_process(); - } + if let Some(a) = oci.annotations() { + if ImageService::is_sandbox(a) { + return ImageService::get_pause_image_process(); } - None => {} } } Ok(ocip.clone()) diff --git a/src/agent/src/sandbox.rs b/src/agent/src/sandbox.rs index c68bc8905c..1277b973cf 100644 --- a/src/agent/src/sandbox.rs +++ b/src/agent/src/sandbox.rs @@ -428,13 +428,10 @@ impl Sandbox { pub fn setup_shared_mounts(&self, c: &LinuxContainer, mounts: &Vec) -> Result<()> { let mut src_ctrs: HashMap = HashMap::new(); for shared_mount in mounts { - match src_ctrs.get(&shared_mount.src_ctr) { - None => { - if let Some(c) = self.find_container_by_name(&shared_mount.src_ctr) { - src_ctrs.insert(shared_mount.src_ctr.clone(), c.init_process_pid); - } + if src_ctrs.get(&shared_mount.src_ctr) == None { + if let Some(c) = self.find_container_by_name(&shared_mount.src_ctr) { + src_ctrs.insert(shared_mount.src_ctr.clone(), c.init_process_pid); } - Some(_) => {} } }