From 66be37d1a6e29fe03a5b49bf17a2de51a818d53d Mon Sep 17 00:00:00 2001 From: Tau <4602612+bash@users.noreply.github.com> Date: Mon, 25 Dec 2023 14:50:27 +0100 Subject: [PATCH 1/3] Make clippy happy --- .../src/localization/line_id_generation.rs | 3 ++- crates/bevy_plugin/src/project.rs | 4 ++-- .../compilation_steps/validate_unique_node_names.rs | 12 ++++++------ crates/compiler/src/compiler.rs | 2 +- crates/compiler/src/visitors/type_check_visitor.rs | 10 ++++------ crates/example_dialogue_view/src/option_selection.rs | 2 +- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/crates/bevy_plugin/src/localization/line_id_generation.rs b/crates/bevy_plugin/src/localization/line_id_generation.rs index 5e3ed2ed..442c4ea3 100644 --- a/crates/bevy_plugin/src/localization/line_id_generation.rs +++ b/crates/bevy_plugin/src/localization/line_id_generation.rs @@ -149,7 +149,8 @@ fn add_tags_to_lines(yarn_file: &YarnFile) -> YarnCompilerResult> let existing_tags = yarn_file .string_table .iter() - .filter_map(|(key, string_info)| (!string_info.is_implicit_tag).then(|| key.clone())) + .filter(|(_, string_info)| !string_info.is_implicit_tag) + .map(|(key, _)| key.clone()) .collect(); YarnCompiler::add_tags_to_lines(yarn_file.file.source.clone(), existing_tags) } diff --git a/crates/bevy_plugin/src/project.rs b/crates/bevy_plugin/src/project.rs index cfa1cb66..61bead21 100644 --- a/crates/bevy_plugin/src/project.rs +++ b/crates/bevy_plugin/src/project.rs @@ -95,9 +95,9 @@ impl YarnProject { .get(node_name)? .headers .iter() - .fold(HashMap::new(), |mut map, header| { + .fold(HashMap::new(), |mut map: HashMap<_, Vec<_>>, header| { map.entry(header.key.as_str()) - .or_insert_with(Vec::new) + .or_default() .push(header.value.as_str()); map }) diff --git a/crates/compiler/src/compilation_steps/validate_unique_node_names.rs b/crates/compiler/src/compilation_steps/validate_unique_node_names.rs index 7de0165d..b228822d 100644 --- a/crates/compiler/src/compilation_steps/validate_unique_node_names.rs +++ b/crates/compiler/src/compilation_steps/validate_unique_node_names.rs @@ -34,13 +34,13 @@ pub(crate) fn validate_unique_node_names( }) }); - let nodes_by_name = - nodes_with_names.fold(HashMap::new(), |mut map, (name, header_context, file)| { - map.entry(name) - .or_insert_with(Vec::new) - .push((header_context, file)); + let nodes_by_name = nodes_with_names.fold( + HashMap::new(), + |mut map: HashMap<_, Vec<_>>, (name, header_context, file)| { + map.entry(name).or_default().push((header_context, file)); map - }); + }, + ); // Find groups of nodes with the same name and generate diagnostics // for each diff --git a/crates/compiler/src/compiler.rs b/crates/compiler/src/compiler.rs index c4492256..efeaf16f 100644 --- a/crates/compiler/src/compiler.rs +++ b/crates/compiler/src/compiler.rs @@ -82,7 +82,7 @@ impl Compiler { /// Extends the Yarn function library with the given [`Library`]. The standard library is only added if this is called with [`Library::standard_library`]. pub fn extend_library(&mut self, library: Library) -> &mut Self { - self.library.extend(library.into_iter()); + self.library.extend(library); self } diff --git a/crates/compiler/src/visitors/type_check_visitor.rs b/crates/compiler/src/visitors/type_check_visitor.rs index 3b98504e..fb3532df 100644 --- a/crates/compiler/src/visitors/type_check_visitor.rs +++ b/crates/compiler/src/visitors/type_check_visitor.rs @@ -387,12 +387,10 @@ impl<'input> YarnSpinnerParserVisitorCompat<'input> for TypeCheckVisitor<'input> fn visit_variable(&mut self, ctx: &VariableContext<'input>) -> Self::Return { // The type of the value depends on the declared type of the // variable - let Some(var_id) = ctx.get_token(yarnspinnerlexer::VAR_ID, 0) else { - // We don't have a variable name for this Variable context. - // The parser will have generated an error for us in an - // earlier stage; here, we'll bail out. - return None - }; + // the parser will have generated an error for us in an + // earlier stage if we don't have a variable name for + // this Variable context; here, we'll bail out. + let var_id = ctx.get_token(yarnspinnerlexer::VAR_ID, 0)?; let name = var_id.get_text(); if let Some(declaration) = self.declarations().find(|decl| decl.name == name) { return Some(declaration.r#type.clone()); diff --git a/crates/example_dialogue_view/src/option_selection.rs b/crates/example_dialogue_view/src/option_selection.rs index fc79e174..76193dfd 100644 --- a/crates/example_dialogue_view/src/option_selection.rs +++ b/crates/example_dialogue_view/src/option_selection.rs @@ -88,7 +88,7 @@ fn select_option( let mut selection = None; let key_to_option: HashMap<_, _> = NUMBER_KEYS .into_iter() - .zip(NUMPAD_KEYS.into_iter()) + .zip(NUMPAD_KEYS) .zip(option_selection.options.iter().map(|option| option.id)) .collect(); for ((num_key, numpad_key), option) in key_to_option { From 0e01769ceeb4d1f3f13bfe519a1a4da65b0ea7a2 Mon Sep 17 00:00:00 2001 From: Tau <4602612+bash@users.noreply.github.com> Date: Mon, 25 Dec 2023 14:50:38 +0100 Subject: [PATCH 2/3] Run `rustfmt` --- .../src/dialogue_runner/runtime_interaction.rs | 5 +---- .../src/localization/line_id_generation.rs | 8 +++++--- crates/bevy_plugin/src/project/compilation.rs | 16 ++++++++++++++-- .../add_initial_value_registrations.rs | 16 +++++++++------- .../last_line_before_options_visitor.rs | 2 +- .../src/visitors/type_check_visitor.rs | 2 +- .../type_check_visitor/check_operation.rs | 16 ++++++++++++---- crates/runtime/src/markup/line_parser.rs | 16 +++++++++------- crates/runtime/src/virtual_machine.rs | 4 +--- crates/yarn_slinger/tests/test_base/mod.rs | 18 +++++++++--------- demo/src/visual_effects.rs | 2 +- 11 files changed, 63 insertions(+), 42 deletions(-) diff --git a/crates/bevy_plugin/src/dialogue_runner/runtime_interaction.rs b/crates/bevy_plugin/src/dialogue_runner/runtime_interaction.rs index 5ca207ac..a6f219c0 100644 --- a/crates/bevy_plugin/src/dialogue_runner/runtime_interaction.rs +++ b/crates/bevy_plugin/src/dialogue_runner/runtime_interaction.rs @@ -73,10 +73,7 @@ fn continue_runtime( let Some(option) = options.into_iter().find(|o| o.id == option) else { let expected_options = last_options .values() - .flat_map(|options| - options - .iter() - .map(|option| option.id.to_string())) + .flat_map(|options| options.iter().map(|option| option.id.to_string())) .collect::>() .join(", "); bail!("Dialogue options does not contain selected option. Expected one of [{expected_options}], but found {option}"); diff --git a/crates/bevy_plugin/src/localization/line_id_generation.rs b/crates/bevy_plugin/src/localization/line_id_generation.rs index 442c4ea3..043f4733 100644 --- a/crates/bevy_plugin/src/localization/line_id_generation.rs +++ b/crates/bevy_plugin/src/localization/line_id_generation.rs @@ -35,8 +35,8 @@ fn handle_yarn_file_events_outside_development( ) { for event in events.iter() { let AssetEvent::Modified { handle } = event else { - continue; - }; + continue; + }; if !(yarn_files_being_loaded.0.contains(handle) || project.yarn_files.contains(handle)) { continue; } @@ -90,7 +90,9 @@ fn handle_yarn_file_events( } last_recompiled_yarn_file.replace(yarn_file.clone()); for mut dialogue_runner in dialogue_runners.iter_mut() { - dialogue_runner.text_provider.extend_base_string_table(yarn_file.string_table.clone()); + dialogue_runner + .text_provider + .extend_base_string_table(yarn_file.string_table.clone()); } added_tags.remove(handle); recompilation_needed = true; diff --git a/crates/bevy_plugin/src/project/compilation.rs b/crates/bevy_plugin/src/project/compilation.rs index c5b6aedc..1b51aa75 100644 --- a/crates/bevy_plugin/src/project/compilation.rs +++ b/crates/bevy_plugin/src/project/compilation.rs @@ -109,7 +109,13 @@ fn recompile_loaded_yarn_files( let Some(mut yarn_project) = yarn_project else { return Ok(()); }; - let Some(compilation) = compile_yarn_files(&yarn_project.yarn_files, &yarn_files, yarn_project.localizations.as_ref(), yarn_project.development_file_generation)? else { + let Some(compilation) = compile_yarn_files( + &yarn_project.yarn_files, + &yarn_files, + yarn_project.localizations.as_ref(), + yarn_project.development_file_generation, + )? + else { return Ok(()); }; let metadata = compilation @@ -175,7 +181,13 @@ fn compile_loaded_yarn_files( .unwrap() .as_ref(); let development_file_generation = yarn_project_config_to_load.development_file_generation; - let Some(compilation) = compile_yarn_files(&yarn_files_being_loaded.0, &yarn_files, localizations, development_file_generation)? else { + let Some(compilation) = compile_yarn_files( + &yarn_files_being_loaded.0, + &yarn_files, + localizations, + development_file_generation, + )? + else { return Ok(()); }; let file_count = yarn_files_being_loaded.0.len(); 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 a0227f1f..5c5b5414 100644 --- a/crates/compiler/src/compilation_steps/add_initial_value_registrations.rs +++ b/crates/compiler/src/compilation_steps/add_initial_value_registrations.rs @@ -9,8 +9,8 @@ pub(crate) fn add_initial_value_registrations( // of the inputs, and create an initial value registration for // it. let Ok(compilation) = state.result.as_mut().unwrap().as_mut() else { - return state; - }; + return state; + }; let declarations = state .known_variable_declarations @@ -19,11 +19,13 @@ pub(crate) fn add_initial_value_registrations( for declaration in declarations { let Some(default_value) = declaration.default_value.clone() else { - state.diagnostics.push( - Diagnostic::from_message( - format!("Variable declaration {} (type {}) has a null default value. This is not allowed.", declaration.name, declaration.r#type.format()))); - continue; - }; + state.diagnostics.push(Diagnostic::from_message(format!( + "Variable declaration {} (type {}) has a null default value. This is not allowed.", + declaration.name, + declaration.r#type.format() + ))); + continue; + }; if let Some(ref mut program) = compilation.program { let value = match &declaration.r#type { Type::String => Operand::from(String::try_from(default_value).unwrap()), diff --git a/crates/compiler/src/visitors/last_line_before_options_visitor.rs b/crates/compiler/src/visitors/last_line_before_options_visitor.rs index 94990a47..88453400 100644 --- a/crates/compiler/src/visitors/last_line_before_options_visitor.rs +++ b/crates/compiler/src/visitors/last_line_before_options_visitor.rs @@ -82,7 +82,7 @@ impl LastLineBeforeOptionsVisitor { } let Some(shortcut_option_statement) = statement.shortcut_option_statement() else { - // we aren't an option, keep moving + // we aren't an option, keep moving continue; }; // we need to visit the option in case it has embedded statements diff --git a/crates/compiler/src/visitors/type_check_visitor.rs b/crates/compiler/src/visitors/type_check_visitor.rs index fb3532df..d0acb5f1 100644 --- a/crates/compiler/src/visitors/type_check_visitor.rs +++ b/crates/compiler/src/visitors/type_check_visitor.rs @@ -273,7 +273,7 @@ impl<'input> YarnSpinnerParserVisitorCompat<'input> for TypeCheckVisitor<'input> let hint = self.hints.get(ctx).cloned(); let function_type = if let Some(function_declaration) = function_declaration { let Type::Function(mut function_type) = function_declaration.r#type.clone() else { - unreachable!("Internal error: function declaration is not of type Function. This is a bug. Please report it at https://github.com/yarn-slinger/yarn_slinger/issues/new") + unreachable!("Internal error: function declaration is not of type Function. This is a bug. Please report it at https://github.com/yarn-slinger/yarn_slinger/issues/new") }; // we have an existing function but its undefined diff --git a/crates/compiler/src/visitors/type_check_visitor/check_operation.rs b/crates/compiler/src/visitors/type_check_visitor/check_operation.rs index 6b647d98..d41bcdce 100644 --- a/crates/compiler/src/visitors/type_check_visitor/check_operation.rs +++ b/crates/compiler/src/visitors/type_check_visitor/check_operation.rs @@ -122,10 +122,18 @@ impl<'input> TypeCheckVisitor<'input> { // annoyingly the function will already have an implicit definition created for it // we will have to strip that out and add in a new one with the new return type for term in terms { - let Term::Expression(expression) = term else { continue; }; - let ExpressionContextAll::ExpValueContext(value_context) = expression.as_ref() else { continue; }; - let Some(value) = value_context.value() else { continue; }; - let ValueContextAll::ValueFuncContext(func_context) = value.as_ref() else { continue; }; + let Term::Expression(expression) = term else { + continue; + }; + let ExpressionContextAll::ExpValueContext(value_context) = expression.as_ref() else { + continue; + }; + let Some(value) = value_context.value() else { + continue; + }; + let ValueContextAll::ValueFuncContext(func_context) = value.as_ref() else { + continue; + }; let id = func_context .function_call() diff --git a/crates/runtime/src/markup/line_parser.rs b/crates/runtime/src/markup/line_parser.rs index fa41ec89..0ea23bae 100644 --- a/crates/runtime/src/markup/line_parser.rs +++ b/crates/runtime/src/markup/line_parser.rs @@ -148,12 +148,14 @@ impl LineParser { } if let Some(prop) = marker.properties.get(TRIM_WHITESPACE_PROPERTY) { let MarkupValue::Bool(trim_whitespace) = prop else { - return Err(MarkupParseError::TrimWhitespaceAttributeIsNotBoolean { - input: self.input.clone(), - name: marker.name, - position: self.position, - type_: prop.type_name().to_lowercase(), - }); + return Err( + MarkupParseError::TrimWhitespaceAttributeIsNotBoolean { + input: self.input.clone(), + name: marker.name, + position: self.position, + type_: prop.type_name().to_lowercase(), + }, + ); }; trim_whitespace_if_able = *trim_whitespace; } @@ -637,7 +639,7 @@ impl LineParser { fn peek_numeric(&mut self) -> Result { self.consume_whitespace()?; let Some(next) = self.peek_next() else { - return Ok(false) + return Ok(false); }; Ok(next.is_ascii_digit()) } diff --git a/crates/runtime/src/virtual_machine.rs b/crates/runtime/src/virtual_machine.rs index 77049b88..44ddf464 100644 --- a/crates/runtime/src/virtual_machine.rs +++ b/crates/runtime/src/virtual_machine.rs @@ -112,9 +112,7 @@ impl VirtualMachine { let node_name = node_name.into(); debug!("Loading node \"{node_name}\""); let Some(current_node) = self.get_node_from_name(&node_name) else { - return Err(DialogueError::InvalidNode{ - node_name - }); + return Err(DialogueError::InvalidNode { node_name }); }; self.current_node = Some(current_node.clone()); diff --git a/crates/yarn_slinger/tests/test_base/mod.rs b/crates/yarn_slinger/tests/test_base/mod.rs index 4d6e64b3..1381d8fe 100644 --- a/crates/yarn_slinger/tests/test_base/mod.rs +++ b/crates/yarn_slinger/tests/test_base/mod.rs @@ -151,9 +151,9 @@ impl TestBase { match event { DialogueEvent::Line(line) => { println!("Line: {}", line.text); - let Some(test_plan) = self.test_plan.as_mut() else { - continue; - }; + let Some(test_plan) = self.test_plan.as_mut() else { + continue; + }; test_plan.next(); assert_eq!( @@ -182,8 +182,8 @@ impl TestBase { println!(" - {} (available: {})", option.line, option.enabled); } let Some(test_plan) = self.test_plan.as_mut() else { - continue; - }; + continue; + }; test_plan.next(); assert_eq!( @@ -210,8 +210,8 @@ impl TestBase { DialogueEvent::Command(command) => { println!("Command: {}", command.raw); let Some(test_plan) = self.test_plan.as_mut() else { - continue; - }; + continue; + }; test_plan.next(); assert_eq!( ExpectedStepType::Command, @@ -236,8 +236,8 @@ impl TestBase { DialogueEvent::LineHints(_) => {} DialogueEvent::DialogueComplete => { let Some(test_plan) = self.test_plan.as_mut() else { - continue; - }; + continue; + }; test_plan.next(); assert_eq!( ExpectedStepType::Stop, diff --git a/demo/src/visual_effects.rs b/demo/src/visual_effects.rs index 6853429b..962a7f3d 100644 --- a/demo/src/visual_effects.rs +++ b/demo/src/visual_effects.rs @@ -40,7 +40,7 @@ pub(crate) fn rotate_sprite( mut materials: ResMut>, ) { for (mut transform, material, mut rotator) in rotators.iter_mut() { - let RotationPhase::ChangingSprite{change, sprite}= rotator.deref_mut() else { + let RotationPhase::ChangingSprite { change, sprite } = rotator.deref_mut() else { continue; }; let output = change.elastic(1.3); From 496b08eafbc112be12e8ed7ba83cda37d3d0619a Mon Sep 17 00:00:00 2001 From: Tau <4602612+bash@users.noreply.github.com> Date: Mon, 25 Dec 2023 15:02:49 +0100 Subject: [PATCH 3/3] Remove needless borrow --- crates/bevy_plugin/tests/test_strings_tables.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/bevy_plugin/tests/test_strings_tables.rs b/crates/bevy_plugin/tests/test_strings_tables.rs index ce00f6b8..6dd9814e 100644 --- a/crates/bevy_plugin/tests/test_strings_tables.rs +++ b/crates/bevy_plugin/tests/test_strings_tables.rs @@ -148,7 +148,7 @@ fn appends_to_pre_existing_strings_file() -> anyhow::Result<()> { let original_strings_path = project_root_path().join("assets/dialogue/de-CH.strings.csv"); let strings_file_path = dir.path().join("dialogue/de-CH.strings.csv"); fs::create_dir_all(strings_file_path.parent().unwrap())?; - fs::copy(&original_strings_path, &strings_file_path)?; + fs::copy(original_strings_path, &strings_file_path)?; let original_strings_file_source = fs::read_to_string(&strings_file_path)?; let original_strings_file_line_ids: Vec<_> = original_strings_file_source .lines()