From d920613d57cc83e4b58107c0fe95f442fb7a8a88 Mon Sep 17 00:00:00 2001 From: John-John Tedro Date: Fri, 24 Jul 2020 19:10:07 +0200 Subject: [PATCH 1/4] Avoid shadowing call errors in get_indexed_mut --- src/engine.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/engine.rs b/src/engine.rs index cb7234d3..daa24844 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -1052,17 +1052,20 @@ impl Engine { #[cfg(not(feature = "no_index"))] _ => { - let type_name = self.map_type_name(val.type_name()); + let val_type_name = val.type_name(); let args = &mut [val, &mut idx]; self.exec_fn_call( state, lib, FN_IDX_GET, true, 0, args, is_ref, true, None, level, ) .map(|(v, _)| v.into()) - .map_err(|_| { - Box::new(EvalAltResult::ErrorIndexingType( - type_name.into(), - Position::none(), - )) + .map_err(|e| match *e { + EvalAltResult::ErrorFunctionNotFound(..) => { + Box::new(EvalAltResult::ErrorIndexingType( + self.map_type_name(val_type_name).into(), + Position::none(), + )) + } + _ => e, }) } From e7aaec8e3a686364a00045bd0c53661c37871050 Mon Sep 17 00:00:00 2001 From: John-John Tedro Date: Sat, 25 Jul 2020 09:14:29 +0200 Subject: [PATCH 2/4] Seal Variant trait to prevent downstream implementations --- src/any.rs | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/any.rs b/src/any.rs index 7f637187..202afa24 100644 --- a/src/any.rs +++ b/src/any.rs @@ -30,12 +30,24 @@ use crate::stdlib::time::Instant; #[cfg(target_arch = "wasm32")] use instant::Instant; +mod private { + use crate::fn_native::SendSync; + use crate::stdlib::any::Any; + + /// A sealed trait that prevents other crates from implementing [Variant]. + /// + /// [Variant]: super::Variant + pub trait Sealed {} + + impl Sealed for T {} +} + /// Trait to represent any type. /// /// Currently, `Variant` is not `Send` nor `Sync`, so it can practically be any type. /// Turn on the `sync` feature to restrict it to only types that implement `Send + Sync`. #[cfg(not(feature = "sync"))] -pub trait Variant: Any { +pub trait Variant: Any + private::Sealed { /// Convert this `Variant` trait object to `&dyn Any`. fn as_any(&self) -> &dyn Any; @@ -53,10 +65,6 @@ pub trait Variant: Any { /// Clone into `Dynamic`. fn clone_into_dynamic(&self) -> Dynamic; - - /// This trait may only be implemented by `rhai`. - #[doc(hidden)] - fn _closed(&self) -> _Private; } /// Trait to represent any type. @@ -64,7 +72,7 @@ pub trait Variant: Any { /// `From<_>` is implemented for `i64` (`i32` if `only_i32`), `f64` (if not `no_float`), /// `bool`, `String`, `char`, `Vec` (into `Array`) and `HashMap` (into `Map`). #[cfg(feature = "sync")] -pub trait Variant: Any + Send + Sync { +pub trait Variant: Any + Send + Sync + private::Sealed { /// Convert this `Variant` trait object to `&dyn Any`. fn as_any(&self) -> &dyn Any; @@ -82,10 +90,6 @@ pub trait Variant: Any + Send + Sync { /// Clone into `Dynamic`. fn clone_into_dynamic(&self) -> Dynamic; - - /// This trait may only be implemented by `rhai`. - #[doc(hidden)] - fn _closed(&self) -> _Private; } impl Variant for T { @@ -107,9 +111,6 @@ impl Variant for T { fn clone_into_dynamic(&self) -> Dynamic { Dynamic::from(self.clone()) } - fn _closed(&self) -> _Private { - _Private - } } impl dyn Variant { From 261273bac3138b3ce84a478df834dc264d43d316 Mon Sep 17 00:00:00 2001 From: John-John Tedro Date: Sat, 25 Jul 2020 09:14:39 +0200 Subject: [PATCH 3/4] Unbreak no_std --- src/fn_native.rs | 1 + src/parser.rs | 2 +- src/syntax.rs | 3 ++- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/fn_native.rs b/src/fn_native.rs index f4de5982..a113db4b 100644 --- a/src/fn_native.rs +++ b/src/fn_native.rs @@ -5,6 +5,7 @@ use crate::engine::Engine; use crate::module::{FuncReturn, Module}; use crate::parser::ScriptFnDef; use crate::result::EvalAltResult; +use crate::stdlib::vec::Vec; use crate::token::{is_valid_identifier, Position}; use crate::utils::{ImmutableString, StaticVec}; use crate::Scope; diff --git a/src/parser.rs b/src/parser.rs index b6a3fa08..643c7aa9 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -592,7 +592,7 @@ impl fmt::Debug for CustomExpr { } impl Hash for CustomExpr { - fn hash(&self, state: &mut H) { + fn hash(&self, state: &mut H) { self.0.hash(state); } } diff --git a/src/syntax.rs b/src/syntax.rs index 485e99ea..616833c1 100644 --- a/src/syntax.rs +++ b/src/syntax.rs @@ -12,7 +12,8 @@ use crate::token::{is_valid_identifier, Position, Token}; use crate::utils::StaticVec; use crate::stdlib::{ - fmt, + boxed::Box, + fmt, format, rc::Rc, string::{String, ToString}, sync::Arc, From be86927bc5b566e07e01dab851958c75e8b21caf Mon Sep 17 00:00:00 2001 From: John-John Tedro Date: Sat, 25 Jul 2020 09:19:21 +0200 Subject: [PATCH 4/4] Use bash syntax to check value of TRAVIS_RUST_VERSION --- .ci/build.sh | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.ci/build.sh b/.ci/build.sh index 20c75afa..fb0e7e04 100755 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -5,9 +5,7 @@ set -ex cargo build --verbose cargo test --verbose -if [ "$TRAVIS_RUST_VERSION" = "nightly" ] -then +if [[ $TRAVIS_RUST_VERSION == "nightly" ]]; then cargo build --verbose --features no_std cargo test --verbose --features no_std fi -