From b1a657f905422a33447342944761f48632022faf Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Sat, 11 Apr 2020 19:47:40 +0000 Subject: crosvm: collapse simple boolean matches Rust 1.42 introduces matches!(), which can be used to collapse simple match statements like these. --- devices/src/pci/vfio_pci.rs | 5 +---- devices/src/virtio/gpu/mod.rs | 5 +---- kernel_cmdline/src/kernel_cmdline.rs | 5 +---- msg_socket/msg_on_socket_derive/msg_on_socket_derive.rs | 5 +---- src/main.rs | 5 +---- src/plugin/vcpu.rs | 5 +---- sys_util/src/handle_eintr.rs | 10 ++-------- 7 files changed, 8 insertions(+), 32 deletions(-) diff --git a/devices/src/pci/vfio_pci.rs b/devices/src/pci/vfio_pci.rs index d1b6f2b..5c13d28 100644 --- a/devices/src/pci/vfio_pci.rs +++ b/devices/src/pci/vfio_pci.rs @@ -832,10 +832,7 @@ impl PciDevice for VfioPciDevice { low = self.config.read_config_dword(offset); let low_flag = low & 0xf; - let is_64bit = match low_flag & 0x4 { - 0x4 => true, - _ => false, - }; + let is_64bit = (low_flag & 0x4) == 0x4; if (low_flag & 0x1 == 0 || i == VFIO_PCI_ROM_REGION_INDEX) && low != 0 { let mut upper: u32 = 0xffffffff; if is_64bit { diff --git a/devices/src/virtio/gpu/mod.rs b/devices/src/virtio/gpu/mod.rs index e8e7f4a..fec2904 100644 --- a/devices/src/virtio/gpu/mod.rs +++ b/devices/src/virtio/gpu/mod.rs @@ -977,10 +977,7 @@ impl DisplayBackend { } fn is_x(&self) -> bool { - match self { - DisplayBackend::X(_) => true, - _ => false, - } + matches!(self, DisplayBackend::X(_)) } } diff --git a/kernel_cmdline/src/kernel_cmdline.rs b/kernel_cmdline/src/kernel_cmdline.rs index d2777c7..c836e12 100644 --- a/kernel_cmdline/src/kernel_cmdline.rs +++ b/kernel_cmdline/src/kernel_cmdline.rs @@ -39,10 +39,7 @@ impl Display for Error { pub type Result = result::Result; fn valid_char(c: char) -> bool { - match c { - ' '..='~' => true, - _ => false, - } + matches!(c, ' '..='~') } fn valid_str(s: &str) -> Result<()> { diff --git a/msg_socket/msg_on_socket_derive/msg_on_socket_derive.rs b/msg_socket/msg_on_socket_derive/msg_on_socket_derive.rs index 85c5a7e..70b7e3f 100644 --- a/msg_socket/msg_on_socket_derive/msg_on_socket_derive.rs +++ b/msg_socket/msg_on_socket_derive/msg_on_socket_derive.rs @@ -43,10 +43,7 @@ fn msg_socket_impl(input: DeriveInput) -> TokenStream { } fn is_named_struct(ds: &DataStruct) -> bool { - match &ds.fields { - Fields::Named(_f) => true, - _ => false, - } + matches!(&ds.fields, Fields::Named(_)) } /************************** Named Struct Impls ********************************************/ diff --git a/src/main.rs b/src/main.rs index 144e49c..e33be66 100644 --- a/src/main.rs +++ b/src/main.rs @@ -38,10 +38,7 @@ use vm_control::{ }; fn executable_is_plugin(executable: &Option) -> bool { - match executable { - Some(Executable::Plugin(_)) => true, - _ => false, - } + matches!(executable, Some(Executable::Plugin(_))) } // Wait for all children to exit. Return true if they have all exited, false diff --git a/src/plugin/vcpu.rs b/src/plugin/vcpu.rs index 3bb6bed..a5bf73c 100644 --- a/src/plugin/vcpu.rs +++ b/src/plugin/vcpu.rs @@ -323,10 +323,7 @@ enum VcpuRunData<'a> { impl<'a> VcpuRunData<'a> { fn is_write(&self) -> bool { - match self { - VcpuRunData::Write(_) => true, - _ => false, - } + matches!(self, VcpuRunData::Write(_)) } fn as_slice(&self) -> &[u8] { diff --git a/sys_util/src/handle_eintr.rs b/sys_util/src/handle_eintr.rs index d8cc0b3..8e38c09 100644 --- a/sys_util/src/handle_eintr.rs +++ b/sys_util/src/handle_eintr.rs @@ -17,19 +17,13 @@ pub trait InterruptibleResult { impl InterruptibleResult for crate::Result { fn is_interrupted(&self) -> bool { - match self { - Err(e) if e.errno() == EINTR => true, - _ => false, - } + matches!(self, Err(e) if e.errno() == EINTR) } } impl InterruptibleResult for io::Result { fn is_interrupted(&self) -> bool { - match self { - Err(e) if e.kind() == io::ErrorKind::Interrupted => true, - _ => false, - } + matches!(self, Err(e) if e.kind() == io::ErrorKind::Interrupted) } } -- cgit 1.4.1