[pbs-devel] [PATCH proxmox-backup 10/12] tools: clippy fixes
Dominik Csapak
d.csapak at proxmox.com
Tue Apr 6 08:27:45 CEST 2021
fixes:
* needless static lifetimes
* unnecessary returns
* `len() == 0` => `is_empty()`
Signed-off-by: Dominik Csapak <d.csapak at 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
More information about the pbs-devel
mailing list