From 2aaa13bd7efa2d35476c706f2e09e6d5d01551c1 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Tue, 22 Apr 2025 18:18:32 +0100 Subject: [PATCH] Deny the clippy::str_to_string lint --- src/database/conditions.rs | 2 +- src/database/mod.rs | 2 +- src/game.rs | 8 ++++---- src/lib.rs | 2 +- src/logging.rs | 10 ++++----- src/metadata/file.rs | 2 +- src/metadata/message.rs | 2 +- src/metadata/metadata_document.rs | 20 +++++++++--------- src/metadata/yaml/emit.rs | 34 +++++++++++++++---------------- src/metadata/yaml/parse.rs | 2 +- src/plugin/mod.rs | 8 ++++---- src/sorting/error.rs | 4 ++-- src/sorting/groups.rs | 8 ++++---- src/sorting/mod.rs | 9 ++++---- src/sorting/plugins.rs | 21 ++++++++----------- src/sorting/validate.rs | 8 ++++---- src/tests.rs | 2 +- src/version.rs | 4 ++-- 18 files changed, 72 insertions(+), 76 deletions(-) diff --git a/src/database/conditions.rs b/src/database/conditions.rs index 3fd83081..ad43b79d 100644 --- a/src/database/conditions.rs +++ b/src/database/conditions.rs @@ -131,7 +131,7 @@ mod tests { let mut plugin = PluginMetadata::new(BLANK_ESM).unwrap(); plugin.set_group("group1".into()); - let condition = "file(\"missing.esp\")".to_string(); + let condition = "file(\"missing.esp\")".to_owned(); let files = vec![ File::new(BLANK_ESP.into()), File::new(BLANK_DIFFERENT_ESM.into()).with_condition(condition.clone()), diff --git a/src/database/mod.rs b/src/database/mod.rs index f71e4890..ca2a6135 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -333,7 +333,7 @@ fn merge_groups(lhs: &[Group], rhs: &[Group]) -> Vec { let mut new_group = group.clone(); if let Some(description) = rhs_group.description() { - new_group = new_group.with_description(description.to_string()); + new_group = new_group.with_description(description.to_owned()); } if !rhs_group.after_groups().is_empty() { diff --git a/src/game.rs b/src/game.rs index 8a34330e..297d62b2 100644 --- a/src/game.rs +++ b/src/game.rs @@ -339,7 +339,7 @@ impl Game { .collect(); for plugin in &plugins { - loaded_plugins.insert(Filename::new(plugin.name().to_string()), plugin); + loaded_plugins.insert(Filename::new(plugin.name().to_owned()), plugin); } let loaded_plugins: Vec<_> = loaded_plugins.into_values().collect(); @@ -776,7 +776,7 @@ impl GameCache { fn insert_plugins(&mut self, plugins: Vec) { for plugin in plugins { self.plugins - .insert(Filename::new(plugin.name().to_string()), Arc::new(plugin)); + .insert(Filename::new(plugin.name().to_owned()), Arc::new(plugin)); } } @@ -793,7 +793,7 @@ impl GameCache { } fn plugin(&self, plugin_name: &str) -> Option<&Arc> { - self.plugins.get(&Filename::new(plugin_name.to_string())) + self.plugins.get(&Filename::new(plugin_name.to_owned())) } pub fn archives_iter(&self) -> impl Iterator { @@ -1259,7 +1259,7 @@ mod tests { .unwrap(); game.load_current_load_order_state().unwrap(); - load_order.push(filename.to_string()); + load_order.push(filename.to_owned()); assert_eq!(load_order, game.load_order()); } diff --git a/src/lib.rs b/src/lib.rs index 724bead7..5533d9f8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -77,7 +77,7 @@ clippy::redundant_type_annotations, clippy::ref_patterns, clippy::rest_pat_in_fully_bound_structs, - // clippy::str_to_string, + clippy::str_to_string, clippy::string_lit_chars_any, // clippy::string_slice, clippy::string_to_string, diff --git a/src/logging.rs b/src/logging.rs index 86209eee..f444c29f 100644 --- a/src/logging.rs +++ b/src/logging.rs @@ -192,7 +192,7 @@ mod tests { fn callback(level: LogLevel, message: &str) { if let Ok(mut messages) = MESSAGES.lock() { - messages.push((level, message.to_string())); + messages.push((level, message.to_owned())); } } @@ -216,7 +216,7 @@ mod tests { let cloned_messages = Arc::clone(&messages); let callback = move |level, message: &str| { if let Ok(mut messages) = cloned_messages.lock() { - messages.push((level, message.to_string())); + messages.push((level, message.to_owned())); } }; @@ -237,7 +237,7 @@ mod tests { fn callback_fn(level: LogLevel, message: &str) { if let Ok(mut messages) = MESSAGES.lock() { - messages.push((level, message.to_string())); + messages.push((level, message.to_owned())); } } @@ -250,7 +250,7 @@ mod tests { let cloned_messages = Arc::clone(&messages); let callback = move |level, message: &str| { if let Ok(mut messages) = cloned_messages.lock() { - messages.push((level, message.to_string())); + messages.push((level, message.to_owned())); } }; @@ -284,7 +284,7 @@ mod tests { fn callback(level: LogLevel, message: &str) { if let Ok(mut messages) = MESSAGES.lock() { - messages.push((level, message.to_string())); + messages.push((level, message.to_owned())); } } diff --git a/src/metadata/file.rs b/src/metadata/file.rs index 0a9d1f75..7ac5b102 100644 --- a/src/metadata/file.rs +++ b/src/metadata/file.rs @@ -213,7 +213,7 @@ impl TryFromYaml for File { let constraint = parse_condition(h, "constraint", YamlObjectType::File)?; Ok(File { - name: Filename::new(name.to_string()), + name: Filename::new(name.to_owned()), display_name: display_name.map(|(_, s)| s.into()), detail, condition, diff --git a/src/metadata/message.rs b/src/metadata/message.rs index 1069274c..19f1bb15 100644 --- a/src/metadata/message.rs +++ b/src/metadata/message.rs @@ -369,7 +369,7 @@ impl TryFromYaml for Message { if let Ok(Some(m)) = FMT_REGEX.find(&mc.text) { return Err(ParseMetadataError::new( value.span.start, - MetadataParsingErrorReason::MissingSubstitution(m.as_str().to_string()), + MetadataParsingErrorReason::MissingSubstitution(m.as_str().to_owned()), )); } } diff --git a/src/metadata/metadata_document.rs b/src/metadata/metadata_document.rs index dc0a0968..ea39b3d9 100644 --- a/src/metadata/metadata_document.rs +++ b/src/metadata/metadata_document.rs @@ -120,11 +120,11 @@ impl MetadataDocument { if plugin.is_regex_plugin() { regex_plugins.push(plugin); } else { - let filename = Filename::new(plugin.name().to_string()); + let filename = Filename::new(plugin.name().to_owned()); if let Some(old) = plugins.insert(filename, plugin) { return Err(ParseMetadataError::duplicate_entry( plugin_yaml.span.start, - old.name().to_string(), + old.name().to_owned(), YamlObjectType::PluginMetadata, ) .into()); @@ -155,13 +155,13 @@ impl MetadataDocument { if str_set.contains(bash_tag) { return Err(ParseMetadataError::duplicate_entry( bash_tag_yaml.span.start, - bash_tag.to_string(), + bash_tag.to_owned(), YamlObjectType::BashTagsElement, ) .into()); } - bash_tags.push(bash_tag.to_string()); + bash_tags.push(bash_tag.to_owned()); str_set.insert(bash_tag); } @@ -170,11 +170,11 @@ impl MetadataDocument { for group_yaml in get_as_slice(&doc, "groups", YamlObjectType::MetadataDocument)? { let group = Group::try_from_yaml(group_yaml)?; - let name = group.name().to_string(); + let name = group.name().to_owned(); if group_names.contains(&name) { return Err(ParseMetadataError::duplicate_entry( group_yaml.span.start, - group.name().to_string(), + group.name().to_owned(), YamlObjectType::Group, ) .into()); @@ -266,7 +266,7 @@ impl MetadataDocument { } pub fn find_plugin(&self, plugin_name: &str) -> Result, RegexError> { - let mut metadata = match self.plugins.get(&Filename::new(plugin_name.to_string())) { + let mut metadata = match self.plugins.get(&Filename::new(plugin_name.to_owned())) { Some(m) => m.clone(), None => PluginMetadata::new(plugin_name)?, }; @@ -303,14 +303,14 @@ impl MetadataDocument { self.regex_plugins.push(plugin_metadata); } else { self.plugins.insert( - Filename::new(plugin_metadata.name().to_string()), + Filename::new(plugin_metadata.name().to_owned()), plugin_metadata, ); } } pub fn remove_plugin_metadata(&mut self, plugin_name: &str) { - self.plugins.remove(&Filename::new(plugin_name.to_string())); + self.plugins.remove(&Filename::new(plugin_name.to_owned())); } pub fn clear(&mut self) { @@ -390,7 +390,7 @@ fn find_prelude_bounds(masterlist: &str) -> Option<(usize, usize)> { } fn indent_prelude(prelude: &str, line_ending: &str) -> String { - let prelude = ("\n ".to_string() + &prelude.replace('\n', "\n ")) + let prelude = ("\n ".to_owned() + &prelude.replace('\n', "\n ")) .replace(&format!(" {line_ending}"), line_ending); if prelude.ends_with("\n ") { diff --git a/src/metadata/yaml/emit.rs b/src/metadata/yaml/emit.rs index 5cbbafcb..a4a554bc 100644 --- a/src/metadata/yaml/emit.rs +++ b/src/metadata/yaml/emit.rs @@ -271,23 +271,23 @@ fn double_quote(value: &str) -> String { .map(|c| { if should_escape(c) { match c { - '\x00' => "\\0".to_string(), - '\x07' => "\\a".to_string(), - '\x08' => "\\b".to_string(), - '\x09' => "\\t".to_string(), - '\x0A' => "\\n".to_string(), - '\x0B' => "\\v".to_string(), - '\x0C' => "\\f".to_string(), - '\x0D' => "\\r".to_string(), - '\x1B' => "\\e".to_string(), - '\x20' => "\\x20".to_string(), - '"' => "\\\"".to_string(), - '/' => "\\/".to_string(), - '\\' => "\\\\".to_string(), - '\u{0085}' => "\\N".to_string(), - '\u{00A0}' => "\\_".to_string(), - '\u{2028}' => "\\L".to_string(), - '\u{2029}' => "\\P".to_string(), + '\x00' => "\\0".to_owned(), + '\x07' => "\\a".to_owned(), + '\x08' => "\\b".to_owned(), + '\x09' => "\\t".to_owned(), + '\x0A' => "\\n".to_owned(), + '\x0B' => "\\v".to_owned(), + '\x0C' => "\\f".to_owned(), + '\x0D' => "\\r".to_owned(), + '\x1B' => "\\e".to_owned(), + '\x20' => "\\x20".to_owned(), + '"' => "\\\"".to_owned(), + '/' => "\\/".to_owned(), + '\\' => "\\\\".to_owned(), + '\u{0085}' => "\\N".to_owned(), + '\u{00A0}' => "\\_".to_owned(), + '\u{2028}' => "\\L".to_owned(), + '\u{2029}' => "\\P".to_owned(), '\u{00}'..='\u{FF}' => format!("\\x{:02X}", u32::from(c)), '\u{0100}'..='\u{FFFF}' => format!("\\u{:04X}", u32::from(c)), c => format!("\\U{:08X}", u32::from(c)), diff --git a/src/metadata/yaml/parse.rs b/src/metadata/yaml/parse.rs index 787e2386..e953815a 100644 --- a/src/metadata/yaml/parse.rs +++ b/src/metadata/yaml/parse.rs @@ -185,7 +185,7 @@ pub fn parse_condition( ) -> Result>, ParseMetadataError> { match get_string_value(mapping, key, yaml_type)? { Some((marker, s)) => { - let s = s.to_string(); + let s = s.to_owned(); if let Err(e) = Expression::from_str(&s) { return Err(ParseMetadataError::invalid_condition(marker, s, e)); } diff --git a/src/plugin/mod.rs b/src/plugin/mod.rs index 26b02773..a877647a 100644 --- a/src/plugin/mod.rs +++ b/src/plugin/mod.rs @@ -358,8 +358,8 @@ pub(crate) fn plugins_metadata( fn name_string(game_type: GameType, path: &Path) -> Result { match path.file_name() { Some(f) => match f.to_str() { - Some(f) if game_type == GameType::OpenMW => Ok(f.to_string()), - Some(f) => Ok(trim_dot_ghost(f).to_string()), + Some(f) if game_type == GameType::OpenMW => Ok(f.to_owned()), + Some(f) => Ok(trim_dot_ghost(f).to_owned()), None => Err(LoadPluginError::InvalidFilename( InvalidFilenameReason::NonUnicode, )), @@ -396,7 +396,7 @@ fn extract_bash_tags(description: &str) -> Vec { if let Some(end_pos) = description[start_pos..].find("}}") { return description[start_pos..start_pos + end_pos] .split(',') - .map(|s| s.trim().to_string()) + .map(|s| s.trim().to_owned()) .collect(); } } @@ -1147,7 +1147,7 @@ Requires Skyrim Special Edition 1.5.39 or greater. assert_eq!( vec![ - "C.Climate".to_string(), + "C.Climate".to_owned(), "C.Encounter".into(), "C.ImageSpace".into(), "C.Light".into(), diff --git a/src/sorting/error.rs b/src/sorting/error.rs index dafec336..4c37b4da 100644 --- a/src/sorting/error.rs +++ b/src/sorting/error.rs @@ -56,10 +56,10 @@ pub(crate) fn display_cycle(cycle: &[Vertex]) -> String { if let Some(edge_type) = v.out_edge_type() { format!("{} --[{}]-> ", v.name(), edge_type) } else { - v.name().to_string() + v.name().to_owned() } }) - .chain(cycle.first().iter().map(|v| v.name().to_string())) + .chain(cycle.first().iter().map(|v| v.name().to_owned())) .collect() } diff --git a/src/sorting/groups.rs b/src/sorting/groups.rs index f3e5c432..d152a334 100644 --- a/src/sorting/groups.rs +++ b/src/sorting/groups.rs @@ -91,14 +91,14 @@ fn add_groups<'a>( "Unexpectedly couldn't find node for group {}: it should have just been added to the graph", group.name() ); - return Err(UndefinedGroupError::new(group.name().to_string())); + return Err(UndefinedGroupError::new(group.name().to_owned())); }; for other_group_name in sorted_clone(group.after_groups()) { if let Some(other_index) = group_nodes.get(other_group_name) { graph.update_edge(*other_index, *node_index, edge_type); } else { - return Err(UndefinedGroupError::new(other_group_name.to_string())); + return Err(UndefinedGroupError::new(other_group_name.to_owned())); } } } @@ -198,7 +198,7 @@ fn find_node_by_weight( Ok(n) } else { logging::error!("Can't find group with name {}", weight); - Err(UndefinedGroupError::new(weight.to_string())) + Err(UndefinedGroupError::new(weight.to_owned())) } } @@ -272,7 +272,7 @@ pub fn get_default_group_node(graph: &GroupsGraph) -> Result Self { Self { - name: name.to_string(), + name: name.to_owned(), ..Default::default() } } pub fn add_master(&mut self, plugin_name: &str) { - self.masters.push(plugin_name.to_string()); + self.masters.push(plugin_name.to_owned()); } pub fn add_overlapping_records(&mut self, plugin_name: &str) { - self.overlapping_record_plugins - .push(plugin_name.to_string()); + self.overlapping_record_plugins.push(plugin_name.to_owned()); } pub fn add_overlapping_assets(&mut self, plugin_name: &str) { - self.overlapping_asset_plugins.push(plugin_name.to_string()); + self.overlapping_asset_plugins.push(plugin_name.to_owned()); } } diff --git a/src/sorting/plugins.rs b/src/sorting/plugins.rs index c0e3a3b3..8417bb4b 100644 --- a/src/sorting/plugins.rs +++ b/src/sorting/plugins.rs @@ -142,10 +142,7 @@ impl SortingPlugin for Plugin { } fn to_filenames(files: &[File]) -> Box<[String]> { - files - .iter() - .map(|f| f.name().as_str().to_string()) - .collect() + files.iter().map(|f| f.name().as_str().to_owned()).collect() } type InnerPluginsGraph<'a, T> = Graph>, EdgeType>; @@ -288,7 +285,7 @@ impl<'a, T: SortingPlugin> PluginsGraph<'a, T> { } fn check_for_cycles(&mut self) -> Result<(), CyclicInteractionError> { - if let Some(cycle) = find_cycle(&self.inner, |node| node.name().to_string()) { + if let Some(cycle) = find_cycle(&self.inner, |node| node.name().to_owned()) { Err(CyclicInteractionError::new(cycle)) } else { Ok(()) @@ -692,7 +689,7 @@ impl<'a, T: SortingPlugin> PluginsGraph<'a, T> { fn topological_sort(&self) -> Result, SortingError> { petgraph::algo::toposort(&self.inner, None) - .map_err(|e| SortingError::CycleInvolving(self[e.node_id()].name().to_string())) + .map_err(|e| SortingError::CycleInvolving(self[e.node_id()].name().to_owned())) } /// Returns the first pair of consecutive nodes that don't have an edge joining them. @@ -862,7 +859,7 @@ fn sort_plugins_partition( let sorted_plugin_names = sorted_nodes .into_iter() - .map(|i| graph[i].name().to_string()) + .map(|i| graph[i].name().to_owned()) .collect(); Ok(sorted_plugin_names) @@ -926,7 +923,7 @@ impl<'a, 'b, T: SortingPlugin> PathFinder<'a, 'b, T> { path_to_string(self.graph, &path) ); return Err(PathfindingError::PrecedingNodeNotFound( - self.graph[current_node].name().to_string(), + self.graph[current_node].name().to_owned(), )); } } @@ -947,7 +944,7 @@ impl<'a, 'b, T: SortingPlugin> PathFinder<'a, 'b, T> { path_to_string(self.graph, &path) ); return Err(PathfindingError::FollowingNodeNotFound( - self.graph[current_node].name().to_string(), + self.graph[current_node].name().to_owned(), )); } } @@ -3109,7 +3106,7 @@ mod tests { let sorted_plugin_names: Vec<_> = sorted .into_iter() - .map(|i| graph[i].name().to_string()) + .map(|i| graph[i].name().to_owned()) .collect(); assert_eq!( @@ -3154,7 +3151,7 @@ mod tests { let sorted_plugin_names: Vec<_> = sorted .into_iter() - .map(|i| graph[i].name().to_string()) + .map(|i| graph[i].name().to_owned()) .collect(); assert_eq!( @@ -3199,7 +3196,7 @@ mod tests { let sorted_plugin_names: Vec<_> = sorted .into_iter() - .map(|i| graph[i].name().to_string()) + .map(|i| graph[i].name().to_owned()) .collect(); assert_eq!( diff --git a/src/sorting/validate.rs b/src/sorting/validate.rs index f8caa7d6..7494c1b9 100644 --- a/src/sorting/validate.rs +++ b/src/sorting/validate.rs @@ -93,7 +93,7 @@ fn validate_plugin( if non_masters.contains(&key) { return Err(CyclicInteractionError::new(vec![ Vertex::new(master).with_out_edge_type(EdgeType::Master), - Vertex::new(plugin.name().to_string()).with_out_edge_type(EdgeType::MasterFlag), + Vertex::new(plugin.name().to_owned()).with_out_edge_type(EdgeType::MasterFlag), ]) .into()); } @@ -164,14 +164,14 @@ fn validate_files( if non_masters.contains(&key) { return Err(CyclicInteractionError::new(vec![ Vertex::new(file.clone()).with_out_edge_type(edge_type), - Vertex::new(plugin_name.to_string()).with_out_edge_type(EdgeType::MasterFlag), + Vertex::new(plugin_name.to_owned()).with_out_edge_type(EdgeType::MasterFlag), ])); } if blueprint_masters.contains(&key) { return Err(CyclicInteractionError::new(vec![ Vertex::new(file.clone()).with_out_edge_type(edge_type), - Vertex::new(plugin_name.to_string()).with_out_edge_type(EdgeType::BlueprintMaster), + Vertex::new(plugin_name.to_owned()).with_out_edge_type(EdgeType::BlueprintMaster), ])); } } @@ -191,7 +191,7 @@ fn validate_early_loading_plugins( // 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(master.name().to_string()).with_out_edge_type(EdgeType::MasterFlag), + Vertex::new(master.name().to_owned()).with_out_edge_type(EdgeType::MasterFlag), ])); } } diff --git a/src/tests.rs b/src/tests.rs index e4246767..32e6ff44 100644 --- a/src/tests.rs +++ b/src/tests.rs @@ -284,7 +284,7 @@ impl Fixture { } else { std::fs::rename( data_path.join(BLANK_MASTER_DEPENDENT_ESM), - data_path.join(BLANK_MASTER_DEPENDENT_ESM.to_string() + ".ghost"), + data_path.join(BLANK_MASTER_DEPENDENT_ESM.to_owned() + ".ghost"), ) .unwrap(); } diff --git a/src/version.rs b/src/version.rs index 0bb260c9..a2a7f2b3 100644 --- a/src/version.rs +++ b/src/version.rs @@ -9,12 +9,12 @@ pub const LIBLOOT_VERSION_PATCH: u32 = parse_u32(env!("CARGO_PKG_VERSION_PATCH") /// Get the library version in the form "major.minor.patch". pub fn libloot_version() -> String { - env!("CARGO_PKG_VERSION").to_string() + env!("CARGO_PKG_VERSION").to_owned() } /// Get the ID of the source control revision that libloot was built from. pub fn libloot_revision() -> String { - libloot_revision_const().to_string() + libloot_revision_const().to_owned() } /// Checks whether the loaded API is compatible with the given version of the