[pbs-devel] [PATCH proxmox-backup v2 10/14] tools: clippy fixes
Dominik Csapak
d.csapak at proxmox.com
Fri Apr 16 12:29:06 CEST 2021
fixes:
* needless static lifetimes
* unnecessary returns
* `len() == 0` => `is_empty()`
* too many arguments
Signed-off-by: Dominik Csapak <d.csapak at 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
More information about the pbs-devel
mailing list