From e223ab0a1d29c6d7d5c04984b7bdbf6f5a7d1ac7 Mon Sep 17 00:00:00 2001 From: Rex Magana Date: Sat, 4 May 2024 09:20:00 -0700 Subject: [PATCH 1/3] Remove unused StrRefExt trait --- crates/core/src/types/type.rs | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/crates/core/src/types/type.rs b/crates/core/src/types/type.rs index 05a7e19d..f036441a 100644 --- a/crates/core/src/types/type.rs +++ b/crates/core/src/types/type.rs @@ -209,18 +209,6 @@ impl_type! { Type::Boolean => [bool,], } -// The macro has problems with the following expansions - -trait StrRefExt { - fn r#type() -> Type; -} - -impl StrRefExt for &str { - fn r#type() -> Type { - Type::String - } -} - impl From<&str> for Type { fn from(_value: &str) -> Self { Type::String From 1505756b6e9ebeb4ced55fcaf300378219af5373 Mon Sep 17 00:00:00 2001 From: Rex Magana Date: Sat, 4 May 2024 09:39:55 -0700 Subject: [PATCH 2/3] redundant_clone --- .../compilation_steps/add_initial_value_registrations.rs | 4 +++- .../src/compilation_steps/clean_up_diagnostics.rs | 2 +- crates/compiler/src/listeners/compiler_listener.rs | 8 +++++--- .../src/visitors/string_table_generator_visitor.rs | 8 ++++++-- crates/compiler/src/visitors/type_check_visitor.rs | 2 +- crates/runtime/src/virtual_machine.rs | 2 +- crates/yarnspinner/tests/test_base/test_plan.rs | 2 +- 7 files changed, 18 insertions(+), 10 deletions(-) diff --git a/crates/compiler/src/compilation_steps/add_initial_value_registrations.rs b/crates/compiler/src/compilation_steps/add_initial_value_registrations.rs index 05e79ed0..5a1a16dd 100644 --- a/crates/compiler/src/compilation_steps/add_initial_value_registrations.rs +++ b/crates/compiler/src/compilation_steps/add_initial_value_registrations.rs @@ -39,6 +39,8 @@ pub(crate) fn add_initial_value_registrations( } } - compilation.declarations = state.derived_variable_declarations.clone(); + compilation + .declarations + .clone_from(&state.derived_variable_declarations); state } diff --git a/crates/compiler/src/compilation_steps/clean_up_diagnostics.rs b/crates/compiler/src/compilation_steps/clean_up_diagnostics.rs index fa087252..f3203c99 100644 --- a/crates/compiler/src/compilation_steps/clean_up_diagnostics.rs +++ b/crates/compiler/src/compilation_steps/clean_up_diagnostics.rs @@ -27,7 +27,7 @@ pub(crate) fn clean_up_diagnostics(mut state: CompilationIntermediate) -> Compil if state.diagnostics.has_errors() { state.result = Some(Err(CompilerError(state.diagnostics.clone()))); } else if let Some(Ok(compilation)) = state.result.as_mut() { - compilation.warnings = state.diagnostics.clone(); + compilation.warnings.clone_from(&state.diagnostics); } state } diff --git a/crates/compiler/src/listeners/compiler_listener.rs b/crates/compiler/src/listeners/compiler_listener.rs index 87d94efc..e0006aca 100644 --- a/crates/compiler/src/listeners/compiler_listener.rs +++ b/crates/compiler/src/listeners/compiler_listener.rs @@ -99,8 +99,10 @@ impl<'input> YarnSpinnerParserListener<'input> for CompilerListener<'input> { // Duplicate node name! We'll have caught this during the // declarations pass, so no need to issue an error here. } - self.current_debug_info.node_name = name.clone(); - self.current_debug_info.file_name = self.file.name.clone(); + self.current_debug_info.node_name.clone_from(name); + self.current_debug_info + .file_name + .clone_from(&self.file.name); self.debug_infos .borrow_mut() .push(self.current_debug_info.clone()); @@ -130,7 +132,7 @@ impl<'input> YarnSpinnerParserListener<'input> for CompilerListener<'input> { match header_key { "title" => { // Set the name of the node - current_node.name = header_value.clone(); + current_node.name.clone_from(&header_value); } "tags" => { // Split the list of tags by spaces, and use that diff --git a/crates/compiler/src/visitors/string_table_generator_visitor.rs b/crates/compiler/src/visitors/string_table_generator_visitor.rs index 36db2bd1..3d2e55e3 100644 --- a/crates/compiler/src/visitors/string_table_generator_visitor.rs +++ b/crates/compiler/src/visitors/string_table_generator_visitor.rs @@ -51,8 +51,12 @@ impl<'input> YarnSpinnerParserVisitorCompat<'input> for StringTableGeneratorVisi for header in ctx.header_all() { let header_key = header.header_key.as_ref().unwrap().get_text(); if header_key == "title" { - self.current_node_name = - header.header_value.as_ref().unwrap().get_text().to_owned(); + header + .header_value + .as_ref() + .unwrap() + .get_text() + .clone_into(&mut self.current_node_name) } else if header_key == "tags" { let header_value = header .header_value diff --git a/crates/compiler/src/visitors/type_check_visitor.rs b/crates/compiler/src/visitors/type_check_visitor.rs index ee1c97c1..341889d5 100644 --- a/crates/compiler/src/visitors/type_check_visitor.rs +++ b/crates/compiler/src/visitors/type_check_visitor.rs @@ -361,7 +361,7 @@ impl<'input> YarnSpinnerParserVisitorCompat<'input> for TypeCheckVisitor<'input> let Type::Function(function_type) = &mut declaration.r#type else { unreachable!(); }; - function_type.parameters[i] = supplied_type.clone(); + function_type.parameters[i].clone_from(&supplied_type); expected_type = &supplied_type; } if !supplied_type.is_sub_type_of(expected_type) { diff --git a/crates/runtime/src/virtual_machine.rs b/crates/runtime/src/virtual_machine.rs index 1d823c32..e847addb 100644 --- a/crates/runtime/src/virtual_machine.rs +++ b/crates/runtime/src/virtual_machine.rs @@ -82,7 +82,7 @@ impl VirtualMachine { pub(crate) fn set_language_code(&mut self, language_code: impl Into>) { let language_code = language_code.into(); - self.language_code = language_code.clone(); + self.language_code.clone_from(&language_code); self.line_parser.set_language_code(language_code.clone()); self.text_provider.set_language(language_code); } diff --git a/crates/yarnspinner/tests/test_base/test_plan.rs b/crates/yarnspinner/tests/test_base/test_plan.rs index 3ec3f4b2..15cce09a 100644 --- a/crates/yarnspinner/tests/test_base/test_plan.rs +++ b/crates/yarnspinner/tests/test_base/test_plan.rs @@ -66,7 +66,7 @@ impl TestPlan { }); } else { self.next_expected_step = current_step.expected_step_type; - self.next_step_value = current_step.value.clone(); + self.next_step_value.clone_from(¤t_step.value); return; } } From cabef3899432f6eebf1ca8507ae25f02c8397b4a Mon Sep 17 00:00:00 2001 From: Rex Magana Date: Sat, 4 May 2024 09:40:07 -0700 Subject: [PATCH 3/3] Unused code --- .../bevy_plugin/tests/test_asset_provider.rs | 20 ------------------- .../compiler/src/compiler/antlr_rust_ext.rs | 15 -------------- 2 files changed, 35 deletions(-) diff --git a/crates/bevy_plugin/tests/test_asset_provider.rs b/crates/bevy_plugin/tests/test_asset_provider.rs index 023baf68..3bd4f6b7 100644 --- a/crates/bevy_plugin/tests/test_asset_provider.rs +++ b/crates/bevy_plugin/tests/test_asset_provider.rs @@ -3,7 +3,6 @@ use anyhow::{bail, Result}; use bevy::prelude::*; use bevy::utils::Instant; use bevy_yarnspinner::prelude::*; -use bevy_yarnspinner::UnderlyingYarnLine; use utils::prelude::*; mod utils; @@ -198,22 +197,3 @@ fn does_not_load_asset_with_invalid_type() -> Result<()> { assert!(asset.is_none()); Ok(()) } - -trait AssetProviderExt { - fn get_assets_for_id(&self, id: &str) -> LineAssets; -} - -impl AssetProviderExt for T -where - T: AssetProvider + ?Sized, -{ - fn get_assets_for_id(&self, id: &str) -> LineAssets { - let line_id = LineId(id.to_owned()); - let yarn_line = UnderlyingYarnLine { - id: line_id, - text: String::new(), - attributes: vec![], - }; - T::get_assets(self, &yarn_line) - } -} diff --git a/crates/compiler/src/compiler/antlr_rust_ext.rs b/crates/compiler/src/compiler/antlr_rust_ext.rs index 08beae0a..d50abc73 100644 --- a/crates/compiler/src/compiler/antlr_rust_ext.rs +++ b/crates/compiler/src/compiler/antlr_rust_ext.rs @@ -1,15 +1,11 @@ //! Contains functionality provided in the C# implementation of ANTLR but not (yet?) in antlr4rust. -use crate::parser::generated::yarnspinnerparser::YarnSpinnerParserContextType; use crate::parser::ActualTokenStream; use crate::prelude::generated::yarnspinnerparser::YarnSpinnerParserContext; -use crate::prelude::ContextRefExt; use antlr_rust::int_stream::IntStream; -use antlr_rust::rule_context::RuleContext; use antlr_rust::token::{CommonToken, Token, TOKEN_DEFAULT_CHANNEL}; use antlr_rust::token_factory::{CommonTokenFactory, TokenFactory}; use antlr_rust::token_stream::TokenStream; -use antlr_rust::tree::ErrorNode; use antlr_rust::InputStream; use better_any::TidExt; use std::rc::Rc; @@ -209,17 +205,6 @@ pub(crate) trait YarnSpinnerParserContextExt<'input>: .filter_map(|child| child.downcast_rc::().ok()) .nth(pos) } - - /// Adapted from - fn add_error_node( - &self, - bad_token: CommonToken<'input>, - ) -> Rc> { - let error_node = Rc::new(ErrorNode::new(Box::new(bad_token))); - error_node.set_parent(&Some(self.ref_to_rc())); - self.add_child(error_node.clone()); - error_node - } } impl<'input, T: YarnSpinnerParserContext<'input> + ?Sized> YarnSpinnerParserContextExt<'input> for T