Fix builds.

This commit is contained in:
Stephen Chung 2022-11-23 18:02:10 +08:00
parent 02ef119603
commit 46514bbc85
4 changed files with 24 additions and 20 deletions

View File

@ -270,7 +270,7 @@ impl Engine {
} else { } else {
let abs_index = index.unsigned_abs(); let abs_index = index.unsigned_abs();
if abs_index > usize::MAX as u64 { if abs_index as u64 > usize::MAX as u64 {
return Err( return Err(
ERR::ErrorStringBounds(s.chars().count(), index, idx_pos).into() ERR::ErrorStringBounds(s.chars().count(), index, idx_pos).into()
); );

View File

@ -2482,7 +2482,9 @@ impl Engine {
syntax: &crate::api::custom_syntax::CustomSyntax, syntax: &crate::api::custom_syntax::CustomSyntax,
pos: Position, pos: Position,
) -> ParseResult<Expr> { ) -> ParseResult<Expr> {
#[allow(clippy::wildcard_imports)]
use crate::api::custom_syntax::markers::*; use crate::api::custom_syntax::markers::*;
const KEYWORD_SEMICOLON: &str = Token::SemiColon.literal_syntax(); const KEYWORD_SEMICOLON: &str = Token::SemiColon.literal_syntax();
const KEYWORD_CLOSE_BRACE: &str = Token::RightBrace.literal_syntax(); const KEYWORD_CLOSE_BRACE: &str = Token::RightBrace.literal_syntax();
@ -2534,7 +2536,7 @@ impl Engine {
#[cfg(feature = "no_module")] #[cfg(feature = "no_module")]
let ns = (); let ns = ();
segments.push(name.clone().into()); segments.push(name.clone());
tokens.push(state.get_interned_string(CUSTOM_SYNTAX_MARKER_IDENT)); tokens.push(state.get_interned_string(CUSTOM_SYNTAX_MARKER_IDENT));
inputs.push(Expr::Variable((None, ns, 0, name).into(), None, pos)); inputs.push(Expr::Variable((None, ns, 0, name).into(), None, pos));
} }
@ -2548,7 +2550,7 @@ impl Engine {
CUSTOM_SYNTAX_MARKER_EXPR => { CUSTOM_SYNTAX_MARKER_EXPR => {
inputs.push(self.parse_expr(input, state, lib, settings)?); inputs.push(self.parse_expr(input, state, lib, settings)?);
let keyword = state.get_interned_string(CUSTOM_SYNTAX_MARKER_EXPR); let keyword = state.get_interned_string(CUSTOM_SYNTAX_MARKER_EXPR);
segments.push(keyword.clone().into()); segments.push(keyword.clone());
tokens.push(keyword); tokens.push(keyword);
} }
CUSTOM_SYNTAX_MARKER_BLOCK => { CUSTOM_SYNTAX_MARKER_BLOCK => {
@ -2556,7 +2558,7 @@ impl Engine {
block @ Stmt::Block(..) => { block @ Stmt::Block(..) => {
inputs.push(Expr::Stmt(Box::new(block.into()))); inputs.push(Expr::Stmt(Box::new(block.into())));
let keyword = state.get_interned_string(CUSTOM_SYNTAX_MARKER_BLOCK); let keyword = state.get_interned_string(CUSTOM_SYNTAX_MARKER_BLOCK);
segments.push(keyword.clone().into()); segments.push(keyword.clone());
tokens.push(keyword); tokens.push(keyword);
} }
stmt => unreachable!("Stmt::Block expected but gets {:?}", stmt), stmt => unreachable!("Stmt::Block expected but gets {:?}", stmt),
@ -2617,11 +2619,11 @@ impl Engine {
if *t == s => if *t == s =>
{ {
segments.push(required_token.clone()); segments.push(required_token.clone());
tokens.push(required_token.clone().into()); tokens.push(required_token.clone());
} }
(t, ..) if t.is_literal() && t.literal_syntax() == s => { (t, ..) if t.is_literal() && t.literal_syntax() == s => {
segments.push(required_token.clone()); segments.push(required_token.clone());
tokens.push(required_token.clone().into()); tokens.push(required_token.clone());
} }
(.., pos) => { (.., pos) => {
return Err(PERR::MissingToken( return Err(PERR::MissingToken(
@ -3007,19 +3009,19 @@ impl Engine {
// import expr ... // import expr ...
let expr = self.parse_expr(input, state, lib, settings.level_up())?; let expr = self.parse_expr(input, state, lib, settings.level_up())?;
let export = if !match_token(input, Token::As).0 { let export = if match_token(input, Token::As).0 {
// import expr;
Ident {
name: state.get_interned_string(""),
pos: Position::NONE,
}
} else {
// import expr as name ... // import expr as name ...
let (name, pos) = parse_var_name(input)?; let (name, pos) = parse_var_name(input)?;
Ident { Ident {
name: state.get_interned_string(name), name: state.get_interned_string(name),
pos, pos,
} }
} else {
// import expr;
Ident {
name: state.get_interned_string(""),
pos: Position::NONE,
}
}; };
state.imports.push(export.name.clone()); state.imports.push(export.name.clone());
@ -3595,7 +3597,7 @@ impl Engine {
match input.next().expect(NEVER_ENDS) { match input.next().expect(NEVER_ENDS) {
(Token::RightParen, ..) => break, (Token::RightParen, ..) => break,
(Token::Identifier(s), pos) => { (Token::Identifier(s), pos) => {
if params.iter().any(|(p, _)| p.as_str() == &*s) { if params.iter().any(|(p, _)| p.as_str() == *s) {
return Err( return Err(
PERR::FnDuplicatedParam(name.into(), s.to_string()).into_err(pos) PERR::FnDuplicatedParam(name.into(), s.to_string()).into_err(pos)
); );
@ -3666,7 +3668,7 @@ impl Engine {
externals: StaticVec<Ident>, externals: StaticVec<Ident>,
pos: Position, pos: Position,
) -> Expr { ) -> Expr {
use crate::{ast::Namespace, FnArgsVec}; use crate::FnArgsVec;
// If there are no captured variables, no need to curry // If there are no captured variables, no need to curry
if externals.is_empty() { if externals.is_empty() {
@ -3681,15 +3683,16 @@ impl Engine {
args.extend(externals.iter().cloned().map(|Ident { name, pos }| { args.extend(externals.iter().cloned().map(|Ident { name, pos }| {
let (index, is_func) = parent.access_var(&name, lib, pos); let (index, is_func) = parent.access_var(&name, lib, pos);
let idx = match index { let idx = match index {
#[allow(clippy::cast_possible_truncation)]
Some(n) if !is_func && n.get() <= u8::MAX as usize => NonZeroU8::new(n.get() as u8), Some(n) if !is_func && n.get() <= u8::MAX as usize => NonZeroU8::new(n.get() as u8),
_ => None, _ => None,
}; };
Expr::Variable((index, Namespace::default(), 0, name).into(), idx, pos) Expr::Variable((index, Default::default(), 0, name).into(), idx, pos)
})); }));
let expr = FnCallExpr { let expr = FnCallExpr {
#[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_module"))]
namespace: Namespace::default(), namespace: Default::default(),
name: state.get_interned_string(crate::engine::KEYWORD_FN_PTR_CURRY), name: state.get_interned_string(crate::engine::KEYWORD_FN_PTR_CURRY),
hashes: FnCallHashes::from_native(calc_fn_hash( hashes: FnCallHashes::from_native(calc_fn_hash(
None, None,

View File

@ -40,8 +40,9 @@ impl DynamicSerializer {
/// # #[cfg(not(feature = "no_index"))] /// # #[cfg(not(feature = "no_index"))]
/// # #[cfg(not(feature = "no_object"))] /// # #[cfg(not(feature = "no_object"))]
/// # #[cfg(not(feature = "no_float"))] /// # #[cfg(not(feature = "no_float"))]
/// # #[cfg(not(feature = "f32_float"))]
/// # { /// # {
/// use rhai::{Dynamic, Array, Map, INT}; /// use rhai::{Dynamic, Array, Map};
/// use rhai::serde::to_dynamic; /// use rhai::serde::to_dynamic;
/// use serde::Serialize; /// use serde::Serialize;
/// ///

View File

@ -1409,9 +1409,9 @@ impl Dynamic {
*self = crate::func::shared_try_take(cell).map_or_else( *self = crate::func::shared_try_take(cell).map_or_else(
|ref cell| crate::func::locked_read(cell).clone(), |ref cell| crate::func::locked_read(cell).clone(),
#[cfg(not(feature = "sync"))] #[cfg(not(feature = "sync"))]
crate::Locked::into_inner, |value| value.into_inner(),
#[cfg(feature = "sync")] #[cfg(feature = "sync")]
crate::Locked::into_inner().unwrap(), |value| value.into_inner().unwrap(),
); );
} }
_ => (), _ => (),