From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 605B870D4F for ; Tue, 6 Apr 2021 08:28:23 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 5791729BAA for ; Tue, 6 Apr 2021 08:27:53 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [212.186.127.180]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS id E0AE529AD8 for ; Tue, 6 Apr 2021 08:27:49 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id AC6E74271E for ; Tue, 6 Apr 2021 08:27:49 +0200 (CEST) From: Dominik Csapak To: pbs-devel@lists.proxmox.com Date: Tue, 6 Apr 2021 08:27:45 +0200 Message-Id: <20210406062747.9356-11-d.csapak@proxmox.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210406062747.9356-1-d.csapak@proxmox.com> References: <20210406062747.9356-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.171 Adjusted score from AWL reputation of From: address KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pbs-devel] [PATCH proxmox-backup 10/12] tools: clippy fixes X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Apr 2021 06:28:23 -0000 fixes: * needless static lifetimes * unnecessary returns * `len() == 0` => `is_empty()` Signed-off-by: Dominik Csapak --- 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