From 3df3552e4d62d60aac3bc33a4ee9468e7514202f Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Mon, 11 Mar 2019 12:36:30 -0700 Subject: 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 Tested-by: David Tolnay Tested-by: kokoro Reviewed-by: David Tolnay --- src/plugin/mod.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/plugin/mod.rs') 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), } } -- cgit 1.4.1