From c80319182ddc2381cba4ae7dc78f6e666b7dacf3 Mon Sep 17 00:00:00 2001 From: Daniel Verkamp Date: Mon, 10 May 2021 13:52:04 -0700 Subject: [PATCH] tree-wide: replace single-leaf match with if let Fixes the clippy warning: you seem to be trying to use `match` for destructuring a single pattern. Consider using `if let` https://rust-lang.github.io/rust-clippy/master/index.html#single_match BUG=None TEST=bin/clippy Change-Id: I5901a1fa0f487e0f012bad4c21b43ea300348031 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/2885786 Tested-by: kokoro Commit-Queue: Daniel Verkamp Reviewed-by: Zach Reizner Reviewed-by: Gurchetan Singh --- bin/clippy | 1 - rutabaga_gfx/src/cross_domain/cross_domain.rs | 49 ++++++++----------- src/gdb.rs | 10 ++-- vm_memory/src/guest_memory.rs | 5 +- 4 files changed, 27 insertions(+), 38 deletions(-) diff --git a/bin/clippy b/bin/clippy index a98f4ba040..236ad3c180 100755 --- a/bin/clippy +++ b/bin/clippy @@ -39,7 +39,6 @@ SUPPRESS=( needless_range_loop option_map_unit_fn range_plus_one - single_match slow_vector_initialization unnecessary_filter_map unnecessary_mut_passed diff --git a/rutabaga_gfx/src/cross_domain/cross_domain.rs b/rutabaga_gfx/src/cross_domain/cross_domain.rs index 6b73553b21..49aa005afd 100644 --- a/rutabaga_gfx/src/cross_domain/cross_domain.rs +++ b/rutabaga_gfx/src/cross_domain/cross_domain.rs @@ -211,28 +211,22 @@ impl RutabagaContext for CrossDomainContext { } fn attach(&mut self, resource: &mut RutabagaResource) { - match resource.blob_mem { - RUTABAGA_BLOB_MEM_GUEST => { - self.context_resources.insert( - resource.resource_id, - CrossDomainResource { - handle: None, - backing_iovecs: resource.backing_iovecs.take(), - }, - ); - } - _ => match resource.handle { - Some(ref handle) => { - self.context_resources.insert( - resource.resource_id, - CrossDomainResource { - handle: Some(handle.clone()), - backing_iovecs: None, - }, - ); - } - _ => (), - }, + if resource.blob_mem == RUTABAGA_BLOB_MEM_GUEST { + self.context_resources.insert( + resource.resource_id, + CrossDomainResource { + handle: None, + backing_iovecs: resource.backing_iovecs.take(), + }, + ); + } else if let Some(ref handle) = resource.handle { + self.context_resources.insert( + resource.resource_id, + CrossDomainResource { + handle: Some(handle.clone()), + backing_iovecs: None, + }, + ); } } @@ -261,14 +255,11 @@ impl RutabagaComponent for CrossDomain { fn get_capset(&self, _capset_id: u32, _version: u32) -> Vec { let mut caps: CrossDomainCapabilities = Default::default(); - match self.channels { - Some(ref channels) => { - for channel in channels { - caps.supported_channels = 1 << channel.channel_type; - } + if let Some(ref channels) = self.channels { + for channel in channels { + caps.supported_channels = 1 << channel.channel_type; } - None => (), - }; + } if self.gralloc.lock().supports_dmabuf() { caps.supports_dmabuf = 1; diff --git a/src/gdb.rs b/src/gdb.rs index 6a18f5564c..080124158a 100644 --- a/src/gdb.rs +++ b/src/gdb.rs @@ -175,11 +175,12 @@ impl SingleThreadOps for GdbStub { // Polling loop { - match self + // TODO(keiichiw): handle error? + if let Ok(msg) = self .from_vcpu .recv_timeout(std::time::Duration::from_millis(100)) { - Ok(msg) => match msg.msg { + match msg.msg { VcpuDebugStatus::HitBreakPoint => { if single_step { return Ok(StopReason::DoneStep); @@ -190,9 +191,8 @@ impl SingleThreadOps for GdbStub { status => { error!("Unexpected VcpuDebugStatus: {:?}", status); } - }, - Err(_) => {} // TODO(keiichiw): handle error? - }; + } + } if check_gdb_interrupt() { self.vm_request(VmRequest::Suspend).map_err(|e| { diff --git a/vm_memory/src/guest_memory.rs b/vm_memory/src/guest_memory.rs index 803c167508..b9ad354252 100644 --- a/vm_memory/src/guest_memory.rs +++ b/vm_memory/src/guest_memory.rs @@ -325,9 +325,8 @@ impl GuestMemory { for (_, region) in self.regions.iter().enumerate() { let ret = region.mapping.use_hugepages(); - match ret { - Err(err) => println!("Failed to enable HUGEPAGE for mapping {}", err), - Ok(_) => (), + if let Err(err) = ret { + println!("Failed to enable HUGEPAGE for mapping {}", err); } } }