diff --git a/src/api/eval.rs b/src/api/eval.rs index aec12d99..a90d88bc 100644 --- a/src/api/eval.rs +++ b/src/api/eval.rs @@ -6,9 +6,9 @@ use crate::types::dynamic::Variant; use crate::{ Dynamic, Engine, OptimizationLevel, Position, RhaiResult, RhaiResultOf, Scope, AST, ERR, }; +use std::any::type_name; #[cfg(feature = "no_std")] use std::prelude::v1::*; -use std::{any::type_name, mem}; impl Engine { /// Evaluate a string. @@ -222,7 +222,7 @@ impl Engine { global.source = ast.source_raw().clone(); #[cfg(not(feature = "no_module"))] - let orig_embedded_module_resolver = mem::replace( + let orig_embedded_module_resolver = std::mem::replace( &mut global.embedded_module_resolver, ast.resolver().cloned(), ); diff --git a/src/parser.rs b/src/parser.rs index f3350933..0dfdcf4b 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -497,10 +497,14 @@ impl Engine { let root = namespace.root(); let index = state.find_module(root); + #[cfg(not(feature = "no_function"))] + #[cfg(not(feature = "no_module"))] + let is_global = root == crate::engine::KEYWORD_GLOBAL; + #[cfg(any(feature = "no_function", feature = "no_module"))] + let is_global = false; + if settings.options.contains(LangOptions::STRICT_VAR) && index.is_none() { - if root != crate::engine::KEYWORD_GLOBAL - && !self.global_sub_modules.contains_key(root) - { + if !is_global && !self.global_sub_modules.contains_key(root) { return Err(PERR::ModuleUndefined(root.to_string()) .into_err(namespace.position())); } @@ -557,10 +561,14 @@ impl Engine { let root = namespace.root(); let index = state.find_module(root); + #[cfg(not(feature = "no_function"))] + #[cfg(not(feature = "no_module"))] + let is_global = root == crate::engine::KEYWORD_GLOBAL; + #[cfg(any(feature = "no_function", feature = "no_module"))] + let is_global = false; + if settings.options.contains(LangOptions::STRICT_VAR) && index.is_none() { - if root != crate::engine::KEYWORD_GLOBAL - && !self.global_sub_modules.contains_key(root) - { + if !is_global && !self.global_sub_modules.contains_key(root) { return Err(PERR::ModuleUndefined(root.to_string()) .into_err(namespace.position())); } @@ -1262,7 +1270,9 @@ impl Engine { Token::Pipe | Token::Or if settings.options.contains(LangOptions::ANON_FN) => { let mut new_state = ParseState::new(self, state.scope, state.tokenizer_control.clone()); - new_state.imports = state.imports.clone(); + + #[cfg(not(feature = "no_module"))] + new_state.imports.clone_from(&state.imports); #[cfg(not(feature = "unchecked"))] { @@ -1676,10 +1686,14 @@ impl Engine { let root = namespace.root(); let index = state.find_module(root); + #[cfg(not(feature = "no_function"))] + #[cfg(not(feature = "no_module"))] + let is_global = root == crate::engine::KEYWORD_GLOBAL; + #[cfg(any(feature = "no_function", feature = "no_module"))] + let is_global = false; + if settings.options.contains(LangOptions::STRICT_VAR) && index.is_none() { - if root != crate::engine::KEYWORD_GLOBAL - && !self.global_sub_modules.contains_key(root) - { + if !is_global && !self.global_sub_modules.contains_key(root) { return Err(PERR::ModuleUndefined(root.to_string()) .into_err(namespace.position())); } @@ -3072,7 +3086,9 @@ impl Engine { (Token::Fn, pos) => { let mut new_state = ParseState::new(self, state.scope, state.tokenizer_control.clone()); - new_state.imports = state.imports.clone(); + + #[cfg(not(feature = "no_module"))] + new_state.imports.clone_from(&state.imports); #[cfg(not(feature = "unchecked"))] {