code cleanup.

This commit is contained in:
Stephen Chung 2022-12-01 14:24:08 +08:00
parent acadb58f4f
commit 28640a6fe4
7 changed files with 9 additions and 5 deletions

View File

@ -8,6 +8,7 @@ Bug fixes
--------- ---------
* Integer numbers that are too large to deserialize into `INT` now fall back to `Decimal` or `FLOAT` instead of silently truncating. * Integer numbers that are too large to deserialize into `INT` now fall back to `Decimal` or `FLOAT` instead of silently truncating.
* Parsing deeply-nested closures (e.g. `||{||{||{||{||{||{||{...}}}}}}}`) no longer panics but will be confined to the nesting limit.
Breaking API changes Breaking API changes
-------------------- --------------------

View File

@ -4,7 +4,7 @@
fn init() { fn init() {
// Can detect system-provided default states! // Can detect system-provided default states!
// Add 'bool_state' as new state variable if one does not exist // Add 'bool_state' as new state variable if one does not exist
if !("bool_state" in this) { if "bool_state" !in this {
this.bool_state = false; this.bool_state = false;
} }
// Add 'value' as new state variable (overwrites any existing) // Add 'value' as new state variable (overwrites any existing)

View File

@ -4,7 +4,7 @@
/// State is stored inside an object map bound to 'state'. /// State is stored inside an object map bound to 'state'.
fn init() { fn init() {
// Add 'bool_state' as new state variable if one does not exist // Add 'bool_state' as new state variable if one does not exist
if !("bool_state" in state) { if "bool_state" !in state {
state.bool_state = false; state.bool_state = false;
} }
// Add 'obj_state' as new state variable (overwrites any existing) // Add 'obj_state' as new state variable (overwrites any existing)
@ -37,7 +37,7 @@ fn start(data) {
/// 'end' event handler /// 'end' event handler
fn end(data) { fn end(data) {
if !state.bool_state || !("start_mode" in state) { if !state.bool_state || "start_mode" !in state {
throw "Not yet started!"; throw "Not yet started!";
} }
if state.value > 0 { if state.value > 0 {

View File

@ -6,7 +6,7 @@ use crate::{Dynamic, Engine, Scope};
use std::prelude::v1::*; use std::prelude::v1::*;
/// Context of a script evaluation process. /// Context of a script evaluation process.
#[derive(Debug)] #[allow(dead_code)]
pub struct EvalContext<'a, 's, 'ps, 'g, 'c, 't> { pub struct EvalContext<'a, 's, 'ps, 'g, 'c, 't> {
/// The current [`Engine`]. /// The current [`Engine`].
engine: &'a Engine, engine: &'a Engine,

View File

@ -3,7 +3,7 @@
use super::{Caches, EvalContext, GlobalRuntimeState, Target}; use super::{Caches, EvalContext, GlobalRuntimeState, Target};
use crate::api::events::VarDefInfo; use crate::api::events::VarDefInfo;
use crate::ast::{ use crate::ast::{
ASTFlags, BinaryExpr, Expr, Ident, OpAssignment, Stmt, SwitchCasesCollection, TryCatchBlock, ASTFlags, BinaryExpr, Expr, OpAssignment, Stmt, SwitchCasesCollection, TryCatchBlock,
}; };
use crate::func::{get_builtin_op_assignment_fn, get_hasher}; use crate::func::{get_builtin_op_assignment_fn, get_hasher};
use crate::types::dynamic::{AccessMode, Union}; use crate::types::dynamic::{AccessMode, Union};
@ -834,6 +834,7 @@ impl Engine {
// Export statement // Export statement
#[cfg(not(feature = "no_module"))] #[cfg(not(feature = "no_module"))]
Stmt::Export(x, ..) => { Stmt::Export(x, ..) => {
use crate::ast::Ident;
let (Ident { name, pos, .. }, Ident { name: alias, .. }) = &**x; let (Ident { name, pos, .. }, Ident { name: alias, .. }) = &**x;
// Mark scope variables as public // Mark scope variables as public
scope.search(name).map_or_else( scope.search(name).map_or_else(

View File

@ -665,6 +665,7 @@ mod range_functions {
} }
/// Return true if the range contains no items. /// Return true if the range contains no items.
#[rhai_fn(get = "is_empty", name = "is_empty", pure)] #[rhai_fn(get = "is_empty", name = "is_empty", pure)]
#[allow(unstable_name_collisions)]
pub fn is_empty_exclusive(range: &mut ExclusiveRange) -> bool { pub fn is_empty_exclusive(range: &mut ExclusiveRange) -> bool {
range.is_empty() range.is_empty()
} }

View File

@ -1175,6 +1175,7 @@ impl Dynamic {
/// ``` /// ```
#[inline] #[inline]
#[must_use] #[must_use]
#[allow(unused_mut)]
pub fn try_cast<T: Any>(mut self) -> Option<T> { pub fn try_cast<T: Any>(mut self) -> Option<T> {
// Coded this way in order to maximally leverage potentials for dead-code removal. // Coded this way in order to maximally leverage potentials for dead-code removal.