From ac26a442d0eb3fdd1f6efaac6fd14a5086bb564c Mon Sep 17 00:00:00 2001 From: Jan Haller Date: Fri, 10 Jan 2025 22:48:13 +0100 Subject: [PATCH] Clippy: replace `map_or(false|true, ...)` -> `is_some_and(...)` or comparison --- .../src/special_cases/codegen_special_cases.rs | 14 ++++++++------ godot-ffi/src/toolbox.rs | 2 +- godot-macros/src/util/mod.rs | 6 +++--- itest/rust/src/framework/runner.rs | 4 +--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/godot-codegen/src/special_cases/codegen_special_cases.rs b/godot-codegen/src/special_cases/codegen_special_cases.rs index b37425ca3..7e0eadfa5 100644 --- a/godot-codegen/src/special_cases/codegen_special_cases.rs +++ b/godot-codegen/src/special_cases/codegen_special_cases.rs @@ -74,14 +74,16 @@ pub(crate) fn is_class_method_excluded(method: &JsonClassMethod, ctx: &mut Conte }; // Exclude if return type contains an excluded type. - if method.return_value.as_ref().map_or(false, |ret| { - is_arg_or_return_excluded(ret.type_.as_str(), ctx) - }) { + if method + .return_value + .as_ref() + .is_some_and(|ret| is_arg_or_return_excluded(ret.type_.as_str(), ctx)) + { return true; } // Exclude if any argument contains an excluded type. - if method.arguments.as_ref().map_or(false, |args| { + if method.arguments.as_ref().is_some_and(|args| { args.iter() .any(|arg| is_arg_or_return_excluded(arg.type_.as_str(), ctx)) }) { @@ -107,8 +109,8 @@ pub(crate) fn is_utility_function_excluded( function .return_type .as_ref() - .map_or(false, |ret| is_type_excluded(ret.as_str(), ctx)) - || function.arguments.as_ref().map_or(false, |args| { + .is_some_and(|ret| is_type_excluded(ret.as_str(), ctx)) + || function.arguments.as_ref().is_some_and(|args| { args.iter() .any(|arg| is_type_excluded(arg.type_.as_str(), ctx)) }) diff --git a/godot-ffi/src/toolbox.rs b/godot-ffi/src/toolbox.rs index 1d1f82164..1393d8fa0 100644 --- a/godot-ffi/src/toolbox.rs +++ b/godot-ffi/src/toolbox.rs @@ -227,7 +227,7 @@ fn strip_module_paths(full_name: &str) -> String { result.push(c); // Handle spaces after commas for readability. - if c == ',' && chars.peek().map_or(false, |&next_c| next_c != ' ') { + if c == ',' && chars.peek().is_some_and(|&next_c| next_c != ' ') { result.push(' '); } } diff --git a/godot-macros/src/util/mod.rs b/godot-macros/src/util/mod.rs index 133936c70..702fd85f1 100644 --- a/godot-macros/src/util/mod.rs +++ b/godot-macros/src/util/mod.rs @@ -141,7 +141,7 @@ fn delimiter_opening_char(delimiter: Delimiter) -> char { /// declaration of the form `impl MyTrait for SomeType`. The type `SomeType` is irrelevant in this example. pub(crate) fn is_impl_named(original_impl: &venial::Impl, name: &str) -> bool { let trait_name = original_impl.trait_ty.as_ref().unwrap(); // unwrap: already checked outside - extract_typename(trait_name).map_or(false, |seg| seg.ident == name) + extract_typename(trait_name).is_some_and(|seg| seg.ident == name) } /// Validates either: @@ -238,7 +238,7 @@ pub(crate) fn path_ends_with_complex(path: &venial::TypeExpr, expected: &str) -> .map(|path| { path.segments .last() - .map_or(false, |seg| seg.ident == expected) + .is_some_and(|seg| seg.ident == expected) }) .unwrap_or(false) } @@ -248,7 +248,7 @@ pub(crate) fn extract_cfg_attrs( ) -> impl IntoIterator { attrs.iter().filter(|attr| { attr.get_single_path_segment() - .map_or(false, |name| name == "cfg") + .is_some_and(|name| name == "cfg") }) } diff --git a/itest/rust/src/framework/runner.rs b/itest/rust/src/framework/runner.rs index d550b5d3c..299809614 100644 --- a/itest/rust/src/framework/runner.rs +++ b/itest/rust/src/framework/runner.rs @@ -333,9 +333,7 @@ fn print_test_pre(test_case: &str, test_file: String, last_file: &mut Option) { // Check if we need to open a new category for a file. - let print_file = last_file - .as_ref() - .map_or(true, |last_file| last_file != &file); + let print_file = last_file.as_ref() != Some(&file); if print_file { println!("\n {}:", extract_file_subtitle(&file));