diff --git a/src/ast.rs b/src/ast.rs index 4414464e..6df1f3c9 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -1498,12 +1498,12 @@ impl fmt::Debug for FnCallHashes { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { if let Some(script) = self.script { if script == self.native { - write!(f, "({}=={})", script, self.native) + fmt::Debug::fmt(&self.native, f) } else { write!(f, "({}, {})", script, self.native) } } else { - write!(f, "{}", self.native) + write!(f, "{} (native only)", self.native) } } } diff --git a/src/engine.rs b/src/engine.rs index 7b0faa6b..a795a1ee 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -95,7 +95,7 @@ impl Imports { .iter() .enumerate() .rev() - .find_map(|(i, key)| if *key == name { Some(i) } else { None }) + .find_map(|(i, key)| if key == name { Some(i) } else { None }) } /// Push an imported [modules][Module] onto the stack. #[inline(always)] diff --git a/src/fn_call.rs b/src/fn_call.rs index 932d0019..a0310c0c 100644 --- a/src/fn_call.rs +++ b/src/fn_call.rs @@ -142,7 +142,7 @@ impl Engine { .map(|a| if a.is::() { "&str | ImmutableString | String" } else { - self.map_type_name((*a).type_name()) + self.map_type_name(a.type_name()) }) .collect::>() .join(", ") @@ -171,8 +171,10 @@ impl Engine { is_op_assignment: bool, ) -> &'s Option> { let mut hash = args.as_ref().map_or(hash_script, |args| { - let hash_params = calc_fn_params_hash(args.iter().map(|a| a.type_id())); - combine_hashes(hash_script, hash_params) + combine_hashes( + hash_script, + calc_fn_params_hash(args.iter().map(|a| a.type_id())), + ) }); &*state @@ -188,43 +190,17 @@ impl Engine { let mut bitmask = 1usize; // Bitmask of which parameter to replace with `Dynamic` loop { - let func = lib - .iter() - .find_map(|m| { - m.get_fn(hash).cloned().map(|func| { - let source = m.id_raw().cloned(); - FnResolutionCacheEntry { func, source } - }) - }) - .or_else(|| { - self.global_namespace - .get_fn(hash) - .cloned() - .map(|func| FnResolutionCacheEntry { func, source: None }) - }) - .or_else(|| { - self.global_modules.iter().find_map(|m| { - m.get_fn(hash).cloned().map(|func| { - let source = m.id_raw().cloned(); - FnResolutionCacheEntry { func, source } - }) - }) - }) - .or_else(|| { - mods.get_fn(hash).map(|(func, source)| { - let func = func.clone(); - let source = source.cloned(); - FnResolutionCacheEntry { func, source } - }) - }) - .or_else(|| { - self.global_sub_modules.values().find_map(|m| { - m.get_qualified_fn(hash).cloned().map(|func| { - let source = m.id_raw().cloned(); - FnResolutionCacheEntry { func, source } - }) - }) - }); + let func = lib.iter().find_map(|m| m.get_fn(hash).cloned().map(|func| FnResolutionCacheEntry { + func, source: m.id_raw().cloned() + })).or_else(|| self.global_namespace.get_fn(hash).cloned().map(|func| FnResolutionCacheEntry { + func, source: None + })).or_else(|| self.global_modules.iter().find_map(|m| m.get_fn(hash).cloned().map(|func| FnResolutionCacheEntry { + func, source: m.id_raw().cloned() + }))).or_else(|| mods.get_fn(hash).map(|(func, source)| FnResolutionCacheEntry { + func: func.clone(), source: source.cloned() + })).or_else(|| self.global_sub_modules.values().find_map(|m| m.get_qualified_fn(hash).cloned().map(|func| FnResolutionCacheEntry { + func, source: m.id_raw().cloned() + }))); match func { // Specific version found @@ -239,23 +215,17 @@ impl Engine { return args.and_then(|args| { if !is_op_assignment { get_builtin_binary_op_fn(fn_name, &args[0], &args[1]).map(|f| { - let func = CallableFunction::from_method( + FnResolutionCacheEntry { func: CallableFunction::from_method( Box::new(f) as Box - ); - FnResolutionCacheEntry { func, source: None } + ), source: None } }) } else { let (first, second) = args.split_first() .expect("never fails because an op-assignment must have two arguments"); - get_builtin_op_assignment_fn(fn_name, *first, second[0]).map( - |f| { - let func = CallableFunction::from_method( - Box::new(f) as Box - ); - FnResolutionCacheEntry { func, source: None } - }, - ) + get_builtin_op_assignment_fn(fn_name, *first, second[0]).map(|f| FnResolutionCacheEntry { + func: CallableFunction::from_method(Box::new(f) as Box), source: None + }) } .map(Box::new) }); @@ -437,11 +407,10 @@ impl Engine { } // Raise error - _ => EvalAltResult::ErrorFunctionNotFound( - self.gen_call_signature(None, name, args.as_ref()), - pos, - ) - .into(), + _ => { + EvalAltResult::ErrorFunctionNotFound(self.gen_call_signature(None, name, args), pos) + .into() + } } } @@ -1451,7 +1420,7 @@ impl Engine { Some(f) => unreachable!("unknown function type: {:?}", f), None => EvalAltResult::ErrorFunctionNotFound( - self.gen_call_signature(Some(namespace), fn_name, args.as_ref()), + self.gen_call_signature(Some(namespace), fn_name, &args), pos, ) .into(), diff --git a/src/parse.rs b/src/parse.rs index 890db0cf..ece916a4 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -191,7 +191,7 @@ impl<'e> ParseState<'e> { .iter() .rev() .enumerate() - .find(|&(_, n)| *n == name) + .find(|&(_, n)| n == name) .and_then(|(i, _)| NonZeroUsize::new(i + 1)) } @@ -1070,8 +1070,8 @@ fn parse_primary( let (expr, func) = parse_anon_fn(input, &mut new_state, lib, settings)?; #[cfg(not(feature = "no_closure"))] - new_state.external_vars.iter().for_each(|(closure, pos)| { - state.access_var(closure, *pos); + new_state.external_vars.iter().for_each(|(closure, &pos)| { + state.access_var(closure, pos); }); let hash_script = calc_fn_hash(&func.name, func.params.len()); diff --git a/src/scope.rs b/src/scope.rs index 8f6138eb..513a9e89 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -448,7 +448,7 @@ impl<'a> Scope<'a> { .1 .as_mut() .expect("never fails because the list is initialized"); - if !list.iter().any(|a| &alias == a) { + if !list.iter().any(|a| a == &alias) { list.push(alias); } self