Unused parameters naming.

This commit is contained in:
Stephen Chung 2022-04-11 16:29:16 +08:00
parent 1777ee7f6f
commit 63359f3f81
14 changed files with 45 additions and 80 deletions

View File

@ -1,5 +1,5 @@
Rhai - Embedded Scripting for Rust Rhai - Embedded Scripting for Rust
================================= ==================================
![GitHub last commit](https://img.shields.io/github/last-commit/rhaiscript/rhai?logo=github) ![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) [![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 For those who actually want their own language
--------------------------------------------- ----------------------------------------------
* Use as a [DSL](https://rhai.rs/book/engine/dsl.html). * 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). * Disable certain [language features](https://rhai.rs/book/engine/options.html#language-features) such as [looping](https://rhai.rs/book/engine/disable-looping.html).

View File

@ -636,9 +636,7 @@ impl Expr {
/// `non_qualified` is ignored under `no_module`. /// `non_qualified` is ignored under `no_module`.
#[inline] #[inline]
#[must_use] #[must_use]
pub(crate) fn is_variable_access(&self, non_qualified: bool) -> bool { pub(crate) fn is_variable_access(&self, _non_qualified: bool) -> bool {
let _non_qualified = non_qualified;
match self { match self {
#[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_module"))]
Self::Variable(x, ..) if _non_qualified && !x.1.is_empty() => false, Self::Variable(x, ..) if _non_qualified && !x.1.is_empty() => false,
@ -651,9 +649,7 @@ impl Expr {
/// `non_qualified` is ignored under `no_module`. /// `non_qualified` is ignored under `no_module`.
#[inline] #[inline]
#[must_use] #[must_use]
pub(crate) fn get_variable_name(&self, non_qualified: bool) -> Option<&str> { pub(crate) fn get_variable_name(&self, _non_qualified: bool) -> Option<&str> {
let _non_qualified = non_qualified;
match self { match self {
#[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_module"))]
Self::Variable(x, ..) if _non_qualified && !x.1.is_empty() => None, Self::Variable(x, ..) if _non_qualified && !x.1.is_empty() => None,

View File

@ -321,7 +321,7 @@ fn debug_callback(
let mut input = String::new(); let mut input = String::new();
loop { loop {
print!("rhai-dbg> "); print!("dbg> ");
stdout().flush().expect("couldn't flush stdout"); stdout().flush().expect("couldn't flush stdout");

View File

@ -295,9 +295,7 @@ impl Engine {
} }
/// Check a result to ensure that it is valid. /// Check a result to ensure that it is valid.
pub(crate) fn check_return_value(&self, mut result: RhaiResult, pos: Position) -> RhaiResult { pub(crate) fn check_return_value(&self, mut result: RhaiResult, _pos: Position) -> RhaiResult {
let _pos = pos;
match result { match result {
Ok(ref mut r) => { Ok(ref mut r) => {
// Concentrate all empty strings into one instance to save memory // Concentrate all empty strings into one instance to save memory

View File

@ -127,16 +127,14 @@ impl Engine {
this_ptr: &mut Option<&mut Dynamic>, this_ptr: &mut Option<&mut Dynamic>,
target: &mut Target, target: &mut Target,
root: (&str, Position), root: (&str, Position),
parent: &Expr, _parent: &Expr,
rhs: &Expr, rhs: &Expr,
parent_options: ASTFlags, _parent_options: ASTFlags,
idx_values: &mut StaticVec<super::ChainArgument>, idx_values: &mut StaticVec<super::ChainArgument>,
chain_type: ChainType, chain_type: ChainType,
level: usize, level: usize,
new_val: Option<((Dynamic, Position), (Option<OpAssignment>, Position))>, new_val: Option<((Dynamic, Position), (Option<OpAssignment>, Position))>,
) -> RhaiResultOf<(Dynamic, bool)> { ) -> RhaiResultOf<(Dynamic, bool)> {
let _parent = parent;
let _parent_options = parent_options;
let is_ref_mut = target.is_ref(); let is_ref_mut = target.is_ref();
// Pop the last index value // Pop the last index value
@ -671,7 +669,7 @@ impl Engine {
this_ptr: &mut Option<&mut Dynamic>, this_ptr: &mut Option<&mut Dynamic>,
expr: &Expr, expr: &Expr,
parent_options: ASTFlags, parent_options: ASTFlags,
parent_chain_type: ChainType, _parent_chain_type: ChainType,
idx_values: &mut StaticVec<super::ChainArgument>, idx_values: &mut StaticVec<super::ChainArgument>,
size: usize, size: usize,
level: usize, level: usize,
@ -679,8 +677,6 @@ impl Engine {
#[cfg(not(feature = "unchecked"))] #[cfg(not(feature = "unchecked"))]
self.inc_operations(&mut global.num_operations, expr.position())?; self.inc_operations(&mut global.num_operations, expr.position())?;
let _parent_chain_type = parent_chain_type;
match expr { match expr {
#[cfg(not(feature = "no_object"))] #[cfg(not(feature = "no_object"))]
Expr::MethodCall(x, ..) Expr::MethodCall(x, ..)
@ -850,18 +846,15 @@ impl Engine {
state: &mut EvalState, state: &mut EvalState,
lib: &[&Module], lib: &[&Module],
target: &'t mut Dynamic, target: &'t mut Dynamic,
idx: Dynamic, mut idx: Dynamic,
idx_pos: Position, idx_pos: Position,
add_if_not_found: bool, _add_if_not_found: bool,
use_indexers: bool, use_indexers: bool,
level: usize, level: usize,
) -> RhaiResultOf<Target<'t>> { ) -> RhaiResultOf<Target<'t>> {
#[cfg(not(feature = "unchecked"))] #[cfg(not(feature = "unchecked"))]
self.inc_operations(&mut global.num_operations, Position::NONE)?; self.inc_operations(&mut global.num_operations, Position::NONE)?;
let mut idx = idx;
let _add_if_not_found = add_if_not_found;
match target { match target {
#[cfg(not(feature = "no_index"))] #[cfg(not(feature = "no_index"))]
Dynamic(Union::Array(arr, ..)) => { Dynamic(Union::Array(arr, ..)) => {

View File

@ -16,9 +16,7 @@ impl Engine {
/// ///
/// Panics if any interior data is shared (should never happen). /// Panics if any interior data is shared (should never happen).
#[cfg(not(feature = "unchecked"))] #[cfg(not(feature = "unchecked"))]
pub(crate) fn calc_data_sizes(value: &Dynamic, top: bool) -> (usize, usize, usize) { pub(crate) fn calc_data_sizes(value: &Dynamic, _top: bool) -> (usize, usize, usize) {
let _top = top;
match value.0 { match value.0 {
#[cfg(not(feature = "no_index"))] #[cfg(not(feature = "no_index"))]
Union::Array(ref arr, ..) => { Union::Array(ref arr, ..) => {

View File

@ -195,7 +195,7 @@ impl Engine {
#[must_use] #[must_use]
fn resolve_fn<'s>( fn resolve_fn<'s>(
&self, &self,
global: &GlobalRuntimeState, _global: &GlobalRuntimeState,
state: &'s mut EvalState, state: &'s mut EvalState,
lib: &[&Module], lib: &[&Module],
fn_name: &str, fn_name: &str,
@ -204,8 +204,6 @@ impl Engine {
allow_dynamic: bool, allow_dynamic: bool,
is_op_assignment: bool, is_op_assignment: bool,
) -> Option<&'s FnResolutionCacheEntry> { ) -> Option<&'s FnResolutionCacheEntry> {
let _global = global;
if hash_script == 0 { if hash_script == 0 {
return None; return None;
} }
@ -576,7 +574,7 @@ impl Engine {
/// all others are silently replaced by `()`! /// all others are silently replaced by `()`!
pub(crate) fn exec_fn_call( pub(crate) fn exec_fn_call(
&self, &self,
scope: Option<&mut Scope>, _scope: Option<&mut Scope>,
global: &mut GlobalRuntimeState, global: &mut GlobalRuntimeState,
state: &mut EvalState, state: &mut EvalState,
lib: &[&Module], lib: &[&Module],
@ -584,7 +582,7 @@ impl Engine {
hashes: FnCallHashes, hashes: FnCallHashes,
args: &mut FnCallArgs, args: &mut FnCallArgs,
is_ref_mut: bool, is_ref_mut: bool,
is_method_call: bool, _is_method_call: bool,
pos: Position, pos: Position,
level: usize, level: usize,
) -> RhaiResultOf<(Dynamic, bool)> { ) -> RhaiResultOf<(Dynamic, bool)> {
@ -600,9 +598,6 @@ impl Engine {
#[cfg(not(feature = "no_closure"))] #[cfg(not(feature = "no_closure"))]
ensure_no_data_race(fn_name, args, is_ref_mut)?; 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. // These may be redirected from method style calls.
match fn_name { match fn_name {
// Handle type_of() // Handle type_of()
@ -1418,11 +1413,9 @@ impl Engine {
state: &mut EvalState, state: &mut EvalState,
lib: &[&Module], lib: &[&Module],
script: &str, script: &str,
pos: Position, _pos: Position,
level: usize, level: usize,
) -> RhaiResult { ) -> RhaiResult {
let _pos = pos;
#[cfg(not(feature = "unchecked"))] #[cfg(not(feature = "unchecked"))]
self.inc_operations(&mut global.num_operations, _pos)?; self.inc_operations(&mut global.num_operations, _pos)?;

View File

@ -38,13 +38,11 @@ impl Engine {
#[inline(never)] #[inline(never)]
fn make_error( fn make_error(
name: String, name: String,
fn_def: &ScriptFnDef, _fn_def: &ScriptFnDef,
global: &GlobalRuntimeState, global: &GlobalRuntimeState,
err: RhaiError, err: RhaiError,
pos: Position, pos: Position,
) -> RhaiResult { ) -> RhaiResult {
let _fn_def = fn_def;
#[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_module"))]
let source = _fn_def let source = _fn_def
.environ .environ
@ -232,13 +230,11 @@ impl Engine {
#[must_use] #[must_use]
pub(crate) fn has_script_fn( pub(crate) fn has_script_fn(
&self, &self,
global: Option<&GlobalRuntimeState>, _global: Option<&GlobalRuntimeState>,
state: &mut EvalState, state: &mut EvalState,
lib: &[&Module], lib: &[&Module],
hash_script: u64, hash_script: u64,
) -> bool { ) -> bool {
let _global = global;
let cache = state.fn_resolution_cache_mut(); let cache = state.fn_resolution_cache_mut();
if let Some(result) = cache.get(&hash_script).map(|v| v.is_some()) { if let Some(result) = cache.get(&hash_script).map(|v| v.is_some()) {

View File

@ -863,7 +863,7 @@ fn optimize_stmt(stmt: &mut Stmt, state: &mut OptimizerState, preserve_result: b
} }
/// Optimize an [expression][Expr]. /// 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 // These keywords are handled specially
const DONT_EVAL_KEYWORDS: &[&str] = &[ const DONT_EVAL_KEYWORDS: &[&str] = &[
KEYWORD_PRINT, // side effects KEYWORD_PRINT, // side effects
@ -871,8 +871,6 @@ fn optimize_expr(expr: &mut Expr, state: &mut OptimizerState, chaining: bool) {
KEYWORD_EVAL, // arbitrary scripts KEYWORD_EVAL, // arbitrary scripts
]; ];
let _chaining = chaining;
match expr { match expr {
// {} // {}
Expr::Stmt(x) if x.is_empty() => { state.set_dirty(); *expr = Expr::Unit(x.position()) } Expr::Stmt(x) if x.is_empty() => { state.set_dirty(); *expr = Expr::Unit(x.position()) }

View File

@ -795,13 +795,13 @@ mod range_functions {
/// Return `true` if the range is inclusive. /// Return `true` if the range is inclusive.
#[rhai_fn(get = "is_inclusive", name = "is_inclusive", pure)] #[rhai_fn(get = "is_inclusive", name = "is_inclusive", pure)]
pub fn is_inclusive(range: &mut ExclusiveRange) -> bool { pub fn is_inclusive(range: &mut ExclusiveRange) -> bool {
let _range = range; let _ = range;
false false
} }
/// Return `true` if the range is exclusive. /// Return `true` if the range is exclusive.
#[rhai_fn(get = "is_exclusive", name = "is_exclusive", pure)] #[rhai_fn(get = "is_exclusive", name = "is_exclusive", pure)]
pub fn is_exclusive(range: &mut ExclusiveRange) -> bool { pub fn is_exclusive(range: &mut ExclusiveRange) -> bool {
let _range = range; let _ = range;
true true
} }
/// Return the start of the inclusive range. /// Return the start of the inclusive range.
@ -817,13 +817,13 @@ mod range_functions {
/// Return `true` if the range is inclusive. /// Return `true` if the range is inclusive.
#[rhai_fn(get = "is_inclusive", name = "is_inclusive", pure)] #[rhai_fn(get = "is_inclusive", name = "is_inclusive", pure)]
pub fn is_inclusive_inclusive(range: &mut InclusiveRange) -> bool { pub fn is_inclusive_inclusive(range: &mut InclusiveRange) -> bool {
let _range = range; let _ = range;
true true
} }
/// Return `true` if the range is exclusive. /// Return `true` if the range is exclusive.
#[rhai_fn(get = "is_exclusive", name = "is_exclusive", pure)] #[rhai_fn(get = "is_exclusive", name = "is_exclusive", pure)]
pub fn is_exclusive_inclusive(range: &mut InclusiveRange) -> bool { pub fn is_exclusive_inclusive(range: &mut InclusiveRange) -> bool {
let _range = range; let _ = range;
false false
} }
} }

View File

@ -76,7 +76,7 @@ mod string_functions {
#[rhai_fn(name = "+")] #[rhai_fn(name = "+")]
pub fn add_append_unit(string: ImmutableString, item: ()) -> ImmutableString { pub fn add_append_unit(string: ImmutableString, item: ()) -> ImmutableString {
let _item = item; let _ = item;
string string
} }
#[rhai_fn(name = "+")] #[rhai_fn(name = "+")]

View File

@ -3504,11 +3504,9 @@ impl Engine {
&self, &self,
input: &mut TokenStream, input: &mut TokenStream,
state: &mut ParseState, state: &mut ParseState,
scope: &Scope, _scope: &Scope,
optimization_level: OptimizationLevel, _optimization_level: OptimizationLevel,
) -> ParseResult<AST> { ) -> ParseResult<AST> {
let _scope = scope;
let _optimization_level = optimization_level;
let mut functions = BTreeMap::new(); let mut functions = BTreeMap::new();
let settings = ParseSettings { let settings = ParseSettings {
@ -3552,7 +3550,7 @@ impl Engine {
statements, statements,
#[cfg(not(feature = "no_function"))] #[cfg(not(feature = "no_function"))]
StaticVec::new_const(), StaticVec::new_const(),
optimization_level, _optimization_level,
)); ));
#[cfg(feature = "no_optimize")] #[cfg(feature = "no_optimize")]
@ -3630,12 +3628,9 @@ impl Engine {
&self, &self,
input: &mut TokenStream, input: &mut TokenStream,
state: &mut ParseState, state: &mut ParseState,
scope: &Scope, _scope: &Scope,
optimization_level: OptimizationLevel, _optimization_level: OptimizationLevel,
) -> ParseResult<AST> { ) -> ParseResult<AST> {
let _scope = scope;
let _optimization_level = optimization_level;
let (statements, _lib) = self.parse_global_level(input, state)?; let (statements, _lib) = self.parse_global_level(input, state)?;
#[cfg(not(feature = "no_optimize"))] #[cfg(not(feature = "no_optimize"))]
@ -3645,7 +3640,7 @@ impl Engine {
statements, statements,
#[cfg(not(feature = "no_function"))] #[cfg(not(feature = "no_function"))]
_lib, _lib,
optimization_level, _optimization_level,
)); ));
#[cfg(feature = "no_optimize")] #[cfg(feature = "no_optimize")]

View File

@ -417,9 +417,9 @@ impl SerializeSeq for DynamicSerializer {
fn serialize_element<T: ?Sized + Serialize>(&mut self, _value: &T) -> RhaiResultOf<()> { fn serialize_element<T: ?Sized + Serialize>(&mut self, _value: &T) -> RhaiResultOf<()> {
#[cfg(not(feature = "no_index"))] #[cfg(not(feature = "no_index"))]
{ {
let _value = _value.serialize(&mut *self)?; let value = _value.serialize(&mut *self)?;
let arr = self._value.downcast_mut::<crate::Array>().unwrap(); let arr = self._value.downcast_mut::<crate::Array>().unwrap();
arr.push(_value); arr.push(value);
Ok(()) Ok(())
} }
#[cfg(feature = "no_index")] #[cfg(feature = "no_index")]
@ -452,9 +452,9 @@ impl SerializeTuple for DynamicSerializer {
fn serialize_element<T: ?Sized + Serialize>(&mut self, _value: &T) -> RhaiResultOf<()> { fn serialize_element<T: ?Sized + Serialize>(&mut self, _value: &T) -> RhaiResultOf<()> {
#[cfg(not(feature = "no_index"))] #[cfg(not(feature = "no_index"))]
{ {
let _value = _value.serialize(&mut *self)?; let value = _value.serialize(&mut *self)?;
let arr = self._value.downcast_mut::<crate::Array>().unwrap(); let arr = self._value.downcast_mut::<crate::Array>().unwrap();
arr.push(_value); arr.push(value);
Ok(()) Ok(())
} }
#[cfg(feature = "no_index")] #[cfg(feature = "no_index")]
@ -486,9 +486,9 @@ impl SerializeTupleStruct for DynamicSerializer {
fn serialize_field<T: ?Sized + Serialize>(&mut self, _value: &T) -> RhaiResultOf<()> { fn serialize_field<T: ?Sized + Serialize>(&mut self, _value: &T) -> RhaiResultOf<()> {
#[cfg(not(feature = "no_index"))] #[cfg(not(feature = "no_index"))]
{ {
let _value = _value.serialize(&mut *self)?; let value = _value.serialize(&mut *self)?;
let arr = self._value.downcast_mut::<crate::Array>().unwrap(); let arr = self._value.downcast_mut::<crate::Array>().unwrap();
arr.push(_value); arr.push(value);
Ok(()) Ok(())
} }
#[cfg(feature = "no_index")] #[cfg(feature = "no_index")]
@ -540,9 +540,9 @@ impl SerializeMap for DynamicSerializer {
.map_err(|typ| { .map_err(|typ| {
ERR::ErrorMismatchDataType("string".into(), typ.into(), Position::NONE) 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::<crate::Map>().unwrap(); let map = self._value.downcast_mut::<crate::Map>().unwrap();
map.insert(key.into(), _value); map.insert(key.into(), value);
Ok(()) Ok(())
} }
#[cfg(feature = "no_object")] #[cfg(feature = "no_object")]
@ -561,13 +561,13 @@ impl SerializeMap for DynamicSerializer {
) -> RhaiResultOf<()> { ) -> RhaiResultOf<()> {
#[cfg(not(feature = "no_object"))] #[cfg(not(feature = "no_object"))]
{ {
let _key: Dynamic = _key.serialize(&mut *self)?; let key: Dynamic = _key.serialize(&mut *self)?;
let _key = _key.into_immutable_string().map_err(|typ| { let key = key.into_immutable_string().map_err(|typ| {
ERR::ErrorMismatchDataType("string".into(), typ.into(), Position::NONE) 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::<crate::Map>().unwrap(); let map = self._value.downcast_mut::<crate::Map>().unwrap();
map.insert(_key.into(), _value); map.insert(key.into(), value);
Ok(()) Ok(())
} }
#[cfg(feature = "no_object")] #[cfg(feature = "no_object")]
@ -603,9 +603,9 @@ impl SerializeStruct for DynamicSerializer {
) -> RhaiResultOf<()> { ) -> RhaiResultOf<()> {
#[cfg(not(feature = "no_object"))] #[cfg(not(feature = "no_object"))]
{ {
let _value = _value.serialize(&mut *self)?; let value = _value.serialize(&mut *self)?;
let map = self._value.downcast_mut::<crate::Map>().unwrap(); let map = self._value.downcast_mut::<crate::Map>().unwrap();
map.insert(_key.into(), _value); map.insert(_key.into(), value);
Ok(()) Ok(())
} }
#[cfg(feature = "no_object")] #[cfg(feature = "no_object")]

View File

@ -469,9 +469,7 @@ impl Hash for Dynamic {
#[cfg(feature = "sync")] #[cfg(feature = "sync")]
Union::Shared(ref cell, ..) => (*cell.read().unwrap()).hash(state), Union::Shared(ref cell, ..) => (*cell.read().unwrap()).hash(state),
Union::Variant(ref v, ..) => { Union::Variant(ref _v, ..) => {
let _v = v;
#[cfg(not(feature = "only_i32"))] #[cfg(not(feature = "only_i32"))]
#[cfg(not(feature = "only_i64"))] #[cfg(not(feature = "only_i64"))]
{ {