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 <noreply+kokoro@google.com>
Commit-Queue: Daniel Verkamp <dverkamp@chromium.org>
Reviewed-by: Zach Reizner <zachr@chromium.org>
Reviewed-by: Gurchetan Singh <gurchetansingh@chromium.org>
This commit is contained in:
Daniel Verkamp 2021-05-10 13:52:04 -07:00 committed by Commit Bot
parent d6c0f61489
commit c80319182d
4 changed files with 27 additions and 38 deletions

View file

@ -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

View file

@ -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<u8> {
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;

View file

@ -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| {

View file

@ -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);
}
}
}