diff --git a/src/api/definitions/mod.rs b/src/api/definitions/mod.rs index 33c29c92..e0caef31 100644 --- a/src/api/definitions/mod.rs +++ b/src/api/definitions/mod.rs @@ -9,7 +9,7 @@ use crate::{Engine, Module, Scope, INT}; #[cfg(feature = "no_std")] use std::prelude::v1::*; -use std::{any::type_name, borrow::Cow, cmp::Ordering, fmt, fmt::Write}; +use std::{any::type_name, borrow::Cow, cmp::Ordering, fmt}; impl Engine { /// _(metadata, internals)_ Return [`Definitions`] that can be used to generate definition files @@ -186,6 +186,8 @@ impl Definitions<'_> { #[cfg(not(feature = "no_module"))] { + use std::fmt::Write; + for (module_name, module_def) in self.modules_impl(&config) { write!( &mut def_file, @@ -382,6 +384,7 @@ impl Definitions<'_> { impl Module { /// Return definitions for all items inside the [`Module`]. + #[cfg(not(feature = "no_module"))] fn definition(&self, def: &Definitions) -> String { let mut s = String::new(); self.write_definition(&mut s, def).unwrap(); diff --git a/src/ast/ast.rs b/src/ast/ast.rs index 55a4bc76..cabd7c10 100644 --- a/src/ast/ast.rs +++ b/src/ast/ast.rs @@ -213,6 +213,7 @@ impl AST { #[cfg(feature = "metadata")] #[inline(always)] #[must_use] + #[allow(dead_code)] pub(crate) fn doc_mut(&mut self) -> &mut crate::SmartString { &mut self.doc } diff --git a/src/engine.rs b/src/engine.rs index 265a3aa0..4c63be00 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -14,11 +14,7 @@ use crate::{ }; #[cfg(feature = "no_std")] use std::prelude::v1::*; -use std::{ - collections::{BTreeMap, BTreeSet}, - fmt, - num::NonZeroU8, -}; +use std::{collections::BTreeSet, fmt, num::NonZeroU8}; pub type Precedence = NonZeroU8; @@ -99,7 +95,7 @@ pub struct Engine { pub(crate) global_modules: StaticVec>, /// A collection of all sub-modules directly loaded into the Engine. #[cfg(not(feature = "no_module"))] - pub(crate) global_sub_modules: BTreeMap>, + pub(crate) global_sub_modules: std::collections::BTreeMap>, /// A module resolution service. #[cfg(not(feature = "no_module"))] @@ -112,10 +108,11 @@ pub struct Engine { pub(crate) disabled_symbols: BTreeSet, /// A map containing custom keywords and precedence to recognize. #[cfg(not(feature = "no_custom_syntax"))] - pub(crate) custom_keywords: BTreeMap>, + pub(crate) custom_keywords: std::collections::BTreeMap>, /// Custom syntax. #[cfg(not(feature = "no_custom_syntax"))] - pub(crate) custom_syntax: BTreeMap, + pub(crate) custom_syntax: + std::collections::BTreeMap, /// Callback closure for filtering variable definition. pub(crate) def_var_filter: Option>, /// Callback closure for resolving variable access. @@ -265,7 +262,7 @@ impl Engine { global_modules: StaticVec::new_const(), #[cfg(not(feature = "no_module"))] - global_sub_modules: BTreeMap::new(), + global_sub_modules: std::collections::BTreeMap::new(), #[cfg(not(feature = "no_module"))] module_resolver: Box::new(crate::module::resolvers::DummyModuleResolver::new()), @@ -273,9 +270,9 @@ impl Engine { interned_strings: StringsInterner::new().into(), disabled_symbols: BTreeSet::new(), #[cfg(not(feature = "no_custom_syntax"))] - custom_keywords: BTreeMap::new(), + custom_keywords: std::collections::BTreeMap::new(), #[cfg(not(feature = "no_custom_syntax"))] - custom_syntax: BTreeMap::new(), + custom_syntax: std::collections::BTreeMap::new(), def_var_filter: None, resolve_var: None, diff --git a/src/eval/global_state.rs b/src/eval/global_state.rs index 28c0589f..7421a95a 100644 --- a/src/eval/global_state.rs +++ b/src/eval/global_state.rs @@ -1,6 +1,6 @@ //! Global runtime state. -use crate::{Dynamic, Engine, Identifier, ImmutableString}; +use crate::{Dynamic, Engine, Identifier}; #[cfg(feature = "no_std")] use std::prelude::v1::*; use std::{fmt, marker::PhantomData}; @@ -9,7 +9,7 @@ use std::{fmt, marker::PhantomData}; #[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_function"))] pub type GlobalConstants = - crate::Shared>>; + crate::Shared>>; /// _(internals)_ Global runtime states. /// Exported under the `internals` feature only. @@ -25,7 +25,7 @@ pub type GlobalConstants = pub struct GlobalRuntimeState<'a> { /// Stack of module names. #[cfg(not(feature = "no_module"))] - keys: crate::StaticVec, + keys: crate::StaticVec, /// Stack of imported [modules][crate::Module]. #[cfg(not(feature = "no_module"))] modules: crate::StaticVec>, @@ -169,7 +169,7 @@ impl GlobalRuntimeState<'_> { #[inline(always)] pub fn push_import( &mut self, - name: impl Into, + name: impl Into, module: impl Into>, ) { self.keys.push(name.into()); @@ -205,7 +205,7 @@ impl GlobalRuntimeState<'_> { #[inline] pub(crate) fn iter_imports_raw( &self, - ) -> impl Iterator)> { + ) -> impl Iterator)> { self.keys.iter().rev().zip(self.modules.iter().rev()) } /// Get an iterator to the stack of globally-imported [modules][crate::Module] in forward order. @@ -216,7 +216,7 @@ impl GlobalRuntimeState<'_> { #[inline] pub fn scan_imports_raw( &self, - ) -> impl Iterator)> { + ) -> impl Iterator)> { self.keys.iter().zip(self.modules.iter()) } /// Does the specified function hash key exist in the stack of globally-imported @@ -310,9 +310,9 @@ impl GlobalRuntimeState<'_> { #[cfg(not(feature = "no_module"))] impl IntoIterator for GlobalRuntimeState<'_> { - type Item = (ImmutableString, crate::Shared); + type Item = (crate::ImmutableString, crate::Shared); type IntoIter = std::iter::Zip< - std::iter::Rev>, + std::iter::Rev>, std::iter::Rev; 3]>>, >; @@ -327,9 +327,9 @@ impl IntoIterator for GlobalRuntimeState<'_> { #[cfg(not(feature = "no_module"))] impl<'a> IntoIterator for &'a GlobalRuntimeState<'_> { - type Item = (&'a ImmutableString, &'a crate::Shared); + type Item = (&'a crate::ImmutableString, &'a crate::Shared); type IntoIter = std::iter::Zip< - std::iter::Rev>, + std::iter::Rev>, std::iter::Rev>>, >; @@ -341,7 +341,7 @@ impl<'a> IntoIterator for &'a GlobalRuntimeState<'_> { } #[cfg(not(feature = "no_module"))] -impl, M: Into>> Extend<(K, M)> +impl, M: Into>> Extend<(K, M)> for GlobalRuntimeState<'_> { #[inline] diff --git a/src/packages/lang_core.rs b/src/packages/lang_core.rs index 379fd4c7..5c073146 100644 --- a/src/packages/lang_core.rs +++ b/src/packages/lang_core.rs @@ -1,6 +1,6 @@ use crate::def_package; use crate::plugin::*; -use crate::types::{dynamic::Tag, StringsInterner}; +use crate::types::dynamic::Tag; use crate::{Dynamic, RhaiResultOf, ERR, INT}; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -129,12 +129,12 @@ fn collect_fn_metadata( filter: impl Fn(FnNamespace, FnAccess, &str, usize, &crate::Shared) -> bool + Copy, ) -> crate::Array { - use crate::{ast::ScriptFnDef, Array, Identifier, Map}; + use crate::{ast::ScriptFnDef, Array, Map}; // Create a metadata record for a function. fn make_metadata( - dict: &mut StringsInterner, - #[cfg(not(feature = "no_module"))] namespace: Identifier, + dict: &mut crate::types::StringsInterner, + #[cfg(not(feature = "no_module"))] namespace: crate::Identifier, func: &ScriptFnDef, ) -> Map { let mut map = Map::new(); @@ -179,7 +179,7 @@ fn collect_fn_metadata( map } - let dict = &mut StringsInterner::new(); + let dict = &mut crate::types::StringsInterner::new(); let mut list = Array::new(); ctx.iter_namespaces() @@ -190,7 +190,7 @@ fn collect_fn_metadata( make_metadata( dict, #[cfg(not(feature = "no_module"))] - Identifier::new_const(), + crate::Identifier::new_const(), f, ) .into(), @@ -207,7 +207,7 @@ fn collect_fn_metadata( make_metadata( dict, #[cfg(not(feature = "no_module"))] - Identifier::new_const(), + crate::Identifier::new_const(), f, ) .into(), @@ -225,7 +225,7 @@ fn collect_fn_metadata( make_metadata( dict, #[cfg(not(feature = "no_module"))] - Identifier::new_const(), + crate::Identifier::new_const(), f, ) .into(), @@ -236,7 +236,7 @@ fn collect_fn_metadata( { // Recursively scan modules for script-defined functions. fn scan_module( - dict: &mut StringsInterner, + dict: &mut crate::types::StringsInterner, list: &mut Array, namespace: &str, module: &Module, diff --git a/src/packages/mod.rs b/src/packages/mod.rs index c41c721d..ab4df033 100644 --- a/src/packages/mod.rs +++ b/src/packages/mod.rs @@ -83,6 +83,7 @@ pub trait Package { /// /// package.register_into_engine_as(&mut engine, "core"); /// ``` + #[cfg(not(feature = "no_module"))] fn register_into_engine_as(&self, engine: &mut Engine, name: &str) -> &Self { Self::init_engine(engine); engine.register_static_module(name, self.as_shared_module()); diff --git a/src/parser.rs b/src/parser.rs index 2bf5d3b9..754513c8 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -187,12 +187,13 @@ impl<'e> ParseState<'e> { lib: &FnLib, pos: Position, ) -> (Option, bool) { + let _lib = lib; let _pos = pos; let (index, hit_barrier) = self.find_var(name); #[cfg(not(feature = "no_function"))] - let is_func_name = lib.values().any(|f| f.name == name); + let is_func_name = _lib.values().any(|f| f.name == name); #[cfg(feature = "no_function")] let is_func_name = false; diff --git a/src/serde/metadata.rs b/src/serde/metadata.rs index d792119a..f4d9732f 100644 --- a/src/serde/metadata.rs +++ b/src/serde/metadata.rs @@ -2,7 +2,7 @@ #![cfg(feature = "metadata")] use crate::module::{calc_native_fn_hash, FuncInfo}; -use crate::{calc_fn_hash, Engine, FnAccess, FnNamespace, SmartString, StaticVec, AST}; +use crate::{calc_fn_hash, Engine, FnAccess, SmartString, StaticVec, AST}; use serde::Serialize; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -30,7 +30,7 @@ struct FnMetadata<'a> { pub base_hash: u64, pub full_hash: u64, #[cfg(not(feature = "no_module"))] - pub namespace: FnNamespace, + pub namespace: crate::FnNamespace, pub access: FnAccess, pub name: &'a str, #[serde(rename = "type")] @@ -184,7 +184,7 @@ pub fn gen_metadata_to_json( let mut meta: FnMetadata = f.into(); #[cfg(not(feature = "no_module"))] { - meta.namespace = FnNamespace::Global; + meta.namespace = crate::FnNamespace::Global; } global.functions.push(meta); }); @@ -196,7 +196,7 @@ pub fn gen_metadata_to_json( let mut meta: FnMetadata = f.into(); #[cfg(not(feature = "no_module"))] { - meta.namespace = FnNamespace::Global; + meta.namespace = crate::FnNamespace::Global; } global.functions.push(meta); } diff --git a/src/tokenizer.rs b/src/tokenizer.rs index 62d120e5..a2ca3fcd 100644 --- a/src/tokenizer.rs +++ b/src/tokenizer.rs @@ -333,22 +333,29 @@ impl Span { } impl fmt::Display for Span { + #[inline] fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + let _f = f; + + #[cfg(not(feature = "no_position"))] match (self.start(), self.end()) { - (Position::NONE, Position::NONE) => write!(f, "{:?}", Position::NONE), - (Position::NONE, end) => write!(f, "..{:?}", end), - (start, Position::NONE) => write!(f, "{:?}", start), + (Position::NONE, Position::NONE) => write!(_f, "{:?}", Position::NONE), + (Position::NONE, end) => write!(_f, "..{:?}", end), + (start, Position::NONE) => write!(_f, "{:?}", start), (start, end) if start.line() != end.line() => { - write!(f, "{:?}-{:?}", start, end) + write!(_f, "{:?}-{:?}", start, end) } (start, end) => write!( - f, + _f, "{}:{}-{}", start.line().unwrap(), start.position().unwrap_or(0), end.position().unwrap_or(0) ), } + + #[cfg(feature = "no_position")] + Ok(()) } } diff --git a/src/types/dynamic.rs b/src/types/dynamic.rs index 1a37cd16..a318581b 100644 --- a/src/types/dynamic.rs +++ b/src/types/dynamic.rs @@ -1,7 +1,7 @@ //! Helper module which defines the [`Dynamic`] data type and the //! [`Any`] trait to to allow custom type handling. -use crate::func::{locked_read, SendSync}; +use crate::func::SendSync; use crate::{reify, ExclusiveRange, FnPtr, ImmutableString, InclusiveRange, INT}; #[cfg(feature = "no_std")] use std::prelude::v1::*; @@ -23,6 +23,7 @@ pub use std::time::Instant; pub use instant::Instant; /// The message: data type was checked +#[allow(dead_code)] const CHECKED: &str = "data type was checked"; mod private { @@ -427,7 +428,7 @@ impl Dynamic { Union::Variant(ref v, ..) => (***v).type_id(), #[cfg(not(feature = "no_closure"))] - Union::Shared(ref cell, ..) => (*locked_read(cell)).type_id(), + Union::Shared(ref cell, ..) => (*crate::func::locked_read(cell)).type_id(), } } /// Get the name of the type of the value held by this [`Dynamic`]. @@ -501,7 +502,7 @@ impl Hash for Dynamic { Union::FnPtr(ref f, ..) => f.hash(state), #[cfg(not(feature = "no_closure"))] - Union::Shared(ref cell, ..) => (*locked_read(cell)).hash(state), + Union::Shared(ref cell, ..) => (*crate::func::locked_read(cell)).hash(state), Union::Variant(..) => unimplemented!("{} cannot be hashed", self.type_name()), @@ -1073,7 +1074,7 @@ impl Dynamic { pub fn is_read_only(&self) -> bool { #[cfg(not(feature = "no_closure"))] if let Union::Shared(ref cell, ..) = self.0 { - return match locked_read(cell).access_mode() { + return match crate::func::locked_read(cell).access_mode() { ReadWrite => false, ReadOnly => true, }; @@ -1102,7 +1103,7 @@ impl Dynamic { Union::Map(..) => true, #[cfg(not(feature = "no_closure"))] - Union::Shared(ref cell, ..) => locked_read(cell).is_hashable(), + Union::Shared(ref cell, ..) => crate::func::locked_read(cell).is_hashable(), _ => false, } @@ -1353,7 +1354,7 @@ impl Dynamic { pub fn flatten_clone(&self) -> Self { match self.0 { #[cfg(not(feature = "no_closure"))] - Union::Shared(ref cell, ..) => locked_read(cell).clone(), + Union::Shared(ref cell, ..) => crate::func::locked_read(cell).clone(), _ => self.clone(), } } @@ -1369,7 +1370,7 @@ impl Dynamic { match self.0 { #[cfg(not(feature = "no_closure"))] Union::Shared(cell, ..) => crate::func::shared_try_take(cell).map_or_else( - |ref cell| locked_read(cell).clone(), + |ref cell| crate::func::locked_read(cell).clone(), #[cfg(not(feature = "sync"))] |value| value.into_inner(), #[cfg(feature = "sync")] @@ -1391,7 +1392,7 @@ impl Dynamic { Union::Shared(ref mut cell, ..) => { let cell = mem::take(cell); *self = crate::func::shared_try_take(cell).map_or_else( - |ref cell| locked_read(cell).clone(), + |ref cell| crate::func::locked_read(cell).clone(), #[cfg(not(feature = "sync"))] |value| value.into_inner(), #[cfg(feature = "sync")] @@ -1440,7 +1441,7 @@ impl Dynamic { match self.0 { #[cfg(not(feature = "no_closure"))] Union::Shared(ref cell, ..) => { - let value = locked_read(cell); + let value = crate::func::locked_read(cell); return if (*value).type_id() != TypeId::of::() && TypeId::of::() != TypeId::of::() @@ -1788,7 +1789,7 @@ impl Dynamic { Union::Str(s, ..) => Ok(s), #[cfg(not(feature = "no_closure"))] Union::Shared(ref cell, ..) => { - let value = locked_read(cell); + let value = crate::func::locked_read(cell); match value.0 { Union::Str(ref s, ..) => Ok(s.clone()), @@ -1807,7 +1808,7 @@ impl Dynamic { Union::Array(a, ..) => Ok(*a), #[cfg(not(feature = "no_closure"))] Union::Shared(ref cell, ..) => { - let value = locked_read(cell); + let value = crate::func::locked_read(cell); match value.0 { Union::Array(ref a, ..) => Ok(a.as_ref().clone()), @@ -1842,7 +1843,7 @@ impl Dynamic { Union::Blob(..) if TypeId::of::() == TypeId::of::() => Ok(self.cast::>()), #[cfg(not(feature = "no_closure"))] Union::Shared(ref cell, ..) => { - let value = locked_read(cell); + let value = crate::func::locked_read(cell); match value.0 { Union::Array(ref a, ..) => { @@ -1880,7 +1881,7 @@ impl Dynamic { Union::Blob(a, ..) => Ok(*a), #[cfg(not(feature = "no_closure"))] Union::Shared(ref cell, ..) => { - let value = locked_read(cell); + let value = crate::func::locked_read(cell); match value.0 { Union::Blob(ref a, ..) => Ok(a.as_ref().clone()), diff --git a/src/types/interner.rs b/src/types/interner.rs index 8ce63284..90c28461 100644 --- a/src/types/interner.rs +++ b/src/types/interner.rs @@ -127,6 +127,7 @@ impl StringsInterner<'_> { /// Number of strings interned. #[inline(always)] #[must_use] + #[allow(dead_code)] pub fn len(&self) -> usize { self.strings.len() } @@ -134,12 +135,14 @@ impl StringsInterner<'_> { /// Returns `true` if there are no interned strings. #[inline(always)] #[must_use] + #[allow(dead_code)] pub fn is_empty(&self) -> bool { self.strings.is_empty() } /// Clear all interned strings. #[inline(always)] + #[allow(dead_code)] pub fn clear(&mut self) { self.strings.clear(); } diff --git a/tests/packages.rs b/tests/packages.rs index 75537721..06d64e52 100644 --- a/tests/packages.rs +++ b/tests/packages.rs @@ -7,6 +7,7 @@ def_package! { m.set_native_fn("hello", |x: INT| Ok(x + 1)); m.set_native_fn("@", |x: INT, y: INT| Ok(x * x + y * y)); } |> |engine| { + #[cfg(not(feature = "no_custom_syntax"))] engine.register_custom_operator("@", 160).unwrap(); } } @@ -30,11 +31,20 @@ fn test_packages() -> Result<(), Box> { scope.push("x", x); // Evaluate script. - engine.eval_with_scope::(&mut scope, "hello(x) @ foo::hello(x)") + + #[cfg(not(feature = "no_custom_syntax"))] + return engine.eval_with_scope::(&mut scope, "hello(x) @ foo::hello(x)"); + + #[cfg(feature = "no_custom_syntax")] + return engine.eval_with_scope::(&mut scope, "hello(x) + foo::hello(x)"); }; + #[cfg(not(feature = "no_custom_syntax"))] assert_eq!(make_call(42)?, 3698); + #[cfg(feature = "no_custom_syntax")] + assert_eq!(make_call(42)?, 86); + Ok(()) }