diff --git a/src/engine.rs b/src/engine.rs index 301bbfca..6245d1cc 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -173,11 +173,8 @@ impl FunctionsLib { vec.into_iter() .map(|fn_def| { // Qualifiers (none) + function name + placeholders (one for each parameter). - let hash = calc_fn_hash( - empty(), - &fn_def.name, - repeat(EMPTY_TYPE_ID()).take(fn_def.params.len()), - ); + let args_iter = repeat(EMPTY_TYPE_ID()).take(fn_def.params.len()); + let hash = calc_fn_hash(empty(), &fn_def.name, args_iter); #[cfg(feature = "sync")] { @@ -284,11 +281,9 @@ pub struct Engine { pub(crate) packages: PackagesCollection, /// A collection of all library packages loaded into the engine. pub(crate) base_package: PackageStore, - /// A module resolution service. #[cfg(not(feature = "no_module"))] pub(crate) module_resolver: Option>, - /// A hashmap mapping type names to pretty-print names. pub(crate) type_names: HashMap, @@ -299,7 +294,6 @@ pub struct Engine { /// Optimize the AST after compilation. pub(crate) optimization_level: OptimizationLevel, - /// Maximum levels of call-stack to prevent infinite recursion. /// /// Defaults to 28 for debug builds and 256 for non-debug builds. diff --git a/src/error.rs b/src/error.rs index ee3f87f7..11b7c9e2 100644 --- a/src/error.rs +++ b/src/error.rs @@ -122,7 +122,7 @@ impl ParseErrorType { } /// Error when parsing a script. -#[derive(Debug, PartialEq, Eq, Clone, Hash)] +#[derive(Debug, Eq, PartialEq, Clone, Hash)] pub struct ParseError(pub(crate) ParseErrorType, pub(crate) Position); impl ParseError { diff --git a/src/fn_native.rs b/src/fn_native.rs index bfc9311b..12134550 100644 --- a/src/fn_native.rs +++ b/src/fn_native.rs @@ -70,7 +70,7 @@ pub trait IteratorCallback: Fn(Dynamic) -> Box> + ' impl Box> + 'static> IteratorCallback for F {} /// A type representing the type of ABI of a native Rust function. -#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq)] +#[derive(Debug, Eq, PartialEq, Clone, Copy, Hash)] pub enum NativeFunctionABI { /// A pure function where all arguments are passed by value. Pure, diff --git a/src/module.rs b/src/module.rs index 089acd3d..f86b2dca 100644 --- a/src/module.rs +++ b/src/module.rs @@ -757,7 +757,7 @@ mod file { /// let mut engine = Engine::new(); /// engine.set_module_resolver(Some(resolver)); /// ``` - #[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)] + #[derive(Debug, Eq, PartialEq, PartialOrd, Ord, Clone, Hash)] pub struct FileModuleResolver { path: PathBuf, extension: String, @@ -875,7 +875,7 @@ mod file { /// /// A `StaticVec` is used because most module-level access contains only one level, /// and it is wasteful to always allocate a `Vec` with one element. -#[derive(Clone, Hash, Default)] +#[derive(Clone, Eq, PartialEq, Hash, Default)] pub struct ModuleRef(StaticVec<(String, Position)>, Option); impl fmt::Debug for ModuleRef { diff --git a/src/parser.rs b/src/parser.rs index da35d62d..8264da56 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -13,7 +13,7 @@ use crate::utils::EMPTY_TYPE_ID; use crate::module::ModuleRef; #[cfg(feature = "no_module")] -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Eq, PartialEq, Clone, Hash, Copy, Default)] pub struct ModuleRef; use crate::stdlib::{ @@ -179,7 +179,7 @@ impl Add for &AST { } /// A type representing the access mode of a scripted function. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] pub enum FnAccess { /// Private function. Private, @@ -210,7 +210,7 @@ pub type SharedFnDef = Arc; pub type SharedFnDef = Rc; /// `return`/`throw` statement. -#[derive(Debug, PartialEq, Eq, Hash, Clone, Copy)] +#[derive(Debug, Eq, PartialEq, Hash, Clone, Copy)] pub enum ReturnType { /// `return` statement. Return, diff --git a/src/scope.rs b/src/scope.rs index 9f47b446..17909970 100644 --- a/src/scope.rs +++ b/src/scope.rs @@ -22,7 +22,7 @@ pub enum EntryType { } /// An entry in the Scope. -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Entry<'a> { /// Name of the entry. pub name: Cow<'a, str>, @@ -64,7 +64,7 @@ pub struct Entry<'a> { /// allowing for automatic _shadowing_. /// /// Currently, `Scope` is neither `Send` nor `Sync`. Turn on the `sync` feature to make it `Send + Sync`. -#[derive(Debug, Default)] +#[derive(Debug, Clone, Default)] pub struct Scope<'a>(Vec>); impl<'a> Scope<'a> { diff --git a/src/utils.rs b/src/utils.rs index 7abe88ab..4694fce4 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -64,6 +64,14 @@ pub struct StaticVec { more: Vec, } +impl PartialEq for StaticVec { + fn eq(&self, other: &Self) -> bool { + self.len == other.len && self.list == other.list && self.more == other.more + } +} + +impl Eq for StaticVec {} + impl Default for StaticVec { fn default() -> Self { Self {