summary refs log tree commit diff
path: root/qcow
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 /qcow
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>
Diffstat (limited to 'qcow')
-rw-r--r--qcow/Cargo.toml1
-rw-r--r--qcow/src/qcow.rs18
2 files changed, 13 insertions, 6 deletions
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),
         }
     }
 }