Fix builds.

This commit is contained in:
Stephen Chung 2022-06-09 18:22:53 +08:00
parent a31a4e4887
commit 09e19790fe
2 changed files with 29 additions and 13 deletions

View File

@ -6,9 +6,9 @@ use crate::types::dynamic::Variant;
use crate::{ use crate::{
Dynamic, Engine, OptimizationLevel, Position, RhaiResult, RhaiResultOf, Scope, AST, ERR, Dynamic, Engine, OptimizationLevel, Position, RhaiResult, RhaiResultOf, Scope, AST, ERR,
}; };
use std::any::type_name;
#[cfg(feature = "no_std")] #[cfg(feature = "no_std")]
use std::prelude::v1::*; use std::prelude::v1::*;
use std::{any::type_name, mem};
impl Engine { impl Engine {
/// Evaluate a string. /// Evaluate a string.
@ -222,7 +222,7 @@ impl Engine {
global.source = ast.source_raw().clone(); global.source = ast.source_raw().clone();
#[cfg(not(feature = "no_module"))] #[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, &mut global.embedded_module_resolver,
ast.resolver().cloned(), ast.resolver().cloned(),
); );

View File

@ -497,10 +497,14 @@ impl Engine {
let root = namespace.root(); let root = namespace.root();
let index = state.find_module(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 settings.options.contains(LangOptions::STRICT_VAR) && index.is_none() {
if root != crate::engine::KEYWORD_GLOBAL if !is_global && !self.global_sub_modules.contains_key(root) {
&& !self.global_sub_modules.contains_key(root)
{
return Err(PERR::ModuleUndefined(root.to_string()) return Err(PERR::ModuleUndefined(root.to_string())
.into_err(namespace.position())); .into_err(namespace.position()));
} }
@ -557,10 +561,14 @@ impl Engine {
let root = namespace.root(); let root = namespace.root();
let index = state.find_module(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 settings.options.contains(LangOptions::STRICT_VAR) && index.is_none() {
if root != crate::engine::KEYWORD_GLOBAL if !is_global && !self.global_sub_modules.contains_key(root) {
&& !self.global_sub_modules.contains_key(root)
{
return Err(PERR::ModuleUndefined(root.to_string()) return Err(PERR::ModuleUndefined(root.to_string())
.into_err(namespace.position())); .into_err(namespace.position()));
} }
@ -1262,7 +1270,9 @@ impl Engine {
Token::Pipe | Token::Or if settings.options.contains(LangOptions::ANON_FN) => { Token::Pipe | Token::Or if settings.options.contains(LangOptions::ANON_FN) => {
let mut new_state = let mut new_state =
ParseState::new(self, state.scope, state.tokenizer_control.clone()); 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"))] #[cfg(not(feature = "unchecked"))]
{ {
@ -1676,10 +1686,14 @@ impl Engine {
let root = namespace.root(); let root = namespace.root();
let index = state.find_module(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 settings.options.contains(LangOptions::STRICT_VAR) && index.is_none() {
if root != crate::engine::KEYWORD_GLOBAL if !is_global && !self.global_sub_modules.contains_key(root) {
&& !self.global_sub_modules.contains_key(root)
{
return Err(PERR::ModuleUndefined(root.to_string()) return Err(PERR::ModuleUndefined(root.to_string())
.into_err(namespace.position())); .into_err(namespace.position()));
} }
@ -3072,7 +3086,9 @@ impl Engine {
(Token::Fn, pos) => { (Token::Fn, pos) => {
let mut new_state = let mut new_state =
ParseState::new(self, state.scope, state.tokenizer_control.clone()); 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"))] #[cfg(not(feature = "unchecked"))]
{ {