From dba451045695359a95acc273d001a32707220504 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Fri, 13 Aug 2021 13:42:39 +0800 Subject: [PATCH] Better function parameter names. --- src/engine.rs | 24 ++++++--- src/fn_call.rs | 4 +- src/optimize.rs | 15 ++++-- src/packages/array_basic.rs | 16 +++--- src/packages/fn_basic.rs | 8 +-- src/packages/map_basic.rs | 23 ++++---- src/packages/math_basic.rs | 22 ++++---- src/packages/string_more.rs | 15 ++++-- src/packages/time_basic.rs | 32 +++++------ src/parse.rs | 105 ++++++++++++++++++++++++++---------- src/token.rs | 7 +-- 11 files changed, 174 insertions(+), 97 deletions(-) diff --git a/src/engine.rs b/src/engine.rs index d72b2dac..95dbf331 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -1235,13 +1235,14 @@ impl Engine { target: &mut Target, root: (&str, Position), rhs: &Expr, - _terminate_chaining: bool, + terminate_chaining: bool, idx_values: &mut StaticVec, chain_type: ChainType, level: usize, new_val: Option<((Dynamic, Position), (Option, Position))>, ) -> Result<(Dynamic, bool), Box> { let is_ref_mut = target.is_ref(); + let _terminate_chaining = terminate_chaining; // Pop the last index value let idx_val = idx_values @@ -1725,7 +1726,7 @@ impl Engine { this_ptr: &mut Option<&mut Dynamic>, expr: &Expr, terminate_chaining: bool, - _parent_chain_type: ChainType, + parent_chain_type: ChainType, idx_values: &mut StaticVec, size: usize, level: usize, @@ -1733,6 +1734,8 @@ impl Engine { #[cfg(not(feature = "unchecked"))] self.inc_operations(state, expr.position())?; + let _parent_chain_type = parent_chain_type; + match expr { #[cfg(not(feature = "no_object"))] Expr::FnCall(x, _) if _parent_chain_type == ChainType::Dotting && !x.is_qualified() => { @@ -1848,15 +1851,18 @@ impl Engine { state: &mut EvalState, lib: &[&Module], target: &'t mut Dynamic, - mut idx: Dynamic, + idx: Dynamic, idx_pos: Position, - _create: bool, - indexers: bool, + add_if_not_found: bool, + use_indexers: bool, level: usize, ) -> Result, Box> { #[cfg(not(feature = "unchecked"))] self.inc_operations(state, 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, _, _)) => { @@ -1907,7 +1913,7 @@ impl Engine { self.make_type_mismatch_err::(idx.type_name(), idx_pos) })?; - if _create && !map.contains_key(index.as_str()) { + if _add_if_not_found && !map.contains_key(index.as_str()) { map.insert(index.clone().into(), Default::default()); } @@ -1988,7 +1994,7 @@ impl Engine { Ok(Target::StringChar(target, offset, ch.into())) } - _ if indexers => { + _ if use_indexers => { let args = &mut [target, &mut idx]; let hash_get = FnCallHashes::from_native(crate::calc_fn_hash(FN_IDX_GET, 2)); let idx_pos = Position::NONE; @@ -2298,13 +2304,15 @@ impl Engine { op_pos: Position, target: &mut Target, root: (&str, Position), - mut new_val: Dynamic, + new_val: Dynamic, ) -> Result<(), Box> { if target.is_read_only() { // Assignment to constant variable return EvalAltResult::ErrorAssignmentToConstant(root.0.to_string(), root.1).into(); } + let mut new_val = new_val; + if let Some(OpAssignment { hash_op_assign, hash_op, diff --git a/src/fn_call.rs b/src/fn_call.rs index e79e906a..8ed8430c 100644 --- a/src/fn_call.rs +++ b/src/fn_call.rs @@ -611,7 +611,7 @@ impl Engine { hashes: FnCallHashes, args: &mut FnCallArgs, is_ref_mut: bool, - _is_method_call: bool, + is_method_call: bool, pos: Position, _capture_scope: Option, _level: usize, @@ -625,6 +625,8 @@ impl Engine { #[cfg(not(feature = "no_closure"))] ensure_no_data_race(fn_name, args, is_ref_mut)?; + let _is_method_call = is_method_call; + // These may be redirected from method style calls. match fn_name { // Handle type_of() diff --git a/src/optimize.rs b/src/optimize.rs index 08f3fadd..299098c0 100644 --- a/src/optimize.rs +++ b/src/optimize.rs @@ -686,7 +686,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 @@ -694,6 +694,8 @@ 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()) } @@ -1061,12 +1063,14 @@ fn optimize_expr(expr: &mut Expr, state: &mut OptimizerState, _chaining: bool) { /// Optimize a block of [statements][Stmt] at top level. fn optimize_top_level( - mut statements: Vec, + statements: Vec, engine: &Engine, scope: &Scope, lib: &[&Module], optimization_level: OptimizationLevel, ) -> Vec { + let mut statements = statements; + // If optimization level is None then skip optimizing if optimization_level == OptimizationLevel::None { statements.shrink_to_fit(); @@ -1093,8 +1097,8 @@ fn optimize_top_level( pub fn optimize_into_ast( engine: &Engine, scope: &Scope, - mut statements: Vec, - _functions: Vec>, + statements: Vec, + functions: Vec>, optimization_level: OptimizationLevel, ) -> AST { let level = if cfg!(feature = "no_optimize") { @@ -1103,6 +1107,9 @@ pub fn optimize_into_ast( optimization_level }; + let mut statements = statements; + let _functions = functions; + #[cfg(not(feature = "no_function"))] let lib = { let mut module = Module::new(); diff --git a/src/packages/array_basic.rs b/src/packages/array_basic.rs index 3400f1d1..a8422e98 100644 --- a/src/packages/array_basic.rs +++ b/src/packages/array_basic.rs @@ -753,17 +753,19 @@ mod array_functions { #[rhai_fn(name = "==", return_raw, pure)] pub fn equals( ctx: NativeCallContext, - array: &mut Array, - mut array2: Array, + array1: &mut Array, + array2: Array, ) -> Result> { - if array.len() != array2.len() { + if array1.len() != array2.len() { return Ok(false); } - if array.is_empty() { + if array1.is_empty() { return Ok(true); } - for (a1, a2) in array.iter_mut().zip(array2.iter_mut()) { + let mut array2 = array2; + + for (a1, a2) in array1.iter_mut().zip(array2.iter_mut()) { if !ctx .call_fn_dynamic_raw(OP_EQUALS, true, &mut [a1, a2]) .or_else(|err| match *err { @@ -791,9 +793,9 @@ mod array_functions { #[rhai_fn(name = "!=", return_raw, pure)] pub fn not_equals( ctx: NativeCallContext, - array: &mut Array, + array1: &mut Array, array2: Array, ) -> Result> { - equals(ctx, array, array2).map(|r| !r) + equals(ctx, array1, array2).map(|r| !r) } } diff --git a/src/packages/fn_basic.rs b/src/packages/fn_basic.rs index 063bd42c..dbe86112 100644 --- a/src/packages/fn_basic.rs +++ b/src/packages/fn_basic.rs @@ -10,15 +10,15 @@ def_package!(crate:BasicFnPackage:"Basic Fn functions.", lib, { #[export_module] mod fn_ptr_functions { #[rhai_fn(name = "name", get = "name", pure)] - pub fn name(f: &mut FnPtr) -> ImmutableString { - f.fn_name_raw().into() + pub fn name(fn_ptr: &mut FnPtr) -> ImmutableString { + fn_ptr.fn_name_raw().into() } #[cfg(not(feature = "no_function"))] pub mod functions { #[rhai_fn(name = "is_anonymous", get = "is_anonymous", pure)] - pub fn is_anonymous(f: &mut FnPtr) -> bool { - f.is_anonymous() + pub fn is_anonymous(fn_ptr: &mut FnPtr) -> bool { + fn_ptr.is_anonymous() } } diff --git a/src/packages/map_basic.rs b/src/packages/map_basic.rs index a7f068da..b7e52bc3 100644 --- a/src/packages/map_basic.rs +++ b/src/packages/map_basic.rs @@ -34,9 +34,10 @@ mod map_functions { map.extend(map2.into_iter()); } #[rhai_fn(name = "+")] - pub fn merge(mut map: Map, map2: Map) -> Map { - map.extend(map2.into_iter()); - map + pub fn merge(map1: Map, map2: Map) -> Map { + let mut map1 = map1; + map1.extend(map2.into_iter()); + map1 } pub fn fill_with(map: &mut Map, map2: Map) { map2.into_iter().for_each(|(key, value)| { @@ -46,17 +47,19 @@ mod map_functions { #[rhai_fn(name = "==", return_raw, pure)] pub fn equals( ctx: NativeCallContext, - map: &mut Map, - mut map2: Map, + map1: &mut Map, + map2: Map, ) -> Result> { - if map.len() != map2.len() { + if map1.len() != map2.len() { return Ok(false); } - if map.is_empty() { + if map1.is_empty() { return Ok(true); } - for (m1, v1) in map.iter_mut() { + let mut map2 = map2; + + for (m1, v1) in map1.iter_mut() { if let Some(v2) = map2.get_mut(m1) { let equals = ctx .call_fn_dynamic_raw(OP_EQUALS, true, &mut [v1, v2]) @@ -75,10 +78,10 @@ mod map_functions { #[rhai_fn(name = "!=", return_raw, pure)] pub fn not_equals( ctx: NativeCallContext, - map: &mut Map, + map1: &mut Map, map2: Map, ) -> Result> { - equals(ctx, map, map2).map(|r| !r) + equals(ctx, map1, map2).map(|r| !r) } #[cfg(not(feature = "no_index"))] diff --git a/src/packages/math_basic.rs b/src/packages/math_basic.rs index 674a6a2e..1f281390 100644 --- a/src/packages/math_basic.rs +++ b/src/packages/math_basic.rs @@ -112,7 +112,7 @@ def_package!(crate:BasicMathPackage:"Basic mathematic functions.", lib, { #[export_module] mod int_functions { #[rhai_fn(name = "parse_int", return_raw)] - pub fn parse_int_radix(s: &str, radix: INT) -> Result> { + pub fn parse_int_radix(string: &str, radix: INT) -> Result> { if !(2..=36).contains(&radix) { return EvalAltResult::ErrorArithmetic( format!("Invalid radix: '{}'", radix), @@ -121,17 +121,17 @@ mod int_functions { .into(); } - INT::from_str_radix(s.trim(), radix as u32).map_err(|err| { + INT::from_str_radix(string.trim(), radix as u32).map_err(|err| { EvalAltResult::ErrorArithmetic( - format!("Error parsing integer number '{}': {}", s, err), + format!("Error parsing integer number '{}': {}", string, err), Position::NONE, ) .into() }) } #[rhai_fn(name = "parse_int", return_raw)] - pub fn parse_int(s: &str) -> Result> { - parse_int_radix(s, 10) + pub fn parse_int(string: &str) -> Result> { + parse_int_radix(string, 10) } } @@ -283,10 +283,10 @@ mod float_functions { } } #[rhai_fn(return_raw)] - pub fn parse_float(s: &str) -> Result> { - s.trim().parse::().map_err(|err| { + pub fn parse_float(string: &str) -> Result> { + string.trim().parse::().map_err(|err| { EvalAltResult::ErrorArithmetic( - format!("Error parsing floating-point number '{}': {}", s, err), + format!("Error parsing floating-point number '{}': {}", string, err), Position::NONE, ) .into() @@ -427,12 +427,12 @@ mod decimal_functions { x.fract() } #[rhai_fn(return_raw)] - pub fn parse_decimal(s: &str) -> Result> { - Decimal::from_str(s) + pub fn parse_decimal(string: &str) -> Result> { + Decimal::from_str(string) .or_else(|_| Decimal::from_scientific(s)) .map_err(|err| { EvalAltResult::ErrorArithmetic( - format!("Error parsing decimal number '{}': {}", s, err), + format!("Error parsing decimal number '{}': {}", string, err), Position::NONE, ) .into() diff --git a/src/packages/string_more.rs b/src/packages/string_more.rs index 22c9074d..c72a695a 100644 --- a/src/packages/string_more.rs +++ b/src/packages/string_more.rs @@ -50,12 +50,13 @@ mod string_functions { string1 + string2 } #[rhai_fn(name = "+", name = "append")] - pub fn add_append_char(string: ImmutableString, ch: char) -> ImmutableString { - string + ch + pub fn add_append_char(string: ImmutableString, character: char) -> ImmutableString { + string + character } #[rhai_fn(name = "+", name = "append")] - pub fn add_append_unit(string: ImmutableString, _item: ()) -> ImmutableString { + pub fn add_append_unit(string: ImmutableString, item: ()) -> ImmutableString { + let _item = item; string } #[rhai_fn(name = "+")] @@ -369,11 +370,13 @@ mod string_functions { #[rhai_fn(return_raw)] pub fn pad( - _ctx: NativeCallContext, + ctx: NativeCallContext, string: &mut ImmutableString, len: INT, character: char, ) -> Result<(), Box> { + let _ctx = ctx; + // Check if string will be over max size limit #[cfg(not(feature = "unchecked"))] if _ctx.engine().max_string_size() > 0 && len as usize > _ctx.engine().max_string_size() { @@ -411,11 +414,13 @@ mod string_functions { } #[rhai_fn(name = "pad", return_raw)] pub fn pad_with_string( - _ctx: NativeCallContext, + ctx: NativeCallContext, string: &mut ImmutableString, len: INT, padding: &str, ) -> Result<(), Box> { + let _ctx = ctx; + // Check if string will be over max size limit #[cfg(not(feature = "unchecked"))] if _ctx.engine().max_string_size() > 0 && len as usize > _ctx.engine().max_string_size() { diff --git a/src/packages/time_basic.rs b/src/packages/time_basic.rs index 0ef705c9..44961872 100644 --- a/src/packages/time_basic.rs +++ b/src/packages/time_basic.rs @@ -54,14 +54,14 @@ mod time_functions { #[rhai_fn(return_raw, name = "-")] pub fn time_diff( - timestamp: Instant, + timestamp1: Instant, timestamp2: Instant, ) -> Result> { #[cfg(not(feature = "no_float"))] - return Ok(if timestamp2 > timestamp { - -(timestamp2 - timestamp).as_secs_f64() as FLOAT + return Ok(if timestamp2 > timestamp1 { + -(timestamp2 - timestamp1).as_secs_f64() as FLOAT } else { - (timestamp - timestamp2).as_secs_f64() as FLOAT + (timestamp1 - timestamp2).as_secs_f64() as FLOAT } .into()); @@ -225,27 +225,27 @@ mod time_functions { } #[rhai_fn(name = "==")] - pub fn eq(timestamp: Instant, timestamp2: Instant) -> bool { - timestamp == timestamp2 + pub fn eq(timestamp1: Instant, timestamp2: Instant) -> bool { + timestamp1 == timestamp2 } #[rhai_fn(name = "!=")] - pub fn ne(timestamp: Instant, timestamp2: Instant) -> bool { - timestamp != timestamp2 + pub fn ne(timestamp1: Instant, timestamp2: Instant) -> bool { + timestamp1 != timestamp2 } #[rhai_fn(name = "<")] - pub fn lt(timestamp: Instant, timestamp2: Instant) -> bool { - timestamp < timestamp2 + pub fn lt(timestamp1: Instant, timestamp2: Instant) -> bool { + timestamp1 < timestamp2 } #[rhai_fn(name = "<=")] - pub fn lte(timestamp: Instant, timestamp2: Instant) -> bool { - timestamp <= timestamp2 + pub fn lte(timestamp1: Instant, timestamp2: Instant) -> bool { + timestamp1 <= timestamp2 } #[rhai_fn(name = ">")] - pub fn gt(timestamp: Instant, timestamp2: Instant) -> bool { - timestamp > timestamp2 + pub fn gt(timestamp1: Instant, timestamp2: Instant) -> bool { + timestamp1 > timestamp2 } #[rhai_fn(name = ">=")] - pub fn gte(timestamp: Instant, timestamp2: Instant) -> bool { - timestamp >= timestamp2 + pub fn gte(timestamp1: Instant, timestamp2: Instant) -> bool { + timestamp1 >= timestamp2 } } diff --git a/src/parse.rs b/src/parse.rs index 777020d8..4b132653 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -142,8 +142,9 @@ impl<'e> ParseState<'e> { /// /// Return `None` when the variable name is not found in the `stack`. #[inline] - pub fn access_var(&mut self, name: &str, _pos: Position) -> Option { + pub fn access_var(&mut self, name: &str, pos: Position) -> Option { let mut barrier = false; + let _pos = pos; let index = self .stack @@ -393,8 +394,10 @@ fn parse_paren_expr( input: &mut TokenStream, state: &mut ParseState, lib: &mut FunctionsLib, - mut settings: ParseSettings, + settings: ParseSettings, ) -> Result { + let mut settings = settings; + #[cfg(not(feature = "unchecked"))] settings.ensure_level_within_max_limit(state.max_expr_depth)?; @@ -428,7 +431,7 @@ fn parse_fn_call( lib: &mut FunctionsLib, id: Identifier, capture: bool, - mut namespace: Option, + namespace: Option, settings: ParseSettings, ) -> Result { #[cfg(not(feature = "unchecked"))] @@ -436,6 +439,7 @@ fn parse_fn_call( let (token, token_pos) = input.peek().expect(NEVER_ENDS); + let mut namespace = namespace; let mut args = StaticVec::new(); match token { @@ -565,8 +569,10 @@ fn parse_index_chain( state: &mut ParseState, lib: &mut FunctionsLib, lhs: Expr, - mut settings: ParseSettings, + settings: ParseSettings, ) -> Result { + let mut settings = settings; + #[cfg(not(feature = "unchecked"))] settings.ensure_level_within_max_limit(state.max_expr_depth)?; @@ -726,8 +732,10 @@ fn parse_array_literal( input: &mut TokenStream, state: &mut ParseState, lib: &mut FunctionsLib, - mut settings: ParseSettings, + settings: ParseSettings, ) -> Result { + let mut settings = settings; + #[cfg(not(feature = "unchecked"))] settings.ensure_level_within_max_limit(state.max_expr_depth)?; @@ -798,8 +806,10 @@ fn parse_map_literal( input: &mut TokenStream, state: &mut ParseState, lib: &mut FunctionsLib, - mut settings: ParseSettings, + settings: ParseSettings, ) -> Result { + let mut settings = settings; + #[cfg(not(feature = "unchecked"))] settings.ensure_level_within_max_limit(state.max_expr_depth)?; @@ -914,8 +924,10 @@ fn parse_switch( input: &mut TokenStream, state: &mut ParseState, lib: &mut FunctionsLib, - mut settings: ParseSettings, + settings: ParseSettings, ) -> Result { + let mut settings = settings; + #[cfg(not(feature = "unchecked"))] settings.ensure_level_within_max_limit(state.max_expr_depth)?; @@ -1059,8 +1071,10 @@ fn parse_primary( input: &mut TokenStream, state: &mut ParseState, lib: &mut FunctionsLib, - mut settings: ParseSettings, + settings: ParseSettings, ) -> Result { + let mut settings = settings; + #[cfg(not(feature = "unchecked"))] settings.ensure_level_within_max_limit(state.max_expr_depth)?; @@ -1439,8 +1453,10 @@ fn parse_unary( input: &mut TokenStream, state: &mut ParseState, lib: &mut FunctionsLib, - mut settings: ParseSettings, + settings: ParseSettings, ) -> Result { + let mut settings = settings; + let (token, token_pos) = input.peek().expect(NEVER_ENDS); settings.pos = *token_pos; @@ -1623,8 +1639,10 @@ fn parse_op_assignment_stmt( state: &mut ParseState, lib: &mut FunctionsLib, lhs: Expr, - mut settings: ParseSettings, + settings: ParseSettings, ) -> Result { + let mut settings = settings; + #[cfg(not(feature = "unchecked"))] settings.ensure_level_within_max_limit(state.max_expr_depth)?; @@ -1774,8 +1792,10 @@ fn parse_binary_op( lib: &mut FunctionsLib, parent_precedence: Option, lhs: Expr, - mut settings: ParseSettings, + settings: ParseSettings, ) -> Result { + let mut settings = settings; + #[cfg(not(feature = "unchecked"))] settings.ensure_level_within_max_limit(state.max_expr_depth)?; @@ -1955,11 +1975,12 @@ fn parse_custom_syntax( input: &mut TokenStream, state: &mut ParseState, lib: &mut FunctionsLib, - mut settings: ParseSettings, + settings: ParseSettings, key: &str, syntax: &CustomSyntax, pos: Position, ) -> Result { + let mut settings = settings; let mut keywords: StaticVec = Default::default(); let mut segments: StaticVec<_> = Default::default(); let mut tokens: StaticVec<_> = Default::default(); @@ -2101,8 +2122,10 @@ fn parse_expr( input: &mut TokenStream, state: &mut ParseState, lib: &mut FunctionsLib, - mut settings: ParseSettings, + settings: ParseSettings, ) -> Result { + let mut settings = settings; + #[cfg(not(feature = "unchecked"))] settings.ensure_level_within_max_limit(state.max_expr_depth)?; @@ -2144,8 +2167,10 @@ fn parse_if( input: &mut TokenStream, state: &mut ParseState, lib: &mut FunctionsLib, - mut settings: ParseSettings, + settings: ParseSettings, ) -> Result { + let mut settings = settings; + #[cfg(not(feature = "unchecked"))] settings.ensure_level_within_max_limit(state.max_expr_depth)?; @@ -2183,8 +2208,10 @@ fn parse_while_loop( input: &mut TokenStream, state: &mut ParseState, lib: &mut FunctionsLib, - mut settings: ParseSettings, + settings: ParseSettings, ) -> Result { + let mut settings = settings; + #[cfg(not(feature = "unchecked"))] settings.ensure_level_within_max_limit(state.max_expr_depth)?; @@ -2212,8 +2239,10 @@ fn parse_do( input: &mut TokenStream, state: &mut ParseState, lib: &mut FunctionsLib, - mut settings: ParseSettings, + settings: ParseSettings, ) -> Result { + let mut settings = settings; + #[cfg(not(feature = "unchecked"))] settings.ensure_level_within_max_limit(state.max_expr_depth)?; @@ -2254,8 +2283,10 @@ fn parse_for( input: &mut TokenStream, state: &mut ParseState, lib: &mut FunctionsLib, - mut settings: ParseSettings, + settings: ParseSettings, ) -> Result { + let mut settings = settings; + #[cfg(not(feature = "unchecked"))] settings.ensure_level_within_max_limit(state.max_expr_depth)?; @@ -2353,9 +2384,11 @@ fn parse_let( state: &mut ParseState, lib: &mut FunctionsLib, var_type: AccessMode, - export: bool, - mut settings: ParseSettings, + is_export: bool, + settings: ParseSettings, ) -> Result { + let mut settings = settings; + #[cfg(not(feature = "unchecked"))] settings.ensure_level_within_max_limit(state.max_expr_depth)?; @@ -2381,7 +2414,7 @@ fn parse_let( state.stack.push((name, var_type)); - let export = if export { + let export = if is_export { AST_OPTION_EXPORTED } else { AST_OPTION_NONE @@ -2406,8 +2439,10 @@ fn parse_import( input: &mut TokenStream, state: &mut ParseState, lib: &mut FunctionsLib, - mut settings: ParseSettings, + settings: ParseSettings, ) -> Result { + let mut settings = settings; + #[cfg(not(feature = "unchecked"))] settings.ensure_level_within_max_limit(state.max_expr_depth)?; @@ -2446,8 +2481,10 @@ fn parse_export( input: &mut TokenStream, state: &mut ParseState, lib: &mut FunctionsLib, - mut settings: ParseSettings, + settings: ParseSettings, ) -> Result { + let mut settings = settings; + #[cfg(not(feature = "unchecked"))] settings.ensure_level_within_max_limit(state.max_expr_depth)?; @@ -2518,8 +2555,10 @@ fn parse_block( input: &mut TokenStream, state: &mut ParseState, lib: &mut FunctionsLib, - mut settings: ParseSettings, + settings: ParseSettings, ) -> Result { + let mut settings = settings; + // Must start with { settings.pos = match input.next().expect(NEVER_ENDS) { (Token::LeftBrace, pos) => pos, @@ -2619,8 +2658,10 @@ fn parse_expr_stmt( input: &mut TokenStream, state: &mut ParseState, lib: &mut FunctionsLib, - mut settings: ParseSettings, + settings: ParseSettings, ) -> Result { + let mut settings = settings; + #[cfg(not(feature = "unchecked"))] settings.ensure_level_within_max_limit(state.max_expr_depth)?; @@ -2636,10 +2677,12 @@ fn parse_stmt( input: &mut TokenStream, state: &mut ParseState, lib: &mut FunctionsLib, - mut settings: ParseSettings, + settings: ParseSettings, ) -> Result { use AccessMode::{ReadOnly, ReadWrite}; + let mut settings = settings; + #[cfg(not(feature = "no_function"))] #[cfg(feature = "metadata")] let comments = { @@ -2836,8 +2879,10 @@ fn parse_try_catch( input: &mut TokenStream, state: &mut ParseState, lib: &mut FunctionsLib, - mut settings: ParseSettings, + settings: ParseSettings, ) -> Result { + let mut settings = settings; + #[cfg(not(feature = "unchecked"))] settings.ensure_level_within_max_limit(state.max_expr_depth)?; @@ -2892,11 +2937,13 @@ fn parse_fn( state: &mut ParseState, lib: &mut FunctionsLib, access: FnAccess, - mut settings: ParseSettings, + settings: ParseSettings, #[cfg(not(feature = "no_function"))] #[cfg(feature = "metadata")] comments: StaticVec, ) -> Result { + let mut settings = settings; + #[cfg(not(feature = "unchecked"))] settings.ensure_level_within_max_limit(state.max_expr_depth)?; @@ -3039,8 +3086,10 @@ fn parse_anon_fn( input: &mut TokenStream, state: &mut ParseState, lib: &mut FunctionsLib, - mut settings: ParseSettings, + settings: ParseSettings, ) -> Result<(Expr, ScriptFnDef), ParseError> { + let mut settings = settings; + #[cfg(not(feature = "unchecked"))] settings.ensure_level_within_max_limit(state.max_expr_depth)?; diff --git a/src/token.rs b/src/token.rs index cc425efd..3fd2d8b3 100644 --- a/src/token.rs +++ b/src/token.rs @@ -1266,11 +1266,12 @@ fn eat_next(stream: &mut impl InputStream, pos: &mut Position) -> Option { /// Scan for a block comment until the end. fn scan_block_comment( stream: &mut impl InputStream, - mut level: usize, + level: usize, pos: &mut Position, - mut comment: Option<&mut String>, + comment: Option<&mut String>, ) -> usize { - let comment = &mut comment; + let mut level = level; + let mut comment = comment; while let Some(c) = stream.get_next() { pos.advance();