Fix feature builds.

This commit is contained in:
Stephen Chung 2021-03-31 10:16:38 +08:00
parent a049f7b5ba
commit 98afb2e7d6
8 changed files with 68 additions and 42 deletions

View File

@ -35,6 +35,7 @@ jobs:
- "--features no_closure" - "--features no_closure"
- "--features unicode-xid-ident" - "--features unicode-xid-ident"
- "--features sync,no_function,no_float,no_optimize,no_module,no_closure,metadata,serde,unchecked" - "--features sync,no_function,no_float,no_optimize,no_module,no_closure,metadata,serde,unchecked"
- "--features no_function,no_float,no_index,no_object,no_optimize,no_module,no_closure,unchecked"
toolchain: [stable] toolchain: [stable]
experimental: [false] experimental: [false]
include: include:

View File

@ -28,6 +28,11 @@ This avoids spending precious resources maintaining metadata for functions for t
use cases where such information is not required. use cases where such information is not required.
Bug fixes
---------
* The feature flags `no_index + no_object` now compile without errors.
Breaking changes Breaking changes
---------------- ----------------

View File

@ -1,6 +1,6 @@
//! Main module defining the script evaluation [`Engine`]. //! Main module defining the script evaluation [`Engine`].
use crate::ast::{Expr, FnCallExpr, FnCallHash, Ident, OpAssignment, ReturnType, Stmt, StmtBlock}; use crate::ast::{Expr, FnCallExpr, Ident, OpAssignment, ReturnType, Stmt, StmtBlock};
use crate::dynamic::{map_std_type_name, AccessMode, Union, Variant}; use crate::dynamic::{map_std_type_name, AccessMode, Union, Variant};
use crate::fn_native::{ use crate::fn_native::{
CallableFunction, IteratorFn, OnDebugCallback, OnPrintCallback, OnProgressCallback, CallableFunction, IteratorFn, OnDebugCallback, OnPrintCallback, OnProgressCallback,
@ -25,8 +25,8 @@ use crate::stdlib::{
use crate::syntax::CustomSyntax; use crate::syntax::CustomSyntax;
use crate::utils::get_hasher; use crate::utils::get_hasher;
use crate::{ use crate::{
Dynamic, EvalAltResult, FnPtr, Identifier, ImmutableString, Module, Position, RhaiResult, Dynamic, EvalAltResult, FnPtr, Identifier, Module, Position, RhaiResult, Scope, Shared,
Scope, Shared, StaticVec, StaticVec,
}; };
#[cfg(not(feature = "no_index"))] #[cfg(not(feature = "no_index"))]
@ -35,6 +35,9 @@ use crate::{calc_fn_hash, stdlib::iter::empty, Array};
#[cfg(not(feature = "no_object"))] #[cfg(not(feature = "no_object"))]
use crate::Map; use crate::Map;
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
use crate::ast::FnCallHash;
pub type Precedence = NonZeroU8; pub type Precedence = NonZeroU8;
/// _(INTERNALS)_ A stack of imported [modules][Module]. /// _(INTERNALS)_ A stack of imported [modules][Module].
@ -394,7 +397,6 @@ impl<'a> Target<'a> {
} }
} }
/// Update the value of the `Target`. /// Update the value of the `Target`.
#[cfg(any(not(feature = "no_object"), not(feature = "no_index")))]
pub fn set_value( pub fn set_value(
&mut self, &mut self,
new_val: Dynamic, new_val: Dynamic,
@ -408,7 +410,7 @@ impl<'a> Target<'a> {
Self::Value(_) => panic!("cannot update a value"), Self::Value(_) => panic!("cannot update a value"),
#[cfg(not(feature = "no_index"))] #[cfg(not(feature = "no_index"))]
Self::StringChar(s, index, _) => { Self::StringChar(s, index, _) => {
let s = &mut *s.write_lock::<ImmutableString>().unwrap(); let s = &mut *s.write_lock::<crate::ImmutableString>().unwrap();
// Replace the character at the specified index position // Replace the character at the specified index position
let new_ch = new_val.as_char().map_err(|err| { let new_ch = new_val.as_char().map_err(|err| {
@ -589,7 +591,7 @@ pub struct Limits {
/// Not available under `no_module`. /// Not available under `no_module`.
#[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_module"))]
pub max_modules: usize, pub max_modules: usize,
/// Maximum length of a [string][ImmutableString]. /// Maximum length of a [string][crate::ImmutableString].
pub max_string_size: Option<NonZeroUsize>, pub max_string_size: Option<NonZeroUsize>,
/// Maximum length of an [array][Array]. /// Maximum length of an [array][Array].
/// ///
@ -1569,8 +1571,8 @@ impl Engine {
#[cfg(not(feature = "no_object"))] #[cfg(not(feature = "no_object"))]
Dynamic(Union::Map(map, _)) => { Dynamic(Union::Map(map, _)) => {
// val_map[idx] // val_map[idx]
let index = &*idx.read_lock::<ImmutableString>().ok_or_else(|| { let index = &*idx.read_lock::<crate::ImmutableString>().ok_or_else(|| {
self.make_type_mismatch_err::<ImmutableString>(idx.type_name(), idx_pos) self.make_type_mismatch_err::<crate::ImmutableString>(idx.type_name(), idx_pos)
})?; })?;
if _create && !map.contains_key(index.as_str()) { if _create && !map.contains_key(index.as_str()) {
@ -2427,7 +2429,7 @@ impl Engine {
if let Some(path) = self if let Some(path) = self
.eval_expr(scope, mods, state, lib, this_ptr, &expr, level)? .eval_expr(scope, mods, state, lib, this_ptr, &expr, level)?
.try_cast::<ImmutableString>() .try_cast::<crate::ImmutableString>()
{ {
use crate::ModuleResolver; use crate::ModuleResolver;
@ -2460,7 +2462,7 @@ impl Engine {
Ok(Dynamic::UNIT) Ok(Dynamic::UNIT)
} else { } else {
Err(self.make_type_mismatch_err::<ImmutableString>("", expr.position())) Err(self.make_type_mismatch_err::<crate::ImmutableString>("", expr.position()))
} }
} }
@ -2515,17 +2517,17 @@ impl Engine {
} }
// If no data size limits, just return // If no data size limits, just return
let mut has_limit = self.limits.max_string_size.is_some(); let mut _has_limit = self.limits.max_string_size.is_some();
#[cfg(not(feature = "no_index"))] #[cfg(not(feature = "no_index"))]
{ {
has_limit = has_limit || self.limits.max_array_size.is_some(); _has_limit = _has_limit || self.limits.max_array_size.is_some();
} }
#[cfg(not(feature = "no_object"))] #[cfg(not(feature = "no_object"))]
{ {
has_limit = has_limit || self.limits.max_map_size.is_some(); _has_limit = _has_limit || self.limits.max_map_size.is_some();
} }
if !has_limit { if !_has_limit {
return result; return result;
} }

View File

@ -13,8 +13,8 @@ use crate::stdlib::{
}; };
use crate::token::is_valid_identifier; use crate::token::is_valid_identifier;
use crate::{ use crate::{
calc_fn_hash, Dynamic, Engine, EvalAltResult, EvalContext, Identifier, ImmutableString, Module, calc_fn_hash, Dynamic, Engine, EvalAltResult, EvalContext, ImmutableString, Module, Position,
Position, RhaiResult, StaticVec, RhaiResult, StaticVec,
}; };
/// Trait that maps to `Send + Sync` only under the `sync` feature. /// Trait that maps to `Send + Sync` only under the `sync` feature.
@ -144,7 +144,9 @@ impl<'a> NativeCallContext<'a> {
#[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_module"))]
#[allow(dead_code)] #[allow(dead_code)]
#[inline(always)] #[inline(always)]
pub(crate) fn iter_imports_raw(&self) -> impl Iterator<Item = (&Identifier, &Shared<Module>)> { pub(crate) fn iter_imports_raw(
&self,
) -> impl Iterator<Item = (&crate::Identifier, &Shared<Module>)> {
self.mods.iter().flat_map(|&m| m.iter_raw()) self.mods.iter().flat_map(|&m| m.iter_raw())
} }
/// _(INTERNALS)_ The current set of modules imported via `import` statements. /// _(INTERNALS)_ The current set of modules imported via `import` statements.

View File

@ -2,7 +2,7 @@
use crate::plugin::*; use crate::plugin::*;
use crate::stdlib::{format, string::ToString}; use crate::stdlib::{format, string::ToString};
use crate::{def_package, FnPtr, ImmutableString}; use crate::{def_package, FnPtr};
#[cfg(not(feature = "no_index"))] #[cfg(not(feature = "no_index"))]
use crate::Array; use crate::Array;
@ -10,6 +10,7 @@ use crate::Array;
#[cfg(not(feature = "no_object"))] #[cfg(not(feature = "no_object"))]
use crate::Map; use crate::Map;
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
const FUNC_TO_DEBUG: &'static str = "to_debug"; const FUNC_TO_DEBUG: &'static str = "to_debug";
def_package!(crate:BasicStringPackage:"Basic string utilities, including printing.", lib, { def_package!(crate:BasicStringPackage:"Basic string utilities, including printing.", lib, {
@ -20,9 +21,15 @@ def_package!(crate:BasicStringPackage:"Basic string utilities, including printin
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))] #[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
#[inline(always)] #[inline(always)]
fn print_with_func(fn_name: &str, ctx: &NativeCallContext, value: &mut Dynamic) -> ImmutableString { fn print_with_func(
fn_name: &str,
ctx: &NativeCallContext,
value: &mut Dynamic,
) -> crate::ImmutableString {
match ctx.call_fn_dynamic_raw(fn_name, true, &mut [value]) { match ctx.call_fn_dynamic_raw(fn_name, true, &mut [value]) {
Ok(result) if result.is::<ImmutableString>() => result.take_immutable_string().unwrap(), Ok(result) if result.is::<crate::ImmutableString>() => {
result.take_immutable_string().unwrap()
}
Ok(result) => ctx.engine().map_type_name(result.type_name()).into(), Ok(result) => ctx.engine().map_type_name(result.type_name()).into(),
Err(_) => ctx.engine().map_type_name(value.type_name()).into(), Err(_) => ctx.engine().map_type_name(value.type_name()).into(),
} }

View File

@ -183,7 +183,7 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
self.deserialize_int(v, visitor) self.deserialize_int(v, visitor)
} else { } else {
self.value self.value
.downclone_cast::<i8>() .downcast_ref::<i8>()
.map_or_else(|| self.type_error(), |&x| visitor.visit_i8(x)) .map_or_else(|| self.type_error(), |&x| visitor.visit_i8(x))
} }
} }
@ -193,7 +193,7 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
self.deserialize_int(v, visitor) self.deserialize_int(v, visitor)
} else { } else {
self.value self.value
.downclone_cast::<i16>() .downcast_ref::<i16>()
.map_or_else(|| self.type_error(), |&x| visitor.visit_i16(x)) .map_or_else(|| self.type_error(), |&x| visitor.visit_i16(x))
} }
} }
@ -205,7 +205,7 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
self.type_error() self.type_error()
} else { } else {
self.value self.value
.downclone_cast::<i32>() .downcast_ref::<i32>()
.map_or_else(|| self.type_error(), |&x| visitor.visit_i32(x)) .map_or_else(|| self.type_error(), |&x| visitor.visit_i32(x))
} }
} }
@ -217,7 +217,7 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
self.type_error() self.type_error()
} else { } else {
self.value self.value
.downclone_cast::<i64>() .downcast_ref::<i64>()
.map_or_else(|| self.type_error(), |&x| visitor.visit_i64(x)) .map_or_else(|| self.type_error(), |&x| visitor.visit_i64(x))
} }
} }
@ -229,7 +229,7 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
self.type_error() self.type_error()
} else { } else {
self.value self.value
.downclone_cast::<i128>() .downcast_ref::<i128>()
.map_or_else(|| self.type_error(), |&x| visitor.visit_i128(x)) .map_or_else(|| self.type_error(), |&x| visitor.visit_i128(x))
} }
} }
@ -239,7 +239,7 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
self.deserialize_int(v, visitor) self.deserialize_int(v, visitor)
} else { } else {
self.value self.value
.downclone_cast::<u8>() .downcast_ref::<u8>()
.map_or_else(|| self.type_error(), |&x| visitor.visit_u8(x)) .map_or_else(|| self.type_error(), |&x| visitor.visit_u8(x))
} }
} }
@ -249,7 +249,7 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
self.deserialize_int(v, visitor) self.deserialize_int(v, visitor)
} else { } else {
self.value self.value
.downclone_cast::<u16>() .downcast_ref::<u16>()
.map_or_else(|| self.type_error(), |&x| visitor.visit_u16(x)) .map_or_else(|| self.type_error(), |&x| visitor.visit_u16(x))
} }
} }
@ -259,7 +259,7 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
self.deserialize_int(v, visitor) self.deserialize_int(v, visitor)
} else { } else {
self.value self.value
.downclone_cast::<u32>() .downcast_ref::<u32>()
.map_or_else(|| self.type_error(), |&x| visitor.visit_u32(x)) .map_or_else(|| self.type_error(), |&x| visitor.visit_u32(x))
} }
} }
@ -269,7 +269,7 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
self.deserialize_int(v, visitor) self.deserialize_int(v, visitor)
} else { } else {
self.value self.value
.downclone_cast::<u64>() .downcast_ref::<u64>()
.map_or_else(|| self.type_error(), |&x| visitor.visit_u64(x)) .map_or_else(|| self.type_error(), |&x| visitor.visit_u64(x))
} }
} }
@ -279,7 +279,7 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
self.deserialize_int(v, visitor) self.deserialize_int(v, visitor)
} else { } else {
self.value self.value
.downclone_cast::<u128>() .downcast_ref::<u128>()
.map_or_else(|| self.type_error(), |&x| visitor.visit_u128(x)) .map_or_else(|| self.type_error(), |&x| visitor.visit_u128(x))
} }
} }
@ -288,7 +288,7 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
#[cfg(not(feature = "no_float"))] #[cfg(not(feature = "no_float"))]
return self return self
.value .value
.downclone_cast::<f32>() .downcast_ref::<f32>()
.map_or_else(|| self.type_error(), |&x| _visitor.visit_f32(x)); .map_or_else(|| self.type_error(), |&x| _visitor.visit_f32(x));
#[cfg(feature = "no_float")] #[cfg(feature = "no_float")]
@ -298,7 +298,7 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
return self return self
.value .value
.downclone_cast::<rust_decimal::Decimal>() .downcast_ref::<rust_decimal::Decimal>()
.and_then(|&x| x.to_f32()) .and_then(|&x| x.to_f32())
.map_or_else(|| self.type_error(), |v| _visitor.visit_f32(v)); .map_or_else(|| self.type_error(), |v| _visitor.visit_f32(v));
} }
@ -312,7 +312,7 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
#[cfg(not(feature = "no_float"))] #[cfg(not(feature = "no_float"))]
return self return self
.value .value
.downclone_cast::<f64>() .downcast_ref::<f64>()
.map_or_else(|| self.type_error(), |&x| _visitor.visit_f64(x)); .map_or_else(|| self.type_error(), |&x| _visitor.visit_f64(x));
#[cfg(feature = "no_float")] #[cfg(feature = "no_float")]
@ -322,7 +322,7 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
return self return self
.value .value
.downclone_cast::<rust_decimal::Decimal>() .downcast_ref::<rust_decimal::Decimal>()
.and_then(|&x| x.to_f64()) .and_then(|&x| x.to_f64())
.map_or_else(|| self.type_error(), |v| _visitor.visit_f64(v)); .map_or_else(|| self.type_error(), |v| _visitor.visit_f64(v));
} }
@ -334,12 +334,12 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
fn deserialize_char<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value, Box<EvalAltResult>> { fn deserialize_char<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value, Box<EvalAltResult>> {
self.value self.value
.downclone_cast::<char>() .downcast_ref::<char>()
.map_or_else(|| self.type_error(), |&x| visitor.visit_char(x)) .map_or_else(|| self.type_error(), |&x| visitor.visit_char(x))
} }
fn deserialize_str<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value, Box<EvalAltResult>> { fn deserialize_str<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value, Box<EvalAltResult>> {
self.value.downclone_cast::<ImmutableString>().map_or_else( self.value.downcast_ref::<ImmutableString>().map_or_else(
|| self.type_error(), || self.type_error(),
|x| visitor.visit_borrowed_str(x.as_str()), |x| visitor.visit_borrowed_str(x.as_str()),
) )
@ -366,7 +366,7 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
fn deserialize_unit<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value, Box<EvalAltResult>> { fn deserialize_unit<V: Visitor<'de>>(self, visitor: V) -> Result<V::Value, Box<EvalAltResult>> {
self.value self.value
.downclone_cast::<()>() .downcast_ref::<()>()
.map_or_else(|| self.type_error(), |_| visitor.visit_unit()) .map_or_else(|| self.type_error(), |_| visitor.visit_unit())
} }
@ -388,7 +388,7 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
fn deserialize_seq<V: Visitor<'de>>(self, _visitor: V) -> Result<V::Value, Box<EvalAltResult>> { fn deserialize_seq<V: Visitor<'de>>(self, _visitor: V) -> Result<V::Value, Box<EvalAltResult>> {
#[cfg(not(feature = "no_index"))] #[cfg(not(feature = "no_index"))]
return self.value.downclone_cast::<Array>().map_or_else( return self.value.downcast_ref::<Array>().map_or_else(
|| self.type_error(), || self.type_error(),
|arr| _visitor.visit_seq(IterateArray::new(arr.iter())), |arr| _visitor.visit_seq(IterateArray::new(arr.iter())),
); );
@ -416,7 +416,7 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
fn deserialize_map<V: Visitor<'de>>(self, _visitor: V) -> Result<V::Value, Box<EvalAltResult>> { fn deserialize_map<V: Visitor<'de>>(self, _visitor: V) -> Result<V::Value, Box<EvalAltResult>> {
#[cfg(not(feature = "no_object"))] #[cfg(not(feature = "no_object"))]
return self.value.downclone_cast::<Map>().map_or_else( return self.value.downcast_ref::<Map>().map_or_else(
|| self.type_error(), || self.type_error(),
|map| { |map| {
_visitor.visit_map(IterateMap::new( _visitor.visit_map(IterateMap::new(
@ -449,7 +449,7 @@ impl<'de> Deserializer<'de> for &mut DynamicDeserializer<'de> {
visitor.visit_enum(s.as_str().into_deserializer()) visitor.visit_enum(s.as_str().into_deserializer())
} else { } else {
#[cfg(not(feature = "no_object"))] #[cfg(not(feature = "no_object"))]
if let Some(map) = self.value.downclone_cast::<Map>() { if let Some(map) = self.value.downcast_ref::<Map>() {
let mut iter = map.iter(); let mut iter = map.iter();
let first = iter.next(); let first = iter.next();
let second = iter.next(); let second = iter.next();

View File

@ -2,14 +2,20 @@
use crate::stdlib::{fmt, string::ToString}; use crate::stdlib::{fmt, string::ToString};
use crate::{Dynamic, ImmutableString, INT}; use crate::{Dynamic, ImmutableString, INT};
use serde::de::{Deserialize, Deserializer, Error, MapAccess, SeqAccess, Visitor}; use serde::de::{Deserialize, Deserializer, Error, Visitor};
#[cfg(not(feature = "no_index"))] #[cfg(not(feature = "no_index"))]
use crate::Array; use crate::Array;
#[cfg(not(feature = "no_index"))]
use serde::de::SeqAccess;
#[cfg(not(feature = "no_object"))] #[cfg(not(feature = "no_object"))]
use crate::Map; use crate::Map;
#[cfg(not(feature = "no_object"))]
use serde::de::MapAccess;
struct DynamicVisitor; struct DynamicVisitor;
impl<'d> Visitor<'d> for DynamicVisitor { impl<'d> Visitor<'d> for DynamicVisitor {

View File

@ -3,7 +3,10 @@
use crate::dynamic::{Union, Variant}; use crate::dynamic::{Union, Variant};
use crate::stdlib::string::ToString; use crate::stdlib::string::ToString;
use crate::{Dynamic, ImmutableString}; use crate::{Dynamic, ImmutableString};
use serde::ser::{Serialize, SerializeMap, Serializer}; use serde::ser::{Serialize, Serializer};
#[cfg(not(feature = "no_object"))]
use serde::ser::SerializeMap;
impl Serialize for Dynamic { impl Serialize for Dynamic {
fn serialize<S: Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> { fn serialize<S: Serializer>(&self, ser: S) -> Result<S::Ok, S::Error> {