Deny the clippy::str_to_string lint

This commit is contained in:
Oliver Hamlet
2025-04-23 00:16:09 +01:00
parent e0a7d7c79f
commit 2aaa13bd7e
18 changed files with 72 additions and 76 deletions
+1 -1
View File
@@ -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()),
+1 -1
View File
@@ -333,7 +333,7 @@ fn merge_groups(lhs: &[Group], rhs: &[Group]) -> Vec<Group> {
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() {
+4 -4
View File
@@ -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<Plugin>) {
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<Plugin>> {
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<Item = &PathBuf> {
@@ -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());
}
+1 -1
View File
@@ -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,
+5 -5
View File
@@ -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()));
}
}
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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()),
));
}
}
+10 -10
View File
@@ -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<Option<PluginMetadata>, 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 ") {
+17 -17
View File
@@ -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)),
+1 -1
View File
@@ -185,7 +185,7 @@ pub fn parse_condition(
) -> Result<Option<Box<str>>, 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));
}
+4 -4
View File
@@ -358,8 +358,8 @@ pub(crate) fn plugins_metadata(
fn name_string(game_type: GameType, path: &Path) -> Result<String, LoadPluginError> {
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<String> {
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(),
+2 -2
View File
@@ -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()
}
+4 -4
View File
@@ -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<NodeIndex, Undefine
graph
.node_indices()
.find(|n| graph[*n].as_ref() == Group::DEFAULT_NAME)
.ok_or_else(|| UndefinedGroupError::new(Group::DEFAULT_NAME.to_string()))
.ok_or_else(|| UndefinedGroupError::new(Group::DEFAULT_NAME.to_owned()))
}
#[cfg(test)]
+4 -5
View File
@@ -25,22 +25,21 @@ mod test {
impl TestPlugin {
pub fn new(name: &str) -> 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());
}
}
+9 -12
View File
@@ -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<Rc<PluginSortingData<'a, T>>, 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<Vec<NodeIndex>, 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<T: SortingPlugin>(
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!(
+4 -4
View File
@@ -93,7 +93,7 @@ fn validate_plugin<T: SortingPlugin>(
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<T: SortingPlugin>(
// 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),
]));
}
}
+1 -1
View File
@@ -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();
}
+2 -2
View File
@@ -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