diff --git a/src/fn_native.rs b/src/fn_native.rs index 69790b8d..113f19a1 100644 --- a/src/fn_native.rs +++ b/src/fn_native.rs @@ -1,7 +1,7 @@ //! Module defining interfaces to native-Rust functions. use crate::any::Dynamic; -use crate::engine::{Engine, EvalContext, FN_ANONYMOUS}; +use crate::engine::{Engine, EvalContext}; use crate::module::Module; use crate::parser::{FnAccess, ScriptFnDef}; use crate::plugin::PluginFunction; @@ -11,6 +11,9 @@ use crate::token::{is_valid_identifier, Position}; use crate::utils::ImmutableString; use crate::{calc_fn_hash, StaticVec}; +#[cfg(not(feature = "no_function"))] +use crate::engine::FN_ANONYMOUS; + use crate::stdlib::{boxed::Box, convert::TryFrom, fmt, iter::empty, mem, string::String}; #[cfg(feature = "sync")] @@ -138,6 +141,7 @@ impl FnPtr { self.1.as_ref() } /// Does this function pointer refer to an anonymous function? + #[cfg(not(feature = "no_function"))] #[inline(always)] pub fn is_anonymous(&self) -> bool { self.0.starts_with(FN_ANONYMOUS) diff --git a/src/parser.rs b/src/parser.rs index 404d1ffd..b957ebeb 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -670,17 +670,28 @@ impl<'e> ParseState<'e> { } /// Find a module by name in the `ParseState`, searching in reverse. - /// The return value is the offset to be deducted from `Stack::len`, + /// + /// Returns the offset to be deducted from `Stack::len`, /// i.e. the top element of the `ParseState` is offset 1. - /// Return `None` when the variable name is not found in the `ParseState`. + /// + /// Returns `None` when the variable name is not found in the `ParseState`. + /// + /// # Panics + /// + /// Panics when called under `no_module`. #[inline(always)] pub fn find_module(&self, name: &str) -> Option { - self.modules + #[cfg(feature = "no_module")] + unreachable!(); + + #[cfg(not(feature = "no_module"))] + return self + .modules .iter() .rev() .enumerate() .find(|(_, n)| *n == name) - .and_then(|(i, _)| NonZeroUsize::new(i + 1)) + .and_then(|(i, _)| NonZeroUsize::new(i + 1)); } }