From b1ca60f5ba5f06992dc4cf3e5b6e468d01cd189b Mon Sep 17 00:00:00 2001 From: Marc Hartmayer Date: Tue, 3 Dec 2024 15:43:49 +0100 Subject: [PATCH] rust: Automatically generated Clippy fixes for the tools only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clippy settings: [workspace.lints.clippy] cognitive_complexity = "warn" dbg_macro = "warn" debug_assert_with_mut_call = "warn" doc_link_with_quotes = "warn" doc_markdown = "warn" empty_line_after_outer_attr = "warn" empty_structs_with_brackets = "warn" float_cmp = "warn" float_cmp_const = "warn" float_equality_without_abs = "warn" missing_const_for_fn = "warn" missing_errors_doc = "warn" mod_module_files = "warn" option_if_let_else = "warn" similar_names = "warn" suspicious_operation_groupings = "warn" unused_self = "warn" use_debug = "warn" used_underscore_binding = "warn" useless_let_if_seq = "warn" wildcard_dependencies = "warn" wildcard_imports = "warn" Command used: $ cargo +nightly clippy --fix Reviewed-by: Steffen Eiden Signed-off-by: Marc Hartmayer Signed-off-by: Jan Höppner --- rust/cpacfinfo/src/main.rs | 5 +---- rust/cpacfinfo/src/query.rs | 11 ++--------- rust/pvapconfig/src/ap.rs | 15 +++------------ rust/pvattest/src/cmd/check/host_key.rs | 4 ++-- rust/pvattest/src/exchange.rs | 2 +- rust/pvattest/src/main.rs | 2 +- 6 files changed, 10 insertions(+), 29 deletions(-) diff --git a/rust/cpacfinfo/src/main.rs b/rust/cpacfinfo/src/main.rs index ff82f60a..1e84f925 100644 --- a/rust/cpacfinfo/src/main.rs +++ b/rust/cpacfinfo/src/main.rs @@ -135,10 +135,7 @@ fn main() -> anyhowRes<()> { /* ---- GET INFORMATION ---- */ // get stfle bits - let stfle_bits = match Stfle::new() { - Ok(stfle) => stfle, - Err(e) => return Err(e), - }; + let stfle_bits = Stfle::new()?; // check stfle bits for available MSA levels for lvl in &mut levels { diff --git a/rust/cpacfinfo/src/query.rs b/rust/cpacfinfo/src/query.rs index 85916732..a92fba40 100644 --- a/rust/cpacfinfo/src/query.rs +++ b/rust/cpacfinfo/src/query.rs @@ -5,7 +5,6 @@ use std::fs::File; use std::io::Error; use std::io::Read; -use std::io::Result as ioRes; use std::ops::Index; use std::result::Result; @@ -217,10 +216,7 @@ pub fn query(ins: &InstructionKind, fc: u8) -> Result { ); // open file - let mut f = match File::open(filepath) { - ioRes::Ok(file) => file, - Err(e) => return Err(e), - }; + let mut f = File::open(filepath)?; // read file let res = match param { @@ -228,10 +224,7 @@ pub fn query(ins: &InstructionKind, fc: u8) -> Result { Param::QaiParam(ref mut c) => read_file_to_buf(&mut f, c), }; - let bytes_read = match res { - Ok(b) => b, - Err(e) => return Err(e), - }; + let bytes_read = res?; match bytes_read == bytes_to_be_read { true => Ok(param), diff --git a/rust/pvapconfig/src/ap.rs b/rust/pvapconfig/src/ap.rs index ff5bfb1b..f8881770 100644 --- a/rust/pvapconfig/src/ap.rs +++ b/rust/pvapconfig/src/ap.rs @@ -578,10 +578,7 @@ pub fn set_apqn_bind_state(card: u32, dom: u32, state: BindState) -> Result<(), card, dom )); } - let newstate = match get_apqn_bind_state(card, dom) { - Err(err) => return Err(err), - Ok(s) => s, - }; + let newstate = get_apqn_bind_state(card, dom)?; if newstate == state { return Ok(()); } @@ -653,10 +650,7 @@ fn set_apqn_associate_state_associate(card: u32, dom: u32, idx: u16) -> Result<( card, dom, idx )); } - let newstate = match get_apqn_associate_state(card, dom) { - Err(err) => return Err(err), - Ok(s) => s, - }; + let newstate = get_apqn_associate_state(card, dom)?; if let AssocState::Associated(i) = newstate { if idx == i { return Ok(()); @@ -694,10 +688,7 @@ fn set_apqn_associate_state_unbind(card: u32, dom: u32) -> Result<(), String> { card, dom )); } - let newstate = match get_apqn_associate_state(card, dom) { - Err(err) => return Err(err), - Ok(s) => s, - }; + let newstate = get_apqn_associate_state(card, dom)?; if newstate == AssocState::Unassociated { return Ok(()); } diff --git a/rust/pvattest/src/cmd/check/host_key.rs b/rust/pvattest/src/cmd/check/host_key.rs index bf8c4fe0..27b30141 100644 --- a/rust/pvattest/src/cmd/check/host_key.rs +++ b/rust/pvattest/src/cmd/check/host_key.rs @@ -86,14 +86,14 @@ pub struct HostKeyCheck<'a> { } impl<'a> HostKeyCheck<'a> { - pub fn new(check_enforced: bool, hash: Option<&'a Path>) -> Self { + pub const fn new(check_enforced: bool, hash: Option<&'a Path>) -> Self { Self { check_enforced, hash, } } - pub fn hide(&self) -> bool { + pub const fn hide(&self) -> bool { self.hash.is_none() && !self.check_enforced } } diff --git a/rust/pvattest/src/exchange.rs b/rust/pvattest/src/exchange.rs index 884df946..3bbff245 100644 --- a/rust/pvattest/src/exchange.rs +++ b/rust/pvattest/src/exchange.rs @@ -577,7 +577,7 @@ anyhow!( /// /// # Error /// Returns an error if the [`ExchangeFormatRequest`] contains no CUID, - pub fn config_uid(&self) -> &ConfigUid { + pub const fn config_uid(&self) -> &ConfigUid { &self.config_uid } diff --git a/rust/pvattest/src/main.rs b/rust/pvattest/src/main.rs index 6eb62124..b69332bc 100644 --- a/rust/pvattest/src/main.rs +++ b/rust/pvattest/src/main.rs @@ -14,7 +14,7 @@ use log::trace; use std::process::ExitCode; use utils::{print_cli_error, print_error, print_version, PvLogger}; -use crate::cmd::*; +use crate::cmd::{check, create, perform, verify, CMD_FN, UV_CMD_FN}; static LOGGER: PvLogger = PvLogger; const FEATURES: &[&[&str]] = &[CMD_FN, UV_CMD_FN];