From b6c7d6ce26ea133047e83606a44bd4b6149a4eae Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sat, 17 May 2025 19:03:33 +0100 Subject: [PATCH] Address clippy warnings introduced in Rust 1.87.0 --- src/game.rs | 30 +++++++++++++++--------------- src/metadata/group.rs | 1 - src/metadata/message.rs | 17 ++++++++--------- src/plugin/mod.rs | 34 +++++++++++++++++----------------- src/sorting/validate.rs | 2 +- 5 files changed, 41 insertions(+), 43 deletions(-) diff --git a/src/game.rs b/src/game.rs index 389d8f9c..236ce575 100644 --- a/src/game.rs +++ b/src/game.rs @@ -138,8 +138,8 @@ impl From for esplugin::GameId { /// The interface through which game-specific functionality is provided. #[derive(Debug)] pub struct Game { - game_type: GameType, - game_path: PathBuf, + base_type: GameType, + install_path: PathBuf, load_order: Box<(dyn WritableLoadOrder + Send + Sync + 'static)>, // Stored in an Arc> to support loading metadata in parallel with // loading plugins. @@ -179,8 +179,8 @@ impl Game { new_condition_evaluator_state(game_type, &resolved_game_path, load_order.as_ref()); Ok(Game { - game_type, - game_path: resolved_game_path, + base_type: game_type, + install_path: resolved_game_path, load_order, database: Arc::new(RwLock::new(Database::new(condition_evaluator_state))), cache: GameCache::default(), @@ -233,8 +233,8 @@ impl Game { new_condition_evaluator_state(game_type, &resolved_game_path, load_order.as_ref()); Ok(Game { - game_type, - game_path: resolved_game_path, + base_type: game_type, + install_path: resolved_game_path, load_order, database: Arc::new(RwLock::new(Database::new(condition_evaluator_state))), cache: GameCache::default(), @@ -243,7 +243,7 @@ impl Game { /// Get the game's type. pub fn game_type(&self) -> GameType { - self.game_type + self.base_type } /// Gets the currently-set additional data paths. @@ -309,11 +309,11 @@ impl Game { /// as given. pub fn is_valid_plugin(&self, plugin_path: &Path) -> bool { let resolved_path = resolve_plugin_path( - self.game_type, - &data_path(self.game_type, &self.game_path), + self.base_type, + &data_path(self.base_type, &self.install_path), plugin_path, ); - validate_plugin_path_and_header(self.game_type, &resolved_path).is_ok() + validate_plugin_path_and_header(self.base_type, &resolved_path).is_ok() } /// Fully parses plugins and loads their data. @@ -335,7 +335,7 @@ impl Game { let mut plugins = self.load_plugins_common(plugin_paths, LoadScope::WholePlugin)?; if matches!( - self.game_type, + self.base_type, GameType::Morrowind | GameType::OpenMW | GameType::Starfield ) { let mut loaded_plugins: HashMap = self @@ -387,12 +387,12 @@ impl Game { plugin_paths: &[&Path], load_scope: LoadScope, ) -> Result, LoadPluginsError> { - let data_path = data_path(self.game_type, &self.game_path); + let data_path = data_path(self.base_type, &self.install_path); - validate_plugin_paths(self.game_type, &data_path, plugin_paths)?; + validate_plugin_paths(self.base_type, &data_path, plugin_paths)?; let archive_paths = - find_archives(self.game_type, self.additional_data_paths(), &data_path)?; + find_archives(self.base_type, self.additional_data_paths(), &data_path)?; self.cache.set_archive_paths(archive_paths); @@ -401,7 +401,7 @@ impl Game { let plugins: Vec<_> = plugin_paths .par_iter() .filter_map(|path| { - try_load_plugin(&data_path, path, self.game_type, &self.cache, load_scope) + try_load_plugin(&data_path, path, self.base_type, &self.cache, load_scope) }) .collect(); diff --git a/src/metadata/group.rs b/src/metadata/group.rs index f37dfc7c..3be15c4d 100644 --- a/src/metadata/group.rs +++ b/src/metadata/group.rs @@ -62,7 +62,6 @@ impl Group { impl std::default::Default for Group { /// Construct a Group with the default name and an empty set of groups to /// load after. - #[must_use] fn default() -> Self { Self { name: Group::DEFAULT_NAME.into(), diff --git a/src/metadata/message.rs b/src/metadata/message.rs index b1d957d6..36c1669c 100644 --- a/src/metadata/message.rs +++ b/src/metadata/message.rs @@ -79,7 +79,6 @@ impl MessageContent { impl std::default::Default for MessageContent { /// Construct a [MessageContent] object with an empty message string and the /// default language. - #[must_use] fn default() -> Self { Self { text: Box::default(), @@ -151,7 +150,7 @@ pub fn select_message_content<'a>( /// Represents a message with localisable text content. #[derive(Clone, Debug, Default, Eq, PartialEq, Ord, PartialOrd, Hash)] pub struct Message { - message_type: MessageType, + level: MessageType, content: Box<[MessageContent]>, condition: Option>, } @@ -162,7 +161,7 @@ impl Message { #[must_use] pub fn new(message_type: MessageType, content: String) -> Self { Self { - message_type, + level: message_type, content: Box::new([MessageContent::new(content)]), condition: None, } @@ -178,7 +177,7 @@ impl Message { validate_message_contents(&content)?; Ok(Self { - message_type, + level: message_type, content: content.into_boxed_slice(), condition: None, }) @@ -193,7 +192,7 @@ impl Message { /// Get the message type. pub fn message_type(&self) -> MessageType { - self.message_type + self.level } /// Get the message content. @@ -306,7 +305,7 @@ impl TryFromYaml for Message { let condition = parse_condition(mapping, "condition", YamlObjectType::Message)?; Ok(Message { - message_type, + level: message_type, content, condition, }) @@ -436,7 +435,7 @@ impl EmitYaml for Message { emitter.begin_map(); emitter.map_key("type"); - emitter.unquoted_str(&self.message_type.to_string()); + emitter.unquoted_str(&self.level.to_string()); emit_message_contents(&self.content, emitter, "content"); @@ -829,7 +828,7 @@ mod tests { assert_eq!( format!( "type: {}\ncontent: '{}'\ncondition: '{}'", - message.message_type, + message.level, message.content[0].text, message.condition.unwrap() ), @@ -857,7 +856,7 @@ content: text: '{}' - lang: {} text: '{}'", - message.message_type, + message.level, message.content[0].language(), message.content[0].text(), message.content[1].language(), diff --git a/src/plugin/mod.rs b/src/plugin/mod.rs index 5a307823..54661320 100644 --- a/src/plugin/mod.rs +++ b/src/plugin/mod.rs @@ -44,7 +44,7 @@ impl std::fmt::Display for LoadScope { #[derive(Clone, Debug, Eq, PartialEq)] pub struct Plugin { name: String, - plugin: Option, + data: Option, game_type: GameType, crc: Option, version: Option, @@ -97,7 +97,7 @@ impl Plugin { Ok(Self { name, - plugin, + data: plugin, game_type, crc, version, @@ -123,7 +123,7 @@ impl Plugin { /// and OpenMW) or if the `HEDR` subrecord could not be found, of if the /// version field's value was `NaN`. pub fn header_version(&self) -> Option { - self.plugin + self.data .as_ref() .and_then(esplugin::Plugin::header_version) } @@ -140,7 +140,7 @@ impl Plugin { /// Get the plugin's masters. pub fn masters(&self) -> Result, PluginDataError> { - self.plugin + self.data .as_ref() .map_or_else(|| Ok(Vec::new()), |p| p.masters().map_err(Into::into)) } @@ -173,7 +173,7 @@ impl Plugin { if self.game_type == GameType::OpenMW { false } else { - self.plugin + self.data .as_ref() .is_some_and(esplugin::Plugin::is_master_file) } @@ -181,49 +181,49 @@ impl Plugin { /// Check if the plugin is a light plugin. pub fn is_light_plugin(&self) -> bool { - self.plugin + self.data .as_ref() .is_some_and(esplugin::Plugin::is_light_plugin) } /// Check if the plugin is a medium plugin. pub fn is_medium_plugin(&self) -> bool { - self.plugin + self.data .as_ref() .is_some_and(esplugin::Plugin::is_medium_plugin) } /// Check if the plugin is an update plugin. pub fn is_update_plugin(&self) -> bool { - self.plugin + self.data .as_ref() .is_some_and(esplugin::Plugin::is_update_plugin) } /// Check if the plugin is a blueprint plugin. pub fn is_blueprint_plugin(&self) -> bool { - self.plugin + self.data .as_ref() .is_some_and(esplugin::Plugin::is_blueprint_plugin) } /// Check if the plugin is or would be valid as a light plugin. pub fn is_valid_as_light_plugin(&self) -> Result { - self.plugin.as_ref().map_or(Ok(false), |p| { + self.data.as_ref().map_or(Ok(false), |p| { p.is_valid_as_light_plugin().map_err(Into::into) }) } /// Check if the plugin is or would be valid as a medium plugin. pub fn is_valid_as_medium_plugin(&self) -> Result { - self.plugin.as_ref().map_or(Ok(false), |p| { + self.data.as_ref().map_or(Ok(false), |p| { p.is_valid_as_medium_plugin().map_err(Into::into) }) } /// Check if the plugin is or would be valid as an update plugin. pub fn is_valid_as_update_plugin(&self) -> Result { - self.plugin.as_ref().map_or(Ok(false), |p| { + self.data.as_ref().map_or(Ok(false), |p| { p.is_valid_as_update_plugin().map_err(Into::into) }) } @@ -231,7 +231,7 @@ impl Plugin { /// Check if the plugin contains any records other than its `TES3`/`TES4` /// header. pub fn is_empty(&self) -> bool { - self.plugin + self.data .as_ref() .and_then(esplugin::Plugin::record_and_group_count) .unwrap_or(0) @@ -248,7 +248,7 @@ impl Plugin { /// FormIDs are compared for all games apart from Morrowind, which doesn't /// have FormIDs and so has other identifying data compared. pub fn do_records_overlap(&self, plugin: &Plugin) -> Result { - if let (Some(plugin), Some(other_plugin)) = (&self.plugin, &plugin.plugin) { + if let (Some(plugin), Some(other_plugin)) = (&self.data, &plugin.data) { plugin.overlaps_with(other_plugin).map_err(Into::into) } else { Ok(false) @@ -256,7 +256,7 @@ impl Plugin { } pub(crate) fn override_record_count(&self) -> Result { - self.plugin + self.data .as_ref() .map_or(Ok(0), |p| p.count_override_records().map_err(Into::into)) } @@ -273,7 +273,7 @@ impl Plugin { &mut self, plugins_metadata: &[esplugin::PluginMetadata], ) -> Result<(), PluginDataError> { - if let Some(plugin) = &mut self.plugin { + if let Some(plugin) = &mut self.data { plugin.resolve_record_ids(plugins_metadata)?; } Ok(()) @@ -351,7 +351,7 @@ pub(crate) fn has_ascii_extension(path: &Path, extension: &str) -> bool { pub(crate) fn plugins_metadata( plugins: &[&Plugin], ) -> Result, PluginDataError> { - let esplugins: Vec<_> = plugins.iter().filter_map(|p| p.plugin.as_ref()).collect(); + let esplugins: Vec<_> = plugins.iter().filter_map(|p| p.data.as_ref()).collect(); Ok(esplugin::plugins_metadata(&esplugins)?) } diff --git a/src/sorting/validate.rs b/src/sorting/validate.rs index 7494c1b9..5e74df8c 100644 --- a/src/sorting/validate.rs +++ b/src/sorting/validate.rs @@ -190,7 +190,7 @@ fn validate_early_loading_plugins( if non_masters.contains(&key) { // Just report the cycle to the first master. return Err(CyclicInteractionError::new(vec![ - Vertex::new(plugin.to_string()).with_out_edge_type(EdgeType::Hardcoded), + Vertex::new(plugin.clone()).with_out_edge_type(EdgeType::Hardcoded), Vertex::new(master.name().to_owned()).with_out_edge_type(EdgeType::MasterFlag), ])); }