From 9af5b1c78e56e00e48800d919ca3ea329a1e3b13 Mon Sep 17 00:00:00 2001 From: Mathieu Lala Date: Fri, 30 Dec 2022 18:07:39 +0100 Subject: [PATCH 1/6] fix: default clippy lints --- codegen/src/test/function.rs | 2 +- codegen/src/test/module.rs | 8 ++----- codegen/tests/test_functions.rs | 17 +++++++------- codegen/tests/test_modules.rs | 26 +++++++++++---------- codegen/tests/test_nested.rs | 10 ++++---- examples/event_handler_js/main.rs | 2 +- examples/event_handler_main/main.rs | 2 +- examples/event_handler_map/main.rs | 2 +- src/api/eval.rs | 20 ++++++++-------- src/api/files.rs | 2 +- src/api/run.rs | 20 ++++++++-------- src/ast/expr.rs | 2 ++ src/eval/data_check.rs | 4 ++-- src/func/script.rs | 13 +++-------- src/lib.rs | 6 ++--- src/packages/string_basic.rs | 6 ++--- src/packages/string_more.rs | 6 ++--- src/types/fn_ptr.rs | 1 + tests/arrays.rs | 30 +++++++++++------------- tests/blobs.rs | 6 ++--- tests/bool_op.rs | 36 ++++++++++++++--------------- tests/call_fn.rs | 2 +- tests/comments.rs | 2 +- tests/compound_equality.rs | 10 ++++---- tests/custom_syntax.rs | 9 ++++---- tests/expressions.rs | 7 +++--- tests/float.rs | 8 ++++--- tests/functions.rs | 1 + tests/get_set.rs | 16 +++++++------ tests/maps.rs | 10 ++++---- tests/method_call.rs | 2 +- tests/mismatched_op.rs | 1 + tests/modules.rs | 22 ++++++++++-------- tests/native.rs | 4 ++-- tests/not.rs | 11 ++++----- tests/options.rs | 2 +- tests/serde.rs | 14 +++++++---- tests/side_effects.rs | 1 + tests/switch.rs | 29 +++++++++++------------ tests/types.rs | 1 + tests/unit.rs | 6 +++-- tests/var_scope.rs | 2 ++ 42 files changed, 191 insertions(+), 190 deletions(-) diff --git a/codegen/src/test/function.rs b/codegen/src/test/function.rs index 0af46110..9db588e2 100644 --- a/codegen/src/test/function.rs +++ b/codegen/src/test/function.rs @@ -235,7 +235,7 @@ mod generate_tests { fn assert_streams_eq(actual: TokenStream, expected: TokenStream) { let actual = actual.to_string(); let expected = expected.to_string(); - if &actual != &expected { + if actual != expected { let mut counter = 0; let _iter = actual.chars().zip(expected.chars()).skip_while(|(a, e)| { if *a == *e { diff --git a/codegen/src/test/module.rs b/codegen/src/test/module.rs index 0f0bc9dd..4ae05dfa 100644 --- a/codegen/src/test/module.rs +++ b/codegen/src/test/module.rs @@ -86,11 +86,7 @@ mod module_tests { assert_eq!(item_mod.fns().len(), 1); assert_eq!(item_mod.fns()[0].name().to_string(), "get_mystic_number"); assert_eq!( - item_mod.fns()[0] - .comments() - .iter() - .cloned() - .collect::>(), + item_mod.fns()[0].comments().to_vec(), vec![ "\ /// This is a doc-comment.\n\ @@ -286,7 +282,7 @@ mod generate_tests { fn assert_streams_eq(actual: TokenStream, expected: TokenStream) { let actual = actual.to_string(); let expected = expected.to_string(); - if &actual != &expected { + if actual != expected { let mut counter = 0; let _iter = actual.chars().zip(expected.chars()).skip_while(|(a, e)| { if *a == *e { diff --git a/codegen/tests/test_functions.rs b/codegen/tests/test_functions.rs index cc665678..8734f45b 100644 --- a/codegen/tests/test_functions.rs +++ b/codegen/tests/test_functions.rs @@ -75,10 +75,9 @@ fn raw_fn_str_test() -> Result<(), Box> { rhai::set_exported_fn!(m, "write_out_str", raw_fn_str::write_out_str); engine.register_static_module("Host::IO", m.into()); - assert_eq!( - engine.eval::(r#"let x = Host::IO::write_out_str("hello world!"); x"#)?, - true - ); + assert!(engine + .eval::(r#"let x = Host::IO::write_out_str("hello world!"); x"#) + .unwrap()); Ok(()) } @@ -86,6 +85,7 @@ mod mut_opaque_ref { use rhai::plugin::*; use rhai::INT; + #[allow(dead_code)] // used inside `export_module!` #[derive(Clone)] pub struct StatusMessage { os_code: Option, @@ -127,17 +127,16 @@ fn mut_opaque_ref_test() -> Result<(), Box> { rhai::set_exported_fn!(m, "write_out_message", mut_opaque_ref::write_out_message); engine.register_static_module("Host::Msg", m.into()); - assert_eq!( - engine.eval::( + assert!(engine + .eval::( r#" let message1 = Host::Msg::new_message(true, "it worked"); let ok1 = Host::Msg::write_out_message(message1); let message2 = Host::Msg::new_os_message(true, 0); let ok2 = Host::Msg::write_out_message(message2); ok1 && ok2"# - )?, - true - ); + ) + .unwrap()); Ok(()) } diff --git a/codegen/tests/test_modules.rs b/codegen/tests/test_modules.rs index 95f8d15f..7524e2b0 100644 --- a/codegen/tests/test_modules.rs +++ b/codegen/tests/test_modules.rs @@ -3,6 +3,7 @@ use rhai::{Array, Engine, EvalAltResult, FLOAT, INT}; pub mod empty_module { use rhai::plugin::*; + #[allow(non_snake_case)] #[export_module] pub mod EmptyModule {} } @@ -93,10 +94,9 @@ fn raw_fn_str_module_test() -> Result<(), Box> { let m = rhai::exported_module!(crate::raw_fn_str_module::host_io); engine.register_static_module("Host::IO", m.into()); - assert_eq!( - engine.eval::(r#"let x = Host::IO::write_out_str("hello world!"); x"#)?, - true - ); + assert!(engine + .eval::(r#"let x = Host::IO::write_out_str("hello world!"); x"#) + .unwrap()); Ok(()) } @@ -104,6 +104,7 @@ pub mod mut_opaque_ref_module { use rhai::plugin::*; use rhai::INT; + #[allow(dead_code)] // used inside `exported_module!` #[derive(Clone)] pub struct StatusMessage { os_code: Option, @@ -144,8 +145,8 @@ fn mut_opaque_ref_test() -> Result<(), Box> { let m = rhai::exported_module!(crate::mut_opaque_ref_module::host_msg); engine.register_static_module("Host::Msg", m.into()); - assert_eq!( - engine.eval::( + assert!(engine + .eval::( r#" let success = "it worked"; let message1 = Host::Msg::new_message(true, success); @@ -154,9 +155,8 @@ fn mut_opaque_ref_test() -> Result<(), Box> { let ok2 = Host::Msg::write_out_message(message2); ok1 && ok2 "# - )?, - true - ); + ) + .unwrap()); Ok(()) } @@ -267,6 +267,7 @@ fn multiple_fn_rename_test() -> Result<(), Box> { Ok(()) } +#[allow(dead_code)] // used inside `export_module!` mod export_by_prefix { use rhai::plugin::*; @@ -331,7 +332,7 @@ fn export_by_prefix_test() -> Result<(), Box> { let fx = Math::Advanced::foo_add_float2(ex, 1.0); fx ").unwrap_err(), - EvalAltResult::ErrorFunctionNotFound(s, p) + EvalAltResult::ErrorFunctionNotFound(s, ..) if s == "Math::Advanced::foo_add_float2 (f64, f64)")); assert!(matches!(*engine.eval::( @@ -340,12 +341,13 @@ fn export_by_prefix_test() -> Result<(), Box> { let fx = Math::Advanced::bar_m(ex, 1.0); fx ").unwrap_err(), - EvalAltResult::ErrorFunctionNotFound(s, p) + EvalAltResult::ErrorFunctionNotFound(s, ..) if s == "Math::Advanced::bar_m (f64, f64)")); Ok(()) } +#[allow(dead_code)] // used inside `export_module!` mod export_all { use rhai::plugin::*; @@ -411,7 +413,7 @@ fn export_all_test() -> Result<(), Box> { let fx = Math::Advanced::foo_p(ex, 1); fx ").unwrap_err(), - EvalAltResult::ErrorFunctionNotFound(s, p) + EvalAltResult::ErrorFunctionNotFound(s, ..) if s == "Math::Advanced::foo_p (i64, i64)")); Ok(()) diff --git a/codegen/tests/test_nested.rs b/codegen/tests/test_nested.rs index 9a7ff676..c5323685 100644 --- a/codegen/tests/test_nested.rs +++ b/codegen/tests/test_nested.rs @@ -92,6 +92,7 @@ mod export_nested_by_prefix { } } + #[allow(dead_code)] // used inside a `exported_module!` #[rhai_mod(name = "foo_third_adders")] pub mod baz_third_adders { use rhai::{FLOAT, INT}; @@ -105,6 +106,7 @@ mod export_nested_by_prefix { } } + #[allow(dead_code)] // used inside a `exported_module!` pub mod bar_fourth_adders { use rhai::{FLOAT, INT}; @@ -153,7 +155,7 @@ fn export_nested_by_prefix_test() -> Result<(), Box> { let fx = Math::Advanced::foo_third_adders::add_float(ex, 1.0); fx ").unwrap_err(), - EvalAltResult::ErrorFunctionNotFound(s, p) + EvalAltResult::ErrorFunctionNotFound(s, ..) if s == "Math::Advanced::foo_third_adders::add_float (f64, f64)")); assert!(matches!(*engine.eval::( @@ -162,7 +164,7 @@ fn export_nested_by_prefix_test() -> Result<(), Box> { let fx = Math::Advanced::foo_third_adders::add_int(ex, 1); fx ").unwrap_err(), - EvalAltResult::ErrorFunctionNotFound(s, p) + EvalAltResult::ErrorFunctionNotFound(s, ..) if s == "Math::Advanced::foo_third_adders::add_int (i64, i64)")); assert!(matches!(*engine.eval::( @@ -171,7 +173,7 @@ fn export_nested_by_prefix_test() -> Result<(), Box> { let fx = Math::Advanced::bar_fourth_adders::add_int(ex, 1); fx ").unwrap_err(), - EvalAltResult::ErrorFunctionNotFound(s, p) + EvalAltResult::ErrorFunctionNotFound(s, ..) if s == "Math::Advanced::bar_fourth_adders::add_int (i64, i64)")); assert!(matches!(*engine.eval::( @@ -180,7 +182,7 @@ fn export_nested_by_prefix_test() -> Result<(), Box> { let fx = Math::Advanced::bar_fourth_adders::add_float(ex, 1.0); fx ").unwrap_err(), - EvalAltResult::ErrorFunctionNotFound(s, p) + EvalAltResult::ErrorFunctionNotFound(s, ..) if s == "Math::Advanced::bar_fourth_adders::add_float (f64, f64)")); Ok(()) diff --git a/examples/event_handler_js/main.rs b/examples/event_handler_js/main.rs index e6998d7a..efed0107 100644 --- a/examples/event_handler_js/main.rs +++ b/examples/event_handler_js/main.rs @@ -80,7 +80,7 @@ pub fn main() { // Compile the handler script. println!("> Loading script file: {path}"); - let ast = match engine.compile_file_with_scope(&mut scope, path.into()) { + let ast = match engine.compile_file_with_scope(&scope, path.into()) { Ok(ast) => ast, Err(err) => { eprintln!("! Error: {err}"); diff --git a/examples/event_handler_main/main.rs b/examples/event_handler_main/main.rs index 8fbfdafd..43cfdb0e 100644 --- a/examples/event_handler_main/main.rs +++ b/examples/event_handler_main/main.rs @@ -69,7 +69,7 @@ pub fn main() { // Compile the handler script. println!("> Loading script file: {path}"); - let ast = match engine.compile_file_with_scope(&mut scope, path.into()) { + let ast = match engine.compile_file_with_scope(&scope, path.into()) { Ok(ast) => ast, Err(err) => { eprintln!("! Error: {}", err); diff --git a/examples/event_handler_map/main.rs b/examples/event_handler_map/main.rs index b92dba94..9bef50b5 100644 --- a/examples/event_handler_map/main.rs +++ b/examples/event_handler_map/main.rs @@ -83,7 +83,7 @@ pub fn main() { // Compile the handler script. println!("> Loading script file: {path}"); - let ast = match engine.compile_file_with_scope(&mut scope, path.into()) { + let ast = match engine.compile_file_with_scope(&scope, path.into()) { Ok(ast) => ast, Err(err) => { eprintln!("! Error: {err}"); diff --git a/src/api/eval.rs b/src/api/eval.rs index d08915c4..6e61382a 100644 --- a/src/api/eval.rs +++ b/src/api/eval.rs @@ -245,16 +245,16 @@ impl Engine { g.source = orig_source; }); - self.eval_global_statements(global, caches, scope, ast.statements()) - .and_then(|r| { - #[cfg(feature = "debugging")] - if self.is_debugger_registered() { - global.debugger_mut().status = crate::eval::DebuggerStatus::Terminate; - let node = &crate::ast::Stmt::Noop(Position::NONE); - self.run_debugger(global, caches, scope, None, node)?; - } - Ok(r) - }) + let r = self.eval_global_statements(global, caches, scope, ast.statements())?; + + #[cfg(feature = "debugging")] + if self.is_debugger_registered() { + global.debugger_mut().status = crate::eval::DebuggerStatus::Terminate; + let node = &crate::ast::Stmt::Noop(Position::NONE); + self.run_debugger(global, caches, scope, None, node)?; + } + + Ok(r) } } diff --git a/src/api/files.rs b/src/api/files.rs index 2025b412..3322eedb 100644 --- a/src/api/files.rs +++ b/src/api/files.rs @@ -97,7 +97,7 @@ impl Engine { /// /// // Compile a script to an AST and store it for later evaluation. /// // Notice that a PathBuf is required which can easily be constructed from a string. - /// let ast = engine.compile_file_with_scope(&mut scope, "script.rhai".into())?; + /// let ast = engine.compile_file_with_scope(&scope, "script.rhai".into())?; /// /// let result = engine.eval_ast::(&ast)?; /// # } diff --git a/src/api/run.rs b/src/api/run.rs index e0f0b49c..678be8eb 100644 --- a/src/api/run.rs +++ b/src/api/run.rs @@ -126,16 +126,16 @@ impl Engine { global.embedded_module_resolver = ast.resolver().cloned(); } - self.eval_global_statements(global, caches, scope, ast.statements()) - .and_then(|_| { - #[cfg(feature = "debugging")] - if self.is_debugger_registered() { - global.debugger_mut().status = crate::eval::DebuggerStatus::Terminate; - let node = &crate::ast::Stmt::Noop(crate::Position::NONE); - self.run_debugger(global, caches, scope, None, node)?; - } - Ok(()) - }) + let _ = self.eval_global_statements(global, caches, scope, ast.statements())?; + + #[cfg(feature = "debugging")] + if self.is_debugger_registered() { + global.debugger_mut().status = crate::eval::DebuggerStatus::Terminate; + let node = &crate::ast::Stmt::Noop(crate::Position::NONE); + self.run_debugger(global, caches, scope, None, node)?; + } + + Ok(()) } } diff --git a/src/ast/expr.rs b/src/ast/expr.rs index c8cdedb1..ffafc09a 100644 --- a/src/ast/expr.rs +++ b/src/ast/expr.rs @@ -287,6 +287,7 @@ pub enum Expr { Array(Box>, Position), /// #{ name:expr, ... } Map( + #[allow(clippy::type_complexity)] Box<(StaticVec<(Ident, Expr)>, BTreeMap)>, Position, ), @@ -304,6 +305,7 @@ pub enum Expr { ), /// Property access - ((getter, hash), (setter, hash), prop) Property( + #[allow(clippy::type_complexity)] Box<( (ImmutableString, u64), (ImmutableString, u64), diff --git a/src/eval/data_check.rs b/src/eval/data_check.rs index 57d3297a..e4e5dc68 100644 --- a/src/eval/data_check.rs +++ b/src/eval/data_check.rs @@ -103,11 +103,11 @@ impl Dynamic { pub(crate) fn calc_data_sizes(&self, _top: bool) -> (usize, usize, usize) { match self.0 { #[cfg(not(feature = "no_index"))] - Union::Array(ref arr, ..) => Self::calc_array_sizes(&**arr), + Union::Array(ref arr, ..) => Self::calc_array_sizes(arr), #[cfg(not(feature = "no_index"))] Union::Blob(ref blob, ..) => (blob.len(), 0, 0), #[cfg(not(feature = "no_object"))] - Union::Map(ref map, ..) => Self::calc_map_sizes(&**map), + Union::Map(ref map, ..) => Self::calc_map_sizes(map), Union::Str(ref s, ..) => (0, 0, s.len()), #[cfg(not(feature = "no_closure"))] Union::Shared(..) if _top => self.read_lock::().unwrap().calc_data_sizes(true), diff --git a/src/func/script.rs b/src/func/script.rs index b864b4e8..ddcc3c43 100644 --- a/src/func/script.rs +++ b/src/func/script.rs @@ -28,7 +28,7 @@ impl Engine { global: &mut GlobalRuntimeState, caches: &mut Caches, scope: &mut Scope, - mut this_ptr: Option<&mut Dynamic>, + this_ptr: Option<&mut Dynamic>, _environ: Option<&EncapsulatedEnviron>, fn_def: &ScriptFnDef, args: &mut FnCallArgs, @@ -108,19 +108,12 @@ impl Engine { #[cfg(feature = "debugging")] if self.is_debugger_registered() { let node = crate::ast::Stmt::Noop(fn_def.body.position()); - self.run_debugger(global, caches, scope, this_ptr.as_deref_mut(), &node)?; + self.run_debugger(global, caches, scope, this_ptr, &node)?; } // Evaluate the function let mut _result: RhaiResult = self - .eval_stmt_block( - global, - caches, - scope, - this_ptr.as_deref_mut(), - &fn_def.body, - rewind_scope, - ) + .eval_stmt_block(global, caches, scope, this_ptr, &fn_def.body, rewind_scope) .or_else(|err| match *err { // Convert return statement to return value ERR::Return(x, ..) => Ok(x), diff --git a/src/lib.rs b/src/lib.rs index b6be66eb..0c414401 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,7 +42,7 @@ //! //! # #[cfg(not(feature = "no_std"))] //! # #[cfg(not(target_family = "wasm"))] -//! # +//! # //! // Evaluate the script, expecting a 'bool' result //! let result: bool = engine.eval_file("my_script.rhai".into())?; //! @@ -82,8 +82,8 @@ // The lints below can be turned off to reduce signal/noise ratio // #![allow(clippy::too_many_lines)] // #![allow(clippy::let_underscore_drop)] -// #![allow(clippy::absurd_extreme_comparisons)] -// #![allow(clippy::unnecessary_cast)] +#![allow(clippy::absurd_extreme_comparisons)] +#![allow(clippy::unnecessary_cast)] // #![allow(clippy::wildcard_imports)] #[cfg(feature = "no_std")] diff --git a/src/packages/string_basic.rs b/src/packages/string_basic.rs index f2ff7304..1324a845 100644 --- a/src/packages/string_basic.rs +++ b/src/packages/string_basic.rs @@ -141,14 +141,12 @@ mod print_debug_functions { /// Return the empty string. #[rhai_fn(name = "print", name = "to_string")] - pub fn print_unit(ctx: NativeCallContext, unit: ()) -> ImmutableString { - let _ = unit; + pub fn print_unit(ctx: NativeCallContext, _unit: ()) -> ImmutableString { ctx.engine().const_empty_string() } /// Convert the unit into a string in debug format. #[rhai_fn(name = "debug", name = "to_debug")] - pub fn debug_unit(unit: ()) -> ImmutableString { - let _ = unit; + pub fn debug_unit(_unit: ()) -> ImmutableString { "()".into() } diff --git a/src/packages/string_more.rs b/src/packages/string_more.rs index 3819295d..45257925 100644 --- a/src/packages/string_more.rs +++ b/src/packages/string_more.rs @@ -84,8 +84,7 @@ mod string_functions { } #[rhai_fn(name = "+")] - pub fn add_append_unit(string: ImmutableString, item: ()) -> ImmutableString { - let _ = item; + pub fn add_append_unit(string: ImmutableString, _item: ()) -> ImmutableString { string } #[rhai_fn(name = "+")] @@ -102,9 +101,8 @@ mod string_functions { *string += character; } #[rhai_fn(name = "+=")] - pub fn add_assign_append_unit(string: &mut ImmutableString, item: ()) { + pub fn add_assign_append_unit(string: &mut ImmutableString, _item: ()) { let _ = string; - let _ = item; } #[cfg(not(feature = "no_index"))] diff --git a/src/types/fn_ptr.rs b/src/types/fn_ptr.rs index 155eaa27..192fe674 100644 --- a/src/types/fn_ptr.rs +++ b/src/types/fn_ptr.rs @@ -99,6 +99,7 @@ impl FnPtr { #[cfg(not(feature = "no_function"))] #[inline(always)] #[must_use] + #[allow(clippy::type_complexity)] pub(crate) fn take_data( self, ) -> ( diff --git a/tests/arrays.rs b/tests/arrays.rs index e0d5226e..502ad450 100644 --- a/tests/arrays.rs +++ b/tests/arrays.rs @@ -1,10 +1,10 @@ #![cfg(not(feature = "no_index"))] use rhai::{Array, Dynamic, Engine, EvalAltResult, ParseErrorType, INT}; +use std::iter::FromIterator; #[test] fn test_arrays() -> Result<(), Box> { - let mut a = Array::new(); - a.push((42 as INT).into()); + let a = Array::from_iter([(42 as INT).into()]); assert_eq!(a[0].clone_cast::(), 42); @@ -125,7 +125,7 @@ fn test_arrays() -> Result<(), Box> { let y = [4, 5]; x.append(y); - x + x " )? .into_typed_array::()?, @@ -501,15 +501,14 @@ fn test_arrays_map_reduce() -> Result<(), Box> { 3 ); - assert_eq!( - engine.eval::<()>( + engine + .eval::<()>( " let x = [1, 2, 3, 2, 1]; x.find(|v| v > 4) - " - )?, - () - ); + ", + ) + .unwrap(); assert_eq!( engine.eval::( @@ -521,15 +520,14 @@ fn test_arrays_map_reduce() -> Result<(), Box> { 2 ); - assert_eq!( - engine.eval::<()>( + engine + .eval::<()>( " let x = [#{alice: 1}, #{bob: 2}, #{clara: 3}]; x.find_map(|v| v.dave) - " - )?, - () - ); + ", + ) + .unwrap(); Ok(()) } @@ -538,7 +536,7 @@ fn test_arrays_map_reduce() -> Result<(), Box> { fn test_arrays_elvis() -> Result<(), Box> { let engine = Engine::new(); - assert_eq!(engine.eval::<()>("let x = (); x?[2]")?, ()); + engine.eval::<()>("let x = (); x?[2]").unwrap(); engine.run("let x = (); x?[2] = 42")?; diff --git a/tests/blobs.rs b/tests/blobs.rs index d961563f..acd9f953 100644 --- a/tests/blobs.rs +++ b/tests/blobs.rs @@ -1,12 +1,10 @@ #![cfg(not(feature = "no_index"))] use rhai::{Blob, Engine, EvalAltResult, Scope, INT}; +use std::iter::FromIterator; #[test] fn test_blobs() -> Result<(), Box> { - let mut a = Blob::new(); - a.push(1); - a.push(2); - a.push(3); + let a = Blob::from_iter([1, 2, 3]); let engine = Engine::new(); let mut scope = Scope::new(); diff --git a/tests/bool_op.rs b/tests/bool_op.rs index e6ef023a..30a551cd 100644 --- a/tests/bool_op.rs +++ b/tests/bool_op.rs @@ -4,8 +4,8 @@ use rhai::{Engine, EvalAltResult}; fn test_bool_op1() -> Result<(), Box> { let engine = Engine::new(); - assert_eq!(engine.eval::("true && (false || true)")?, true); - assert_eq!(engine.eval::("true & (false | true)")?, true); + assert!(engine.eval::("true && (false || true)").unwrap()); + assert!(engine.eval::("true & (false | true)").unwrap()); Ok(()) } @@ -14,8 +14,8 @@ fn test_bool_op1() -> Result<(), Box> { fn test_bool_op2() -> Result<(), Box> { let engine = Engine::new(); - assert_eq!(engine.eval::("false && (false || true)")?, false); - assert_eq!(engine.eval::("false & (false | true)")?, false); + assert!(!engine.eval::("false && (false || true)").unwrap()); + assert!(!engine.eval::("false & (false | true)").unwrap()); Ok(()) } @@ -25,9 +25,9 @@ fn test_bool_op3() -> Result<(), Box> { let engine = Engine::new(); assert!(engine.eval::("true && (false || 123)").is_err()); - assert_eq!(engine.eval::("true && (true || { throw })")?, true); + assert!(engine.eval::("true && (true || { throw })").unwrap()); assert!(engine.eval::("123 && (false || true)").is_err()); - assert_eq!(engine.eval::("false && (true || { throw })")?, false); + assert!(!engine.eval::("false && (true || { throw })").unwrap()); Ok(()) } @@ -36,25 +36,23 @@ fn test_bool_op3() -> Result<(), Box> { fn test_bool_op_short_circuit() -> Result<(), Box> { let engine = Engine::new(); - assert_eq!( - engine.eval::( + assert!(engine + .eval::( " let x = true; x || { throw; }; " - )?, - true - ); + ) + .unwrap()); - assert_eq!( - engine.eval::( + assert!(!engine + .eval::( " let x = false; x && { throw; }; " - )?, - false - ); + ) + .unwrap()); Ok(()) } @@ -63,14 +61,14 @@ fn test_bool_op_short_circuit() -> Result<(), Box> { fn test_bool_op_no_short_circuit1() { let engine = Engine::new(); - assert!(engine + let _ = engine .eval::( " let x = true; x | { throw; } - " + ", ) - .is_err()); + .unwrap_err(); } #[test] diff --git a/tests/call_fn.rs b/tests/call_fn.rs index 26b3ec8b..5d4338d9 100644 --- a/tests/call_fn.rs +++ b/tests/call_fn.rs @@ -169,7 +169,7 @@ fn test_fn_ptr_raw() -> Result<(), Box> { .register_fn("mul", |x: &mut INT, y: INT| *x *= y) .register_raw_fn( "bar", - &[ + [ TypeId::of::(), TypeId::of::(), TypeId::of::(), diff --git a/tests/comments.rs b/tests/comments.rs index 3ad7e4ca..15f15afc 100644 --- a/tests/comments.rs +++ b/tests/comments.rs @@ -21,7 +21,7 @@ fn test_comments() -> Result<(), Box> { 42 ); - assert_eq!(engine.run("/* Hello world */")?, ()); + engine.run("/* Hello world */").unwrap(); Ok(()) } diff --git a/tests/compound_equality.rs b/tests/compound_equality.rs index af5c16b6..e7de4cec 100644 --- a/tests/compound_equality.rs +++ b/tests/compound_equality.rs @@ -5,8 +5,8 @@ fn test_or_equals() -> Result<(), Box> { let engine = Engine::new(); assert_eq!(engine.eval::("let x = 16; x |= 74; x")?, 90); - assert_eq!(engine.eval::("let x = true; x |= false; x")?, true); - assert_eq!(engine.eval::("let x = false; x |= true; x")?, true); + assert!(engine.eval::("let x = true; x |= false; x").unwrap()); + assert!(engine.eval::("let x = false; x |= true; x").unwrap()); Ok(()) } @@ -16,9 +16,9 @@ fn test_and_equals() -> Result<(), Box> { let engine = Engine::new(); assert_eq!(engine.eval::("let x = 16; x &= 31; x")?, 16); - assert_eq!(engine.eval::("let x = true; x &= false; x")?, false); - assert_eq!(engine.eval::("let x = false; x &= true; x")?, false); - assert_eq!(engine.eval::("let x = true; x &= true; x")?, true); + assert!(!engine.eval::("let x = true; x &= false; x").unwrap()); + assert!(!engine.eval::("let x = false; x &= true; x").unwrap()); + assert!(engine.eval::("let x = true; x &= true; x").unwrap()); Ok(()) } diff --git a/tests/custom_syntax.rs b/tests/custom_syntax.rs index 899d83a9..32382acd 100644 --- a/tests/custom_syntax.rs +++ b/tests/custom_syntax.rs @@ -91,11 +91,12 @@ fn test_custom_syntax() -> Result<(), Box> { } // Do not rewind if the variable is upper-case - if var_name.to_uppercase() == var_name { - context.eval_expression_tree_raw(stmt, false)?; + let _: Dynamic = if var_name.to_uppercase() == var_name { + #[allow(deprecated)] // not deprecated but unstable + context.eval_expression_tree_raw(stmt, false) } else { - context.eval_expression_tree(stmt)?; - } + context.eval_expression_tree(stmt) + }?; count += 1; diff --git a/tests/expressions.rs b/tests/expressions.rs index 34938a57..182f9fa9 100644 --- a/tests/expressions.rs +++ b/tests/expressions.rs @@ -90,6 +90,7 @@ fn test_expressions() -> Result<(), Box> { #[test] #[cfg(not(feature = "no_object"))] fn test_expressions_eval() -> Result<(), Box> { + #[allow(clippy::upper_case_acronyms)] #[derive(Debug, Clone)] struct AGENT { pub gender: String, @@ -124,14 +125,12 @@ fn test_expressions_eval() -> Result<(), Box> { scope.push_constant("agent", my_agent); // Evaluate the expression - let result: bool = engine.eval_expression_with_scope( + assert!(engine.eval_expression_with_scope( &mut scope, r#" agent.age > 10 && agent.gender == "male" "#, - )?; - - assert_eq!(result, true); + )?); Ok(()) } diff --git a/tests/float.rs b/tests/float.rs index a1c05186..b09740e6 100644 --- a/tests/float.rs +++ b/tests/float.rs @@ -7,9 +7,11 @@ const EPSILON: FLOAT = 0.000_000_000_1; fn test_float() -> Result<(), Box> { let engine = Engine::new(); - assert!(engine.eval::("let x = 0.0; let y = 1.0; x < y")?,); - assert!(!engine.eval::("let x = 0.0; let y = 1.0; x > y")?,); - assert_eq!(engine.eval::("let x = 0.; let y = 1.; x > y")?, false); + assert!(engine.eval::("let x = 0.0; let y = 1.0; x < y")?); + assert!(!engine.eval::("let x = 0.0; let y = 1.0; x > y")?); + assert!(!engine + .eval::("let x = 0.; let y = 1.; x > y") + .unwrap()); assert!((engine.eval::("let x = 9.9999; x")? - 9.9999 as FLOAT).abs() < EPSILON); Ok(()) diff --git a/tests/functions.rs b/tests/functions.rs index 8e4a7f36..0dc70d04 100644 --- a/tests/functions.rs +++ b/tests/functions.rs @@ -8,6 +8,7 @@ fn test_functions_trait_object() -> Result<(), Box> { fn greet(&self) -> INT; } + #[allow(clippy::upper_case_acronyms)] #[derive(Debug, Clone)] struct ABC(INT); diff --git a/tests/get_set.rs b/tests/get_set.rs index af1416a6..d5af9080 100644 --- a/tests/get_set.rs +++ b/tests/get_set.rs @@ -267,7 +267,7 @@ fn test_get_set_collection() -> Result<(), Box> { engine .register_type_with_name::("MyBag") .register_iterator::() - .register_fn("new_bag", || MyBag::new()) + .register_fn("new_bag", MyBag::new) .register_fn("len", |col: &mut MyBag| col.len() as INT) .register_get("len", |col: &mut MyBag| col.len() as INT) .register_fn("clear", |col: &mut MyBag| col.clear()) @@ -314,7 +314,7 @@ fn test_get_set_indexer() -> Result<(), Box> { engine .register_type_with_name::("MyMap") - .register_fn("new_map", || MyMap::new()) + .register_fn("new_map", MyMap::new) .register_indexer_get( |map: &mut MyMap, index: &str| -> Result<_, Box> { map.get(index).cloned().ok_or_else(|| { @@ -376,7 +376,7 @@ fn test_get_set_indexer() -> Result<(), Box> { r#" let my_map = new_map(); my_map["eggs"] = 42; - + try { let eggs = my_map["eggs"]; let eggs = my_map["not found"]; @@ -385,7 +385,7 @@ fn test_get_set_indexer() -> Result<(), Box> { { print("Not found!"); } - + my_map["eggs"] "#, )?, @@ -399,9 +399,11 @@ fn test_get_set_indexer() -> Result<(), Box> { fn test_get_set_elvis() -> Result<(), Box> { let engine = Engine::new(); - assert_eq!(engine.eval::<()>("let x = (); x?.foo.bar.baz")?, ()); - assert_eq!(engine.eval::<()>("let x = (); x?.foo(1,2,3)")?, ()); - assert_eq!(engine.eval::<()>("let x = #{a:()}; x.a?.foo.bar.baz")?, ()); + engine.eval::<()>("let x = (); x?.foo.bar.baz").unwrap(); + engine.eval::<()>("let x = (); x?.foo(1,2,3)").unwrap(); + engine + .eval::<()>("let x = #{a:()}; x.a?.foo.bar.baz") + .unwrap(); assert_eq!(engine.eval::("let x = 'x'; x?.type_of()")?, "char"); Ok(()) diff --git a/tests/maps.rs b/tests/maps.rs index 2620738d..2bfab623 100644 --- a/tests/maps.rs +++ b/tests/maps.rs @@ -111,7 +111,7 @@ b`: 1}; y["a\nb"] fn test_map_prop() -> Result<(), Box> { let mut engine = Engine::new(); - assert_eq!(engine.eval::<()>("let x = #{a: 42}; x.b")?, ()); + engine.eval::<()>("let x = #{a: 42}; x.b").unwrap(); engine.set_fail_on_invalid_map_property(true); @@ -182,7 +182,7 @@ fn test_map_assign() -> Result<(), Box> { let x = engine.eval::(r#"let x = #{a: 1, b: true, "c$": "hello"}; x"#)?; assert_eq!(x["a"].as_int().unwrap(), 1); - assert_eq!(x["b"].as_bool().unwrap(), true); + assert!(x["b"].as_bool().unwrap()); assert_eq!(x["c$"].clone_cast::(), "hello"); Ok(()) @@ -195,7 +195,7 @@ fn test_map_return() -> Result<(), Box> { let x = engine.eval::(r#"#{a: 1, b: true, "c$": "hello"}"#)?; assert_eq!(x["a"].as_int().unwrap(), 1); - assert_eq!(x["b"].as_bool().unwrap(), true); + assert!(x["b"].as_bool().unwrap()); assert_eq!(x["c$"].clone_cast::(), "hello"); Ok(()) @@ -240,10 +240,10 @@ fn test_map_json() -> Result<(), Box> { assert!(!map.contains_key("x")); assert_eq!(map["a"].as_int().unwrap(), 1); - assert_eq!(map["b"].as_bool().unwrap(), true); + assert!(map["b"].as_bool().unwrap()); assert_eq!(map["c"].as_int().unwrap(), 42); assert_eq!(map["$d e f!"].clone_cast::(), "hello"); - assert_eq!(map["z"].as_unit().unwrap(), ()); + let _: () = map["z"].as_unit().unwrap(); #[cfg(not(feature = "no_index"))] { diff --git a/tests/method_call.rs b/tests/method_call.rs index a9f2c4b7..dee55417 100644 --- a/tests/method_call.rs +++ b/tests/method_call.rs @@ -56,7 +56,7 @@ fn test_method_call_with_full_optimization() -> Result<(), Box> { engine.set_optimization_level(rhai::OptimizationLevel::Full); engine - .register_fn("new_ts", || TestStruct::new()) + .register_fn("new_ts", TestStruct::new) .register_fn("ymd", |_: INT, _: INT, _: INT| 42 as INT) .register_fn("range", |_: &mut TestStruct, _: INT, _: INT| { TestStruct::new() diff --git a/tests/mismatched_op.rs b/tests/mismatched_op.rs index a117f215..7147330a 100644 --- a/tests/mismatched_op.rs +++ b/tests/mismatched_op.rs @@ -13,6 +13,7 @@ fn test_mismatched_op() { #[test] #[cfg(not(feature = "no_object"))] fn test_mismatched_op_custom_type() -> Result<(), Box> { + #[allow(dead_code)] // used inside `register_type_with_name` #[derive(Debug, Clone)] struct TestStruct { x: INT, diff --git a/tests/modules.rs b/tests/modules.rs index babc862a..63dfbfb5 100644 --- a/tests/modules.rs +++ b/tests/modules.rs @@ -1,9 +1,12 @@ #![cfg(not(feature = "no_module"))] use rhai::{ module_resolvers::{DummyModuleResolver, StaticModuleResolver}, - Dynamic, Engine, EvalAltResult, FnNamespace, FnPtr, ImmutableString, Module, NativeCallContext, - ParseError, ParseErrorType, Scope, INT, + Dynamic, Engine, EvalAltResult, FnNamespace, ImmutableString, Module, ParseError, + ParseErrorType, Scope, INT, }; +// +#[cfg(all(not(feature = "no_function"), feature = "internals"))] +use rhai::{FnPtr, NativeCallContext}; #[test] fn test_module() { @@ -241,7 +244,7 @@ fn test_module_resolver() -> Result<(), Box> { "# ) .expect_err("should error"), - EvalAltResult::ErrorInFunctionCall(fn_name, _, ..) if fn_name == "foo" + EvalAltResult::ErrorInFunctionCall(fn_name, ..) if fn_name == "foo" )); engine.set_max_modules(1000); @@ -269,9 +272,9 @@ fn test_module_resolver() -> Result<(), Box> { } foo(1) + { import "hello" as h; h::answer } "#; - let mut scope = Scope::new(); + let scope = Scope::new(); - let ast = engine.compile_into_self_contained(&mut scope, script)?; + let ast = engine.compile_into_self_contained(&scope, script)?; engine.set_module_resolver(DummyModuleResolver::new()); @@ -329,15 +332,15 @@ fn test_module_from_ast() -> Result<(), Box> { private fn hidden() { throw "you shouldn't see me!"; } - + // Imported modules become sub-modules import "another module" as extra; - + // Variables defined at global level become module variables export const x = 123; let foo = 41; let hello; - + // Final variable values become constant module variable values foo = calc(foo); hello = `hello, ${foo} worlds!`; @@ -527,8 +530,7 @@ fn test_module_ast_namespace2() -> Result<(), Box> { Ok(()) } -#[cfg(not(feature = "no_function"))] -#[cfg(feature = "internals")] +#[cfg(all(not(feature = "no_function"), feature = "internals"))] #[test] fn test_module_context() -> Result<(), Box> { let script = "fn bar() { calc(|x| x + 1) }"; diff --git a/tests/native.rs b/tests/native.rs index 71b833c4..0c339cb0 100644 --- a/tests/native.rs +++ b/tests/native.rs @@ -33,12 +33,12 @@ fn test_native_context_fn_name() -> Result<(), Box> { engine .register_raw_fn( "add_double", - &[TypeId::of::(), TypeId::of::()], + [TypeId::of::(), TypeId::of::()], add_double, ) .register_raw_fn( "append_x2", - &[TypeId::of::(), TypeId::of::()], + [TypeId::of::(), TypeId::of::()], add_double, ); diff --git a/tests/not.rs b/tests/not.rs index 41220389..c9db6e2f 100644 --- a/tests/not.rs +++ b/tests/not.rs @@ -4,15 +4,14 @@ use rhai::{Engine, EvalAltResult}; fn test_not() -> Result<(), Box> { let engine = Engine::new(); - assert_eq!( - engine.eval::("let not_true = !true; not_true")?, - false - ); + assert!(!engine + .eval::("let not_true = !true; not_true") + .unwrap()); #[cfg(not(feature = "no_function"))] - assert_eq!(engine.eval::("fn not(x) { !x } not(false)")?, true); + assert!(engine.eval::("fn not(x) { !x } not(false)").unwrap()); - assert_eq!(engine.eval::("!!!!true")?, true); + assert!(engine.eval::("!!!!true").unwrap()); Ok(()) } diff --git a/tests/options.rs b/tests/options.rs index 4f04f1ec..2ff30cb5 100644 --- a/tests/options.rs +++ b/tests/options.rs @@ -83,7 +83,7 @@ fn test_options_strict_var() -> Result<(), Box> { assert!(engine.compile("let x = if y { z } else { w };").is_err()); #[cfg(not(feature = "no_object"))] - engine.compile_with_scope(&mut scope, "if x.abs() { y } else { x + y.len };")?; + engine.compile_with_scope(&scope, "if x.abs() { y } else { x + y.len };")?; engine.compile("let y = 42; let x = y;")?; diff --git a/tests/serde.rs b/tests/serde.rs index f3c7914f..fb0ce51e 100644 --- a/tests/serde.rs +++ b/tests/serde.rs @@ -127,6 +127,7 @@ fn test_serde_ser_unit_enum() -> Result<(), Box> { #[test] #[cfg(not(feature = "no_object"))] fn test_serde_ser_externally_tagged_enum() -> Result<(), Box> { + #[allow(clippy::enum_variant_names)] #[derive(Serialize)] enum MyEnum { VariantUnit, @@ -227,6 +228,7 @@ fn test_serde_ser_internally_tagged_enum() -> Result<(), Box> { #[test] #[cfg(not(feature = "no_object"))] fn test_serde_ser_adjacently_tagged_enum() -> Result<(), Box> { + #[allow(clippy::enum_variant_names)] #[derive(Serialize)] #[serde(tag = "tag", content = "content")] enum MyEnum { @@ -355,8 +357,8 @@ fn test_serde_ser_untagged_enum() -> Result<(), Box> { fn test_serde_de_primary_types() -> Result<(), Box> { assert_eq!(42, from_dynamic::(&Dynamic::from(42_u16))?); assert_eq!(42, from_dynamic::(&(42 as INT).into())?); - assert_eq!(true, from_dynamic::(&true.into())?); - assert_eq!((), from_dynamic::<()>(&().into())?); + assert!(from_dynamic::(&true.into())?); + let _: () = from_dynamic::<()>(&().into()).unwrap(); #[cfg(not(feature = "no_float"))] { @@ -447,12 +449,14 @@ fn test_serde_de_struct() -> Result<(), Box> { #[cfg(not(feature = "no_object"))] #[cfg(not(feature = "no_float"))] fn test_serde_de_script() -> Result<(), Box> { + #[allow(dead_code)] #[derive(Debug, Deserialize)] struct Point { x: FLOAT, y: FLOAT, } + #[allow(dead_code)] #[derive(Debug, Deserialize)] struct MyStruct { a: i64, @@ -500,6 +504,7 @@ fn test_serde_de_unit_enum() -> Result<(), Box> { #[test] #[cfg(not(feature = "no_object"))] fn test_serde_de_externally_tagged_enum() -> Result<(), Box> { + #[allow(clippy::enum_variant_names)] #[derive(Debug, PartialEq, Deserialize)] #[serde(deny_unknown_fields)] enum MyEnum { @@ -598,6 +603,7 @@ fn test_serde_de_internally_tagged_enum() -> Result<(), Box> { #[test] #[cfg(not(feature = "no_object"))] fn test_serde_de_adjacently_tagged_enum() -> Result<(), Box> { + #[allow(clippy::enum_variant_names)] #[derive(Debug, PartialEq, Deserialize)] #[serde(tag = "tag", content = "content", deny_unknown_fields)] enum MyEnum { @@ -814,7 +820,7 @@ fn test_serde_optional() -> Result<(), Box> { let map = r.cast::(); assert_eq!(map.len(), 1); - assert_eq!(map.get("foo").unwrap().as_unit().unwrap(), ()); + let _: () = map.get("foo").unwrap().as_unit().unwrap(); Ok(()) } @@ -882,7 +888,7 @@ fn test_serde_scope() { assert_eq!(scope.len(), 3); assert_eq!(scope.get_value::("x").unwrap(), 42); - assert_eq!(scope.get_value::("y").unwrap(), true); + assert!(scope.get_value::("y").unwrap()); assert_eq!( scope.get_value::("z").unwrap(), "serde::test_serde_scope::TestStruct" diff --git a/tests/side_effects.rs b/tests/side_effects.rs index ad5a8f42..72afc71d 100644 --- a/tests/side_effects.rs +++ b/tests/side_effects.rs @@ -19,6 +19,7 @@ impl Command { } } +#[allow(clippy::upper_case_acronyms)] type API = Arc>; #[cfg(not(feature = "no_object"))] diff --git a/tests/switch.rs b/tests/switch.rs index 2a4aed98..0de962f7 100644 --- a/tests/switch.rs +++ b/tests/switch.rs @@ -10,10 +10,9 @@ fn test_switch() -> Result<(), Box> { engine.eval::("switch 2 { 1 => (), 2 => 'a', 42 => true }")?, 'a' ); - assert_eq!( - engine.run("switch 3 { 1 => (), 2 => 'a', 42 => true }")?, - () - ); + engine + .run("switch 3 { 1 => (), 2 => 'a', 42 => true }") + .unwrap(); assert_eq!( engine.eval::("switch 3 { 1 => (), 2 => 'a', 42 => true, _ => 123 }")?, 123 @@ -32,18 +31,16 @@ fn test_switch() -> Result<(), Box> { )?, 'a' ); - assert_eq!( - engine.eval_with_scope::(&mut scope, "switch x { 1 => (), 2 => 'a', 42 => true }")?, - true - ); - assert_eq!( - engine.eval_with_scope::(&mut scope, "switch x { 1 => (), 2 => 'a', _ => true }")?, - true - ); - assert_eq!( - engine.eval_with_scope::<()>(&mut scope, "switch x { 1 => 123, 2 => 'a' }")?, - () - ); + assert!(engine + .eval_with_scope::(&mut scope, "switch x { 1 => (), 2 => 'a', 42 => true }") + .unwrap()); + assert!(engine + .eval_with_scope::(&mut scope, "switch x { 1 => (), 2 => 'a', _ => true }") + .unwrap()); + let _: () = engine + .eval_with_scope::<()>(&mut scope, "switch x { 1 => 123, 2 => 'a' }") + .unwrap(); + assert_eq!( engine.eval_with_scope::( &mut scope, diff --git a/tests/types.rs b/tests/types.rs index 87e93d51..76bbfe99 100644 --- a/tests/types.rs +++ b/tests/types.rs @@ -2,6 +2,7 @@ use rhai::{Engine, EvalAltResult, INT}; #[test] fn test_type_of() -> Result<(), Box> { + #[allow(dead_code)] #[derive(Clone)] struct TestStruct { x: INT, diff --git a/tests/unit.rs b/tests/unit.rs index bb9d1496..ed3d2847 100644 --- a/tests/unit.rs +++ b/tests/unit.rs @@ -10,13 +10,15 @@ fn test_unit() -> Result<(), Box> { #[test] fn test_unit_eq() -> Result<(), Box> { let engine = Engine::new(); - assert_eq!(engine.eval::("let x = (); let y = (); x == y")?, true); + assert!(engine + .eval::("let x = (); let y = (); x == y") + .unwrap()); Ok(()) } #[test] fn test_unit_with_spaces() -> Result<(), Box> { let engine = Engine::new(); - engine.run("let x = ( ); x").expect_err("should error"); + let _ = engine.run("let x = ( ); x").expect_err("should error"); Ok(()) } diff --git a/tests/var_scope.rs b/tests/var_scope.rs index e249b6de..32db7db7 100644 --- a/tests/var_scope.rs +++ b/tests/var_scope.rs @@ -167,6 +167,7 @@ fn test_var_resolver() -> Result<(), Box> { #[cfg(not(feature = "no_closure"))] let shared = base.clone(); + #[allow(deprecated)] // not deprecated but unstable engine.on_var(move |name, _, context| { match name { "MYSTIC_NUMBER" => Ok(Some((42 as INT).into())), @@ -222,6 +223,7 @@ fn test_var_def_filter() -> Result<(), Box> { let ast = engine.compile("let x = 42;")?; engine.run_ast(&ast)?; + #[allow(deprecated)] // not deprecated but unstable engine.on_def_var(|_, info, _| match (info.name, info.nesting_level) { ("x", 0 | 1) => Ok(false), _ => Ok(true), From c5002801c872a45ad15253bfc0bf4e31a6508b2f Mon Sep 17 00:00:00 2001 From: Mathieu Lala Date: Fri, 30 Dec 2022 19:29:27 +0100 Subject: [PATCH 2/6] ci: add feature powerset & style: used #[cfg(all(..))] --- .github/workflows/build.yml | 13 ++++++++++ src/func/script.rs | 13 +++++++--- src/lib.rs | 51 +++++++++++++------------------------ 3 files changed, 40 insertions(+), 37 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 7dabfb37..a3d006be 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -88,6 +88,19 @@ jobs: command: test args: ${{matrix.flags}} + feature_powerset: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + - uses: taiki-e/install-action@v2 + with: + tool: cargo-hack@0.5.25 + - run: cargo hack check --feature-powerset --depth 2 --no-dev-deps --exclude-features "stdweb wasm-bindgen f32_float" + # no-std builds are a bit more extensive to test no_std_build: name: NoStdBuild diff --git a/src/func/script.rs b/src/func/script.rs index ddcc3c43..b864b4e8 100644 --- a/src/func/script.rs +++ b/src/func/script.rs @@ -28,7 +28,7 @@ impl Engine { global: &mut GlobalRuntimeState, caches: &mut Caches, scope: &mut Scope, - this_ptr: Option<&mut Dynamic>, + mut this_ptr: Option<&mut Dynamic>, _environ: Option<&EncapsulatedEnviron>, fn_def: &ScriptFnDef, args: &mut FnCallArgs, @@ -108,12 +108,19 @@ impl Engine { #[cfg(feature = "debugging")] if self.is_debugger_registered() { let node = crate::ast::Stmt::Noop(fn_def.body.position()); - self.run_debugger(global, caches, scope, this_ptr, &node)?; + self.run_debugger(global, caches, scope, this_ptr.as_deref_mut(), &node)?; } // Evaluate the function let mut _result: RhaiResult = self - .eval_stmt_block(global, caches, scope, this_ptr, &fn_def.body, rewind_scope) + .eval_stmt_block( + global, + caches, + scope, + this_ptr.as_deref_mut(), + &fn_def.body, + rewind_scope, + ) .or_else(|err| match *err { // Convert return statement to return value ERR::Return(x, ..) => Ok(x), diff --git a/src/lib.rs b/src/lib.rs index 0c414401..21f7fa2e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -167,8 +167,7 @@ const MAX_USIZE_INT: INT = INT::MAX; const MAX_USIZE_INT: INT = usize::MAX as INT; /// The maximum integer that can fit into a [`usize`]. -#[cfg(feature = "only_i32")] -#[cfg(target_pointer_width = "32")] +#[cfg(all(feature = "only_i32", target_pointer_width = "32"))] const MAX_USIZE_INT: INT = INT::MAX; /// Number of bits in [`INT`]. @@ -187,8 +186,7 @@ const INT_BYTES: usize = std::mem::size_of::(); /// Not available under `no_float`. /// /// If the `f32_float` feature is enabled, this will be [`f32`] instead. -#[cfg(not(feature = "no_float"))] -#[cfg(not(feature = "f32_float"))] +#[cfg(all(not(feature = "no_float"), not(feature = "f32_float")))] pub type FLOAT = f64; /// The system floating-point type. @@ -197,15 +195,13 @@ pub type FLOAT = f64; /// Not available under `no_float`. /// /// If the `f32_float` feature is not used, this will be `f64` instead. -#[cfg(not(feature = "no_float"))] -#[cfg(feature = "f32_float")] +#[cfg(all(not(feature = "no_float"), feature = "f32_float"))] pub type FLOAT = f32; /// Number of bytes that make up a [`FLOAT`]. /// /// It is 8 unless the `f32_float` feature is enabled when it will be 4. -#[cfg(not(feature = "no_float"))] -#[cfg(not(feature = "no_index"))] +#[cfg(all(not(feature = "no_float"), not(feature = "no_index")))] const FLOAT_BYTES: usize = std::mem::size_of::(); /// An exclusive integer range. @@ -218,8 +214,7 @@ type InclusiveRange = std::ops::RangeInclusive; pub use api::build_type::{CustomType, TypeBuilder}; #[cfg(not(feature = "no_custom_syntax"))] pub use api::custom_syntax::Expression; -#[cfg(not(feature = "no_std"))] -#[cfg(not(target_family = "wasm"))] +#[cfg(all(not(feature = "no_std"), target_family = "wasm"))] pub use api::files::{eval_file, run_file}; pub use api::{eval::eval, events::VarDefInfo, run::run}; pub use ast::{FnAccess, AST}; @@ -317,8 +312,7 @@ pub type OptimizationLevel = (); #[cfg(feature = "internals")] pub use types::dynamic::{AccessMode, DynamicReadLock, DynamicWriteLock, Variant}; -#[cfg(feature = "internals")] -#[cfg(not(feature = "no_float"))] +#[cfg(all(feature = "internals", not(feature = "no_float")))] pub use types::FloatWrapper; #[cfg(feature = "internals")] @@ -340,12 +334,10 @@ pub use ast::{ Ident, OpAssignment, RangeCase, ScriptFnDef, Stmt, StmtBlock, SwitchCasesCollection, }; -#[cfg(feature = "internals")] -#[cfg(not(feature = "no_custom_syntax"))] +#[cfg(all(feature = "internals", not(feature = "no_custom_syntax")))] pub use ast::CustomExpr; -#[cfg(feature = "internals")] -#[cfg(not(feature = "no_module"))] +#[cfg(all(feature = "internals", not(feature = "no_module")))] pub use ast::Namespace; #[cfg(feature = "internals")] @@ -358,8 +350,7 @@ pub use eval::{Caches, FnResolutionCache, FnResolutionCacheEntry, GlobalRuntimeS #[allow(deprecated)] pub use func::{locked_read, locked_write, CallableFunction, NativeCallContextStore}; -#[cfg(feature = "internals")] -#[cfg(feature = "metadata")] +#[cfg(all(feature = "internals", feature = "metadata"))] pub use api::definitions::Definitions; /// Number of items to keep inline for [`StaticVec`]. @@ -462,34 +453,26 @@ type SmartString = smartstring::SmartString; // Compiler guards against mutually-exclusive feature flags -#[cfg(feature = "no_float")] -#[cfg(feature = "f32_float")] +#[cfg(all(feature = "no_float", feature = "f32_float"))] compile_error!("`f32_float` cannot be used with `no_float`"); -#[cfg(feature = "only_i32")] -#[cfg(feature = "only_i64")] +#[cfg(all(feature = "only_i32", feature = "only_i64"))] compile_error!("`only_i32` and `only_i64` cannot be used together"); -#[cfg(feature = "no_std")] -#[cfg(feature = "wasm-bindgen")] +#[cfg(all(feature = "no_std", feature = "wasm-bindgen"))] compile_error!("`wasm-bindgen` cannot be used with `no-std`"); -#[cfg(feature = "no_std")] -#[cfg(feature = "stdweb")] +#[cfg(all(feature = "no_std", feature = "stdweb"))] compile_error!("`stdweb` cannot be used with `no-std`"); -#[cfg(target_family = "wasm")] -#[cfg(feature = "no_std")] +#[cfg(all(target_family = "wasm", feature = "no_std"))] compile_error!("`no_std` cannot be used for WASM target"); -#[cfg(not(target_family = "wasm"))] -#[cfg(feature = "wasm-bindgen")] +#[cfg(all(not(target_family = "wasm"), feature = "wasm-bindgen"))] compile_error!("`wasm-bindgen` cannot be used for non-WASM target"); -#[cfg(not(target_family = "wasm"))] -#[cfg(feature = "stdweb")] +#[cfg(all(not(target_family = "wasm"), feature = "stdweb"))] compile_error!("`stdweb` cannot be used non-WASM target"); -#[cfg(feature = "wasm-bindgen")] -#[cfg(feature = "stdweb")] +#[cfg(all(feature = "wasm-bindgen", feature = "stdweb"))] compile_error!("`wasm-bindgen` and `stdweb` cannot be used together"); From af2e331b0fe430f067b89be09ad5230b30b2d00c Mon Sep 17 00:00:00 2001 From: Mathieu Lala Date: Fri, 30 Dec 2022 20:45:26 +0100 Subject: [PATCH 3/6] fix: not #cfg --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 21f7fa2e..aace6b02 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -214,7 +214,7 @@ type InclusiveRange = std::ops::RangeInclusive; pub use api::build_type::{CustomType, TypeBuilder}; #[cfg(not(feature = "no_custom_syntax"))] pub use api::custom_syntax::Expression; -#[cfg(all(not(feature = "no_std"), target_family = "wasm"))] +#[cfg(all(not(feature = "no_std"), not(target_family = "wasm")))] pub use api::files::{eval_file, run_file}; pub use api::{eval::eval, events::VarDefInfo, run::run}; pub use ast::{FnAccess, AST}; From 9bdf3c290d05b7f58cd31741f88b7ba866b1f051 Mon Sep 17 00:00:00 2001 From: Mathieu Lala Date: Sun, 5 Feb 2023 17:59:02 +0100 Subject: [PATCH 4/6] pull main & udpate lint --- .github/workflows/build.yml | 13 --------- codegen/src/test/function.rs | 2 +- codegen/src/test/module.rs | 2 +- codegen/tests/test_functions.rs | 2 +- codegen/tests/test_modules.rs | 2 +- examples/event_handler_main/main.rs | 2 +- src/api/eval.rs | 4 +-- src/ast/expr.rs | 2 -- src/lib.rs | 45 +++++++++++++++++++---------- src/packages/time_basic.rs | 8 +++-- src/tokenizer.rs | 2 +- src/types/fn_ptr.rs | 1 - 12 files changed, 44 insertions(+), 41 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a3d006be..7dabfb37 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -88,19 +88,6 @@ jobs: command: test args: ${{matrix.flags}} - feature_powerset: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - uses: taiki-e/install-action@v2 - with: - tool: cargo-hack@0.5.25 - - run: cargo hack check --feature-powerset --depth 2 --no-dev-deps --exclude-features "stdweb wasm-bindgen f32_float" - # no-std builds are a bit more extensive to test no_std_build: name: NoStdBuild diff --git a/codegen/src/test/function.rs b/codegen/src/test/function.rs index 9db588e2..b45cc4bc 100644 --- a/codegen/src/test/function.rs +++ b/codegen/src/test/function.rs @@ -254,7 +254,7 @@ mod generate_tests { } (actual_diff, expected_diff) }; - eprintln!("actual != expected, diverge at char {}", counter); + eprintln!("actual != expected, diverge at char {counter}"); // eprintln!(" actual: {}", _actual_diff); // eprintln!("expected: {}", _expected_diff); // assert!(false); diff --git a/codegen/src/test/module.rs b/codegen/src/test/module.rs index 4ae05dfa..0f960956 100644 --- a/codegen/src/test/module.rs +++ b/codegen/src/test/module.rs @@ -301,7 +301,7 @@ mod generate_tests { } (actual_diff, expected_diff) }; - eprintln!("actual != expected, diverge at char {}", counter); + eprintln!("actual != expected, diverge at char {counter}"); // eprintln!(" actual: {}", _actual_diff); // eprintln!("expected: {}", _expected_diff); // assert!(false); diff --git a/codegen/tests/test_functions.rs b/codegen/tests/test_functions.rs index 8734f45b..3fdbf76a 100644 --- a/codegen/tests/test_functions.rs +++ b/codegen/tests/test_functions.rs @@ -62,7 +62,7 @@ mod raw_fn_str { #[export_fn] pub fn write_out_str(message: &str) -> bool { - eprintln!("{}", message); + eprintln!("{message}"); true } } diff --git a/codegen/tests/test_modules.rs b/codegen/tests/test_modules.rs index 7524e2b0..cbc61568 100644 --- a/codegen/tests/test_modules.rs +++ b/codegen/tests/test_modules.rs @@ -82,7 +82,7 @@ pub mod raw_fn_str_module { #[export_module] pub mod host_io { pub fn write_out_str(message: &str) -> bool { - eprintln!("{}", message); + eprintln!("{message}"); true } } diff --git a/examples/event_handler_main/main.rs b/examples/event_handler_main/main.rs index 43cfdb0e..2a1d8f79 100644 --- a/examples/event_handler_main/main.rs +++ b/examples/event_handler_main/main.rs @@ -44,7 +44,7 @@ pub fn main() { let mut input = String::new(); // Read script file - print!("Script file [{}]: ", SCRIPT_FILE); + print!("Script file [{SCRIPT_FILE}]: "); stdout().flush().expect("flush stdout"); input.clear(); diff --git a/src/api/eval.rs b/src/api/eval.rs index 8c90a757..7c00e01e 100644 --- a/src/api/eval.rs +++ b/src/api/eval.rs @@ -212,12 +212,12 @@ impl Engine { } /// Evaluate an [`AST`] with own scope, returning the result value or an error. #[inline] - pub(crate) fn eval_ast_with_scope_raw<'a>( + pub(crate) fn eval_ast_with_scope_raw( &self, global: &mut GlobalRuntimeState, caches: &mut Caches, scope: &mut Scope, - ast: &'a AST, + ast: &AST, ) -> RhaiResult { let orig_source = mem::replace(&mut global.source, ast.source_raw().cloned()); diff --git a/src/ast/expr.rs b/src/ast/expr.rs index ffafc09a..c8cdedb1 100644 --- a/src/ast/expr.rs +++ b/src/ast/expr.rs @@ -287,7 +287,6 @@ pub enum Expr { Array(Box>, Position), /// #{ name:expr, ... } Map( - #[allow(clippy::type_complexity)] Box<(StaticVec<(Ident, Expr)>, BTreeMap)>, Position, ), @@ -305,7 +304,6 @@ pub enum Expr { ), /// Property access - ((getter, hash), (setter, hash), prop) Property( - #[allow(clippy::type_complexity)] Box<( (ImmutableString, u64), (ImmutableString, u64), diff --git a/src/lib.rs b/src/lib.rs index 70eb5c9b..9ac564bb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -185,7 +185,8 @@ const INT_BYTES: usize = std::mem::size_of::(); /// Not available under `no_float`. /// /// If the `f32_float` feature is enabled, this will be [`f32`] instead. -#[cfg(all(not(feature = "no_float"), not(feature = "f32_float")))] +#[cfg(not(feature = "no_float"))] +#[cfg(not(feature = "f32_float"))] pub type FLOAT = f64; /// The system floating-point type. @@ -194,13 +195,15 @@ pub type FLOAT = f64; /// Not available under `no_float`. /// /// If the `f32_float` feature is not used, this will be `f64` instead. -#[cfg(all(not(feature = "no_float"), feature = "f32_float"))] +#[cfg(not(feature = "no_float"))] +#[cfg(feature = "f32_float")] pub type FLOAT = f32; /// Number of bytes that make up a [`FLOAT`]. /// /// It is 8 unless the `f32_float` feature is enabled when it will be 4. -#[cfg(all(not(feature = "no_float"), not(feature = "no_index")))] +#[cfg(not(feature = "no_float"))] +#[cfg(not(feature = "no_index"))] const FLOAT_BYTES: usize = std::mem::size_of::(); /// An exclusive integer range. @@ -213,7 +216,8 @@ type InclusiveRange = std::ops::RangeInclusive; pub use api::build_type::{CustomType, TypeBuilder}; #[cfg(not(feature = "no_custom_syntax"))] pub use api::custom_syntax::Expression; -#[cfg(all(not(feature = "no_std"), not(target_family = "wasm")))] +#[cfg(not(feature = "no_std"))] +#[cfg(not(target_family = "wasm"))] pub use api::files::{eval_file, run_file}; pub use api::{eval::eval, events::VarDefInfo, run::run}; pub use ast::{FnAccess, AST}; @@ -333,10 +337,12 @@ pub use ast::{ Ident, OpAssignment, RangeCase, ScriptFnDef, Stmt, StmtBlock, SwitchCasesCollection, }; -#[cfg(all(feature = "internals", not(feature = "no_custom_syntax")))] +#[cfg(feature = "internals")] +#[cfg(not(feature = "no_custom_syntax"))] pub use ast::CustomExpr; -#[cfg(all(feature = "internals", not(feature = "no_module")))] +#[cfg(feature = "internals")] +#[cfg(not(feature = "no_module"))] pub use ast::Namespace; #[cfg(feature = "internals")] @@ -349,7 +355,8 @@ pub use eval::{Caches, FnResolutionCache, FnResolutionCacheEntry, GlobalRuntimeS #[allow(deprecated)] pub use func::{locked_read, locked_write, CallableFunction, NativeCallContextStore}; -#[cfg(all(feature = "internals", feature = "metadata"))] +#[cfg(feature = "internals")] +#[cfg(feature = "metadata")] pub use api::definitions::Definitions; /// Number of items to keep inline for [`StaticVec`]. @@ -452,26 +459,34 @@ type SmartString = smartstring::SmartString; // Compiler guards against mutually-exclusive feature flags -#[cfg(all(feature = "no_float", feature = "f32_float"))] +#[cfg(feature = "no_float")] +#[cfg(feature = "f32_float")] compile_error!("`f32_float` cannot be used with `no_float`"); -#[cfg(all(feature = "only_i32", feature = "only_i64"))] +#[cfg(feature = "only_i32")] +#[cfg(feature = "only_i64")] compile_error!("`only_i32` and `only_i64` cannot be used together"); -#[cfg(all(feature = "no_std", feature = "wasm-bindgen"))] +#[cfg(feature = "no_std")] +#[cfg(feature = "wasm-bindgen")] compile_error!("`wasm-bindgen` cannot be used with `no-std`"); -#[cfg(all(feature = "no_std", feature = "stdweb"))] +#[cfg(feature = "no_std")] +#[cfg(feature = "stdweb")] compile_error!("`stdweb` cannot be used with `no-std`"); -#[cfg(all(target_family = "wasm", feature = "no_std"))] +#[cfg(target_family = "wasm")] +#[cfg(feature = "no_std")] compile_error!("`no_std` cannot be used for WASM target"); -#[cfg(all(not(target_family = "wasm"), feature = "wasm-bindgen"))] +#[cfg(not(target_family = "wasm"))] +#[cfg(feature = "wasm-bindgen")] compile_error!("`wasm-bindgen` cannot be used for non-WASM target"); -#[cfg(all(not(target_family = "wasm"), feature = "stdweb"))] +#[cfg(not(target_family = "wasm"))] +#[cfg(feature = "stdweb")] compile_error!("`stdweb` cannot be used non-WASM target"); -#[cfg(all(feature = "wasm-bindgen", feature = "stdweb"))] +#[cfg(feature = "wasm-bindgen")] +#[cfg(feature = "stdweb")] compile_error!("`wasm-bindgen` and `stdweb` cannot be used together"); diff --git a/src/packages/time_basic.rs b/src/packages/time_basic.rs index 828c8d8a..cf64bba1 100644 --- a/src/packages/time_basic.rs +++ b/src/packages/time_basic.rs @@ -155,7 +155,9 @@ mod time_functions { }) } } else { - Ok(timestamp - Duration::from_millis((seconds * 1000.0) as u64)) + Ok(timestamp + .checked_sub(Duration::from_millis((seconds * 1000.0) as u64)) + .unwrap()) } } @@ -212,7 +214,9 @@ mod time_functions { )) }) } else { - Ok(timestamp - Duration::from_secs(seconds as u64)) + Ok(timestamp + .checked_sub(Duration::from_secs(seconds as u64)) + .unwrap()) } } diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 16381ccf..f6a0a72e 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -1203,7 +1203,7 @@ const fn is_hex_digit(c: char) -> bool { /// Test if the given character is a numeric digit. #[inline(always)] const fn is_numeric_digit(c: char) -> bool { - matches!(c, '0'..='9') + c.is_ascii_digit() } /// Test if the comment block is a doc-comment. diff --git a/src/types/fn_ptr.rs b/src/types/fn_ptr.rs index 192fe674..155eaa27 100644 --- a/src/types/fn_ptr.rs +++ b/src/types/fn_ptr.rs @@ -99,7 +99,6 @@ impl FnPtr { #[cfg(not(feature = "no_function"))] #[inline(always)] #[must_use] - #[allow(clippy::type_complexity)] pub(crate) fn take_data( self, ) -> ( From 8e5b280d8a17c37904fdf22c2418a07ac651ab86 Mon Sep 17 00:00:00 2001 From: Mathieu Lala Date: Thu, 9 Feb 2023 19:03:02 +0100 Subject: [PATCH 5/6] fix: rename _unit for unit --- src/packages/string_basic.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/packages/string_basic.rs b/src/packages/string_basic.rs index 1324a845..bb03f664 100644 --- a/src/packages/string_basic.rs +++ b/src/packages/string_basic.rs @@ -140,13 +140,15 @@ mod print_debug_functions { } /// Return the empty string. + #[allow(unused_variables)] #[rhai_fn(name = "print", name = "to_string")] - pub fn print_unit(ctx: NativeCallContext, _unit: ()) -> ImmutableString { + pub fn print_unit(ctx: NativeCallContext, unit: ()) -> ImmutableString { ctx.engine().const_empty_string() } /// Convert the unit into a string in debug format. + #[allow(unused_variables)] #[rhai_fn(name = "debug", name = "to_debug")] - pub fn debug_unit(_unit: ()) -> ImmutableString { + pub fn debug_unit(unit: ()) -> ImmutableString { "()".into() } From 3523941feea952a6eeb35bd673a5e0eface08ea7 Mon Sep 17 00:00:00 2001 From: Mathieu Lala Date: Fri, 10 Feb 2023 11:04:14 +0100 Subject: [PATCH 6/6] fix: rename _item for item --- src/packages/string_more.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/packages/string_more.rs b/src/packages/string_more.rs index 45257925..664fa15b 100644 --- a/src/packages/string_more.rs +++ b/src/packages/string_more.rs @@ -83,12 +83,14 @@ mod string_functions { buf.into() } + #[allow(unused_variables)] #[rhai_fn(name = "+")] - pub fn add_append_unit(string: ImmutableString, _item: ()) -> ImmutableString { + pub fn add_append_unit(string: ImmutableString, item: ()) -> ImmutableString { string } + #[allow(unused_variables)] #[rhai_fn(name = "+")] - pub fn add_prepend_unit(_item: (), string: ImmutableString) -> ImmutableString { + pub fn add_prepend_unit(item: (), string: ImmutableString) -> ImmutableString { string } @@ -100,10 +102,9 @@ mod string_functions { pub fn add_assign_append_char(string: &mut ImmutableString, character: char) { *string += character; } + #[allow(unused_variables)] #[rhai_fn(name = "+=")] - pub fn add_assign_append_unit(string: &mut ImmutableString, _item: ()) { - let _ = string; - } + pub fn add_assign_append_unit(string: &mut ImmutableString, item: ()) {} #[cfg(not(feature = "no_index"))] pub mod blob_functions {