clippy: misc fixes

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
Fabian Grünbichler 2021-12-02 09:00:52 +01:00
parent b1c2250000
commit e303ad8605
9 changed files with 20 additions and 26 deletions

View File

@ -257,7 +257,7 @@ impl CommandLineInterface {
/// ``stdout``.
pub fn print_bash_completion(&self) {
let comp_point: usize = match std::env::var("COMP_POINT") {
Ok(val) => match usize::from_str_radix(&val, 10) {
Ok(val) => match val.parse::<usize>() {
Ok(i) => i,
Err(_) => return,
},

View File

@ -223,14 +223,14 @@ fn test_boolean_arg() {
for (args, expect) in variants {
let res = parse_arguments(
&args,
&vec![],
&[],
&HashMap::new(),
ParameterSchema::from(&PARAMETERS),
);
assert!(res.is_ok());
if let Ok((options, remaining)) = res {
assert!(options["enable"] == expect);
assert!(remaining.len() == 0);
assert!(remaining.is_empty());
}
}
}
@ -258,6 +258,6 @@ fn test_argument_paramenter() {
if let Ok((options, remaining)) = res {
assert!(options["enable"] == true);
assert!(options["storage"] == "local");
assert!(remaining.len() == 0);
assert!(remaining.is_empty());
}
}

View File

@ -278,9 +278,7 @@ impl TableFormatOptions {
let key = key.into();
match self.sortkeys {
None => {
let mut list = Vec::new();
list.push((key, sort_desc));
self.sortkeys = Some(list);
self.sortkeys = Some(vec![(key, sort_desc)]);
}
Some(ref mut list) => {
list.push((key, sort_desc));
@ -379,9 +377,7 @@ fn format_table<W: Write>(
let sortkeys = if let Some(ref sortkeys) = options.sortkeys {
sortkeys.clone()
} else {
let mut keys = Vec::new();
keys.push((properties_to_print[0].clone(), false)); // leftmost, ASC
keys
vec![(properties_to_print[0].clone(), false)] // leftmost, ASC
};
let mut sortinfo = Vec::new();
@ -712,9 +708,7 @@ fn format_object<W: Write>(
right_align: all_right_aligned,
};
let mut tabledata: Vec<TableColumn> = Vec::new();
tabledata.push(name_column);
tabledata.push(value_column);
let tabledata = vec![name_column, value_column];
render_table(output, &tabledata, &column_names, options)
}

View File

@ -216,7 +216,7 @@ mod test {
return groups.contains(&Value::from(group));
}
return false;
false
}
fn lookup_privs(&self, userid: &str, path: &[&str]) -> u64 {
@ -227,7 +227,7 @@ mod test {
}
}
return 0;
0
}
}

View File

@ -342,7 +342,7 @@ impl StringSchema {
}
}
ApiStringFormat::Enum(variants) => {
if variants.iter().find(|&e| e.value == value).is_none() {
if !variants.iter().any(|e| e.value == value) {
bail!("value '{}' is not defined in the enumeration.", value);
}
}

View File

@ -65,7 +65,7 @@ fn mmap_file<T: Init>(file: &mut File, initialize: bool) -> Result<Mmap<T>, Erro
Init::initialize(&mut mmap[0]);
}
match Init::check_type_magic(&mut mmap[0]) {
match Init::check_type_magic(&mmap[0]) {
Ok(()) => (),
Err(err) => bail!("detected wrong types in mmaped files: {}", err),
}
@ -164,7 +164,7 @@ impl <T: Sized + Init> SharedMemory<T> {
drop(file); // no longer required
match res {
Ok(_rc) => return Ok(mmap),
Ok(_rc) => Ok(mmap),
// if someone else was faster, open the existing file:
Err(nix::Error::Sys(Errno::EEXIST)) => {
// if opening fails again now, we'll just error...
@ -172,12 +172,12 @@ impl <T: Sized + Init> SharedMemory<T> {
Ok(fd) => {
let mut file = unsafe { File::from_raw_fd(fd) };
let mmap = mmap_file(&mut file, false)?;
return Ok(mmap);
Ok(mmap)
}
Err(err) => bail!("open {:?} failed - {}", path, err),
};
}
Err(err) => return Err(err.into()),
}
Err(err) => Err(err.into()),
}
}

View File

@ -102,7 +102,7 @@ fn sort_data(data: TokenStream) -> Result<TokenStream, Error> {
});
if let Some(err) = err {
return Err(err.into());
return Err(err);
}
array.elems = Punctuated::from_iter(fields);

View File

@ -28,7 +28,7 @@ pub fn fill_with_random_data(buffer: &mut [u8]) -> Result<(), Error> {
libc::getrandom(
buffer.as_mut_ptr() as *mut libc::c_void,
buffer.len() as libc::size_t,
0 as libc::c_uint,
0_u32,
)
};

View File

@ -36,7 +36,7 @@ impl LogRotate {
}
Ok(Self {
base_path: path.as_ref().to_path_buf(),
options: options.unwrap_or(CreateOptions::new()),
options: options.unwrap_or_default(),
compress,
max_files,
})
@ -58,7 +58,7 @@ impl LogRotate {
}
}
fn compress(source_path: &PathBuf, target_path: &PathBuf, options: &CreateOptions) -> Result<(), Error> {
fn compress(source_path: &Path, target_path: &Path, options: &CreateOptions) -> Result<(), Error> {
let mut source = File::open(source_path)?;
let (fd, tmp_path) = make_tmp_file(target_path, options.clone())?;
let target = unsafe { File::from_raw_fd(fd.into_raw_fd()) };