summary refs log tree commit diff
path: root/devices/src/virtio/wl.rs
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@chromium.org>2019-03-01 18:07:56 -0800
committerchrome-bot <chrome-bot@chromium.org>2019-03-02 17:41:31 -0800
commitc69f97542a6071f78d48a743ee94119a93bc9471 (patch)
tree69ee27de806bf460c108219d9d2c64bd633cf35d /devices/src/virtio/wl.rs
parent5e1b46cbd8cb031a12c0fb20e94670f1007fd789 (diff)
downloadcrosvm-c69f97542a6071f78d48a743ee94119a93bc9471.tar
crosvm-c69f97542a6071f78d48a743ee94119a93bc9471.tar.gz
crosvm-c69f97542a6071f78d48a743ee94119a93bc9471.tar.bz2
crosvm-c69f97542a6071f78d48a743ee94119a93bc9471.tar.lz
crosvm-c69f97542a6071f78d48a743ee94119a93bc9471.tar.xz
crosvm-c69f97542a6071f78d48a743ee94119a93bc9471.tar.zst
crosvm-c69f97542a6071f78d48a743ee94119a93bc9471.zip
error: Consistently use Display instead of error description()
The description method is deprecated and its signature forces less
helpful error messages than what Display can provide.

BUG=none
TEST=cargo check --all-features
TEST=cargo check --target aarch64-unknown-linux-gnu

Change-Id: I27fc99d59d0ef457c5273dc53e4c563ef439c2c0
Reviewed-on: https://chromium-review.googlesource.com/1497735
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Dylan Reid <dgreid@chromium.org>
Diffstat (limited to 'devices/src/virtio/wl.rs')
-rw-r--r--devices/src/virtio/wl.rs51
1 files changed, 24 insertions, 27 deletions
diff --git a/devices/src/virtio/wl.rs b/devices/src/virtio/wl.rs
index 0220d42..a9498fe 100644
--- a/devices/src/virtio/wl.rs
+++ b/devices/src/virtio/wl.rs
@@ -32,9 +32,8 @@ use std::cell::RefCell;
 use std::collections::btree_map::Entry;
 use std::collections::{BTreeMap as Map, BTreeSet as Set, VecDeque};
 use std::convert::From;
-use std::error::{self, Error as StdError};
 use std::ffi::CStr;
-use std::fmt;
+use std::fmt::{self, Display};
 use std::fs::File;
 use std::io::{self, Read, Seek, SeekFrom};
 use std::mem::{size_of, size_of_val};
@@ -442,35 +441,33 @@ enum WlError {
     DmabufSync(io::Error),
 }
 
-impl fmt::Display for WlError {
+impl Display for WlError {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
-        write!(f, "{}", self.description())
-    }
-}
-
-impl error::Error for WlError {
-    fn description(&self) -> &str {
-        match *self {
-            WlError::NewAlloc(_) => "Failed to create shared memory allocation",
-            WlError::NewPipe(_) => "Failed to create pipe",
-            WlError::AllocSetSize(_) => "Failed to set size of shared memory",
-            WlError::SocketConnect(_) => "Failed to connect socket",
-            WlError::SocketNonBlock(_) => "Failed to set socket as non-blocking",
-            WlError::VmControl(_) => "Failed to control parent VM",
-            WlError::VmBadResponse => "Invalid response from parent VM",
-            WlError::CheckedOffset => "Overflow in calculation",
-            WlError::GuestMemory(_) => "Access violation in guest memory",
-            WlError::VolatileMemory(_) => "Access violating in guest volatile memory",
-            WlError::SendVfd(_) => "Failed to send on a socket",
-            WlError::WritePipe(_) => "Failed to write to a pipe",
-            WlError::RecvVfd(_) => "Failed to recv on a socket",
-            WlError::ReadPipe(_) => "Failed to read a pipe",
-            WlError::PollContextAdd(_) => "Failed to listen to FD on poll context",
-            WlError::DmabufSync(_) => "Failed to synchronize DMABuf access",
+        use self::WlError::*;
+
+        match self {
+            NewAlloc(e) => write!(f, "failed to create shared memory allocation: {}", e),
+            NewPipe(e) => write!(f, "failed to create pipe: {}", e),
+            AllocSetSize(e) => write!(f, "failed to set size of shared memory: {}", e),
+            SocketConnect(e) => write!(f, "failed to connect socket: {}", e),
+            SocketNonBlock(e) => write!(f, "failed to set socket as non-blocking: {}", e),
+            VmControl(e) => write!(f, "failed to control parent VM: {}", e),
+            VmBadResponse => write!(f, "invalid response from parent VM"),
+            CheckedOffset => write!(f, "overflow in calculation"),
+            GuestMemory(e) => write!(f, "access violation in guest memory: {}", e),
+            VolatileMemory(e) => write!(f, "access violating in guest volatile memory: {}", e),
+            SendVfd(e) => write!(f, "failed to send on a socket: {}", e),
+            WritePipe(e) => write!(f, "failed to write to a pipe: {}", e),
+            RecvVfd(e) => write!(f, "failed to recv on a socket: {}", e),
+            ReadPipe(e) => write!(f, "failed to read a pipe: {}", e),
+            PollContextAdd(e) => write!(f, "failed to listen to FD on poll context: {}", e),
+            DmabufSync(e) => write!(f, "failed to synchronize DMABuf access: {}", e),
         }
     }
 }
 
+impl std::error::Error for WlError {}
+
 type WlResult<T> = result::Result<T, WlError>;
 
 impl From<GuestMemoryError> for WlError {
@@ -648,7 +645,7 @@ enum WlResp<'a> {
     VfdHup {
         id: u32,
     },
-    Err(Box<error::Error>),
+    Err(Box<std::error::Error>),
     OutOfMemory,
     InvalidId,
     InvalidType,