summary refs log tree commit diff
path: root/devices/src/virtio/gpu
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 /devices/src/virtio/gpu
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 'devices/src/virtio/gpu')
-rw-r--r--devices/src/virtio/gpu/backend.rs10
-rw-r--r--devices/src/virtio/gpu/mod.rs6
-rw-r--r--devices/src/virtio/gpu/protocol.rs84
3 files changed, 50 insertions, 50 deletions
diff --git a/devices/src/virtio/gpu/backend.rs b/devices/src/virtio/gpu/backend.rs
index 0359dd3..2de357f 100644
--- a/devices/src/virtio/gpu/backend.rs
+++ b/devices/src/virtio/gpu/backend.rs
@@ -208,7 +208,7 @@ impl VirglResource for BackedBuffer {
 
     fn attach_guest_backing(&mut self, mem: &GuestMemory, vecs: Vec<(GuestAddress, usize)>) {
         self.backing = vecs.clone();
-        if let Some(ref mut resource) = self.gpu_renderer_resource {
+        if let Some(resource) = &mut self.gpu_renderer_resource {
             if let Err(e) = resource.attach_backing(&vecs[..], mem) {
                 error!("failed to attach backing to BackBuffer resource: {}", e);
             }
@@ -216,7 +216,7 @@ impl VirglResource for BackedBuffer {
     }
 
     fn detach_guest_backing(&mut self) {
-        if let Some(ref mut resource) = self.gpu_renderer_resource {
+        if let Some(resource) = &mut self.gpu_renderer_resource {
             resource.detach_backing();
         }
         self.backing.clear();
@@ -231,9 +231,9 @@ impl VirglResource for BackedBuffer {
     }
 
     fn import_to_display(&mut self, display: &Rc<RefCell<GpuDisplay>>) -> Option<u32> {
-        if let Some((ref self_display, import)) = self.display_import {
-            if Rc::ptr_eq(&self_display, display) {
-                return Some(import);
+        if let Some((self_display, import)) = &self.display_import {
+            if Rc::ptr_eq(self_display, display) {
+                return Some(*import);
             }
         }
         let dmabuf = match self.buffer.export_plane_fd(0) {
diff --git a/devices/src/virtio/gpu/mod.rs b/devices/src/virtio/gpu/mod.rs
index 2c13acc..e8fb49f 100644
--- a/devices/src/virtio/gpu/mod.rs
+++ b/devices/src/virtio/gpu/mod.rs
@@ -515,7 +515,7 @@ impl Worker {
             }
         };
 
-        if let Some(ref resource_bridge) = self.resource_bridge {
+        if let Some(resource_bridge) = &self.resource_bridge {
             if let Err(e) = poll_ctx.add(resource_bridge, Token::ResourceBridge) {
                 error!("failed to add resource bridge to PollContext: {}", e);
             }
@@ -586,7 +586,7 @@ impl Worker {
             // created or destroyed by the control queue. Processing the resource bridge first may
             // lead to a race condition.
             if process_resource_bridge {
-                if let Some(ref resource_bridge) = self.resource_bridge {
+                if let Some(resource_bridge) = &self.resource_bridge {
                     self.state.process_resource_bridge(resource_bridge);
                 }
             }
@@ -654,7 +654,7 @@ impl VirtioDevice for Gpu {
             keep_fds.push(libc::STDERR_FILENO);
         }
         keep_fds.push(self.exit_evt.as_raw_fd());
-        if let Some(ref resource_bridge) = self.resource_bridge {
+        if let Some(resource_bridge) = &self.resource_bridge {
             keep_fds.push(resource_bridge.as_raw_fd());
         }
         keep_fds
diff --git a/devices/src/virtio/gpu/protocol.rs b/devices/src/virtio/gpu/protocol.rs
index f0dcad8..033f799 100644
--- a/devices/src/virtio/gpu/protocol.rs
+++ b/devices/src/virtio/gpu/protocol.rs
@@ -517,27 +517,27 @@ impl From<VolatileMemoryError> for GpuCommandDecodeError {
 impl fmt::Debug for GpuCommand {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         use self::GpuCommand::*;
-        match *self {
-            GetDisplayInfo(ref _info) => f.debug_struct("GetDisplayInfo").finish(),
-            ResourceCreate2d(ref _info) => f.debug_struct("ResourceCreate2d").finish(),
-            ResourceUnref(ref _info) => f.debug_struct("ResourceUnref").finish(),
-            SetScanout(ref _info) => f.debug_struct("SetScanout").finish(),
-            ResourceFlush(ref _info) => f.debug_struct("ResourceFlush").finish(),
-            TransferToHost2d(ref _info) => f.debug_struct("TransferToHost2d").finish(),
-            ResourceAttachBacking(ref _info) => f.debug_struct("ResourceAttachBacking").finish(),
-            ResourceDetachBacking(ref _info) => f.debug_struct("ResourceDetachBacking").finish(),
-            GetCapsetInfo(ref _info) => f.debug_struct("GetCapsetInfo").finish(),
-            GetCapset(ref _info) => f.debug_struct("GetCapset").finish(),
-            CtxCreate(ref _info) => f.debug_struct("CtxCreate").finish(),
-            CtxDestroy(ref _info) => f.debug_struct("CtxDestroy").finish(),
-            CtxAttachResource(ref _info) => f.debug_struct("CtxAttachResource").finish(),
-            CtxDetachResource(ref _info) => f.debug_struct("CtxDetachResource").finish(),
-            ResourceCreate3d(ref _info) => f.debug_struct("ResourceCreate3d").finish(),
-            TransferToHost3d(ref _info) => f.debug_struct("TransferToHost3d").finish(),
-            TransferFromHost3d(ref _info) => f.debug_struct("TransferFromHost3d").finish(),
-            CmdSubmit3d(ref _info) => f.debug_struct("CmdSubmit3d").finish(),
-            UpdateCursor(ref _info) => f.debug_struct("UpdateCursor").finish(),
-            MoveCursor(ref _info) => f.debug_struct("MoveCursor").finish(),
+        match self {
+            GetDisplayInfo(_info) => f.debug_struct("GetDisplayInfo").finish(),
+            ResourceCreate2d(_info) => f.debug_struct("ResourceCreate2d").finish(),
+            ResourceUnref(_info) => f.debug_struct("ResourceUnref").finish(),
+            SetScanout(_info) => f.debug_struct("SetScanout").finish(),
+            ResourceFlush(_info) => f.debug_struct("ResourceFlush").finish(),
+            TransferToHost2d(_info) => f.debug_struct("TransferToHost2d").finish(),
+            ResourceAttachBacking(_info) => f.debug_struct("ResourceAttachBacking").finish(),
+            ResourceDetachBacking(_info) => f.debug_struct("ResourceDetachBacking").finish(),
+            GetCapsetInfo(_info) => f.debug_struct("GetCapsetInfo").finish(),
+            GetCapset(_info) => f.debug_struct("GetCapset").finish(),
+            CtxCreate(_info) => f.debug_struct("CtxCreate").finish(),
+            CtxDestroy(_info) => f.debug_struct("CtxDestroy").finish(),
+            CtxAttachResource(_info) => f.debug_struct("CtxAttachResource").finish(),
+            CtxDetachResource(_info) => f.debug_struct("CtxDetachResource").finish(),
+            ResourceCreate3d(_info) => f.debug_struct("ResourceCreate3d").finish(),
+            TransferToHost3d(_info) => f.debug_struct("TransferToHost3d").finish(),
+            TransferFromHost3d(_info) => f.debug_struct("TransferFromHost3d").finish(),
+            CmdSubmit3d(_info) => f.debug_struct("CmdSubmit3d").finish(),
+            UpdateCursor(_info) => f.debug_struct("UpdateCursor").finish(),
+            MoveCursor(_info) => f.debug_struct("MoveCursor").finish(),
         }
     }
 }
@@ -575,27 +575,27 @@ impl GpuCommand {
     /// Gets the generic `virtio_gpu_ctrl_hdr` from this command.
     pub fn ctrl_hdr(&self) -> &virtio_gpu_ctrl_hdr {
         use self::GpuCommand::*;
-        match *self {
-            GetDisplayInfo(ref info) => &info,
-            ResourceCreate2d(ref info) => &info.hdr,
-            ResourceUnref(ref info) => &info.hdr,
-            SetScanout(ref info) => &info.hdr,
-            ResourceFlush(ref info) => &info.hdr,
-            TransferToHost2d(ref info) => &info.hdr,
-            ResourceAttachBacking(ref info) => &info.hdr,
-            ResourceDetachBacking(ref info) => &info.hdr,
-            GetCapsetInfo(ref info) => &info.hdr,
-            GetCapset(ref info) => &info.hdr,
-            CtxCreate(ref info) => &info.hdr,
-            CtxDestroy(ref info) => &info.hdr,
-            CtxAttachResource(ref info) => &info.hdr,
-            CtxDetachResource(ref info) => &info.hdr,
-            ResourceCreate3d(ref info) => &info.hdr,
-            TransferToHost3d(ref info) => &info.hdr,
-            TransferFromHost3d(ref info) => &info.hdr,
-            CmdSubmit3d(ref info) => &info.hdr,
-            UpdateCursor(ref info) => &info.hdr,
-            MoveCursor(ref info) => &info.hdr,
+        match self {
+            GetDisplayInfo(info) => info,
+            ResourceCreate2d(info) => &info.hdr,
+            ResourceUnref(info) => &info.hdr,
+            SetScanout(info) => &info.hdr,
+            ResourceFlush(info) => &info.hdr,
+            TransferToHost2d(info) => &info.hdr,
+            ResourceAttachBacking(info) => &info.hdr,
+            ResourceDetachBacking(info) => &info.hdr,
+            GetCapsetInfo(info) => &info.hdr,
+            GetCapset(info) => &info.hdr,
+            CtxCreate(info) => &info.hdr,
+            CtxDestroy(info) => &info.hdr,
+            CtxAttachResource(info) => &info.hdr,
+            CtxDetachResource(info) => &info.hdr,
+            ResourceCreate3d(info) => &info.hdr,
+            TransferToHost3d(info) => &info.hdr,
+            TransferFromHost3d(info) => &info.hdr,
+            CmdSubmit3d(info) => &info.hdr,
+            UpdateCursor(info) => &info.hdr,
+            MoveCursor(info) => &info.hdr,
         }
     }
 }