diff options
author | David Tolnay <dtolnay@chromium.org> | 2019-03-11 12:36:30 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2019-04-13 18:37:55 -0700 |
commit | 3df3552e4d62d60aac3bc33a4ee9468e7514202f (patch) | |
tree | ce416fe0ebf7bce37cec60a0db744bf037cd8add /devices | |
parent | d49adc9005a300dbae60bd8ecb12ea620fc0fd31 (diff) | |
download | crosvm-3df3552e4d62d60aac3bc33a4ee9468e7514202f.tar crosvm-3df3552e4d62d60aac3bc33a4ee9468e7514202f.tar.gz crosvm-3df3552e4d62d60aac3bc33a4ee9468e7514202f.tar.bz2 crosvm-3df3552e4d62d60aac3bc33a4ee9468e7514202f.tar.lz crosvm-3df3552e4d62d60aac3bc33a4ee9468e7514202f.tar.xz crosvm-3df3552e4d62d60aac3bc33a4ee9468e7514202f.tar.zst crosvm-3df3552e4d62d60aac3bc33a4ee9468e7514202f.zip |
lints: Enforce sorted order for enum variants
To avoid wasting time re-sorting these things (CL:1492612). https://docs.rs/remain Disclaimer: I wrote the macro. This CL adds #[sorted] attributes to those Error enums that seemed to have made some effort to be in sorted order. TEST=cargo check TEST=cargo check --all-features TEST=cargo check --target aarch64-unknown-linux-gnu TEST=emerge-nami crosvm TEST=local kokoro CQ-DEPEND=CL:1524247 Change-Id: I89685ced05e2f149fa189ca509bc14c70aebb531 Reviewed-on: https://chromium-review.googlesource.com/1515998 Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com> Tested-by: David Tolnay <dtolnay@chromium.org> Tested-by: kokoro <noreply+kokoro@google.com> Reviewed-by: David Tolnay <dtolnay@chromium.org>
Diffstat (limited to 'devices')
-rw-r--r-- | devices/Cargo.toml | 1 | ||||
-rw-r--r-- | devices/src/lib.rs | 1 | ||||
-rw-r--r-- | devices/src/virtio/vhost/mod.rs | 58 |
3 files changed, 33 insertions, 27 deletions
diff --git a/devices/Cargo.toml b/devices/Cargo.toml index 7a09f4a..cd554c9 100644 --- a/devices/Cargo.toml +++ b/devices/Cargo.toml @@ -27,6 +27,7 @@ net_sys = { path = "../net_sys" } net_util = { path = "../net_util" } p9 = { path = "../p9" } protos = { path = "../protos", optional = true } +remain = "*" resources = { path = "../resources" } sync = { path = "../sync" } sys_util = { path = "../sys_util" } diff --git a/devices/src/lib.rs b/devices/src/lib.rs index 2bac47d..d28ea15 100644 --- a/devices/src/lib.rs +++ b/devices/src/lib.rs @@ -17,6 +17,7 @@ extern crate msg_socket; extern crate net_sys; extern crate net_util; extern crate p9; +extern crate remain; extern crate resources; extern crate sync; #[macro_use] diff --git a/devices/src/virtio/vhost/mod.rs b/devices/src/virtio/vhost/mod.rs index f96bebb..66c62d0 100644 --- a/devices/src/virtio/vhost/mod.rs +++ b/devices/src/virtio/vhost/mod.rs @@ -8,6 +8,7 @@ use std; use std::fmt::{self, Display}; use net_util::Error as TapError; +use remain::sorted; use sys_util::Error as SysError; use vhost::Error as VhostError; @@ -18,42 +19,47 @@ mod worker; pub use self::net::Net; pub use self::vsock::Vsock; +#[sorted] #[derive(Debug)] pub enum Error { + /// Cloning kill eventfd failed. + CloneKillEventFd(SysError), /// Creating kill eventfd failed. CreateKillEventFd(SysError), /// Creating poll context failed. CreatePollContext(SysError), - /// Cloning kill eventfd failed. - CloneKillEventFd(SysError), /// Error while polling for events. PollError(SysError), + /// Enabling tap interface failed. + TapEnable(TapError), /// Open tap device failed. TapOpen(TapError), /// Setting tap IP failed. TapSetIp(TapError), - /// Setting tap netmask failed. - TapSetNetmask(TapError), /// Setting tap mac address failed. TapSetMacAddress(TapError), + /// Setting tap netmask failed. + TapSetNetmask(TapError), /// Setting tap interface offload flags failed. TapSetOffload(TapError), /// Setting vnet header size failed. TapSetVnetHdrSize(TapError), - /// Enabling tap interface failed. - TapEnable(TapError), - /// Failed to open vhost device. - VhostOpen(VhostError), - /// Set owner failed. - VhostSetOwner(VhostError), /// Get features failed. VhostGetFeatures(VhostError), + /// Failed to create vhost eventfd. + VhostIrqCreate(SysError), + /// Failed to read vhost eventfd. + VhostIrqRead(SysError), + /// Net set backend failed. + VhostNetSetBackend(VhostError), + /// Failed to open vhost device. + VhostOpen(VhostError), /// Set features failed. VhostSetFeatures(VhostError), /// Set mem table failed. VhostSetMemTable(VhostError), - /// Set vring num failed. - VhostSetVringNum(VhostError), + /// Set owner failed. + VhostSetOwner(VhostError), /// Set vring addr failed. VhostSetVringAddr(VhostError), /// Set vring base failed. @@ -62,51 +68,49 @@ pub enum Error { VhostSetVringCall(VhostError), /// Set vring kick failed. VhostSetVringKick(VhostError), - /// Net set backend failed. - VhostNetSetBackend(VhostError), + /// Set vring num failed. + VhostSetVringNum(VhostError), /// Failed to set CID for guest. VhostVsockSetCid(VhostError), /// Failed to start vhost-vsock driver. VhostVsockStart(VhostError), - /// Failed to create vhost eventfd. - VhostIrqCreate(SysError), - /// Failed to read vhost eventfd. - VhostIrqRead(SysError), } pub type Result<T> = std::result::Result<T, Error>; impl Display for Error { + #[remain::check] fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { use self::Error::*; + #[sorted] match self { + CloneKillEventFd(e) => write!(f, "failed to clone kill eventfd: {}", e), CreateKillEventFd(e) => write!(f, "failed to create kill eventfd: {}", e), CreatePollContext(e) => write!(f, "failed to create poll context: {}", e), - CloneKillEventFd(e) => write!(f, "failed to clone kill eventfd: {}", e), PollError(e) => write!(f, "failed polling for events: {}", e), + TapEnable(e) => write!(f, "failed to enable tap interface: {}", e), TapOpen(e) => write!(f, "failed to open tap device: {}", e), TapSetIp(e) => write!(f, "failed to set tap IP: {}", e), - TapSetNetmask(e) => write!(f, "failed to set tap netmask: {}", e), TapSetMacAddress(e) => write!(f, "failed to set tap mac address: {}", e), + TapSetNetmask(e) => write!(f, "failed to set tap netmask: {}", e), TapSetOffload(e) => write!(f, "failed to set tap interface offload flags: {}", e), TapSetVnetHdrSize(e) => write!(f, "failed to set vnet header size: {}", e), - TapEnable(e) => write!(f, "failed to enable tap interface: {}", e), - VhostOpen(e) => write!(f, "failed to open vhost device: {}", e), - VhostSetOwner(e) => write!(f, "failed to set owner: {}", e), VhostGetFeatures(e) => write!(f, "failed to get features: {}", e), + VhostIrqCreate(e) => write!(f, "failed to create vhost eventfd: {}", e), + VhostIrqRead(e) => write!(f, "failed to read vhost eventfd: {}", e), + VhostNetSetBackend(e) => write!(f, "net set backend failed: {}", e), + VhostOpen(e) => write!(f, "failed to open vhost device: {}", e), VhostSetFeatures(e) => write!(f, "failed to set features: {}", e), VhostSetMemTable(e) => write!(f, "failed to set mem table: {}", e), - VhostSetVringNum(e) => write!(f, "failed to set vring num: {}", e), + VhostSetOwner(e) => write!(f, "failed to set owner: {}", e), VhostSetVringAddr(e) => write!(f, "failed to set vring addr: {}", e), VhostSetVringBase(e) => write!(f, "failed to set vring base: {}", e), VhostSetVringCall(e) => write!(f, "failed to set vring call: {}", e), VhostSetVringKick(e) => write!(f, "failed to set vring kick: {}", e), - VhostNetSetBackend(e) => write!(f, "net set backend failed: {}", e), + VhostSetVringNum(e) => write!(f, "failed to set vring num: {}", e), VhostVsockSetCid(e) => write!(f, "failed to set CID for guest: {}", e), VhostVsockStart(e) => write!(f, "failed to start vhost-vsock driver: {}", e), - VhostIrqCreate(e) => write!(f, "failed to create vhost eventfd: {}", e), - VhostIrqRead(e) => write!(f, "failed to read vhost eventfd: {}", e), } } } |