public inbox for pbs-devel@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 10/12] tools: clippy fixes
Date: Tue,  6 Apr 2021 08:27:45 +0200	[thread overview]
Message-ID: <20210406062747.9356-11-d.csapak@proxmox.com> (raw)
In-Reply-To: <20210406062747.9356-1-d.csapak@proxmox.com>

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

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

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 987d5738..5d7539a2 100644
--- a/src/tools/sgutils2.rs
+++ b/src/tools/sgutils2.rs
@@ -114,7 +114,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",
@@ -165,7 +165,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",
@@ -447,13 +447,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 {
@@ -489,15 +489,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()),
         }
     }
 
@@ -540,7 +540,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-06  6:28 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-06  6:27 [pbs-devel] [PATCH proxmox-backup 00/12] " Dominik Csapak
2021-04-06  6:27 ` [pbs-devel] [PATCH proxmox-backup 01/12] api2/tape: " Dominik Csapak
2021-04-06  6:27 ` [pbs-devel] [PATCH proxmox-backup 02/12] tape/changer: " Dominik Csapak
2021-04-06  6:27 ` [pbs-devel] [PATCH proxmox-backup 03/12] tape/drive: " Dominik Csapak
2021-04-06  6:27 ` [pbs-devel] [PATCH proxmox-backup 04/12] tape/media_*: " Dominik Csapak
2021-04-06  6:27 ` [pbs-devel] [PATCH proxmox-backup 05/12] tape/pool_writer: " Dominik Csapak
2021-04-06  6:27 ` [pbs-devel] [PATCH proxmox-backup 06/12] backup: " Dominik Csapak
2021-04-06  6:27 ` [pbs-devel] [PATCH proxmox-backup 07/12] pxar: clippy fix `or_fun_call` Dominik Csapak
2021-04-06  6:27 ` [pbs-devel] [PATCH proxmox-backup 08/12] bin: clippy fixes Dominik Csapak
2021-04-06  6:27 ` [pbs-devel] [PATCH proxmox-backup 09/12] tape/*: " Dominik Csapak
2021-04-06  6:27 ` Dominik Csapak [this message]
2021-04-06  6:27 ` [pbs-devel] [PATCH proxmox-backup 11/12] config/tape_encryption_keys: " Dominik Csapak
2021-04-06  6:27 ` [pbs-devel] [PATCH proxmox-backup 12/12] server/worker_task: clippy fix 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=20210406062747.9356-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal