all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup v2 10/14] tools: clippy fixes
Date: Fri, 16 Apr 2021 12:29:06 +0200	[thread overview]
Message-ID: <20210416102910.8506-11-d.csapak@proxmox.com> (raw)
In-Reply-To: <20210416102910.8506-1-d.csapak@proxmox.com>

fixes:
* needless static lifetimes
* unnecessary returns
* `len() == 0` => `is_empty()`
* too many arguments

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/tools/cpio.rs     |  1 +
 src/tools/fs.rs       |  3 +++
 src/tools/sgutils2.rs | 18 +++++++++---------
 3 files changed, 13 insertions(+), 9 deletions(-)

diff --git a/src/tools/cpio.rs b/src/tools/cpio.rs
index 8800e3ad..48f1470f 100644
--- a/src/tools/cpio.rs
+++ b/src/tools/cpio.rs
@@ -8,6 +8,7 @@ use std::ffi::{CString, CStr};
 use tokio::io::{copy, AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
 
 /// Write a cpio file entry to an AsyncWrite.
+#[allow(clippy::too_many_arguments)]
 pub async fn append_file<W: AsyncWrite + Unpin, R: AsyncRead + Unpin>(
     mut target: W,
     content: R,
diff --git a/src/tools/fs.rs b/src/tools/fs.rs
index 72a530d8..0397113b 100644
--- a/src/tools/fs.rs
+++ b/src/tools/fs.rs
@@ -75,6 +75,9 @@ impl ReadDirEntry {
         self.parent_fd
     }
 
+    /// # Safety
+    ///
+    /// same safety concerns as `std::str::from_utf8_unchecked`
     pub unsafe fn file_name_utf8_unchecked(&self) -> &str {
         std::str::from_utf8_unchecked(self.file_name().to_bytes())
     }
diff --git a/src/tools/sgutils2.rs b/src/tools/sgutils2.rs
index b45d7468..b8600e1b 100644
--- a/src/tools/sgutils2.rs
+++ b/src/tools/sgutils2.rs
@@ -91,7 +91,7 @@ impl SgPt {
 /// Peripheral device type text (see `inquiry` command)
 ///
 /// see [https://en.wikipedia.org/wiki/SCSI_Peripheral_Device_Type]
-pub const PERIPHERAL_DEVICE_TYPE_TEXT: [&'static str; 32] = [
+pub const PERIPHERAL_DEVICE_TYPE_TEXT: [&str; 32] = [
     "Disk Drive",
     "Tape Drive",
     "Printer",
@@ -142,7 +142,7 @@ pub const SENSE_KEY_VOLUME_OVERFLOW: u8 = 0x0d;
 pub const SENSE_KEY_MISCOMPARE: u8      = 0x0e;
 
 /// Sense Key Descriptions
-pub const SENSE_KEY_DESCRIPTIONS: [&'static str; 16] = [
+pub const SENSE_KEY_DESCRIPTIONS: [&str; 16] = [
     "No Sense",
     "Recovered Error",
     "Not Ready",
@@ -464,13 +464,13 @@ impl <'a, F: AsRawFd> SgRaw<'a, F> {
 
         let res_cat = unsafe { get_scsi_pt_result_category(ptvp.as_ptr()) };
         match res_cat {
-            SCSI_PT_RESULT_GOOD => return Ok(()),
+            SCSI_PT_RESULT_GOOD => Ok(()),
             SCSI_PT_RESULT_STATUS => {
                 let status = unsafe { get_scsi_pt_status_response(ptvp.as_ptr()) };
                 if status != 0 {
                     return Err(format_err!("unknown scsi error - status response {}", status).into());
                 }
-                return Ok(());
+                Ok(())
             }
             SCSI_PT_RESULT_SENSE => {
                 if sense_len == 0 {
@@ -506,15 +506,15 @@ impl <'a, F: AsRawFd> SgRaw<'a, F> {
                     }
                 };
 
-                return Err(ScsiError::Sense(sense));
+                Err(ScsiError::Sense(sense))
             }
-            SCSI_PT_RESULT_TRANSPORT_ERR => return Err(format_err!("scsi command failed: transport error").into()),
+            SCSI_PT_RESULT_TRANSPORT_ERR => Err(format_err!("scsi command failed: transport error").into()),
             SCSI_PT_RESULT_OS_ERR => {
                 let errno = unsafe { get_scsi_pt_os_err(ptvp.as_ptr()) };
                 let err = nix::Error::from_errno(nix::errno::Errno::from_i32(errno));
-                return Err(format_err!("scsi command failed with err {}", err).into());
+                Err(format_err!("scsi command failed with err {}", err).into())
             }
-            unknown => return Err(format_err!("scsi command failed: unknown result category {}", unknown).into()),
+            unknown => Err(format_err!("scsi command failed: unknown result category {}", unknown).into()),
         }
     }
 
@@ -557,7 +557,7 @@ impl <'a, F: AsRawFd> SgRaw<'a, F> {
             return Err(format_err!("no valid SCSI command").into());
         }
 
-        if data.len() == 0 {
+        if data.is_empty() {
             return Err(format_err!("got zero-sized input buffer").into());
         }
 
-- 
2.20.1





  parent reply	other threads:[~2021-04-16 10:29 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-16 10:28 [pbs-devel] [PATCH proxmox-backup v2 00/14] various " Dominik Csapak
2021-04-16 10:28 ` [pbs-devel] [PATCH proxmox-backup v2 01/14] api2/tape: " Dominik Csapak
2021-04-16 10:28 ` [pbs-devel] [PATCH proxmox-backup v2 02/14] tape/changer: " Dominik Csapak
2021-04-16 10:28 ` [pbs-devel] [PATCH proxmox-backup v2 03/14] tape/drive: " Dominik Csapak
2021-04-16 10:29 ` [pbs-devel] [PATCH proxmox-backup v2 04/14] tape/media_*: " Dominik Csapak
2021-04-16 10:29 ` [pbs-devel] [PATCH proxmox-backup v2 05/14] tape/pool_writer: " Dominik Csapak
2021-04-16 10:29 ` [pbs-devel] [PATCH proxmox-backup v2 06/14] backup: " Dominik Csapak
2021-04-16 10:29 ` [pbs-devel] [PATCH proxmox-backup v2 07/14] pxar: clippy fix `or_fun_call` Dominik Csapak
2021-04-16 10:29 ` [pbs-devel] [PATCH proxmox-backup v2 08/14] bin: clippy fixes Dominik Csapak
2021-04-16 10:29 ` [pbs-devel] [PATCH proxmox-backup v2 09/14] tape/*: " Dominik Csapak
2021-04-16 10:29 ` Dominik Csapak [this message]
2021-04-16 10:29 ` [pbs-devel] [PATCH proxmox-backup v2 11/14] config/tape_encryption_keys: " Dominik Csapak
2021-04-16 10:29 ` [pbs-devel] [PATCH proxmox-backup v2 12/14] server/worker_task: clippy fix Dominik Csapak
2021-04-16 10:29 ` [pbs-devel] [PATCH proxmox-backup v2 13/14] bin/proxmox-file-restore: clippy fixes Dominik Csapak
2021-04-16 10:29 ` [pbs-devel] [PATCH proxmox-backup v2 14/14] bin/proxmox-restore-daemon: " Dominik Csapak

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210416102910.8506-11-d.csapak@proxmox.com \
    --to=d.csapak@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal