summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@chromium.org>2019-03-11 12:36:30 -0700
committerchrome-bot <chrome-bot@chromium.org>2019-04-13 18:37:55 -0700
commit3df3552e4d62d60aac3bc33a4ee9468e7514202f (patch)
treece416fe0ebf7bce37cec60a0db744bf037cd8add
parentd49adc9005a300dbae60bd8ecb12ea620fc0fd31 (diff)
downloadcrosvm-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>
-rw-r--r--Cargo.lock30
-rw-r--r--Cargo.toml1
-rw-r--r--aarch64/Cargo.toml1
-rw-r--r--aarch64/src/lib.rs5
-rw-r--r--devices/Cargo.toml1
-rw-r--r--devices/src/lib.rs1
-rw-r--r--devices/src/virtio/vhost/mod.rs58
-rw-r--r--qcow/Cargo.toml1
-rw-r--r--qcow/src/qcow.rs18
-rw-r--r--src/linux.rs8
-rw-r--r--src/main.rs1
-rw-r--r--src/plugin/mod.rs12
-rw-r--r--x86_64/Cargo.toml1
-rw-r--r--x86_64/src/lib.rs5
14 files changed, 97 insertions, 46 deletions
diff --git a/Cargo.lock b/Cargo.lock
index eab4e90..fa8218b 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -10,6 +10,7 @@ dependencies = [
  "kvm 0.1.0",
  "kvm_sys 0.1.0",
  "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
+ "remain 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "resources 0.1.0",
  "sync 0.1.0",
  "sys_util 0.1.0",
@@ -51,7 +52,7 @@ version = "0.1.0"
 dependencies = [
  "proc-macro2 0.4.21 (registry+https://github.com/rust-lang/crates.io-index)",
  "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
- "syn 0.15.21 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -104,6 +105,7 @@ dependencies = [
  "protos 0.1.0",
  "qcow 0.1.0",
  "rand_ish 0.1.0",
+ "remain 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "render_node_forward 0.1.0",
  "resources 0.1.0",
  "sync 0.1.0",
@@ -153,6 +155,7 @@ dependencies = [
  "net_util 0.1.0",
  "p9 0.1.0",
  "protos 0.1.0",
+ "remain 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "resources 0.1.0",
  "sync 0.1.0",
  "sys_util 0.1.0",
@@ -169,7 +172,7 @@ version = "0.1.0"
 dependencies = [
  "proc-macro2 0.4.21 (registry+https://github.com/rust-lang/crates.io-index)",
  "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
- "syn 0.15.21 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -277,7 +280,7 @@ version = "0.1.0"
 dependencies = [
  "proc-macro2 0.4.21 (registry+https://github.com/rust-lang/crates.io-index)",
  "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
- "syn 0.15.21 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -332,7 +335,7 @@ version = "0.1.0"
 dependencies = [
  "proc-macro2 0.4.21 (registry+https://github.com/rust-lang/crates.io-index)",
  "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
- "syn 0.15.21 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -390,6 +393,7 @@ version = "0.1.0"
 dependencies = [
  "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
  "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
+ "remain 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "sys_util 0.1.0",
 ]
 
@@ -416,6 +420,16 @@ name = "rand_ish"
 version = "0.1.0"
 
 [[package]]
+name = "remain"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+dependencies = [
+ "proc-macro2 0.4.21 (registry+https://github.com/rust-lang/crates.io-index)",
+ "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)",
+]
+
+[[package]]
 name = "render_node_forward"
 version = "0.1.0"
 dependencies = [
@@ -434,7 +448,7 @@ dependencies = [
 
 [[package]]
 name = "syn"
-version = "0.15.21"
+version = "0.15.26"
 source = "registry+https://github.com/rust-lang/crates.io-index"
 dependencies = [
  "proc-macro2 0.4.21 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -539,7 +553,7 @@ version = "0.1.0"
 dependencies = [
  "proc-macro2 0.4.21 (registry+https://github.com/rust-lang/crates.io-index)",
  "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)",
- "syn 0.15.21 (registry+https://github.com/rust-lang/crates.io-index)",
+ "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)",
 ]
 
 [[package]]
@@ -557,6 +571,7 @@ dependencies = [
  "kvm 0.1.0",
  "kvm_sys 0.1.0",
  "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)",
+ "remain 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
  "resources 0.1.0",
  "sync 0.1.0",
  "sys_util 0.1.0",
@@ -577,6 +592,7 @@ dependencies = [
 "checksum protoc 2.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "82ac4c59bf852f415c62a1d30da3348f977322dc66bdb283c92b3df9bee2073a"
 "checksum protoc-rust 2.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0e9dc0547688715431c954528a3dabe7559b4d53b3161426981e19419ea7b1f0"
 "checksum quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "53fa22a1994bd0f9372d7a816207d8a2677ad0325b073f5c5332760f0fb62b5c"
-"checksum syn 0.15.21 (registry+https://github.com/rust-lang/crates.io-index)" = "816b7af21405b011a23554ea2dc3f6576dc86ca557047c34098c1d741f10f823"
+"checksum remain 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3bec2543b50be4539fdc27fde082e218cf4c3895358ca77f5c52fe930589e209"
+"checksum syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)" = "f92e629aa1d9c827b2bb8297046c1ccffc57c99b947a680d3ccff1f136a3bee9"
 "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
 "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
diff --git a/Cargo.toml b/Cargo.toml
index 6baf7e1..dbb203c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -53,6 +53,7 @@ protobuf = { version = "2.3", optional = true }
 protos = { path = "protos", optional = true }
 qcow = { path = "qcow" }
 rand_ish = { path = "rand_ish" }
+remain = "*"
 render_node_forward = { path = "render_node_forward", optional = true }
 resources = { path = "resources" }
 sync = { path = "sync" }
diff --git a/aarch64/Cargo.toml b/aarch64/Cargo.toml
index 4d773a3..8c754d1 100644
--- a/aarch64/Cargo.toml
+++ b/aarch64/Cargo.toml
@@ -13,6 +13,7 @@ kernel_cmdline = { path = "../kernel_cmdline" }
 kvm = { path = "../kvm" }
 kvm_sys = { path = "../kvm_sys" }
 libc = "*"
+remain = "*"
 resources = { path = "../resources" }
 sync = { path = "../sync" }
 sys_util = { path = "../sys_util" }
diff --git a/aarch64/src/lib.rs b/aarch64/src/lib.rs
index e8cabe4..07fbff5 100644
--- a/aarch64/src/lib.rs
+++ b/aarch64/src/lib.rs
@@ -10,6 +10,7 @@ extern crate kernel_cmdline;
 extern crate kvm;
 extern crate kvm_sys;
 extern crate libc;
+extern crate remain;
 extern crate resources;
 extern crate sync;
 extern crate sys_util;
@@ -25,6 +26,7 @@ use std::sync::Arc;
 use arch::{RunnableLinuxVm, VmComponents};
 use devices::{Bus, BusError, PciConfigMmio, PciDevice, PciInterruptPin};
 use io_jail::Minijail;
+use remain::sorted;
 use resources::{AddressRanges, SystemAllocator};
 use sync::Mutex;
 use sys_util::{EventFd, GuestAddress, GuestMemory, GuestMemoryError};
@@ -115,6 +117,7 @@ const AARCH64_MMIO_SIZE: u64 = 0x100000;
 // Virtio devices start at SPI interrupt number 2
 const AARCH64_IRQ_BASE: u32 = 2;
 
+#[sorted]
 #[derive(Debug)]
 pub enum Error {
     CloneEventFd(sys_util::Error),
@@ -141,9 +144,11 @@ pub enum Error {
 }
 
 impl Display for Error {
+    #[remain::check]
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         use self::Error::*;
 
+        #[sorted]
         match self {
             CloneEventFd(e) => write!(f, "unable to clone an EventFd: {}", e),
             Cmdline(e) => write!(f, "the given kernel command line was invalid: {}", e),
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),
         }
     }
 }
diff --git a/qcow/Cargo.toml b/qcow/Cargo.toml
index 0876d41..06bf9f5 100644
--- a/qcow/Cargo.toml
+++ b/qcow/Cargo.toml
@@ -10,4 +10,5 @@ path = "src/qcow.rs"
 [dependencies]
 byteorder = "*"
 libc = "*"
+remain = "*"
 sys_util = { path = "../sys_util" }
diff --git a/qcow/src/qcow.rs b/qcow/src/qcow.rs
index 746037d..8178212 100644
--- a/qcow/src/qcow.rs
+++ b/qcow/src/qcow.rs
@@ -4,6 +4,7 @@
 
 extern crate byteorder;
 extern crate libc;
+extern crate remain;
 #[macro_use]
 extern crate sys_util;
 
@@ -13,6 +14,7 @@ mod vec_cache;
 
 use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
 use libc::{EINVAL, ENOSPC, ENOTSUP};
+use remain::sorted;
 use sys_util::{FileSetLen, FileSync, PunchHole, SeekHole, WriteZeroes};
 
 use std::cmp::min;
@@ -26,13 +28,14 @@ use crate::qcow_raw_file::QcowRawFile;
 use crate::refcount::RefCount;
 use crate::vec_cache::{CacheMap, Cacheable, VecCache};
 
+#[sorted]
 #[derive(Debug)]
 pub enum Error {
     BackingFilesNotSupported,
     CompressedBlocksNotSupported,
+    EvictingCache(io::Error),
     GettingFileSize(io::Error),
     GettingRefcount(refcount::Error),
-    EvictingCache(io::Error),
     InvalidClusterIndex,
     InvalidClusterSize,
     InvalidIndex,
@@ -47,30 +50,33 @@ pub enum Error {
     ReadingData(io::Error),
     ReadingHeader(io::Error),
     ReadingPointers(io::Error),
-    ReadingRefCounts(io::Error),
     ReadingRefCountBlock(refcount::Error),
+    ReadingRefCounts(io::Error),
     RebuildingRefCounts(io::Error),
     SeekingFile(io::Error),
     SettingFileSize(io::Error),
     SettingRefcountRefcount(io::Error),
     SizeTooSmallForNumberOfClusters,
-    WritingHeader(io::Error),
     UnsupportedRefcountOrder,
     UnsupportedVersion(u32),
     WritingData(io::Error),
+    WritingHeader(io::Error),
 }
+
 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 {
             BackingFilesNotSupported => write!(f, "backing files not supported"),
             CompressedBlocksNotSupported => write!(f, "compressed blocks not supported"),
+            EvictingCache(e) => write!(f, "failed to evict cache: {}", e),
             GettingFileSize(e) => write!(f, "failed to get file size: {}", e),
             GettingRefcount(e) => write!(f, "failed to get refcount: {}", e),
-            EvictingCache(e) => write!(f, "failed to evict cache: {}", e),
             InvalidClusterIndex => write!(f, "invalid cluster index"),
             InvalidClusterSize => write!(f, "invalid cluster size"),
             InvalidIndex => write!(f, "invalid index"),
@@ -85,17 +91,17 @@ impl Display for Error {
             ReadingData(e) => write!(f, "failed to read data: {}", e),
             ReadingHeader(e) => write!(f, "failed to read header: {}", e),
             ReadingPointers(e) => write!(f, "failed to read pointers: {}", e),
-            ReadingRefCounts(e) => write!(f, "failed to read ref counts: {}", e),
             ReadingRefCountBlock(e) => write!(f, "failed to read ref count block: {}", e),
+            ReadingRefCounts(e) => write!(f, "failed to read ref counts: {}", e),
             RebuildingRefCounts(e) => write!(f, "failed to rebuild ref counts: {}", e),
             SeekingFile(e) => write!(f, "failed to seek file: {}", e),
             SettingFileSize(e) => write!(f, "failed to set file size: {}", e),
             SettingRefcountRefcount(e) => write!(f, "failed to set refcount refcount: {}", e),
             SizeTooSmallForNumberOfClusters => write!(f, "size too small for number of clusters"),
-            WritingHeader(e) => write!(f, "failed to write header: {}", e),
             UnsupportedRefcountOrder => write!(f, "unsupported refcount order"),
             UnsupportedVersion(v) => write!(f, "unsupported version: {}", v),
             WritingData(e) => write!(f, "failed to write data: {}", e),
+            WritingHeader(e) => write!(f, "failed to write header: {}", e),
         }
     }
 }
diff --git a/src/linux.rs b/src/linux.rs
index ba95f8c..78e5740 100644
--- a/src/linux.rs
+++ b/src/linux.rs
@@ -33,6 +33,7 @@ use msg_socket::{MsgError, MsgReceiver, MsgSender, MsgSocket};
 use net_util::{Error as NetError, MacAddress, Tap};
 use qcow::{self, ImageType, QcowFile};
 use rand_ish::SimpleRng;
+use remain::sorted;
 use sync::{Condvar, Mutex};
 use sys_util::net::{UnixSeqpacket, UnixSeqpacketListener, UnlinkUnixSeqpacketListener};
 use sys_util::{
@@ -65,6 +66,7 @@ use self::render_node_forward::*;
 #[cfg(not(feature = "gpu-forward"))]
 type RenderNodeHost = ();
 
+#[sorted]
 #[derive(Debug)]
 pub enum Error {
     AddGpuDeviceMemory(sys_util::Error),
@@ -133,9 +135,11 @@ pub enum Error {
 }
 
 impl Display for Error {
+    #[remain::check]
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         use self::Error::*;
 
+        #[sorted]
         match self {
             AddGpuDeviceMemory(e) => write!(f, "failed to add gpu device memory: {}", e),
             AllocateGpuDeviceAddress => write!(f, "failed to allocate gpu device guest address"),
@@ -169,14 +173,14 @@ impl Display for Error {
             IoJail(e) => write!(f, "{}", e),
             LoadKernel(e) => write!(f, "failed to load kernel: {}", e),
             NetDeviceNew(e) => write!(f, "failed to set up virtio networking: {}", e),
-            OpenInitrd(p, e) => write!(f, "failed to open initrd {}: {}", p.display(), e),
-            OpenKernel(p, e) => write!(f, "failed to open kernel image {}: {}", p.display(), e),
             OpenAndroidFstab(p, e) => write!(
                 f,
                 "failed to open android fstab file {}: {}",
                 p.display(),
                 e
             ),
+            OpenInitrd(p, e) => write!(f, "failed to open initrd {}: {}", p.display(), e),
+            OpenKernel(p, e) => write!(f, "failed to open kernel image {}: {}", p.display(), e),
             OpenVinput(p, e) => write!(f, "failed to open vinput device {}: {}", p.display(), e),
             P9DeviceNew(e) => write!(f, "failed to create 9p device: {}", e),
             PivotRootDoesntExist(p) => write!(f, "{} doesn't exist, can't jail devices.", p),
diff --git a/src/main.rs b/src/main.rs
index ff466e1..c000ac8 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -32,6 +32,7 @@ extern crate protobuf;
 #[cfg(feature = "plugin")]
 extern crate protos;
 extern crate rand_ish;
+extern crate remain;
 extern crate resources;
 extern crate sync;
 extern crate vhost;
diff --git a/src/plugin/mod.rs b/src/plugin/mod.rs
index 052b057..f37f2eb 100644
--- a/src/plugin/mod.rs
+++ b/src/plugin/mod.rs
@@ -23,6 +23,7 @@ use libc::{
 };
 
 use protobuf::ProtobufError;
+use remain::sorted;
 
 use io_jail::{self, Minijail};
 use kvm::{Datamatch, IoeventAddress, Kvm, Vcpu, VcpuExit, Vm};
@@ -41,6 +42,7 @@ const MAX_DATAGRAM_SIZE: usize = 4096;
 const MAX_VCPU_DATAGRAM_SIZE: usize = 0x40000;
 
 /// An error that occurs during the lifetime of a plugin process.
+#[sorted]
 pub enum Error {
     CloneEventFd(SysError),
     CloneVcpuSocket(io::Error),
@@ -95,18 +97,20 @@ pub enum Error {
     },
     SignalFd(SignalFdError),
     SpawnVcpu(io::Error),
+    TapEnable(TapError),
     TapOpen(TapError),
     TapSetIp(TapError),
-    TapSetNetmask(TapError),
     TapSetMacAddress(TapError),
-    TapEnable(TapError),
+    TapSetNetmask(TapError),
     ValidateTapFd(SysError),
 }
 
 impl Display for Error {
+    #[remain::check]
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         use self::Error::*;
 
+        #[sorted]
         match self {
             CloneEventFd(e) => write!(f, "failed to clone eventfd: {}", e),
             CloneVcpuSocket(e) => write!(f, "failed to clone vcpu socket: {}", e),
@@ -160,11 +164,11 @@ impl Display for Error {
             ),
             SignalFd(e) => write!(f, "failed to read signal fd: {}", e),
             SpawnVcpu(e) => write!(f, "error spawning vcpu thread: {}", e),
+            TapEnable(e) => write!(f, "error enabling tap device: {}", e),
             TapOpen(e) => write!(f, "error opening tap device: {}", e),
             TapSetIp(e) => write!(f, "error setting tap ip: {}", e),
-            TapSetNetmask(e) => write!(f, "error setting tap netmask: {}", e),
             TapSetMacAddress(e) => write!(f, "error setting tap mac address: {}", e),
-            TapEnable(e) => write!(f, "error enabling tap device: {}", e),
+            TapSetNetmask(e) => write!(f, "error setting tap netmask: {}", e),
             ValidateTapFd(e) => write!(f, "failed to validate raw tap fd: {}", e),
         }
     }
diff --git a/x86_64/Cargo.toml b/x86_64/Cargo.toml
index 937702f..4aa97a9 100644
--- a/x86_64/Cargo.toml
+++ b/x86_64/Cargo.toml
@@ -16,6 +16,7 @@ kernel_loader = { path = "../kernel_loader" }
 kvm = { path = "../kvm" }
 kvm_sys = { path = "../kvm_sys" }
 libc = "*"
+remain = "*"
 resources = { path = "../resources" }
 sync = { path = "../sync" }
 sys_util = { path = "../sys_util" }
diff --git a/x86_64/src/lib.rs b/x86_64/src/lib.rs
index de12a10..3272086 100644
--- a/x86_64/src/lib.rs
+++ b/x86_64/src/lib.rs
@@ -12,6 +12,7 @@ extern crate kernel_loader;
 extern crate kvm;
 extern crate kvm_sys;
 extern crate libc;
+extern crate remain;
 extern crate resources;
 extern crate sync;
 extern crate sys_util;
@@ -80,10 +81,12 @@ use arch::{RunnableLinuxVm, VmComponents};
 use devices::{PciConfigIo, PciDevice, PciInterruptPin};
 use io_jail::Minijail;
 use kvm::*;
+use remain::sorted;
 use resources::{AddressRanges, SystemAllocator};
 use sync::Mutex;
 use sys_util::{Clock, EventFd, GuestAddress, GuestMemory, GuestMemoryError};
 
+#[sorted]
 #[derive(Debug)]
 pub enum Error {
     CloneEventFd(sys_util::Error),
@@ -121,9 +124,11 @@ pub enum Error {
 }
 
 impl Display for Error {
+    #[remain::check]
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         use self::Error::*;
 
+        #[sorted]
         match self {
             CloneEventFd(e) => write!(f, "unable to clone an EventFd: {}", e),
             Cmdline(e) => write!(f, "the given kernel command line was invalid: {}", e),