diff --git a/src/module/resolvers/file.rs b/src/module/resolvers/file.rs index 25f196f2..441114f3 100644 --- a/src/module/resolvers/file.rs +++ b/src/module/resolvers/file.rs @@ -345,17 +345,19 @@ impl ModuleResolver for FileModuleResolver { let file_path = self.get_file_path(path, source_path); // Load the script file and compile it - match engine.compile_file(file_path).map_err(|err| match *err { - EvalAltResult::ErrorSystem(_, err) if err.is::() => { - Box::new(EvalAltResult::ErrorModuleNotFound(path.to_string(), pos)) - } - _ => Box::new(EvalAltResult::ErrorInModule(path.to_string(), err, pos)), - }) { - Ok(mut ast) => { - ast.set_source(path); - Some(Ok(ast)) - } - err => Some(err), - } + Some( + engine + .compile_file(file_path) + .map(|mut ast| { + ast.set_source(path); + ast + }) + .map_err(|err| match *err { + EvalAltResult::ErrorSystem(_, err) if err.is::() => { + EvalAltResult::ErrorModuleNotFound(path.to_string(), pos).into() + } + _ => EvalAltResult::ErrorInModule(path.to_string(), err, pos).into(), + }), + ) } } diff --git a/src/packages/iter_basic.rs b/src/packages/iter_basic.rs index c4b51b1a..835030fe 100644 --- a/src/packages/iter_basic.rs +++ b/src/packages/iter_basic.rs @@ -27,10 +27,11 @@ where return EvalAltResult::ErrorInFunctionCall( "range".to_string(), Default::default(), - Box::new(EvalAltResult::ErrorArithmetic( + EvalAltResult::ErrorArithmetic( "step value cannot be zero".to_string(), crate::Position::NONE, - )), + ) + .into(), crate::Position::NONE, ) .into(); @@ -314,7 +315,7 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, { #[cfg(not(feature = "unchecked"))] if step == 0.0 { return EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(), - Box::new(EvalAltResult::ErrorArithmetic("step value cannot be zero".to_string(), crate::Position::NONE)), + EvalAltResult::ErrorArithmetic("step value cannot be zero".to_string(), crate::Position::NONE).into(), crate::Position::NONE, ).into(); } @@ -376,7 +377,7 @@ def_package!(crate:BasicIteratorPackage:"Basic range iterators.", lib, { #[cfg(not(feature = "unchecked"))] if step.is_zero() { return EvalAltResult::ErrorInFunctionCall("range".to_string(), "".to_string(), - Box::new(EvalAltResult::ErrorArithmetic("step value cannot be zero".to_string(), crate::Position::NONE)), + EvalAltResult::ErrorArithmetic("step value cannot be zero".to_string(), crate::Position::NONE).into(), crate::Position::NONE, ).into(); } diff --git a/src/packages/lang_core.rs b/src/packages/lang_core.rs index e20f76db..26d4c5b0 100644 --- a/src/packages/lang_core.rs +++ b/src/packages/lang_core.rs @@ -14,7 +14,7 @@ mod core_functions { #[rhai_fn(name = "set_tag", set = "tag", return_raw)] pub fn set_tag(value: &mut Dynamic, tag: INT) -> Result<(), Box> { if tag < Tag::MIN as INT { - Err(Box::new(EvalAltResult::ErrorArithmetic( + EvalAltResult::ErrorArithmetic( format!( "{} is too small to fit into a tag (must be between {} and {})", tag, @@ -22,9 +22,10 @@ mod core_functions { Tag::MAX ), Position::NONE, - ))) + ) + .into() } else if tag > Tag::MAX as INT { - Err(Box::new(EvalAltResult::ErrorArithmetic( + EvalAltResult::ErrorArithmetic( format!( "{} is too large to fit into a tag (must be between {} and {})", tag, @@ -32,7 +33,8 @@ mod core_functions { Tag::MAX ), Position::NONE, - ))) + ) + .into() } else { value.set_tag(tag as Tag); Ok(()) diff --git a/tests/syntax.rs b/tests/syntax.rs index a0ce0ab8..8c44ae4b 100644 --- a/tests/syntax.rs +++ b/tests/syntax.rs @@ -130,13 +130,9 @@ fn test_custom_syntax_raw() -> Result<(), Box> { 1 => Ok(Some("$ident$".into())), 2 => match stream[1].as_str() { "world" | "kitty" => Ok(None), - s => Err(ParseError( - Box::new(ParseErrorType::BadInput(LexError::ImproperSymbol( - s.to_string(), - Default::default(), - ))), - Position::NONE, - )), + s => Err(LexError::ImproperSymbol(s.to_string(), Default::default()) + .into_err(Position::NONE) + .into()), }, _ => unreachable!(), },