summary refs log tree commit diff
path: root/sys_util/src
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@chromium.org>2019-04-15 15:56:35 -0700
committerchrome-bot <chrome-bot@chromium.org>2019-04-18 19:51:01 -0700
commit64cd5eae5778b86f6e498a6fa1b1962693aa5a46 (patch)
tree9b68f7fce3385c410f4fd9c4e978660a9b5a0973 /sys_util/src
parentb1de6323ab8c96c52a60e0ff735e4bbb8a8464c9 (diff)
downloadcrosvm-64cd5eae5778b86f6e498a6fa1b1962693aa5a46.tar
crosvm-64cd5eae5778b86f6e498a6fa1b1962693aa5a46.tar.gz
crosvm-64cd5eae5778b86f6e498a6fa1b1962693aa5a46.tar.bz2
crosvm-64cd5eae5778b86f6e498a6fa1b1962693aa5a46.tar.lz
crosvm-64cd5eae5778b86f6e498a6fa1b1962693aa5a46.tar.xz
crosvm-64cd5eae5778b86f6e498a6fa1b1962693aa5a46.tar.zst
crosvm-64cd5eae5778b86f6e498a6fa1b1962693aa5a46.zip
edition: Eliminate ref keyword
As described in:
https://doc.rust-lang.org/edition-guide/rust-2018/ownership-and-lifetimes/default-match-bindings.html
which also covers the new mental model that the Rust Book will use for
teaching binding modes and has been found to be more friendly for both
beginners and experienced users.

Before:

    match *opt {
        Some(ref v) => ...,
        None => ...,
    }

After:

    match opt {
        Some(v) => ...,
        None => ...,
    }

TEST=cargo check --all-features
TEST=local kokoro

Change-Id: I3c5800a9be36aaf5d3290ae3bd3116f699cb00b7
Reviewed-on: https://chromium-review.googlesource.com/1566669
Commit-Ready: David Tolnay <dtolnay@chromium.org>
Tested-by: David Tolnay <dtolnay@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Diffstat (limited to 'sys_util/src')
-rw-r--r--sys_util/src/clock.rs6
-rw-r--r--sys_util/src/guest_memory.rs8
-rw-r--r--sys_util/src/syslog.rs4
-rw-r--r--sys_util/src/tempdir.rs4
-rw-r--r--sys_util/src/timerfd.rs2
5 files changed, 12 insertions, 12 deletions
diff --git a/sys_util/src/clock.rs b/sys_util/src/clock.rs
index 09bcd0a..878014d 100644
--- a/sys_util/src/clock.rs
+++ b/sys_util/src/clock.rs
@@ -72,15 +72,15 @@ impl FakeClock {
     /// Drop any existing events registered to the same raw fd.
     pub fn add_event_fd(&mut self, deadline_ns: u64, fd: EventFd) {
         self.deadlines
-            .retain(|&(_, ref old_fd)| fd.as_raw_fd() != old_fd.as_raw_fd());
+            .retain(|(_, old_fd)| fd.as_raw_fd() != old_fd.as_raw_fd());
         self.deadlines.push((deadline_ns, fd));
     }
 
     pub fn add_ns(&mut self, ns: u64) {
         self.ns_since_epoch += ns;
         let time = self.ns_since_epoch;
-        self.deadlines.retain(|&(ns, ref fd)| {
-            let expired = ns <= time;
+        self.deadlines.retain(|(ns, fd)| {
+            let expired = *ns <= time;
             if expired {
                 fd.write(1).unwrap();
             }
diff --git a/sys_util/src/guest_memory.rs b/sys_util/src/guest_memory.rs
index 6586e6b..25b4d4b 100644
--- a/sys_util/src/guest_memory.rs
+++ b/sys_util/src/guest_memory.rs
@@ -93,8 +93,8 @@ pub struct GuestMemory {
 
 impl AsRawFd for GuestMemory {
     fn as_raw_fd(&self) -> RawFd {
-        match self.memfd {
-            Some(ref memfd) => memfd.as_raw_fd(),
+        match &self.memfd {
+            Some(memfd) => memfd.as_raw_fd(),
             None => panic!("GuestMemory is not backed by a memfd"),
         }
     }
@@ -165,8 +165,8 @@ impl GuestMemory {
                 }
             }
 
-            let mapping = match memfd {
-                Some(ref memfd) => MemoryMapping::from_fd_offset(memfd, range.1 as usize, offset),
+            let mapping = match &memfd {
+                Some(memfd) => MemoryMapping::from_fd_offset(memfd, range.1 as usize, offset),
                 None => MemoryMapping::new(range.1 as usize),
             }
             .map_err(Error::MemoryMappingFailed)?;
diff --git a/sys_util/src/syslog.rs b/sys_util/src/syslog.rs
index af5cefc..41b4b97 100644
--- a/sys_util/src/syslog.rs
+++ b/sys_util/src/syslog.rs
@@ -414,7 +414,7 @@ pub fn log(pri: Priority, fac: Facility, file_name: &str, line: u32, args: fmt::
 
     let mut state = lock!();
     let mut buf = [0u8; 1024];
-    if let Some(ref socket) = state.socket {
+    if let Some(socket) = &state.socket {
         let tm = get_localtime();
         let prifac = (pri as u8) | (fac as u8);
         let (res, len) = {
@@ -452,7 +452,7 @@ pub fn log(pri: Priority, fac: Facility, file_name: &str, line: u32, args: fmt::
         )
     };
     if res.is_ok() {
-        if let Some(ref mut file) = state.file {
+        if let Some(file) = &mut state.file {
             let _ = file.write_all(&buf[..len]);
         }
         if state.stderr {
diff --git a/sys_util/src/tempdir.rs b/sys_util/src/tempdir.rs
index cf13af5..045f245 100644
--- a/sys_util/src/tempdir.rs
+++ b/sys_util/src/tempdir.rs
@@ -66,13 +66,13 @@ impl TempDir {
 
     /// Returns the path to the tempdir if it is currently valid
     pub fn as_path(&self) -> Option<&Path> {
-        self.path.as_ref().map(|ref p| p.as_path())
+        self.path.as_ref().map(PathBuf::as_path)
     }
 }
 
 impl Drop for TempDir {
     fn drop(&mut self) {
-        if let Some(ref p) = self.path {
+        if let Some(p) = &self.path {
             // Nothing can be done here if this returns an error.
             let _ = fs::remove_dir_all(p);
         }
diff --git a/sys_util/src/timerfd.rs b/sys_util/src/timerfd.rs
index 2387cc5..8e5d91b 100644
--- a/sys_util/src/timerfd.rs
+++ b/sys_util/src/timerfd.rs
@@ -170,7 +170,7 @@ impl FakeTimerFd {
     pub fn wait(&mut self) -> Result<u64> {
         loop {
             self.fd.read()?;
-            if let Some(ref mut deadline_ns) = self.deadline_ns {
+            if let Some(deadline_ns) = &mut self.deadline_ns {
                 let mut guard = self.clock.lock();
                 let now = guard.nanos();
                 if now >= *deadline_ns {