Use into().

This commit is contained in:
Stephen Chung 2021-10-11 15:49:51 +08:00
parent 4908b58473
commit 90b6b15f15
4 changed files with 11 additions and 15 deletions

View File

@ -1959,12 +1959,11 @@ impl Engine {
- index - index
.checked_abs() .checked_abs()
.ok_or_else(|| { .ok_or_else(|| {
Box::new(EvalAltResult::ErrorArrayBounds(arr_len, index, idx_pos)) EvalAltResult::ErrorArrayBounds(arr_len, index, idx_pos).into()
}) })
.and_then(|n| { .and_then(|n| {
if n as usize > arr_len { if n as usize > arr_len {
Err(EvalAltResult::ErrorArrayBounds(arr_len, index, idx_pos) EvalAltResult::ErrorArrayBounds(arr_len, index, idx_pos).into()
.into())
} else { } else {
Ok(n as usize) Ok(n as usize)
} }

View File

@ -225,10 +225,7 @@ impl<T: AsRef<str>> From<T> for EvalAltResult {
impl<T: AsRef<str>> From<T> for Box<EvalAltResult> { impl<T: AsRef<str>> From<T> for Box<EvalAltResult> {
#[inline(always)] #[inline(always)]
fn from(err: T) -> Self { fn from(err: T) -> Self {
Box::new(EvalAltResult::ErrorRuntime( EvalAltResult::ErrorRuntime(err.as_ref().to_string().into(), Position::NONE).into()
err.as_ref().to_string().into(),
Position::NONE,
))
} }
} }

View File

@ -299,7 +299,7 @@ impl fmt::Display for ParseError {
impl From<ParseErrorType> for Box<EvalAltResult> { impl From<ParseErrorType> for Box<EvalAltResult> {
#[inline(always)] #[inline(always)]
fn from(err: ParseErrorType) -> Self { fn from(err: ParseErrorType) -> Self {
Box::new(err.into()) err.into()
} }
} }
@ -313,7 +313,7 @@ impl From<ParseErrorType> for EvalAltResult {
impl From<ParseError> for Box<EvalAltResult> { impl From<ParseError> for Box<EvalAltResult> {
#[inline(always)] #[inline(always)]
fn from(err: ParseError) -> Self { fn from(err: ParseError) -> Self {
Box::new(err.into()) err.into()
} }
} }

View File

@ -681,12 +681,12 @@ impl Engine {
return Ok(( return Ok((
if num_params < 0 { if num_params < 0 {
Dynamic::FALSE false
} else { } else {
let hash_script = calc_fn_hash(fn_name.as_str(), num_params as usize); let hash_script = calc_fn_hash(fn_name.as_str(), num_params as usize);
self.has_script_fn(Some(mods), state, lib, hash_script) self.has_script_fn(Some(mods), state, lib, hash_script)
.into() }
}, .into(),
false, false,
)); ));
} }
@ -1189,12 +1189,12 @@ impl Engine {
.map_err(|typ| self.make_type_mismatch_err::<crate::INT>(typ, arg_pos))?; .map_err(|typ| self.make_type_mismatch_err::<crate::INT>(typ, arg_pos))?;
return Ok(if num_params < 0 { return Ok(if num_params < 0 {
Dynamic::FALSE false
} else { } else {
let hash_script = calc_fn_hash(&fn_name, num_params as usize); let hash_script = calc_fn_hash(&fn_name, num_params as usize);
self.has_script_fn(Some(mods), state, lib, hash_script) self.has_script_fn(Some(mods), state, lib, hash_script)
.into() }
}); .into());
} }
// Handle is_def_var() // Handle is_def_var()