From 63359f3f81fce40fa3f3ac26b0ef289115e97548 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Mon, 11 Apr 2022 16:29:16 +0800 Subject: [PATCH] Unused parameters naming. --- README.md | 4 ++-- src/ast/expr.rs | 8 ++------ src/bin/rhai-dbg.rs | 2 +- src/engine.rs | 4 +--- src/eval/chaining.rs | 17 +++++------------ src/eval/data_check.rs | 4 +--- src/func/call.rs | 15 ++++----------- src/func/script.rs | 8 ++------ src/optimizer.rs | 4 +--- src/packages/iter_basic.rs | 8 ++++---- src/packages/string_more.rs | 2 +- src/parser.rs | 17 ++++++----------- src/serde/ser.rs | 28 ++++++++++++++-------------- src/types/dynamic.rs | 4 +--- 14 files changed, 45 insertions(+), 80 deletions(-) diff --git a/README.md b/README.md index 5c05adb9..b070ca1e 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ Rhai - Embedded Scripting for Rust -================================= +================================== ![GitHub last commit](https://img.shields.io/github/last-commit/rhaiscript/rhai?logo=github) [![Build Status](https://github.com/rhaiscript/rhai/workflows/Build/badge.svg)](https://github.com/rhaiscript/rhai/actions) @@ -66,7 +66,7 @@ Protected against attacks For those who actually want their own language ---------------------------------------------- +---------------------------------------------- * Use as a [DSL](https://rhai.rs/book/engine/dsl.html). * Disable certain [language features](https://rhai.rs/book/engine/options.html#language-features) such as [looping](https://rhai.rs/book/engine/disable-looping.html). diff --git a/src/ast/expr.rs b/src/ast/expr.rs index 52a11a29..6bad94a7 100644 --- a/src/ast/expr.rs +++ b/src/ast/expr.rs @@ -636,9 +636,7 @@ impl Expr { /// `non_qualified` is ignored under `no_module`. #[inline] #[must_use] - pub(crate) fn is_variable_access(&self, non_qualified: bool) -> bool { - let _non_qualified = non_qualified; - + pub(crate) fn is_variable_access(&self, _non_qualified: bool) -> bool { match self { #[cfg(not(feature = "no_module"))] Self::Variable(x, ..) if _non_qualified && !x.1.is_empty() => false, @@ -651,9 +649,7 @@ impl Expr { /// `non_qualified` is ignored under `no_module`. #[inline] #[must_use] - pub(crate) fn get_variable_name(&self, non_qualified: bool) -> Option<&str> { - let _non_qualified = non_qualified; - + pub(crate) fn get_variable_name(&self, _non_qualified: bool) -> Option<&str> { match self { #[cfg(not(feature = "no_module"))] Self::Variable(x, ..) if _non_qualified && !x.1.is_empty() => None, diff --git a/src/bin/rhai-dbg.rs b/src/bin/rhai-dbg.rs index 2fa211aa..7656c31a 100644 --- a/src/bin/rhai-dbg.rs +++ b/src/bin/rhai-dbg.rs @@ -321,7 +321,7 @@ fn debug_callback( let mut input = String::new(); loop { - print!("rhai-dbg> "); + print!("dbg> "); stdout().flush().expect("couldn't flush stdout"); diff --git a/src/engine.rs b/src/engine.rs index 192416d0..8b0975d4 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -295,9 +295,7 @@ impl Engine { } /// Check a result to ensure that it is valid. - pub(crate) fn check_return_value(&self, mut result: RhaiResult, pos: Position) -> RhaiResult { - let _pos = pos; - + pub(crate) fn check_return_value(&self, mut result: RhaiResult, _pos: Position) -> RhaiResult { match result { Ok(ref mut r) => { // Concentrate all empty strings into one instance to save memory diff --git a/src/eval/chaining.rs b/src/eval/chaining.rs index 3cb2076a..bcedd846 100644 --- a/src/eval/chaining.rs +++ b/src/eval/chaining.rs @@ -127,16 +127,14 @@ impl Engine { this_ptr: &mut Option<&mut Dynamic>, target: &mut Target, root: (&str, Position), - parent: &Expr, + _parent: &Expr, rhs: &Expr, - parent_options: ASTFlags, + _parent_options: ASTFlags, idx_values: &mut StaticVec, chain_type: ChainType, level: usize, new_val: Option<((Dynamic, Position), (Option, Position))>, ) -> RhaiResultOf<(Dynamic, bool)> { - let _parent = parent; - let _parent_options = parent_options; let is_ref_mut = target.is_ref(); // Pop the last index value @@ -671,7 +669,7 @@ impl Engine { this_ptr: &mut Option<&mut Dynamic>, expr: &Expr, parent_options: ASTFlags, - parent_chain_type: ChainType, + _parent_chain_type: ChainType, idx_values: &mut StaticVec, size: usize, level: usize, @@ -679,8 +677,6 @@ impl Engine { #[cfg(not(feature = "unchecked"))] self.inc_operations(&mut global.num_operations, expr.position())?; - let _parent_chain_type = parent_chain_type; - match expr { #[cfg(not(feature = "no_object"))] Expr::MethodCall(x, ..) @@ -850,18 +846,15 @@ impl Engine { state: &mut EvalState, lib: &[&Module], target: &'t mut Dynamic, - idx: Dynamic, + mut idx: Dynamic, idx_pos: Position, - add_if_not_found: bool, + _add_if_not_found: bool, use_indexers: bool, level: usize, ) -> RhaiResultOf> { #[cfg(not(feature = "unchecked"))] self.inc_operations(&mut global.num_operations, Position::NONE)?; - let mut idx = idx; - let _add_if_not_found = add_if_not_found; - match target { #[cfg(not(feature = "no_index"))] Dynamic(Union::Array(arr, ..)) => { diff --git a/src/eval/data_check.rs b/src/eval/data_check.rs index 29d39406..a9cda2bc 100644 --- a/src/eval/data_check.rs +++ b/src/eval/data_check.rs @@ -16,9 +16,7 @@ impl Engine { /// /// Panics if any interior data is shared (should never happen). #[cfg(not(feature = "unchecked"))] - pub(crate) fn calc_data_sizes(value: &Dynamic, top: bool) -> (usize, usize, usize) { - let _top = top; - + pub(crate) fn calc_data_sizes(value: &Dynamic, _top: bool) -> (usize, usize, usize) { match value.0 { #[cfg(not(feature = "no_index"))] Union::Array(ref arr, ..) => { diff --git a/src/func/call.rs b/src/func/call.rs index dbe502d2..190a29c7 100644 --- a/src/func/call.rs +++ b/src/func/call.rs @@ -195,7 +195,7 @@ impl Engine { #[must_use] fn resolve_fn<'s>( &self, - global: &GlobalRuntimeState, + _global: &GlobalRuntimeState, state: &'s mut EvalState, lib: &[&Module], fn_name: &str, @@ -204,8 +204,6 @@ impl Engine { allow_dynamic: bool, is_op_assignment: bool, ) -> Option<&'s FnResolutionCacheEntry> { - let _global = global; - if hash_script == 0 { return None; } @@ -576,7 +574,7 @@ impl Engine { /// all others are silently replaced by `()`! pub(crate) fn exec_fn_call( &self, - scope: Option<&mut Scope>, + _scope: Option<&mut Scope>, global: &mut GlobalRuntimeState, state: &mut EvalState, lib: &[&Module], @@ -584,7 +582,7 @@ impl Engine { hashes: FnCallHashes, args: &mut FnCallArgs, is_ref_mut: bool, - is_method_call: bool, + _is_method_call: bool, pos: Position, level: usize, ) -> RhaiResultOf<(Dynamic, bool)> { @@ -600,9 +598,6 @@ impl Engine { #[cfg(not(feature = "no_closure"))] ensure_no_data_race(fn_name, args, is_ref_mut)?; - let _scope = scope; - let _is_method_call = is_method_call; - // These may be redirected from method style calls. match fn_name { // Handle type_of() @@ -1418,11 +1413,9 @@ impl Engine { state: &mut EvalState, lib: &[&Module], script: &str, - pos: Position, + _pos: Position, level: usize, ) -> RhaiResult { - let _pos = pos; - #[cfg(not(feature = "unchecked"))] self.inc_operations(&mut global.num_operations, _pos)?; diff --git a/src/func/script.rs b/src/func/script.rs index 97721df5..97bcdaba 100644 --- a/src/func/script.rs +++ b/src/func/script.rs @@ -38,13 +38,11 @@ impl Engine { #[inline(never)] fn make_error( name: String, - fn_def: &ScriptFnDef, + _fn_def: &ScriptFnDef, global: &GlobalRuntimeState, err: RhaiError, pos: Position, ) -> RhaiResult { - let _fn_def = fn_def; - #[cfg(not(feature = "no_module"))] let source = _fn_def .environ @@ -232,13 +230,11 @@ impl Engine { #[must_use] pub(crate) fn has_script_fn( &self, - global: Option<&GlobalRuntimeState>, + _global: Option<&GlobalRuntimeState>, state: &mut EvalState, lib: &[&Module], hash_script: u64, ) -> bool { - let _global = global; - let cache = state.fn_resolution_cache_mut(); if let Some(result) = cache.get(&hash_script).map(|v| v.is_some()) { diff --git a/src/optimizer.rs b/src/optimizer.rs index 2fcd06bb..fe13e94f 100644 --- a/src/optimizer.rs +++ b/src/optimizer.rs @@ -863,7 +863,7 @@ fn optimize_stmt(stmt: &mut Stmt, state: &mut OptimizerState, preserve_result: b } /// Optimize an [expression][Expr]. -fn optimize_expr(expr: &mut Expr, state: &mut OptimizerState, chaining: bool) { +fn optimize_expr(expr: &mut Expr, state: &mut OptimizerState, _chaining: bool) { // These keywords are handled specially const DONT_EVAL_KEYWORDS: &[&str] = &[ KEYWORD_PRINT, // side effects @@ -871,8 +871,6 @@ fn optimize_expr(expr: &mut Expr, state: &mut OptimizerState, chaining: bool) { KEYWORD_EVAL, // arbitrary scripts ]; - let _chaining = chaining; - match expr { // {} Expr::Stmt(x) if x.is_empty() => { state.set_dirty(); *expr = Expr::Unit(x.position()) } diff --git a/src/packages/iter_basic.rs b/src/packages/iter_basic.rs index 2f0843d2..7e8b6af8 100644 --- a/src/packages/iter_basic.rs +++ b/src/packages/iter_basic.rs @@ -795,13 +795,13 @@ mod range_functions { /// Return `true` if the range is inclusive. #[rhai_fn(get = "is_inclusive", name = "is_inclusive", pure)] pub fn is_inclusive(range: &mut ExclusiveRange) -> bool { - let _range = range; + let _ = range; false } /// Return `true` if the range is exclusive. #[rhai_fn(get = "is_exclusive", name = "is_exclusive", pure)] pub fn is_exclusive(range: &mut ExclusiveRange) -> bool { - let _range = range; + let _ = range; true } /// Return the start of the inclusive range. @@ -817,13 +817,13 @@ mod range_functions { /// Return `true` if the range is inclusive. #[rhai_fn(get = "is_inclusive", name = "is_inclusive", pure)] pub fn is_inclusive_inclusive(range: &mut InclusiveRange) -> bool { - let _range = range; + let _ = range; true } /// Return `true` if the range is exclusive. #[rhai_fn(get = "is_exclusive", name = "is_exclusive", pure)] pub fn is_exclusive_inclusive(range: &mut InclusiveRange) -> bool { - let _range = range; + let _ = range; false } } diff --git a/src/packages/string_more.rs b/src/packages/string_more.rs index 3028c815..6a0c2cad 100644 --- a/src/packages/string_more.rs +++ b/src/packages/string_more.rs @@ -76,7 +76,7 @@ mod string_functions { #[rhai_fn(name = "+")] pub fn add_append_unit(string: ImmutableString, item: ()) -> ImmutableString { - let _item = item; + let _ = item; string } #[rhai_fn(name = "+")] diff --git a/src/parser.rs b/src/parser.rs index fa665cea..dd6659d4 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -3504,11 +3504,9 @@ impl Engine { &self, input: &mut TokenStream, state: &mut ParseState, - scope: &Scope, - optimization_level: OptimizationLevel, + _scope: &Scope, + _optimization_level: OptimizationLevel, ) -> ParseResult { - let _scope = scope; - let _optimization_level = optimization_level; let mut functions = BTreeMap::new(); let settings = ParseSettings { @@ -3552,7 +3550,7 @@ impl Engine { statements, #[cfg(not(feature = "no_function"))] StaticVec::new_const(), - optimization_level, + _optimization_level, )); #[cfg(feature = "no_optimize")] @@ -3630,12 +3628,9 @@ impl Engine { &self, input: &mut TokenStream, state: &mut ParseState, - scope: &Scope, - optimization_level: OptimizationLevel, + _scope: &Scope, + _optimization_level: OptimizationLevel, ) -> ParseResult { - let _scope = scope; - let _optimization_level = optimization_level; - let (statements, _lib) = self.parse_global_level(input, state)?; #[cfg(not(feature = "no_optimize"))] @@ -3645,7 +3640,7 @@ impl Engine { statements, #[cfg(not(feature = "no_function"))] _lib, - optimization_level, + _optimization_level, )); #[cfg(feature = "no_optimize")] diff --git a/src/serde/ser.rs b/src/serde/ser.rs index d85cea90..b7e2d915 100644 --- a/src/serde/ser.rs +++ b/src/serde/ser.rs @@ -417,9 +417,9 @@ impl SerializeSeq for DynamicSerializer { fn serialize_element(&mut self, _value: &T) -> RhaiResultOf<()> { #[cfg(not(feature = "no_index"))] { - let _value = _value.serialize(&mut *self)?; + let value = _value.serialize(&mut *self)?; let arr = self._value.downcast_mut::().unwrap(); - arr.push(_value); + arr.push(value); Ok(()) } #[cfg(feature = "no_index")] @@ -452,9 +452,9 @@ impl SerializeTuple for DynamicSerializer { fn serialize_element(&mut self, _value: &T) -> RhaiResultOf<()> { #[cfg(not(feature = "no_index"))] { - let _value = _value.serialize(&mut *self)?; + let value = _value.serialize(&mut *self)?; let arr = self._value.downcast_mut::().unwrap(); - arr.push(_value); + arr.push(value); Ok(()) } #[cfg(feature = "no_index")] @@ -486,9 +486,9 @@ impl SerializeTupleStruct for DynamicSerializer { fn serialize_field(&mut self, _value: &T) -> RhaiResultOf<()> { #[cfg(not(feature = "no_index"))] { - let _value = _value.serialize(&mut *self)?; + let value = _value.serialize(&mut *self)?; let arr = self._value.downcast_mut::().unwrap(); - arr.push(_value); + arr.push(value); Ok(()) } #[cfg(feature = "no_index")] @@ -540,9 +540,9 @@ impl SerializeMap for DynamicSerializer { .map_err(|typ| { ERR::ErrorMismatchDataType("string".into(), typ.into(), Position::NONE) })?; - let _value = _value.serialize(&mut *self)?; + let value = _value.serialize(&mut *self)?; let map = self._value.downcast_mut::().unwrap(); - map.insert(key.into(), _value); + map.insert(key.into(), value); Ok(()) } #[cfg(feature = "no_object")] @@ -561,13 +561,13 @@ impl SerializeMap for DynamicSerializer { ) -> RhaiResultOf<()> { #[cfg(not(feature = "no_object"))] { - let _key: Dynamic = _key.serialize(&mut *self)?; - let _key = _key.into_immutable_string().map_err(|typ| { + let key: Dynamic = _key.serialize(&mut *self)?; + let key = key.into_immutable_string().map_err(|typ| { ERR::ErrorMismatchDataType("string".into(), typ.into(), Position::NONE) })?; - let _value = _value.serialize(&mut *self)?; + let value = _value.serialize(&mut *self)?; let map = self._value.downcast_mut::().unwrap(); - map.insert(_key.into(), _value); + map.insert(key.into(), value); Ok(()) } #[cfg(feature = "no_object")] @@ -603,9 +603,9 @@ impl SerializeStruct for DynamicSerializer { ) -> RhaiResultOf<()> { #[cfg(not(feature = "no_object"))] { - let _value = _value.serialize(&mut *self)?; + let value = _value.serialize(&mut *self)?; let map = self._value.downcast_mut::().unwrap(); - map.insert(_key.into(), _value); + map.insert(_key.into(), value); Ok(()) } #[cfg(feature = "no_object")] diff --git a/src/types/dynamic.rs b/src/types/dynamic.rs index e8a8a07a..792d008b 100644 --- a/src/types/dynamic.rs +++ b/src/types/dynamic.rs @@ -469,9 +469,7 @@ impl Hash for Dynamic { #[cfg(feature = "sync")] Union::Shared(ref cell, ..) => (*cell.read().unwrap()).hash(state), - Union::Variant(ref v, ..) => { - let _v = v; - + Union::Variant(ref _v, ..) => { #[cfg(not(feature = "only_i32"))] #[cfg(not(feature = "only_i64"))] {