diff --git a/src/eval/chaining.rs b/src/eval/chaining.rs index 1e1e8de5..ba946764 100644 --- a/src/eval/chaining.rs +++ b/src/eval/chaining.rs @@ -550,11 +550,12 @@ impl Engine { level: usize, new_val: Option<(Dynamic, OpAssignment)>, ) -> RhaiResult { - let (crate::ast::BinaryExpr { lhs, rhs }, chain_type, options, op_pos) = match expr { + let chain_type = ChainType::from(expr); + let (crate::ast::BinaryExpr { lhs, rhs }, options, op_pos) = match expr { #[cfg(not(feature = "no_index"))] - Expr::Index(x, options, pos) => (x.as_ref(), ChainType::Indexing, *options, *pos), + Expr::Index(x, options, pos) => (x.as_ref(), *options, *pos), #[cfg(not(feature = "no_object"))] - Expr::Dot(x, options, pos) => (x.as_ref(), ChainType::Dotting, *options, *pos), + Expr::Dot(x, options, pos) => (x.as_ref(), *options, *pos), expr => unreachable!("Expr::Index or Expr::Dot expected but gets {:?}", expr), }; @@ -677,7 +678,7 @@ impl Engine { { let crate::ast::BinaryExpr { lhs, rhs, .. } = x.as_ref(); - let mut arg_values = FnArgsVec::new(); + let mut _arg_values = FnArgsVec::new_const(); // Evaluate in left-to-right order match lhs { @@ -690,7 +691,7 @@ impl Engine { if _parent_chain_type == ChainType::Dotting && !x.is_qualified() => { for arg_expr in x.args.as_ref() { - arg_values.push( + _arg_values.push( self.get_arg_value( scope, global, caches, lib, this_ptr, arg_expr, level, )? @@ -709,7 +710,7 @@ impl Engine { } #[cfg(not(feature = "no_index"))] _ if _parent_chain_type == ChainType::Indexing => { - arg_values.push( + _arg_values.push( self.eval_expr(scope, global, caches, lib, this_ptr, lhs, level)? .flatten(), ); @@ -725,7 +726,9 @@ impl Engine { size, level, )?; - idx_values.extend(arg_values); + if !_arg_values.is_empty() { + idx_values.extend(_arg_values); + } } #[cfg(not(feature = "no_object"))] diff --git a/src/eval/target.rs b/src/eval/target.rs index a2c4d34c..10456439 100644 --- a/src/eval/target.rs +++ b/src/eval/target.rs @@ -273,7 +273,7 @@ impl<'a> Target<'a> { /// Propagate a changed value back to the original source. /// This has no effect for direct references. #[inline] - pub fn propagate_changed_value(&mut self, pos: Position) -> RhaiResultOf<()> { + pub fn propagate_changed_value(&mut self, _pos: Position) -> RhaiResultOf<()> { match self { Self::RefMut(..) | Self::TempValue(..) => (), #[cfg(not(feature = "no_closure"))] @@ -285,7 +285,7 @@ impl<'a> Target<'a> { Box::new(crate::ERR::ErrorMismatchDataType( "bool".to_string(), err.to_string(), - pos, + _pos, )) })?; @@ -315,7 +315,7 @@ impl<'a> Target<'a> { Box::new(crate::ERR::ErrorMismatchDataType( "integer".to_string(), err.to_string(), - pos, + _pos, )) })?; @@ -336,7 +336,7 @@ impl<'a> Target<'a> { Box::new(crate::ERR::ErrorMismatchDataType( "INT".to_string(), err.to_string(), - pos, + _pos, )) })?; @@ -361,7 +361,7 @@ impl<'a> Target<'a> { Box::new(crate::ERR::ErrorMismatchDataType( "char".to_string(), err.to_string(), - pos, + _pos, )) })?; diff --git a/src/func/call.rs b/src/func/call.rs index 6cee575e..62f92c0b 100644 --- a/src/func/call.rs +++ b/src/func/call.rs @@ -904,8 +904,8 @@ impl Engine { _ => { let mut fn_name = fn_name; let _redirected; + let mut _arg_values: FnArgsVec<_>; let mut call_args = call_args; - let mut arg_values: FnArgsVec<_>; // Check if it is a map method call in OOP style #[cfg(not(feature = "no_object"))] @@ -917,13 +917,13 @@ impl Engine { fn_name = &_redirected; // Add curried arguments if fn_ptr.is_curried() { - arg_values = fn_ptr + _arg_values = fn_ptr .curry() .iter() .cloned() .chain(call_args.iter_mut().map(mem::take)) .collect(); - call_args = &mut arg_values; + call_args = &mut _arg_values; } // Recalculate the hash based on the new function name and new arguments hash = FnCallHashes::from_all( diff --git a/src/func/register.rs b/src/func/register.rs index 5b08ab31..99e460f3 100644 --- a/src/func/register.rs +++ b/src/func/register.rs @@ -134,9 +134,9 @@ macro_rules! def_register { #[cfg(feature = "metadata")] #[inline(always)] fn return_type() -> TypeId { TypeId::of::() } #[cfg(feature = "metadata")] #[inline(always)] fn return_type_name() -> &'static str { std::any::type_name::() } #[inline(always)] fn into_callable_function(self) -> CallableFunction { - CallableFunction::$abi(Box::new(move |ctx: NativeCallContext, args: &mut FnCallArgs| { + CallableFunction::$abi(Box::new(move |_ctx: NativeCallContext, args: &mut FnCallArgs| { // The arguments are assumed to be of the correct number and types! - check_constant!(ctx, args); + check_constant!(_ctx, args); let mut _drain = args.iter_mut(); $($let $par = ($clone)(_drain.next().expect(EXPECT_ARGS)); )* @@ -186,9 +186,9 @@ macro_rules! def_register { #[cfg(feature = "metadata")] #[inline(always)] fn return_type() -> TypeId { TypeId::of::>() } #[cfg(feature = "metadata")] #[inline(always)] fn return_type_name() -> &'static str { std::any::type_name::>() } #[inline(always)] fn into_callable_function(self) -> CallableFunction { - CallableFunction::$abi(Box::new(move |ctx: NativeCallContext, args: &mut FnCallArgs| { + CallableFunction::$abi(Box::new(move |_ctx: NativeCallContext, args: &mut FnCallArgs| { // The arguments are assumed to be of the correct number and types! - check_constant!(ctx, args); + check_constant!(_ctx, args); let mut _drain = args.iter_mut(); $($let $par = ($clone)(_drain.next().expect(EXPECT_ARGS)); )* diff --git a/src/lib.rs b/src/lib.rs index 8cd8b472..129b1f84 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -130,6 +130,7 @@ const INT_BITS: usize = std::mem::size_of::() * 8; /// Number of bytes that make up an [`INT`]. /// /// It is 8 unless the `only_i32` feature is enabled when it will be 4. +#[cfg(not(feature = "no_index"))] const INT_BYTES: usize = std::mem::size_of::(); /// The system floating-point type. It is defined as [`f64`]. @@ -155,6 +156,7 @@ pub type FLOAT = f32; /// /// 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"))] const FLOAT_BYTES: usize = std::mem::size_of::(); /// An exclusive integer range. diff --git a/src/optimizer.rs b/src/optimizer.rs index fe3e9101..bf5f5e1e 100644 --- a/src/optimizer.rs +++ b/src/optimizer.rs @@ -10,7 +10,7 @@ use crate::tokenizer::{Span, Token}; use crate::types::dynamic::AccessMode; use crate::{ calc_fn_hash, calc_fn_params_hash, combine_hashes, Dynamic, Engine, FnPtr, Identifier, - Position, Scope, StaticVec, AST, INT, INT_BITS, + Position, Scope, StaticVec, AST, INT, }; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -966,16 +966,16 @@ fn optimize_expr(expr: &mut Expr, state: &mut OptimizerState, _chaining: bool) { .unwrap_or_else(|| Expr::Unit(*pos)); } // int[int] - (Expr::IntegerConstant(n, pos), Expr::IntegerConstant(i, ..)) if *i >= 0 && (*i as usize) < INT_BITS => { + (Expr::IntegerConstant(n, pos), Expr::IntegerConstant(i, ..)) if *i >= 0 && (*i as usize) < crate::INT_BITS => { // Bit-field literal indexing - get the bit state.set_dirty(); *expr = Expr::BoolConstant((*n & (1 << (*i as usize))) != 0, *pos); } // int[-int] - (Expr::IntegerConstant(n, pos), Expr::IntegerConstant(i, ..)) if *i < 0 && i.checked_abs().map(|i| i as usize <= INT_BITS).unwrap_or(false) => { + (Expr::IntegerConstant(n, pos), Expr::IntegerConstant(i, ..)) if *i < 0 && i.checked_abs().map(|i| i as usize <= crate::INT_BITS).unwrap_or(false) => { // Bit-field literal indexing - get the bit state.set_dirty(); - *expr = Expr::BoolConstant((*n & (1 << (INT_BITS - i.abs() as usize))) != 0, *pos); + *expr = Expr::BoolConstant((*n & (1 << (crate::INT_BITS - i.abs() as usize))) != 0, *pos); } // string[int] (Expr::StringConstant(s, pos), Expr::IntegerConstant(i, ..)) if *i >= 0 && (*i as usize) < s.chars().count() => { diff --git a/src/parser.rs b/src/parser.rs index b25073f7..d689ce83 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -2904,7 +2904,7 @@ impl Engine { } }; - let mut statements = StaticVec::new(); + let mut statements = StaticVec::new_const(); let prev_entry_stack_len = state.block_stack_len; state.block_stack_len = state.stack.len();