Use turbofish notation.

This commit is contained in:
Stephen Chung 2022-02-08 21:28:15 +08:00
parent 83b213b086
commit 8cf6f424a5
4 changed files with 27 additions and 25 deletions

View File

@ -477,9 +477,11 @@ impl Stmt {
| Self::Expr(..) | Self::Expr(..)
| Self::FnCall(..) => true, | Self::FnCall(..) => true,
Self::Noop(..) | Self::While(..) | Self::Do(..) | Self::For(..) | Self::TryCatch(..) => { Self::Noop(..)
false | Self::While(..)
} | Self::Do(..)
| Self::For(..)
| Self::TryCatch(..) => false,
Self::Var(..) | Self::Assignment(..) | Self::BreakLoop(..) | Self::Return(..) => false, Self::Var(..) | Self::Assignment(..) | Self::BreakLoop(..) | Self::Return(..) => false,

View File

@ -4,7 +4,9 @@
use super::{EvalState, GlobalRuntimeState, Target}; use super::{EvalState, GlobalRuntimeState, Target};
use crate::ast::{Expr, OpAssignment}; use crate::ast::{Expr, OpAssignment};
use crate::types::dynamic::Union; use crate::types::dynamic::Union;
use crate::{Dynamic, Engine, Module, Position, RhaiResult, RhaiResultOf, Scope, StaticVec, ERR}; use crate::{
Dynamic, Engine, Module, Position, RhaiError, RhaiResult, RhaiResultOf, Scope, StaticVec, ERR,
};
use std::hash::Hash; use std::hash::Hash;
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;
@ -733,7 +735,7 @@ impl Engine {
let (values, pos) = args.iter().try_fold( let (values, pos) = args.iter().try_fold(
(crate::FnArgsVec::with_capacity(args.len()), Position::NONE), (crate::FnArgsVec::with_capacity(args.len()), Position::NONE),
|(mut values, mut pos), expr| -> RhaiResultOf<_> { |(mut values, mut pos), expr| {
let (value, arg_pos) = self.get_arg_value( let (value, arg_pos) = self.get_arg_value(
scope, global, state, lib, this_ptr, expr, constants, level, scope, global, state, lib, this_ptr, expr, constants, level,
)?; )?;
@ -741,7 +743,7 @@ impl Engine {
pos = arg_pos; pos = arg_pos;
} }
values.push(value.flatten()); values.push(value.flatten());
Ok((values, pos)) Ok::<_, RhaiError>((values, pos))
}, },
)?; )?;
@ -779,7 +781,7 @@ impl Engine {
let (values, pos) = args.iter().try_fold( let (values, pos) = args.iter().try_fold(
(crate::FnArgsVec::with_capacity(args.len()), Position::NONE), (crate::FnArgsVec::with_capacity(args.len()), Position::NONE),
|(mut values, mut pos), expr| -> RhaiResultOf<_> { |(mut values, mut pos), expr| {
let (value, arg_pos) = self.get_arg_value( let (value, arg_pos) = self.get_arg_value(
scope, global, state, lib, this_ptr, expr, constants, level, scope, global, state, lib, this_ptr, expr, constants, level,
)?; )?;
@ -787,7 +789,7 @@ impl Engine {
pos = arg_pos pos = arg_pos
} }
values.push(value.flatten()); values.push(value.flatten());
Ok((values, pos)) Ok::<_, RhaiError>((values, pos))
}, },
)?; )?;
super::ChainArgument::from_fn_call_args(values, pos) super::ChainArgument::from_fn_call_args(values, pos)

View File

@ -12,8 +12,8 @@ use crate::engine::{
use crate::eval::{EvalState, GlobalRuntimeState}; use crate::eval::{EvalState, GlobalRuntimeState};
use crate::{ use crate::{
calc_fn_hash, calc_fn_params_hash, combine_hashes, Dynamic, Engine, FnArgsVec, FnPtr, calc_fn_hash, calc_fn_params_hash, combine_hashes, Dynamic, Engine, FnArgsVec, FnPtr,
Identifier, ImmutableString, Module, OptimizationLevel, Position, RhaiResult, RhaiResultOf, Identifier, ImmutableString, Module, OptimizationLevel, Position, RhaiError, RhaiResult,
Scope, ERR, RhaiResultOf, Scope, ERR,
}; };
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;
@ -1079,15 +1079,12 @@ impl Engine {
let (name, fn_curry) = arg_value.cast::<FnPtr>().take_data(); let (name, fn_curry) = arg_value.cast::<FnPtr>().take_data();
// Append the new curried arguments to the existing list. // Append the new curried arguments to the existing list.
let fn_curry = let fn_curry = a_expr.iter().try_fold(fn_curry, |mut curried, expr| {
a_expr
.iter()
.try_fold(fn_curry, |mut curried, expr| -> RhaiResultOf<_> {
let (value, ..) = self.get_arg_value( let (value, ..) = self.get_arg_value(
scope, global, state, lib, this_ptr, expr, constants, level, scope, global, state, lib, this_ptr, expr, constants, level,
)?; )?;
curried.push(value); curried.push(value);
Ok(curried) Ok::<_, RhaiError>(curried)
})?; })?;
return Ok(FnPtr::new_unchecked(name, fn_curry).into()); return Ok(FnPtr::new_unchecked(name, fn_curry).into());

View File

@ -1264,8 +1264,10 @@ fn parse_primary(
let (expr, func) = parse_anon_fn(input, &mut new_state, lib, new_settings)?; let (expr, func) = parse_anon_fn(input, &mut new_state, lib, new_settings)?;
#[cfg(not(feature = "no_closure"))] #[cfg(not(feature = "no_closure"))]
new_state.external_vars.iter().try_for_each( new_state
|crate::ast::Ident { name, pos }| -> ParseResult<_> { .external_vars
.iter()
.try_for_each(|crate::ast::Ident { name, pos }| {
let index = state.access_var(name, *pos); let index = state.access_var(name, *pos);
if settings.strict_var && !settings.is_closure && index.is_none() { if settings.strict_var && !settings.is_closure && index.is_none() {
@ -1274,10 +1276,9 @@ fn parse_primary(
// Under Strict Variables mode, this is not allowed. // Under Strict Variables mode, this is not allowed.
Err(PERR::VariableUndefined(name.to_string()).into_err(*pos)) Err(PERR::VariableUndefined(name.to_string()).into_err(*pos))
} else { } else {
Ok(()) Ok::<_, ParseError>(())
} }
}, })?;
)?;
let hash_script = calc_fn_hash(&func.name, func.params.len()); let hash_script = calc_fn_hash(&func.name, func.params.len());
lib.insert(hash_script, func.into()); lib.insert(hash_script, func.into());