From a677041a55cf449504d65c8f75ab97781bcbbc11 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Mon, 11 Aug 2025 18:54:54 +0100 Subject: [PATCH] Fix new Clippy errors Introduced in Clippy v0.1.89 / Rust v1.89.0. --- src/database/mod.rs | 38 +++++++++++++++---------------- src/error.rs | 2 +- src/lib.rs | 2 +- src/metadata/message.rs | 29 ++++++++++++----------- src/metadata/metadata_document.rs | 28 +++++++++++------------ src/metadata/mod.rs | 2 +- src/plugin/mod.rs | 11 +++++---- 7 files changed, 55 insertions(+), 57 deletions(-) diff --git a/src/database/mod.rs b/src/database/mod.rs index f496f7d1..61bbe1d1 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -248,23 +248,22 @@ impl Database { ) -> Result, MetadataRetrievalError> { let mut metadata = self.masterlist.find_plugin(plugin_name)?; - if include_user_metadata == MergeMode::WithUserMetadata { - if let Some(mut user_metadata) = self.userlist.find_plugin(plugin_name)? { - if let Some(metadata) = metadata { - user_metadata.merge_metadata(&metadata); - } - metadata = Some(user_metadata); - } - } - - if evaluate_conditions == EvalMode::Evaluate { + if include_user_metadata == MergeMode::WithUserMetadata + && let Some(mut user_metadata) = self.userlist.find_plugin(plugin_name)? + { if let Some(metadata) = metadata { - return evaluate_all_conditions(metadata, &self.condition_evaluator_state) - .map_err(Into::into); + user_metadata.merge_metadata(&metadata); } + metadata = Some(user_metadata); } - Ok(metadata) + if evaluate_conditions == EvalMode::Evaluate + && let Some(metadata) = metadata + { + evaluate_all_conditions(metadata, &self.condition_evaluator_state).map_err(Into::into) + } else { + Ok(metadata) + } } /// Get a plugin's metadata loaded from the given userlist. @@ -278,14 +277,13 @@ impl Database { ) -> Result, MetadataRetrievalError> { let metadata = self.userlist.find_plugin(plugin_name)?; - if evaluate_conditions == EvalMode::Evaluate { - if let Some(metadata) = metadata { - return evaluate_all_conditions(metadata, &self.condition_evaluator_state) - .map_err(Into::into); - } + if evaluate_conditions == EvalMode::Evaluate + && let Some(metadata) = metadata + { + evaluate_all_conditions(metadata, &self.condition_evaluator_state).map_err(Into::into) + } else { + Ok(metadata) } - - Ok(metadata) } /// Sets a plugin's user metadata, replacing any loaded user metadata for diff --git a/src/error.rs b/src/error.rs index a64c9217..f5c61cd6 100644 --- a/src/error.rs +++ b/src/error.rs @@ -11,7 +11,7 @@ use crate::sorting::error::{ }; use crate::{Vertex, escape_ascii}; -/// Represents an error that occurred while trying to create a [`Game`]. +/// Represents an error that occurred while trying to create a [`Game`](crate::Game). #[derive(Debug)] #[non_exhaustive] pub enum GameHandleCreationError { diff --git a/src/lib.rs b/src/lib.rs index 3488b05b..114174be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -46,6 +46,6 @@ fn case_insensitive_regex(value: &str) -> Result> { Regex::with_flags(value, "iu").map_err(Into::into) } -fn escape_ascii(path: &Path) -> EscapeAscii { +fn escape_ascii(path: &Path) -> EscapeAscii<'_> { path.as_os_str().as_encoded_bytes().escape_ascii() } diff --git a/src/metadata/message.rs b/src/metadata/message.rs index 0c396b3e..544fc75b 100644 --- a/src/metadata/message.rs +++ b/src/metadata/message.rs @@ -129,12 +129,11 @@ pub fn select_message_content<'a>( } else if matched.is_none() { if language_code.is_some_and(|c| c == mc.language.as_ref()) { matched = Some(mc); - } else if language_code.is_none() { - if let Some((content_language_code, _)) = mc.language.split_once('_') { - if content_language_code == language { - matched = Some(mc); - } - } + } else if language_code.is_none() + && let Some((content_language_code, _)) = mc.language.split_once('_') + && content_language_code == language + { + matched = Some(mc); } if mc.language.as_ref() == MessageContent::DEFAULT_LANGUAGE { @@ -375,16 +374,16 @@ fn format(text: &str, subs: &[&str]) -> Result, MetadataParsingErrorRea new_text.push('{'); } - if let Some(sub_index) = unused_sub_indexes.first() { - if let Some(sub) = subs.get(*sub_index) { - return Err(MetadataParsingErrorReason::MissingPlaceholder( - (*sub).to_owned(), - *sub_index, - )); - } + if let Some(sub_index) = unused_sub_indexes.first() + && let Some(sub) = subs.get(*sub_index) + { + Err(MetadataParsingErrorReason::MissingPlaceholder( + (*sub).to_owned(), + *sub_index, + )) + } else { + Ok(new_text.into_boxed_str()) } - - Ok(new_text.into_boxed_str()) } impl EmitYaml for MessageContent { diff --git a/src/metadata/metadata_document.rs b/src/metadata/metadata_document.rs index 698d29d2..ae554454 100644 --- a/src/metadata/metadata_document.rs +++ b/src/metadata/metadata_document.rs @@ -358,21 +358,21 @@ fn split_on_prelude(masterlist: &str) -> Option<(&str, &str)> { continue; } - if let Some((_, next_byte)) = iter.peek() { - if !matches!(next_byte, b' ' | b'#' | b'\n' | b'\r') { - // LIMITATION: Slicing at index should never fail, but the - // compiler can't see that. A variation of str.find() that - // could take a closure that matches on substrings would - // eliminate the need for this. - if let Some(suffix) = remainder.get(index..) { - return Some((prefix, suffix)); - } - - logging::error!( - "Unexpectedly failed to slice the masterlist on a new line at index {}", - prefix.len() + index - ); + if let Some((_, next_byte)) = iter.peek() + && !matches!(next_byte, b' ' | b'#' | b'\n' | b'\r') + { + // LIMITATION: Slicing at index should never fail, but the + // compiler can't see that. A variation of str.find() that + // could take a closure that matches on substrings would + // eliminate the need for this. + if let Some(suffix) = remainder.get(index..) { + return Some((prefix, suffix)); } + + logging::error!( + "Unexpectedly failed to slice the masterlist on a new line at index {}", + prefix.len() + index + ); } } diff --git a/src/metadata/mod.rs b/src/metadata/mod.rs index 4446cd66..004a9c11 100644 --- a/src/metadata/mod.rs +++ b/src/metadata/mod.rs @@ -27,7 +27,7 @@ fn emit(metadata: &T) -> String { } #[cfg(test)] -fn parse(yaml: &str) -> saphyr::MarkedYaml { +fn parse(yaml: &str) -> saphyr::MarkedYaml<'_> { use saphyr::LoadableYamlNode; saphyr::MarkedYaml::load_from_str(yaml) diff --git a/src/plugin/mod.rs b/src/plugin/mod.rs index d5ad8e5a..045c1907 100644 --- a/src/plugin/mod.rs +++ b/src/plugin/mod.rs @@ -391,12 +391,13 @@ fn calculate_crc(path: &Path) -> std::io::Result { } fn extract_bash_tags(description: &str) -> Vec { - if let Some((_, bash_tags)) = description.split_once("{{BASH:") { - if let Some((bash_tags, _)) = bash_tags.split_once("}}") { - return bash_tags.split(',').map(|s| s.trim().to_owned()).collect(); - } + if let Some((_, bash_tags)) = description.split_once("{{BASH:") + && let Some((bash_tags, _)) = bash_tags.split_once("}}") + { + bash_tags.split(',').map(|s| s.trim().to_owned()).collect() + } else { + Vec::new() } - Vec::new() } fn extract_version(description: &str) -> Option {